Create a helper function to fetch a single record from a query.

This commit is contained in:
Mike McCormack 2005-06-02 10:29:28 +00:00 committed by Alexandre Julliard
parent 9ffac609ea
commit 6309892499
3 changed files with 42 additions and 25 deletions

View File

@ -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;
}

View File

@ -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 ** );

View File

@ -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)
{