Permalink
Browse files

* Fixed bugs in execute: Return true if empty result set.

  • Loading branch information...
1 parent b83126b commit 2bfb83bcc541ce0a1d031c73ffd6814ddf8146ae @donv donv committed Nov 30, 2012
Showing with 10 additions and 23 deletions.
  1. +1 −1 Gemfile.lock
  2. +0 −6 src/org/sqldroid/SQLDroidConnection.java
  3. +9 −16 src/org/sqldroid/SQLDroidStatement.java
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- sqldroid (1.0.0.RC2)
+ sqldroid (1.0.0.RC4)
GEM
remote: http://rubygems.org/
@@ -187,45 +187,39 @@ public boolean getAutoCommit() throws SQLException {
public String getCatalog() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
-
return null;
}
@Override
public int getHoldability() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
-
return 0;
}
@Override
public DatabaseMetaData getMetaData() throws SQLException {
-
return new SQLDroidDatabaseMetaData(this);
}
@Override
public int getTransactionIsolation() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
-
return 0;
}
@Override
public Map<String, Class<?>> getTypeMap() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
-
return null;
}
@Override
public SQLWarning getWarnings() throws SQLException {
System.err.println(" ********************* not implemented @ " + DebugPrinter.getFileName() + " line "
+ DebugPrinter.getLineNumber());
-
return null;
}
@@ -68,44 +68,37 @@ public void close() throws SQLException {
/** Close the result set (if open) and null the rs variable. */
public void closeResultSet() throws SQLException {
- if (rs != null && !rs.isClosed()) {
+ if (rs != null) {
if (!rs.isClosed()) {
rs.close();
}
rs = null;
}
}
+
@Override
/** Execute the SQL statement.
- * @return false if there are no result (if the request was not a select or similar) or the result set was empty. True if a
- * non-empty result set is available. This meets the requirement of java.sql.Statement.
+ * @return false if there are no result (if the request was not a select or similar). True if a
+ * result set is available. This meets the requirement of java.sql.Statement.
*/
public boolean execute(String sql) throws SQLException {
- updateCount = -1; // default outcome. If the sql is a query or any other sql fails.
- boolean ok = false;
+ updateCount = -1; // default outcome. If the sql is a query or any other sql fails.
closeResultSet();
- boolean isSelect = sql.toUpperCase().matches("(?m)(?s)\\s*SELECT.*");
- // problem, a PRAGMA statement (and maybe others) should also cause a result set
- if ( !isSelect && sql.toUpperCase().matches("(?m)(?s)\\s*PRAGMA.*") ) {
- isSelect = true;
- }
- if ( rs!= null && !rs.isClosed() ) {
+ boolean isSelect = sql.toUpperCase().matches("(?m)(?s)\\s*(SELECT|PRAGMA).*");
+ if ( rs != null && !rs.isClosed() ) {
rs.close();
}
- rs = null;
if (isSelect) {
String limitedSql = sql + (maxRows != null ? " LIMIT " + maxRows : "");
Cursor c = db.rawQuery(limitedSql, new String[0]);
rs = new SQLDroidResultSet(c);
- if ( c.getCount() != 0 ) {
- ok = true;
- }
} else {
db.execSQL(sql);
+ rs = null;
updateCount = db.changedRowCount();
}
- boolean resultSetAvailable = ok && !sql.toUpperCase().startsWith("CREATE") && rs != null;
+ boolean resultSetAvailable = (rs != null);
// if (resultSetAvailable) {
// boolean headerDrawn = false;

0 comments on commit 2bfb83b

Please sign in to comment.