2003-08-13 01:27:48 +00:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
2005-02-16 16:05:11 +00:00
|
|
|
* Copyright 2002-2005 Mike McCormack for CodeWeavers
|
2003-08-13 01:27:48 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2004-10-07 03:06:48 +00:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2003-08-13 01:27:48 +00:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wine/debug.h"
|
2004-06-29 03:41:28 +00:00
|
|
|
#include "wine/unicode.h"
|
2003-08-13 01:27:48 +00:00
|
|
|
#include "msi.h"
|
|
|
|
#include "msiquery.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "objidl.h"
|
|
|
|
#include "msipriv.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
|
|
|
|
#include "query.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
void MSI_CloseView( MSIOBJECTHDR *arg )
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
2004-07-09 22:25:34 +00:00
|
|
|
MSIQUERY *query = (MSIQUERY*) arg;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
if( query->view && query->view->ops->delete )
|
|
|
|
query->view->ops->delete( query->view );
|
2004-07-09 22:25:34 +00:00
|
|
|
msiobj_release( &query->db->hdr );
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT VIEW_find_column( MSIVIEW *table, LPWSTR name, UINT *n )
|
|
|
|
{
|
|
|
|
LPWSTR col_name;
|
|
|
|
UINT i, count, r;
|
|
|
|
|
|
|
|
r = table->ops->get_dimensions( table, NULL, &count );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
for( i=1; i<=count; i++ )
|
|
|
|
{
|
|
|
|
INT x;
|
|
|
|
|
|
|
|
col_name = NULL;
|
|
|
|
r = table->ops->get_column_info( table, i, &col_name, NULL );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
x = lstrcmpW( name, col_name );
|
|
|
|
HeapFree( GetProcessHeap(), 0, col_name );
|
|
|
|
if( !x )
|
|
|
|
{
|
|
|
|
*n = i;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiDatabaseOpenViewA(MSIHANDLE hdb,
|
|
|
|
LPCSTR szQuery, MSIHANDLE *phView)
|
|
|
|
{
|
|
|
|
UINT r;
|
2003-09-27 02:24:31 +00:00
|
|
|
LPWSTR szwQuery;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
TRACE("%ld %s %p\n", hdb, debugstr_a(szQuery), phView);
|
|
|
|
|
|
|
|
if( szQuery )
|
|
|
|
{
|
2003-09-27 02:24:31 +00:00
|
|
|
UINT len = MultiByteToWideChar( CP_ACP, 0, szQuery, -1, NULL, 0 );
|
|
|
|
szwQuery = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
2003-08-13 01:27:48 +00:00
|
|
|
if( !szwQuery )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2003-09-27 02:24:31 +00:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, szQuery, -1, szwQuery, len );
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
szwQuery = NULL;
|
|
|
|
|
|
|
|
r = MsiDatabaseOpenViewW( hdb, szwQuery, phView);
|
|
|
|
|
2004-12-10 15:24:52 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, szwQuery );
|
2003-08-13 01:27:48 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
UINT MSI_DatabaseOpenViewW(MSIDATABASE *db,
|
|
|
|
LPCWSTR szQuery, MSIQUERY **pView)
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
|
|
|
MSIQUERY *query;
|
|
|
|
UINT r;
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
TRACE("%s %p\n", debugstr_w(szQuery), pView);
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
if( !szQuery)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
/* pre allocate a handle to hold a pointer to the view */
|
2004-07-09 22:25:34 +00:00
|
|
|
query = alloc_msiobject( MSIHANDLETYPE_VIEW, sizeof (MSIQUERY),
|
|
|
|
MSI_CloseView );
|
|
|
|
if( !query )
|
2003-08-13 01:27:48 +00:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
msiobj_addref( &db->hdr );
|
2003-08-13 01:27:48 +00:00
|
|
|
query->row = 0;
|
|
|
|
query->db = db;
|
|
|
|
query->view = NULL;
|
|
|
|
|
|
|
|
r = MSI_ParseSQL( db, szQuery, &query->view );
|
2004-07-09 22:25:34 +00:00
|
|
|
if( r == ERROR_SUCCESS )
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
2004-07-09 22:25:34 +00:00
|
|
|
msiobj_addref( &query->hdr );
|
|
|
|
*pView = query;
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
msiobj_release( &query->hdr );
|
2004-07-19 19:35:05 +00:00
|
|
|
return r;
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
|
2005-01-21 16:19:11 +00:00
|
|
|
UINT MSI_OpenQuery( MSIDATABASE *db, MSIQUERY **view, LPCWSTR fmt, ... )
|
|
|
|
{
|
|
|
|
LPWSTR szQuery;
|
|
|
|
LPCWSTR p;
|
|
|
|
UINT sz, rc;
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
/* figure out how much space we need to allocate */
|
|
|
|
va_start(va, fmt);
|
|
|
|
sz = strlenW(fmt) + 1;
|
|
|
|
p = fmt;
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
p = strchrW(p, '%');
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
p++;
|
|
|
|
switch (*p)
|
|
|
|
{
|
|
|
|
case 's': /* a string */
|
|
|
|
sz += strlenW(va_arg(va,LPCWSTR));
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
case 'i': /* an integer -2147483648 seems to be longest */
|
|
|
|
sz += 3*sizeof(int);
|
|
|
|
(void)va_arg(va,int);
|
|
|
|
break;
|
|
|
|
case '%': /* a single % - leave it alone */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled character type %c\n",*p);
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
/* construct the string */
|
|
|
|
szQuery = HeapAlloc(GetProcessHeap(), 0, sz*sizeof(WCHAR));
|
|
|
|
va_start(va, fmt);
|
|
|
|
vsnprintfW(szQuery, sz, fmt, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
/* perform the query */
|
|
|
|
rc = MSI_DatabaseOpenViewW(db, szQuery, view);
|
|
|
|
HeapFree(GetProcessHeap(), 0, szQuery);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-02-02 09:55:51 +00:00
|
|
|
UINT MSI_IterateRecords( MSIQUERY *view, DWORD *count,
|
|
|
|
record_func func, LPVOID param )
|
|
|
|
{
|
|
|
|
MSIRECORD *rec = NULL;
|
|
|
|
UINT r, n = 0, max = 0;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( view, NULL );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if( count )
|
|
|
|
max = *count;
|
|
|
|
|
|
|
|
/* iterate a query */
|
|
|
|
for( n = 0; (max == 0) || (n < max); n++ )
|
|
|
|
{
|
|
|
|
r = MSI_ViewFetch( view, &rec );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
break;
|
|
|
|
r = func( rec, param );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
MSI_ViewClose( view );
|
|
|
|
|
|
|
|
if( count )
|
|
|
|
*count = n;
|
|
|
|
|
2005-02-16 16:05:11 +00:00
|
|
|
if( r == ERROR_NO_MORE_ITEMS )
|
|
|
|
r = ERROR_SUCCESS;
|
|
|
|
|
2005-02-02 09:55:51 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
UINT WINAPI MsiDatabaseOpenViewW(MSIHANDLE hdb,
|
|
|
|
LPCWSTR szQuery, MSIHANDLE *phView)
|
|
|
|
{
|
|
|
|
MSIDATABASE *db;
|
|
|
|
MSIQUERY *query = NULL;
|
|
|
|
UINT ret;
|
|
|
|
|
|
|
|
TRACE("%s %p\n", debugstr_w(szQuery), phView);
|
|
|
|
|
|
|
|
db = msihandle2msiinfo( hdb, MSIHANDLETYPE_DATABASE );
|
|
|
|
if( !db )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
ret = MSI_DatabaseOpenViewW( db, szQuery, &query );
|
|
|
|
if( ret == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
*phView = alloc_msihandle( &query->hdr );
|
|
|
|
msiobj_release( &query->hdr );
|
|
|
|
}
|
|
|
|
msiobj_release( &db->hdr );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT MSI_ViewFetch(MSIQUERY *query, MSIRECORD **prec)
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
|
|
|
MSIVIEW *view;
|
2004-07-09 22:25:34 +00:00
|
|
|
MSIRECORD *rec;
|
2003-08-13 01:27:48 +00:00
|
|
|
UINT row_count = 0, col_count = 0, i, ival, ret, type;
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
TRACE("%p %p\n", query, prec );
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
view = query->view;
|
|
|
|
if( !view )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
ret = view->ops->get_dimensions( view, &row_count, &col_count );
|
|
|
|
if( ret )
|
|
|
|
return ret;
|
|
|
|
if( !col_count )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if( query->row >= row_count )
|
|
|
|
return ERROR_NO_MORE_ITEMS;
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
rec = MSI_CreateRecord( col_count );
|
|
|
|
if( !rec )
|
2003-08-13 01:27:48 +00:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
for( i=1; i<=col_count; i++ )
|
|
|
|
{
|
|
|
|
ret = view->ops->get_column_info( view, i, NULL, &type );
|
|
|
|
if( ret )
|
|
|
|
{
|
|
|
|
ERR("Error getting column type for %d\n", i );
|
|
|
|
continue;
|
|
|
|
}
|
2004-07-09 19:33:45 +00:00
|
|
|
if (( type != MSITYPE_BINARY) && (type != (MSITYPE_BINARY |
|
|
|
|
MSITYPE_NULLABLE)))
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
2004-07-06 18:56:12 +00:00
|
|
|
ret = view->ops->fetch_int( view, query->row, i, &ival );
|
|
|
|
if( ret )
|
|
|
|
{
|
|
|
|
ERR("Error fetching data for %d\n", i );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if( ! (type & MSITYPE_VALID ) )
|
|
|
|
ERR("Invalid type!\n");
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2004-07-06 18:56:12 +00:00
|
|
|
/* check if it's nul (0) - if so, don't set anything */
|
|
|
|
if( !ival )
|
|
|
|
continue;
|
2004-06-29 03:41:28 +00:00
|
|
|
|
2004-07-06 18:56:12 +00:00
|
|
|
if( type & MSITYPE_STRING )
|
2004-06-29 03:41:28 +00:00
|
|
|
{
|
2004-07-06 18:56:12 +00:00
|
|
|
LPWSTR sval;
|
|
|
|
|
2004-06-29 03:41:28 +00:00
|
|
|
sval = MSI_makestring( query->db, ival );
|
2004-07-09 22:25:34 +00:00
|
|
|
MSI_RecordSetStringW( rec, i, sval );
|
2004-06-29 03:41:28 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, sval );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-06 18:56:12 +00:00
|
|
|
if( (type & MSI_DATASIZEMASK) == 2 )
|
2004-07-09 22:25:34 +00:00
|
|
|
MSI_RecordSetInteger( rec, i, ival - (1<<15) );
|
2004-07-06 18:56:12 +00:00
|
|
|
else
|
2004-07-09 22:25:34 +00:00
|
|
|
MSI_RecordSetInteger( rec, i, ival - (1<<31) );
|
2004-06-29 03:41:28 +00:00
|
|
|
}
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-09 22:25:34 +00:00
|
|
|
IStream *stm = NULL;
|
2004-07-06 18:56:12 +00:00
|
|
|
|
|
|
|
ret = view->ops->fetch_stream( view, query->row, i, &stm );
|
|
|
|
if( ( ret == ERROR_SUCCESS ) && stm )
|
|
|
|
{
|
2004-07-09 22:25:34 +00:00
|
|
|
MSI_RecordSetIStream( rec, i, stm );
|
2004-07-06 18:56:12 +00:00
|
|
|
IStream_Release( stm );
|
|
|
|
}
|
2003-08-13 01:27:48 +00:00
|
|
|
else
|
2004-07-06 18:56:12 +00:00
|
|
|
ERR("failed to get stream\n");
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
query->row ++;
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
*prec = rec;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
UINT WINAPI MsiViewFetch(MSIHANDLE hView, MSIHANDLE *record)
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
|
|
|
MSIQUERY *query;
|
2004-07-09 22:25:34 +00:00
|
|
|
MSIRECORD *rec = NULL;
|
|
|
|
UINT ret;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
TRACE("%ld %p\n", hView, record);
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
query = msihandle2msiinfo( hView, MSIHANDLETYPE_VIEW );
|
|
|
|
if( !query )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
2004-07-09 22:25:34 +00:00
|
|
|
ret = MSI_ViewFetch( query, &rec );
|
|
|
|
if( ret == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
*record = alloc_msihandle( &rec->hdr );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
msiobj_release( &query->hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT MSI_ViewClose(MSIQUERY *query)
|
|
|
|
{
|
|
|
|
MSIVIEW *view;
|
|
|
|
|
|
|
|
TRACE("%p\n", query );
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
view = query->view;
|
|
|
|
if( !view )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
if( !view->ops->close )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return view->ops->close( view );
|
|
|
|
}
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
UINT WINAPI MsiViewClose(MSIHANDLE hView)
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
|
|
|
MSIQUERY *query;
|
2004-07-09 22:25:34 +00:00
|
|
|
UINT ret;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
TRACE("%ld\n", hView );
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
query = msihandle2msiinfo( hView, MSIHANDLETYPE_VIEW );
|
|
|
|
if( !query )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
ret = MSI_ViewClose( query );
|
|
|
|
msiobj_release( &query->hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT MSI_ViewExecute(MSIQUERY *query, MSIRECORD *rec )
|
|
|
|
{
|
|
|
|
MSIVIEW *view;
|
|
|
|
|
|
|
|
TRACE("%p %p\n", query, rec);
|
|
|
|
|
2003-08-13 01:27:48 +00:00
|
|
|
view = query->view;
|
|
|
|
if( !view )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
if( !view->ops->execute )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
query->row = 0;
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
return view->ops->execute( view, rec );
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiViewExecute(MSIHANDLE hView, MSIHANDLE hRec)
|
|
|
|
{
|
|
|
|
MSIQUERY *query;
|
|
|
|
MSIRECORD *rec = NULL;
|
|
|
|
UINT ret;
|
|
|
|
|
|
|
|
TRACE("%ld %ld\n", hView, hRec);
|
|
|
|
|
|
|
|
query = msihandle2msiinfo( hView, MSIHANDLETYPE_VIEW );
|
|
|
|
if( !query )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
if( hRec )
|
|
|
|
{
|
|
|
|
rec = msihandle2msiinfo( hRec, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
|
|
|
{
|
|
|
|
ret = ERROR_INVALID_HANDLE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-21 10:16:30 +00:00
|
|
|
msiobj_lock( &rec->hdr );
|
2004-07-09 22:25:34 +00:00
|
|
|
ret = MSI_ViewExecute( query, rec );
|
2005-01-21 10:16:30 +00:00
|
|
|
msiobj_unlock( &rec->hdr );
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
out:
|
2005-03-10 11:15:40 +00:00
|
|
|
msiobj_release( &query->hdr );
|
2004-07-09 22:25:34 +00:00
|
|
|
if( rec )
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
|
|
|
|
return ret;
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiViewGetColumnInfo(MSIHANDLE hView, MSICOLINFO info, MSIHANDLE *hRec)
|
|
|
|
{
|
2005-02-08 13:44:25 +00:00
|
|
|
MSIVIEW *view = NULL;
|
|
|
|
MSIQUERY *query = NULL;
|
|
|
|
MSIRECORD *rec = NULL;
|
|
|
|
UINT r = ERROR_FUNCTION_FAILED, i, count = 0, type;
|
2003-08-13 01:27:48 +00:00
|
|
|
LPWSTR name;
|
|
|
|
|
|
|
|
TRACE("%ld %d %p\n", hView, info, hRec);
|
|
|
|
|
|
|
|
query = msihandle2msiinfo( hView, MSIHANDLETYPE_VIEW );
|
|
|
|
if( !query )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
view = query->view;
|
|
|
|
if( !view )
|
2005-02-08 13:44:25 +00:00
|
|
|
goto out;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
if( !view->ops->get_dimensions )
|
2005-02-08 13:44:25 +00:00
|
|
|
goto out;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2005-02-08 13:44:25 +00:00
|
|
|
r = view->ops->get_dimensions( view, NULL, &count );
|
|
|
|
if( r )
|
|
|
|
goto out;
|
2003-08-13 01:27:48 +00:00
|
|
|
if( !count )
|
2005-02-08 13:44:25 +00:00
|
|
|
{
|
|
|
|
r = ERROR_INVALID_PARAMETER;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2005-02-08 13:44:25 +00:00
|
|
|
rec = MSI_CreateRecord( count );
|
|
|
|
if( !rec )
|
2005-02-16 16:05:11 +00:00
|
|
|
{
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
for( i=0; i<count; i++ )
|
|
|
|
{
|
|
|
|
name = NULL;
|
2005-02-08 13:44:25 +00:00
|
|
|
r = view->ops->get_column_info( view, i+1, &name, &type );
|
|
|
|
if( r != ERROR_SUCCESS )
|
2003-08-13 01:27:48 +00:00
|
|
|
continue;
|
2005-02-08 13:44:25 +00:00
|
|
|
MSI_RecordSetStringW( rec, i+1, name );
|
2003-08-13 01:27:48 +00:00
|
|
|
HeapFree( GetProcessHeap(), 0, name );
|
|
|
|
}
|
|
|
|
|
2005-02-08 13:44:25 +00:00
|
|
|
*hRec = alloc_msihandle( &rec->hdr );
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2005-02-08 13:44:25 +00:00
|
|
|
out:
|
2005-03-10 11:15:40 +00:00
|
|
|
msiobj_release( &query->hdr );
|
2005-02-08 13:44:25 +00:00
|
|
|
if( rec )
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiViewModify( MSIHANDLE hView, MSIMODIFY eModifyMode,
|
|
|
|
MSIHANDLE hRecord)
|
|
|
|
{
|
|
|
|
MSIVIEW *view = NULL;
|
|
|
|
MSIQUERY *query = NULL;
|
|
|
|
MSIRECORD *rec = NULL;
|
|
|
|
UINT r = ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
TRACE("%ld %x %ld\n", hView, eModifyMode, hRecord);
|
|
|
|
|
|
|
|
query = msihandle2msiinfo( hView, MSIHANDLETYPE_VIEW );
|
|
|
|
if( !query )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
view = query->view;
|
|
|
|
if( !view )
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if( !view->ops->modify )
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
rec = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
|
|
|
{
|
|
|
|
r = ERROR_INVALID_HANDLE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = view->ops->modify( view, eModifyMode, rec );
|
|
|
|
|
|
|
|
out:
|
2005-03-10 11:15:40 +00:00
|
|
|
msiobj_release( &query->hdr );
|
2005-02-08 13:44:25 +00:00
|
|
|
if( rec )
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
|
|
|
|
return r;
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiDatabaseApplyTransformA( MSIHANDLE hdb,
|
|
|
|
LPCSTR szTransformFile, int iErrorCond)
|
|
|
|
{
|
|
|
|
FIXME("%ld %s %d\n", hdb, debugstr_a(szTransformFile), iErrorCond);
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiDatabaseApplyTransformW( MSIHANDLE hdb,
|
|
|
|
LPCWSTR szTransformFile, int iErrorCond)
|
|
|
|
{
|
|
|
|
FIXME("%ld %s %d\n", hdb, debugstr_w(szTransformFile), iErrorCond);
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiDatabaseGenerateTransformA( MSIHANDLE hdb, MSIHANDLE hdbref,
|
|
|
|
LPCSTR szTransformFile, int iReserved1, int iReserved2 )
|
|
|
|
{
|
|
|
|
FIXME("%ld %ld %s %d %d\n", hdb, hdbref,
|
|
|
|
debugstr_a(szTransformFile), iReserved1, iReserved2);
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiDatabaseGenerateTransformW( MSIHANDLE hdb, MSIHANDLE hdbref,
|
|
|
|
LPCWSTR szTransformFile, int iReserved1, int iReserved2 )
|
|
|
|
{
|
|
|
|
FIXME("%ld %ld %s %d %d\n", hdb, hdbref,
|
|
|
|
debugstr_w(szTransformFile), iReserved1, iReserved2);
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiDatabaseCommit( MSIHANDLE hdb )
|
|
|
|
{
|
2004-03-18 04:04:08 +00:00
|
|
|
MSIDATABASE *db;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("%ld\n", hdb);
|
|
|
|
|
|
|
|
db = msihandle2msiinfo( hdb, MSIHANDLETYPE_DATABASE );
|
|
|
|
if( !db )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
/* FIXME: lock the database */
|
|
|
|
|
|
|
|
r = MSI_CommitTables( db );
|
|
|
|
|
|
|
|
/* FIXME: unlock the database */
|
|
|
|
|
2005-01-20 20:34:29 +00:00
|
|
|
msiobj_release( &db->hdr );
|
|
|
|
|
2004-03-18 04:04:08 +00:00
|
|
|
return r;
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
|
2005-02-16 16:05:11 +00:00
|
|
|
struct msi_primary_key_record_info
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
2005-02-16 16:05:11 +00:00
|
|
|
DWORD n;
|
|
|
|
MSIRECORD *rec;
|
|
|
|
};
|
|
|
|
|
|
|
|
static UINT msi_primary_key_iterator( MSIRECORD *rec, LPVOID param )
|
|
|
|
{
|
|
|
|
struct msi_primary_key_record_info *info = param;
|
|
|
|
LPCWSTR name;
|
|
|
|
DWORD type;
|
|
|
|
|
|
|
|
type = MSI_RecordGetInteger( rec, 4 );
|
|
|
|
if( type & MSITYPE_KEY )
|
|
|
|
{
|
|
|
|
info->n++;
|
|
|
|
if( info->rec )
|
|
|
|
{
|
|
|
|
name = MSI_RecordGetString( rec, 3 );
|
|
|
|
MSI_RecordSetStringW( info->rec, info->n, name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
|
2005-02-16 16:05:11 +00:00
|
|
|
UINT MSI_DatabaseGetPrimaryKeys( MSIDATABASE *db,
|
|
|
|
LPCWSTR table, MSIRECORD **prec )
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
2005-02-16 16:05:11 +00:00
|
|
|
static const WCHAR sql[] = {
|
|
|
|
's','e','l','e','c','t',' ','*',' ',
|
|
|
|
'f','r','o','m',' ','`','_','C','o','l','u','m','n','s','`',' ',
|
|
|
|
'w','h','e','r','e',' ',
|
|
|
|
'`','T','a','b','l','e','`',' ','=',' ','\'','%','s','\'',0 };
|
|
|
|
struct msi_primary_key_record_info info;
|
|
|
|
MSIQUERY *query = NULL;
|
|
|
|
MSIVIEW *view;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
r = MSI_OpenQuery( db, &query, sql, table );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
view = query->view;
|
|
|
|
|
|
|
|
/* count the number of primary key records */
|
|
|
|
info.n = 0;
|
|
|
|
info.rec = 0;
|
|
|
|
r = MSI_IterateRecords( query, 0, msi_primary_key_iterator, &info );
|
|
|
|
if( r == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
TRACE("Found %ld primary keys\n", info.n );
|
|
|
|
|
|
|
|
/* allocate a record and fill in the names of the tables */
|
|
|
|
info.rec = MSI_CreateRecord( info.n );
|
|
|
|
info.n = 0;
|
|
|
|
r = MSI_IterateRecords( query, 0, msi_primary_key_iterator, &info );
|
|
|
|
if( r == ERROR_SUCCESS )
|
|
|
|
*prec = info.rec;
|
|
|
|
else
|
|
|
|
msiobj_release( &info.rec->hdr );
|
|
|
|
}
|
|
|
|
msiobj_release( &query->hdr );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiDatabaseGetPrimaryKeysW( MSIHANDLE hdb,
|
|
|
|
LPCWSTR table, MSIHANDLE* phRec )
|
|
|
|
{
|
|
|
|
MSIRECORD *rec = NULL;
|
|
|
|
MSIDATABASE *db;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("%ld %s %p\n", hdb, debugstr_w(table), phRec);
|
|
|
|
|
|
|
|
db = msihandle2msiinfo( hdb, MSIHANDLETYPE_DATABASE );
|
|
|
|
if( !db )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
r = MSI_DatabaseGetPrimaryKeys( db, table, &rec );
|
|
|
|
if( r == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
*phRec = alloc_msihandle( &rec->hdr );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
msiobj_release( &db->hdr );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiDatabaseGetPrimaryKeysA(MSIHANDLE hdb,
|
|
|
|
LPCSTR table, MSIHANDLE* phRec)
|
|
|
|
{
|
|
|
|
LPWSTR szwTable = NULL;
|
|
|
|
DWORD len;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("%ld %s %p\n", hdb, debugstr_a(table), phRec);
|
|
|
|
|
|
|
|
if( table )
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, table, -1, NULL, 0 );
|
|
|
|
szwTable = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, table, -1, szwTable, len );
|
|
|
|
}
|
|
|
|
r = MsiDatabaseGetPrimaryKeysW( hdb, szwTable, phRec );
|
|
|
|
HeapFree( GetProcessHeap(), 0, szwTable );
|
|
|
|
|
|
|
|
return r;
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
2003-10-30 22:47:42 +00:00
|
|
|
|
2005-01-21 10:16:30 +00:00
|
|
|
UINT WINAPI MsiDatabaseIsTablePersistentA(
|
|
|
|
MSIHANDLE hDatabase, LPSTR szTableName)
|
|
|
|
{
|
|
|
|
FIXME("%lx %s\n", hDatabase, debugstr_a(szTableName));
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiDatabaseIsTablePersistentW(
|
|
|
|
MSIHANDLE hDatabase, LPWSTR szTableName)
|
|
|
|
{
|
|
|
|
FIXME("%lx %s\n", hDatabase, debugstr_w(szTableName));
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|