msi: Validate database fields before inserting them.

This commit is contained in:
Mike McCormack 2006-08-31 17:06:20 +09:00 committed by Alexandre Julliard
parent 71d8f4ebf6
commit 533833b4e1
2 changed files with 36 additions and 8 deletions

View File

@ -1302,12 +1302,38 @@ static UINT msi_table_find_row( MSITABLEVIEW *tv, MSIRECORD *rec, UINT *row );
static UINT table_validate_new( MSITABLEVIEW *tv, MSIRECORD *rec )
{
UINT r, row;
UINT r, row, i;
/* check there's no null values where they're not allowed */
for( i = 0; i < tv->num_cols; i++ )
{
if ( tv->columns[i].type & MSITYPE_NULLABLE )
continue;
if ( tv->columns[i].type & MSITYPE_STRING )
{
LPCWSTR str;
str = MSI_RecordGetString( rec, i+1 );
if (str == NULL || str[0] == 0)
return ERROR_INVALID_DATA;
}
else
{
UINT n;
n = MSI_RecordGetInteger( rec, i+1 );
if (n == MSI_NULL_INTEGER)
return ERROR_INVALID_DATA;
}
}
/* check there's no duplicate keys */
r = msi_table_find_row( tv, rec, &row );
if (r != ERROR_SUCCESS)
return ERROR_SUCCESS;
return ERROR_INVALID_DATA;
if (r == ERROR_SUCCESS)
return ERROR_INVALID_DATA;
return ERROR_SUCCESS;
}
static UINT msi_table_modify_row( MSITABLEVIEW *tv, MSIRECORD *rec,
@ -1352,6 +1378,11 @@ static UINT TABLE_insert_row( struct tagMSIVIEW *view, MSIRECORD *rec )
TRACE("%p %p\n", tv, rec );
/* check that the key is unique - can we find a matching row? */
r = table_validate_new( tv, rec );
if( r != ERROR_SUCCESS )
return ERROR_FUNCTION_FAILED;
r = table_create_new_row( view, &row );
TRACE("insert_row returned %08x\n", r);
if( r != ERROR_SUCCESS )

View File

@ -1323,10 +1323,7 @@ static void test_markers(void)
MsiRecordSetString(rec, 3, "haha");
query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
r = run_query(hdb, rec, query);
todo_wine
{
ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
}
ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
/* try all markers */
MsiCloseHandle(rec);