2004-07-04 02:30:02 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
|
|
|
* Copyright 2004 Mike McCormack for CodeWeavers
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2007-05-04 12:08:15 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2004-07-04 02:30:02 +02:00
|
|
|
* 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
|
2004-07-04 02:30:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#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);
|
2004-07-04 02:30:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* below is the query interface to a table */
|
|
|
|
|
|
|
|
typedef struct tagMSIUPDATEVIEW
|
|
|
|
{
|
|
|
|
MSIVIEW view;
|
|
|
|
MSIDATABASE *db;
|
|
|
|
MSIVIEW *wv;
|
2005-05-29 22:17:16 +02:00
|
|
|
column_info *vals;
|
2004-07-04 02:30:02 +02:00
|
|
|
} MSIUPDATEVIEW;
|
|
|
|
|
|
|
|
static UINT UPDATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
|
|
|
|
{
|
|
|
|
MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %d %d %p\n", uv, row, col, val );
|
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
static UINT UPDATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
|
2004-07-04 02:30:02 +02:00
|
|
|
{
|
|
|
|
MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
|
2006-10-26 10:09:47 +02:00
|
|
|
UINT i, r, col_count = 0, row_count = 0;
|
2006-10-26 07:08:38 +02:00
|
|
|
MSIRECORD *values = NULL;
|
2008-01-09 06:16:07 +01:00
|
|
|
MSIRECORD *where = NULL;
|
2004-07-04 02:30:02 +02:00
|
|
|
MSIVIEW *wv;
|
2008-01-09 06:16:07 +01:00
|
|
|
UINT cols_count, where_count;
|
|
|
|
column_info *col = uv->vals;
|
2004-07-04 02:30:02 +02:00
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
TRACE("%p %p\n", uv, record );
|
2004-07-04 02:30:02 +02:00
|
|
|
|
2008-01-09 06:16:07 +01:00
|
|
|
/* extract the where markers from the record */
|
|
|
|
if (record)
|
|
|
|
{
|
|
|
|
r = MSI_RecordGetFieldCount(record);
|
|
|
|
|
|
|
|
for (i = 0; col; col = col->next)
|
|
|
|
i++;
|
|
|
|
|
|
|
|
cols_count = i;
|
|
|
|
where_count = r - i;
|
|
|
|
|
|
|
|
if (where_count > 0)
|
|
|
|
{
|
|
|
|
where = MSI_CreateRecord(where_count);
|
|
|
|
|
|
|
|
if (where)
|
|
|
|
for (i = 1; i <= where_count; i++)
|
|
|
|
MSI_RecordCopyField(record, cols_count + i, where, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-04 02:30:02 +02:00
|
|
|
wv = uv->wv;
|
|
|
|
if( !wv )
|
2008-01-09 06:16:07 +01:00
|
|
|
{
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
2004-07-04 02:30:02 +02:00
|
|
|
|
2008-01-09 06:16:07 +01:00
|
|
|
r = wv->ops->execute( wv, where );
|
2004-07-04 02:30:02 +02:00
|
|
|
TRACE("tv execute returned %x\n", r);
|
|
|
|
if( r )
|
2008-01-09 06:16:07 +01:00
|
|
|
goto done;
|
2004-07-04 02:30:02 +02:00
|
|
|
|
|
|
|
r = wv->ops->get_dimensions( wv, &row_count, &col_count );
|
|
|
|
if( r )
|
2008-01-09 06:16:07 +01:00
|
|
|
goto done;
|
2004-07-04 02:30:02 +02:00
|
|
|
|
2006-10-26 07:08:38 +02:00
|
|
|
values = msi_query_merge_record( col_count, uv->vals, record );
|
|
|
|
if (!values)
|
2008-01-09 06:16:07 +01:00
|
|
|
{
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
goto done;
|
|
|
|
}
|
2006-10-26 07:08:38 +02:00
|
|
|
|
2006-10-26 10:09:47 +02:00
|
|
|
for ( i=0; i<row_count; i++ )
|
2004-07-04 02:30:02 +02:00
|
|
|
{
|
2006-10-26 10:09:47 +02:00
|
|
|
r = wv->ops->set_row( wv, i, values, (1 << col_count) - 1 );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
2004-07-04 02:30:02 +02:00
|
|
|
}
|
|
|
|
|
2008-01-09 06:16:07 +01:00
|
|
|
done:
|
|
|
|
if ( where ) msiobj_release( &where->hdr );
|
|
|
|
if ( values ) msiobj_release( &values->hdr );
|
2006-10-26 07:08:38 +02:00
|
|
|
|
2006-10-26 10:09:47 +02:00
|
|
|
return r;
|
2004-07-04 02:30:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static UINT UPDATE_close( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
|
|
|
|
MSIVIEW *wv;
|
|
|
|
|
|
|
|
TRACE("%p\n", uv);
|
|
|
|
|
|
|
|
wv = uv->wv;
|
|
|
|
if( !wv )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return wv->ops->close( wv );
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT UPDATE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
|
|
|
|
{
|
|
|
|
MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
|
|
|
|
MSIVIEW *wv;
|
|
|
|
|
|
|
|
TRACE("%p %p %p\n", uv, rows, cols );
|
|
|
|
|
|
|
|
wv = uv->wv;
|
|
|
|
if( !wv )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return wv->ops->get_dimensions( wv, rows, cols );
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT UPDATE_get_column_info( struct tagMSIVIEW *view,
|
2009-10-18 18:41:41 +02:00
|
|
|
UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
|
|
|
|
LPWSTR* table_name )
|
2004-07-04 02:30:02 +02:00
|
|
|
{
|
|
|
|
MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
|
|
|
|
MSIVIEW *wv;
|
|
|
|
|
2009-10-18 18:41:41 +02:00
|
|
|
TRACE("%p %d %p %p %p %p\n", uv, n, name, type, temporary, table_name );
|
2004-07-04 02:30:02 +02:00
|
|
|
|
|
|
|
wv = uv->wv;
|
|
|
|
if( !wv )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2009-10-18 18:41:41 +02:00
|
|
|
return wv->ops->get_column_info( wv, n, name, type, temporary, table_name );
|
2004-07-04 02:30:02 +02:00
|
|
|
}
|
|
|
|
|
2005-02-08 14:44:25 +01:00
|
|
|
static UINT UPDATE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
|
2007-07-27 02:40:38 +02:00
|
|
|
MSIRECORD *rec, UINT row )
|
2004-07-04 02:30:02 +02:00
|
|
|
{
|
|
|
|
MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
|
|
|
|
|
2005-02-08 14:44:25 +01:00
|
|
|
TRACE("%p %d %p\n", uv, eModifyMode, rec );
|
2004-07-04 02:30:02 +02:00
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT UPDATE_delete( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSIUPDATEVIEW *uv = (MSIUPDATEVIEW*)view;
|
|
|
|
MSIVIEW *wv;
|
|
|
|
|
|
|
|
TRACE("%p\n", uv );
|
|
|
|
|
|
|
|
wv = uv->wv;
|
|
|
|
if( wv )
|
|
|
|
wv->ops->delete( wv );
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_release( &uv->db->hdr );
|
2005-09-20 13:57:19 +02:00
|
|
|
msi_free( uv );
|
2004-07-04 02:30:02 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-03-18 17:12:15 +01:00
|
|
|
static UINT UPDATE_find_matching_rows( struct tagMSIVIEW *view, UINT col, UINT val, UINT *row, MSIITERHANDLE *handle )
|
|
|
|
{
|
|
|
|
TRACE("%p %d %d %p\n", view, col, val, *handle );
|
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2004-07-04 02:30:02 +02:00
|
|
|
|
2006-11-29 11:03:14 +01:00
|
|
|
static const MSIVIEWOPS update_ops =
|
2004-07-04 02:30:02 +02:00
|
|
|
{
|
|
|
|
UPDATE_fetch_int,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-07-06 20:56:12 +02:00
|
|
|
NULL,
|
2007-06-18 22:49:31 +02:00
|
|
|
NULL,
|
2007-07-27 02:40:38 +02:00
|
|
|
NULL,
|
2004-07-04 02:30:02 +02:00
|
|
|
UPDATE_execute,
|
|
|
|
UPDATE_close,
|
|
|
|
UPDATE_get_dimensions,
|
|
|
|
UPDATE_get_column_info,
|
|
|
|
UPDATE_modify,
|
2006-03-18 17:12:15 +01:00
|
|
|
UPDATE_delete,
|
2007-07-19 03:21:00 +02:00
|
|
|
UPDATE_find_matching_rows,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2007-07-20 23:01:13 +02:00
|
|
|
NULL,
|
2007-07-21 03:41:16 +02:00
|
|
|
NULL,
|
2008-10-02 22:56:54 +02:00
|
|
|
NULL,
|
2004-07-04 02:30:02 +02:00
|
|
|
};
|
|
|
|
|
2007-06-13 23:36:31 +02:00
|
|
|
UINT UPDATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPCWSTR table,
|
2005-05-29 22:17:16 +02:00
|
|
|
column_info *columns, struct expr *expr )
|
2004-07-04 02:30:02 +02:00
|
|
|
{
|
|
|
|
MSIUPDATEVIEW *uv = NULL;
|
|
|
|
UINT r;
|
|
|
|
MSIVIEW *tv = NULL, *sv = NULL, *wv = NULL;
|
|
|
|
|
|
|
|
TRACE("%p\n", uv );
|
|
|
|
|
|
|
|
r = TABLE_CreateView( db, table, &tv );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
2006-10-26 10:40:47 +02:00
|
|
|
if (expr)
|
2004-07-04 02:30:02 +02:00
|
|
|
{
|
2006-10-26 10:40:47 +02:00
|
|
|
/* add conditions first */
|
|
|
|
r = WHERE_CreateView( db, &wv, tv, expr );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
tv->ops->delete( tv );
|
|
|
|
return r;
|
|
|
|
}
|
2004-07-04 02:30:02 +02:00
|
|
|
}
|
2006-10-26 10:40:47 +02:00
|
|
|
else
|
|
|
|
wv = tv;
|
|
|
|
|
2004-07-04 02:30:02 +02:00
|
|
|
/* then select the columns we want */
|
2005-05-29 22:17:16 +02:00
|
|
|
r = SELECT_CreateView( db, &sv, wv, columns );
|
2004-07-04 02:30:02 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
2005-09-26 12:55:18 +02:00
|
|
|
wv->ops->delete( wv );
|
2004-07-04 02:30:02 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2005-09-20 13:57:19 +02:00
|
|
|
uv = msi_alloc_zero( sizeof *uv );
|
2004-07-04 02:30:02 +02:00
|
|
|
if( !uv )
|
2009-05-28 15:04:17 +02:00
|
|
|
{
|
|
|
|
wv->ops->delete( wv );
|
2004-07-04 02:30:02 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2009-05-28 15:04:17 +02:00
|
|
|
}
|
2004-07-04 02:30:02 +02:00
|
|
|
|
|
|
|
/* fill the structure */
|
|
|
|
uv->view.ops = &update_ops;
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_addref( &db->hdr );
|
2004-07-04 02:30:02 +02:00
|
|
|
uv->db = db;
|
2005-05-29 22:17:16 +02:00
|
|
|
uv->vals = columns;
|
2004-07-04 02:30:02 +02:00
|
|
|
uv->wv = sv;
|
|
|
|
*view = (MSIVIEW*) uv;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|