[PATCH 6/13] msi: Move table creation to table.c.

Robert Shearman rob at codeweavers.com
Mon Apr 23 02:21:32 CDT 2007


---
  dlls/msi/create.c  |   93 +----------------------------------------------
  dlls/msi/msipriv.h |    2 +
  dlls/msi/query.h   |    3 ++
  dlls/msi/table.c   |  102 
+++++++++++++++++++++++++++++++++++++++++++++++++++-
  4 files changed, 107 insertions(+), 93 deletions(-)
-------------- next part --------------
diff --git a/dlls/msi/create.c b/dlls/msi/create.c
index 740f563..ef71684 100644
--- a/dlls/msi/create.c
+++ b/dlls/msi/create.c
@@ -59,101 +59,12 @@ static UINT CREATE_fetch_int( struct tag
 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 )
diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h
index a6554e6..53cd432 100644
--- a/dlls/msi/msipriv.h
+++ b/dlls/msi/msipriv.h
@@ -564,7 +564,7 @@ extern string_table *msi_load_string_tab
 extern UINT msi_save_string_table( string_table *st, IStorage *storage );
 
 
-extern BOOL TABLE_Exists( MSIDATABASE *db, LPWSTR name );
+extern BOOL TABLE_Exists( MSIDATABASE *db, LPCWSTR name );
 extern MSICONDITION MSI_DatabaseIsTablePersistent( MSIDATABASE *db, LPCWSTR table );
 
 extern UINT read_raw_stream_data( MSIDATABASE*, LPCWSTR stname,
diff --git a/dlls/msi/query.h b/dlls/msi/query.h
index 86773ad..a8a633f 100644
--- a/dlls/msi/query.h
+++ b/dlls/msi/query.h
@@ -127,4 +127,7 @@ int sqliteGetToken(const WCHAR *z, int *
 
 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 */
diff --git a/dlls/msi/table.c b/dlls/msi/table.c
index 17f5b24..49ab2f0 100644
--- a/dlls/msi/table.c
+++ b/dlls/msi/table.c
@@ -593,6 +593,106 @@ static UINT table_get_column_info( MSIDA
     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;
@@ -843,7 +943,7 @@ static UINT get_tablecolumns( MSIDATABAS
 }
 
 /* try to find the table name in the _Tables table */
-BOOL TABLE_Exists( MSIDATABASE *db, LPWSTR name )
+BOOL TABLE_Exists( MSIDATABASE *db, LPCWSTR name )
 {
     UINT r, table_id = 0, i, count;
     MSITABLE *table = NULL;


More information about the wine-patches mailing list