DLL statements return result other than 0

9 views
Skip to first unread message

fiona

unread,
Feb 3, 2012, 2:00:54 PM2/3/12
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. "

Grace B

unread,
Feb 18, 2013, 7:36:19 PM2/18/13
to xer...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages