Commit 8568e0a4 authored by James Hawkins's avatar James Hawkins Committed by Alexandre Julliard

msi: Represent table data as bytes instead of shorts.

parent 65f23343
...@@ -62,9 +62,9 @@ typedef struct tagMSICOLUMNINFO ...@@ -62,9 +62,9 @@ typedef struct tagMSICOLUMNINFO
struct tagMSITABLE struct tagMSITABLE
{ {
USHORT **data; BYTE **data;
UINT row_count; UINT row_count;
USHORT **nonpersistent_data; BYTE **nonpersistent_data;
UINT nonpersistent_row_count; UINT nonpersistent_row_count;
struct list entry; struct list entry;
MSICOLUMNINFO *colinfo; MSICOLUMNINFO *colinfo;
...@@ -486,7 +486,7 @@ static UINT msi_table_get_row_size( const MSICOLUMNINFO *cols, UINT count ) ...@@ -486,7 +486,7 @@ static UINT msi_table_get_row_size( const MSICOLUMNINFO *cols, UINT count )
/* add this table to the list of cached tables in the database */ /* add this table to the list of cached tables in the database */
static UINT read_table_from_storage( MSITABLE *t, IStorage *stg ) static UINT read_table_from_storage( MSITABLE *t, IStorage *stg )
{ {
USHORT *rawdata = NULL; BYTE *rawdata = NULL;
UINT rawsize = 0, i, j, row_size = 0; UINT rawsize = 0, i, j, row_size = 0;
TRACE("%s\n",debugstr_w(t->name)); TRACE("%s\n",debugstr_w(t->name));
...@@ -494,7 +494,7 @@ static UINT read_table_from_storage( MSITABLE *t, IStorage *stg ) ...@@ -494,7 +494,7 @@ static UINT read_table_from_storage( MSITABLE *t, IStorage *stg )
row_size = msi_table_get_row_size( t->colinfo, t->col_count ); row_size = msi_table_get_row_size( t->colinfo, t->col_count );
/* if we can't read the table, just assume that it's empty */ /* if we can't read the table, just assume that it's empty */
read_stream_data( stg, t->name, &rawdata, &rawsize ); read_stream_data( stg, t->name, (USHORT **)&rawdata, &rawsize );
if( !rawdata ) if( !rawdata )
return ERROR_SUCCESS; return ERROR_SUCCESS;
...@@ -521,7 +521,7 @@ static UINT read_table_from_storage( MSITABLE *t, IStorage *stg ) ...@@ -521,7 +521,7 @@ static UINT read_table_from_storage( MSITABLE *t, IStorage *stg )
for( j=0; j<t->col_count; j++ ) for( j=0; j<t->col_count; j++ )
{ {
UINT ofs = t->colinfo[j].offset/2; UINT ofs = t->colinfo[j].offset;
UINT n = bytes_per_column( &t->colinfo[j] ); UINT n = bytes_per_column( &t->colinfo[j] );
UINT k; UINT k;
...@@ -531,8 +531,8 @@ static UINT read_table_from_storage( MSITABLE *t, IStorage *stg ) ...@@ -531,8 +531,8 @@ static UINT read_table_from_storage( MSITABLE *t, IStorage *stg )
goto err; goto err;
} }
for ( k = 0; k < n / 2; k++ ) for ( k = 0; k < n; k++ )
t->data[i][ofs + k] = rawdata[ofs*t->row_count + i * n / 2 + k]; t->data[i][ofs + k] = rawdata[ofs*t->row_count + i * n + k];
} }
} }
...@@ -811,7 +811,7 @@ static UINT get_table( MSIDATABASE *db, LPCWSTR name, MSITABLE **table_ret ) ...@@ -811,7 +811,7 @@ static UINT get_table( MSIDATABASE *db, LPCWSTR name, MSITABLE **table_ret )
static UINT save_table( MSIDATABASE *db, MSITABLE *t ) static UINT save_table( MSIDATABASE *db, MSITABLE *t )
{ {
USHORT *rawdata = NULL, *p; BYTE *rawdata = NULL, *p;
UINT rawsize, r, i, j, row_size; UINT rawsize, r, i, j, row_size;
/* Nothing to do for non-persistent tables */ /* Nothing to do for non-persistent tables */
...@@ -837,9 +837,13 @@ static UINT save_table( MSIDATABASE *db, MSITABLE *t ) ...@@ -837,9 +837,13 @@ static UINT save_table( MSIDATABASE *db, MSITABLE *t )
{ {
UINT offset = t->colinfo[i].offset; UINT offset = t->colinfo[i].offset;
*p++ = t->data[j][offset/2]; *p++ = t->data[j][offset];
*p++ = t->data[j][offset + 1];
if( 4 == bytes_per_column( &t->colinfo[i] ) ) if( 4 == bytes_per_column( &t->colinfo[i] ) )
*p++ = t->data[j][offset/2+1]; {
*p++ = t->data[j][offset + 2];
*p++ = t->data[j][offset + 3];
}
} }
} }
...@@ -924,12 +928,12 @@ static LPWSTR msi_makestring( MSIDATABASE *db, UINT stringid) ...@@ -924,12 +928,12 @@ static LPWSTR msi_makestring( MSIDATABASE *db, UINT stringid)
return strdupW(msi_string_lookup_id( db->strings, stringid )); return strdupW(msi_string_lookup_id( db->strings, stringid ));
} }
static UINT read_table_int(USHORT **data, UINT row, UINT col, UINT bytes) static UINT read_table_int(BYTE **data, UINT row, UINT col, UINT bytes)
{ {
UINT ret = 0, i; UINT ret = 0, i;
for (i = 0; i < bytes / 2; i++) for (i = 0; i < bytes; i++)
ret += (data[row][col + i] << i * 16); ret += (data[row][col + i] << i * 8);
return ret; return ret;
} }
...@@ -975,8 +979,8 @@ static UINT get_tablecolumns( MSIDATABASE *db, ...@@ -975,8 +979,8 @@ static UINT get_tablecolumns( MSIDATABASE *db,
continue; continue;
if( colinfo ) if( colinfo )
{ {
UINT id = table->data[ i ] [ 2 ]; UINT id = read_table_int(table->data, i, 4, sizeof(USHORT));
UINT col = table->data[ i ][ 1 ] - (1<<15); UINT col = read_table_int(table->data, i, 2, sizeof(USHORT)) - (1<<15);
/* check the column number is in range */ /* check the column number is in range */
if (col<1 || col>maxcount) if (col<1 || col>maxcount)
...@@ -995,7 +999,7 @@ static UINT get_tablecolumns( MSIDATABASE *db, ...@@ -995,7 +999,7 @@ static UINT get_tablecolumns( MSIDATABASE *db,
colinfo[ col - 1 ].tablename = msi_makestring( db, table_id ); colinfo[ col - 1 ].tablename = msi_makestring( db, table_id );
colinfo[ col - 1 ].number = col; colinfo[ col - 1 ].number = col;
colinfo[ col - 1 ].colname = msi_makestring( db, id ); colinfo[ col - 1 ].colname = msi_makestring( db, id );
colinfo[ col - 1 ].type = table->data[ i ] [ 3 ] - (1<<15); colinfo[ col - 1 ].type = read_table_int(table->data, i, 6, sizeof(USHORT)) - (1<<15);
colinfo[ col - 1 ].offset = 0; colinfo[ col - 1 ].offset = 0;
colinfo[ col - 1 ].hash_table = NULL; colinfo[ col - 1 ].hash_table = NULL;
} }
...@@ -1080,7 +1084,7 @@ static UINT TABLE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT * ...@@ -1080,7 +1084,7 @@ static UINT TABLE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *
{ {
MSITABLEVIEW *tv = (MSITABLEVIEW*)view; MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
UINT offset, n; UINT offset, n;
USHORT **data; BYTE **data;
if( !tv->table ) if( !tv->table )
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
...@@ -1114,7 +1118,7 @@ static UINT TABLE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT * ...@@ -1114,7 +1118,7 @@ static UINT TABLE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *
return ERROR_FUNCTION_FAILED; return ERROR_FUNCTION_FAILED;
} }
offset = tv->columns[col-1].offset / 2; offset = tv->columns[col-1].offset;
*val = read_table_int(data, row, offset, n); *val = read_table_int(data, row, offset, n);
/* TRACE("Data [%d][%d] = %d\n", row, col, *val ); */ /* TRACE("Data [%d][%d] = %d\n", row, col, *val ); */
...@@ -1193,7 +1197,7 @@ static UINT TABLE_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, ISt ...@@ -1193,7 +1197,7 @@ static UINT TABLE_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, ISt
static UINT TABLE_set_int( MSITABLEVIEW *tv, UINT row, UINT col, UINT val ) static UINT TABLE_set_int( MSITABLEVIEW *tv, UINT row, UINT col, UINT val )
{ {
UINT offset, n, i; UINT offset, n, i;
USHORT **data; BYTE **data;
if( !tv->table ) if( !tv->table )
return ERROR_INVALID_PARAMETER; return ERROR_INVALID_PARAMETER;
...@@ -1229,9 +1233,9 @@ static UINT TABLE_set_int( MSITABLEVIEW *tv, UINT row, UINT col, UINT val ) ...@@ -1229,9 +1233,9 @@ static UINT TABLE_set_int( MSITABLEVIEW *tv, UINT row, UINT col, UINT val )
return ERROR_FUNCTION_FAILED; return ERROR_FUNCTION_FAILED;
} }
offset = tv->columns[col-1].offset / 2; offset = tv->columns[col-1].offset;
for ( i = 0; i < n / 2; i++ ) for ( i = 0; i < n; i++ )
data[row][offset + i] = (val >> i * 16) & 0xffff; data[row][offset + i] = (val >> i * 8) & 0xff;
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
...@@ -1299,9 +1303,9 @@ static UINT TABLE_set_row( struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UI ...@@ -1299,9 +1303,9 @@ static UINT TABLE_set_row( struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UI
static UINT table_create_new_row( struct tagMSIVIEW *view, UINT *num, BOOL temporary ) static UINT table_create_new_row( struct tagMSIVIEW *view, UINT *num, BOOL temporary )
{ {
MSITABLEVIEW *tv = (MSITABLEVIEW*)view; MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
USHORT **p, *row; BYTE **p, *row;
UINT sz; UINT sz;
USHORT ***data_ptr; BYTE ***data_ptr;
UINT *row_count; UINT *row_count;
TRACE("%p %s\n", view, temporary ? "TRUE" : "FALSE"); TRACE("%p %s\n", view, temporary ? "TRUE" : "FALSE");
...@@ -1326,7 +1330,7 @@ static UINT table_create_new_row( struct tagMSIVIEW *view, UINT *num, BOOL tempo ...@@ -1326,7 +1330,7 @@ static UINT table_create_new_row( struct tagMSIVIEW *view, UINT *num, BOOL tempo
*num = tv->table->row_count; *num = tv->table->row_count;
} }
sz = (*row_count + 1) * sizeof (UINT*); sz = (*row_count + 1) * sizeof (BYTE*);
if( *data_ptr ) if( *data_ptr )
p = msi_realloc( *data_ptr, sz ); p = msi_realloc( *data_ptr, sz );
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment