Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 4th, 2005, 04:25 PM
WATYF WATYF is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Smiling back at you...
Posts: 19 WATYF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 32 m 9 sec
Reputation Power: 0
Unhappy DELETE statement is deleting more records than it should...

Hi there... I'm using an Embedded FB DB as the backend for my .NET app, and it has solved a number of problems I had with SQLite (my app is heavily multi-threaded, so SQLite didn't work out too well), but I seem to have run into an odd issue with FB.

I have a thread that deletes items from a table when they're "done". I'm using the same SQL I was using with SQLite (which worked fine) but with FB it appears to be deleting all records from the table that begin with the text of the item that's "done"

For example, I have three items, Test1, Test2, Test3. Test1 runs its course and the thread catches it and proceeds to remove it from the table. The SQL is as follows:

"DELETE FROM tblTasks WHERE Name='Test1'"

Now... I've done concurrent DB checks to confirm what's happening, and basically, instead of deleting "Test1", it deletes Test1, Test2, and Test3.

At first I thought the DELETE command was somehow deleting all records regardless of what Name I specified, but it ends up that it's a matter of a wildcard somehow being applied to the Name that I provide.

I tested this by renaming my items to completely unrealted names. Test1, Check1, Sample1.

I then ran the same exact code and it only deleted the one item instead of all of them.


So... why is it deleting all rows that have a Name starting with the text I'm specifying? I'm not using a wildcard character, so what can I do to stop thig behavior?



WATYF

Reply With Quote
  #2  
Old May 4th, 2005, 05:06 PM
shammat shammat is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2003
Location: Munich, Bavaria
Posts: 992 shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level)shammat User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 3 h 36 m 10 sec
Reputation Power: 66
I'm pretty sure that this is something in your code either messing around with the statement or the parameters to the statement.

I very much doubt that there is something wrong in FB with such a simple DELETE statement (in fact I have used very similar delete statements and all of them deleted what they should)

Reply With Quote
  #3  
Old May 5th, 2005, 12:55 AM
SilverDB's Avatar
SilverDB SilverDB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Location: Romania
Posts: 173 SilverDB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 45 m 53 sec
Reputation Power: 4
Send a message via Yahoo to SilverDB
Try this:
get IBSQL ( from www.ibobjects.com) or any other free SQL app ... run your query and see what it deletes.
If it deletes what it should that means that you have a problem in your code ...

Good luck.
__________________
If i've been helpful, please add to my reputation.
My unfinished site: http://www.dever.ro

Reply With Quote
  #4  
Old May 5th, 2005, 08:33 AM
WATYF WATYF is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Smiling back at you...
Posts: 19 WATYF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 32 m 9 sec
Reputation Power: 0
Here's the code... I can't imagine there's a problem in it... the only thing I can think of is that FB sees the ' character as some kind of wildcard.

sTsk = "Test"
cmd = db.CreateCommand
cmd.CommandText = "DELETE FROM tblTasks WHERE TskNm='" & sTsk & "'"
cmd.ExecuteNonQuery()
cmd = Nothing

And my example above was typed out wrong... the items would be Test, Test1, Test2. If I try to delete "Test", it deletes them all.



WATYF

Reply With Quote
  #5  
Old May 5th, 2005, 08:36 AM
WATYF WATYF is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Smiling back at you...
Posts: 19 WATYF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 32 m 9 sec
Reputation Power: 0
Quote:
Originally Posted by SilverDB
Try this:
get IBSQL ( from www.ibobjects.com) or any other free SQL app ... run your query and see what it deletes.
If it deletes what it should that means that you have a problem in your code ...

Good luck.

What I'm saying is, I did run just that query, and that's what it did. I checked the table, saw that there were three records, ran that one SQL statment, and then there were no records.


WATYF

Reply With Quote
  #6  
Old May 5th, 2005, 08:41 AM
WATYF WATYF is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Smiling back at you...
Posts: 19 WATYF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 32 m 9 sec
Reputation Power: 0
btw, there are no parameters for this statement... a single SQLCommand is created, I set the command text, and execute the query. The only variable being passed to the code is the name of the item that it's supposed to delete.


WATYF

Reply With Quote
  #7  
Old May 5th, 2005, 09:12 AM
WATYF WATYF is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Smiling back at you...
Posts: 19 WATYF User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 32 m 9 sec
Reputation Power: 0
Well... I figured it out. When trying to convert my previous tables (Created in SQLite) to FB tables, I picked the wrong data type.

I was using data type BLOB SUB_TYPE TEXT for the "Name" field, so something about that data type caused it to DELETE anything that started with "Test".

Anyway... I switched the data type for that field to VARCHAR and the problem went away.



WATYF

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > DELETE statement is deleting more records than it should...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway