From 56574c7c6e3c6674d4c821919592c4c9de206aa5 Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Mon, 4 Feb 2008 11:26:58 -0600 Subject: [PATCH] msi: Add tests for using single quotes in an INSERT query. --- dlls/msi/tests/db.c | 129 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/dlls/msi/tests/db.c b/dlls/msi/tests/db.c index 85b65d76301..e40e86756f5 100644 --- a/dlls/msi/tests/db.c +++ b/dlls/msi/tests/db.c @@ -5053,6 +5053,134 @@ static void test_deleterow() DeleteFileA(msifile); } +static const CHAR import_dat[] = "A\n" + "s72\n" + "Table\tA\n" + "This is a new 'string' ok\n"; + +static void test_quotes(void) +{ + MSIHANDLE hdb, hview, hrec; + const char *query; + char buf[MAX_PATH]; + UINT r; + DWORD size; + + DeleteFile(msifile); + + r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + + query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )"; + r = run_query(hdb, 0, query); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + + query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a 'string' ok' )"; + r = run_query(hdb, 0, query); + ok(r == ERROR_BAD_QUERY_SYNTAX, + "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r); + + query = "INSERT INTO `Table` ( `A` ) VALUES ( \"This is a 'string' ok\" )"; + r = run_query(hdb, 0, query); + ok(r == ERROR_BAD_QUERY_SYNTAX, + "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r); + + query = "INSERT INTO `Table` ( `A` ) VALUES ( \"test\" )"; + r = run_query(hdb, 0, query); + ok(r == ERROR_BAD_QUERY_SYNTAX, + "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r); + + query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a ''string'' ok' )"; + r = run_query(hdb, 0, query); + todo_wine + { + ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r); + } + + query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a '''string''' ok' )"; + r = run_query(hdb, 0, query); + ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r); + + query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \'string\' ok' )"; + r = run_query(hdb, 0, query); + ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r); + + query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \"string\" ok' )"; + r = run_query(hdb, 0, query); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + + query = "SELECT * FROM `Table`"; + r = MsiDatabaseOpenView(hdb, query, &hview); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + + r = MsiViewExecute(hview, 0); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + + r = MsiViewFetch(hview, &hrec); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + + size = MAX_PATH; + r = MsiRecordGetString(hrec, 1, buf, &size); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + todo_wine + { + ok(!lstrcmp(buf, "This is a \"string\" ok"), + "Expected \"This is a \"string\" ok\", got %s\n", buf); + } + + MsiCloseHandle(hrec); + + r = MsiViewFetch(hview, &hrec); + todo_wine + { + ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r); + } + + MsiCloseHandle(hview); + + write_file("import.idt", import_dat, (sizeof(import_dat) - 1) * sizeof(char)); + + r = MsiDatabaseImportA(hdb, CURR_DIR, "import.idt"); + todo_wine + { + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + } + + DeleteFileA("import.idt"); + + query = "SELECT * FROM `Table`"; + r = MsiDatabaseOpenView(hdb, query, &hview); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + + r = MsiViewExecute(hview, 0); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + + r = MsiViewFetch(hview, &hrec); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + + size = MAX_PATH; + r = MsiRecordGetString(hrec, 1, buf, &size); + ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); + todo_wine + { + ok(!lstrcmp(buf, "This is a new 'string' ok"), + "Expected \"This is a new 'string' ok\", got %s\n", buf); + } + + MsiCloseHandle(hrec); + + r = MsiViewFetch(hview, &hrec); + todo_wine + { + ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r); + } + + MsiCloseHandle(hview); + + MsiCloseHandle(hdb); + DeleteFileA(msifile); +} + START_TEST(db) { test_msidatabase(); @@ -5084,4 +5212,5 @@ START_TEST(db) test_order(); test_viewmodify_delete_temporary(); test_deleterow(); + test_quotes(); }