mongo SHOW_CREATE_TABLE when EMPTY

This commit is contained in:
黎明伟 2020-06-17 18:51:41 +08:00
parent e2be0993c5
commit a27d615c6e
2 changed files with 21 additions and 3 deletions

View File

@ -84,8 +84,8 @@ public class JSqlParserMongoStatementParser extends AbstractJSqlParserMongoState
}
if (_sql.startsWith("SHOW CREATE TABLE")) {
String tableName = MongoJSqlParserUtil.getTableNameWhenShow(sql);
return new SHOW_CREATE_TABLE() //
String tableName = MongoJSqlParserUtil.getTableNameWhenShow(sql);
return new SHOW_CREATE_TABLE() //
.setTableName(tableName);
}
@ -237,6 +237,14 @@ public class JSqlParserMongoStatementParser extends AbstractJSqlParserMongoState
}
private JdbcStatement parseDelete(String sql, Delete delete) {
if (null != delete.getLimit()) {
throw new RuntimeException("#241 not supported limit when delete, sql=" + sql);
}
if (null != delete.getOrderByElements()) {
throw new RuntimeException("#245 not supported order by when delete, sql=" + sql);
}
String collectionName = delete.getTable().getName();
Map<String, Object> where = this.whereDocument(delete.getWhere());
@ -253,6 +261,14 @@ public class JSqlParserMongoStatementParser extends AbstractJSqlParserMongoState
}
private JdbcStatement parseUpdate(String sql, Update update) {
if (null != update.getLimit()) {
throw new RuntimeException("#265 not supported limit when update, sql=" + sql);
}
if (null != update.getOrderByElements()) {
throw new RuntimeException("#269 not supported order by when update, sql=" + sql);
}
Table table = MongoJSqlParserUtil.getUpdateTable(sql, update);
String collectionName = table.getName();

View File

@ -36,7 +36,9 @@ public class SHOW_CREATE_TABLE extends AbstractMongoStatement {
// 没结果
Iterator<?> iterator = statementExecutor.find(this.tableName, new StatementDocument().limit(1));
if (!iterator.hasNext()) {
ResultSet resultSet = new MapArrayResultSet(new String[] { TABLE, CREATE_TABLE }, new Map[0]);
Map<String, String> valueMap = MapUtil.stringMap(TABLE, this.tableName, //
CREATE_TABLE, "EMPTY TABLE " + this.tableName);
ResultSet resultSet = new MapArrayResultSet(new String[] { TABLE, CREATE_TABLE }, new Map[] { valueMap });
((AbstractBudoJdbcPreparedStatement) preparedStatement).setResultSet(resultSet);
return;
}