mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +00:00
f4be6dc36f
* [MSIEXEC] Sync msiexec to wine-9.8 * [WINESYNC] msi: Disable FS redirection for temporary file in cabinet_copy_file(). wine commit id a58c6251870dfb7d214464e709bbbc9ca649b900 by Paul Gofman <pgofman@codeweavers.com> * [WINESYNC] msi/tests: Correct a couple of failure messages in test_msirecord. wine commit id 2fde0a3f5c233b0ea1637f409998ce4ee85d28a7 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Use the wcsdup function instead of reimplementing it. wine commit id 7cc7a6defc08d4de7574b7a75d574c3ab1f32db8 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Use _O_* constants from fcntl.h instead of redefining them. wine commit id b07c95e79cdf6ae26c5170daa481ad160e0ce76a by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Remove wrappers around CRT memory allocation functions. wine commit id d920aa81ad0c4618c27ebd7e9863618e988328e0 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Initialize all members of WINTRUST_DATA. The pSignatureSettings field was not unitilized so it got a random value from the stack causing a later crash when it was dereferenced in Wintrust (SoftPubloadSignature). wine commit id 904bedb3e96bc68101652e151db102532399abe8 by Philip K. Gisslow <ripxorip@gmail.com> * [WINESYNC] msi: Fix memory leak on realloc failure in create_diff_row_query (cppcheck). wine commit id 3e231d0f36a56ce991c7edbb6ae7845094e8417e by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Fix memory leak on realloc failure in msi_get_window_text (cppcheck). wine commit id 6c1dd0f2c5669e084eb1f84571c38761a97c0970 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Fix memory leak on realloc failure in search_directory (cppcheck). wine commit id d394df4a30feb685927908fce2887bf5496b5d66 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] ntdll: Default to Windows 10. wine commit id 69154f0329aec4fb64886a0689da198b5323dcde by Hans Leidekker <hans@codeweavers.com> * [MSI] Fix build * [WINESYNC] Update winesync file * [WINESYNC] msi/tests: Avoid test failures when running with insufficient rights. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51040 wine commit id 79ec3d9fb8551e84e9ff71dcf18861430246278a by Hans Leidekker <hans@codeweavers.com> * [WINESYNC] msi: Install and patch global assemblies in InstallFinalize. Installing global assemblies requires assembly caches to be initialized and this is no longer the case after the PE conversion (builtin fusion no longer loads if the dll is not present on disk). The next patch changes msi to perform late initialization of the assembly caches so that native fusion can be loaded once it's installed by .NET installers. However, there's no guarantee that all necessary files and registry keys are installed before the InstallFiles and PatchFiles actions are executed. Therefore this patch moves the parts of these actions handling global assemblies to InstallFinalize. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51345 wine commit id 2c450fd6215c0da4685143f97ece8b6db0f54a0b by Hans Leidekker <hans@codeweavers.com> * [WINESYNC] msi: Perform late initialization of the assembly caches. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51345 wine commit id d9d700f3328f00ec419571df0e02cef208fa1e7b by Hans Leidekker <hans@codeweavers.com> * [WINESYNC] msi: Remove msi_ prefix from static functions. wine commit id 3611398b7575177b91e8162a84ebca977c50c2f5 by Hans Leidekker <hans@codeweavers.com> * [WINESYNC] msi: Get rid of unnecessary typedefs. wine commit id 258012742512a4072265fcc47826c52319bd37ab by Hans Leidekker <hans@codeweavers.com> * [WINESYNC] msi: Handle memory allocation failure in get_link_file (cppcheck). wine commit id 687c4f5c8dc65def6fc066d5d802d7448db70d7f by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Annotate memory allocation functions with __WINE_(DEALLOC|MALLOC). wine commit id 9df04bfdb03a3017f532e70a047ee83290dbc257 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi/tests: Fix the ok() formats so they match the size of their arguments. wine commit id b6fb1b8983af7644b78bb0ba5fb9d18a1f0822f1 by Francois Gouget <fgouget@codeweavers.com> * [WINESYNC] msi/tests: Ok_() takes printf-style arguments. This lets the compiler check that the format and argument sizes match. wine commit id a80b183af74194a06af3281ee272590a7134b7f1 by Francois Gouget <fgouget@codeweavers.com> * [WINESYNC] msi: Return ERROR_OUTOFMEMORY if calloc fails in TransformView_Create (scan-build). Instead of ERROR_SUCCESS. wine commit id daa20d9d636057d7009ff3652a8577b423d23fcf by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Make TransformView_Create static. wine commit id 1da5618cbac1214082bfb897dc81804d14fc6e9e by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Fix memory leak in ready_media (scan-build). base_url was never freed, and can simply be enlarged instead of copying it to a new buffer. wine commit id c39f785b34692ee994b2449cc17a96815517e9bf by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Fix memory leak on error path in MSI_ProcessMessage (scan-build). wine commit id d06b3fd5274b056c720e2fb42eb189052d99404d by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Release record instead of free. ../dlls/msi/dialog.c:4476:11: warning: attempt to call free on non-heap object 'hdr' [-Wfree-nonheap-object] free( &rec->hdr ); ^ wine commit id 7b3690dd7399cd64123554c8a6fc7e35dcbebbe1 by Daniel Lehman <dlehman25@gmail.com> * [WINESYNC] include: Remove redundant __WINE_USE_MSVCRT checks. wine commit id 93630ce14ebf16333fda8481b5ede6f587eb32ca by Alexandre Julliard <julliard@winehq.org> * [WINESYNC] msi: Fix memory leak on error path in MSI_OpenPackageW (scan-build). wine commit id 4db2ffa60e16e06b4f6ef89fcc4c73229f4446b1 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Fix double free on error paths in TransformView_Create (scan-build). If TransformView_Create returns an error, it should not return a pointer that table_load_transform will try to free. wine commit id 0653409e0631582d89edaab0ac516994710dae1a by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Fix memory leaks in HANDLE_CustomType23 (scan-build). wine commit id 993f4d48d23477e70e92256890c77687a1c4ba08 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Reject shorter/longer lines in MsiDatabaseImportA. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54532 Signed-off-by: David Kahurani <k.kahurani@gmail.com> wine commit id e1ddc58a259d80f16bf1e62f23428775e1b070a0 by David Kahurani <k.kahurani@gmail.com> * [WINESYNC] msi: Convert newlines to alternate representation when exporting. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54532 Signed-off-by: David Kahurani <k.kahurani@gmail.com> wine commit id 60e4f8a261ae9044aafa9c4eec2a3f2aec6481b5 by David Kahurani <k.kahurani@gmail.com> * [WINESYNC] msi: Remove DECLSPEC_HIDDEN usage. wine commit id 51049c95a242f1553562a442142e813e37cee233 by Alistair Leslie-Hughes <leslie_alistair@hotmail.com> * [MSI] remove DECLSPEC_HIDDEN * [WINESYNC] msi: Fully initialize the control structure in dialog_line_control(). Fixes: 76606eaea034c51a73190aac92e75d8b20e82164 Fixes: 174b7b51ac9e57c6cfa8f48e62bbf468ae3b1f24 wine commit id 735584076efafc29673e0c9418a64343634f9aa5 by Jinoh Kang <jinoh.kang.kr@gmail.com> * [WINESYNC] msi: Make insertion order of line controls consistent with other controls. Fixes: 2c5bd49297f79d9941a256d8ec61e0eb2bf9bf9c wine commit id 3eceda2f2a77754f0bf93ea33018e8ef49e82669 by Jinoh Kang <jinoh.kang.kr@gmail.com> * [WINESYNC] msi: Don't open code dialog_add_control() in dialog_line_control(). Commit b1cc87cb656 ("msi: The line control has a height of exactly 2 device units.", 2007-12-16) open-coded the body of (msi_)dialog_add_control() inside dialog_line_control() modulo the height override. Except the fixed height, line controls have nothing special compared to other controls. Thus, there is little merit in open-coding it. Also, dialog_line_control() has bit-rotted over time; it already missed a few changes that were done to any other controls. Fix this by just using dialog_add_control(). Also, add a special case logic just for line controls. wine commit id 1fca47b724b3835ac0267f58c5b3486fc222fc71 by Jinoh Kang <jinoh.kang.kr@gmail.com> * [WINESYNC] msi: Use nameless unions/structs. wine commit id 8de0a9dc740d3ed1e3cf9460852db7e609122f3b by Alexandre Julliard <julliard@winehq.org> * [MSI] disable nameless structs * [WINESYNC] msi/tests: Use nameless unions/structs. wine commit id 490aee03e45222aa9d7e3e7fd6ff80064dc3778d by Alexandre Julliard <julliard@winehq.org> * [WINESYNC] makedep: Use #pragma makedep testdll for TESTDLL resources. wine commit id 81da9ff0f8dea4932a3afdc4c447c1c9242bb596 by Rémi Bernon <rbernon@codeweavers.com> * [WINESYNC] msi: Use CreateFileW() for handling path from cabinet_open() instead. wine commit id 085e95cd5eceb36c3e21cb7d42adab5a6af38a38 by Jactry Zeng <jzeng@codeweavers.com> * [WINESYNC] msiexec: Use CRT allocation functions. wine commit id 0f44b3bdcb3d91701a9a8ef1ad07f3e88c08a666 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Remove DECLSPEC_HIDDEN usage. wine commit id 91e81083458374706bbace11114f4ad5e473ac07 by Alistair Leslie-Hughes <leslie_alistair@hotmail.com> * [WINESYNC] msi: Store Context as MSIINSTALLCONTEXT in MSIPACKAGE. Avoids casting to enum pointer in msi_locate_product call. wine commit id 2daa8c9f95b35983c885f5f7efe9e1b48e91f679 by Jacek Caban <jacek@codeweavers.com> * [WINESYNC] msi/tests: Initialize pathkey in test_installprops. It could be used uninitialized on early no access return. wine commit id 93668319dd63add97036fbb79b5745c699117313 by Jacek Caban <jacek@codeweavers.com> * [WINESYNC] regsvr32: Use message boxes by default for output. regsvr32 is in GUI subsystem and shouldn't interact with console. Keeping unix I/O output in silent mode. Removing -c option as not existing in native. Signed-off-by: Eric Pouech <epouech@codeweavers.com> wine commit id ac8da35b87005e45947b8164a4132f3bbb4ec2cc by Eric Pouech <epouech@codeweavers.com> * [MSI]: Reduce diff * [WINESYNC] msiexec: No longer use console/file output APIs. Regular GUI apps don't. Signed-off-by: Eric Pouech <epouech@codeweavers.com> wine commit id e048f71ecbb103ae7c1876092cb8244b24a73cb7 by Eric Pouech <epouech@codeweavers.com> * [WINESYNC] msi: Fix a memory leak (Coverity). wine commit id 4afca1787febb012d0cdd2c007dd32beba35178d by Zhiyi Zhang <zzhang@codeweavers.com> * [WINESYNC] msi: Don't write past end of string when selecting parent directory. wine commit id bbce5d014db7f023b133d6d09e6846e027586f7d by Fabian Maurer <dark.shadow4@web.de> * [WINESYNC] msi: Avoid leaking stream on DB update. MSI_RecordGetIStream adds a reference to the stream. This reference should be negated as we are done setting the stream. Signed-off-by: David Kahurani <k.kahurani@gmail.com> wine commit id 386dbe1059ba08485696760c267ef06dbed95bad by David Kahurani <k.kahurani@gmail.com> * [WINESYNC] msi/tests: Expand costing tests. wine commit id 674efeb1f7445935cf4f49dd1285727055664ab9 by Zebediah Figura <zfigura@codeweavers.com> * [WINESYNC] msi: Round costs up to 4096 bytes instead of clamping. wine commit id 9725a2286acdb791de316295d9bcb11411a3fd56 by Zebediah Figura <zfigura@codeweavers.com> * [WINESYNC] msi: Store component cost in 512-byte units. This avoids overflow when component costs exceed 4 GB. wine commit id d7bbe884ef29215f4db2027f450fb959314f5383 by Zebediah Figura <zfigura@codeweavers.com> * [MSI] store component cost in 512-byte units * [WINESYNC] msi: Multiply by 512 in dialog_vcl_add_drives(). The main motivation here is to avoid overflow, and multiplying in one place seems simpler. wine commit id 4a227c62a59a55aff9bacf1473c7f478f5c83294 by Zebediah Figura <zfigura@codeweavers.com> * [MSI] reduce diff * [WINESYNC] msi: Create the custom action server as an elevated process. Dragon Naturally Speaking 12.5 manually validates that the custom action server is elevated. One might imagine that the right approach here is to add a manifest to msiexec; however, msiexec does not always trigger a UAC prompt on Windows. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51143 wine commit id 366398cc53c76028c8dfe8d8a16c78a6a10ce962 by Zebediah Figura <z.figura12@gmail.com> * [WINESYNC] msi/tests: Delete the temp .msi file in all failure cases. wine commit id 43fb0ecd0717ad1a6aa0702ed68368ee35d3ecda by Alexandre Julliard <julliard@winehq.org> * [WINESYNC] msi/tests: Use the helpers from utils.h in more modules. wine commit id b3f11ceb7a0ddcf5fe742377f99c947b0b56a051 by Hans Leidekker <hans@codeweavers.com> * [MSITEST] include util header * [WINESYNC] msi/tests: Try restarting tests elevated. Wine starts processes non-elevated since e92ba2de43d7afbe0704b11b29f7c30f44dfaeca which means that many tests are skipped now. wine commit id a6eb51f0e595b2e5ddc521fb61b10d72849dd0f2 by Hans Leidekker <hans@codeweavers.com> * [MSITEST] try restarting for tests elevated * [WINESYNC] msi/tests: Get rid of workarounds for old Windows versions. wine commit id 738ec8285583248a84349939734ed600a47ba73d by Hans Leidekker <hans@codeweavers.com> * [MSI] fix patch failed * [WINESYNC] msi: Install global assemblies before running deferred custom actions. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56493 wine commit id 7f0ca9c284d15d03f14a8fefefac834990d622cd by Hans Leidekker <hans@codeweavers.com> * [WINESYNC] msi: Install global assemblies after install custom actions and before commit custom actions. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56609 wine commit id 27f5470ff4c20121b9eacd702c888400191c7d9e by Hans Leidekker <hans@codeweavers.com> * [WINESYNC]: msi is now in sync with wine-staging wine-9.8 * [MSI] Fix build * [WINESYNC] Update WINESYNC doc * [MSI] Remove nonameless* defines * [MSIEXEC] Fix build * [MSIEXEC] Fix build * [MSI] Fix vcl_get_cost
1308 lines
32 KiB
C
1308 lines
32 KiB
C
/*
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
*
|
|
* Copyright 2002 Mike McCormack for CodeWeavers
|
|
* Copyright 2011 Bernhard Loos
|
|
*
|
|
* 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 <assert.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"
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msidb);
|
|
|
|
/* below is the query interface to a table */
|
|
struct row_entry
|
|
{
|
|
struct tagMSIWHEREVIEW *wv; /* used during sorting */
|
|
UINT values[1];
|
|
};
|
|
|
|
struct join_table
|
|
{
|
|
struct join_table *next;
|
|
MSIVIEW *view;
|
|
UINT col_count;
|
|
UINT row_count;
|
|
UINT table_index;
|
|
};
|
|
|
|
typedef struct tagMSIORDERINFO
|
|
{
|
|
UINT col_count;
|
|
UINT error;
|
|
union ext_column columns[1];
|
|
} MSIORDERINFO;
|
|
|
|
typedef struct tagMSIWHEREVIEW
|
|
{
|
|
MSIVIEW view;
|
|
MSIDATABASE *db;
|
|
struct join_table *tables;
|
|
UINT row_count;
|
|
UINT col_count;
|
|
UINT table_count;
|
|
struct row_entry **reorder;
|
|
UINT reorder_size; /* number of entries available in reorder */
|
|
struct expr *cond;
|
|
UINT rec_index;
|
|
MSIORDERINFO *order_info;
|
|
} MSIWHEREVIEW;
|
|
|
|
static UINT WHERE_evaluate( MSIWHEREVIEW *wv, const UINT rows[],
|
|
struct expr *cond, INT *val, MSIRECORD *record );
|
|
|
|
#define INITIAL_REORDER_SIZE 16
|
|
|
|
#define INVALID_ROW_INDEX (-1)
|
|
|
|
static void free_reorder(MSIWHEREVIEW *wv)
|
|
{
|
|
UINT i;
|
|
|
|
if (!wv->reorder)
|
|
return;
|
|
|
|
for (i = 0; i < wv->row_count; i++)
|
|
free(wv->reorder[i]);
|
|
|
|
free(wv->reorder);
|
|
wv->reorder = NULL;
|
|
wv->reorder_size = 0;
|
|
wv->row_count = 0;
|
|
}
|
|
|
|
static UINT init_reorder(MSIWHEREVIEW *wv)
|
|
{
|
|
struct row_entry **new = calloc(INITIAL_REORDER_SIZE, sizeof(*new));
|
|
if (!new)
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
free_reorder(wv);
|
|
|
|
wv->reorder = new;
|
|
wv->reorder_size = INITIAL_REORDER_SIZE;
|
|
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
static inline UINT find_row(MSIWHEREVIEW *wv, UINT row, UINT *(values[]))
|
|
{
|
|
if (row >= wv->row_count)
|
|
return ERROR_NO_MORE_ITEMS;
|
|
|
|
*values = wv->reorder[row]->values;
|
|
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
static UINT add_row(MSIWHEREVIEW *wv, UINT vals[])
|
|
{
|
|
struct row_entry *new;
|
|
|
|
if (wv->reorder_size <= wv->row_count)
|
|
{
|
|
struct row_entry **new_reorder;
|
|
UINT newsize = wv->reorder_size * 2;
|
|
|
|
new_reorder = realloc(wv->reorder, newsize * sizeof(*new_reorder));
|
|
if (!new_reorder)
|
|
return ERROR_OUTOFMEMORY;
|
|
memset(new_reorder + wv->reorder_size, 0, (newsize - wv->reorder_size) * sizeof(*new_reorder));
|
|
|
|
wv->reorder = new_reorder;
|
|
wv->reorder_size = newsize;
|
|
}
|
|
|
|
new = malloc(offsetof(struct row_entry, values[wv->table_count]));
|
|
|
|
if (!new)
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
wv->reorder[wv->row_count++] = new;
|
|
|
|
memcpy(new->values, vals, wv->table_count * sizeof(UINT));
|
|
new->wv = wv;
|
|
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
static struct join_table *find_table(MSIWHEREVIEW *wv, UINT col, UINT *table_col)
|
|
{
|
|
struct join_table *table = wv->tables;
|
|
|
|
if(col == 0 || col > wv->col_count)
|
|
return NULL;
|
|
|
|
while (col > table->col_count)
|
|
{
|
|
col -= table->col_count;
|
|
table = table->next;
|
|
assert(table);
|
|
}
|
|
|
|
*table_col = col;
|
|
return table;
|
|
}
|
|
|
|
static UINT parse_column(MSIWHEREVIEW *wv, union ext_column *column,
|
|
UINT *column_type)
|
|
{
|
|
struct join_table *table = wv->tables;
|
|
UINT i, r;
|
|
|
|
do
|
|
{
|
|
LPCWSTR table_name;
|
|
|
|
if (column->unparsed.table)
|
|
{
|
|
r = table->view->ops->get_column_info(table->view, 1, NULL, NULL,
|
|
NULL, &table_name);
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
if (wcscmp(table_name, column->unparsed.table) != 0)
|
|
continue;
|
|
}
|
|
|
|
for(i = 1; i <= table->col_count; i++)
|
|
{
|
|
LPCWSTR col_name;
|
|
|
|
r = table->view->ops->get_column_info(table->view, i, &col_name, column_type,
|
|
NULL, NULL);
|
|
if(r != ERROR_SUCCESS )
|
|
return r;
|
|
|
|
if(wcscmp(col_name, column->unparsed.column))
|
|
continue;
|
|
column->parsed.column = i;
|
|
column->parsed.table = table;
|
|
return ERROR_SUCCESS;
|
|
}
|
|
}
|
|
while ((table = table->next));
|
|
|
|
WARN("Couldn't find column %s.%s\n", debugstr_w( column->unparsed.table ), debugstr_w( column->unparsed.column ) );
|
|
return ERROR_BAD_QUERY_SYNTAX;
|
|
}
|
|
|
|
static UINT WHERE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
struct join_table *table;
|
|
UINT *rows;
|
|
UINT r;
|
|
|
|
TRACE("%p %d %d %p\n", wv, row, col, val );
|
|
|
|
if( !wv->tables )
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
r = find_row(wv, row, &rows);
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
|
|
table = find_table(wv, col, &col);
|
|
if (!table)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
return table->view->ops->fetch_int(table->view, rows[table->table_index], col, val);
|
|
}
|
|
|
|
static UINT WHERE_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm )
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
struct join_table *table;
|
|
UINT *rows;
|
|
UINT r;
|
|
|
|
TRACE("%p %d %d %p\n", wv, row, col, stm );
|
|
|
|
if( !wv->tables )
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
r = find_row(wv, row, &rows);
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
|
|
table = find_table(wv, col, &col);
|
|
if (!table)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
return table->view->ops->fetch_stream( table->view, rows[table->table_index], col, stm );
|
|
}
|
|
|
|
static UINT WHERE_set_int(struct tagMSIVIEW *view, UINT row, UINT col, int val)
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
struct join_table *table;
|
|
UINT *rows;
|
|
UINT r;
|
|
|
|
TRACE("view %p, row %u, col %u, val %d.\n", wv, row, col, val );
|
|
|
|
r = find_row(wv, row, &rows);
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
|
|
table = find_table(wv, col, &col);
|
|
if (!table)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
return table->view->ops->set_int(table->view, rows[table->table_index], col, val);
|
|
}
|
|
|
|
static UINT WHERE_set_string(struct tagMSIVIEW *view, UINT row, UINT col, const WCHAR *val, int len)
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
struct join_table *table;
|
|
UINT *rows;
|
|
UINT r;
|
|
|
|
TRACE("view %p, row %u, col %u, val %s.\n", wv, row, col, debugstr_wn(val, len));
|
|
|
|
r = find_row(wv, row, &rows);
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
|
|
table = find_table(wv, col, &col);
|
|
if (!table)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
return table->view->ops->set_string(table->view, rows[table->table_index], col, val, len);
|
|
}
|
|
|
|
static UINT WHERE_set_stream(MSIVIEW *view, UINT row, UINT col, IStream *stream)
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
struct join_table *table;
|
|
UINT *rows;
|
|
UINT r;
|
|
|
|
TRACE("view %p, row %u, col %u, stream %p.\n", wv, row, col, stream);
|
|
|
|
r = find_row(wv, row, &rows);
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
|
|
table = find_table(wv, col, &col);
|
|
if (!table)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
return table->view->ops->set_stream(table->view, rows[table->table_index], col, stream);
|
|
}
|
|
|
|
static UINT WHERE_set_row( struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UINT mask )
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
UINT i, r, offset = 0;
|
|
struct join_table *table = wv->tables;
|
|
UINT *rows;
|
|
UINT mask_copy = mask;
|
|
|
|
TRACE("%p %d %p %08x\n", wv, row, rec, mask );
|
|
|
|
if( !wv->tables )
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
r = find_row(wv, row, &rows);
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
|
|
if (mask >= 1 << wv->col_count)
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
do
|
|
{
|
|
for (i = 0; i < table->col_count; i++) {
|
|
UINT type;
|
|
|
|
if (!(mask_copy & (1 << i)))
|
|
continue;
|
|
r = table->view->ops->get_column_info(table->view, i + 1, NULL,
|
|
&type, NULL, NULL );
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
if (type & MSITYPE_KEY)
|
|
return ERROR_FUNCTION_FAILED;
|
|
}
|
|
mask_copy >>= table->col_count;
|
|
}
|
|
while (mask_copy && (table = table->next));
|
|
|
|
table = wv->tables;
|
|
|
|
do
|
|
{
|
|
const UINT col_count = table->col_count;
|
|
UINT i;
|
|
MSIRECORD *reduced;
|
|
UINT reduced_mask = (mask >> offset) & ((1 << col_count) - 1);
|
|
|
|
if (!reduced_mask)
|
|
{
|
|
offset += col_count;
|
|
continue;
|
|
}
|
|
|
|
reduced = MSI_CreateRecord(col_count);
|
|
if (!reduced)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
for (i = 1; i <= col_count; i++)
|
|
{
|
|
r = MSI_RecordCopyField(rec, i + offset, reduced, i);
|
|
if (r != ERROR_SUCCESS)
|
|
break;
|
|
}
|
|
|
|
offset += col_count;
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
r = table->view->ops->set_row(table->view, rows[table->table_index], reduced, reduced_mask);
|
|
|
|
msiobj_release(&reduced->hdr);
|
|
}
|
|
while ((table = table->next));
|
|
return r;
|
|
}
|
|
|
|
static UINT WHERE_delete_row(struct tagMSIVIEW *view, UINT row)
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW *)view;
|
|
UINT r;
|
|
UINT *rows;
|
|
|
|
TRACE("(%p %d)\n", view, row);
|
|
|
|
if (!wv->tables)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
r = find_row(wv, row, &rows);
|
|
if ( r != ERROR_SUCCESS )
|
|
return r;
|
|
|
|
if (wv->table_count > 1)
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
return wv->tables->view->ops->delete_row(wv->tables->view, rows[0]);
|
|
}
|
|
|
|
static INT INT_evaluate_binary( MSIWHEREVIEW *wv, const UINT rows[],
|
|
const struct complex_expr *expr, INT *val, MSIRECORD *record )
|
|
{
|
|
UINT rl, rr;
|
|
INT lval, rval;
|
|
|
|
rl = WHERE_evaluate(wv, rows, expr->left, &lval, record);
|
|
if (rl != ERROR_SUCCESS && rl != ERROR_CONTINUE)
|
|
return rl;
|
|
rr = WHERE_evaluate(wv, rows, expr->right, &rval, record);
|
|
if (rr != ERROR_SUCCESS && rr != ERROR_CONTINUE)
|
|
return rr;
|
|
|
|
if (rl == ERROR_CONTINUE || rr == ERROR_CONTINUE)
|
|
{
|
|
if (rl == rr)
|
|
{
|
|
*val = TRUE;
|
|
return ERROR_CONTINUE;
|
|
}
|
|
|
|
if (expr->op == OP_AND)
|
|
{
|
|
if ((rl == ERROR_CONTINUE && !rval) || (rr == ERROR_CONTINUE && !lval))
|
|
{
|
|
*val = FALSE;
|
|
return ERROR_SUCCESS;
|
|
}
|
|
}
|
|
else if (expr->op == OP_OR)
|
|
{
|
|
if ((rl == ERROR_CONTINUE && rval) || (rr == ERROR_CONTINUE && lval))
|
|
{
|
|
*val = TRUE;
|
|
return ERROR_SUCCESS;
|
|
}
|
|
}
|
|
|
|
*val = TRUE;
|
|
return ERROR_CONTINUE;
|
|
}
|
|
|
|
switch( expr->op )
|
|
{
|
|
case OP_EQ:
|
|
*val = ( lval == rval );
|
|
break;
|
|
case OP_AND:
|
|
*val = ( lval && rval );
|
|
break;
|
|
case OP_OR:
|
|
*val = ( lval || rval );
|
|
break;
|
|
case OP_GT:
|
|
*val = ( lval > rval );
|
|
break;
|
|
case OP_LT:
|
|
*val = ( lval < rval );
|
|
break;
|
|
case OP_LE:
|
|
*val = ( lval <= rval );
|
|
break;
|
|
case OP_GE:
|
|
*val = ( lval >= rval );
|
|
break;
|
|
case OP_NE:
|
|
*val = ( lval != rval );
|
|
break;
|
|
default:
|
|
ERR("Unknown operator %d\n", expr->op );
|
|
return ERROR_FUNCTION_FAILED;
|
|
}
|
|
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
static inline UINT expr_fetch_value(const union ext_column *expr, const UINT rows[], UINT *val)
|
|
{
|
|
struct join_table *table = expr->parsed.table;
|
|
|
|
if( rows[table->table_index] == INVALID_ROW_INDEX )
|
|
{
|
|
*val = 1;
|
|
return ERROR_CONTINUE;
|
|
}
|
|
return table->view->ops->fetch_int(table->view, rows[table->table_index],
|
|
expr->parsed.column, val);
|
|
}
|
|
|
|
|
|
static UINT INT_evaluate_unary( MSIWHEREVIEW *wv, const UINT rows[],
|
|
const struct complex_expr *expr, INT *val, MSIRECORD *record )
|
|
{
|
|
UINT r;
|
|
UINT lval;
|
|
|
|
r = expr_fetch_value(&expr->left->u.column, rows, &lval);
|
|
if(r != ERROR_SUCCESS)
|
|
return r;
|
|
|
|
switch( expr->op )
|
|
{
|
|
case OP_ISNULL:
|
|
*val = !lval;
|
|
break;
|
|
case OP_NOTNULL:
|
|
*val = lval;
|
|
break;
|
|
default:
|
|
ERR("Unknown operator %d\n", expr->op );
|
|
return ERROR_FUNCTION_FAILED;
|
|
}
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
static UINT STRING_evaluate( MSIWHEREVIEW *wv, const UINT rows[],
|
|
const struct expr *expr,
|
|
const MSIRECORD *record,
|
|
const WCHAR **str )
|
|
{
|
|
UINT val = 0, r = ERROR_SUCCESS;
|
|
|
|
switch( expr->type )
|
|
{
|
|
case EXPR_COL_NUMBER_STRING:
|
|
r = expr_fetch_value(&expr->u.column, rows, &val);
|
|
if (r == ERROR_SUCCESS)
|
|
*str = msi_string_lookup(wv->db->strings, val, NULL);
|
|
else
|
|
*str = NULL;
|
|
break;
|
|
|
|
case EXPR_SVAL:
|
|
*str = expr->u.sval;
|
|
break;
|
|
|
|
case EXPR_WILDCARD:
|
|
*str = MSI_RecordGetString(record, ++wv->rec_index);
|
|
break;
|
|
|
|
default:
|
|
ERR("Invalid expression type\n");
|
|
r = ERROR_FUNCTION_FAILED;
|
|
*str = NULL;
|
|
break;
|
|
}
|
|
return r;
|
|
}
|
|
|
|
static UINT STRCMP_Evaluate( MSIWHEREVIEW *wv, const UINT rows[], const struct complex_expr *expr,
|
|
INT *val, const MSIRECORD *record )
|
|
{
|
|
int sr;
|
|
const WCHAR *l_str, *r_str;
|
|
UINT r;
|
|
|
|
*val = TRUE;
|
|
r = STRING_evaluate(wv, rows, expr->left, record, &l_str);
|
|
if (r == ERROR_CONTINUE)
|
|
return r;
|
|
r = STRING_evaluate(wv, rows, expr->right, record, &r_str);
|
|
if (r == ERROR_CONTINUE)
|
|
return r;
|
|
|
|
if( l_str == r_str ||
|
|
((!l_str || !*l_str) && (!r_str || !*r_str)) )
|
|
sr = 0;
|
|
else if( l_str && ! r_str )
|
|
sr = 1;
|
|
else if( r_str && ! l_str )
|
|
sr = -1;
|
|
else
|
|
sr = wcscmp( l_str, r_str );
|
|
|
|
*val = ( expr->op == OP_EQ && ( sr == 0 ) ) ||
|
|
( expr->op == OP_NE && ( sr != 0 ) );
|
|
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
static UINT WHERE_evaluate( MSIWHEREVIEW *wv, const UINT rows[],
|
|
struct expr *cond, INT *val, MSIRECORD *record )
|
|
{
|
|
UINT r, tval;
|
|
|
|
if( !cond )
|
|
{
|
|
*val = TRUE;
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
switch( cond->type )
|
|
{
|
|
case EXPR_COL_NUMBER:
|
|
r = expr_fetch_value(&cond->u.column, rows, &tval);
|
|
if( r != ERROR_SUCCESS )
|
|
return r;
|
|
*val = tval - 0x8000;
|
|
return ERROR_SUCCESS;
|
|
|
|
case EXPR_COL_NUMBER32:
|
|
r = expr_fetch_value(&cond->u.column, rows, &tval);
|
|
if( r != ERROR_SUCCESS )
|
|
return r;
|
|
*val = tval - 0x80000000;
|
|
return r;
|
|
|
|
case EXPR_UVAL:
|
|
*val = cond->u.uval;
|
|
return ERROR_SUCCESS;
|
|
|
|
case EXPR_COMPLEX:
|
|
return INT_evaluate_binary(wv, rows, &cond->u.expr, val, record);
|
|
|
|
case EXPR_UNARY:
|
|
return INT_evaluate_unary( wv, rows, &cond->u.expr, val, record );
|
|
|
|
case EXPR_STRCMP:
|
|
return STRCMP_Evaluate( wv, rows, &cond->u.expr, val, record );
|
|
|
|
case EXPR_WILDCARD:
|
|
*val = MSI_RecordGetInteger( record, ++wv->rec_index );
|
|
return ERROR_SUCCESS;
|
|
|
|
default:
|
|
ERR("Invalid expression type\n");
|
|
return ERROR_FUNCTION_FAILED;
|
|
}
|
|
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
static UINT check_condition( MSIWHEREVIEW *wv, MSIRECORD *record, struct join_table **tables,
|
|
UINT table_rows[] )
|
|
{
|
|
UINT r = ERROR_FUNCTION_FAILED;
|
|
INT val;
|
|
|
|
for (table_rows[(*tables)->table_index] = 0;
|
|
table_rows[(*tables)->table_index] < (*tables)->row_count;
|
|
table_rows[(*tables)->table_index]++)
|
|
{
|
|
val = 0;
|
|
wv->rec_index = 0;
|
|
r = WHERE_evaluate( wv, table_rows, wv->cond, &val, record );
|
|
if (r != ERROR_SUCCESS && r != ERROR_CONTINUE)
|
|
break;
|
|
if (val)
|
|
{
|
|
if (*(tables + 1))
|
|
{
|
|
r = check_condition(wv, record, tables + 1, table_rows);
|
|
if (r != ERROR_SUCCESS)
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
if (r != ERROR_SUCCESS)
|
|
break;
|
|
add_row (wv, table_rows);
|
|
}
|
|
}
|
|
}
|
|
table_rows[(*tables)->table_index] = INVALID_ROW_INDEX;
|
|
return r;
|
|
}
|
|
|
|
static int __cdecl compare_entry( const void *left, const void *right )
|
|
{
|
|
const struct row_entry *le = *(const struct row_entry **)left;
|
|
const struct row_entry *re = *(const struct row_entry **)right;
|
|
const MSIWHEREVIEW *wv = le->wv;
|
|
MSIORDERINFO *order = wv->order_info;
|
|
UINT i, j, r, l_val, r_val;
|
|
|
|
assert(le->wv == re->wv);
|
|
|
|
if (order)
|
|
{
|
|
for (i = 0; i < order->col_count; i++)
|
|
{
|
|
const union ext_column *column = &order->columns[i];
|
|
|
|
r = column->parsed.table->view->ops->fetch_int(column->parsed.table->view,
|
|
le->values[column->parsed.table->table_index],
|
|
column->parsed.column, &l_val);
|
|
if (r != ERROR_SUCCESS)
|
|
{
|
|
order->error = r;
|
|
return 0;
|
|
}
|
|
|
|
r = column->parsed.table->view->ops->fetch_int(column->parsed.table->view,
|
|
re->values[column->parsed.table->table_index],
|
|
column->parsed.column, &r_val);
|
|
if (r != ERROR_SUCCESS)
|
|
{
|
|
order->error = r;
|
|
return 0;
|
|
}
|
|
|
|
if (l_val != r_val)
|
|
return l_val < r_val ? -1 : 1;
|
|
}
|
|
}
|
|
|
|
for (j = 0; j < wv->table_count; j++)
|
|
{
|
|
if (le->values[j] != re->values[j])
|
|
return le->values[j] < re->values[j] ? -1 : 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void add_to_array( struct join_table **array, struct join_table *elem )
|
|
{
|
|
while (*array && *array != elem)
|
|
array++;
|
|
if (!*array)
|
|
*array = elem;
|
|
}
|
|
|
|
static BOOL in_array( struct join_table **array, struct join_table *elem )
|
|
{
|
|
while (*array && *array != elem)
|
|
array++;
|
|
return *array != NULL;
|
|
}
|
|
|
|
#define CONST_EXPR 1 /* comparison to a constant value */
|
|
#define JOIN_TO_CONST_EXPR 0x10000 /* comparison to a table involved with
|
|
a CONST_EXPR comaprison */
|
|
|
|
static UINT reorder_check( const struct expr *expr, struct join_table **ordered_tables,
|
|
BOOL process_joins, struct join_table **lastused )
|
|
{
|
|
UINT res = 0;
|
|
|
|
switch (expr->type)
|
|
{
|
|
case EXPR_WILDCARD:
|
|
case EXPR_SVAL:
|
|
case EXPR_UVAL:
|
|
return 0;
|
|
case EXPR_COL_NUMBER:
|
|
case EXPR_COL_NUMBER32:
|
|
case EXPR_COL_NUMBER_STRING:
|
|
if (in_array(ordered_tables, expr->u.column.parsed.table))
|
|
return JOIN_TO_CONST_EXPR;
|
|
*lastused = expr->u.column.parsed.table;
|
|
return CONST_EXPR;
|
|
case EXPR_STRCMP:
|
|
case EXPR_COMPLEX:
|
|
res = reorder_check(expr->u.expr.right, ordered_tables, process_joins, lastused);
|
|
/* fall through */
|
|
case EXPR_UNARY:
|
|
res += reorder_check(expr->u.expr.left, ordered_tables, process_joins, lastused);
|
|
if (res == 0)
|
|
return 0;
|
|
if (res == CONST_EXPR)
|
|
add_to_array(ordered_tables, *lastused);
|
|
if (process_joins && res == JOIN_TO_CONST_EXPR + CONST_EXPR)
|
|
add_to_array(ordered_tables, *lastused);
|
|
return res;
|
|
default:
|
|
ERR("Unknown expr type: %i\n", expr->type);
|
|
assert(0);
|
|
return 0x1000000;
|
|
}
|
|
}
|
|
|
|
/* reorders the tablelist in a way to evaluate the condition as fast as possible */
|
|
static struct join_table **ordertables( MSIWHEREVIEW *wv )
|
|
{
|
|
struct join_table *table, **tables;
|
|
|
|
tables = calloc(wv->table_count + 1, sizeof(*tables));
|
|
|
|
if (wv->cond)
|
|
{
|
|
table = NULL;
|
|
reorder_check(wv->cond, tables, FALSE, &table);
|
|
table = NULL;
|
|
reorder_check(wv->cond, tables, TRUE, &table);
|
|
}
|
|
|
|
table = wv->tables;
|
|
while (table)
|
|
{
|
|
add_to_array(tables, table);
|
|
table = table->next;
|
|
}
|
|
return tables;
|
|
}
|
|
|
|
static UINT WHERE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
UINT r;
|
|
struct join_table *table = wv->tables;
|
|
UINT *rows;
|
|
struct join_table **ordered_tables;
|
|
UINT i = 0;
|
|
|
|
TRACE("%p %p\n", wv, record);
|
|
|
|
if( !table )
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
r = init_reorder(wv);
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
|
|
do
|
|
{
|
|
table->view->ops->execute(table->view, NULL);
|
|
|
|
r = table->view->ops->get_dimensions(table->view, &table->row_count, NULL);
|
|
if (r != ERROR_SUCCESS)
|
|
{
|
|
ERR("failed to get table dimensions\n");
|
|
return r;
|
|
}
|
|
|
|
/* each table must have at least one row */
|
|
if (table->row_count == 0)
|
|
return ERROR_SUCCESS;
|
|
}
|
|
while ((table = table->next));
|
|
|
|
ordered_tables = ordertables( wv );
|
|
|
|
rows = malloc(wv->table_count * sizeof(*rows));
|
|
for (i = 0; i < wv->table_count; i++)
|
|
rows[i] = INVALID_ROW_INDEX;
|
|
|
|
r = check_condition(wv, record, ordered_tables, rows);
|
|
|
|
if (wv->order_info)
|
|
wv->order_info->error = ERROR_SUCCESS;
|
|
|
|
qsort(wv->reorder, wv->row_count, sizeof(struct row_entry *), compare_entry);
|
|
|
|
if (wv->order_info)
|
|
r = wv->order_info->error;
|
|
|
|
free(rows);
|
|
free(ordered_tables);
|
|
return r;
|
|
}
|
|
|
|
static UINT WHERE_close( struct tagMSIVIEW *view )
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
struct join_table *table = wv->tables;
|
|
|
|
TRACE("%p\n", wv );
|
|
|
|
if (!table)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
do
|
|
table->view->ops->close(table->view);
|
|
while ((table = table->next));
|
|
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
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->tables)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
if (rows)
|
|
{
|
|
if (!wv->reorder)
|
|
return ERROR_FUNCTION_FAILED;
|
|
*rows = wv->row_count;
|
|
}
|
|
|
|
if (cols)
|
|
*cols = wv->col_count;
|
|
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
static UINT WHERE_get_column_info( struct tagMSIVIEW *view, UINT n, LPCWSTR *name,
|
|
UINT *type, BOOL *temporary, LPCWSTR *table_name )
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
struct join_table *table;
|
|
|
|
TRACE("%p %d %p %p %p %p\n", wv, n, name, type, temporary, table_name );
|
|
|
|
if(!wv->tables)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
table = find_table(wv, n, &n);
|
|
if (!table)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
return table->view->ops->get_column_info(table->view, n, name,
|
|
type, temporary, table_name);
|
|
}
|
|
|
|
static UINT join_find_row( MSIWHEREVIEW *wv, MSIRECORD *rec, UINT *row )
|
|
{
|
|
LPCWSTR str;
|
|
UINT r, i, id, data;
|
|
|
|
str = MSI_RecordGetString( rec, 1 );
|
|
r = msi_string2id( wv->db->strings, str, -1, &id );
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
|
|
for (i = 0; i < wv->row_count; i++)
|
|
{
|
|
WHERE_fetch_int( &wv->view, i, 1, &data );
|
|
|
|
if (data == id)
|
|
{
|
|
*row = i;
|
|
return ERROR_SUCCESS;
|
|
}
|
|
}
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
}
|
|
|
|
static UINT join_modify_update( struct tagMSIVIEW *view, MSIRECORD *rec )
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW *)view;
|
|
UINT r, row, i, mask = 0;
|
|
MSIRECORD *current;
|
|
|
|
|
|
r = join_find_row( wv, rec, &row );
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
|
|
r = msi_view_get_row( wv->db, view, row, ¤t );
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
|
|
assert(MSI_RecordGetFieldCount(rec) == MSI_RecordGetFieldCount(current));
|
|
|
|
for (i = MSI_RecordGetFieldCount(rec); i > 0; i--)
|
|
{
|
|
if (!MSI_RecordsAreFieldsEqual(rec, current, i))
|
|
mask |= 1 << (i - 1);
|
|
}
|
|
msiobj_release(¤t->hdr);
|
|
|
|
return WHERE_set_row( view, row, rec, mask );
|
|
}
|
|
|
|
static UINT WHERE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
|
|
MSIRECORD *rec, UINT row )
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
struct join_table *table = wv->tables;
|
|
UINT r;
|
|
|
|
TRACE("%p %d %p\n", wv, eModifyMode, rec);
|
|
|
|
if (!table)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
if (!table->next)
|
|
{
|
|
UINT *rows;
|
|
|
|
if (find_row(wv, row, &rows) == ERROR_SUCCESS)
|
|
row = rows[0];
|
|
else
|
|
row = -1;
|
|
|
|
return table->view->ops->modify(table->view, eModifyMode, rec, row);
|
|
}
|
|
|
|
switch (eModifyMode)
|
|
{
|
|
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, eModifyMode, rec, row );
|
|
r = ERROR_INVALID_PARAMETER;
|
|
break;
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
static UINT WHERE_delete( struct tagMSIVIEW *view )
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW*)view;
|
|
struct join_table *table = wv->tables;
|
|
|
|
TRACE("%p\n", wv );
|
|
|
|
while(table)
|
|
{
|
|
struct join_table *next;
|
|
|
|
table->view->ops->delete(table->view);
|
|
table->view = NULL;
|
|
next = table->next;
|
|
free(table);
|
|
table = next;
|
|
}
|
|
wv->tables = NULL;
|
|
wv->table_count = 0;
|
|
|
|
free_reorder(wv);
|
|
|
|
free(wv->order_info);
|
|
wv->order_info = NULL;
|
|
|
|
msiobj_release( &wv->db->hdr );
|
|
free(wv);
|
|
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
static UINT WHERE_sort(struct tagMSIVIEW *view, column_info *columns)
|
|
{
|
|
MSIWHEREVIEW *wv = (MSIWHEREVIEW *)view;
|
|
struct join_table *table = wv->tables;
|
|
column_info *column = columns;
|
|
MSIORDERINFO *orderinfo;
|
|
UINT r, count = 0;
|
|
UINT i;
|
|
|
|
TRACE("%p %p\n", view, columns);
|
|
|
|
if (!table)
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
while (column)
|
|
{
|
|
count++;
|
|
column = column->next;
|
|
}
|
|
|
|
if (count == 0)
|
|
return ERROR_SUCCESS;
|
|
|
|
orderinfo = malloc(offsetof(MSIORDERINFO, columns[count]));
|
|
if (!orderinfo)
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
orderinfo->col_count = count;
|
|
|
|
column = columns;
|
|
|
|
for (i = 0; i < count; i++)
|
|
{
|
|
orderinfo->columns[i].unparsed.column = column->column;
|
|
orderinfo->columns[i].unparsed.table = column->table;
|
|
|
|
r = parse_column(wv, &orderinfo->columns[i], NULL);
|
|
if (r != ERROR_SUCCESS)
|
|
goto error;
|
|
}
|
|
|
|
wv->order_info = orderinfo;
|
|
|
|
return ERROR_SUCCESS;
|
|
error:
|
|
free(orderinfo);
|
|
return r;
|
|
}
|
|
|
|
static const MSIVIEWOPS where_ops =
|
|
{
|
|
WHERE_fetch_int,
|
|
WHERE_fetch_stream,
|
|
WHERE_set_int,
|
|
WHERE_set_string,
|
|
WHERE_set_stream,
|
|
WHERE_set_row,
|
|
NULL,
|
|
WHERE_delete_row,
|
|
WHERE_execute,
|
|
WHERE_close,
|
|
WHERE_get_dimensions,
|
|
WHERE_get_column_info,
|
|
WHERE_modify,
|
|
WHERE_delete,
|
|
NULL,
|
|
NULL,
|
|
NULL,
|
|
WHERE_sort,
|
|
NULL,
|
|
};
|
|
|
|
static UINT WHERE_VerifyCondition( MSIWHEREVIEW *wv, struct expr *cond,
|
|
UINT *valid )
|
|
{
|
|
UINT r;
|
|
|
|
switch( cond->type )
|
|
{
|
|
case EXPR_COLUMN:
|
|
{
|
|
UINT type;
|
|
|
|
*valid = FALSE;
|
|
|
|
r = parse_column(wv, &cond->u.column, &type);
|
|
if (r != ERROR_SUCCESS)
|
|
break;
|
|
|
|
if (type&MSITYPE_STRING)
|
|
cond->type = EXPR_COL_NUMBER_STRING;
|
|
else if ((type&0xff) == 4)
|
|
cond->type = EXPR_COL_NUMBER32;
|
|
else
|
|
cond->type = EXPR_COL_NUMBER;
|
|
|
|
*valid = TRUE;
|
|
break;
|
|
}
|
|
case EXPR_COMPLEX:
|
|
r = WHERE_VerifyCondition( wv, cond->u.expr.left, valid );
|
|
if( r != ERROR_SUCCESS )
|
|
return r;
|
|
if( !*valid )
|
|
return ERROR_SUCCESS;
|
|
r = WHERE_VerifyCondition( wv, cond->u.expr.right, valid );
|
|
if( r != ERROR_SUCCESS )
|
|
return r;
|
|
|
|
/* check the type of the comparison */
|
|
if( ( cond->u.expr.left->type == EXPR_SVAL ) ||
|
|
( 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 ) )
|
|
{
|
|
switch( cond->u.expr.op )
|
|
{
|
|
case OP_EQ:
|
|
case OP_NE:
|
|
break;
|
|
default:
|
|
*valid = FALSE;
|
|
return ERROR_INVALID_PARAMETER;
|
|
}
|
|
|
|
/* FIXME: check we're comparing a string to a column */
|
|
|
|
cond->type = EXPR_STRCMP;
|
|
}
|
|
|
|
break;
|
|
case EXPR_UNARY:
|
|
if ( cond->u.expr.left->type != EXPR_COLUMN )
|
|
{
|
|
*valid = FALSE;
|
|
return ERROR_INVALID_PARAMETER;
|
|
}
|
|
r = WHERE_VerifyCondition( wv, cond->u.expr.left, valid );
|
|
if( r != ERROR_SUCCESS )
|
|
return r;
|
|
break;
|
|
case EXPR_IVAL:
|
|
*valid = 1;
|
|
cond->type = EXPR_UVAL;
|
|
cond->u.uval = cond->u.ival;
|
|
break;
|
|
case EXPR_WILDCARD:
|
|
*valid = 1;
|
|
break;
|
|
case EXPR_SVAL:
|
|
*valid = 1;
|
|
break;
|
|
default:
|
|
ERR("Invalid expression type\n");
|
|
*valid = 0;
|
|
break;
|
|
}
|
|
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
UINT WHERE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR tables,
|
|
struct expr *cond )
|
|
{
|
|
MSIWHEREVIEW *wv = NULL;
|
|
UINT r, valid = 0;
|
|
WCHAR *ptr;
|
|
|
|
TRACE("(%s)\n", debugstr_w(tables) );
|
|
|
|
wv = calloc(1, sizeof *wv);
|
|
if( !wv )
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
/* fill the structure */
|
|
wv->view.ops = &where_ops;
|
|
msiobj_addref( &db->hdr );
|
|
wv->db = db;
|
|
wv->cond = cond;
|
|
|
|
while (*tables)
|
|
{
|
|
struct join_table *table;
|
|
|
|
if ((ptr = wcschr(tables, ' ')))
|
|
*ptr = '\0';
|
|
|
|
table = malloc(sizeof(*table));
|
|
if (!table)
|
|
{
|
|
r = ERROR_OUTOFMEMORY;
|
|
goto end;
|
|
}
|
|
|
|
r = TABLE_CreateView(db, tables, &table->view);
|
|
if (r != ERROR_SUCCESS)
|
|
{
|
|
WARN("can't create table: %s\n", debugstr_w(tables));
|
|
free(table);
|
|
r = ERROR_BAD_QUERY_SYNTAX;
|
|
goto end;
|
|
}
|
|
|
|
r = table->view->ops->get_dimensions(table->view, NULL,
|
|
&table->col_count);
|
|
if (r != ERROR_SUCCESS)
|
|
{
|
|
ERR("can't get table dimensions\n");
|
|
table->view->ops->delete(table->view);
|
|
free(table);
|
|
goto end;
|
|
}
|
|
|
|
wv->col_count += table->col_count;
|
|
table->table_index = wv->table_count++;
|
|
|
|
table->next = wv->tables;
|
|
wv->tables = table;
|
|
|
|
if (!ptr)
|
|
break;
|
|
|
|
tables = ptr + 1;
|
|
}
|
|
|
|
if( cond )
|
|
{
|
|
r = WHERE_VerifyCondition( wv, cond, &valid );
|
|
if( r != ERROR_SUCCESS )
|
|
goto end;
|
|
if( !valid ) {
|
|
r = ERROR_FUNCTION_FAILED;
|
|
goto end;
|
|
}
|
|
}
|
|
|
|
*view = (MSIVIEW*) wv;
|
|
|
|
return ERROR_SUCCESS;
|
|
end:
|
|
WHERE_delete(&wv->view);
|
|
|
|
return r;
|
|
}
|