WCHAR name[1];
};
-typedef struct tagMSITRANSFORM {
- struct list entry;
- IStorage *stg;
-} MSITRANSFORM;
-
static const WCHAR szStringData[] = {
'_','S','t','r','i','n','g','D','a','t','a',0 };
static const WCHAR szStringPool[] = {
static UINT get_tablecolumns( MSIDATABASE *db,
LPCWSTR szTableName, MSICOLUMNINFO *colinfo, UINT *sz);
static void msi_free_colinfo( MSICOLUMNINFO *colinfo, UINT count );
-static UINT table_find_insert_idx (MSIVIEW *view, LPCWSTR name, INT *pidx);
static inline UINT bytes_per_column( MSIDATABASE *db, const MSICOLUMNINFO *col )
{
return -1;
}
-static LPWSTR encode_streamname(BOOL bTable, LPCWSTR in)
+LPWSTR encode_streamname(BOOL bTable, LPCWSTR in)
{
DWORD count = MAX_STREAM_NAME;
DWORD ch, next;
return ret;
}
-static UINT db_get_raw_stream( MSIDATABASE *db, LPCWSTR stname, IStream **stm )
-{
- LPWSTR encname;
- HRESULT r;
-
- encname = encode_streamname(FALSE, stname);
-
- TRACE("%s -> %s\n",debugstr_w(stname),debugstr_w(encname));
-
- r = IStorage_OpenStream(db->storage, encname, NULL,
- STGM_READ | STGM_SHARE_EXCLUSIVE, 0, stm);
- if( FAILED( r ) )
- {
- MSITRANSFORM *transform;
-
- LIST_FOR_EACH_ENTRY( transform, &db->transforms, MSITRANSFORM, entry )
- {
- TRACE("looking for %s in transform storage\n", debugstr_w(stname) );
- r = IStorage_OpenStream( transform->stg, encname, NULL,
- STGM_READ | STGM_SHARE_EXCLUSIVE, 0, stm );
- if (SUCCEEDED(r))
- break;
- }
- }
-
- msi_free( encname );
-
- return SUCCEEDED(r) ? ERROR_SUCCESS : ERROR_FUNCTION_FAILED;
-}
-
-UINT read_raw_stream_data( MSIDATABASE *db, LPCWSTR stname,
- USHORT **pdata, UINT *psz )
-{
- HRESULT r;
- UINT ret = ERROR_FUNCTION_FAILED;
- VOID *data;
- ULONG sz, count;
- IStream *stm = NULL;
- STATSTG stat;
-
- r = db_get_raw_stream( db, stname, &stm );
- if( r != ERROR_SUCCESS)
- return ret;
- r = IStream_Stat(stm, &stat, STATFLAG_NONAME );
- if( FAILED( r ) )
- {
- WARN("open stream failed r = %08x!\n", r);
- goto end;
- }
-
- if( stat.cbSize.QuadPart >> 32 )
- {
- WARN("Too big!\n");
- goto end;
- }
-
- sz = stat.cbSize.QuadPart;
- data = msi_alloc( sz );
- if( !data )
- {
- WARN("couldn't allocate memory r=%08x!\n", r);
- ret = ERROR_NOT_ENOUGH_MEMORY;
- goto end;
- }
-
- r = IStream_Read(stm, data, sz, &count );
- if( FAILED( r ) || ( count != sz ) )
- {
- msi_free( data );
- WARN("read stream failed r = %08x!\n", r);
- goto end;
- }
-
- *pdata = data;
- *psz = sz;
- ret = ERROR_SUCCESS;
-
-end:
- IStream_Release( stm );
-
- return ret;
-}
-
UINT write_stream_data( IStorage *stg, LPCWSTR stname,
LPCVOID data, UINT sz, BOOL bTable )
{
column_info *col;
MSITABLE *table;
UINT i;
- INT idx;
/* only add tables that don't exist already */
if( TABLE_Exists(db, name ) )
if( r )
goto err;
- r = table_find_insert_idx (tv, name, &idx);
- if (r != ERROR_SUCCESS)
- idx = -1;
-
- r = tv->ops->insert_row( tv, rec, idx, persistent == MSICONDITION_FALSE );
+ r = tv->ops->insert_row( tv, rec, -1, persistent == MSICONDITION_FALSE );
TRACE("insert_row returned %x\n", r);
if( r )
goto err;
if( r )
goto err;
- r = table_find_insert_idx (tv, name, &idx);
- if (r != ERROR_SUCCESS)
- idx = -1;
-
- r = tv->ops->insert_row( tv, rec, idx, FALSE );
+ r = tv->ops->insert_row( tv, rec, -1, FALSE );
if( r )
goto err;
static void msi_update_table_columns( MSIDATABASE *db, LPCWSTR name )
{
MSITABLE *table;
+ LPWSTR tablename;
UINT size, offset, old_count;
UINT n;
- table = find_cached_table( db, name );
+ /* We may free name in msi_free_colinfo. */
+ tablename = strdupW( name );
+
+ table = find_cached_table( db, tablename );
old_count = table->col_count;
+ msi_free_colinfo( table->colinfo, table->col_count );
msi_free( table->colinfo );
table->colinfo = NULL;
- table_get_column_info( db, name, &table->colinfo, &table->col_count );
+ table_get_column_info( db, tablename, &table->colinfo, &table->col_count );
if (!table->col_count)
- return;
+ goto done;
size = msi_table_get_row_size( db, table->colinfo, table->col_count );
offset = table->colinfo[table->col_count - 1].offset;
if (old_count < table->col_count)
memset( &table->data[n][offset], 0, size - offset );
}
+
+done:
+ msi_free(tablename);
}
/* try to find the table name in the _Tables table */
type = tv->columns[i].type;
if ( type & MSITYPE_KEY )
{
- static const WCHAR szDot[] = { '.', 0 };
-
r = TABLE_fetch_int( view, row, i+1, &ival );
if ( r != ERROR_SUCCESS )
goto err;
switch( n )
{
case 2:
- sprintfW( number, fmt, ival^0x8000 );
+ sprintfW( number, fmt, ival-0x8000 );
break;
case 4:
sprintfW( number, fmt, ival^0x80000000 );
{
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
UINT r;
- LPWSTR full_name = NULL;
+ LPWSTR encname, full_name = NULL;
if( !view->ops->fetch_int )
return ERROR_INVALID_PARAMETER;
return r;
}
- r = db_get_raw_stream( tv->db, full_name, stm );
+ encname = encode_streamname( FALSE, full_name );
+ r = db_get_raw_stream( tv->db, encname, stm );
if( r )
ERR("fetching stream %s, error = %d\n",debugstr_w(full_name), r);
- msi_free( full_name );
+ msi_free( full_name );
+ msi_free( encname );
return r;
}
return r;
}
+static UINT get_table_value_from_record( MSITABLEVIEW *tv, MSIRECORD *rec, UINT iField, UINT *pvalue )
+{
+ MSICOLUMNINFO columninfo;
+ UINT r;
+
+ if ( (iField <= 0) ||
+ (iField > tv->num_cols) ||
+ MSI_RecordIsNull( rec, iField ) )
+ 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 )
+ {
+ LPCWSTR sval = MSI_RecordGetString( rec, iField );
+
+ r = msi_string2idW(tv->db->strings, sval, pvalue);
+ if (r != ERROR_SUCCESS)
+ return ERROR_NOT_FOUND;
+ }
+ else if ( 2 == bytes_per_column( tv->db, &columninfo ) )
+ {
+ *pvalue = 0x8000 + MSI_RecordGetInteger( rec, iField );
+ if ( *pvalue & 0xffff0000 )
+ {
+ ERR("field %u value %d out of range\n", iField, *pvalue - 0x8000);
+ return ERROR_FUNCTION_FAILED;
+ }
+ }
+ else
+ {
+ INT ival = MSI_RecordGetInteger( rec, iField );
+ *pvalue = ival ^ 0x80000000;
+ }
+
+ return ERROR_SUCCESS;
+}
+
static UINT TABLE_set_row( struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UINT mask )
{
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
val = 0;
if ( !MSI_RecordIsNull( rec, i + 1 ) )
{
+ r = get_table_value_from_record (tv, rec, i + 1, &val);
if ( MSITYPE_IS_BINARY(tv->columns[ i ].type) )
{
IStream *stm;
LPWSTR stname;
+ if ( r != ERROR_SUCCESS )
+ return ERROR_FUNCTION_FAILED;
+
r = MSI_RecordGetIStream( rec, i + 1, &stm );
if ( r != ERROR_SUCCESS )
return r;
if ( r != ERROR_SUCCESS )
return r;
-
- val = 1; /* refers to the first key column */
}
else if ( tv->columns[i].type & MSITYPE_STRING )
{
- LPCWSTR sval = MSI_RecordGetString( rec, i + 1 );
- UINT ival, x;
+ UINT x;
- r = msi_string2idW(tv->db->strings, sval, &ival);
- if (r == ERROR_SUCCESS)
+ if ( r != ERROR_SUCCESS )
{
- TABLE_fetch_int(&tv->view, row, i + 1, &x);
- if (ival == x)
- continue;
- }
+ LPCWSTR sval = MSI_RecordGetString( rec, i + 1 );
+ val = msi_addstringW( tv->db->strings, 0, sval, -1, 1,
+ persistent ? StringPersistent : StringNonPersistent );
- val = msi_addstringW( tv->db->strings, 0, sval, -1, 1,
- persistent ? StringPersistent : StringNonPersistent );
- }
- else if ( 2 == bytes_per_column( tv->db, &tv->columns[ i ] ) )
- {
- val = 0x8000 + MSI_RecordGetInteger( rec, i + 1 );
- if ( val & 0xffff0000 )
+ }
+ else
{
- ERR("field %u value %d out of range\n", i+1, val - 0x8000 );
- return ERROR_FUNCTION_FAILED;
+ TABLE_fetch_int(&tv->view, row, i + 1, &x);
+ if (val == x)
+ continue;
}
}
else
{
- INT ival = MSI_RecordGetInteger( rec, i + 1 );
- val = ival ^ 0x80000000;
+ if ( r != ERROR_SUCCESS )
+ return ERROR_FUNCTION_FAILED;
}
}
}
static UINT TABLE_get_column_info( struct tagMSIVIEW *view,
- UINT n, LPWSTR *name, UINT *type, BOOL *temporary )
+ UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR *table_name )
{
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
return ERROR_FUNCTION_FAILED;
}
+ if( table_name )
+ {
+ *table_name = strdupW( tv->columns[n-1].tablename );
+ if( !*table_name )
+ return ERROR_FUNCTION_FAILED;
+ }
+
if( type )
*type = tv->columns[n-1].type;
return ERROR_SUCCESS;
}
+static UINT find_insert_index( MSITABLEVIEW *tv, MSIRECORD *rec, UINT *pidx )
+{
+ UINT r, idx, j, ivalue, x;
+
+ TRACE("%p %p %p\n", tv, rec, pidx);
+
+ for (idx = 0; idx < tv->table->row_count; idx++)
+ {
+ for (j = 0; j < tv->num_cols; j++ )
+ {
+ r = get_table_value_from_record (tv, rec, j+1, &ivalue);
+ if (r != ERROR_SUCCESS)
+ break;
+
+ r = TABLE_fetch_int(&tv->view, idx, j + 1, &x);
+ if (r != ERROR_SUCCESS)
+ return r;
+
+ if (ivalue > x)
+ break;
+ else if (ivalue == x)
+ continue;
+ else {
+ TRACE("Found %d.\n", idx);
+ *pidx = idx;
+ return ERROR_SUCCESS;
+ }
+ }
+ }
+
+ TRACE("Found %d.\n", idx);
+ *pidx = idx;
+ return ERROR_SUCCESS;
+}
+
static UINT TABLE_insert_row( struct tagMSIVIEW *view, MSIRECORD *rec, UINT row, BOOL temporary )
{
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
if( r != ERROR_SUCCESS )
return ERROR_FUNCTION_FAILED;
+ if (row == -1)
+ {
+ r = find_insert_index(tv, rec, &row);
+ if( r != ERROR_SUCCESS )
+ return ERROR_FUNCTION_FAILED;
+ }
+
r = table_create_new_row( view, &row, temporary );
TRACE("insert_row returned %08x\n", r);
if( r != ERROR_SUCCESS )
tv->columns[i].hash_table = NULL;
}
- if ( row == num_rows - 1 )
- return ERROR_SUCCESS;
-
for (i = row + 1; i < num_rows; i++)
{
memcpy(tv->table->data[i - 1], tv->table->data[i], tv->row_size);
tv->table->data_persistent[i - 1] = tv->table->data_persistent[i];
}
+ msi_free(tv->table->data[num_rows - 1]);
+
return ERROR_SUCCESS;
}
if (r != ERROR_SUCCESS)
return r;
+ /* Close the original record */
+ MSI_CloseRecord(&rec->hdr);
+
count = MSI_RecordGetFieldCount(rec);
for (i = 0; i < count; i++)
MSI_RecordCopyField(curr, i + 1, rec, i + 1);
static UINT order_add_column(struct tagMSIVIEW *view, MSIORDERINFO *order, LPCWSTR name)
{
UINT n, r, count;
+ MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
r = TABLE_get_dimensions(view, NULL, &count);
if (r != ERROR_SUCCESS)
if (order->num_cols >= count)
return ERROR_FUNCTION_FAILED;
- r = VIEW_find_column(view, name, &n);
+ r = VIEW_find_column(view, name, tv->name, &n);
if (r != ERROR_SUCCESS)
return r;
list_remove(&tv->table->entry);
free_table(tv->table);
- TABLE_delete(view);
done:
msiobj_release(&rec->hdr);
static UINT msi_record_encoded_stream_name( const MSITABLEVIEW *tv, MSIRECORD *rec, LPWSTR *pstname )
{
- static const WCHAR szDot[] = { '.', 0 };
LPWSTR stname = NULL, sval, p;
DWORD len;
UINT i, r;
case 2:
val = read_raw_int(rawdata, ofs, n);
if (val)
- MSI_RecordSetInteger( rec, i+1, val^0x8000 );
+ MSI_RecordSetInteger( rec, i+1, val-0x8000 );
TRACE(" field %d [0x%04x]\n", i+1, val );
break;
case 4:
r = TABLE_insert_row( &tv->view, rec, -1, FALSE );
if (r != ERROR_SUCCESS)
- ERR("insert row failed\n");
+ WARN("insert row failed\n");
if ( number != MSI_NULL_INTEGER && !lstrcmpW(name, szColumns) )
msi_update_table_columns( db, table );
r = msi_table_find_row( tv, rec, &row );
if (r != ERROR_SUCCESS)
- ERR("no matching row to transform\n");
+ WARN("no matching row to transform\n");
else if ( mask )
{
TRACE("modifying row [%d]:\n", row);
return ret;
}
-
-void append_storage_to_db( MSIDATABASE *db, IStorage *stg )
-{
- MSITRANSFORM *t;
-
- t = msi_alloc( sizeof *t );
- t->stg = stg;
- IStorage_AddRef( stg );
- list_add_tail( &db->transforms, &t->entry );
-}
-
-void msi_free_transforms( MSIDATABASE *db )
-{
- while( !list_empty( &db->transforms ) )
- {
- MSITRANSFORM *t = LIST_ENTRY( list_head( &db->transforms ),
- MSITRANSFORM, entry );
- list_remove( &t->entry );
- IStorage_Release( t->stg );
- msi_free( t );
- }
-}
-
-static UINT table_find_insert_idx (MSIVIEW *view, LPCWSTR name, INT *pidx)
-{
- UINT r, name_id, row_id;
- INT idx;
- MSITABLEVIEW *tv = (MSITABLEVIEW *)view;
-
- TRACE ("%p %s\n", view, debugstr_w(name));
-
- r = msi_string2idW(tv->db->strings, name, &name_id);
- if (r != ERROR_SUCCESS)
- {
- *pidx = -1;
- return r;
- }
-
- for( idx = 0; idx < tv->table->row_count; idx++ )
- {
- r = TABLE_fetch_int( &tv->view, idx, 1, &row_id );
- if (row_id > name_id)
- break;
- }
-
- *pidx = idx;
- return ERROR_SUCCESS;
-}