Hi List,

I am new to sqlite and having trouble determining if an update has worked.

I am using the C/C++ API.

For an update, when sqlite3_step is executed it returns SQLITE_DONE when
a record is updated or if a record does not exist.  I have not found an
answer by reading and  searching the documentation and searching the
internet

This is the same for the command line tool.

Using code based on "http://www.sqlite.org/cvstrac/wiki?p=SimpleCode";

$ fred testdb "create table bob(p1 text PRIMARY KEY, p2 text)"
SQLITE_DONE: 101 : unknown error
$ fred testdb "insert into bob (p1, p2) values('foo', 'sue')"
SQLITE_DONE: 101 : unknown error
$ fred testdb "insert into bob (p1, p2) values('foo', 'sue')"
Error: 19 : constraint failed
$ fred testdb "update bob set p2 = 'fred' where p1 = 'foo'"
SQLITE_DONE: 101 : unknown error <-- update ok
$ fred testdb "update bob set p2 = 'fred' where p1 = 'fo1'"
SQLITE_DONE: 101 : unknown error <-- update fail
$ fred testdb "select count(*) from bob"
count(*) = 1
SQLITE_DONE: 101 : unknown error
$ fred testdb "select * from bob"
p1 = foo
p2 = fred
SQLITE_DONE: 101 : unknown error
$

When using the command line tool.
SQLite version 3.6.16
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table bob(p1 text PRIMARY KEY, p2 text);
sqlite> .header on
sqlite> .show
      echo: off
   explain: off
   headers: on
      mode: list
nullvalue: ""
    output: stdout
separator: "|"
     width:
sqlite> update bob set p2 = 'fred' where p1 = 'foo';
sqlite> insert into bob (p1, p2, p3) values('foo', 'sue', 'todd');
SQL error: table bob has no column named p3
sqlite> insert into bob (p1, p2) values('foo', 'sue');
sqlite> select * from bob;
p1|p2
foo|sue
sqlite> update bob set p2 = 'fred' where p1 = 'foo';
sqlite> select * from bob;
p1|p2
foo|fred
sqlite> update bob set p2 = 'fred' where p1 = 'fo1';
sqlite>


Thanks
Steve



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to