fiona
unread,Feb 3, 2012, 2:00:54 PM2/3/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Xerial
For example,
stat.executeUpdate("insert into people values ('blah', 'someone');");
then
stat.executeUpdate("drop table if exists people;");
returns 1( the result from INSERT statement), instead of 0. That's
because executeUpdate returns changes = db.changes() without checking
whether it is a DDL statement or not.
This is how it happened. From Stmt.java:
public int executeUpdate(String sql) throws SQLException {
close();
this.sql = sql;
int changes = 0;
SQLExtension ext = ExtendedCommand.parse(sql);
if (ext != null) {
// execute extended command
ext.execute(db);
}
else {
try {
//db.prepare(this);
//changes = db.executeUpdate(this, null);
// directly invokes the exec API to support multiple
SQL statements
int statusCode = db._exec(sql);
if (statusCode != SQLITE_OK)
throw DB.newSQLException(statusCode, "");
changes = db.changes();
}
finally {
close();
}
}
return changes;
}
here native method NativeDB.changes() calling for C function int
sqlite3_changes(sqlite3*);, which " returns the number of changes in
the most recent INSERT, UPDATE, or DELETE that also occurred at the
top level. "