use of com.actiontech.dble.plan.common.ptr.StringPtr in project dble by actiontech.
the class ItemFuncDateFormat method valStr.
@Override
public String valStr() {
String format;
MySQLTime lTime = new MySQLTime();
int size;
if (!isTimeFormat) {
if (getArg0Date(lTime, MyTime.TIME_FUZZY_DATE))
return null;
} else {
if (getArg0Time(lTime))
return null;
lTime.setDay(0);
lTime.setMonth(0);
lTime.setYear(0);
}
if ((format = args.get(1).valStr()) == null || format.length() == 0) {
nullValue = true;
return null;
}
size = formatLength(format);
if (size < MyTime.MAX_DATE_STRING_REP_LENGTH)
size = MyTime.MAX_DATE_STRING_REP_LENGTH;
DateTimeFormat dateTimeFormat = new DateTimeFormat();
dateTimeFormat.setFormat(format);
StringPtr strPtr = new StringPtr("");
if (!MyTime.makeDateTime(dateTimeFormat, lTime, isTimeFormat ? MySQLTimestampType.MYSQL_TIMESTAMP_TIME : MySQLTimestampType.MYSQL_TIMESTAMP_DATE, strPtr)) {
return strPtr.get();
}
nullValue = true;
return null;
}
use of com.actiontech.dble.plan.common.ptr.StringPtr in project dble by actiontech.
the class DruidDeleteParser method visitorParse.
@Override
public SchemaConfig visitorParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt, ServerSchemaStatVisitor visitor, ServerConnection sc) throws SQLException {
String schemaName = schema == null ? null : schema.getName();
MySqlDeleteStatement delete = (MySqlDeleteStatement) stmt;
SQLTableSource tableSource = delete.getTableSource();
SQLTableSource fromSource = delete.getFrom();
if (fromSource != null) {
tableSource = fromSource;
}
if (tableSource instanceof SQLJoinTableSource) {
StringPtr sqlSchema = new StringPtr(null);
if (!SchemaUtil.isNoSharding(sc, (SQLJoinTableSource) tableSource, stmt, schemaName, sqlSchema)) {
String msg = "DELETE query with multiple tables is not supported, sql:" + stmt;
throw new SQLNonTransientException(msg);
} else {
if (delete.getWhere() != null && !SchemaUtil.isNoSharding(sc, delete.getWhere(), schemaName, sqlSchema)) {
String msg = "DELETE query with sub-query is not supported, sql:" + stmt;
throw new SQLNonTransientException(msg);
}
String realSchema = sqlSchema.get() == null ? schemaName : sqlSchema.get();
SchemaConfig schemaConfig = DbleServer.getInstance().getConfig().getSchemas().get(realSchema);
rrs.setStatement(RouterUtil.removeSchema(rrs.getStatement(), realSchema));
RouterUtil.routeToSingleNode(rrs, schemaConfig.getDataNode());
rrs.setFinishedRoute(true);
return schema;
}
} else {
SQLExprTableSource deleteTableSource = (SQLExprTableSource) tableSource;
SchemaInfo schemaInfo = SchemaUtil.getSchemaInfo(sc.getUser(), schemaName, deleteTableSource);
if (!ServerPrivileges.checkPrivilege(sc, schemaInfo.getSchema(), schemaInfo.getTable(), CheckType.DELETE)) {
String msg = "The statement DML privilege check is not passed, sql:" + stmt;
throw new SQLNonTransientException(msg);
}
schema = schemaInfo.getSchemaConfig();
rrs.setStatement(RouterUtil.removeSchema(rrs.getStatement(), schemaInfo.getSchema()));
if (RouterUtil.isNoSharding(schema, schemaInfo.getTable())) {
if (delete.getWhere() != null && !SchemaUtil.isNoSharding(sc, delete.getWhere(), schemaName, new StringPtr(schemaInfo.getSchema()))) {
String msg = "DELETE query with sub-query is not supported, sql:" + stmt;
throw new SQLNonTransientException(msg);
}
RouterUtil.routeToSingleNode(rrs, schema.getDataNode());
return schema;
}
super.visitorParse(schema, rrs, stmt, visitor, sc);
if (visitor.isHasSubQuery()) {
String msg = "DELETE query with sub-query is not supported, sql:" + stmt;
throw new SQLNonTransientException(msg);
}
TableConfig tc = schema.getTables().get(schemaInfo.getTable());
if (tc != null && tc.isGlobalTable()) {
RouterUtil.routeToMultiNode(false, rrs, tc.getDataNodes(), tc.isGlobalTable());
rrs.setFinishedRoute(true);
return schema;
}
}
return schema;
}
use of com.actiontech.dble.plan.common.ptr.StringPtr in project dble by actiontech.
the class DruidUpdateParser method visitorParse.
public SchemaConfig visitorParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt, ServerSchemaStatVisitor visitor, ServerConnection sc) throws SQLException {
MySqlUpdateStatement update = (MySqlUpdateStatement) stmt;
SQLTableSource tableSource = update.getTableSource();
String schemaName = schema == null ? null : schema.getName();
if (tableSource instanceof SQLJoinTableSource) {
StringPtr sqlSchema = new StringPtr(null);
if (!SchemaUtil.isNoSharding(sc, (SQLJoinTableSource) tableSource, stmt, schemaName, sqlSchema)) {
String msg = "UPDATE query with multiple tables is not supported, sql:" + stmt;
throw new SQLNonTransientException(msg);
} else {
if (update.getWhere() != null && !SchemaUtil.isNoSharding(sc, update.getWhere(), schemaName, sqlSchema)) {
String msg = "UPDATE query with sub-query is not supported, sql:" + stmt;
throw new SQLNonTransientException(msg);
}
String realSchema = sqlSchema.get() == null ? schemaName : sqlSchema.get();
SchemaConfig schemaConfig = DbleServer.getInstance().getConfig().getSchemas().get(realSchema);
rrs.setStatement(RouterUtil.removeSchema(rrs.getStatement(), realSchema));
RouterUtil.routeToSingleNode(rrs, schemaConfig.getDataNode());
rrs.setFinishedRoute(true);
return schema;
}
} else {
SchemaInfo schemaInfo = SchemaUtil.getSchemaInfo(sc.getUser(), schemaName, (SQLExprTableSource) tableSource);
if (!ServerPrivileges.checkPrivilege(sc, schemaInfo.getSchema(), schemaInfo.getTable(), ServerPrivileges.CheckType.UPDATE)) {
String msg = "The statement DML privilege check is not passed, sql:" + stmt;
throw new SQLNonTransientException(msg);
}
schema = schemaInfo.getSchemaConfig();
String tableName = schemaInfo.getTable();
rrs.setStatement(RouterUtil.removeSchema(rrs.getStatement(), schemaInfo.getSchema()));
if (RouterUtil.isNoSharding(schema, tableName)) {
if (update.getWhere() != null && !SchemaUtil.isNoSharding(sc, update.getWhere(), schemaName, new StringPtr(schemaInfo.getSchema()))) {
String msg = "UPDATE query with sub-query is not supported, sql:" + stmt;
throw new SQLNonTransientException(msg);
}
RouterUtil.routeToSingleNode(rrs, schema.getDataNode());
rrs.setFinishedRoute(true);
return schema;
}
super.visitorParse(schema, rrs, stmt, visitor, sc);
if (visitor.isHasSubQuery()) {
String msg = "UPDATE query with sub-query is not supported, sql:" + stmt;
throw new SQLNonTransientException(msg);
}
TableConfig tc = schema.getTables().get(tableName);
if (tc.isGlobalTable()) {
if (GlobalTableUtil.useGlobalTableCheck()) {
String sql = convertUpdateSQL(schemaInfo, update, rrs.getStatement());
rrs.setStatement(sql);
}
RouterUtil.routeToMultiNode(false, rrs, tc.getDataNodes(), tc.isGlobalTable());
rrs.setFinishedRoute(true);
return schema;
}
String partitionColumn = tc.getPartitionColumn();
String joinKey = tc.getJoinKey();
confirmShardColumnNotUpdated(update, schema, tableName, partitionColumn, joinKey, rrs);
confirmChildColumnNotUpdated(update, schema, tableName);
if (schema.getTables().get(tableName).isGlobalTable() && ctx.getRouteCalculateUnit().getTablesAndConditions().size() > 1) {
throw new SQLNonTransientException("global table is not supported in multi table related update " + tableName);
}
if (ctx.getTables().size() == 0) {
ctx.addTable(schemaInfo.getTable());
}
}
return schema;
}
use of com.actiontech.dble.plan.common.ptr.StringPtr in project dble by actiontech.
the class MyTime method myDatetimeToStr.
/**
* Print a datetime value with an optional fractional part.
*
* @return The length of the result string.
* @l_time The MYSQL_TIME value to print.
* @to OUT The string pointer to print at.
*/
public static String myDatetimeToStr(final MySQLTime lTime, long dec) {
StringPtr ptrtmp = new StringPtr("");
timeToDatetimeStr(ptrtmp, lTime);
String res = ptrtmp.get();
if (dec != 0) {
// TODO: 6 digits after Decimal point
// String stmp = String.format("%06d", l_time.second_part);
// res += "." + stmp.substring(0, (int) dec);
}
return res;
}
Aggregations