Solved

double insertion using cfquery

Posted on 2004-09-10
4
461 Views
Last Modified: 2013-12-24
So i have a number of queries running on different pages,
on the final page, where the totals are entered and the payment status are also entered, and an invoice number is generated.
every thing goes fine until the last query, i get a douple insert, one with the P_ID entered and the rest is empty except for the invoce number (which is automatically generated)
the second insert, the P_ID is empty but the rest is entered. you have to notice that only one user at a time is entered per session, so the info in the arrays and the structures belong to one user, so i guess no need to loop over it?
here is the code
<cflock scope="session" type="exclusive" timeout="10" throwontimeout="no">
            <cfset Pay = Duplicate(Session.PartAct.Pay)>
            <cfset Pinfo = Duplicate(Session.PartAct.Pinfo)>
            <cfset Total = Duplicate(session.PartAct.Sum)>
      </cflock>
      <cftransaction action="begin">
            <cftry>
                  <cfquery name="inputtotal" datasource="#request.MyDSN#">
                  INSERT INTO dbo.Status (P_ID,total,regsub,accosub,socisub)
                  VALUES (#Pinfo[5]#, #Total[4]#, #Total[1]#, #Total[2]#, #Total[3]#);
                  
                </cfquery>
            
          <cfcatch type="any">
               <cftransaction action="rollback" />
         </cfcatch>
      </cftry>
      <cftransaction action="commit" />
</cftransaction>

I have tried this without the <cftransaction action="commit" />, and with a starting <cftransaction action="begin">
I have also removed the table from the db and remade it.
here is how the table looks like after the insertion
------------------------------------------------------------|
|P_ID|Total|regsub|accosub|socisub|Invoicenumber|
|-----------------------------------------------------------|
|1     |null  | null    | null     | null     |2                  |
------------------------------------------------------------|
|null  |200 |100     | 50       | 50      | 3                 |
------------------------------------------------------------|

I know you will tell me that i'm better off without storing these values in the table since i can calculate them on the fly, but at the moment i'm short on time, and since i'm new to all of this, i will do it this way for now then later modifiy it.

but i need a solution to this double insertion thing, especially that it does not add all the values twice, it actually pick on them
0
Comment
Question by:MMsabry
4 Comments
 
LVL 17

Expert Comment

by:Tacobell777
ID: 12031048
Can't tell you why two records are inserted, you will have to show all of the code.
I can tell you that what I see looks a bit weird.

I think you are inserting each index of an array?
Total[4]#, #Total[1]#, #Total[2]#, #Total[3] is that correct?

you could just do arraySum(session.PartAct.Sum) to get the total of the array
0
 

Author Comment

by:MMsabry
ID: 12031148
ok, Tacobell777
I cannot do that, since i need to insert every subtotal at the moment, until i figure out how to use the stored procedure (which i have to learn) but since i do not have time at the moment, i will have to store all the values.

I figured out what was going wrong, a couple of pages before that, i had already inserted a value into the table, the pid and another value. and that is why i was always seeing two columns with the same pid, one is full without the other value, and the second row only contains the insertion from the first query. so i just had to use update statment and not insert.
thanks for your help any way.
sabry
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 12148823
Closed, 500 points refunded.
Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question