1

I am using Xojo 2013 Version 1. I am trying to delete a record from a SQLite database. But I am failing miserably. Instead of deleting the record, it duplicates it for some reason.

Here is the code that I use:

command = "DELETE * from names where ID = 10"

namesDB.SQLExecute(command)

I am dynamically generating command. but however I change it it always does the same. Same result with or without quotes.

Any ideas?

EnterpriseXL
  • 467
  • 8
  • 19

3 Answers3

2

The very first thing I would do is check to see if there is an error being generated.

if namesDB.Error then
  dim s as string = namesDB.errorMessage
  msgbox s
  return
end

It will tell you if there's a database error and what the error is. If there's no error then the problem lies elsewhere.

FWIW, always, always, always check the error bit after every db operation. Unlike other languages, Xojo does NOT generate/throw an exception if there's a database error so it's up to you to check it.

BKeeney Software
  • 1,299
  • 6
  • 8
1

Try calling Commit().

I just made a sample SQLite database with a "names" table, and this code worked fine:

db.SQLExecute("Delete from names where ID=2")
db.Commit

I have done a lot of work with XOJO and SQLite, and they work well together. I have never seen a record duplicated erroneously as you report. That is very weird. If this doesn't help, post more of your code. For example, I assume your "command" variable is a String, but maybe it's a Variant, etc.

  • I have spend time and time and same result. this is exactly what happens. say I have ID = 3, and I delete it... it is gone, however the new record (with same data) is created on position 4, and three is gone. I have hard coded the command string... dynamically convert it... Just the same for some reason. – EnterpriseXL Jul 13 '13 at 09:17
0

I think on SQLite you don't need the * between the DELETE and the FROM.

Sabilv
  • 602
  • 1
  • 15
  • 44