2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002-2005 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
29 #include "wine/unicode.h"
38 #include "msiserver.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
44 static void MSI_CloseView( MSIOBJECTHDR
*arg
)
46 MSIQUERY
*query
= (MSIQUERY
*) arg
;
49 if( query
->view
&& query
->view
->ops
->delete )
50 query
->view
->ops
->delete( query
->view
);
51 msiobj_release( &query
->db
->hdr
);
53 LIST_FOR_EACH_SAFE( ptr
, t
, &query
->mem
)
59 UINT
VIEW_find_column( MSIVIEW
*table
, LPCWSTR name
, LPCWSTR table_name
, UINT
*n
)
61 LPCWSTR col_name
, haystack_table_name
;
64 r
= table
->ops
->get_dimensions( table
, NULL
, &count
);
65 if( r
!= ERROR_SUCCESS
)
68 for( i
=1; i
<=count
; i
++ )
72 r
= table
->ops
->get_column_info( table
, i
, &col_name
, NULL
,
73 NULL
, &haystack_table_name
);
74 if( r
!= ERROR_SUCCESS
)
76 x
= strcmpW( name
, col_name
);
78 x
|= strcmpW( table_name
, haystack_table_name
);
85 return ERROR_INVALID_PARAMETER
;
88 UINT WINAPI
MsiDatabaseOpenViewA(MSIHANDLE hdb
,
89 LPCSTR szQuery
, MSIHANDLE
*phView
)
94 TRACE("%d %s %p\n", hdb
, debugstr_a(szQuery
), phView
);
98 szwQuery
= strdupAtoW( szQuery
);
100 return ERROR_FUNCTION_FAILED
;
105 r
= MsiDatabaseOpenViewW( hdb
, szwQuery
, phView
);
107 msi_free( szwQuery
);
111 UINT
MSI_DatabaseOpenViewW(MSIDATABASE
*db
,
112 LPCWSTR szQuery
, MSIQUERY
**pView
)
117 TRACE("%s %p\n", debugstr_w(szQuery
), pView
);
120 return ERROR_INVALID_PARAMETER
;
122 /* pre allocate a handle to hold a pointer to the view */
123 query
= alloc_msiobject( MSIHANDLETYPE_VIEW
, sizeof (MSIQUERY
),
126 return ERROR_FUNCTION_FAILED
;
128 msiobj_addref( &db
->hdr
);
130 list_init( &query
->mem
);
132 r
= MSI_ParseSQL( db
, szQuery
, &query
->view
, &query
->mem
);
133 if( r
== ERROR_SUCCESS
)
135 msiobj_addref( &query
->hdr
);
139 msiobj_release( &query
->hdr
);
143 UINT
MSI_OpenQuery( MSIDATABASE
*db
, MSIQUERY
**view
, LPCWSTR fmt
, ... )
149 /* construct the string */
153 query
= msi_alloc( size
*sizeof(WCHAR
) );
155 res
= vsnprintfW(query
, size
, fmt
, va
);
157 if (res
== -1) size
*= 2;
158 else if (res
>= size
) size
= res
+ 1;
162 /* perform the query */
163 r
= MSI_DatabaseOpenViewW(db
, query
, view
);
168 UINT
MSI_IterateRecords( MSIQUERY
*view
, LPDWORD count
,
169 record_func func
, LPVOID param
)
171 MSIRECORD
*rec
= NULL
;
172 UINT r
, n
= 0, max
= 0;
174 r
= MSI_ViewExecute( view
, NULL
);
175 if( r
!= ERROR_SUCCESS
)
181 /* iterate a query */
182 for( n
= 0; (max
== 0) || (n
< max
); n
++ )
184 r
= MSI_ViewFetch( view
, &rec
);
185 if( r
!= ERROR_SUCCESS
)
188 r
= func( rec
, param
);
189 msiobj_release( &rec
->hdr
);
190 if( r
!= ERROR_SUCCESS
)
194 MSI_ViewClose( view
);
199 if( r
== ERROR_NO_MORE_ITEMS
)
205 /* return a single record from a query */
206 MSIRECORD
*MSI_QueryGetRecord( MSIDATABASE
*db
, LPCWSTR fmt
, ... )
208 MSIRECORD
*rec
= NULL
;
209 MSIQUERY
*view
= NULL
;
214 /* construct the string */
218 query
= msi_alloc( size
*sizeof(WCHAR
) );
220 res
= vsnprintfW(query
, size
, fmt
, va
);
222 if (res
== -1) size
*= 2;
223 else if (res
>= size
) size
= res
+ 1;
227 /* perform the query */
228 r
= MSI_DatabaseOpenViewW(db
, query
, &view
);
231 if( r
== ERROR_SUCCESS
)
233 MSI_ViewExecute( view
, NULL
);
234 MSI_ViewFetch( view
, &rec
);
235 MSI_ViewClose( view
);
236 msiobj_release( &view
->hdr
);
241 UINT WINAPI
MsiDatabaseOpenViewW(MSIHANDLE hdb
,
242 LPCWSTR szQuery
, MSIHANDLE
*phView
)
245 MSIQUERY
*query
= NULL
;
248 TRACE("%s %p\n", debugstr_w(szQuery
), phView
);
250 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
254 IWineMsiRemoteDatabase
*remote_database
;
256 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hdb
);
257 if ( !remote_database
)
258 return ERROR_INVALID_HANDLE
;
260 hr
= IWineMsiRemoteDatabase_OpenView( remote_database
, szQuery
, phView
);
261 IWineMsiRemoteDatabase_Release( remote_database
);
265 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
266 return HRESULT_CODE(hr
);
268 return ERROR_FUNCTION_FAILED
;
271 return ERROR_SUCCESS
;
274 ret
= MSI_DatabaseOpenViewW( db
, szQuery
, &query
);
275 if( ret
== ERROR_SUCCESS
)
277 *phView
= alloc_msihandle( &query
->hdr
);
279 ret
= ERROR_NOT_ENOUGH_MEMORY
;
280 msiobj_release( &query
->hdr
);
282 msiobj_release( &db
->hdr
);
287 UINT
msi_view_get_row(MSIDATABASE
*db
, MSIVIEW
*view
, UINT row
, MSIRECORD
**rec
)
289 UINT row_count
= 0, col_count
= 0, i
, ival
, ret
, type
;
291 TRACE("%p %p %d %p\n", db
, view
, row
, rec
);
293 ret
= view
->ops
->get_dimensions(view
, &row_count
, &col_count
);
298 return ERROR_INVALID_PARAMETER
;
300 if (row
>= row_count
)
301 return ERROR_NO_MORE_ITEMS
;
303 *rec
= MSI_CreateRecord(col_count
);
305 return ERROR_FUNCTION_FAILED
;
307 for (i
= 1; i
<= col_count
; i
++)
309 ret
= view
->ops
->get_column_info(view
, i
, NULL
, &type
, NULL
, NULL
);
312 ERR("Error getting column type for %d\n", i
);
316 if (MSITYPE_IS_BINARY(type
))
320 ret
= view
->ops
->fetch_stream(view
, row
, i
, &stm
);
321 if ((ret
== ERROR_SUCCESS
) && stm
)
323 MSI_RecordSetIStream(*rec
, i
, stm
);
324 IStream_Release(stm
);
327 WARN("failed to get stream\n");
332 ret
= view
->ops
->fetch_int(view
, row
, i
, &ival
);
335 ERR("Error fetching data for %d\n", i
);
339 if (! (type
& MSITYPE_VALID
))
340 ERR("Invalid type!\n");
342 /* check if it's nul (0) - if so, don't set anything */
346 if (type
& MSITYPE_STRING
)
349 const WCHAR
*sval
= msi_string_lookup( db
->strings
, ival
, &len
);
350 msi_record_set_string( *rec
, i
, sval
, len
);
354 if ((type
& MSI_DATASIZEMASK
) == 2)
355 MSI_RecordSetInteger(*rec
, i
, ival
- (1<<15));
357 MSI_RecordSetInteger(*rec
, i
, ival
- (1<<31));
361 return ERROR_SUCCESS
;
364 UINT
MSI_ViewFetch(MSIQUERY
*query
, MSIRECORD
**prec
)
369 TRACE("%p %p\n", query
, prec
);
373 return ERROR_FUNCTION_FAILED
;
375 r
= msi_view_get_row(query
->db
, view
, query
->row
, prec
);
376 if (r
== ERROR_SUCCESS
)
379 MSI_RecordSetIntPtr(*prec
, 0, (INT_PTR
)query
);
385 UINT WINAPI
MsiViewFetch(MSIHANDLE hView
, MSIHANDLE
*record
)
388 MSIRECORD
*rec
= NULL
;
391 TRACE("%d %p\n", hView
, record
);
394 return ERROR_INVALID_PARAMETER
;
397 query
= msihandle2msiinfo( hView
, MSIHANDLETYPE_VIEW
);
399 return ERROR_INVALID_HANDLE
;
400 ret
= MSI_ViewFetch( query
, &rec
);
401 if( ret
== ERROR_SUCCESS
)
403 *record
= alloc_msihandle( &rec
->hdr
);
405 ret
= ERROR_NOT_ENOUGH_MEMORY
;
406 msiobj_release( &rec
->hdr
);
408 msiobj_release( &query
->hdr
);
412 UINT
MSI_ViewClose(MSIQUERY
*query
)
416 TRACE("%p\n", query
);
420 return ERROR_FUNCTION_FAILED
;
421 if( !view
->ops
->close
)
422 return ERROR_FUNCTION_FAILED
;
424 return view
->ops
->close( view
);
427 UINT WINAPI
MsiViewClose(MSIHANDLE hView
)
432 TRACE("%d\n", hView
);
434 query
= msihandle2msiinfo( hView
, MSIHANDLETYPE_VIEW
);
436 return ERROR_INVALID_HANDLE
;
438 ret
= MSI_ViewClose( query
);
439 msiobj_release( &query
->hdr
);
443 UINT
MSI_ViewExecute(MSIQUERY
*query
, MSIRECORD
*rec
)
447 TRACE("%p %p\n", query
, rec
);
451 return ERROR_FUNCTION_FAILED
;
452 if( !view
->ops
->execute
)
453 return ERROR_FUNCTION_FAILED
;
456 return view
->ops
->execute( view
, rec
);
459 UINT WINAPI
MsiViewExecute(MSIHANDLE hView
, MSIHANDLE hRec
)
462 MSIRECORD
*rec
= NULL
;
465 TRACE("%d %d\n", hView
, hRec
);
467 query
= msihandle2msiinfo( hView
, MSIHANDLETYPE_VIEW
);
469 return ERROR_INVALID_HANDLE
;
473 rec
= msihandle2msiinfo( hRec
, MSIHANDLETYPE_RECORD
);
476 ret
= ERROR_INVALID_HANDLE
;
481 msiobj_lock( &rec
->hdr
);
482 ret
= MSI_ViewExecute( query
, rec
);
483 msiobj_unlock( &rec
->hdr
);
486 msiobj_release( &query
->hdr
);
488 msiobj_release( &rec
->hdr
);
493 static UINT
msi_set_record_type_string( MSIRECORD
*rec
, UINT field
,
494 UINT type
, BOOL temporary
)
496 static const WCHAR fmt
[] = { '%','d',0 };
499 if (MSITYPE_IS_BINARY(type
))
501 else if (type
& MSITYPE_LOCALIZABLE
)
503 else if (type
& MSITYPE_UNKNOWN
)
505 else if (type
& MSITYPE_STRING
)
520 if (type
& MSITYPE_NULLABLE
)
523 sprintfW( &szType
[1], fmt
, (type
&0xff) );
525 TRACE("type %04x -> %s\n", type
, debugstr_w(szType
) );
527 return MSI_RecordSetStringW( rec
, field
, szType
);
530 UINT
MSI_ViewGetColumnInfo( MSIQUERY
*query
, MSICOLINFO info
, MSIRECORD
**prec
)
532 UINT r
= ERROR_FUNCTION_FAILED
, i
, count
= 0, type
;
534 MSIVIEW
*view
= query
->view
;
539 return ERROR_FUNCTION_FAILED
;
541 if( !view
->ops
->get_dimensions
)
542 return ERROR_FUNCTION_FAILED
;
544 r
= view
->ops
->get_dimensions( view
, NULL
, &count
);
545 if( r
!= ERROR_SUCCESS
)
548 return ERROR_INVALID_PARAMETER
;
550 rec
= MSI_CreateRecord( count
);
552 return ERROR_FUNCTION_FAILED
;
554 for( i
=0; i
<count
; i
++ )
557 r
= view
->ops
->get_column_info( view
, i
+1, &name
, &type
, &temporary
, NULL
);
558 if( r
!= ERROR_SUCCESS
)
560 if (info
== MSICOLINFO_NAMES
)
561 MSI_RecordSetStringW( rec
, i
+1, name
);
563 msi_set_record_type_string( rec
, i
+1, type
, temporary
);
566 return ERROR_SUCCESS
;
569 UINT WINAPI
MsiViewGetColumnInfo(MSIHANDLE hView
, MSICOLINFO info
, MSIHANDLE
*hRec
)
571 MSIQUERY
*query
= NULL
;
572 MSIRECORD
*rec
= NULL
;
575 TRACE("%d %d %p\n", hView
, info
, hRec
);
578 return ERROR_INVALID_PARAMETER
;
580 if( info
!= MSICOLINFO_NAMES
&& info
!= MSICOLINFO_TYPES
)
581 return ERROR_INVALID_PARAMETER
;
583 query
= msihandle2msiinfo( hView
, MSIHANDLETYPE_VIEW
);
585 return ERROR_INVALID_HANDLE
;
587 r
= MSI_ViewGetColumnInfo( query
, info
, &rec
);
588 if ( r
== ERROR_SUCCESS
)
590 *hRec
= alloc_msihandle( &rec
->hdr
);
592 r
= ERROR_NOT_ENOUGH_MEMORY
;
593 msiobj_release( &rec
->hdr
);
596 msiobj_release( &query
->hdr
);
601 UINT
MSI_ViewModify( MSIQUERY
*query
, MSIMODIFY mode
, MSIRECORD
*rec
)
603 MSIVIEW
*view
= NULL
;
606 if ( !query
|| !rec
)
607 return ERROR_INVALID_HANDLE
;
610 if ( !view
|| !view
->ops
->modify
)
611 return ERROR_FUNCTION_FAILED
;
613 if ( mode
== MSIMODIFY_UPDATE
&& MSI_RecordGetIntPtr( rec
, 0 ) != (INT_PTR
)query
)
614 return ERROR_FUNCTION_FAILED
;
616 r
= view
->ops
->modify( view
, mode
, rec
, query
->row
);
617 if (mode
== MSIMODIFY_DELETE
&& r
== ERROR_SUCCESS
)
623 UINT WINAPI
MsiViewModify( MSIHANDLE hView
, MSIMODIFY eModifyMode
,
626 MSIQUERY
*query
= NULL
;
627 MSIRECORD
*rec
= NULL
;
628 UINT r
= ERROR_FUNCTION_FAILED
;
630 TRACE("%d %x %d\n", hView
, eModifyMode
, hRecord
);
632 query
= msihandle2msiinfo( hView
, MSIHANDLETYPE_VIEW
);
634 return ERROR_INVALID_HANDLE
;
636 rec
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
637 r
= MSI_ViewModify( query
, eModifyMode
, rec
);
639 msiobj_release( &query
->hdr
);
641 msiobj_release( &rec
->hdr
);
646 MSIDBERROR WINAPI
MsiViewGetErrorW( MSIHANDLE handle
, LPWSTR buffer
, LPDWORD buflen
)
653 TRACE("%u %p %p\n", handle
, buffer
, buflen
);
656 return MSIDBERROR_INVALIDARG
;
658 query
= msihandle2msiinfo( handle
, MSIHANDLETYPE_VIEW
);
660 return MSIDBERROR_INVALIDARG
;
662 if ((r
= query
->view
->error
)) column
= query
->view
->error_column
;
663 else column
= szEmpty
;
665 len
= strlenW( column
);
669 strcpyW( buffer
, column
);
671 r
= MSIDBERROR_MOREDATA
;
674 msiobj_release( &query
->hdr
);
678 MSIDBERROR WINAPI
MsiViewGetErrorA( MSIHANDLE handle
, LPSTR buffer
, LPDWORD buflen
)
685 TRACE("%u %p %p\n", handle
, buffer
, buflen
);
688 return MSIDBERROR_INVALIDARG
;
690 query
= msihandle2msiinfo( handle
, MSIHANDLETYPE_VIEW
);
692 return MSIDBERROR_INVALIDARG
;
694 if ((r
= query
->view
->error
)) column
= query
->view
->error_column
;
695 else column
= szEmpty
;
697 len
= WideCharToMultiByte( CP_ACP
, 0, column
, -1, NULL
, 0, NULL
, NULL
);
701 WideCharToMultiByte( CP_ACP
, 0, column
, -1, buffer
, *buflen
, NULL
, NULL
);
703 r
= MSIDBERROR_MOREDATA
;
706 msiobj_release( &query
->hdr
);
710 MSIHANDLE WINAPI
MsiGetLastErrorRecord( void )
716 UINT
MSI_DatabaseApplyTransformW( MSIDATABASE
*db
,
717 LPCWSTR szTransformFile
, int iErrorCond
)
720 UINT ret
= ERROR_FUNCTION_FAILED
;
721 IStorage
*stg
= NULL
;
724 TRACE("%p %s %d\n", db
, debugstr_w(szTransformFile
), iErrorCond
);
726 r
= StgOpenStorage( szTransformFile
, NULL
,
727 STGM_DIRECT
|STGM_READ
|STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
730 WARN("failed to open transform 0x%08x\n", r
);
734 r
= IStorage_Stat( stg
, &stat
, STATFLAG_NONAME
);
738 if ( !IsEqualGUID( &stat
.clsid
, &CLSID_MsiTransform
) )
741 if( TRACE_ON( msi
) )
742 enum_stream_names( stg
);
744 ret
= msi_table_apply_transform( db
, stg
);
747 IStorage_Release( stg
);
752 UINT WINAPI
MsiDatabaseApplyTransformW( MSIHANDLE hdb
,
753 LPCWSTR szTransformFile
, int iErrorCond
)
758 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
761 IWineMsiRemoteDatabase
*remote_database
;
763 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hdb
);
764 if ( !remote_database
)
765 return ERROR_INVALID_HANDLE
;
767 IWineMsiRemoteDatabase_Release( remote_database
);
768 WARN("MsiDatabaseApplyTransform not allowed during a custom action!\n");
770 return ERROR_SUCCESS
;
773 r
= MSI_DatabaseApplyTransformW( db
, szTransformFile
, iErrorCond
);
774 msiobj_release( &db
->hdr
);
778 UINT WINAPI
MsiDatabaseApplyTransformA( MSIHANDLE hdb
,
779 LPCSTR szTransformFile
, int iErrorCond
)
784 TRACE("%d %s %d\n", hdb
, debugstr_a(szTransformFile
), iErrorCond
);
786 wstr
= strdupAtoW( szTransformFile
);
787 if( szTransformFile
&& !wstr
)
788 return ERROR_NOT_ENOUGH_MEMORY
;
790 ret
= MsiDatabaseApplyTransformW( hdb
, wstr
, iErrorCond
);
797 UINT WINAPI
MsiDatabaseGenerateTransformA( MSIHANDLE hdb
, MSIHANDLE hdbref
,
798 LPCSTR szTransformFile
, int iReserved1
, int iReserved2
)
800 FIXME("%d %d %s %d %d\n", hdb
, hdbref
,
801 debugstr_a(szTransformFile
), iReserved1
, iReserved2
);
802 return ERROR_CALL_NOT_IMPLEMENTED
;
805 UINT WINAPI
MsiDatabaseGenerateTransformW( MSIHANDLE hdb
, MSIHANDLE hdbref
,
806 LPCWSTR szTransformFile
, int iReserved1
, int iReserved2
)
808 FIXME("%d %d %s %d %d\n", hdb
, hdbref
,
809 debugstr_w(szTransformFile
), iReserved1
, iReserved2
);
810 return ERROR_CALL_NOT_IMPLEMENTED
;
813 UINT WINAPI
MsiDatabaseCommit( MSIHANDLE hdb
)
820 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
823 IWineMsiRemoteDatabase
*remote_database
;
825 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hdb
);
826 if ( !remote_database
)
827 return ERROR_INVALID_HANDLE
;
829 IWineMsiRemoteDatabase_Release( remote_database
);
830 WARN("not allowed during a custom action!\n");
832 return ERROR_SUCCESS
;
835 if (db
->mode
== MSIDBOPEN_READONLY
)
837 msiobj_release( &db
->hdr
);
838 return ERROR_SUCCESS
;
841 /* FIXME: lock the database */
843 r
= MSI_CommitTables( db
);
844 if (r
!= ERROR_SUCCESS
) ERR("Failed to commit tables!\n");
846 /* FIXME: unlock the database */
848 msiobj_release( &db
->hdr
);
850 if (r
== ERROR_SUCCESS
)
852 msi_free( db
->deletefile
);
853 db
->deletefile
= NULL
;
859 struct msi_primary_key_record_info
865 static UINT
msi_primary_key_iterator( MSIRECORD
*rec
, LPVOID param
)
867 struct msi_primary_key_record_info
*info
= param
;
871 type
= MSI_RecordGetInteger( rec
, 4 );
872 if( type
& MSITYPE_KEY
)
879 table
= MSI_RecordGetString( rec
, 1 );
880 MSI_RecordSetStringW( info
->rec
, 0, table
);
883 name
= MSI_RecordGetString( rec
, 3 );
884 MSI_RecordSetStringW( info
->rec
, info
->n
, name
);
888 return ERROR_SUCCESS
;
891 UINT
MSI_DatabaseGetPrimaryKeys( MSIDATABASE
*db
,
892 LPCWSTR table
, MSIRECORD
**prec
)
894 static const WCHAR sql
[] = {
895 's','e','l','e','c','t',' ','*',' ',
896 'f','r','o','m',' ','`','_','C','o','l','u','m','n','s','`',' ',
897 'w','h','e','r','e',' ',
898 '`','T','a','b','l','e','`',' ','=',' ','\'','%','s','\'',0 };
899 struct msi_primary_key_record_info info
;
900 MSIQUERY
*query
= NULL
;
903 if (!TABLE_Exists( db
, table
))
904 return ERROR_INVALID_TABLE
;
906 r
= MSI_OpenQuery( db
, &query
, sql
, table
);
907 if( r
!= ERROR_SUCCESS
)
910 /* count the number of primary key records */
913 r
= MSI_IterateRecords( query
, 0, msi_primary_key_iterator
, &info
);
914 if( r
== ERROR_SUCCESS
)
916 TRACE("Found %d primary keys\n", info
.n
);
918 /* allocate a record and fill in the names of the tables */
919 info
.rec
= MSI_CreateRecord( info
.n
);
921 r
= MSI_IterateRecords( query
, 0, msi_primary_key_iterator
, &info
);
922 if( r
== ERROR_SUCCESS
)
925 msiobj_release( &info
.rec
->hdr
);
927 msiobj_release( &query
->hdr
);
932 UINT WINAPI
MsiDatabaseGetPrimaryKeysW( MSIHANDLE hdb
,
933 LPCWSTR table
, MSIHANDLE
* phRec
)
935 MSIRECORD
*rec
= NULL
;
939 TRACE("%d %s %p\n", hdb
, debugstr_w(table
), phRec
);
941 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
945 IWineMsiRemoteDatabase
*remote_database
;
947 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hdb
);
948 if ( !remote_database
)
949 return ERROR_INVALID_HANDLE
;
951 hr
= IWineMsiRemoteDatabase_GetPrimaryKeys( remote_database
, table
, phRec
);
952 IWineMsiRemoteDatabase_Release( remote_database
);
956 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
957 return HRESULT_CODE(hr
);
959 return ERROR_FUNCTION_FAILED
;
962 return ERROR_SUCCESS
;
965 r
= MSI_DatabaseGetPrimaryKeys( db
, table
, &rec
);
966 if( r
== ERROR_SUCCESS
)
968 *phRec
= alloc_msihandle( &rec
->hdr
);
970 r
= ERROR_NOT_ENOUGH_MEMORY
;
971 msiobj_release( &rec
->hdr
);
973 msiobj_release( &db
->hdr
);
978 UINT WINAPI
MsiDatabaseGetPrimaryKeysA(MSIHANDLE hdb
,
979 LPCSTR table
, MSIHANDLE
* phRec
)
981 LPWSTR szwTable
= NULL
;
984 TRACE("%d %s %p\n", hdb
, debugstr_a(table
), phRec
);
988 szwTable
= strdupAtoW( table
);
990 return ERROR_OUTOFMEMORY
;
992 r
= MsiDatabaseGetPrimaryKeysW( hdb
, szwTable
, phRec
);
993 msi_free( szwTable
);
998 MSICONDITION WINAPI
MsiDatabaseIsTablePersistentA(
999 MSIHANDLE hDatabase
, LPCSTR szTableName
)
1001 LPWSTR szwTableName
= NULL
;
1004 TRACE("%x %s\n", hDatabase
, debugstr_a(szTableName
));
1008 szwTableName
= strdupAtoW( szTableName
);
1010 return MSICONDITION_ERROR
;
1012 r
= MsiDatabaseIsTablePersistentW( hDatabase
, szwTableName
);
1013 msi_free( szwTableName
);
1018 MSICONDITION WINAPI
MsiDatabaseIsTablePersistentW(
1019 MSIHANDLE hDatabase
, LPCWSTR szTableName
)
1024 TRACE("%x %s\n", hDatabase
, debugstr_w(szTableName
));
1026 db
= msihandle2msiinfo( hDatabase
, MSIHANDLETYPE_DATABASE
);
1030 MSICONDITION condition
;
1031 IWineMsiRemoteDatabase
*remote_database
;
1033 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( hDatabase
);
1034 if ( !remote_database
)
1035 return MSICONDITION_ERROR
;
1037 hr
= IWineMsiRemoteDatabase_IsTablePersistent( remote_database
,
1038 szTableName
, &condition
);
1039 IWineMsiRemoteDatabase_Release( remote_database
);
1042 return MSICONDITION_ERROR
;
1047 r
= MSI_DatabaseIsTablePersistent( db
, szTableName
);
1049 msiobj_release( &db
->hdr
);