fix(sqlserver): preserve unicode import literals
This commit is contained in:
1 parent
8b473d5912
commit
24f67f0498
2 files changed
+45
No files matched your search
@@ -677,4 +677,34 @@ mod tests {
|
||||
row_count: 1,
|
||||
}]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_insert_batches_preserve_sqlserver_unicode_text() {
|
||||
let mappings =
|
||||
vec![TableImportColumnMapping { source_column: "name".to_string(), target_column: "name".to_string() }];
|
||||
let data = ParsedImportFile {
|
||||
columns: vec!["name".to_string()],
|
||||
rows: vec![vec![serde_json::json!("Tiếng Việt")]],
|
||||
total_rows: 1,
|
||||
};
|
||||
|
||||
let batches = build_import_insert_batches(
|
||||
&data,
|
||||
&mappings,
|
||||
&[("name".to_string(), "nvarchar(100)".to_string())],
|
||||
"customers",
|
||||
"dbo",
|
||||
&DatabaseType::SqlServer,
|
||||
500,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
batches,
|
||||
vec![ImportSqlBatch {
|
||||
sql: "INSERT INTO [dbo].[customers] ([name]) VALUES\n(N'Tiếng Việt')".to_string(),
|
||||
row_count: 1,
|
||||
}]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -639,6 +639,7 @@ pub fn escape_value_typed(val: &serde_json::Value, db_type: &DatabaseType, colum
|
||||
{
|
||||
format!("b'{escaped}'")
|
||||
}
|
||||
DatabaseType::SqlServer => format!("N'{escaped}'"),
|
||||
_ => format!("'{escaped}'"),
|
||||
}
|
||||
}
|
||||
@@ -4093,6 +4094,20 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sqlserver_insert_prefixes_string_literals_as_unicode() {
|
||||
let sql = generate_insert_typed(
|
||||
&[String::from("name"), String::from("note")],
|
||||
&[Some(String::from("nvarchar(100)")), Some(String::from("varchar(100)"))],
|
||||
&[vec![json!("Tiếng Việt"), json!("O'Brien")]],
|
||||
"customers",
|
||||
"dbo",
|
||||
&DatabaseType::SqlServer,
|
||||
);
|
||||
|
||||
assert_eq!(sql, "INSERT INTO [dbo].[customers] ([name], [note]) VALUES\n(N'Tiếng Việt', N'O''Brien')");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transfer_write_sql_batches_split_large_insert_statements() {
|
||||
let rows = (0..4).map(|index| vec![json!(index), json!("x".repeat(180 * 1024))]).collect::<Vec<_>>();
|
||||
|
||||
Reference in new issue
Block a user