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 create_col_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
;
63 UINT r
, nField
, row
, table_val
, column_val
;
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 };
68 TRACE("%p Table %s (%s)\n", cv
, debugstr_w(cv
->name
),
69 cv
->bIsTemp
?"temporary":"permanent");
71 /* only add tables that don't exist already */
72 if( TABLE_Exists(cv
->db
, cv
->name
) )
73 return ERROR_BAD_QUERY_SYNTAX
;
75 /* add the name to the _Tables table */
76 table_val
= msi_addstringW( cv
->db
->strings
, 0, cv
->name
, -1, 1 );
77 TRACE("New string %s -> %d\n", debugstr_w( cv
->name
), table_val
);
79 return ERROR_FUNCTION_FAILED
;
81 r
= TABLE_CreateView( cv
->db
, szTables
, &tv
);
82 TRACE("CreateView returned %x\n", r
);
86 r
= tv
->ops
->execute( tv
, 0 );
87 TRACE("tv execute returned %x\n", r
);
92 r
= tv
->ops
->insert_row( tv
, &row
);
93 TRACE("insert_row returned %x\n", r
);
97 r
= tv
->ops
->set_int( tv
, row
, 1, table_val
);
100 tv
->ops
->delete( tv
);
103 /* add each column to the _Columns table */
104 r
= TABLE_CreateView( cv
->db
, szColumns
, &tv
);
108 r
= tv
->ops
->execute( tv
, 0 );
109 TRACE("tv execute returned %x\n", r
);
114 * need to set the table, column number, col name and type
115 * for each column we enter in the table
118 for( col
= cv
->col_info
; col
; col
= col
->next
)
121 r
= tv
->ops
->insert_row( tv
, &row
);
125 column_val
= msi_addstringW( cv
->db
->strings
, 0, col
->colname
, -1, 1 );
126 TRACE("New string %s -> %d\n", debugstr_w( col
->colname
), column_val
);
130 /* add the string again here so we increase the reference count */
131 table_val
= msi_addstringW( cv
->db
->strings
, 0, cv
->name
, -1, 1 );
135 r
= tv
->ops
->set_int( tv
, row
, 1, table_val
);
139 r
= tv
->ops
->set_int( tv
, row
, 2, 0x8000|nField
);
143 r
= tv
->ops
->set_int( tv
, row
, 3, column_val
);
147 r
= tv
->ops
->set_int( tv
, row
, 4, 0x8000|col
->type
);
157 /* FIXME: remove values from the string table on error */
159 tv
->ops
->delete( tv
);
163 static UINT
CREATE_close( struct tagMSIVIEW
*view
)
165 MSICREATEVIEW
*cv
= (MSICREATEVIEW
*)view
;
169 return ERROR_SUCCESS
;
172 static UINT
CREATE_get_dimensions( struct tagMSIVIEW
*view
, UINT
*rows
, UINT
*cols
)
174 MSICREATEVIEW
*cv
= (MSICREATEVIEW
*)view
;
176 TRACE("%p %p %p\n", cv
, rows
, cols
);
178 return ERROR_FUNCTION_FAILED
;
181 static UINT
CREATE_get_column_info( struct tagMSIVIEW
*view
,
182 UINT n
, LPWSTR
*name
, UINT
*type
)
184 MSICREATEVIEW
*cv
= (MSICREATEVIEW
*)view
;
186 TRACE("%p %d %p %p\n", cv
, n
, name
, type
);
188 return ERROR_FUNCTION_FAILED
;
191 static UINT
CREATE_modify( struct tagMSIVIEW
*view
, MSIMODIFY eModifyMode
, MSIHANDLE hrec
)
193 MSICREATEVIEW
*cv
= (MSICREATEVIEW
*)view
;
195 TRACE("%p %d %ld\n", cv
, eModifyMode
, hrec
);
197 return ERROR_FUNCTION_FAILED
;
200 static UINT
CREATE_delete( struct tagMSIVIEW
*view
)
202 MSICREATEVIEW
*cv
= (MSICREATEVIEW
*)view
;
203 create_col_info
*col
;
210 create_col_info
*t
= col
;
212 HeapFree( GetProcessHeap(), 0, t
->colname
);
213 HeapFree( GetProcessHeap(), 0, t
);
215 HeapFree( GetProcessHeap(), 0, cv
->name
);
216 HeapFree( GetProcessHeap(), 0, cv
);
217 msiobj_release( &cv
->db
->hdr
);
219 return ERROR_SUCCESS
;
223 MSIVIEWOPS create_ops
=
231 CREATE_get_dimensions
,
232 CREATE_get_column_info
,
237 UINT
CREATE_CreateView( MSIDATABASE
*db
, MSIVIEW
**view
, LPWSTR table
,
238 create_col_info
*col_info
, BOOL temp
)
240 MSICREATEVIEW
*cv
= NULL
;
244 cv
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof *cv
);
246 return ERROR_FUNCTION_FAILED
;
248 /* fill the structure */
249 cv
->view
.ops
= &create_ops
;
250 msiobj_addref( &db
->hdr
);
252 cv
->name
= table
; /* FIXME: strdupW it? */
253 cv
->col_info
= col_info
;
255 *view
= (MSIVIEW
*) cv
;
257 return ERROR_SUCCESS
;