2003-08-13 01:27:48 +00:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
2004-06-30 18:18:27 +00:00
|
|
|
* Copyright 2002-2004 Mike McCormack for CodeWeavers
|
2003-08-13 01:27:48 +00: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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2003-08-13 01:27:48 +00: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 14:24:21 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msidb);
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* below is the query interface to a table */
|
|
|
|
|
|
|
|
typedef struct tagMSISELECTVIEW
|
|
|
|
{
|
|
|
|
MSIVIEW view;
|
|
|
|
MSIDATABASE *db;
|
|
|
|
MSIVIEW *table;
|
|
|
|
UINT num_cols;
|
|
|
|
UINT max_cols;
|
|
|
|
UINT cols[1];
|
|
|
|
} MSISELECTVIEW;
|
|
|
|
|
|
|
|
static UINT SELECT_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
|
|
|
|
{
|
|
|
|
MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %d %d %p\n", sv, row, col, val );
|
|
|
|
|
|
|
|
if( !sv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if( (col==0) || (col>sv->num_cols) )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
col = sv->cols[ col - 1 ];
|
|
|
|
|
|
|
|
return sv->table->ops->fetch_int( sv->table, row, col, val );
|
|
|
|
}
|
|
|
|
|
2004-07-06 18:56:12 +00:00
|
|
|
static UINT SELECT_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm)
|
|
|
|
{
|
|
|
|
MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %d %d %p\n", sv, row, col, stm );
|
|
|
|
|
|
|
|
if( !sv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if( (col==0) || (col>sv->num_cols) )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
col = sv->cols[ col - 1 ];
|
|
|
|
|
|
|
|
return sv->table->ops->fetch_stream( sv->table, row, col, stm );
|
|
|
|
}
|
|
|
|
|
2004-06-30 18:18:27 +00:00
|
|
|
static UINT SELECT_set_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT val )
|
|
|
|
{
|
|
|
|
MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %d %d %04x\n", sv, row, col, val );
|
|
|
|
|
|
|
|
if( !sv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if( (col==0) || (col>sv->num_cols) )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
col = sv->cols[ col - 1 ];
|
|
|
|
|
|
|
|
return sv->table->ops->set_int( sv->table, row, col, val );
|
|
|
|
}
|
|
|
|
|
2005-08-24 11:10:23 +00:00
|
|
|
static UINT SELECT_insert_row( struct tagMSIVIEW *view, MSIRECORD *record )
|
2004-06-30 18:18:27 +00:00
|
|
|
{
|
|
|
|
MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
|
|
|
|
|
2005-08-24 11:10:23 +00:00
|
|
|
TRACE("%p %p\n", sv, record );
|
2004-06-30 18:18:27 +00:00
|
|
|
|
|
|
|
if( !sv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2005-08-24 11:10:23 +00:00
|
|
|
return sv->table->ops->insert_row( sv->table, record );
|
2004-06-30 18:18:27 +00:00
|
|
|
}
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
static UINT SELECT_execute( struct tagMSIVIEW *view, MSIRECORD *record )
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
|
|
|
MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
|
|
|
|
|
2004-07-09 22:25:34 +00:00
|
|
|
TRACE("%p %p\n", sv, record);
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
if( !sv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return sv->table->ops->execute( sv->table, record );
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT SELECT_close( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p\n", sv );
|
|
|
|
|
|
|
|
if( !sv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return sv->table->ops->close( sv->table );
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT SELECT_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
|
|
|
|
{
|
|
|
|
MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %p %p\n", sv, rows, cols );
|
|
|
|
|
|
|
|
if( !sv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if( cols )
|
|
|
|
*cols = sv->num_cols;
|
|
|
|
|
|
|
|
return sv->table->ops->get_dimensions( sv->table, rows, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT SELECT_get_column_info( struct tagMSIVIEW *view,
|
|
|
|
UINT n, LPWSTR *name, UINT *type )
|
|
|
|
{
|
|
|
|
MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %d %p %p\n", sv, n, name, type );
|
|
|
|
|
|
|
|
if( !sv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if( (n==0) || (n>sv->num_cols) )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
n = sv->cols[ n - 1 ];
|
|
|
|
|
|
|
|
return sv->table->ops->get_column_info( sv->table, n, name, type );
|
|
|
|
}
|
|
|
|
|
2005-02-08 13:44:25 +00:00
|
|
|
static UINT SELECT_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
|
|
|
|
MSIRECORD *rec )
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
|
|
|
MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
|
|
|
|
|
2005-02-08 13:44:25 +00:00
|
|
|
TRACE("%p %d %p\n", sv, eModifyMode, rec );
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
if( !sv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2005-02-08 13:44:25 +00:00
|
|
|
return sv->table->ops->modify( sv->table, eModifyMode, rec );
|
2003-08-13 01:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT SELECT_delete( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p\n", sv );
|
|
|
|
|
|
|
|
if( sv->table )
|
|
|
|
sv->table->ops->delete( sv->table );
|
2005-09-26 10:55:18 +00:00
|
|
|
sv->table = NULL;
|
2003-08-13 01:27:48 +00:00
|
|
|
|
2005-09-20 11:57:19 +00:00
|
|
|
msi_free( sv );
|
2003-08-13 01:27:48 +00:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MSIVIEWOPS select_ops =
|
|
|
|
{
|
|
|
|
SELECT_fetch_int,
|
2004-07-06 18:56:12 +00:00
|
|
|
SELECT_fetch_stream,
|
2004-06-30 18:18:27 +00:00
|
|
|
SELECT_set_int,
|
|
|
|
SELECT_insert_row,
|
2003-08-13 01:27:48 +00:00
|
|
|
SELECT_execute,
|
|
|
|
SELECT_close,
|
|
|
|
SELECT_get_dimensions,
|
|
|
|
SELECT_get_column_info,
|
|
|
|
SELECT_modify,
|
|
|
|
SELECT_delete
|
|
|
|
};
|
|
|
|
|
2005-05-29 20:17:16 +00:00
|
|
|
static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPCWSTR name )
|
2003-08-13 01:27:48 +00:00
|
|
|
{
|
|
|
|
UINT r, n=0;
|
|
|
|
MSIVIEW *table;
|
|
|
|
|
|
|
|
TRACE("%p adding %s\n", sv, debugstr_w( name ) );
|
|
|
|
|
|
|
|
if( sv->view.ops != &select_ops )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
table = sv->table;
|
|
|
|
if( !table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
if( !table->ops->get_dimensions )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
if( !table->ops->get_column_info )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if( sv->num_cols >= sv->max_cols )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
r = VIEW_find_column( table, name, &n );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
sv->cols[sv->num_cols] = n;
|
|
|
|
TRACE("Translating column %s from %d -> %d\n",
|
|
|
|
debugstr_w( name ), sv->num_cols, n);
|
|
|
|
|
|
|
|
sv->num_cols++;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2004-06-30 18:18:27 +00:00
|
|
|
|
|
|
|
UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table,
|
2005-05-29 20:17:16 +00:00
|
|
|
column_info *columns )
|
2004-06-30 18:18:27 +00:00
|
|
|
{
|
|
|
|
MSISELECTVIEW *sv = NULL;
|
|
|
|
UINT count = 0, r;
|
|
|
|
|
|
|
|
TRACE("%p\n", sv );
|
|
|
|
|
|
|
|
r = table->ops->get_dimensions( table, NULL, &count );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
ERR("can't get table dimensions\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2005-09-20 11:57:19 +00:00
|
|
|
sv = msi_alloc_zero( sizeof *sv + count*sizeof (UINT) );
|
2004-06-30 18:18:27 +00:00
|
|
|
if( !sv )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
/* fill the structure */
|
|
|
|
sv->view.ops = &select_ops;
|
|
|
|
sv->db = db;
|
|
|
|
sv->table = table;
|
|
|
|
sv->num_cols = 0;
|
|
|
|
sv->max_cols = count;
|
|
|
|
|
|
|
|
while( columns )
|
|
|
|
{
|
2005-05-29 20:17:16 +00:00
|
|
|
r = SELECT_AddColumn( sv, columns->column );
|
2004-06-30 18:18:27 +00:00
|
|
|
if( r )
|
|
|
|
break;
|
|
|
|
columns = columns->next;
|
|
|
|
}
|
|
|
|
|
2005-09-26 10:55:18 +00:00
|
|
|
if( r == ERROR_SUCCESS )
|
|
|
|
*view = &sv->view;
|
|
|
|
else
|
|
|
|
msi_free( sv );
|
2004-06-30 18:18:27 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|