From e8ed4281f95c59282b7532bc83e14e0de516b2e4 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 16 Jun 2006 21:44:41 +0000 Subject: [PATCH] Change the DB query functions to return values of the actual types they are, rather than to return everything as strings -- this will prevent the need for parseInt on COUNT(*) values, etc. and is generally better This will temporarily break the display of numeric fields on the interface side --- .../chromeFiles/content/scholar/xpcom/db.js | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/xpcom/db.js b/chrome/chromeFiles/content/scholar/xpcom/db.js index e2b5cd9f34..0330a73bea 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/db.js +++ b/chrome/chromeFiles/content/scholar/xpcom/db.js @@ -59,8 +59,9 @@ Scholar.DB = new function(){ var dataset = new Array(); while (statement.executeStep()){ var row = new Array(); + for(var i=0; i -1){ - var value = statement.getInt32(0); - } - else { - var value = statement.getUTF8String(0); - } - statement.reset(); - return value; + + return _getTypedValue(statement, 0); } @@ -141,7 +136,7 @@ Scholar.DB = new function(){ if (statement){ var column = new Array(); while (statement.executeStep()){ - column.push(statement.getUTF8String(0)); + column.push(_getTypedValue(statement, 0)); } statement.reset(); return column.length ? column : false; @@ -314,4 +309,27 @@ Scholar.DB = new function(){ return _connection; } + + + function _getTypedValue(statement, i){ + var type = statement.getTypeOfIndex(i); + switch (type){ + case statement.VALUE_TYPE_INTEGER: + var func = statement.getInt32; + break; + case statement.VALUE_TYPE_TEXT: + var func = statement.getUTF8String; + break; + case statement.VALUE_TYPE_NULL: + return null; + case statement.VALUE_TYPE_FLOAT: + var func = statement.getDouble; + break; + case statement.VALUE_TYPE_BLOB: + var func = statement.getBlob; + break; + } + + return func(i); + } }