Rob Shearman : msi: Move table creation to table.c.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Apr 24 07:24:02 CDT 2007


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

Author: Rob Shearman <rob at codeweavers.com>
Date:   Mon Apr 23 08:21:32 2007 +0100

msi: Move table creation to table.c.

---

 dlls/msi/create.c |   93 +------------------------------------------------
 dlls/msi/query.h  |    3 ++
 dlls/msi/table.c  |  100 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 105 insertions(+), 91 deletions(-)

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 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 )
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 *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 */
diff --git a/dlls/msi/table.c b/dlls/msi/table.c
index e414517..dbc292d 100644
--- a/dlls/msi/table.c
+++ b/dlls/msi/table.c
@@ -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;




More information about the wine-cvs mailing list