msi: Keep track of the current view in the sql parser.

This allows us to free said view in the case of a syntax error. This
also allows us to get rid of a few places where we tried to clean up
the view ourselves in the parsing code.
This commit is contained in:
James Hawkins 2009-12-15 18:18:31 -08:00 committed by Alexandre Julliard
parent 393c5af205
commit 1692e1fe67
1 changed files with 52 additions and 31 deletions

View File

@ -47,7 +47,10 @@ typedef struct tag_SQL_input
LPCWSTR command; LPCWSTR command;
DWORD n, len; DWORD n, len;
UINT r; UINT r;
MSIVIEW **view; /* view structure for the resulting query */ MSIVIEW **view; /* View structure for the resulting query. This value
* tracks the view currently being created so we can free
* this view on syntax error.
*/
struct list *mem; struct list *mem;
} SQL_input; } SQL_input;
@ -68,6 +71,10 @@ static struct expr * EXPR_ival( void *info, int val );
static struct expr * EXPR_sval( void *info, const struct sql_str *str ); static struct expr * EXPR_sval( void *info, const struct sql_str *str );
static struct expr * EXPR_wildcard( void *info ); static struct expr * EXPR_wildcard( void *info );
#define PARSER_BUBBLE_UP_VIEW( sql, result, current_view ) \
*sql->view = current_view; \
result = current_view
%} %}
%pure-parser %pure-parser
@ -149,7 +156,8 @@ oneinsert:
INSERT_CreateView( sql->db, &insert, $3, $5, $9, FALSE ); INSERT_CreateView( sql->db, &insert, $3, $5, $9, FALSE );
if( !insert ) if( !insert )
YYABORT; YYABORT;
$$ = insert;
PARSER_BUBBLE_UP_VIEW( sql, $$, insert );
} }
| TK_INSERT TK_INTO table TK_LP selcollist TK_RP TK_VALUES TK_LP constlist TK_RP TK_TEMPORARY | TK_INSERT TK_INTO table TK_LP selcollist TK_RP TK_VALUES TK_LP constlist TK_RP TK_TEMPORARY
{ {
@ -159,7 +167,8 @@ oneinsert:
INSERT_CreateView( sql->db, &insert, $3, $5, $9, TRUE ); INSERT_CreateView( sql->db, &insert, $3, $5, $9, TRUE );
if( !insert ) if( !insert )
YYABORT; YYABORT;
$$ = insert;
PARSER_BUBBLE_UP_VIEW( sql, $$, insert );
} }
; ;
@ -178,7 +187,8 @@ onecreate:
sql->r = r; sql->r = r;
YYABORT; YYABORT;
} }
$$ = create;
PARSER_BUBBLE_UP_VIEW( sql, $$, create );
} }
| TK_CREATE TK_TABLE table TK_LP table_def TK_RP TK_HOLD | TK_CREATE TK_TABLE table TK_LP table_def TK_RP TK_HOLD
{ {
@ -190,7 +200,8 @@ onecreate:
CREATE_CreateView( sql->db, &create, $3, $5, TRUE ); CREATE_CreateView( sql->db, &create, $3, $5, TRUE );
if( !create ) if( !create )
YYABORT; YYABORT;
$$ = create;
PARSER_BUBBLE_UP_VIEW( sql, $$, create );
} }
; ;
@ -203,7 +214,8 @@ oneupdate:
UPDATE_CreateView( sql->db, &update, $2, $4, $6 ); UPDATE_CreateView( sql->db, &update, $2, $4, $6 );
if( !update ) if( !update )
YYABORT; YYABORT;
$$ = update;
PARSER_BUBBLE_UP_VIEW( sql, $$, update );
} }
| TK_UPDATE table TK_SET update_assign_list | TK_UPDATE table TK_SET update_assign_list
{ {
@ -213,7 +225,8 @@ oneupdate:
UPDATE_CreateView( sql->db, &update, $2, $4, NULL ); UPDATE_CreateView( sql->db, &update, $2, $4, NULL );
if( !update ) if( !update )
YYABORT; YYABORT;
$$ = update;
PARSER_BUBBLE_UP_VIEW( sql, $$, update );
} }
; ;
@ -226,7 +239,8 @@ onedelete:
DELETE_CreateView( sql->db, &delete, $2 ); DELETE_CreateView( sql->db, &delete, $2 );
if( !delete ) if( !delete )
YYABORT; YYABORT;
$$ = delete;
PARSER_BUBBLE_UP_VIEW( sql, $$, delete );
} }
; ;
@ -239,7 +253,8 @@ onealter:
ALTER_CreateView( sql->db, &alter, $3, NULL, $4 ); ALTER_CreateView( sql->db, &alter, $3, NULL, $4 );
if( !alter ) if( !alter )
YYABORT; YYABORT;
$$ = alter;
PARSER_BUBBLE_UP_VIEW( sql, $$, alter );
} }
| TK_ALTER TK_TABLE table TK_ADD column_and_type | TK_ALTER TK_TABLE table TK_ADD column_and_type
{ {
@ -249,7 +264,8 @@ onealter:
ALTER_CreateView( sql->db, &alter, $3, $5, 0 ); ALTER_CreateView( sql->db, &alter, $3, $5, 0 );
if (!alter) if (!alter)
YYABORT; YYABORT;
$$ = alter;
PARSER_BUBBLE_UP_VIEW( sql, $$, alter );
} }
| TK_ALTER TK_TABLE table TK_ADD column_and_type TK_HOLD | TK_ALTER TK_TABLE table TK_ADD column_and_type TK_HOLD
{ {
@ -259,7 +275,8 @@ onealter:
ALTER_CreateView( sql->db, &alter, $3, $5, 1 ); ALTER_CreateView( sql->db, &alter, $3, $5, 1 );
if (!alter) if (!alter)
YYABORT; YYABORT;
$$ = alter;
PARSER_BUBBLE_UP_VIEW( sql, $$, alter );
} }
; ;
@ -278,12 +295,14 @@ onedrop:
TK_DROP TK_TABLE table TK_DROP TK_TABLE table
{ {
SQL_input* sql = (SQL_input*) info; SQL_input* sql = (SQL_input*) info;
MSIVIEW* drop = NULL;
UINT r; UINT r;
$$ = NULL; r = DROP_CreateView( sql->db, &drop, $3 );
r = DROP_CreateView( sql->db, &$$, $3 );
if( r != ERROR_SUCCESS || !$$ ) if( r != ERROR_SUCCESS || !$$ )
YYABORT; YYABORT;
PARSER_BUBBLE_UP_VIEW( sql, $$, drop );
} }
; ;
@ -414,15 +433,14 @@ unorderedsel:
| TK_SELECT TK_DISTINCT selectfrom | TK_SELECT TK_DISTINCT selectfrom
{ {
SQL_input* sql = (SQL_input*) info; SQL_input* sql = (SQL_input*) info;
MSIVIEW* distinct = NULL;
UINT r; UINT r;
$$ = NULL; r = DISTINCT_CreateView( sql->db, &distinct, $3 );
r = DISTINCT_CreateView( sql->db, &$$, $3 );
if (r != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
{
$3->ops->delete($3);
YYABORT; YYABORT;
}
PARSER_BUBBLE_UP_VIEW( sql, $$, distinct );
} }
; ;
@ -430,17 +448,16 @@ selectfrom:
selcollist from selcollist from
{ {
SQL_input* sql = (SQL_input*) info; SQL_input* sql = (SQL_input*) info;
MSIVIEW* select = NULL;
UINT r; UINT r;
$$ = NULL;
if( $1 ) if( $1 )
{ {
r = SELECT_CreateView( sql->db, &$$, $2, $1 ); r = SELECT_CreateView( sql->db, &select, $2, $1 );
if (r != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
{
$2->ops->delete($2);
YYABORT; YYABORT;
}
PARSER_BUBBLE_UP_VIEW( sql, $$, select );
} }
else else
$$ = $2; $$ = $2;
@ -464,15 +481,14 @@ from:
| fromtable TK_WHERE expr | fromtable TK_WHERE expr
{ {
SQL_input* sql = (SQL_input*) info; SQL_input* sql = (SQL_input*) info;
MSIVIEW* where = NULL;
UINT r; UINT r;
$$ = NULL; r = WHERE_CreateView( sql->db, &where, $1, $3 );
r = WHERE_CreateView( sql->db, &$$, $1, $3 );
if( r != ERROR_SUCCESS ) if( r != ERROR_SUCCESS )
{
$1->ops->delete( $1 );
YYABORT; YYABORT;
}
PARSER_BUBBLE_UP_VIEW( sql, $$, where );
} }
; ;
@ -480,21 +496,26 @@ fromtable:
TK_FROM table TK_FROM table
{ {
SQL_input* sql = (SQL_input*) info; SQL_input* sql = (SQL_input*) info;
MSIVIEW* table = NULL;
UINT r; UINT r;
$$ = NULL; r = TABLE_CreateView( sql->db, $2, &table );
r = TABLE_CreateView( sql->db, $2, &$$ );
if( r != ERROR_SUCCESS || !$$ ) if( r != ERROR_SUCCESS || !$$ )
YYABORT; YYABORT;
PARSER_BUBBLE_UP_VIEW( sql, $$, table );
} }
| TK_FROM tablelist | TK_FROM tablelist
{ {
SQL_input* sql = (SQL_input*) info; SQL_input* sql = (SQL_input*) info;
MSIVIEW* join = NULL;
UINT r; UINT r;
r = JOIN_CreateView( sql->db, &$$, $2 ); r = JOIN_CreateView( sql->db, &join, $2 );
if( r != ERROR_SUCCESS ) if( r != ERROR_SUCCESS )
YYABORT; YYABORT;
PARSER_BUBBLE_UP_VIEW( sql, $$, join );
} }
; ;