Skip to content

Commit

Permalink
Fix bugs when processing null date
Browse files Browse the repository at this point in the history
Format where condition for id column by type
  • Loading branch information
gslack-app committed Apr 23, 2020
1 parent 09c4f4f commit fe3cb7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 16 additions & 1 deletion www/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class ApiServlet extends HttpServlet {

if (id) {
orderBy = null;
condition = `${this.queryAdapter.getIdByColumn(pk.column)} = ${pk.type == 'number' ? id : "'" + id + "'"}`;
condition = `${this.queryAdapter.getIdByColumn(pk.column)} = ${this.formatLiteral(pk.type, id)}`;
}
else {
// Reserved words must be back-quoted if used as an identifier
Expand Down Expand Up @@ -250,6 +250,21 @@ export class ApiServlet extends HttpServlet {
return errors.length ? errors : null;
}

protected formatLiteral(type: string, value: any): string {
switch (type) {
case 'number':
return value;
case 'date':
return `date '${value}'`;
case 'time':
return `timeofday '${value}'`;
case 'datetime':
return `datetime '${value}'`;
default:
return `'${value}'`;
}
}

protected getValidators(): any {
let names = ['error', 'object', 'array', 'string', 'number',
'boolean', 'date', 'regexp', 'Null', 'Undefined',
Expand Down
6 changes: 4 additions & 2 deletions www/query-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ export class QueryAdapter implements IQueryAdapter {

switch (type) {
case 'date':
let value = eval(`new ${col.v}`);
item[name] = pattern ? Utilities.formatDate(value, Session.getScriptTimeZone(), pattern) : value;
if (col.v) {
let value = eval(`new ${col.v}`);
item[name] = pattern ? Utilities.formatDate(value, Session.getScriptTimeZone(), pattern) : value;
}
break;
default:
item[name] = col.v;
Expand Down

0 comments on commit fe3cb7d

Please sign in to comment.