Commit 0d1c3a14 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

Create the ORDER BY view in a single call.

parent 7b1df689
......@@ -264,40 +264,8 @@ MSIVIEWOPS order_ops =
ORDER_delete
};
UINT ORDER_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table )
static UINT ORDER_AddColumn( MSIORDERVIEW *ov, LPCWSTR name )
{
MSIORDERVIEW *ov = NULL;
UINT count = 0, r;
TRACE("%p\n", ov );
r = table->ops->get_dimensions( table, NULL, &count );
if( r != ERROR_SUCCESS )
{
ERR("can't get table dimensions\n");
return r;
}
ov = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof *ov + sizeof (UINT) * count );
if( !ov )
return ERROR_FUNCTION_FAILED;
/* fill the structure */
ov->view.ops = &order_ops;
msiobj_addref( &db->hdr );
ov->db = db;
ov->table = table;
ov->reorder = NULL;
ov->num_cols = 0;
*view = (MSIVIEW*) ov;
return ERROR_SUCCESS;
}
UINT ORDER_AddColumn( MSIVIEW *view, LPWSTR name )
{
MSIORDERVIEW *ov = (MSIORDERVIEW*)view;
UINT n, count, r;
MSIVIEW *table;
......@@ -332,3 +300,39 @@ UINT ORDER_AddColumn( MSIVIEW *view, LPWSTR name )
return ERROR_SUCCESS;
}
UINT ORDER_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
string_list *columns )
{
MSIORDERVIEW *ov = NULL;
UINT count = 0, r;
string_list *x;
TRACE("%p\n", ov );
r = table->ops->get_dimensions( table, NULL, &count );
if( r != ERROR_SUCCESS )
{
ERR("can't get table dimensions\n");
return r;
}
ov = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof *ov + sizeof (UINT) * count );
if( !ov )
return ERROR_FUNCTION_FAILED;
/* fill the structure */
ov->view.ops = &order_ops;
msiobj_addref( &db->hdr );
ov->db = db;
ov->table = table;
ov->reorder = NULL;
ov->num_cols = 0;
*view = (MSIVIEW*) ov;
for( x = columns; x ; x = x->next )
ORDER_AddColumn( ov, x->string );
return ERROR_SUCCESS;
}
......@@ -114,8 +114,8 @@ UINT SELECT_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_AddColumn( MSIVIEW *group, LPWSTR name );
UINT ORDER_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
string_list *columns );
UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
struct expr *cond );
......
......@@ -54,8 +54,6 @@ static int SQL_lex( void *SQL_lval, SQL_input *info);
static MSIVIEW *do_one_select( MSIDATABASE *db, MSIVIEW *in,
string_list *columns );
static MSIVIEW *do_order_by( MSIDATABASE *db, MSIVIEW *in,
string_list *columns );
static BOOL SQL_MarkPrimaryKeys( create_col_info *cols,
string_list *keys);
......@@ -330,12 +328,13 @@ oneselect:
{
SQL_input* sql = (SQL_input*) info;
if( !$1 )
YYABORT;
$$ = NULL;
if( $4 )
$$ = do_order_by( sql->db, $1, $4 );
ORDER_CreateView( sql->db, &$$, $1, $4 );
else
$$ = $1;
if( !$$ )
YYABORT;
}
| unorderedsel
;
......@@ -690,25 +689,6 @@ static MSIVIEW *do_one_select( MSIDATABASE *db, MSIVIEW *in,
return view;
}
static MSIVIEW *do_order_by( MSIDATABASE *db, MSIVIEW *in,
string_list *columns )
{
MSIVIEW *view = NULL;
ORDER_CreateView( db, &view, in );
if( view )
{
string_list *x = columns;
for( x = columns; x ; x = x->next )
ORDER_AddColumn( view, x->string );
}
else
ERR("Error creating select query\n");
delete_string_list( columns );
return view;
}
static struct expr * EXPR_wildcard()
{
struct expr *e = HeapAlloc( GetProcessHeap(), 0, sizeof *e );
......
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