Skip to content

Commit fcb33d4

Browse files
committed
fix db filesystem file read for mssql
1 parent 1f30d4d commit fcb33d4

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/filesystem.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub(crate) struct DbFsQueries {
148148
impl DbFsQueries {
149149
fn get_create_table_sql(db_kind: AnyKind) -> &'static str {
150150
match db_kind {
151-
AnyKind::Mssql => "CREATE TABLE sqlpage_files(path NVARCHAR(255) NOT NULL PRIMARY KEY, contents TEXT, last_modified DATETIME2(3) NOT NULL DEFAULT CURRENT_TIMESTAMP);",
151+
AnyKind::Mssql => "CREATE TABLE sqlpage_files(path NVARCHAR(255) NOT NULL PRIMARY KEY, contents VARBINARY(MAX), last_modified DATETIME2(3) NOT NULL DEFAULT CURRENT_TIMESTAMP);",
152152
_ => "CREATE TABLE IF NOT EXISTS sqlpage_files(path VARCHAR(255) NOT NULL PRIMARY KEY, contents BLOB, last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP);",
153153
}
154154
}
@@ -183,7 +183,7 @@ impl DbFsQueries {
183183
db_kind: AnyKind,
184184
) -> anyhow::Result<AnyStatement<'static>> {
185185
let was_modified_query = format!(
186-
"SELECT contents from sqlpage_files WHERE path = {} LIMIT 1",
186+
"SELECT contents from sqlpage_files WHERE path = {}",
187187
make_placeholder(db_kind, 1),
188188
);
189189
let param_types: &[AnyTypeInfo; 1] = &[<str as Type<Postgres>>::type_info().into()];
@@ -240,11 +240,21 @@ async fn test_sql_file_read_utf8() -> anyhow::Result<()> {
240240
state
241241
.db
242242
.connection
243-
.execute(format!(
244-
"{create_table_sql}
245-
INSERT INTO sqlpage_files(path, contents) VALUES ('unit test file.txt', 'Héllö world! 😀');
246-
").as_str())
243+
.execute(format!("DROP TABLE IF EXISTS sqlpage_files; {create_table_sql}").as_str())
247244
.await?;
245+
246+
let db_kind = state.db.connection.any_kind();
247+
let insert_sql = format!(
248+
"INSERT INTO sqlpage_files(path, contents) VALUES ({}, {})",
249+
make_placeholder(db_kind, 1),
250+
make_placeholder(db_kind, 2)
251+
);
252+
sqlx::query(&insert_sql)
253+
.bind("unit test file.txt")
254+
.bind("Héllö world! 😀".as_bytes())
255+
.execute(&state.db.connection)
256+
.await?;
257+
248258
let fs = FileSystem::init("/", &state.db).await;
249259
let actual = fs
250260
.read_to_string(&state, "unit test file.txt".as_ref(), false)

0 commit comments

Comments
 (0)