Commit d0df4db5 authored by nanahira's avatar nanahira

fix non string things

parent 245eba66
...@@ -28,9 +28,21 @@ async function loadConstants() { ...@@ -28,9 +28,21 @@ async function loadConstants() {
} }
} }
} }
/*
function replaceClause(clause: string | any, falseStatement: boolean) {
if (typeof (clause) !== "string") {
return falseStatement ? ;
}
let newClause = clause;
for (let constantKey of Array.from(constantDict.keys())) {
const regex = new RegExp(`\{${constantKey}\}`, "g");
newClause = newClause.replace(regex, constantDict.get(constantKey).toString());
}
if()
}
*/
function replaceWhereClause(whereClause: (string | number)[]) { function replaceWhereClause(whereClause: (string | number)[]) {
const newClause: string[] = []; const newClauses: string[] = [];
if (!whereClause.length) { if (!whereClause.length) {
return ""; return "";
} }
...@@ -42,9 +54,9 @@ function replaceWhereClause(whereClause: (string | number)[]) { ...@@ -42,9 +54,9 @@ function replaceWhereClause(whereClause: (string | number)[]) {
const regex = new RegExp(`\{${constantKey}\}`, "g"); const regex = new RegExp(`\{${constantKey}\}`, "g");
clause = clause.replace(regex, constantDict.get(constantKey).toString()); clause = clause.replace(regex, constantDict.get(constantKey).toString());
} }
newClause.push(`and (${clause})`); newClauses.push(`and (${clause})`);
} }
return newClause.join(' '); return newClauses.join(' ');
} }
async function openDatabase() { async function openDatabase() {
...@@ -66,6 +78,7 @@ function getMedianCode(cards: Card[]) { ...@@ -66,6 +78,7 @@ function getMedianCode(cards: Card[]) {
async function queryCards(queryInfo: QueryInfo) { async function queryCards(queryInfo: QueryInfo) {
const replacedWhere = replaceWhereClause(queryInfo.where); const replacedWhere = replaceWhereClause(queryInfo.where);
console.log(replacedWhere);
const cards: Card[] = await db.all(`select datas.id,texts.name from datas,texts where datas.id = texts.id and datas.type & 0x4000 = 0 and datas.id > ? and datas.id <= ? and (datas.alias = 0 or datas.alias - datas.id > 10) ${replacedWhere} order by datas.id asc`, [queryInfo.lower, queryInfo.upper]); const cards: Card[] = await db.all(`select datas.id,texts.name from datas,texts where datas.id = texts.id and datas.type & 0x4000 = 0 and datas.id > ? and datas.id <= ? and (datas.alias = 0 or datas.alias - datas.id > 10) ${replacedWhere} order by datas.id asc`, [queryInfo.lower, queryInfo.upper]);
return cards; return cards;
} }
......
upper: 100000000 upper: 100000000
lower: 0 lower: 0
where: where:
- type & {TYPE_TUNER} > 0 - "not (type & {TYPE_MONSTER} > 0)"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment