move getSQLDataType to Z.DB
This commit is contained in:
parent
acdc36c9a1
commit
21a2188caa
3 changed files with 26 additions and 26 deletions
|
@ -1265,7 +1265,7 @@ Zotero.Item.prototype.save = function() {
|
|||
value = Zotero.DB.transactionDateTime;
|
||||
}
|
||||
|
||||
var dataType = ZU.getSQLDataType(value);
|
||||
var dataType = Zotero.DB.getSQLDataType(value);
|
||||
|
||||
switch (dataType) {
|
||||
case 32:
|
||||
|
@ -1598,7 +1598,7 @@ Zotero.Item.prototype.save = function() {
|
|||
value = Zotero.DB.transactionDateTime;
|
||||
}
|
||||
|
||||
var dataType = ZU.getSQLDataType(value);
|
||||
var dataType = Zotero.DB.getSQLDataType(value);
|
||||
|
||||
switch (dataType) {
|
||||
case 32:
|
||||
|
|
|
@ -1010,6 +1010,30 @@ Zotero.DBConnection.prototype.stopDummyStatement = function () {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the necessary data type for SQLite parameter binding
|
||||
*
|
||||
* @return int 0 for string, 32 for int32, 64 for int64
|
||||
*/
|
||||
Zotero.DBConnection.prototype.getSQLDataType = function(value) {
|
||||
var strVal = value + '';
|
||||
if (strVal.match(/^[1-9]+[0-9]*$/)) {
|
||||
// These upper bounds also specified in Zotero.DB
|
||||
//
|
||||
// Store as 32-bit signed integer
|
||||
if (value <= 2147483647) {
|
||||
return 32;
|
||||
}
|
||||
// Store as 64-bit signed integer
|
||||
// 2^53 is JS's upper-bound for decimal integers
|
||||
else if (value < 9007199254740992) {
|
||||
return 64;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Private methods
|
||||
|
|
|
@ -379,30 +379,6 @@ Zotero.Utilities.prototype.rand = function (min, max) {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the necessary data type for SQLite parameter binding
|
||||
*
|
||||
* @return int 0 for string, 32 for int32, 64 for int64
|
||||
*/
|
||||
Zotero.Utilities.prototype.getSQLDataType = function(value) {
|
||||
var strVal = value + '';
|
||||
if (strVal.match(/^[1-9]+[0-9]*$/)) {
|
||||
// These upper bounds also specified in Zotero.DB
|
||||
//
|
||||
// Store as 32-bit signed integer
|
||||
if (value <= 2147483647) {
|
||||
return 32;
|
||||
}
|
||||
// Store as 64-bit signed integer
|
||||
// 2^53 is JS's upper-bound for decimal integers
|
||||
else if (value < 9007199254740992) {
|
||||
return 64;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Adapted from http://developer.mozilla.org/en/docs/nsICryptoHash
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue