Commit 2e6ed06f authored by James Hawkins's avatar James Hawkins Committed by Alexandre Julliard

msi: Reimplement joins to allow joining any number of tables, each of arbitrary size.

parent 4f6a93b9
......@@ -119,8 +119,7 @@ UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPCWSTR table,
UINT DELETE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table );
UINT JOIN_CreateView( MSIDATABASE *db, MSIVIEW **view,
LPCWSTR left, LPCWSTR right );
UINT JOIN_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR tables );
UINT ALTER_CreateView( MSIDATABASE *db, MSIVIEW **view, LPCWSTR name, column_info *colinfo, int hold );
......
......@@ -53,6 +53,7 @@ static LPWSTR SQL_getstring( void *info, const struct sql_str *str );
static INT SQL_getint( void *info );
static int sql_lex( void *SQL_lval, SQL_input *info );
static LPWSTR parser_add_table( LPWSTR list, LPWSTR table );
static void *parser_alloc( void *info, unsigned int sz );
static column_info *parser_alloc_column( void *info, LPCWSTR table, LPCWSTR column );
......@@ -101,7 +102,7 @@ static struct expr * EXPR_wildcard( void *info );
%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
COLUMN AGG_FUNCTION.
%type <string> table id
%type <string> table tablelist id
%type <column_list> selcollist column column_and_type column_def table_def
%type <column_list> column_assignment update_assign_list constlist
%type <query> query from fromtable selectfrom unorderedsel
......@@ -466,18 +467,32 @@ fromtable:
if( r != ERROR_SUCCESS || !$$ )
YYABORT;
}
| TK_FROM table TK_COMMA table
| TK_FROM tablelist
{
SQL_input* sql = (SQL_input*) info;
UINT r;
/* only support inner joins on two tables */
r = JOIN_CreateView( sql->db, &$$, $2, $4 );
r = JOIN_CreateView( sql->db, &$$, $2 );
msi_free( $2 );
if( r != ERROR_SUCCESS )
YYABORT;
}
;
tablelist:
table
{
$$ = strdupW($1);
}
|
table TK_COMMA tablelist
{
$$ = parser_add_table($3, $1);
if (!$$)
YYABORT;
}
;
expr:
TK_LP expr TK_RP
{
......@@ -663,6 +678,19 @@ number:
%%
static LPWSTR parser_add_table(LPWSTR list, LPWSTR table)
{
DWORD size = lstrlenW(list) + lstrlenW(table) + 2;
static const WCHAR space[] = {' ',0};
list = msi_realloc(list, size * sizeof(WCHAR));
if (!list) return NULL;
lstrcatW(list, space);
lstrcatW(list, table);
return list;
}
static void *parser_alloc( void *info, unsigned int sz )
{
SQL_input* sql = (SQL_input*) info;
......
......@@ -2890,10 +2890,7 @@ static void test_join(void)
ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
r = MsiViewExecute(hview, 0);
todo_wine
{
ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
}
ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
i = 0;
data_correct = TRUE;
......@@ -2919,10 +2916,7 @@ static void test_join(void)
}
ok( data_correct, "data returned in the wrong order\n");
todo_wine
{
ok( i == 6, "Expected 6 rows, got %d\n", i );
}
ok( i == 6, "Expected 6 rows, got %d\n", i );
ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
MsiViewClose(hview);
......@@ -3000,7 +2994,7 @@ static void test_join(void)
MsiCloseHandle(hrec);
}
todo_wine ok( data_correct, "data returned in the wrong order\n");
ok( data_correct, "data returned in the wrong order\n");
ok( i == 6, "Expected 6 rows, got %d\n", i );
ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
......@@ -3048,7 +3042,7 @@ static void test_join(void)
i++;
MsiCloseHandle(hrec);
}
todo_wine ok( data_correct, "data returned in the wrong order\n");
ok( data_correct, "data returned in the wrong order\n");
ok( i == 6, "Expected 6 rows, got %d\n", i );
ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
......@@ -3058,10 +3052,10 @@ static void test_join(void)
query = "SELECT * FROM `One`, `Two`, `Three` ";
r = MsiDatabaseOpenView(hdb, query, &hview);
todo_wine ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
r = MsiViewExecute(hview, 0);
todo_wine ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
i = 0;
data_correct = TRUE;
......@@ -3099,11 +3093,8 @@ static void test_join(void)
}
ok( data_correct, "data returned in the wrong order\n");
todo_wine
{
ok( i == 6, "Expected 6 rows, got %d\n", i );
ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
}
ok( i == 6, "Expected 6 rows, got %d\n", i );
ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
MsiViewClose(hview);
MsiCloseHandle(hview);
......
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