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
28 #include "wine/debug.h"
29 #include "wine/unicode.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msi);
42 typedef struct tagMSIQUERY
51 UINT WINAPI MsiDatabaseIsTablePersistentA(
52 MSIHANDLE hDatabase, LPSTR szTableName)
54 FIXME("%lx %s\n", hDatabase, debugstr_a(szTableName));
55 return ERROR_CALL_NOT_IMPLEMENTED;
58 UINT WINAPI MsiDatabaseIsTablePersistentW(
59 MSIHANDLE hDatabase, LPWSTR szTableName)
61 FIXME("%lx %s\n", hDatabase, debugstr_w(szTableName));
62 return ERROR_CALL_NOT_IMPLEMENTED;
65 void MSI_CloseView( MSIOBJECTHDR *arg )
67 MSIQUERY *query = (MSIQUERY*) arg;
69 if( query->view && query->view->ops->delete )
70 query->view->ops->delete( query->view );
71 msiobj_release( &query->db->hdr );
74 UINT VIEW_find_column( MSIVIEW *table, LPWSTR name, UINT *n )
79 r = table->ops->get_dimensions( table, NULL, &count );
80 if( r != ERROR_SUCCESS )
83 for( i=1; i<=count; i++ )
88 r = table->ops->get_column_info( table, i, &col_name, NULL );
89 if( r != ERROR_SUCCESS )
91 x = lstrcmpW( name, col_name );
92 HeapFree( GetProcessHeap(), 0, col_name );
100 return ERROR_INVALID_PARAMETER;
103 UINT WINAPI MsiDatabaseOpenViewA(MSIHANDLE hdb,
104 LPCSTR szQuery, MSIHANDLE *phView)
109 TRACE("%ld %s %p\n", hdb, debugstr_a(szQuery), phView);
113 UINT len = MultiByteToWideChar( CP_ACP, 0, szQuery, -1, NULL, 0 );
114 szwQuery = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
116 return ERROR_FUNCTION_FAILED;
117 MultiByteToWideChar( CP_ACP, 0, szQuery, -1, szwQuery, len );
122 r = MsiDatabaseOpenViewW( hdb, szwQuery, phView);
127 UINT MSI_DatabaseOpenViewW(MSIDATABASE *db,
128 LPCWSTR szQuery, MSIQUERY **pView)
133 TRACE("%s %p\n", debugstr_w(szQuery), pView);
136 return ERROR_INVALID_PARAMETER;
138 /* pre allocate a handle to hold a pointer to the view */
139 query = alloc_msiobject( MSIHANDLETYPE_VIEW, sizeof (MSIQUERY),
142 return ERROR_FUNCTION_FAILED;
144 msiobj_addref( &db->hdr );
149 r = MSI_ParseSQL( db, szQuery, &query->view );
150 if( r == ERROR_SUCCESS )
152 msiobj_addref( &query->hdr );
156 msiobj_release( &query->hdr );
160 UINT WINAPI MsiDatabaseOpenViewW(MSIHANDLE hdb,
161 LPCWSTR szQuery, MSIHANDLE *phView)
164 MSIQUERY *query = NULL;
167 TRACE("%s %p\n", debugstr_w(szQuery), phView);
169 db = msihandle2msiinfo( hdb, MSIHANDLETYPE_DATABASE );
171 return ERROR_INVALID_HANDLE;
173 ret = MSI_DatabaseOpenViewW( db, szQuery, &query );
174 if( ret == ERROR_SUCCESS )
176 *phView = alloc_msihandle( &query->hdr );
177 msiobj_release( &query->hdr );
179 msiobj_release( &db->hdr );
184 UINT MSI_ViewFetch(MSIQUERY *query, MSIRECORD **prec)
188 UINT row_count = 0, col_count = 0, i, ival, ret, type;
190 TRACE("%p %p\n", query, prec );
194 return ERROR_FUNCTION_FAILED;
196 ret = view->ops->get_dimensions( view, &row_count, &col_count );
200 return ERROR_INVALID_PARAMETER;
202 if( query->row >= row_count )
203 return ERROR_NO_MORE_ITEMS;
205 rec = MSI_CreateRecord( col_count );
207 return ERROR_FUNCTION_FAILED;
209 for( i=1; i<=col_count; i++ )
211 ret = view->ops->get_column_info( view, i, NULL, &type );
214 ERR("Error getting column type for %d\n", i );
217 if (( type != MSITYPE_BINARY) && (type != (MSITYPE_BINARY |
220 ret = view->ops->fetch_int( view, query->row, i, &ival );
223 ERR("Error fetching data for %d\n", i );
226 if( ! (type & MSITYPE_VALID ) )
227 ERR("Invalid type!\n");
229 /* check if it's nul (0) - if so, don't set anything */
233 if( type & MSITYPE_STRING )
237 sval = MSI_makestring( query->db, ival );
238 MSI_RecordSetStringW( rec, i, sval );
239 HeapFree( GetProcessHeap(), 0, sval );
243 if( (type & MSI_DATASIZEMASK) == 2 )
244 MSI_RecordSetInteger( rec, i, ival - (1<<15) );
246 MSI_RecordSetInteger( rec, i, ival - (1<<31) );
253 ret = view->ops->fetch_stream( view, query->row, i, &stm );
254 if( ( ret == ERROR_SUCCESS ) && stm )
256 MSI_RecordSetIStream( rec, i, stm );
257 IStream_Release( stm );
260 ERR("failed to get stream\n");
267 return ERROR_SUCCESS;
270 UINT WINAPI MsiViewFetch(MSIHANDLE hView, MSIHANDLE *record)
273 MSIRECORD *rec = NULL;
276 TRACE("%ld %p\n", hView, record);
278 query = msihandle2msiinfo( hView, MSIHANDLETYPE_VIEW );
280 return ERROR_INVALID_HANDLE;
281 ret = MSI_ViewFetch( query, &rec );
282 if( ret == ERROR_SUCCESS )
284 *record = alloc_msihandle( &rec->hdr );
285 msiobj_release( &rec->hdr );
287 msiobj_release( &query->hdr );
291 UINT MSI_ViewClose(MSIQUERY *query)
295 TRACE("%p\n", query );
299 return ERROR_FUNCTION_FAILED;
300 if( !view->ops->close )
301 return ERROR_FUNCTION_FAILED;
303 return view->ops->close( view );
306 UINT WINAPI MsiViewClose(MSIHANDLE hView)
311 TRACE("%ld\n", hView );
313 query = msihandle2msiinfo( hView, MSIHANDLETYPE_VIEW );
315 return ERROR_INVALID_HANDLE;
317 ret = MSI_ViewClose( query );
318 msiobj_release( &query->hdr );
322 UINT MSI_ViewExecute(MSIQUERY *query, MSIRECORD *rec )
326 TRACE("%p %p\n", query, rec);
330 return ERROR_FUNCTION_FAILED;
331 if( !view->ops->execute )
332 return ERROR_FUNCTION_FAILED;
335 return view->ops->execute( view, rec );
338 UINT WINAPI MsiViewExecute(MSIHANDLE hView, MSIHANDLE hRec)
341 MSIRECORD *rec = NULL;
344 TRACE("%ld %ld\n", hView, hRec);
346 query = msihandle2msiinfo( hView, MSIHANDLETYPE_VIEW );
348 return ERROR_INVALID_HANDLE;
352 rec = msihandle2msiinfo( hRec, MSIHANDLETYPE_RECORD );
355 ret = ERROR_INVALID_HANDLE;
360 ret = MSI_ViewExecute( query, rec );
363 msiobj_release( &query->hdr );
365 msiobj_release( &rec->hdr );
370 UINT WINAPI MsiViewGetColumnInfo(MSIHANDLE hView, MSICOLINFO info, MSIHANDLE *hRec)
375 UINT ret, i, count = 0, type;
378 TRACE("%ld %d %p\n", hView, info, hRec);
380 query = msihandle2msiinfo( hView, MSIHANDLETYPE_VIEW );
382 return ERROR_INVALID_HANDLE;
386 return ERROR_FUNCTION_FAILED;
388 if( !view->ops->get_dimensions )
389 return ERROR_FUNCTION_FAILED;
391 ret = view->ops->get_dimensions( view, NULL, &count );
395 return ERROR_INVALID_PARAMETER;
397 handle = MsiCreateRecord( count );
399 return ERROR_FUNCTION_FAILED;
401 for( i=0; i<count; i++ )
404 ret = view->ops->get_column_info( view, i+1, &name, &type );
405 if( ret != ERROR_SUCCESS )
407 MsiRecordSetStringW( handle, i+1, name );
408 HeapFree( GetProcessHeap(), 0, name );
413 return ERROR_SUCCESS;
416 UINT WINAPI MsiDatabaseApplyTransformA( MSIHANDLE hdb,
417 LPCSTR szTransformFile, int iErrorCond)
419 FIXME("%ld %s %d\n", hdb, debugstr_a(szTransformFile), iErrorCond);
420 return ERROR_CALL_NOT_IMPLEMENTED;
423 UINT WINAPI MsiDatabaseApplyTransformW( MSIHANDLE hdb,
424 LPCWSTR szTransformFile, int iErrorCond)
426 FIXME("%ld %s %d\n", hdb, debugstr_w(szTransformFile), iErrorCond);
427 return ERROR_CALL_NOT_IMPLEMENTED;
430 UINT WINAPI MsiDatabaseGenerateTransformA( MSIHANDLE hdb, MSIHANDLE hdbref,
431 LPCSTR szTransformFile, int iReserved1, int iReserved2 )
433 FIXME("%ld %ld %s %d %d\n", hdb, hdbref,
434 debugstr_a(szTransformFile), iReserved1, iReserved2);
435 return ERROR_CALL_NOT_IMPLEMENTED;
438 UINT WINAPI MsiDatabaseGenerateTransformW( MSIHANDLE hdb, MSIHANDLE hdbref,
439 LPCWSTR szTransformFile, int iReserved1, int iReserved2 )
441 FIXME("%ld %ld %s %d %d\n", hdb, hdbref,
442 debugstr_w(szTransformFile), iReserved1, iReserved2);
443 return ERROR_CALL_NOT_IMPLEMENTED;
446 UINT WINAPI MsiDatabaseCommit( MSIHANDLE hdb )
453 db = msihandle2msiinfo( hdb, MSIHANDLETYPE_DATABASE );
455 return ERROR_INVALID_HANDLE;
457 /* FIXME: lock the database */
459 r = MSI_CommitTables( db );
461 /* FIXME: unlock the database */
466 UINT WINAPI MsiDatabaseGetPrimaryKeysA(MSIHANDLE hdb,
467 LPCSTR table, MSIHANDLE* rec)
469 FIXME("%ld %s %p\n", hdb, debugstr_a(table), rec);
470 return ERROR_CALL_NOT_IMPLEMENTED;
473 UINT WINAPI MsiDatabaseGetPrimaryKeysW(MSIHANDLE hdb,
474 LPCWSTR table, MSIHANDLE* rec)
476 FIXME("%ld %s %p\n", hdb, debugstr_w(table), rec);
477 return ERROR_CALL_NOT_IMPLEMENTED;
480 UINT WINAPI MsiViewModify(MSIHANDLE hView, MSIMODIFY eModifyMode, MSIHANDLE
483 FIXME("%ld %x %ld\n",hView, eModifyMode, hRecord);
484 return ERROR_CALL_NOT_IMPLEMENTED;