SQLite

  • Thread starter Matthias Huening
  • Start date
M

Matthias Huening

Hi,

This is probably trivial, but I cannot find a solution right now.
With MySQLdb, I could test the success of a deleting action like this:

sql = "DELETE FROM table WHERE name='xxx'"
res = cur.execute(sql)
if res == 1:
print 'Okay'
else:
print 'nothing deleted'


This seems not to work with sqlite3. How can I test whether deletion was
sussessful or not?

Thanks,
Matthias
 
G

gordyt

Howdy Matthias!

The delete operation will set the rowcount member of your cursor.
Let's assume you have an sqlite3 database with a table called 'test'
with an id column. It does have a record with id=1. It does not have
a record with id=2.


--gordy
 
P

Petite Abeille

This seems not to work with sqlite3.

Before going any further... make sure that SQLite's count_change is
enabled:

PRAGMA count_changes
PRAGMA count_changes = 0 | 1

"Query or change the count-changes flag. Normally, when the count-
changes flag is not set, INSERT, UPDATE and DELETE statements return
no data. When count-changes is set, each of these commands returns a
single row of data consisting of one integer value - the number of
rows inserted, modified or deleted by the command. "

http://www.sqlite.org/pragma.html

Cheers,
 
M

Matthias Huening

Thanks!
cursor.rowcount does exactly what I need.
Before going any further... make sure that SQLite's count_change is
enabled:

PRAGMA count_changes
PRAGMA count_changes = 0 | 1

"Query or change the count-changes flag. Normally, when the
count-changes flag is not set, INSERT, UPDATE and DELETE statements
return no data. When count-changes is set, each of these commands
returns a single row of data consisting of one integer value - the
number of rows inserted, modified or deleted by the command. "

Looks like this is not really necessary. My database hat count_changes
disabled, but rowcount seems to work anyway. Are there any pitfalls?

Matthias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top