2006-07-26 09:27:15 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
|
|
|
* Copyright 2006 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.
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "msi.h"
|
|
|
|
#include "msiquery.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "objidl.h"
|
|
|
|
#include "msipriv.h"
|
|
|
|
#include "query.h"
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
2006-07-26 09:27:15 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msidb);
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
typedef struct tagJOINTABLE
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
MSIVIEW *view;
|
|
|
|
UINT columns;
|
|
|
|
UINT rows;
|
|
|
|
UINT next_rows;
|
|
|
|
} JOINTABLE;
|
|
|
|
|
2006-07-26 09:27:15 +02:00
|
|
|
typedef struct tagMSIJOINVIEW
|
|
|
|
{
|
|
|
|
MSIVIEW view;
|
|
|
|
MSIDATABASE *db;
|
2007-08-01 23:25:45 +02:00
|
|
|
struct list tables;
|
|
|
|
UINT columns;
|
|
|
|
UINT rows;
|
2006-07-26 09:27:15 +02:00
|
|
|
} MSIJOINVIEW;
|
|
|
|
|
|
|
|
static UINT JOIN_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
|
|
|
|
{
|
|
|
|
MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
|
2007-08-01 23:25:45 +02:00
|
|
|
JOINTABLE *table;
|
|
|
|
UINT cols = 0;
|
|
|
|
UINT prev_rows = 1;
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
TRACE("%d, %d\n", row, col);
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
if (col == 0 || col > jv->columns)
|
2006-07-26 09:27:15 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
if (row >= jv->rows)
|
2006-07-26 09:27:15 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(table, &jv->tables, JOINTABLE, entry)
|
2006-07-26 09:27:15 +02:00
|
|
|
{
|
2007-08-01 23:25:45 +02:00
|
|
|
if (col <= cols + table->columns)
|
|
|
|
{
|
|
|
|
row = (row % (jv->rows / table->next_rows)) / prev_rows;
|
|
|
|
col -= cols;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-03-12 16:12:01 +01:00
|
|
|
prev_rows *= table->rows;
|
2007-08-01 23:25:45 +02:00
|
|
|
cols += table->columns;
|
2006-07-26 09:27:15 +02:00
|
|
|
}
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
return table->view->ops->fetch_int( table->view, row, col, val );
|
2006-07-26 09:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT JOIN_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm)
|
|
|
|
{
|
|
|
|
MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
|
2007-08-01 23:25:45 +02:00
|
|
|
JOINTABLE *table;
|
|
|
|
UINT cols = 0;
|
|
|
|
UINT prev_rows = 1;
|
2006-07-26 09:27:15 +02:00
|
|
|
|
|
|
|
TRACE("%p %d %d %p\n", jv, row, col, stm );
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
if (col == 0 || col > jv->columns)
|
2006-07-26 09:27:15 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
if (row >= jv->rows)
|
2006-07-26 09:27:15 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(table, &jv->tables, JOINTABLE, entry)
|
2006-07-26 09:27:15 +02:00
|
|
|
{
|
2007-08-01 23:25:45 +02:00
|
|
|
if (col <= cols + table->columns)
|
|
|
|
{
|
|
|
|
row = (row % (jv->rows / table->next_rows)) / prev_rows;
|
|
|
|
col -= cols;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-03-12 16:12:01 +01:00
|
|
|
prev_rows *= table->rows;
|
2007-08-01 23:25:45 +02:00
|
|
|
cols += table->columns;
|
2006-07-26 09:27:15 +02:00
|
|
|
}
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
return table->view->ops->fetch_stream( table->view, row, col, stm );
|
2006-07-26 09:27:15 +02:00
|
|
|
}
|
|
|
|
|
2007-07-27 02:40:38 +02:00
|
|
|
static UINT JOIN_get_row( struct tagMSIVIEW *view, UINT row, MSIRECORD **rec )
|
|
|
|
{
|
2007-08-01 23:25:45 +02:00
|
|
|
FIXME("(%p, %d, %p): stub!\n", view, row, rec);
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2007-07-27 02:40:38 +02:00
|
|
|
}
|
|
|
|
|
2006-07-26 09:27:15 +02:00
|
|
|
static UINT JOIN_execute( struct tagMSIVIEW *view, MSIRECORD *record )
|
|
|
|
{
|
|
|
|
MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
|
2007-08-01 23:25:45 +02:00
|
|
|
JOINTABLE *table;
|
|
|
|
UINT r, rows;
|
2006-07-26 09:27:15 +02:00
|
|
|
|
|
|
|
TRACE("%p %p\n", jv, record);
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(table, &jv->tables, JOINTABLE, entry)
|
2006-10-31 08:16:51 +01:00
|
|
|
{
|
2007-08-01 23:25:45 +02:00
|
|
|
table->view->ops->execute(table->view, NULL);
|
|
|
|
|
|
|
|
r = table->view->ops->get_dimensions(table->view, &table->rows, NULL);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("failed to get table dimensions\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* each table must have at least one row */
|
|
|
|
if (table->rows == 0)
|
|
|
|
{
|
|
|
|
jv->rows = 0;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (jv->rows == 0)
|
|
|
|
jv->rows = table->rows;
|
|
|
|
else
|
|
|
|
jv->rows *= table->rows;
|
2006-10-31 08:16:51 +01:00
|
|
|
}
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
rows = jv->rows;
|
|
|
|
LIST_FOR_EACH_ENTRY(table, &jv->tables, JOINTABLE, entry)
|
2006-10-31 08:16:51 +01:00
|
|
|
{
|
2007-08-01 23:25:45 +02:00
|
|
|
rows /= table->rows;
|
|
|
|
table->next_rows = rows;
|
2006-10-31 08:16:51 +01:00
|
|
|
}
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
return ERROR_SUCCESS;
|
2006-07-26 09:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT JOIN_close( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
|
2007-08-01 23:25:45 +02:00
|
|
|
JOINTABLE *table;
|
2006-07-26 09:27:15 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", jv );
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(table, &jv->tables, JOINTABLE, entry)
|
|
|
|
{
|
|
|
|
table->view->ops->close(table->view);
|
|
|
|
}
|
2006-07-26 09:27:15 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT JOIN_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
|
|
|
|
{
|
|
|
|
MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %p %p\n", jv, rows, cols );
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
if (cols)
|
|
|
|
*cols = jv->columns;
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
if (rows)
|
|
|
|
*rows = jv->rows;
|
2006-07-26 09:27:15 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT JOIN_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 )
|
2006-07-26 09:27:15 +02:00
|
|
|
{
|
|
|
|
MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
|
2007-08-01 23:25:45 +02:00
|
|
|
JOINTABLE *table;
|
|
|
|
UINT cols = 0;
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2009-10-18 18:41:41 +02:00
|
|
|
TRACE("%p %d %p %p %p %p\n", jv, n, name, type, temporary, table_name );
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
if (n == 0 || n > jv->columns)
|
2006-07-26 09:27:15 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
LIST_FOR_EACH_ENTRY(table, &jv->tables, JOINTABLE, entry)
|
|
|
|
{
|
|
|
|
if (n <= cols + table->columns)
|
2009-03-02 06:41:39 +01:00
|
|
|
return table->view->ops->get_column_info(table->view, n - cols,
|
2009-10-18 18:41:41 +02:00
|
|
|
name, type, temporary,
|
|
|
|
table_name);
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
cols += table->columns;
|
|
|
|
}
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2006-07-26 09:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT JOIN_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
|
2007-07-27 02:40:38 +02:00
|
|
|
MSIRECORD *rec, UINT row )
|
2006-07-26 09:27:15 +02:00
|
|
|
{
|
2007-08-01 23:25:45 +02:00
|
|
|
TRACE("%p %d %p\n", view, eModifyMode, rec);
|
2006-07-26 09:27:15 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT JOIN_delete( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
|
2009-12-14 04:36:31 +01:00
|
|
|
struct list *item, *cursor;
|
2006-07-26 09:27:15 +02:00
|
|
|
|
|
|
|
TRACE("%p\n", jv );
|
|
|
|
|
2009-12-14 04:36:31 +01:00
|
|
|
LIST_FOR_EACH_SAFE(item, cursor, &jv->tables)
|
2007-08-01 23:25:45 +02:00
|
|
|
{
|
2009-12-14 04:36:31 +01:00
|
|
|
JOINTABLE* table = LIST_ENTRY(item, JOINTABLE, entry);
|
|
|
|
|
|
|
|
list_remove(&table->entry);
|
2007-08-01 23:25:45 +02:00
|
|
|
table->view->ops->delete(table->view);
|
|
|
|
table->view = NULL;
|
2009-12-14 04:36:31 +01:00
|
|
|
msi_free(table);
|
2007-08-01 23:25:45 +02:00
|
|
|
}
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
msi_free(jv);
|
2006-08-29 10:07:45 +02:00
|
|
|
|
2006-07-26 09:27:15 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT JOIN_find_matching_rows( struct tagMSIVIEW *view, UINT col,
|
|
|
|
UINT val, UINT *row, MSIITERHANDLE *handle )
|
|
|
|
{
|
|
|
|
MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
|
2007-08-01 23:25:45 +02:00
|
|
|
UINT i, row_value;
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
TRACE("%p, %d, %u, %p\n", view, col, val, *handle);
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
if (col == 0 || col > jv->columns)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
for (i = (UINT)*handle; i < jv->rows; i++)
|
|
|
|
{
|
|
|
|
if (view->ops->fetch_int( view, i, col, &row_value ) != ERROR_SUCCESS)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (row_value == val)
|
|
|
|
{
|
|
|
|
*row = i;
|
|
|
|
(*(UINT *)handle) = i + 1;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_NO_MORE_ITEMS;
|
2006-07-26 09:27:15 +02:00
|
|
|
}
|
|
|
|
|
2007-12-18 02:35:31 +01:00
|
|
|
static UINT JOIN_sort(struct tagMSIVIEW *view, column_info *columns)
|
|
|
|
{
|
|
|
|
MSIJOINVIEW *jv = (MSIJOINVIEW *)view;
|
|
|
|
JOINTABLE *table;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("%p %p\n", view, columns);
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(table, &jv->tables, JOINTABLE, entry)
|
|
|
|
{
|
|
|
|
r = table->view->ops->sort(table->view, columns);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-07-26 09:27:15 +02:00
|
|
|
static const MSIVIEWOPS join_ops =
|
|
|
|
{
|
|
|
|
JOIN_fetch_int,
|
|
|
|
JOIN_fetch_stream,
|
2007-07-27 02:40:38 +02:00
|
|
|
JOIN_get_row,
|
2006-10-26 10:08:43 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2007-06-18 22:49:31 +02:00
|
|
|
NULL,
|
2006-07-26 09:27:15 +02:00
|
|
|
JOIN_execute,
|
|
|
|
JOIN_close,
|
|
|
|
JOIN_get_dimensions,
|
|
|
|
JOIN_get_column_info,
|
|
|
|
JOIN_modify,
|
|
|
|
JOIN_delete,
|
2007-07-19 03:21:00 +02:00
|
|
|
JOIN_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
|
|
|
JOIN_sort,
|
2008-10-02 22:56:54 +02:00
|
|
|
NULL,
|
2006-07-26 09:27:15 +02:00
|
|
|
};
|
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
UINT JOIN_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR tables )
|
2006-07-26 09:27:15 +02:00
|
|
|
{
|
|
|
|
MSIJOINVIEW *jv = NULL;
|
|
|
|
UINT r = ERROR_SUCCESS;
|
2007-08-01 23:25:45 +02:00
|
|
|
JOINTABLE *table;
|
|
|
|
LPWSTR ptr;
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
TRACE("%p (%s)\n", jv, debugstr_w(tables) );
|
2006-07-26 09:27:15 +02:00
|
|
|
|
|
|
|
jv = msi_alloc_zero( sizeof *jv );
|
|
|
|
if( !jv )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
/* fill the structure */
|
|
|
|
jv->view.ops = &join_ops;
|
|
|
|
jv->db = db;
|
2007-08-01 23:25:45 +02:00
|
|
|
jv->columns = 0;
|
|
|
|
jv->rows = 0;
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
list_init(&jv->tables);
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
while (*tables)
|
2006-07-26 09:27:15 +02:00
|
|
|
{
|
2007-08-01 23:25:45 +02:00
|
|
|
if ((ptr = strchrW(tables, ' ')))
|
|
|
|
*ptr = '\0';
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
table = msi_alloc(sizeof(JOINTABLE));
|
|
|
|
if (!table)
|
2009-05-28 15:04:17 +02:00
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
2006-07-26 09:27:15 +02:00
|
|
|
|
2007-08-01 23:25:45 +02:00
|
|
|
r = TABLE_CreateView( db, tables, &table->view );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
2008-04-03 01:31:18 +02:00
|
|
|
WARN("can't create table: %s\n", debugstr_w(tables));
|
|
|
|
r = ERROR_BAD_QUERY_SYNTAX;
|
2007-08-01 23:25:45 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = table->view->ops->get_dimensions( table->view, NULL, &table->columns );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
ERR("can't get table dimensions\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
jv->columns += table->columns;
|
|
|
|
|
|
|
|
list_add_head( &jv->tables, &table->entry );
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
break;
|
|
|
|
|
|
|
|
tables = ptr + 1;
|
2006-07-26 09:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*view = &jv->view;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
end:
|
|
|
|
jv->view.ops->delete( &jv->view );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|