From a3df0c39e289fa772e71062b32d6eea370a4898c Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 20 Jun 2006 15:42:01 +0000 Subject: [PATCH] - DB parameters can now be bound using the native JS type rather than by specifying the type explicitly (e.g. Scholar.DB.query(sql, [1, 2, "hello"]) -- for use when the data is generated internally and trusted, obviously - Don't try to display an SQLite error when it's "not an error" (i.e. when the error is in something else) - Switch to nsIFile instead of nsILocalFile to retrieve the profile directory --- .../chromeFiles/content/scholar/xpcom/db.js | 78 +++++++++++++++---- 1 file changed, 62 insertions(+), 16 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/xpcom/db.js b/chrome/chromeFiles/content/scholar/xpcom/db.js index 36ba0aab8..b47b630b4 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/db.js +++ b/chrome/chromeFiles/content/scholar/xpcom/db.js @@ -31,7 +31,7 @@ Scholar.DB = new function(){ * Run an SQL query * * Optional _params_ is an array of bind parameters in the form - * [{'int':2},{'string':'foobar'}] + * [1,"hello",3] or [{'int':2},{'string':'foobar'}] * * Returns: * - Associative array (similar to mysql_fetch_assoc) for SELECT's @@ -89,7 +89,9 @@ Scholar.DB = new function(){ } } catch (e){ - throw(e + ' [QUERY: ' + sql + '] [ERROR: ' + db.lastErrorString + ']'); + var dberr = (db.lastErrorString!='not an error') + ? ' [ERROR: ' + db.lastErrorString + ']' : ''; + throw(e + ' [QUERY: ' + sql + ']' + dberr); } } @@ -151,7 +153,7 @@ Scholar.DB = new function(){ * Run a query, returning a mozIStorageStatement for direct manipulation * * Optional _params_ is an array of bind parameters in the form - * [{'int':2},{'string':'foobar'}] + * [1,"hello",3] or [{'int':2},{'string':'foobar'}] */ function statementQuery(sql,params){ var db = _getDBConnection(); @@ -161,27 +163,67 @@ Scholar.DB = new function(){ var statement = db.createStatement(sql); } catch (e){ - throw('[QUERY: ' + sql + '] [ERROR: ' + db.lastErrorString + ']'); + var dberr = (db.lastErrorString!='not an error') + ? ' [ERROR: ' + db.lastErrorString + ']' : ''; + throw(e + ' [QUERY: ' + sql + ']' + dberr); } if (statement && params){ for (var i=0; i file.append(SCHOLAR_CONFIG['DB_FILE']);