msi: Add tablename tracking to VIEW_find_column.
This fixes the bug where multiple columns of the same name, but
different tables are members of a join. Any attempt to refer to these
columns will resolve to the first available column with that name,
irregardless of any tablename modifier.
diff --git a/dlls/msi/alter.c b/dlls/msi/alter.c
index 0f750d0..a62b13e 100644
--- a/dlls/msi/alter.c
+++ b/dlls/msi/alter.c
@@ -183,11 +183,12 @@
}
static UINT ALTER_get_column_info( struct tagMSIVIEW *view,
- UINT n, LPWSTR *name, UINT *type, BOOL *temporary )
+ UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR *table_name)
{
MSIALTERVIEW *av = (MSIALTERVIEW*)view;
- TRACE("%p %d %p %p %p\n", av, n, name, type, temporary );
+ TRACE("%p %d %p %p %p %p\n", av, n, name, type, temporary, table_name );
return ERROR_FUNCTION_FAILED;
}
diff --git a/dlls/msi/create.c b/dlls/msi/create.c
index 63cd373..2e13d59 100644
--- a/dlls/msi/create.c
+++ b/dlls/msi/create.c
@@ -91,11 +91,12 @@
}
static UINT CREATE_get_column_info( struct tagMSIVIEW *view,
- UINT n, LPWSTR *name, UINT *type, BOOL *temporary )
+ UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR *table_name)
{
MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
- TRACE("%p %d %p %p %p\n", cv, n, name, type, temporary );
+ TRACE("%p %d %p %p %p %p\n", cv, n, name, type, temporary, table_name );
return ERROR_FUNCTION_FAILED;
}
diff --git a/dlls/msi/delete.c b/dlls/msi/delete.c
index c824d9e..210fc9e 100644
--- a/dlls/msi/delete.c
+++ b/dlls/msi/delete.c
@@ -127,17 +127,18 @@
}
static UINT DELETE_get_column_info( struct tagMSIVIEW *view,
- UINT n, LPWSTR *name, UINT *type, BOOL *temporary )
+ UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR *table_name)
{
MSIDELETEVIEW *dv = (MSIDELETEVIEW*)view;
- TRACE("%p %d %p %p %p\n", dv, n, name, type, temporary );
+ TRACE("%p %d %p %p %p %p\n", dv, n, name, type, temporary, table_name );
if( !dv->table )
return ERROR_FUNCTION_FAILED;
return dv->table->ops->get_column_info( dv->table, n, name,
- type, temporary );
+ type, temporary, table_name);
}
static UINT DELETE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
diff --git a/dlls/msi/distinct.c b/dlls/msi/distinct.c
index 1e0cc2f..06beece 100644
--- a/dlls/msi/distinct.c
+++ b/dlls/msi/distinct.c
@@ -205,17 +205,18 @@
}
static UINT DISTINCT_get_column_info( struct tagMSIVIEW *view,
- UINT n, LPWSTR *name, UINT *type, BOOL *temporary )
+ UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR *table_name)
{
MSIDISTINCTVIEW *dv = (MSIDISTINCTVIEW*)view;
- TRACE("%p %d %p %p %p\n", dv, n, name, type, temporary );
+ TRACE("%p %d %p %p %p %p\n", dv, n, name, type, temporary, table_name );
if( !dv->table )
return ERROR_FUNCTION_FAILED;
return dv->table->ops->get_column_info( dv->table, n, name,
- type, temporary );
+ type, temporary, table_name );
}
static UINT DISTINCT_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
diff --git a/dlls/msi/insert.c b/dlls/msi/insert.c
index 0a1fbe6..61807e9 100644
--- a/dlls/msi/insert.c
+++ b/dlls/msi/insert.c
@@ -114,8 +114,8 @@
for (i = 1; i <= col_count; i++)
{
- iv->sv->ops->get_column_info(iv->sv, i, &a, NULL, NULL);
- iv->table->ops->get_column_info(iv->table, i, &b, NULL, NULL);
+ iv->sv->ops->get_column_info(iv->sv, i, &a, NULL, NULL, NULL);
+ iv->table->ops->get_column_info(iv->table, i, &b, NULL, NULL, NULL);
res = lstrcmpW(a, b);
msi_free(a);
@@ -157,13 +157,14 @@
for (colidx = 1; colidx <= val_count; colidx++)
{
- r = iv->sv->ops->get_column_info(iv->sv, colidx, &a, NULL, NULL);
+ r = iv->sv->ops->get_column_info(iv->sv, colidx, &a, NULL, NULL, NULL);
if (r != ERROR_SUCCESS)
goto err;
for (i = 1; i <= col_count; i++)
{
- r = iv->table->ops->get_column_info(iv->table, i, &b, NULL, NULL);
+ r = iv->table->ops->get_column_info(iv->table, i, &b, NULL,
+ NULL, NULL);
if (r != ERROR_SUCCESS)
goto err;
@@ -200,7 +201,8 @@
for (i = 1; i <= col_count; i++)
{
- r = iv->table->ops->get_column_info(iv->table, i, NULL, &type, NULL);
+ r = iv->table->ops->get_column_info(iv->table, i, NULL, &type,
+ NULL, NULL);
if (r != ERROR_SUCCESS)
return FALSE;
@@ -291,18 +293,19 @@
}
static UINT INSERT_get_column_info( struct tagMSIVIEW *view,
- UINT n, LPWSTR *name, UINT *type, BOOL *temporary )
+ UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR *table_name)
{
MSIINSERTVIEW *iv = (MSIINSERTVIEW*)view;
MSIVIEW *sv;
- TRACE("%p %d %p %p %p\n", iv, n, name, type, temporary );
+ TRACE("%p %d %p %p %p %p\n", iv, n, name, type, temporary, table_name );
sv = iv->sv;
if( !sv )
return ERROR_FUNCTION_FAILED;
- return sv->ops->get_column_info( sv, n, name, type, temporary );
+ return sv->ops->get_column_info( sv, n, name, type, temporary, table_name );
}
static UINT INSERT_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIRECORD *rec, UINT row)
diff --git a/dlls/msi/join.c b/dlls/msi/join.c
index 35db2fe..1aeb17c 100644
--- a/dlls/msi/join.c
+++ b/dlls/msi/join.c
@@ -194,13 +194,14 @@
}
static UINT JOIN_get_column_info( struct tagMSIVIEW *view,
- UINT n, LPWSTR *name, UINT *type, BOOL *temporary )
+ UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR *table_name )
{
MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
JOINTABLE *table;
UINT cols = 0;
- TRACE("%p %d %p %p %p\n", jv, n, name, type, temporary );
+ TRACE("%p %d %p %p %p %p\n", jv, n, name, type, temporary, table_name );
if (n == 0 || n > jv->columns)
return ERROR_FUNCTION_FAILED;
@@ -209,7 +210,8 @@
{
if (n <= cols + table->columns)
return table->view->ops->get_column_info(table->view, n - cols,
- name, type, temporary);
+ name, type, temporary,
+ table_name);
cols += table->columns;
}
diff --git a/dlls/msi/msipriv.h b/dlls/msi/msipriv.h
index 9692b64..cfc3828 100644
--- a/dlls/msi/msipriv.h
+++ b/dlls/msi/msipriv.h
@@ -228,11 +228,11 @@
/*
* get_column_info - returns the name and type of a specific column
*
- * The name is HeapAlloc'ed by this function and should be freed by
- * the caller.
+ * The name and tablename is HeapAlloc'ed by this function and should be
+ * freed by the caller.
* The column information can be queried at any time.
*/
- UINT (*get_column_info)( struct tagMSIVIEW *view, UINT n, LPWSTR *name, UINT *type, BOOL *temporary );
+ UINT (*get_column_info)( struct tagMSIVIEW *view, UINT n, LPWSTR *name, UINT *type, BOOL *temporary, LPWSTR *tableName);
/*
* modify - not yet implemented properly
@@ -737,7 +737,7 @@
extern UINT MSI_ViewClose( MSIQUERY* );
extern UINT MSI_ViewGetColumnInfo(MSIQUERY *, MSICOLINFO, MSIRECORD **);
extern UINT MSI_ViewModify( MSIQUERY *, MSIMODIFY, MSIRECORD * );
-extern UINT VIEW_find_column( MSIVIEW *, LPCWSTR, UINT * );
+extern UINT VIEW_find_column( MSIVIEW *, LPCWSTR, LPCWSTR, UINT * );
extern UINT msi_view_get_row(MSIDATABASE *, MSIVIEW *, UINT, MSIRECORD **);
/* install internals */
diff --git a/dlls/msi/msiquery.c b/dlls/msi/msiquery.c
index b973382..ddbb28d 100644
--- a/dlls/msi/msiquery.c
+++ b/dlls/msi/msiquery.c
@@ -56,9 +56,10 @@
}
}
-UINT VIEW_find_column( MSIVIEW *table, LPCWSTR name, UINT *n )
+UINT VIEW_find_column( MSIVIEW *table, LPCWSTR name, LPCWSTR table_name, UINT *n )
{
LPWSTR col_name;
+ LPWSTR haystack_table_name;
UINT i, count, r;
r = table->ops->get_dimensions( table, NULL, &count );
@@ -70,11 +71,15 @@
INT x;
col_name = NULL;
- r = table->ops->get_column_info( table, i, &col_name, NULL, NULL );
+ r = table->ops->get_column_info( table, i, &col_name, NULL,
+ NULL, &haystack_table_name );
if( r != ERROR_SUCCESS )
return r;
x = lstrcmpW( name, col_name );
+ if( table_name )
+ x |= lstrcmpW( table_name, haystack_table_name );
msi_free( col_name );
+ msi_free( haystack_table_name );
if( !x )
{
*n = i;
@@ -306,7 +311,7 @@
for (i = 1; i <= col_count; i++)
{
- ret = view->ops->get_column_info(view, i, NULL, &type, NULL);
+ ret = view->ops->get_column_info(view, i, NULL, &type, NULL, NULL);
if (ret)
{
ERR("Error getting column type for %d\n", i);
@@ -553,7 +558,8 @@
for( i=0; i<count; i++ )
{
name = NULL;
- r = view->ops->get_column_info( view, i+1, &name, &type, &temporary );
+ r = view->ops->get_column_info( view, i+1, &name, &type, &temporary,
+ NULL );
if( r != ERROR_SUCCESS )
continue;
if (info == MSICOLINFO_NAMES)
diff --git a/dlls/msi/query.h b/dlls/msi/query.h
index eb11a1c..a43663d 100644
--- a/dlls/msi/query.h
+++ b/dlls/msi/query.h
@@ -68,6 +68,12 @@
struct expr *right;
};
+struct ext_column
+{
+ LPCWSTR column;
+ LPCWSTR table;
+};
+
struct expr
{
int type;
@@ -77,7 +83,7 @@
INT ival;
UINT uval;
LPCWSTR sval;
- LPCWSTR column;
+ struct ext_column column;
UINT col_number;
} u;
};
diff --git a/dlls/msi/select.c b/dlls/msi/select.c
index 8fd761e..c4b9e80 100644
--- a/dlls/msi/select.c
+++ b/dlls/msi/select.c
@@ -209,11 +209,12 @@
}
static UINT SELECT_get_column_info( struct tagMSIVIEW *view,
- UINT n, LPWSTR *name, UINT *type, BOOL *temporary )
+ UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR *table_name)
{
MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
- TRACE("%p %d %p %p %p\n", sv, n, name, type, temporary );
+ TRACE("%p %d %p %p %p %p\n", sv, n, name, type, temporary, table_name );
if( !sv->table )
return ERROR_FUNCTION_FAILED;
@@ -224,7 +225,7 @@
n = sv->cols[ n - 1 ];
return sv->table->ops->get_column_info( sv->table, n, name,
- type, temporary );
+ type, temporary, table_name );
}
static UINT msi_select_update(struct tagMSIVIEW *view, MSIRECORD *rec, UINT row)
@@ -247,7 +248,7 @@
{
col = sv->cols[i];
- r = SELECT_get_column_info(view, i + 1, &name, &type, NULL);
+ r = SELECT_get_column_info(view, i + 1, &name, &type, NULL, NULL);
msi_free(name);
if (r != ERROR_SUCCESS)
{
@@ -388,7 +389,7 @@
if( sv->num_cols >= sv->max_cols )
return ERROR_FUNCTION_FAILED;
- r = VIEW_find_column( table, name, &n );
+ r = VIEW_find_column( table, name, NULL, &n );
if( r != ERROR_SUCCESS )
return r;
diff --git a/dlls/msi/sql.y b/dlls/msi/sql.y
index 969c92c..e2484df 100644
--- a/dlls/msi/sql.y
+++ b/dlls/msi/sql.y
@@ -856,7 +856,8 @@
if( e )
{
e->type = EXPR_COLUMN;
- e->u.sval = column->column;
+ e->u.column.column = column->column;
+ e->u.column.table = column->table;
}
return e;
}
diff --git a/dlls/msi/storages.c b/dlls/msi/storages.c
index 16b323c..005bcdb 100644
--- a/dlls/msi/storages.c
+++ b/dlls/msi/storages.c
@@ -289,14 +289,16 @@
}
static UINT STORAGES_get_column_info(struct tagMSIVIEW *view, UINT n,
- LPWSTR *name, UINT *type, BOOL *temporary)
+ LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR *table_name)
{
LPCWSTR name_ptr = NULL;
static const WCHAR Name[] = {'N','a','m','e',0};
static const WCHAR Data[] = {'D','a','t','a',0};
- TRACE("(%p, %d, %p, %p, %p)\n", view, n, name, type, temporary);
+ TRACE("(%p, %d, %p, %p, %p, %p)\n", view, n, name, type, temporary,
+ table_name);
if (n == 0 || n > NUM_STORAGES_COLS)
return ERROR_INVALID_PARAMETER;
diff --git a/dlls/msi/streams.c b/dlls/msi/streams.c
index 12f707e..23ae971 100644
--- a/dlls/msi/streams.c
+++ b/dlls/msi/streams.c
@@ -255,14 +255,16 @@
}
static UINT STREAMS_get_column_info(struct tagMSIVIEW *view, UINT n,
- LPWSTR *name, UINT *type, BOOL *temporary)
+ LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR *table_name)
{
LPCWSTR name_ptr = NULL;
static const WCHAR Name[] = {'N','a','m','e',0};
static const WCHAR Data[] = {'D','a','t','a',0};
- TRACE("(%p, %d, %p, %p, %p)\n", view, n, name, type, temporary);
+ TRACE("(%p, %d, %p, %p, %p, %p)\n", view, n, name, type, temporary,
+ table_name);
if (n == 0 || n > NUM_STREAMS_COLS)
return ERROR_INVALID_PARAMETER;
diff --git a/dlls/msi/table.c b/dlls/msi/table.c
index 35f7979..33d1fce 100644
--- a/dlls/msi/table.c
+++ b/dlls/msi/table.c
@@ -1582,7 +1582,8 @@
}
static UINT TABLE_get_column_info( struct tagMSIVIEW *view,
- UINT n, LPWSTR *name, UINT *type, BOOL *temporary )
+ UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR *table_name )
{
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
@@ -1598,6 +1599,13 @@
return ERROR_FUNCTION_FAILED;
}
+ if( table_name )
+ {
+ *table_name = strdupW( tv->columns[n-1].tablename );
+ if( !*table_name )
+ return ERROR_FUNCTION_FAILED;
+ }
+
if( type )
*type = tv->columns[n-1].type;
@@ -2118,6 +2126,7 @@
static UINT order_add_column(struct tagMSIVIEW *view, MSIORDERINFO *order, LPCWSTR name)
{
UINT n, r, count;
+ MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
r = TABLE_get_dimensions(view, NULL, &count);
if (r != ERROR_SUCCESS)
@@ -2126,7 +2135,7 @@
if (order->num_cols >= count)
return ERROR_FUNCTION_FAILED;
- r = VIEW_find_column(view, name, &n);
+ r = VIEW_find_column(view, name, tv->name, &n);
if (r != ERROR_SUCCESS)
return r;
diff --git a/dlls/msi/update.c b/dlls/msi/update.c
index 56d2391..c80d5a9 100644
--- a/dlls/msi/update.c
+++ b/dlls/msi/update.c
@@ -155,18 +155,19 @@
}
static UINT UPDATE_get_column_info( struct tagMSIVIEW *view,
- UINT n, LPWSTR *name, UINT *type, BOOL *temporary )
+ UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR* table_name )
{
MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
MSIVIEW *wv;
- TRACE("%p %d %p %p %p\n", uv, n, name, type, temporary );
+ TRACE("%p %d %p %p %p %p\n", uv, n, name, type, temporary, table_name );
wv = uv->wv;
if( !wv )
return ERROR_FUNCTION_FAILED;
- return wv->ops->get_column_info( wv, n, name, type, temporary );
+ return wv->ops->get_column_info( wv, n, name, type, temporary, table_name );
}
static UINT UPDATE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
diff --git a/dlls/msi/where.c b/dlls/msi/where.c
index fc804a4..32f71b9 100644
--- a/dlls/msi/where.c
+++ b/dlls/msi/where.c
@@ -490,17 +490,18 @@
}
static UINT WHERE_get_column_info( struct tagMSIVIEW *view,
- UINT n, LPWSTR *name, UINT *type, BOOL *temporary )
+ UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
+ LPWSTR *table_name)
{
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
- TRACE("%p %d %p %p %p\n", wv, n, name, type, temporary );
+ TRACE("%p %d %p %p %p %p\n", wv, n, name, type, temporary, table_name );
if( !wv->table )
return ERROR_FUNCTION_FAILED;
return wv->table->ops->get_column_info( wv->table, n, name,
- type, temporary );
+ type, temporary, table_name );
}
static UINT WHERE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
@@ -597,11 +598,13 @@
switch( cond->type )
{
case EXPR_COLUMN:
- r = VIEW_find_column( table, cond->u.column, &val );
+ r = VIEW_find_column( table, cond->u.column.column,
+ cond->u.column.table, &val );
if( r == ERROR_SUCCESS )
{
UINT type = 0;
- r = table->ops->get_column_info( table, val, NULL, &type, NULL );
+ r = table->ops->get_column_info( table, val, NULL, &type,
+ NULL, NULL );
if( r == ERROR_SUCCESS )
{
if (type&MSITYPE_STRING)
@@ -619,7 +622,7 @@
else
{
*valid = 0;
- WARN("Couldn't find column %s\n", debugstr_w( cond->u.column ) );
+ WARN("Couldn't find column %s.%s\n", debugstr_w( cond->u.column.table ), debugstr_w( cond->u.column.column ) );
}
break;
case EXPR_COMPLEX: