Commit ba0507a1 authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

msi: Move table creation to table.c.

parent 3aa9a25c
......@@ -59,101 +59,12 @@ static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT
static UINT CREATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
{
MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
column_info *col;
UINT r, nField;
static const WCHAR szTables[] = { '_','T','a','b','l','e','s',0 };
static const WCHAR szColumns[] = { '_','C','o','l','u','m','n','s',0 };
MSIVIEW *tv = NULL;
MSIRECORD *rec = NULL;
MSITABLE *table;
TRACE("%p Table %s (%s)\n", cv, debugstr_w(cv->name),
cv->bIsTemp?"temporary":"permanent");
/* only add tables that don't exist already */
if( TABLE_Exists(cv->db, cv->name ) )
return ERROR_BAD_QUERY_SYNTAX;
r = TABLE_CreateView( cv->db, szTables, &tv );
TRACE("CreateView returned %x\n", r);
if( r )
return r;
r = tv->ops->execute( tv, 0 );
TRACE("tv execute returned %x\n", r);
if( r )
goto err;
rec = MSI_CreateRecord( 1 );
if( !rec )
goto err;
r = MSI_RecordSetStringW( rec, 1, cv->name );
if( r )
goto err;
r = tv->ops->insert_row( tv, rec );
TRACE("insert_row returned %x\n", r);
if( r )
goto err;
tv->ops->delete( tv );
tv = NULL;
msiobj_release( &rec->hdr );
/* add each column to the _Columns table */
r = TABLE_CreateView( cv->db, szColumns, &tv );
if( r )
return r;
r = tv->ops->execute( tv, 0 );
TRACE("tv execute returned %x\n", r);
if( r )
goto err;
rec = MSI_CreateRecord( 4 );
if( !rec )
goto err;
r = MSI_RecordSetStringW( rec, 1, cv->name );
if( r )
goto err;
/*
* need to set the table, column number, col name and type
* for each column we enter in the table
*/
nField = 1;
for( col = cv->col_info; col; col = col->next )
{
r = MSI_RecordSetInteger( rec, 2, nField );
if( r )
goto err;
r = MSI_RecordSetStringW( rec, 3, col->column );
if( r )
goto err;
r = MSI_RecordSetInteger( rec, 4, col->type );
if( r )
goto err;
r = tv->ops->insert_row( tv, rec );
if( r )
goto err;
nField++;
}
if( !col )
r = ERROR_SUCCESS;
err:
if (rec)
msiobj_release( &rec->hdr );
/* FIXME: remove values from the string table on error */
if( tv )
tv->ops->delete( tv );
return r;
return msi_create_table( cv->db, cv->name, cv->col_info, !cv->bIsTemp, &table);
}
static UINT CREATE_close( struct tagMSIVIEW *view )
......
......@@ -127,4 +127,7 @@ int sqliteGetToken(const WCHAR *z, int *tokenType);
MSIRECORD *msi_query_merge_record( UINT fields, column_info *vl, MSIRECORD *rec );
UINT msi_create_table( MSIDATABASE *db, LPCWSTR name, column_info *col_info,
BOOL persistent, MSITABLE **table_ret);
#endif /* __WINE_MSI_QUERY_H */
......@@ -593,6 +593,106 @@ static UINT table_get_column_info( MSIDATABASE *db, LPCWSTR name, MSICOLUMNINFO
return r;
}
static UINT get_table( MSIDATABASE *db, LPCWSTR name, MSITABLE **table_ret );
UINT msi_create_table( MSIDATABASE *db, LPCWSTR name, column_info *col_info,
BOOL persistent, MSITABLE **table_ret)
{
UINT r, nField;
MSIVIEW *tv = NULL;
MSIRECORD *rec = NULL;
column_info *col;
/* only add tables that don't exist already */
if( TABLE_Exists(db, name ) )
return ERROR_BAD_QUERY_SYNTAX;
r = TABLE_CreateView( db, szTables, &tv );
TRACE("CreateView returned %x\n", r);
if( r )
return r;
r = tv->ops->execute( tv, 0 );
TRACE("tv execute returned %x\n", r);
if( r )
goto err;
rec = MSI_CreateRecord( 1 );
if( !rec )
goto err;
r = MSI_RecordSetStringW( rec, 1, name );
if( r )
goto err;
r = tv->ops->insert_row( tv, rec );
TRACE("insert_row returned %x\n", r);
if( r )
goto err;
tv->ops->delete( tv );
tv = NULL;
msiobj_release( &rec->hdr );
/* add each column to the _Columns table */
r = TABLE_CreateView( db, szColumns, &tv );
if( r )
return r;
r = tv->ops->execute( tv, 0 );
TRACE("tv execute returned %x\n", r);
if( r )
goto err;
rec = MSI_CreateRecord( 4 );
if( !rec )
goto err;
r = MSI_RecordSetStringW( rec, 1, name );
if( r )
goto err;
/*
* need to set the table, column number, col name and type
* for each column we enter in the table
*/
nField = 1;
for( col = col_info; col; col = col->next )
{
r = MSI_RecordSetInteger( rec, 2, nField );
if( r )
goto err;
r = MSI_RecordSetStringW( rec, 3, col->column );
if( r )
goto err;
r = MSI_RecordSetInteger( rec, 4, col->type );
if( r )
goto err;
r = tv->ops->insert_row( tv, rec );
if( r )
goto err;
nField++;
}
if( !col )
r = ERROR_SUCCESS;
err:
if (rec)
msiobj_release( &rec->hdr );
/* FIXME: remove values from the string table on error */
if( tv )
tv->ops->delete( tv );
if (r == ERROR_SUCCESS)
r = get_table( db, name, table_ret );
return r;
}
static UINT get_table( MSIDATABASE *db, LPCWSTR name, MSITABLE **table_ret )
{
MSITABLE *table;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment