Click here to Skip to main content
15,915,508 members
Home / Discussions / Database
   

Database

 
GeneralRe: DELETE FROM ... not affecting the table? Pin
David Wulff31-Jan-02 4:15
David Wulff31-Jan-02 4:15 
GeneralRe: DELETE FROM ... not affecting the table? Pin
Andrew Peace3-Feb-02 13:39
Andrew Peace3-Feb-02 13:39 
GeneralRe: DELETE FROM ... not affecting the table? Pin
David Wulff3-Feb-02 14:16
David Wulff3-Feb-02 14:16 
GeneralRe: DELETE FROM ... not affecting the table? Pin
David Wulff10-Feb-02 8:00
David Wulff10-Feb-02 8:00 
GeneralRe: DELETE FROM ... not affecting the table? Pin
Andrew Peace10-Feb-02 8:45
Andrew Peace10-Feb-02 8:45 
GeneralRe: DELETE FROM ... not affecting the table? Pin
David Wulff10-Feb-02 8:56
David Wulff10-Feb-02 8:56 
GeneralRe: DELETE FROM ... not affecting the table? Pin
Andrew Peace10-Feb-02 9:11
Andrew Peace10-Feb-02 9:11 
GeneralRe: DELETE FROM ... not affecting the table? Pin
David Wulff10-Feb-02 10:49
David Wulff10-Feb-02 10:49 
I found the problem. Remember when I told you it would be something so simple and also so stupid that we'd laugh afterwards? Well...

I was tring to delete a non existing record, or to put it another way, I was using the incorrect record ID.

Let me explain how this got past all the checks...

The ASP page receives a record ID in data posted from a another page's form. It extracts this ID and stores it in a local variable:

if (Request.QueryString("TransactionID").Count)
	strTransactionID = Request("TransactionID");
else
	// abort action ...


Then, before I delete the record, I need to extract information about it, specifically if the user has permission to do so, and the ID's or linked records in other tables so I can update a couple of related records. I cosntruct the statement like thus:

SELECT Client.ClientID, Transaction.TransactionType, Transaction.TransactionData0, "+
	"Transaction.TransactionData1, Transaction.TransactionData2, Transaction.ProductID, "+
	"Product.NumberOfLicenses "+
	"FROM (Client INNER JOIN Product ON Client.ClientID = Product.ClientID) " +
	"INNER JOIN [Transaction] ON Product.ProductID = Transaction.ProductID";


Now, this was where my bug was being introduced. I had forgotten to add a WHERE clause specifing that I only wanted records with TransactionID's matching the one I retrieved above. After I get the records from this, I just checked to see if there were any, then used the various data items to update the relavent linked records, and finally I constructed the SQL statement to delete the record(s) using the TransactionID returned from the SELECT operation (which of course was always the first record in the table, which had now been deleted about eighty times!). What is very worrying is that none of my other test data fell through with the other tables, so I need to do some serious brainstorming as to why that managed to slip through.

When I output the SQL statement to the page so I could check it was correct, I was using the strTransactionID rather than that I used in the DELETE statement. I figured of course that the transaction ID's where the same...

D'oh.

Now who feels the utter idiot? Smile | :)

Thanks for helping me though my mental breakdown, guys! This wasn't the same cause the last time I had similar difficulties though, but at least I can get this out by Monday morning if I pull off another all-nighter tonight. Hmmm | :|

________________
David Wulff
http://www.davidwulff.co.uk

"I loathe people who keep dogs. They are cowards who haven't got the guts to bite people themselves" - August Strindberg
AnswerRe: DELETE FROM ... not affecting the table? Pin
Matt Gullett10-Feb-02 9:04
Matt Gullett10-Feb-02 9:04 
GeneralRe: DELETE FROM ... not affecting the table? Pin
David Wulff10-Feb-02 10:00
David Wulff10-Feb-02 10:00 
GeneralSQL Authentication Pin
Mike Osbahr28-Jan-02 4:32
Mike Osbahr28-Jan-02 4:32 
Generalset Request Value option on the field ! Pin
Hadi Rezaee27-Jan-02 10:15
Hadi Rezaee27-Jan-02 10:15 
GeneralOLE-DB connection Pin
User 988527-Jan-02 7:01
User 988527-Jan-02 7:01 
QuestionCan you show me about SQL Server 7.0 Pin
25-Jan-02 7:39
suss25-Jan-02 7:39 
AnswerRe: Can you show me about SQL Server 7.0 Pin
Carlos Antollini25-Jan-02 7:51
Carlos Antollini25-Jan-02 7:51 
GeneralSpecifying a connection should use TCP/IP Pin
James T. Johnson24-Jan-02 12:23
James T. Johnson24-Jan-02 12:23 
GeneralRe: Specifying a connection should use TCP/IP Pin
AndyG26-Jan-02 8:22
AndyG26-Jan-02 8:22 
GeneralRe: Specifying a connection should use TCP/IP Pin
James T. Johnson26-Jan-02 19:44
James T. Johnson26-Jan-02 19:44 
GeneralCHAR, adVarWChar, CString Pin
David Pokluda22-Jan-02 21:12
David Pokluda22-Jan-02 21:12 
GeneralADO Data Control Pin
22-Jan-02 20:37
suss22-Jan-02 20:37 
Questionwhich data type responding to DBTYPE_DBTIMESTAMP? Pin
Aaron K.B. Huang18-Jan-02 2:17
Aaron K.B. Huang18-Jan-02 2:17 
AnswerRe: which data type responding to DBTYPE_DBTIMESTAMP? Pin
Konstantin Vasserman18-Jan-02 2:30
Konstantin Vasserman18-Jan-02 2:30 
GeneralRe: which data type responding to DBTYPE_DBTIMESTAMP? Pin
Aaron K.B. Huang18-Jan-02 21:56
Aaron K.B. Huang18-Jan-02 21:56 
GeneralMemory leak when connecting to an Excel data source usin ODBC Pin
Martin Fridegren15-Jan-02 3:33
Martin Fridegren15-Jan-02 3:33 
GeneralAbout Provider's memeory manager Pin
Jeason Zhao14-Jan-02 23:13
Jeason Zhao14-Jan-02 23:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.