From 63098924990952f3f8cf4af308873b63c95fe9b2 Mon Sep 17 00:00:00 2001 From: Mike McCormack Date: Thu, 2 Jun 2005 10:29:28 +0000 Subject: [PATCH] Create a helper function to fetch a single record from a query. --- dlls/msi/dialog.c | 23 +++-------------------- dlls/msi/msipriv.h | 1 + dlls/msi/msiquery.c | 43 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/dlls/msi/dialog.c b/dlls/msi/dialog.c index 5e0bf478d8f..92e05f87800 100644 --- a/dlls/msi/dialog.c +++ b/dlls/msi/dialog.c @@ -341,20 +341,12 @@ static LPWSTR msi_get_checkbox_value( msi_dialog *dialog, LPCWSTR prop ) '`','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( msi_dialog *dialog ) '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; } diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h index b2098c62f3b..de609d35075 100644 --- a/dlls/msi/msipriv.h +++ b/dlls/msi/msipriv.h @@ -340,6 +340,7 @@ extern UINT MSI_DatabaseOpenViewW(MSIDATABASE *, LPCWSTR, MSIQUERY ** ); 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 ** ); diff --git a/dlls/msi/msiquery.c b/dlls/msi/msiquery.c index e413fc7b7eb..d21403eaedc 100644 --- a/dlls/msi/msiquery.c +++ b/dlls/msi/msiquery.c @@ -139,7 +139,8 @@ UINT MSI_DatabaseOpenViewW(MSIDATABASE *db, 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, MSIQUERY **view, LPCWSTR fmt, ... ) 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, MSIQUERY **view, LPCWSTR fmt, ... ) } 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, MSIQUERY **view, LPCWSTR fmt, ... ) 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, DWORD *count, 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) {