MSI: create a helper function to fetch a single record from a query
Mike McCormack
mike at codeweavers.com
Thu Jun 2 01:45:34 CDT 2005
ChangeLog:
* create a helper function to fetch a single record from a query
-------------- next part --------------
Index: dlls/msi/dialog.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/dialog.c,v
retrieving revision 1.16
diff -u -p -r1.16 dialog.c
--- dlls/msi/dialog.c 1 Jun 2005 19:48:48 -0000 1.16
+++ dlls/msi/dialog.c 2 Jun 2005 06:46:24 -0000
@@ -341,20 +341,12 @@ static LPWSTR msi_get_checkbox_value( ms
'`','P','r','o','p','e','r','t','y','`',' ','=',' ',
'\'','%','s','\'',0
};
- MSIQUERY *view = NULL;
MSIRECORD *rec = NULL;
LPCWSTR val = NULL;
LPWSTR ret = NULL;
- UINT r;
/* find if there is a value associated with the checkbox */
- r = MSI_OpenQuery( dialog->package->db, &view, query, prop);
- if( r != ERROR_SUCCESS )
- return ret;
- MSI_ViewExecute( view, NULL );
- MSI_ViewFetch( view, &rec );
- MSI_ViewClose( view );
- msiobj_release( &view->hdr );
+ rec = MSI_QueryGetRecord( dialog->package->db, query, prop );
if (!rec)
return ret;
@@ -802,22 +794,13 @@ static MSIRECORD *msi_get_dialog_record(
'W','H','E','R','E',' ',
'`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
MSIPACKAGE *package = dialog->package;
- MSIQUERY *view = NULL;
MSIRECORD *rec = NULL;
- UINT r;
TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
- r = MSI_OpenQuery( package->db, &view, query, dialog->name );
- if( r != ERROR_SUCCESS )
- {
+ rec = MSI_QueryGetRecord( package->db, query, dialog->name );
+ if( !rec )
ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
- return NULL;
- }
- MSI_ViewExecute( view, NULL );
- MSI_ViewFetch( view, &rec );
- MSI_ViewClose( view );
- msiobj_release( &view->hdr );
return rec;
}
Index: dlls/msi/msipriv.h
===================================================================
RCS file: /home/wine/wine/dlls/msi/msipriv.h,v
retrieving revision 1.62
diff -u -p -r1.62 msipriv.h
--- dlls/msi/msipriv.h 1 Jun 2005 11:02:19 -0000 1.62
+++ dlls/msi/msipriv.h 2 Jun 2005 06:46:24 -0000
@@ -340,6 +340,7 @@ extern UINT MSI_DatabaseOpenViewW(MSIDAT
extern UINT MSI_OpenQuery( MSIDATABASE *, MSIQUERY **, LPCWSTR, ... );
typedef UINT (*record_func)( MSIRECORD *, LPVOID );
extern UINT MSI_IterateRecords( MSIQUERY *, DWORD *, record_func, LPVOID );
+extern MSIRECORD *MSI_QueryGetRecord( MSIDATABASE *db, LPCWSTR query, ... );
extern UINT MSI_DatabaseImport( MSIDATABASE *, LPCWSTR, LPCWSTR );
extern UINT MSI_DatabaseExport( MSIDATABASE *, LPCWSTR, LPCWSTR, LPCWSTR );
extern UINT MSI_DatabaseGetPrimaryKeys( MSIDATABASE *, LPCWSTR, MSIRECORD ** );
Index: dlls/msi/msiquery.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/msiquery.c,v
retrieving revision 1.30
diff -u -p -r1.30 msiquery.c
--- dlls/msi/msiquery.c 31 May 2005 09:30:28 -0000 1.30
+++ dlls/msi/msiquery.c 2 Jun 2005 06:46:24 -0000
@@ -139,7 +139,8 @@ UINT MSI_DatabaseOpenViewW(MSIDATABASE *
return r;
}
-UINT MSI_OpenQuery( MSIDATABASE *db, MSIQUERY **view, LPCWSTR fmt, ... )
+static UINT MSI_OpenQueryV( MSIDATABASE *db, MSIQUERY **view,
+ LPCWSTR fmt, va_list args )
{
LPWSTR szQuery;
LPCWSTR p;
@@ -147,7 +148,7 @@ UINT MSI_OpenQuery( MSIDATABASE *db, MSI
va_list va;
/* figure out how much space we need to allocate */
- va_start(va, fmt);
+ va = args;
sz = lstrlenW(fmt) + 1;
p = fmt;
while (*p)
@@ -173,13 +174,11 @@ UINT MSI_OpenQuery( MSIDATABASE *db, MSI
}
p++;
}
- va_end(va);
/* construct the string */
szQuery = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
- va_start(va, fmt);
+ va = args;
vsnprintfW(szQuery, sz, fmt, va);
- va_end(va);
/* perform the query */
rc = MSI_DatabaseOpenViewW(db, szQuery, view);
@@ -187,6 +186,18 @@ UINT MSI_OpenQuery( MSIDATABASE *db, MSI
return rc;
}
+UINT MSI_OpenQuery( MSIDATABASE *db, MSIQUERY **view, LPCWSTR fmt, ... )
+{
+ UINT r;
+ va_list va;
+
+ va_start(va, fmt);
+ r = MSI_OpenQueryV( db, view, fmt, va );
+ va_end(va);
+
+ return r;
+}
+
UINT MSI_IterateRecords( MSIQUERY *view, DWORD *count,
record_func func, LPVOID param )
{
@@ -221,6 +232,28 @@ UINT MSI_IterateRecords( MSIQUERY *view,
r = ERROR_SUCCESS;
return r;
+}
+
+/* return a single record from a query */
+MSIRECORD *MSI_QueryGetRecord( MSIDATABASE *db, LPCWSTR fmt, ... )
+{
+ MSIRECORD *rec = NULL;
+ MSIQUERY *view = NULL;
+ UINT r;
+ va_list va;
+
+ va_start(va, fmt);
+ r = MSI_OpenQueryV( db, &view, fmt, va );
+ va_end(va);
+
+ if( r == ERROR_SUCCESS )
+ {
+ MSI_ViewExecute( view, NULL );
+ MSI_ViewFetch( view, &rec );
+ MSI_ViewClose( view );
+ msiobj_release( &view->hdr );
+ }
+ return rec;
}
UINT WINAPI MsiDatabaseOpenViewW(MSIHANDLE hdb,
More information about the wine-patches
mailing list