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/exception.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
= wcscmp( name
, col_name
);
78 x
|= wcscmp( 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
);
119 /* pre allocate a handle to hold a pointer to the view */
120 query
= alloc_msiobject( MSIHANDLETYPE_VIEW
, sizeof (MSIQUERY
),
123 return ERROR_FUNCTION_FAILED
;
125 msiobj_addref( &db
->hdr
);
127 list_init( &query
->mem
);
129 r
= MSI_ParseSQL( db
, szQuery
, &query
->view
, &query
->mem
);
130 if( r
== ERROR_SUCCESS
)
132 msiobj_addref( &query
->hdr
);
136 msiobj_release( &query
->hdr
);
140 UINT WINAPIV
MSI_OpenQuery( MSIDATABASE
*db
, MSIQUERY
**view
, LPCWSTR fmt
, ... )
146 /* construct the string */
150 query
= msi_alloc( size
*sizeof(WCHAR
) );
151 __ms_va_start(va
, fmt
);
152 res
= vswprintf(query
, size
, fmt
, va
);
154 if (res
== -1) size
*= 2;
155 else if (res
>= size
) size
= res
+ 1;
159 /* perform the query */
160 r
= MSI_DatabaseOpenViewW(db
, query
, view
);
165 UINT
MSI_IterateRecords( MSIQUERY
*view
, LPDWORD count
,
166 record_func func
, LPVOID param
)
168 MSIRECORD
*rec
= NULL
;
169 UINT r
, n
= 0, max
= 0;
171 r
= MSI_ViewExecute( view
, NULL
);
172 if( r
!= ERROR_SUCCESS
)
178 /* iterate a query */
179 for( n
= 0; (max
== 0) || (n
< max
); n
++ )
181 r
= MSI_ViewFetch( view
, &rec
);
182 if( r
!= ERROR_SUCCESS
)
185 r
= func( rec
, param
);
186 msiobj_release( &rec
->hdr
);
187 if( r
!= ERROR_SUCCESS
)
191 MSI_ViewClose( view
);
196 if( r
== ERROR_NO_MORE_ITEMS
)
202 /* return a single record from a query */
203 MSIRECORD
* WINAPIV
MSI_QueryGetRecord( MSIDATABASE
*db
, LPCWSTR fmt
, ... )
205 MSIRECORD
*rec
= NULL
;
206 MSIQUERY
*view
= NULL
;
211 /* construct the string */
215 query
= msi_alloc( size
*sizeof(WCHAR
) );
216 __ms_va_start(va
, fmt
);
217 res
= vswprintf(query
, size
, fmt
, va
);
219 if (res
== -1) size
*= 2;
220 else if (res
>= size
) size
= res
+ 1;
224 /* perform the query */
225 r
= MSI_DatabaseOpenViewW(db
, query
, &view
);
228 if( r
== ERROR_SUCCESS
)
230 MSI_ViewExecute( view
, NULL
);
231 MSI_ViewFetch( view
, &rec
);
232 MSI_ViewClose( view
);
233 msiobj_release( &view
->hdr
);
238 UINT WINAPI
MsiDatabaseOpenViewW(MSIHANDLE hdb
,
239 LPCWSTR szQuery
, MSIHANDLE
*phView
)
242 MSIQUERY
*query
= NULL
;
245 TRACE("%s %p\n", debugstr_w(szQuery
), phView
);
248 return ERROR_INVALID_PARAMETER
;
251 return ERROR_BAD_QUERY_SYNTAX
;
253 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
256 MSIHANDLE remote
, remote_view
;
258 if (!(remote
= msi_get_remote(hdb
)))
259 return ERROR_INVALID_HANDLE
;
263 ret
= remote_DatabaseOpenView(remote
, szQuery
, &remote_view
);
267 ret
= GetExceptionCode();
272 *phView
= alloc_msi_remote_handle(remote_view
);
276 ret
= MSI_DatabaseOpenViewW( db
, szQuery
, &query
);
277 if( ret
== ERROR_SUCCESS
)
279 *phView
= alloc_msihandle( &query
->hdr
);
281 ret
= ERROR_NOT_ENOUGH_MEMORY
;
282 msiobj_release( &query
->hdr
);
284 msiobj_release( &db
->hdr
);
289 UINT
msi_view_refresh_row(MSIDATABASE
*db
, MSIVIEW
*view
, UINT row
, MSIRECORD
*rec
)
291 UINT row_count
= 0, col_count
= 0, i
, ival
, ret
, type
;
293 TRACE("%p %p %d %p\n", db
, view
, row
, rec
);
295 ret
= view
->ops
->get_dimensions(view
, &row_count
, &col_count
);
300 return ERROR_INVALID_PARAMETER
;
302 for (i
= 1; i
<= col_count
; i
++)
304 ret
= view
->ops
->get_column_info(view
, i
, NULL
, &type
, NULL
, NULL
);
307 ERR("Error getting column type for %d\n", i
);
311 if (MSITYPE_IS_BINARY(type
))
315 ret
= view
->ops
->fetch_stream(view
, row
, i
, &stm
);
316 if ((ret
== ERROR_SUCCESS
) && stm
)
318 MSI_RecordSetIStream(rec
, i
, stm
);
319 IStream_Release(stm
);
322 WARN("failed to get stream\n");
327 ret
= view
->ops
->fetch_int(view
, row
, i
, &ival
);
330 ERR("Error fetching data for %d\n", i
);
334 if (! (type
& MSITYPE_VALID
))
335 ERR("Invalid type!\n");
337 if (type
& MSITYPE_STRING
)
340 const WCHAR
*sval
= msi_string_lookup(db
->strings
, ival
, &len
);
341 msi_record_set_string(rec
, i
, sval
, len
);
345 if ((type
& MSI_DATASIZEMASK
) == 2)
346 MSI_RecordSetInteger(rec
, i
, ival
? ival
- (1<<15) : MSI_NULL_INTEGER
);
348 MSI_RecordSetInteger(rec
, i
, ival
- (1u<<31));
352 return ERROR_SUCCESS
;
355 UINT
msi_view_get_row(MSIDATABASE
*db
, MSIVIEW
*view
, UINT row
, MSIRECORD
**rec
)
357 UINT row_count
= 0, col_count
= 0, r
;
360 TRACE("view %p, row %u, rec %p.\n", view
, row
, rec
);
362 if ((r
= view
->ops
->get_dimensions(view
, &row_count
, &col_count
)))
365 if (row
>= row_count
)
366 return ERROR_NO_MORE_ITEMS
;
368 if (!(object
= MSI_CreateRecord( col_count
)))
369 return ERROR_OUTOFMEMORY
;
371 if ((r
= msi_view_refresh_row(db
, view
, row
, object
)))
372 msiobj_release( &object
->hdr
);
379 UINT
MSI_ViewFetch(MSIQUERY
*query
, MSIRECORD
**prec
)
384 TRACE("%p %p\n", query
, prec
);
388 return ERROR_FUNCTION_FAILED
;
390 r
= msi_view_get_row(query
->db
, view
, query
->row
, prec
);
391 if (r
== ERROR_SUCCESS
)
394 (*prec
)->cookie
= (UINT64
)(ULONG_PTR
)query
;
395 MSI_RecordSetInteger(*prec
, 0, 1);
401 UINT WINAPI
MsiViewFetch(MSIHANDLE hView
, MSIHANDLE
*record
)
404 MSIRECORD
*rec
= NULL
;
407 TRACE("%d %p\n", hView
, record
);
410 return ERROR_INVALID_PARAMETER
;
413 query
= msihandle2msiinfo( hView
, MSIHANDLETYPE_VIEW
);
416 struct wire_record
*wire_rec
= NULL
;
419 if (!(remote
= msi_get_remote(hView
)))
420 return ERROR_INVALID_HANDLE
;
424 ret
= remote_ViewFetch(remote
, &wire_rec
);
428 ret
= GetExceptionCode();
434 ret
= unmarshal_record(wire_rec
, record
);
435 free_remote_record(wire_rec
);
439 ret
= MSI_ViewFetch( query
, &rec
);
440 if( ret
== ERROR_SUCCESS
)
442 *record
= alloc_msihandle( &rec
->hdr
);
444 ret
= ERROR_NOT_ENOUGH_MEMORY
;
445 msiobj_release( &rec
->hdr
);
447 msiobj_release( &query
->hdr
);
451 UINT
MSI_ViewClose(MSIQUERY
*query
)
455 TRACE("%p\n", query
);
459 return ERROR_FUNCTION_FAILED
;
460 if( !view
->ops
->close
)
461 return ERROR_FUNCTION_FAILED
;
463 return view
->ops
->close( view
);
466 UINT WINAPI
MsiViewClose(MSIHANDLE hView
)
471 TRACE("%d\n", hView
);
473 query
= msihandle2msiinfo( hView
, MSIHANDLETYPE_VIEW
);
478 if (!(remote
= msi_get_remote(hView
)))
479 return ERROR_INVALID_HANDLE
;
483 ret
= remote_ViewClose(remote
);
487 ret
= GetExceptionCode();
494 ret
= MSI_ViewClose( query
);
495 msiobj_release( &query
->hdr
);
499 UINT
MSI_ViewExecute(MSIQUERY
*query
, MSIRECORD
*rec
)
503 TRACE("%p %p\n", query
, rec
);
507 return ERROR_FUNCTION_FAILED
;
508 if( !view
->ops
->execute
)
509 return ERROR_FUNCTION_FAILED
;
512 return view
->ops
->execute( view
, rec
);
515 UINT WINAPI
MsiViewExecute(MSIHANDLE hView
, MSIHANDLE hRec
)
518 MSIRECORD
*rec
= NULL
;
521 TRACE("%d %d\n", hView
, hRec
);
525 rec
= msihandle2msiinfo( hRec
, MSIHANDLETYPE_RECORD
);
527 return ERROR_INVALID_HANDLE
;
530 query
= msihandle2msiinfo( hView
, MSIHANDLETYPE_VIEW
);
535 if (!(remote
= msi_get_remote(hView
)))
536 return ERROR_INVALID_HANDLE
;
540 ret
= remote_ViewExecute(remote
, rec
? (struct wire_record
*)&rec
->count
: NULL
);
544 ret
= GetExceptionCode();
549 msiobj_release(&rec
->hdr
);
553 msiobj_lock( &rec
->hdr
);
554 ret
= MSI_ViewExecute( query
, rec
);
555 msiobj_unlock( &rec
->hdr
);
557 msiobj_release( &query
->hdr
);
559 msiobj_release( &rec
->hdr
);
564 static UINT
msi_set_record_type_string( MSIRECORD
*rec
, UINT field
,
565 UINT type
, BOOL temporary
)
569 if (MSITYPE_IS_BINARY(type
))
571 else if (type
& MSITYPE_LOCALIZABLE
)
573 else if (type
& MSITYPE_UNKNOWN
)
575 else if (type
& MSITYPE_STRING
)
590 if (type
& MSITYPE_NULLABLE
)
593 swprintf( &szType
[1], ARRAY_SIZE(szType
) - 1, L
"%d", (type
&0xff) );
595 TRACE("type %04x -> %s\n", type
, debugstr_w(szType
) );
597 return MSI_RecordSetStringW( rec
, field
, szType
);
600 UINT
MSI_ViewGetColumnInfo( MSIQUERY
*query
, MSICOLINFO info
, MSIRECORD
**prec
)
602 UINT r
= ERROR_FUNCTION_FAILED
, i
, count
= 0, type
;
604 MSIVIEW
*view
= query
->view
;
609 return ERROR_FUNCTION_FAILED
;
611 if( !view
->ops
->get_dimensions
)
612 return ERROR_FUNCTION_FAILED
;
614 r
= view
->ops
->get_dimensions( view
, NULL
, &count
);
615 if( r
!= ERROR_SUCCESS
)
618 return ERROR_INVALID_PARAMETER
;
620 rec
= MSI_CreateRecord( count
);
622 return ERROR_FUNCTION_FAILED
;
624 for( i
=0; i
<count
; i
++ )
627 r
= view
->ops
->get_column_info( view
, i
+1, &name
, &type
, &temporary
, NULL
);
628 if( r
!= ERROR_SUCCESS
)
630 if (info
== MSICOLINFO_NAMES
)
631 MSI_RecordSetStringW( rec
, i
+1, name
);
633 msi_set_record_type_string( rec
, i
+1, type
, temporary
);
636 return ERROR_SUCCESS
;
639 UINT WINAPI
MsiViewGetColumnInfo(MSIHANDLE hView
, MSICOLINFO info
, MSIHANDLE
*hRec
)
641 MSIQUERY
*query
= NULL
;
642 MSIRECORD
*rec
= NULL
;
645 TRACE("%d %d %p\n", hView
, info
, hRec
);
648 return ERROR_INVALID_PARAMETER
;
650 if( info
!= MSICOLINFO_NAMES
&& info
!= MSICOLINFO_TYPES
)
651 return ERROR_INVALID_PARAMETER
;
653 query
= msihandle2msiinfo( hView
, MSIHANDLETYPE_VIEW
);
656 struct wire_record
*wire_rec
= NULL
;
659 if (!(remote
= msi_get_remote(hView
)))
660 return ERROR_INVALID_HANDLE
;
664 r
= remote_ViewGetColumnInfo(remote
, info
, &wire_rec
);
668 r
= GetExceptionCode();
674 r
= unmarshal_record(wire_rec
, hRec
);
675 free_remote_record(wire_rec
);
681 r
= MSI_ViewGetColumnInfo( query
, info
, &rec
);
682 if ( r
== ERROR_SUCCESS
)
684 *hRec
= alloc_msihandle( &rec
->hdr
);
686 r
= ERROR_NOT_ENOUGH_MEMORY
;
687 msiobj_release( &rec
->hdr
);
690 msiobj_release( &query
->hdr
);
695 UINT
MSI_ViewModify( MSIQUERY
*query
, MSIMODIFY mode
, MSIRECORD
*rec
)
697 MSIVIEW
*view
= NULL
;
700 if ( !query
|| !rec
)
701 return ERROR_INVALID_HANDLE
;
704 if ( !view
|| !view
->ops
->modify
)
705 return ERROR_FUNCTION_FAILED
;
707 if ( mode
== MSIMODIFY_UPDATE
&& rec
->cookie
!= (UINT64
)(ULONG_PTR
)query
)
708 return ERROR_FUNCTION_FAILED
;
710 r
= view
->ops
->modify( view
, mode
, rec
, query
->row
- 1 );
711 if (mode
== MSIMODIFY_DELETE
&& r
== ERROR_SUCCESS
)
717 UINT WINAPI
MsiViewModify( MSIHANDLE hView
, MSIMODIFY eModifyMode
,
720 MSIQUERY
*query
= NULL
;
721 MSIRECORD
*rec
= NULL
;
722 UINT r
= ERROR_FUNCTION_FAILED
;
724 TRACE("%d %x %d\n", hView
, eModifyMode
, hRecord
);
726 rec
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
729 return ERROR_INVALID_HANDLE
;
731 query
= msihandle2msiinfo( hView
, MSIHANDLETYPE_VIEW
);
734 struct wire_record
*wire_refreshed
= NULL
;
737 if (!(remote
= msi_get_remote(hView
)))
738 return ERROR_INVALID_HANDLE
;
742 r
= remote_ViewModify(remote
, eModifyMode
,
743 (struct wire_record
*)&rec
->count
, &wire_refreshed
);
747 r
= GetExceptionCode();
751 if (!r
&& (eModifyMode
== MSIMODIFY_REFRESH
|| eModifyMode
== MSIMODIFY_SEEK
))
753 r
= copy_remote_record(wire_refreshed
, hRecord
);
754 free_remote_record(wire_refreshed
);
757 msiobj_release(&rec
->hdr
);
761 r
= MSI_ViewModify( query
, eModifyMode
, rec
);
763 msiobj_release( &query
->hdr
);
764 msiobj_release(&rec
->hdr
);
768 MSIDBERROR WINAPI
MsiViewGetErrorW( MSIHANDLE handle
, LPWSTR buffer
, LPDWORD buflen
)
774 TRACE("%u %p %p\n", handle
, buffer
, buflen
);
777 return MSIDBERROR_INVALIDARG
;
779 if (!(query
= msihandle2msiinfo(handle
, MSIHANDLETYPE_VIEW
)))
781 WCHAR
*remote_column
= NULL
;
784 if (!(remote
= msi_get_remote(handle
)))
785 return MSIDBERROR_INVALIDARG
;
788 return MSIDBERROR_FUNCTIONERROR
;
792 r
= remote_ViewGetError(remote
, &remote_column
);
796 r
= GetExceptionCode();
800 if (msi_strncpyW(remote_column
? remote_column
: L
"", -1, buffer
, buflen
) == ERROR_MORE_DATA
)
801 r
= MSIDBERROR_MOREDATA
;
804 midl_user_free(remote_column
);
809 if ((r
= query
->view
->error
)) column
= query
->view
->error_column
;
812 if (msi_strncpyW(column
, -1, buffer
, buflen
) == ERROR_MORE_DATA
)
813 r
= MSIDBERROR_MOREDATA
;
815 msiobj_release( &query
->hdr
);
819 MSIDBERROR WINAPI
MsiViewGetErrorA( MSIHANDLE handle
, LPSTR buffer
, LPDWORD buflen
)
825 TRACE("%u %p %p\n", handle
, buffer
, buflen
);
828 return MSIDBERROR_INVALIDARG
;
830 if (!(query
= msihandle2msiinfo(handle
, MSIHANDLETYPE_VIEW
)))
832 WCHAR
*remote_column
= NULL
;
835 if (!(remote
= msi_get_remote(handle
)))
836 return MSIDBERROR_INVALIDARG
;
839 return MSIDBERROR_FUNCTIONERROR
;
843 r
= remote_ViewGetError(remote
, &remote_column
);
847 r
= GetExceptionCode();
851 if (msi_strncpyWtoA(remote_column
? remote_column
: L
"", -1, buffer
, buflen
, FALSE
) == ERROR_MORE_DATA
)
852 r
= MSIDBERROR_MOREDATA
;
855 midl_user_free(remote_column
);
860 if ((r
= query
->view
->error
)) column
= query
->view
->error_column
;
863 if (msi_strncpyWtoA(column
, -1, buffer
, buflen
, FALSE
) == ERROR_MORE_DATA
)
864 r
= MSIDBERROR_MOREDATA
;
866 msiobj_release( &query
->hdr
);
870 MSIHANDLE WINAPI
MsiGetLastErrorRecord( void )
876 UINT
MSI_DatabaseApplyTransformW( MSIDATABASE
*db
, const WCHAR
*transform
, int error_cond
)
879 UINT ret
= ERROR_FUNCTION_FAILED
;
883 TRACE( "%p %s %08x\n", db
, debugstr_w(transform
), error_cond
);
885 if (*transform
== ':')
887 hr
= IStorage_OpenStorage( db
->storage
, transform
+ 1, NULL
, STGM_SHARE_EXCLUSIVE
, NULL
, 0, &stg
);
890 WARN( "failed to open substorage transform 0x%08x\n", hr
);
891 return ERROR_FUNCTION_FAILED
;
896 hr
= StgOpenStorage( transform
, NULL
, STGM_DIRECT
|STGM_READ
|STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
899 WARN( "failed to open file transform 0x%08x\n", hr
);
900 return ERROR_FUNCTION_FAILED
;
904 hr
= IStorage_Stat( stg
, &stat
, STATFLAG_NONAME
);
905 if (FAILED( hr
)) goto end
;
906 if (!IsEqualGUID( &stat
.clsid
, &CLSID_MsiTransform
)) goto end
;
907 if (TRACE_ON( msi
)) enum_stream_names( stg
);
909 ret
= msi_table_apply_transform( db
, stg
, error_cond
);
912 IStorage_Release( stg
);
916 UINT WINAPI
MsiDatabaseApplyTransformW( MSIHANDLE hdb
, const WCHAR
*transform
, int error_cond
)
921 if (error_cond
& ~MSITRANSFORM_ERROR_VIEWTRANSFORM
) FIXME( "ignoring error conditions\n" );
923 if (!(db
= msihandle2msiinfo(hdb
, MSIHANDLETYPE_DATABASE
)))
924 return ERROR_INVALID_HANDLE
;
926 r
= MSI_DatabaseApplyTransformW( db
, transform
, error_cond
);
927 msiobj_release( &db
->hdr
);
931 UINT WINAPI
MsiDatabaseApplyTransformA( MSIHANDLE hdb
, const char *transform
, int error_cond
)
936 TRACE( "%d %s %08x\n", hdb
, debugstr_a(transform
), error_cond
);
938 wstr
= strdupAtoW( transform
);
939 if (transform
&& !wstr
)
940 return ERROR_NOT_ENOUGH_MEMORY
;
942 ret
= MsiDatabaseApplyTransformW( hdb
, wstr
, error_cond
);
947 UINT WINAPI
MsiDatabaseGenerateTransformA( MSIHANDLE hdb
, MSIHANDLE hdbref
,
948 LPCSTR szTransformFile
, int iReserved1
, int iReserved2
)
950 FIXME("%d %d %s %d %d\n", hdb
, hdbref
,
951 debugstr_a(szTransformFile
), iReserved1
, iReserved2
);
952 return ERROR_CALL_NOT_IMPLEMENTED
;
955 UINT WINAPI
MsiDatabaseGenerateTransformW( MSIHANDLE hdb
, MSIHANDLE hdbref
,
956 LPCWSTR szTransformFile
, int iReserved1
, int iReserved2
)
958 FIXME("%d %d %s %d %d\n", hdb
, hdbref
,
959 debugstr_w(szTransformFile
), iReserved1
, iReserved2
);
960 return ERROR_CALL_NOT_IMPLEMENTED
;
963 UINT WINAPI
MsiDatabaseCommit( MSIHANDLE hdb
)
970 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
975 if (!(remote
= msi_get_remote(hdb
)))
976 return ERROR_INVALID_HANDLE
;
978 WARN("not allowed during a custom action!\n");
980 return ERROR_SUCCESS
;
983 if (db
->mode
== MSI_OPEN_READONLY
)
985 msiobj_release( &db
->hdr
);
986 return ERROR_SUCCESS
;
989 /* FIXME: lock the database */
991 r
= msi_commit_streams( db
);
992 if (r
!= ERROR_SUCCESS
) ERR("Failed to commit streams!\n");
995 r
= MSI_CommitTables( db
);
996 if (r
!= ERROR_SUCCESS
) ERR("Failed to commit tables!\n");
999 /* FIXME: unlock the database */
1001 msiobj_release( &db
->hdr
);
1003 if (r
== ERROR_SUCCESS
)
1005 msi_free( db
->deletefile
);
1006 db
->deletefile
= NULL
;
1012 struct msi_primary_key_record_info
1018 static UINT
msi_primary_key_iterator( MSIRECORD
*rec
, LPVOID param
)
1020 struct msi_primary_key_record_info
*info
= param
;
1021 LPCWSTR name
, table
;
1024 type
= MSI_RecordGetInteger( rec
, 4 );
1025 if( type
& MSITYPE_KEY
)
1032 table
= MSI_RecordGetString( rec
, 1 );
1033 MSI_RecordSetStringW( info
->rec
, 0, table
);
1036 name
= MSI_RecordGetString( rec
, 3 );
1037 MSI_RecordSetStringW( info
->rec
, info
->n
, name
);
1041 return ERROR_SUCCESS
;
1044 UINT
MSI_DatabaseGetPrimaryKeys( MSIDATABASE
*db
,
1045 LPCWSTR table
, MSIRECORD
**prec
)
1047 struct msi_primary_key_record_info info
;
1048 MSIQUERY
*query
= NULL
;
1051 if (!TABLE_Exists( db
, table
))
1052 return ERROR_INVALID_TABLE
;
1054 r
= MSI_OpenQuery( db
, &query
, L
"SELECT * FROM `_Columns` WHERE `Table` = '%s'", table
);
1055 if( r
!= ERROR_SUCCESS
)
1058 /* count the number of primary key records */
1061 r
= MSI_IterateRecords( query
, 0, msi_primary_key_iterator
, &info
);
1062 if( r
== ERROR_SUCCESS
)
1064 TRACE("Found %d primary keys\n", info
.n
);
1066 /* allocate a record and fill in the names of the tables */
1067 info
.rec
= MSI_CreateRecord( info
.n
);
1069 r
= MSI_IterateRecords( query
, 0, msi_primary_key_iterator
, &info
);
1070 if( r
== ERROR_SUCCESS
)
1073 msiobj_release( &info
.rec
->hdr
);
1075 msiobj_release( &query
->hdr
);
1080 UINT WINAPI
MsiDatabaseGetPrimaryKeysW( MSIHANDLE hdb
,
1081 LPCWSTR table
, MSIHANDLE
* phRec
)
1083 MSIRECORD
*rec
= NULL
;
1087 TRACE("%d %s %p\n", hdb
, debugstr_w(table
), phRec
);
1089 db
= msihandle2msiinfo( hdb
, MSIHANDLETYPE_DATABASE
);
1092 struct wire_record
*wire_rec
= NULL
;
1095 if (!(remote
= msi_get_remote(hdb
)))
1096 return ERROR_INVALID_HANDLE
;
1100 r
= remote_DatabaseGetPrimaryKeys(remote
, table
, &wire_rec
);
1102 __EXCEPT(rpc_filter
)
1104 r
= GetExceptionCode();
1110 r
= unmarshal_record(wire_rec
, phRec
);
1111 free_remote_record(wire_rec
);
1117 r
= MSI_DatabaseGetPrimaryKeys( db
, table
, &rec
);
1118 if( r
== ERROR_SUCCESS
)
1120 *phRec
= alloc_msihandle( &rec
->hdr
);
1122 r
= ERROR_NOT_ENOUGH_MEMORY
;
1123 msiobj_release( &rec
->hdr
);
1125 msiobj_release( &db
->hdr
);
1130 UINT WINAPI
MsiDatabaseGetPrimaryKeysA(MSIHANDLE hdb
,
1131 LPCSTR table
, MSIHANDLE
* phRec
)
1133 LPWSTR szwTable
= NULL
;
1136 TRACE("%d %s %p\n", hdb
, debugstr_a(table
), phRec
);
1140 szwTable
= strdupAtoW( table
);
1142 return ERROR_OUTOFMEMORY
;
1144 r
= MsiDatabaseGetPrimaryKeysW( hdb
, szwTable
, phRec
);
1145 msi_free( szwTable
);
1150 MSICONDITION WINAPI
MsiDatabaseIsTablePersistentA(
1151 MSIHANDLE hDatabase
, LPCSTR szTableName
)
1153 LPWSTR szwTableName
= NULL
;
1156 TRACE("%x %s\n", hDatabase
, debugstr_a(szTableName
));
1160 szwTableName
= strdupAtoW( szTableName
);
1162 return MSICONDITION_ERROR
;
1164 r
= MsiDatabaseIsTablePersistentW( hDatabase
, szwTableName
);
1165 msi_free( szwTableName
);
1170 MSICONDITION WINAPI
MsiDatabaseIsTablePersistentW(
1171 MSIHANDLE hDatabase
, LPCWSTR szTableName
)
1176 TRACE("%x %s\n", hDatabase
, debugstr_w(szTableName
));
1178 db
= msihandle2msiinfo( hDatabase
, MSIHANDLETYPE_DATABASE
);
1183 if (!(remote
= msi_get_remote(hDatabase
)))
1184 return MSICONDITION_ERROR
;
1188 r
= remote_DatabaseIsTablePersistent(remote
, szTableName
);
1190 __EXCEPT(rpc_filter
)
1192 r
= MSICONDITION_ERROR
;
1199 r
= MSI_DatabaseIsTablePersistent( db
, szTableName
);
1201 msiobj_release( &db
->hdr
);
1206 UINT __cdecl
s_remote_ViewClose(MSIHANDLE view
)
1208 return MsiViewClose(view
);
1211 UINT __cdecl
s_remote_ViewExecute(MSIHANDLE view
, struct wire_record
*remote_rec
)
1216 if ((r
= unmarshal_record(remote_rec
, &rec
)))
1219 r
= MsiViewExecute(view
, rec
);
1221 MsiCloseHandle(rec
);
1225 UINT __cdecl
s_remote_ViewFetch(MSIHANDLE view
, struct wire_record
**rec
)
1228 UINT r
= MsiViewFetch(view
, &handle
);
1231 *rec
= marshal_record(handle
);
1232 MsiCloseHandle(handle
);
1236 UINT __cdecl
s_remote_ViewGetColumnInfo(MSIHANDLE view
, MSICOLINFO info
, struct wire_record
**rec
)
1239 UINT r
= MsiViewGetColumnInfo(view
, info
, &handle
);
1242 *rec
= marshal_record(handle
);
1243 MsiCloseHandle(handle
);
1247 MSIDBERROR __cdecl
s_remote_ViewGetError(MSIHANDLE view
, LPWSTR
*column
)
1253 r
= MsiViewGetErrorW(view
, empty
, &size
);
1254 if (r
== MSIDBERROR_MOREDATA
)
1256 if (!(*column
= midl_user_allocate(++size
* sizeof(WCHAR
))))
1257 return MSIDBERROR_FUNCTIONERROR
;
1258 r
= MsiViewGetErrorW(view
, *column
, &size
);
1263 UINT __cdecl
s_remote_ViewModify(MSIHANDLE view
, MSIMODIFY mode
,
1264 struct wire_record
*remote_rec
, struct wire_record
**remote_refreshed
)
1266 MSIHANDLE handle
= 0;
1269 if ((r
= unmarshal_record(remote_rec
, &handle
)))
1272 r
= MsiViewModify(view
, mode
, handle
);
1273 *remote_refreshed
= NULL
;
1274 if (!r
&& (mode
== MSIMODIFY_REFRESH
|| mode
== MSIMODIFY_SEEK
))
1275 *remote_refreshed
= marshal_record(handle
);
1277 MsiCloseHandle(handle
);