Create the WHERE part of a query in one function call.
This commit is contained in:
parent
ed7c4bc84c
commit
f6492dc5ca
|
@ -110,8 +110,8 @@ 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 );
|
||||||
UINT ORDER_AddColumn( MSIVIEW *group, LPWSTR name );
|
UINT ORDER_AddColumn( MSIVIEW *group, LPWSTR name );
|
||||||
|
|
||||||
UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table );
|
UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
|
||||||
UINT WHERE_AddCondition( MSIVIEW *view, struct expr *condition );
|
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 );
|
create_col_info *col_info, BOOL temp );
|
||||||
|
|
|
@ -215,40 +215,37 @@ column_def:
|
||||||
;
|
;
|
||||||
|
|
||||||
ci->next = HeapAlloc( GetProcessHeap(), 0, sizeof *$$ );
|
ci->next = HeapAlloc( GetProcessHeap(), 0, sizeof *$$ );
|
||||||
if( ci->next )
|
if( !ci->next )
|
||||||
{
|
{
|
||||||
ci->next->colname = $3;
|
/* FIXME: free $1 */
|
||||||
ci->next->type = $4;
|
YYABORT;
|
||||||
ci->next->next = NULL;
|
|
||||||
}
|
|
||||||
else if( $1 )
|
|
||||||
{
|
|
||||||
HeapFree( GetProcessHeap(), 0, $1 );
|
|
||||||
$1 = NULL;
|
|
||||||
}
|
}
|
||||||
|
ci->next->colname = $3;
|
||||||
|
ci->next->type = $4;
|
||||||
|
ci->next->next = NULL;
|
||||||
|
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
| column column_type
|
| column column_type
|
||||||
{
|
{
|
||||||
$$ = HeapAlloc( GetProcessHeap(), 0, sizeof *$$ );
|
$$ = HeapAlloc( GetProcessHeap(), 0, sizeof *$$ );
|
||||||
if( $$ )
|
if( ! $$ )
|
||||||
{
|
YYABORT;
|
||||||
$$->colname = $1;
|
$$->colname = $1;
|
||||||
$$->type = $2;
|
$$->type = $2;
|
||||||
$$->next = NULL;
|
$$->next = NULL;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
column_type:
|
column_type:
|
||||||
data_type_l
|
data_type_l
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = $1 | MSITYPE_VALID;
|
||||||
}
|
}
|
||||||
| data_type_l TK_LOCALIZABLE
|
| data_type_l TK_LOCALIZABLE
|
||||||
{
|
{
|
||||||
FIXME("LOCALIZABLE ignored\n");
|
FIXME("LOCALIZABLE ignored\n");
|
||||||
$$ = $1;
|
$$ = $1 | MSITYPE_VALID;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -270,7 +267,7 @@ data_type:
|
||||||
}
|
}
|
||||||
| TK_CHAR TK_LP data_count TK_RP
|
| TK_CHAR TK_LP data_count TK_RP
|
||||||
{
|
{
|
||||||
$$ = MSITYPE_STRING | 0x500 | $3;
|
$$ = MSITYPE_STRING | 0x400 | $3;
|
||||||
}
|
}
|
||||||
| TK_LONGCHAR
|
| TK_LONGCHAR
|
||||||
{
|
{
|
||||||
|
@ -397,10 +394,7 @@ from:
|
||||||
r = TABLE_CreateView( sql->db, $2, &view );
|
r = TABLE_CreateView( sql->db, $2, &view );
|
||||||
if( r != ERROR_SUCCESS )
|
if( r != ERROR_SUCCESS )
|
||||||
YYABORT;
|
YYABORT;
|
||||||
r = WHERE_CreateView( sql->db, &view, view );
|
r = WHERE_CreateView( sql->db, &view, view, $4 );
|
||||||
if( r != ERROR_SUCCESS )
|
|
||||||
YYABORT;
|
|
||||||
r = WHERE_AddCondition( view, $4 );
|
|
||||||
if( r != ERROR_SUCCESS )
|
if( r != ERROR_SUCCESS )
|
||||||
YYABORT;
|
YYABORT;
|
||||||
$$ = view;
|
$$ = view;
|
||||||
|
|
|
@ -321,36 +321,6 @@ MSIVIEWOPS where_ops =
|
||||||
WHERE_delete
|
WHERE_delete
|
||||||
};
|
};
|
||||||
|
|
||||||
UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table )
|
|
||||||
{
|
|
||||||
MSIWHEREVIEW *wv = NULL;
|
|
||||||
UINT count = 0, r;
|
|
||||||
|
|
||||||
TRACE("%p\n", wv );
|
|
||||||
|
|
||||||
r = table->ops->get_dimensions( table, NULL, &count );
|
|
||||||
if( r != ERROR_SUCCESS )
|
|
||||||
{
|
|
||||||
ERR("can't get table dimensions\n");
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
wv = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof *wv );
|
|
||||||
if( !wv )
|
|
||||||
return ERROR_FUNCTION_FAILED;
|
|
||||||
|
|
||||||
/* fill the structure */
|
|
||||||
wv->view.ops = &where_ops;
|
|
||||||
wv->db = db;
|
|
||||||
wv->table = table;
|
|
||||||
wv->row_count = 0;
|
|
||||||
wv->reorder = NULL;
|
|
||||||
wv->cond = NULL;
|
|
||||||
*view = (MSIVIEW*) wv;
|
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static UINT WHERE_VerifyCondition( MSIDATABASE *db, MSIVIEW *table, struct expr *cond,
|
static UINT WHERE_VerifyCondition( MSIDATABASE *db, MSIVIEW *table, struct expr *cond,
|
||||||
UINT *valid )
|
UINT *valid )
|
||||||
{
|
{
|
||||||
|
@ -423,33 +393,42 @@ static UINT WHERE_VerifyCondition( MSIDATABASE *db, MSIVIEW *table, struct expr
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT WHERE_AddCondition( MSIVIEW *view, struct expr *cond )
|
UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
|
||||||
|
struct expr *cond )
|
||||||
{
|
{
|
||||||
MSIWHEREVIEW *wv = (MSIWHEREVIEW *) view;
|
MSIWHEREVIEW *wv = NULL;
|
||||||
UINT r, valid = 0;
|
UINT count = 0, r, valid = 0;
|
||||||
|
|
||||||
if( wv->view.ops != &where_ops )
|
TRACE("%p\n", wv );
|
||||||
return ERROR_FUNCTION_FAILED;
|
|
||||||
if( !wv->table )
|
|
||||||
return ERROR_INVALID_PARAMETER;
|
|
||||||
|
|
||||||
if( !cond )
|
|
||||||
return ERROR_SUCCESS;
|
|
||||||
|
|
||||||
TRACE("Adding condition\n");
|
r = table->ops->get_dimensions( table, NULL, &count );
|
||||||
|
|
||||||
r = WHERE_VerifyCondition( wv->db, wv->table, cond, &valid );
|
|
||||||
if( r != ERROR_SUCCESS )
|
if( r != ERROR_SUCCESS )
|
||||||
ERR("condition evaluation failed\n");
|
|
||||||
|
|
||||||
TRACE("condition is %s\n", valid ? "valid" : "invalid" );
|
|
||||||
if( !valid )
|
|
||||||
{
|
{
|
||||||
delete_expr( cond );
|
ERR("can't get table dimensions\n");
|
||||||
return ERROR_FUNCTION_FAILED;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( cond )
|
||||||
|
{
|
||||||
|
r = WHERE_VerifyCondition( db, table, cond, &valid );
|
||||||
|
if( r != ERROR_SUCCESS )
|
||||||
|
return r;
|
||||||
|
if( !valid )
|
||||||
|
return ERROR_FUNCTION_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
wv = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof *wv );
|
||||||
|
if( !wv )
|
||||||
|
return ERROR_FUNCTION_FAILED;
|
||||||
|
|
||||||
|
/* fill the structure */
|
||||||
|
wv->view.ops = &where_ops;
|
||||||
|
wv->db = db;
|
||||||
|
wv->table = table;
|
||||||
|
wv->row_count = 0;
|
||||||
|
wv->reorder = NULL;
|
||||||
wv->cond = cond;
|
wv->cond = cond;
|
||||||
|
*view = (MSIVIEW*) wv;
|
||||||
|
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue