|
|
@ -22,6 +22,8 @@ class Xsql { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************** START : Cache functions ****************/ |
|
|
|
init(cbk) { |
|
|
|
init(cbk) { |
|
|
|
this.dbCacheInitAsync((err, results) => { |
|
|
|
this.dbCacheInitAsync((err, results) => { |
|
|
|
cbk(err, results) |
|
|
|
cbk(err, results) |
|
|
@ -137,6 +139,8 @@ class Xsql { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/**************** END : Cache functions ****************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exec(query, params) { |
|
|
|
exec(query, params) { |
|
|
|
|
|
|
|
|
|
|
@ -162,13 +166,13 @@ class Xsql { |
|
|
|
const flatTypes = ['float', 'double', 'decimal']; |
|
|
|
const flatTypes = ['float', 'double', 'decimal']; |
|
|
|
const dateTypes = ['date', 'datetime', 'timestamp', 'time', 'year']; |
|
|
|
const dateTypes = ['date', 'datetime', 'timestamp', 'time', 'year']; |
|
|
|
|
|
|
|
|
|
|
|
if (getType(Type, strTypes)) { |
|
|
|
if (dataHelp.getType(Type, strTypes)) { |
|
|
|
return "string" |
|
|
|
return "string" |
|
|
|
} else if (getType(Type, intTypes)) { |
|
|
|
} else if (dataHelp.getType(Type, intTypes)) { |
|
|
|
return "int" |
|
|
|
return "int" |
|
|
|
} else if (getType(Type, flatTypes)) { |
|
|
|
} else if (dataHelp.getType(Type, flatTypes)) { |
|
|
|
return "float" |
|
|
|
return "float" |
|
|
|
} else if (getType(Type, dateTypes)) { |
|
|
|
} else if (dataHelp.getType(Type, dateTypes)) { |
|
|
|
return "date" |
|
|
|
return "date" |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return "unknown" |
|
|
|
return "unknown" |
|
|
@ -466,7 +470,7 @@ class Xsql { |
|
|
|
// get a where clause out of the above columnNames and their values
|
|
|
|
// get a where clause out of the above columnNames and their values
|
|
|
|
for (let i = 0; i < pks.length; ++i) { |
|
|
|
for (let i = 0; i < pks.length; ++i) { |
|
|
|
|
|
|
|
|
|
|
|
let type = getColumnType(pks[i]); |
|
|
|
let type = dataHelp.getColumnType(pks[i]); |
|
|
|
|
|
|
|
|
|
|
|
whereCol = pks[i]['column_name'] |
|
|
|
whereCol = pks[i]['column_name'] |
|
|
|
|
|
|
|
|
|
|
@ -503,7 +507,7 @@ class Xsql { |
|
|
|
let fks = this.metaDb.tables[childTable].foreignKeys; |
|
|
|
let fks = this.metaDb.tables[childTable].foreignKeys; |
|
|
|
let fk = dataHelp.findObjectInArrayByKey('referenced_table_name', parentTable, fks); |
|
|
|
let fk = dataHelp.findObjectInArrayByKey('referenced_table_name', parentTable, fks); |
|
|
|
let whereCol = fk['column_name'] |
|
|
|
let whereCol = fk['column_name'] |
|
|
|
let colType = getColumnType(fk); |
|
|
|
let colType = dataHelp.getColumnType(fk); |
|
|
|
|
|
|
|
|
|
|
|
if (colType === 'string') { |
|
|
|
if (colType === 'string') { |
|
|
|
whereValue = mysql.escape(parentId) |
|
|
|
whereValue = mysql.escape(parentId) |
|
|
@ -1005,47 +1009,3 @@ class Xsql { |
|
|
|
module.exports = Xsql; |
|
|
|
module.exports = Xsql; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getDataType(colType, typesArr) { |
|
|
|
|
|
|
|
// console.log(colType,typesArr);
|
|
|
|
|
|
|
|
for (let i = 0; i < typesArr.length; ++i) { |
|
|
|
|
|
|
|
if (colType.indexOf(typesArr[i]) !== -1) { |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getColumnType(column) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let strTypes = ['varchar', 'text', 'char', 'tinytext', 'mediumtext', 'longtext', 'blob', 'mediumblob', 'longblob', 'tinyblob', 'binary', 'varbinary']; |
|
|
|
|
|
|
|
let intTypes = ['int', 'long', 'smallint', 'mediumint', 'bigint', 'tinyint']; |
|
|
|
|
|
|
|
let flatTypes = ['float', 'double', 'decimal']; |
|
|
|
|
|
|
|
let dateTypes = ['date', 'datetime', 'timestamp', 'time', 'year']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//console.log(column);
|
|
|
|
|
|
|
|
if (getDataType(column['data_type'], strTypes)) { |
|
|
|
|
|
|
|
return "string" |
|
|
|
|
|
|
|
} else if (getDataType(column['data_type'], intTypes)) { |
|
|
|
|
|
|
|
return "int" |
|
|
|
|
|
|
|
} else if (getDataType(column['data_type'], flatTypes)) { |
|
|
|
|
|
|
|
return "float" |
|
|
|
|
|
|
|
} else if (getDataType(column['data_type'], dateTypes)) { |
|
|
|
|
|
|
|
return "date" |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return "string" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getType(colType, typesArr) { |
|
|
|
|
|
|
|
for (let i = 0; i < typesArr.length; ++i) { |
|
|
|
|
|
|
|
// if (typesArr[i].indexOf(colType) !== -1) {
|
|
|
|
|
|
|
|
// return 1;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (colType.indexOf(typesArr[i]) !== -1) { |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|