Skip to content

Commit 117ec4a

Browse files
author
Shuai Yang
committed
Handle 'QualifiedWildcard'
1 parent 478831f commit 117ec4a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ document.getElementById('convert-button').addEventListener('click', function ()
2121

2222
try {
2323
let ast = wasm.parse_sql("--mysql", input);
24+
console.log(ast);
2425

2526
output_text_area.value = (new Converter(JSON.parse(ast)[0].Query)).run();
2627
} catch (e) {
@@ -182,6 +183,8 @@ class Converter
182183
res.push(this.resolveSelectSectionItem(select_item.UnnamedExpr));
183184
} else if (select_item === 'Wildcard') {
184185
res.push('*');
186+
} else if (propertyExistsInObjectAndNotNull(select_item, 'QualifiedWildcard')) {
187+
res.push(quote(this.getActualTableName(select_item.QualifiedWildcard[0].value) + '.*'))
185188
} else {
186189
throw 'Logic error, unhandled select item [' + Object.keys(select_item)[0] + ']';
187190
}
@@ -348,6 +351,14 @@ class Converter
348351
}
349352
}
350353

354+
getActualTableName(table_name_or_alias) {
355+
if (propertyExistsInObjectAndNotNull(this.table_name_by_alias, table_name_or_alias)) {
356+
return this.table_name_by_alias[table_name_or_alias];
357+
}
358+
359+
return table_name_or_alias;
360+
}
361+
351362
/**
352363
* @param identifier
353364
* @param {boolean} need_quote
@@ -358,9 +369,7 @@ class Converter
358369
let table_name_or_alias = values[0];
359370

360371
// First index always is table name or alias, change it to actual table name.
361-
if (propertyExistsInObjectAndNotNull(this.table_name_by_alias, table_name_or_alias)) {
362-
values[0] = this.table_name_by_alias[table_name_or_alias];
363-
}
372+
values[0] = this.getActualTableName(table_name_or_alias);
364373

365374
let res = values.join('.');
366375

0 commit comments

Comments
 (0)