mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
fix rep check clone error
This commit is contained in:
@@ -60,7 +60,7 @@ public class SQLCheck extends SQLConstraintImpl implements SQLTableElement, SQLT
|
||||
super.cloneTo(x);
|
||||
|
||||
if (expr != null) {
|
||||
expr = expr.clone();
|
||||
x.expr = expr.clone();
|
||||
}
|
||||
|
||||
x.enforced = enforced;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.alibaba.druid.bvt.sql.mysql;
|
||||
|
||||
import com.alibaba.druid.sql.repository.Schema;
|
||||
import com.alibaba.druid.sql.repository.SchemaObject;
|
||||
import com.alibaba.druid.sql.repository.SchemaRepository;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MySqlRepCheckTest {
|
||||
final private SchemaRepository repository = new SchemaRepository(JdbcUtils.MYSQL);
|
||||
|
||||
public static void main(String[] args) {
|
||||
MySqlRepCheckTest testRep = new MySqlRepCheckTest();
|
||||
String schemaName = "test_db";
|
||||
testRep.repository.setDefaultSchema(schemaName);
|
||||
testRep.repository.console("CREATE TABLE `test_table` (\n" +
|
||||
" `id` int NOT NULL AUTO_INCREMENT,\n" +
|
||||
" `action_flag` smallint unsigned NOT NULL,\n" +
|
||||
" CONSTRAINT `chk_1` CHECK ((`action_flag` >= 0))\n" +
|
||||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci");
|
||||
Map<String, String> snapshot = testRep.snapshot();
|
||||
System.out.println(snapshot.get(schemaName));
|
||||
}
|
||||
|
||||
public Map<String, String> snapshot() {
|
||||
Map<String, String> schemaDdls = new HashMap<String, String>();
|
||||
for (Schema schema : repository.getSchemas()) {
|
||||
StringBuffer data = new StringBuffer(4 * 1024);
|
||||
for (String table : schema.showTables()) {
|
||||
SchemaObject schemaObject = schema.findTable(table);
|
||||
schemaObject.getStatement().output(data);
|
||||
data.append("; \n");
|
||||
}
|
||||
schemaDdls.put(schema.getName(), data.toString());
|
||||
}
|
||||
|
||||
return schemaDdls;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user