use of com.alibaba.druid.FastsqlException in project druid by alibaba.
the class MySqlCharExpr method output.
public void output(Appendable buf) {
try {
if (charset != null) {
buf.append(charset);
buf.append(' ');
}
if (super.text != null) {
super.output(buf);
}
if (collate != null) {
buf.append(" COLLATE ");
buf.append(collate);
}
} catch (IOException ex) {
throw new FastsqlException("output error", ex);
}
}
use of com.alibaba.druid.FastsqlException in project druid by alibaba.
the class SchemaRepository method console.
public String console(String input) {
try {
StringBuffer buf = new StringBuffer();
List<SQLStatement> stmtList = SQLUtils.parseStatements(input, dbType);
for (SQLStatement stmt : stmtList) {
if (stmt instanceof SQLShowColumnsStatement) {
SQLShowColumnsStatement showColumns = ((SQLShowColumnsStatement) stmt);
SQLName db = showColumns.getDatabase();
Schema schema;
if (db == null) {
schema = getDefaultSchema();
} else {
schema = findSchema(db.getSimpleName());
}
SQLName table = null;
SchemaObject schemaObject = null;
if (schema != null) {
table = showColumns.getTable();
schemaObject = schema.findTable(table.nameHashCode64());
}
if (schemaObject == null) {
buf.append("ERROR 1146 (42S02): Table '" + table + "' doesn't exist\n");
} else {
MySqlCreateTableStatement createTableStmt = (MySqlCreateTableStatement) schemaObject.getStatement();
createTableStmt.showCoumns(buf);
}
} else if (stmt instanceof SQLShowCreateTableStatement) {
SQLShowCreateTableStatement showCreateTableStmt = (SQLShowCreateTableStatement) stmt;
SQLName table = showCreateTableStmt.getName();
SchemaObject schemaObject = findTable(table);
if (schemaObject == null) {
buf.append("ERROR 1146 (42S02): Table '" + table + "' doesn't exist\n");
} else {
MySqlCreateTableStatement createTableStmt = (MySqlCreateTableStatement) schemaObject.getStatement();
createTableStmt.output(buf);
}
} else if (stmt instanceof MySqlRenameTableStatement) {
MySqlRenameTableStatement renameStmt = (MySqlRenameTableStatement) stmt;
for (MySqlRenameTableStatement.Item item : renameStmt.getItems()) {
renameTable(item.getName(), item.getTo());
}
} else if (stmt instanceof SQLShowTablesStatement) {
SQLShowTablesStatement showTables = (SQLShowTablesStatement) stmt;
SQLName database = showTables.getDatabase();
Schema schema;
if (database == null) {
schema = getDefaultSchema();
} else {
schema = findSchema(database.getSimpleName());
}
if (schema != null) {
for (String table : schema.showTables()) {
buf.append(table);
buf.append('\n');
}
}
} else {
stmt.accept(consoleVisitor);
}
}
if (buf.length() == 0) {
return "\n";
}
return buf.toString();
} catch (IOException ex) {
throw new FastsqlException("exeucte command error.", ex);
}
}
use of com.alibaba.druid.FastsqlException in project druid by alibaba.
the class SQLEvalVisitorUtils method eval.
public static Object eval(DbType dbType, SQLObject sqlObject, List<Object> parameters, boolean throwError) {
SQLEvalVisitor visitor = createEvalVisitor(dbType);
visitor.setParameters(parameters);
Object value;
if (sqlObject instanceof SQLValuableExpr) {
value = ((SQLValuableExpr) sqlObject).getValue();
} else {
sqlObject.accept(visitor);
value = getValue(sqlObject);
if (value == null) {
if (throwError && !sqlObject.containsAttribute(EVAL_VALUE)) {
throw new FastsqlException("eval error : " + SQLUtils.toSQLString(sqlObject, dbType));
}
}
}
return value;
}
use of com.alibaba.druid.FastsqlException in project druid by alibaba.
the class SQLDataTypeValidator method validate.
public void validate(SQLDataType x) {
long hash = x.nameHashCode64();
if (Arrays.binarySearch(supportTypeHashCodes, hash) < 0) {
String msg = "illegal dataType : " + x.getName();
final SQLObject parent = x.getParent();
if (parent instanceof SQLColumnDefinition) {
SQLColumnDefinition column = (SQLColumnDefinition) parent;
if (column.getName() != null) {
msg += ", column " + column.getName();
}
}
throw new FastsqlException(msg);
}
}
use of com.alibaba.druid.FastsqlException in project druid by alibaba.
the class CalciteMySqlNodeVisitor method buildIdentifier.
void buildIdentifier(SQLPropertyExpr x, List<String> names) {
String name = SQLUtils.normalize(x.getName());
SQLExpr owner = x.getOwner();
if (owner instanceof SQLIdentifierExpr) {
names.add(((SQLIdentifierExpr) owner).normalizedName());
} else if (owner instanceof SQLPropertyExpr) {
buildIdentifier((SQLPropertyExpr) owner, names);
} else {
throw new FastsqlException("not support : " + owner);
}
names.add(name);
}
Aggregations