Commit 068b4ec7 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

First go at write support.

parent 7e997ef0
/*
* Implementation of the Microsoft Installer (msi.dll)
*
* Copyright 2002 Mike McCormack for CodeWeavers
* Copyright 2002-2004 Mike McCormack for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -59,30 +59,107 @@ static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT
static UINT CREATE_execute( struct tagMSIVIEW *view, MSIHANDLE record )
{
MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
create_col_info *c;
FIXME("%p %ld\n", cv, record);
create_col_info *col;
UINT r, nField, row, table_val, column_val;
const WCHAR szTables[] = { '_','T','a','b','l','e','s',0 };
const WCHAR szColumns[] = { '_','C','o','l','u','m','n','s',0 };
MSIVIEW *tv = NULL;
FIXME("Table %s (%s)\n", debugstr_w(cv->name),
TRACE("%p Table %s (%s)\n", cv, debugstr_w(cv->name),
cv->bIsTemp?"temporary":"permanent");
for( c = cv->col_info; c; c = c->next )
/* only add tables that don't exist already */
if( TABLE_Exists(cv->db, cv->name ) )
return ERROR_BAD_QUERY_SYNTAX;
/* add the name to the _Tables table */
table_val = msi_addstringW( cv->db->strings, 0, cv->name, -1, 1 );
TRACE("New string %s -> %d\n", debugstr_w( cv->name ), table_val );
if( table_val < 0 )
return ERROR_FUNCTION_FAILED;
r = TABLE_CreateView( cv->db, szTables, &tv );
TRACE("CreateView returned %x\n", r);
if( r )
return r;
r = tv->ops->execute( tv, 0 );
TRACE("tv execute returned %x\n", r);
if( r )
return r;
row = -1;
r = tv->ops->insert_row( tv, &row );
TRACE("insert_row returned %x\n", r);
if( r )
goto err;
r = tv->ops->set_int( tv, row, 1, table_val );
if( r )
goto err;
tv->ops->delete( tv );
tv = NULL;
/* add each column to the _Columns table */
r = TABLE_CreateView( cv->db, szColumns, &tv );
if( r )
return r;
r = tv->ops->execute( tv, 0 );
TRACE("tv execute returned %x\n", r);
if( r )
return r;
row = -1;
r = tv->ops->insert_row( tv, &row );
if( r )
goto err;
/*
* need to set the table, column number, col name and type
* for each column we enter in the table
*/
nField = 1;
for( col = cv->col_info; col; col = col->next )
{
FIXME("Column %s type %04x\n", debugstr_w(c->colname), c->type );
column_val = msi_addstringW( cv->db->strings, 0, col->colname, -1, 1 );
TRACE("New string %s -> %d\n", debugstr_w( col->colname ), column_val );
if( column_val < 0 )
break;
r = tv->ops->set_int( tv, row, 1, table_val );
if( r )
break;
r = tv->ops->set_int( tv, row, 2, 0x8000|nField );
if( r )
break;
r = tv->ops->set_int( tv, row, 3, column_val );
if( r )
break;
r = tv->ops->set_int( tv, row, 4, 0x8000|col->type );
if( r )
break;
}
return ERROR_SUCCESS;
return ERROR_FUNCTION_FAILED;
if( !col )
r = ERROR_SUCCESS;
err:
/* FIXME: remove values from the string table on error */
if( tv )
tv->ops->delete( tv );
return r;
}
static UINT CREATE_close( struct tagMSIVIEW *view )
{
MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
FIXME("%p\n", cv );
TRACE("%p\n", cv);
return ERROR_SUCCESS;
return ERROR_FUNCTION_FAILED;
}
static UINT CREATE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
......@@ -138,6 +215,8 @@ static UINT CREATE_delete( struct tagMSIVIEW *view )
MSIVIEWOPS create_ops =
{
CREATE_fetch_int,
NULL,
NULL,
CREATE_execute,
CREATE_close,
CREATE_get_dimensions,
......
......@@ -250,6 +250,8 @@ static UINT DISTINCT_delete( struct tagMSIVIEW *view )
MSIVIEWOPS distinct_ops =
{
DISTINCT_fetch_int,
NULL,
NULL,
DISTINCT_execute,
DISTINCT_close,
DISTINCT_get_dimensions,
......
......@@ -211,6 +211,8 @@ UINT WINAPI MsiOpenDatabaseW(
{
r = StgCreateDocfile( szDBPath,
STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &stg);
if( r == ERROR_SUCCESS )
r = init_string_table( stg );
}
else if( szPersist == MSIDBOPEN_TRANSACT )
{
......
......@@ -65,6 +65,19 @@ typedef struct tagMSIVIEWOPS
UINT (*fetch_int)( struct tagMSIVIEW *, UINT row, UINT col, UINT *val );
/*
* get_int - sets one integer at {row,col} in the table
*
* Similar semantics to fetch_int
*/
UINT (*set_int)( struct tagMSIVIEW *, UINT row, UINT col, UINT val );
/*
* Inserts a new, blank row into the database
* *row receives the number of the new row
*/
UINT (*insert_row)( struct tagMSIVIEW *, UINT *row );
/*
* execute - loads the underlying data into memory so it can be read
*/
UINT (*execute)( struct tagMSIVIEW *, MSIHANDLE );
......@@ -154,14 +167,18 @@ extern UINT find_cached_table(MSIDATABASE *db, LPCWSTR name, MSITABLE **table);
extern UINT get_table(MSIDATABASE *db, LPCWSTR name, MSITABLE **table);
extern UINT load_string_table( MSIDATABASE *db );
extern UINT MSI_CommitTables( MSIDATABASE *db );
extern HRESULT init_string_table( IStorage *stg );
/* string table functions */
extern BOOL msi_addstring( string_table *st, UINT string_no, CHAR *data, UINT len, UINT refcount );
extern BOOL msi_addstring( string_table *st, UINT string_no, const CHAR *data, UINT len, UINT refcount );
extern BOOL msi_addstringW( string_table *st, UINT string_no, const WCHAR *data, UINT len, UINT refcount );
extern UINT msi_id2stringW( string_table *st, UINT string_no, LPWSTR buffer, UINT *sz );
extern UINT msi_id2stringA( string_table *st, UINT string_no, LPSTR buffer, UINT *sz );
extern LPWSTR MSI_makestring( MSIDATABASE *db, UINT stringid);
extern UINT msi_string2id( string_table *st, LPCWSTR buffer, UINT *id );
extern UINT msi_string2idA( string_table *st, LPCSTR str, UINT *id );
extern string_table *msi_init_stringtable( int entries );
extern VOID msi_destroy_stringtable( string_table *st );
extern UINT msi_string_count( string_table *st );
......@@ -170,4 +187,6 @@ extern UINT msi_string_totalsize( string_table *st );
UINT VIEW_find_column( MSIVIEW *view, LPWSTR name, UINT *n );
extern BOOL TABLE_Exists( MSIDATABASE *db, LPWSTR name );
#endif /* __WINE_MSI_PRIVATE__ */
......@@ -253,6 +253,8 @@ static UINT ORDER_delete( struct tagMSIVIEW *view )
MSIVIEWOPS order_ops =
{
ORDER_fetch_int,
NULL,
NULL,
ORDER_execute,
ORDER_close,
ORDER_get_dimensions,
......
......@@ -79,7 +79,7 @@ typedef struct _create_col_info
UINT MSI_ParseSQL( MSIDATABASE *db, LPCWSTR command, MSIVIEW **phView);
UINT TABLE_CreateView( MSIDATABASE *db, LPWSTR name, MSIVIEW **view );
UINT TABLE_CreateView( MSIDATABASE *db, LPCWSTR name, MSIVIEW **view );
UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table );
UINT SELECT_AddColumn( MSIVIEW *select, LPWSTR name );
......
......@@ -152,6 +152,8 @@ static UINT SELECT_delete( struct tagMSIVIEW *view )
MSIVIEWOPS select_ops =
{
SELECT_fetch_int,
NULL,
NULL,
SELECT_execute,
SELECT_close,
SELECT_get_dimensions,
......
......@@ -3,7 +3,7 @@
/*
* Implementation of the Microsoft Installer (msi.dll)
*
* Copyright 2002 Mike McCormack for CodeWeavers
* Copyright 2002-2004 Mike McCormack for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -98,10 +98,12 @@ static struct expr * EXPR_sval( LPWSTR string );
%token TK_HAVING TK_HOLD
%token TK_IGNORE TK_ILLEGAL TK_IMMEDIATE TK_IN TK_INDEX TK_INITIALLY
%token <string> TK_ID
%token TK_INSERT TK_INSTEAD TK_INT TK_INTEGER TK_INTERSECT TK_INTO TK_IS TK_ISNULL
%token TK_INSERT TK_INSTEAD TK_INT TK_INTEGER TK_INTERSECT TK_INTO TK_IS
%token TK_ISNULL
%token TK_JOIN TK_JOIN_KW
%token TK_KEY
%token TK_LE TK_LIKE TK_LIMIT TK_LONG TK_LONGCHAR TK_LP TK_LSHIFT TK_LT
%token TK_LOCALIZABLE
%token TK_MATCH TK_MINUS
%token TK_NE TK_NOT TK_NOTNULL TK_NULL
%token TK_OBJECT TK_OF TK_OFFSET TK_ON TK_OR TK_ORACLE_OUTER_JOIN TK_ORDER
......@@ -129,7 +131,7 @@ static struct expr * EXPR_sval( LPWSTR string );
%type <column_list> selcollist
%type <query> from unorderedsel oneselect onequery onecreate
%type <expr> expr val column_val
%type <column_type> column_type data_type data_count
%type <column_type> column_type data_type data_type_l data_count
%type <column_info> column_def table_def
%%
......@@ -183,15 +185,24 @@ table_def:
column_def:
column_def TK_COMMA column column_type
{
$$ = HeapAlloc( GetProcessHeap(), 0, sizeof *$$ );
if( $$ )
create_col_info *ci;
for( ci = $1; ci->next; ci = ci->next )
;
ci->next = HeapAlloc( GetProcessHeap(), 0, sizeof *$$ );
if( ci->next )
{
$$->colname = $3;
$$->type = $4;
$$->next = $1;
ci->next->colname = $3;
ci->next->type = $4;
ci->next->next = NULL;
}
else if( $1 )
{
HeapFree( GetProcessHeap(), 0, $1 );
$1 = NULL;
}
$$ = $1;
}
| column column_type
{
......@@ -206,6 +217,18 @@ column_def:
;
column_type:
data_type_l
{
$$ = $1;
}
| data_type_l TK_LOCALIZABLE
{
FIXME("LOCALIZABLE ignored\n");
$$ = $1;
}
;
data_type_l:
data_type
{
$$ |= MSITYPE_NULLABLE;
......
/*
* Implementation of the Microsoft Installer (msi.dll)
*
* Copyright 2002 Mike McCormack for CodeWeavers
* Copyright 2002-2004, Mike McCormack for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -50,7 +50,7 @@ struct string_table
msistring *strings; /* an array of strings (in the tree) */
};
static int msistring_makehash( char *str )
static int msistring_makehash( const char *str )
{
int hash = 0;
......@@ -78,7 +78,7 @@ string_table *msi_init_stringtable( int entries )
return NULL;
}
st->count = entries;
st->freeslot = 0;
st->freeslot = 1;
return st;
}
......@@ -98,18 +98,28 @@ VOID msi_destroy_stringtable( string_table *st )
static int st_find_free_entry( string_table *st )
{
int i;
int i, sz;
msistring *p;
for( i = st->freeslot; i < st->count; i++ )
if( !st->strings[i].refcount )
return i;
for( i = 0; i < st->freeslot; i++ )
for( i = 1; i < st->freeslot; i++ )
if( !st->strings[i].refcount )
return i;
FIXME("dynamically resize\n");
return -1;
/* dynamically resize */
sz = st->count + 1 + st->count/2;
p = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
st->strings, sz*sizeof(msistring) );
if( !p )
return -1;
st->strings = p;
st->freeslot = st->count;
st->count = sz;
if( st->strings[st->freeslot].refcount )
ERR("oops. expected freeslot to be free...\n");
return st->freeslot;
}
static void st_mark_entry_used( string_table *st, int n )
......@@ -119,15 +129,28 @@ static void st_mark_entry_used( string_table *st, int n )
st->freeslot = n + 1;
}
int msi_addstring( string_table *st, UINT string_no, CHAR *data, UINT len, UINT refcount )
int msi_addstring( string_table *st, UINT n, const CHAR *data, UINT len, UINT refcount )
{
int n;
/* TRACE("[%2d] = %s\n", string_no, debugstr_an(data,len) ); */
n = st_find_free_entry( st );
if( n < 0 )
return -1;
if( !data[0] )
return 0;
if( n > 0 )
{
if( st->strings[n].refcount )
return -1;
}
else
{
if( ERROR_SUCCESS == msi_string2idA( st, data, &n ) )
{
st->strings[n].refcount++;
return n;
}
n = st_find_free_entry( st );
if( n < 0 )
return -1;
}
/* allocate a new string */
if( len < 0 )
......@@ -145,6 +168,47 @@ int msi_addstring( string_table *st, UINT string_no, CHAR *data, UINT len, UINT
return n;
}
int msi_addstringW( string_table *st, UINT n, const WCHAR *data, UINT len, UINT refcount )
{
int sz;
/* TRACE("[%2d] = %s\n", string_no, debugstr_an(data,len) ); */
if( !data[0] )
return 0;
if( n > 0 )
{
if( st->strings[n].refcount )
return -1;
}
else
{
if( ERROR_SUCCESS == msi_string2id( st, data, &n ) )
{
st->strings[n].refcount++;
return n;
}
n = st_find_free_entry( st );
if( n < 0 )
return -1;
}
/* allocate a new string */
sz = WideCharToMultiByte( CP_UTF8, 0, data, len, NULL, 0, NULL, NULL );
st->strings[n].str = HeapAlloc( GetProcessHeap(), 0, sz + 1 );
if( !st->strings[n].str )
return -1;
WideCharToMultiByte( CP_UTF8, 0, data, len,
st->strings[n].str, sz, NULL, NULL );
st->strings[n].str[sz] = 0;
st->strings[n].refcount = 1;
st->strings[n].hash = msistring_makehash( st->strings[n].str );
st_mark_entry_used( st, n );
return n;
}
UINT msi_id2stringW( string_table *st, UINT string_no, LPWSTR buffer, UINT *sz )
{
UINT len;
......@@ -154,7 +218,7 @@ UINT msi_id2stringW( string_table *st, UINT string_no, LPWSTR buffer, UINT *sz )
if( string_no >= st->count )
return ERROR_FUNCTION_FAILED;
if( !st->strings[string_no].refcount )
if( string_no && !st->strings[string_no].refcount )
return ERROR_FUNCTION_FAILED;
str = st->strings[string_no].str;
......@@ -182,7 +246,7 @@ UINT msi_id2stringA( string_table *st, UINT string_no, LPSTR buffer, UINT *sz )
if( string_no >= st->count )
return ERROR_FUNCTION_FAILED;
if( !st->strings[string_no].refcount )
if( string_no && !st->strings[string_no].refcount )
return ERROR_FUNCTION_FAILED;
str = st->strings[string_no].str;
......@@ -202,25 +266,13 @@ UINT msi_id2stringA( string_table *st, UINT string_no, LPSTR buffer, UINT *sz )
return ERROR_SUCCESS;
}
UINT msi_string2id( string_table *st, LPCWSTR buffer, UINT *id )
UINT msi_string2idA( string_table *st, LPCSTR str, UINT *id )
{
DWORD sz;
UINT i, r = ERROR_INVALID_PARAMETER;
LPSTR str;
int hash;
TRACE("Finding string %s in string table\n", debugstr_w(buffer) );
sz = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
if( sz <= 0 )
return r;
str = HeapAlloc( GetProcessHeap(), 0, sz );
if( !str )
return ERROR_NOT_ENOUGH_MEMORY;
WideCharToMultiByte( CP_ACP, 0, buffer, -1, str, sz, NULL, NULL );
UINT i, r = ERROR_INVALID_PARAMETER;
hash = msistring_makehash( str );
for( i=0; i<st->count; i++)
for( i=0; i<st->count; i++ )
{
if( ( st->strings[i].hash == hash ) &&
!strcmp( st->strings[i].str, str ) )
......@@ -231,12 +283,33 @@ UINT msi_string2id( string_table *st, LPCWSTR buffer, UINT *id )
}
}
return r;
}
UINT msi_string2id( string_table *st, LPCWSTR buffer, UINT *id )
{
DWORD sz;
UINT r = ERROR_INVALID_PARAMETER;
LPSTR str;
TRACE("Finding string %s in string table\n", debugstr_w(buffer) );
sz = WideCharToMultiByte( CP_UTF8, 0, buffer, -1, NULL, 0, NULL, NULL );
if( sz <= 0 )
return r;
str = HeapAlloc( GetProcessHeap(), 0, sz );
if( !str )
return ERROR_NOT_ENOUGH_MEMORY;
WideCharToMultiByte( CP_UTF8, 0, buffer, -1, str, sz, NULL, NULL );
r = msi_string2idA( st, str, id );
if( str )
HeapFree( GetProcessHeap(), 0, str );
return r;
}
UINT msi_string_count( string_table *st )
{
return st->count;
......
......@@ -106,6 +106,7 @@ static const Keyword aKeywordTable[] = {
{ "LEFT", TK_JOIN_KW },
{ "LIKE", TK_LIKE },
{ "LIMIT", TK_LIMIT },
{ "LOCALIZABLE", TK_LOCALIZABLE },
{ "LONG", TK_LONG },
{ "LONGCHAR", TK_LONGCHAR },
{ "MATCH", TK_MATCH },
......
......@@ -268,6 +268,8 @@ static UINT WHERE_delete( struct tagMSIVIEW *view )
MSIVIEWOPS where_ops =
{
WHERE_fetch_int,
NULL,
NULL,
WHERE_execute,
WHERE_close,
WHERE_get_dimensions,
......
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