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
|
|
|
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 )
|
|
|
|
{
|
2010-01-18 13:09:46 +01:00
|
|
|
MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %d %p\n", jv, row, rec);
|
|
|
|
|
|
|
|
return msi_view_get_row( jv->db, view, row, rec );
|
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;
|
|
|
|
}
|
|
|
|
|
2011-07-27 10:53:10 +02:00
|
|
|
static UINT JOIN_get_column_info( struct tagMSIVIEW *view, UINT n, LPCWSTR *name,
|
|
|
|
UINT *type, BOOL *temporary, LPCWSTR *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);
|
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
|
|
|
}
|
|
|
|
|
2010-01-22 12:49:11 +01:00
|
|
|
static UINT join_find_row( MSIJOINVIEW *jv, MSIRECORD *rec, UINT *row )
|
2006-07-26 09:27:15 +02:00
|
|
|
{
|
2010-01-22 12:49:11 +01:00
|
|
|
LPCWSTR str;
|
2010-09-29 09:58:02 +02:00
|
|
|
UINT r, i, id, data;
|
2010-01-22 12:49:11 +01:00
|
|
|
|
|
|
|
str = MSI_RecordGetString( rec, 1 );
|
2010-09-29 09:58:02 +02:00
|
|
|
r = msi_string2idW( jv->db->strings, str, &id );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2010-01-22 12:49:11 +01:00
|
|
|
|
|
|
|
for (i = 0; i < jv->rows; i++)
|
|
|
|
{
|
|
|
|
JOIN_fetch_int( &jv->view, i, 1, &data );
|
|
|
|
|
|
|
|
if (data == id)
|
|
|
|
{
|
|
|
|
*row = i;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-26 09:27:15 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2010-01-22 12:49:11 +01:00
|
|
|
static UINT JOIN_set_row( struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UINT mask )
|
|
|
|
{
|
|
|
|
MSIJOINVIEW *jv = (MSIJOINVIEW*)view;
|
|
|
|
JOINTABLE *table;
|
|
|
|
UINT i, reduced_mask = 0, r = ERROR_SUCCESS, offset = 0, col_count;
|
|
|
|
MSIRECORD *reduced;
|
|
|
|
|
|
|
|
TRACE("%p %d %p %u %08x\n", jv, row, rec, rec->count, mask );
|
|
|
|
|
|
|
|
if (mask >= 1 << jv->columns)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(table, &jv->tables, JOINTABLE, entry)
|
|
|
|
{
|
|
|
|
r = table->view->ops->get_dimensions( table->view, NULL, &col_count );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
reduced = MSI_CreateRecord( col_count );
|
|
|
|
if (!reduced)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
for (i = 0; i < col_count; i++)
|
|
|
|
{
|
|
|
|
r = MSI_RecordCopyField( rec, i + offset + 1, reduced, i + 1 );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += col_count;
|
|
|
|
reduced_mask = mask >> (jv->columns - offset) & ((1 << col_count) - 1);
|
|
|
|
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
r = table->view->ops->set_row( table->view, row, reduced, reduced_mask );
|
|
|
|
|
|
|
|
msiobj_release( &reduced->hdr );
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT join_modify_update( struct tagMSIVIEW *view, MSIRECORD *rec )
|
|
|
|
{
|
|
|
|
MSIJOINVIEW *jv = (MSIJOINVIEW *)view;
|
|
|
|
UINT r, row;
|
|
|
|
|
|
|
|
r = join_find_row( jv, rec, &row );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return JOIN_set_row( view, row, rec, (1 << jv->columns) - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT JOIN_modify( struct tagMSIVIEW *view, MSIMODIFY mode, MSIRECORD *rec, UINT row )
|
|
|
|
{
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("%p %d %p %u\n", view, mode, rec, row);
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
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, mode, rec, row );
|
|
|
|
r = ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-07-26 09:27:15 +02:00
|
|
|
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;
|
|
|
|
|
2009-12-30 21:24:27 +01:00
|
|
|
for (i = PtrToUlong(*handle); i < jv->rows; i++)
|
2007-08-01 23:25:45 +02:00
|
|
|
{
|
|
|
|
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));
|
2009-12-16 03:18:40 +01:00
|
|
|
msi_free(table);
|
2008-04-03 01:31:18 +02:00
|
|
|
r = ERROR_BAD_QUERY_SYNTAX;
|
2007-08-01 23:25:45 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2009-12-16 03:18:40 +01:00
|
|
|
r = table->view->ops->get_dimensions( table->view, NULL,
|
|
|
|
&table->columns );
|
2007-08-01 23:25:45 +02:00
|
|
|
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;
|
|
|
|
}
|