msi: Remove the dependence on compressed cabinets in the install tests.
[wine.git] / dlls / msi / tests / db.c
blobac15d24e3392623c11585adcaaafe9e545db5b6c
1 /*
2 * Copyright (C) 2005 Mike McCormack for CodeWeavers
4 * A test program for MSI database files.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdio.h>
25 #include <windows.h>
26 #include <msi.h>
27 #include <msiquery.h>
29 #include <objidl.h>
31 #include "wine/test.h"
33 static const char *msifile = "winetest.msi";
34 static const char *msifile2 = "winetst2.msi";
35 static const char *mstfile = "winetst.mst";
37 static void test_msidatabase(void)
39 MSIHANDLE hdb = 0, hdb2 = 0;
40 UINT res;
42 DeleteFile(msifile);
44 res = MsiOpenDatabase( msifile, msifile2, &hdb );
45 ok( res == ERROR_OPEN_FAILED, "expected failure\n");
47 res = MsiOpenDatabase( msifile, (LPSTR) 0xff, &hdb );
48 ok( res == ERROR_INVALID_PARAMETER, "expected failure\n");
50 res = MsiCloseHandle( hdb );
51 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
53 /* create an empty database */
54 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
55 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
57 res = MsiDatabaseCommit( hdb );
58 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
60 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
62 res = MsiCloseHandle( hdb );
63 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
64 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
65 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
67 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile2 ), "database should exist\n");
69 res = MsiDatabaseCommit( hdb2 );
70 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
72 res = MsiCloseHandle( hdb2 );
73 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
75 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
76 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
78 res = MsiCloseHandle( hdb2 );
79 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
81 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile2 ), "uncommitted database should not exist\n");
83 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
84 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
86 res = MsiDatabaseCommit( hdb2 );
87 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
89 res = MsiCloseHandle( hdb2 );
90 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
92 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile2 ), "committed database should exist\n");
94 res = MsiOpenDatabase( msifile, MSIDBOPEN_READONLY, &hdb );
95 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
97 res = MsiCloseHandle( hdb );
98 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
100 res = MsiOpenDatabase( msifile, MSIDBOPEN_DIRECT, &hdb );
101 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
103 res = MsiCloseHandle( hdb );
104 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
106 res = MsiOpenDatabase( msifile, MSIDBOPEN_TRANSACT, &hdb );
107 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
109 res = MsiCloseHandle( hdb );
110 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
111 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
113 /* MSIDBOPEN_CREATE deletes the database if MsiCommitDatabase isn't called */
114 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
115 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
117 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
119 res = MsiCloseHandle( hdb );
120 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
122 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile ), "database should exist\n");
124 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
125 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
127 res = MsiDatabaseCommit( hdb );
128 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
130 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
132 res = MsiCloseHandle( hdb );
133 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
135 res = DeleteFile( msifile2 );
136 ok( res == TRUE, "Failed to delete database\n" );
138 res = DeleteFile( msifile );
139 ok( res == TRUE, "Failed to delete database\n" );
142 static UINT do_query(MSIHANDLE hdb, const char *query, MSIHANDLE *phrec)
144 MSIHANDLE hview = 0;
145 UINT r, ret;
147 /* open a select query */
148 r = MsiDatabaseOpenView(hdb, query, &hview);
149 if (r != ERROR_SUCCESS)
150 return r;
151 r = MsiViewExecute(hview, 0);
152 if (r != ERROR_SUCCESS)
153 return r;
154 ret = MsiViewFetch(hview, phrec);
155 r = MsiViewClose(hview);
156 if (r != ERROR_SUCCESS)
157 return r;
158 r = MsiCloseHandle(hview);
159 if (r != ERROR_SUCCESS)
160 return r;
161 return ret;
164 static UINT run_query( MSIHANDLE hdb, MSIHANDLE hrec, const char *query )
166 MSIHANDLE hview = 0;
167 UINT r;
169 r = MsiDatabaseOpenView(hdb, query, &hview);
170 if( r != ERROR_SUCCESS )
171 return r;
173 r = MsiViewExecute(hview, hrec);
174 if( r == ERROR_SUCCESS )
175 r = MsiViewClose(hview);
176 MsiCloseHandle(hview);
177 return r;
180 static UINT create_component_table( MSIHANDLE hdb )
182 return run_query( hdb, 0,
183 "CREATE TABLE `Component` ( "
184 "`Component` CHAR(72) NOT NULL, "
185 "`ComponentId` CHAR(38), "
186 "`Directory_` CHAR(72) NOT NULL, "
187 "`Attributes` SHORT NOT NULL, "
188 "`Condition` CHAR(255), "
189 "`KeyPath` CHAR(72) "
190 "PRIMARY KEY `Component`)" );
193 static UINT create_feature_components_table( MSIHANDLE hdb )
195 return run_query( hdb, 0,
196 "CREATE TABLE `FeatureComponents` ( "
197 "`Feature_` CHAR(38) NOT NULL, "
198 "`Component_` CHAR(72) NOT NULL "
199 "PRIMARY KEY `Feature_`, `Component_` )" );
202 static UINT create_std_dlls_table( MSIHANDLE hdb )
204 return run_query( hdb, 0,
205 "CREATE TABLE `StdDlls` ( "
206 "`File` CHAR(255) NOT NULL, "
207 "`Binary_` CHAR(72) NOT NULL "
208 "PRIMARY KEY `File` )" );
211 static UINT create_binary_table( MSIHANDLE hdb )
213 return run_query( hdb, 0,
214 "CREATE TABLE `Binary` ( "
215 "`Name` CHAR(72) NOT NULL, "
216 "`Data` CHAR(72) NOT NULL "
217 "PRIMARY KEY `Name` )" );
220 static UINT add_component_entry( MSIHANDLE hdb, const char *values )
222 char insert[] = "INSERT INTO `Component` "
223 "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `Condition`, `KeyPath`) "
224 "VALUES( %s )";
225 char *query;
226 UINT sz, r;
228 sz = strlen(values) + sizeof insert;
229 query = HeapAlloc(GetProcessHeap(),0,sz);
230 sprintf(query,insert,values);
231 r = run_query( hdb, 0, query );
232 HeapFree(GetProcessHeap(), 0, query);
233 return r;
236 static UINT add_feature_components_entry( MSIHANDLE hdb, const char *values )
238 char insert[] = "INSERT INTO `FeatureComponents` "
239 "(`Feature_`, `Component_`) "
240 "VALUES( %s )";
241 char *query;
242 UINT sz, r;
244 sz = strlen(values) + sizeof insert;
245 query = HeapAlloc(GetProcessHeap(),0,sz);
246 sprintf(query,insert,values);
247 r = run_query( hdb, 0, query );
248 HeapFree(GetProcessHeap(), 0, query);
249 return r;
252 static UINT add_std_dlls_entry( MSIHANDLE hdb, const char *values )
254 char insert[] = "INSERT INTO `StdDlls` "
255 "(`File`, `Binary_`) "
256 "VALUES( %s )";
257 char *query;
258 UINT sz, r;
260 sz = strlen(values) + sizeof insert;
261 query = HeapAlloc(GetProcessHeap(),0,sz);
262 sprintf(query,insert,values);
263 r = run_query( hdb, 0, query );
264 HeapFree(GetProcessHeap(), 0, query);
265 return r;
268 static UINT add_binary_entry( MSIHANDLE hdb, const char *values )
270 char insert[] = "INSERT INTO `Binary` "
271 "(`Name`, `Data`) "
272 "VALUES( %s )";
273 char *query;
274 UINT sz, r;
276 sz = strlen(values) + sizeof insert;
277 query = HeapAlloc(GetProcessHeap(),0,sz);
278 sprintf(query,insert,values);
279 r = run_query( hdb, 0, query );
280 HeapFree(GetProcessHeap(), 0, query);
281 return r;
284 static void test_msiinsert(void)
286 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
287 UINT r;
288 const char *query;
289 char buf[80];
290 DWORD sz;
292 DeleteFile(msifile);
294 /* just MsiOpenDatabase should not create a file */
295 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
296 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
298 /* create a table */
299 query = "CREATE TABLE `phone` ( "
300 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
301 "PRIMARY KEY `id`)";
302 r = MsiDatabaseOpenView(hdb, query, &hview);
303 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
304 r = MsiViewExecute(hview, 0);
305 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
306 r = MsiViewClose(hview);
307 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
308 r = MsiCloseHandle(hview);
309 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
311 /* insert a value into it */
312 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
313 "VALUES('1', 'Abe', '8675309')";
314 r = MsiDatabaseOpenView(hdb, query, &hview);
315 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
316 r = MsiViewExecute(hview, 0);
317 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
318 r = MsiViewClose(hview);
319 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
320 r = MsiCloseHandle(hview);
321 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
323 query = "SELECT * FROM `phone` WHERE `id` = 1";
324 r = do_query(hdb, query, &hrec);
325 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
327 /* check the record contains what we put in it */
328 r = MsiRecordGetFieldCount(hrec);
329 ok(r == 3, "record count wrong\n");
331 todo_wine {
332 r = MsiRecordIsNull(hrec, 0);
333 ok(r == FALSE, "field 0 not null\n");
336 r = MsiRecordGetInteger(hrec, 1);
337 ok(r == 1, "field 1 contents wrong\n");
338 sz = sizeof buf;
339 r = MsiRecordGetString(hrec, 2, buf, &sz);
340 ok(r == ERROR_SUCCESS, "field 2 content fetch failed\n");
341 ok(!strcmp(buf,"Abe"), "field 2 content incorrect\n");
342 sz = sizeof buf;
343 r = MsiRecordGetString(hrec, 3, buf, &sz);
344 ok(r == ERROR_SUCCESS, "field 3 content fetch failed\n");
345 ok(!strcmp(buf,"8675309"), "field 3 content incorrect\n");
347 r = MsiCloseHandle(hrec);
348 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
350 /* open a select query */
351 hrec = 100;
352 query = "SELECT * FROM `phone` WHERE `id` >= 10";
353 r = do_query(hdb, query, &hrec);
354 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
355 ok(hrec == 0, "hrec should be null\n");
357 r = MsiCloseHandle(hrec);
358 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
360 query = "SELECT * FROM `phone` WHERE `id` < 0";
361 r = do_query(hdb, query, &hrec);
362 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
364 query = "SELECT * FROM `phone` WHERE `id` <= 0";
365 r = do_query(hdb, query, &hrec);
366 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
368 query = "SELECT * FROM `phone` WHERE `id` <> 1";
369 r = do_query(hdb, query, &hrec);
370 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
372 query = "SELECT * FROM `phone` WHERE `id` > 10";
373 r = do_query(hdb, query, &hrec);
374 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
376 /* now try a few bad INSERT xqueries */
377 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
378 "VALUES(?, ?)";
379 r = MsiDatabaseOpenView(hdb, query, &hview);
380 ok(r == ERROR_BAD_QUERY_SYNTAX, "MsiDatabaseOpenView failed\n");
382 /* construct a record to insert */
383 hrec = MsiCreateRecord(4);
384 r = MsiRecordSetInteger(hrec, 1, 2);
385 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
386 r = MsiRecordSetString(hrec, 2, "Adam");
387 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
388 r = MsiRecordSetString(hrec, 3, "96905305");
389 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
391 /* insert another value, using a record and wildcards */
392 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
393 "VALUES(?, ?, ?)";
394 r = MsiDatabaseOpenView(hdb, query, &hview);
395 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
397 if (r == ERROR_SUCCESS)
399 r = MsiViewExecute(hview, hrec);
400 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
401 r = MsiViewClose(hview);
402 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
403 r = MsiCloseHandle(hview);
404 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
406 r = MsiCloseHandle(hrec);
407 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
409 r = MsiViewFetch(0, NULL);
410 ok(r == ERROR_INVALID_PARAMETER, "MsiViewFetch failed\n");
412 r = MsiDatabaseCommit(hdb);
413 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
415 r = MsiCloseHandle(hdb);
416 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
418 r = DeleteFile(msifile);
419 ok(r == TRUE, "file didn't exist after commit\n");
422 typedef UINT (WINAPI *fnMsiDecomposeDescriptorA)(LPCSTR, LPCSTR, LPSTR, LPSTR, DWORD *);
423 static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA;
425 static void test_msidecomposedesc(void)
427 char prod[MAX_FEATURE_CHARS+1], comp[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1];
428 const char *desc;
429 UINT r;
430 DWORD len;
431 HMODULE hmod;
433 hmod = GetModuleHandle("msi.dll");
434 pMsiDecomposeDescriptorA = (fnMsiDecomposeDescriptorA)
435 GetProcAddress(hmod, "MsiDecomposeDescriptorA");
436 if (!pMsiDecomposeDescriptorA)
437 return;
439 /* test a valid feature descriptor */
440 desc = "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
441 len = 0;
442 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
443 ok(r == ERROR_SUCCESS, "returned an error\n");
444 ok(len == strlen(desc), "length was wrong\n");
445 ok(strcmp(prod,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
446 ok(strcmp(feature,"FollowTheWhiteRabbit")==0, "feature wrong\n");
447 ok(strcmp(comp,"{A7CD68DB-EF74-49C8-FBB2-A7C463B2AC24}")==0,"component wrong\n");
449 /* test an invalid feature descriptor with too many characters */
450 desc = "']gAVn-}f(ZXfeAR6.ji"
451 "ThisWillFailIfTheresMoreThanAGuidsChars>"
452 "3w2x^IGfe?CxI5heAvk.";
453 len = 0;
454 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
455 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
458 * Test a valid feature descriptor with the
459 * maximum number of characters and some trailing characters.
461 desc = "']gAVn-}f(ZXfeAR6.ji"
462 "ThisWillWorkIfTheresLTEThanAGuidsChars>"
463 "3w2x^IGfe?CxI5heAvk."
464 "extra";
465 len = 0;
466 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
467 ok(r == ERROR_SUCCESS, "returned wrong error\n");
468 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
470 len = 0;
471 r = pMsiDecomposeDescriptorA(desc, prod, feature, NULL, &len);
472 ok(r == ERROR_SUCCESS, "returned wrong error\n");
473 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
475 len = 0;
476 r = pMsiDecomposeDescriptorA(desc, prod, NULL, NULL, &len);
477 ok(r == ERROR_SUCCESS, "returned wrong error\n");
478 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
480 len = 0;
481 r = pMsiDecomposeDescriptorA(desc, NULL, NULL, NULL, &len);
482 ok(r == ERROR_SUCCESS, "returned wrong error\n");
483 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
485 len = 0;
486 r = pMsiDecomposeDescriptorA(NULL, NULL, NULL, NULL, &len);
487 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
488 ok(len == 0, "length wrong\n");
491 static UINT try_query_param( MSIHANDLE hdb, LPCSTR szQuery, MSIHANDLE hrec )
493 MSIHANDLE htab = 0;
494 UINT res;
496 res = MsiDatabaseOpenView( hdb, szQuery, &htab );
497 if(res == ERROR_SUCCESS )
499 UINT r;
501 r = MsiViewExecute( htab, hrec );
502 if(r != ERROR_SUCCESS )
503 res = r;
505 r = MsiViewClose( htab );
506 if(r != ERROR_SUCCESS )
507 res = r;
509 r = MsiCloseHandle( htab );
510 if(r != ERROR_SUCCESS )
511 res = r;
513 return res;
516 static UINT try_query( MSIHANDLE hdb, LPCSTR szQuery )
518 return try_query_param( hdb, szQuery, 0 );
521 static UINT try_insert_query( MSIHANDLE hdb, LPCSTR szQuery )
523 MSIHANDLE hrec = 0;
524 UINT r;
526 hrec = MsiCreateRecord( 1 );
527 MsiRecordSetString( hrec, 1, "Hello");
529 r = try_query_param( hdb, szQuery, hrec );
531 MsiCloseHandle( hrec );
532 return r;
535 static void test_msibadqueries(void)
537 MSIHANDLE hdb = 0;
538 UINT r;
540 DeleteFile(msifile);
542 /* just MsiOpenDatabase should not create a file */
543 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
544 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
546 r = MsiDatabaseCommit( hdb );
547 ok(r == ERROR_SUCCESS , "Failed to commit database\n");
549 r = MsiCloseHandle( hdb );
550 ok(r == ERROR_SUCCESS , "Failed to close database\n");
552 /* open it readonly */
553 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb );
554 ok(r == ERROR_SUCCESS , "Failed to open database r/o\n");
556 /* add a table to it */
557 r = try_query( hdb, "select * from _Tables");
558 ok(r == ERROR_SUCCESS , "query 1 failed\n");
560 r = MsiCloseHandle( hdb );
561 ok(r == ERROR_SUCCESS , "Failed to close database r/o\n");
563 /* open it read/write */
564 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
565 ok(r == ERROR_SUCCESS , "Failed to open database r/w\n");
567 /* a bunch of test queries that fail with the native MSI */
569 r = try_query( hdb, "CREATE TABLE");
570 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2a return code\n");
572 r = try_query( hdb, "CREATE TABLE `a`");
573 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2b return code\n");
575 r = try_query( hdb, "CREATE TABLE `a` ()");
576 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2c return code\n");
578 r = try_query( hdb, "CREATE TABLE `a` (`b`)");
579 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2d return code\n");
581 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) )");
582 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2e return code\n");
584 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
585 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2f return code\n");
587 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
588 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2g return code\n");
590 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
591 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2h return code\n");
593 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
594 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2i return code\n");
596 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
597 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2j return code\n");
599 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
600 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2k return code\n");
602 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
603 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2l return code\n");
605 r = try_query( hdb, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
606 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2m return code\n");
608 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
609 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2n return code\n");
611 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
612 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2o return code\n");
614 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
615 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
617 r = try_query( hdb, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
618 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
620 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
621 ok(r == ERROR_SUCCESS , "valid query 2z failed\n");
623 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
624 ok(r == ERROR_BAD_QUERY_SYNTAX , "created same table again\n");
626 r = try_query( hdb, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
627 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
628 ok(r == ERROR_SUCCESS , "query 4 failed\n");
630 r = MsiDatabaseCommit( hdb );
631 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
633 r = try_query( hdb, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
634 "PRIMARY KEY `foo`)");
635 ok(r == ERROR_SUCCESS , "query 4 failed\n");
637 r = try_insert_query( hdb, "insert into a ( `b` ) VALUES ( ? )");
638 ok(r == ERROR_SUCCESS , "failed to insert record in db\n");
640 r = MsiDatabaseCommit( hdb );
641 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
643 r = try_query( hdb, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
644 "PRIMARY KEY `ba`)");
645 ok(r != ERROR_SUCCESS , "query 5 succeeded\n");
647 r = try_query( hdb,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
648 ok(r != ERROR_SUCCESS , "query 6 succeeded\n");
650 r = try_query( hdb, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
651 "PRIMARY KEY `t`)");
652 ok(r == ERROR_SUCCESS , "query 7 failed\n");
654 r = try_query( hdb, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
655 ok(r == ERROR_SUCCESS , "query 8 failed\n");
657 r = try_query( hdb, "select * from c");
658 ok(r == ERROR_SUCCESS , "query failed\n");
660 r = try_query( hdb, "select * from c where b = 'x");
661 todo_wine ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
663 r = try_query( hdb, "select * from 'c'");
664 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
666 r = try_query( hdb, "select * from ''");
667 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
669 r = try_query( hdb, "select * from c where b = x");
670 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
672 r = try_query( hdb, "select * from c where b = \"x\"");
673 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
675 r = try_query( hdb, "select * from c where b = 'x'");
676 ok(r == ERROR_SUCCESS, "query failed\n");
678 r = try_query( hdb, "select * from c where b = '\"x'");
679 ok(r == ERROR_SUCCESS, "query failed\n");
681 if (0) /* FIXME: this query causes trouble with other tests */
683 r = try_query( hdb, "select * from c where b = '\\\'x'");
684 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
687 r = try_query( hdb, "select * from 'c'");
688 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
690 r = MsiCloseHandle( hdb );
691 ok(r == ERROR_SUCCESS , "Failed to close database transact\n");
693 r = DeleteFile( msifile );
694 ok(r == TRUE, "file didn't exist after commit\n");
697 static void test_viewmodify(void)
699 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
700 UINT r;
701 MSIDBERROR err;
702 const char *query;
703 char buffer[0x100];
704 DWORD sz;
706 DeleteFile(msifile);
708 /* just MsiOpenDatabase should not create a file */
709 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
710 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
712 query = "CREATE TABLE `phone` ( "
713 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
714 "PRIMARY KEY `id`)";
715 r = run_query( hdb, 0, query );
716 ok(r == ERROR_SUCCESS, "query failed\n");
718 /* check what the error function reports without doing anything */
719 sz = 0;
720 /* passing NULL as the 3rd param make function to crash on older platforms */
721 err = MsiViewGetError( 0, NULL, &sz );
722 ok(err == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
724 /* open a view */
725 query = "SELECT * FROM `phone`";
726 r = MsiDatabaseOpenView(hdb, query, &hview);
727 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
729 /* see what happens with a good hview and bad args */
730 err = MsiViewGetError( hview, NULL, NULL );
731 ok(err == MSIDBERROR_INVALIDARG || err == MSIDBERROR_NOERROR,
732 "MsiViewGetError returns %u (expected -3)\n", err);
733 err = MsiViewGetError( hview, buffer, NULL );
734 ok(err == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
736 /* see what happens with a zero length buffer */
737 sz = 0;
738 buffer[0] = 'x';
739 err = MsiViewGetError( hview, buffer, &sz );
740 ok(err == MSIDBERROR_MOREDATA, "MsiViewGetError return\n");
741 ok(buffer[0] == 'x', "buffer cleared\n");
742 ok(sz == 0, "size not zero\n");
744 /* ok this one is strange */
745 sz = 0;
746 err = MsiViewGetError( hview, NULL, &sz );
747 ok(err == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
748 ok(sz == 0, "size not zero\n");
750 /* see if it really has an error */
751 sz = sizeof buffer;
752 buffer[0] = 'x';
753 err = MsiViewGetError( hview, buffer, &sz );
754 ok(err == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
755 ok(buffer[0] == 0, "buffer not cleared\n");
756 ok(sz == 0, "size not zero\n");
758 r = MsiViewExecute(hview, 0);
759 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
761 /* try some invalid records */
762 r = MsiViewModify(hview, MSIMODIFY_INSERT, 0 );
763 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
764 r = MsiViewModify(hview, -1, 0 );
765 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
767 /* try an small record */
768 hrec = MsiCreateRecord(1);
769 r = MsiViewModify(hview, -1, hrec );
770 ok(r == ERROR_INVALID_DATA, "MsiViewModify failed\n");
772 r = MsiCloseHandle(hrec);
773 ok(r == ERROR_SUCCESS, "failed to close record\n");
775 /* insert a valid record */
776 hrec = MsiCreateRecord(3);
778 r = MsiRecordSetInteger(hrec, 1, 1);
779 ok(r == ERROR_SUCCESS, "failed to set integer\n");
780 r = MsiRecordSetString(hrec, 2, "bob");
781 ok(r == ERROR_SUCCESS, "failed to set string\n");
782 r = MsiRecordSetString(hrec, 3, "7654321");
783 ok(r == ERROR_SUCCESS, "failed to set string\n");
785 r = MsiViewExecute(hview, 0);
786 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
787 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
788 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
790 /* insert the same thing again */
791 r = MsiViewExecute(hview, 0);
792 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
794 /* should fail ... */
795 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
796 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
798 r = MsiCloseHandle(hrec);
799 ok(r == ERROR_SUCCESS, "failed to close record\n");
801 r = MsiViewClose(hview);
802 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
803 r = MsiCloseHandle(hview);
804 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
806 query = "SELECT * FROM `phone`";
807 r = MsiDatabaseOpenView(hdb, query, &hview);
808 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
810 r = MsiViewExecute(hview, 0);
811 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
813 r = MsiViewFetch(hview, &hrec);
814 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
816 r = MsiRecordGetInteger(hrec, 1);
817 ok(r == 1, "Expected 1, got %d\n", r);
819 sz = sizeof(buffer);
820 r = MsiRecordGetString(hrec, 2, buffer, &sz);
821 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
822 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
824 sz = sizeof(buffer);
825 r = MsiRecordGetString(hrec, 3, buffer, &sz);
826 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
827 ok(!lstrcmp(buffer, "7654321"), "Expected 7654321, got %s\n", buffer);
829 /* update the view, non-primary key */
830 r = MsiRecordSetString(hrec, 3, "3141592");
831 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
833 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
834 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
836 /* do it again */
837 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
838 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
840 /* update the view, primary key */
841 r = MsiRecordSetInteger(hrec, 1, 5);
842 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
844 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
845 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
847 r = MsiCloseHandle(hrec);
848 ok(r == ERROR_SUCCESS, "failed to close record\n");
850 r = MsiViewClose(hview);
851 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
852 r = MsiCloseHandle(hview);
853 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
855 query = "SELECT * FROM `phone`";
856 r = MsiDatabaseOpenView(hdb, query, &hview);
857 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
859 r = MsiViewExecute(hview, 0);
860 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
862 r = MsiViewFetch(hview, &hrec);
863 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
865 r = MsiRecordGetInteger(hrec, 1);
866 ok(r == 1, "Expected 1, got %d\n", r);
868 sz = sizeof(buffer);
869 r = MsiRecordGetString(hrec, 2, buffer, &sz);
870 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
871 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
873 sz = sizeof(buffer);
874 r = MsiRecordGetString(hrec, 3, buffer, &sz);
875 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
876 ok(!lstrcmp(buffer, "3141592"), "Expected 3141592, got %s\n", buffer);
878 r = MsiCloseHandle(hrec);
879 ok(r == ERROR_SUCCESS, "failed to close record\n");
881 /* use a record that doesn't come from a view fetch */
882 hrec = MsiCreateRecord(3);
883 ok(hrec != 0, "MsiCreateRecord failed\n");
885 r = MsiRecordSetInteger(hrec, 1, 3);
886 ok(r == ERROR_SUCCESS, "failed to set integer\n");
887 r = MsiRecordSetString(hrec, 2, "jane");
888 ok(r == ERROR_SUCCESS, "failed to set string\n");
889 r = MsiRecordSetString(hrec, 3, "112358");
890 ok(r == ERROR_SUCCESS, "failed to set string\n");
892 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
893 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
895 r = MsiCloseHandle(hrec);
896 ok(r == ERROR_SUCCESS, "failed to close record\n");
898 /* use a record that doesn't come from a view fetch, primary key matches */
899 hrec = MsiCreateRecord(3);
900 ok(hrec != 0, "MsiCreateRecord failed\n");
902 r = MsiRecordSetInteger(hrec, 1, 1);
903 ok(r == ERROR_SUCCESS, "failed to set integer\n");
904 r = MsiRecordSetString(hrec, 2, "jane");
905 ok(r == ERROR_SUCCESS, "failed to set string\n");
906 r = MsiRecordSetString(hrec, 3, "112358");
907 ok(r == ERROR_SUCCESS, "failed to set string\n");
909 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
910 todo_wine
912 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
915 r = MsiCloseHandle(hrec);
916 ok(r == ERROR_SUCCESS, "failed to close record\n");
918 hrec = MsiCreateRecord(3);
920 r = MsiRecordSetInteger(hrec, 1, 2);
921 ok(r == ERROR_SUCCESS, "failed to set integer\n");
922 r = MsiRecordSetString(hrec, 2, "nick");
923 ok(r == ERROR_SUCCESS, "failed to set string\n");
924 r = MsiRecordSetString(hrec, 3, "141421");
925 ok(r == ERROR_SUCCESS, "failed to set string\n");
927 r = MsiViewExecute(hview, 0);
928 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
929 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
930 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
932 r = MsiViewClose(hview);
933 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
934 r = MsiCloseHandle(hview);
935 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
937 query = "SELECT * FROM `phone` WHERE `id` = 1";
938 r = MsiDatabaseOpenView(hdb, query, &hview);
939 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
940 r = MsiViewExecute(hview, 0);
941 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
942 r = MsiViewFetch(hview, &hrec);
943 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
945 /* change the id to match the second row */
946 r = MsiRecordSetInteger(hrec, 1, 2);
947 ok(r == ERROR_SUCCESS, "failed to set integer\n");
948 r = MsiRecordSetString(hrec, 2, "jerry");
949 ok(r == ERROR_SUCCESS, "failed to set string\n");
951 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
952 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
954 r = MsiCloseHandle(hrec);
955 ok(r == ERROR_SUCCESS, "failed to close record\n");
956 r = MsiViewClose(hview);
957 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
958 r = MsiCloseHandle(hview);
959 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
961 /* broader search */
962 query = "SELECT * FROM `phone` ORDER BY `id`";
963 r = MsiDatabaseOpenView(hdb, query, &hview);
964 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
965 r = MsiViewExecute(hview, 0);
966 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
967 r = MsiViewFetch(hview, &hrec);
968 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
970 /* change the id to match the second row */
971 r = MsiRecordSetInteger(hrec, 1, 2);
972 ok(r == ERROR_SUCCESS, "failed to set integer\n");
973 r = MsiRecordSetString(hrec, 2, "jerry");
974 ok(r == ERROR_SUCCESS, "failed to set string\n");
976 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
977 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
979 r = MsiCloseHandle(hrec);
980 ok(r == ERROR_SUCCESS, "failed to close record\n");
981 r = MsiViewClose(hview);
982 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
983 r = MsiCloseHandle(hview);
984 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
986 r = MsiCloseHandle( hdb );
987 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
990 static MSIHANDLE create_db(void)
992 MSIHANDLE hdb = 0;
993 UINT res;
995 DeleteFile(msifile);
997 /* create an empty database */
998 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
999 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
1000 if( res != ERROR_SUCCESS )
1001 return hdb;
1003 res = MsiDatabaseCommit( hdb );
1004 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
1006 return hdb;
1009 static void test_getcolinfo(void)
1011 MSIHANDLE hdb, hview = 0, rec = 0;
1012 UINT r;
1013 DWORD sz;
1014 char buffer[0x20];
1016 /* create an empty db */
1017 hdb = create_db();
1018 ok( hdb, "failed to create db\n");
1020 /* tables should be present */
1021 r = MsiDatabaseOpenView(hdb, "select * from _Tables", &hview);
1022 ok( r == ERROR_SUCCESS, "failed to open query\n");
1024 r = MsiViewExecute(hview, 0);
1025 ok( r == ERROR_SUCCESS, "failed to execute query\n");
1027 /* check that NAMES works */
1028 rec = 0;
1029 r = MsiViewGetColumnInfo( hview, MSICOLINFO_NAMES, &rec );
1030 ok( r == ERROR_SUCCESS, "failed to get names\n");
1031 sz = sizeof buffer;
1032 r = MsiRecordGetString(rec, 1, buffer, &sz );
1033 ok( r == ERROR_SUCCESS, "failed to get string\n");
1034 ok( !strcmp(buffer,"Name"), "_Tables has wrong column name\n");
1035 r = MsiCloseHandle( rec );
1036 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1038 /* check that TYPES works */
1039 rec = 0;
1040 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, &rec );
1041 ok( r == ERROR_SUCCESS, "failed to get names\n");
1042 sz = sizeof buffer;
1043 r = MsiRecordGetString(rec, 1, buffer, &sz );
1044 ok( r == ERROR_SUCCESS, "failed to get string\n");
1045 ok( !strcmp(buffer,"s64"), "_Tables has wrong column type\n");
1046 r = MsiCloseHandle( rec );
1047 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1049 /* check that invalid values fail */
1050 rec = 0;
1051 r = MsiViewGetColumnInfo( hview, 100, &rec );
1052 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1053 ok( rec == 0, "returned a record\n");
1055 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, NULL );
1056 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1058 r = MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES, &rec );
1059 ok( r == ERROR_INVALID_HANDLE, "wrong error code\n");
1061 r = MsiViewClose(hview);
1062 ok( r == ERROR_SUCCESS, "failed to close view\n");
1063 r = MsiCloseHandle(hview);
1064 ok( r == ERROR_SUCCESS, "failed to close view handle\n");
1065 r = MsiCloseHandle(hdb);
1066 ok( r == ERROR_SUCCESS, "failed to close database\n");
1069 static MSIHANDLE get_column_info(MSIHANDLE hdb, const char *query, MSICOLINFO type)
1071 MSIHANDLE hview = 0, rec = 0;
1072 UINT r;
1074 r = MsiDatabaseOpenView(hdb, query, &hview);
1075 if( r != ERROR_SUCCESS )
1076 return r;
1078 r = MsiViewExecute(hview, 0);
1079 if( r == ERROR_SUCCESS )
1081 MsiViewGetColumnInfo( hview, type, &rec );
1082 MsiViewClose(hview);
1084 MsiCloseHandle(hview);
1085 return rec;
1088 static UINT get_columns_table_type(MSIHANDLE hdb, const char *table, UINT field)
1090 MSIHANDLE hview = 0, rec = 0;
1091 UINT r, type = 0;
1092 char query[0x100];
1094 sprintf(query, "select * from `_Columns` where `Table` = '%s'", table );
1096 r = MsiDatabaseOpenView(hdb, query, &hview);
1097 if( r != ERROR_SUCCESS )
1098 return r;
1100 r = MsiViewExecute(hview, 0);
1101 if( r == ERROR_SUCCESS )
1103 while (1)
1105 r = MsiViewFetch( hview, &rec );
1106 if( r != ERROR_SUCCESS)
1107 break;
1108 r = MsiRecordGetInteger( rec, 2 );
1109 if (r == field)
1110 type = MsiRecordGetInteger( rec, 4 );
1111 MsiCloseHandle( rec );
1114 MsiViewClose(hview);
1116 MsiCloseHandle(hview);
1117 return type;
1120 static BOOL check_record( MSIHANDLE rec, UINT field, LPCSTR val )
1122 CHAR buffer[0x20];
1123 UINT r;
1124 DWORD sz;
1126 sz = sizeof buffer;
1127 r = MsiRecordGetString( rec, field, buffer, &sz );
1128 return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
1131 static void test_viewgetcolumninfo(void)
1133 MSIHANDLE hdb = 0, rec;
1134 UINT r;
1136 hdb = create_db();
1137 ok( hdb, "failed to create db\n");
1139 r = run_query( hdb, 0,
1140 "CREATE TABLE `Properties` "
1141 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1142 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1144 /* check the column types */
1145 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_TYPES );
1146 ok( rec, "failed to get column info record\n" );
1148 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1149 ok( check_record( rec, 2, "S1"), "wrong record type\n");
1151 MsiCloseHandle( rec );
1153 /* check the type in _Columns */
1154 ok( 0x3dff == get_columns_table_type(hdb, "Properties", 1 ), "_columns table wrong\n");
1155 ok( 0x1d01 == get_columns_table_type(hdb, "Properties", 2 ), "_columns table wrong\n");
1157 /* now try the names */
1158 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_NAMES );
1159 ok( rec, "failed to get column info record\n" );
1161 ok( check_record( rec, 1, "Property"), "wrong record type\n");
1162 ok( check_record( rec, 2, "Value"), "wrong record type\n");
1164 MsiCloseHandle( rec );
1166 r = run_query( hdb, 0,
1167 "CREATE TABLE `Binary` "
1168 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
1169 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1171 /* check the column types */
1172 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_TYPES );
1173 ok( rec, "failed to get column info record\n" );
1175 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1176 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1178 MsiCloseHandle( rec );
1180 /* check the type in _Columns */
1181 ok( 0x3dff == get_columns_table_type(hdb, "Binary", 1 ), "_columns table wrong\n");
1182 ok( 0x1900 == get_columns_table_type(hdb, "Binary", 2 ), "_columns table wrong\n");
1184 /* now try the names */
1185 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_NAMES );
1186 ok( rec, "failed to get column info record\n" );
1188 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1189 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1190 MsiCloseHandle( rec );
1192 r = run_query( hdb, 0,
1193 "CREATE TABLE `UIText` "
1194 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1195 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1197 ok( 0x2d48 == get_columns_table_type(hdb, "UIText", 1 ), "_columns table wrong\n");
1198 ok( 0x1fff == get_columns_table_type(hdb, "UIText", 2 ), "_columns table wrong\n");
1200 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_NAMES );
1201 ok( rec, "failed to get column info record\n" );
1202 ok( check_record( rec, 1, "Key"), "wrong record type\n");
1203 ok( check_record( rec, 2, "Text"), "wrong record type\n");
1204 MsiCloseHandle( rec );
1206 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_TYPES );
1207 ok( rec, "failed to get column info record\n" );
1208 ok( check_record( rec, 1, "s72"), "wrong record type\n");
1209 ok( check_record( rec, 2, "L255"), "wrong record type\n");
1210 MsiCloseHandle( rec );
1212 MsiCloseHandle( hdb );
1215 static void test_msiexport(void)
1217 MSIHANDLE hdb = 0, hview = 0;
1218 UINT r;
1219 const char *query;
1220 char path[MAX_PATH];
1221 const char file[] = "phone.txt";
1222 HANDLE handle;
1223 char buffer[0x100];
1224 DWORD length;
1225 const char expected[] =
1226 "id\tname\tnumber\r\n"
1227 "I2\tS32\tS32\r\n"
1228 "phone\tid\r\n"
1229 "1\tAbe\t8675309\r\n";
1231 DeleteFile(msifile);
1233 /* just MsiOpenDatabase should not create a file */
1234 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1235 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1237 /* create a table */
1238 query = "CREATE TABLE `phone` ( "
1239 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1240 "PRIMARY KEY `id`)";
1241 r = MsiDatabaseOpenView(hdb, query, &hview);
1242 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1243 r = MsiViewExecute(hview, 0);
1244 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1245 r = MsiViewClose(hview);
1246 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1247 r = MsiCloseHandle(hview);
1248 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1250 /* insert a value into it */
1251 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
1252 "VALUES('1', 'Abe', '8675309')";
1253 r = MsiDatabaseOpenView(hdb, query, &hview);
1254 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1255 r = MsiViewExecute(hview, 0);
1256 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1257 r = MsiViewClose(hview);
1258 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1259 r = MsiCloseHandle(hview);
1260 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1262 GetCurrentDirectory(MAX_PATH, path);
1264 r = MsiDatabaseExport(hdb, "phone", path, file);
1265 ok(r == ERROR_SUCCESS, "MsiDatabaseExport failed\n");
1267 MsiCloseHandle(hdb);
1269 lstrcat(path, "\\");
1270 lstrcat(path, file);
1272 /* check the data that was written */
1273 length = 0;
1274 memset(buffer, 0, sizeof buffer);
1275 handle = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
1276 if (handle != INVALID_HANDLE_VALUE)
1278 ReadFile(handle, buffer, sizeof buffer, &length, NULL);
1279 CloseHandle(handle);
1280 DeleteFile(path);
1282 else
1283 ok(0, "failed to open file %s\n", path);
1285 ok( length == strlen(expected), "length of data wrong\n");
1286 ok( !lstrcmp(buffer, expected), "data doesn't match\n");
1287 DeleteFile(msifile);
1290 static void test_longstrings(void)
1292 const char insert_query[] =
1293 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1294 char *str;
1295 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
1296 DWORD len;
1297 UINT r;
1298 const DWORD STRING_LENGTH = 0x10005;
1300 DeleteFile(msifile);
1301 /* just MsiOpenDatabase should not create a file */
1302 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1303 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1305 /* create a table */
1306 r = try_query( hdb,
1307 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1308 ok(r == ERROR_SUCCESS, "query failed\n");
1310 /* try a insert a very long string */
1311 str = HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH+sizeof insert_query);
1312 len = strchr(insert_query, 'Z') - insert_query;
1313 strcpy(str, insert_query);
1314 memset(str+len, 'Z', STRING_LENGTH);
1315 strcpy(str+len+STRING_LENGTH, insert_query+len+1);
1316 r = try_query( hdb, str );
1317 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1319 HeapFree(GetProcessHeap(), 0, str);
1321 MsiDatabaseCommit(hdb);
1322 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
1323 MsiCloseHandle(hdb);
1325 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
1326 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1328 r = MsiDatabaseOpenView(hdb, "select * from `strings` where `id` = 1", &hview);
1329 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1331 r = MsiViewExecute(hview, 0);
1332 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1334 r = MsiViewFetch(hview, &hrec);
1335 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1337 MsiCloseHandle(hview);
1339 r = MsiRecordGetString(hrec, 2, NULL, &len);
1340 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1341 ok(len == STRING_LENGTH, "string length wrong\n");
1343 MsiCloseHandle(hrec);
1344 MsiCloseHandle(hdb);
1345 DeleteFile(msifile);
1348 static void create_file(const CHAR *name)
1350 HANDLE file;
1351 DWORD written;
1353 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1354 ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
1355 WriteFile(file, name, strlen(name), &written, NULL);
1356 WriteFile(file, "\n", strlen("\n"), &written, NULL);
1357 CloseHandle(file);
1360 static void test_streamtable(void)
1362 MSIHANDLE hdb = 0, rec, view;
1363 char file[MAX_PATH];
1364 char buf[MAX_PATH];
1365 DWORD size;
1366 UINT r;
1368 hdb = create_db();
1369 ok( hdb, "failed to create db\n");
1371 r = run_query( hdb, 0,
1372 "CREATE TABLE `Properties` "
1373 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1374 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1376 r = run_query( hdb, 0,
1377 "INSERT INTO `Properties` "
1378 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1379 ok( r == ERROR_SUCCESS, "Failed to add to table\n" );
1381 r = MsiDatabaseCommit( hdb );
1382 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1384 MsiCloseHandle( hdb );
1386 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
1387 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1389 /* check the column types */
1390 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_TYPES );
1391 ok( rec, "failed to get column info record\n" );
1393 ok( check_record( rec, 1, "s62"), "wrong record type\n");
1394 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1396 MsiCloseHandle( rec );
1398 /* now try the names */
1399 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_NAMES );
1400 ok( rec, "failed to get column info record\n" );
1402 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1403 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1405 MsiCloseHandle( rec );
1407 /* insert a file into the _Streams table */
1408 create_file( "test.txt" );
1410 rec = MsiCreateRecord( 2 );
1411 MsiRecordSetString( rec, 1, "data" );
1413 r = MsiRecordSetStream( rec, 2, "test.txt" );
1414 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1416 DeleteFile("test.txt");
1418 r = MsiDatabaseOpenView( hdb,
1419 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view );
1420 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1422 r = MsiViewExecute( view, rec );
1423 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1425 MsiCloseHandle( rec );
1426 MsiCloseHandle( view );
1428 r = MsiDatabaseOpenView( hdb,
1429 "SELECT `Name`, `Data` FROM `_Streams`", &view );
1430 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1432 r = MsiViewExecute( view, 0 );
1433 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1435 r = MsiViewFetch( view, &rec );
1436 ok( r == ERROR_SUCCESS, "Failed to fetch record: %d\n", r);
1438 size = MAX_PATH;
1439 r = MsiRecordGetString( rec, 1, file, &size );
1440 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1441 ok( !lstrcmp(file, "data"), "Expected 'data', got %s\n", file);
1443 size = MAX_PATH;
1444 memset(buf, 0, MAX_PATH);
1445 r = MsiRecordReadStream( rec, 2, buf, &size );
1446 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1447 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf);
1449 MsiCloseHandle( rec );
1451 r = MsiViewFetch( view, &rec );
1452 ok( r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
1454 MsiCloseHandle( view );
1455 MsiCloseHandle( hdb );
1456 DeleteFile(msifile);
1459 static void test_where(void)
1461 MSIHANDLE hdb = 0, rec, view;
1462 LPCSTR query;
1463 UINT r;
1464 DWORD size;
1465 CHAR buf[MAX_PATH];
1466 UINT count;
1468 hdb = create_db();
1469 ok( hdb, "failed to create db\n");
1471 r = run_query( hdb, 0,
1472 "CREATE TABLE `Media` ("
1473 "`DiskId` SHORT NOT NULL, "
1474 "`LastSequence` LONG, "
1475 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1476 "`Cabinet` CHAR(255), "
1477 "`VolumeLabel` CHAR(32), "
1478 "`Source` CHAR(72) "
1479 "PRIMARY KEY `DiskId`)" );
1480 ok( r == S_OK, "cannot create Media table: %d\n", r );
1482 r = run_query( hdb, 0, "INSERT INTO `Media` "
1483 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1484 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1485 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1487 r = run_query( hdb, 0, "INSERT INTO `Media` "
1488 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1489 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1490 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1492 r = run_query( hdb, 0, "INSERT INTO `Media` "
1493 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1494 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1495 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1497 query = "SELECT * FROM `Media`";
1498 r = do_query(hdb, query, &rec);
1499 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1500 ok( check_record( rec, 4, "zero.cab"), "wrong cabinet\n");
1501 MsiCloseHandle( rec );
1503 query = "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1504 r = do_query(hdb, query, &rec);
1505 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1506 ok( check_record( rec, 4, "one.cab"), "wrong cabinet\n");
1508 r = MsiRecordGetInteger(rec, 1);
1509 ok( 2 == r, "field wrong\n");
1510 r = MsiRecordGetInteger(rec, 2);
1511 ok( 1 == r, "field wrong\n");
1512 MsiCloseHandle( rec );
1514 query = "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1515 r = MsiDatabaseOpenView(hdb, query, &view);
1516 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1518 r = MsiViewExecute(view, 0);
1519 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1521 r = MsiViewFetch(view, &rec);
1522 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1524 count = MsiRecordGetFieldCount( rec );
1525 ok( count == 1, "Expected 1 record fields, got %d\n", count );
1527 size = MAX_PATH;
1528 r = MsiRecordGetString( rec, 1, buf, &size );
1529 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1530 ok( !lstrcmp( buf, "2" ),
1531 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf );
1532 MsiCloseHandle( rec );
1534 r = MsiViewFetch(view, &rec);
1535 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1537 size = MAX_PATH;
1538 r = MsiRecordGetString( rec, 1, buf, &size );
1539 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1540 ok( !lstrcmp( buf, "3" ),
1541 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf );
1542 MsiCloseHandle( rec );
1544 r = MsiViewFetch(view, &rec);
1545 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
1547 MsiViewClose(view);
1548 MsiCloseHandle(view);
1550 MsiCloseHandle( rec );
1552 rec = 0;
1553 query = "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1554 r = do_query(hdb, query, &rec);
1555 ok( r == ERROR_SUCCESS, "query failed: %d\n", r );
1556 MsiCloseHandle( rec );
1558 rec = MsiCreateRecord(1);
1559 MsiRecordSetString(rec, 1, "");
1561 query = "SELECT * FROM `Media` WHERE `DiskPrompt` = ?";
1562 r = MsiDatabaseOpenView(hdb, query, &view);
1563 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1564 r = MsiViewExecute(view, rec);
1565 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1567 MsiCloseHandle(rec);
1569 r = MsiViewFetch(view, &rec);
1570 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1572 MsiCloseHandle(rec);
1573 MsiViewClose(view);
1574 MsiCloseHandle(view);
1576 MsiCloseHandle( hdb );
1577 DeleteFile(msifile);
1580 static CHAR CURR_DIR[MAX_PATH];
1582 static const CHAR test_data[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1583 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1584 "TestTable\tFirstPrimaryColumn\n"
1585 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1587 static const CHAR two_primary[] = "PrimaryOne\tPrimaryTwo\n"
1588 "s255\ts255\n"
1589 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1590 "papaya\tleaf\n"
1591 "papaya\tflower\n";
1593 static const CHAR endlines1[] = "A\tB\tC\tD\tE\tF\r\n"
1594 "s72\ts72\ts72\ts72\ts72\ts72\n"
1595 "Table\tA\r\n"
1596 "a\tb\tc\td\te\tf\n"
1597 "g\th\ti\t\rj\tk\tl\r\n";
1599 static const CHAR endlines2[] = "A\tB\tC\tD\tE\tF\r"
1600 "s72\ts72\ts72\ts72\ts72\ts72\n"
1601 "Table2\tA\r\n"
1602 "a\tb\tc\td\te\tf\n"
1603 "g\th\ti\tj\tk\tl\r\n";
1605 static void write_file(const CHAR *filename, const char *data, int data_size)
1607 DWORD size;
1609 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
1610 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1612 WriteFile(hf, data, data_size, &size, NULL);
1613 CloseHandle(hf);
1616 static UINT add_table_to_db(MSIHANDLE hdb, LPCSTR table_data)
1618 UINT r;
1620 write_file("temp_file", table_data, (lstrlen(table_data) - 1) * sizeof(char));
1621 r = MsiDatabaseImportA(hdb, CURR_DIR, "temp_file");
1622 DeleteFileA("temp_file");
1624 return r;
1627 static void test_msiimport(void)
1629 MSIHANDLE hdb, view, rec;
1630 LPCSTR query;
1631 UINT r, count;
1632 signed int i;
1634 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
1636 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
1637 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1639 r = add_table_to_db(hdb, test_data);
1640 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1642 r = add_table_to_db(hdb, two_primary);
1643 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1645 r = add_table_to_db(hdb, endlines1);
1646 if (r == ERROR_FUNCTION_FAILED)
1648 /* win9x doesn't handle this case */
1649 skip("endlines not handled correctly.\n");
1650 MsiCloseHandle(hdb);
1651 DeleteFileA(msifile);
1652 return;
1655 r = add_table_to_db(hdb, endlines2);
1656 ok(r == ERROR_FUNCTION_FAILED,
1657 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
1659 query = "SELECT * FROM `TestTable`";
1660 r = MsiDatabaseOpenView(hdb, query, &view);
1661 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1663 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
1664 count = MsiRecordGetFieldCount(rec);
1665 ok(count == 9, "Expected 9, got %d\n", count);
1666 ok(check_record(rec, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
1667 ok(check_record(rec, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
1668 ok(check_record(rec, 3, "ShortInt"), "Expected ShortInt\n");
1669 ok(check_record(rec, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
1670 ok(check_record(rec, 5, "LongInt"), "Expected LongInt\n");
1671 ok(check_record(rec, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
1672 ok(check_record(rec, 7, "String"), "Expected String\n");
1673 ok(check_record(rec, 8, "LocalizableString"), "Expected LocalizableString\n");
1674 ok(check_record(rec, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
1675 MsiCloseHandle(rec);
1677 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
1678 count = MsiRecordGetFieldCount(rec);
1679 ok(count == 9, "Expected 9, got %d\n", count);
1680 ok(check_record(rec, 1, "s255"), "Expected s255\n");
1681 ok(check_record(rec, 2, "i2"), "Expected i2\n");
1682 ok(check_record(rec, 3, "i2"), "Expected i2\n");
1683 ok(check_record(rec, 4, "I2"), "Expected I2\n");
1684 ok(check_record(rec, 5, "i4"), "Expected i4\n");
1685 ok(check_record(rec, 6, "I4"), "Expected I4\n");
1686 ok(check_record(rec, 7, "S255"), "Expected S255\n");
1687 ok(check_record(rec, 8, "S0"), "Expected S0\n");
1688 ok(check_record(rec, 9, "s0"), "Expected s0\n");
1689 MsiCloseHandle(rec);
1691 query = "SELECT * FROM `TestTable`";
1692 r = do_query(hdb, query, &rec);
1693 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1694 ok(check_record(rec, 1, "stringage"), "Expected 'stringage'\n");
1695 ok(check_record(rec, 7, "another string"), "Expected 'another string'\n");
1696 ok(check_record(rec, 8, "localizable"), "Expected 'localizable'\n");
1697 ok(check_record(rec, 9, "duh"), "Expected 'duh'\n");
1699 i = MsiRecordGetInteger(rec, 2);
1700 ok(i == 5, "Expected 5, got %d\n", i);
1702 i = MsiRecordGetInteger(rec, 3);
1703 ok(i == 2, "Expected 2, got %d\n", i);
1705 i = MsiRecordGetInteger(rec, 4);
1706 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
1708 i = MsiRecordGetInteger(rec, 5);
1709 ok(i == 2147483640, "Expected 2147483640, got %d\n", i);
1711 i = MsiRecordGetInteger(rec, 6);
1712 ok(i == -2147483640, "Expected -2147483640, got %d\n", i);
1714 MsiCloseHandle(rec);
1715 MsiCloseHandle(view);
1717 query = "SELECT * FROM `TwoPrimary`";
1718 r = MsiDatabaseOpenView(hdb, query, &view);
1719 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1721 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
1722 count = MsiRecordGetFieldCount(rec);
1723 ok(count == 2, "Expected 2, got %d\n", count);
1724 ok(check_record(rec, 1, "PrimaryOne"), "Expected PrimaryOne\n");
1725 ok(check_record(rec, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
1727 MsiCloseHandle(rec);
1729 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
1730 count = MsiRecordGetFieldCount(rec);
1731 ok(count == 2, "Expected 2, got %d\n", count);
1732 ok(check_record(rec, 1, "s255"), "Expected s255\n");
1733 ok(check_record(rec, 2, "s255"), "Expected s255\n");
1734 MsiCloseHandle(rec);
1736 r = MsiViewExecute(view, 0);
1737 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1739 r = MsiViewFetch(view, &rec);
1740 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1742 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
1743 ok(check_record(rec, 2, "leaf"), "Expected 'leaf'\n");
1745 MsiCloseHandle(rec);
1747 r = MsiViewFetch(view, &rec);
1748 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1750 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
1751 ok(check_record(rec, 2, "flower"), "Expected 'flower'\n");
1753 MsiCloseHandle(rec);
1755 r = MsiViewFetch(view, &rec);
1756 ok(r == ERROR_NO_MORE_ITEMS,
1757 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
1759 r = MsiViewClose(view);
1760 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1762 MsiCloseHandle(view);
1764 query = "SELECT * FROM `Table`";
1765 r = MsiDatabaseOpenView(hdb, query, &view);
1766 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1768 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
1769 count = MsiRecordGetFieldCount(rec);
1770 ok(count == 6, "Expected 6, got %d\n", count);
1771 ok(check_record(rec, 1, "A"), "Expected A\n");
1772 ok(check_record(rec, 2, "B"), "Expected B\n");
1773 ok(check_record(rec, 3, "C"), "Expected C\n");
1774 ok(check_record(rec, 4, "D"), "Expected D\n");
1775 ok(check_record(rec, 5, "E"), "Expected E\n");
1776 ok(check_record(rec, 6, "F"), "Expected F\n");
1777 MsiCloseHandle(rec);
1779 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
1780 count = MsiRecordGetFieldCount(rec);
1781 ok(count == 6, "Expected 6, got %d\n", count);
1782 ok(check_record(rec, 1, "s72"), "Expected s72\n");
1783 ok(check_record(rec, 2, "s72"), "Expected s72\n");
1784 ok(check_record(rec, 3, "s72"), "Expected s72\n");
1785 ok(check_record(rec, 4, "s72"), "Expected s72\n");
1786 ok(check_record(rec, 5, "s72"), "Expected s72\n");
1787 ok(check_record(rec, 6, "s72"), "Expected s72\n");
1788 MsiCloseHandle(rec);
1790 MsiViewClose(view);
1791 MsiCloseHandle(view);
1793 query = "SELECT * FROM `Table`";
1794 r = MsiDatabaseOpenView(hdb, query, &view);
1795 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1797 r = MsiViewExecute(view, 0);
1798 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1800 r = MsiViewFetch(view, &rec);
1801 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1802 ok(check_record(rec, 1, "a"), "Expected 'a'\n");
1803 ok(check_record(rec, 2, "b"), "Expected 'b'\n");
1804 ok(check_record(rec, 3, "c"), "Expected 'c'\n");
1805 ok(check_record(rec, 4, "d"), "Expected 'd'\n");
1806 ok(check_record(rec, 5, "e"), "Expected 'e'\n");
1807 ok(check_record(rec, 6, "f"), "Expected 'f'\n");
1809 MsiCloseHandle(rec);
1811 r = MsiViewFetch(view, &rec);
1812 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1813 ok(check_record(rec, 1, "g"), "Expected 'g'\n");
1814 ok(check_record(rec, 2, "h"), "Expected 'h'\n");
1815 ok(check_record(rec, 3, "i"), "Expected 'i'\n");
1816 ok(check_record(rec, 4, "j"), "Expected 'j'\n");
1817 ok(check_record(rec, 5, "k"), "Expected 'k'\n");
1818 ok(check_record(rec, 6, "l"), "Expected 'l'\n");
1820 MsiCloseHandle(rec);
1822 r = MsiViewFetch(view, &rec);
1823 ok(r == ERROR_NO_MORE_ITEMS,
1824 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
1826 MsiViewClose(view);
1827 MsiCloseHandle(view);
1828 MsiCloseHandle(hdb);
1829 DeleteFileA(msifile);
1832 static void test_markers(void)
1834 MSIHANDLE hdb, rec;
1835 LPCSTR query;
1836 UINT r;
1838 hdb = create_db();
1839 ok( hdb, "failed to create db\n");
1841 rec = MsiCreateRecord(3);
1842 MsiRecordSetString(rec, 1, "Table");
1843 MsiRecordSetString(rec, 2, "Apples");
1844 MsiRecordSetString(rec, 3, "Oranges");
1846 /* try a legit create */
1847 query = "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1848 r = run_query(hdb, 0, query);
1849 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1850 MsiCloseHandle(rec);
1852 /* try table name as marker */
1853 rec = MsiCreateRecord(1);
1854 MsiRecordSetString(rec, 1, "Fable");
1855 query = "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1856 r = run_query(hdb, rec, query);
1857 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1859 /* verify that we just created a table called '?', not 'Fable' */
1860 r = try_query(hdb, "SELECT * from `Fable`");
1861 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1863 r = try_query(hdb, "SELECT * from `?`");
1864 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1866 /* try table name as marker without backticks */
1867 MsiRecordSetString(rec, 1, "Mable");
1868 query = "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1869 r = run_query(hdb, rec, query);
1870 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1872 /* try one column name as marker */
1873 MsiRecordSetString(rec, 1, "One");
1874 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1875 r = run_query(hdb, rec, query);
1876 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1877 MsiCloseHandle(rec);
1879 /* try column names as markers */
1880 rec = MsiCreateRecord(2);
1881 MsiRecordSetString(rec, 1, "One");
1882 MsiRecordSetString(rec, 2, "Two");
1883 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
1884 r = run_query(hdb, rec, query);
1885 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1886 MsiCloseHandle(rec);
1888 /* try names with backticks */
1889 rec = MsiCreateRecord(3);
1890 MsiRecordSetString(rec, 1, "One");
1891 MsiRecordSetString(rec, 2, "Two");
1892 MsiRecordSetString(rec, 3, "One");
1893 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1894 r = run_query(hdb, rec, query);
1895 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1897 /* try names with backticks, minus definitions */
1898 query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
1899 r = run_query(hdb, rec, query);
1900 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1902 /* try names without backticks */
1903 query = "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
1904 r = run_query(hdb, rec, query);
1905 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1906 MsiCloseHandle(rec);
1908 /* try one long marker */
1909 rec = MsiCreateRecord(1);
1910 MsiRecordSetString(rec, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
1911 query = "CREATE TABLE `Mable` ( ? )";
1912 r = run_query(hdb, rec, query);
1913 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1914 MsiCloseHandle(rec);
1916 /* try all names as markers */
1917 rec = MsiCreateRecord(4);
1918 MsiRecordSetString(rec, 1, "Mable");
1919 MsiRecordSetString(rec, 2, "One");
1920 MsiRecordSetString(rec, 3, "Two");
1921 MsiRecordSetString(rec, 4, "One");
1922 query = "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1923 r = run_query(hdb, rec, query);
1924 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1925 MsiCloseHandle(rec);
1927 /* try a legit insert */
1928 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
1929 r = run_query(hdb, 0, query);
1930 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1932 r = try_query(hdb, "SELECT * from `Table`");
1933 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1935 /* try values as markers */
1936 rec = MsiCreateRecord(2);
1937 MsiRecordSetInteger(rec, 1, 4);
1938 MsiRecordSetString(rec, 2, "hi");
1939 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1940 r = run_query(hdb, rec, query);
1941 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1942 MsiCloseHandle(rec);
1944 /* try column names and values as markers */
1945 rec = MsiCreateRecord(4);
1946 MsiRecordSetString(rec, 1, "One");
1947 MsiRecordSetString(rec, 2, "Two");
1948 MsiRecordSetInteger(rec, 3, 5);
1949 MsiRecordSetString(rec, 4, "hi");
1950 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
1951 r = run_query(hdb, rec, query);
1952 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1953 MsiCloseHandle(rec);
1955 /* try column names as markers */
1956 rec = MsiCreateRecord(2);
1957 MsiRecordSetString(rec, 1, "One");
1958 MsiRecordSetString(rec, 2, "Two");
1959 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
1960 r = run_query(hdb, rec, query);
1961 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1962 MsiCloseHandle(rec);
1964 /* try table name as a marker */
1965 rec = MsiCreateRecord(1);
1966 MsiRecordSetString(rec, 1, "Table");
1967 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
1968 r = run_query(hdb, rec, query);
1969 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1970 MsiCloseHandle(rec);
1972 /* try table name and values as markers */
1973 rec = MsiCreateRecord(3);
1974 MsiRecordSetString(rec, 1, "Table");
1975 MsiRecordSetInteger(rec, 2, 10);
1976 MsiRecordSetString(rec, 3, "haha");
1977 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
1978 r = run_query(hdb, rec, query);
1979 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
1980 MsiCloseHandle(rec);
1982 /* try all markers */
1983 rec = MsiCreateRecord(5);
1984 MsiRecordSetString(rec, 1, "Table");
1985 MsiRecordSetString(rec, 1, "One");
1986 MsiRecordSetString(rec, 1, "Two");
1987 MsiRecordSetInteger(rec, 2, 10);
1988 MsiRecordSetString(rec, 3, "haha");
1989 query = "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
1990 r = run_query(hdb, rec, query);
1991 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1992 MsiCloseHandle(rec);
1994 /* insert an integer as a string */
1995 rec = MsiCreateRecord(2);
1996 MsiRecordSetString(rec, 1, "11");
1997 MsiRecordSetString(rec, 2, "hi");
1998 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1999 r = run_query(hdb, rec, query);
2000 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2001 MsiCloseHandle(rec);
2003 /* leave off the '' for the string */
2004 rec = MsiCreateRecord(2);
2005 MsiRecordSetInteger(rec, 1, 12);
2006 MsiRecordSetString(rec, 2, "hi");
2007 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
2008 r = run_query(hdb, rec, query);
2009 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2010 MsiCloseHandle(rec);
2012 MsiCloseHandle(hdb);
2013 DeleteFileA(msifile);
2016 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
2017 static void test_handle_limit(void)
2019 int i;
2020 MSIHANDLE hdb;
2021 MSIHANDLE hviews[MY_NVIEWS];
2022 UINT r;
2024 /* create an empty db */
2025 hdb = create_db();
2026 ok( hdb, "failed to create db\n");
2028 memset(hviews, 0, sizeof(hviews));
2030 for (i=0; i<MY_NVIEWS; i++) {
2031 static char szQueryBuf[256] = "SELECT * from `_Tables`";
2032 hviews[i] = 0xdeadbeeb;
2033 r = MsiDatabaseOpenView(hdb, szQueryBuf, &hviews[i]);
2034 if( r != ERROR_SUCCESS || hviews[i] == 0xdeadbeeb ||
2035 hviews[i] == 0 || (i && (hviews[i] == hviews[i-1])))
2036 break;
2039 ok( i == MY_NVIEWS, "problem opening views\n");
2041 for (i=0; i<MY_NVIEWS; i++) {
2042 if (hviews[i] != 0 && hviews[i] != 0xdeadbeeb) {
2043 r = MsiCloseHandle(hviews[i]);
2044 if (r != ERROR_SUCCESS)
2045 break;
2049 ok( i == MY_NVIEWS, "problem closing views\n");
2051 r = MsiCloseHandle(hdb);
2052 ok( r == ERROR_SUCCESS, "failed to close database\n");
2055 static void generate_transform(void)
2057 MSIHANDLE hdb1, hdb2, hrec;
2058 LPCSTR query;
2059 UINT r;
2061 /* start with two identical databases */
2062 CopyFile(msifile2, msifile, FALSE);
2064 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb1 );
2065 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2067 r = MsiDatabaseCommit( hdb1 );
2068 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
2070 r = MsiOpenDatabase(msifile2, MSIDBOPEN_READONLY, &hdb2 );
2071 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2073 /* the transform between two identical database should be empty */
2074 r = MsiDatabaseGenerateTransform(hdb1, hdb2, NULL, 0, 0);
2075 todo_wine {
2076 ok( r == ERROR_NO_DATA, "return code %d, should be ERROR_NO_DATA\n", r );
2079 query = "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
2080 r = run_query(hdb1, 0, query);
2081 ok(r == ERROR_SUCCESS, "failed to add table\n");
2083 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
2084 r = run_query(hdb1, 0, query);
2085 ok(r == ERROR_SUCCESS, "failed to add row 1\n");
2087 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
2088 r = run_query(hdb1, 0, query);
2089 ok(r == ERROR_SUCCESS, "failed to add row 2\n");
2091 query = "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
2092 r = run_query(hdb1, 0, query);
2093 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2095 query = "DELETE FROM `MOO` WHERE `NOO` = 3";
2096 r = run_query(hdb1, 0, query);
2097 ok(r == ERROR_SUCCESS, "failed to delete row\n");
2099 hrec = MsiCreateRecord(2);
2100 r = MsiRecordSetInteger(hrec, 1, 1);
2101 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2103 write_file("testdata.bin", "naengmyon", 9);
2104 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2105 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2107 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2108 r = run_query(hdb1, hrec, query);
2109 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2111 MsiCloseHandle(hrec);
2113 query = "ALTER TABLE `MOO` ADD `COW` INTEGER";
2114 r = run_query(hdb1, 0, query);
2115 ok(r == ERROR_SUCCESS, "failed to add column\n");
2117 query = "ALTER TABLE `MOO` ADD `PIG` INTEGER";
2118 r = run_query(hdb1, 0, query);
2119 ok(r == ERROR_SUCCESS, "failed to add column\n");
2121 query = "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
2122 r = run_query(hdb1, 0, query);
2123 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2125 query = "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
2126 "`Value` CHAR(0) PRIMARY KEY `Property`)";
2127 r = run_query(hdb1, 0, query);
2128 ok(r == ERROR_SUCCESS, "failed to add property table\n");
2130 query = "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2131 r = run_query(hdb1, 0, query);
2132 ok(r == ERROR_SUCCESS, "failed to add property\n");
2134 /* database needs to be committed */
2135 MsiDatabaseCommit(hdb1);
2137 r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
2138 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
2140 MsiCloseHandle( hdb1 );
2141 MsiCloseHandle( hdb2 );
2143 DeleteFile("testdata.bin");
2146 /* data for generating a transform */
2148 /* tables transform names - encoded as they would be in an msi database file */
2149 static const WCHAR name1[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
2150 static const WCHAR name2[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
2151 static const WCHAR name3[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
2152 static const WCHAR name4[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2153 static const WCHAR name5[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2154 static const WCHAR name6[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
2155 static const WCHAR name7[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
2156 static const WCHAR name8[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
2157 static const WCHAR name9[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2159 /* data in each table */
2160 static const WCHAR data1[] = { /* AAR */
2161 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
2162 0x0201, 0x0009, 0x8002,
2164 static const WCHAR data2[] = { /* _Columns */
2165 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
2166 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
2167 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
2168 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
2169 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
2170 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
2172 static const WCHAR data3[] = { /* _Tables */
2173 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
2174 0x0101, 0x000a,
2176 static const char data4[] = /* _StringData */
2177 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
2178 static const WCHAR data5[] = { /* _StringPool */
2179 /* len, refs */
2180 0, 0, /* string 0 '' */
2181 3, 2, /* string 1 'MOO' */
2182 3, 1, /* string 2 'COW' */
2183 3, 1, /* string 3 'PIG' */
2184 1, 1, /* string 4 'c' */
2185 3, 3, /* string 5 'AAR' */
2186 3, 1, /* string 6 'CAR' */
2187 3, 1, /* string 7 'BAR' */
2188 2, 1, /* string 8 'vw' */
2189 3, 1, /* string 9 'bmw' */
2190 8, 4, /* string 10 'Property' */
2191 5, 1, /* string 11 'Value' */
2192 4, 1, /* string 12 'prop' */
2193 3, 1, /* string 13 'val' */
2195 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
2196 static const WCHAR data6[] = { /* MOO */
2197 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
2198 0x0000, 0x8003, /* delete row */
2201 static const WCHAR data7[] = { /* BINARY */
2202 0x0201, 0x8001, 0x0001,
2205 static const char data8[] = /* stream data for the BINARY table */
2206 "naengmyon";
2208 static const WCHAR data9[] = { /* Property */
2209 0x0201, 0x000c, 0x000d,
2212 static const struct {
2213 LPCWSTR name;
2214 const void *data;
2215 DWORD size;
2216 } table_transform_data[] =
2218 { name1, data1, sizeof data1 },
2219 { name2, data2, sizeof data2 },
2220 { name3, data3, sizeof data3 },
2221 { name4, data4, sizeof data4 - 1 },
2222 { name5, data5, sizeof data5 },
2223 { name6, data6, sizeof data6 },
2224 { name7, data7, sizeof data7 },
2225 { name8, data8, sizeof data8 - 1 },
2226 { name9, data9, sizeof data9 },
2229 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2231 static void generate_transform_manual(void)
2233 IStorage *stg = NULL;
2234 IStream *stm;
2235 WCHAR name[0x20];
2236 HRESULT r;
2237 DWORD i, count;
2238 const DWORD mode = STGM_CREATE|STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE;
2240 const CLSID CLSID_MsiTransform = { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2242 MultiByteToWideChar(CP_ACP, 0, mstfile, -1, name, 0x20);
2244 r = StgCreateDocfile(name, mode, 0, &stg);
2245 ok(r == S_OK, "failed to create storage\n");
2246 if (!stg)
2247 return;
2249 r = IStorage_SetClass( stg, &CLSID_MsiTransform );
2250 ok(r == S_OK, "failed to set storage type\n");
2252 for (i=0; i<NUM_TRANSFORM_TABLES; i++)
2254 r = IStorage_CreateStream( stg, table_transform_data[i].name,
2255 STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm );
2256 if (FAILED(r))
2258 ok(0, "failed to create stream %08x\n", r);
2259 continue;
2262 r = IStream_Write( stm, table_transform_data[i].data,
2263 table_transform_data[i].size, &count );
2264 if (FAILED(r) || count != table_transform_data[i].size)
2265 ok(0, "failed to write stream\n");
2266 IStream_Release(stm);
2269 IStorage_Release(stg);
2272 static UINT set_summary_info(MSIHANDLE hdb)
2274 UINT res;
2275 MSIHANDLE suminfo;
2277 /* build summmary info */
2278 res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
2279 ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );
2281 res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
2282 "Installation Database");
2283 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2285 res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
2286 "Installation Database");
2287 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2289 res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
2290 "Wine Hackers");
2291 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2293 res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
2294 ";1033");
2295 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2297 res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
2298 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2299 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2301 res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
2302 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2304 res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
2305 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2307 res = MsiSummaryInfoPersist(suminfo);
2308 ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );
2310 res = MsiCloseHandle( suminfo);
2311 ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );
2313 return res;
2316 static MSIHANDLE create_package_db(LPCSTR filename)
2318 MSIHANDLE hdb = 0;
2319 UINT res;
2321 DeleteFile(msifile);
2323 /* create an empty database */
2324 res = MsiOpenDatabase(filename, MSIDBOPEN_CREATE, &hdb );
2325 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
2326 if( res != ERROR_SUCCESS )
2327 return hdb;
2329 res = MsiDatabaseCommit( hdb );
2330 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
2332 res = set_summary_info(hdb);
2334 res = run_query( hdb, 0,
2335 "CREATE TABLE `Directory` ( "
2336 "`Directory` CHAR(255) NOT NULL, "
2337 "`Directory_Parent` CHAR(255), "
2338 "`DefaultDir` CHAR(255) NOT NULL "
2339 "PRIMARY KEY `Directory`)" );
2340 ok( res == ERROR_SUCCESS , "Failed to create directory table\n" );
2342 return hdb;
2345 static MSIHANDLE package_from_db(MSIHANDLE hdb)
2347 UINT res;
2348 CHAR szPackage[10];
2349 MSIHANDLE hPackage;
2351 sprintf(szPackage,"#%li",hdb);
2352 res = MsiOpenPackage(szPackage,&hPackage);
2353 if (res != ERROR_SUCCESS)
2354 return 0;
2356 res = MsiCloseHandle(hdb);
2357 if (res != ERROR_SUCCESS)
2358 return 0;
2360 return hPackage;
2363 static void test_try_transform(void)
2365 MSIHANDLE hdb, hview, hrec, hpkg;
2366 LPCSTR query;
2367 UINT r;
2368 DWORD sz;
2369 char buffer[MAX_PATH];
2371 DeleteFile(msifile);
2372 DeleteFile(mstfile);
2374 /* create the database */
2375 hdb = create_package_db(msifile);
2376 ok(hdb, "Failed to create package db\n");
2378 query = "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
2379 r = run_query(hdb, 0, query);
2380 ok(r == ERROR_SUCCESS, "failed to add table\n");
2382 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
2383 r = run_query(hdb, 0, query);
2384 ok(r == ERROR_SUCCESS, "failed to add row\n");
2386 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
2387 r = run_query(hdb, 0, query);
2388 ok(r == ERROR_SUCCESS, "failed to add row\n");
2390 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
2391 r = run_query(hdb, 0, query);
2392 ok(r == ERROR_SUCCESS, "failed to add row\n");
2394 query = "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
2395 r = run_query(hdb, 0, query);
2396 ok(r == ERROR_SUCCESS, "failed to add table\n");
2398 hrec = MsiCreateRecord(2);
2399 r = MsiRecordSetInteger(hrec, 1, 2);
2400 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2402 write_file("testdata.bin", "lamyon", 6);
2403 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2404 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2406 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2407 r = run_query(hdb, hrec, query);
2408 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2410 MsiCloseHandle(hrec);
2412 r = MsiDatabaseCommit( hdb );
2413 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
2415 MsiCloseHandle( hdb );
2416 DeleteFileA("testdata.bin");
2419 * Both these generate an equivalent transform,
2420 * but the first doesn't work in Wine yet
2421 * because MsiDatabaseGenerateTransform is unimplemented.
2423 if (0)
2424 generate_transform();
2425 else
2426 generate_transform_manual();
2428 r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb );
2429 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2431 r = MsiDatabaseApplyTransform( hdb, mstfile, 0 );
2432 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
2434 MsiDatabaseCommit( hdb );
2436 /* check new values */
2437 hrec = 0;
2438 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
2439 r = do_query(hdb, query, &hrec);
2440 ok(r == ERROR_SUCCESS, "select query failed\n");
2441 MsiCloseHandle(hrec);
2443 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
2444 hrec = 0;
2445 r = do_query(hdb, query, &hrec);
2446 ok(r == ERROR_SUCCESS, "select query failed\n");
2447 MsiCloseHandle(hrec);
2449 /* check updated values */
2450 hrec = 0;
2451 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
2452 r = do_query(hdb, query, &hrec);
2453 ok(r == ERROR_SUCCESS, "select query failed\n");
2454 MsiCloseHandle(hrec);
2456 /* check unchanged value */
2457 hrec = 0;
2458 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
2459 r = do_query(hdb, query, &hrec);
2460 ok(r == ERROR_SUCCESS, "select query failed\n");
2461 MsiCloseHandle(hrec);
2463 /* check deleted value */
2464 hrec = 0;
2465 query = "select * from `MOO` where `NOO` = 3";
2466 r = do_query(hdb, query, &hrec);
2467 ok(r == ERROR_NO_MORE_ITEMS, "select query failed\n");
2468 if (hrec) MsiCloseHandle(hrec);
2470 /* check added stream */
2471 hrec = 0;
2472 query = "select `BLOB` from `BINARY` where `ID` = 1";
2473 r = do_query(hdb, query, &hrec);
2474 ok(r == ERROR_SUCCESS, "select query failed\n");
2476 /* check the contents of the stream */
2477 sz = sizeof buffer;
2478 r = MsiRecordReadStream( hrec, 1, buffer, &sz );
2479 ok(r == ERROR_SUCCESS, "read stream failed\n");
2480 ok(!memcmp(buffer, "naengmyon", 9), "stream data was wrong\n");
2481 ok(sz == 9, "stream data was wrong size\n");
2482 if (hrec) MsiCloseHandle(hrec);
2484 /* check the validity of the table with a deleted row */
2485 hrec = 0;
2486 query = "select * from `MOO`";
2487 r = MsiDatabaseOpenView(hdb, query, &hview);
2488 ok(r == ERROR_SUCCESS, "open view failed\n");
2490 r = MsiViewExecute(hview, 0);
2491 ok(r == ERROR_SUCCESS, "view execute failed\n");
2493 r = MsiViewFetch(hview, &hrec);
2494 ok(r == ERROR_SUCCESS, "view fetch failed\n");
2496 r = MsiRecordGetInteger(hrec, 1);
2497 ok(r == 1, "Expected 1, got %d\n", r);
2499 sz = sizeof buffer;
2500 r = MsiRecordGetString(hrec, 2, buffer, &sz);
2501 ok(r == ERROR_SUCCESS, "record get string failed\n");
2502 ok(!lstrcmpA(buffer, "c"), "Expected c, got %s\n", buffer);
2504 r = MsiRecordGetInteger(hrec, 3);
2505 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2507 r = MsiRecordGetInteger(hrec, 4);
2508 ok(r == 5, "Expected 5, got %d\n", r);
2510 MsiCloseHandle(hrec);
2512 r = MsiViewFetch(hview, &hrec);
2513 ok(r == ERROR_SUCCESS, "view fetch failed\n");
2515 r = MsiRecordGetInteger(hrec, 1);
2516 ok(r == 2, "Expected 2, got %d\n", r);
2518 sz = sizeof buffer;
2519 r = MsiRecordGetString(hrec, 2, buffer, &sz);
2520 ok(r == ERROR_SUCCESS, "record get string failed\n");
2521 ok(!lstrcmpA(buffer, "b"), "Expected b, got %s\n", buffer);
2523 r = MsiRecordGetInteger(hrec, 3);
2524 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2526 r = MsiRecordGetInteger(hrec, 4);
2527 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2529 MsiCloseHandle(hrec);
2531 r = MsiViewFetch(hview, &hrec);
2532 ok(r == ERROR_NO_MORE_ITEMS, "view fetch succeeded\n");
2534 MsiCloseHandle(hrec);
2535 MsiCloseHandle(hview);
2537 /* check that the property was added */
2538 hpkg = package_from_db(hdb);
2539 ok(hpkg != 0, "Expected non-NULL hpkg\n");
2541 sz = MAX_PATH;
2542 r = MsiGetProperty(hpkg, "prop", buffer, &sz);
2543 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2544 ok(!lstrcmp(buffer, "val"), "Expected val, got %s\n", buffer);
2546 MsiCloseHandle(hpkg);
2547 MsiCloseHandle(hdb);
2549 DeleteFile(msifile);
2550 DeleteFile(mstfile);
2553 struct join_res
2555 const CHAR one[MAX_PATH];
2556 const CHAR two[MAX_PATH];
2559 struct join_res_4col
2561 const CHAR one[MAX_PATH];
2562 const CHAR two[MAX_PATH];
2563 const CHAR three[MAX_PATH];
2564 const CHAR four[MAX_PATH];
2567 struct join_res_uint
2569 UINT one;
2570 UINT two;
2571 UINT three;
2572 UINT four;
2573 UINT five;
2574 UINT six;
2577 static const struct join_res join_res_first[] =
2579 { "alveolar", "procerus" },
2580 { "septum", "procerus" },
2581 { "septum", "nasalis" },
2582 { "ramus", "nasalis" },
2583 { "malar", "mentalis" },
2586 static const struct join_res join_res_second[] =
2588 { "nasal", "septum" },
2589 { "mandible", "ramus" },
2592 static const struct join_res join_res_third[] =
2594 { "msvcp.dll", "abcdefgh" },
2595 { "msvcr.dll", "ijklmnop" },
2598 static const struct join_res join_res_fourth[] =
2600 { "msvcp.dll.01234", "single.dll.31415" },
2603 static const struct join_res join_res_fifth[] =
2605 { "malar", "procerus" },
2608 static const struct join_res join_res_sixth[] =
2610 { "malar", "procerus" },
2611 { "malar", "procerus" },
2612 { "malar", "nasalis" },
2613 { "malar", "nasalis" },
2614 { "malar", "nasalis" },
2615 { "malar", "mentalis" },
2618 static const struct join_res join_res_seventh[] =
2620 { "malar", "nasalis" },
2621 { "malar", "nasalis" },
2622 { "malar", "nasalis" },
2625 static const struct join_res_4col join_res_eighth[] =
2627 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
2628 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
2629 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
2630 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
2631 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
2632 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
2635 static const struct join_res_uint join_res_ninth[] =
2637 { 1, 2, 3, 4, 7, 8 },
2638 { 1, 2, 5, 6, 7, 8 },
2639 { 1, 2, 3, 4, 9, 10 },
2640 { 1, 2, 5, 6, 9, 10 },
2641 { 1, 2, 3, 4, 11, 12 },
2642 { 1, 2, 5, 6, 11, 12 },
2645 static void test_join(void)
2647 MSIHANDLE hdb, hview, hrec;
2648 LPCSTR query;
2649 CHAR buf[MAX_PATH];
2650 UINT r, count;
2651 DWORD size, i;
2652 BOOL data_correct;
2654 hdb = create_db();
2655 ok( hdb, "failed to create db\n");
2657 r = create_component_table( hdb );
2658 ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
2660 r = add_component_entry( hdb, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
2661 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2663 r = add_component_entry( hdb, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
2664 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2666 r = add_component_entry( hdb, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
2667 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2669 r = add_component_entry( hdb, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
2670 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2672 r = create_feature_components_table( hdb );
2673 ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
2675 r = add_feature_components_entry( hdb, "'procerus', 'maxilla'" );
2676 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2678 r = add_feature_components_entry( hdb, "'procerus', 'nasal'" );
2679 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2681 r = add_feature_components_entry( hdb, "'nasalis', 'nasal'" );
2682 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2684 r = add_feature_components_entry( hdb, "'nasalis', 'mandible'" );
2685 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2687 r = add_feature_components_entry( hdb, "'nasalis', 'notacomponent'" );
2688 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2690 r = add_feature_components_entry( hdb, "'mentalis', 'zygomatic'" );
2691 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2693 r = create_std_dlls_table( hdb );
2694 ok( r == ERROR_SUCCESS, "cannot create StdDlls table: %d\n", r );
2696 r = add_std_dlls_entry( hdb, "'msvcp.dll', 'msvcp.dll.01234'" );
2697 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
2699 r = add_std_dlls_entry( hdb, "'msvcr.dll', 'msvcr.dll.56789'" );
2700 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
2702 r = create_binary_table( hdb );
2703 ok( r == ERROR_SUCCESS, "cannot create Binary table: %d\n", r );
2705 r = add_binary_entry( hdb, "'msvcp.dll.01234', 'abcdefgh'" );
2706 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
2708 r = add_binary_entry( hdb, "'msvcr.dll.56789', 'ijklmnop'" );
2709 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
2711 r = add_binary_entry( hdb, "'single.dll.31415', 'msvcp.dll'" );
2712 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
2714 query = "CREATE TABLE `One` (`A` SHORT, `B` SHORT PRIMARY KEY `A`)";
2715 r = run_query( hdb, 0, query);
2716 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
2718 query = "CREATE TABLE `Two` (`C` SHORT, `D` SHORT PRIMARY KEY `C`)";
2719 r = run_query( hdb, 0, query);
2720 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
2722 query = "CREATE TABLE `Three` (`E` SHORT, `F` SHORT PRIMARY KEY `E`)";
2723 r = run_query( hdb, 0, query);
2724 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
2726 query = "INSERT INTO `One` (`A`, `B`) VALUES (1, 2)";
2727 r = run_query( hdb, 0, query);
2728 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2730 query = "INSERT INTO `Two` (`C`, `D`) VALUES (3, 4)";
2731 r = run_query( hdb, 0, query);
2732 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2734 query = "INSERT INTO `Two` (`C`, `D`) VALUES (5, 6)";
2735 r = run_query( hdb, 0, query);
2736 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2738 query = "INSERT INTO `Three` (`E`, `F`) VALUES (7, 8)";
2739 r = run_query( hdb, 0, query);
2740 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2742 query = "INSERT INTO `Three` (`E`, `F`) VALUES (9, 10)";
2743 r = run_query( hdb, 0, query);
2744 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2746 query = "INSERT INTO `Three` (`E`, `F`) VALUES (11, 12)";
2747 r = run_query( hdb, 0, query);
2748 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2750 query = "CREATE TABLE `Four` (`G` SHORT, `H` SHORT PRIMARY KEY `G`)";
2751 r = run_query( hdb, 0, query);
2752 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
2754 query = "CREATE TABLE `Five` (`I` SHORT, `J` SHORT PRIMARY KEY `I`)";
2755 r = run_query( hdb, 0, query);
2756 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
2758 query = "INSERT INTO `Five` (`I`, `J`) VALUES (13, 14)";
2759 r = run_query( hdb, 0, query);
2760 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2762 query = "INSERT INTO `Five` (`I`, `J`) VALUES (15, 16)";
2763 r = run_query( hdb, 0, query);
2764 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2766 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2767 "FROM `Component`, `FeatureComponents` "
2768 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
2769 "ORDER BY `Feature_`";
2770 r = MsiDatabaseOpenView(hdb, query, &hview);
2771 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2773 r = MsiViewExecute(hview, 0);
2774 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2776 i = 0;
2777 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2779 count = MsiRecordGetFieldCount( hrec );
2780 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2782 size = MAX_PATH;
2783 r = MsiRecordGetString( hrec, 1, buf, &size );
2784 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2785 ok( !lstrcmp( buf, join_res_first[i].one ),
2786 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_first[i].one, buf );
2788 size = MAX_PATH;
2789 r = MsiRecordGetString( hrec, 2, buf, &size );
2790 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2791 ok( !lstrcmp( buf, join_res_first[i].two ),
2792 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_first[i].two, buf );
2794 i++;
2795 MsiCloseHandle(hrec);
2798 ok( i == 5, "Expected 5 rows, got %d\n", i );
2799 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2801 MsiViewClose(hview);
2802 MsiCloseHandle(hview);
2804 /* try a join without a WHERE condition */
2805 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2806 "FROM `Component`, `FeatureComponents` ";
2807 r = MsiDatabaseOpenView(hdb, query, &hview);
2808 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2810 r = MsiViewExecute(hview, 0);
2811 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2813 i = 0;
2814 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2816 i++;
2817 MsiCloseHandle(hrec);
2819 ok( i == 24, "Expected 24 rows, got %d\n", i );
2821 MsiViewClose(hview);
2822 MsiCloseHandle(hview);
2824 query = "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
2825 "WHERE FeatureComponents.Component_=Component.Component "
2826 "AND (Feature_='nasalis') ORDER BY Feature_";
2827 r = MsiDatabaseOpenView(hdb, query, &hview);
2828 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2830 r = MsiViewExecute(hview, 0);
2831 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2833 i = 0;
2834 data_correct = TRUE;
2835 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2837 count = MsiRecordGetFieldCount( hrec );
2838 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2840 size = MAX_PATH;
2841 r = MsiRecordGetString( hrec, 1, buf, &size );
2842 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2843 if( lstrcmp( buf, join_res_second[i].one ))
2844 data_correct = FALSE;
2846 size = MAX_PATH;
2847 r = MsiRecordGetString( hrec, 2, buf, &size );
2848 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2849 if( lstrcmp( buf, join_res_second[i].two ))
2850 data_correct = FALSE;
2852 i++;
2853 MsiCloseHandle(hrec);
2856 ok( data_correct, "data returned in the wrong order\n");
2858 ok( i == 2, "Expected 2 rows, got %d\n", i );
2859 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2861 MsiViewClose(hview);
2862 MsiCloseHandle(hview);
2864 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2865 "FROM `StdDlls`, `Binary` "
2866 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
2867 "ORDER BY `File`";
2868 r = MsiDatabaseOpenView(hdb, query, &hview);
2869 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2871 r = MsiViewExecute(hview, 0);
2872 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2874 i = 0;
2875 data_correct = TRUE;
2876 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2878 count = MsiRecordGetFieldCount( hrec );
2879 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2881 size = MAX_PATH;
2882 r = MsiRecordGetString( hrec, 1, buf, &size );
2883 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2884 if( lstrcmp( buf, join_res_third[i].one ) )
2885 data_correct = FALSE;
2887 size = MAX_PATH;
2888 r = MsiRecordGetString( hrec, 2, buf, &size );
2889 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2890 if( lstrcmp( buf, join_res_third[i].two ) )
2891 data_correct = FALSE;
2893 i++;
2894 MsiCloseHandle(hrec);
2896 ok( data_correct, "data returned in the wrong order\n");
2898 ok( i == 2, "Expected 2 rows, got %d\n", i );
2900 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2902 MsiViewClose(hview);
2903 MsiCloseHandle(hview);
2905 query = "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
2906 "FROM `StdDlls`, `Binary` "
2907 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
2908 "ORDER BY `Name`";
2909 r = MsiDatabaseOpenView(hdb, query, &hview);
2910 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2912 r = MsiViewExecute(hview, 0);
2913 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2915 i = 0;
2916 data_correct = TRUE;
2917 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2919 count = MsiRecordGetFieldCount( hrec );
2920 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2922 size = MAX_PATH;
2923 r = MsiRecordGetString( hrec, 1, buf, &size );
2924 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2925 if( lstrcmp( buf, join_res_fourth[i].one ))
2926 data_correct = FALSE;
2928 size = MAX_PATH;
2929 r = MsiRecordGetString( hrec, 2, buf, &size );
2930 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2931 if( lstrcmp( buf, join_res_fourth[i].two ))
2932 data_correct = FALSE;
2934 i++;
2935 MsiCloseHandle(hrec);
2937 ok( data_correct, "data returned in the wrong order\n");
2939 ok( i == 1, "Expected 1 rows, got %d\n", i );
2940 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2942 MsiViewClose(hview);
2943 MsiCloseHandle(hview);
2945 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2946 "FROM `Component`, `FeatureComponents` "
2947 "WHERE `Component`.`Component` = 'zygomatic' "
2948 "AND `FeatureComponents`.`Component_` = 'maxilla' "
2949 "ORDER BY `Feature_`";
2950 r = MsiDatabaseOpenView(hdb, query, &hview);
2951 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2953 r = MsiViewExecute(hview, 0);
2954 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2956 i = 0;
2957 data_correct = TRUE;
2958 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2960 count = MsiRecordGetFieldCount( hrec );
2961 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2963 size = MAX_PATH;
2964 r = MsiRecordGetString( hrec, 1, buf, &size );
2965 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2966 if( lstrcmp( buf, join_res_fifth[i].one ))
2967 data_correct = FALSE;
2969 size = MAX_PATH;
2970 r = MsiRecordGetString( hrec, 2, buf, &size );
2971 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2972 if( lstrcmp( buf, join_res_fifth[i].two ))
2973 data_correct = FALSE;
2975 i++;
2976 MsiCloseHandle(hrec);
2978 ok( data_correct, "data returned in the wrong order\n");
2980 ok( i == 1, "Expected 1 rows, got %d\n", i );
2981 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2983 MsiViewClose(hview);
2984 MsiCloseHandle(hview);
2986 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2987 "FROM `Component`, `FeatureComponents` "
2988 "WHERE `Component` = 'zygomatic' "
2989 "ORDER BY `Feature_`";
2990 r = MsiDatabaseOpenView(hdb, query, &hview);
2991 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2993 r = MsiViewExecute(hview, 0);
2994 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2996 i = 0;
2997 data_correct = TRUE;
2998 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3000 count = MsiRecordGetFieldCount( hrec );
3001 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3003 size = MAX_PATH;
3004 r = MsiRecordGetString( hrec, 1, buf, &size );
3005 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3006 if( lstrcmp( buf, join_res_sixth[i].one ))
3007 data_correct = FALSE;
3009 size = MAX_PATH;
3010 r = MsiRecordGetString( hrec, 2, buf, &size );
3011 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3012 if( lstrcmp( buf, join_res_sixth[i].two ))
3013 data_correct = FALSE;
3015 i++;
3016 MsiCloseHandle(hrec);
3018 ok( data_correct, "data returned in the wrong order\n");
3020 ok( i == 6, "Expected 6 rows, got %d\n", i );
3021 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3023 MsiViewClose(hview);
3024 MsiCloseHandle(hview);
3026 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3027 "FROM `Component`, `FeatureComponents` "
3028 "WHERE `Component` = 'zygomatic' "
3029 "AND `Feature_` = 'nasalis' "
3030 "ORDER BY `Feature_`";
3031 r = MsiDatabaseOpenView(hdb, query, &hview);
3032 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3034 r = MsiViewExecute(hview, 0);
3035 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3037 i = 0;
3038 data_correct = TRUE;
3039 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3041 count = MsiRecordGetFieldCount( hrec );
3042 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3044 size = MAX_PATH;
3045 r = MsiRecordGetString( hrec, 1, buf, &size );
3046 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3047 if( lstrcmp( buf, join_res_seventh[i].one ))
3048 data_correct = FALSE;
3050 size = MAX_PATH;
3051 r = MsiRecordGetString( hrec, 2, buf, &size );
3052 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3053 if( lstrcmp( buf, join_res_seventh[i].two ))
3054 data_correct = FALSE;
3056 i++;
3057 MsiCloseHandle(hrec);
3060 ok( data_correct, "data returned in the wrong order\n");
3061 ok( i == 3, "Expected 3 rows, got %d\n", i );
3062 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3064 MsiViewClose(hview);
3065 MsiCloseHandle(hview);
3067 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3068 "FROM `StdDlls`, `Binary` ";
3069 r = MsiDatabaseOpenView(hdb, query, &hview);
3070 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3072 r = MsiViewExecute(hview, 0);
3073 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3075 i = 0;
3076 data_correct = TRUE;
3077 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3079 count = MsiRecordGetFieldCount( hrec );
3080 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3082 size = MAX_PATH;
3083 r = MsiRecordGetString( hrec, 1, buf, &size );
3084 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3085 if( lstrcmp( buf, join_res_eighth[i].one ))
3086 data_correct = FALSE;
3088 size = MAX_PATH;
3089 r = MsiRecordGetString( hrec, 2, buf, &size );
3090 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3091 if( lstrcmp( buf, join_res_eighth[i].four ))
3092 data_correct = FALSE;
3094 i++;
3095 MsiCloseHandle(hrec);
3098 ok( data_correct, "data returned in the wrong order\n");
3099 ok( i == 6, "Expected 6 rows, got %d\n", i );
3100 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3102 MsiViewClose(hview);
3103 MsiCloseHandle(hview);
3105 query = "SELECT * FROM `StdDlls`, `Binary` ";
3106 r = MsiDatabaseOpenView(hdb, query, &hview);
3107 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3109 r = MsiViewExecute(hview, 0);
3110 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3112 i = 0;
3113 data_correct = TRUE;
3114 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3116 count = MsiRecordGetFieldCount( hrec );
3117 ok( count == 4, "Expected 4 record fields, got %d\n", count );
3119 size = MAX_PATH;
3120 r = MsiRecordGetString( hrec, 1, buf, &size );
3121 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3122 if( lstrcmp( buf, join_res_eighth[i].one ))
3123 data_correct = FALSE;
3125 size = MAX_PATH;
3126 r = MsiRecordGetString( hrec, 2, buf, &size );
3127 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3128 if( lstrcmp( buf, join_res_eighth[i].two ))
3129 data_correct = FALSE;
3131 size = MAX_PATH;
3132 r = MsiRecordGetString( hrec, 3, buf, &size );
3133 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3134 if( lstrcmp( buf, join_res_eighth[i].three ))
3135 data_correct = FALSE;
3137 size = MAX_PATH;
3138 r = MsiRecordGetString( hrec, 4, buf, &size );
3139 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3140 if( lstrcmp( buf, join_res_eighth[i].four ))
3141 data_correct = FALSE;
3143 i++;
3144 MsiCloseHandle(hrec);
3146 ok( data_correct, "data returned in the wrong order\n");
3148 ok( i == 6, "Expected 6 rows, got %d\n", i );
3149 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3151 MsiViewClose(hview);
3152 MsiCloseHandle(hview);
3154 query = "SELECT * FROM `One`, `Two`, `Three` ";
3155 r = MsiDatabaseOpenView(hdb, query, &hview);
3156 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3158 r = MsiViewExecute(hview, 0);
3159 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3161 i = 0;
3162 data_correct = TRUE;
3163 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3165 count = MsiRecordGetFieldCount( hrec );
3166 ok( count == 6, "Expected 6 record fields, got %d\n", count );
3168 r = MsiRecordGetInteger( hrec, 1 );
3169 if( r != join_res_ninth[i].one )
3170 data_correct = FALSE;
3172 r = MsiRecordGetInteger( hrec, 2 );
3173 if( r != join_res_ninth[i].two )
3174 data_correct = FALSE;
3176 r = MsiRecordGetInteger( hrec, 3 );
3177 if( r != join_res_ninth[i].three )
3178 data_correct = FALSE;
3180 r = MsiRecordGetInteger( hrec, 4 );
3181 if( r != join_res_ninth[i].four )
3182 data_correct = FALSE;
3184 r = MsiRecordGetInteger( hrec, 5 );
3185 if( r != join_res_ninth[i].five )
3186 data_correct = FALSE;
3188 r = MsiRecordGetInteger( hrec, 6);
3189 if( r != join_res_ninth[i].six )
3190 data_correct = FALSE;
3192 i++;
3193 MsiCloseHandle(hrec);
3195 ok( data_correct, "data returned in the wrong order\n");
3197 ok( i == 6, "Expected 6 rows, got %d\n", i );
3198 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3200 MsiViewClose(hview);
3201 MsiCloseHandle(hview);
3203 query = "SELECT * FROM `Four`, `Five`";
3204 r = MsiDatabaseOpenView(hdb, query, &hview);
3205 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3207 r = MsiViewExecute(hview, 0);
3208 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3210 r = MsiViewFetch(hview, &hrec);
3211 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3213 MsiViewClose(hview);
3214 MsiCloseHandle(hview);
3216 MsiCloseHandle(hdb);
3217 DeleteFile(msifile);
3220 static void test_temporary_table(void)
3222 MSICONDITION cond;
3223 MSIHANDLE hdb = 0, view = 0, rec;
3224 const char *query;
3225 UINT r;
3226 char buf[0x10];
3227 DWORD sz;
3229 cond = MsiDatabaseIsTablePersistent(0, NULL);
3230 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3232 hdb = create_db();
3233 ok( hdb, "failed to create db\n");
3235 cond = MsiDatabaseIsTablePersistent(hdb, NULL);
3236 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3238 todo_wine {
3239 cond = MsiDatabaseIsTablePersistent(hdb, "_Tables");
3240 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3242 cond = MsiDatabaseIsTablePersistent(hdb, "_Columns");
3243 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3246 cond = MsiDatabaseIsTablePersistent(hdb, "_Streams");
3247 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3249 query = "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
3250 r = run_query(hdb, 0, query);
3251 ok(r == ERROR_SUCCESS, "failed to add table\n");
3253 cond = MsiDatabaseIsTablePersistent(hdb, "P");
3254 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3256 query = "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
3257 r = run_query(hdb, 0, query);
3258 ok(r == ERROR_SUCCESS, "failed to add table\n");
3260 cond = MsiDatabaseIsTablePersistent(hdb, "P2");
3261 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3263 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3264 r = run_query(hdb, 0, query);
3265 ok(r == ERROR_SUCCESS, "failed to add table\n");
3267 cond = MsiDatabaseIsTablePersistent(hdb, "T");
3268 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
3270 query = "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3271 r = run_query(hdb, 0, query);
3272 ok(r == ERROR_SUCCESS, "failed to add table\n");
3274 todo_wine {
3275 cond = MsiDatabaseIsTablePersistent(hdb, "T2");
3276 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3279 query = "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
3280 r = run_query(hdb, 0, query);
3281 ok(r == ERROR_SUCCESS, "failed to add table\n");
3283 cond = MsiDatabaseIsTablePersistent(hdb, "T3");
3284 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3286 todo_wine {
3287 query = "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3288 r = run_query(hdb, 0, query);
3289 ok(r == ERROR_FUNCTION_FAILED, "failed to add table\n");
3291 cond = MsiDatabaseIsTablePersistent(hdb, "T4");
3292 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3295 query = "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
3296 r = run_query(hdb, 0, query);
3297 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add table\n");
3299 query = "select * from `T`";
3300 r = MsiDatabaseOpenView(hdb, query, &view);
3301 ok(r == ERROR_SUCCESS, "failed to query table\n");
3302 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
3303 ok(r == ERROR_SUCCESS, "failed to get column info\n");
3305 sz = sizeof buf;
3306 r = MsiRecordGetString(rec, 1, buf, &sz);
3307 ok(r == ERROR_SUCCESS, "failed to get string\n");
3308 todo_wine ok( 0 == strcmp("G255", buf), "wrong column type\n");
3310 sz = sizeof buf;
3311 r = MsiRecordGetString(rec, 2, buf, &sz);
3312 ok(r == ERROR_SUCCESS, "failed to get string\n");
3313 todo_wine ok( 0 == strcmp("j2", buf), "wrong column type\n");
3315 MsiCloseHandle( rec );
3316 MsiCloseHandle( view );
3318 /* query the table data */
3319 rec = 0;
3320 r = do_query(hdb, "select * from `_Tables` where `Name` = 'T'", &rec);
3321 ok( r == ERROR_SUCCESS, "temporary table exists in _Tables\n");
3322 MsiCloseHandle( rec );
3324 /* query the column data */
3325 rec = 0;
3326 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec);
3327 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3328 if (rec) MsiCloseHandle( rec );
3330 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec);
3331 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3332 if (rec) MsiCloseHandle( rec );
3334 MsiCloseHandle( hdb );
3336 DeleteFile(msifile);
3339 static void test_alter(void)
3341 MSICONDITION cond;
3342 MSIHANDLE hdb = 0;
3343 const char *query;
3344 UINT r;
3346 hdb = create_db();
3347 ok( hdb, "failed to create db\n");
3349 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3350 r = run_query(hdb, 0, query);
3351 ok(r == ERROR_SUCCESS, "failed to add table\n");
3353 cond = MsiDatabaseIsTablePersistent(hdb, "T");
3354 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
3356 query = "ALTER TABLE `T` HOLD";
3357 r = run_query(hdb, 0, query);
3358 ok(r == ERROR_SUCCESS, "failed to hold table %d\n", r);
3360 query = "ALTER TABLE `T` FREE";
3361 r = run_query(hdb, 0, query);
3362 ok(r == ERROR_SUCCESS, "failed to free table\n");
3364 query = "ALTER TABLE `T` FREE";
3365 r = run_query(hdb, 0, query);
3366 ok(r == ERROR_SUCCESS, "failed to free table\n");
3368 query = "ALTER TABLE `T` FREE";
3369 r = run_query(hdb, 0, query);
3370 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to free table\n");
3372 query = "ALTER TABLE `T` HOLD";
3373 r = run_query(hdb, 0, query);
3374 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to hold table %d\n", r);
3376 /* table T is removed */
3377 query = "SELECT * FROM `T`";
3378 r = run_query(hdb, 0, query);
3379 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3381 /* create the table again */
3382 query = "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
3383 r = run_query(hdb, 0, query);
3384 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3386 /* up the ref count */
3387 query = "ALTER TABLE `U` HOLD";
3388 r = run_query(hdb, 0, query);
3389 ok(r == ERROR_SUCCESS, "failed to free table\n");
3391 /* add column, no data type */
3392 query = "ALTER TABLE `U` ADD `C`";
3393 r = run_query(hdb, 0, query);
3394 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3396 query = "ALTER TABLE `U` ADD `C` INTEGER";
3397 r = run_query(hdb, 0, query);
3398 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3400 /* add column C again */
3401 query = "ALTER TABLE `U` ADD `C` INTEGER";
3402 r = run_query(hdb, 0, query);
3403 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3405 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
3406 r = run_query(hdb, 0, query);
3407 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3409 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
3410 r = run_query(hdb, 0, query);
3411 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3413 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
3414 r = run_query(hdb, 0, query);
3415 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3417 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
3418 r = run_query(hdb, 0, query);
3419 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3421 query = "SELECT * FROM `U` WHERE `D` = 8";
3422 r = run_query(hdb, 0, query);
3423 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3425 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
3426 r = run_query(hdb, 0, query);
3427 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3429 query = "ALTER COLUMN `D` FREE";
3430 r = run_query(hdb, 0, query);
3431 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3433 /* drop the ref count */
3434 query = "ALTER TABLE `U` FREE";
3435 r = run_query(hdb, 0, query);
3436 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3438 /* table is not empty */
3439 query = "SELECT * FROM `U`";
3440 r = run_query(hdb, 0, query);
3441 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3443 /* column D is removed */
3444 query = "SELECT * FROM `U` WHERE `D` = 8";
3445 r = run_query(hdb, 0, query);
3446 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3448 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
3449 r = run_query(hdb, 0, query);
3450 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3452 /* add the column again */
3453 query = "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
3454 r = run_query(hdb, 0, query);
3455 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3457 /* up the ref count */
3458 query = "ALTER TABLE `U` HOLD";
3459 r = run_query(hdb, 0, query);
3460 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3462 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
3463 r = run_query(hdb, 0, query);
3464 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3466 query = "SELECT * FROM `U` WHERE `E` = 16";
3467 r = run_query(hdb, 0, query);
3468 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3470 /* drop the ref count */
3471 query = "ALTER TABLE `U` FREE";
3472 r = run_query(hdb, 0, query);
3473 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3475 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
3476 r = run_query(hdb, 0, query);
3477 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3479 query = "SELECT * FROM `U` WHERE `E` = 20";
3480 r = run_query(hdb, 0, query);
3481 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3483 /* drop the ref count */
3484 query = "ALTER TABLE `U` FREE";
3485 r = run_query(hdb, 0, query);
3486 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3488 /* table still exists */
3489 query = "SELECT * FROM `U`";
3490 r = run_query(hdb, 0, query);
3491 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3493 /* col E is removed */
3494 query = "SELECT * FROM `U` WHERE `E` = 20";
3495 r = run_query(hdb, 0, query);
3496 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3498 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
3499 r = run_query(hdb, 0, query);
3500 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3502 /* drop the ref count once more */
3503 query = "ALTER TABLE `U` FREE";
3504 r = run_query(hdb, 0, query);
3505 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3507 /* table still exists */
3508 query = "SELECT * FROM `U`";
3509 r = run_query(hdb, 0, query);
3510 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3512 MsiCloseHandle( hdb );
3513 DeleteFile(msifile);
3516 static void test_integers(void)
3518 MSIHANDLE hdb = 0, view = 0, rec = 0;
3519 DWORD count, i;
3520 const char *query;
3521 UINT r;
3523 /* just MsiOpenDatabase should not create a file */
3524 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3525 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3527 /* create a table */
3528 query = "CREATE TABLE `integers` ( "
3529 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
3530 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
3531 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
3532 "PRIMARY KEY `one`)";
3533 r = MsiDatabaseOpenView(hdb, query, &view);
3534 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3535 r = MsiViewExecute(view, 0);
3536 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3537 r = MsiViewClose(view);
3538 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3539 r = MsiCloseHandle(view);
3540 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3542 query = "SELECT * FROM `integers`";
3543 r = MsiDatabaseOpenView(hdb, query, &view);
3544 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3546 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
3547 count = MsiRecordGetFieldCount(rec);
3548 ok(count == 8, "Expected 8, got %d\n", count);
3549 ok(check_record(rec, 1, "one"), "Expected one\n");
3550 ok(check_record(rec, 2, "two"), "Expected two\n");
3551 ok(check_record(rec, 3, "three"), "Expected three\n");
3552 ok(check_record(rec, 4, "four"), "Expected four\n");
3553 ok(check_record(rec, 5, "five"), "Expected five\n");
3554 ok(check_record(rec, 6, "six"), "Expected six\n");
3555 ok(check_record(rec, 7, "seven"), "Expected seven\n");
3556 ok(check_record(rec, 8, "eight"), "Expected eight\n");
3557 MsiCloseHandle(rec);
3559 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
3560 count = MsiRecordGetFieldCount(rec);
3561 ok(count == 8, "Expected 8, got %d\n", count);
3562 ok(check_record(rec, 1, "I2"), "Expected I2\n");
3563 ok(check_record(rec, 2, "I2"), "Expected I2\n");
3564 ok(check_record(rec, 3, "I2"), "Expected I2\n");
3565 ok(check_record(rec, 4, "I4"), "Expected I4\n");
3566 ok(check_record(rec, 5, "i2"), "Expected i2\n");
3567 ok(check_record(rec, 6, "i2"), "Expected i2\n");
3568 ok(check_record(rec, 7, "i2"), "Expected i2\n");
3569 ok(check_record(rec, 8, "i4"), "Expected i4\n");
3570 MsiCloseHandle(rec);
3572 MsiViewClose(view);
3573 MsiCloseHandle(view);
3575 /* insert values into it, NULL where NOT NULL is specified */
3576 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3577 "VALUES('', '', '', '', '', '', '', '')";
3578 r = MsiDatabaseOpenView(hdb, query, &view);
3579 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3580 r = MsiViewExecute(view, 0);
3581 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
3583 MsiViewClose(view);
3584 MsiCloseHandle(view);
3586 query = "SELECT * FROM `integers`";
3587 r = do_query(hdb, query, &rec);
3588 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3590 r = MsiRecordGetFieldCount(rec);
3591 ok(r == -1, "record count wrong: %d\n", r);
3593 MsiCloseHandle(rec);
3595 /* insert legitimate values into it */
3596 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3597 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
3598 r = MsiDatabaseOpenView(hdb, query, &view);
3599 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3600 r = MsiViewExecute(view, 0);
3601 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3603 query = "SELECT * FROM `integers`";
3604 r = do_query(hdb, query, &rec);
3605 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3607 r = MsiRecordGetFieldCount(rec);
3608 ok(r == 8, "record count wrong: %d\n", r);
3610 i = MsiRecordGetInteger(rec, 1);
3611 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
3612 i = MsiRecordGetInteger(rec, 3);
3613 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
3614 i = MsiRecordGetInteger(rec, 2);
3615 ok(i == 2, "Expected 2, got %d\n", i);
3616 i = MsiRecordGetInteger(rec, 4);
3617 ok(i == 4, "Expected 4, got %d\n", i);
3618 i = MsiRecordGetInteger(rec, 5);
3619 ok(i == 5, "Expected 5, got %d\n", i);
3620 i = MsiRecordGetInteger(rec, 6);
3621 ok(i == 6, "Expected 6, got %d\n", i);
3622 i = MsiRecordGetInteger(rec, 7);
3623 ok(i == 7, "Expected 7, got %d\n", i);
3624 i = MsiRecordGetInteger(rec, 8);
3625 ok(i == 8, "Expected 8, got %d\n", i);
3627 MsiCloseHandle(rec);
3628 MsiViewClose(view);
3629 MsiCloseHandle(view);
3631 r = MsiDatabaseCommit(hdb);
3632 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
3634 r = MsiCloseHandle(hdb);
3635 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3637 r = DeleteFile(msifile);
3638 ok(r == TRUE, "file didn't exist after commit\n");
3641 static void test_update(void)
3643 MSIHANDLE hdb = 0, view = 0, rec = 0;
3644 CHAR result[MAX_PATH];
3645 const char *query;
3646 DWORD size;
3647 UINT r;
3649 /* just MsiOpenDatabase should not create a file */
3650 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3651 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3653 /* create the Control table */
3654 query = "CREATE TABLE `Control` ( "
3655 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
3656 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
3657 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
3658 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
3659 r = MsiDatabaseOpenView(hdb, query, &view);
3660 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3661 r = MsiViewExecute(view, 0);
3662 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3663 r = MsiViewClose(view);
3664 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3665 r = MsiCloseHandle(view);
3666 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3668 /* add a control */
3669 query = "INSERT INTO `Control` ( "
3670 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3671 "`Property`, `Text`, `Control_Next`, `Help` )"
3672 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3673 r = MsiDatabaseOpenView(hdb, query, &view);
3674 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3675 r = MsiViewExecute(view, 0);
3676 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3677 r = MsiViewClose(view);
3678 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3679 r = MsiCloseHandle(view);
3680 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3682 /* add a second control */
3683 query = "INSERT INTO `Control` ( "
3684 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3685 "`Property`, `Text`, `Control_Next`, `Help` )"
3686 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
3687 r = MsiDatabaseOpenView(hdb, query, &view);
3688 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3689 r = MsiViewExecute(view, 0);
3690 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3691 r = MsiViewClose(view);
3692 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3693 r = MsiCloseHandle(view);
3694 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3696 /* add a third control */
3697 query = "INSERT INTO `Control` ( "
3698 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3699 "`Property`, `Text`, `Control_Next`, `Help` )"
3700 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3701 r = MsiDatabaseOpenView(hdb, query, &view);
3702 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3703 r = MsiViewExecute(view, 0);
3704 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3705 r = MsiViewClose(view);
3706 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3707 r = MsiCloseHandle(view);
3708 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3710 /* bad table */
3711 query = "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3712 r = MsiDatabaseOpenView(hdb, query, &view);
3713 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3715 /* bad set column */
3716 query = "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3717 r = MsiDatabaseOpenView(hdb, query, &view);
3718 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3720 /* bad where condition */
3721 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
3722 r = MsiDatabaseOpenView(hdb, query, &view);
3723 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3725 /* just the dialog_ specified */
3726 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3727 r = MsiDatabaseOpenView(hdb, query, &view);
3728 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3729 r = MsiViewExecute(view, 0);
3730 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3731 r = MsiViewClose(view);
3732 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3733 r = MsiCloseHandle(view);
3734 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3736 /* check the modified text */
3737 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3738 r = MsiDatabaseOpenView(hdb, query, &view);
3739 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3740 r = MsiViewExecute(view, 0);
3741 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3743 r = MsiViewFetch(view, &rec);
3744 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3746 size = MAX_PATH;
3747 r = MsiRecordGetString(rec, 1, result, &size);
3748 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3749 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3751 MsiCloseHandle(rec);
3753 r = MsiViewFetch(view, &rec);
3754 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3756 size = MAX_PATH;
3757 r = MsiRecordGetString(rec, 1, result, &size);
3758 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3759 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
3761 MsiCloseHandle(rec);
3763 r = MsiViewFetch(view, &rec);
3764 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3766 r = MsiViewClose(view);
3767 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3768 r = MsiCloseHandle(view);
3769 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3771 /* dialog_ and control specified */
3772 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
3773 r = MsiDatabaseOpenView(hdb, query, &view);
3774 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3775 r = MsiViewExecute(view, 0);
3776 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3777 r = MsiViewClose(view);
3778 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3779 r = MsiCloseHandle(view);
3780 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3782 /* check the modified text */
3783 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3784 r = MsiDatabaseOpenView(hdb, query, &view);
3785 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3786 r = MsiViewExecute(view, 0);
3787 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3789 r = MsiViewFetch(view, &rec);
3790 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3792 size = MAX_PATH;
3793 r = MsiRecordGetString(rec, 1, result, &size);
3794 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3795 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3797 MsiCloseHandle(rec);
3799 r = MsiViewFetch(view, &rec);
3800 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3802 size = MAX_PATH;
3803 r = MsiRecordGetString(rec, 1, result, &size);
3804 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3805 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
3807 MsiCloseHandle(rec);
3809 r = MsiViewFetch(view, &rec);
3810 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3812 r = MsiViewClose(view);
3813 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3814 r = MsiCloseHandle(view);
3815 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3817 /* no where condition */
3818 query = "UPDATE `Control` SET `Text` = 'this is text'";
3819 r = MsiDatabaseOpenView(hdb, query, &view);
3820 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3821 r = MsiViewExecute(view, 0);
3822 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3823 r = MsiViewClose(view);
3824 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3825 r = MsiCloseHandle(view);
3826 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3828 /* check the modified text */
3829 query = "SELECT `Text` FROM `Control`";
3830 r = MsiDatabaseOpenView(hdb, query, &view);
3831 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3832 r = MsiViewExecute(view, 0);
3833 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3835 r = MsiViewFetch(view, &rec);
3836 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3838 size = MAX_PATH;
3839 r = MsiRecordGetString(rec, 1, result, &size);
3840 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3841 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3843 MsiCloseHandle(rec);
3845 r = MsiViewFetch(view, &rec);
3846 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3848 size = MAX_PATH;
3849 r = MsiRecordGetString(rec, 1, result, &size);
3850 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3851 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3853 MsiCloseHandle(rec);
3855 r = MsiViewFetch(view, &rec);
3856 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3858 size = MAX_PATH;
3859 r = MsiRecordGetString(rec, 1, result, &size);
3860 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3861 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3863 MsiCloseHandle(rec);
3865 r = MsiViewFetch(view, &rec);
3866 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3868 r = MsiViewClose(view);
3869 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3870 r = MsiCloseHandle(view);
3871 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3873 query = "CREATE TABLE `Apple` ( `Banana` CHAR(72) NOT NULL, "
3874 "`Orange` CHAR(72), `Pear` INT PRIMARY KEY `Banana`)";
3875 r = run_query(hdb, 0, query);
3876 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3878 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
3879 "VALUES('one', 'two', 3)";
3880 r = run_query(hdb, 0, query);
3881 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3883 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
3884 "VALUES('three', 'four', 5)";
3885 r = run_query(hdb, 0, query);
3886 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3888 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
3889 "VALUES('six', 'two', 7)";
3890 r = run_query(hdb, 0, query);
3891 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3893 rec = MsiCreateRecord(2);
3894 MsiRecordSetInteger(rec, 1, 8);
3895 MsiRecordSetString(rec, 2, "two");
3897 query = "UPDATE `Apple` SET `Pear` = ? WHERE `Orange` = ?";
3898 r = run_query(hdb, rec, query);
3899 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3901 MsiCloseHandle(rec);
3903 query = "SELECT `Pear` FROM `Apple` ORDER BY `Orange`";
3904 r = MsiDatabaseOpenView(hdb, query, &view);
3905 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3906 r = MsiViewExecute(view, 0);
3907 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3909 r = MsiViewFetch(view, &rec);
3910 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3912 r = MsiRecordGetInteger(rec, 1);
3913 ok(r == 8, "Expected 8, got %d\n", r);
3915 MsiCloseHandle(rec);
3917 r = MsiViewFetch(view, &rec);
3918 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3920 r = MsiRecordGetInteger(rec, 1);
3921 ok(r == 8, "Expected 8, got %d\n", r);
3923 MsiCloseHandle(rec);
3925 r = MsiViewFetch(view, &rec);
3926 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3928 r = MsiRecordGetInteger(rec, 1);
3929 ok(r == 5, "Expected 5, got %d\n", r);
3931 MsiCloseHandle(rec);
3933 r = MsiViewFetch(view, &rec);
3934 ok(r == ERROR_NO_MORE_ITEMS, "Expectd ERROR_NO_MORE_ITEMS, got %d\n", r);
3936 MsiViewClose(view);
3937 MsiCloseHandle(view);
3939 r = MsiDatabaseCommit(hdb);
3940 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
3941 r = MsiCloseHandle(hdb);
3942 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3944 DeleteFile(msifile);
3947 static void test_special_tables(void)
3949 const char *query;
3950 MSIHANDLE hdb = 0;
3951 UINT r;
3953 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3954 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3956 query = "CREATE TABLE `_Properties` ( "
3957 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3958 r = run_query(hdb, 0, query);
3959 ok(r == ERROR_SUCCESS, "failed to create table\n");
3961 query = "CREATE TABLE `_Streams` ( "
3962 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3963 r = run_query(hdb, 0, query);
3964 todo_wine ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Streams table\n");
3966 query = "CREATE TABLE `_Tables` ( "
3967 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3968 r = run_query(hdb, 0, query);
3969 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Tables table\n");
3971 query = "CREATE TABLE `_Columns` ( "
3972 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3973 r = run_query(hdb, 0, query);
3974 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Columns table\n");
3976 r = MsiCloseHandle(hdb);
3977 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3980 static void test_select_markers(void)
3982 MSIHANDLE hdb = 0, rec, view, res;
3983 LPCSTR query;
3984 UINT r;
3985 DWORD size;
3986 CHAR buf[MAX_PATH];
3988 hdb = create_db();
3989 ok( hdb, "failed to create db\n");
3991 r = run_query(hdb, 0,
3992 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
3993 ok(r == S_OK, "cannot create table: %d\n", r);
3995 r = run_query(hdb, 0, "INSERT INTO `Table` "
3996 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
3997 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3999 r = run_query(hdb, 0, "INSERT INTO `Table` "
4000 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
4001 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4003 r = run_query(hdb, 0, "INSERT INTO `Table` "
4004 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
4005 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4007 r = run_query(hdb, 0, "INSERT INTO `Table` "
4008 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
4009 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4011 rec = MsiCreateRecord(2);
4012 MsiRecordSetString(rec, 1, "apple");
4013 MsiRecordSetString(rec, 2, "two");
4015 query = "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
4016 r = MsiDatabaseOpenView(hdb, query, &view);
4017 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4019 r = MsiViewExecute(view, rec);
4020 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4022 r = MsiViewFetch(view, &res);
4023 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4025 size = MAX_PATH;
4026 r = MsiRecordGetString(res, 1, buf, &size);
4027 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4028 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
4030 size = MAX_PATH;
4031 r = MsiRecordGetString(res, 2, buf, &size);
4032 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4033 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
4035 r = MsiRecordGetInteger(res, 3);
4036 ok(r == 1, "Expected 1, got %d\n", r);
4038 MsiCloseHandle(res);
4040 r = MsiViewFetch(view, &res);
4041 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4043 size = MAX_PATH;
4044 r = MsiRecordGetString(res, 1, buf, &size);
4045 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4046 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
4048 size = MAX_PATH;
4049 r = MsiRecordGetString(res, 2, buf, &size);
4050 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4051 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
4053 r = MsiRecordGetInteger(res, 3);
4054 ok(r == 2, "Expected 2, got %d\n", r);
4056 MsiCloseHandle(res);
4058 r = MsiViewFetch(view, &res);
4059 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4061 MsiCloseHandle(rec);
4062 MsiViewClose(view);
4063 MsiCloseHandle(view);
4065 rec = MsiCreateRecord(2);
4066 MsiRecordSetString(rec, 1, "one");
4067 MsiRecordSetInteger(rec, 2, 1);
4069 query = "SELECT * FROM `Table` WHERE `Two`<>? AND `Three`>? ORDER BY `Three`";
4070 r = MsiDatabaseOpenView(hdb, query, &view);
4071 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4072 r = MsiViewExecute(view, rec);
4073 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4075 r = MsiViewFetch(view, &res);
4076 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4078 size = MAX_PATH;
4079 r = MsiRecordGetString(res, 1, buf, &size);
4080 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4081 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
4083 size = MAX_PATH;
4084 r = MsiRecordGetString(res, 2, buf, &size);
4085 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4086 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
4088 r = MsiRecordGetInteger(res, 3);
4089 ok(r == 2, "Expected 2, got %d\n", r);
4091 MsiCloseHandle(res);
4093 r = MsiViewFetch(view, &res);
4094 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4096 size = MAX_PATH;
4097 r = MsiRecordGetString(res, 1, buf, &size);
4098 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4099 ok(!lstrcmp(buf, "banana"), "Expected banana, got %s\n", buf);
4101 size = MAX_PATH;
4102 r = MsiRecordGetString(res, 2, buf, &size);
4103 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4104 ok(!lstrcmp(buf, "three"), "Expected three, got %s\n", buf);
4106 r = MsiRecordGetInteger(res, 3);
4107 ok(r == 3, "Expected 3, got %d\n", r);
4109 MsiCloseHandle(res);
4111 r = MsiViewFetch(view, &res);
4112 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4114 MsiCloseHandle(rec);
4115 MsiViewClose(view);
4116 MsiCloseHandle(view);
4117 MsiCloseHandle(hdb);
4118 DeleteFile(msifile);
4121 static void test_viewmodify_update(void)
4123 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
4124 const char *query;
4125 UINT r;
4127 DeleteFile(msifile);
4129 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4130 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4132 query = "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
4133 r = run_query( hdb, 0, query );
4134 ok(r == ERROR_SUCCESS, "query failed\n");
4136 query = "INSERT INTO `table` (`A`, `B`) VALUES (1, 2)";
4137 r = run_query( hdb, 0, query );
4138 ok(r == ERROR_SUCCESS, "query failed\n");
4140 query = "INSERT INTO `table` (`A`, `B`) VALUES (3, 4)";
4141 r = run_query( hdb, 0, query );
4142 ok(r == ERROR_SUCCESS, "query failed\n");
4144 query = "INSERT INTO `table` (`A`, `B`) VALUES (5, 6)";
4145 r = run_query( hdb, 0, query );
4146 ok(r == ERROR_SUCCESS, "query failed\n");
4148 query = "SELECT `B` FROM `table`";
4149 r = MsiDatabaseOpenView(hdb, query, &hview);
4150 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4151 r = MsiViewExecute(hview, 0);
4152 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4153 r = MsiViewFetch(hview, &hrec);
4154 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4156 r = MsiRecordSetInteger(hrec, 1, 0);
4157 ok(r == ERROR_SUCCESS, "failed to set integer\n");
4159 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
4160 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
4162 r = MsiCloseHandle(hrec);
4163 ok(r == ERROR_SUCCESS, "failed to close record\n");
4165 r = MsiViewClose(hview);
4166 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4167 r = MsiCloseHandle(hview);
4168 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4170 query = "SELECT * FROM `table`";
4171 r = MsiDatabaseOpenView(hdb, query, &hview);
4172 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4173 r = MsiViewExecute(hview, 0);
4174 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4175 r = MsiViewFetch(hview, &hrec);
4176 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4178 r = MsiRecordGetInteger(hrec, 1);
4179 ok(r == 1, "Expected 1, got %d\n", r);
4180 r = MsiRecordGetInteger(hrec, 2);
4181 ok(r == 0, "Expected 0, got %d\n", r);
4183 r = MsiCloseHandle(hrec);
4184 ok(r == ERROR_SUCCESS, "failed to close record\n");
4186 r = MsiViewFetch(hview, &hrec);
4187 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4189 r = MsiRecordGetInteger(hrec, 1);
4190 ok(r == 3, "Expected 3, got %d\n", r);
4191 r = MsiRecordGetInteger(hrec, 2);
4192 ok(r == 4, "Expected 4, got %d\n", r);
4194 r = MsiCloseHandle(hrec);
4195 ok(r == ERROR_SUCCESS, "failed to close record\n");
4197 r = MsiViewFetch(hview, &hrec);
4198 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4200 r = MsiRecordGetInteger(hrec, 1);
4201 ok(r == 5, "Expected 5, got %d\n", r);
4202 r = MsiRecordGetInteger(hrec, 2);
4203 ok(r == 6, "Expected 6, got %d\n", r);
4205 r = MsiCloseHandle(hrec);
4206 ok(r == ERROR_SUCCESS, "failed to close record\n");
4208 r = MsiViewFetch(hview, &hrec);
4209 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4211 r = MsiViewClose(hview);
4212 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4213 r = MsiCloseHandle(hview);
4214 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4216 /* loop through all elements */
4217 query = "SELECT `B` FROM `table`";
4218 r = MsiDatabaseOpenView(hdb, query, &hview);
4219 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4220 r = MsiViewExecute(hview, 0);
4221 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4223 while (TRUE)
4225 r = MsiViewFetch(hview, &hrec);
4226 if (r != ERROR_SUCCESS)
4227 break;
4229 r = MsiRecordSetInteger(hrec, 1, 0);
4230 ok(r == ERROR_SUCCESS, "failed to set integer\n");
4232 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
4233 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
4235 r = MsiCloseHandle(hrec);
4236 ok(r == ERROR_SUCCESS, "failed to close record\n");
4239 r = MsiViewClose(hview);
4240 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4241 r = MsiCloseHandle(hview);
4242 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4244 query = "SELECT * FROM `table`";
4245 r = MsiDatabaseOpenView(hdb, query, &hview);
4246 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4247 r = MsiViewExecute(hview, 0);
4248 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4249 r = MsiViewFetch(hview, &hrec);
4250 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4252 r = MsiRecordGetInteger(hrec, 1);
4253 ok(r == 1, "Expected 1, got %d\n", r);
4254 r = MsiRecordGetInteger(hrec, 2);
4255 ok(r == 0, "Expected 0, got %d\n", r);
4257 r = MsiCloseHandle(hrec);
4258 ok(r == ERROR_SUCCESS, "failed to close record\n");
4260 r = MsiViewFetch(hview, &hrec);
4261 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4263 r = MsiRecordGetInteger(hrec, 1);
4264 ok(r == 3, "Expected 3, got %d\n", r);
4265 r = MsiRecordGetInteger(hrec, 2);
4266 ok(r == 0, "Expected 0, got %d\n", r);
4268 r = MsiCloseHandle(hrec);
4269 ok(r == ERROR_SUCCESS, "failed to close record\n");
4271 r = MsiViewFetch(hview, &hrec);
4272 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4274 r = MsiRecordGetInteger(hrec, 1);
4275 ok(r == 5, "Expected 5, got %d\n", r);
4276 r = MsiRecordGetInteger(hrec, 2);
4277 ok(r == 0, "Expected 0, got %d\n", r);
4279 r = MsiCloseHandle(hrec);
4280 ok(r == ERROR_SUCCESS, "failed to close record\n");
4282 r = MsiViewFetch(hview, &hrec);
4283 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4285 r = MsiViewClose(hview);
4286 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4287 r = MsiCloseHandle(hview);
4288 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4290 r = MsiCloseHandle( hdb );
4291 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
4294 static const WCHAR data10[] = { /* MOO */
4295 0x8001, 0x000b,
4297 static const WCHAR data11[] = { /* AAR */
4298 0x8002, 0x8005,
4299 0x000c, 0x000f,
4301 static const char data12[] = /* _StringData */
4302 "MOOABAARCDonetwofourfive";
4303 static const WCHAR data13[] = { /* _StringPool */
4304 /* len, refs */
4305 0, 0, /* string 0 '' */
4306 0, 0, /* string 1 '' */
4307 0, 0, /* string 2 '' */
4308 0, 0, /* string 3 '' */
4309 0, 0, /* string 4 '' */
4310 3, 3, /* string 5 'MOO' */
4311 1, 1, /* string 6 'A' */
4312 1, 1, /* string 7 'B' */
4313 3, 3, /* string 8 'AAR' */
4314 1, 1, /* string 9 'C' */
4315 1, 1, /* string a 'D' */
4316 3, 1, /* string b 'one' */
4317 3, 1, /* string c 'two' */
4318 0, 0, /* string d '' */
4319 4, 1, /* string e 'four' */
4320 4, 1, /* string f 'five' */
4323 static void test_stringtable(void)
4325 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
4326 IStorage *stg = NULL;
4327 IStream *stm;
4328 WCHAR name[0x20];
4329 HRESULT hr;
4330 const char *query;
4331 char buffer[MAX_PATH];
4332 WCHAR data[MAX_PATH];
4333 DWORD sz, read;
4334 UINT r;
4336 static const DWORD mode = STGM_DIRECT | STGM_READ | STGM_SHARE_DENY_WRITE;
4337 static const WCHAR stringdata[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0}; /* _StringData */
4338 static const WCHAR stringpool[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0}; /* _StringPool */
4339 static const WCHAR moo[] = {0x4840, 0x3e16, 0x4818, 0}; /* MOO */
4340 static const WCHAR aar[] = {0x4840, 0x3a8a, 0x481b, 0}; /* AAR */
4342 DeleteFile(msifile);
4344 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4345 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4347 query = "CREATE TABLE `MOO` (`A` INT, `B` CHAR(72) PRIMARY KEY `A`)";
4348 r = run_query(hdb, 0, query);
4349 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4351 query = "CREATE TABLE `AAR` (`C` INT, `D` CHAR(72) PRIMARY KEY `C`)";
4352 r = run_query(hdb, 0, query);
4353 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4355 /* insert persistent row */
4356 query = "INSERT INTO `MOO` (`A`, `B`) VALUES (1, 'one')";
4357 r = run_query(hdb, 0, query);
4358 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4360 /* insert persistent row */
4361 query = "INSERT INTO `AAR` (`C`, `D`) VALUES (2, 'two')";
4362 r = run_query(hdb, 0, query);
4363 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4365 /* open a view */
4366 query = "SELECT * FROM `MOO`";
4367 r = MsiDatabaseOpenView(hdb, query, &hview);
4368 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4369 r = MsiViewExecute(hview, 0);
4370 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4372 hrec = MsiCreateRecord(2);
4374 r = MsiRecordSetInteger(hrec, 1, 3);
4375 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4376 r = MsiRecordSetString(hrec, 2, "three");
4377 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4379 /* insert a nonpersistent row */
4380 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
4381 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4383 r = MsiCloseHandle(hrec);
4384 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4385 r = MsiViewClose(hview);
4386 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4387 r = MsiCloseHandle(hview);
4388 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4390 /* insert persistent row */
4391 query = "INSERT INTO `MOO` (`A`, `B`) VALUES (4, 'four')";
4392 r = run_query(hdb, 0, query);
4393 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4395 /* insert persistent row */
4396 query = "INSERT INTO `AAR` (`C`, `D`) VALUES (5, 'five')";
4397 r = run_query(hdb, 0, query);
4398 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4400 r = MsiDatabaseCommit(hdb);
4401 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4403 r = MsiCloseHandle(hdb);
4404 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4406 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
4407 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4409 query = "SELECT * FROM `MOO`";
4410 r = MsiDatabaseOpenView(hdb, query, &hview);
4411 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4413 r = MsiViewExecute(hview, 0);
4414 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4416 r = MsiViewFetch(hview, &hrec);
4417 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4419 r = MsiRecordGetFieldCount(hrec);
4420 ok(r == 2, "Expected 2, got %d\n", r);
4422 r = MsiRecordGetInteger(hrec, 1);
4423 ok(r == 1, "Expected 1, got %d\n", r);
4425 sz = sizeof(buffer);
4426 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4427 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4428 ok(!lstrcmp(buffer, "one"), "Expected one, got %s\n", buffer);
4430 r = MsiCloseHandle(hrec);
4431 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4433 r = MsiViewFetch(hview, &hrec);
4434 todo_wine
4436 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4439 r = MsiViewClose(hview);
4440 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4441 r = MsiCloseHandle(hview);
4442 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4443 r = MsiCloseHandle(hrec);
4444 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4446 query = "SELECT * FROM `AAR`";
4447 r = MsiDatabaseOpenView(hdb, query, &hview);
4448 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4450 r = MsiViewExecute(hview, 0);
4451 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4453 r = MsiViewFetch(hview, &hrec);
4454 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4456 r = MsiRecordGetFieldCount(hrec);
4457 ok(r == 2, "Expected 2, got %d\n", r);
4459 r = MsiRecordGetInteger(hrec, 1);
4460 ok(r == 2, "Expected 2, got %d\n", r);
4462 sz = sizeof(buffer);
4463 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4464 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4465 ok(!lstrcmp(buffer, "two"), "Expected two, got %s\n", buffer);
4467 r = MsiCloseHandle(hrec);
4468 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4470 r = MsiViewFetch(hview, &hrec);
4471 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4473 r = MsiRecordGetFieldCount(hrec);
4474 ok(r == 2, "Expected 2, got %d\n", r);
4476 r = MsiRecordGetInteger(hrec, 1);
4477 ok(r == 5, "Expected 5, got %d\n", r);
4479 sz = sizeof(buffer);
4480 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4481 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4482 ok(!lstrcmp(buffer, "five"), "Expected five, got %s\n", buffer);
4484 r = MsiCloseHandle(hrec);
4485 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4487 r = MsiViewFetch(hview, &hrec);
4488 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4490 r = MsiViewClose(hview);
4491 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4492 r = MsiCloseHandle(hview);
4493 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4494 r = MsiCloseHandle(hrec);
4495 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4496 r = MsiCloseHandle(hdb);
4497 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4499 MultiByteToWideChar(CP_ACP, 0, msifile, -1, name, 0x20);
4500 hr = StgOpenStorage(name, NULL, mode, NULL, 0, &stg);
4501 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4502 ok(stg != NULL, "Expected non-NULL storage\n");
4504 hr = IStorage_OpenStream(stg, moo, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
4505 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4506 ok(stm != NULL, "Expected non-NULL stream\n");
4508 hr = IStream_Read(stm, data, MAX_PATH, &read);
4509 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4510 todo_wine
4512 ok(read == 4, "Expected 4, got %d\n", read);
4513 ok(!memcmp(data, data10, read), "Unexpected data\n");
4516 hr = IStream_Release(stm);
4517 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4519 hr = IStorage_OpenStream(stg, aar, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
4520 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4521 ok(stm != NULL, "Expected non-NULL stream\n");
4523 hr = IStream_Read(stm, data, MAX_PATH, &read);
4524 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4525 ok(read == 8, "Expected 8, got %d\n", read);
4526 todo_wine
4528 ok(!memcmp(data, data11, read), "Unexpected data\n");
4531 hr = IStream_Release(stm);
4532 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4534 hr = IStorage_OpenStream(stg, stringdata, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
4535 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4536 ok(stm != NULL, "Expected non-NULL stream\n");
4538 hr = IStream_Read(stm, buffer, MAX_PATH, &read);
4539 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4540 ok(read == 24, "Expected 24, got %d\n", read);
4541 ok(!memcmp(buffer, data12, read), "Unexpected data\n");
4543 hr = IStream_Release(stm);
4544 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4546 hr = IStorage_OpenStream(stg, stringpool, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
4547 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4548 ok(stm != NULL, "Expected non-NULL stream\n");
4550 hr = IStream_Read(stm, data, MAX_PATH, &read);
4551 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4552 todo_wine
4554 ok(read == 64, "Expected 64, got %d\n", read);
4555 ok(!memcmp(data, data13, read), "Unexpected data\n");
4558 hr = IStream_Release(stm);
4559 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4561 hr = IStorage_Release(stg);
4562 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
4564 DeleteFileA(msifile);
4567 static void test_viewmodify_delete(void)
4569 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
4570 UINT r;
4571 const char *query;
4572 char buffer[0x100];
4573 DWORD sz;
4575 DeleteFile(msifile);
4577 /* just MsiOpenDatabase should not create a file */
4578 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4579 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4581 query = "CREATE TABLE `phone` ( "
4582 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
4583 "PRIMARY KEY `id`)";
4584 r = run_query(hdb, 0, query);
4585 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4587 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
4588 "VALUES('1', 'Alan', '5030581')";
4589 r = run_query(hdb, 0, query);
4590 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4592 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
4593 "VALUES('2', 'Barry', '928440')";
4594 r = run_query(hdb, 0, query);
4595 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4597 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
4598 "VALUES('3', 'Cindy', '2937550')";
4599 r = run_query(hdb, 0, query);
4600 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4602 query = "SELECT * FROM `phone` WHERE `id` <= 2";
4603 r = MsiDatabaseOpenView(hdb, query, &hview);
4604 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4605 r = MsiViewExecute(hview, 0);
4606 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4607 r = MsiViewFetch(hview, &hrec);
4608 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4610 /* delete 1 */
4611 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
4612 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4614 r = MsiCloseHandle(hrec);
4615 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4616 r = MsiViewFetch(hview, &hrec);
4617 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4619 /* delete 2 */
4620 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
4621 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4623 r = MsiCloseHandle(hrec);
4624 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4625 r = MsiViewClose(hview);
4626 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4627 r = MsiCloseHandle(hview);
4628 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4630 query = "SELECT * FROM `phone`";
4631 r = MsiDatabaseOpenView(hdb, query, &hview);
4632 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4633 r = MsiViewExecute(hview, 0);
4634 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4635 r = MsiViewFetch(hview, &hrec);
4636 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4638 r = MsiRecordGetInteger(hrec, 1);
4639 ok(r == 3, "Expected 3, got %d\n", r);
4641 sz = sizeof(buffer);
4642 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4643 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4644 ok(!lstrcmp(buffer, "Cindy"), "Expected Cindy, got %s\n", buffer);
4646 sz = sizeof(buffer);
4647 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4648 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4649 ok(!lstrcmp(buffer, "2937550"), "Expected 2937550, got %s\n", buffer);
4651 r = MsiCloseHandle(hrec);
4652 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4654 r = MsiViewFetch(hview, &hrec);
4655 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4657 r = MsiViewClose(hview);
4658 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4659 r = MsiCloseHandle(hview);
4660 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4661 r = MsiCloseHandle(hdb);
4662 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4665 static const WCHAR _Tables[] = {0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0};
4666 static const WCHAR _StringData[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0};
4667 static const WCHAR _StringPool[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0};
4669 static const WCHAR data14[] = { /* _StringPool */
4670 /* len, refs */
4671 0, 0, /* string 0 '' */
4674 static const struct {
4675 LPCWSTR name;
4676 const void *data;
4677 DWORD size;
4678 } database_table_data[] =
4680 {_Tables, NULL, 0},
4681 {_StringData, NULL, 0},
4682 {_StringPool, data14, sizeof data14},
4685 void enum_stream_names(IStorage *stg)
4687 IEnumSTATSTG *stgenum = NULL;
4688 IStream *stm;
4689 HRESULT hr;
4690 STATSTG stat;
4691 ULONG n, count;
4692 BYTE data[MAX_PATH];
4693 BYTE check[MAX_PATH];
4694 DWORD sz;
4696 memset(check, 'a', MAX_PATH);
4698 hr = IStorage_EnumElements(stg, 0, NULL, 0, &stgenum);
4699 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
4701 n = 0;
4702 while(TRUE)
4704 count = 0;
4705 hr = IEnumSTATSTG_Next(stgenum, 1, &stat, &count);
4706 if(FAILED(hr) || !count)
4707 break;
4709 ok(!lstrcmpW(stat.pwcsName, database_table_data[n].name),
4710 "Expected table %d name to match\n", n);
4712 stm = NULL;
4713 hr = IStorage_OpenStream(stg, stat.pwcsName, NULL,
4714 STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
4715 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
4716 ok(stm != NULL, "Expected non-NULL stream\n");
4718 sz = MAX_PATH;
4719 memset(data, 'a', MAX_PATH);
4720 hr = IStream_Read(stm, data, sz, &count);
4721 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
4723 ok(count == database_table_data[n].size,
4724 "Expected %d, got %d\n", database_table_data[n].size, count);
4726 if (!database_table_data[n].size)
4727 ok(!memcmp(data, check, MAX_PATH), "data should not be changed\n");
4728 else
4729 ok(!memcmp(data, database_table_data[n].data, database_table_data[n].size),
4730 "Expected table %d data to match\n", n);
4732 IStream_Release(stm);
4733 n++;
4736 ok(n == 3, "Expected 3, got %d\n", n);
4738 IEnumSTATSTG_Release(stgenum);
4741 static void test_defaultdatabase(void)
4743 UINT r;
4744 HRESULT hr;
4745 MSIHANDLE hdb;
4746 IStorage *stg = NULL;
4748 static const WCHAR msifileW[] = {'w','i','n','e','t','e','s','t','.','m','s','i',0};
4750 DeleteFile(msifile);
4752 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4753 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4755 r = MsiDatabaseCommit(hdb);
4756 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4758 MsiCloseHandle(hdb);
4760 hr = StgOpenStorage(msifileW, NULL, STGM_READ | STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
4761 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
4762 ok(stg != NULL, "Expected non-NULL stg\n");
4764 enum_stream_names(stg);
4766 IStorage_Release(stg);
4767 DeleteFileA(msifile);
4770 static void test_order(void)
4772 MSIHANDLE hdb, hview, hrec;
4773 LPCSTR query;
4774 UINT r;
4775 int val;
4777 hdb = create_db();
4778 ok(hdb, "failed to create db\n");
4780 query = "CREATE TABLE `Mesa` ( `A` SHORT NOT NULL, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
4781 r = run_query(hdb, 0, query);
4782 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4784 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 1, 2, 9 )";
4785 r = run_query(hdb, 0, query);
4786 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4788 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 3, 4, 7 )";
4789 r = run_query(hdb, 0, query);
4790 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4792 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 5, 6, 8 )";
4793 r = run_query(hdb, 0, query);
4794 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4796 query = "CREATE TABLE `Sideboard` ( `D` SHORT NOT NULL, `E` SHORT, `F` SHORT PRIMARY KEY `D`)";
4797 r = run_query(hdb, 0, query);
4798 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4800 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 10, 11, 18 )";
4801 r = run_query(hdb, 0, query);
4802 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4804 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 12, 13, 16 )";
4805 r = run_query(hdb, 0, query);
4806 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4808 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 14, 15, 17 )";
4809 r = run_query(hdb, 0, query);
4810 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4812 query = "SELECT `A`, `B` FROM `Mesa` ORDER BY `C`";
4813 r = MsiDatabaseOpenView(hdb, query, &hview);
4814 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4815 r = MsiViewExecute(hview, 0);
4816 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4818 r = MsiViewFetch(hview, &hrec);
4819 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4821 val = MsiRecordGetInteger(hrec, 1);
4822 ok(val == 3, "Expected 3, got %d\n", val);
4824 val = MsiRecordGetInteger(hrec, 2);
4825 ok(val == 4, "Expected 3, got %d\n", val);
4827 MsiCloseHandle(hrec);
4829 r = MsiViewFetch(hview, &hrec);
4830 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4832 val = MsiRecordGetInteger(hrec, 1);
4833 ok(val == 5, "Expected 5, got %d\n", val);
4835 val = MsiRecordGetInteger(hrec, 2);
4836 ok(val == 6, "Expected 6, got %d\n", val);
4838 MsiCloseHandle(hrec);
4840 r = MsiViewFetch(hview, &hrec);
4841 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4843 val = MsiRecordGetInteger(hrec, 1);
4844 ok(val == 1, "Expected 1, got %d\n", val);
4846 val = MsiRecordGetInteger(hrec, 2);
4847 ok(val == 2, "Expected 2, got %d\n", val);
4849 MsiCloseHandle(hrec);
4851 r = MsiViewFetch(hview, &hrec);
4852 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4854 MsiViewClose(hview);
4855 MsiCloseHandle(hview);
4857 query = "SELECT `A`, `D` FROM `Mesa`, `Sideboard` ORDER BY `F`";
4858 r = MsiDatabaseOpenView(hdb, query, &hview);
4859 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4860 r = MsiViewExecute(hview, 0);
4861 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4863 r = MsiViewFetch(hview, &hrec);
4864 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4866 val = MsiRecordGetInteger(hrec, 1);
4867 ok(val == 1, "Expected 1, got %d\n", val);
4869 val = MsiRecordGetInteger(hrec, 2);
4870 ok(val == 12, "Expected 12, got %d\n", val);
4872 MsiCloseHandle(hrec);
4874 r = MsiViewFetch(hview, &hrec);
4875 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4877 val = MsiRecordGetInteger(hrec, 1);
4878 ok(val == 3, "Expected 3, got %d\n", val);
4880 val = MsiRecordGetInteger(hrec, 2);
4881 ok(val == 12, "Expected 12, got %d\n", val);
4883 MsiCloseHandle(hrec);
4885 r = MsiViewFetch(hview, &hrec);
4886 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4888 val = MsiRecordGetInteger(hrec, 1);
4889 ok(val == 5, "Expected 5, got %d\n", val);
4891 val = MsiRecordGetInteger(hrec, 2);
4892 ok(val == 12, "Expected 12, got %d\n", val);
4894 MsiCloseHandle(hrec);
4896 r = MsiViewFetch(hview, &hrec);
4897 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4899 val = MsiRecordGetInteger(hrec, 1);
4900 ok(val == 1, "Expected 1, got %d\n", val);
4902 val = MsiRecordGetInteger(hrec, 2);
4903 ok(val == 14, "Expected 14, got %d\n", val);
4905 MsiCloseHandle(hrec);
4907 r = MsiViewFetch(hview, &hrec);
4908 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4910 val = MsiRecordGetInteger(hrec, 1);
4911 ok(val == 3, "Expected 3, got %d\n", val);
4913 val = MsiRecordGetInteger(hrec, 2);
4914 ok(val == 14, "Expected 14, got %d\n", val);
4916 MsiCloseHandle(hrec);
4918 r = MsiViewFetch(hview, &hrec);
4919 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4921 val = MsiRecordGetInteger(hrec, 1);
4922 ok(val == 5, "Expected 5, got %d\n", val);
4924 val = MsiRecordGetInteger(hrec, 2);
4925 ok(val == 14, "Expected 14, got %d\n", val);
4927 MsiCloseHandle(hrec);
4929 r = MsiViewFetch(hview, &hrec);
4930 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4932 val = MsiRecordGetInteger(hrec, 1);
4933 ok(val == 1, "Expected 1, got %d\n", val);
4935 val = MsiRecordGetInteger(hrec, 2);
4936 ok(val == 10, "Expected 10, got %d\n", val);
4938 MsiCloseHandle(hrec);
4940 r = MsiViewFetch(hview, &hrec);
4941 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4943 val = MsiRecordGetInteger(hrec, 1);
4944 ok(val == 3, "Expected 3, got %d\n", val);
4946 val = MsiRecordGetInteger(hrec, 2);
4947 ok(val == 10, "Expected 10, got %d\n", val);
4949 MsiCloseHandle(hrec);
4951 r = MsiViewFetch(hview, &hrec);
4952 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4954 val = MsiRecordGetInteger(hrec, 1);
4955 ok(val == 5, "Expected 5, got %d\n", val);
4957 val = MsiRecordGetInteger(hrec, 2);
4958 ok(val == 10, "Expected 10, got %d\n", val);
4960 MsiCloseHandle(hrec);
4962 r = MsiViewFetch(hview, &hrec);
4963 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4965 MsiViewClose(hview);
4966 MsiCloseHandle(hview);
4967 MsiCloseHandle(hdb);
4970 static void test_viewmodify_delete_temporary(void)
4972 MSIHANDLE hdb, hview, hrec;
4973 const char *query;
4974 UINT r;
4976 DeleteFile(msifile);
4978 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4979 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4981 query = "CREATE TABLE `Table` ( `A` SHORT PRIMARY KEY `A` )";
4982 r = run_query(hdb, 0, query);
4983 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4985 query = "SELECT * FROM `Table`";
4986 r = MsiDatabaseOpenView(hdb, query, &hview);
4987 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4988 r = MsiViewExecute(hview, 0);
4989 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4991 hrec = MsiCreateRecord(1);
4992 MsiRecordSetInteger(hrec, 1, 1);
4994 r = MsiViewModify(hview, MSIMODIFY_INSERT, hrec);
4995 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4997 MsiCloseHandle(hrec);
4999 hrec = MsiCreateRecord(1);
5000 MsiRecordSetInteger(hrec, 1, 2);
5002 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
5003 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5005 MsiCloseHandle(hrec);
5007 hrec = MsiCreateRecord(1);
5008 MsiRecordSetInteger(hrec, 1, 3);
5010 r = MsiViewModify(hview, MSIMODIFY_INSERT, hrec);
5011 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5013 MsiCloseHandle(hrec);
5015 hrec = MsiCreateRecord(1);
5016 MsiRecordSetInteger(hrec, 1, 4);
5018 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
5019 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5021 MsiCloseHandle(hrec);
5022 MsiViewClose(hview);
5023 MsiCloseHandle(hview);
5025 query = "SELECT * FROM `Table` WHERE `A` = 2";
5026 r = MsiDatabaseOpenView(hdb, query, &hview);
5027 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5028 r = MsiViewExecute(hview, 0);
5029 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5030 r = MsiViewFetch(hview, &hrec);
5031 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5033 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
5034 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5036 MsiCloseHandle(hrec);
5037 MsiViewClose(hview);
5038 MsiCloseHandle(hview);
5040 query = "SELECT * FROM `Table` WHERE `A` = 3";
5041 r = MsiDatabaseOpenView(hdb, query, &hview);
5042 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5043 r = MsiViewExecute(hview, 0);
5044 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5045 r = MsiViewFetch(hview, &hrec);
5046 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5048 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
5049 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5051 MsiCloseHandle(hrec);
5052 MsiViewClose(hview);
5053 MsiCloseHandle(hview);
5055 query = "SELECT * FROM `Table` ORDER BY `A`";
5056 r = MsiDatabaseOpenView(hdb, query, &hview);
5057 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5058 r = MsiViewExecute(hview, 0);
5059 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5061 r = MsiViewFetch(hview, &hrec);
5062 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5064 r = MsiRecordGetInteger(hrec, 1);
5065 ok(r == 1, "Expected 1, got %d\n", r);
5067 MsiCloseHandle(hrec);
5069 r = MsiViewFetch(hview, &hrec);
5070 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5072 r = MsiRecordGetInteger(hrec, 1);
5073 ok(r == 4, "Expected 4, got %d\n", r);
5075 MsiCloseHandle(hrec);
5077 r = MsiViewFetch(hview, &hrec);
5078 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5080 MsiViewClose(hview);
5081 MsiCloseHandle(hview);
5082 MsiCloseHandle(hdb);
5083 DeleteFileA(msifile);
5086 static void test_deleterow()
5088 MSIHANDLE hdb, hview, hrec;
5089 const char *query;
5090 char buf[MAX_PATH];
5091 UINT r;
5092 DWORD size;
5094 DeleteFile(msifile);
5096 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5097 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5099 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5100 r = run_query(hdb, 0, query);
5101 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5103 query = "INSERT INTO `Table` (`A`) VALUES ('one')";
5104 r = run_query(hdb, 0, query);
5105 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5107 query = "INSERT INTO `Table` (`A`) VALUES ('two')";
5108 r = run_query(hdb, 0, query);
5109 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5111 query = "DELETE FROM `Table` WHERE `A` = 'one'";
5112 r = run_query(hdb, 0, query);
5113 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5115 r = MsiDatabaseCommit(hdb);
5116 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5118 MsiCloseHandle(hdb);
5120 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
5121 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5123 query = "SELECT * FROM `Table`";
5124 r = MsiDatabaseOpenView(hdb, query, &hview);
5125 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5126 r = MsiViewExecute(hview, 0);
5127 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5129 r = MsiViewFetch(hview, &hrec);
5130 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5132 size = MAX_PATH;
5133 r = MsiRecordGetStringA(hrec, 1, buf, &size);
5134 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5135 ok(!lstrcmpA(buf, "two"), "Expected two, got %s\n", buf);
5137 MsiCloseHandle(hrec);
5139 r = MsiViewFetch(hview, &hrec);
5140 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5142 MsiViewClose(hview);
5143 MsiCloseHandle(hview);
5144 MsiCloseHandle(hdb);
5145 DeleteFileA(msifile);
5148 static const CHAR import_dat[] = "A\n"
5149 "s72\n"
5150 "Table\tA\n"
5151 "This is a new 'string' ok\n";
5153 static void test_quotes(void)
5155 MSIHANDLE hdb, hview, hrec;
5156 const char *query;
5157 char buf[MAX_PATH];
5158 UINT r;
5159 DWORD size;
5161 DeleteFile(msifile);
5163 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5164 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5166 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5167 r = run_query(hdb, 0, query);
5168 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5170 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a 'string' ok' )";
5171 r = run_query(hdb, 0, query);
5172 ok(r == ERROR_BAD_QUERY_SYNTAX,
5173 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5175 query = "INSERT INTO `Table` ( `A` ) VALUES ( \"This is a 'string' ok\" )";
5176 r = run_query(hdb, 0, query);
5177 ok(r == ERROR_BAD_QUERY_SYNTAX,
5178 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5180 query = "INSERT INTO `Table` ( `A` ) VALUES ( \"test\" )";
5181 r = run_query(hdb, 0, query);
5182 ok(r == ERROR_BAD_QUERY_SYNTAX,
5183 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5185 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a ''string'' ok' )";
5186 r = run_query(hdb, 0, query);
5187 todo_wine
5189 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5192 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a '''string''' ok' )";
5193 r = run_query(hdb, 0, query);
5194 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5196 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \'string\' ok' )";
5197 r = run_query(hdb, 0, query);
5198 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5200 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \"string\" ok' )";
5201 r = run_query(hdb, 0, query);
5202 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5204 query = "SELECT * FROM `Table`";
5205 r = MsiDatabaseOpenView(hdb, query, &hview);
5206 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5208 r = MsiViewExecute(hview, 0);
5209 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5211 r = MsiViewFetch(hview, &hrec);
5212 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5214 size = MAX_PATH;
5215 r = MsiRecordGetString(hrec, 1, buf, &size);
5216 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5217 todo_wine
5219 ok(!lstrcmp(buf, "This is a \"string\" ok"),
5220 "Expected \"This is a \"string\" ok\", got %s\n", buf);
5223 MsiCloseHandle(hrec);
5225 r = MsiViewFetch(hview, &hrec);
5226 todo_wine
5228 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5231 MsiCloseHandle(hview);
5233 write_file("import.idt", import_dat, (sizeof(import_dat) - 1) * sizeof(char));
5235 r = MsiDatabaseImportA(hdb, CURR_DIR, "import.idt");
5236 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5238 DeleteFileA("import.idt");
5240 query = "SELECT * FROM `Table`";
5241 r = MsiDatabaseOpenView(hdb, query, &hview);
5242 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5244 r = MsiViewExecute(hview, 0);
5245 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5247 r = MsiViewFetch(hview, &hrec);
5248 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5250 size = MAX_PATH;
5251 r = MsiRecordGetString(hrec, 1, buf, &size);
5252 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5253 ok(!lstrcmp(buf, "This is a new 'string' ok"),
5254 "Expected \"This is a new 'string' ok\", got %s\n", buf);
5256 MsiCloseHandle(hrec);
5258 r = MsiViewFetch(hview, &hrec);
5259 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5261 MsiCloseHandle(hview);
5263 MsiCloseHandle(hdb);
5264 DeleteFileA(msifile);
5267 static void test_carriagereturn(void)
5269 MSIHANDLE hdb, hview, hrec;
5270 const char *query;
5271 char buf[MAX_PATH];
5272 UINT r;
5273 DWORD size;
5275 DeleteFile(msifile);
5277 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5278 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5280 query = "CREATE TABLE `Table`\r ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5281 r = run_query(hdb, 0, query);
5282 todo_wine
5284 ok(r == ERROR_BAD_QUERY_SYNTAX,
5285 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5288 query = "CREATE TABLE `Table` \r( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5289 r = run_query(hdb, 0, query);
5290 ok(r == ERROR_BAD_QUERY_SYNTAX,
5291 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5293 query = "CREATE\r TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5294 r = run_query(hdb, 0, query);
5295 ok(r == ERROR_BAD_QUERY_SYNTAX,
5296 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5298 query = "CREATE TABLE\r `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5299 r = run_query(hdb, 0, query);
5300 ok(r == ERROR_BAD_QUERY_SYNTAX,
5301 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5303 query = "CREATE TABLE `Table` (\r `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5304 r = run_query(hdb, 0, query);
5305 ok(r == ERROR_BAD_QUERY_SYNTAX,
5306 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5308 query = "CREATE TABLE `Table` ( `A`\r CHAR(72) NOT NULL PRIMARY KEY `A` )";
5309 r = run_query(hdb, 0, query);
5310 ok(r == ERROR_BAD_QUERY_SYNTAX,
5311 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5313 query = "CREATE TABLE `Table` ( `A` CHAR(72)\r NOT NULL PRIMARY KEY `A` )";
5314 r = run_query(hdb, 0, query);
5315 ok(r == ERROR_BAD_QUERY_SYNTAX,
5316 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5318 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT\r NULL PRIMARY KEY `A` )";
5319 r = run_query(hdb, 0, query);
5320 ok(r == ERROR_BAD_QUERY_SYNTAX,
5321 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5323 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT \rNULL PRIMARY KEY `A` )";
5324 r = run_query(hdb, 0, query);
5325 ok(r == ERROR_BAD_QUERY_SYNTAX,
5326 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5328 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL\r PRIMARY KEY `A` )";
5329 r = run_query(hdb, 0, query);
5330 ok(r == ERROR_BAD_QUERY_SYNTAX,
5331 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5333 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL \rPRIMARY KEY `A` )";
5334 r = run_query(hdb, 0, query);
5335 ok(r == ERROR_BAD_QUERY_SYNTAX,
5336 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5338 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY\r KEY `A` )";
5339 r = run_query(hdb, 0, query);
5340 ok(r == ERROR_BAD_QUERY_SYNTAX,
5341 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5343 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY \rKEY `A` )";
5344 r = run_query(hdb, 0, query);
5345 ok(r == ERROR_BAD_QUERY_SYNTAX,
5346 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5348 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY\r `A` )";
5349 r = run_query(hdb, 0, query);
5350 ok(r == ERROR_BAD_QUERY_SYNTAX,
5351 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5353 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A`\r )";
5354 r = run_query(hdb, 0, query);
5355 ok(r == ERROR_BAD_QUERY_SYNTAX,
5356 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5358 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )\r";
5359 r = run_query(hdb, 0, query);
5360 ok(r == ERROR_BAD_QUERY_SYNTAX,
5361 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5363 query = "CREATE TABLE `\rOne` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5364 r = run_query(hdb, 0, query);
5365 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5367 query = "CREATE TABLE `Tw\ro` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5368 r = run_query(hdb, 0, query);
5369 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5371 query = "CREATE TABLE `Three\r` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5372 r = run_query(hdb, 0, query);
5373 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5375 query = "CREATE TABLE `Four` ( `A\r` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5376 r = run_query(hdb, 0, query);
5377 ok(r == ERROR_BAD_QUERY_SYNTAX,
5378 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5380 query = "CREATE TABLE `Four` ( `\rA` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5381 r = run_query(hdb, 0, query);
5382 ok(r == ERROR_BAD_QUERY_SYNTAX,
5383 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5385 query = "CREATE TABLE `Four` ( `A` CHAR(72\r) NOT NULL PRIMARY KEY `A` )";
5386 r = run_query(hdb, 0, query);
5387 todo_wine
5389 ok(r == ERROR_BAD_QUERY_SYNTAX,
5390 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5393 query = "CREATE TABLE `Four` ( `A` CHAR(\r72) NOT NULL PRIMARY KEY `A` )";
5394 r = run_query(hdb, 0, query);
5395 ok(r == ERROR_BAD_QUERY_SYNTAX,
5396 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5398 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `\rA` )";
5399 r = run_query(hdb, 0, query);
5400 ok(r == ERROR_BAD_QUERY_SYNTAX,
5401 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5403 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
5404 r = run_query(hdb, 0, query);
5405 ok(r == ERROR_BAD_QUERY_SYNTAX,
5406 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5408 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
5409 r = run_query(hdb, 0, query);
5410 ok(r == ERROR_BAD_QUERY_SYNTAX,
5411 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5413 query = "SELECT * FROM `_Tables`";
5414 r = MsiDatabaseOpenView(hdb, query, &hview);
5415 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5416 r = MsiViewExecute(hview, 0);
5417 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5419 r = MsiViewFetch(hview, &hrec);
5420 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5422 size = MAX_PATH;
5423 r = MsiRecordGetStringA(hrec, 1, buf, &size);
5424 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5425 todo_wine
5427 ok(!lstrcmpA(buf, "\rOne"), "Expected \"\\rOne\", got \"%s\"\n", buf);
5430 MsiCloseHandle(hrec);
5432 r = MsiViewFetch(hview, &hrec);
5433 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5435 size = MAX_PATH;
5436 r = MsiRecordGetStringA(hrec, 1, buf, &size);
5437 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5438 todo_wine
5440 ok(!lstrcmpA(buf, "Tw\ro"), "Expected \"Tw\\ro\", got \"%s\"\n", buf);
5443 MsiCloseHandle(hrec);
5445 r = MsiViewFetch(hview, &hrec);
5446 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5448 size = MAX_PATH;
5449 r = MsiRecordGetStringA(hrec, 1, buf, &size);
5450 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5451 todo_wine
5453 ok(!lstrcmpA(buf, "Three\r"),
5454 "Expected \"Three\r\", got \"%s\"\n", buf);
5457 MsiCloseHandle(hrec);
5459 r = MsiViewFetch(hview, &hrec);
5460 todo_wine
5462 ok(r == ERROR_NO_MORE_ITEMS,
5463 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5466 MsiViewClose(hview);
5467 MsiCloseHandle(hview);
5469 MsiCloseHandle(hdb);
5470 DeleteFileA(msifile);
5473 static void test_noquotes(void)
5475 MSIHANDLE hdb, hview, hrec;
5476 const char *query;
5477 char buf[MAX_PATH];
5478 UINT r;
5479 DWORD size;
5481 DeleteFile(msifile);
5483 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5484 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5486 query = "CREATE TABLE Table ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5487 r = run_query(hdb, 0, query);
5488 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5490 query = "CREATE TABLE `Table` ( A CHAR(72) NOT NULL PRIMARY KEY `A` )";
5491 r = run_query(hdb, 0, query);
5492 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5494 query = "CREATE TABLE `Table2` ( `A` CHAR(72) NOT NULL PRIMARY KEY A )";
5495 r = run_query(hdb, 0, query);
5496 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5498 query = "CREATE TABLE `Table3` ( A CHAR(72) NOT NULL PRIMARY KEY A )";
5499 r = run_query(hdb, 0, query);
5500 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5502 query = "SELECT * FROM `_Tables`";
5503 r = MsiDatabaseOpenView(hdb, query, &hview);
5504 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5505 r = MsiViewExecute(hview, 0);
5506 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5508 r = MsiViewFetch(hview, &hrec);
5509 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5511 size = MAX_PATH;
5512 r = MsiRecordGetStringA(hrec, 1, buf, &size);
5513 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5514 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
5516 MsiCloseHandle(hrec);
5518 r = MsiViewFetch(hview, &hrec);
5519 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5521 size = MAX_PATH;
5522 r = MsiRecordGetStringA(hrec, 1, buf, &size);
5523 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5524 ok(!lstrcmpA(buf, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf);
5526 MsiCloseHandle(hrec);
5528 r = MsiViewFetch(hview, &hrec);
5529 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5531 size = MAX_PATH;
5532 r = MsiRecordGetStringA(hrec, 1, buf, &size);
5533 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5534 ok(!lstrcmpA(buf, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf);
5536 MsiCloseHandle(hrec);
5538 r = MsiViewFetch(hview, &hrec);
5539 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5541 MsiViewClose(hview);
5542 MsiCloseHandle(hview);
5544 query = "SELECT * FROM `_Columns`";
5545 r = MsiDatabaseOpenView(hdb, query, &hview);
5546 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5547 r = MsiViewExecute(hview, 0);
5548 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5550 r = MsiViewFetch(hview, &hrec);
5551 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5553 size = MAX_PATH;
5554 r = MsiRecordGetStringA(hrec, 1, buf, &size);
5555 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5556 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
5558 r = MsiRecordGetInteger(hrec, 2);
5559 ok(r == 1, "Expected 1, got %d\n", r);
5561 size = MAX_PATH;
5562 r = MsiRecordGetStringA(hrec, 3, buf, &size);
5563 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5564 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
5566 MsiCloseHandle(hrec);
5568 r = MsiViewFetch(hview, &hrec);
5569 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5571 size = MAX_PATH;
5572 r = MsiRecordGetStringA(hrec, 1, buf, &size);
5573 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5574 ok(!lstrcmpA(buf, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf);
5576 r = MsiRecordGetInteger(hrec, 2);
5577 ok(r == 1, "Expected 1, got %d\n", r);
5579 size = MAX_PATH;
5580 r = MsiRecordGetStringA(hrec, 3, buf, &size);
5581 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5582 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
5584 MsiCloseHandle(hrec);
5586 r = MsiViewFetch(hview, &hrec);
5587 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5589 size = MAX_PATH;
5590 r = MsiRecordGetStringA(hrec, 1, buf, &size);
5591 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5592 ok(!lstrcmpA(buf, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf);
5594 r = MsiRecordGetInteger(hrec, 2);
5595 ok(r == 1, "Expected 1, got %d\n", r);
5597 size = MAX_PATH;
5598 r = MsiRecordGetStringA(hrec, 3, buf, &size);
5599 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5600 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
5602 MsiCloseHandle(hrec);
5604 r = MsiViewFetch(hview, &hrec);
5605 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5607 MsiViewClose(hview);
5608 MsiCloseHandle(hview);
5610 query = "INSERT INTO Table ( `A` ) VALUES ( 'hi' )";
5611 r = run_query(hdb, 0, query);
5612 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5614 query = "INSERT INTO `Table` ( A ) VALUES ( 'hi' )";
5615 r = run_query(hdb, 0, query);
5616 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5618 query = "INSERT INTO `Table` ( `A` ) VALUES ( hi )";
5619 r = run_query(hdb, 0, query);
5620 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5622 query = "SELECT * FROM Table WHERE `A` = 'hi'";
5623 r = run_query(hdb, 0, query);
5624 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5626 query = "SELECT * FROM `Table` WHERE `A` = hi";
5627 r = run_query(hdb, 0, query);
5628 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5630 query = "SELECT * FROM Table";
5631 r = run_query(hdb, 0, query);
5632 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5634 query = "SELECT * FROM Table2";
5635 r = MsiDatabaseOpenView(hdb, query, &hview);
5636 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5637 r = MsiViewExecute(hview, 0);
5638 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5640 r = MsiViewFetch(hview, &hrec);
5641 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5643 MsiViewClose(hview);
5644 MsiCloseHandle(hview);
5646 query = "SELECT * FROM `Table` WHERE A = 'hi'";
5647 r = MsiDatabaseOpenView(hdb, query, &hview);
5648 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5649 r = MsiViewExecute(hview, 0);
5650 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5652 r = MsiViewFetch(hview, &hrec);
5653 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5655 size = MAX_PATH;
5656 r = MsiRecordGetStringA(hrec, 1, buf, &size);
5657 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5658 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
5660 MsiCloseHandle(hrec);
5662 r = MsiViewFetch(hview, &hrec);
5663 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5665 MsiViewClose(hview);
5666 MsiCloseHandle(hview);
5669 MsiCloseHandle(hdb);
5670 DeleteFileA(msifile);
5673 static void read_file_data(LPCSTR filename, LPSTR buffer)
5675 OFSTRUCT ofs;
5676 HFILE file;
5677 DWORD read;
5679 file = OpenFile(filename, &ofs, OF_READ);
5680 ZeroMemory(buffer, MAX_PATH);
5681 ReadFile((HANDLE)file, buffer, MAX_PATH, &read, NULL);
5682 CloseHandle((HANDLE)file);
5685 static void test_forcecodepage(void)
5687 MSIHANDLE hdb;
5688 const char *query;
5689 char buffer[MAX_PATH];
5690 UINT r;
5692 DeleteFile(msifile);
5694 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5695 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5697 query = "SELECT * FROM `_ForceCodepage`";
5698 r = run_query(hdb, 0, query);
5699 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5701 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5702 r = run_query(hdb, 0, query);
5703 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5705 query = "SELECT * FROM `_ForceCodepage`";
5706 r = run_query(hdb, 0, query);
5707 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5709 r = MsiDatabaseCommit(hdb);
5710 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5712 query = "SELECT * FROM `_ForceCodepage`";
5713 r = run_query(hdb, 0, query);
5714 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5716 MsiCloseHandle(hdb);
5718 r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb);
5719 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5721 query = "SELECT * FROM `_ForceCodepage`";
5722 r = run_query(hdb, 0, query);
5723 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
5725 r = MsiDatabaseExport(hdb, "_ForceCodepage", CURR_DIR, "forcecodepage.idt");
5726 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5728 read_file_data("forcecodepage.idt", buffer);
5729 ok(!lstrcmpA(buffer, "\r\n\r\n0\t_ForceCodepage\r\n"),
5730 "Expected \"\r\n\r\n0\t_ForceCodepage\r\n\", got \"%s\"", buffer);
5732 MsiCloseHandle(hdb);
5733 DeleteFileA(msifile);
5734 DeleteFileA("forcecodepage.idt");
5737 static void test_viewmodify_refresh(void)
5739 MSIHANDLE hdb, hview, hrec;
5740 const char *query;
5741 char buffer[MAX_PATH];
5742 UINT r;
5743 DWORD size;
5745 DeleteFile(msifile);
5747 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5748 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5750 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL, `B` INT PRIMARY KEY `A` )";
5751 r = run_query(hdb, 0, query);
5752 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5754 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hi', 1 )";
5755 r = run_query(hdb, 0, query);
5756 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5758 query = "SELECT * FROM `Table`";
5759 r = MsiDatabaseOpenView(hdb, query, &hview);
5760 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5761 r = MsiViewExecute(hview, 0);
5762 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5764 r = MsiViewFetch(hview, &hrec);
5765 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5767 query = "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hi'";
5768 r = run_query(hdb, 0, query);
5769 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5771 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
5772 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5774 size = MAX_PATH;
5775 r = MsiRecordGetStringA(hrec, 1, buffer, &size);
5776 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5777 ok(!lstrcmpA(buffer, "hi"), "Expected \"hi\", got \"%s\"\n", buffer);
5778 ok(size == 2, "Expected 2, got %d\n", size);
5780 r = MsiRecordGetInteger(hrec, 2);
5781 ok(r == 2, "Expected 2, got %d\n", r);
5783 MsiCloseHandle(hrec);
5784 MsiViewClose(hview);
5785 MsiCloseHandle(hview);
5787 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hello', 3 )";
5788 r = run_query(hdb, 0, query);
5789 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5791 query = "SELECT * FROM `Table` WHERE `B` = 3";
5792 r = MsiDatabaseOpenView(hdb, query, &hview);
5793 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5794 r = MsiViewExecute(hview, 0);
5795 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5797 r = MsiViewFetch(hview, &hrec);
5798 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5800 query = "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hello'";
5801 r = run_query(hdb, 0, query);
5802 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5804 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hithere', 3 )";
5805 r = run_query(hdb, 0, query);
5806 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5808 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
5809 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5811 size = MAX_PATH;
5812 r = MsiRecordGetStringA(hrec, 1, buffer, &size);
5813 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5814 ok(!lstrcmpA(buffer, "hello"), "Expected \"hello\", got \"%s\"\n", buffer);
5815 ok(size == 5, "Expected 5, got %d\n", size);
5817 r = MsiRecordGetInteger(hrec, 2);
5818 ok(r == 2, "Expected 2, got %d\n", r);
5820 MsiCloseHandle(hrec);
5821 MsiViewClose(hview);
5822 MsiCloseHandle(hview);
5823 MsiCloseHandle(hdb);
5824 DeleteFileA(msifile);
5827 START_TEST(db)
5829 test_msidatabase();
5830 test_msiinsert();
5831 test_msidecomposedesc();
5832 test_msibadqueries();
5833 test_viewmodify();
5834 test_viewgetcolumninfo();
5835 test_getcolinfo();
5836 test_msiexport();
5837 test_longstrings();
5838 test_streamtable();
5839 test_where();
5840 test_msiimport();
5841 test_markers();
5842 test_handle_limit();
5843 test_try_transform();
5844 test_join();
5845 test_temporary_table();
5846 test_alter();
5847 test_integers();
5848 test_update();
5849 test_special_tables();
5850 test_select_markers();
5851 test_viewmodify_update();
5852 test_stringtable();
5853 test_viewmodify_delete();
5854 test_defaultdatabase();
5855 test_order();
5856 test_viewmodify_delete_temporary();
5857 test_deleterow();
5858 test_quotes();
5859 test_carriagereturn();
5860 test_noquotes();
5861 test_forcecodepage();
5862 test_viewmodify_refresh();