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); + } }