2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002-2004 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msi);
39 /* below is the query interface to a table */
41 typedef struct tagMSICREATEVIEW
47 column_info *col_info;
50 static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
52 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
54 TRACE("%p %d %d %p\n", cv, row, col, val );
56 return ERROR_FUNCTION_FAILED;
59 static UINT CREATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
61 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
64 static const WCHAR szTables[] = { '_','T','a','b','l','e','s',0 };
65 static const WCHAR szColumns[] = { '_','C','o','l','u','m','n','s',0 };
69 TRACE("%p Table %s (%s)\n", cv, debugstr_w(cv->name),
70 cv->bIsTemp?"temporary":"permanent");
72 /* only add tables that don't exist already */
73 if( TABLE_Exists(cv->db, cv->name ) )
74 return ERROR_BAD_QUERY_SYNTAX;
76 r = TABLE_CreateView( cv->db, szTables, &tv );
77 TRACE("CreateView returned %x\n", r);
81 r = tv->ops->execute( tv, 0 );
82 TRACE("tv execute returned %x\n", r);
86 rec = MSI_CreateRecord( 1 );
90 r = MSI_RecordSetStringW( rec, 1, cv->name );
94 r = tv->ops->insert_row( tv, rec );
95 TRACE("insert_row returned %x\n", r);
99 tv->ops->delete( tv );
102 msiobj_release( &rec->hdr );
104 /* add each column to the _Columns table */
105 r = TABLE_CreateView( cv->db, szColumns, &tv );
109 r = tv->ops->execute( tv, 0 );
110 TRACE("tv execute returned %x\n", r);
114 rec = MSI_CreateRecord( 4 );
118 r = MSI_RecordSetStringW( rec, 1, cv->name );
123 * need to set the table, column number, col name and type
124 * for each column we enter in the table
127 for( col = cv->col_info; col; col = col->next )
129 r = MSI_RecordSetInteger( rec, 2, nField );
133 r = MSI_RecordSetStringW( rec, 3, col->column );
137 r = MSI_RecordSetInteger( rec, 4, col->type );
141 r = tv->ops->insert_row( tv, rec );
151 /* FIXME: remove values from the string table on error */
153 tv->ops->delete( tv );
157 static UINT CREATE_close( struct tagMSIVIEW *view )
159 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
163 return ERROR_SUCCESS;
166 static UINT CREATE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
168 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
170 TRACE("%p %p %p\n", cv, rows, cols );
172 return ERROR_FUNCTION_FAILED;
175 static UINT CREATE_get_column_info( struct tagMSIVIEW *view,
176 UINT n, LPWSTR *name, UINT *type )
178 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
180 TRACE("%p %d %p %p\n", cv, n, name, type );
182 return ERROR_FUNCTION_FAILED;
185 static UINT CREATE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
188 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
190 TRACE("%p %d %p\n", cv, eModifyMode, rec );
192 return ERROR_FUNCTION_FAILED;
195 static UINT CREATE_delete( struct tagMSIVIEW *view )
197 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
201 msiobj_release( &cv->db->hdr );
202 HeapFree( GetProcessHeap(), 0, cv );
204 return ERROR_SUCCESS;
208 MSIVIEWOPS create_ops =
216 CREATE_get_dimensions,
217 CREATE_get_column_info,
222 UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
223 column_info *col_info, BOOL temp )
225 MSICREATEVIEW *cv = NULL;
229 cv = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof *cv );
231 return ERROR_FUNCTION_FAILED;
233 /* fill the structure */
234 cv->view.ops = &create_ops;
235 msiobj_addref( &db->hdr );
238 cv->col_info = col_info;
240 *view = (MSIVIEW*) cv;
242 return ERROR_SUCCESS;