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

This commit is contained in:
Mike McCormack 2006-08-31 17:04:40 +09:00 committed by Alexandre Julliard
parent bd9891ffed
commit 2924501a68
2 changed files with 30 additions and 5 deletions

View File

@ -221,17 +221,35 @@ static const MSIVIEWOPS create_ops =
CREATE_delete 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, UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
column_info *col_info, BOOL temp ) column_info *col_info, BOOL temp )
{ {
MSICREATEVIEW *cv = NULL; MSICREATEVIEW *cv = NULL;
UINT r;
TRACE("%p\n", cv ); TRACE("%p\n", cv );
r = check_columns( col_info );
if( r != ERROR_SUCCESS )
return r;
cv = msi_alloc_zero( sizeof *cv ); cv = msi_alloc_zero( sizeof *cv );
if( !cv ) if( !cv )
return ERROR_FUNCTION_FAILED; return ERROR_FUNCTION_FAILED;
/* fill the structure */ /* fill the structure */
cv->view.ops = &create_ops; cv->view.ops = &create_ops;
msiobj_addref( &db->hdr ); msiobj_addref( &db->hdr );

View File

@ -1203,6 +1203,13 @@ static void test_markers(void)
r = run_query(hdb, rec, query); r = run_query(hdb, rec, query);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); 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 */ /* try table name as marker without backticks */
MsiRecordSetString(rec, 1, "Mable"); MsiRecordSetString(rec, 1, "Mable");
query = "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)"; 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"); MsiRecordSetString(rec, 3, "One");
query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)"; query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
r = run_query(hdb, rec, query); 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 */ /* try names with backticks, minus definitions */
query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)"; query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
@ -1271,6 +1275,9 @@ static void test_markers(void)
r = run_query(hdb, 0, query); r = run_query(hdb, 0, query);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r); 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 */ /* try values as markers */
MsiCloseHandle(rec); MsiCloseHandle(rec);
rec = MsiCreateRecord(2); rec = MsiCreateRecord(2);