2003-08-13 03:27:48 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
2005-09-22 12:34:07 +02:00
|
|
|
* Copyright 2002-2005 Mike McCormack for CodeWeavers
|
2003-08-13 03:27:48 +02: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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-08-13 03:27:48 +02:00
|
|
|
*/
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#include <stdarg.h>
|
2006-11-12 19:43:16 +01:00
|
|
|
#include <assert.h>
|
2004-10-07 05:06:48 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
2004-03-19 02:16:36 +01:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "msi.h"
|
|
|
|
#include "msiquery.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "objidl.h"
|
|
|
|
#include "winnls.h"
|
2006-10-17 11:00:33 +02:00
|
|
|
#include "msipriv.h"
|
2003-08-13 03:27:48 +02:00
|
|
|
#include "query.h"
|
|
|
|
|
2006-10-17 11:00:33 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2005-11-02 15:24:21 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msidb);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2006-03-18 17:12:15 +01:00
|
|
|
#define MSITABLE_HASH_TABLE_SIZE 37
|
|
|
|
|
|
|
|
typedef struct tagMSICOLUMNHASHENTRY
|
|
|
|
{
|
|
|
|
struct tagMSICOLUMNHASHENTRY *next;
|
|
|
|
UINT value;
|
|
|
|
UINT row;
|
|
|
|
} MSICOLUMNHASHENTRY;
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
typedef struct tagMSICOLUMNINFO
|
|
|
|
{
|
2011-07-25 15:57:43 +02:00
|
|
|
LPCWSTR tablename;
|
|
|
|
UINT number;
|
|
|
|
LPCWSTR colname;
|
|
|
|
UINT type;
|
|
|
|
UINT offset;
|
2006-03-18 17:12:15 +01:00
|
|
|
MSICOLUMNHASHENTRY **hash_table;
|
2003-08-13 03:27:48 +02:00
|
|
|
} MSICOLUMNINFO;
|
|
|
|
|
|
|
|
struct tagMSITABLE
|
|
|
|
{
|
2007-06-08 01:41:15 +02:00
|
|
|
BYTE **data;
|
2009-06-07 07:11:40 +02:00
|
|
|
BOOL *data_persistent;
|
2004-03-18 05:04:08 +01:00
|
|
|
UINT row_count;
|
2005-09-14 12:07:26 +02:00
|
|
|
struct list entry;
|
2007-04-23 09:20:21 +02:00
|
|
|
MSICOLUMNINFO *colinfo;
|
|
|
|
UINT col_count;
|
2009-02-26 04:45:15 +01:00
|
|
|
MSICONDITION persistent;
|
2022-02-04 09:49:54 +01:00
|
|
|
LONG ref_count;
|
2003-08-13 03:27:48 +02:00
|
|
|
WCHAR name[1];
|
2004-03-18 05:04:08 +01:00
|
|
|
};
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2007-04-23 09:20:21 +02:00
|
|
|
/* information for default tables */
|
2008-08-25 07:09:34 +02:00
|
|
|
static const MSICOLUMNINFO _Columns_cols[4] = {
|
2020-10-29 11:47:14 +01:00
|
|
|
{ L"_Columns", 1, L"Table", MSITYPE_VALID | MSITYPE_STRING | MSITYPE_KEY | 64, 0, NULL },
|
|
|
|
{ L"_Columns", 2, L"Number", MSITYPE_VALID | MSITYPE_KEY | 2, 2, NULL },
|
|
|
|
{ L"_Columns", 3, L"Name", MSITYPE_VALID | MSITYPE_STRING | 64, 4, NULL },
|
|
|
|
{ L"_Columns", 4, L"Type", MSITYPE_VALID | 2, 6, NULL },
|
2007-04-23 09:20:21 +02:00
|
|
|
};
|
2008-08-25 07:09:34 +02:00
|
|
|
|
|
|
|
static const MSICOLUMNINFO _Tables_cols[1] = {
|
2020-10-29 11:47:14 +01:00
|
|
|
{ L"_Tables", 1, L"Name", MSITYPE_VALID | MSITYPE_STRING | MSITYPE_KEY | 64, 0, NULL },
|
2007-04-23 09:20:21 +02:00
|
|
|
};
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
#define MAX_STREAM_NAME 0x1f
|
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
static inline UINT bytes_per_column( MSIDATABASE *db, const MSICOLUMNINFO *col, UINT bytes_per_strref )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2007-06-26 23:24:47 +02:00
|
|
|
if( MSITYPE_IS_BINARY(col->type) )
|
|
|
|
return 2;
|
2009-08-04 12:20:10 +02:00
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
if( col->type & MSITYPE_STRING )
|
2010-10-11 12:09:45 +02:00
|
|
|
return bytes_per_strref;
|
2009-08-04 12:20:10 +02:00
|
|
|
|
|
|
|
if( (col->type & 0xff) <= 2)
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
if( (col->type & 0xff) != 4 )
|
2015-02-13 13:37:22 +01:00
|
|
|
ERR("Invalid column size %u\n", col->type & 0xff);
|
2009-08-04 12:20:10 +02:00
|
|
|
|
|
|
|
return 4;
|
2004-03-18 05:04:08 +01:00
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
static int utf2mime(int x)
|
|
|
|
{
|
|
|
|
if( (x>='0') && (x<='9') )
|
|
|
|
return x-'0';
|
|
|
|
if( (x>='A') && (x<='Z') )
|
|
|
|
return x-'A'+10;
|
|
|
|
if( (x>='a') && (x<='z') )
|
|
|
|
return x-'a'+10+26;
|
|
|
|
if( x=='.' )
|
|
|
|
return 10+26+26;
|
|
|
|
if( x=='_' )
|
|
|
|
return 10+26+26+1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-12-17 04:05:12 +01:00
|
|
|
LPWSTR encode_streamname(BOOL bTable, LPCWSTR in)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
DWORD count = MAX_STREAM_NAME;
|
|
|
|
DWORD ch, next;
|
2004-07-06 21:00:46 +02:00
|
|
|
LPWSTR out, p;
|
|
|
|
|
|
|
|
if( !bTable )
|
2005-05-11 14:58:22 +02:00
|
|
|
count = lstrlenW( in )+2;
|
2011-02-01 14:02:01 +01:00
|
|
|
if (!(out = msi_alloc( count*sizeof(WCHAR) ))) return NULL;
|
2004-07-06 21:00:46 +02:00
|
|
|
p = out;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( bTable )
|
|
|
|
{
|
2004-07-06 21:00:46 +02:00
|
|
|
*p++ = 0x4840;
|
2003-08-13 03:27:48 +02:00
|
|
|
count --;
|
|
|
|
}
|
2020-10-29 11:47:14 +01:00
|
|
|
while( count -- )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
ch = *in++;
|
|
|
|
if( !ch )
|
|
|
|
{
|
2004-07-06 21:00:46 +02:00
|
|
|
*p = ch;
|
|
|
|
return out;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
if( ( ch < 0x80 ) && ( utf2mime(ch) >= 0 ) )
|
|
|
|
{
|
|
|
|
ch = utf2mime(ch) + 0x4800;
|
|
|
|
next = *in;
|
|
|
|
if( next && (next<0x80) )
|
|
|
|
{
|
|
|
|
next = utf2mime(next);
|
2007-12-26 22:44:22 +01:00
|
|
|
if( next != -1 )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
next += 0x3ffffc0;
|
|
|
|
ch += (next<<6);
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-06 21:00:46 +02:00
|
|
|
*p++ = ch;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2004-07-06 21:00:46 +02:00
|
|
|
ERR("Failed to encode stream name (%s)\n",debugstr_w(in));
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( out );
|
2004-07-06 21:00:46 +02:00
|
|
|
return NULL;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mime2utf(int x)
|
|
|
|
{
|
|
|
|
if( x<10 )
|
|
|
|
return x + '0';
|
|
|
|
if( x<(10+26))
|
|
|
|
return x - 10 + 'A';
|
|
|
|
if( x<(10+26+26))
|
|
|
|
return x - 10 - 26 + 'a';
|
|
|
|
if( x == (10+26+26) )
|
|
|
|
return '.';
|
|
|
|
return '_';
|
|
|
|
}
|
|
|
|
|
2007-06-13 23:36:31 +02:00
|
|
|
BOOL decode_streamname(LPCWSTR in, LPWSTR out)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
WCHAR ch;
|
|
|
|
DWORD count = 0;
|
|
|
|
|
|
|
|
while ( (ch = *in++) )
|
|
|
|
{
|
|
|
|
if( (ch >= 0x3800 ) && (ch < 0x4840 ) )
|
|
|
|
{
|
|
|
|
if( ch >= 0x4800 )
|
|
|
|
ch = mime2utf(ch-0x4800);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ch -= 0x3800;
|
|
|
|
*out++ = mime2utf(ch&0x3f);
|
|
|
|
count++;
|
|
|
|
ch = mime2utf((ch>>6)&0x3f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*out++ = ch;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
*out = 0;
|
|
|
|
return count;
|
|
|
|
}
|
2004-06-29 05:41:28 +02:00
|
|
|
|
|
|
|
void enum_stream_names( IStorage *stg )
|
|
|
|
{
|
|
|
|
IEnumSTATSTG *stgenum = NULL;
|
|
|
|
HRESULT r;
|
|
|
|
STATSTG stat;
|
|
|
|
ULONG n, count;
|
|
|
|
WCHAR name[0x40];
|
|
|
|
|
|
|
|
r = IStorage_EnumElements( stg, 0, NULL, 0, &stgenum );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
while( 1 )
|
|
|
|
{
|
|
|
|
count = 0;
|
|
|
|
r = IEnumSTATSTG_Next( stgenum, 1, &stat, &count );
|
|
|
|
if( FAILED( r ) || !count )
|
|
|
|
break;
|
|
|
|
decode_streamname( stat.pwcsName, name );
|
2022-02-07 17:47:05 +01:00
|
|
|
TRACE( "stream %2lu -> %s %s\n", n, debugstr_w(stat.pwcsName), debugstr_w(name) );
|
2007-12-26 12:02:55 +01:00
|
|
|
CoTaskMemFree( stat.pwcsName );
|
2004-06-29 05:41:28 +02:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumSTATSTG_Release( stgenum );
|
|
|
|
}
|
|
|
|
|
2007-07-16 23:45:29 +02:00
|
|
|
UINT read_stream_data( IStorage *stg, LPCWSTR stname, BOOL table,
|
2007-06-26 23:25:28 +02:00
|
|
|
BYTE **pdata, UINT *psz )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
UINT ret = ERROR_FUNCTION_FAILED;
|
|
|
|
VOID *data;
|
|
|
|
ULONG sz, count;
|
2003-10-28 22:49:06 +01:00
|
|
|
IStream *stm = NULL;
|
|
|
|
STATSTG stat;
|
2004-07-06 21:00:46 +02:00
|
|
|
LPWSTR encname;
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2007-07-16 23:45:29 +02:00
|
|
|
encname = encode_streamname(table, stname);
|
2004-03-18 05:04:08 +01:00
|
|
|
|
|
|
|
TRACE("%s -> %s\n",debugstr_w(stname),debugstr_w(encname));
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = IStorage_OpenStream(stg, encname, NULL,
|
2003-10-28 22:49:06 +01:00
|
|
|
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( encname );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
2022-02-07 17:47:05 +01:00
|
|
|
WARN( "open stream failed r = %#lx - empty table?\n", r );
|
2003-10-28 22:49:06 +01:00
|
|
|
return ret;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
r = IStream_Stat(stm, &stat, STATFLAG_NONAME );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
2022-02-07 17:47:05 +01:00
|
|
|
WARN( "open stream failed r = %#lx!\n", r );
|
2003-08-13 03:27:48 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( stat.cbSize.QuadPart >> 32 )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Too big!\n");
|
2003-08-13 03:27:48 +02:00
|
|
|
goto end;
|
|
|
|
}
|
2020-10-29 11:47:14 +01:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
sz = stat.cbSize.QuadPart;
|
2005-09-20 13:59:14 +02:00
|
|
|
data = msi_alloc( sz );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( !data )
|
|
|
|
{
|
2022-02-07 17:47:05 +01:00
|
|
|
WARN( "couldn't allocate memory r = %#lx!\n", r );
|
2003-10-28 22:49:06 +01:00
|
|
|
ret = ERROR_NOT_ENOUGH_MEMORY;
|
2003-08-13 03:27:48 +02:00
|
|
|
goto end;
|
|
|
|
}
|
2020-10-29 11:47:14 +01:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
r = IStream_Read(stm, data, sz, &count );
|
2003-10-28 22:49:06 +01:00
|
|
|
if( FAILED( r ) || ( count != sz ) )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( data );
|
2022-02-07 17:47:05 +01:00
|
|
|
WARN("read stream failed r = %#lx!\n", r);
|
2003-08-13 03:27:48 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2003-10-28 22:49:06 +01:00
|
|
|
*pdata = data;
|
|
|
|
*psz = sz;
|
|
|
|
ret = ERROR_SUCCESS;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
end:
|
2003-10-28 22:49:06 +01:00
|
|
|
IStream_Release( stm );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-04-23 09:17:40 +02:00
|
|
|
UINT write_stream_data( IStorage *stg, LPCWSTR stname,
|
2007-06-13 23:36:31 +02:00
|
|
|
LPCVOID data, UINT sz, BOOL bTable )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
UINT ret = ERROR_FUNCTION_FAILED;
|
|
|
|
ULONG count;
|
|
|
|
IStream *stm = NULL;
|
|
|
|
ULARGE_INTEGER size;
|
|
|
|
LARGE_INTEGER pos;
|
2004-07-06 21:00:46 +02:00
|
|
|
LPWSTR encname;
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2007-04-25 12:22:01 +02:00
|
|
|
encname = encode_streamname(bTable, stname );
|
2020-10-29 11:47:14 +01:00
|
|
|
r = IStorage_OpenStream( stg, encname, NULL,
|
2004-03-18 05:04:08 +01:00
|
|
|
STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, &stm);
|
2004-03-19 02:16:36 +01:00
|
|
|
if( FAILED(r) )
|
|
|
|
{
|
|
|
|
r = IStorage_CreateStream( stg, encname,
|
|
|
|
STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm);
|
|
|
|
}
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( encname );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
2022-02-07 17:47:05 +01:00
|
|
|
WARN( "open stream failed r = %#lx\n", r );
|
2004-03-18 05:04:08 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
size.QuadPart = sz;
|
|
|
|
r = IStream_SetSize( stm, size );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( FAILED( r ) )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Failed to SetSize\n");
|
2004-03-18 05:04:08 +01:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
r = IStream_Seek( stm, pos, STREAM_SEEK_SET, NULL );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( FAILED( r ) )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Failed to Seek\n");
|
2004-03-18 05:04:08 +01:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2007-04-23 09:17:40 +02:00
|
|
|
if (sz)
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2007-04-23 09:17:40 +02:00
|
|
|
r = IStream_Write(stm, data, sz, &count );
|
|
|
|
if( FAILED( r ) || ( count != sz ) )
|
|
|
|
{
|
|
|
|
WARN("Failed to Write\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2004-03-18 05:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
end:
|
|
|
|
IStream_Release( stm );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-06-07 10:35:58 +02:00
|
|
|
static void msi_free_colinfo( MSICOLUMNINFO *colinfo, UINT count )
|
|
|
|
{
|
|
|
|
UINT i;
|
2011-07-25 15:57:43 +02:00
|
|
|
for (i = 0; i < count; i++) msi_free( colinfo[i].hash_table );
|
2011-06-07 10:35:58 +02:00
|
|
|
}
|
|
|
|
|
2005-09-17 16:29:38 +02:00
|
|
|
static void free_table( MSITABLE *table )
|
|
|
|
{
|
2008-01-03 22:56:39 +01:00
|
|
|
UINT i;
|
2005-09-17 16:29:38 +02:00
|
|
|
for( i=0; i<table->row_count; i++ )
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( table->data[i] );
|
|
|
|
msi_free( table->data );
|
2009-06-07 07:11:40 +02:00
|
|
|
msi_free( table->data_persistent );
|
2008-08-25 07:09:34 +02:00
|
|
|
msi_free_colinfo( table->colinfo, table->col_count );
|
|
|
|
msi_free( table->colinfo );
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( table );
|
2005-09-17 16:29:38 +02:00
|
|
|
}
|
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
static UINT msi_table_get_row_size( MSIDATABASE *db, const MSICOLUMNINFO *cols, UINT count, UINT bytes_per_strref )
|
2005-09-26 15:25:48 +02:00
|
|
|
{
|
2010-10-11 12:09:45 +02:00
|
|
|
const MSICOLUMNINFO *last_col;
|
|
|
|
|
2005-09-26 15:25:48 +02:00
|
|
|
if (!count)
|
|
|
|
return 0;
|
2010-10-11 12:09:45 +02:00
|
|
|
|
|
|
|
if (bytes_per_strref != LONG_STR_BYTES)
|
|
|
|
{
|
|
|
|
UINT i, size = 0;
|
|
|
|
for (i = 0; i < count; i++) size += bytes_per_column( db, &cols[i], bytes_per_strref );
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
last_col = &cols[count - 1];
|
|
|
|
return last_col->offset + bytes_per_column( db, last_col, bytes_per_strref );
|
2005-09-26 15:25:48 +02:00
|
|
|
}
|
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
/* add this table to the list of cached tables in the database */
|
2008-08-25 07:09:34 +02:00
|
|
|
static UINT read_table_from_storage( MSIDATABASE *db, MSITABLE *t, IStorage *stg )
|
2003-10-28 22:49:06 +01:00
|
|
|
{
|
2007-06-08 01:41:15 +02:00
|
|
|
BYTE *rawdata = NULL;
|
2010-10-11 12:09:45 +02:00
|
|
|
UINT rawsize = 0, i, j, row_size, row_size_mem;
|
2003-10-28 22:49:06 +01:00
|
|
|
|
2007-04-23 09:20:21 +02:00
|
|
|
TRACE("%s\n",debugstr_w(t->name));
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
row_size = msi_table_get_row_size( db, t->colinfo, t->col_count, db->bytes_per_strref );
|
|
|
|
row_size_mem = msi_table_get_row_size( db, t->colinfo, t->col_count, LONG_STR_BYTES );
|
2003-10-28 22:49:06 +01:00
|
|
|
|
|
|
|
/* if we can't read the table, just assume that it's empty */
|
2007-07-16 23:45:29 +02:00
|
|
|
read_stream_data( stg, t->name, TRUE, &rawdata, &rawsize );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( !rawdata )
|
2007-04-23 09:20:21 +02:00
|
|
|
return ERROR_SUCCESS;
|
2004-03-18 05:04:08 +01:00
|
|
|
|
|
|
|
TRACE("Read %d bytes\n", rawsize );
|
|
|
|
|
|
|
|
if( rawsize % row_size )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Table size is invalid %d/%d\n", rawsize, row_size );
|
2005-09-21 12:20:20 +02:00
|
|
|
goto err;
|
2004-03-18 05:04:08 +01:00
|
|
|
}
|
|
|
|
|
2017-03-28 10:45:56 +02:00
|
|
|
if ((t->row_count = rawsize / row_size))
|
|
|
|
{
|
|
|
|
if (!(t->data = msi_alloc_zero( t->row_count * sizeof(USHORT *) ))) goto err;
|
|
|
|
if (!(t->data_persistent = msi_alloc_zero( t->row_count * sizeof(BOOL) ))) goto err;
|
|
|
|
}
|
2004-03-18 05:04:08 +01:00
|
|
|
|
|
|
|
/* transpose all the data */
|
2006-07-26 23:52:56 +02:00
|
|
|
TRACE("Transposing data from %d rows\n", t->row_count );
|
2010-10-11 12:09:45 +02:00
|
|
|
for (i = 0; i < t->row_count; i++)
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2010-10-11 12:09:45 +02:00
|
|
|
UINT ofs = 0, ofs_mem = 0;
|
|
|
|
|
|
|
|
t->data[i] = msi_alloc( row_size_mem );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( !t->data[i] )
|
2005-09-17 16:29:38 +02:00
|
|
|
goto err;
|
2009-06-07 07:11:40 +02:00
|
|
|
t->data_persistent[i] = TRUE;
|
2005-09-21 12:20:20 +02:00
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
for (j = 0; j < t->col_count; j++)
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2010-10-11 12:09:45 +02:00
|
|
|
UINT m = bytes_per_column( db, &t->colinfo[j], LONG_STR_BYTES );
|
|
|
|
UINT n = bytes_per_column( db, &t->colinfo[j], db->bytes_per_strref );
|
2007-06-08 01:40:31 +02:00
|
|
|
UINT k;
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2007-06-08 01:41:51 +02:00
|
|
|
if ( n != 2 && n != 3 && n != 4 )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
|
|
|
ERR("oops - unknown column width %d\n", n);
|
2005-09-17 16:29:38 +02:00
|
|
|
goto err;
|
2004-03-18 05:04:08 +01:00
|
|
|
}
|
2010-10-11 12:09:45 +02:00
|
|
|
if (t->colinfo[j].type & MSITYPE_STRING && n < m)
|
|
|
|
{
|
|
|
|
for (k = 0; k < m; k++)
|
|
|
|
{
|
|
|
|
if (k < n)
|
|
|
|
t->data[i][ofs_mem + k] = rawdata[ofs * t->row_count + i * n + k];
|
|
|
|
else
|
|
|
|
t->data[i][ofs_mem + k] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (k = 0; k < n; k++)
|
|
|
|
t->data[i][ofs_mem + k] = rawdata[ofs * t->row_count + i * n + k];
|
|
|
|
}
|
|
|
|
ofs_mem += m;
|
|
|
|
ofs += n;
|
2004-03-18 05:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( rawdata );
|
2007-04-23 09:20:21 +02:00
|
|
|
return ERROR_SUCCESS;
|
2005-09-17 16:29:38 +02:00
|
|
|
err:
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( rawdata );
|
2007-04-23 09:20:21 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void free_cached_tables( MSIDATABASE *db )
|
|
|
|
{
|
2005-09-14 12:07:26 +02:00
|
|
|
while( !list_empty( &db->tables ) )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-09-14 12:07:26 +02:00
|
|
|
MSITABLE *t = LIST_ENTRY( list_head( &db->tables ), MSITABLE, entry );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-14 12:07:26 +02:00
|
|
|
list_remove( &t->entry );
|
2005-09-21 12:20:20 +02:00
|
|
|
free_table( t );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
static MSITABLE *find_cached_table( MSIDATABASE *db, LPCWSTR name )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSITABLE *t;
|
|
|
|
|
2005-09-14 12:07:26 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( t, &db->tables, MSITABLE, entry )
|
2019-06-13 08:42:35 +02:00
|
|
|
if( !wcscmp( name, t->name ) )
|
2005-09-21 12:20:20 +02:00
|
|
|
return t;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-21 12:20:20 +02:00
|
|
|
return NULL;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2011-06-07 10:35:58 +02:00
|
|
|
static void table_calc_column_offsets( MSIDATABASE *db, MSICOLUMNINFO *colinfo, DWORD count )
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
for (i = 0; colinfo && i < count; i++)
|
|
|
|
{
|
|
|
|
assert( i + 1 == colinfo[i].number );
|
|
|
|
if (i) colinfo[i].offset = colinfo[i - 1].offset +
|
|
|
|
bytes_per_column( db, &colinfo[i - 1], LONG_STR_BYTES );
|
|
|
|
else colinfo[i].offset = 0;
|
|
|
|
|
|
|
|
TRACE("column %d is [%s] with type %08x ofs %d\n",
|
|
|
|
colinfo[i].number, debugstr_w(colinfo[i].colname),
|
|
|
|
colinfo[i].type, colinfo[i].offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT get_defaulttablecolumns( MSIDATABASE *db, LPCWSTR name, MSICOLUMNINFO *colinfo, UINT *sz )
|
|
|
|
{
|
|
|
|
const MSICOLUMNINFO *p;
|
|
|
|
DWORD i, n;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(name));
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if (!wcscmp( name, L"_Tables" ))
|
2011-06-07 10:35:58 +02:00
|
|
|
{
|
|
|
|
p = _Tables_cols;
|
|
|
|
n = 1;
|
|
|
|
}
|
2020-10-29 11:47:14 +01:00
|
|
|
else if (!wcscmp( name, L"_Columns" ))
|
2011-06-07 10:35:58 +02:00
|
|
|
{
|
|
|
|
p = _Columns_cols;
|
|
|
|
n = 4;
|
|
|
|
}
|
|
|
|
else return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
2011-07-25 15:57:43 +02:00
|
|
|
if (colinfo && i < *sz) colinfo[i] = p[i];
|
2011-06-07 10:35:58 +02:00
|
|
|
if (colinfo && i >= *sz) break;
|
|
|
|
}
|
|
|
|
table_calc_column_offsets( db, colinfo, n );
|
|
|
|
*sz = n;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT get_tablecolumns( MSIDATABASE *db, LPCWSTR szTableName, MSICOLUMNINFO *colinfo, UINT *sz );
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
static UINT table_get_column_info( MSIDATABASE *db, LPCWSTR name, MSICOLUMNINFO **pcols, UINT *pcount )
|
|
|
|
{
|
2005-09-22 12:34:07 +02:00
|
|
|
UINT r, column_count = 0;
|
2004-03-18 05:04:08 +01:00
|
|
|
MSICOLUMNINFO *columns;
|
|
|
|
|
|
|
|
/* get the number of columns in this table */
|
|
|
|
column_count = 0;
|
|
|
|
r = get_tablecolumns( db, name, NULL, &column_count );
|
2011-06-07 10:35:58 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
2004-03-18 05:04:08 +01:00
|
|
|
return r;
|
|
|
|
|
2008-10-07 08:52:00 +02:00
|
|
|
*pcount = column_count;
|
|
|
|
|
2013-11-20 23:39:28 +01:00
|
|
|
/* if there are no columns, there's no table */
|
2011-06-07 10:35:58 +02:00
|
|
|
if (!column_count)
|
2004-03-18 05:04:08 +01:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2011-06-07 10:35:58 +02:00
|
|
|
TRACE("table %s found\n", debugstr_w(name));
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2011-06-07 10:35:58 +02:00
|
|
|
columns = msi_alloc( column_count * sizeof(MSICOLUMNINFO) );
|
|
|
|
if (!columns)
|
2004-03-18 05:04:08 +01:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
r = get_tablecolumns( db, name, columns, &column_count );
|
2011-06-07 10:35:58 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( columns );
|
2004-03-18 05:04:08 +01:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
*pcols = columns;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-06-07 10:35:58 +02:00
|
|
|
static UINT get_table( MSIDATABASE *db, LPCWSTR name, MSITABLE **table_ret )
|
|
|
|
{
|
|
|
|
MSITABLE *table;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
/* first, see if the table is cached */
|
|
|
|
table = find_cached_table( db, name );
|
|
|
|
if (table)
|
|
|
|
{
|
|
|
|
*table_ret = table;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nonexistent tables should be interpreted as empty tables */
|
|
|
|
table = msi_alloc( sizeof(MSITABLE) + lstrlenW( name ) * sizeof(WCHAR) );
|
|
|
|
if (!table)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
table->row_count = 0;
|
|
|
|
table->data = NULL;
|
|
|
|
table->data_persistent = NULL;
|
|
|
|
table->colinfo = NULL;
|
|
|
|
table->col_count = 0;
|
|
|
|
table->persistent = MSICONDITION_TRUE;
|
|
|
|
lstrcpyW( table->name, name );
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if (!wcscmp( name, L"_Tables" ) || !wcscmp( name, L"_Columns" ))
|
2011-06-07 10:35:58 +02:00
|
|
|
table->persistent = MSICONDITION_NONE;
|
|
|
|
|
|
|
|
r = table_get_column_info( db, name, &table->colinfo, &table->col_count );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
free_table( table );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
r = read_table_from_storage( db, table, db->storage );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
free_table( table );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
list_add_head( &db->tables, &table->entry );
|
|
|
|
*table_ret = table;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT read_table_int( BYTE *const *data, UINT row, UINT col, UINT bytes )
|
|
|
|
{
|
|
|
|
UINT ret = 0, i;
|
|
|
|
|
|
|
|
for (i = 0; i < bytes; i++)
|
|
|
|
ret += data[row][col + i] << i * 8;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT get_tablecolumns( MSIDATABASE *db, LPCWSTR szTableName, MSICOLUMNINFO *colinfo, UINT *sz )
|
|
|
|
{
|
|
|
|
UINT r, i, n = 0, table_id, count, maxcount = *sz;
|
|
|
|
MSITABLE *table = NULL;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(szTableName));
|
|
|
|
|
|
|
|
/* first check if there is a default table with that name */
|
|
|
|
r = get_defaulttablecolumns( db, szTableName, colinfo, sz );
|
|
|
|
if (r == ERROR_SUCCESS && *sz)
|
|
|
|
return r;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = get_table( db, L"_Columns", &table );
|
2011-06-07 10:35:58 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("couldn't load _Columns table\n");
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert table and column names to IDs from the string table */
|
2012-10-29 12:12:50 +01:00
|
|
|
r = msi_string2id( db->strings, szTableName, -1, &table_id );
|
2011-06-07 10:35:58 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WARN("Couldn't find id for %s\n", debugstr_w(szTableName));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
TRACE("Table id is %d, row count is %d\n", table_id, table->row_count);
|
|
|
|
|
|
|
|
/* Note: _Columns table doesn't have non-persistent data */
|
|
|
|
|
|
|
|
/* if maxcount is non-zero, assume it's exactly right for this table */
|
2014-05-18 19:27:42 +02:00
|
|
|
if (colinfo) memset( colinfo, 0, maxcount * sizeof(*colinfo) );
|
2011-06-07 10:35:58 +02:00
|
|
|
count = table->row_count;
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (read_table_int( table->data, i, 0, LONG_STR_BYTES) != table_id) continue;
|
|
|
|
if (colinfo)
|
|
|
|
{
|
|
|
|
UINT id = read_table_int( table->data, i, table->colinfo[2].offset, LONG_STR_BYTES );
|
|
|
|
UINT col = read_table_int( table->data, i, table->colinfo[1].offset, sizeof(USHORT) ) - (1 << 15);
|
|
|
|
|
|
|
|
/* check the column number is in range */
|
|
|
|
if (col < 1 || col > maxcount)
|
|
|
|
{
|
2014-05-18 19:27:42 +02:00
|
|
|
ERR("column %d out of range (maxcount: %d)\n", col, maxcount);
|
2011-06-07 10:35:58 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* check if this column was already set */
|
|
|
|
if (colinfo[col - 1].number)
|
|
|
|
{
|
|
|
|
ERR("duplicate column %d\n", col);
|
|
|
|
continue;
|
|
|
|
}
|
2012-10-29 12:12:50 +01:00
|
|
|
colinfo[col - 1].tablename = msi_string_lookup( db->strings, table_id, NULL );
|
2011-06-07 10:35:58 +02:00
|
|
|
colinfo[col - 1].number = col;
|
2012-10-29 12:12:50 +01:00
|
|
|
colinfo[col - 1].colname = msi_string_lookup( db->strings, id, NULL );
|
2011-06-07 10:35:58 +02:00
|
|
|
colinfo[col - 1].type = read_table_int( table->data, i, table->colinfo[3].offset,
|
|
|
|
sizeof(USHORT) ) - (1 << 15);
|
|
|
|
colinfo[col - 1].offset = 0;
|
|
|
|
colinfo[col - 1].hash_table = NULL;
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
TRACE("%s has %d columns\n", debugstr_w(szTableName), n);
|
|
|
|
|
|
|
|
if (colinfo && n != maxcount)
|
|
|
|
{
|
|
|
|
ERR("missing column in table %s\n", debugstr_w(szTableName));
|
|
|
|
msi_free_colinfo( colinfo, maxcount );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
table_calc_column_offsets( db, colinfo, n );
|
|
|
|
*sz = n;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-04-23 09:21:32 +02:00
|
|
|
UINT msi_create_table( MSIDATABASE *db, LPCWSTR name, column_info *col_info,
|
2020-06-30 05:40:20 +02:00
|
|
|
MSICONDITION persistent, BOOL hold )
|
2007-04-23 09:21:32 +02:00
|
|
|
{
|
|
|
|
UINT r, nField;
|
|
|
|
MSIVIEW *tv = NULL;
|
|
|
|
MSIRECORD *rec = NULL;
|
|
|
|
column_info *col;
|
2007-04-23 09:22:27 +02:00
|
|
|
MSITABLE *table;
|
|
|
|
UINT i;
|
2007-04-23 09:21:32 +02:00
|
|
|
|
|
|
|
/* only add tables that don't exist already */
|
|
|
|
if( TABLE_Exists(db, name ) )
|
2007-04-23 09:24:41 +02:00
|
|
|
{
|
|
|
|
WARN("table %s exists\n", debugstr_w(name));
|
2007-04-23 09:21:32 +02:00
|
|
|
return ERROR_BAD_QUERY_SYNTAX;
|
2007-04-23 09:24:41 +02:00
|
|
|
}
|
2007-04-23 09:21:32 +02:00
|
|
|
|
2007-04-23 09:22:27 +02:00
|
|
|
table = msi_alloc( sizeof (MSITABLE) + lstrlenW(name)*sizeof (WCHAR) );
|
|
|
|
if( !table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2020-06-30 05:40:20 +02:00
|
|
|
table->ref_count = 0;
|
2007-04-23 09:22:27 +02:00
|
|
|
table->row_count = 0;
|
|
|
|
table->data = NULL;
|
2009-06-07 07:11:40 +02:00
|
|
|
table->data_persistent = NULL;
|
2007-04-23 09:22:27 +02:00
|
|
|
table->colinfo = NULL;
|
|
|
|
table->col_count = 0;
|
2007-04-24 12:00:44 +02:00
|
|
|
table->persistent = persistent;
|
2007-04-23 09:22:27 +02:00
|
|
|
lstrcpyW( table->name, name );
|
|
|
|
|
2020-06-30 05:40:20 +02:00
|
|
|
if( hold )
|
|
|
|
table->ref_count++;
|
|
|
|
|
2007-04-23 09:22:27 +02:00
|
|
|
for( col = col_info; col; col = col->next )
|
|
|
|
table->col_count++;
|
|
|
|
|
|
|
|
table->colinfo = msi_alloc( table->col_count * sizeof(MSICOLUMNINFO) );
|
|
|
|
if (!table->colinfo)
|
|
|
|
{
|
|
|
|
free_table( table );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( i = 0, col = col_info; col; i++, col = col->next )
|
|
|
|
{
|
2019-01-24 07:07:32 +01:00
|
|
|
UINT table_id = msi_add_string( db->strings, col->table, -1, persistent );
|
|
|
|
UINT col_id = msi_add_string( db->strings, col->column, -1, persistent );
|
2011-07-27 10:52:48 +02:00
|
|
|
|
2012-10-29 12:12:50 +01:00
|
|
|
table->colinfo[ i ].tablename = msi_string_lookup( db->strings, table_id, NULL );
|
2007-04-23 09:22:27 +02:00
|
|
|
table->colinfo[ i ].number = i + 1;
|
2012-10-29 12:12:50 +01:00
|
|
|
table->colinfo[ i ].colname = msi_string_lookup( db->strings, col_id, NULL );
|
2007-04-23 09:22:27 +02:00
|
|
|
table->colinfo[ i ].type = col->type;
|
|
|
|
table->colinfo[ i ].offset = 0;
|
|
|
|
table->colinfo[ i ].hash_table = NULL;
|
|
|
|
}
|
2008-08-25 07:09:34 +02:00
|
|
|
table_calc_column_offsets( db, table->colinfo, table->col_count);
|
2007-04-23 09:22:27 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = TABLE_CreateView( db, L"_Tables", &tv );
|
2007-04-23 09:21:32 +02:00
|
|
|
TRACE("CreateView returned %x\n", r);
|
|
|
|
if( r )
|
2007-04-23 09:22:27 +02:00
|
|
|
{
|
|
|
|
free_table( table );
|
2007-04-23 09:21:32 +02:00
|
|
|
return r;
|
2007-04-23 09:22:27 +02:00
|
|
|
}
|
2007-04-23 09:21:32 +02:00
|
|
|
|
|
|
|
r = tv->ops->execute( tv, 0 );
|
|
|
|
TRACE("tv execute returned %x\n", r);
|
|
|
|
if( r )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
rec = MSI_CreateRecord( 1 );
|
|
|
|
if( !rec )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
r = MSI_RecordSetStringW( rec, 1, name );
|
|
|
|
if( r )
|
|
|
|
goto err;
|
|
|
|
|
2009-10-20 14:30:46 +02:00
|
|
|
r = tv->ops->insert_row( tv, rec, -1, persistent == MSICONDITION_FALSE );
|
2007-04-23 09:21:32 +02:00
|
|
|
TRACE("insert_row returned %x\n", r);
|
|
|
|
if( r )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
tv->ops->delete( tv );
|
|
|
|
tv = NULL;
|
|
|
|
|
|
|
|
msiobj_release( &rec->hdr );
|
2007-04-24 13:31:31 +02:00
|
|
|
rec = NULL;
|
2007-04-23 09:21:32 +02:00
|
|
|
|
2009-02-26 04:45:15 +01:00
|
|
|
if( persistent != MSICONDITION_FALSE )
|
2007-04-23 09:21:32 +02:00
|
|
|
{
|
2007-04-23 09:25:17 +02:00
|
|
|
/* add each column to the _Columns table */
|
2020-10-29 11:47:14 +01:00
|
|
|
r = TABLE_CreateView( db, L"_Columns", &tv );
|
2007-04-23 09:21:32 +02:00
|
|
|
if( r )
|
2015-07-15 15:13:35 +02:00
|
|
|
goto err;
|
2007-04-23 09:21:32 +02:00
|
|
|
|
2007-04-23 09:25:17 +02:00
|
|
|
r = tv->ops->execute( tv, 0 );
|
|
|
|
TRACE("tv execute returned %x\n", r);
|
2007-04-23 09:21:32 +02:00
|
|
|
if( r )
|
|
|
|
goto err;
|
|
|
|
|
2007-04-23 09:25:17 +02:00
|
|
|
rec = MSI_CreateRecord( 4 );
|
|
|
|
if( !rec )
|
2007-04-23 09:21:32 +02:00
|
|
|
goto err;
|
|
|
|
|
2007-04-23 09:25:17 +02:00
|
|
|
r = MSI_RecordSetStringW( rec, 1, name );
|
2007-04-23 09:21:32 +02:00
|
|
|
if( r )
|
|
|
|
goto err;
|
|
|
|
|
2007-04-23 09:25:17 +02:00
|
|
|
/*
|
|
|
|
* need to set the table, column number, col name and type
|
|
|
|
* for each column we enter in the table
|
|
|
|
*/
|
|
|
|
nField = 1;
|
|
|
|
for( col = col_info; col; col = col->next )
|
|
|
|
{
|
|
|
|
r = MSI_RecordSetInteger( rec, 2, nField );
|
|
|
|
if( r )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
r = MSI_RecordSetStringW( rec, 3, col->column );
|
|
|
|
if( r )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
r = MSI_RecordSetInteger( rec, 4, col->type );
|
|
|
|
if( r )
|
|
|
|
goto err;
|
|
|
|
|
2009-10-20 14:30:46 +02:00
|
|
|
r = tv->ops->insert_row( tv, rec, -1, FALSE );
|
2007-04-23 09:25:17 +02:00
|
|
|
if( r )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
nField++;
|
|
|
|
}
|
|
|
|
if( !col )
|
|
|
|
r = ERROR_SUCCESS;
|
2007-04-23 09:21:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (rec)
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
/* FIXME: remove values from the string table on error */
|
|
|
|
if( tv )
|
|
|
|
tv->ops->delete( tv );
|
|
|
|
|
|
|
|
if (r == ERROR_SUCCESS)
|
2007-04-23 09:22:27 +02:00
|
|
|
list_add_head( &db->tables, &table->entry );
|
|
|
|
else
|
|
|
|
free_table( table );
|
|
|
|
|
2007-04-23 09:21:32 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
static UINT save_table( MSIDATABASE *db, const MSITABLE *t, UINT bytes_per_strref )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2010-10-11 12:09:45 +02:00
|
|
|
BYTE *rawdata = NULL;
|
2011-01-27 11:55:19 +01:00
|
|
|
UINT rawsize, i, j, row_size, row_count;
|
|
|
|
UINT r = ERROR_FUNCTION_FAILED;
|
2004-03-19 02:16:36 +01:00
|
|
|
|
2007-04-24 12:00:44 +02:00
|
|
|
/* Nothing to do for non-persistent tables */
|
2009-02-26 04:45:15 +01:00
|
|
|
if( t->persistent == MSICONDITION_FALSE )
|
2007-04-24 12:00:44 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
TRACE("Saving %s\n", debugstr_w( t->name ) );
|
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
row_size = msi_table_get_row_size( db, t->colinfo, t->col_count, bytes_per_strref );
|
|
|
|
row_count = t->row_count;
|
|
|
|
for (i = 0; i < t->row_count; i++)
|
|
|
|
{
|
|
|
|
if (!t->data_persistent[i])
|
|
|
|
{
|
|
|
|
row_count = 1; /* yes, this is bizarre */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rawsize = row_count * row_size;
|
2005-09-20 13:59:14 +02:00
|
|
|
rawdata = msi_alloc_zero( rawsize );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( !rawdata )
|
2005-09-26 15:25:48 +02:00
|
|
|
{
|
|
|
|
r = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
goto err;
|
|
|
|
}
|
2004-03-19 02:16:36 +01:00
|
|
|
|
2009-06-07 07:11:40 +02:00
|
|
|
rawsize = 0;
|
2015-04-21 11:20:24 +02:00
|
|
|
for (i = 0; i < row_count; i++)
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
2010-10-11 12:09:45 +02:00
|
|
|
UINT ofs = 0, ofs_mem = 0;
|
|
|
|
|
|
|
|
if (!t->data_persistent[i]) break;
|
2004-03-19 02:16:36 +01:00
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
for (j = 0; j < t->col_count; j++)
|
|
|
|
{
|
|
|
|
UINT m = bytes_per_column( db, &t->colinfo[j], LONG_STR_BYTES );
|
|
|
|
UINT n = bytes_per_column( db, &t->colinfo[j], bytes_per_strref );
|
|
|
|
UINT k;
|
2009-06-07 07:11:40 +02:00
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
if (n != 2 && n != 3 && n != 4)
|
2007-06-08 01:41:15 +02:00
|
|
|
{
|
2010-10-11 12:09:45 +02:00
|
|
|
ERR("oops - unknown column width %d\n", n);
|
|
|
|
goto err;
|
2007-06-08 01:41:15 +02:00
|
|
|
}
|
2010-10-11 12:09:45 +02:00
|
|
|
if (t->colinfo[j].type & MSITYPE_STRING && n < m)
|
|
|
|
{
|
|
|
|
UINT id = read_table_int( t->data, i, ofs_mem, LONG_STR_BYTES );
|
|
|
|
if (id > 1 << bytes_per_strref * 8)
|
|
|
|
{
|
|
|
|
ERR("string id %u out of range\n", id);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (k = 0; k < n; k++)
|
|
|
|
{
|
|
|
|
rawdata[ofs * row_count + i * n + k] = t->data[i][ofs_mem + k];
|
|
|
|
}
|
|
|
|
ofs_mem += m;
|
|
|
|
ofs += n;
|
2004-03-19 02:16:36 +01:00
|
|
|
}
|
2010-10-11 12:09:45 +02:00
|
|
|
rawsize += row_size;
|
2004-03-19 02:16:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("writing %d bytes\n", rawsize);
|
2007-04-25 12:22:01 +02:00
|
|
|
r = write_stream_data( db->storage, t->name, rawdata, rawsize, TRUE );
|
2004-03-19 02:16:36 +01:00
|
|
|
|
2005-09-26 15:25:48 +02:00
|
|
|
err:
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( rawdata );
|
2004-03-19 02:16:36 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2007-07-20 23:01:13 +02:00
|
|
|
static void msi_update_table_columns( MSIDATABASE *db, LPCWSTR name )
|
|
|
|
{
|
|
|
|
MSITABLE *table;
|
2007-10-17 14:13:53 +02:00
|
|
|
UINT size, offset, old_count;
|
2008-01-03 22:56:39 +01:00
|
|
|
UINT n;
|
2007-07-20 23:01:13 +02:00
|
|
|
|
2015-02-13 13:37:22 +01:00
|
|
|
if (!(table = find_cached_table( db, name ))) return;
|
2007-10-17 14:13:53 +02:00
|
|
|
old_count = table->col_count;
|
2009-12-08 04:55:21 +01:00
|
|
|
msi_free_colinfo( table->colinfo, table->col_count );
|
2007-07-20 23:01:13 +02:00
|
|
|
msi_free( table->colinfo );
|
2009-04-20 16:08:26 +02:00
|
|
|
table->colinfo = NULL;
|
2007-07-20 23:01:13 +02:00
|
|
|
|
2011-07-25 15:57:43 +02:00
|
|
|
table_get_column_info( db, name, &table->colinfo, &table->col_count );
|
|
|
|
if (!table->col_count) return;
|
2008-10-07 08:52:00 +02:00
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
size = msi_table_get_row_size( db, table->colinfo, table->col_count, LONG_STR_BYTES );
|
2007-07-20 23:01:13 +02:00
|
|
|
offset = table->colinfo[table->col_count - 1].offset;
|
|
|
|
|
|
|
|
for ( n = 0; n < table->row_count; n++ )
|
|
|
|
{
|
|
|
|
table->data[n] = msi_realloc( table->data[n], size );
|
2007-10-17 14:13:53 +02:00
|
|
|
if (old_count < table->col_count)
|
|
|
|
memset( &table->data[n][offset], 0, size - offset );
|
2007-07-20 23:01:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
/* try to find the table name in the _Tables table */
|
2007-04-21 09:33:10 +02:00
|
|
|
BOOL TABLE_Exists( MSIDATABASE *db, LPCWSTR name )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2010-09-08 12:17:01 +02:00
|
|
|
UINT r, table_id, i;
|
|
|
|
MSITABLE *table;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if( !wcscmp( name, L"_Tables" ) || !wcscmp( name, L"_Columns" ) ||
|
|
|
|
!wcscmp( name, L"_Streams" ) || !wcscmp( name, L"_Storages" ) )
|
2003-08-13 03:27:48 +02:00
|
|
|
return TRUE;
|
|
|
|
|
2012-10-29 12:12:50 +01:00
|
|
|
r = msi_string2id( db->strings, name, -1, &table_id );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
2004-03-19 02:16:36 +01:00
|
|
|
TRACE("Couldn't find id for %s\n", debugstr_w(name));
|
2003-08-13 03:27:48 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = get_table( db, L"_Tables", &table );
|
2007-04-23 09:20:21 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2020-10-29 11:47:14 +01:00
|
|
|
ERR("table _Tables not available\n");
|
2003-08-13 03:27:48 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-09-08 12:17:01 +02:00
|
|
|
for( i = 0; i < table->row_count; i++ )
|
|
|
|
{
|
2010-10-11 12:09:45 +02:00
|
|
|
if( read_table_int( table->data, i, 0, LONG_STR_BYTES ) == table_id )
|
2008-10-02 22:56:54 +02:00
|
|
|
return TRUE;
|
2010-09-08 12:17:01 +02:00
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* below is the query interface to a table */
|
|
|
|
|
|
|
|
typedef struct tagMSITABLEVIEW
|
|
|
|
{
|
|
|
|
MSIVIEW view;
|
|
|
|
MSIDATABASE *db;
|
|
|
|
MSITABLE *table;
|
|
|
|
MSICOLUMNINFO *columns;
|
|
|
|
UINT num_cols;
|
|
|
|
UINT row_size;
|
|
|
|
WCHAR name[1];
|
|
|
|
} MSITABLEVIEW;
|
|
|
|
|
|
|
|
static UINT TABLE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
2007-04-23 09:24:41 +02:00
|
|
|
UINT offset, n;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( !tv->table )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if( (col==0) || (col>tv->num_cols) )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
/* how many rows are there ? */
|
2009-06-07 07:11:40 +02:00
|
|
|
if( row >= tv->table->row_count )
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_NO_MORE_ITEMS;
|
|
|
|
|
|
|
|
if( tv->columns[col-1].offset >= tv->row_size )
|
|
|
|
{
|
|
|
|
ERR("Stuffed up %d >= %d\n", tv->columns[col-1].offset, tv->row_size );
|
|
|
|
ERR("%p %p\n", tv, tv->columns );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
n = bytes_per_column( tv->db, &tv->columns[col - 1], LONG_STR_BYTES );
|
2007-06-08 01:41:51 +02:00
|
|
|
if (n != 2 && n != 3 && n != 4)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
ERR("oops! what is %d bytes per column?\n", n );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2007-06-08 01:41:15 +02:00
|
|
|
offset = tv->columns[col-1].offset;
|
2009-06-07 07:11:40 +02:00
|
|
|
*val = read_table_int(tv->table->data, row, offset, n);
|
2007-06-08 01:40:31 +02:00
|
|
|
|
2005-11-10 13:14:56 +01:00
|
|
|
/* TRACE("Data [%d][%d] = %d\n", row, col, *val ); */
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-03-04 14:30:08 +01:00
|
|
|
static UINT get_stream_name( const MSITABLEVIEW *tv, UINT row, WCHAR **pstname )
|
2009-05-24 18:51:53 +02:00
|
|
|
{
|
|
|
|
LPWSTR p, stname = NULL;
|
|
|
|
UINT i, r, type, ival;
|
|
|
|
DWORD len;
|
|
|
|
LPCWSTR sval;
|
|
|
|
MSIVIEW *view = (MSIVIEW *) tv;
|
|
|
|
|
|
|
|
TRACE("%p %d\n", tv, row);
|
|
|
|
|
|
|
|
len = lstrlenW( tv->name ) + 1;
|
|
|
|
stname = msi_alloc( len*sizeof(WCHAR) );
|
|
|
|
if ( !stname )
|
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
lstrcpyW( stname, tv->name );
|
|
|
|
|
|
|
|
for ( i = 0; i < tv->num_cols; i++ )
|
|
|
|
{
|
|
|
|
type = tv->columns[i].type;
|
|
|
|
if ( type & MSITYPE_KEY )
|
|
|
|
{
|
2011-03-04 13:48:27 +01:00
|
|
|
WCHAR number[0x20];
|
|
|
|
|
2009-05-24 18:51:53 +02:00
|
|
|
r = TABLE_fetch_int( view, row, i+1, &ival );
|
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if ( tv->columns[i].type & MSITYPE_STRING )
|
|
|
|
{
|
2012-10-29 12:12:50 +01:00
|
|
|
sval = msi_string_lookup( tv->db->strings, ival, NULL );
|
2009-05-24 18:51:53 +02:00
|
|
|
if ( !sval )
|
|
|
|
{
|
|
|
|
r = ERROR_INVALID_PARAMETER;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-11 12:09:45 +02:00
|
|
|
UINT n = bytes_per_column( tv->db, &tv->columns[i], LONG_STR_BYTES );
|
2009-05-24 18:51:53 +02:00
|
|
|
|
|
|
|
switch( n )
|
|
|
|
{
|
|
|
|
case 2:
|
2020-10-29 11:47:14 +01:00
|
|
|
swprintf( number, ARRAY_SIZE(number), L"%d", ival-0x8000 );
|
2009-05-24 18:51:53 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
2020-10-29 11:47:14 +01:00
|
|
|
swprintf( number, ARRAY_SIZE(number), L"%d", ival^0x80000000 );
|
2009-05-24 18:51:53 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR( "oops - unknown column width %d\n", n );
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
sval = number;
|
|
|
|
}
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
len += lstrlenW( L"." ) + lstrlenW( sval );
|
2009-05-24 18:51:53 +02:00
|
|
|
p = msi_realloc ( stname, len*sizeof(WCHAR) );
|
|
|
|
if ( !p )
|
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
stname = p;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
lstrcatW( stname, L"." );
|
2009-05-24 18:51:53 +02:00
|
|
|
lstrcatW( stname, sval );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pstname = stname;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
err:
|
|
|
|
msi_free( stname );
|
|
|
|
*pstname = NULL;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2004-07-06 20:56:12 +02:00
|
|
|
/*
|
|
|
|
* We need a special case for streams, as we need to reference column with
|
|
|
|
* the name of the stream in the same table, and the table name
|
|
|
|
* which may not be available at higher levels of the query
|
|
|
|
*/
|
|
|
|
static UINT TABLE_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
2009-05-24 18:51:53 +02:00
|
|
|
UINT r;
|
2015-02-13 13:39:38 +01:00
|
|
|
WCHAR *name;
|
2004-07-06 20:56:12 +02:00
|
|
|
|
|
|
|
if( !view->ops->fetch_int )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2015-03-04 14:30:08 +01:00
|
|
|
r = get_stream_name( tv, row, &name );
|
2015-02-13 13:39:38 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
2006-10-17 11:00:33 +02:00
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
ERR("fetching stream, error = %u\n", r);
|
2009-05-24 18:51:53 +02:00
|
|
|
return r;
|
2006-10-17 11:00:33 +02:00
|
|
|
}
|
2004-07-06 20:56:12 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
r = msi_get_stream( tv->db, name, stm );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
ERR("fetching stream %s, error = %u\n", debugstr_w(name), r);
|
2004-07-06 20:56:12 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
msi_free( name );
|
2004-07-06 20:56:12 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2019-01-26 23:58:58 +01:00
|
|
|
/* Set a table value, i.e. preadjusted integer or string ID. */
|
|
|
|
static UINT table_set_bytes( MSITABLEVIEW *tv, UINT row, UINT col, UINT val )
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
2007-06-08 01:40:31 +02:00
|
|
|
UINT offset, n, i;
|
2004-03-19 02:16:36 +01:00
|
|
|
|
|
|
|
if( !tv->table )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if( (col==0) || (col>tv->num_cols) )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2009-06-07 07:11:40 +02:00
|
|
|
if( row >= tv->table->row_count )
|
2007-04-23 09:24:41 +02:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
if( tv->columns[col-1].offset >= tv->row_size )
|
|
|
|
{
|
|
|
|
ERR("Stuffed up %d >= %d\n", tv->columns[col-1].offset, tv->row_size );
|
|
|
|
ERR("%p %p\n", tv, tv->columns );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2007-04-23 09:19:07 +02:00
|
|
|
msi_free( tv->columns[col-1].hash_table );
|
|
|
|
tv->columns[col-1].hash_table = NULL;
|
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
n = bytes_per_column( tv->db, &tv->columns[col - 1], LONG_STR_BYTES );
|
2007-06-08 01:41:51 +02:00
|
|
|
if ( n != 2 && n != 3 && n != 4 )
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
|
|
|
ERR("oops! what is %d bytes per column?\n", n );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
2007-06-08 01:40:31 +02:00
|
|
|
|
2007-06-08 01:41:15 +02:00
|
|
|
offset = tv->columns[col-1].offset;
|
|
|
|
for ( i = 0; i < n; i++ )
|
2009-06-07 07:11:40 +02:00
|
|
|
tv->table->data[row][offset + i] = (val >> i * 8) & 0xff;
|
2007-06-08 01:40:31 +02:00
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-01-26 23:58:57 +01:00
|
|
|
static UINT int_to_table_storage( const MSITABLEVIEW *tv, UINT col, int val, UINT *ret )
|
|
|
|
{
|
|
|
|
if ((tv->columns[col-1].type & MSI_DATASIZEMASK) == 2)
|
|
|
|
{
|
|
|
|
if (val == MSI_NULL_INTEGER)
|
|
|
|
*ret = 0;
|
|
|
|
else if ((val + 0x8000) & 0xffff0000)
|
|
|
|
{
|
|
|
|
ERR("value %d out of range\n", val);
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*ret = val + 0x8000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*ret = val ^ 0x80000000;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-01-26 23:58:58 +01:00
|
|
|
static UINT TABLE_set_int( MSIVIEW *view, UINT row, UINT col, int val )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW *)view;
|
|
|
|
UINT r, table_int;
|
|
|
|
|
|
|
|
TRACE("row %u, col %u, val %d.\n", row, col, val);
|
|
|
|
|
|
|
|
if ((r = int_to_table_storage( tv, col, val, &table_int )))
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (tv->columns[col-1].type & MSITYPE_KEY)
|
|
|
|
{
|
|
|
|
UINT key;
|
|
|
|
|
|
|
|
if ((r = TABLE_fetch_int( view, row, col, &key )))
|
|
|
|
return r;
|
|
|
|
if (key != table_int)
|
|
|
|
{
|
|
|
|
ERR("Cannot modify primary key %s.%s.\n",
|
|
|
|
debugstr_w(tv->table->name), debugstr_w(tv->columns[col-1].colname));
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return table_set_bytes( tv, row, col, table_int );
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TABLE_set_string( MSIVIEW *view, UINT row, UINT col, const WCHAR *val, int len )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW *)view;
|
|
|
|
BOOL persistent;
|
|
|
|
UINT id, r;
|
|
|
|
|
|
|
|
TRACE("row %u, col %u, val %s.\n", row, col, debugstr_wn(val, len));
|
|
|
|
|
|
|
|
persistent = (tv->table->persistent != MSICONDITION_FALSE)
|
|
|
|
&& tv->table->data_persistent[row];
|
|
|
|
|
|
|
|
if (val)
|
|
|
|
{
|
|
|
|
r = msi_string2id( tv->db->strings, val, len, &id );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
id = msi_add_string( tv->db->strings, val, len, persistent );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
id = 0;
|
|
|
|
|
|
|
|
if (tv->columns[col-1].type & MSITYPE_KEY)
|
|
|
|
{
|
|
|
|
UINT key;
|
|
|
|
|
|
|
|
if ((r = TABLE_fetch_int( view, row, col, &key )))
|
|
|
|
return r;
|
|
|
|
if (key != id)
|
|
|
|
{
|
|
|
|
ERR("Cannot modify primary key %s.%s.\n",
|
|
|
|
debugstr_w(tv->table->name), debugstr_w(tv->columns[col-1].colname));
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return table_set_bytes( tv, row, col, id );
|
|
|
|
}
|
|
|
|
|
2007-07-27 02:40:38 +02:00
|
|
|
static UINT TABLE_get_row( struct tagMSIVIEW *view, UINT row, MSIRECORD **rec )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW *)view;
|
|
|
|
|
|
|
|
if (!tv->table)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
return msi_view_get_row(tv->db, view, row, rec);
|
|
|
|
}
|
|
|
|
|
2015-03-04 14:30:08 +01:00
|
|
|
static UINT add_stream( MSIDATABASE *db, const WCHAR *name, IStream *data )
|
2009-05-24 18:51:53 +02:00
|
|
|
{
|
2015-03-04 14:30:08 +01:00
|
|
|
MSIQUERY *query;
|
2011-07-27 10:53:26 +02:00
|
|
|
MSIRECORD *rec;
|
|
|
|
UINT r;
|
2009-05-24 18:51:53 +02:00
|
|
|
|
|
|
|
TRACE("%p %s %p\n", db, debugstr_w(name), data);
|
|
|
|
|
2015-03-04 14:30:08 +01:00
|
|
|
if (!(rec = MSI_CreateRecord( 2 )))
|
2009-05-24 18:51:53 +02:00
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
r = MSI_RecordSetStringW( rec, 1, name );
|
2015-03-04 14:30:08 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
2009-05-24 18:51:53 +02:00
|
|
|
|
|
|
|
r = MSI_RecordSetIStream( rec, 2, data );
|
2015-03-04 14:30:08 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
2009-05-24 18:51:53 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = MSI_DatabaseOpenViewW( db, L"INSERT INTO `_Streams` (`Name`,`Data`) VALUES (?,?)", &query );
|
2015-03-04 14:30:08 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
2009-05-24 18:51:53 +02:00
|
|
|
|
|
|
|
r = MSI_ViewExecute( query, rec );
|
2015-03-04 14:30:08 +01:00
|
|
|
msiobj_release( &query->hdr );
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
goto done;
|
2009-05-24 18:51:53 +02:00
|
|
|
|
2015-03-04 14:30:08 +01:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
if (!(rec = MSI_CreateRecord( 2 )))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
r = MSI_RecordSetIStream( rec, 1, data );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
r = MSI_RecordSetStringW( rec, 2, name );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = MSI_DatabaseOpenViewW( db, L"UPDATE `_Streams` SET `Data` = ? WHERE `Name` = ?", &query );
|
2015-03-04 14:30:08 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( query, rec );
|
2009-05-24 18:51:53 +02:00
|
|
|
msiobj_release( &query->hdr );
|
2015-03-04 14:30:08 +01:00
|
|
|
|
|
|
|
done:
|
2009-05-24 18:51:53 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2019-01-29 05:11:08 +01:00
|
|
|
static UINT TABLE_set_stream( MSIVIEW *view, UINT row, UINT col, IStream *stream )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW *)view;
|
|
|
|
WCHAR *name;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("row %u, col %u, stream %p.\n", row, col, stream);
|
|
|
|
|
|
|
|
if ((r = get_stream_name( tv, row - 1, &name )))
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = add_stream( tv->db, name, stream );
|
|
|
|
msi_free( name );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-10-20 14:29:02 +02:00
|
|
|
static UINT get_table_value_from_record( MSITABLEVIEW *tv, MSIRECORD *rec, UINT iField, UINT *pvalue )
|
|
|
|
{
|
|
|
|
MSICOLUMNINFO columninfo;
|
|
|
|
UINT r;
|
|
|
|
|
2018-06-26 09:06:48 +02:00
|
|
|
if (!iField || iField > tv->num_cols || MSI_RecordIsNull( rec, iField ))
|
2009-10-20 14:29:02 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
columninfo = tv->columns[ iField - 1 ];
|
|
|
|
|
|
|
|
if ( MSITYPE_IS_BINARY(columninfo.type) )
|
|
|
|
{
|
|
|
|
*pvalue = 1; /* refers to the first key column */
|
|
|
|
}
|
|
|
|
else if ( columninfo.type & MSITYPE_STRING )
|
|
|
|
{
|
2012-10-29 12:14:44 +01:00
|
|
|
int len;
|
|
|
|
const WCHAR *sval = msi_record_get_string( rec, iField, &len );
|
2010-10-19 11:27:44 +02:00
|
|
|
if (sval)
|
|
|
|
{
|
2012-10-29 12:14:44 +01:00
|
|
|
r = msi_string2id( tv->db->strings, sval, len, pvalue );
|
2010-10-19 11:27:44 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return ERROR_NOT_FOUND;
|
|
|
|
}
|
|
|
|
else *pvalue = 0;
|
2009-10-20 14:29:02 +02:00
|
|
|
}
|
|
|
|
else
|
2019-01-26 23:58:57 +01:00
|
|
|
return int_to_table_storage( tv, iField, MSI_RecordGetInteger( rec, iField ), pvalue );
|
2009-10-20 14:29:02 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-10-26 10:09:47 +02:00
|
|
|
static UINT TABLE_set_row( struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UINT mask )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
UINT i, val, r = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
if ( !tv->table )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
/* test if any of the mask bits are invalid */
|
|
|
|
if ( mask >= (1<<tv->num_cols) )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
for ( i = 0; i < tv->num_cols; i++ )
|
|
|
|
{
|
2007-04-23 09:27:37 +02:00
|
|
|
BOOL persistent;
|
|
|
|
|
2006-10-26 10:09:47 +02:00
|
|
|
/* only update the fields specified in the mask */
|
|
|
|
if ( !(mask&(1<<i)) )
|
|
|
|
continue;
|
|
|
|
|
2009-02-26 04:45:15 +01:00
|
|
|
persistent = (tv->table->persistent != MSICONDITION_FALSE) &&
|
2009-06-07 07:11:40 +02:00
|
|
|
(tv->table->data_persistent[row]);
|
2006-10-26 10:09:47 +02:00
|
|
|
/* FIXME: should we allow updating keys? */
|
|
|
|
|
|
|
|
val = 0;
|
|
|
|
if ( !MSI_RecordIsNull( rec, i + 1 ) )
|
|
|
|
{
|
2009-10-20 14:29:02 +02:00
|
|
|
r = get_table_value_from_record (tv, rec, i + 1, &val);
|
2006-10-26 10:09:47 +02:00
|
|
|
if ( MSITYPE_IS_BINARY(tv->columns[ i ].type) )
|
|
|
|
{
|
2009-05-24 18:51:53 +02:00
|
|
|
IStream *stm;
|
|
|
|
LPWSTR stname;
|
|
|
|
|
2009-10-20 14:29:02 +02:00
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2009-05-24 18:51:53 +02:00
|
|
|
r = MSI_RecordGetIStream( rec, i + 1, &stm );
|
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
2015-03-04 14:30:08 +01:00
|
|
|
r = get_stream_name( tv, row, &stname );
|
2009-05-24 18:51:53 +02:00
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
IStream_Release( stm );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2015-03-04 14:30:08 +01:00
|
|
|
r = add_stream( tv->db, stname, stm );
|
2009-05-24 18:51:53 +02:00
|
|
|
IStream_Release( stm );
|
|
|
|
msi_free ( stname );
|
|
|
|
|
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
2006-10-26 10:09:47 +02:00
|
|
|
}
|
|
|
|
else if ( tv->columns[i].type & MSITYPE_STRING )
|
|
|
|
{
|
2009-10-20 14:29:02 +02:00
|
|
|
UINT x;
|
2007-11-05 10:48:15 +01:00
|
|
|
|
2009-10-20 14:29:02 +02:00
|
|
|
if ( r != ERROR_SUCCESS )
|
2007-11-05 10:48:15 +01:00
|
|
|
{
|
2012-10-29 12:14:44 +01:00
|
|
|
int len;
|
|
|
|
const WCHAR *sval = msi_record_get_string( rec, i + 1, &len );
|
2019-01-24 07:07:32 +01:00
|
|
|
val = msi_add_string( tv->db->strings, sval, len, persistent );
|
2009-10-20 14:29:02 +02:00
|
|
|
}
|
|
|
|
else
|
2006-10-26 10:09:47 +02:00
|
|
|
{
|
2009-10-20 14:29:02 +02:00
|
|
|
TABLE_fetch_int(&tv->view, row, i + 1, &x);
|
|
|
|
if (val == x)
|
|
|
|
continue;
|
2006-10-26 10:09:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-20 14:29:02 +02:00
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2006-10-26 10:09:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-26 23:58:58 +01:00
|
|
|
r = table_set_bytes( tv, row, i+1, val );
|
2006-10-26 10:09:47 +02:00
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2007-04-23 09:24:41 +02:00
|
|
|
static UINT table_create_new_row( struct tagMSIVIEW *view, UINT *num, BOOL temporary )
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
2007-06-08 01:41:15 +02:00
|
|
|
BYTE **p, *row;
|
2009-06-07 07:11:40 +02:00
|
|
|
BOOL *b;
|
2004-03-19 02:16:36 +01:00
|
|
|
UINT sz;
|
2007-06-08 01:41:15 +02:00
|
|
|
BYTE ***data_ptr;
|
2009-06-07 07:11:40 +02:00
|
|
|
BOOL **data_persist_ptr;
|
2007-04-23 09:24:41 +02:00
|
|
|
UINT *row_count;
|
2004-03-19 02:16:36 +01:00
|
|
|
|
2007-04-23 09:24:41 +02:00
|
|
|
TRACE("%p %s\n", view, temporary ? "TRUE" : "FALSE");
|
2004-03-19 02:16:36 +01:00
|
|
|
|
|
|
|
if( !tv->table )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
row = msi_alloc_zero( tv->row_size );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( !row )
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
|
2009-06-07 07:11:40 +02:00
|
|
|
row_count = &tv->table->row_count;
|
|
|
|
data_ptr = &tv->table->data;
|
|
|
|
data_persist_ptr = &tv->table->data_persistent;
|
|
|
|
if (*num == -1)
|
|
|
|
*num = tv->table->row_count;
|
2007-04-23 09:24:41 +02:00
|
|
|
|
2007-06-08 01:41:15 +02:00
|
|
|
sz = (*row_count + 1) * sizeof (BYTE*);
|
2007-04-23 09:24:41 +02:00
|
|
|
if( *data_ptr )
|
|
|
|
p = msi_realloc( *data_ptr, sz );
|
2004-03-19 02:16:36 +01:00
|
|
|
else
|
2005-09-20 13:59:14 +02:00
|
|
|
p = msi_alloc( sz );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( !p )
|
2004-12-10 16:24:52 +01:00
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( row );
|
2004-03-19 02:16:36 +01:00
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
2004-12-10 16:24:52 +01:00
|
|
|
}
|
2004-03-19 02:16:36 +01:00
|
|
|
|
2009-06-07 07:11:40 +02:00
|
|
|
sz = (*row_count + 1) * sizeof (BOOL);
|
|
|
|
if( *data_persist_ptr )
|
|
|
|
b = msi_realloc( *data_persist_ptr, sz );
|
|
|
|
else
|
|
|
|
b = msi_alloc( sz );
|
|
|
|
if( !b )
|
|
|
|
{
|
|
|
|
msi_free( row );
|
|
|
|
msi_free( p );
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
}
|
|
|
|
|
2007-04-23 09:24:41 +02:00
|
|
|
*data_ptr = p;
|
|
|
|
(*data_ptr)[*row_count] = row;
|
2009-06-07 07:11:40 +02:00
|
|
|
|
|
|
|
*data_persist_ptr = b;
|
|
|
|
(*data_persist_ptr)[*row_count] = !temporary;
|
|
|
|
|
2007-04-23 09:24:41 +02:00
|
|
|
(*row_count)++;
|
2004-03-19 02:16:36 +01:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
static UINT TABLE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
TRACE("%p %p\n", tv, record);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
TRACE("There are %d columns\n", tv->num_cols );
|
2005-08-24 13:10:23 +02:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TABLE_close( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
TRACE("%p\n", view );
|
2020-10-29 11:47:14 +01:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TABLE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols)
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %p %p\n", view, rows, cols );
|
|
|
|
|
|
|
|
if( cols )
|
|
|
|
*cols = tv->num_cols;
|
|
|
|
if( rows )
|
|
|
|
{
|
|
|
|
if( !tv->table )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2009-06-07 07:11:40 +02:00
|
|
|
*rows = tv->table->row_count;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TABLE_get_column_info( struct tagMSIVIEW *view,
|
2011-07-27 10:53:10 +02:00
|
|
|
UINT n, LPCWSTR *name, UINT *type, BOOL *temporary,
|
|
|
|
LPCWSTR *table_name )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %d %p %p\n", tv, n, name, type );
|
|
|
|
|
|
|
|
if( ( n == 0 ) || ( n > tv->num_cols ) )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if( name )
|
|
|
|
{
|
2011-07-27 10:53:10 +02:00
|
|
|
*name = tv->columns[n-1].colname;
|
2003-08-13 03:27:48 +02:00
|
|
|
if( !*name )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
2009-03-02 06:41:39 +01:00
|
|
|
|
2009-10-18 18:41:41 +02:00
|
|
|
if( table_name )
|
|
|
|
{
|
2011-07-27 10:53:10 +02:00
|
|
|
*table_name = tv->columns[n-1].tablename;
|
2009-10-18 18:41:41 +02:00
|
|
|
if( !*table_name )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
if( type )
|
|
|
|
*type = tv->columns[n-1].type;
|
|
|
|
|
2009-03-02 06:41:39 +01:00
|
|
|
if( temporary )
|
2020-06-30 05:40:57 +02:00
|
|
|
*temporary = (tv->columns[n-1].type & MSITYPE_TEMPORARY) != 0;
|
2009-03-02 06:41:39 +01:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-06-07 10:34:49 +02:00
|
|
|
static UINT msi_table_find_row( MSITABLEVIEW *tv, MSIRECORD *rec, UINT *row, UINT *column );
|
2005-08-24 13:10:23 +02:00
|
|
|
|
2011-06-07 10:34:49 +02:00
|
|
|
static UINT table_validate_new( MSITABLEVIEW *tv, MSIRECORD *rec, UINT *column )
|
2005-08-24 13:10:23 +02:00
|
|
|
{
|
2006-08-31 10:06:20 +02:00
|
|
|
UINT r, row, i;
|
2005-08-24 13:10:23 +02:00
|
|
|
|
2013-11-20 23:39:28 +01:00
|
|
|
/* check there are no null values where they're not allowed */
|
2006-08-31 10:06:20 +02:00
|
|
|
for( i = 0; i < tv->num_cols; i++ )
|
|
|
|
{
|
|
|
|
if ( tv->columns[i].type & MSITYPE_NULLABLE )
|
|
|
|
continue;
|
|
|
|
|
2006-10-17 10:48:53 +02:00
|
|
|
if ( MSITYPE_IS_BINARY(tv->columns[i].type) )
|
|
|
|
TRACE("skipping binary column\n");
|
|
|
|
else if ( tv->columns[i].type & MSITYPE_STRING )
|
2006-08-31 10:06:20 +02:00
|
|
|
{
|
2012-10-29 12:14:44 +01:00
|
|
|
int len;
|
|
|
|
const WCHAR *str = msi_record_get_string( rec, i+1, &len );
|
2006-08-31 10:06:20 +02:00
|
|
|
|
2012-10-29 12:14:44 +01:00
|
|
|
if (!str || (!str[0] && !len))
|
2011-06-07 10:34:49 +02:00
|
|
|
{
|
|
|
|
if (column) *column = i;
|
2006-08-31 10:06:20 +02:00
|
|
|
return ERROR_INVALID_DATA;
|
2011-06-07 10:34:49 +02:00
|
|
|
}
|
2006-08-31 10:06:20 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UINT n;
|
|
|
|
|
|
|
|
n = MSI_RecordGetInteger( rec, i+1 );
|
|
|
|
if (n == MSI_NULL_INTEGER)
|
2011-06-07 10:34:49 +02:00
|
|
|
{
|
|
|
|
if (column) *column = i;
|
2006-08-31 10:06:20 +02:00
|
|
|
return ERROR_INVALID_DATA;
|
2011-06-07 10:34:49 +02:00
|
|
|
}
|
2006-08-31 10:06:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-20 23:39:28 +01:00
|
|
|
/* check there are no duplicate keys */
|
2011-06-07 10:34:49 +02:00
|
|
|
r = msi_table_find_row( tv, rec, &row, column );
|
2006-08-31 10:06:20 +02:00
|
|
|
if (r == ERROR_SUCCESS)
|
2007-10-18 05:53:54 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2006-08-31 10:06:20 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2005-08-24 13:10:23 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 17:09:16 +02:00
|
|
|
static int compare_record( MSITABLEVIEW *tv, UINT row, MSIRECORD *rec )
|
2009-10-20 14:29:54 +02:00
|
|
|
{
|
2010-09-24 17:09:16 +02:00
|
|
|
UINT r, i, ivalue, x;
|
2009-10-20 14:29:54 +02:00
|
|
|
|
2010-09-24 17:09:16 +02:00
|
|
|
for (i = 0; i < tv->num_cols; i++ )
|
2009-10-20 14:29:54 +02:00
|
|
|
{
|
2011-03-07 12:40:06 +01:00
|
|
|
if (!(tv->columns[i].type & MSITYPE_KEY)) continue;
|
|
|
|
|
2010-09-24 17:09:16 +02:00
|
|
|
r = get_table_value_from_record( tv, rec, i + 1, &ivalue );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
r = TABLE_fetch_int( &tv->view, row, i + 1, &x );
|
|
|
|
if (r != ERROR_SUCCESS)
|
2009-10-20 14:29:54 +02:00
|
|
|
{
|
2010-09-24 17:09:16 +02:00
|
|
|
WARN("TABLE_fetch_int should not fail here %u\n", r);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (ivalue > x)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (ivalue == x)
|
|
|
|
{
|
|
|
|
if (i < tv->num_cols - 1) continue;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2009-10-20 14:29:54 +02:00
|
|
|
|
2010-09-24 17:09:16 +02:00
|
|
|
static int find_insert_index( MSITABLEVIEW *tv, MSIRECORD *rec )
|
|
|
|
{
|
|
|
|
int idx, c, low = 0, high = tv->table->row_count - 1;
|
2009-10-20 14:29:54 +02:00
|
|
|
|
2010-09-24 17:09:16 +02:00
|
|
|
TRACE("%p %p\n", tv, rec);
|
|
|
|
|
|
|
|
while (low <= high)
|
|
|
|
{
|
|
|
|
idx = (low + high) / 2;
|
|
|
|
c = compare_record( tv, idx, rec );
|
|
|
|
|
|
|
|
if (c < 0)
|
|
|
|
high = idx - 1;
|
|
|
|
else if (c > 0)
|
|
|
|
low = idx + 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("found %u\n", idx);
|
|
|
|
return idx;
|
2009-10-20 14:29:54 +02:00
|
|
|
}
|
|
|
|
}
|
2010-09-24 17:09:16 +02:00
|
|
|
TRACE("found %u\n", high + 1);
|
|
|
|
return high + 1;
|
2009-10-20 14:29:54 +02:00
|
|
|
}
|
|
|
|
|
2009-03-02 06:41:22 +01:00
|
|
|
static UINT TABLE_insert_row( struct tagMSIVIEW *view, MSIRECORD *rec, UINT row, BOOL temporary )
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
2009-06-07 07:11:40 +02:00
|
|
|
UINT i, r;
|
2005-10-27 14:25:04 +02:00
|
|
|
|
2007-04-23 09:24:41 +02:00
|
|
|
TRACE("%p %p %s\n", tv, rec, temporary ? "TRUE" : "FALSE" );
|
2005-10-27 14:25:04 +02:00
|
|
|
|
2006-08-31 10:06:20 +02:00
|
|
|
/* check that the key is unique - can we find a matching row? */
|
2011-06-07 10:34:49 +02:00
|
|
|
r = table_validate_new( tv, rec, NULL );
|
2006-08-31 10:06:20 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2009-10-20 14:29:54 +02:00
|
|
|
if (row == -1)
|
2010-09-24 17:09:16 +02:00
|
|
|
row = find_insert_index( tv, rec );
|
2009-10-20 14:29:54 +02:00
|
|
|
|
2007-04-23 09:24:41 +02:00
|
|
|
r = table_create_new_row( view, &row, temporary );
|
2005-10-27 14:25:04 +02:00
|
|
|
TRACE("insert_row returned %08x\n", r);
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
2009-03-02 06:41:22 +01:00
|
|
|
/* shift the rows to make room for the new row */
|
2009-06-07 07:11:40 +02:00
|
|
|
for (i = tv->table->row_count - 1; i > row; i--)
|
2009-03-02 06:41:22 +01:00
|
|
|
{
|
2009-06-07 07:11:40 +02:00
|
|
|
memmove(&(tv->table->data[i][0]),
|
|
|
|
&(tv->table->data[i - 1][0]), tv->row_size);
|
|
|
|
tv->table->data_persistent[i] = tv->table->data_persistent[i - 1];
|
2009-03-02 06:41:22 +01:00
|
|
|
}
|
|
|
|
|
2009-06-07 07:11:40 +02:00
|
|
|
/* Re-set the persistence flag */
|
|
|
|
tv->table->data_persistent[row] = !temporary;
|
2006-10-26 10:09:47 +02:00
|
|
|
return TABLE_set_row( view, row, rec, (1<<tv->num_cols) - 1 );
|
2005-10-27 14:25:04 +02:00
|
|
|
}
|
|
|
|
|
2007-06-18 22:49:31 +02:00
|
|
|
static UINT TABLE_delete_row( struct tagMSIVIEW *view, UINT row )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
2007-11-05 10:35:13 +01:00
|
|
|
UINT r, num_rows, num_cols, i;
|
2007-06-18 22:49:31 +02:00
|
|
|
|
|
|
|
TRACE("%p %d\n", tv, row);
|
|
|
|
|
|
|
|
if ( !tv->table )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
r = TABLE_get_dimensions( view, &num_rows, &num_cols );
|
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if ( row >= num_rows )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2009-06-07 07:11:40 +02:00
|
|
|
num_rows = tv->table->row_count;
|
|
|
|
tv->table->row_count--;
|
2007-06-18 22:49:31 +02:00
|
|
|
|
2008-01-09 09:36:25 +01:00
|
|
|
/* reset the hash tables */
|
|
|
|
for (i = 0; i < tv->num_cols; i++)
|
|
|
|
{
|
|
|
|
msi_free( tv->columns[i].hash_table );
|
|
|
|
tv->columns[i].hash_table = NULL;
|
|
|
|
}
|
|
|
|
|
2007-11-05 10:35:13 +01:00
|
|
|
for (i = row + 1; i < num_rows; i++)
|
2009-06-07 07:11:40 +02:00
|
|
|
{
|
|
|
|
memcpy(tv->table->data[i - 1], tv->table->data[i], tv->row_size);
|
|
|
|
tv->table->data_persistent[i - 1] = tv->table->data_persistent[i];
|
|
|
|
}
|
2007-11-05 10:35:13 +01:00
|
|
|
|
2009-12-08 04:54:37 +01:00
|
|
|
msi_free(tv->table->data[num_rows - 1]);
|
|
|
|
|
2007-06-18 22:49:31 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-07-27 02:40:38 +02:00
|
|
|
static UINT msi_table_update(struct tagMSIVIEW *view, MSIRECORD *rec, UINT row)
|
2007-07-24 04:20:51 +02:00
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW *)view;
|
2007-07-27 02:40:38 +02:00
|
|
|
UINT r, new_row;
|
2007-07-24 04:20:51 +02:00
|
|
|
|
|
|
|
/* FIXME: MsiViewFetch should set rec index 0 to some ID that
|
|
|
|
* sets the fetched record apart from other records
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!tv->table)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2011-06-07 10:34:49 +02:00
|
|
|
r = msi_table_find_row(tv, rec, &new_row, NULL);
|
2007-07-24 04:20:51 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
2007-07-27 02:40:38 +02:00
|
|
|
{
|
|
|
|
ERR("can't find row to modify\n");
|
2007-10-18 05:54:39 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2007-07-27 02:40:38 +02:00
|
|
|
}
|
2007-07-24 04:20:51 +02:00
|
|
|
|
|
|
|
/* the row cannot be changed */
|
2019-01-24 07:07:33 +01:00
|
|
|
if (row != new_row)
|
2007-07-24 04:20:51 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2007-07-27 02:40:38 +02:00
|
|
|
return TABLE_set_row(view, new_row, rec, (1 << tv->num_cols) - 1);
|
2007-07-24 04:20:51 +02:00
|
|
|
}
|
|
|
|
|
2009-07-06 12:26:20 +02:00
|
|
|
static UINT msi_table_assign(struct tagMSIVIEW *view, MSIRECORD *rec)
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW *)view;
|
|
|
|
UINT r, row;
|
|
|
|
|
|
|
|
if (!tv->table)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2011-06-07 10:34:49 +02:00
|
|
|
r = msi_table_find_row(tv, rec, &row, NULL);
|
2009-07-06 12:26:20 +02:00
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
return TABLE_set_row(view, row, rec, (1 << tv->num_cols) - 1);
|
|
|
|
else
|
|
|
|
return TABLE_insert_row( view, rec, -1, FALSE );
|
|
|
|
}
|
|
|
|
|
2008-02-14 06:36:44 +01:00
|
|
|
static UINT msi_refresh_record( struct tagMSIVIEW *view, MSIRECORD *rec, UINT row )
|
|
|
|
{
|
|
|
|
MSIRECORD *curr;
|
|
|
|
UINT r, i, count;
|
|
|
|
|
2019-01-24 07:07:33 +01:00
|
|
|
r = TABLE_get_row(view, row, &curr);
|
2008-02-14 06:36:44 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
2009-12-11 02:01:12 +01:00
|
|
|
/* Close the original record */
|
|
|
|
MSI_CloseRecord(&rec->hdr);
|
|
|
|
|
2008-02-14 06:36:44 +01:00
|
|
|
count = MSI_RecordGetFieldCount(rec);
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
MSI_RecordCopyField(curr, i + 1, rec, i + 1);
|
|
|
|
|
|
|
|
msiobj_release(&curr->hdr);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-02-08 14:44:25 +01:00
|
|
|
static UINT TABLE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
|
2007-07-27 02:40:38 +02:00
|
|
|
MSIRECORD *rec, UINT row)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-08-24 13:10:23 +02:00
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
2012-03-19 23:19:17 +01:00
|
|
|
UINT r, frow, column;
|
2005-08-24 13:10:23 +02:00
|
|
|
|
|
|
|
TRACE("%p %d %p\n", view, eModifyMode, rec );
|
|
|
|
|
|
|
|
switch (eModifyMode)
|
|
|
|
{
|
2007-11-05 10:35:13 +01:00
|
|
|
case MSIMODIFY_DELETE:
|
2019-01-29 05:11:12 +01:00
|
|
|
r = TABLE_delete_row( view, row );
|
2007-11-05 10:35:13 +01:00
|
|
|
break;
|
2005-08-24 13:10:23 +02:00
|
|
|
case MSIMODIFY_VALIDATE_NEW:
|
2011-06-07 10:34:49 +02:00
|
|
|
r = table_validate_new( tv, rec, &column );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
tv->view.error = MSIDBERROR_DUPLICATEKEY;
|
|
|
|
tv->view.error_column = tv->columns[column].colname;
|
|
|
|
r = ERROR_INVALID_DATA;
|
|
|
|
}
|
2005-08-24 13:10:23 +02:00
|
|
|
break;
|
|
|
|
|
2007-12-22 04:04:18 +01:00
|
|
|
case MSIMODIFY_INSERT:
|
2011-06-07 10:34:49 +02:00
|
|
|
r = table_validate_new( tv, rec, NULL );
|
2007-12-22 04:04:18 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
2009-03-02 06:41:22 +01:00
|
|
|
r = TABLE_insert_row( view, rec, -1, FALSE );
|
2007-12-22 04:04:18 +01:00
|
|
|
break;
|
|
|
|
|
2005-08-24 13:10:23 +02:00
|
|
|
case MSIMODIFY_INSERT_TEMPORARY:
|
2011-06-07 10:34:49 +02:00
|
|
|
r = table_validate_new( tv, rec, NULL );
|
2005-08-24 13:10:23 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
2009-03-02 06:41:22 +01:00
|
|
|
r = TABLE_insert_row( view, rec, -1, TRUE );
|
2005-08-24 13:10:23 +02:00
|
|
|
break;
|
|
|
|
|
2008-02-14 06:36:44 +01:00
|
|
|
case MSIMODIFY_REFRESH:
|
|
|
|
r = msi_refresh_record( view, rec, row );
|
|
|
|
break;
|
|
|
|
|
2007-07-24 04:20:51 +02:00
|
|
|
case MSIMODIFY_UPDATE:
|
2007-07-27 02:40:38 +02:00
|
|
|
r = msi_table_update( view, rec, row );
|
2007-07-24 04:20:51 +02:00
|
|
|
break;
|
|
|
|
|
2005-08-24 13:10:23 +02:00
|
|
|
case MSIMODIFY_ASSIGN:
|
2009-07-06 12:26:20 +02:00
|
|
|
r = msi_table_assign( view, rec );
|
|
|
|
break;
|
|
|
|
|
2005-08-24 13:10:23 +02:00
|
|
|
case MSIMODIFY_MERGE:
|
2012-03-19 23:19:17 +01:00
|
|
|
/* check row that matches this record */
|
|
|
|
r = msi_table_find_row( tv, rec, &frow, &column );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
r = table_validate_new( tv, rec, NULL );
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
r = TABLE_insert_row( view, rec, -1, FALSE );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSIMODIFY_REPLACE:
|
2005-08-24 13:10:23 +02:00
|
|
|
case MSIMODIFY_VALIDATE:
|
|
|
|
case MSIMODIFY_VALIDATE_FIELD:
|
|
|
|
case MSIMODIFY_VALIDATE_DELETE:
|
|
|
|
FIXME("%p %d %p - mode not implemented\n", view, eModifyMode, rec );
|
|
|
|
r = ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
r = ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TABLE_delete( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p\n", view );
|
|
|
|
|
|
|
|
tv->table = NULL;
|
|
|
|
tv->columns = NULL;
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( tv );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-07-19 03:21:00 +02:00
|
|
|
static UINT TABLE_add_ref(struct tagMSIVIEW *view)
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
2022-02-07 17:47:05 +01:00
|
|
|
TRACE( "%p, %ld\n", view, tv->table->ref_count );
|
2007-07-19 03:21:00 +02:00
|
|
|
return InterlockedIncrement(&tv->table->ref_count);
|
|
|
|
}
|
|
|
|
|
2020-07-01 10:43:05 +02:00
|
|
|
static UINT TABLE_remove_column(struct tagMSIVIEW *view, UINT number)
|
2007-07-21 03:41:16 +02:00
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
2007-07-24 04:19:15 +02:00
|
|
|
MSIRECORD *rec = NULL;
|
2007-07-21 03:41:16 +02:00
|
|
|
MSIVIEW *columns = NULL;
|
|
|
|
UINT row, r;
|
|
|
|
|
2020-06-30 05:40:06 +02:00
|
|
|
if (tv->table->col_count != number)
|
|
|
|
return ERROR_BAD_QUERY_SYNTAX;
|
|
|
|
|
2020-06-30 05:40:57 +02:00
|
|
|
if (tv->table->colinfo[number-1].type & MSITYPE_TEMPORARY)
|
2020-06-30 05:40:06 +02:00
|
|
|
{
|
|
|
|
UINT size = tv->table->colinfo[number-1].offset;
|
|
|
|
tv->table->col_count--;
|
|
|
|
tv->table->colinfo = msi_realloc( tv->table->colinfo, sizeof(*tv->table->colinfo) * tv->table->col_count );
|
|
|
|
|
|
|
|
for (row = 0; row < tv->table->row_count; row++)
|
|
|
|
tv->table->data[row] = msi_realloc( tv->table->data[row], size );
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-07-21 03:41:16 +02:00
|
|
|
rec = MSI_CreateRecord(2);
|
|
|
|
if (!rec)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
2020-07-01 10:43:05 +02:00
|
|
|
MSI_RecordSetStringW(rec, 1, tv->name);
|
2007-07-21 03:41:16 +02:00
|
|
|
MSI_RecordSetInteger(rec, 2, number);
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = TABLE_CreateView(tv->db, L"_Columns", &columns);
|
2007-07-21 03:41:16 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
2014-03-27 03:57:30 +01:00
|
|
|
{
|
|
|
|
msiobj_release(&rec->hdr);
|
2007-07-21 03:41:16 +02:00
|
|
|
return r;
|
2014-03-27 03:57:30 +01:00
|
|
|
}
|
2007-07-21 03:41:16 +02:00
|
|
|
|
2011-06-07 10:34:49 +02:00
|
|
|
r = msi_table_find_row((MSITABLEVIEW *)columns, rec, &row, NULL);
|
2007-07-21 03:41:16 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
r = TABLE_delete_row(columns, row);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
2020-07-01 10:43:05 +02:00
|
|
|
msi_update_table_columns(tv->db, tv->name);
|
2007-07-21 03:41:16 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
msiobj_release(&rec->hdr);
|
2009-01-25 13:08:58 +01:00
|
|
|
columns->ops->delete(columns);
|
2007-07-21 03:41:16 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2007-07-19 03:21:00 +02:00
|
|
|
static UINT TABLE_release(struct tagMSIVIEW *view)
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
INT ref = tv->table->ref_count;
|
2020-06-30 05:40:06 +02:00
|
|
|
UINT r;
|
|
|
|
INT i;
|
2007-07-19 03:21:00 +02:00
|
|
|
|
|
|
|
TRACE("%p %d\n", view, ref);
|
|
|
|
|
2020-06-30 05:40:25 +02:00
|
|
|
ref = InterlockedDecrement(&tv->table->ref_count);
|
|
|
|
if (ref == 0)
|
2007-07-21 03:41:16 +02:00
|
|
|
{
|
2020-06-30 05:40:25 +02:00
|
|
|
for (i = tv->table->col_count - 1; i >= 0; i--)
|
2007-07-21 03:41:16 +02:00
|
|
|
{
|
2020-06-30 05:40:25 +02:00
|
|
|
if (tv->table->colinfo[i].type & MSITYPE_TEMPORARY)
|
2007-07-21 03:41:16 +02:00
|
|
|
{
|
2020-07-01 10:43:05 +02:00
|
|
|
r = TABLE_remove_column(view, tv->table->colinfo[i].number);
|
2007-07-21 03:41:16 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
}
|
2020-06-30 05:40:25 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2007-07-21 03:41:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-30 05:40:25 +02:00
|
|
|
if (!tv->table->col_count)
|
2007-07-19 03:21:00 +02:00
|
|
|
{
|
|
|
|
list_remove(&tv->table->entry);
|
|
|
|
free_table(tv->table);
|
|
|
|
TABLE_delete(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2020-06-30 05:40:41 +02:00
|
|
|
static UINT TABLE_add_column(struct tagMSIVIEW *view, LPCWSTR column,
|
2020-06-30 05:40:46 +02:00
|
|
|
INT type, BOOL hold)
|
2007-07-20 23:01:13 +02:00
|
|
|
{
|
2020-06-30 05:40:41 +02:00
|
|
|
UINT i, r, table_id, col_id, size, offset;
|
2020-06-30 05:40:46 +02:00
|
|
|
BOOL temporary = type & MSITYPE_TEMPORARY;
|
2007-07-20 23:01:13 +02:00
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
2020-06-30 05:40:41 +02:00
|
|
|
MSICOLUMNINFO *colinfo;
|
2007-07-20 23:01:13 +02:00
|
|
|
|
2020-06-30 05:40:41 +02:00
|
|
|
if (temporary && !hold && !tv->table->ref_count)
|
|
|
|
return ERROR_SUCCESS;
|
2007-07-20 23:01:13 +02:00
|
|
|
|
2020-06-30 05:40:41 +02:00
|
|
|
if (!temporary && tv->table->col_count &&
|
2020-06-30 05:40:57 +02:00
|
|
|
tv->table->colinfo[tv->table->col_count-1].type & MSITYPE_TEMPORARY)
|
2020-06-30 05:40:41 +02:00
|
|
|
return ERROR_BAD_QUERY_SYNTAX;
|
|
|
|
|
|
|
|
for (i = 0; i < tv->table->col_count; i++)
|
|
|
|
{
|
|
|
|
if (!wcscmp(tv->table->colinfo[i].colname, column))
|
|
|
|
return ERROR_BAD_QUERY_SYNTAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
colinfo = msi_realloc(tv->table->colinfo, sizeof(*tv->table->colinfo) * (tv->table->col_count + 1));
|
|
|
|
if (!colinfo)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
tv->table->colinfo = colinfo;
|
2007-07-20 23:01:13 +02:00
|
|
|
|
2020-06-30 05:40:41 +02:00
|
|
|
r = msi_string2id( tv->db->strings, tv->name, -1, &table_id );
|
2007-07-20 23:01:13 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
2020-06-30 05:40:41 +02:00
|
|
|
return r;
|
|
|
|
col_id = msi_add_string( tv->db->strings, column, -1, !temporary );
|
2007-07-20 23:01:13 +02:00
|
|
|
|
2020-06-30 05:40:41 +02:00
|
|
|
colinfo[tv->table->col_count].tablename = msi_string_lookup( tv->db->strings, table_id, NULL );
|
|
|
|
colinfo[tv->table->col_count].number = tv->table->col_count + 1;
|
|
|
|
colinfo[tv->table->col_count].colname = msi_string_lookup( tv->db->strings, col_id, NULL );
|
|
|
|
colinfo[tv->table->col_count].type = type;
|
|
|
|
colinfo[tv->table->col_count].offset = 0;
|
|
|
|
colinfo[tv->table->col_count].hash_table = NULL;
|
|
|
|
tv->table->col_count++;
|
2007-07-20 23:01:13 +02:00
|
|
|
|
2020-06-30 05:40:41 +02:00
|
|
|
table_calc_column_offsets( tv->db, tv->table->colinfo, tv->table->col_count);
|
2007-07-21 03:41:16 +02:00
|
|
|
|
2020-06-30 05:40:41 +02:00
|
|
|
size = msi_table_get_row_size( tv->db, tv->table->colinfo, tv->table->col_count, LONG_STR_BYTES );
|
|
|
|
offset = tv->table->colinfo[tv->table->col_count - 1].offset;
|
|
|
|
for (i = 0; i < tv->table->row_count; i++)
|
|
|
|
{
|
|
|
|
BYTE *data = msi_realloc( tv->table->data[i], size );
|
|
|
|
if (!data)
|
|
|
|
{
|
|
|
|
tv->table->col_count--;
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2007-07-21 03:41:16 +02:00
|
|
|
|
2020-06-30 05:40:41 +02:00
|
|
|
tv->table->data[i] = data;
|
|
|
|
memset(data + offset, 0, size - offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!temporary)
|
|
|
|
{
|
|
|
|
MSIVIEW *columns;
|
|
|
|
MSIRECORD *rec;
|
|
|
|
|
|
|
|
rec = MSI_CreateRecord(4);
|
|
|
|
if (!rec)
|
|
|
|
{
|
|
|
|
tv->table->col_count--;
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
MSI_RecordSetStringW(rec, 1, tv->name);
|
|
|
|
MSI_RecordSetInteger(rec, 2, tv->table->col_count);
|
|
|
|
MSI_RecordSetStringW(rec, 3, column);
|
|
|
|
MSI_RecordSetInteger(rec, 4, type);
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = TABLE_CreateView(tv->db, L"_Columns", &columns);
|
2020-06-30 05:40:41 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
tv->table->col_count--;
|
|
|
|
msiobj_release(&rec->hdr);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = TABLE_insert_row(columns, rec, -1, FALSE);
|
|
|
|
columns->ops->delete(columns);
|
|
|
|
msiobj_release(&rec->hdr);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
tv->table->col_count--;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hold)
|
|
|
|
TABLE_add_ref(view);
|
|
|
|
return ERROR_SUCCESS;
|
2007-07-20 23:01:13 +02:00
|
|
|
}
|
|
|
|
|
2008-10-02 22:56:54 +02:00
|
|
|
static UINT TABLE_drop(struct tagMSIVIEW *view)
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
MSIVIEW *tables = NULL;
|
|
|
|
MSIRECORD *rec = NULL;
|
2008-10-07 08:49:49 +02:00
|
|
|
UINT r, row;
|
|
|
|
INT i;
|
2008-10-02 22:56:54 +02:00
|
|
|
|
|
|
|
TRACE("dropping table %s\n", debugstr_w(tv->name));
|
|
|
|
|
2008-10-07 08:49:49 +02:00
|
|
|
for (i = tv->table->col_count - 1; i >= 0; i--)
|
2008-10-02 22:56:54 +02:00
|
|
|
{
|
2020-07-01 10:43:05 +02:00
|
|
|
r = TABLE_remove_column(view, tv->table->colinfo[i].number);
|
2008-10-02 22:56:54 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
rec = MSI_CreateRecord(1);
|
|
|
|
if (!rec)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
MSI_RecordSetStringW(rec, 1, tv->name);
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = TABLE_CreateView(tv->db, L"_Tables", &tables);
|
2008-10-02 22:56:54 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
2014-03-27 03:56:14 +01:00
|
|
|
{
|
|
|
|
msiobj_release(&rec->hdr);
|
2008-10-02 22:56:54 +02:00
|
|
|
return r;
|
2014-03-27 03:56:14 +01:00
|
|
|
}
|
2008-10-02 22:56:54 +02:00
|
|
|
|
2011-06-07 10:34:49 +02:00
|
|
|
r = msi_table_find_row((MSITABLEVIEW *)tables, rec, &row, NULL);
|
2008-10-02 22:56:54 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
r = TABLE_delete_row(tables, row);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
list_remove(&tv->table->entry);
|
|
|
|
free_table(tv->table);
|
|
|
|
|
|
|
|
done:
|
|
|
|
msiobj_release(&rec->hdr);
|
|
|
|
tables->ops->delete(tables);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-06-10 12:02:39 +02:00
|
|
|
static const MSIVIEWOPS table_ops =
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
TABLE_fetch_int,
|
2004-07-06 20:56:12 +02:00
|
|
|
TABLE_fetch_stream,
|
2019-01-26 23:58:58 +01:00
|
|
|
TABLE_set_int,
|
|
|
|
TABLE_set_string,
|
2019-01-29 05:11:08 +01:00
|
|
|
TABLE_set_stream,
|
2006-10-26 10:09:47 +02:00
|
|
|
TABLE_set_row,
|
2004-03-19 02:16:36 +01:00
|
|
|
TABLE_insert_row,
|
2007-06-18 22:49:31 +02:00
|
|
|
TABLE_delete_row,
|
2003-08-13 03:27:48 +02:00
|
|
|
TABLE_execute,
|
|
|
|
TABLE_close,
|
|
|
|
TABLE_get_dimensions,
|
|
|
|
TABLE_get_column_info,
|
|
|
|
TABLE_modify,
|
2006-03-18 17:12:15 +01:00
|
|
|
TABLE_delete,
|
2007-07-19 03:21:00 +02:00
|
|
|
TABLE_add_ref,
|
|
|
|
TABLE_release,
|
2007-07-20 23:01:13 +02:00
|
|
|
TABLE_add_column,
|
2011-10-20 14:22:25 +02:00
|
|
|
NULL,
|
2008-10-02 22:56:54 +02:00
|
|
|
TABLE_drop,
|
2003-08-13 03:27:48 +02:00
|
|
|
};
|
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
UINT TABLE_CreateView( MSIDATABASE *db, LPCWSTR name, MSIVIEW **view )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv ;
|
2007-04-23 09:20:21 +02:00
|
|
|
UINT r, sz;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
TRACE("%p %s %p\n", db, debugstr_w(name), view );
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if ( !wcscmp( name, L"_Streams" ) )
|
2007-04-25 12:22:01 +02:00
|
|
|
return STREAMS_CreateView( db, view );
|
2020-10-29 11:47:14 +01:00
|
|
|
else if ( !wcscmp( name, L"_Storages" ) )
|
2008-07-08 06:59:07 +02:00
|
|
|
return STORAGES_CreateView( db, view );
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2012-11-09 16:47:44 +01:00
|
|
|
sz = FIELD_OFFSET( MSITABLEVIEW, name[lstrlenW( name ) + 1] );
|
2005-09-20 13:59:14 +02:00
|
|
|
tv = msi_alloc_zero( sz );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( !tv )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2007-04-23 09:20:21 +02:00
|
|
|
r = get_table( db, name, &tv->table );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( tv );
|
2007-04-23 09:20:21 +02:00
|
|
|
WARN("table not found\n");
|
|
|
|
return r;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2007-04-23 09:20:21 +02:00
|
|
|
TRACE("table %p found with %d columns\n", tv->table, tv->table->col_count);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
/* fill the structure */
|
|
|
|
tv->view.ops = &table_ops;
|
|
|
|
tv->db = db;
|
2007-04-23 09:20:21 +02:00
|
|
|
tv->columns = tv->table->colinfo;
|
|
|
|
tv->num_cols = tv->table->col_count;
|
2010-10-11 12:09:45 +02:00
|
|
|
tv->row_size = msi_table_get_row_size( db, tv->table->colinfo, tv->table->col_count, LONG_STR_BYTES );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
TRACE("%s one row is %d bytes\n", debugstr_w(name), tv->row_size );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
*view = (MSIVIEW*) tv;
|
|
|
|
lstrcpyW( tv->name, name );
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2020-06-25 20:08:48 +02:00
|
|
|
static WCHAR* create_key_string(MSITABLEVIEW *tv, MSIRECORD *rec)
|
|
|
|
{
|
|
|
|
DWORD i, p, len, key_len = 0;
|
|
|
|
WCHAR *key;
|
|
|
|
|
|
|
|
for (i = 0; i < tv->num_cols; i++)
|
|
|
|
{
|
|
|
|
if (!(tv->columns[i].type & MSITYPE_KEY))
|
|
|
|
continue;
|
|
|
|
if (MSI_RecordGetStringW( rec, i+1, NULL, &len ) == ERROR_SUCCESS)
|
|
|
|
key_len += len;
|
|
|
|
key_len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = msi_alloc( key_len * sizeof(WCHAR) );
|
|
|
|
if(!key)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
p = 0;
|
|
|
|
for (i = 0; i < tv->num_cols; i++)
|
|
|
|
{
|
|
|
|
if (!(tv->columns[i].type & MSITYPE_KEY))
|
|
|
|
continue;
|
|
|
|
if (p)
|
|
|
|
key[p++] = '\t';
|
|
|
|
len = key_len - p;
|
|
|
|
if (MSI_RecordGetStringW( rec, i+1, key + p, &len ) == ERROR_SUCCESS)
|
|
|
|
p += len;
|
|
|
|
}
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2022-02-04 09:49:54 +01:00
|
|
|
static UINT msi_record_stream_name( const MSITABLEVIEW *tv, MSIRECORD *rec, LPWSTR name, DWORD *len )
|
2020-06-25 20:08:39 +02:00
|
|
|
{
|
2022-02-04 09:49:54 +01:00
|
|
|
UINT p = 0, i, r;
|
|
|
|
DWORD l;
|
2020-06-25 20:08:39 +02:00
|
|
|
|
|
|
|
l = wcslen( tv->name );
|
|
|
|
if (name && *len > l)
|
|
|
|
memcpy(name, tv->name, l * sizeof(WCHAR));
|
|
|
|
p += l;
|
|
|
|
|
|
|
|
for ( i = 0; i < tv->num_cols; i++ )
|
|
|
|
{
|
|
|
|
if (!(tv->columns[i].type & MSITYPE_KEY))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (name && *len > p + 1)
|
|
|
|
name[p] = '.';
|
|
|
|
p++;
|
|
|
|
|
|
|
|
l = (*len > p ? *len - p : 0);
|
|
|
|
r = MSI_RecordGetStringW( rec, i + 1, name ? name + p : NULL, &l );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
p += l;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name && *len > p)
|
|
|
|
name[p] = 0;
|
|
|
|
|
|
|
|
*len = p;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-06-25 20:08:43 +02:00
|
|
|
static UINT TransformView_fetch_int( MSIVIEW *view, UINT row, UINT col, UINT *val )
|
|
|
|
{
|
2020-06-25 20:08:55 +02:00
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
2020-06-25 20:08:57 +02:00
|
|
|
if (!tv->table || col > tv->table->col_count)
|
2020-06-25 20:08:55 +02:00
|
|
|
{
|
|
|
|
*val = 0;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2020-06-25 20:08:48 +02:00
|
|
|
return TABLE_fetch_int( view, row, col, val );
|
2020-06-25 20:08:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TransformView_fetch_stream( MSIVIEW *view, UINT row, UINT col, IStream **stm )
|
|
|
|
{
|
2020-06-25 20:08:55 +02:00
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
2020-06-25 20:08:57 +02:00
|
|
|
if (!tv->table || col > tv->table->col_count)
|
2020-06-25 20:08:55 +02:00
|
|
|
{
|
|
|
|
*stm = NULL;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2020-06-25 20:08:48 +02:00
|
|
|
return TABLE_fetch_stream( view, row, col, stm );
|
2020-06-25 20:08:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TransformView_set_row( MSIVIEW *view, UINT row, MSIRECORD *rec, UINT mask )
|
|
|
|
{
|
2020-06-25 20:08:48 +02:00
|
|
|
static const WCHAR query_pfx[] =
|
2020-07-01 10:43:08 +02:00
|
|
|
L"INSERT INTO `_TransformView` (`new`, `Table`, `Column`, `Row`, `Data`, `Current`) VALUES (1, '";
|
2020-06-25 20:08:48 +02:00
|
|
|
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
2020-07-01 10:43:00 +02:00
|
|
|
WCHAR buf[256], *query;
|
2020-06-25 20:08:48 +02:00
|
|
|
MSIRECORD *old_rec;
|
|
|
|
MSIQUERY *q;
|
|
|
|
WCHAR *key;
|
2022-02-04 09:49:54 +01:00
|
|
|
UINT i, p, r, qlen;
|
|
|
|
DWORD len;
|
2020-06-25 20:08:48 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if (!wcscmp( tv->name, L"_Columns" ))
|
2020-06-25 20:08:48 +02:00
|
|
|
{
|
|
|
|
ERR( "trying to modify existing column\n" );
|
|
|
|
return ERROR_INSTALL_TRANSFORM_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if (!wcscmp( tv->name, L"_Tables" ))
|
2020-06-25 20:08:48 +02:00
|
|
|
{
|
|
|
|
ERR( "trying to modify existing table\n" );
|
|
|
|
return ERROR_INSTALL_TRANSFORM_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
key = create_key_string( tv, rec );
|
|
|
|
if (!key)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
r = msi_view_get_row( tv->db, view, row, &old_rec );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
old_rec = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < tv->num_cols; i++)
|
|
|
|
{
|
|
|
|
if (!(mask & (1 << i)))
|
|
|
|
continue;
|
|
|
|
if (tv->columns[i].type & MSITYPE_KEY)
|
|
|
|
continue;
|
|
|
|
|
2020-07-01 10:43:08 +02:00
|
|
|
qlen = p = ARRAY_SIZE( query_pfx ) - 1;
|
2020-06-25 20:08:48 +02:00
|
|
|
qlen += wcslen( tv->name ) + 3; /* strlen("','") */
|
|
|
|
qlen += wcslen( tv->columns[i].colname ) + 3;
|
|
|
|
qlen += wcslen( key ) + 3;
|
|
|
|
if (MSITYPE_IS_BINARY( tv->columns[i].type ))
|
|
|
|
r = msi_record_stream_name( tv, rec, NULL, &len );
|
|
|
|
else
|
|
|
|
r = MSI_RecordGetStringW( rec, i + 1, NULL, &len );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (old_rec)
|
|
|
|
msiobj_release( &old_rec->hdr );
|
|
|
|
msi_free( key );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
qlen += len + 3;
|
|
|
|
if (old_rec && (r = MSI_RecordGetStringW( old_rec, i+1, NULL, &len )))
|
|
|
|
{
|
|
|
|
msiobj_release( &old_rec->hdr );
|
|
|
|
msi_free( key );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
qlen += len + 3; /* strlen("')") + 1 */
|
|
|
|
|
|
|
|
if (qlen > ARRAY_SIZE(buf))
|
|
|
|
{
|
|
|
|
query = msi_alloc( qlen * sizeof(WCHAR) );
|
|
|
|
if (!query)
|
|
|
|
{
|
|
|
|
if (old_rec)
|
|
|
|
msiobj_release( &old_rec->hdr );
|
|
|
|
msi_free( key );
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
2020-07-01 10:43:00 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
query = buf;
|
|
|
|
}
|
2020-06-25 20:08:48 +02:00
|
|
|
|
|
|
|
memcpy( query, query_pfx, p * sizeof(WCHAR) );
|
|
|
|
len = wcslen( tv->name );
|
|
|
|
memcpy( query + p, tv->name, len * sizeof(WCHAR) );
|
|
|
|
p += len;
|
|
|
|
query[p++] = '\'';
|
|
|
|
query[p++] = ',';
|
|
|
|
query[p++] = '\'';
|
|
|
|
len = wcslen( tv->columns[i].colname );
|
|
|
|
memcpy( query + p, tv->columns[i].colname, len * sizeof(WCHAR) );
|
|
|
|
p += len;
|
|
|
|
query[p++] = '\'';
|
|
|
|
query[p++] = ',';
|
|
|
|
query[p++] = '\'';
|
|
|
|
len = wcslen( key );
|
|
|
|
memcpy( query + p, key, len * sizeof(WCHAR) );
|
|
|
|
p += len;
|
|
|
|
query[p++] = '\'';
|
|
|
|
query[p++] = ',';
|
|
|
|
query[p++] = '\'';
|
|
|
|
len = qlen - p;
|
|
|
|
if (MSITYPE_IS_BINARY( tv->columns[i].type ))
|
|
|
|
msi_record_stream_name( tv, rec, query + p, &len );
|
|
|
|
else
|
|
|
|
MSI_RecordGetStringW( rec, i + 1, query + p, &len );
|
|
|
|
p += len;
|
|
|
|
query[p++] = '\'';
|
|
|
|
query[p++] = ',';
|
|
|
|
query[p++] = '\'';
|
|
|
|
if (old_rec)
|
|
|
|
{
|
|
|
|
len = qlen - p;
|
|
|
|
MSI_RecordGetStringW( old_rec, i + 1, query + p, &len );
|
|
|
|
p += len;
|
|
|
|
}
|
|
|
|
query[p++] = '\'';
|
|
|
|
query[p++] = ')';
|
|
|
|
query[p++] = 0;
|
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW( tv->db, query, &q );
|
|
|
|
if (query != buf)
|
|
|
|
msi_free( query );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (old_rec)
|
|
|
|
msiobj_release( &old_rec->hdr );
|
|
|
|
msi_free( key );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( q, NULL );
|
|
|
|
msiobj_release( &q->hdr );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (old_rec)
|
|
|
|
msiobj_release( &old_rec->hdr );
|
|
|
|
msi_free( key );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_rec)
|
|
|
|
msiobj_release( &old_rec->hdr );
|
|
|
|
msi_free( key );
|
|
|
|
return ERROR_SUCCESS;
|
2020-06-25 20:08:43 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 20:08:55 +02:00
|
|
|
static UINT TransformView_create_table( MSITABLEVIEW *tv, MSIRECORD *rec )
|
|
|
|
{
|
|
|
|
static const WCHAR query_fmt[] =
|
2020-07-01 10:43:08 +02:00
|
|
|
L"INSERT INTO `_TransformView` (`Table`, `Column`, `new`) VALUES ('%s', 'CREATE', 1)";
|
2020-06-25 20:08:55 +02:00
|
|
|
|
|
|
|
WCHAR buf[256], *query = buf;
|
|
|
|
const WCHAR *name;
|
|
|
|
MSIQUERY *q;
|
|
|
|
int len;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
name = msi_record_get_string( rec, 1, &len );
|
|
|
|
if (!name)
|
|
|
|
return ERROR_INSTALL_TRANSFORM_FAILURE;
|
|
|
|
|
|
|
|
len = _snwprintf( NULL, 0, query_fmt, name ) + 1;
|
|
|
|
if (len > ARRAY_SIZE(buf))
|
|
|
|
{
|
|
|
|
query = msi_alloc( len * sizeof(WCHAR) );
|
|
|
|
if (!query)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
swprintf( query, len, query_fmt, name );
|
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW( tv->db, query, &q );
|
|
|
|
if (query != buf)
|
|
|
|
msi_free( query );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( q, NULL );
|
|
|
|
msiobj_release( &q->hdr );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-06-25 20:08:57 +02:00
|
|
|
static UINT TransformView_add_column( MSITABLEVIEW *tv, MSIRECORD *rec )
|
|
|
|
{
|
|
|
|
static const WCHAR query_pfx[] =
|
2020-07-01 10:43:08 +02:00
|
|
|
L"INSERT INTO `_TransformView` (`new`, `Table`, `Current`, `Column`, `Data`) VALUES (1, '";
|
2020-06-25 20:08:57 +02:00
|
|
|
|
|
|
|
WCHAR buf[256], *query = buf;
|
2022-02-04 09:49:54 +01:00
|
|
|
UINT i, p, r, qlen;
|
|
|
|
DWORD len;
|
2020-06-25 20:08:57 +02:00
|
|
|
MSIQUERY *q;
|
|
|
|
|
|
|
|
qlen = p = wcslen( query_pfx );
|
|
|
|
for (i = 1; i <= 4; i++)
|
|
|
|
{
|
|
|
|
r = MSI_RecordGetStringW( rec, i, NULL, &len );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
qlen += len + 3; /* strlen( "','" ) */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qlen > ARRAY_SIZE(buf))
|
|
|
|
{
|
|
|
|
query = msi_alloc( len * sizeof(WCHAR) );
|
|
|
|
qlen = len;
|
|
|
|
if (!query)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy( query, query_pfx, p * sizeof(WCHAR) );
|
|
|
|
for (i = 1; i <= 4; i++)
|
|
|
|
{
|
|
|
|
len = qlen - p;
|
|
|
|
MSI_RecordGetStringW( rec, i, query + p, &len );
|
|
|
|
p += len;
|
|
|
|
query[p++] = '\'';
|
|
|
|
if (i != 4)
|
|
|
|
{
|
|
|
|
query[p++] = ',';
|
|
|
|
query[p++] = '\'';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
query[p++] = ')';
|
|
|
|
query[p++] = 0;
|
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW( tv->db, query, &q );
|
|
|
|
if (query != buf)
|
|
|
|
msi_free( query );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( q, NULL );
|
|
|
|
msiobj_release( &q->hdr );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-06-25 20:08:43 +02:00
|
|
|
static UINT TransformView_insert_row( MSIVIEW *view, MSIRECORD *rec, UINT row, BOOL temporary )
|
|
|
|
{
|
2020-06-25 20:09:14 +02:00
|
|
|
static const WCHAR query_fmt[] =
|
2020-07-01 10:43:08 +02:00
|
|
|
L"INSERT INTO `_TransformView` (`new`, `Table`, `Column`, `Row`) VALUES (1, '%s', 'INSERT', '%s')";
|
2020-06-25 20:09:14 +02:00
|
|
|
|
2020-06-25 20:08:55 +02:00
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
2020-06-25 20:09:14 +02:00
|
|
|
WCHAR buf[256], *query = buf;
|
|
|
|
MSIQUERY *q;
|
|
|
|
WCHAR *key;
|
|
|
|
int len;
|
|
|
|
UINT r;
|
2020-06-25 20:08:55 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if (!wcscmp(tv->name, L"_Tables"))
|
2020-06-25 20:08:55 +02:00
|
|
|
return TransformView_create_table( tv, rec );
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if (!wcscmp(tv->name, L"_Columns"))
|
2020-06-25 20:08:57 +02:00
|
|
|
return TransformView_add_column( tv, rec );
|
|
|
|
|
2020-06-25 20:09:14 +02:00
|
|
|
key = create_key_string( tv, rec );
|
|
|
|
if (!key)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
len = _snwprintf( NULL, 0, query_fmt, tv->name, key ) + 1;
|
|
|
|
if (len > ARRAY_SIZE(buf))
|
|
|
|
{
|
|
|
|
query = msi_alloc( len * sizeof(WCHAR) );
|
|
|
|
if (!query)
|
|
|
|
{
|
|
|
|
msi_free( key );
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
swprintf( query, len, query_fmt, tv->name, key );
|
|
|
|
msi_free( key );
|
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW( tv->db, query, &q );
|
|
|
|
if (query != buf)
|
|
|
|
msi_free( query );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( q, NULL );
|
|
|
|
msiobj_release( &q->hdr );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return TransformView_set_row( view, row, rec, ~0 );
|
2020-06-25 20:08:43 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 20:09:22 +02:00
|
|
|
static UINT TransformView_drop_table( MSITABLEVIEW *tv, UINT row )
|
|
|
|
{
|
2020-07-01 10:43:08 +02:00
|
|
|
static const WCHAR query_pfx[] = L"INSERT INTO `_TransformView` ( `new`, `Table`, `Column` ) VALUES ( 1, '";
|
2020-06-25 20:09:22 +02:00
|
|
|
static const WCHAR query_sfx[] = L"', 'DROP' )";
|
|
|
|
|
|
|
|
WCHAR buf[256], *query = buf;
|
|
|
|
UINT r, table_id, len;
|
|
|
|
const WCHAR *table;
|
|
|
|
int table_len;
|
|
|
|
MSIQUERY *q;
|
|
|
|
|
|
|
|
r = TABLE_fetch_int( &tv->view, row, 1, &table_id );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
table = msi_string_lookup( tv->db->strings, table_id, &table_len );
|
|
|
|
if (!table)
|
|
|
|
return ERROR_INSTALL_TRANSFORM_FAILURE;
|
|
|
|
|
|
|
|
len = ARRAY_SIZE(query_pfx) - 1 + table_len + ARRAY_SIZE(query_sfx);
|
|
|
|
if (len > ARRAY_SIZE(buf))
|
|
|
|
{
|
|
|
|
query = msi_alloc( len * sizeof(WCHAR) );
|
|
|
|
if (!query)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy( query, query_pfx, ARRAY_SIZE(query_pfx) * sizeof(WCHAR) );
|
|
|
|
len = ARRAY_SIZE(query_pfx) - 1;
|
|
|
|
memcpy( query + len, table, table_len * sizeof(WCHAR) );
|
|
|
|
len += table_len;
|
|
|
|
memcpy( query + len, query_sfx, ARRAY_SIZE(query_sfx) * sizeof(WCHAR) );
|
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW( tv->db, query, &q );
|
|
|
|
if (query != buf)
|
|
|
|
msi_free( query );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( q, NULL );
|
|
|
|
msiobj_release( &q->hdr );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-06-25 20:08:43 +02:00
|
|
|
static UINT TransformView_delete_row( MSIVIEW *view, UINT row )
|
|
|
|
{
|
2020-07-01 10:43:08 +02:00
|
|
|
static const WCHAR query_pfx[] = L"INSERT INTO `_TransformView` ( `new`, `Table`, `Column`, `Row`) VALUES ( 1, '";
|
2020-06-25 20:09:36 +02:00
|
|
|
static const WCHAR query_column[] = L"', 'DELETE', '";
|
|
|
|
static const WCHAR query_sfx[] = L"')";
|
|
|
|
|
2020-06-25 20:09:22 +02:00
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
2020-06-25 20:09:36 +02:00
|
|
|
WCHAR *key, buf[256], *query = buf;
|
|
|
|
UINT r, len, name_len, key_len;
|
|
|
|
MSIRECORD *rec;
|
|
|
|
MSIQUERY *q;
|
2020-06-25 20:09:22 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if (!wcscmp( tv->name, L"_Columns" ))
|
2020-06-25 20:09:22 +02:00
|
|
|
{
|
|
|
|
ERR("trying to remove column\n");
|
|
|
|
return ERROR_INSTALL_TRANSFORM_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if (!wcscmp( tv->name, L"_Tables" ))
|
2020-06-25 20:09:22 +02:00
|
|
|
return TransformView_drop_table( tv, row );
|
|
|
|
|
2020-06-25 20:09:36 +02:00
|
|
|
r = msi_view_get_row( tv->db, view, row, &rec );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
key = create_key_string( tv, rec );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
if (!key)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
name_len = wcslen( tv->name );
|
|
|
|
key_len = wcslen( key );
|
|
|
|
len = ARRAY_SIZE(query_pfx) + name_len + ARRAY_SIZE(query_column) + key_len + ARRAY_SIZE(query_sfx) - 2;
|
|
|
|
if (len > ARRAY_SIZE(buf))
|
|
|
|
{
|
|
|
|
query = msi_alloc( len * sizeof(WCHAR) );
|
|
|
|
if (!query)
|
|
|
|
{
|
|
|
|
msi_free( tv );
|
|
|
|
msi_free( key );
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy( query, query_pfx, ARRAY_SIZE(query_pfx) * sizeof(WCHAR) );
|
|
|
|
len = ARRAY_SIZE(query_pfx) - 1;
|
|
|
|
memcpy( query + len, tv->name, name_len * sizeof(WCHAR) );
|
|
|
|
len += name_len;
|
|
|
|
memcpy( query + len, query_column, ARRAY_SIZE(query_column) * sizeof(WCHAR) );
|
|
|
|
len += ARRAY_SIZE(query_column) - 1;
|
|
|
|
memcpy( query + len, key, key_len * sizeof(WCHAR) );
|
|
|
|
len += key_len;
|
|
|
|
memcpy( query + len, query_sfx, ARRAY_SIZE(query_sfx) * sizeof(WCHAR) );
|
|
|
|
msi_free( key );
|
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW( tv->db, query, &q );
|
|
|
|
if (query != buf)
|
|
|
|
msi_free( query );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( q, NULL );
|
|
|
|
msiobj_release( &q->hdr );
|
|
|
|
return r;
|
2020-06-25 20:08:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TransformView_execute( MSIVIEW *view, MSIRECORD *record )
|
|
|
|
{
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TransformView_close( MSIVIEW *view )
|
|
|
|
{
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TransformView_get_dimensions( MSIVIEW *view, UINT *rows, UINT *cols )
|
|
|
|
{
|
2020-06-25 20:08:48 +02:00
|
|
|
return TABLE_get_dimensions( view, rows, cols );
|
2020-06-25 20:08:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TransformView_get_column_info( MSIVIEW *view, UINT n, LPCWSTR *name, UINT *type,
|
|
|
|
BOOL *temporary, LPCWSTR *table_name )
|
|
|
|
{
|
2020-06-25 20:08:48 +02:00
|
|
|
return TABLE_get_column_info( view, n, name, type, temporary, table_name );
|
2020-06-25 20:08:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TransformView_delete( MSIVIEW *view )
|
|
|
|
{
|
2020-06-25 20:08:57 +02:00
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
if (!tv->table || tv->columns != tv->table->colinfo)
|
|
|
|
msi_free( tv->columns );
|
2020-06-25 20:08:43 +02:00
|
|
|
return TABLE_delete( view );
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MSIVIEWOPS transform_view_ops =
|
|
|
|
{
|
|
|
|
TransformView_fetch_int,
|
|
|
|
TransformView_fetch_stream,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
TransformView_set_row,
|
|
|
|
TransformView_insert_row,
|
|
|
|
TransformView_delete_row,
|
|
|
|
TransformView_execute,
|
|
|
|
TransformView_close,
|
|
|
|
TransformView_get_dimensions,
|
|
|
|
TransformView_get_column_info,
|
|
|
|
NULL,
|
|
|
|
TransformView_delete,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
UINT TransformView_Create( MSIDATABASE *db, string_table *st, LPCWSTR name, MSIVIEW **view )
|
|
|
|
{
|
2020-06-25 20:08:57 +02:00
|
|
|
static const WCHAR query_pfx[] = L"SELECT `Column`, `Data`, `Current` FROM `_TransformView` WHERE `Table`='";
|
2020-07-01 10:43:08 +02:00
|
|
|
static const WCHAR query_sfx[] = L"' AND `Row` IS NULL AND `Current` IS NOT NULL AND `new` = 1";
|
2020-06-25 20:08:57 +02:00
|
|
|
|
|
|
|
WCHAR buf[256], *query = buf;
|
|
|
|
UINT r, len, name_len, size, add_col;
|
|
|
|
MSICOLUMNINFO *colinfo;
|
2020-06-25 20:08:43 +02:00
|
|
|
MSITABLEVIEW *tv;
|
2020-06-25 20:08:57 +02:00
|
|
|
MSIRECORD *rec;
|
|
|
|
MSIQUERY *q;
|
2020-06-25 20:08:55 +02:00
|
|
|
|
|
|
|
name_len = wcslen( name );
|
2020-06-25 20:08:43 +02:00
|
|
|
|
|
|
|
r = TABLE_CreateView( db, name, view );
|
|
|
|
if (r == ERROR_INVALID_PARAMETER)
|
|
|
|
{
|
|
|
|
/* table does not exist */
|
2020-06-25 20:08:55 +02:00
|
|
|
size = FIELD_OFFSET( MSITABLEVIEW, name[name_len + 1] );
|
|
|
|
tv = msi_alloc_zero( size );
|
|
|
|
if (!tv)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
tv->db = db;
|
|
|
|
memcpy( tv->name, name, name_len * sizeof(WCHAR) );
|
|
|
|
*view = (MSIVIEW*)tv;
|
2020-06-25 20:08:43 +02:00
|
|
|
}
|
|
|
|
else if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tv = (MSITABLEVIEW*)*view;
|
|
|
|
}
|
|
|
|
|
|
|
|
tv->view.ops = &transform_view_ops;
|
2020-06-25 20:08:57 +02:00
|
|
|
|
|
|
|
len = ARRAY_SIZE(query_pfx) + name_len + ARRAY_SIZE(query_sfx) - 1;
|
|
|
|
if (len > ARRAY_SIZE(buf))
|
|
|
|
{
|
|
|
|
query = msi_alloc( len * sizeof(WCHAR) );
|
|
|
|
if (!query)
|
|
|
|
{
|
|
|
|
msi_free( tv );
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memcpy( query, query_pfx, ARRAY_SIZE(query_pfx) * sizeof(WCHAR) );
|
|
|
|
len = ARRAY_SIZE(query_pfx) - 1;
|
|
|
|
memcpy( query + len, name, name_len * sizeof(WCHAR) );
|
|
|
|
len += name_len;
|
|
|
|
memcpy( query + len, query_sfx, ARRAY_SIZE(query_sfx) * sizeof(WCHAR) );
|
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW( tv->db, query, &q );
|
|
|
|
if (query != buf)
|
|
|
|
msi_free( query );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
msi_free( tv );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( q, NULL );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
msi_free( tv );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = q->view->ops->get_dimensions( q->view, &add_col, NULL );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
MSI_ViewClose( q );
|
|
|
|
msiobj_release( &q->hdr );
|
|
|
|
msi_free( tv );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
if (!add_col)
|
|
|
|
{
|
|
|
|
MSI_ViewClose( q );
|
|
|
|
msiobj_release( &q->hdr );
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
colinfo = msi_alloc_zero( (add_col + tv->num_cols) * sizeof(*colinfo) );
|
|
|
|
if (!colinfo)
|
|
|
|
{
|
|
|
|
MSI_ViewClose( q );
|
|
|
|
msiobj_release( &q->hdr );
|
|
|
|
msi_free( tv );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (MSI_ViewFetch( q, &rec ) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
int name_len;
|
|
|
|
const WCHAR *name = msi_record_get_string( rec, 1, &name_len );
|
|
|
|
const WCHAR *type = msi_record_get_string( rec, 2, NULL );
|
|
|
|
UINT name_id, idx;
|
|
|
|
|
|
|
|
idx = _wtoi( msi_record_get_string(rec, 3, NULL) );
|
|
|
|
colinfo[idx - 1].number = idx;
|
|
|
|
colinfo[idx - 1].type = _wtoi( type );
|
|
|
|
|
|
|
|
r = msi_string2id( st, name, name_len, &name_id );
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
colinfo[idx - 1].colname = msi_string_lookup( st, name_id, NULL );
|
|
|
|
else
|
|
|
|
ERR( "column name %s is not defined in strings table\n", wine_dbgstr_w(name) );
|
2020-08-02 19:20:25 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
2020-06-25 20:08:57 +02:00
|
|
|
}
|
|
|
|
MSI_ViewClose( q );
|
|
|
|
msiobj_release( &q->hdr );
|
|
|
|
|
|
|
|
memcpy( colinfo, tv->columns, tv->num_cols * sizeof(*colinfo) );
|
|
|
|
tv->columns = colinfo;
|
|
|
|
tv->num_cols += add_col;
|
2020-06-25 20:08:43 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
UINT MSI_CommitTables( MSIDATABASE *db )
|
|
|
|
{
|
2010-10-11 12:09:45 +02:00
|
|
|
UINT r, bytes_per_strref;
|
2010-08-27 10:50:20 +02:00
|
|
|
HRESULT hr;
|
2004-03-18 05:04:08 +01:00
|
|
|
MSITABLE *table = NULL;
|
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
TRACE("%p\n",db);
|
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
r = msi_save_string_table( db->strings, db->storage, &bytes_per_strref );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("failed to save string table r=%08x\n",r);
|
2004-03-19 02:16:36 +01:00
|
|
|
return r;
|
|
|
|
}
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2005-09-14 12:07:26 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( table, &db->tables, MSITABLE, entry )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2010-10-11 12:09:45 +02:00
|
|
|
r = save_table( db, table, bytes_per_strref );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( r != ERROR_SUCCESS )
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("failed to save table %s (r=%08x)\n",
|
2004-03-19 02:16:36 +01:00
|
|
|
debugstr_w(table->name), r);
|
2004-03-18 05:04:08 +01:00
|
|
|
return r;
|
2004-03-19 02:16:36 +01:00
|
|
|
}
|
2004-03-18 05:04:08 +01:00
|
|
|
}
|
|
|
|
|
2010-08-27 10:50:20 +02:00
|
|
|
hr = IStorage_Commit( db->storage, 0 );
|
|
|
|
if (FAILED( hr ))
|
|
|
|
{
|
2022-02-07 17:47:05 +01:00
|
|
|
WARN( "failed to commit changes %#lx\n", hr );
|
2010-08-27 10:50:20 +02:00
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
return r;
|
2004-03-18 05:04:08 +01:00
|
|
|
}
|
2005-10-26 15:56:33 +02:00
|
|
|
|
2006-09-13 11:46:13 +02:00
|
|
|
MSICONDITION MSI_DatabaseIsTablePersistent( MSIDATABASE *db, LPCWSTR table )
|
|
|
|
{
|
2007-04-24 12:00:44 +02:00
|
|
|
MSITABLE *t;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("%p %s\n", db, debugstr_w(table));
|
|
|
|
|
2006-09-13 11:46:13 +02:00
|
|
|
if (!table)
|
|
|
|
return MSICONDITION_ERROR;
|
|
|
|
|
2007-04-24 12:00:44 +02:00
|
|
|
r = get_table( db, table, &t );
|
|
|
|
if (r != ERROR_SUCCESS)
|
2007-04-21 09:33:10 +02:00
|
|
|
return MSICONDITION_NONE;
|
|
|
|
|
2009-02-26 04:45:15 +01:00
|
|
|
return t->persistent;
|
2006-09-13 11:46:13 +02:00
|
|
|
}
|
|
|
|
|
2007-06-26 23:25:28 +02:00
|
|
|
static UINT read_raw_int(const BYTE *data, UINT col, UINT bytes)
|
|
|
|
{
|
|
|
|
UINT ret = 0, i;
|
|
|
|
|
|
|
|
for (i = 0; i < bytes; i++)
|
|
|
|
ret += (data[col + i] << i * 8);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-05-24 18:51:58 +02:00
|
|
|
static UINT msi_record_encoded_stream_name( const MSITABLEVIEW *tv, MSIRECORD *rec, LPWSTR *pstname )
|
|
|
|
{
|
2022-02-04 09:49:54 +01:00
|
|
|
UINT r;
|
|
|
|
DWORD len;
|
2020-06-25 20:08:39 +02:00
|
|
|
WCHAR *name;
|
2009-05-24 18:51:58 +02:00
|
|
|
|
|
|
|
TRACE("%p %p\n", tv, rec);
|
|
|
|
|
2020-06-25 20:08:39 +02:00
|
|
|
r = msi_record_stream_name( tv, rec, NULL, &len );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
len++;
|
2009-05-24 18:51:58 +02:00
|
|
|
|
2020-06-25 20:08:39 +02:00
|
|
|
name = msi_alloc( len * sizeof(WCHAR) );
|
|
|
|
if (!name)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2009-05-24 18:51:58 +02:00
|
|
|
|
2020-06-25 20:08:39 +02:00
|
|
|
r = msi_record_stream_name( tv, rec, name, &len );
|
|
|
|
if (r != ERROR_SUCCESS)
|
2009-05-24 18:51:58 +02:00
|
|
|
{
|
2020-06-25 20:08:39 +02:00
|
|
|
msi_free( name );
|
|
|
|
return r;
|
2009-05-24 18:51:58 +02:00
|
|
|
}
|
|
|
|
|
2020-06-25 20:08:39 +02:00
|
|
|
*pstname = encode_streamname( FALSE, name );
|
|
|
|
msi_free( name );
|
2009-05-24 18:51:58 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-06-13 23:36:31 +02:00
|
|
|
static MSIRECORD *msi_get_transform_record( const MSITABLEVIEW *tv, const string_table *st,
|
2015-07-15 15:13:35 +02:00
|
|
|
IStorage *stg, const BYTE *rawdata, UINT bytes_per_strref )
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
|
|
|
UINT i, val, ofs = 0;
|
2007-06-26 23:25:28 +02:00
|
|
|
USHORT mask;
|
2005-10-27 14:25:04 +02:00
|
|
|
MSICOLUMNINFO *columns = tv->columns;
|
|
|
|
MSIRECORD *rec;
|
|
|
|
|
2007-06-26 23:25:28 +02:00
|
|
|
mask = rawdata[0] | (rawdata[1] << 8);
|
|
|
|
rawdata += 2;
|
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
rec = MSI_CreateRecord( tv->num_cols );
|
|
|
|
if( !rec )
|
|
|
|
return rec;
|
|
|
|
|
2006-10-15 17:19:54 +02:00
|
|
|
TRACE("row ->\n");
|
2005-10-27 14:25:04 +02:00
|
|
|
for( i=0; i<tv->num_cols; i++ )
|
|
|
|
{
|
|
|
|
if ( (mask&1) && (i>=(mask>>8)) )
|
|
|
|
break;
|
|
|
|
/* all keys must be present */
|
|
|
|
if ( (~mask&1) && (~columns[i].type & MSITYPE_KEY) && ((1<<i) & ~mask) )
|
|
|
|
continue;
|
|
|
|
|
2009-05-24 18:51:58 +02:00
|
|
|
if( MSITYPE_IS_BINARY(tv->columns[i].type) )
|
|
|
|
{
|
|
|
|
LPWSTR encname;
|
|
|
|
IStream *stm = NULL;
|
|
|
|
UINT r;
|
|
|
|
|
2010-10-11 12:09:45 +02:00
|
|
|
ofs += bytes_per_column( tv->db, &columns[i], bytes_per_strref );
|
2009-05-24 18:51:58 +02:00
|
|
|
|
|
|
|
r = msi_record_encoded_stream_name( tv, rec, &encname );
|
|
|
|
if ( r != ERROR_SUCCESS )
|
2015-07-15 15:13:35 +02:00
|
|
|
{
|
|
|
|
msiobj_release( &rec->hdr );
|
2009-05-24 18:51:58 +02:00
|
|
|
return NULL;
|
2015-07-15 15:13:35 +02:00
|
|
|
}
|
|
|
|
r = IStorage_OpenStream( stg, encname, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm );
|
2009-05-24 18:51:58 +02:00
|
|
|
if ( r != ERROR_SUCCESS )
|
2012-09-06 15:19:48 +02:00
|
|
|
{
|
2015-07-15 15:13:35 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
2012-09-06 15:19:48 +02:00
|
|
|
msi_free( encname );
|
2009-05-24 18:51:58 +02:00
|
|
|
return NULL;
|
2012-09-06 15:19:48 +02:00
|
|
|
}
|
2009-05-24 18:51:58 +02:00
|
|
|
|
|
|
|
MSI_RecordSetStream( rec, i+1, stm );
|
|
|
|
TRACE(" field %d [%s]\n", i+1, debugstr_w(encname));
|
2012-09-06 15:19:48 +02:00
|
|
|
msi_free( encname );
|
2009-05-24 18:51:58 +02:00
|
|
|
}
|
|
|
|
else if( columns[i].type & MSITYPE_STRING )
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
2012-10-29 12:14:19 +01:00
|
|
|
int len;
|
|
|
|
const WCHAR *sval;
|
2007-06-26 23:25:28 +02:00
|
|
|
|
|
|
|
val = read_raw_int(rawdata, ofs, bytes_per_strref);
|
2012-10-29 12:14:19 +01:00
|
|
|
sval = msi_string_lookup( st, val, &len );
|
|
|
|
msi_record_set_string( rec, i+1, sval, len );
|
|
|
|
TRACE(" field %d [%s]\n", i+1, debugstr_wn(sval, len));
|
2007-06-26 23:25:28 +02:00
|
|
|
ofs += bytes_per_strref;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-11 12:09:45 +02:00
|
|
|
UINT n = bytes_per_column( tv->db, &columns[i], bytes_per_strref );
|
2007-06-26 23:25:28 +02:00
|
|
|
switch( n )
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
2007-06-26 23:25:28 +02:00
|
|
|
case 2:
|
|
|
|
val = read_raw_int(rawdata, ofs, n);
|
2006-10-06 10:35:13 +02:00
|
|
|
if (val)
|
2009-11-19 09:30:04 +01:00
|
|
|
MSI_RecordSetInteger( rec, i+1, val-0x8000 );
|
2006-10-06 10:37:06 +02:00
|
|
|
TRACE(" field %d [0x%04x]\n", i+1, val );
|
2007-06-26 23:25:28 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
val = read_raw_int(rawdata, ofs, n);
|
|
|
|
if (val)
|
|
|
|
MSI_RecordSetInteger( rec, i+1, val^0x80000000 );
|
|
|
|
TRACE(" field %d [0x%08x]\n", i+1, val );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("oops - unknown column width %d\n", n);
|
|
|
|
break;
|
2005-10-27 14:25:04 +02:00
|
|
|
}
|
2007-06-26 23:25:28 +02:00
|
|
|
ofs += n;
|
2005-10-27 14:25:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
2007-06-13 23:36:31 +02:00
|
|
|
static void dump_table( const string_table *st, const USHORT *rawdata, UINT rawsize )
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
|
|
|
UINT i;
|
2012-10-29 12:12:50 +01:00
|
|
|
for (i = 0; i < rawsize / 2; i++)
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
2012-10-29 12:12:50 +01:00
|
|
|
int len;
|
|
|
|
const WCHAR *sval = msi_string_lookup( st, rawdata[i], &len );
|
|
|
|
MESSAGE(" %04x %s\n", rawdata[i], debugstr_wn(sval, len) );
|
2005-10-27 14:25:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-13 23:36:31 +02:00
|
|
|
static UINT* msi_record_to_row( const MSITABLEVIEW *tv, MSIRECORD *rec )
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
|
|
|
UINT i, r, *data;
|
|
|
|
|
|
|
|
data = msi_alloc( tv->num_cols *sizeof (UINT) );
|
|
|
|
for( i=0; i<tv->num_cols; i++ )
|
|
|
|
{
|
|
|
|
data[i] = 0;
|
|
|
|
|
|
|
|
if ( ~tv->columns[i].type & MSITYPE_KEY )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* turn the transform column value into a row value */
|
|
|
|
if ( ( tv->columns[i].type & MSITYPE_STRING ) &&
|
|
|
|
! MSITYPE_IS_BINARY(tv->columns[i].type) )
|
|
|
|
{
|
2012-10-29 12:14:44 +01:00
|
|
|
int len;
|
|
|
|
const WCHAR *str = msi_record_get_string( rec, i+1, &len );
|
2010-10-19 11:27:44 +02:00
|
|
|
if (str)
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
2012-10-29 12:14:44 +01:00
|
|
|
r = msi_string2id( tv->db->strings, str, len, &data[i] );
|
2010-10-19 11:27:44 +02:00
|
|
|
|
|
|
|
/* if there's no matching string in the string table,
|
|
|
|
these keys can't match any record, so fail now. */
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
msi_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-10-27 14:25:04 +02:00
|
|
|
}
|
2010-10-19 11:27:44 +02:00
|
|
|
else data[i] = 0;
|
2005-10-27 14:25:04 +02:00
|
|
|
}
|
|
|
|
else
|
2006-10-12 14:28:26 +02:00
|
|
|
{
|
2019-01-26 23:58:57 +01:00
|
|
|
if (int_to_table_storage( tv, i + 1, MSI_RecordGetInteger( rec, i + 1 ), &data[i] ))
|
|
|
|
{
|
|
|
|
msi_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-10-12 14:28:26 +02:00
|
|
|
}
|
2005-10-27 14:25:04 +02:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2011-06-07 10:34:49 +02:00
|
|
|
static UINT msi_row_matches( MSITABLEVIEW *tv, UINT row, const UINT *data, UINT *column )
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
|
|
|
UINT i, r, x, ret = ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
for( i=0; i<tv->num_cols; i++ )
|
|
|
|
{
|
|
|
|
if ( ~tv->columns[i].type & MSITYPE_KEY )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* turn the transform column value into a row value */
|
|
|
|
r = TABLE_fetch_int( &tv->view, row, i+1, &x );
|
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
ERR("TABLE_fetch_int shouldn't fail here\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if this key matches, move to the next column */
|
|
|
|
if ( x != data[i] )
|
|
|
|
{
|
|
|
|
ret = ERROR_FUNCTION_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
2011-06-07 10:34:49 +02:00
|
|
|
if (column) *column = i;
|
2005-10-27 14:25:04 +02:00
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-06-07 10:34:49 +02:00
|
|
|
static UINT msi_table_find_row( MSITABLEVIEW *tv, MSIRECORD *rec, UINT *row, UINT *column )
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
|
|
|
UINT i, r = ERROR_FUNCTION_FAILED, *data;
|
|
|
|
|
|
|
|
data = msi_record_to_row( tv, rec );
|
|
|
|
if( !data )
|
|
|
|
return r;
|
2009-06-07 07:11:40 +02:00
|
|
|
for( i = 0; i < tv->table->row_count; i++ )
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
2011-06-07 10:34:49 +02:00
|
|
|
r = msi_row_matches( tv, i, data, column );
|
2005-10-27 14:25:04 +02:00
|
|
|
if( r == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
*row = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msi_free( data );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2007-07-10 04:34:41 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
LPWSTR name;
|
|
|
|
} TRANSFORMDATA;
|
|
|
|
|
2005-10-26 15:56:33 +02:00
|
|
|
static UINT msi_table_load_transform( MSIDATABASE *db, IStorage *stg,
|
2007-07-10 04:34:41 +02:00
|
|
|
string_table *st, TRANSFORMDATA *transform,
|
2020-06-25 20:08:43 +02:00
|
|
|
UINT bytes_per_strref, int err_cond )
|
2005-10-26 15:56:33 +02:00
|
|
|
{
|
2007-06-26 23:25:28 +02:00
|
|
|
BYTE *rawdata = NULL;
|
2005-10-27 14:25:04 +02:00
|
|
|
MSITABLEVIEW *tv = NULL;
|
2012-01-24 10:03:59 +01:00
|
|
|
UINT r, n, sz, i, mask, num_cols, colcol = 0, rawsize = 0;
|
2005-10-27 14:25:04 +02:00
|
|
|
MSIRECORD *rec = NULL;
|
2006-10-19 18:53:32 +02:00
|
|
|
WCHAR coltable[32];
|
2012-01-24 10:03:59 +01:00
|
|
|
const WCHAR *name;
|
2007-07-10 20:26:44 +02:00
|
|
|
|
|
|
|
if (!transform)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
name = transform->name;
|
2005-10-27 14:25:04 +02:00
|
|
|
|
2006-10-19 18:53:32 +02:00
|
|
|
coltable[0] = 0;
|
2005-10-27 14:25:04 +02:00
|
|
|
TRACE("%p %p %p %s\n", db, stg, st, debugstr_w(name) );
|
|
|
|
|
2006-10-10 12:19:37 +02:00
|
|
|
/* read the transform data */
|
2007-07-16 23:45:29 +02:00
|
|
|
read_stream_data( stg, name, TRUE, &rawdata, &rawsize );
|
2006-10-06 10:35:44 +02:00
|
|
|
if ( !rawdata )
|
|
|
|
{
|
|
|
|
TRACE("table %s empty\n", debugstr_w(name) );
|
|
|
|
return ERROR_INVALID_TABLE;
|
|
|
|
}
|
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
/* create a table view */
|
2020-06-25 20:08:43 +02:00
|
|
|
if ( err_cond & MSITRANSFORM_ERROR_VIEWTRANSFORM )
|
|
|
|
r = TransformView_Create( db, st, name, (MSIVIEW**) &tv );
|
|
|
|
else
|
|
|
|
r = TABLE_CreateView( db, name, (MSIVIEW**) &tv );
|
2005-10-27 14:25:04 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
r = tv->view.ops->execute( &tv->view, NULL );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
TRACE("name = %s columns = %u row_size = %u raw size = %u\n",
|
|
|
|
debugstr_w(name), tv->num_cols, tv->row_size, rawsize );
|
|
|
|
|
|
|
|
/* interpret the data */
|
2012-01-24 10:03:59 +01:00
|
|
|
for (n = 0; n < rawsize;)
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
2012-01-24 10:03:59 +01:00
|
|
|
mask = rawdata[n] | (rawdata[n + 1] << 8);
|
|
|
|
if (mask & 1)
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* if the low bit is set, columns are continuous and
|
|
|
|
* the number of columns is specified in the high byte
|
|
|
|
*/
|
2007-06-26 23:25:28 +02:00
|
|
|
sz = 2;
|
2012-01-24 10:03:59 +01:00
|
|
|
num_cols = mask >> 8;
|
2015-02-13 13:37:22 +01:00
|
|
|
if (num_cols > tv->num_cols)
|
|
|
|
{
|
|
|
|
ERR("excess columns in transform: %u > %u\n", num_cols, tv->num_cols);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-01-24 10:03:59 +01:00
|
|
|
for (i = 0; i < num_cols; i++)
|
2007-06-26 23:25:28 +02:00
|
|
|
{
|
|
|
|
if( (tv->columns[i].type & MSITYPE_STRING) &&
|
|
|
|
! MSITYPE_IS_BINARY(tv->columns[i].type) )
|
|
|
|
sz += bytes_per_strref;
|
|
|
|
else
|
2010-10-11 12:09:45 +02:00
|
|
|
sz += bytes_per_column( tv->db, &tv->columns[i], bytes_per_strref );
|
2007-06-26 23:25:28 +02:00
|
|
|
}
|
2005-10-27 14:25:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
2007-06-26 23:25:28 +02:00
|
|
|
* If the low bit is not set, mask is a bitmask.
|
2005-10-27 14:25:04 +02:00
|
|
|
* Excepting for key fields, which are always present,
|
|
|
|
* each bit indicates that a field is present in the transform record.
|
|
|
|
*
|
2007-06-26 23:25:28 +02:00
|
|
|
* mask == 0 is a special case ... only the keys will be present
|
2005-10-27 14:25:04 +02:00
|
|
|
* and it means that this row should be deleted.
|
|
|
|
*/
|
|
|
|
sz = 2;
|
2012-01-24 10:03:59 +01:00
|
|
|
num_cols = tv->num_cols;
|
|
|
|
for (i = 0; i < num_cols; i++)
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
2012-01-24 10:03:59 +01:00
|
|
|
if ((tv->columns[i].type & MSITYPE_KEY) || ((1 << i) & mask))
|
2007-06-26 23:25:28 +02:00
|
|
|
{
|
2012-01-24 10:03:59 +01:00
|
|
|
if ((tv->columns[i].type & MSITYPE_STRING) &&
|
|
|
|
!MSITYPE_IS_BINARY(tv->columns[i].type))
|
2007-06-26 23:25:28 +02:00
|
|
|
sz += bytes_per_strref;
|
|
|
|
else
|
2010-10-11 12:09:45 +02:00
|
|
|
sz += bytes_per_column( tv->db, &tv->columns[i], bytes_per_strref );
|
2007-06-26 23:25:28 +02:00
|
|
|
}
|
2005-10-27 14:25:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check we didn't run of the end of the table */
|
2012-01-24 10:03:59 +01:00
|
|
|
if (n + sz > rawsize)
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
|
|
|
ERR("borked.\n");
|
2007-06-26 23:25:28 +02:00
|
|
|
dump_table( st, (USHORT *)rawdata, rawsize );
|
2005-10-27 14:25:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-05-24 18:51:58 +02:00
|
|
|
rec = msi_get_transform_record( tv, st, stg, &rawdata[n], bytes_per_strref );
|
2005-10-27 14:25:04 +02:00
|
|
|
if (rec)
|
|
|
|
{
|
2010-06-11 15:20:12 +02:00
|
|
|
WCHAR table[32];
|
|
|
|
DWORD sz = 32;
|
|
|
|
UINT number = MSI_NULL_INTEGER;
|
|
|
|
UINT row = 0;
|
2006-10-06 10:36:37 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if (!wcscmp( name, L"_Columns" ))
|
2010-06-11 15:20:12 +02:00
|
|
|
{
|
|
|
|
MSI_RecordGetStringW( rec, 1, table, &sz );
|
|
|
|
number = MSI_RecordGetInteger( rec, 2 );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Native msi seems writes nul into the Number (2nd) column of
|
2015-02-13 13:37:22 +01:00
|
|
|
* the _Columns table when there are new columns
|
2010-06-11 15:20:12 +02:00
|
|
|
*/
|
|
|
|
if ( number == MSI_NULL_INTEGER )
|
2006-10-06 10:36:37 +02:00
|
|
|
{
|
2010-06-11 15:20:12 +02:00
|
|
|
/* reset the column number on a new table */
|
2019-06-13 08:42:35 +02:00
|
|
|
if (wcscmp( coltable, table ))
|
2006-10-19 18:53:32 +02:00
|
|
|
{
|
2010-06-11 15:20:12 +02:00
|
|
|
colcol = 0;
|
|
|
|
lstrcpyW( coltable, table );
|
2006-10-19 18:53:32 +02:00
|
|
|
}
|
2010-06-11 15:20:12 +02:00
|
|
|
|
|
|
|
/* fix nul column numbers */
|
|
|
|
MSI_RecordSetInteger( rec, 2, ++colcol );
|
2006-10-06 10:36:37 +02:00
|
|
|
}
|
2010-06-11 15:20:12 +02:00
|
|
|
}
|
2006-10-06 10:36:37 +02:00
|
|
|
|
2010-06-11 15:20:12 +02:00
|
|
|
if (TRACE_ON(msidb)) dump_record( rec );
|
2007-07-10 04:34:41 +02:00
|
|
|
|
2020-06-25 20:08:55 +02:00
|
|
|
if (tv->table)
|
|
|
|
r = msi_table_find_row( tv, rec, &row, NULL );
|
|
|
|
else
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
2010-06-11 15:20:12 +02:00
|
|
|
if (r == ERROR_SUCCESS)
|
2005-10-27 14:25:04 +02:00
|
|
|
{
|
2010-06-11 15:20:12 +02:00
|
|
|
if (!mask)
|
2006-10-12 11:55:53 +02:00
|
|
|
{
|
2010-06-11 15:20:12 +02:00
|
|
|
TRACE("deleting row [%d]:\n", row);
|
2020-06-25 20:08:43 +02:00
|
|
|
r = tv->view.ops->delete_row( &tv->view, row );
|
2010-06-11 15:20:12 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
WARN("failed to delete row %u\n", r);
|
|
|
|
}
|
|
|
|
else if (mask & 1)
|
|
|
|
{
|
|
|
|
TRACE("modifying full row [%d]:\n", row);
|
2020-06-25 20:08:43 +02:00
|
|
|
r = tv->view.ops->set_row( &tv->view, row, rec, (1 << tv->num_cols) - 1 );
|
2010-06-11 15:20:12 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
WARN("failed to modify row %u\n", r);
|
2006-10-12 11:55:53 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-11 15:20:12 +02:00
|
|
|
TRACE("modifying masked row [%d]:\n", row);
|
2020-06-25 20:08:43 +02:00
|
|
|
r = tv->view.ops->set_row( &tv->view, row, rec, mask );
|
2010-06-11 15:20:12 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
WARN("failed to modify row %u\n", r);
|
2006-10-12 11:55:53 +02:00
|
|
|
}
|
2005-10-27 14:25:04 +02:00
|
|
|
}
|
2010-06-11 15:20:12 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("inserting row\n");
|
2020-06-25 20:08:43 +02:00
|
|
|
r = tv->view.ops->insert_row( &tv->view, rec, -1, FALSE );
|
2010-06-11 15:20:12 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
WARN("failed to insert row %u\n", r);
|
|
|
|
}
|
|
|
|
|
2020-06-25 20:08:43 +02:00
|
|
|
if (!(err_cond & MSITRANSFORM_ERROR_VIEWTRANSFORM) &&
|
2020-10-29 11:47:14 +01:00
|
|
|
!wcscmp( name, L"_Columns" ))
|
2010-06-11 15:20:12 +02:00
|
|
|
msi_update_table_columns( db, table );
|
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
|
2007-06-26 23:25:28 +02:00
|
|
|
n += sz;
|
2005-10-27 14:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
|
|
|
/* no need to free the table, it's associated with the database */
|
|
|
|
msi_free( rawdata );
|
|
|
|
if( tv )
|
|
|
|
tv->view.ops->delete( &tv->view );
|
|
|
|
|
2005-10-26 15:56:33 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* msi_table_apply_transform
|
|
|
|
*
|
|
|
|
* Enumerate the table transforms in a transform storage and apply each one.
|
|
|
|
*/
|
2020-06-25 20:08:43 +02:00
|
|
|
UINT msi_table_apply_transform( MSIDATABASE *db, IStorage *stg, int err_cond )
|
2005-10-26 15:56:33 +02:00
|
|
|
{
|
2007-07-10 04:34:41 +02:00
|
|
|
struct list transforms;
|
2005-10-26 15:56:33 +02:00
|
|
|
IEnumSTATSTG *stgenum = NULL;
|
2007-07-10 04:34:41 +02:00
|
|
|
TRANSFORMDATA *transform;
|
|
|
|
TRANSFORMDATA *tables = NULL, *columns = NULL;
|
2016-09-14 10:06:10 +02:00
|
|
|
HRESULT hr;
|
2005-10-26 15:56:33 +02:00
|
|
|
STATSTG stat;
|
|
|
|
string_table *strings;
|
|
|
|
UINT ret = ERROR_FUNCTION_FAILED;
|
2007-06-26 23:25:28 +02:00
|
|
|
UINT bytes_per_strref;
|
2014-11-04 10:57:40 +01:00
|
|
|
BOOL property_update = FALSE;
|
2020-07-01 10:43:08 +02:00
|
|
|
MSIVIEW *transform_view = NULL;
|
2005-10-26 15:56:33 +02:00
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
TRACE("%p %p\n", db, stg );
|
|
|
|
|
2007-06-26 23:25:28 +02:00
|
|
|
strings = msi_load_string_table( stg, &bytes_per_strref );
|
2005-10-26 15:56:33 +02:00
|
|
|
if( !strings )
|
|
|
|
goto end;
|
|
|
|
|
2016-09-14 10:06:10 +02:00
|
|
|
hr = IStorage_EnumElements( stg, 0, NULL, 0, &stgenum );
|
|
|
|
if (FAILED( hr ))
|
2005-10-26 15:56:33 +02:00
|
|
|
goto end;
|
|
|
|
|
2007-07-10 04:34:41 +02:00
|
|
|
list_init(&transforms);
|
|
|
|
|
|
|
|
while ( TRUE )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = NULL;
|
|
|
|
WCHAR name[0x40];
|
|
|
|
ULONG count = 0;
|
|
|
|
|
2016-09-14 10:06:10 +02:00
|
|
|
hr = IEnumSTATSTG_Next( stgenum, 1, &stat, &count );
|
|
|
|
if (FAILED( hr ) || !count)
|
2007-07-10 04:34:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
decode_streamname( stat.pwcsName, name );
|
2007-12-26 12:02:55 +01:00
|
|
|
CoTaskMemFree( stat.pwcsName );
|
2007-07-10 04:34:41 +02:00
|
|
|
if ( name[0] != 0x4840 )
|
|
|
|
continue;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if ( !wcscmp( name+1, L"_StringPool" ) ||
|
|
|
|
!wcscmp( name+1, L"_StringData" ) )
|
2007-07-10 04:34:41 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
transform = msi_alloc_zero( sizeof(TRANSFORMDATA) );
|
|
|
|
if ( !transform )
|
|
|
|
break;
|
|
|
|
|
|
|
|
list_add_tail( &transforms, &transform->entry );
|
|
|
|
|
|
|
|
transform->name = strdupW( name + 1 );
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if ( !wcscmp( transform->name, L"_Tables" ) )
|
2007-07-10 04:34:41 +02:00
|
|
|
tables = transform;
|
2020-10-29 11:47:14 +01:00
|
|
|
else if (!wcscmp( transform->name, L"_Columns" ) )
|
2007-07-10 04:34:41 +02:00
|
|
|
columns = transform;
|
2020-10-29 11:47:14 +01:00
|
|
|
else if (!wcscmp( transform->name, L"Property" ))
|
2014-11-04 10:57:40 +01:00
|
|
|
property_update = TRUE;
|
2007-07-10 04:34:41 +02:00
|
|
|
|
|
|
|
TRACE("transform contains stream %s\n", debugstr_w(name));
|
|
|
|
|
|
|
|
/* load the table */
|
2016-09-14 10:06:10 +02:00
|
|
|
if (TABLE_CreateView( db, transform->name, (MSIVIEW**) &tv ) != ERROR_SUCCESS)
|
2007-07-10 04:34:41 +02:00
|
|
|
continue;
|
|
|
|
|
2016-09-14 10:06:10 +02:00
|
|
|
if (tv->view.ops->execute( &tv->view, NULL ) != ERROR_SUCCESS)
|
2007-07-10 04:34:41 +02:00
|
|
|
{
|
|
|
|
tv->view.ops->delete( &tv->view );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tv->view.ops->delete( &tv->view );
|
|
|
|
}
|
|
|
|
|
2020-06-25 20:08:43 +02:00
|
|
|
if (err_cond & MSITRANSFORM_ERROR_VIEWTRANSFORM)
|
|
|
|
{
|
|
|
|
static const WCHAR create_query[] = L"CREATE TABLE `_TransformView` ( "
|
|
|
|
L"`Table` CHAR(0) NOT NULL TEMPORARY, `Column` CHAR(0) NOT NULL TEMPORARY, "
|
|
|
|
L"`Row` CHAR(0) TEMPORARY, `Data` CHAR(0) TEMPORARY, `Current` CHAR(0) TEMPORARY "
|
|
|
|
L"PRIMARY KEY `Table`, `Column`, `Row` ) HOLD";
|
2020-10-29 11:47:14 +01:00
|
|
|
|
2020-06-25 20:08:43 +02:00
|
|
|
MSIQUERY *query;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW( db, create_query, &query );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( query, NULL );
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
MSI_ViewClose( query );
|
|
|
|
msiobj_release( &query->hdr );
|
2020-07-01 10:43:08 +02:00
|
|
|
if (r != ERROR_BAD_QUERY_SYNTAX && r != ERROR_SUCCESS)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (TABLE_CreateView(db, L"_TransformView", &transform_view) != ERROR_SUCCESS)
|
|
|
|
goto end;
|
|
|
|
|
2020-06-25 20:08:43 +02:00
|
|
|
if (r == ERROR_BAD_QUERY_SYNTAX)
|
2020-07-01 10:43:08 +02:00
|
|
|
transform_view->ops->add_ref( transform_view );
|
|
|
|
|
|
|
|
r = transform_view->ops->add_column( transform_view, L"new",
|
|
|
|
MSITYPE_TEMPORARY | MSITYPE_NULLABLE | 0x402 /* INT */, FALSE );
|
2020-06-25 20:08:43 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2006-10-06 10:35:44 +02:00
|
|
|
/*
|
2006-11-01 07:09:33 +01:00
|
|
|
* Apply _Tables and _Columns transforms first so that
|
2006-10-06 10:35:44 +02:00
|
|
|
* the table metadata is correct, and empty tables exist.
|
|
|
|
*/
|
2020-06-25 20:08:43 +02:00
|
|
|
ret = msi_table_load_transform( db, stg, strings, tables, bytes_per_strref, err_cond );
|
2006-10-06 10:35:44 +02:00
|
|
|
if (ret != ERROR_SUCCESS && ret != ERROR_INVALID_TABLE)
|
|
|
|
goto end;
|
|
|
|
|
2020-06-25 20:08:43 +02:00
|
|
|
ret = msi_table_load_transform( db, stg, strings, columns, bytes_per_strref, err_cond );
|
2006-10-06 10:35:44 +02:00
|
|
|
if (ret != ERROR_SUCCESS && ret != ERROR_INVALID_TABLE)
|
|
|
|
goto end;
|
|
|
|
|
2005-10-26 15:56:33 +02:00
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
|
2007-07-10 04:34:41 +02:00
|
|
|
while ( !list_empty( &transforms ) )
|
2005-10-26 15:56:33 +02:00
|
|
|
{
|
2007-07-10 04:34:41 +02:00
|
|
|
transform = LIST_ENTRY( list_head( &transforms ), TRANSFORMDATA, entry );
|
2006-10-06 10:35:44 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if ( wcscmp( transform->name, L"_Columns" ) &&
|
|
|
|
wcscmp( transform->name, L"_Tables" ) &&
|
2007-07-10 04:34:41 +02:00
|
|
|
ret == ERROR_SUCCESS )
|
|
|
|
{
|
2020-06-25 20:08:43 +02:00
|
|
|
ret = msi_table_load_transform( db, stg, strings, transform, bytes_per_strref, err_cond );
|
2007-07-10 04:34:41 +02:00
|
|
|
}
|
2006-10-05 10:00:46 +02:00
|
|
|
|
2007-07-10 04:34:41 +02:00
|
|
|
list_remove( &transform->entry );
|
|
|
|
msi_free( transform->name );
|
|
|
|
msi_free( transform );
|
2005-10-26 15:56:33 +02:00
|
|
|
}
|
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
if ( ret == ERROR_SUCCESS )
|
2014-11-04 10:57:40 +01:00
|
|
|
{
|
2006-11-01 07:09:23 +01:00
|
|
|
append_storage_to_db( db, stg );
|
2014-11-04 10:57:40 +01:00
|
|
|
if (property_update) msi_clone_properties( db );
|
|
|
|
}
|
2005-10-27 14:25:04 +02:00
|
|
|
|
2005-10-26 15:56:33 +02:00
|
|
|
end:
|
|
|
|
if ( stgenum )
|
|
|
|
IEnumSTATSTG_Release( stgenum );
|
|
|
|
if ( strings )
|
|
|
|
msi_destroy_stringtable( strings );
|
2020-07-01 10:43:08 +02:00
|
|
|
if (transform_view)
|
2020-06-25 20:08:43 +02:00
|
|
|
{
|
2020-07-01 10:43:08 +02:00
|
|
|
struct tagMSITABLE *table = ((MSITABLEVIEW*)transform_view)->table;
|
|
|
|
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
transform_view->ops->release( transform_view );
|
|
|
|
|
|
|
|
if (!wcscmp(table->colinfo[table->col_count - 1].colname, L"new"))
|
|
|
|
TABLE_remove_column( transform_view, table->colinfo[table->col_count - 1].number );
|
|
|
|
transform_view->ops->delete( transform_view );
|
2020-06-25 20:08:43 +02:00
|
|
|
}
|
2005-10-26 15:56:33 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|