2003-08-13 03:27:48 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
2003-09-08 21:38:45 +02:00
|
|
|
* Copyright 2002 Mike McCormack for CodeWeavers
|
2011-09-09 11:25:58 +02:00
|
|
|
* Copyright 2011 Bernhard Loos
|
2003-08-13 03:27:48 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-08-13 03:27:48 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2011-08-26 04:53:34 +02:00
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "msi.h"
|
|
|
|
#include "msiquery.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "objidl.h"
|
|
|
|
#include "msipriv.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
|
|
|
|
#include "query.h"
|
|
|
|
|
2005-11-02 15:24:21 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msidb);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
/* below is the query interface to a table */
|
2011-08-24 16:42:53 +02:00
|
|
|
typedef struct tagMSIROWENTRY
|
2007-12-03 03:42:25 +01:00
|
|
|
{
|
2011-08-26 04:53:44 +02:00
|
|
|
struct tagMSIWHEREVIEW *wv; /* used during sorting */
|
2011-08-26 04:53:34 +02:00
|
|
|
UINT values[1];
|
2011-08-24 16:42:53 +02:00
|
|
|
} MSIROWENTRY;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
typedef struct tagJOINTABLE
|
|
|
|
{
|
|
|
|
struct tagJOINTABLE *next;
|
|
|
|
MSIVIEW *view;
|
|
|
|
UINT col_count;
|
|
|
|
UINT row_count;
|
|
|
|
UINT table_index;
|
|
|
|
} JOINTABLE;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2011-08-26 04:53:44 +02:00
|
|
|
typedef struct tagMSIORDERINFO
|
|
|
|
{
|
|
|
|
UINT col_count;
|
|
|
|
UINT error;
|
|
|
|
union ext_column columns[1];
|
|
|
|
} MSIORDERINFO;
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
typedef struct tagMSIWHEREVIEW
|
|
|
|
{
|
|
|
|
MSIVIEW view;
|
|
|
|
MSIDATABASE *db;
|
2011-08-26 04:53:34 +02:00
|
|
|
JOINTABLE *tables;
|
2003-08-13 03:27:48 +02:00
|
|
|
UINT row_count;
|
2011-08-26 04:53:34 +02:00
|
|
|
UINT col_count;
|
|
|
|
UINT table_count;
|
2011-08-24 16:42:53 +02:00
|
|
|
MSIROWENTRY **reorder;
|
|
|
|
UINT reorder_size; /* number of entries available in reorder */
|
2003-08-13 03:27:48 +02:00
|
|
|
struct expr *cond;
|
2007-07-27 20:11:54 +02:00
|
|
|
UINT rec_index;
|
2011-08-26 04:53:44 +02:00
|
|
|
MSIORDERINFO *order_info;
|
2003-08-13 03:27:48 +02:00
|
|
|
} MSIWHEREVIEW;
|
|
|
|
|
2011-09-09 11:25:58 +02:00
|
|
|
static UINT WHERE_evaluate( MSIWHEREVIEW *wv, const UINT rows[],
|
|
|
|
struct expr *cond, INT *val, MSIRECORD *record );
|
|
|
|
|
2011-08-24 16:42:53 +02:00
|
|
|
#define INITIAL_REORDER_SIZE 16
|
2007-12-03 03:42:25 +01:00
|
|
|
|
2011-09-09 11:25:58 +02:00
|
|
|
#define INVALID_ROW_INDEX (-1)
|
|
|
|
|
2011-08-24 16:42:53 +02:00
|
|
|
static void free_reorder(MSIWHEREVIEW *wv)
|
2007-12-03 03:42:25 +01:00
|
|
|
{
|
2011-08-24 16:42:53 +02:00
|
|
|
UINT i;
|
2007-12-03 03:42:25 +01:00
|
|
|
|
2011-08-24 16:42:53 +02:00
|
|
|
if (!wv->reorder)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < wv->row_count; i++)
|
|
|
|
msi_free(wv->reorder[i]);
|
|
|
|
|
|
|
|
msi_free( wv->reorder );
|
|
|
|
wv->reorder = NULL;
|
|
|
|
wv->reorder_size = 0;
|
|
|
|
wv->row_count = 0;
|
|
|
|
}
|
2008-04-06 21:31:19 +02:00
|
|
|
|
2011-09-09 11:25:51 +02:00
|
|
|
static UINT init_reorder(MSIWHEREVIEW *wv)
|
|
|
|
{
|
|
|
|
MSIROWENTRY **new = msi_alloc_zero(sizeof(MSIROWENTRY *) * INITIAL_REORDER_SIZE);
|
|
|
|
if (!new)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
free_reorder(wv);
|
|
|
|
|
|
|
|
wv->reorder = new;
|
|
|
|
wv->reorder_size = INITIAL_REORDER_SIZE;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
static inline UINT find_row(MSIWHEREVIEW *wv, UINT row, UINT *(values[]))
|
2011-08-24 16:42:53 +02:00
|
|
|
{
|
|
|
|
if (row >= wv->row_count)
|
|
|
|
return ERROR_NO_MORE_ITEMS;
|
2007-12-03 03:42:25 +01:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
*values = wv->reorder[row]->values;
|
2007-12-03 03:42:25 +01:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
static UINT add_row(MSIWHEREVIEW *wv, UINT vals[])
|
2007-12-03 03:42:25 +01:00
|
|
|
{
|
2011-08-24 16:42:53 +02:00
|
|
|
MSIROWENTRY *new;
|
|
|
|
|
|
|
|
if (wv->reorder_size <= wv->row_count)
|
|
|
|
{
|
|
|
|
MSIROWENTRY **new_reorder;
|
|
|
|
UINT newsize = wv->reorder_size * 2;
|
|
|
|
|
|
|
|
new_reorder = msi_realloc_zero(wv->reorder, sizeof(MSIROWENTRY *) * newsize);
|
|
|
|
if (!new_reorder)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
wv->reorder = new_reorder;
|
|
|
|
wv->reorder_size = newsize;
|
|
|
|
}
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
new = msi_alloc(FIELD_OFFSET( MSIROWENTRY, values[wv->table_count] ));
|
2007-12-03 03:42:25 +01:00
|
|
|
|
|
|
|
if (!new)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
2011-08-24 16:42:53 +02:00
|
|
|
wv->reorder[wv->row_count++] = new;
|
2007-12-03 03:42:25 +01:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
memcpy(new->values, vals, wv->table_count * sizeof(UINT));
|
2011-08-26 04:53:44 +02:00
|
|
|
new->wv = wv;
|
2007-12-03 03:42:25 +01:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-09-02 10:51:16 +02:00
|
|
|
static JOINTABLE *find_table(MSIWHEREVIEW *wv, UINT col, UINT *table_col)
|
2011-08-26 04:53:34 +02:00
|
|
|
{
|
|
|
|
JOINTABLE *table = wv->tables;
|
|
|
|
|
|
|
|
if(col == 0 || col > wv->col_count)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
while (col > table->col_count)
|
|
|
|
{
|
|
|
|
col -= table->col_count;
|
|
|
|
table = table->next;
|
|
|
|
assert(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
*table_col = col;
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT parse_column(MSIWHEREVIEW *wv, union ext_column *column,
|
|
|
|
UINT *column_type)
|
|
|
|
{
|
|
|
|
JOINTABLE *table = wv->tables;
|
|
|
|
UINT i, r;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
LPCWSTR table_name;
|
|
|
|
|
|
|
|
if (column->unparsed.table)
|
|
|
|
{
|
|
|
|
r = table->view->ops->get_column_info(table->view, 1, NULL, NULL,
|
|
|
|
NULL, &table_name);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2019-06-13 08:42:35 +02:00
|
|
|
if (wcscmp(table_name, column->unparsed.table) != 0)
|
2011-08-26 04:53:34 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 1; i <= table->col_count; i++)
|
|
|
|
{
|
|
|
|
LPCWSTR col_name;
|
|
|
|
|
|
|
|
r = table->view->ops->get_column_info(table->view, i, &col_name, column_type,
|
|
|
|
NULL, NULL);
|
|
|
|
if(r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
if(wcscmp(col_name, column->unparsed.column))
|
2011-08-26 04:53:34 +02:00
|
|
|
continue;
|
|
|
|
column->parsed.column = i;
|
|
|
|
column->parsed.table = table;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ((table = table->next));
|
|
|
|
|
|
|
|
WARN("Couldn't find column %s.%s\n", debugstr_w( column->unparsed.table ), debugstr_w( column->unparsed.column ) );
|
|
|
|
return ERROR_BAD_QUERY_SYNTAX;
|
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
static UINT WHERE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
2011-08-26 04:53:34 +02:00
|
|
|
JOINTABLE *table;
|
|
|
|
UINT *rows;
|
2007-12-03 03:42:25 +01:00
|
|
|
UINT r;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
TRACE("%p %d %d %p\n", wv, row, col, val );
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
if( !wv->tables )
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
r = find_row(wv, row, &rows);
|
2007-12-03 03:42:25 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
table = find_table(wv, col, &col);
|
|
|
|
if (!table)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return table->view->ops->fetch_int(table->view, rows[table->table_index], col, val);
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2004-07-06 20:56:12 +02:00
|
|
|
static UINT WHERE_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm )
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
2011-08-26 04:53:34 +02:00
|
|
|
JOINTABLE *table;
|
|
|
|
UINT *rows;
|
2007-12-03 03:42:25 +01:00
|
|
|
UINT r;
|
2004-07-06 20:56:12 +02:00
|
|
|
|
|
|
|
TRACE("%p %d %d %p\n", wv, row, col, stm );
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
if( !wv->tables )
|
2004-07-06 20:56:12 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
r = find_row(wv, row, &rows);
|
2007-12-03 03:42:25 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2004-07-06 20:56:12 +02:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
table = find_table(wv, col, &col);
|
|
|
|
if (!table)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return table->view->ops->fetch_stream( table->view, rows[table->table_index], col, stm );
|
2004-07-06 20:56:12 +02:00
|
|
|
}
|
|
|
|
|
2019-01-26 23:58:58 +01:00
|
|
|
static UINT WHERE_set_int(struct tagMSIVIEW *view, UINT row, UINT col, int val)
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
|
|
JOINTABLE *table;
|
|
|
|
UINT *rows;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("view %p, row %u, col %u, val %d.\n", wv, row, col, val );
|
|
|
|
|
|
|
|
r = find_row(wv, row, &rows);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
table = find_table(wv, col, &col);
|
|
|
|
if (!table)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return table->view->ops->set_int(table->view, rows[table->table_index], col, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT WHERE_set_string(struct tagMSIVIEW *view, UINT row, UINT col, const WCHAR *val, int len)
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
|
|
JOINTABLE *table;
|
|
|
|
UINT *rows;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("view %p, row %u, col %u, val %s.\n", wv, row, col, debugstr_wn(val, len));
|
|
|
|
|
|
|
|
r = find_row(wv, row, &rows);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
table = find_table(wv, col, &col);
|
|
|
|
if (!table)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return table->view->ops->set_string(table->view, rows[table->table_index], col, val, len);
|
|
|
|
}
|
|
|
|
|
2019-01-29 05:11:08 +01:00
|
|
|
static UINT WHERE_set_stream(MSIVIEW *view, UINT row, UINT col, IStream *stream)
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
|
|
JOINTABLE *table;
|
|
|
|
UINT *rows;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("view %p, row %u, col %u, stream %p.\n", wv, row, col, stream);
|
|
|
|
|
|
|
|
r = find_row(wv, row, &rows);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
table = find_table(wv, col, &col);
|
|
|
|
if (!table)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return table->view->ops->set_stream(table->view, rows[table->table_index], col, stream);
|
|
|
|
}
|
|
|
|
|
2006-10-26 10:09:47 +02:00
|
|
|
static UINT WHERE_set_row( struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UINT mask )
|
2004-07-04 02:30:02 +02:00
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
2011-08-26 04:53:39 +02:00
|
|
|
UINT i, r, offset = 0;
|
2011-08-26 04:53:34 +02:00
|
|
|
JOINTABLE *table = wv->tables;
|
|
|
|
UINT *rows;
|
2011-08-26 04:53:39 +02:00
|
|
|
UINT mask_copy = mask;
|
2004-07-04 02:30:02 +02:00
|
|
|
|
2006-10-26 10:09:47 +02:00
|
|
|
TRACE("%p %d %p %08x\n", wv, row, rec, mask );
|
2004-07-04 02:30:02 +02:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
if( !wv->tables )
|
2004-07-04 02:30:02 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2006-10-26 10:09:47 +02:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
r = find_row(wv, row, &rows);
|
2007-12-03 03:42:25 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2006-10-26 10:09:47 +02:00
|
|
|
|
2011-08-26 04:53:39 +02:00
|
|
|
if (mask >= 1 << wv->col_count)
|
2011-08-26 04:53:34 +02:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2011-08-26 04:53:39 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
for (i = 0; i < table->col_count; i++) {
|
|
|
|
UINT type;
|
|
|
|
|
|
|
|
if (!(mask_copy & (1 << i)))
|
|
|
|
continue;
|
|
|
|
r = table->view->ops->get_column_info(table->view, i + 1, NULL,
|
|
|
|
&type, NULL, NULL );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
if (type & MSITYPE_KEY)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
mask_copy >>= table->col_count;
|
|
|
|
}
|
|
|
|
while (mask_copy && (table = table->next));
|
|
|
|
|
|
|
|
table = wv->tables;
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
const UINT col_count = table->col_count;
|
|
|
|
UINT i;
|
|
|
|
MSIRECORD *reduced;
|
2011-08-26 04:53:39 +02:00
|
|
|
UINT reduced_mask = (mask >> offset) & ((1 << col_count) - 1);
|
|
|
|
|
|
|
|
if (!reduced_mask)
|
|
|
|
{
|
|
|
|
offset += col_count;
|
|
|
|
continue;
|
|
|
|
}
|
2011-08-26 04:53:34 +02:00
|
|
|
|
|
|
|
reduced = MSI_CreateRecord(col_count);
|
|
|
|
if (!reduced)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2011-08-26 04:53:39 +02:00
|
|
|
for (i = 1; i <= col_count; i++)
|
2011-08-26 04:53:34 +02:00
|
|
|
{
|
2011-08-26 04:53:39 +02:00
|
|
|
r = MSI_RecordCopyField(rec, i + offset, reduced, i);
|
2011-08-26 04:53:34 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += col_count;
|
|
|
|
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
r = table->view->ops->set_row(table->view, rows[table->table_index], reduced, reduced_mask);
|
|
|
|
|
|
|
|
msiobj_release(&reduced->hdr);
|
|
|
|
}
|
|
|
|
while ((table = table->next));
|
|
|
|
return r;
|
2004-07-04 02:30:02 +02:00
|
|
|
}
|
|
|
|
|
2008-01-09 09:36:25 +01:00
|
|
|
static UINT WHERE_delete_row(struct tagMSIVIEW *view, UINT row)
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW *)view;
|
|
|
|
UINT r;
|
2011-08-26 04:53:34 +02:00
|
|
|
UINT *rows;
|
2008-01-09 09:36:25 +01:00
|
|
|
|
|
|
|
TRACE("(%p %d)\n", view, row);
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
if (!wv->tables)
|
2008-01-09 09:36:25 +01:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
r = find_row(wv, row, &rows);
|
2008-01-09 09:36:25 +01:00
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
if (wv->table_count > 1)
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
return wv->tables->view->ops->delete_row(wv->tables->view, rows[0]);
|
2008-01-09 09:36:25 +01:00
|
|
|
}
|
|
|
|
|
2011-09-09 11:25:58 +02:00
|
|
|
static INT INT_evaluate_binary( MSIWHEREVIEW *wv, const UINT rows[],
|
|
|
|
const struct complex_expr *expr, INT *val, MSIRECORD *record )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2011-09-09 11:25:58 +02:00
|
|
|
UINT rl, rr;
|
|
|
|
INT lval, rval;
|
|
|
|
|
|
|
|
rl = WHERE_evaluate(wv, rows, expr->left, &lval, record);
|
|
|
|
if (rl != ERROR_SUCCESS && rl != ERROR_CONTINUE)
|
|
|
|
return rl;
|
|
|
|
rr = WHERE_evaluate(wv, rows, expr->right, &rval, record);
|
|
|
|
if (rr != ERROR_SUCCESS && rr != ERROR_CONTINUE)
|
|
|
|
return rr;
|
|
|
|
|
|
|
|
if (rl == ERROR_CONTINUE || rr == ERROR_CONTINUE)
|
|
|
|
{
|
|
|
|
if (rl == rr)
|
|
|
|
{
|
|
|
|
*val = TRUE;
|
|
|
|
return ERROR_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expr->op == OP_AND)
|
|
|
|
{
|
|
|
|
if ((rl == ERROR_CONTINUE && !rval) || (rr == ERROR_CONTINUE && !lval))
|
|
|
|
{
|
|
|
|
*val = FALSE;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (expr->op == OP_OR)
|
|
|
|
{
|
|
|
|
if ((rl == ERROR_CONTINUE && rval) || (rr == ERROR_CONTINUE && lval))
|
|
|
|
{
|
|
|
|
*val = TRUE;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*val = TRUE;
|
|
|
|
return ERROR_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( expr->op )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
case OP_EQ:
|
2011-09-09 11:25:58 +02:00
|
|
|
*val = ( lval == rval );
|
|
|
|
break;
|
2003-08-13 03:27:48 +02:00
|
|
|
case OP_AND:
|
2011-09-09 11:25:58 +02:00
|
|
|
*val = ( lval && rval );
|
|
|
|
break;
|
2003-08-13 03:27:48 +02:00
|
|
|
case OP_OR:
|
2011-09-09 11:25:58 +02:00
|
|
|
*val = ( lval || rval );
|
|
|
|
break;
|
2003-08-13 03:27:48 +02:00
|
|
|
case OP_GT:
|
2011-09-09 11:25:58 +02:00
|
|
|
*val = ( lval > rval );
|
|
|
|
break;
|
2003-08-13 03:27:48 +02:00
|
|
|
case OP_LT:
|
2011-09-09 11:25:58 +02:00
|
|
|
*val = ( lval < rval );
|
|
|
|
break;
|
2003-08-13 03:27:48 +02:00
|
|
|
case OP_LE:
|
2011-09-09 11:25:58 +02:00
|
|
|
*val = ( lval <= rval );
|
|
|
|
break;
|
2003-08-13 03:27:48 +02:00
|
|
|
case OP_GE:
|
2011-09-09 11:25:58 +02:00
|
|
|
*val = ( lval >= rval );
|
|
|
|
break;
|
2003-08-13 03:27:48 +02:00
|
|
|
case OP_NE:
|
2011-09-09 11:25:58 +02:00
|
|
|
*val = ( lval != rval );
|
|
|
|
break;
|
2006-11-07 07:07:16 +01:00
|
|
|
default:
|
2011-09-09 11:25:58 +02:00
|
|
|
ERR("Unknown operator %d\n", expr->op );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2006-11-07 07:07:16 +01:00
|
|
|
}
|
2011-09-09 11:25:58 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2006-11-07 07:07:16 +01:00
|
|
|
}
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
static inline UINT expr_fetch_value(const union ext_column *expr, const UINT rows[], UINT *val)
|
|
|
|
{
|
|
|
|
JOINTABLE *table = expr->parsed.table;
|
|
|
|
|
2011-09-09 11:25:58 +02:00
|
|
|
if( rows[table->table_index] == INVALID_ROW_INDEX )
|
|
|
|
{
|
|
|
|
*val = 1;
|
|
|
|
return ERROR_CONTINUE;
|
|
|
|
}
|
2011-08-26 04:53:34 +02:00
|
|
|
return table->view->ops->fetch_int(table->view, rows[table->table_index],
|
|
|
|
expr->parsed.column, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-09 11:25:58 +02:00
|
|
|
static UINT INT_evaluate_unary( MSIWHEREVIEW *wv, const UINT rows[],
|
|
|
|
const struct complex_expr *expr, INT *val, MSIRECORD *record )
|
2006-11-07 07:07:16 +01:00
|
|
|
{
|
2011-09-09 11:25:58 +02:00
|
|
|
UINT r;
|
|
|
|
UINT lval;
|
|
|
|
|
|
|
|
r = expr_fetch_value(&expr->left->u.column, rows, &lval);
|
|
|
|
if(r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
switch( expr->op )
|
2006-11-07 07:07:16 +01:00
|
|
|
{
|
2003-08-13 03:27:48 +02:00
|
|
|
case OP_ISNULL:
|
2011-09-09 11:25:58 +02:00
|
|
|
*val = !lval;
|
|
|
|
break;
|
2003-08-13 03:27:48 +02:00
|
|
|
case OP_NOTNULL:
|
2011-09-09 11:25:58 +02:00
|
|
|
*val = lval;
|
|
|
|
break;
|
2003-08-13 03:27:48 +02:00
|
|
|
default:
|
2011-09-09 11:25:58 +02:00
|
|
|
ERR("Unknown operator %d\n", expr->op );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2011-09-09 11:25:58 +02:00
|
|
|
return ERROR_SUCCESS;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2011-09-09 11:25:58 +02:00
|
|
|
static UINT STRING_evaluate( MSIWHEREVIEW *wv, const UINT rows[],
|
2007-07-27 20:11:54 +02:00
|
|
|
const struct expr *expr,
|
2011-09-09 11:25:58 +02:00
|
|
|
const MSIRECORD *record,
|
|
|
|
const WCHAR **str )
|
2004-06-26 02:11:08 +02:00
|
|
|
{
|
2011-09-09 11:25:58 +02:00
|
|
|
UINT val = 0, r = ERROR_SUCCESS;
|
2004-06-26 02:11:08 +02:00
|
|
|
|
|
|
|
switch( expr->type )
|
|
|
|
{
|
2004-12-22 16:22:12 +01:00
|
|
|
case EXPR_COL_NUMBER_STRING:
|
2011-08-26 04:53:34 +02:00
|
|
|
r = expr_fetch_value(&expr->u.column, rows, &val);
|
2011-09-09 11:25:58 +02:00
|
|
|
if (r == ERROR_SUCCESS)
|
2012-10-29 12:12:50 +01:00
|
|
|
*str = msi_string_lookup(wv->db->strings, val, NULL);
|
2011-09-09 11:25:58 +02:00
|
|
|
else
|
|
|
|
*str = NULL;
|
|
|
|
break;
|
2004-06-26 02:11:08 +02:00
|
|
|
|
2004-06-30 20:18:27 +02:00
|
|
|
case EXPR_SVAL:
|
2011-09-09 11:25:58 +02:00
|
|
|
*str = expr->u.sval;
|
|
|
|
break;
|
2004-06-30 20:18:27 +02:00
|
|
|
|
|
|
|
case EXPR_WILDCARD:
|
2011-09-09 11:25:58 +02:00
|
|
|
*str = MSI_RecordGetString(record, ++wv->rec_index);
|
|
|
|
break;
|
2004-06-26 02:11:08 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Invalid expression type\n");
|
2011-09-09 11:25:58 +02:00
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
*str = NULL;
|
2004-06-26 02:11:08 +02:00
|
|
|
break;
|
|
|
|
}
|
2011-09-09 11:25:58 +02:00
|
|
|
return r;
|
2004-06-26 02:11:08 +02:00
|
|
|
}
|
|
|
|
|
2011-09-09 11:25:58 +02:00
|
|
|
static UINT STRCMP_Evaluate( MSIWHEREVIEW *wv, const UINT rows[], const struct complex_expr *expr,
|
2007-07-27 20:11:54 +02:00
|
|
|
INT *val, const MSIRECORD *record )
|
2004-06-26 02:11:08 +02:00
|
|
|
{
|
|
|
|
int sr;
|
2004-06-30 20:18:27 +02:00
|
|
|
const WCHAR *l_str, *r_str;
|
2011-09-09 11:25:58 +02:00
|
|
|
UINT r;
|
|
|
|
|
|
|
|
*val = TRUE;
|
|
|
|
r = STRING_evaluate(wv, rows, expr->left, record, &l_str);
|
|
|
|
if (r == ERROR_CONTINUE)
|
|
|
|
return r;
|
|
|
|
r = STRING_evaluate(wv, rows, expr->right, record, &r_str);
|
|
|
|
if (r == ERROR_CONTINUE)
|
|
|
|
return r;
|
2004-06-26 02:11:08 +02:00
|
|
|
|
2007-07-30 06:23:19 +02:00
|
|
|
if( l_str == r_str ||
|
|
|
|
((!l_str || !*l_str) && (!r_str || !*r_str)) )
|
2004-06-26 02:11:08 +02:00
|
|
|
sr = 0;
|
|
|
|
else if( l_str && ! r_str )
|
|
|
|
sr = 1;
|
|
|
|
else if( r_str && ! l_str )
|
|
|
|
sr = -1;
|
|
|
|
else
|
2019-06-13 08:42:35 +02:00
|
|
|
sr = wcscmp( l_str, r_str );
|
2004-06-26 02:11:08 +02:00
|
|
|
|
2011-09-09 11:25:58 +02:00
|
|
|
*val = ( expr->op == OP_EQ && ( sr == 0 ) ) ||
|
|
|
|
( expr->op == OP_NE && ( sr != 0 ) );
|
2004-06-26 02:11:08 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
static UINT WHERE_evaluate( MSIWHEREVIEW *wv, const UINT rows[],
|
2007-07-27 20:11:54 +02:00
|
|
|
struct expr *cond, INT *val, MSIRECORD *record )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2006-07-25 04:17:56 +02:00
|
|
|
UINT r, tval;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( !cond )
|
2011-08-26 04:53:34 +02:00
|
|
|
{
|
|
|
|
*val = TRUE;
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_SUCCESS;
|
2011-08-26 04:53:34 +02:00
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
switch( cond->type )
|
|
|
|
{
|
|
|
|
case EXPR_COL_NUMBER:
|
2011-08-26 04:53:34 +02:00
|
|
|
r = expr_fetch_value(&cond->u.column, rows, &tval);
|
2011-01-27 11:54:35 +01:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
2006-07-25 04:17:56 +02:00
|
|
|
*val = tval - 0x8000;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case EXPR_COL_NUMBER32:
|
2011-08-26 04:53:34 +02:00
|
|
|
r = expr_fetch_value(&cond->u.column, rows, &tval);
|
2011-01-27 11:54:35 +01:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
2006-07-27 05:34:20 +02:00
|
|
|
*val = tval - 0x80000000;
|
2006-07-25 04:17:56 +02:00
|
|
|
return r;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
case EXPR_UVAL:
|
|
|
|
*val = cond->u.uval;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case EXPR_COMPLEX:
|
2011-09-09 11:25:58 +02:00
|
|
|
return INT_evaluate_binary(wv, rows, &cond->u.expr, val, record);
|
2006-11-07 07:07:16 +01:00
|
|
|
|
|
|
|
case EXPR_UNARY:
|
2011-09-09 11:25:58 +02:00
|
|
|
return INT_evaluate_unary( wv, rows, &cond->u.expr, val, record );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-06-26 02:11:08 +02:00
|
|
|
case EXPR_STRCMP:
|
2011-09-09 11:25:58 +02:00
|
|
|
return STRCMP_Evaluate( wv, rows, &cond->u.expr, val, record );
|
2004-06-30 20:18:27 +02:00
|
|
|
|
|
|
|
case EXPR_WILDCARD:
|
2007-07-27 20:11:54 +02:00
|
|
|
*val = MSI_RecordGetInteger( record, ++wv->rec_index );
|
2004-06-30 20:18:27 +02:00
|
|
|
return ERROR_SUCCESS;
|
2004-06-26 02:11:08 +02:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
default:
|
|
|
|
ERR("Invalid expression type\n");
|
2016-05-09 12:51:34 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2006-11-07 07:07:16 +01:00
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-10-20 14:21:48 +02:00
|
|
|
static UINT check_condition( MSIWHEREVIEW *wv, MSIRECORD *record, JOINTABLE **tables,
|
2011-08-26 04:53:34 +02:00
|
|
|
UINT table_rows[] )
|
|
|
|
{
|
|
|
|
UINT r = ERROR_FUNCTION_FAILED;
|
|
|
|
INT val;
|
|
|
|
|
2011-10-20 14:21:48 +02:00
|
|
|
for (table_rows[(*tables)->table_index] = 0;
|
|
|
|
table_rows[(*tables)->table_index] < (*tables)->row_count;
|
|
|
|
table_rows[(*tables)->table_index]++)
|
2011-08-26 04:53:34 +02:00
|
|
|
{
|
2011-09-09 11:25:58 +02:00
|
|
|
val = 0;
|
|
|
|
wv->rec_index = 0;
|
|
|
|
r = WHERE_evaluate( wv, table_rows, wv->cond, &val, record );
|
|
|
|
if (r != ERROR_SUCCESS && r != ERROR_CONTINUE)
|
|
|
|
break;
|
|
|
|
if (val)
|
2011-08-26 04:53:34 +02:00
|
|
|
{
|
2011-10-20 14:21:48 +02:00
|
|
|
if (*(tables + 1))
|
2011-09-09 11:25:58 +02:00
|
|
|
{
|
2011-10-20 14:21:48 +02:00
|
|
|
r = check_condition(wv, record, tables + 1, table_rows);
|
2011-09-09 11:25:58 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
add_row (wv, table_rows);
|
|
|
|
}
|
2011-08-26 04:53:34 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-20 14:21:48 +02:00
|
|
|
table_rows[(*tables)->table_index] = INVALID_ROW_INDEX;
|
2011-08-26 04:53:34 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
static int __cdecl compare_entry( const void *left, const void *right )
|
2011-08-26 04:53:44 +02:00
|
|
|
{
|
|
|
|
const MSIROWENTRY *le = *(const MSIROWENTRY**)left;
|
|
|
|
const MSIROWENTRY *re = *(const MSIROWENTRY**)right;
|
|
|
|
const MSIWHEREVIEW *wv = le->wv;
|
|
|
|
MSIORDERINFO *order = wv->order_info;
|
|
|
|
UINT i, j, r, l_val, r_val;
|
|
|
|
|
|
|
|
assert(le->wv == re->wv);
|
|
|
|
|
|
|
|
if (order)
|
|
|
|
{
|
|
|
|
for (i = 0; i < order->col_count; i++)
|
|
|
|
{
|
|
|
|
const union ext_column *column = &order->columns[i];
|
|
|
|
|
|
|
|
r = column->parsed.table->view->ops->fetch_int(column->parsed.table->view,
|
|
|
|
le->values[column->parsed.table->table_index],
|
|
|
|
column->parsed.column, &l_val);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
order->error = r;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = column->parsed.table->view->ops->fetch_int(column->parsed.table->view,
|
|
|
|
re->values[column->parsed.table->table_index],
|
|
|
|
column->parsed.column, &r_val);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
order->error = r;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l_val != r_val)
|
|
|
|
return l_val < r_val ? -1 : 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < wv->table_count; j++)
|
|
|
|
{
|
|
|
|
if (le->values[j] != re->values[j])
|
|
|
|
return le->values[j] < re->values[j] ? -1 : 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-20 14:21:48 +02:00
|
|
|
static void add_to_array( JOINTABLE **array, JOINTABLE *elem )
|
|
|
|
{
|
|
|
|
while (*array && *array != elem)
|
|
|
|
array++;
|
|
|
|
if (!*array)
|
|
|
|
*array = elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL in_array( JOINTABLE **array, JOINTABLE *elem )
|
|
|
|
{
|
|
|
|
while (*array && *array != elem)
|
|
|
|
array++;
|
|
|
|
return *array != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CONST_EXPR 1 /* comparison to a constant value */
|
|
|
|
#define JOIN_TO_CONST_EXPR 0x10000 /* comparison to a table involved with
|
|
|
|
a CONST_EXPR comaprison */
|
|
|
|
|
|
|
|
static UINT reorder_check( const struct expr *expr, JOINTABLE **ordered_tables,
|
|
|
|
BOOL process_joins, JOINTABLE **lastused )
|
|
|
|
{
|
|
|
|
UINT res = 0;
|
|
|
|
|
|
|
|
switch (expr->type)
|
|
|
|
{
|
|
|
|
case EXPR_WILDCARD:
|
|
|
|
case EXPR_SVAL:
|
|
|
|
case EXPR_UVAL:
|
|
|
|
return 0;
|
|
|
|
case EXPR_COL_NUMBER:
|
|
|
|
case EXPR_COL_NUMBER32:
|
|
|
|
case EXPR_COL_NUMBER_STRING:
|
|
|
|
if (in_array(ordered_tables, expr->u.column.parsed.table))
|
|
|
|
return JOIN_TO_CONST_EXPR;
|
|
|
|
*lastused = expr->u.column.parsed.table;
|
|
|
|
return CONST_EXPR;
|
|
|
|
case EXPR_STRCMP:
|
|
|
|
case EXPR_COMPLEX:
|
|
|
|
res = reorder_check(expr->u.expr.right, ordered_tables, process_joins, lastused);
|
|
|
|
/* fall through */
|
|
|
|
case EXPR_UNARY:
|
|
|
|
res += reorder_check(expr->u.expr.left, ordered_tables, process_joins, lastused);
|
|
|
|
if (res == 0)
|
|
|
|
return 0;
|
|
|
|
if (res == CONST_EXPR)
|
|
|
|
add_to_array(ordered_tables, *lastused);
|
|
|
|
if (process_joins && res == JOIN_TO_CONST_EXPR + CONST_EXPR)
|
|
|
|
add_to_array(ordered_tables, *lastused);
|
|
|
|
return res;
|
|
|
|
default:
|
2011-11-28 11:37:42 +01:00
|
|
|
ERR("Unknown expr type: %i\n", expr->type);
|
2011-10-20 14:21:48 +02:00
|
|
|
assert(0);
|
|
|
|
return 0x1000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reorders the tablelist in a way to evaluate the condition as fast as possible */
|
|
|
|
static JOINTABLE **ordertables( MSIWHEREVIEW *wv )
|
|
|
|
{
|
|
|
|
JOINTABLE *table;
|
|
|
|
JOINTABLE **tables;
|
|
|
|
|
|
|
|
tables = msi_alloc_zero( (wv->table_count + 1) * sizeof(*tables) );
|
|
|
|
|
|
|
|
if (wv->cond)
|
|
|
|
{
|
|
|
|
table = NULL;
|
|
|
|
reorder_check(wv->cond, tables, FALSE, &table);
|
|
|
|
table = NULL;
|
|
|
|
reorder_check(wv->cond, tables, TRUE, &table);
|
|
|
|
}
|
|
|
|
|
|
|
|
table = wv->tables;
|
|
|
|
while (table)
|
|
|
|
{
|
|
|
|
add_to_array(tables, table);
|
|
|
|
table = table->next;
|
|
|
|
}
|
|
|
|
return tables;
|
|
|
|
}
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
static UINT WHERE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
2011-08-26 04:53:34 +02:00
|
|
|
UINT r;
|
|
|
|
JOINTABLE *table = wv->tables;
|
2011-08-29 13:52:32 +02:00
|
|
|
UINT *rows;
|
2011-10-20 14:21:48 +02:00
|
|
|
JOINTABLE **ordered_tables;
|
2013-02-16 22:09:17 +01:00
|
|
|
UINT i = 0;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
TRACE("%p %p\n", wv, record);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( !table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2011-08-24 16:42:53 +02:00
|
|
|
r = init_reorder(wv);
|
2011-08-26 04:53:34 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
2011-08-24 16:42:53 +02:00
|
|
|
return r;
|
2010-06-11 15:19:46 +02:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
do
|
2006-03-18 17:12:15 +01:00
|
|
|
{
|
2011-08-26 04:53:34 +02:00
|
|
|
table->view->ops->execute(table->view, NULL);
|
2006-03-18 17:12:15 +01:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
r = table->view->ops->get_dimensions(table->view, &table->row_count, NULL);
|
|
|
|
if (r != ERROR_SUCCESS)
|
2006-03-18 17:12:15 +01:00
|
|
|
{
|
2011-08-26 04:53:34 +02:00
|
|
|
ERR("failed to get table dimensions\n");
|
|
|
|
return r;
|
2006-03-18 17:12:15 +01:00
|
|
|
}
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
/* each table must have at least one row */
|
|
|
|
if (table->row_count == 0)
|
|
|
|
return ERROR_SUCCESS;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2011-08-26 04:53:34 +02:00
|
|
|
while ((table = table->next));
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2011-10-20 14:21:48 +02:00
|
|
|
ordered_tables = ordertables( wv );
|
|
|
|
|
2011-08-29 13:52:32 +02:00
|
|
|
rows = msi_alloc( wv->table_count * sizeof(*rows) );
|
2011-09-09 11:25:58 +02:00
|
|
|
for (i = 0; i < wv->table_count; i++)
|
|
|
|
rows[i] = INVALID_ROW_INDEX;
|
|
|
|
|
2011-10-20 14:21:48 +02:00
|
|
|
r = check_condition(wv, record, ordered_tables, rows);
|
2011-08-26 04:53:44 +02:00
|
|
|
|
|
|
|
if (wv->order_info)
|
|
|
|
wv->order_info->error = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
qsort(wv->reorder, wv->row_count, sizeof(MSIROWENTRY *), compare_entry);
|
|
|
|
|
|
|
|
if (wv->order_info)
|
|
|
|
r = wv->order_info->error;
|
2011-09-05 11:47:37 +02:00
|
|
|
|
2011-08-29 13:52:32 +02:00
|
|
|
msi_free( rows );
|
2011-10-20 14:21:48 +02:00
|
|
|
msi_free( ordered_tables );
|
2011-08-26 04:53:34 +02:00
|
|
|
return r;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT WHERE_close( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
2011-08-26 04:53:34 +02:00
|
|
|
JOINTABLE *table = wv->tables;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", wv );
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
if (!table)
|
2007-12-03 03:42:25 +01:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
do
|
|
|
|
table->view->ops->close(table->view);
|
|
|
|
while ((table = table->next));
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT WHERE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %p %p\n", wv, rows, cols );
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
if(!wv->tables)
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
if (rows)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2011-08-26 04:53:34 +02:00
|
|
|
if (!wv->reorder)
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
*rows = wv->row_count;
|
|
|
|
}
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
if (cols)
|
|
|
|
*cols = wv->col_count;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2011-07-27 10:53:10 +02:00
|
|
|
static UINT WHERE_get_column_info( struct tagMSIVIEW *view, UINT n, LPCWSTR *name,
|
|
|
|
UINT *type, BOOL *temporary, LPCWSTR *table_name )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
2011-08-26 04:53:34 +02:00
|
|
|
JOINTABLE *table;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2009-10-18 18:41:41 +02:00
|
|
|
TRACE("%p %d %p %p %p %p\n", wv, n, name, type, temporary, table_name );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
if(!wv->tables)
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
table = find_table(wv, n, &n);
|
|
|
|
if (!table)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return table->view->ops->get_column_info(table->view, n, name,
|
|
|
|
type, temporary, table_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT join_find_row( MSIWHEREVIEW *wv, MSIRECORD *rec, UINT *row )
|
|
|
|
{
|
|
|
|
LPCWSTR str;
|
|
|
|
UINT r, i, id, data;
|
|
|
|
|
|
|
|
str = MSI_RecordGetString( rec, 1 );
|
2012-10-29 12:12:50 +01:00
|
|
|
r = msi_string2id( wv->db->strings, str, -1, &id );
|
2011-08-26 04:53:34 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
for (i = 0; i < wv->row_count; i++)
|
|
|
|
{
|
|
|
|
WHERE_fetch_int( &wv->view, i, 1, &data );
|
|
|
|
|
|
|
|
if (data == id)
|
|
|
|
{
|
|
|
|
*row = i;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT join_modify_update( struct tagMSIVIEW *view, MSIRECORD *rec )
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW *)view;
|
2011-08-26 04:53:39 +02:00
|
|
|
UINT r, row, i, mask = 0;
|
|
|
|
MSIRECORD *current;
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
|
|
|
|
r = join_find_row( wv, rec, &row );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
2011-08-26 04:53:39 +02:00
|
|
|
r = msi_view_get_row( wv->db, view, row, ¤t );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
assert(MSI_RecordGetFieldCount(rec) == MSI_RecordGetFieldCount(current));
|
|
|
|
|
|
|
|
for (i = MSI_RecordGetFieldCount(rec); i > 0; i--)
|
|
|
|
{
|
|
|
|
if (!MSI_RecordsAreFieldsEqual(rec, current, i))
|
|
|
|
mask |= 1 << (i - 1);
|
|
|
|
}
|
|
|
|
msiobj_release(¤t->hdr);
|
|
|
|
|
|
|
|
return WHERE_set_row( view, row, rec, mask );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2005-02-08 14:44:25 +01:00
|
|
|
static UINT WHERE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
|
2007-07-27 02:40:38 +02:00
|
|
|
MSIRECORD *rec, UINT row )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
2011-08-26 04:53:34 +02:00
|
|
|
JOINTABLE *table = wv->tables;
|
|
|
|
UINT r;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2008-02-14 06:36:44 +01:00
|
|
|
TRACE("%p %d %p\n", wv, eModifyMode, rec);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
if (!table)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if (!table->next)
|
|
|
|
{
|
|
|
|
UINT *rows;
|
|
|
|
|
2019-01-24 07:07:33 +01:00
|
|
|
if (find_row(wv, row, &rows) == ERROR_SUCCESS)
|
|
|
|
row = rows[0];
|
2011-08-26 04:53:34 +02:00
|
|
|
else
|
|
|
|
row = -1;
|
2008-04-06 21:31:19 +02:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
return table->view->ops->modify(table->view, eModifyMode, rec, row);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (eModifyMode)
|
|
|
|
{
|
|
|
|
case MSIMODIFY_UPDATE:
|
|
|
|
return join_modify_update( view, rec );
|
|
|
|
|
|
|
|
case MSIMODIFY_ASSIGN:
|
|
|
|
case MSIMODIFY_DELETE:
|
|
|
|
case MSIMODIFY_INSERT:
|
|
|
|
case MSIMODIFY_INSERT_TEMPORARY:
|
|
|
|
case MSIMODIFY_MERGE:
|
|
|
|
case MSIMODIFY_REPLACE:
|
|
|
|
case MSIMODIFY_SEEK:
|
|
|
|
case MSIMODIFY_VALIDATE:
|
|
|
|
case MSIMODIFY_VALIDATE_DELETE:
|
|
|
|
case MSIMODIFY_VALIDATE_FIELD:
|
|
|
|
case MSIMODIFY_VALIDATE_NEW:
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSIMODIFY_REFRESH:
|
|
|
|
r = ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WARN("%p %d %p %u - unknown mode\n", view, eModifyMode, rec, row );
|
|
|
|
r = ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT WHERE_delete( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
2011-08-26 04:53:34 +02:00
|
|
|
JOINTABLE *table = wv->tables;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", wv );
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
while(table)
|
|
|
|
{
|
|
|
|
JOINTABLE *next;
|
|
|
|
|
|
|
|
table->view->ops->delete(table->view);
|
|
|
|
table->view = NULL;
|
|
|
|
next = table->next;
|
|
|
|
msi_free(table);
|
|
|
|
table = next;
|
|
|
|
}
|
|
|
|
wv->tables = NULL;
|
|
|
|
wv->table_count = 0;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2011-08-24 16:42:53 +02:00
|
|
|
free_reorder(wv);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2011-10-11 00:03:35 +02:00
|
|
|
msi_free(wv->order_info);
|
|
|
|
wv->order_info = NULL;
|
2011-08-26 04:53:44 +02:00
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_release( &wv->db->hdr );
|
2005-09-20 13:57:19 +02:00
|
|
|
msi_free( wv );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-12-18 02:35:31 +01:00
|
|
|
static UINT WHERE_sort(struct tagMSIVIEW *view, column_info *columns)
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW *)view;
|
2011-08-26 04:53:34 +02:00
|
|
|
JOINTABLE *table = wv->tables;
|
2011-08-26 04:53:44 +02:00
|
|
|
column_info *column = columns;
|
|
|
|
MSIORDERINFO *orderinfo;
|
|
|
|
UINT r, count = 0;
|
2013-02-16 22:09:17 +01:00
|
|
|
UINT i;
|
2007-12-18 02:35:31 +01:00
|
|
|
|
|
|
|
TRACE("%p %p\n", view, columns);
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
if (!table)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2011-08-26 04:53:44 +02:00
|
|
|
while (column)
|
2011-08-26 04:53:34 +02:00
|
|
|
{
|
2011-08-26 04:53:44 +02:00
|
|
|
count++;
|
|
|
|
column = column->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count == 0)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2012-12-13 16:56:42 +01:00
|
|
|
orderinfo = msi_alloc(FIELD_OFFSET(MSIORDERINFO, columns[count]));
|
2011-08-26 04:53:44 +02:00
|
|
|
if (!orderinfo)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
orderinfo->col_count = count;
|
|
|
|
|
|
|
|
column = columns;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
orderinfo->columns[i].unparsed.column = column->column;
|
|
|
|
orderinfo->columns[i].unparsed.table = column->table;
|
|
|
|
|
|
|
|
r = parse_column(wv, &orderinfo->columns[i], NULL);
|
2011-08-26 04:53:34 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
2011-08-26 04:53:44 +02:00
|
|
|
goto error;
|
2011-08-26 04:53:34 +02:00
|
|
|
}
|
2011-08-26 04:53:44 +02:00
|
|
|
|
|
|
|
wv->order_info = orderinfo;
|
2011-08-26 04:53:34 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2011-08-26 04:53:44 +02:00
|
|
|
error:
|
|
|
|
msi_free(orderinfo);
|
|
|
|
return r;
|
2007-12-18 02:35:31 +01:00
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2006-06-10 12:02:39 +02:00
|
|
|
static const MSIVIEWOPS where_ops =
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
WHERE_fetch_int,
|
2004-07-06 20:56:12 +02:00
|
|
|
WHERE_fetch_stream,
|
2019-01-26 23:58:58 +01:00
|
|
|
WHERE_set_int,
|
|
|
|
WHERE_set_string,
|
2019-01-29 05:11:08 +01:00
|
|
|
WHERE_set_stream,
|
2006-10-26 10:09:47 +02:00
|
|
|
WHERE_set_row,
|
2004-03-19 02:16:36 +01:00
|
|
|
NULL,
|
2008-01-09 09:36:25 +01:00
|
|
|
WHERE_delete_row,
|
2003-08-13 03:27:48 +02:00
|
|
|
WHERE_execute,
|
|
|
|
WHERE_close,
|
|
|
|
WHERE_get_dimensions,
|
|
|
|
WHERE_get_column_info,
|
|
|
|
WHERE_modify,
|
2006-03-18 17:12:15 +01:00
|
|
|
WHERE_delete,
|
2007-07-19 03:21:00 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2007-07-20 23:01:13 +02:00
|
|
|
NULL,
|
2007-12-18 02:35:31 +01:00
|
|
|
WHERE_sort,
|
2008-10-02 22:56:54 +02:00
|
|
|
NULL,
|
2003-08-13 03:27:48 +02:00
|
|
|
};
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
static UINT WHERE_VerifyCondition( MSIWHEREVIEW *wv, struct expr *cond,
|
2003-08-13 03:27:48 +02:00
|
|
|
UINT *valid )
|
|
|
|
{
|
2011-08-26 04:53:34 +02:00
|
|
|
UINT r;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
switch( cond->type )
|
|
|
|
{
|
|
|
|
case EXPR_COLUMN:
|
2011-08-26 04:53:34 +02:00
|
|
|
{
|
|
|
|
UINT type;
|
|
|
|
|
|
|
|
*valid = FALSE;
|
|
|
|
|
|
|
|
r = parse_column(wv, &cond->u.column, &type);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (type&MSITYPE_STRING)
|
|
|
|
cond->type = EXPR_COL_NUMBER_STRING;
|
|
|
|
else if ((type&0xff) == 4)
|
|
|
|
cond->type = EXPR_COL_NUMBER32;
|
2003-08-13 03:27:48 +02:00
|
|
|
else
|
2011-08-26 04:53:34 +02:00
|
|
|
cond->type = EXPR_COL_NUMBER;
|
|
|
|
|
|
|
|
*valid = TRUE;
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
2011-08-26 04:53:34 +02:00
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
case EXPR_COMPLEX:
|
2011-08-26 04:53:34 +02:00
|
|
|
r = WHERE_VerifyCondition( wv, cond->u.expr.left, valid );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
if( !*valid )
|
|
|
|
return ERROR_SUCCESS;
|
2011-08-26 04:53:34 +02:00
|
|
|
r = WHERE_VerifyCondition( wv, cond->u.expr.right, valid );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
2004-06-26 02:11:08 +02:00
|
|
|
|
|
|
|
/* check the type of the comparison */
|
2004-06-30 20:18:27 +02:00
|
|
|
if( ( cond->u.expr.left->type == EXPR_SVAL ) ||
|
2004-12-22 16:22:12 +01:00
|
|
|
( cond->u.expr.left->type == EXPR_COL_NUMBER_STRING ) ||
|
|
|
|
( cond->u.expr.right->type == EXPR_SVAL ) ||
|
|
|
|
( cond->u.expr.right->type == EXPR_COL_NUMBER_STRING ) )
|
2004-06-26 02:11:08 +02:00
|
|
|
{
|
|
|
|
switch( cond->u.expr.op )
|
|
|
|
{
|
|
|
|
case OP_EQ:
|
2007-12-22 06:13:30 +01:00
|
|
|
case OP_NE:
|
2004-06-26 02:11:08 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*valid = FALSE;
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: check we're comparing a string to a column */
|
|
|
|
|
|
|
|
cond->type = EXPR_STRCMP;
|
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
2006-11-07 07:07:16 +01:00
|
|
|
case EXPR_UNARY:
|
|
|
|
if ( cond->u.expr.left->type != EXPR_COLUMN )
|
|
|
|
{
|
|
|
|
*valid = FALSE;
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
2011-08-26 04:53:34 +02:00
|
|
|
r = WHERE_VerifyCondition( wv, cond->u.expr.left, valid );
|
2006-11-07 07:07:16 +01:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
break;
|
2003-08-13 03:27:48 +02:00
|
|
|
case EXPR_IVAL:
|
|
|
|
*valid = 1;
|
|
|
|
cond->type = EXPR_UVAL;
|
2006-07-25 04:17:56 +02:00
|
|
|
cond->u.uval = cond->u.ival;
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
2004-06-30 20:18:27 +02:00
|
|
|
case EXPR_WILDCARD:
|
|
|
|
*valid = 1;
|
|
|
|
break;
|
2003-08-13 03:27:48 +02:00
|
|
|
case EXPR_SVAL:
|
2004-06-26 02:11:08 +02:00
|
|
|
*valid = 1;
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Invalid expression type\n");
|
|
|
|
*valid = 0;
|
|
|
|
break;
|
2006-11-07 07:07:16 +01:00
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR tables,
|
2004-07-04 02:27:48 +02:00
|
|
|
struct expr *cond )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-07-04 02:27:48 +02:00
|
|
|
MSIWHEREVIEW *wv = NULL;
|
2011-08-26 04:53:34 +02:00
|
|
|
UINT r, valid = 0;
|
|
|
|
WCHAR *ptr;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2011-08-26 04:53:34 +02:00
|
|
|
TRACE("(%s)\n", debugstr_w(tables) );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-20 13:57:19 +02:00
|
|
|
wv = msi_alloc_zero( sizeof *wv );
|
2004-07-04 02:27:48 +02:00
|
|
|
if( !wv )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2020-10-29 11:47:14 +01:00
|
|
|
|
2004-07-04 02:27:48 +02:00
|
|
|
/* fill the structure */
|
|
|
|
wv->view.ops = &where_ops;
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_addref( &db->hdr );
|
2004-07-04 02:27:48 +02:00
|
|
|
wv->db = db;
|
2003-08-13 03:27:48 +02:00
|
|
|
wv->cond = cond;
|
2011-08-26 04:53:34 +02:00
|
|
|
|
|
|
|
while (*tables)
|
|
|
|
{
|
|
|
|
JOINTABLE *table;
|
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
if ((ptr = wcschr(tables, ' ')))
|
2011-08-26 04:53:34 +02:00
|
|
|
*ptr = '\0';
|
|
|
|
|
|
|
|
table = msi_alloc(sizeof(JOINTABLE));
|
|
|
|
if (!table)
|
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = TABLE_CreateView(db, tables, &table->view);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WARN("can't create table: %s\n", debugstr_w(tables));
|
|
|
|
msi_free(table);
|
|
|
|
r = ERROR_BAD_QUERY_SYNTAX;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = table->view->ops->get_dimensions(table->view, NULL,
|
|
|
|
&table->col_count);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("can't get table dimensions\n");
|
2012-11-07 01:05:50 +01:00
|
|
|
table->view->ops->delete(table->view);
|
|
|
|
msi_free(table);
|
2011-08-26 04:53:34 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
wv->col_count += table->col_count;
|
|
|
|
table->table_index = wv->table_count++;
|
|
|
|
|
2011-08-26 04:53:44 +02:00
|
|
|
table->next = wv->tables;
|
|
|
|
wv->tables = table;
|
2011-08-26 04:53:34 +02:00
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
break;
|
|
|
|
|
|
|
|
tables = ptr + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( cond )
|
|
|
|
{
|
|
|
|
r = WHERE_VerifyCondition( wv, cond, &valid );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
goto end;
|
|
|
|
if( !valid ) {
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-04 02:27:48 +02:00
|
|
|
*view = (MSIVIEW*) wv;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2011-08-26 04:53:34 +02:00
|
|
|
end:
|
|
|
|
WHERE_delete(&wv->view);
|
|
|
|
|
|
|
|
return r;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|