Mike McCormack : msi: Check that column names are unique when creating a table.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Sep 7 05:07:07 CDT 2006


Module: wine
Branch: master
Commit: 2924501a6807803fd145f8e52b96fede3d84fa6a
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=2924501a6807803fd145f8e52b96fede3d84fa6a

Author: Mike McCormack <mike at codeweavers.com>
Date:   Thu Aug 31 17:04:40 2006 +0900

msi: Check that column names are unique when creating a table.

---

 dlls/msi/create.c   |   20 +++++++++++++++++++-
 dlls/msi/tests/db.c |   15 +++++++++++----
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/dlls/msi/create.c b/dlls/msi/create.c
index a8fe65c..740f563 100644
--- a/dlls/msi/create.c
+++ b/dlls/msi/create.c
@@ -221,17 +221,35 @@ static const MSIVIEWOPS create_ops =
     CREATE_delete
 };
 
+static UINT check_columns( column_info *col_info )
+{
+    column_info *c1, *c2;
+
+    /* check for two columns with the same name */
+    for( c1 = col_info; c1; c1 = c1->next )
+        for( c2 = c1->next; c2; c2 = c2->next )
+            if (!lstrcmpW(c1->column, c2->column))
+                return ERROR_BAD_QUERY_SYNTAX;
+
+    return ERROR_SUCCESS;
+}
+
 UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
                         column_info *col_info, BOOL temp )
 {
     MSICREATEVIEW *cv = NULL;
+    UINT r;
 
     TRACE("%p\n", cv );
 
+    r = check_columns( col_info );
+    if( r != ERROR_SUCCESS )
+        return r;
+
     cv = msi_alloc_zero( sizeof *cv );
     if( !cv )
         return ERROR_FUNCTION_FAILED;
-    
+
     /* fill the structure */
     cv->view.ops = &create_ops;
     msiobj_addref( &db->hdr );
diff --git a/dlls/msi/tests/db.c b/dlls/msi/tests/db.c
index 6b5336d..c8d42f9 100644
--- a/dlls/msi/tests/db.c
+++ b/dlls/msi/tests/db.c
@@ -1203,6 +1203,13 @@ static void test_markers(void)
     r = run_query(hdb, rec, query);
     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
 
+    /* verify that we just created a table called '?', not 'Fable' */
+    r = try_query(hdb, "SELECT * from `Fable`");
+    ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
+
+    r = try_query(hdb, "SELECT * from `?`");
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
+
     /* try table name as marker without backticks */
     MsiRecordSetString(rec, 1, "Mable");
     query = "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
@@ -1232,10 +1239,7 @@ static void test_markers(void)
     MsiRecordSetString(rec, 3, "One");
     query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
     r = run_query(hdb, rec, query);
-    todo_wine
-    {
-        ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
-    }
+    ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
 
     /* try names with backticks, minus definitions */
     query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
@@ -1271,6 +1275,9 @@ static void test_markers(void)
     r = run_query(hdb, 0, query);
     ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
 
+    r = try_query(hdb, "SELECT * from `Table`");
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
+
     /* try values as markers */
     MsiCloseHandle(rec);
     rec = MsiCreateRecord(2);




More information about the wine-cvs mailing list