ChangeSet ID: 17871 CVSROOT: /opt/cvs-commit Module name: wine Changes by: julliard@wine.codeweavers.com 2005/06/02 05:29:28 Modified files: dlls/msi : msiquery.c msipriv.h dialog.c Log message: Mike McCormack Create a helper function to fetch a single record from a query. Patch: http://cvs.winehq.org/patch.py?id=17871 Old revision New revision Changes Path 1.30 1.31 +38 -5 wine/dlls/msi/msiquery.c 1.62 1.63 +1 -0 wine/dlls/msi/msipriv.h 1.16 1.17 +3 -20 wine/dlls/msi/dialog.c Index: wine/dlls/msi/msiquery.c diff -u -p wine/dlls/msi/msiquery.c:1.30 wine/dlls/msi/msiquery.c:1.31 --- wine/dlls/msi/msiquery.c:1.30 Sat May 18 22:34:31 2013 +++ wine/dlls/msi/msiquery.c Sat May 18 22:34:31 2013 @@ -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 ) { @@ -223,6 +234,28 @@ UINT MSI_IterateRecords( MSIQUERY *view, 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, LPCWSTR szQuery, MSIHANDLE *phView) { Index: wine/dlls/msi/msipriv.h diff -u -p wine/dlls/msi/msipriv.h:1.62 wine/dlls/msi/msipriv.h:1.63 --- wine/dlls/msi/msipriv.h:1.62 Sat May 18 22:34:31 2013 +++ wine/dlls/msi/msipriv.h Sat May 18 22:34:31 2013 @@ -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: wine/dlls/msi/dialog.c diff -u -p wine/dlls/msi/dialog.c:1.16 wine/dlls/msi/dialog.c:1.17 --- wine/dlls/msi/dialog.c:1.16 Sat May 18 22:34:31 2013 +++ wine/dlls/msi/dialog.c Sat May 18 22:34:31 2013 @@ -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; }