2005-03-29 13:28:57 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
|
|
|
* Copyright 2002,2003,2004,2005 Mike McCormack for CodeWeavers
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-29 13:28:57 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2010-11-17 10:58:10 +01:00
|
|
|
#include <stdio.h>
|
2005-03-29 13:28:57 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "wine/debug.h"
|
2006-09-26 05:03:31 +02:00
|
|
|
#include "wine/unicode.h"
|
2005-03-29 13:28:57 +02:00
|
|
|
#include "msi.h"
|
|
|
|
#include "msiquery.h"
|
|
|
|
#include "msipriv.h"
|
|
|
|
#include "objidl.h"
|
|
|
|
#include "objbase.h"
|
2007-11-12 01:13:08 +01:00
|
|
|
#include "msiserver.h"
|
2008-10-09 05:42:33 +02:00
|
|
|
#include "query.h"
|
2005-03-29 13:28:57 +02:00
|
|
|
|
|
|
|
#include "initguid.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* .MSI file format
|
|
|
|
*
|
|
|
|
* An .msi file is a structured storage file.
|
|
|
|
* It contains a number of streams.
|
|
|
|
* A stream for each table in the database.
|
|
|
|
* Two streams for the string table in the database.
|
|
|
|
* Any binary data in a table is a reference to a stream.
|
|
|
|
*/
|
|
|
|
|
2010-01-29 15:01:17 +01:00
|
|
|
#define IS_INTMSIDBOPEN(x) (((ULONG_PTR)(x) >> 16) == 0)
|
|
|
|
|
2009-12-17 04:05:12 +01:00
|
|
|
typedef struct tagMSITRANSFORM {
|
|
|
|
struct list entry;
|
|
|
|
IStorage *stg;
|
|
|
|
} MSITRANSFORM;
|
|
|
|
|
|
|
|
typedef struct tagMSISTREAM {
|
|
|
|
struct list entry;
|
2011-05-06 14:40:48 +02:00
|
|
|
IStorage *stg;
|
2009-12-17 04:05:12 +01:00
|
|
|
IStream *stm;
|
|
|
|
} MSISTREAM;
|
|
|
|
|
2011-05-06 14:40:48 +02:00
|
|
|
static UINT find_open_stream( MSIDATABASE *db, IStorage *stg, LPCWSTR name, IStream **stm )
|
2009-12-17 04:05:12 +01:00
|
|
|
{
|
|
|
|
MSISTREAM *stream;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( stream, &db->streams, MSISTREAM, entry )
|
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
STATSTG stat;
|
|
|
|
|
2011-05-06 14:40:48 +02:00
|
|
|
if (stream->stg != stg) continue;
|
|
|
|
|
2009-12-17 04:05:12 +01:00
|
|
|
r = IStream_Stat( stream->stm, &stat, 0 );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
WARN("failed to stat stream r = %08x!\n", r);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-10-19 11:27:44 +02:00
|
|
|
if( !strcmpW( name, stat.pwcsName ) )
|
2009-12-17 04:05:12 +01:00
|
|
|
{
|
|
|
|
TRACE("found %s\n", debugstr_w(name));
|
|
|
|
*stm = stream->stm;
|
|
|
|
CoTaskMemFree( stat.pwcsName );
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoTaskMemFree( stat.pwcsName );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2011-05-06 14:40:48 +02:00
|
|
|
UINT msi_clone_open_stream( MSIDATABASE *db, IStorage *stg, LPCWSTR name, IStream **stm )
|
2009-12-17 04:05:12 +01:00
|
|
|
{
|
|
|
|
IStream *stream;
|
|
|
|
|
2011-05-06 14:40:48 +02:00
|
|
|
if (find_open_stream( db, stg, name, &stream ) == ERROR_SUCCESS)
|
2009-12-17 04:05:12 +01:00
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
LARGE_INTEGER pos;
|
|
|
|
|
|
|
|
r = IStream_Clone( stream, stm );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
WARN("failed to clone stream r = %08x!\n", r);
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
r = IStream_Seek( *stm, pos, STREAM_SEEK_SET, NULL );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
IStream_Release( *stm );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2011-05-06 14:40:48 +02:00
|
|
|
UINT msi_get_raw_stream( MSIDATABASE *db, LPCWSTR stname, IStream **stm )
|
2009-12-17 04:05:12 +01:00
|
|
|
{
|
|
|
|
HRESULT r;
|
2011-05-06 14:40:48 +02:00
|
|
|
IStorage *stg;
|
2010-07-21 09:47:39 +02:00
|
|
|
WCHAR decoded[MAX_STREAM_NAME_LEN];
|
2009-12-17 04:05:12 +01:00
|
|
|
|
2010-07-21 09:47:39 +02:00
|
|
|
decode_streamname( stname, decoded );
|
|
|
|
TRACE("%s -> %s\n", debugstr_w(stname), debugstr_w(decoded));
|
2009-12-17 04:05:12 +01:00
|
|
|
|
2011-05-06 14:40:48 +02:00
|
|
|
if (msi_clone_open_stream( db, db->storage, stname, stm ) == ERROR_SUCCESS)
|
2009-12-17 04:05:12 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2010-02-19 12:26:30 +01:00
|
|
|
r = IStorage_OpenStream( db->storage, stname, NULL,
|
2009-12-17 04:05:12 +01:00
|
|
|
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, stm );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
MSITRANSFORM *transform;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( transform, &db->transforms, MSITRANSFORM, entry )
|
|
|
|
{
|
2010-02-19 12:26:30 +01:00
|
|
|
r = IStorage_OpenStream( transform->stg, stname, NULL,
|
2009-12-17 04:05:12 +01:00
|
|
|
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, stm );
|
|
|
|
if (SUCCEEDED(r))
|
2011-05-06 14:40:48 +02:00
|
|
|
{
|
|
|
|
stg = transform->stg;
|
2009-12-17 04:05:12 +01:00
|
|
|
break;
|
2011-05-06 14:40:48 +02:00
|
|
|
}
|
2009-12-17 04:05:12 +01:00
|
|
|
}
|
|
|
|
}
|
2011-05-06 14:40:48 +02:00
|
|
|
else stg = db->storage;
|
2009-12-17 04:05:12 +01:00
|
|
|
|
|
|
|
if( SUCCEEDED(r) )
|
|
|
|
{
|
|
|
|
MSISTREAM *stream;
|
|
|
|
|
2011-05-06 14:40:48 +02:00
|
|
|
if (!(stream = msi_alloc( sizeof(MSISTREAM) ))) return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
stream->stg = stg;
|
2012-07-27 14:03:12 +02:00
|
|
|
IStorage_AddRef( stg );
|
2009-12-17 04:05:12 +01:00
|
|
|
stream->stm = *stm;
|
|
|
|
IStream_AddRef( *stm );
|
|
|
|
list_add_tail( &db->streams, &stream->entry );
|
|
|
|
}
|
|
|
|
|
2009-12-18 11:03:03 +01:00
|
|
|
return SUCCEEDED(r) ? ERROR_SUCCESS : ERROR_FUNCTION_FAILED;
|
2009-12-17 04:05:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void free_transforms( MSIDATABASE *db )
|
|
|
|
{
|
|
|
|
while( !list_empty( &db->transforms ) )
|
|
|
|
{
|
|
|
|
MSITRANSFORM *t = LIST_ENTRY( list_head( &db->transforms ),
|
|
|
|
MSITRANSFORM, entry );
|
|
|
|
list_remove( &t->entry );
|
|
|
|
IStorage_Release( t->stg );
|
|
|
|
msi_free( t );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 14:40:48 +02:00
|
|
|
void msi_destroy_stream( MSIDATABASE *db, const WCHAR *stname )
|
2010-03-23 11:48:23 +01:00
|
|
|
{
|
|
|
|
MSISTREAM *stream, *stream2;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( stream, stream2, &db->streams, MSISTREAM, entry )
|
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
STATSTG stat;
|
|
|
|
|
|
|
|
r = IStream_Stat( stream->stm, &stat, 0 );
|
|
|
|
if (FAILED(r))
|
|
|
|
{
|
|
|
|
WARN("failed to stat stream r = %08x\n", r);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmpW( stname, stat.pwcsName ))
|
|
|
|
{
|
|
|
|
TRACE("destroying %s\n", debugstr_w(stname));
|
|
|
|
|
|
|
|
list_remove( &stream->entry );
|
|
|
|
IStream_Release( stream->stm );
|
2012-07-27 14:03:12 +02:00
|
|
|
IStorage_Release( stream->stg );
|
2011-05-06 14:40:48 +02:00
|
|
|
IStorage_DestroyElement( stream->stg, stname );
|
2010-03-23 11:48:23 +01:00
|
|
|
msi_free( stream );
|
|
|
|
CoTaskMemFree( stat.pwcsName );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
CoTaskMemFree( stat.pwcsName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-17 04:05:12 +01:00
|
|
|
static void free_streams( MSIDATABASE *db )
|
|
|
|
{
|
|
|
|
while( !list_empty( &db->streams ) )
|
|
|
|
{
|
2011-05-06 14:40:48 +02:00
|
|
|
MSISTREAM *s = LIST_ENTRY(list_head( &db->streams ), MSISTREAM, entry);
|
2009-12-17 04:05:12 +01:00
|
|
|
list_remove( &s->entry );
|
|
|
|
IStream_Release( s->stm );
|
2012-07-27 14:03:12 +02:00
|
|
|
IStorage_Release( s->stg );
|
2009-12-17 04:05:12 +01:00
|
|
|
msi_free( s );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-19 12:25:38 +01:00
|
|
|
void append_storage_to_db( MSIDATABASE *db, IStorage *stg )
|
|
|
|
{
|
|
|
|
MSITRANSFORM *t;
|
|
|
|
|
|
|
|
t = msi_alloc( sizeof *t );
|
|
|
|
t->stg = stg;
|
|
|
|
IStorage_AddRef( stg );
|
2010-07-21 09:47:18 +02:00
|
|
|
list_add_head( &db->transforms, &t->entry );
|
2010-02-19 12:25:38 +01:00
|
|
|
|
|
|
|
/* the transform may add or replace streams */
|
|
|
|
free_streams( db );
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:30:28 +02:00
|
|
|
static VOID MSI_CloseDatabase( MSIOBJECTHDR *arg )
|
2005-03-29 13:28:57 +02:00
|
|
|
{
|
|
|
|
MSIDATABASE *db = (MSIDATABASE *) arg;
|
|
|
|
|
2006-09-26 05:03:31 +02:00
|
|
|
msi_free(db->path);
|
2005-03-29 13:28:57 +02:00
|
|
|
free_cached_tables( db );
|
2009-12-17 04:05:12 +01:00
|
|
|
free_streams( db );
|
|
|
|
free_transforms( db );
|
2010-09-17 15:20:07 +02:00
|
|
|
if (db->strings) msi_destroy_stringtable( db->strings );
|
2006-10-23 18:11:30 +02:00
|
|
|
IStorage_Release( db->storage );
|
2006-09-12 17:47:10 +02:00
|
|
|
if (db->deletefile)
|
|
|
|
{
|
|
|
|
DeleteFileW( db->deletefile );
|
|
|
|
msi_free( db->deletefile );
|
2009-10-20 14:09:53 +02:00
|
|
|
}
|
2005-03-29 13:28:57 +02:00
|
|
|
}
|
|
|
|
|
2010-08-27 10:50:35 +02:00
|
|
|
static HRESULT db_initialize( IStorage *stg, const GUID *clsid )
|
|
|
|
{
|
|
|
|
static const WCHAR szTables[] = { '_','T','a','b','l','e','s',0 };
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IStorage_SetClass( stg, clsid );
|
|
|
|
if (FAILED( hr ))
|
|
|
|
{
|
|
|
|
WARN("failed to set class id 0x%08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the _Tables stream */
|
|
|
|
hr = write_stream_data( stg, szTables, NULL, 0, TRUE );
|
|
|
|
if (FAILED( hr ))
|
|
|
|
{
|
|
|
|
WARN("failed to create _Tables stream 0x%08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = msi_init_string_table( stg );
|
|
|
|
if (FAILED( hr ))
|
|
|
|
{
|
|
|
|
WARN("failed to initialize string table 0x%08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IStorage_Commit( stg, 0 );
|
|
|
|
if (FAILED( hr ))
|
|
|
|
{
|
|
|
|
WARN("failed to commit changes 0x%08x\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-03-29 13:28:57 +02:00
|
|
|
UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb)
|
|
|
|
{
|
|
|
|
IStorage *stg = NULL;
|
|
|
|
HRESULT r;
|
|
|
|
MSIDATABASE *db = NULL;
|
|
|
|
UINT ret = ERROR_FUNCTION_FAILED;
|
2006-09-26 05:03:31 +02:00
|
|
|
LPCWSTR szMode, save_path;
|
2005-03-29 13:28:57 +02:00
|
|
|
STATSTG stat;
|
2010-04-19 12:38:51 +02:00
|
|
|
BOOL created = FALSE, patch = FALSE;
|
2006-09-26 05:03:31 +02:00
|
|
|
WCHAR path[MAX_PATH];
|
|
|
|
|
2005-03-29 13:28:57 +02:00
|
|
|
TRACE("%s %s\n",debugstr_w(szDBPath),debugstr_w(szPersist) );
|
|
|
|
|
|
|
|
if( !pdb )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2008-07-08 07:05:31 +02:00
|
|
|
if (szPersist - MSIDBOPEN_PATCHFILE >= MSIDBOPEN_READONLY &&
|
|
|
|
szPersist - MSIDBOPEN_PATCHFILE <= MSIDBOPEN_CREATEDIRECT)
|
|
|
|
{
|
|
|
|
TRACE("Database is a patch\n");
|
|
|
|
szPersist -= MSIDBOPEN_PATCHFILE;
|
2010-04-19 12:38:51 +02:00
|
|
|
patch = TRUE;
|
2008-07-08 07:05:31 +02:00
|
|
|
}
|
|
|
|
|
2006-09-26 05:03:31 +02:00
|
|
|
save_path = szDBPath;
|
2005-05-31 11:30:28 +02:00
|
|
|
szMode = szPersist;
|
2010-01-29 15:01:17 +01:00
|
|
|
if( !IS_INTMSIDBOPEN(szPersist) )
|
2005-03-29 13:28:57 +02:00
|
|
|
{
|
2006-09-12 17:47:10 +02:00
|
|
|
if (!CopyFileW( szDBPath, szPersist, FALSE ))
|
|
|
|
return ERROR_OPEN_FAILED;
|
|
|
|
|
|
|
|
szDBPath = szPersist;
|
|
|
|
szPersist = MSIDBOPEN_TRANSACT;
|
|
|
|
created = TRUE;
|
2005-03-29 13:28:57 +02:00
|
|
|
}
|
2006-09-12 17:47:10 +02:00
|
|
|
|
|
|
|
if( szPersist == MSIDBOPEN_READONLY )
|
2005-03-29 13:28:57 +02:00
|
|
|
{
|
|
|
|
r = StgOpenStorage( szDBPath, NULL,
|
|
|
|
STGM_DIRECT|STGM_READ|STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
|
|
|
|
}
|
2010-08-27 10:50:35 +02:00
|
|
|
else if( szPersist == MSIDBOPEN_CREATE )
|
2005-03-29 13:28:57 +02:00
|
|
|
{
|
2010-08-27 10:50:35 +02:00
|
|
|
r = StgCreateDocfile( szDBPath,
|
|
|
|
STGM_CREATE|STGM_TRANSACTED|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &stg );
|
|
|
|
|
2010-08-27 10:50:20 +02:00
|
|
|
if( SUCCEEDED(r) )
|
2010-08-27 10:50:35 +02:00
|
|
|
r = db_initialize( stg, patch ? &CLSID_MsiPatch : &CLSID_MsiDatabase );
|
|
|
|
created = TRUE;
|
|
|
|
}
|
|
|
|
else if( szPersist == MSIDBOPEN_CREATEDIRECT )
|
|
|
|
{
|
|
|
|
r = StgCreateDocfile( szDBPath,
|
|
|
|
STGM_CREATE|STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &stg );
|
|
|
|
|
|
|
|
if( SUCCEEDED(r) )
|
|
|
|
r = db_initialize( stg, patch ? &CLSID_MsiPatch : &CLSID_MsiDatabase );
|
2006-09-12 17:47:10 +02:00
|
|
|
created = TRUE;
|
2005-03-29 13:28:57 +02:00
|
|
|
}
|
|
|
|
else if( szPersist == MSIDBOPEN_TRANSACT )
|
2006-08-09 19:16:27 +02:00
|
|
|
{
|
|
|
|
r = StgOpenStorage( szDBPath, NULL,
|
2011-07-25 15:58:01 +02:00
|
|
|
STGM_TRANSACTED|STGM_READWRITE|STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
|
2006-08-09 19:16:27 +02:00
|
|
|
}
|
|
|
|
else if( szPersist == MSIDBOPEN_DIRECT )
|
2005-03-29 13:28:57 +02:00
|
|
|
{
|
|
|
|
r = StgOpenStorage( szDBPath, NULL,
|
|
|
|
STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, NULL, 0, &stg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("unknown flag %p\n",szPersist);
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2006-12-05 12:44:09 +01:00
|
|
|
if( FAILED( r ) || !stg )
|
2005-03-29 13:28:57 +02:00
|
|
|
{
|
2011-08-23 14:41:27 +02:00
|
|
|
WARN("open failed r = %08x for %s\n", r, debugstr_w(szDBPath));
|
2005-03-29 13:28:57 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = IStorage_Stat( stg, &stat, STATFLAG_NONAME );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
FIXME("Failed to stat storage\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2005-09-14 12:07:26 +02:00
|
|
|
if ( !IsEqualGUID( &stat.clsid, &CLSID_MsiDatabase ) &&
|
2009-06-30 13:20:38 +02:00
|
|
|
!IsEqualGUID( &stat.clsid, &CLSID_MsiPatch ) &&
|
|
|
|
!IsEqualGUID( &stat.clsid, &CLSID_MsiTransform ) )
|
2005-03-29 13:28:57 +02:00
|
|
|
{
|
|
|
|
ERR("storage GUID is not a MSI database GUID %s\n",
|
|
|
|
debugstr_guid(&stat.clsid) );
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2010-04-19 12:38:51 +02:00
|
|
|
if ( patch && !IsEqualGUID( &stat.clsid, &CLSID_MsiPatch ) )
|
|
|
|
{
|
|
|
|
ERR("storage GUID is not the MSI patch GUID %s\n",
|
|
|
|
debugstr_guid(&stat.clsid) );
|
|
|
|
ret = ERROR_OPEN_FAILED;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2005-03-29 13:28:57 +02:00
|
|
|
db = alloc_msiobject( MSIHANDLETYPE_DATABASE, sizeof (MSIDATABASE),
|
|
|
|
MSI_CloseDatabase );
|
|
|
|
if( !db )
|
|
|
|
{
|
|
|
|
FIXME("Failed to allocate a handle\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2006-09-26 05:03:31 +02:00
|
|
|
if (!strchrW( save_path, '\\' ))
|
|
|
|
{
|
|
|
|
GetCurrentDirectoryW( MAX_PATH, path );
|
2009-10-15 12:46:27 +02:00
|
|
|
lstrcatW( path, szBackSlash );
|
2006-09-26 05:03:31 +02:00
|
|
|
lstrcatW( path, save_path );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
lstrcpyW( path, save_path );
|
|
|
|
|
|
|
|
db->path = strdupW( path );
|
2011-03-22 20:45:09 +01:00
|
|
|
db->media_transform_offset = MSI_INITIAL_MEDIA_TRANSFORM_OFFSET;
|
2011-04-14 14:42:48 +02:00
|
|
|
db->media_transform_disk_id = MSI_INITIAL_MEDIA_TRANSFORM_DISKID;
|
2011-03-22 20:45:09 +01:00
|
|
|
|
2005-03-29 13:28:57 +02:00
|
|
|
if( TRACE_ON( msi ) )
|
|
|
|
enum_stream_names( stg );
|
|
|
|
|
|
|
|
db->storage = stg;
|
|
|
|
db->mode = szMode;
|
2006-09-12 17:47:10 +02:00
|
|
|
if (created)
|
|
|
|
db->deletefile = strdupW( szDBPath );
|
2005-09-14 12:07:26 +02:00
|
|
|
list_init( &db->tables );
|
2005-10-27 14:25:04 +02:00
|
|
|
list_init( &db->transforms );
|
2009-12-16 11:11:19 +01:00
|
|
|
list_init( &db->streams );
|
2005-03-29 13:28:57 +02:00
|
|
|
|
2007-06-08 01:41:51 +02:00
|
|
|
db->strings = msi_load_string_table( stg, &db->bytes_per_strref );
|
2005-09-16 21:01:40 +02:00
|
|
|
if( !db->strings )
|
2005-03-29 13:28:57 +02:00
|
|
|
goto end;
|
|
|
|
|
2005-09-16 21:01:40 +02:00
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
|
2005-03-29 13:28:57 +02:00
|
|
|
msiobj_addref( &db->hdr );
|
|
|
|
IStorage_AddRef( stg );
|
|
|
|
*pdb = db;
|
|
|
|
|
|
|
|
end:
|
|
|
|
if( db )
|
|
|
|
msiobj_release( &db->hdr );
|
|
|
|
if( stg )
|
|
|
|
IStorage_Release( stg );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiOpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIHANDLE *phDB)
|
|
|
|
{
|
|
|
|
MSIDATABASE *db;
|
|
|
|
UINT ret;
|
|
|
|
|
|
|
|
TRACE("%s %s %p\n",debugstr_w(szDBPath),debugstr_w(szPersist), phDB);
|
|
|
|
|
|
|
|
ret = MSI_OpenDatabaseW( szDBPath, szPersist, &db );
|
|
|
|
if( ret == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
*phDB = alloc_msihandle( &db->hdr );
|
2006-08-28 18:44:35 +02:00
|
|
|
if (! *phDB)
|
|
|
|
ret = ERROR_NOT_ENOUGH_MEMORY;
|
2005-03-29 13:28:57 +02:00
|
|
|
msiobj_release( &db->hdr );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiOpenDatabaseA(LPCSTR szDBPath, LPCSTR szPersist, MSIHANDLE *phDB)
|
|
|
|
{
|
|
|
|
HRESULT r = ERROR_FUNCTION_FAILED;
|
|
|
|
LPWSTR szwDBPath = NULL, szwPersist = NULL;
|
|
|
|
|
|
|
|
TRACE("%s %s %p\n", debugstr_a(szDBPath), debugstr_a(szPersist), phDB);
|
|
|
|
|
|
|
|
if( szDBPath )
|
|
|
|
{
|
|
|
|
szwDBPath = strdupAtoW( szDBPath );
|
|
|
|
if( !szwDBPath )
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2010-01-29 15:01:17 +01:00
|
|
|
if( !IS_INTMSIDBOPEN(szPersist) )
|
2005-03-29 13:28:57 +02:00
|
|
|
{
|
|
|
|
szwPersist = strdupAtoW( szPersist );
|
|
|
|
if( !szwPersist )
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
else
|
2006-05-25 04:41:39 +02:00
|
|
|
szwPersist = (LPWSTR)(DWORD_PTR)szPersist;
|
2005-03-29 13:28:57 +02:00
|
|
|
|
|
|
|
r = MsiOpenDatabaseW( szwDBPath, szwPersist, phDB );
|
|
|
|
|
|
|
|
end:
|
2010-01-29 15:01:17 +01:00
|
|
|
if( !IS_INTMSIDBOPEN(szPersist) )
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( szwPersist );
|
|
|
|
msi_free( szwDBPath );
|
2005-03-29 13:28:57 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-05-12 17:23:27 +02:00
|
|
|
static LPWSTR msi_read_text_archive(LPCWSTR path, DWORD *len)
|
2005-03-29 13:28:57 +02:00
|
|
|
{
|
2006-09-28 21:58:16 +02:00
|
|
|
HANDLE file;
|
|
|
|
LPSTR data = NULL;
|
|
|
|
LPWSTR wdata = NULL;
|
|
|
|
DWORD read, size = 0;
|
|
|
|
|
|
|
|
file = CreateFileW( path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
|
|
|
|
if (file == INVALID_HANDLE_VALUE)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size = GetFileSize( file, NULL );
|
2011-05-12 17:23:27 +02:00
|
|
|
if (!(data = msi_alloc( size ))) goto done;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2011-05-12 17:23:27 +02:00
|
|
|
if (!ReadFile( file, data, size, &read, NULL ) || read != size) goto done;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2011-05-12 17:23:27 +02:00
|
|
|
while (!data[size - 1]) size--;
|
|
|
|
*len = MultiByteToWideChar( CP_ACP, 0, data, size, NULL, 0 );
|
|
|
|
if ((wdata = msi_alloc( (*len + 1) * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, data, size, wdata, *len );
|
|
|
|
wdata[*len] = 0;
|
|
|
|
}
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
CloseHandle( file );
|
|
|
|
msi_free( data );
|
|
|
|
return wdata;
|
|
|
|
}
|
|
|
|
|
2011-05-12 17:23:27 +02:00
|
|
|
static void msi_parse_line(LPWSTR *line, LPWSTR **entries, DWORD *num_entries, DWORD *len)
|
2006-09-28 21:58:16 +02:00
|
|
|
{
|
|
|
|
LPWSTR ptr = *line, save;
|
2011-05-12 17:23:27 +02:00
|
|
|
DWORD i, count = 1, chars_left = *len;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
*entries = NULL;
|
|
|
|
|
|
|
|
/* stay on this line */
|
2011-05-12 17:23:27 +02:00
|
|
|
while (chars_left && *ptr != '\n')
|
2006-09-28 21:58:16 +02:00
|
|
|
{
|
|
|
|
/* entries are separated by tabs */
|
|
|
|
if (*ptr == '\t')
|
|
|
|
count++;
|
|
|
|
|
|
|
|
ptr++;
|
2011-05-12 17:23:27 +02:00
|
|
|
chars_left--;
|
2006-09-28 21:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*entries = msi_alloc(count * sizeof(LPWSTR));
|
|
|
|
if (!*entries)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* store pointers into the data */
|
2011-05-12 17:23:27 +02:00
|
|
|
chars_left = *len;
|
2006-09-28 21:58:16 +02:00
|
|
|
for (i = 0, ptr = *line; i < count; i++)
|
|
|
|
{
|
2011-05-12 17:23:27 +02:00
|
|
|
while (chars_left && *ptr == '\r')
|
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
chars_left--;
|
|
|
|
}
|
2006-09-28 21:58:16 +02:00
|
|
|
save = ptr;
|
|
|
|
|
2011-05-12 17:23:27 +02:00
|
|
|
while (chars_left && *ptr != '\t' && *ptr != '\n' && *ptr != '\r')
|
|
|
|
{
|
|
|
|
if (!*ptr) *ptr = '\n'; /* convert embedded nulls to \n */
|
2011-05-12 17:24:11 +02:00
|
|
|
if (ptr > *line && *ptr == '\x19' && *(ptr - 1) == '\x11')
|
|
|
|
{
|
|
|
|
*ptr = '\n';
|
|
|
|
*(ptr - 1) = '\r';
|
|
|
|
}
|
2011-05-12 17:23:27 +02:00
|
|
|
ptr++;
|
|
|
|
chars_left--;
|
|
|
|
}
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
/* NULL-separate the data */
|
2008-02-12 08:37:56 +01:00
|
|
|
if (*ptr == '\n' || *ptr == '\r')
|
|
|
|
{
|
2011-05-12 17:23:27 +02:00
|
|
|
while (chars_left && (*ptr == '\n' || *ptr == '\r'))
|
|
|
|
{
|
|
|
|
*(ptr++) = 0;
|
|
|
|
chars_left--;
|
|
|
|
}
|
2008-02-12 08:37:56 +01:00
|
|
|
}
|
|
|
|
else if (*ptr)
|
2011-05-12 17:23:27 +02:00
|
|
|
{
|
|
|
|
*(ptr++) = 0;
|
|
|
|
chars_left--;
|
|
|
|
}
|
2006-09-28 21:58:16 +02:00
|
|
|
(*entries)[i] = save;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* move to the next line if there's more, else EOF */
|
|
|
|
*line = ptr;
|
2011-05-12 17:23:27 +02:00
|
|
|
*len = chars_left;
|
2006-09-28 21:58:16 +02:00
|
|
|
if (num_entries)
|
|
|
|
*num_entries = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR msi_build_createsql_prelude(LPWSTR table)
|
|
|
|
{
|
|
|
|
LPWSTR prelude;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
static const WCHAR create_fmt[] = {'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','%','s','`',' ','(',' ',0};
|
|
|
|
|
2008-02-27 17:47:51 +01:00
|
|
|
size = sizeof(create_fmt)/sizeof(create_fmt[0]) + lstrlenW(table) - 2;
|
2006-09-28 21:58:16 +02:00
|
|
|
prelude = msi_alloc(size * sizeof(WCHAR));
|
|
|
|
if (!prelude)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sprintfW(prelude, create_fmt, table);
|
|
|
|
return prelude;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR msi_build_createsql_columns(LPWSTR *columns_data, LPWSTR *types, DWORD num_columns)
|
|
|
|
{
|
2007-12-30 19:01:09 +01:00
|
|
|
LPWSTR columns, p;
|
2006-09-28 21:58:16 +02:00
|
|
|
LPCWSTR type;
|
|
|
|
DWORD sql_size = 1, i, len;
|
|
|
|
WCHAR expanded[128], *ptr;
|
2006-10-24 03:07:04 +02:00
|
|
|
WCHAR size[10], comma[2], extra[30];
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
static const WCHAR column_fmt[] = {'`','%','s','`',' ','%','s','%','s','%','s','%','s',' ',0};
|
|
|
|
static const WCHAR size_fmt[] = {'(','%','s',')',0};
|
|
|
|
static const WCHAR type_char[] = {'C','H','A','R',0};
|
|
|
|
static const WCHAR type_int[] = {'I','N','T',0};
|
|
|
|
static const WCHAR type_long[] = {'L','O','N','G',0};
|
2009-05-26 22:31:45 +02:00
|
|
|
static const WCHAR type_object[] = {'O','B','J','E','C','T',0};
|
2006-09-28 21:58:16 +02:00
|
|
|
static const WCHAR type_notnull[] = {' ','N','O','T',' ','N','U','L','L',0};
|
2006-10-24 03:07:04 +02:00
|
|
|
static const WCHAR localizable[] = {' ','L','O','C','A','L','I','Z','A','B','L','E',0};
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
columns = msi_alloc_zero(sql_size * sizeof(WCHAR));
|
|
|
|
if (!columns)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < num_columns; i++)
|
|
|
|
{
|
|
|
|
type = NULL;
|
|
|
|
comma[1] = size[0] = extra[0] = '\0';
|
|
|
|
|
|
|
|
if (i == num_columns - 1)
|
|
|
|
comma[0] = '\0';
|
|
|
|
else
|
|
|
|
comma[0] = ',';
|
|
|
|
|
|
|
|
ptr = &types[i][1];
|
|
|
|
len = atolW(ptr);
|
2006-10-24 03:07:04 +02:00
|
|
|
extra[0] = '\0';
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
switch (types[i][0])
|
|
|
|
{
|
2006-10-24 03:07:04 +02:00
|
|
|
case 'l':
|
2006-09-28 21:58:16 +02:00
|
|
|
lstrcpyW(extra, type_notnull);
|
2011-10-06 23:29:46 +02:00
|
|
|
/* fall through */
|
2006-10-24 03:07:04 +02:00
|
|
|
case 'L':
|
|
|
|
lstrcatW(extra, localizable);
|
|
|
|
type = type_char;
|
|
|
|
sprintfW(size, size_fmt, ptr);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
lstrcpyW(extra, type_notnull);
|
2011-10-06 23:29:46 +02:00
|
|
|
/* fall through */
|
2006-10-24 03:07:04 +02:00
|
|
|
case 'S':
|
2006-09-28 21:58:16 +02:00
|
|
|
type = type_char;
|
|
|
|
sprintfW(size, size_fmt, ptr);
|
|
|
|
break;
|
2006-10-20 02:46:17 +02:00
|
|
|
case 'i':
|
|
|
|
lstrcpyW(extra, type_notnull);
|
2011-10-06 23:29:46 +02:00
|
|
|
/* fall through */
|
2006-10-20 02:46:17 +02:00
|
|
|
case 'I':
|
2009-08-04 12:19:42 +02:00
|
|
|
if (len <= 2)
|
2006-09-28 21:58:16 +02:00
|
|
|
type = type_int;
|
2009-08-04 12:19:42 +02:00
|
|
|
else if (len == 4)
|
2006-09-28 21:58:16 +02:00
|
|
|
type = type_long;
|
2009-08-04 12:19:42 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("invalid int width %u\n", len);
|
|
|
|
msi_free(columns);
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-09-28 21:58:16 +02:00
|
|
|
break;
|
2009-05-26 22:31:45 +02:00
|
|
|
case 'v':
|
|
|
|
lstrcpyW(extra, type_notnull);
|
2011-10-06 23:29:46 +02:00
|
|
|
/* fall through */
|
2009-05-26 22:31:45 +02:00
|
|
|
case 'V':
|
|
|
|
type = type_object;
|
|
|
|
break;
|
2008-02-06 23:17:46 +01:00
|
|
|
default:
|
|
|
|
ERR("Unknown type: %c\n", types[i][0]);
|
|
|
|
msi_free(columns);
|
|
|
|
return NULL;
|
2006-09-28 21:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sprintfW(expanded, column_fmt, columns_data[i], type, size, extra, comma);
|
|
|
|
sql_size += lstrlenW(expanded);
|
|
|
|
|
2007-12-30 19:01:09 +01:00
|
|
|
p = msi_realloc(columns, sql_size * sizeof(WCHAR));
|
|
|
|
if (!p)
|
|
|
|
{
|
|
|
|
msi_free(columns);
|
2006-09-28 21:58:16 +02:00
|
|
|
return NULL;
|
2007-12-30 19:01:09 +01:00
|
|
|
}
|
|
|
|
columns = p;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
lstrcatW(columns, expanded);
|
|
|
|
}
|
|
|
|
|
|
|
|
return columns;
|
|
|
|
}
|
|
|
|
|
2006-10-20 02:30:13 +02:00
|
|
|
static LPWSTR msi_build_createsql_postlude(LPWSTR *primary_keys, DWORD num_keys)
|
2006-09-28 21:58:16 +02:00
|
|
|
{
|
2006-10-20 02:30:13 +02:00
|
|
|
LPWSTR postlude, keys, ptr;
|
|
|
|
DWORD size, key_size, i;
|
|
|
|
|
|
|
|
static const WCHAR key_fmt[] = {'`','%','s','`',',',' ',0};
|
2007-04-23 09:23:13 +02:00
|
|
|
static const WCHAR postlude_fmt[] = {'P','R','I','M','A','R','Y',' ','K','E','Y',' ','%','s',')',0};
|
2006-10-20 02:30:13 +02:00
|
|
|
|
|
|
|
for (i = 0, size = 1; i < num_keys; i++)
|
|
|
|
size += lstrlenW(key_fmt) + lstrlenW(primary_keys[i]) - 2;
|
|
|
|
|
|
|
|
keys = msi_alloc(size * sizeof(WCHAR));
|
|
|
|
if (!keys)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0, ptr = keys; i < num_keys; i++)
|
|
|
|
{
|
|
|
|
key_size = lstrlenW(key_fmt) + lstrlenW(primary_keys[i]) -2;
|
|
|
|
sprintfW(ptr, key_fmt, primary_keys[i]);
|
|
|
|
ptr += key_size;
|
|
|
|
}
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2006-10-20 02:30:13 +02:00
|
|
|
/* remove final ', ' */
|
|
|
|
*(ptr - 2) = '\0';
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2006-10-20 02:30:13 +02:00
|
|
|
size = lstrlenW(postlude_fmt) + size - 1;
|
2006-09-28 21:58:16 +02:00
|
|
|
postlude = msi_alloc(size * sizeof(WCHAR));
|
|
|
|
if (!postlude)
|
2006-10-20 02:30:13 +02:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
sprintfW(postlude, postlude_fmt, keys);
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2006-10-20 02:30:13 +02:00
|
|
|
done:
|
|
|
|
msi_free(keys);
|
2006-09-28 21:58:16 +02:00
|
|
|
return postlude;
|
|
|
|
}
|
|
|
|
|
2006-10-20 02:30:13 +02:00
|
|
|
static UINT msi_add_table_to_db(MSIDATABASE *db, LPWSTR *columns, LPWSTR *types, LPWSTR *labels, DWORD num_labels, DWORD num_columns)
|
2006-09-28 21:58:16 +02:00
|
|
|
{
|
2009-12-16 03:19:25 +01:00
|
|
|
UINT r = ERROR_OUTOFMEMORY;
|
2006-09-28 21:58:16 +02:00
|
|
|
DWORD size;
|
|
|
|
MSIQUERY *view;
|
2009-12-16 03:19:25 +01:00
|
|
|
LPWSTR create_sql = NULL;
|
2006-09-28 21:58:16 +02:00
|
|
|
LPWSTR prelude, columns_sql, postlude;
|
|
|
|
|
|
|
|
prelude = msi_build_createsql_prelude(labels[0]);
|
|
|
|
columns_sql = msi_build_createsql_columns(columns, types, num_columns);
|
2006-10-20 02:30:13 +02:00
|
|
|
postlude = msi_build_createsql_postlude(labels + 1, num_labels - 1); /* skip over table name */
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
if (!prelude || !columns_sql || !postlude)
|
2009-12-16 03:19:25 +01:00
|
|
|
goto done;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
size = lstrlenW(prelude) + lstrlenW(columns_sql) + lstrlenW(postlude) + 1;
|
|
|
|
create_sql = msi_alloc(size * sizeof(WCHAR));
|
|
|
|
if (!create_sql)
|
2009-12-16 03:19:25 +01:00
|
|
|
goto done;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
lstrcpyW(create_sql, prelude);
|
|
|
|
lstrcatW(create_sql, columns_sql);
|
|
|
|
lstrcatW(create_sql, postlude);
|
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW( db, create_sql, &view );
|
|
|
|
if (r != ERROR_SUCCESS)
|
2009-12-16 03:19:25 +01:00
|
|
|
goto done;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
r = MSI_ViewExecute(view, NULL);
|
|
|
|
MSI_ViewClose(view);
|
|
|
|
msiobj_release(&view->hdr);
|
|
|
|
|
2009-12-16 03:19:25 +01:00
|
|
|
done:
|
|
|
|
msi_free(prelude);
|
|
|
|
msi_free(columns_sql);
|
|
|
|
msi_free(postlude);
|
|
|
|
msi_free(create_sql);
|
2006-09-28 21:58:16 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-05-26 22:31:45 +02:00
|
|
|
static LPWSTR msi_import_stream_filename(LPCWSTR path, LPCWSTR name)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
LPWSTR fullname, ptr;
|
|
|
|
|
|
|
|
len = lstrlenW(path) + lstrlenW(name) + 1;
|
|
|
|
fullname = msi_alloc(len*sizeof(WCHAR));
|
|
|
|
if (!fullname)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
lstrcpyW( fullname, path );
|
|
|
|
|
|
|
|
/* chop off extension from path */
|
|
|
|
ptr = strrchrW(fullname, '.');
|
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
msi_free (fullname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*ptr++ = '\\';
|
|
|
|
lstrcpyW( ptr, name );
|
|
|
|
return fullname;
|
|
|
|
}
|
|
|
|
|
2008-02-12 08:37:14 +01:00
|
|
|
static UINT construct_record(DWORD num_columns, LPWSTR *types,
|
2009-05-26 22:31:45 +02:00
|
|
|
LPWSTR *data, LPWSTR path, MSIRECORD **rec)
|
2006-09-28 21:58:16 +02:00
|
|
|
{
|
2008-02-12 08:37:14 +01:00
|
|
|
UINT i;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2008-02-12 08:37:14 +01:00
|
|
|
*rec = MSI_CreateRecord(num_columns);
|
|
|
|
if (!*rec)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
for (i = 0; i < num_columns; i++)
|
|
|
|
{
|
|
|
|
switch (types[i][0])
|
|
|
|
{
|
|
|
|
case 'L': case 'l': case 'S': case 's':
|
2008-02-12 08:37:14 +01:00
|
|
|
MSI_RecordSetStringW(*rec, i + 1, data[i]);
|
2006-09-28 21:58:16 +02:00
|
|
|
break;
|
|
|
|
case 'I': case 'i':
|
2008-02-12 08:37:14 +01:00
|
|
|
if (*data[i])
|
|
|
|
MSI_RecordSetInteger(*rec, i + 1, atoiW(data[i]));
|
2006-09-28 21:58:16 +02:00
|
|
|
break;
|
2009-05-26 22:31:45 +02:00
|
|
|
case 'V': case 'v':
|
|
|
|
if (*data[i])
|
|
|
|
{
|
|
|
|
UINT r;
|
|
|
|
LPWSTR file = msi_import_stream_filename(path, data[i]);
|
|
|
|
if (!file)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
r = MSI_RecordSetStreamFromFileW(*rec, i + 1, file);
|
|
|
|
msi_free (file);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
break;
|
2006-09-28 21:58:16 +02:00
|
|
|
default:
|
2008-02-12 08:37:14 +01:00
|
|
|
ERR("Unhandled column type: %c\n", types[i][0]);
|
|
|
|
msiobj_release(&(*rec)->hdr);
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2007-12-09 19:54:14 +01:00
|
|
|
}
|
2006-09-28 21:58:16 +02:00
|
|
|
}
|
|
|
|
|
2008-02-12 08:37:14 +01:00
|
|
|
return ERROR_SUCCESS;
|
2006-09-28 21:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT msi_add_records_to_table(MSIDATABASE *db, LPWSTR *columns, LPWSTR *types,
|
|
|
|
LPWSTR *labels, LPWSTR **records,
|
2009-05-26 22:31:45 +02:00
|
|
|
int num_columns, int num_records,
|
|
|
|
LPWSTR path)
|
2006-09-28 21:58:16 +02:00
|
|
|
{
|
2008-02-12 08:37:14 +01:00
|
|
|
UINT r;
|
2008-10-20 23:06:16 +02:00
|
|
|
int i;
|
2006-09-28 21:58:16 +02:00
|
|
|
MSIQUERY *view;
|
2008-02-12 08:37:14 +01:00
|
|
|
MSIRECORD *rec;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2008-02-12 08:37:14 +01:00
|
|
|
static const WCHAR select[] = {
|
|
|
|
'S','E','L','E','C','T',' ','*',' ',
|
|
|
|
'F','R','O','M',' ','`','%','s','`',0
|
|
|
|
};
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2008-10-09 05:42:50 +02:00
|
|
|
r = MSI_OpenQuery(db, &view, select, labels[0]);
|
2008-02-12 08:37:14 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2008-02-12 08:37:14 +01:00
|
|
|
while (MSI_ViewFetch(view, &rec) != ERROR_NO_MORE_ITEMS)
|
|
|
|
{
|
|
|
|
r = MSI_ViewModify(view, MSIMODIFY_DELETE, rec);
|
2009-12-14 04:36:09 +01:00
|
|
|
msiobj_release(&rec->hdr);
|
2008-02-12 08:37:14 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
}
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2008-02-12 08:37:14 +01:00
|
|
|
for (i = 0; i < num_records; i++)
|
|
|
|
{
|
2009-05-26 22:31:45 +02:00
|
|
|
r = construct_record(num_columns, types, records[i], path, &rec);
|
2008-02-12 08:37:14 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2008-02-12 08:37:14 +01:00
|
|
|
r = MSI_ViewModify(view, MSIMODIFY_INSERT, rec);
|
2006-09-28 21:58:16 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
2008-02-12 08:37:14 +01:00
|
|
|
{
|
|
|
|
msiobj_release(&rec->hdr);
|
2006-09-28 21:58:16 +02:00
|
|
|
goto done;
|
2008-02-12 08:37:14 +01:00
|
|
|
}
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2008-02-12 08:37:14 +01:00
|
|
|
msiobj_release(&rec->hdr);
|
2006-09-28 21:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2008-02-12 08:37:14 +01:00
|
|
|
msiobj_release(&view->hdr);
|
2006-09-28 21:58:16 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-01-10 15:20:03 +01:00
|
|
|
static UINT MSI_DatabaseImport(MSIDATABASE *db, LPCWSTR folder, LPCWSTR file)
|
2006-09-28 21:58:16 +02:00
|
|
|
{
|
|
|
|
UINT r;
|
|
|
|
DWORD len, i;
|
2008-02-12 08:37:56 +01:00
|
|
|
DWORD num_labels, num_types;
|
2006-09-28 21:58:16 +02:00
|
|
|
DWORD num_columns, num_records = 0;
|
|
|
|
LPWSTR *columns, *types, *labels;
|
|
|
|
LPWSTR path, ptr, data;
|
2008-02-12 08:37:56 +01:00
|
|
|
LPWSTR **records = NULL;
|
2007-12-09 19:54:14 +01:00
|
|
|
LPWSTR **temp_records;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2009-04-13 12:24:46 +02:00
|
|
|
static const WCHAR suminfo[] =
|
|
|
|
{'_','S','u','m','m','a','r','y','I','n','f','o','r','m','a','t','i','o','n',0};
|
2010-11-17 10:58:10 +01:00
|
|
|
static const WCHAR forcecodepage[] =
|
|
|
|
{'_','F','o','r','c','e','C','o','d','e','p','a','g','e',0};
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
TRACE("%p %s %s\n", db, debugstr_w(folder), debugstr_w(file) );
|
2005-03-29 13:28:57 +02:00
|
|
|
|
|
|
|
if( folder == NULL || file == NULL )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2009-10-15 12:46:27 +02:00
|
|
|
len = lstrlenW(folder) + lstrlenW(szBackSlash) + lstrlenW(file) + 1;
|
2006-09-28 21:58:16 +02:00
|
|
|
path = msi_alloc( len * sizeof(WCHAR) );
|
|
|
|
if (!path)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
lstrcpyW( path, folder );
|
2009-10-15 12:46:27 +02:00
|
|
|
lstrcatW( path, szBackSlash );
|
2006-09-28 21:58:16 +02:00
|
|
|
lstrcatW( path, file );
|
|
|
|
|
2011-05-12 17:23:27 +02:00
|
|
|
data = msi_read_text_archive( path, &len );
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
ptr = data;
|
2011-05-12 17:23:27 +02:00
|
|
|
msi_parse_line( &ptr, &columns, &num_columns, &len );
|
|
|
|
msi_parse_line( &ptr, &types, &num_types, &len );
|
|
|
|
msi_parse_line( &ptr, &labels, &num_labels, &len );
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2010-11-17 10:58:10 +01:00
|
|
|
if (num_columns == 1 && !columns[0][0] && num_labels == 1 && !labels[0][0] &&
|
|
|
|
num_types == 2 && !strcmpW( types[1], forcecodepage ))
|
|
|
|
{
|
|
|
|
r = msi_set_string_table_codepage( db->strings, atoiW( types[0] ) );
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2008-02-12 08:37:56 +01:00
|
|
|
if (num_columns != num_types)
|
|
|
|
{
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2006-09-28 21:58:16 +02:00
|
|
|
records = msi_alloc(sizeof(LPWSTR *));
|
|
|
|
if (!records)
|
2007-12-09 19:54:14 +01:00
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
/* read in the table records */
|
2011-05-12 17:23:27 +02:00
|
|
|
while (len)
|
2006-09-28 21:58:16 +02:00
|
|
|
{
|
2011-05-12 17:23:27 +02:00
|
|
|
msi_parse_line( &ptr, &records[num_records], NULL, &len );
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
num_records++;
|
2007-12-09 19:54:14 +01:00
|
|
|
temp_records = msi_realloc(records, (num_records + 1) * sizeof(LPWSTR *));
|
|
|
|
if (!temp_records)
|
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
records = temp_records;
|
2006-09-28 21:58:16 +02:00
|
|
|
}
|
|
|
|
|
2009-04-13 12:24:46 +02:00
|
|
|
if (!strcmpW(labels[0], suminfo))
|
2008-02-12 08:37:14 +01:00
|
|
|
{
|
2009-04-13 12:24:46 +02:00
|
|
|
r = msi_add_suminfo( db, records, num_records, num_columns );
|
2008-02-12 08:37:14 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2009-04-13 12:24:46 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!TABLE_Exists(db, labels[0]))
|
|
|
|
{
|
|
|
|
r = msi_add_table_to_db( db, columns, types, labels, num_labels, num_columns );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2006-09-28 21:58:16 +02:00
|
|
|
|
2009-05-26 22:31:45 +02:00
|
|
|
r = msi_add_records_to_table( db, columns, types, labels, records, num_columns, num_records, path );
|
2009-04-13 12:24:46 +02:00
|
|
|
}
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
msi_free(path);
|
|
|
|
msi_free(data);
|
|
|
|
msi_free(columns);
|
|
|
|
msi_free(types);
|
2006-10-10 08:20:39 +02:00
|
|
|
msi_free(labels);
|
2006-09-28 21:58:16 +02:00
|
|
|
|
|
|
|
for (i = 0; i < num_records; i++)
|
|
|
|
msi_free(records[i]);
|
|
|
|
|
|
|
|
msi_free(records);
|
|
|
|
|
|
|
|
return r;
|
2005-03-29 13:28:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiDatabaseImportW(MSIHANDLE handle, LPCWSTR szFolder, LPCWSTR szFilename)
|
|
|
|
{
|
|
|
|
MSIDATABASE *db;
|
|
|
|
UINT r;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%x %s %s\n",handle,debugstr_w(szFolder), debugstr_w(szFilename));
|
2005-03-29 13:28:57 +02:00
|
|
|
|
|
|
|
db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
|
|
|
|
if( !db )
|
2007-11-12 01:13:08 +01:00
|
|
|
{
|
|
|
|
IWineMsiRemoteDatabase *remote_database;
|
|
|
|
|
|
|
|
remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
|
|
|
|
if ( !remote_database )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
IWineMsiRemoteDatabase_Release( remote_database );
|
|
|
|
WARN("MsiDatabaseImport not allowed during a custom action!\n");
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-03-29 13:28:57 +02:00
|
|
|
r = MSI_DatabaseImport( db, szFolder, szFilename );
|
|
|
|
msiobj_release( &db->hdr );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiDatabaseImportA( MSIHANDLE handle,
|
|
|
|
LPCSTR szFolder, LPCSTR szFilename )
|
|
|
|
{
|
|
|
|
LPWSTR path = NULL, file = NULL;
|
|
|
|
UINT r = ERROR_OUTOFMEMORY;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%x %s %s\n", handle, debugstr_a(szFolder), debugstr_a(szFilename));
|
2005-03-29 13:28:57 +02:00
|
|
|
|
|
|
|
if( szFolder )
|
|
|
|
{
|
|
|
|
path = strdupAtoW( szFolder );
|
|
|
|
if( !path )
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( szFilename )
|
|
|
|
{
|
|
|
|
file = strdupAtoW( szFilename );
|
|
|
|
if( !file )
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = MsiDatabaseImportW( handle, path, file );
|
|
|
|
|
|
|
|
end:
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( path );
|
|
|
|
msi_free( file );
|
2005-03-29 13:28:57 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-08-31 12:52:03 +02:00
|
|
|
static UINT msi_export_record( HANDLE handle, MSIRECORD *row, UINT start )
|
|
|
|
{
|
|
|
|
UINT i, count, len, r = ERROR_SUCCESS;
|
|
|
|
const char *sep;
|
|
|
|
char *buffer;
|
|
|
|
DWORD sz;
|
|
|
|
|
|
|
|
len = 0x100;
|
|
|
|
buffer = msi_alloc( len );
|
|
|
|
if ( !buffer )
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
count = MSI_RecordGetFieldCount( row );
|
|
|
|
for ( i=start; i<=count; i++ )
|
|
|
|
{
|
|
|
|
sz = len;
|
|
|
|
r = MSI_RecordGetStringA( row, i, buffer, &sz );
|
|
|
|
if (r == ERROR_MORE_DATA)
|
|
|
|
{
|
|
|
|
char *p = msi_realloc( buffer, sz + 1 );
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
len = sz + 1;
|
|
|
|
buffer = p;
|
|
|
|
}
|
|
|
|
sz = len;
|
|
|
|
r = MSI_RecordGetStringA( row, i, buffer, &sz );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!WriteFile( handle, buffer, sz, &sz, NULL ))
|
|
|
|
{
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sep = (i < count) ? "\t" : "\r\n";
|
|
|
|
if (!WriteFile( handle, sep, strlen(sep), &sz, NULL ))
|
|
|
|
{
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msi_free( buffer );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT msi_export_row( MSIRECORD *row, void *arg )
|
|
|
|
{
|
|
|
|
return msi_export_record( arg, row, 1 );
|
|
|
|
}
|
|
|
|
|
2010-11-17 10:58:10 +01:00
|
|
|
static UINT msi_export_forcecodepage( HANDLE handle, UINT codepage )
|
2008-02-11 08:13:44 +01:00
|
|
|
{
|
2010-11-17 10:58:10 +01:00
|
|
|
static const char fmt[] = "\r\n\r\n%u\t_ForceCodepage\r\n";
|
|
|
|
char data[sizeof(fmt) + 10];
|
2008-02-11 08:13:44 +01:00
|
|
|
DWORD sz;
|
|
|
|
|
2010-11-17 10:58:10 +01:00
|
|
|
sprintf( data, fmt, codepage );
|
2008-02-11 08:13:44 +01:00
|
|
|
|
|
|
|
sz = lstrlenA(data) + 1;
|
|
|
|
if (!WriteFile(handle, data, sz, &sz, NULL))
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-01-10 15:20:03 +01:00
|
|
|
static UINT MSI_DatabaseExport( MSIDATABASE *db, LPCWSTR table,
|
2005-03-29 13:28:57 +02:00
|
|
|
LPCWSTR folder, LPCWSTR file )
|
|
|
|
{
|
2006-08-31 12:52:03 +02:00
|
|
|
static const WCHAR query[] = {
|
|
|
|
's','e','l','e','c','t',' ','*',' ','f','r','o','m',' ','%','s',0 };
|
2008-02-11 08:13:44 +01:00
|
|
|
static const WCHAR forcecodepage[] = {
|
|
|
|
'_','F','o','r','c','e','C','o','d','e','p','a','g','e',0 };
|
2006-08-31 12:52:03 +02:00
|
|
|
MSIRECORD *rec = NULL;
|
|
|
|
MSIQUERY *view = NULL;
|
|
|
|
LPWSTR filename;
|
|
|
|
HANDLE handle;
|
|
|
|
UINT len, r;
|
|
|
|
|
|
|
|
TRACE("%p %s %s %s\n", db, debugstr_w(table),
|
2005-03-29 13:28:57 +02:00
|
|
|
debugstr_w(folder), debugstr_w(file) );
|
|
|
|
|
|
|
|
if( folder == NULL || file == NULL )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2006-08-31 12:52:03 +02:00
|
|
|
|
|
|
|
len = lstrlenW(folder) + lstrlenW(file) + 2;
|
|
|
|
filename = msi_alloc(len * sizeof (WCHAR));
|
|
|
|
if (!filename)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
lstrcpyW( filename, folder );
|
2009-10-15 12:46:27 +02:00
|
|
|
lstrcatW( filename, szBackSlash );
|
2006-08-31 12:52:03 +02:00
|
|
|
lstrcatW( filename, file );
|
|
|
|
|
|
|
|
handle = CreateFileW( filename, GENERIC_READ | GENERIC_WRITE, 0,
|
|
|
|
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
|
|
|
|
msi_free( filename );
|
|
|
|
if (handle == INVALID_HANDLE_VALUE)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2010-10-19 11:27:44 +02:00
|
|
|
if (!strcmpW( table, forcecodepage ))
|
2008-02-11 08:13:44 +01:00
|
|
|
{
|
2010-11-17 10:58:10 +01:00
|
|
|
UINT codepage = msi_get_string_table_codepage( db->strings );
|
|
|
|
r = msi_export_forcecodepage( handle, codepage );
|
2008-02-11 08:13:44 +01:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2006-08-31 12:52:03 +02:00
|
|
|
r = MSI_OpenQuery( db, &view, query, table );
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
/* write out row 1, the column names */
|
|
|
|
r = MSI_ViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
msi_export_record( handle, rec, 1 );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write out row 2, the column types */
|
|
|
|
r = MSI_ViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
msi_export_record( handle, rec, 1 );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write out row 3, the table name + keys */
|
|
|
|
r = MSI_DatabaseGetPrimaryKeys( db, table, &rec );
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
MSI_RecordSetStringW( rec, 0, table );
|
|
|
|
msi_export_record( handle, rec, 0 );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write out row 4 onwards, the data */
|
|
|
|
r = MSI_IterateRecords( view, 0, msi_export_row, handle );
|
|
|
|
msiobj_release( &view->hdr );
|
|
|
|
}
|
|
|
|
|
2008-02-11 08:13:44 +01:00
|
|
|
done:
|
2006-08-31 12:52:03 +02:00
|
|
|
CloseHandle( handle );
|
|
|
|
return r;
|
2005-03-29 13:28:57 +02:00
|
|
|
}
|
|
|
|
|
2006-08-31 12:52:03 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* MsiExportDatabaseW [MSI.@]
|
|
|
|
*
|
|
|
|
* Writes a file containing the table data as tab separated ASCII.
|
|
|
|
*
|
|
|
|
* The format is as follows:
|
|
|
|
*
|
|
|
|
* row1 : colname1 <tab> colname2 <tab> .... colnameN <cr> <lf>
|
|
|
|
* row2 : coltype1 <tab> coltype2 <tab> .... coltypeN <cr> <lf>
|
|
|
|
* row3 : tablename <tab> key1 <tab> key2 <tab> ... keyM <cr> <lf>
|
|
|
|
*
|
|
|
|
* Followed by the data, starting at row 1 with one row per line
|
|
|
|
*
|
|
|
|
* row4 : data <tab> data <tab> data <tab> ... data <cr> <lf>
|
|
|
|
*/
|
2005-03-29 13:28:57 +02:00
|
|
|
UINT WINAPI MsiDatabaseExportW( MSIHANDLE handle, LPCWSTR szTable,
|
|
|
|
LPCWSTR szFolder, LPCWSTR szFilename )
|
|
|
|
{
|
|
|
|
MSIDATABASE *db;
|
|
|
|
UINT r;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%x %s %s %s\n", handle, debugstr_w(szTable),
|
2005-03-29 13:28:57 +02:00
|
|
|
debugstr_w(szFolder), debugstr_w(szFilename));
|
|
|
|
|
|
|
|
db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
|
|
|
|
if( !db )
|
2007-11-12 01:13:08 +01:00
|
|
|
{
|
|
|
|
IWineMsiRemoteDatabase *remote_database;
|
|
|
|
|
|
|
|
remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
|
|
|
|
if ( !remote_database )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
IWineMsiRemoteDatabase_Release( remote_database );
|
|
|
|
WARN("MsiDatabaseExport not allowed during a custom action!\n");
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-03-29 13:28:57 +02:00
|
|
|
r = MSI_DatabaseExport( db, szTable, szFolder, szFilename );
|
|
|
|
msiobj_release( &db->hdr );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT WINAPI MsiDatabaseExportA( MSIHANDLE handle, LPCSTR szTable,
|
|
|
|
LPCSTR szFolder, LPCSTR szFilename )
|
|
|
|
{
|
|
|
|
LPWSTR path = NULL, file = NULL, table = NULL;
|
|
|
|
UINT r = ERROR_OUTOFMEMORY;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%x %s %s %s\n", handle, debugstr_a(szTable),
|
2005-03-29 13:28:57 +02:00
|
|
|
debugstr_a(szFolder), debugstr_a(szFilename));
|
|
|
|
|
|
|
|
if( szTable )
|
|
|
|
{
|
|
|
|
table = strdupAtoW( szTable );
|
|
|
|
if( !table )
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( szFolder )
|
|
|
|
{
|
|
|
|
path = strdupAtoW( szFolder );
|
|
|
|
if( !path )
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( szFilename )
|
|
|
|
{
|
|
|
|
file = strdupAtoW( szFilename );
|
|
|
|
if( !file )
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2005-04-26 16:30:15 +02:00
|
|
|
r = MsiDatabaseExportW( handle, table, path, file );
|
2005-03-29 13:28:57 +02:00
|
|
|
|
|
|
|
end:
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( table );
|
|
|
|
msi_free( path );
|
|
|
|
msi_free( file );
|
2005-03-29 13:28:57 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2006-01-30 14:56:52 +01:00
|
|
|
|
2008-10-01 03:55:55 +02:00
|
|
|
UINT WINAPI MsiDatabaseMergeA(MSIHANDLE hDatabase, MSIHANDLE hDatabaseMerge,
|
|
|
|
LPCSTR szTableName)
|
|
|
|
{
|
2008-10-01 03:56:27 +02:00
|
|
|
UINT r;
|
|
|
|
LPWSTR table;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("(%d, %d, %s)\n", hDatabase, hDatabaseMerge,
|
2008-10-01 03:55:55 +02:00
|
|
|
debugstr_a(szTableName));
|
|
|
|
|
2008-10-01 03:56:27 +02:00
|
|
|
table = strdupAtoW(szTableName);
|
|
|
|
r = MsiDatabaseMergeW(hDatabase, hDatabaseMerge, table);
|
|
|
|
|
|
|
|
msi_free(table);
|
|
|
|
return r;
|
2008-10-01 03:55:55 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 05:42:33 +02:00
|
|
|
typedef struct _tagMERGETABLE
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
struct list rows;
|
|
|
|
LPWSTR name;
|
|
|
|
DWORD numconflicts;
|
2009-05-26 22:32:24 +02:00
|
|
|
LPWSTR *columns;
|
|
|
|
DWORD numcolumns;
|
|
|
|
LPWSTR *types;
|
|
|
|
DWORD numtypes;
|
|
|
|
LPWSTR *labels;
|
|
|
|
DWORD numlabels;
|
2008-10-09 05:42:33 +02:00
|
|
|
} MERGETABLE;
|
|
|
|
|
|
|
|
typedef struct _tagMERGEROW
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
MSIRECORD *data;
|
|
|
|
} MERGEROW;
|
|
|
|
|
|
|
|
typedef struct _tagMERGEDATA
|
|
|
|
{
|
|
|
|
MSIDATABASE *db;
|
|
|
|
MSIDATABASE *merge;
|
|
|
|
MERGETABLE *curtable;
|
|
|
|
MSIQUERY *curview;
|
|
|
|
struct list *tabledata;
|
|
|
|
} MERGEDATA;
|
|
|
|
|
2009-10-20 15:49:39 +02:00
|
|
|
static BOOL merge_type_match(LPCWSTR type1, LPCWSTR type2)
|
|
|
|
{
|
|
|
|
if (((type1[0] == 'l') || (type1[0] == 's')) &&
|
|
|
|
((type2[0] == 'l') || (type2[0] == 's')))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (((type1[0] == 'L') || (type1[0] == 'S')) &&
|
|
|
|
((type2[0] == 'L') || (type2[0] == 'S')))
|
|
|
|
return TRUE;
|
|
|
|
|
2010-10-19 11:27:44 +02:00
|
|
|
return !strcmpW( type1, type2 );
|
2009-10-20 15:49:39 +02:00
|
|
|
}
|
|
|
|
|
2008-10-09 05:42:33 +02:00
|
|
|
static UINT merge_verify_colnames(MSIQUERY *dbview, MSIQUERY *mergeview)
|
|
|
|
{
|
|
|
|
MSIRECORD *dbrec, *mergerec;
|
|
|
|
UINT r, i, count;
|
|
|
|
|
|
|
|
r = MSI_ViewGetColumnInfo(dbview, MSICOLINFO_NAMES, &dbrec);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = MSI_ViewGetColumnInfo(mergeview, MSICOLINFO_NAMES, &mergerec);
|
|
|
|
if (r != ERROR_SUCCESS)
|
2013-03-31 12:59:33 +02:00
|
|
|
{
|
|
|
|
msiobj_release(&dbrec->hdr);
|
2008-10-09 05:42:33 +02:00
|
|
|
return r;
|
2013-03-31 12:59:33 +02:00
|
|
|
}
|
2008-10-09 05:42:33 +02:00
|
|
|
|
|
|
|
count = MSI_RecordGetFieldCount(dbrec);
|
|
|
|
for (i = 1; i <= count; i++)
|
|
|
|
{
|
|
|
|
if (!MSI_RecordGetString(mergerec, i))
|
|
|
|
break;
|
|
|
|
|
2010-10-19 11:27:44 +02:00
|
|
|
if (strcmpW( MSI_RecordGetString( dbrec, i ), MSI_RecordGetString( mergerec, i ) ))
|
2008-10-09 05:42:33 +02:00
|
|
|
{
|
|
|
|
r = ERROR_DATATYPE_MISMATCH;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msiobj_release(&dbrec->hdr);
|
|
|
|
msiobj_release(&mergerec->hdr);
|
|
|
|
dbrec = mergerec = NULL;
|
|
|
|
|
|
|
|
r = MSI_ViewGetColumnInfo(dbview, MSICOLINFO_TYPES, &dbrec);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = MSI_ViewGetColumnInfo(mergeview, MSICOLINFO_TYPES, &mergerec);
|
|
|
|
if (r != ERROR_SUCCESS)
|
2013-03-31 12:59:33 +02:00
|
|
|
{
|
|
|
|
msiobj_release(&dbrec->hdr);
|
2008-10-09 05:42:33 +02:00
|
|
|
return r;
|
2013-03-31 12:59:33 +02:00
|
|
|
}
|
2008-10-09 05:42:33 +02:00
|
|
|
|
|
|
|
count = MSI_RecordGetFieldCount(dbrec);
|
|
|
|
for (i = 1; i <= count; i++)
|
|
|
|
{
|
|
|
|
if (!MSI_RecordGetString(mergerec, i))
|
|
|
|
break;
|
|
|
|
|
2009-10-20 15:49:39 +02:00
|
|
|
if (!merge_type_match(MSI_RecordGetString(dbrec, i),
|
2008-10-09 05:42:33 +02:00
|
|
|
MSI_RecordGetString(mergerec, i)))
|
|
|
|
{
|
|
|
|
r = ERROR_DATATYPE_MISMATCH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
msiobj_release(&dbrec->hdr);
|
|
|
|
msiobj_release(&mergerec->hdr);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT merge_verify_primary_keys(MSIDATABASE *db, MSIDATABASE *mergedb,
|
|
|
|
LPCWSTR table)
|
|
|
|
{
|
|
|
|
MSIRECORD *dbrec, *mergerec = NULL;
|
|
|
|
UINT r, i, count;
|
|
|
|
|
|
|
|
r = MSI_DatabaseGetPrimaryKeys(db, table, &dbrec);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = MSI_DatabaseGetPrimaryKeys(mergedb, table, &mergerec);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
count = MSI_RecordGetFieldCount(dbrec);
|
|
|
|
if (count != MSI_RecordGetFieldCount(mergerec))
|
|
|
|
{
|
|
|
|
r = ERROR_DATATYPE_MISMATCH;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i <= count; i++)
|
|
|
|
{
|
2010-10-19 11:27:44 +02:00
|
|
|
if (strcmpW( MSI_RecordGetString( dbrec, i ), MSI_RecordGetString( mergerec, i ) ))
|
2008-10-09 05:42:33 +02:00
|
|
|
{
|
|
|
|
r = ERROR_DATATYPE_MISMATCH;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
msiobj_release(&dbrec->hdr);
|
|
|
|
msiobj_release(&mergerec->hdr);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR get_key_value(MSIQUERY *view, LPCWSTR key, MSIRECORD *rec)
|
|
|
|
{
|
|
|
|
MSIRECORD *colnames;
|
2009-05-26 22:32:12 +02:00
|
|
|
LPWSTR str, val;
|
|
|
|
UINT r, i = 0, sz = 0;
|
2008-10-09 05:42:33 +02:00
|
|
|
int cmp;
|
|
|
|
|
|
|
|
r = MSI_ViewGetColumnInfo(view, MSICOLINFO_NAMES, &colnames);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
str = msi_dup_record_field(colnames, ++i);
|
2010-10-19 11:27:44 +02:00
|
|
|
cmp = strcmpW( key, str );
|
2008-10-09 05:42:33 +02:00
|
|
|
msi_free(str);
|
|
|
|
} while (cmp);
|
|
|
|
|
|
|
|
msiobj_release(&colnames->hdr);
|
2009-05-26 22:32:12 +02:00
|
|
|
|
|
|
|
r = MSI_RecordGetStringW(rec, i, NULL, &sz);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
sz++;
|
|
|
|
|
|
|
|
if (MSI_RecordGetString(rec, i)) /* check record field is a string */
|
|
|
|
{
|
|
|
|
/* quote string record fields */
|
|
|
|
const WCHAR szQuote[] = {'\'', 0};
|
|
|
|
sz += 2;
|
|
|
|
val = msi_alloc(sz*sizeof(WCHAR));
|
|
|
|
if (!val)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
lstrcpyW(val, szQuote);
|
|
|
|
r = MSI_RecordGetStringW(rec, i, val+1, &sz);
|
|
|
|
lstrcpyW(val+1+sz, szQuote);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* do not quote integer record fields */
|
|
|
|
val = msi_alloc(sz*sizeof(WCHAR));
|
|
|
|
if (!val)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
r = MSI_RecordGetStringW(rec, i, val, &sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("failed to get string!\n");
|
|
|
|
msi_free(val);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
2008-10-09 05:42:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR create_diff_row_query(MSIDATABASE *merge, MSIQUERY *view,
|
|
|
|
LPWSTR table, MSIRECORD *rec)
|
|
|
|
{
|
2011-07-07 09:22:20 +02:00
|
|
|
LPWSTR query = NULL, clause = NULL, val;
|
|
|
|
LPCWSTR setptr, key;
|
|
|
|
DWORD size, oldsize;
|
2008-10-09 05:42:33 +02:00
|
|
|
MSIRECORD *keys;
|
|
|
|
UINT r, i, count;
|
|
|
|
|
|
|
|
static const WCHAR keyset[] = {
|
|
|
|
'`','%','s','`',' ','=',' ','%','s',' ','A','N','D',' ',0};
|
|
|
|
static const WCHAR lastkeyset[] = {
|
|
|
|
'`','%','s','`',' ','=',' ','%','s',' ',0};
|
|
|
|
static const WCHAR fmt[] = {'S','E','L','E','C','T',' ','*',' ',
|
|
|
|
'F','R','O','M',' ','`','%','s','`',' ',
|
|
|
|
'W','H','E','R','E',' ','%','s',0};
|
|
|
|
|
|
|
|
r = MSI_DatabaseGetPrimaryKeys(merge, table, &keys);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
2011-07-07 09:22:20 +02:00
|
|
|
clause = msi_alloc_zero(sizeof(WCHAR));
|
2008-10-09 05:42:33 +02:00
|
|
|
if (!clause)
|
|
|
|
goto done;
|
|
|
|
|
2011-07-07 09:22:20 +02:00
|
|
|
size = 1;
|
2008-10-09 05:42:33 +02:00
|
|
|
count = MSI_RecordGetFieldCount(keys);
|
|
|
|
for (i = 1; i <= count; i++)
|
|
|
|
{
|
|
|
|
key = MSI_RecordGetString(keys, i);
|
|
|
|
val = get_key_value(view, key, rec);
|
|
|
|
|
|
|
|
if (i == count)
|
|
|
|
setptr = lastkeyset;
|
|
|
|
else
|
|
|
|
setptr = keyset;
|
|
|
|
|
|
|
|
oldsize = size;
|
|
|
|
size += lstrlenW(setptr) + lstrlenW(key) + lstrlenW(val) - 4;
|
|
|
|
clause = msi_realloc(clause, size * sizeof (WCHAR));
|
|
|
|
if (!clause)
|
|
|
|
{
|
|
|
|
msi_free(val);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2011-07-06 10:34:47 +02:00
|
|
|
sprintfW(clause + oldsize - 1, setptr, key, val);
|
2008-10-09 05:42:33 +02:00
|
|
|
msi_free(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
size = lstrlenW(fmt) + lstrlenW(table) + lstrlenW(clause) + 1;
|
|
|
|
query = msi_alloc(size * sizeof(WCHAR));
|
|
|
|
if (!query)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
sprintfW(query, fmt, table, clause);
|
|
|
|
|
|
|
|
done:
|
|
|
|
msi_free(clause);
|
|
|
|
msiobj_release(&keys->hdr);
|
|
|
|
return query;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT merge_diff_row(MSIRECORD *rec, LPVOID param)
|
|
|
|
{
|
2009-01-15 09:46:57 +01:00
|
|
|
MERGEDATA *data = param;
|
2008-10-09 05:42:33 +02:00
|
|
|
MERGETABLE *table = data->curtable;
|
|
|
|
MERGEROW *mergerow;
|
2009-05-26 22:32:00 +02:00
|
|
|
MSIQUERY *dbview = NULL;
|
2009-01-26 11:14:48 +01:00
|
|
|
MSIRECORD *row = NULL;
|
2009-05-26 22:32:24 +02:00
|
|
|
LPWSTR query = NULL;
|
|
|
|
UINT r = ERROR_SUCCESS;
|
2008-10-09 05:42:33 +02:00
|
|
|
|
2009-05-26 22:32:24 +02:00
|
|
|
if (TABLE_Exists(data->db, table->name))
|
|
|
|
{
|
|
|
|
query = create_diff_row_query(data->merge, data->curview, table->name, rec);
|
|
|
|
if (!query)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2008-10-09 05:42:33 +02:00
|
|
|
|
2009-05-26 22:32:24 +02:00
|
|
|
r = MSI_DatabaseOpenViewW(data->db, query, &dbview);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
2008-10-09 05:42:33 +02:00
|
|
|
|
2009-05-26 22:32:24 +02:00
|
|
|
r = MSI_ViewExecute(dbview, NULL);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
2008-10-09 05:42:33 +02:00
|
|
|
|
2009-05-26 22:32:24 +02:00
|
|
|
r = MSI_ViewFetch(dbview, &row);
|
|
|
|
if (r == ERROR_SUCCESS && !MSI_RecordsAreEqual(rec, row))
|
|
|
|
{
|
|
|
|
table->numconflicts++;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else if (r != ERROR_NO_MORE_ITEMS)
|
|
|
|
goto done;
|
2009-10-20 14:24:57 +02:00
|
|
|
|
|
|
|
r = ERROR_SUCCESS;
|
2008-10-09 05:42:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mergerow = msi_alloc(sizeof(MERGEROW));
|
|
|
|
if (!mergerow)
|
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
mergerow->data = MSI_CloneRecord(rec);
|
|
|
|
if (!mergerow->data)
|
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
msi_free(mergerow);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&table->rows, &mergerow->entry);
|
|
|
|
|
|
|
|
done:
|
|
|
|
msi_free(query);
|
|
|
|
msiobj_release(&row->hdr);
|
|
|
|
msiobj_release(&dbview->hdr);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-05-26 22:32:24 +02:00
|
|
|
static UINT msi_get_table_labels(MSIDATABASE *db, LPCWSTR table, LPWSTR **labels, DWORD *numlabels)
|
|
|
|
{
|
|
|
|
UINT r, i, count;
|
|
|
|
MSIRECORD *prec = NULL;
|
|
|
|
|
|
|
|
r = MSI_DatabaseGetPrimaryKeys(db, table, &prec);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
count = MSI_RecordGetFieldCount(prec);
|
|
|
|
*numlabels = count + 1;
|
|
|
|
*labels = msi_alloc((*numlabels)*sizeof(LPWSTR));
|
2009-06-05 14:02:36 +02:00
|
|
|
if (!*labels)
|
2009-05-26 22:32:24 +02:00
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*labels)[0] = strdupW(table);
|
|
|
|
for (i=1; i<=count; i++ )
|
|
|
|
{
|
|
|
|
(*labels)[i] = strdupW(MSI_RecordGetString(prec, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
msiobj_release( &prec->hdr );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT msi_get_query_columns(MSIQUERY *query, LPWSTR **columns, DWORD *numcolumns)
|
|
|
|
{
|
|
|
|
UINT r, i, count;
|
|
|
|
MSIRECORD *prec = NULL;
|
|
|
|
|
|
|
|
r = MSI_ViewGetColumnInfo(query, MSICOLINFO_NAMES, &prec);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
count = MSI_RecordGetFieldCount(prec);
|
|
|
|
*columns = msi_alloc(count*sizeof(LPWSTR));
|
2009-06-05 14:02:36 +02:00
|
|
|
if (!*columns)
|
2009-05-26 22:32:24 +02:00
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=1; i<=count; i++ )
|
|
|
|
{
|
|
|
|
(*columns)[i-1] = strdupW(MSI_RecordGetString(prec, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
*numcolumns = count;
|
|
|
|
|
|
|
|
end:
|
|
|
|
msiobj_release( &prec->hdr );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT msi_get_query_types(MSIQUERY *query, LPWSTR **types, DWORD *numtypes)
|
|
|
|
{
|
|
|
|
UINT r, i, count;
|
|
|
|
MSIRECORD *prec = NULL;
|
|
|
|
|
|
|
|
r = MSI_ViewGetColumnInfo(query, MSICOLINFO_TYPES, &prec);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
count = MSI_RecordGetFieldCount(prec);
|
|
|
|
*types = msi_alloc(count*sizeof(LPWSTR));
|
2009-06-05 14:02:36 +02:00
|
|
|
if (!*types)
|
2009-05-26 22:32:24 +02:00
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2009-12-14 04:35:45 +01:00
|
|
|
*numtypes = count;
|
2009-05-26 22:32:24 +02:00
|
|
|
for (i=1; i<=count; i++ )
|
|
|
|
{
|
|
|
|
(*types)[i-1] = strdupW(MSI_RecordGetString(prec, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
msiobj_release( &prec->hdr );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void merge_free_rows(MERGETABLE *table)
|
|
|
|
{
|
|
|
|
struct list *item, *cursor;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_SAFE(item, cursor, &table->rows)
|
|
|
|
{
|
|
|
|
MERGEROW *row = LIST_ENTRY(item, MERGEROW, entry);
|
|
|
|
|
|
|
|
list_remove(&row->entry);
|
|
|
|
msiobj_release(&row->data->hdr);
|
|
|
|
msi_free(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_merge_table(MERGETABLE *table)
|
|
|
|
{
|
2009-12-14 04:35:45 +01:00
|
|
|
UINT i;
|
2009-05-26 22:32:24 +02:00
|
|
|
|
2009-12-14 04:35:45 +01:00
|
|
|
if (table->labels != NULL)
|
|
|
|
{
|
|
|
|
for (i = 0; i < table->numlabels; i++)
|
|
|
|
msi_free(table->labels[i]);
|
2009-05-26 22:32:24 +02:00
|
|
|
|
2009-12-14 04:35:45 +01:00
|
|
|
msi_free(table->labels);
|
|
|
|
}
|
2009-05-26 22:32:24 +02:00
|
|
|
|
2009-12-14 04:35:45 +01:00
|
|
|
if (table->columns != NULL)
|
|
|
|
{
|
|
|
|
for (i = 0; i < table->numcolumns; i++)
|
|
|
|
msi_free(table->columns[i]);
|
2009-05-26 22:32:24 +02:00
|
|
|
|
2009-12-14 04:35:45 +01:00
|
|
|
msi_free(table->columns);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (table->types != NULL)
|
|
|
|
{
|
|
|
|
for (i = 0; i < table->numtypes; i++)
|
|
|
|
msi_free(table->types[i]);
|
|
|
|
|
|
|
|
msi_free(table->types);
|
|
|
|
}
|
|
|
|
|
|
|
|
msi_free(table->name);
|
|
|
|
merge_free_rows(table);
|
|
|
|
|
|
|
|
msi_free(table);
|
2009-05-26 22:32:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT msi_get_merge_table (MSIDATABASE *db, LPCWSTR name, MERGETABLE **ptable)
|
|
|
|
{
|
|
|
|
UINT r;
|
|
|
|
MERGETABLE *table;
|
|
|
|
MSIQUERY *mergeview = NULL;
|
|
|
|
|
|
|
|
static const WCHAR query[] = {'S','E','L','E','C','T',' ','*',' ',
|
|
|
|
'F','R','O','M',' ','`','%','s','`',0};
|
|
|
|
|
|
|
|
table = msi_alloc_zero(sizeof(MERGETABLE));
|
|
|
|
if (!table)
|
|
|
|
{
|
|
|
|
*ptable = NULL;
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = msi_get_table_labels(db, name, &table->labels, &table->numlabels);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
r = MSI_OpenQuery(db, &mergeview, query, name);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
r = msi_get_query_columns(mergeview, &table->columns, &table->numcolumns);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
r = msi_get_query_types(mergeview, &table->types, &table->numtypes);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
list_init(&table->rows);
|
|
|
|
|
|
|
|
table->name = strdupW(name);
|
|
|
|
table->numconflicts = 0;
|
|
|
|
|
|
|
|
msiobj_release(&mergeview->hdr);
|
|
|
|
*ptable = table;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
err:
|
|
|
|
msiobj_release(&mergeview->hdr);
|
|
|
|
free_merge_table(table);
|
|
|
|
*ptable = NULL;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-10-09 05:42:33 +02:00
|
|
|
static UINT merge_diff_tables(MSIRECORD *rec, LPVOID param)
|
|
|
|
{
|
2009-01-15 09:46:57 +01:00
|
|
|
MERGEDATA *data = param;
|
2008-10-09 05:42:33 +02:00
|
|
|
MERGETABLE *table;
|
2009-05-26 22:32:24 +02:00
|
|
|
MSIQUERY *dbview = NULL;
|
2008-10-09 05:42:33 +02:00
|
|
|
MSIQUERY *mergeview = NULL;
|
|
|
|
LPCWSTR name;
|
|
|
|
UINT r;
|
|
|
|
|
2008-10-09 05:42:50 +02:00
|
|
|
static const WCHAR query[] = {'S','E','L','E','C','T',' ','*',' ',
|
2008-10-09 05:42:33 +02:00
|
|
|
'F','R','O','M',' ','`','%','s','`',0};
|
|
|
|
|
|
|
|
name = MSI_RecordGetString(rec, 1);
|
|
|
|
|
2008-10-09 05:42:50 +02:00
|
|
|
r = MSI_OpenQuery(data->merge, &mergeview, query, name);
|
2008-10-09 05:42:33 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
2009-05-26 22:32:24 +02:00
|
|
|
if (TABLE_Exists(data->db, name))
|
|
|
|
{
|
|
|
|
r = MSI_OpenQuery(data->db, &dbview, query, name);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
2008-10-09 05:42:33 +02:00
|
|
|
|
2009-05-26 22:32:24 +02:00
|
|
|
r = merge_verify_colnames(dbview, mergeview);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
2008-10-09 05:42:33 +02:00
|
|
|
|
2009-05-26 22:32:24 +02:00
|
|
|
r = merge_verify_primary_keys(data->db, data->merge, name);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
2008-10-09 05:42:33 +02:00
|
|
|
}
|
|
|
|
|
2009-05-26 22:32:24 +02:00
|
|
|
r = msi_get_merge_table(data->merge, name, &table);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
2008-10-09 05:42:33 +02:00
|
|
|
data->curtable = table;
|
|
|
|
data->curview = mergeview;
|
|
|
|
r = MSI_IterateRecords(mergeview, NULL, merge_diff_row, data);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
2009-05-26 22:32:24 +02:00
|
|
|
free_merge_table(table);
|
2008-10-09 05:42:33 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(data->tabledata, &table->entry);
|
|
|
|
|
|
|
|
done:
|
|
|
|
msiobj_release(&dbview->hdr);
|
|
|
|
msiobj_release(&mergeview->hdr);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT gather_merge_data(MSIDATABASE *db, MSIDATABASE *merge,
|
|
|
|
struct list *tabledata)
|
|
|
|
{
|
2011-07-27 10:53:26 +02:00
|
|
|
static const WCHAR query[] = {
|
|
|
|
'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
|
|
|
|
'`','_','T','a','b','l','e','s','`',0};
|
2008-10-09 05:42:33 +02:00
|
|
|
MSIQUERY *view;
|
|
|
|
MERGEDATA data;
|
2011-07-27 10:53:26 +02:00
|
|
|
UINT r;
|
2008-10-09 05:42:33 +02:00
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW(merge, query, &view);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
data.db = db;
|
|
|
|
data.merge = merge;
|
|
|
|
data.tabledata = tabledata;
|
|
|
|
r = MSI_IterateRecords(view, NULL, merge_diff_tables, &data);
|
|
|
|
msiobj_release(&view->hdr);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT merge_table(MSIDATABASE *db, MERGETABLE *table)
|
|
|
|
{
|
|
|
|
UINT r;
|
|
|
|
MERGEROW *row;
|
|
|
|
MSIVIEW *tv;
|
|
|
|
|
2009-05-26 22:32:24 +02:00
|
|
|
if (!TABLE_Exists(db, table->name))
|
|
|
|
{
|
|
|
|
r = msi_add_table_to_db(db, table->columns, table->types,
|
|
|
|
table->labels, table->numlabels, table->numcolumns);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2008-10-09 05:42:33 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(row, &table->rows, MERGEROW, entry)
|
|
|
|
{
|
|
|
|
r = TABLE_CreateView(db, table->name, &tv);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
2009-03-02 06:41:22 +01:00
|
|
|
r = tv->ops->insert_row(tv, row->data, -1, FALSE);
|
2008-10-09 05:42:33 +02:00
|
|
|
tv->ops->delete(tv);
|
|
|
|
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT update_merge_errors(MSIDATABASE *db, LPCWSTR error,
|
|
|
|
LPWSTR table, DWORD numconflicts)
|
|
|
|
{
|
|
|
|
UINT r;
|
|
|
|
MSIQUERY *view;
|
|
|
|
|
|
|
|
static const WCHAR create[] = {
|
|
|
|
'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
|
|
|
|
'`','%','s','`',' ','(','`','T','a','b','l','e','`',' ',
|
|
|
|
'C','H','A','R','(','2','5','5',')',' ','N','O','T',' ',
|
|
|
|
'N','U','L','L',',',' ','`','N','u','m','R','o','w','M','e','r','g','e',
|
|
|
|
'C','o','n','f','l','i','c','t','s','`',' ','S','H','O','R','T',' ',
|
|
|
|
'N','O','T',' ','N','U','L','L',' ','P','R','I','M','A','R','Y',' ',
|
|
|
|
'K','E','Y',' ','`','T','a','b','l','e','`',')',0};
|
|
|
|
static const WCHAR insert[] = {
|
|
|
|
'I','N','S','E','R','T',' ','I','N','T','O',' ',
|
|
|
|
'`','%','s','`',' ','(','`','T','a','b','l','e','`',',',' ',
|
|
|
|
'`','N','u','m','R','o','w','M','e','r','g','e',
|
|
|
|
'C','o','n','f','l','i','c','t','s','`',')',' ','V','A','L','U','E','S',
|
|
|
|
' ','(','\'','%','s','\'',',',' ','%','d',')',0};
|
|
|
|
|
|
|
|
if (!TABLE_Exists(db, error))
|
|
|
|
{
|
|
|
|
r = MSI_OpenQuery(db, &view, create, error);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute(view, NULL);
|
|
|
|
msiobj_release(&view->hdr);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = MSI_OpenQuery(db, &view, insert, error, table, numconflicts);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute(view, NULL);
|
|
|
|
msiobj_release(&view->hdr);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-10-01 03:55:55 +02:00
|
|
|
UINT WINAPI MsiDatabaseMergeW(MSIHANDLE hDatabase, MSIHANDLE hDatabaseMerge,
|
|
|
|
LPCWSTR szTableName)
|
|
|
|
{
|
2008-10-09 05:42:33 +02:00
|
|
|
struct list tabledata = LIST_INIT(tabledata);
|
|
|
|
struct list *item, *cursor;
|
|
|
|
MSIDATABASE *db, *merge;
|
|
|
|
MERGETABLE *table;
|
|
|
|
BOOL conflicts;
|
|
|
|
UINT r;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("(%d, %d, %s)\n", hDatabase, hDatabaseMerge,
|
2008-10-01 03:55:55 +02:00
|
|
|
debugstr_w(szTableName));
|
|
|
|
|
2008-10-09 05:42:33 +02:00
|
|
|
if (szTableName && !*szTableName)
|
|
|
|
return ERROR_INVALID_TABLE;
|
|
|
|
|
|
|
|
db = msihandle2msiinfo(hDatabase, MSIHANDLETYPE_DATABASE);
|
|
|
|
merge = msihandle2msiinfo(hDatabaseMerge, MSIHANDLETYPE_DATABASE);
|
|
|
|
if (!db || !merge)
|
|
|
|
{
|
|
|
|
r = ERROR_INVALID_HANDLE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = gather_merge_data(db, merge, &tabledata);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
conflicts = FALSE;
|
|
|
|
LIST_FOR_EACH_ENTRY(table, &tabledata, MERGETABLE, entry)
|
|
|
|
{
|
|
|
|
if (table->numconflicts)
|
|
|
|
{
|
|
|
|
conflicts = TRUE;
|
|
|
|
|
|
|
|
r = update_merge_errors(db, szTableName, table->name,
|
|
|
|
table->numconflicts);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = merge_table(db, table);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOR_EACH_SAFE(item, cursor, &tabledata)
|
|
|
|
{
|
|
|
|
MERGETABLE *table = LIST_ENTRY(item, MERGETABLE, entry);
|
|
|
|
list_remove(&table->entry);
|
2009-05-26 22:32:24 +02:00
|
|
|
free_merge_table(table);
|
2008-10-09 05:42:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (conflicts)
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
done:
|
|
|
|
msiobj_release(&db->hdr);
|
|
|
|
msiobj_release(&merge->hdr);
|
|
|
|
return r;
|
2008-10-01 03:55:55 +02:00
|
|
|
}
|
|
|
|
|
2006-01-30 14:56:52 +01:00
|
|
|
MSIDBSTATE WINAPI MsiGetDatabaseState( MSIHANDLE handle )
|
|
|
|
{
|
|
|
|
MSIDBSTATE ret = MSIDBSTATE_READ;
|
|
|
|
MSIDATABASE *db;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d\n", handle);
|
2006-01-30 14:56:52 +01:00
|
|
|
|
|
|
|
db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
|
2007-11-12 01:13:08 +01:00
|
|
|
if( !db )
|
|
|
|
{
|
|
|
|
IWineMsiRemoteDatabase *remote_database;
|
|
|
|
|
|
|
|
remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
|
|
|
|
if ( !remote_database )
|
|
|
|
return MSIDBSTATE_ERROR;
|
|
|
|
|
|
|
|
IWineMsiRemoteDatabase_Release( remote_database );
|
|
|
|
WARN("MsiGetDatabaseState not allowed during a custom action!\n");
|
|
|
|
|
|
|
|
return MSIDBSTATE_READ;
|
|
|
|
}
|
|
|
|
|
2006-01-30 14:56:52 +01:00
|
|
|
if (db->mode != MSIDBOPEN_READONLY )
|
|
|
|
ret = MSIDBSTATE_WRITE;
|
|
|
|
msiobj_release( &db->hdr );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2007-11-12 01:13:08 +01:00
|
|
|
|
|
|
|
typedef struct _msi_remote_database_impl {
|
2010-12-15 10:55:20 +01:00
|
|
|
IWineMsiRemoteDatabase IWineMsiRemoteDatabase_iface;
|
2007-11-12 01:13:08 +01:00
|
|
|
MSIHANDLE database;
|
|
|
|
LONG refs;
|
|
|
|
} msi_remote_database_impl;
|
|
|
|
|
2010-12-15 10:55:20 +01:00
|
|
|
static inline msi_remote_database_impl *impl_from_IWineMsiRemoteDatabase( IWineMsiRemoteDatabase *iface )
|
2007-11-12 01:13:08 +01:00
|
|
|
{
|
2010-12-15 10:55:20 +01:00
|
|
|
return CONTAINING_RECORD(iface, msi_remote_database_impl, IWineMsiRemoteDatabase_iface);
|
2007-11-12 01:13:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mrd_QueryInterface( IWineMsiRemoteDatabase *iface,
|
|
|
|
REFIID riid,LPVOID *ppobj)
|
|
|
|
{
|
|
|
|
if( IsEqualCLSID( riid, &IID_IUnknown ) ||
|
|
|
|
IsEqualCLSID( riid, &IID_IWineMsiRemoteDatabase ) )
|
|
|
|
{
|
2012-07-27 14:03:12 +02:00
|
|
|
IWineMsiRemoteDatabase_AddRef( iface );
|
2007-11-12 01:13:08 +01:00
|
|
|
*ppobj = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI mrd_AddRef( IWineMsiRemoteDatabase *iface )
|
|
|
|
{
|
2010-12-15 10:55:20 +01:00
|
|
|
msi_remote_database_impl* This = impl_from_IWineMsiRemoteDatabase( iface );
|
2007-11-12 01:13:08 +01:00
|
|
|
|
|
|
|
return InterlockedIncrement( &This->refs );
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI mrd_Release( IWineMsiRemoteDatabase *iface )
|
|
|
|
{
|
2010-12-15 10:55:20 +01:00
|
|
|
msi_remote_database_impl* This = impl_from_IWineMsiRemoteDatabase( iface );
|
2007-11-12 01:13:08 +01:00
|
|
|
ULONG r;
|
|
|
|
|
|
|
|
r = InterlockedDecrement( &This->refs );
|
|
|
|
if (r == 0)
|
|
|
|
{
|
|
|
|
MsiCloseHandle( This->database );
|
|
|
|
msi_free( This );
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-03-01 06:29:43 +01:00
|
|
|
static HRESULT WINAPI mrd_IsTablePersistent( IWineMsiRemoteDatabase *iface,
|
2010-03-12 16:48:38 +01:00
|
|
|
LPCWSTR table, MSICONDITION *persistent )
|
2007-11-12 01:13:08 +01:00
|
|
|
{
|
2010-12-15 10:55:20 +01:00
|
|
|
msi_remote_database_impl *This = impl_from_IWineMsiRemoteDatabase( iface );
|
2009-01-15 09:46:57 +01:00
|
|
|
*persistent = MsiDatabaseIsTablePersistentW(This->database, table);
|
2007-11-12 01:13:08 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-01 06:29:43 +01:00
|
|
|
static HRESULT WINAPI mrd_GetPrimaryKeys( IWineMsiRemoteDatabase *iface,
|
2010-03-12 16:48:38 +01:00
|
|
|
LPCWSTR table, MSIHANDLE *keys )
|
2007-11-12 01:13:08 +01:00
|
|
|
{
|
2010-12-15 10:55:20 +01:00
|
|
|
msi_remote_database_impl *This = impl_from_IWineMsiRemoteDatabase( iface );
|
2009-01-15 09:46:57 +01:00
|
|
|
UINT r = MsiDatabaseGetPrimaryKeysW(This->database, table, keys);
|
2007-11-12 01:13:08 +01:00
|
|
|
return HRESULT_FROM_WIN32(r);
|
|
|
|
}
|
|
|
|
|
2008-03-01 06:29:43 +01:00
|
|
|
static HRESULT WINAPI mrd_GetSummaryInformation( IWineMsiRemoteDatabase *iface,
|
|
|
|
UINT updatecount, MSIHANDLE *suminfo )
|
2007-11-12 01:13:08 +01:00
|
|
|
{
|
2010-12-15 10:55:20 +01:00
|
|
|
msi_remote_database_impl *This = impl_from_IWineMsiRemoteDatabase( iface );
|
2007-11-12 01:13:08 +01:00
|
|
|
UINT r = MsiGetSummaryInformationW(This->database, NULL, updatecount, suminfo);
|
|
|
|
return HRESULT_FROM_WIN32(r);
|
|
|
|
}
|
|
|
|
|
2008-03-01 06:29:43 +01:00
|
|
|
static HRESULT WINAPI mrd_OpenView( IWineMsiRemoteDatabase *iface,
|
2010-03-12 16:48:38 +01:00
|
|
|
LPCWSTR query, MSIHANDLE *view )
|
2007-11-12 01:13:08 +01:00
|
|
|
{
|
2010-12-15 10:55:20 +01:00
|
|
|
msi_remote_database_impl *This = impl_from_IWineMsiRemoteDatabase( iface );
|
2009-01-15 09:46:57 +01:00
|
|
|
UINT r = MsiDatabaseOpenViewW(This->database, query, view);
|
2007-11-12 01:13:08 +01:00
|
|
|
return HRESULT_FROM_WIN32(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI mrd_SetMsiHandle( IWineMsiRemoteDatabase *iface, MSIHANDLE handle )
|
|
|
|
{
|
2010-12-15 10:55:20 +01:00
|
|
|
msi_remote_database_impl* This = impl_from_IWineMsiRemoteDatabase( iface );
|
2007-11-12 01:13:08 +01:00
|
|
|
This->database = handle;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IWineMsiRemoteDatabaseVtbl msi_remote_database_vtbl =
|
|
|
|
{
|
|
|
|
mrd_QueryInterface,
|
|
|
|
mrd_AddRef,
|
|
|
|
mrd_Release,
|
|
|
|
mrd_IsTablePersistent,
|
|
|
|
mrd_GetPrimaryKeys,
|
|
|
|
mrd_GetSummaryInformation,
|
|
|
|
mrd_OpenView,
|
|
|
|
mrd_SetMsiHandle,
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT create_msi_remote_database( IUnknown *pOuter, LPVOID *ppObj )
|
|
|
|
{
|
|
|
|
msi_remote_database_impl *This;
|
|
|
|
|
|
|
|
This = msi_alloc( sizeof *This );
|
|
|
|
if (!This)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2010-12-15 10:55:20 +01:00
|
|
|
This->IWineMsiRemoteDatabase_iface.lpVtbl = &msi_remote_database_vtbl;
|
2007-11-12 01:13:08 +01:00
|
|
|
This->database = 0;
|
|
|
|
This->refs = 1;
|
|
|
|
|
|
|
|
*ppObj = This;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|