Fix:修复 Kingbase 新增字段 SQL 语法 (#2180)
Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>
This commit is contained in:
1 parent
79feccc717
commit
ce72468e5a
2 files changed
+30
-1
No files matched your search
@@ -65,6 +65,7 @@ pub(super) fn build_column_sql(options: &TableStructureSqlOptions, warnings: &mu
|
||||
}
|
||||
statements.extend(build_add_column_sql(
|
||||
dialect,
|
||||
options.database_type,
|
||||
&table,
|
||||
column,
|
||||
&position_clause,
|
||||
@@ -200,6 +201,7 @@ pub(super) fn build_primary_key_sql(
|
||||
|
||||
pub(super) fn build_add_column_sql(
|
||||
dialect: StructureDialect,
|
||||
database_type: Option<crate::models::connection::DatabaseType>,
|
||||
table: &str,
|
||||
column: &EditableStructureColumn,
|
||||
position_clause: &str,
|
||||
@@ -210,7 +212,13 @@ pub(super) fn build_add_column_sql(
|
||||
let mut statements = if dialect == StructureDialect::Oracle || dialect == StructureDialect::Informix {
|
||||
vec![format!("ALTER TABLE {table} ADD ({definition});")]
|
||||
} else {
|
||||
let add_keyword = if dialect == StructureDialect::SqlServer { "ADD" } else { "ADD COLUMN" };
|
||||
let add_keyword = if dialect == StructureDialect::SqlServer
|
||||
|| database_type == Some(crate::models::connection::DatabaseType::Kingbase)
|
||||
{
|
||||
"ADD"
|
||||
} else {
|
||||
"ADD COLUMN"
|
||||
};
|
||||
vec![format!("ALTER TABLE {table} {add_keyword} {definition}{position_clause};")]
|
||||
};
|
||||
if matches!(dialect, StructureDialect::Postgres | StructureDialect::Oracle) && !clean(&column.comment).is_empty() {
|
||||
|
||||
@@ -802,6 +802,27 @@ fn builds_rqlite_changes_with_sqlite_dialect() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_kingbase_add_column_without_column_keyword() {
|
||||
let mut flag = column("flag");
|
||||
flag.data_type = "varchar(100)".to_string();
|
||||
|
||||
let result = build_table_structure_change_sql(TableStructureSqlOptions {
|
||||
database_type: Some(DatabaseType::Kingbase),
|
||||
schema: Some("dbo".to_string()),
|
||||
table_name: "dw_bill_info_copy".to_string(),
|
||||
columns: vec![flag],
|
||||
indexes: Vec::new(),
|
||||
foreign_keys: Vec::new(),
|
||||
triggers: Vec::new(),
|
||||
table_comment: None,
|
||||
original_table_comment: None,
|
||||
});
|
||||
|
||||
assert_eq!(result.warnings, Vec::<String>::new());
|
||||
assert_eq!(result.statements, vec!["ALTER TABLE \"dbo\".\"dw_bill_info_copy\" ADD \"flag\" varchar(100);"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_mysql_column_reorder_statements() {
|
||||
let mut id = column("id");
|
||||
|
||||
Reference in new issue
Block a user