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
|
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>
|
|
|
|
|
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
|
|
|
|
2007-12-03 03:42:25 +01:00
|
|
|
#define MSI_HASH_TABLE_SIZE 37
|
|
|
|
|
|
|
|
typedef struct tagMSIHASHENTRY
|
|
|
|
{
|
|
|
|
struct tagMSIHASHENTRY *next;
|
|
|
|
UINT value;
|
|
|
|
UINT row;
|
|
|
|
} MSIHASHENTRY;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
/* below is the query interface to a table */
|
|
|
|
|
|
|
|
typedef struct tagMSIWHEREVIEW
|
|
|
|
{
|
|
|
|
MSIVIEW view;
|
|
|
|
MSIDATABASE *db;
|
|
|
|
MSIVIEW *table;
|
|
|
|
UINT row_count;
|
2007-12-03 03:42:25 +01:00
|
|
|
MSIHASHENTRY **reorder;
|
2003-08-13 03:27:48 +02:00
|
|
|
struct expr *cond;
|
2007-07-27 20:11:54 +02:00
|
|
|
UINT rec_index;
|
2003-08-13 03:27:48 +02:00
|
|
|
} MSIWHEREVIEW;
|
|
|
|
|
2007-12-03 03:42:25 +01:00
|
|
|
static void free_hash_table(MSIHASHENTRY **table)
|
|
|
|
{
|
|
|
|
MSIHASHENTRY *new, *old;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!table)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < MSI_HASH_TABLE_SIZE; i++)
|
|
|
|
{
|
|
|
|
new = table[i];
|
|
|
|
|
|
|
|
while (new)
|
|
|
|
{
|
|
|
|
old = new;
|
|
|
|
new = old->next;
|
|
|
|
msi_free(old);
|
|
|
|
}
|
|
|
|
|
|
|
|
table[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
msi_free(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT find_entry_in_hash(MSIHASHENTRY **table, UINT row, UINT *val)
|
|
|
|
{
|
|
|
|
MSIHASHENTRY *entry;
|
|
|
|
|
|
|
|
if (!(entry = table[row % MSI_HASH_TABLE_SIZE]))
|
|
|
|
{
|
|
|
|
ERR("Row not found in hash table!\n");
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (entry && entry->row != row)
|
|
|
|
entry = entry->next;
|
|
|
|
|
|
|
|
if (entry) *val = entry->value;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT add_entry_to_hash(MSIHASHENTRY **table, UINT row, UINT val)
|
|
|
|
{
|
|
|
|
MSIHASHENTRY *new = msi_alloc(sizeof(MSIHASHENTRY));
|
|
|
|
MSIHASHENTRY *prev;
|
|
|
|
|
|
|
|
if (!new)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
new->next = NULL;
|
|
|
|
new->value = val;
|
|
|
|
new->row = row;
|
|
|
|
|
|
|
|
prev = table[row % MSI_HASH_TABLE_SIZE];
|
|
|
|
if (prev)
|
|
|
|
new->next = prev;
|
|
|
|
|
|
|
|
table[row % MSI_HASH_TABLE_SIZE] = new;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
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;
|
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 );
|
|
|
|
|
|
|
|
if( !wv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if( row > wv->row_count )
|
|
|
|
return ERROR_NO_MORE_ITEMS;
|
|
|
|
|
2007-12-03 03:42:25 +01:00
|
|
|
r = find_entry_in_hash(wv->reorder, row, &row);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return wv->table->ops->fetch_int( wv->table, row, col, val );
|
|
|
|
}
|
|
|
|
|
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;
|
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 );
|
|
|
|
|
|
|
|
if( !wv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if( row > wv->row_count )
|
|
|
|
return ERROR_NO_MORE_ITEMS;
|
|
|
|
|
2007-12-03 03:42:25 +01:00
|
|
|
r = find_entry_in_hash(wv->reorder, row, &row);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2004-07-06 20:56:12 +02:00
|
|
|
|
|
|
|
return wv->table->ops->fetch_stream( wv->table, row, col, stm );
|
|
|
|
}
|
|
|
|
|
2007-07-27 02:40:38 +02:00
|
|
|
static UINT WHERE_get_row( struct tagMSIVIEW *view, UINT row, MSIRECORD **rec )
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW *)view;
|
2007-12-03 03:42:25 +01:00
|
|
|
UINT r;
|
2007-07-27 02:40:38 +02:00
|
|
|
|
|
|
|
TRACE("%p %d %p\n", wv, row, rec );
|
|
|
|
|
|
|
|
if (!wv->table)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if (row > wv->row_count)
|
|
|
|
return ERROR_NO_MORE_ITEMS;
|
|
|
|
|
2007-12-03 03:42:25 +01:00
|
|
|
r = find_entry_in_hash(wv->reorder, row, &row);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2007-07-27 02:40:38 +02:00
|
|
|
|
|
|
|
return wv->table->ops->get_row(view, row, rec);
|
|
|
|
}
|
|
|
|
|
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;
|
2007-12-03 03:42:25 +01:00
|
|
|
UINT r;
|
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
|
|
|
|
|
|
|
if( !wv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2006-10-26 10:09:47 +02:00
|
|
|
|
2004-07-04 02:30:02 +02:00
|
|
|
if( row > wv->row_count )
|
|
|
|
return ERROR_NO_MORE_ITEMS;
|
2006-10-26 10:09:47 +02:00
|
|
|
|
2007-12-03 03:42:25 +01:00
|
|
|
r = find_entry_in_hash(wv->reorder, row, &row);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2006-10-26 10:09:47 +02:00
|
|
|
|
|
|
|
return wv->table->ops->set_row( wv->table, row, rec, mask );
|
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;
|
|
|
|
|
|
|
|
TRACE("(%p %d)\n", view, row);
|
|
|
|
|
|
|
|
if ( !wv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if ( row > wv->row_count )
|
|
|
|
return ERROR_NO_MORE_ITEMS;
|
|
|
|
|
|
|
|
r = find_entry_in_hash( wv->reorder, row, &row );
|
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return wv->table->ops->delete_row( wv->table, row );
|
|
|
|
}
|
|
|
|
|
2006-11-07 07:07:16 +01:00
|
|
|
static INT INT_evaluate_binary( INT lval, UINT op, INT rval )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
switch( op )
|
|
|
|
{
|
|
|
|
case OP_EQ:
|
|
|
|
return ( lval == rval );
|
|
|
|
case OP_AND:
|
|
|
|
return ( lval && rval );
|
|
|
|
case OP_OR:
|
|
|
|
return ( lval || rval );
|
|
|
|
case OP_GT:
|
|
|
|
return ( lval > rval );
|
|
|
|
case OP_LT:
|
|
|
|
return ( lval < rval );
|
|
|
|
case OP_LE:
|
|
|
|
return ( lval <= rval );
|
|
|
|
case OP_GE:
|
|
|
|
return ( lval >= rval );
|
|
|
|
case OP_NE:
|
|
|
|
return ( lval != rval );
|
2006-11-07 07:07:16 +01:00
|
|
|
default:
|
|
|
|
ERR("Unknown operator %d\n", op );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT INT_evaluate_unary( INT lval, UINT op )
|
|
|
|
{
|
|
|
|
switch( op )
|
|
|
|
{
|
2003-08-13 03:27:48 +02:00
|
|
|
case OP_ISNULL:
|
|
|
|
return ( !lval );
|
|
|
|
case OP_NOTNULL:
|
|
|
|
return ( lval );
|
|
|
|
default:
|
|
|
|
ERR("Unknown operator %d\n", op );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-27 20:11:54 +02:00
|
|
|
static const WCHAR *STRING_evaluate( MSIWHEREVIEW *wv, UINT row,
|
|
|
|
const struct expr *expr,
|
|
|
|
const MSIRECORD *record )
|
2004-06-26 02:11:08 +02:00
|
|
|
{
|
|
|
|
UINT val = 0, r;
|
|
|
|
|
|
|
|
switch( expr->type )
|
|
|
|
{
|
2004-12-22 16:22:12 +01:00
|
|
|
case EXPR_COL_NUMBER_STRING:
|
2007-07-27 20:11:54 +02:00
|
|
|
r = wv->table->ops->fetch_int( wv->table, row, expr->u.col_number, &val );
|
2004-06-26 02:11:08 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return NULL;
|
2007-07-27 20:11:54 +02:00
|
|
|
return msi_string_lookup_id( wv->db->strings, val );
|
2004-06-26 02:11:08 +02:00
|
|
|
|
2004-06-30 20:18:27 +02:00
|
|
|
case EXPR_SVAL:
|
|
|
|
return expr->u.sval;
|
|
|
|
|
|
|
|
case EXPR_WILDCARD:
|
2007-07-27 20:11:54 +02:00
|
|
|
return MSI_RecordGetString( record, ++wv->rec_index );
|
2004-06-26 02:11:08 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Invalid expression type\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-27 20:11:54 +02:00
|
|
|
static UINT STRCMP_Evaluate( MSIWHEREVIEW *wv, UINT row, const struct expr *cond,
|
|
|
|
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;
|
2004-06-26 02:11:08 +02:00
|
|
|
|
2007-07-27 20:11:54 +02:00
|
|
|
l_str = STRING_evaluate( wv, row, cond->u.expr.left, record );
|
|
|
|
r_str = STRING_evaluate( wv, row, cond->u.expr.right, record );
|
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
|
2005-05-29 22:08:12 +02:00
|
|
|
sr = lstrcmpW( l_str, r_str );
|
2004-06-26 02:11:08 +02:00
|
|
|
|
|
|
|
*val = ( cond->u.expr.op == OP_EQ && ( sr == 0 ) ) ||
|
2007-12-22 06:13:30 +01:00
|
|
|
( cond->u.expr.op == OP_NE && ( sr != 0 ) ) ||
|
2004-06-26 02:11:08 +02:00
|
|
|
( cond->u.expr.op == OP_LT && ( sr < 0 ) ) ||
|
|
|
|
( cond->u.expr.op == OP_GT && ( sr > 0 ) );
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-07-27 20:11:54 +02:00
|
|
|
static UINT WHERE_evaluate( MSIWHEREVIEW *wv, UINT row,
|
|
|
|
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;
|
|
|
|
INT lval, rval;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( !cond )
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
switch( cond->type )
|
|
|
|
{
|
|
|
|
case EXPR_COL_NUMBER:
|
2007-07-27 20:11:54 +02:00
|
|
|
r = wv->table->ops->fetch_int( wv->table, row, cond->u.col_number, &tval );
|
2006-07-25 04:17:56 +02:00
|
|
|
*val = tval - 0x8000;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case EXPR_COL_NUMBER32:
|
2007-07-27 20:11:54 +02:00
|
|
|
r = wv->table->ops->fetch_int( wv->table, row, cond->u.col_number, &tval );
|
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:
|
2007-07-27 20:11:54 +02:00
|
|
|
r = WHERE_evaluate( wv, row, cond->u.expr.left, &lval, record );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
2007-07-27 20:11:54 +02:00
|
|
|
r = WHERE_evaluate( wv, row, cond->u.expr.right, &rval, record );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
2006-11-07 07:07:16 +01:00
|
|
|
*val = INT_evaluate_binary( lval, cond->u.expr.op, rval );
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
case EXPR_UNARY:
|
2007-07-27 20:11:54 +02:00
|
|
|
r = wv->table->ops->fetch_int( wv->table, row, cond->u.expr.left->u.col_number, &tval );
|
2006-11-07 07:07:16 +01:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
*val = INT_evaluate_unary( tval, cond->u.expr.op );
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2004-06-26 02:11:08 +02:00
|
|
|
case EXPR_STRCMP:
|
2007-07-27 20:11:54 +02:00
|
|
|
return STRCMP_Evaluate( wv, row, cond, 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");
|
|
|
|
break;
|
2006-11-07 07:07:16 +01:00
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
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;
|
2006-07-25 04:17:56 +02:00
|
|
|
UINT count = 0, r, i;
|
|
|
|
INT val;
|
2003-08-13 03:27:48 +02:00
|
|
|
MSIVIEW *table = wv->table;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
r = table->ops->execute( table, record );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = table->ops->get_dimensions( table, &count, NULL );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
2007-12-03 03:42:25 +01:00
|
|
|
free_hash_table(wv->reorder);
|
|
|
|
wv->reorder = msi_alloc_zero(MSI_HASH_TABLE_SIZE * sizeof(MSIHASHENTRY *));
|
2003-08-13 03:27:48 +02:00
|
|
|
if( !wv->reorder )
|
2007-12-03 03:42:25 +01:00
|
|
|
return ERROR_OUTOFMEMORY;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-02-16 17:06:05 +01:00
|
|
|
wv->row_count = 0;
|
2006-03-18 17:12:15 +01:00
|
|
|
if (wv->cond->type == EXPR_STRCMP)
|
|
|
|
{
|
|
|
|
MSIITERHANDLE handle = NULL;
|
|
|
|
UINT row, value, col;
|
|
|
|
struct expr *col_cond = wv->cond->u.expr.left;
|
|
|
|
struct expr *val_cond = wv->cond->u.expr.right;
|
|
|
|
|
|
|
|
/* swap conditionals */
|
|
|
|
if (col_cond->type != EXPR_COL_NUMBER_STRING)
|
|
|
|
{
|
|
|
|
val_cond = wv->cond->u.expr.left;
|
|
|
|
col_cond = wv->cond->u.expr.right;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((col_cond->type == EXPR_COL_NUMBER_STRING) && (val_cond->type == EXPR_SVAL))
|
|
|
|
{
|
|
|
|
col = col_cond->u.col_number;
|
2006-06-05 02:41:04 +02:00
|
|
|
/* special case for "" - translate it into nil */
|
|
|
|
if (!val_cond->u.sval[0])
|
|
|
|
value = 0;
|
|
|
|
else
|
2006-03-18 17:12:15 +01:00
|
|
|
{
|
2006-06-05 02:41:04 +02:00
|
|
|
r = msi_string2idW(wv->db->strings, val_cond->u.sval, &value);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
TRACE("no id for %s, assuming it doesn't exist in the table\n", debugstr_w(wv->cond->u.expr.right->u.sval));
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2006-03-18 17:12:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
r = table->ops->find_matching_rows(table, col, value, &row, &handle);
|
|
|
|
if (r == ERROR_SUCCESS)
|
2007-12-03 03:42:25 +01:00
|
|
|
add_entry_to_hash(wv->reorder, wv->row_count++, row);
|
2006-03-18 17:12:15 +01:00
|
|
|
} while (r == ERROR_SUCCESS);
|
|
|
|
|
|
|
|
if (r == ERROR_NO_MORE_ITEMS)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
else
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
/* else fallback to slow case */
|
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
for( i=0; i<count; i++ )
|
|
|
|
{
|
|
|
|
val = 0;
|
2007-07-27 20:11:54 +02:00
|
|
|
wv->rec_index = 0;
|
|
|
|
r = WHERE_evaluate( wv, i, wv->cond, &val, record );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
if( val )
|
2007-12-03 03:42:25 +01:00
|
|
|
add_entry_to_hash( wv->reorder, wv->row_count++, i );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT WHERE_close( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p\n", wv );
|
|
|
|
|
|
|
|
if( !wv->table )
|
2007-12-03 03:42:25 +01:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return wv->table->ops->close( wv->table );
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT WHERE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %p %p\n", wv, rows, cols );
|
|
|
|
|
|
|
|
if( !wv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if( rows )
|
|
|
|
{
|
|
|
|
if( !wv->reorder )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
*rows = wv->row_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wv->table->ops->get_dimensions( wv->table, NULL, cols );
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT WHERE_get_column_info( struct tagMSIVIEW *view,
|
|
|
|
UINT n, LPWSTR *name, UINT *type )
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %d %p %p\n", wv, n, name, type );
|
|
|
|
|
|
|
|
if( !wv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return wv->table->ops->get_column_info( wv->table, n, name, type );
|
|
|
|
}
|
|
|
|
|
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;
|
2008-02-14 06:36:44 +01:00
|
|
|
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
|
|
|
|
2008-02-14 06:36:44 +01:00
|
|
|
r = WHERE_execute(view, NULL);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = find_entry_in_hash(wv->reorder, row - 1, &row);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2007-07-27 02:40:38 +02:00
|
|
|
return wv->table->ops->modify( wv->table, eModifyMode, rec, row );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT WHERE_delete( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p\n", wv );
|
|
|
|
|
|
|
|
if( wv->table )
|
|
|
|
wv->table->ops->delete( wv->table );
|
2005-09-26 12:55:18 +02:00
|
|
|
wv->table = 0;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2007-12-03 03:42:25 +01:00
|
|
|
free_hash_table(wv->reorder);
|
2003-08-13 03:27:48 +02:00
|
|
|
wv->reorder = NULL;
|
|
|
|
wv->row_count = 0;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-03-18 17:12:15 +01:00
|
|
|
static UINT WHERE_find_matching_rows( struct tagMSIVIEW *view, UINT col,
|
|
|
|
UINT val, UINT *row, MSIITERHANDLE *handle )
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("%p, %d, %u, %p\n", view, col, val, *handle);
|
|
|
|
|
|
|
|
if( !wv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
r = wv->table->ops->find_matching_rows( wv->table, col, val, row, handle );
|
2007-12-03 03:42:25 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2006-03-18 17:12:15 +01:00
|
|
|
|
|
|
|
if( *row > wv->row_count )
|
|
|
|
return ERROR_NO_MORE_ITEMS;
|
|
|
|
|
2007-12-03 03:42:25 +01:00
|
|
|
return find_entry_in_hash(wv->reorder, *row, row);
|
2006-03-18 17:12:15 +01:00
|
|
|
}
|
|
|
|
|
2007-12-18 02:35:31 +01:00
|
|
|
static UINT WHERE_sort(struct tagMSIVIEW *view, column_info *columns)
|
|
|
|
{
|
|
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW *)view;
|
|
|
|
|
|
|
|
TRACE("%p %p\n", view, columns);
|
|
|
|
|
|
|
|
return wv->table->ops->sort(wv->table, columns);
|
|
|
|
}
|
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,
|
2007-07-27 02:40:38 +02:00
|
|
|
WHERE_get_row,
|
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
|
|
|
WHERE_find_matching_rows,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2007-07-20 23:01:13 +02:00
|
|
|
NULL,
|
2007-07-21 03:41:16 +02:00
|
|
|
NULL,
|
2007-12-18 02:35:31 +01:00
|
|
|
WHERE_sort,
|
2003-08-13 03:27:48 +02:00
|
|
|
};
|
|
|
|
|
2004-06-26 02:11:08 +02:00
|
|
|
static UINT WHERE_VerifyCondition( MSIDATABASE *db, MSIVIEW *table, struct expr *cond,
|
2003-08-13 03:27:48 +02:00
|
|
|
UINT *valid )
|
|
|
|
{
|
2004-06-30 20:18:27 +02:00
|
|
|
UINT r, val = 0;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
switch( cond->type )
|
|
|
|
{
|
|
|
|
case EXPR_COLUMN:
|
2004-06-26 02:11:08 +02:00
|
|
|
r = VIEW_find_column( table, cond->u.column, &val );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r == ERROR_SUCCESS )
|
|
|
|
{
|
2004-12-22 16:22:12 +01:00
|
|
|
UINT type = 0;
|
|
|
|
r = table->ops->get_column_info( table, val, NULL, &type );
|
|
|
|
if( r == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
if (type&MSITYPE_STRING)
|
|
|
|
cond->type = EXPR_COL_NUMBER_STRING;
|
2006-07-25 04:17:56 +02:00
|
|
|
else if ((type&0xff) == 4)
|
|
|
|
cond->type = EXPR_COL_NUMBER32;
|
2004-12-22 16:22:12 +01:00
|
|
|
else
|
|
|
|
cond->type = EXPR_COL_NUMBER;
|
|
|
|
cond->u.col_number = val;
|
|
|
|
*valid = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*valid = 0;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*valid = 0;
|
2007-11-26 01:09:01 +01:00
|
|
|
WARN("Couldn't find column %s\n", debugstr_w( cond->u.column ) );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXPR_COMPLEX:
|
2004-06-26 02:11:08 +02:00
|
|
|
r = WHERE_VerifyCondition( db, table, cond->u.expr.left, valid );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
if( !*valid )
|
|
|
|
return ERROR_SUCCESS;
|
2004-06-26 02:11:08 +02:00
|
|
|
r = WHERE_VerifyCondition( db, table, 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:
|
|
|
|
case OP_GT:
|
|
|
|
case OP_LT:
|
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;
|
|
|
|
}
|
|
|
|
r = WHERE_VerifyCondition( db, table, cond->u.expr.left, valid );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-07-04 02:27:48 +02:00
|
|
|
UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
|
|
|
|
struct expr *cond )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-07-04 02:27:48 +02:00
|
|
|
MSIWHEREVIEW *wv = NULL;
|
|
|
|
UINT count = 0, r, valid = 0;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-26 12:55:18 +02:00
|
|
|
TRACE("%p\n", table );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-07-04 02:27:48 +02:00
|
|
|
r = table->ops->get_dimensions( table, NULL, &count );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
2004-07-04 02:27:48 +02:00
|
|
|
{
|
|
|
|
ERR("can't get table dimensions\n");
|
|
|
|
return r;
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-07-04 02:27:48 +02:00
|
|
|
if( cond )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-07-04 02:27:48 +02:00
|
|
|
r = WHERE_VerifyCondition( db, table, cond, &valid );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
if( !valid )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
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;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
wv->table = table;
|
|
|
|
wv->row_count = 0;
|
|
|
|
wv->reorder = NULL;
|
2003-08-13 03:27:48 +02:00
|
|
|
wv->cond = cond;
|
2007-07-27 20:11:54 +02:00
|
|
|
wv->rec_index = 0;
|
2004-07-04 02:27:48 +02:00
|
|
|
*view = (MSIVIEW*) wv;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|