Support for SQL version 5.7
This commit is contained in:
parent
53b47057ff
commit
4434ad6b3e
@ -57,7 +57,7 @@ function storeSink(sinkID, sinkPrivKey) {
|
||||
global.sinkID = sinkID;
|
||||
global.sinkPrivKey = sinkPrivKey;
|
||||
let encryptedKey = Crypto.AES.encrypt(SINK_KEY_INDICATOR + sinkPrivKey, global.myPrivKey);
|
||||
DB.query('INSERT INTO sinkShares (floID, share) VALUE (?, ?) AS new ON DUPLICATE KEY UPDATE share=new.share', [sinkID, encryptedKey])
|
||||
DB.query('INSERT INTO sinkShares (floID, share) VALUE (?, ?) ON DUPLICATE KEY UPDATE share=?', [sinkID, encryptedKey, encryptedKey])
|
||||
.then(_ => console.log('SinkID:', sinkID, '|SinkEnKey:', encryptedKey))
|
||||
.catch(error => console.error(error));
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ function processDataFromMaster(message) {
|
||||
function storeSinkShare(sinkID, keyShare) {
|
||||
let encryptedShare = Crypto.AES.encrypt(floCrypto.decryptData(keyShare, global.myPrivKey), global.myPrivKey);
|
||||
console.log(Date.now(), '|sinkID:', sinkID, '|EnShare:', encryptedShare);
|
||||
DB.query("INSERT INTO sinkShares (floID, share) VALUE (?, ?) AS new ON DUPLICATE KEY UPDATE share=new.share", [sinkID, encryptedShare])
|
||||
DB.query("INSERT INTO sinkShares (floID, share) VALUE (?, ?) ON DUPLICATE KEY UPDATE share=?", [sinkID, encryptedShare, encryptedShare])
|
||||
.then(_ => null).catch(error => console.error(error));
|
||||
}
|
||||
|
||||
@ -289,13 +289,13 @@ storeBackupData.commit = function(data, result) {
|
||||
function updateBackupTable(add_data, delete_data) {
|
||||
//update _backup table for added data
|
||||
DB.transaction(add_data.map(r => [
|
||||
"INSERT INTO _backup (t_name, id, mode, timestamp) VALUE (?, ?, TRUE, ?) AS new ON DUPLICATE KEY UPDATE mode=TRUE, timestamp=new.timestamp",
|
||||
[r.t_name, r.id, validateValue(r.timestamp)]
|
||||
"INSERT INTO _backup (t_name, id, mode, timestamp) VALUE (?, ?, TRUE, ?) ON DUPLICATE KEY UPDATE mode=TRUE, timestamp=?",
|
||||
[r.t_name, r.id, validateValue(r.timestamp), validateValue(r.timestamp)]
|
||||
])).then(_ => null).catch(error => console.error(error));
|
||||
//update _backup table for deleted data
|
||||
DB.transaction(delete_data.map(r => [
|
||||
"INSERT INTO _backup (t_name, id, mode, timestamp) VALUE (?, ?, NULL, ?) AS new ON DUPLICATE KEY UPDATE mode=NULL, timestamp=new.timestamp",
|
||||
[r.t_name, r.id, validateValue(r.timestamp)]
|
||||
"INSERT INTO _backup (t_name, id, mode, timestamp) VALUE (?, ?, NULL, ?) ON DUPLICATE KEY UPDATE mode=NULL, timestamp=?",
|
||||
[r.t_name, r.id, validateValue(r.timestamp), validateValue(r.timestamp)]
|
||||
])).then(_ => null).catch(error => console.error(error));
|
||||
}
|
||||
|
||||
@ -317,8 +317,8 @@ function updateTableData(table, data) {
|
||||
let cols = Object.keys(data[0]),
|
||||
_mark = "(" + Array(cols.length).fill('?') + ")";
|
||||
let values = data.map(r => cols.map(c => validateValue(r[c]))).flat();
|
||||
let statement = `INSERT INTO ${table} (${cols}) VALUES ${Array(data.length).fill(_mark)} AS new` +
|
||||
" ON DUPLICATE KEY UPDATE " + cols.map(c => c + " = new." + c);
|
||||
let statement = `INSERT INTO ${table} (${cols}) VALUES ${Array(data.length).fill(_mark)}` +
|
||||
" ON DUPLICATE KEY UPDATE " + cols.map(c => `${c}=VALUES(${c})`).join();
|
||||
DB.query(statement, values).then(_ => resolve(true)).catch(error => reject(error));
|
||||
})
|
||||
}
|
||||
|
||||
20
src/main.js
20
src/main.js
@ -50,13 +50,13 @@ function refreshDataFromBlockchain() {
|
||||
promises.push(DB.query("DELETE FROM NodeList WHERE floID=?", [n]));
|
||||
if (content.Nodes.add)
|
||||
for (let n in content.Nodes.add)
|
||||
promises.push(DB.query("INSERT INTO NodeList (floID, uri) VALUE (?,?) AS new ON DUPLICATE KEY UPDATE uri=new.uri", [n, content.Nodes.add[n]]));
|
||||
promises.push(DB.query("INSERT INTO NodeList (floID, uri) VALUE (?,?) ON DUPLICATE KEY UPDATE uri=?", [n, content.Nodes.add[n], content.Nodes.add[n]]));
|
||||
}
|
||||
//Asset List
|
||||
if (content.Assets) {
|
||||
assets_change = true;
|
||||
for (let a in content.Assets)
|
||||
promises.push(DB.query("INSERT INTO AssetList (asset, initialPrice) VALUE (?,?) AS new ON DUPLICATE KEY UPDATE initialPrice=new.initialPrice", [a, content.Assets[a]]));
|
||||
promises.push(DB.query("INSERT INTO AssetList (asset, initialPrice) VALUE (?,?) ON DUPLICATE KEY UPDATE initialPrice=?", [a, content.Assets[a], content.Assets[a]]));
|
||||
}
|
||||
//Trusted List
|
||||
if (content.Trusted) {
|
||||
@ -66,7 +66,7 @@ function refreshDataFromBlockchain() {
|
||||
promises.push(DB.query("DELETE FROM TrustedList WHERE floID=?", [id]));
|
||||
if (content.Trusted.add)
|
||||
for (let id of content.Trusted.add)
|
||||
promises.push(DB.query("INSERT INTO TrustedList (floID) VALUE (?) AS new ON DUPLICATE KEY UPDATE floID=new.floID", [id]));
|
||||
promises.push(DB.query("INSERT INTO TrustedList (floID) VALUE (?) ON DUPLICATE KEY UPDATE floID=floID", [id]));
|
||||
}
|
||||
//Tag List with priority and API
|
||||
if (content.Tag) {
|
||||
@ -75,24 +75,24 @@ function refreshDataFromBlockchain() {
|
||||
promises.push(DB.query("DELETE FROM TagList WHERE tag=?", [t]));
|
||||
if (content.Tag.add)
|
||||
for (let t in content.Tag.add)
|
||||
promises.push(DB.query("INSERT INTO TagList (tag, sellPriority, buyPriority, api) VALUE (?,?,?,?) AS new ON DUPLICATE KEY UPDATE tag=new.tag", [t, content.Tag.add[t].sellPriority, content.Tag.add[t].buyPriority, content.Tag.add[t].api]));
|
||||
promises.push(DB.query("INSERT INTO TagList (tag, sellPriority, buyPriority, api) VALUE (?,?,?,?) ON DUPLICATE KEY UPDATE tag=tag", [t, content.Tag.add[t].sellPriority, content.Tag.add[t].buyPriority, content.Tag.add[t].api]));
|
||||
if (content.Tag.update)
|
||||
for (let t in content.Tag.update)
|
||||
for (let a in content.Tag.update[t])
|
||||
promises.push(`UPDATE TagList WHERE tag=? SET ${a}=?`, [t, content.Tag.update[t][a]]);
|
||||
}
|
||||
});
|
||||
promises.push(DB.query("INSERT INTO LastTx (floID, num) VALUE (?, ?) AS new ON DUPLICATE KEY UPDATE num=new.num", [floGlobals.adminID, result.totalTxs]));
|
||||
promises.push(DB.query("INSERT INTO LastTx (floID, num) VALUE (?, ?) ON DUPLICATE KEY UPDATE num=?", [floGlobals.adminID, result.totalTxs, result.totalTxs]));
|
||||
//Check if all save process were successful
|
||||
Promise.allSettled(promises).then(results => {
|
||||
//console.debug(results.filter(r => r.status === "rejected"));
|
||||
if (results.reduce((a, r) => r.status === "rejected" ? ++a : a, 0))
|
||||
console.warn("Some data might not have been saved in database correctly");
|
||||
});
|
||||
resolve({
|
||||
nodes: nodes_change,
|
||||
assets: assets_change,
|
||||
trusted: trusted_change
|
||||
resolve({
|
||||
nodes: nodes_change,
|
||||
assets: assets_change,
|
||||
trusted: trusted_change
|
||||
});
|
||||
});
|
||||
}).catch(error => reject(error));
|
||||
}).catch(error => reject(error))
|
||||
|
||||
@ -114,9 +114,9 @@ function Login(req, res) {
|
||||
proxyKey: data.proxyKey,
|
||||
timestamp: data.timestamp
|
||||
}, data.sign, data.floID, false).then(req_str => {
|
||||
DB.query("INSERT INTO UserSession (floID, proxyKey) VALUE (?, ?) AS new " +
|
||||
"ON DUPLICATE KEY UPDATE session_time=DEFAULT, proxyKey=new.proxyKey",
|
||||
[data.floID, data.proxyKey]).then(_ => {
|
||||
DB.query("INSERT INTO UserSession (floID, proxyKey) VALUE (?, ?) " +
|
||||
"ON DUPLICATE KEY UPDATE session_time=DEFAULT, proxyKey=?",
|
||||
[data.floID, data.proxyKey, data.proxyKey]).then(_ => {
|
||||
storeRequest(data.floID, req_str, data.sign);
|
||||
res.send("Login Successful");
|
||||
}).catch(error => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user