Commit d1a55eb3 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

Get rid of some redundant parser types.

parent 309ae278
...@@ -44,7 +44,7 @@ typedef struct tagMSICREATEVIEW ...@@ -44,7 +44,7 @@ typedef struct tagMSICREATEVIEW
MSIDATABASE *db; MSIDATABASE *db;
LPWSTR name; LPWSTR name;
BOOL bIsTemp; BOOL bIsTemp;
create_col_info *col_info; column_info *col_info;
} MSICREATEVIEW; } MSICREATEVIEW;
static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val ) static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
...@@ -59,7 +59,7 @@ static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT ...@@ -59,7 +59,7 @@ static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT
static UINT CREATE_execute( struct tagMSIVIEW *view, MSIRECORD *record ) static UINT CREATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
{ {
MSICREATEVIEW *cv = (MSICREATEVIEW*)view; MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
create_col_info *col; column_info *col;
UINT r, nField, row, table_val, column_val; UINT r, nField, row, table_val, column_val;
static const WCHAR szTables[] = { '_','T','a','b','l','e','s',0 }; static const WCHAR szTables[] = { '_','T','a','b','l','e','s',0 };
static const WCHAR szColumns[] = { '_','C','o','l','u','m','n','s',0 }; static const WCHAR szColumns[] = { '_','C','o','l','u','m','n','s',0 };
...@@ -122,8 +122,8 @@ static UINT CREATE_execute( struct tagMSIVIEW *view, MSIRECORD *record ) ...@@ -122,8 +122,8 @@ static UINT CREATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
if( r ) if( r )
goto err; goto err;
column_val = msi_addstringW( cv->db->strings, 0, col->colname, -1, 1 ); column_val = msi_addstringW( cv->db->strings, 0, col->column, -1, 1 );
TRACE("New string %s -> %d\n", debugstr_w( col->colname ), column_val ); TRACE("New string %s -> %d\n", debugstr_w( col->column ), column_val );
if( column_val < 0 ) if( column_val < 0 )
break; break;
...@@ -226,7 +226,7 @@ MSIVIEWOPS create_ops = ...@@ -226,7 +226,7 @@ MSIVIEWOPS create_ops =
}; };
UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table, UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
create_col_info *col_info, BOOL temp ) column_info *col_info, BOOL temp )
{ {
MSICREATEVIEW *cv = NULL; MSICREATEVIEW *cv = NULL;
......
...@@ -255,7 +255,7 @@ MSIVIEWOPS insert_ops = ...@@ -255,7 +255,7 @@ MSIVIEWOPS insert_ops =
}; };
UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table, UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
string_list *columns, value_list *values, BOOL temp ) column_info *columns, value_list *values, BOOL temp )
{ {
MSIINSERTVIEW *iv = NULL; MSIINSERTVIEW *iv = NULL;
UINT r; UINT r;
......
...@@ -302,11 +302,11 @@ static UINT ORDER_AddColumn( MSIORDERVIEW *ov, LPCWSTR name ) ...@@ -302,11 +302,11 @@ static UINT ORDER_AddColumn( MSIORDERVIEW *ov, LPCWSTR name )
} }
UINT ORDER_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table, UINT ORDER_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
string_list *columns ) column_info *columns )
{ {
MSIORDERVIEW *ov = NULL; MSIORDERVIEW *ov = NULL;
UINT count = 0, r; UINT count = 0, r;
string_list *x; column_info *x;
TRACE("%p\n", ov ); TRACE("%p\n", ov );
...@@ -332,7 +332,7 @@ UINT ORDER_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table, ...@@ -332,7 +332,7 @@ UINT ORDER_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
*view = (MSIVIEW*) ov; *view = (MSIVIEW*) ov;
for( x = columns; x ; x = x->next ) for( x = columns; x ; x = x->next )
ORDER_AddColumn( ov, x->string ); ORDER_AddColumn( ov, x->column );
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
...@@ -59,11 +59,14 @@ struct sql_str { ...@@ -59,11 +59,14 @@ struct sql_str {
INT len; INT len;
}; };
typedef struct _string_list typedef struct _column_info
{ {
LPWSTR string; LPCWSTR table;
struct _string_list *next; LPCWSTR column;
} string_list; UINT type;
struct expr *val;
struct _column_info *next;
} column_info;
struct complex_expr struct complex_expr
{ {
...@@ -80,56 +83,42 @@ struct expr ...@@ -80,56 +83,42 @@ struct expr
struct complex_expr expr; struct complex_expr expr;
INT ival; INT ival;
UINT uval; UINT uval;
LPWSTR sval; LPCWSTR sval;
LPWSTR column; LPCWSTR column;
UINT col_number; UINT col_number;
} u; } u;
}; };
typedef struct _create_col_info
{
LPWSTR colname;
UINT type;
struct _create_col_info *next;
} create_col_info;
typedef struct _value_list typedef struct _value_list
{ {
struct expr *val; struct expr *val;
struct _value_list *next; struct _value_list *next;
} value_list; } value_list;
typedef struct _column_assignment
{
string_list *col_list;
value_list *val_list;
} column_assignment;
UINT MSI_ParseSQL( MSIDATABASE *db, LPCWSTR command, MSIVIEW **phview, UINT MSI_ParseSQL( MSIDATABASE *db, LPCWSTR command, MSIVIEW **phview,
struct list *mem ); struct list *mem );
UINT TABLE_CreateView( MSIDATABASE *db, LPCWSTR name, MSIVIEW **view ); UINT TABLE_CreateView( MSIDATABASE *db, LPCWSTR name, MSIVIEW **view );
UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table, UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
string_list *columns ); column_info *columns );
UINT DISTINCT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table ); UINT DISTINCT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table );
UINT ORDER_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table, UINT ORDER_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
string_list *columns ); column_info *columns );
UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table, UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
struct expr *cond ); struct expr *cond );
UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table, UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
create_col_info *col_info, BOOL temp ); column_info *col_info, BOOL temp );
UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table, UINT INSERT_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
string_list *columns, value_list *values, BOOL temp ); column_info *columns, value_list *values, BOOL temp );
UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **, LPWSTR table, UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **, LPWSTR table,
column_assignment *list, struct expr *expr ); column_info *list, struct expr *expr );
UINT DELETE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table ); UINT DELETE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table );
......
...@@ -210,7 +210,7 @@ MSIVIEWOPS select_ops = ...@@ -210,7 +210,7 @@ MSIVIEWOPS select_ops =
SELECT_delete SELECT_delete
}; };
static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPWSTR name ) static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPCWSTR name )
{ {
UINT r, n=0; UINT r, n=0;
MSIVIEW *table; MSIVIEW *table;
...@@ -245,7 +245,7 @@ static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPWSTR name ) ...@@ -245,7 +245,7 @@ static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPWSTR name )
} }
UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table, UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
string_list *columns ) column_info *columns )
{ {
MSISELECTVIEW *sv = NULL; MSISELECTVIEW *sv = NULL;
UINT count = 0, r; UINT count = 0, r;
...@@ -273,7 +273,7 @@ UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table, ...@@ -273,7 +273,7 @@ UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
while( columns ) while( columns )
{ {
r = SELECT_AddColumn( sv, columns->string ); r = SELECT_AddColumn( sv, columns->column );
if( r ) if( r )
break; break;
columns = columns->next; columns = columns->next;
......
...@@ -55,11 +55,12 @@ static INT SQL_getint( void *info ); ...@@ -55,11 +55,12 @@ static INT SQL_getint( void *info );
static int SQL_lex( void *SQL_lval, SQL_input *info ); static int SQL_lex( void *SQL_lval, SQL_input *info );
static void *parser_alloc( void *info, unsigned int sz ); static void *parser_alloc( void *info, unsigned int sz );
static column_info *parser_alloc_column( void *info, LPCWSTR table, LPCWSTR column );
static BOOL SQL_MarkPrimaryKeys( create_col_info *cols, string_list *keys); static BOOL SQL_MarkPrimaryKeys( column_info *cols, column_info *keys);
static struct expr * EXPR_complex( void *info, struct expr *l, UINT op, struct expr *r ); static struct expr * EXPR_complex( void *info, struct expr *l, UINT op, struct expr *r );
static struct expr * EXPR_column( void *info, LPWSTR column ); static struct expr * EXPR_column( void *info, column_info *column );
static struct expr * EXPR_ival( void *info, struct sql_str *, int sign ); static struct expr * EXPR_ival( void *info, struct sql_str *, int sign );
static struct expr * EXPR_sval( void *info, struct sql_str * ); static struct expr * EXPR_sval( void *info, struct sql_str * );
static struct expr * EXPR_wildcard( void *info ); static struct expr * EXPR_wildcard( void *info );
...@@ -72,13 +73,11 @@ static struct expr * EXPR_wildcard( void *info ); ...@@ -72,13 +73,11 @@ static struct expr * EXPR_wildcard( void *info );
{ {
struct sql_str str; struct sql_str str;
LPWSTR string; LPWSTR string;
string_list *column_list; column_info *column_list;
value_list *val_list; value_list *val_list;
MSIVIEW *query; MSIVIEW *query;
struct expr *expr; struct expr *expr;
USHORT column_type; USHORT column_type;
create_col_info *column_info;
column_assignment update_col_info;
} }
%token TK_ABORT TK_AFTER TK_AGG_FUNCTION TK_ALL TK_AND TK_AS TK_ASC %token TK_ABORT TK_AFTER TK_AGG_FUNCTION TK_ALL TK_AND TK_AS TK_ASC
...@@ -125,15 +124,14 @@ static struct expr * EXPR_wildcard( void *info ); ...@@ -125,15 +124,14 @@ static struct expr * EXPR_wildcard( void *info );
%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION %nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
COLUMN AGG_FUNCTION. COLUMN AGG_FUNCTION.
%type <string> column table id %type <string> table id
%type <column_list> selcollist %type <column_list> selcollist column column_and_type column_def table_def
%type <query> query from fromtable unorderedsel selectfrom %type <column_list> column_assignment update_assign_list
%type <query> query from fromtable selectfrom unorderedsel
%type <query> oneupdate onedelete oneselect onequery onecreate oneinsert %type <query> oneupdate onedelete oneselect onequery onecreate oneinsert
%type <expr> expr val column_val const_val %type <expr> expr val column_val const_val
%type <column_type> column_type data_type data_type_l data_count %type <column_type> column_type data_type data_type_l data_count
%type <column_info> column_def table_def
%type <val_list> constlist %type <val_list> constlist
%type <update_col_info> column_assignment update_assign_list
%% %%
...@@ -210,7 +208,7 @@ oneupdate: ...@@ -210,7 +208,7 @@ oneupdate:
SQL_input* sql = (SQL_input*) info; SQL_input* sql = (SQL_input*) info;
MSIVIEW *update = NULL; MSIVIEW *update = NULL;
UPDATE_CreateView( sql->db, &update, $2, &$4, $6 ); UPDATE_CreateView( sql->db, &update, $2, $4, $6 );
if( !update ) if( !update )
YYABORT; YYABORT;
$$ = update; $$ = update;
...@@ -241,33 +239,27 @@ table_def: ...@@ -241,33 +239,27 @@ table_def:
; ;
column_def: column_def:
column_def TK_COMMA column column_type column_def TK_COMMA column_and_type
{ {
create_col_info *ci; column_info *ci;
for( ci = $1; ci->next; ci = ci->next ) for( ci = $1; ci->next; ci = ci->next )
; ;
ci->next = HeapAlloc( GetProcessHeap(), 0, sizeof *$$ ); ci->next = $3;
if( !ci->next )
{
/* FIXME: free $1 */
YYABORT;
}
ci->next->colname = $3;
ci->next->type = $4;
ci->next->next = NULL;
$$ = $1; $$ = $1;
} }
| column column_type | column_and_type
{ {
$$ = HeapAlloc( GetProcessHeap(), 0, sizeof *$$ ); $$ = $1;
if( ! $$ ) }
YYABORT; ;
$$->colname = $1;
column_and_type:
column column_type
{
$$ = $1;
$$->type = $2; $$->type = $2;
$$->next = NULL;
} }
; ;
...@@ -386,30 +378,9 @@ selectfrom: ...@@ -386,30 +378,9 @@ selectfrom:
selcollist: selcollist:
column column
{
string_list *list;
list = HeapAlloc( GetProcessHeap(), 0, sizeof *list );
if( !list )
YYABORT;
list->string = $1;
list->next = NULL;
$$ = list;
TRACE("Collist %s\n",debugstr_w($$->string));
}
| column TK_COMMA selcollist | column TK_COMMA selcollist
{ {
string_list *list; $1->next = $3;
list = HeapAlloc( GetProcessHeap(), 0, sizeof *list );
if( !list )
YYABORT;
list->string = $1;
list->next = $3;
$$ = list;
TRACE("From table: %s\n",debugstr_w($$->string));
} }
| TK_STAR | TK_STAR
{ {
...@@ -553,25 +524,16 @@ update_assign_list: ...@@ -553,25 +524,16 @@ update_assign_list:
column_assignment column_assignment
| column_assignment TK_COMMA update_assign_list | column_assignment TK_COMMA update_assign_list
{ {
$1.col_list->next = $3.col_list;
$1.val_list->next = $3.val_list;
$$ = $1; $$ = $1;
$$->next = $3;
} }
; ;
column_assignment: column_assignment:
column TK_EQ const_val column TK_EQ const_val
{ {
$$.col_list = HeapAlloc( GetProcessHeap(), 0, sizeof *$$.col_list ); $$ = $1;
if( !$$.col_list ) $$->val = $3;
YYABORT;
$$.col_list->string = $1;
$$.col_list->next = NULL;
$$.val_list = HeapAlloc( GetProcessHeap(), 0, sizeof *$$.val_list );
if( !$$.val_list )
YYABORT;
$$.val_list->val = $3;
$$.val_list->next = 0;
} }
; ;
...@@ -614,11 +576,15 @@ column_val: ...@@ -614,11 +576,15 @@ column_val:
column: column:
table TK_DOT id table TK_DOT id
{ {
$$ = $3; /* FIXME */ $$ = parser_alloc_column( info, $1, $3 );
if( !$$ )
YYABORT;
} }
| id | id
{ {
$$ = $1; $$ = parser_alloc_column( info, NULL, $1 );
if( !$$ )
YYABORT;
} }
; ;
...@@ -650,6 +616,23 @@ static void *parser_alloc( void *info, unsigned int sz ) ...@@ -650,6 +616,23 @@ static void *parser_alloc( void *info, unsigned int sz )
return &mem[1]; return &mem[1];
} }
static column_info *parser_alloc_column( void *info, LPCWSTR table, LPCWSTR column )
{
column_info *col;
col = parser_alloc( info, sizeof (*col) );
if( col )
{
col->table = table;
col->column = column;
col->val = NULL;
col->type = 0;
col->next = NULL;
}
return col;
}
int SQL_lex( void *SQL_lval, SQL_input *sql ) int SQL_lex( void *SQL_lval, SQL_input *sql )
{ {
int token; int token;
...@@ -733,13 +716,13 @@ static struct expr * EXPR_complex( void *info, struct expr *l, UINT op, struct e ...@@ -733,13 +716,13 @@ static struct expr * EXPR_complex( void *info, struct expr *l, UINT op, struct e
return e; return e;
} }
static struct expr * EXPR_column( void *info, LPWSTR column ) static struct expr * EXPR_column( void *info, column_info *column )
{ {
struct expr *e = parser_alloc( info, sizeof *e ); struct expr *e = parser_alloc( info, sizeof *e );
if( e ) if( e )
{ {
e->type = EXPR_COLUMN; e->type = EXPR_COLUMN;
e->u.sval = column; e->u.sval = column->column;
} }
return e; return e;
} }
...@@ -766,19 +749,20 @@ static struct expr * EXPR_sval( void *info, struct sql_str *str ) ...@@ -766,19 +749,20 @@ static struct expr * EXPR_sval( void *info, struct sql_str *str )
return e; return e;
} }
static BOOL SQL_MarkPrimaryKeys( create_col_info *cols, string_list *keys) static BOOL SQL_MarkPrimaryKeys( column_info *cols,
column_info *keys )
{ {
string_list *k; column_info *k;
BOOL found = TRUE; BOOL found = TRUE;
for( k = keys; k && found; k = k->next ) for( k = keys; k && found; k = k->next )
{ {
create_col_info *c; column_info *c;
found = FALSE; found = FALSE;
for( c = cols; c && !found; c = c->next ) for( c = cols; c && !found; c = c->next )
{ {
if( lstrcmpW( k->string, c->colname ) ) if( lstrcmpW( k->column, c->column ) )
continue; continue;
c->type |= MSITYPE_KEY; c->type |= MSITYPE_KEY;
found = TRUE; found = TRUE;
......
...@@ -43,7 +43,7 @@ typedef struct tagMSIUPDATEVIEW ...@@ -43,7 +43,7 @@ typedef struct tagMSIUPDATEVIEW
MSIVIEW view; MSIVIEW view;
MSIDATABASE *db; MSIDATABASE *db;
MSIVIEW *wv; MSIVIEW *wv;
value_list *vals; column_info *vals;
} MSIUPDATEVIEW; } MSIUPDATEVIEW;
static UINT UPDATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val ) static UINT UPDATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
...@@ -193,7 +193,7 @@ static MSIVIEWOPS update_ops = ...@@ -193,7 +193,7 @@ static MSIVIEWOPS update_ops =
}; };
UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table, UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
column_assignment *list, struct expr *expr ) column_info *columns, struct expr *expr )
{ {
MSIUPDATEVIEW *uv = NULL; MSIUPDATEVIEW *uv = NULL;
UINT r; UINT r;
...@@ -215,7 +215,7 @@ UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table, ...@@ -215,7 +215,7 @@ UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
} }
/* then select the columns we want */ /* then select the columns we want */
r = SELECT_CreateView( db, &sv, wv, list->col_list ); r = SELECT_CreateView( db, &sv, wv, columns );
if( r != ERROR_SUCCESS ) if( r != ERROR_SUCCESS )
{ {
if( tv ) if( tv )
...@@ -231,7 +231,7 @@ UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table, ...@@ -231,7 +231,7 @@ UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
uv->view.ops = &update_ops; uv->view.ops = &update_ops;
msiobj_addref( &db->hdr ); msiobj_addref( &db->hdr );
uv->db = db; uv->db = db;
uv->vals = list->val_list; uv->vals = columns;
uv->wv = sv; uv->wv = sv;
*view = (MSIVIEW*) uv; *view = (MSIVIEW*) uv;
......
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