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
32 #include "wine/test.h"
34 static const char *msifile = "winetest.msi";
35 static const char *msifile2 = "winetst2.msi";
36 static const char *mstfile = "winetst.mst";
38 static void test_msidatabase(void)
40 MSIHANDLE hdb = 0, hdb2 = 0;
45 res = MsiOpenDatabase( msifile, msifile2, &hdb );
46 ok( res == ERROR_OPEN_FAILED, "expected failure\n");
48 res = MsiOpenDatabase( msifile, (LPSTR) 0xff, &hdb );
49 ok( res == ERROR_INVALID_PARAMETER, "expected failure\n");
51 res = MsiCloseHandle( hdb );
52 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
54 /* create an empty database */
55 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
56 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
58 res = MsiDatabaseCommit( hdb );
59 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
61 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
63 res = MsiCloseHandle( hdb );
64 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
65 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
66 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
68 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile2 ), "database should exist\n");
70 res = MsiDatabaseCommit( hdb2 );
71 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
73 res = MsiCloseHandle( hdb2 );
74 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
76 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
77 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
79 res = MsiCloseHandle( hdb2 );
80 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
82 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile2 ), "uncommitted database should not exist\n");
84 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
85 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
87 res = MsiDatabaseCommit( hdb2 );
88 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
90 res = MsiCloseHandle( hdb2 );
91 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
93 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile2 ), "committed database should exist\n");
95 res = MsiOpenDatabase( msifile, MSIDBOPEN_READONLY, &hdb );
96 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
98 res = MsiCloseHandle( hdb );
99 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
101 res = MsiOpenDatabase( msifile, MSIDBOPEN_DIRECT, &hdb );
102 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
104 res = MsiCloseHandle( hdb );
105 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
107 res = MsiOpenDatabase( msifile, MSIDBOPEN_TRANSACT, &hdb );
108 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
110 res = MsiCloseHandle( hdb );
111 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
112 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
114 /* MSIDBOPEN_CREATE deletes the database if MsiCommitDatabase isn't called */
115 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
116 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
118 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
120 res = MsiCloseHandle( hdb );
121 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
123 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile ), "database should exist\n");
125 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
126 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
128 res = MsiDatabaseCommit( hdb );
129 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
131 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
133 res = MsiCloseHandle( hdb );
134 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
136 res = DeleteFile( msifile2 );
137 ok( res == TRUE, "Failed to delete database\n" );
139 res = DeleteFile( msifile );
140 ok( res == TRUE, "Failed to delete database\n" );
143 static UINT do_query(MSIHANDLE hdb, const char *query, MSIHANDLE *phrec)
151 /* open a select query */
152 r = MsiDatabaseOpenView(hdb, query, &hview);
153 if (r != ERROR_SUCCESS)
155 r = MsiViewExecute(hview, 0);
156 if (r != ERROR_SUCCESS)
158 ret = MsiViewFetch(hview, phrec);
159 r = MsiViewClose(hview);
160 if (r != ERROR_SUCCESS)
162 r = MsiCloseHandle(hview);
163 if (r != ERROR_SUCCESS)
168 static UINT run_query( MSIHANDLE hdb, MSIHANDLE hrec, const char *query )
173 r = MsiDatabaseOpenView(hdb, query, &hview);
174 if( r != ERROR_SUCCESS )
177 r = MsiViewExecute(hview, hrec);
178 if( r == ERROR_SUCCESS )
179 r = MsiViewClose(hview);
180 MsiCloseHandle(hview);
184 static UINT create_component_table( MSIHANDLE hdb )
186 return run_query( hdb, 0,
187 "CREATE TABLE `Component` ( "
188 "`Component` CHAR(72) NOT NULL, "
189 "`ComponentId` CHAR(38), "
190 "`Directory_` CHAR(72) NOT NULL, "
191 "`Attributes` SHORT NOT NULL, "
192 "`Condition` CHAR(255), "
193 "`KeyPath` CHAR(72) "
194 "PRIMARY KEY `Component`)" );
197 static UINT create_custom_action_table( MSIHANDLE hdb )
199 return run_query( hdb, 0,
200 "CREATE TABLE `CustomAction` ( "
201 "`Action` CHAR(72) NOT NULL, "
202 "`Type` SHORT NOT NULL, "
203 "`Source` CHAR(72), "
204 "`Target` CHAR(255) "
205 "PRIMARY KEY `Action`)" );
208 static UINT create_directory_table( MSIHANDLE hdb )
210 return run_query( hdb, 0,
211 "CREATE TABLE `Directory` ( "
212 "`Directory` CHAR(255) NOT NULL, "
213 "`Directory_Parent` CHAR(255), "
214 "`DefaultDir` CHAR(255) NOT NULL "
215 "PRIMARY KEY `Directory`)" );
218 static UINT create_feature_components_table( MSIHANDLE hdb )
220 return run_query( hdb, 0,
221 "CREATE TABLE `FeatureComponents` ( "
222 "`Feature_` CHAR(38) NOT NULL, "
223 "`Component_` CHAR(72) NOT NULL "
224 "PRIMARY KEY `Feature_`, `Component_` )" );
227 static UINT create_std_dlls_table( MSIHANDLE hdb )
229 return run_query( hdb, 0,
230 "CREATE TABLE `StdDlls` ( "
231 "`File` CHAR(255) NOT NULL, "
232 "`Binary_` CHAR(72) NOT NULL "
233 "PRIMARY KEY `File` )" );
236 static UINT create_binary_table( MSIHANDLE hdb )
238 return run_query( hdb, 0,
239 "CREATE TABLE `Binary` ( "
240 "`Name` CHAR(72) NOT NULL, "
241 "`Data` CHAR(72) NOT NULL "
242 "PRIMARY KEY `Name` )" );
245 #define make_add_entry(type, qtext) \
246 static UINT add##_##type##_##entry( MSIHANDLE hdb, const char *values ) \
248 char insert[] = qtext; \
251 sz = strlen(values) + sizeof insert; \
252 query = HeapAlloc(GetProcessHeap(),0,sz); \
253 sprintf(query,insert,values); \
254 r = run_query( hdb, 0, query ); \
255 HeapFree(GetProcessHeap(), 0, query); \
259 make_add_entry(component,
260 "INSERT INTO `Component` "
261 "(`Component`, `ComponentId`, `Directory_`, "
262 "`Attributes`, `Condition`, `KeyPath`) VALUES( %s )")
264 make_add_entry(custom_action,
265 "INSERT INTO `CustomAction` "
266 "(`Action`, `Type`, `Source`, `Target`) VALUES( %s )")
268 make_add_entry(feature_components,
269 "INSERT INTO `FeatureComponents` "
270 "(`Feature_`, `Component_`) VALUES( %s )")
272 make_add_entry(std_dlls,
273 "INSERT INTO `StdDlls` (`File`, `Binary_`) VALUES( %s )")
275 make_add_entry(binary,
276 "INSERT INTO `Binary` (`Name`, `Data`) VALUES( %s )")
278 static void test_msiinsert(void)
280 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
288 /* just MsiOpenDatabase should not create a file */
289 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
290 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
293 query = "CREATE TABLE `phone` ( "
294 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
296 r = MsiDatabaseOpenView(hdb, query, &hview);
297 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
298 r = MsiViewExecute(hview, 0);
299 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
300 r = MsiViewClose(hview);
301 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
302 r = MsiCloseHandle(hview);
303 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
305 /* insert a value into it */
306 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
307 "VALUES('1', 'Abe', '8675309')";
308 r = MsiDatabaseOpenView(hdb, query, &hview);
309 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
310 r = MsiViewExecute(hview, 0);
311 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
312 r = MsiViewClose(hview);
313 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
314 r = MsiCloseHandle(hview);
315 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
317 query = "SELECT * FROM `phone` WHERE `id` = 1";
318 r = do_query(hdb, query, &hrec);
319 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
321 /* check the record contains what we put in it */
322 r = MsiRecordGetFieldCount(hrec);
323 ok(r == 3, "record count wrong\n");
325 r = MsiRecordIsNull(hrec, 0);
326 ok(r == FALSE, "field 0 not null\n");
328 r = MsiRecordGetInteger(hrec, 1);
329 ok(r == 1, "field 1 contents wrong\n");
331 r = MsiRecordGetString(hrec, 2, buf, &sz);
332 ok(r == ERROR_SUCCESS, "field 2 content fetch failed\n");
333 ok(!strcmp(buf,"Abe"), "field 2 content incorrect\n");
335 r = MsiRecordGetString(hrec, 3, buf, &sz);
336 ok(r == ERROR_SUCCESS, "field 3 content fetch failed\n");
337 ok(!strcmp(buf,"8675309"), "field 3 content incorrect\n");
339 r = MsiCloseHandle(hrec);
340 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
342 /* open a select query */
344 query = "SELECT * FROM `phone` WHERE `id` >= 10";
345 r = do_query(hdb, query, &hrec);
346 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
347 ok(hrec == 0, "hrec should be null\n");
349 r = MsiCloseHandle(hrec);
350 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
352 query = "SELECT * FROM `phone` WHERE `id` < 0";
353 r = do_query(hdb, query, &hrec);
354 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
356 query = "SELECT * FROM `phone` WHERE `id` <= 0";
357 r = do_query(hdb, query, &hrec);
358 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
360 query = "SELECT * FROM `phone` WHERE `id` <> 1";
361 r = do_query(hdb, query, &hrec);
362 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
364 query = "SELECT * FROM `phone` WHERE `id` > 10";
365 r = do_query(hdb, query, &hrec);
366 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
368 /* now try a few bad INSERT xqueries */
369 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
371 r = MsiDatabaseOpenView(hdb, query, &hview);
372 ok(r == ERROR_BAD_QUERY_SYNTAX, "MsiDatabaseOpenView failed\n");
374 /* construct a record to insert */
375 hrec = MsiCreateRecord(4);
376 r = MsiRecordSetInteger(hrec, 1, 2);
377 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
378 r = MsiRecordSetString(hrec, 2, "Adam");
379 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
380 r = MsiRecordSetString(hrec, 3, "96905305");
381 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
383 /* insert another value, using a record and wildcards */
384 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
386 r = MsiDatabaseOpenView(hdb, query, &hview);
387 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
389 if (r == ERROR_SUCCESS)
391 r = MsiViewExecute(hview, hrec);
392 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
393 r = MsiViewClose(hview);
394 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
395 r = MsiCloseHandle(hview);
396 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
398 r = MsiCloseHandle(hrec);
399 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
401 r = MsiViewFetch(0, NULL);
402 ok(r == ERROR_INVALID_PARAMETER, "MsiViewFetch failed\n");
404 r = MsiDatabaseCommit(hdb);
405 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
407 r = MsiCloseHandle(hdb);
408 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
410 r = DeleteFile(msifile);
411 ok(r == TRUE, "file didn't exist after commit\n");
414 typedef UINT (WINAPI *fnMsiDecomposeDescriptorA)(LPCSTR, LPCSTR, LPSTR, LPSTR, DWORD *);
415 static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA;
417 static void test_msidecomposedesc(void)
419 char prod[MAX_FEATURE_CHARS+1], comp[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1];
425 hmod = GetModuleHandle("msi.dll");
426 pMsiDecomposeDescriptorA = (fnMsiDecomposeDescriptorA)
427 GetProcAddress(hmod, "MsiDecomposeDescriptorA");
428 if (!pMsiDecomposeDescriptorA)
431 /* test a valid feature descriptor */
432 desc = "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
434 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
435 ok(r == ERROR_SUCCESS, "returned an error\n");
436 ok(len == strlen(desc), "length was wrong\n");
437 ok(strcmp(prod,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
438 ok(strcmp(feature,"FollowTheWhiteRabbit")==0, "feature wrong\n");
439 ok(strcmp(comp,"{A7CD68DB-EF74-49C8-FBB2-A7C463B2AC24}")==0,"component wrong\n");
441 /* test an invalid feature descriptor with too many characters */
442 desc = "']gAVn-}f(ZXfeAR6.ji"
443 "ThisWillFailIfTheresMoreThanAGuidsChars>"
444 "3w2x^IGfe?CxI5heAvk.";
446 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
447 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
450 * Test a valid feature descriptor with the
451 * maximum number of characters and some trailing characters.
453 desc = "']gAVn-}f(ZXfeAR6.ji"
454 "ThisWillWorkIfTheresLTEThanAGuidsChars>"
455 "3w2x^IGfe?CxI5heAvk."
458 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
459 ok(r == ERROR_SUCCESS, "returned wrong error\n");
460 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
463 r = pMsiDecomposeDescriptorA(desc, prod, feature, NULL, &len);
464 ok(r == ERROR_SUCCESS, "returned wrong error\n");
465 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
468 r = pMsiDecomposeDescriptorA(desc, prod, NULL, NULL, &len);
469 ok(r == ERROR_SUCCESS, "returned wrong error\n");
470 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
473 r = pMsiDecomposeDescriptorA(desc, NULL, NULL, NULL, &len);
474 ok(r == ERROR_SUCCESS, "returned wrong error\n");
475 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
478 r = pMsiDecomposeDescriptorA(NULL, NULL, NULL, NULL, &len);
479 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
480 ok(len == 0, "length wrong\n");
483 static UINT try_query_param( MSIHANDLE hdb, LPCSTR szQuery, MSIHANDLE hrec )
488 res = MsiDatabaseOpenView( hdb, szQuery, &htab );
489 if(res == ERROR_SUCCESS )
493 r = MsiViewExecute( htab, hrec );
494 if(r != ERROR_SUCCESS )
497 r = MsiViewClose( htab );
498 if(r != ERROR_SUCCESS )
501 r = MsiCloseHandle( htab );
502 if(r != ERROR_SUCCESS )
508 static UINT try_query( MSIHANDLE hdb, LPCSTR szQuery )
510 return try_query_param( hdb, szQuery, 0 );
513 static UINT try_insert_query( MSIHANDLE hdb, LPCSTR szQuery )
518 hrec = MsiCreateRecord( 1 );
519 MsiRecordSetString( hrec, 1, "Hello");
521 r = try_query_param( hdb, szQuery, hrec );
523 MsiCloseHandle( hrec );
527 static void test_msibadqueries(void)
534 /* just MsiOpenDatabase should not create a file */
535 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
536 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
538 r = MsiDatabaseCommit( hdb );
539 ok(r == ERROR_SUCCESS , "Failed to commit database\n");
541 r = MsiCloseHandle( hdb );
542 ok(r == ERROR_SUCCESS , "Failed to close database\n");
544 /* open it readonly */
545 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb );
546 ok(r == ERROR_SUCCESS , "Failed to open database r/o\n");
548 /* add a table to it */
549 r = try_query( hdb, "select * from _Tables");
550 ok(r == ERROR_SUCCESS , "query 1 failed\n");
552 r = MsiCloseHandle( hdb );
553 ok(r == ERROR_SUCCESS , "Failed to close database r/o\n");
555 /* open it read/write */
556 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
557 ok(r == ERROR_SUCCESS , "Failed to open database r/w\n");
559 /* a bunch of test queries that fail with the native MSI */
561 r = try_query( hdb, "CREATE TABLE");
562 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2a return code\n");
564 r = try_query( hdb, "CREATE TABLE `a`");
565 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2b return code\n");
567 r = try_query( hdb, "CREATE TABLE `a` ()");
568 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2c return code\n");
570 r = try_query( hdb, "CREATE TABLE `a` (`b`)");
571 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2d return code\n");
573 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) )");
574 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2e return code\n");
576 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
577 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2f return code\n");
579 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
580 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2g return code\n");
582 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
583 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2h return code\n");
585 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
586 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2i return code\n");
588 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
589 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2j return code\n");
591 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
592 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2k return code\n");
594 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
595 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2l return code\n");
597 r = try_query( hdb, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
598 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2m return code\n");
600 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
601 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2n return code\n");
603 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
604 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2o return code\n");
606 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
607 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
609 r = try_query( hdb, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
610 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
612 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
613 ok(r == ERROR_SUCCESS , "valid query 2z failed\n");
615 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
616 ok(r == ERROR_BAD_QUERY_SYNTAX , "created same table again\n");
618 r = try_query( hdb, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
619 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
620 ok(r == ERROR_SUCCESS , "query 4 failed\n");
622 r = MsiDatabaseCommit( hdb );
623 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
625 r = try_query( hdb, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
626 "PRIMARY KEY `foo`)");
627 ok(r == ERROR_SUCCESS , "query 4 failed\n");
629 r = try_insert_query( hdb, "insert into a ( `b` ) VALUES ( ? )");
630 ok(r == ERROR_SUCCESS , "failed to insert record in db\n");
632 r = MsiDatabaseCommit( hdb );
633 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
635 r = try_query( hdb, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
636 "PRIMARY KEY `ba`)");
637 ok(r != ERROR_SUCCESS , "query 5 succeeded\n");
639 r = try_query( hdb,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
640 ok(r != ERROR_SUCCESS , "query 6 succeeded\n");
642 r = try_query( hdb, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
644 ok(r == ERROR_SUCCESS , "query 7 failed\n");
646 r = try_query( hdb, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
647 ok(r == ERROR_SUCCESS , "query 8 failed\n");
649 r = try_query( hdb, "select * from c");
650 ok(r == ERROR_SUCCESS , "query failed\n");
652 r = try_query( hdb, "select * from c where b = 'x");
653 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
655 r = try_query( hdb, "select * from c where b = 'x'");
656 ok(r == ERROR_SUCCESS, "query failed\n");
658 r = try_query( hdb, "select * from 'c'");
659 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
661 r = try_query( hdb, "select * from ''");
662 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
664 r = try_query( hdb, "select * from c where b = x");
665 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
667 r = try_query( hdb, "select * from c where b = \"x\"");
668 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
670 r = try_query( hdb, "select * from c where b = 'x'");
671 ok(r == ERROR_SUCCESS, "query failed\n");
673 r = try_query( hdb, "select * from c where b = '\"x'");
674 ok(r == ERROR_SUCCESS, "query failed\n");
676 if (0) /* FIXME: this query causes trouble with other tests */
678 r = try_query( hdb, "select * from c where b = '\\\'x'");
679 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
682 r = try_query( hdb, "select * from 'c'");
683 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
685 r = MsiCloseHandle( hdb );
686 ok(r == ERROR_SUCCESS , "Failed to close database transact\n");
688 r = DeleteFile( msifile );
689 ok(r == TRUE, "file didn't exist after commit\n");
692 static void test_viewmodify(void)
694 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
703 /* just MsiOpenDatabase should not create a file */
704 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
705 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
707 query = "CREATE TABLE `phone` ( "
708 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
710 r = run_query( hdb, 0, query );
711 ok(r == ERROR_SUCCESS, "query failed\n");
713 /* check what the error function reports without doing anything */
715 /* passing NULL as the 3rd param make function to crash on older platforms */
716 err = MsiViewGetError( 0, NULL, &sz );
717 ok(err == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
720 query = "SELECT * FROM `phone`";
721 r = MsiDatabaseOpenView(hdb, query, &hview);
722 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
724 /* see what happens with a good hview and bad args */
725 err = MsiViewGetError( hview, NULL, NULL );
726 ok(err == MSIDBERROR_INVALIDARG || err == MSIDBERROR_NOERROR,
727 "MsiViewGetError returns %u (expected -3)\n", err);
728 err = MsiViewGetError( hview, buffer, NULL );
729 ok(err == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
731 /* see what happens with a zero length buffer */
734 err = MsiViewGetError( hview, buffer, &sz );
735 ok(err == MSIDBERROR_MOREDATA, "MsiViewGetError return\n");
736 ok(buffer[0] == 'x', "buffer cleared\n");
737 ok(sz == 0, "size not zero\n");
739 /* ok this one is strange */
741 err = MsiViewGetError( hview, NULL, &sz );
742 ok(err == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
743 ok(sz == 0, "size not zero\n");
745 /* see if it really has an error */
748 err = MsiViewGetError( hview, buffer, &sz );
749 ok(err == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
750 ok(buffer[0] == 0, "buffer not cleared\n");
751 ok(sz == 0, "size not zero\n");
753 r = MsiViewExecute(hview, 0);
754 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
756 /* try some invalid records */
757 r = MsiViewModify(hview, MSIMODIFY_INSERT, 0 );
758 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
759 r = MsiViewModify(hview, -1, 0 );
760 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
762 /* try an small record */
763 hrec = MsiCreateRecord(1);
764 r = MsiViewModify(hview, -1, hrec );
765 ok(r == ERROR_INVALID_DATA, "MsiViewModify failed\n");
767 r = MsiCloseHandle(hrec);
768 ok(r == ERROR_SUCCESS, "failed to close record\n");
770 /* insert a valid record */
771 hrec = MsiCreateRecord(3);
773 r = MsiRecordSetInteger(hrec, 1, 1);
774 ok(r == ERROR_SUCCESS, "failed to set integer\n");
775 r = MsiRecordSetString(hrec, 2, "bob");
776 ok(r == ERROR_SUCCESS, "failed to set string\n");
777 r = MsiRecordSetString(hrec, 3, "7654321");
778 ok(r == ERROR_SUCCESS, "failed to set string\n");
780 r = MsiViewExecute(hview, 0);
781 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
782 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
783 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
785 /* insert the same thing again */
786 r = MsiViewExecute(hview, 0);
787 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
789 /* should fail ... */
790 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
791 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
793 r = MsiCloseHandle(hrec);
794 ok(r == ERROR_SUCCESS, "failed to close record\n");
796 r = MsiViewClose(hview);
797 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
798 r = MsiCloseHandle(hview);
799 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
801 query = "SELECT * FROM `phone`";
802 r = MsiDatabaseOpenView(hdb, query, &hview);
803 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
805 r = MsiViewExecute(hview, 0);
806 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
808 r = MsiViewFetch(hview, &hrec);
809 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
811 r = MsiRecordGetInteger(hrec, 1);
812 ok(r == 1, "Expected 1, got %d\n", r);
815 r = MsiRecordGetString(hrec, 2, buffer, &sz);
816 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
817 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
820 r = MsiRecordGetString(hrec, 3, buffer, &sz);
821 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
822 ok(!lstrcmp(buffer, "7654321"), "Expected 7654321, got %s\n", buffer);
824 /* update the view, non-primary key */
825 r = MsiRecordSetString(hrec, 3, "3141592");
826 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
828 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
829 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
832 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
833 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
835 /* update the view, primary key */
836 r = MsiRecordSetInteger(hrec, 1, 5);
837 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
839 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
840 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
842 r = MsiCloseHandle(hrec);
843 ok(r == ERROR_SUCCESS, "failed to close record\n");
845 r = MsiViewClose(hview);
846 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
847 r = MsiCloseHandle(hview);
848 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
850 query = "SELECT * FROM `phone`";
851 r = MsiDatabaseOpenView(hdb, query, &hview);
852 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
854 r = MsiViewExecute(hview, 0);
855 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
857 r = MsiViewFetch(hview, &hrec);
858 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
860 r = MsiRecordGetInteger(hrec, 1);
861 ok(r == 1, "Expected 1, got %d\n", r);
864 r = MsiRecordGetString(hrec, 2, buffer, &sz);
865 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
866 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
869 r = MsiRecordGetString(hrec, 3, buffer, &sz);
870 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
871 ok(!lstrcmp(buffer, "3141592"), "Expected 3141592, got %s\n", buffer);
873 r = MsiCloseHandle(hrec);
874 ok(r == ERROR_SUCCESS, "failed to close record\n");
876 /* use a record that doesn't come from a view fetch */
877 hrec = MsiCreateRecord(3);
878 ok(hrec != 0, "MsiCreateRecord failed\n");
880 r = MsiRecordSetInteger(hrec, 1, 3);
881 ok(r == ERROR_SUCCESS, "failed to set integer\n");
882 r = MsiRecordSetString(hrec, 2, "jane");
883 ok(r == ERROR_SUCCESS, "failed to set string\n");
884 r = MsiRecordSetString(hrec, 3, "112358");
885 ok(r == ERROR_SUCCESS, "failed to set string\n");
887 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
888 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
890 r = MsiCloseHandle(hrec);
891 ok(r == ERROR_SUCCESS, "failed to close record\n");
893 /* use a record that doesn't come from a view fetch, primary key matches */
894 hrec = MsiCreateRecord(3);
895 ok(hrec != 0, "MsiCreateRecord failed\n");
897 r = MsiRecordSetInteger(hrec, 1, 1);
898 ok(r == ERROR_SUCCESS, "failed to set integer\n");
899 r = MsiRecordSetString(hrec, 2, "jane");
900 ok(r == ERROR_SUCCESS, "failed to set string\n");
901 r = MsiRecordSetString(hrec, 3, "112358");
902 ok(r == ERROR_SUCCESS, "failed to set string\n");
904 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
905 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
907 r = MsiCloseHandle(hrec);
908 ok(r == ERROR_SUCCESS, "failed to close record\n");
910 hrec = MsiCreateRecord(3);
912 r = MsiRecordSetInteger(hrec, 1, 2);
913 ok(r == ERROR_SUCCESS, "failed to set integer\n");
914 r = MsiRecordSetString(hrec, 2, "nick");
915 ok(r == ERROR_SUCCESS, "failed to set string\n");
916 r = MsiRecordSetString(hrec, 3, "141421");
917 ok(r == ERROR_SUCCESS, "failed to set string\n");
919 r = MsiViewExecute(hview, 0);
920 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
921 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
922 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
924 r = MsiViewClose(hview);
925 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
926 r = MsiCloseHandle(hview);
927 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
929 query = "SELECT * FROM `phone` WHERE `id` = 1";
930 r = MsiDatabaseOpenView(hdb, query, &hview);
931 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
932 r = MsiViewExecute(hview, 0);
933 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
934 r = MsiViewFetch(hview, &hrec);
935 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
937 /* change the id to match the second row */
938 r = MsiRecordSetInteger(hrec, 1, 2);
939 ok(r == ERROR_SUCCESS, "failed to set integer\n");
940 r = MsiRecordSetString(hrec, 2, "jerry");
941 ok(r == ERROR_SUCCESS, "failed to set string\n");
943 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
944 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
946 r = MsiCloseHandle(hrec);
947 ok(r == ERROR_SUCCESS, "failed to close record\n");
948 r = MsiViewClose(hview);
949 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
950 r = MsiCloseHandle(hview);
951 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
954 query = "SELECT * FROM `phone` ORDER BY `id`";
955 r = MsiDatabaseOpenView(hdb, query, &hview);
956 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
957 r = MsiViewExecute(hview, 0);
958 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
959 r = MsiViewFetch(hview, &hrec);
960 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
962 /* change the id to match the second row */
963 r = MsiRecordSetInteger(hrec, 1, 2);
964 ok(r == ERROR_SUCCESS, "failed to set integer\n");
965 r = MsiRecordSetString(hrec, 2, "jerry");
966 ok(r == ERROR_SUCCESS, "failed to set string\n");
968 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
969 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
971 r = MsiCloseHandle(hrec);
972 ok(r == ERROR_SUCCESS, "failed to close record\n");
973 r = MsiViewClose(hview);
974 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
975 r = MsiCloseHandle(hview);
976 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
978 r = MsiCloseHandle( hdb );
979 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
982 static MSIHANDLE create_db(void)
989 /* create an empty database */
990 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
991 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
992 if( res != ERROR_SUCCESS )
995 res = MsiDatabaseCommit( hdb );
996 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
1001 static void test_getcolinfo(void)
1003 MSIHANDLE hdb, hview = 0, rec = 0;
1008 /* create an empty db */
1010 ok( hdb, "failed to create db\n");
1012 /* tables should be present */
1013 r = MsiDatabaseOpenView(hdb, "select * from _Tables", &hview);
1014 ok( r == ERROR_SUCCESS, "failed to open query\n");
1016 r = MsiViewExecute(hview, 0);
1017 ok( r == ERROR_SUCCESS, "failed to execute query\n");
1019 /* check that NAMES works */
1021 r = MsiViewGetColumnInfo( hview, MSICOLINFO_NAMES, &rec );
1022 ok( r == ERROR_SUCCESS, "failed to get names\n");
1024 r = MsiRecordGetString(rec, 1, buffer, &sz );
1025 ok( r == ERROR_SUCCESS, "failed to get string\n");
1026 ok( !strcmp(buffer,"Name"), "_Tables has wrong column name\n");
1027 r = MsiCloseHandle( rec );
1028 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1030 /* check that TYPES works */
1032 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, &rec );
1033 ok( r == ERROR_SUCCESS, "failed to get names\n");
1035 r = MsiRecordGetString(rec, 1, buffer, &sz );
1036 ok( r == ERROR_SUCCESS, "failed to get string\n");
1037 ok( !strcmp(buffer,"s64"), "_Tables has wrong column type\n");
1038 r = MsiCloseHandle( rec );
1039 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1041 /* check that invalid values fail */
1043 r = MsiViewGetColumnInfo( hview, 100, &rec );
1044 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1045 ok( rec == 0, "returned a record\n");
1047 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, NULL );
1048 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1050 r = MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES, &rec );
1051 ok( r == ERROR_INVALID_HANDLE, "wrong error code\n");
1053 r = MsiViewClose(hview);
1054 ok( r == ERROR_SUCCESS, "failed to close view\n");
1055 r = MsiCloseHandle(hview);
1056 ok( r == ERROR_SUCCESS, "failed to close view handle\n");
1057 r = MsiCloseHandle(hdb);
1058 ok( r == ERROR_SUCCESS, "failed to close database\n");
1061 static MSIHANDLE get_column_info(MSIHANDLE hdb, const char *query, MSICOLINFO type)
1063 MSIHANDLE hview = 0, rec = 0;
1066 r = MsiDatabaseOpenView(hdb, query, &hview);
1067 if( r != ERROR_SUCCESS )
1070 r = MsiViewExecute(hview, 0);
1071 if( r == ERROR_SUCCESS )
1073 MsiViewGetColumnInfo( hview, type, &rec );
1075 MsiViewClose(hview);
1076 MsiCloseHandle(hview);
1080 static UINT get_columns_table_type(MSIHANDLE hdb, const char *table, UINT field)
1082 MSIHANDLE hview = 0, rec = 0;
1086 sprintf(query, "select * from `_Columns` where `Table` = '%s'", table );
1088 r = MsiDatabaseOpenView(hdb, query, &hview);
1089 if( r != ERROR_SUCCESS )
1092 r = MsiViewExecute(hview, 0);
1093 if( r == ERROR_SUCCESS )
1097 r = MsiViewFetch( hview, &rec );
1098 if( r != ERROR_SUCCESS)
1100 r = MsiRecordGetInteger( rec, 2 );
1102 type = MsiRecordGetInteger( rec, 4 );
1103 MsiCloseHandle( rec );
1106 MsiViewClose(hview);
1107 MsiCloseHandle(hview);
1111 static BOOL check_record( MSIHANDLE rec, UINT field, LPCSTR val )
1118 r = MsiRecordGetString( rec, field, buffer, &sz );
1119 return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
1122 static void test_viewgetcolumninfo(void)
1124 MSIHANDLE hdb = 0, rec;
1128 ok( hdb, "failed to create db\n");
1130 r = run_query( hdb, 0,
1131 "CREATE TABLE `Properties` "
1132 "( `Property` CHAR(255), "
1133 " `Value` CHAR(1), "
1135 " `Integervalue` INTEGER, "
1136 " `Shortvalue` SHORT, "
1137 " `Longvalue` LONG, "
1138 " `Longcharvalue` LONGCHAR "
1139 " PRIMARY KEY `Property`)" );
1140 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1142 /* check the column types */
1143 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_TYPES );
1144 ok( rec, "failed to get column info record\n" );
1146 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1147 ok( check_record( rec, 2, "S1"), "wrong record type\n");
1148 ok( check_record( rec, 3, "I2"), "wrong record type\n");
1149 ok( check_record( rec, 4, "I2"), "wrong record type\n");
1150 ok( check_record( rec, 5, "I2"), "wrong record type\n");
1151 ok( check_record( rec, 6, "I4"), "wrong record type\n");
1152 ok( check_record( rec, 7, "S0"), "wrong record type\n");
1154 MsiCloseHandle( rec );
1156 /* check the type in _Columns */
1157 ok( 0x3dff == get_columns_table_type(hdb, "Properties", 1 ), "_columns table wrong\n");
1158 ok( 0x1d01 == get_columns_table_type(hdb, "Properties", 2 ), "_columns table wrong\n");
1159 ok( 0x1502 == get_columns_table_type(hdb, "Properties", 3 ), "_columns table wrong\n");
1160 ok( 0x1502 == get_columns_table_type(hdb, "Properties", 4 ), "_columns table wrong\n");
1161 ok( 0x1502 == get_columns_table_type(hdb, "Properties", 5 ), "_columns table wrong\n");
1162 ok( 0x1104 == get_columns_table_type(hdb, "Properties", 6 ), "_columns table wrong\n");
1163 ok( 0x1d00 == get_columns_table_type(hdb, "Properties", 7 ), "_columns table wrong\n");
1165 /* now try the names */
1166 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_NAMES );
1167 ok( rec, "failed to get column info record\n" );
1169 ok( check_record( rec, 1, "Property"), "wrong record type\n");
1170 ok( check_record( rec, 2, "Value"), "wrong record type\n");
1171 ok( check_record( rec, 3, "Intvalue"), "wrong record type\n");
1172 ok( check_record( rec, 4, "Integervalue"), "wrong record type\n");
1173 ok( check_record( rec, 5, "Shortvalue"), "wrong record type\n");
1174 ok( check_record( rec, 6, "Longvalue"), "wrong record type\n");
1175 ok( check_record( rec, 7, "Longcharvalue"), "wrong record type\n");
1177 MsiCloseHandle( rec );
1179 r = run_query( hdb, 0,
1180 "CREATE TABLE `Binary` "
1181 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
1182 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1184 /* check the column types */
1185 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_TYPES );
1186 ok( rec, "failed to get column info record\n" );
1188 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1189 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1191 MsiCloseHandle( rec );
1193 /* check the type in _Columns */
1194 ok( 0x3dff == get_columns_table_type(hdb, "Binary", 1 ), "_columns table wrong\n");
1195 ok( 0x1900 == get_columns_table_type(hdb, "Binary", 2 ), "_columns table wrong\n");
1197 /* now try the names */
1198 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_NAMES );
1199 ok( rec, "failed to get column info record\n" );
1201 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1202 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1203 MsiCloseHandle( rec );
1205 r = run_query( hdb, 0,
1206 "CREATE TABLE `UIText` "
1207 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1208 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1210 ok( 0x2d48 == get_columns_table_type(hdb, "UIText", 1 ), "_columns table wrong\n");
1211 ok( 0x1fff == get_columns_table_type(hdb, "UIText", 2 ), "_columns table wrong\n");
1213 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_NAMES );
1214 ok( rec, "failed to get column info record\n" );
1215 ok( check_record( rec, 1, "Key"), "wrong record type\n");
1216 ok( check_record( rec, 2, "Text"), "wrong record type\n");
1217 MsiCloseHandle( rec );
1219 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_TYPES );
1220 ok( rec, "failed to get column info record\n" );
1221 ok( check_record( rec, 1, "s72"), "wrong record type\n");
1222 ok( check_record( rec, 2, "L255"), "wrong record type\n");
1223 MsiCloseHandle( rec );
1225 MsiCloseHandle( hdb );
1228 static void test_msiexport(void)
1230 MSIHANDLE hdb = 0, hview = 0;
1233 char path[MAX_PATH];
1234 const char file[] = "phone.txt";
1238 const char expected[] =
1239 "id\tname\tnumber\r\n"
1242 "1\tAbe\t8675309\r\n";
1244 DeleteFile(msifile);
1246 /* just MsiOpenDatabase should not create a file */
1247 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1248 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1250 /* create a table */
1251 query = "CREATE TABLE `phone` ( "
1252 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1253 "PRIMARY KEY `id`)";
1254 r = MsiDatabaseOpenView(hdb, query, &hview);
1255 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1256 r = MsiViewExecute(hview, 0);
1257 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1258 r = MsiViewClose(hview);
1259 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1260 r = MsiCloseHandle(hview);
1261 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1263 /* insert a value into it */
1264 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
1265 "VALUES('1', 'Abe', '8675309')";
1266 r = MsiDatabaseOpenView(hdb, query, &hview);
1267 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1268 r = MsiViewExecute(hview, 0);
1269 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1270 r = MsiViewClose(hview);
1271 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1272 r = MsiCloseHandle(hview);
1273 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1275 GetCurrentDirectory(MAX_PATH, path);
1277 r = MsiDatabaseExport(hdb, "phone", path, file);
1278 ok(r == ERROR_SUCCESS, "MsiDatabaseExport failed\n");
1280 MsiCloseHandle(hdb);
1282 lstrcat(path, "\\");
1283 lstrcat(path, file);
1285 /* check the data that was written */
1287 memset(buffer, 0, sizeof buffer);
1288 handle = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
1289 if (handle != INVALID_HANDLE_VALUE)
1291 ReadFile(handle, buffer, sizeof buffer, &length, NULL);
1292 CloseHandle(handle);
1296 ok(0, "failed to open file %s\n", path);
1298 ok( length == strlen(expected), "length of data wrong\n");
1299 ok( !lstrcmp(buffer, expected), "data doesn't match\n");
1300 DeleteFile(msifile);
1303 static void test_longstrings(void)
1305 const char insert_query[] =
1306 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1308 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
1311 const DWORD STRING_LENGTH = 0x10005;
1313 DeleteFile(msifile);
1314 /* just MsiOpenDatabase should not create a file */
1315 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1316 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1318 /* create a table */
1320 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1321 ok(r == ERROR_SUCCESS, "query failed\n");
1323 /* try a insert a very long string */
1324 str = HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH+sizeof insert_query);
1325 len = strchr(insert_query, 'Z') - insert_query;
1326 strcpy(str, insert_query);
1327 memset(str+len, 'Z', STRING_LENGTH);
1328 strcpy(str+len+STRING_LENGTH, insert_query+len+1);
1329 r = try_query( hdb, str );
1330 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1332 HeapFree(GetProcessHeap(), 0, str);
1334 MsiDatabaseCommit(hdb);
1335 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
1336 MsiCloseHandle(hdb);
1338 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
1339 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1341 r = MsiDatabaseOpenView(hdb, "select * from `strings` where `id` = 1", &hview);
1342 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1344 r = MsiViewExecute(hview, 0);
1345 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1347 r = MsiViewFetch(hview, &hrec);
1348 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1350 MsiViewClose(hview);
1351 MsiCloseHandle(hview);
1353 r = MsiRecordGetString(hrec, 2, NULL, &len);
1354 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1355 ok(len == STRING_LENGTH, "string length wrong\n");
1357 MsiCloseHandle(hrec);
1358 MsiCloseHandle(hdb);
1359 DeleteFile(msifile);
1362 static void create_file_data(LPCSTR name, LPCSTR data, DWORD size)
1367 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1368 if (file == INVALID_HANDLE_VALUE)
1371 WriteFile(file, data, strlen(data), &written, NULL);
1372 WriteFile(file, "\n", strlen("\n"), &written, NULL);
1376 SetFilePointer(file, size, NULL, FILE_BEGIN);
1383 #define create_file(name) create_file_data(name, name, 0)
1385 static void test_streamtable(void)
1387 MSIHANDLE hdb = 0, rec, view;
1388 char file[MAX_PATH];
1394 ok( hdb, "failed to create db\n");
1396 r = run_query( hdb, 0,
1397 "CREATE TABLE `Properties` "
1398 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1399 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1401 r = run_query( hdb, 0,
1402 "INSERT INTO `Properties` "
1403 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1404 ok( r == ERROR_SUCCESS, "Failed to add to table\n" );
1406 r = MsiDatabaseCommit( hdb );
1407 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1409 MsiCloseHandle( hdb );
1411 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
1412 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1414 /* check the column types */
1415 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_TYPES );
1416 ok( rec, "failed to get column info record\n" );
1418 ok( check_record( rec, 1, "s62"), "wrong record type\n");
1419 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1421 MsiCloseHandle( rec );
1423 /* now try the names */
1424 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_NAMES );
1425 ok( rec, "failed to get column info record\n" );
1427 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1428 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1430 MsiCloseHandle( rec );
1432 /* insert a file into the _Streams table */
1433 create_file( "test.txt" );
1435 rec = MsiCreateRecord( 2 );
1436 MsiRecordSetString( rec, 1, "data" );
1438 r = MsiRecordSetStream( rec, 2, "test.txt" );
1439 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1441 DeleteFile("test.txt");
1443 r = MsiDatabaseOpenView( hdb,
1444 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view );
1445 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1447 r = MsiViewExecute( view, rec );
1448 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1450 MsiCloseHandle( rec );
1451 MsiViewClose( view );
1452 MsiCloseHandle( view );
1454 r = MsiDatabaseOpenView( hdb,
1455 "SELECT `Name`, `Data` FROM `_Streams`", &view );
1456 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1458 r = MsiViewExecute( view, 0 );
1459 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1461 r = MsiViewFetch( view, &rec );
1462 ok( r == ERROR_SUCCESS, "Failed to fetch record: %d\n", r);
1465 r = MsiRecordGetString( rec, 1, file, &size );
1466 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1467 ok( !lstrcmp(file, "data"), "Expected 'data', got %s\n", file);
1470 memset(buf, 0, MAX_PATH);
1471 r = MsiRecordReadStream( rec, 2, buf, &size );
1472 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1473 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf);
1475 MsiCloseHandle( rec );
1477 r = MsiViewFetch( view, &rec );
1478 ok( r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
1480 MsiViewClose( view );
1481 MsiCloseHandle( view );
1482 MsiCloseHandle( hdb );
1483 DeleteFile(msifile);
1486 static void test_binary(void)
1488 MSIHANDLE hdb = 0, rec;
1489 char file[MAX_PATH];
1495 /* insert a file into the Binary table */
1496 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
1497 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1499 query = "CREATE TABLE `Binary` ( `Name` CHAR(72) NOT NULL, `ID` INT NOT NULL, `Data` OBJECT PRIMARY KEY `Name`, `ID`)";
1500 r = run_query( hdb, 0, query );
1501 ok( r == ERROR_SUCCESS, "Cannot create Binary table: %d\n", r );
1503 create_file( "test.txt" );
1504 rec = MsiCreateRecord( 1 );
1505 r = MsiRecordSetStream( rec, 1, "test.txt" );
1506 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1507 DeleteFile( "test.txt" );
1509 query = "INSERT INTO `Binary` ( `Name`, `ID`, `Data` ) VALUES ( 'filename1', 1, ? )";
1510 r = run_query( hdb, rec, query );
1511 ok( r == ERROR_SUCCESS, "Insert into Binary table failed: %d\n", r );
1513 r = MsiCloseHandle( rec );
1514 ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
1516 r = MsiDatabaseCommit( hdb );
1517 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1519 r = MsiCloseHandle( hdb );
1520 ok( r == ERROR_SUCCESS , "Failed to close database\n" );
1522 /* read file from the Stream table */
1523 r = MsiOpenDatabase( msifile, MSIDBOPEN_READONLY, &hdb );
1524 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1526 query = "SELECT * FROM `_Streams`";
1527 r = do_query( hdb, query, &rec );
1528 ok( r == ERROR_SUCCESS, "SELECT query failed: %d\n", r );
1531 r = MsiRecordGetString( rec, 1, file, &size );
1532 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r );
1533 ok( !lstrcmp(file, "Binary.filename1.1"), "Expected 'Binary.filename1.1', got %s\n", file );
1536 memset( buf, 0, MAX_PATH );
1537 r = MsiRecordReadStream( rec, 2, buf, &size );
1538 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r );
1539 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf );
1541 r = MsiCloseHandle( rec );
1542 ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
1544 /* read file from the Binary table */
1545 query = "SELECT * FROM `Binary`";
1546 r = do_query( hdb, query, &rec );
1547 ok( r == ERROR_SUCCESS, "SELECT query failed: %d\n", r );
1550 r = MsiRecordGetString( rec, 1, file, &size );
1551 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r );
1552 ok( !lstrcmp(file, "filename1"), "Expected 'filename1', got %s\n", file );
1555 memset( buf, 0, MAX_PATH );
1556 r = MsiRecordReadStream( rec, 3, buf, &size );
1557 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r );
1558 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf );
1560 r = MsiCloseHandle( rec );
1561 ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
1563 r = MsiCloseHandle( hdb );
1564 ok( r == ERROR_SUCCESS , "Failed to close database\n" );
1566 DeleteFile( msifile );
1569 static void test_where_not_in_selected(void)
1571 MSIHANDLE hdb = 0, rec, view;
1576 ok( hdb, "failed to create db\n");
1578 r = run_query(hdb, 0,
1579 "CREATE TABLE `IESTable` ("
1580 "`Action` CHAR(64), "
1581 "`Condition` CHAR(64), "
1582 "`Sequence` LONG PRIMARY KEY `Sequence`)");
1583 ok( r == S_OK, "Cannot create IESTable table: %d\n", r);
1585 r = run_query(hdb, 0,
1586 "CREATE TABLE `CATable` ("
1587 "`Action` CHAR(64), "
1588 "`Type` LONG PRIMARY KEY `Type`)");
1589 ok( r == S_OK, "Cannot create CATable table: %d\n", r);
1591 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1592 "( `Action`, `Condition`, `Sequence`) "
1593 "VALUES ( 'clean', 'cond4', 4)");
1594 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1596 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1597 "( `Action`, `Condition`, `Sequence`) "
1598 "VALUES ( 'depends', 'cond1', 1)");
1599 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1601 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1602 "( `Action`, `Condition`, `Sequence`) "
1603 "VALUES ( 'build', 'cond2', 2)");
1604 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1606 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1607 "( `Action`, `Condition`, `Sequence`) "
1608 "VALUES ( 'build2', 'cond6', 6)");
1609 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1611 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1612 "( `Action`, `Condition`, `Sequence`) "
1613 "VALUES ( 'build', 'cond3', 3)");
1614 ok(r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1616 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1617 "( `Action`, `Type` ) "
1618 "VALUES ( 'build', 32)");
1619 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1621 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1622 "( `Action`, `Type` ) "
1623 "VALUES ( 'depends', 64)");
1624 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1626 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1627 "( `Action`, `Type` ) "
1628 "VALUES ( 'clean', 63)");
1629 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1631 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1632 "( `Action`, `Type` ) "
1633 "VALUES ( 'build2', 34)");
1634 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1635 query = "Select IESTable.Condition from CATable, IESTable where "
1636 "CATable.Action = IESTable.Action and CATable.Type = 32";
1637 r = MsiDatabaseOpenView(hdb, query, &view);
1638 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1640 r = MsiViewExecute(view, 0);
1641 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1643 r = MsiViewFetch(view, &rec);
1644 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1646 ok( check_record( rec, 1, "cond2"), "wrong condition\n");
1648 MsiCloseHandle( rec );
1649 r = MsiViewFetch(view, &rec);
1650 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1652 ok( check_record( rec, 1, "cond3"), "wrong condition\n");
1654 MsiCloseHandle( rec );
1656 MsiCloseHandle(view);
1658 MsiCloseHandle( hdb );
1659 DeleteFile(msifile);
1664 static void test_where(void)
1666 MSIHANDLE hdb = 0, rec, view;
1674 ok( hdb, "failed to create db\n");
1676 r = run_query( hdb, 0,
1677 "CREATE TABLE `Media` ("
1678 "`DiskId` SHORT NOT NULL, "
1679 "`LastSequence` LONG, "
1680 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1681 "`Cabinet` CHAR(255), "
1682 "`VolumeLabel` CHAR(32), "
1683 "`Source` CHAR(72) "
1684 "PRIMARY KEY `DiskId`)" );
1685 ok( r == S_OK, "cannot create Media table: %d\n", r );
1687 r = run_query( hdb, 0, "INSERT INTO `Media` "
1688 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1689 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1690 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1692 r = run_query( hdb, 0, "INSERT INTO `Media` "
1693 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1694 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1695 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1697 r = run_query( hdb, 0, "INSERT INTO `Media` "
1698 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1699 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1700 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1702 query = "SELECT * FROM `Media`";
1703 r = do_query(hdb, query, &rec);
1704 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1705 ok( check_record( rec, 4, "zero.cab"), "wrong cabinet\n");
1706 MsiCloseHandle( rec );
1708 query = "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1709 r = do_query(hdb, query, &rec);
1710 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1711 ok( check_record( rec, 4, "one.cab"), "wrong cabinet\n");
1713 r = MsiRecordGetInteger(rec, 1);
1714 ok( 2 == r, "field wrong\n");
1715 r = MsiRecordGetInteger(rec, 2);
1716 ok( 1 == r, "field wrong\n");
1717 MsiCloseHandle( rec );
1719 query = "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1720 r = MsiDatabaseOpenView(hdb, query, &view);
1721 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1723 r = MsiViewExecute(view, 0);
1724 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1726 r = MsiViewFetch(view, &rec);
1727 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1729 count = MsiRecordGetFieldCount( rec );
1730 ok( count == 1, "Expected 1 record fields, got %d\n", count );
1733 r = MsiRecordGetString( rec, 1, buf, &size );
1734 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1735 ok( !lstrcmp( buf, "2" ),
1736 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf );
1737 MsiCloseHandle( rec );
1739 r = MsiViewFetch(view, &rec);
1740 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1743 r = MsiRecordGetString( rec, 1, buf, &size );
1744 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1745 ok( !lstrcmp( buf, "3" ),
1746 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf );
1747 MsiCloseHandle( rec );
1749 r = MsiViewFetch(view, &rec);
1750 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
1753 MsiCloseHandle(view);
1755 MsiCloseHandle( rec );
1758 query = "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1759 r = do_query(hdb, query, &rec);
1760 ok( r == ERROR_SUCCESS, "query failed: %d\n", r );
1761 MsiCloseHandle( rec );
1763 rec = MsiCreateRecord(1);
1764 MsiRecordSetString(rec, 1, "");
1766 query = "SELECT * FROM `Media` WHERE `DiskPrompt` = ?";
1767 r = MsiDatabaseOpenView(hdb, query, &view);
1768 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1769 r = MsiViewExecute(view, rec);
1770 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1772 MsiCloseHandle(rec);
1774 r = MsiViewFetch(view, &rec);
1775 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1777 MsiCloseHandle(rec);
1779 MsiCloseHandle(view);
1781 MsiCloseHandle( hdb );
1782 DeleteFile(msifile);
1785 static CHAR CURR_DIR[MAX_PATH];
1787 static const CHAR test_data[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1788 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1789 "TestTable\tFirstPrimaryColumn\n"
1790 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1792 static const CHAR two_primary[] = "PrimaryOne\tPrimaryTwo\n"
1794 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1798 static const CHAR endlines1[] = "A\tB\tC\tD\tE\tF\r\n"
1799 "s72\ts72\ts72\ts72\ts72\ts72\n"
1801 "a\tb\tc\td\te\tf\n"
1802 "g\th\ti\t\rj\tk\tl\r\n";
1804 static const CHAR endlines2[] = "A\tB\tC\tD\tE\tF\r"
1805 "s72\ts72\ts72\ts72\ts72\ts72\n"
1807 "a\tb\tc\td\te\tf\n"
1808 "g\th\ti\tj\tk\tl\r\n";
1810 static const CHAR suminfo[] = "PropertyId\tValue\n"
1812 "_SummaryInformation\tPropertyId\n"
1814 "2\tInstaller Database\n"
1815 "3\tInstaller description\n"
1818 "6\tInstaller comments\n"
1820 "9\t{12345678-1234-1234-1234-123456789012}\n"
1821 "12\t2009/04/12 15:46:11\n"
1822 "13\t2009/04/12 15:46:11\n"
1828 static void write_file(const CHAR *filename, const char *data, int data_size)
1832 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
1833 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1835 WriteFile(hf, data, data_size, &size, NULL);
1839 static UINT add_table_to_db(MSIHANDLE hdb, LPCSTR table_data)
1843 write_file("temp_file", table_data, (lstrlen(table_data) - 1) * sizeof(char));
1844 r = MsiDatabaseImportA(hdb, CURR_DIR, "temp_file");
1845 DeleteFileA("temp_file");
1850 static void test_suminfo_import(void)
1852 MSIHANDLE hdb, hsi, view = 0;
1854 UINT r, count, size, type;
1859 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
1861 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
1862 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1864 r = add_table_to_db(hdb, suminfo);
1865 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1867 /* _SummaryInformation is not imported as a regular table... */
1869 query = "SELECT * FROM `_SummaryInformation`";
1870 r = MsiDatabaseOpenViewA(hdb, query, &view);
1871 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %u\n", r);
1872 MsiCloseHandle(view);
1874 /* ...its data is added to the special summary information stream */
1876 r = MsiGetSummaryInformationA(hdb, NULL, 0, &hsi);
1877 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1879 r = MsiSummaryInfoGetPropertyCount(hsi, &count);
1880 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1881 ok(count == 14, "Expected 14, got %u\n", count);
1883 r = MsiSummaryInfoGetPropertyA(hsi, PID_CODEPAGE, &type, &int_value, NULL, NULL, NULL);
1884 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1885 ok(type == VT_I2, "Expected VT_I2, got %u\n", type);
1886 ok(int_value == 1252, "Expected 1252, got %d\n", int_value);
1888 size = sizeof(str_value);
1889 r = MsiSummaryInfoGetPropertyA(hsi, PID_TITLE, &type, NULL, NULL, str_value, &size);
1890 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1891 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
1892 ok(size == 18, "Expected 18, got %u\n", size);
1893 ok(!strcmp(str_value, "Installer Database"),
1894 "Expected \"Installer Database\", got %s\n", str_value);
1896 size = sizeof(str_value);
1897 r = MsiSummaryInfoGetPropertyA(hsi, PID_SUBJECT, &type, NULL, NULL, str_value, &size);
1898 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1899 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
1900 ok(!strcmp(str_value, "Installer description"),
1901 "Expected \"Installer description\", got %s\n", str_value);
1903 size = sizeof(str_value);
1904 r = MsiSummaryInfoGetPropertyA(hsi, PID_AUTHOR, &type, NULL, NULL, str_value, &size);
1905 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1906 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
1907 ok(!strcmp(str_value, "WineHQ"),
1908 "Expected \"WineHQ\", got %s\n", str_value);
1910 size = sizeof(str_value);
1911 r = MsiSummaryInfoGetPropertyA(hsi, PID_KEYWORDS, &type, NULL, NULL, str_value, &size);
1912 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1913 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
1914 ok(!strcmp(str_value, "Installer"),
1915 "Expected \"Installer\", got %s\n", str_value);
1917 size = sizeof(str_value);
1918 r = MsiSummaryInfoGetPropertyA(hsi, PID_COMMENTS, &type, NULL, NULL, str_value, &size);
1919 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1920 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
1921 ok(!strcmp(str_value, "Installer comments"),
1922 "Expected \"Installer comments\", got %s\n", str_value);
1924 size = sizeof(str_value);
1925 r = MsiSummaryInfoGetPropertyA(hsi, PID_TEMPLATE, &type, NULL, NULL, str_value, &size);
1926 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1927 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
1928 ok(!strcmp(str_value, "Intel;1033"),
1929 "Expected \"Intel;1033\", got %s\n", str_value);
1931 size = sizeof(str_value);
1932 r = MsiSummaryInfoGetPropertyA(hsi, PID_REVNUMBER, &type, NULL, NULL, str_value, &size);
1933 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1934 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
1935 ok(!strcmp(str_value, "{12345678-1234-1234-1234-123456789012}"),
1936 "Expected \"{12345678-1234-1234-1234-123456789012}\", got %s\n", str_value);
1938 r = MsiSummaryInfoGetPropertyA(hsi, PID_CREATE_DTM, &type, NULL, &ft_value, NULL, NULL);
1939 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1940 ok(type == VT_FILETIME, "Expected VT_FILETIME, got %u\n", type);
1942 r = MsiSummaryInfoGetPropertyA(hsi, PID_LASTSAVE_DTM, &type, NULL, &ft_value, NULL, NULL);
1943 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1944 ok(type == VT_FILETIME, "Expected VT_FILETIME, got %u\n", type);
1946 r = MsiSummaryInfoGetPropertyA(hsi, PID_PAGECOUNT, &type, &int_value, NULL, NULL, NULL);
1947 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1948 ok(type == VT_I4, "Expected VT_I4, got %u\n", type);
1949 ok(int_value == 200, "Expected 200, got %d\n", int_value);
1951 r = MsiSummaryInfoGetPropertyA(hsi, PID_WORDCOUNT, &type, &int_value, NULL, NULL, NULL);
1952 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1953 ok(type == VT_I4, "Expected VT_I4, got %u\n", type);
1954 ok(int_value == 2, "Expected 2, got %d\n", int_value);
1956 r = MsiSummaryInfoGetPropertyA(hsi, PID_SECURITY, &type, &int_value, NULL, NULL, NULL);
1957 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1958 ok(type == VT_I4, "Expected VT_I4, got %u\n", type);
1959 ok(int_value == 2, "Expected 2, got %d\n", int_value);
1961 size = sizeof(str_value);
1962 r = MsiSummaryInfoGetPropertyA(hsi, PID_APPNAME, &type, NULL, NULL, str_value, &size);
1963 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
1964 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
1965 ok(!strcmp(str_value, "Vim"), "Expected \"Vim\", got %s\n", str_value);
1967 MsiCloseHandle(hsi);
1968 MsiCloseHandle(hdb);
1969 DeleteFileA(msifile);
1972 static void test_msiimport(void)
1974 MSIHANDLE hdb, view, rec;
1979 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
1981 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
1982 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1984 r = add_table_to_db(hdb, test_data);
1985 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1987 r = add_table_to_db(hdb, two_primary);
1988 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1990 r = add_table_to_db(hdb, endlines1);
1991 if (r == ERROR_FUNCTION_FAILED)
1993 /* win9x doesn't handle this case */
1994 skip("endlines not handled correctly.\n");
1995 MsiCloseHandle(hdb);
1996 DeleteFileA(msifile);
2000 r = add_table_to_db(hdb, endlines2);
2001 ok(r == ERROR_FUNCTION_FAILED,
2002 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
2004 query = "SELECT * FROM `TestTable`";
2005 r = MsiDatabaseOpenView(hdb, query, &view);
2006 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2008 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
2009 count = MsiRecordGetFieldCount(rec);
2010 ok(count == 9, "Expected 9, got %d\n", count);
2011 ok(check_record(rec, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
2012 ok(check_record(rec, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
2013 ok(check_record(rec, 3, "ShortInt"), "Expected ShortInt\n");
2014 ok(check_record(rec, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
2015 ok(check_record(rec, 5, "LongInt"), "Expected LongInt\n");
2016 ok(check_record(rec, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
2017 ok(check_record(rec, 7, "String"), "Expected String\n");
2018 ok(check_record(rec, 8, "LocalizableString"), "Expected LocalizableString\n");
2019 ok(check_record(rec, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
2020 MsiCloseHandle(rec);
2022 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2023 count = MsiRecordGetFieldCount(rec);
2024 ok(count == 9, "Expected 9, got %d\n", count);
2025 ok(check_record(rec, 1, "s255"), "Expected s255\n");
2026 ok(check_record(rec, 2, "i2"), "Expected i2\n");
2027 ok(check_record(rec, 3, "i2"), "Expected i2\n");
2028 ok(check_record(rec, 4, "I2"), "Expected I2\n");
2029 ok(check_record(rec, 5, "i4"), "Expected i4\n");
2030 ok(check_record(rec, 6, "I4"), "Expected I4\n");
2031 ok(check_record(rec, 7, "S255"), "Expected S255\n");
2032 ok(check_record(rec, 8, "S0"), "Expected S0\n");
2033 ok(check_record(rec, 9, "s0"), "Expected s0\n");
2034 MsiCloseHandle(rec);
2036 query = "SELECT * FROM `TestTable`";
2037 r = do_query(hdb, query, &rec);
2038 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2039 ok(check_record(rec, 1, "stringage"), "Expected 'stringage'\n");
2040 ok(check_record(rec, 7, "another string"), "Expected 'another string'\n");
2041 ok(check_record(rec, 8, "localizable"), "Expected 'localizable'\n");
2042 ok(check_record(rec, 9, "duh"), "Expected 'duh'\n");
2044 i = MsiRecordGetInteger(rec, 2);
2045 ok(i == 5, "Expected 5, got %d\n", i);
2047 i = MsiRecordGetInteger(rec, 3);
2048 ok(i == 2, "Expected 2, got %d\n", i);
2050 i = MsiRecordGetInteger(rec, 4);
2051 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
2053 i = MsiRecordGetInteger(rec, 5);
2054 ok(i == 2147483640, "Expected 2147483640, got %d\n", i);
2056 i = MsiRecordGetInteger(rec, 6);
2057 ok(i == -2147483640, "Expected -2147483640, got %d\n", i);
2059 MsiCloseHandle(rec);
2061 MsiCloseHandle(view);
2063 query = "SELECT * FROM `TwoPrimary`";
2064 r = MsiDatabaseOpenView(hdb, query, &view);
2065 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2067 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
2068 count = MsiRecordGetFieldCount(rec);
2069 ok(count == 2, "Expected 2, got %d\n", count);
2070 ok(check_record(rec, 1, "PrimaryOne"), "Expected PrimaryOne\n");
2071 ok(check_record(rec, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
2073 MsiCloseHandle(rec);
2075 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2076 count = MsiRecordGetFieldCount(rec);
2077 ok(count == 2, "Expected 2, got %d\n", count);
2078 ok(check_record(rec, 1, "s255"), "Expected s255\n");
2079 ok(check_record(rec, 2, "s255"), "Expected s255\n");
2080 MsiCloseHandle(rec);
2082 r = MsiViewExecute(view, 0);
2083 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2085 r = MsiViewFetch(view, &rec);
2086 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2088 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
2089 ok(check_record(rec, 2, "leaf"), "Expected 'leaf'\n");
2091 MsiCloseHandle(rec);
2093 r = MsiViewFetch(view, &rec);
2094 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2096 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
2097 ok(check_record(rec, 2, "flower"), "Expected 'flower'\n");
2099 MsiCloseHandle(rec);
2101 r = MsiViewFetch(view, &rec);
2102 ok(r == ERROR_NO_MORE_ITEMS,
2103 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
2105 r = MsiViewClose(view);
2106 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2108 MsiCloseHandle(view);
2110 query = "SELECT * FROM `Table`";
2111 r = MsiDatabaseOpenView(hdb, query, &view);
2112 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2114 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
2115 count = MsiRecordGetFieldCount(rec);
2116 ok(count == 6, "Expected 6, got %d\n", count);
2117 ok(check_record(rec, 1, "A"), "Expected A\n");
2118 ok(check_record(rec, 2, "B"), "Expected B\n");
2119 ok(check_record(rec, 3, "C"), "Expected C\n");
2120 ok(check_record(rec, 4, "D"), "Expected D\n");
2121 ok(check_record(rec, 5, "E"), "Expected E\n");
2122 ok(check_record(rec, 6, "F"), "Expected F\n");
2123 MsiCloseHandle(rec);
2125 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2126 count = MsiRecordGetFieldCount(rec);
2127 ok(count == 6, "Expected 6, got %d\n", count);
2128 ok(check_record(rec, 1, "s72"), "Expected s72\n");
2129 ok(check_record(rec, 2, "s72"), "Expected s72\n");
2130 ok(check_record(rec, 3, "s72"), "Expected s72\n");
2131 ok(check_record(rec, 4, "s72"), "Expected s72\n");
2132 ok(check_record(rec, 5, "s72"), "Expected s72\n");
2133 ok(check_record(rec, 6, "s72"), "Expected s72\n");
2134 MsiCloseHandle(rec);
2137 MsiCloseHandle(view);
2139 query = "SELECT * FROM `Table`";
2140 r = MsiDatabaseOpenView(hdb, query, &view);
2141 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2143 r = MsiViewExecute(view, 0);
2144 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2146 r = MsiViewFetch(view, &rec);
2147 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2148 ok(check_record(rec, 1, "a"), "Expected 'a'\n");
2149 ok(check_record(rec, 2, "b"), "Expected 'b'\n");
2150 ok(check_record(rec, 3, "c"), "Expected 'c'\n");
2151 ok(check_record(rec, 4, "d"), "Expected 'd'\n");
2152 ok(check_record(rec, 5, "e"), "Expected 'e'\n");
2153 ok(check_record(rec, 6, "f"), "Expected 'f'\n");
2155 MsiCloseHandle(rec);
2157 r = MsiViewFetch(view, &rec);
2158 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2159 ok(check_record(rec, 1, "g"), "Expected 'g'\n");
2160 ok(check_record(rec, 2, "h"), "Expected 'h'\n");
2161 ok(check_record(rec, 3, "i"), "Expected 'i'\n");
2162 ok(check_record(rec, 4, "j"), "Expected 'j'\n");
2163 ok(check_record(rec, 5, "k"), "Expected 'k'\n");
2164 ok(check_record(rec, 6, "l"), "Expected 'l'\n");
2166 MsiCloseHandle(rec);
2168 r = MsiViewFetch(view, &rec);
2169 ok(r == ERROR_NO_MORE_ITEMS,
2170 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
2173 MsiCloseHandle(view);
2174 MsiCloseHandle(hdb);
2175 DeleteFileA(msifile);
2178 static const CHAR bin_import_dat[] = "Name\tData\r\n"
2181 "filename1\tfilename1.ibd\r\n";
2183 static void test_binary_import(void)
2185 MSIHANDLE hdb = 0, rec;
2186 char file[MAX_PATH];
2188 char path[MAX_PATH];
2193 /* create files to import */
2194 write_file("bin_import.idt", bin_import_dat,
2195 (sizeof(bin_import_dat) - 1) * sizeof(char));
2196 CreateDirectory("bin_import", NULL);
2197 create_file_data("bin_import/filename1.ibd", "just some words", 15);
2199 /* import files into database */
2200 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
2201 ok( r == ERROR_SUCCESS , "Failed to open database\n");
2203 GetCurrentDirectory(MAX_PATH, path);
2204 r = MsiDatabaseImport(hdb, path, "bin_import.idt");
2205 ok(r == ERROR_SUCCESS , "Failed to import Binary table\n");
2207 /* read file from the Binary table */
2208 query = "SELECT * FROM `Binary`";
2209 r = do_query(hdb, query, &rec);
2210 ok(r == ERROR_SUCCESS, "SELECT query failed: %d\n", r);
2213 r = MsiRecordGetString(rec, 1, file, &size);
2214 ok(r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
2215 ok(!lstrcmp(file, "filename1"), "Expected 'filename1', got %s\n", file);
2218 memset(buf, 0, MAX_PATH);
2219 r = MsiRecordReadStream(rec, 2, buf, &size);
2220 ok(r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
2221 ok(!lstrcmp(buf, "just some words"),
2222 "Expected 'just some words', got %s\n", buf);
2224 r = MsiCloseHandle(rec);
2225 ok(r == ERROR_SUCCESS , "Failed to close record handle\n");
2227 r = MsiCloseHandle(hdb);
2228 ok(r == ERROR_SUCCESS , "Failed to close database\n");
2230 DeleteFile("bin_import/filename1.ibd");
2231 RemoveDirectory("bin_import");
2232 DeleteFile("bin_import.idt");
2235 static void test_markers(void)
2242 ok( hdb, "failed to create db\n");
2244 rec = MsiCreateRecord(3);
2245 MsiRecordSetString(rec, 1, "Table");
2246 MsiRecordSetString(rec, 2, "Apples");
2247 MsiRecordSetString(rec, 3, "Oranges");
2249 /* try a legit create */
2250 query = "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2251 r = run_query(hdb, 0, query);
2252 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2253 MsiCloseHandle(rec);
2255 /* try table name as marker */
2256 rec = MsiCreateRecord(1);
2257 MsiRecordSetString(rec, 1, "Fable");
2258 query = "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2259 r = run_query(hdb, rec, query);
2260 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2262 /* verify that we just created a table called '?', not 'Fable' */
2263 r = try_query(hdb, "SELECT * from `Fable`");
2264 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2266 r = try_query(hdb, "SELECT * from `?`");
2267 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2269 /* try table name as marker without backticks */
2270 MsiRecordSetString(rec, 1, "Mable");
2271 query = "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2272 r = run_query(hdb, rec, query);
2273 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2275 /* try one column name as marker */
2276 MsiRecordSetString(rec, 1, "One");
2277 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2278 r = run_query(hdb, rec, query);
2279 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2280 MsiCloseHandle(rec);
2282 /* try column names as markers */
2283 rec = MsiCreateRecord(2);
2284 MsiRecordSetString(rec, 1, "One");
2285 MsiRecordSetString(rec, 2, "Two");
2286 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
2287 r = run_query(hdb, rec, query);
2288 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2289 MsiCloseHandle(rec);
2291 /* try names with backticks */
2292 rec = MsiCreateRecord(3);
2293 MsiRecordSetString(rec, 1, "One");
2294 MsiRecordSetString(rec, 2, "Two");
2295 MsiRecordSetString(rec, 3, "One");
2296 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
2297 r = run_query(hdb, rec, query);
2298 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2300 /* try names with backticks, minus definitions */
2301 query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
2302 r = run_query(hdb, rec, query);
2303 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2305 /* try names without backticks */
2306 query = "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
2307 r = run_query(hdb, rec, query);
2308 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2309 MsiCloseHandle(rec);
2311 /* try one long marker */
2312 rec = MsiCreateRecord(1);
2313 MsiRecordSetString(rec, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
2314 query = "CREATE TABLE `Mable` ( ? )";
2315 r = run_query(hdb, rec, query);
2316 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2317 MsiCloseHandle(rec);
2319 /* try all names as markers */
2320 rec = MsiCreateRecord(4);
2321 MsiRecordSetString(rec, 1, "Mable");
2322 MsiRecordSetString(rec, 2, "One");
2323 MsiRecordSetString(rec, 3, "Two");
2324 MsiRecordSetString(rec, 4, "One");
2325 query = "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
2326 r = run_query(hdb, rec, query);
2327 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2328 MsiCloseHandle(rec);
2330 /* try a legit insert */
2331 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
2332 r = run_query(hdb, 0, query);
2333 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2335 r = try_query(hdb, "SELECT * from `Table`");
2336 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2338 /* try values as markers */
2339 rec = MsiCreateRecord(2);
2340 MsiRecordSetInteger(rec, 1, 4);
2341 MsiRecordSetString(rec, 2, "hi");
2342 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2343 r = run_query(hdb, rec, query);
2344 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2345 MsiCloseHandle(rec);
2347 /* try column names and values as markers */
2348 rec = MsiCreateRecord(4);
2349 MsiRecordSetString(rec, 1, "One");
2350 MsiRecordSetString(rec, 2, "Two");
2351 MsiRecordSetInteger(rec, 3, 5);
2352 MsiRecordSetString(rec, 4, "hi");
2353 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
2354 r = run_query(hdb, rec, query);
2355 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2356 MsiCloseHandle(rec);
2358 /* try column names as markers */
2359 rec = MsiCreateRecord(2);
2360 MsiRecordSetString(rec, 1, "One");
2361 MsiRecordSetString(rec, 2, "Two");
2362 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
2363 r = run_query(hdb, rec, query);
2364 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2365 MsiCloseHandle(rec);
2367 /* try table name as a marker */
2368 rec = MsiCreateRecord(1);
2369 MsiRecordSetString(rec, 1, "Table");
2370 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
2371 r = run_query(hdb, rec, query);
2372 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2373 MsiCloseHandle(rec);
2375 /* try table name and values as markers */
2376 rec = MsiCreateRecord(3);
2377 MsiRecordSetString(rec, 1, "Table");
2378 MsiRecordSetInteger(rec, 2, 10);
2379 MsiRecordSetString(rec, 3, "haha");
2380 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
2381 r = run_query(hdb, rec, query);
2382 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
2383 MsiCloseHandle(rec);
2385 /* try all markers */
2386 rec = MsiCreateRecord(5);
2387 MsiRecordSetString(rec, 1, "Table");
2388 MsiRecordSetString(rec, 1, "One");
2389 MsiRecordSetString(rec, 1, "Two");
2390 MsiRecordSetInteger(rec, 2, 10);
2391 MsiRecordSetString(rec, 3, "haha");
2392 query = "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
2393 r = run_query(hdb, rec, query);
2394 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2395 MsiCloseHandle(rec);
2397 /* insert an integer as a string */
2398 rec = MsiCreateRecord(2);
2399 MsiRecordSetString(rec, 1, "11");
2400 MsiRecordSetString(rec, 2, "hi");
2401 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2402 r = run_query(hdb, rec, query);
2403 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2404 MsiCloseHandle(rec);
2406 /* leave off the '' for the string */
2407 rec = MsiCreateRecord(2);
2408 MsiRecordSetInteger(rec, 1, 12);
2409 MsiRecordSetString(rec, 2, "hi");
2410 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
2411 r = run_query(hdb, rec, query);
2412 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2413 MsiCloseHandle(rec);
2415 MsiCloseHandle(hdb);
2416 DeleteFileA(msifile);
2419 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
2420 static void test_handle_limit(void)
2424 MSIHANDLE hviews[MY_NVIEWS];
2427 /* create an empty db */
2429 ok( hdb, "failed to create db\n");
2431 memset(hviews, 0, sizeof(hviews));
2433 for (i=0; i<MY_NVIEWS; i++) {
2434 static char szQueryBuf[256] = "SELECT * from `_Tables`";
2435 hviews[i] = 0xdeadbeeb;
2436 r = MsiDatabaseOpenView(hdb, szQueryBuf, &hviews[i]);
2437 if( r != ERROR_SUCCESS || hviews[i] == 0xdeadbeeb ||
2438 hviews[i] == 0 || (i && (hviews[i] == hviews[i-1])))
2442 ok( i == MY_NVIEWS, "problem opening views\n");
2444 for (i=0; i<MY_NVIEWS; i++) {
2445 if (hviews[i] != 0 && hviews[i] != 0xdeadbeeb) {
2446 MsiViewClose(hviews[i]);
2447 r = MsiCloseHandle(hviews[i]);
2448 if (r != ERROR_SUCCESS)
2453 ok( i == MY_NVIEWS, "problem closing views\n");
2455 r = MsiCloseHandle(hdb);
2456 ok( r == ERROR_SUCCESS, "failed to close database\n");
2459 static void generate_transform(void)
2461 MSIHANDLE hdb1, hdb2, hrec;
2465 /* start with two identical databases */
2466 CopyFile(msifile2, msifile, FALSE);
2468 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb1 );
2469 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2471 r = MsiDatabaseCommit( hdb1 );
2472 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
2474 r = MsiOpenDatabase(msifile2, MSIDBOPEN_READONLY, &hdb2 );
2475 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2477 /* the transform between two identical database should be empty */
2478 r = MsiDatabaseGenerateTransform(hdb1, hdb2, NULL, 0, 0);
2480 ok( r == ERROR_NO_DATA, "return code %d, should be ERROR_NO_DATA\n", r );
2483 query = "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
2484 r = run_query(hdb1, 0, query);
2485 ok(r == ERROR_SUCCESS, "failed to add table\n");
2487 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
2488 r = run_query(hdb1, 0, query);
2489 ok(r == ERROR_SUCCESS, "failed to add row 1\n");
2491 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
2492 r = run_query(hdb1, 0, query);
2493 ok(r == ERROR_SUCCESS, "failed to add row 2\n");
2495 query = "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
2496 r = run_query(hdb1, 0, query);
2497 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2499 query = "DELETE FROM `MOO` WHERE `NOO` = 3";
2500 r = run_query(hdb1, 0, query);
2501 ok(r == ERROR_SUCCESS, "failed to delete row\n");
2503 hrec = MsiCreateRecord(2);
2504 r = MsiRecordSetInteger(hrec, 1, 1);
2505 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2507 write_file("testdata.bin", "naengmyon", 9);
2508 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2509 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2511 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2512 r = run_query(hdb1, hrec, query);
2513 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2515 MsiCloseHandle(hrec);
2517 query = "ALTER TABLE `MOO` ADD `COW` INTEGER";
2518 r = run_query(hdb1, 0, query);
2519 ok(r == ERROR_SUCCESS, "failed to add column\n");
2521 query = "ALTER TABLE `MOO` ADD `PIG` INTEGER";
2522 r = run_query(hdb1, 0, query);
2523 ok(r == ERROR_SUCCESS, "failed to add column\n");
2525 query = "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
2526 r = run_query(hdb1, 0, query);
2527 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2529 query = "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
2530 "`Value` CHAR(0) PRIMARY KEY `Property`)";
2531 r = run_query(hdb1, 0, query);
2532 ok(r == ERROR_SUCCESS, "failed to add property table\n");
2534 query = "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2535 r = run_query(hdb1, 0, query);
2536 ok(r == ERROR_SUCCESS, "failed to add property\n");
2538 /* database needs to be committed */
2539 MsiDatabaseCommit(hdb1);
2541 r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
2542 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
2544 MsiCloseHandle( hdb1 );
2545 MsiCloseHandle( hdb2 );
2547 DeleteFile("testdata.bin");
2550 /* data for generating a transform */
2552 /* tables transform names - encoded as they would be in an msi database file */
2553 static const WCHAR name1[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
2554 static const WCHAR name2[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
2555 static const WCHAR name3[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
2556 static const WCHAR name4[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2557 static const WCHAR name5[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2558 static const WCHAR name6[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
2559 static const WCHAR name7[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
2560 static const WCHAR name8[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
2561 static const WCHAR name9[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2563 /* data in each table */
2564 static const WCHAR data1[] = { /* AAR */
2565 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
2566 0x0201, 0x0009, 0x8002,
2568 static const WCHAR data2[] = { /* _Columns */
2569 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
2570 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
2571 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
2572 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
2573 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
2574 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
2576 static const WCHAR data3[] = { /* _Tables */
2577 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
2580 static const char data4[] = /* _StringData */
2581 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
2582 static const WCHAR data5[] = { /* _StringPool */
2584 0, 0, /* string 0 '' */
2585 3, 2, /* string 1 'MOO' */
2586 3, 1, /* string 2 'COW' */
2587 3, 1, /* string 3 'PIG' */
2588 1, 1, /* string 4 'c' */
2589 3, 3, /* string 5 'AAR' */
2590 3, 1, /* string 6 'CAR' */
2591 3, 1, /* string 7 'BAR' */
2592 2, 1, /* string 8 'vw' */
2593 3, 1, /* string 9 'bmw' */
2594 8, 4, /* string 10 'Property' */
2595 5, 1, /* string 11 'Value' */
2596 4, 1, /* string 12 'prop' */
2597 3, 1, /* string 13 'val' */
2599 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
2600 static const WCHAR data6[] = { /* MOO */
2601 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
2602 0x0000, 0x8003, /* delete row */
2605 static const WCHAR data7[] = { /* BINARY */
2606 0x0201, 0x8001, 0x0001,
2609 static const char data8[] = /* stream data for the BINARY table */
2612 static const WCHAR data9[] = { /* Property */
2613 0x0201, 0x000c, 0x000d,
2616 static const struct {
2620 } table_transform_data[] =
2622 { name1, data1, sizeof data1 },
2623 { name2, data2, sizeof data2 },
2624 { name3, data3, sizeof data3 },
2625 { name4, data4, sizeof data4 - 1 },
2626 { name5, data5, sizeof data5 },
2627 { name6, data6, sizeof data6 },
2628 { name7, data7, sizeof data7 },
2629 { name8, data8, sizeof data8 - 1 },
2630 { name9, data9, sizeof data9 },
2633 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2635 static void generate_transform_manual(void)
2637 IStorage *stg = NULL;
2642 const DWORD mode = STGM_CREATE|STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE;
2644 const CLSID CLSID_MsiTransform = { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2646 MultiByteToWideChar(CP_ACP, 0, mstfile, -1, name, 0x20);
2648 r = StgCreateDocfile(name, mode, 0, &stg);
2649 ok(r == S_OK, "failed to create storage\n");
2653 r = IStorage_SetClass( stg, &CLSID_MsiTransform );
2654 ok(r == S_OK, "failed to set storage type\n");
2656 for (i=0; i<NUM_TRANSFORM_TABLES; i++)
2658 r = IStorage_CreateStream( stg, table_transform_data[i].name,
2659 STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm );
2662 ok(0, "failed to create stream %08x\n", r);
2666 r = IStream_Write( stm, table_transform_data[i].data,
2667 table_transform_data[i].size, &count );
2668 if (FAILED(r) || count != table_transform_data[i].size)
2669 ok(0, "failed to write stream\n");
2670 IStream_Release(stm);
2673 IStorage_Release(stg);
2676 static UINT set_summary_info(MSIHANDLE hdb)
2681 /* build summary info */
2682 res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
2683 ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );
2685 res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
2686 "Installation Database");
2687 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2689 res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
2690 "Installation Database");
2691 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2693 res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
2695 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2697 res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
2699 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2701 res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
2702 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2703 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2705 res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
2706 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2708 res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
2709 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2711 res = MsiSummaryInfoPersist(suminfo);
2712 ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );
2714 res = MsiCloseHandle( suminfo);
2715 ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );
2720 static MSIHANDLE create_package_db(LPCSTR filename)
2725 DeleteFile(msifile);
2727 /* create an empty database */
2728 res = MsiOpenDatabase(filename, MSIDBOPEN_CREATE, &hdb );
2729 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
2730 if( res != ERROR_SUCCESS )
2733 res = MsiDatabaseCommit( hdb );
2734 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
2736 res = set_summary_info(hdb);
2738 res = create_directory_table(hdb);
2739 ok( res == ERROR_SUCCESS , "Failed to create directory table\n" );
2744 static MSIHANDLE package_from_db(MSIHANDLE hdb)
2750 sprintf(szPackage,"#%i",hdb);
2751 res = MsiOpenPackage(szPackage,&hPackage);
2752 if (res != ERROR_SUCCESS)
2755 res = MsiCloseHandle(hdb);
2756 if (res != ERROR_SUCCESS)
2762 static void test_try_transform(void)
2764 MSIHANDLE hdb, hview, hrec, hpkg;
2768 char buffer[MAX_PATH];
2770 DeleteFile(msifile);
2771 DeleteFile(mstfile);
2773 /* create the database */
2774 hdb = create_package_db(msifile);
2775 ok(hdb, "Failed to create package db\n");
2777 query = "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
2778 r = run_query(hdb, 0, query);
2779 ok(r == ERROR_SUCCESS, "failed to add table\n");
2781 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
2782 r = run_query(hdb, 0, query);
2783 ok(r == ERROR_SUCCESS, "failed to add row\n");
2785 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
2786 r = run_query(hdb, 0, query);
2787 ok(r == ERROR_SUCCESS, "failed to add row\n");
2789 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
2790 r = run_query(hdb, 0, query);
2791 ok(r == ERROR_SUCCESS, "failed to add row\n");
2793 query = "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
2794 r = run_query(hdb, 0, query);
2795 ok(r == ERROR_SUCCESS, "failed to add table\n");
2797 hrec = MsiCreateRecord(2);
2798 r = MsiRecordSetInteger(hrec, 1, 2);
2799 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2801 write_file("testdata.bin", "lamyon", 6);
2802 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2803 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2805 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2806 r = run_query(hdb, hrec, query);
2807 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2809 MsiCloseHandle(hrec);
2811 r = MsiDatabaseCommit( hdb );
2812 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
2814 MsiCloseHandle( hdb );
2815 DeleteFileA("testdata.bin");
2818 * Both these generate an equivalent transform,
2819 * but the first doesn't work in Wine yet
2820 * because MsiDatabaseGenerateTransform is unimplemented.
2823 generate_transform();
2825 generate_transform_manual();
2827 r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb );
2828 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2830 r = MsiDatabaseApplyTransform( hdb, mstfile, 0 );
2831 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
2833 MsiDatabaseCommit( hdb );
2835 /* check new values */
2837 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
2838 r = do_query(hdb, query, &hrec);
2839 ok(r == ERROR_SUCCESS, "select query failed\n");
2840 MsiCloseHandle(hrec);
2842 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
2844 r = do_query(hdb, query, &hrec);
2845 ok(r == ERROR_SUCCESS, "select query failed\n");
2846 MsiCloseHandle(hrec);
2848 /* check updated values */
2850 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
2851 r = do_query(hdb, query, &hrec);
2852 ok(r == ERROR_SUCCESS, "select query failed\n");
2853 MsiCloseHandle(hrec);
2855 /* check unchanged value */
2857 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
2858 r = do_query(hdb, query, &hrec);
2859 ok(r == ERROR_SUCCESS, "select query failed\n");
2860 MsiCloseHandle(hrec);
2862 /* check deleted value */
2864 query = "select * from `MOO` where `NOO` = 3";
2865 r = do_query(hdb, query, &hrec);
2866 ok(r == ERROR_NO_MORE_ITEMS, "select query failed\n");
2867 if (hrec) MsiCloseHandle(hrec);
2869 /* check added stream */
2871 query = "select `BLOB` from `BINARY` where `ID` = 1";
2872 r = do_query(hdb, query, &hrec);
2873 ok(r == ERROR_SUCCESS, "select query failed\n");
2875 /* check the contents of the stream */
2877 r = MsiRecordReadStream( hrec, 1, buffer, &sz );
2878 ok(r == ERROR_SUCCESS, "read stream failed\n");
2879 ok(!memcmp(buffer, "naengmyon", 9), "stream data was wrong\n");
2880 ok(sz == 9, "stream data was wrong size\n");
2881 if (hrec) MsiCloseHandle(hrec);
2883 /* check the validity of the table with a deleted row */
2885 query = "select * from `MOO`";
2886 r = MsiDatabaseOpenView(hdb, query, &hview);
2887 ok(r == ERROR_SUCCESS, "open view failed\n");
2889 r = MsiViewExecute(hview, 0);
2890 ok(r == ERROR_SUCCESS, "view execute failed\n");
2892 r = MsiViewFetch(hview, &hrec);
2893 ok(r == ERROR_SUCCESS, "view fetch failed\n");
2895 r = MsiRecordGetInteger(hrec, 1);
2896 ok(r == 1, "Expected 1, got %d\n", r);
2899 r = MsiRecordGetString(hrec, 2, buffer, &sz);
2900 ok(r == ERROR_SUCCESS, "record get string failed\n");
2901 ok(!lstrcmpA(buffer, "c"), "Expected c, got %s\n", buffer);
2903 r = MsiRecordGetInteger(hrec, 3);
2904 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2906 r = MsiRecordGetInteger(hrec, 4);
2907 ok(r == 5, "Expected 5, got %d\n", r);
2909 MsiCloseHandle(hrec);
2911 r = MsiViewFetch(hview, &hrec);
2912 ok(r == ERROR_SUCCESS, "view fetch failed\n");
2914 r = MsiRecordGetInteger(hrec, 1);
2915 ok(r == 2, "Expected 2, got %d\n", r);
2918 r = MsiRecordGetString(hrec, 2, buffer, &sz);
2919 ok(r == ERROR_SUCCESS, "record get string failed\n");
2920 ok(!lstrcmpA(buffer, "b"), "Expected b, got %s\n", buffer);
2922 r = MsiRecordGetInteger(hrec, 3);
2923 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2925 r = MsiRecordGetInteger(hrec, 4);
2926 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2928 MsiCloseHandle(hrec);
2930 r = MsiViewFetch(hview, &hrec);
2931 ok(r == ERROR_NO_MORE_ITEMS, "view fetch succeeded\n");
2933 MsiCloseHandle(hrec);
2934 MsiViewClose(hview);
2935 MsiCloseHandle(hview);
2937 /* check that the property was added */
2938 hpkg = package_from_db(hdb);
2939 ok(hpkg != 0, "Expected non-NULL hpkg\n");
2942 r = MsiGetProperty(hpkg, "prop", buffer, &sz);
2943 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2944 ok(!lstrcmp(buffer, "val"), "Expected val, got %s\n", buffer);
2946 MsiCloseHandle(hpkg);
2947 MsiCloseHandle(hdb);
2949 DeleteFile(msifile);
2950 DeleteFile(mstfile);
2955 const CHAR one[MAX_PATH];
2956 const CHAR two[MAX_PATH];
2959 struct join_res_4col
2961 const CHAR one[MAX_PATH];
2962 const CHAR two[MAX_PATH];
2963 const CHAR three[MAX_PATH];
2964 const CHAR four[MAX_PATH];
2967 struct join_res_uint
2977 static const struct join_res join_res_first[] =
2979 { "alveolar", "procerus" },
2980 { "septum", "procerus" },
2981 { "septum", "nasalis" },
2982 { "ramus", "nasalis" },
2983 { "malar", "mentalis" },
2986 static const struct join_res join_res_second[] =
2988 { "nasal", "septum" },
2989 { "mandible", "ramus" },
2992 static const struct join_res join_res_third[] =
2994 { "msvcp.dll", "abcdefgh" },
2995 { "msvcr.dll", "ijklmnop" },
2998 static const struct join_res join_res_fourth[] =
3000 { "msvcp.dll.01234", "single.dll.31415" },
3003 static const struct join_res join_res_fifth[] =
3005 { "malar", "procerus" },
3008 static const struct join_res join_res_sixth[] =
3010 { "malar", "procerus" },
3011 { "malar", "procerus" },
3012 { "malar", "nasalis" },
3013 { "malar", "nasalis" },
3014 { "malar", "nasalis" },
3015 { "malar", "mentalis" },
3018 static const struct join_res join_res_seventh[] =
3020 { "malar", "nasalis" },
3021 { "malar", "nasalis" },
3022 { "malar", "nasalis" },
3025 static const struct join_res_4col join_res_eighth[] =
3027 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
3028 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
3029 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
3030 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
3031 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
3032 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
3035 static const struct join_res_uint join_res_ninth[] =
3037 { 1, 2, 3, 4, 7, 8 },
3038 { 1, 2, 5, 6, 7, 8 },
3039 { 1, 2, 3, 4, 9, 10 },
3040 { 1, 2, 5, 6, 9, 10 },
3041 { 1, 2, 3, 4, 11, 12 },
3042 { 1, 2, 5, 6, 11, 12 },
3045 static void test_join(void)
3047 MSIHANDLE hdb, hview, hrec;
3055 ok( hdb, "failed to create db\n");
3057 r = create_component_table( hdb );
3058 ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
3060 r = add_component_entry( hdb, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
3061 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3063 r = add_component_entry( hdb, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
3064 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3066 r = add_component_entry( hdb, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
3067 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3069 r = add_component_entry( hdb, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
3070 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3072 r = create_feature_components_table( hdb );
3073 ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
3075 r = add_feature_components_entry( hdb, "'procerus', 'maxilla'" );
3076 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3078 r = add_feature_components_entry( hdb, "'procerus', 'nasal'" );
3079 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3081 r = add_feature_components_entry( hdb, "'nasalis', 'nasal'" );
3082 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3084 r = add_feature_components_entry( hdb, "'nasalis', 'mandible'" );
3085 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3087 r = add_feature_components_entry( hdb, "'nasalis', 'notacomponent'" );
3088 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3090 r = add_feature_components_entry( hdb, "'mentalis', 'zygomatic'" );
3091 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3093 r = create_std_dlls_table( hdb );
3094 ok( r == ERROR_SUCCESS, "cannot create StdDlls table: %d\n", r );
3096 r = add_std_dlls_entry( hdb, "'msvcp.dll', 'msvcp.dll.01234'" );
3097 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
3099 r = add_std_dlls_entry( hdb, "'msvcr.dll', 'msvcr.dll.56789'" );
3100 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
3102 r = create_binary_table( hdb );
3103 ok( r == ERROR_SUCCESS, "cannot create Binary table: %d\n", r );
3105 r = add_binary_entry( hdb, "'msvcp.dll.01234', 'abcdefgh'" );
3106 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
3108 r = add_binary_entry( hdb, "'msvcr.dll.56789', 'ijklmnop'" );
3109 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
3111 r = add_binary_entry( hdb, "'single.dll.31415', 'msvcp.dll'" );
3112 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
3114 query = "CREATE TABLE `One` (`A` SHORT, `B` SHORT PRIMARY KEY `A`)";
3115 r = run_query( hdb, 0, query);
3116 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3118 query = "CREATE TABLE `Two` (`C` SHORT, `D` SHORT PRIMARY KEY `C`)";
3119 r = run_query( hdb, 0, query);
3120 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3122 query = "CREATE TABLE `Three` (`E` SHORT, `F` SHORT PRIMARY KEY `E`)";
3123 r = run_query( hdb, 0, query);
3124 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3126 query = "INSERT INTO `One` (`A`, `B`) VALUES (1, 2)";
3127 r = run_query( hdb, 0, query);
3128 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3130 query = "INSERT INTO `Two` (`C`, `D`) VALUES (3, 4)";
3131 r = run_query( hdb, 0, query);
3132 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3134 query = "INSERT INTO `Two` (`C`, `D`) VALUES (5, 6)";
3135 r = run_query( hdb, 0, query);
3136 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3138 query = "INSERT INTO `Three` (`E`, `F`) VALUES (7, 8)";
3139 r = run_query( hdb, 0, query);
3140 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3142 query = "INSERT INTO `Three` (`E`, `F`) VALUES (9, 10)";
3143 r = run_query( hdb, 0, query);
3144 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3146 query = "INSERT INTO `Three` (`E`, `F`) VALUES (11, 12)";
3147 r = run_query( hdb, 0, query);
3148 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3150 query = "CREATE TABLE `Four` (`G` SHORT, `H` SHORT PRIMARY KEY `G`)";
3151 r = run_query( hdb, 0, query);
3152 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3154 query = "CREATE TABLE `Five` (`I` SHORT, `J` SHORT PRIMARY KEY `I`)";
3155 r = run_query( hdb, 0, query);
3156 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3158 query = "INSERT INTO `Five` (`I`, `J`) VALUES (13, 14)";
3159 r = run_query( hdb, 0, query);
3160 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3162 query = "INSERT INTO `Five` (`I`, `J`) VALUES (15, 16)";
3163 r = run_query( hdb, 0, query);
3164 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3166 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3167 "FROM `Component`, `FeatureComponents` "
3168 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
3169 "ORDER BY `Feature_`";
3170 r = MsiDatabaseOpenView(hdb, query, &hview);
3171 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3173 r = MsiViewExecute(hview, 0);
3174 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3177 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3179 count = MsiRecordGetFieldCount( hrec );
3180 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3183 r = MsiRecordGetString( hrec, 1, buf, &size );
3184 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3185 ok( !lstrcmp( buf, join_res_first[i].one ),
3186 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_first[i].one, buf );
3189 r = MsiRecordGetString( hrec, 2, buf, &size );
3190 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3191 ok( !lstrcmp( buf, join_res_first[i].two ),
3192 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_first[i].two, buf );
3195 MsiCloseHandle(hrec);
3198 ok( i == 5, "Expected 5 rows, got %d\n", i );
3199 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3201 MsiViewClose(hview);
3202 MsiCloseHandle(hview);
3204 /* try a join without a WHERE condition */
3205 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3206 "FROM `Component`, `FeatureComponents` ";
3207 r = MsiDatabaseOpenView(hdb, query, &hview);
3208 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3210 r = MsiViewExecute(hview, 0);
3211 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3214 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3217 MsiCloseHandle(hrec);
3219 ok( i == 24, "Expected 24 rows, got %d\n", i );
3221 MsiViewClose(hview);
3222 MsiCloseHandle(hview);
3224 query = "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
3225 "WHERE FeatureComponents.Component_=Component.Component "
3226 "AND (Feature_='nasalis') ORDER BY Feature_";
3227 r = MsiDatabaseOpenView(hdb, query, &hview);
3228 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3230 r = MsiViewExecute(hview, 0);
3231 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3234 data_correct = TRUE;
3235 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3237 count = MsiRecordGetFieldCount( hrec );
3238 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3241 r = MsiRecordGetString( hrec, 1, buf, &size );
3242 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3243 if( lstrcmp( buf, join_res_second[i].one ))
3244 data_correct = FALSE;
3247 r = MsiRecordGetString( hrec, 2, buf, &size );
3248 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3249 if( lstrcmp( buf, join_res_second[i].two ))
3250 data_correct = FALSE;
3253 MsiCloseHandle(hrec);
3256 ok( data_correct, "data returned in the wrong order\n");
3258 ok( i == 2, "Expected 2 rows, got %d\n", i );
3259 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3261 MsiViewClose(hview);
3262 MsiCloseHandle(hview);
3264 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3265 "FROM `StdDlls`, `Binary` "
3266 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
3268 r = MsiDatabaseOpenView(hdb, query, &hview);
3269 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3271 r = MsiViewExecute(hview, 0);
3272 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3275 data_correct = TRUE;
3276 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3278 count = MsiRecordGetFieldCount( hrec );
3279 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3282 r = MsiRecordGetString( hrec, 1, buf, &size );
3283 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3284 if( lstrcmp( buf, join_res_third[i].one ) )
3285 data_correct = FALSE;
3288 r = MsiRecordGetString( hrec, 2, buf, &size );
3289 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3290 if( lstrcmp( buf, join_res_third[i].two ) )
3291 data_correct = FALSE;
3294 MsiCloseHandle(hrec);
3296 ok( data_correct, "data returned in the wrong order\n");
3298 ok( i == 2, "Expected 2 rows, got %d\n", i );
3300 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3302 MsiViewClose(hview);
3303 MsiCloseHandle(hview);
3305 query = "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
3306 "FROM `StdDlls`, `Binary` "
3307 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
3309 r = MsiDatabaseOpenView(hdb, query, &hview);
3310 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3312 r = MsiViewExecute(hview, 0);
3313 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3316 data_correct = TRUE;
3317 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3319 count = MsiRecordGetFieldCount( hrec );
3320 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3323 r = MsiRecordGetString( hrec, 1, buf, &size );
3324 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3325 if( lstrcmp( buf, join_res_fourth[i].one ))
3326 data_correct = FALSE;
3329 r = MsiRecordGetString( hrec, 2, buf, &size );
3330 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3331 if( lstrcmp( buf, join_res_fourth[i].two ))
3332 data_correct = FALSE;
3335 MsiCloseHandle(hrec);
3337 ok( data_correct, "data returned in the wrong order\n");
3339 ok( i == 1, "Expected 1 rows, got %d\n", i );
3340 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3342 MsiViewClose(hview);
3343 MsiCloseHandle(hview);
3345 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3346 "FROM `Component`, `FeatureComponents` "
3347 "WHERE `Component`.`Component` = 'zygomatic' "
3348 "AND `FeatureComponents`.`Component_` = 'maxilla' "
3349 "ORDER BY `Feature_`";
3350 r = MsiDatabaseOpenView(hdb, query, &hview);
3351 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3353 r = MsiViewExecute(hview, 0);
3354 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3357 data_correct = TRUE;
3358 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3360 count = MsiRecordGetFieldCount( hrec );
3361 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3364 r = MsiRecordGetString( hrec, 1, buf, &size );
3365 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3366 if( lstrcmp( buf, join_res_fifth[i].one ))
3367 data_correct = FALSE;
3370 r = MsiRecordGetString( hrec, 2, buf, &size );
3371 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3372 if( lstrcmp( buf, join_res_fifth[i].two ))
3373 data_correct = FALSE;
3376 MsiCloseHandle(hrec);
3378 ok( data_correct, "data returned in the wrong order\n");
3380 ok( i == 1, "Expected 1 rows, got %d\n", i );
3381 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3383 MsiViewClose(hview);
3384 MsiCloseHandle(hview);
3386 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3387 "FROM `Component`, `FeatureComponents` "
3388 "WHERE `Component` = 'zygomatic' "
3389 "ORDER BY `Feature_`";
3390 r = MsiDatabaseOpenView(hdb, query, &hview);
3391 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3393 r = MsiViewExecute(hview, 0);
3394 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3397 data_correct = TRUE;
3398 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3400 count = MsiRecordGetFieldCount( hrec );
3401 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3404 r = MsiRecordGetString( hrec, 1, buf, &size );
3405 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3406 if( lstrcmp( buf, join_res_sixth[i].one ))
3407 data_correct = FALSE;
3410 r = MsiRecordGetString( hrec, 2, buf, &size );
3411 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3412 if( lstrcmp( buf, join_res_sixth[i].two ))
3413 data_correct = FALSE;
3416 MsiCloseHandle(hrec);
3418 ok( data_correct, "data returned in the wrong order\n");
3420 ok( i == 6, "Expected 6 rows, got %d\n", i );
3421 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3423 MsiViewClose(hview);
3424 MsiCloseHandle(hview);
3426 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3427 "FROM `Component`, `FeatureComponents` "
3428 "WHERE `Component` = 'zygomatic' "
3429 "AND `Feature_` = 'nasalis' "
3430 "ORDER BY `Feature_`";
3431 r = MsiDatabaseOpenView(hdb, query, &hview);
3432 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3434 r = MsiViewExecute(hview, 0);
3435 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3438 data_correct = TRUE;
3439 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3441 count = MsiRecordGetFieldCount( hrec );
3442 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3445 r = MsiRecordGetString( hrec, 1, buf, &size );
3446 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3447 if( lstrcmp( buf, join_res_seventh[i].one ))
3448 data_correct = FALSE;
3451 r = MsiRecordGetString( hrec, 2, buf, &size );
3452 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3453 if( lstrcmp( buf, join_res_seventh[i].two ))
3454 data_correct = FALSE;
3457 MsiCloseHandle(hrec);
3460 ok( data_correct, "data returned in the wrong order\n");
3461 ok( i == 3, "Expected 3 rows, got %d\n", i );
3462 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3464 MsiViewClose(hview);
3465 MsiCloseHandle(hview);
3467 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3468 "FROM `StdDlls`, `Binary` ";
3469 r = MsiDatabaseOpenView(hdb, query, &hview);
3470 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3472 r = MsiViewExecute(hview, 0);
3473 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3476 data_correct = TRUE;
3477 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3479 count = MsiRecordGetFieldCount( hrec );
3480 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3483 r = MsiRecordGetString( hrec, 1, buf, &size );
3484 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3485 if( lstrcmp( buf, join_res_eighth[i].one ))
3486 data_correct = FALSE;
3489 r = MsiRecordGetString( hrec, 2, buf, &size );
3490 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3491 if( lstrcmp( buf, join_res_eighth[i].four ))
3492 data_correct = FALSE;
3495 MsiCloseHandle(hrec);
3498 ok( data_correct, "data returned in the wrong order\n");
3499 ok( i == 6, "Expected 6 rows, got %d\n", i );
3500 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3502 MsiViewClose(hview);
3503 MsiCloseHandle(hview);
3505 query = "SELECT * FROM `StdDlls`, `Binary` ";
3506 r = MsiDatabaseOpenView(hdb, query, &hview);
3507 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3509 r = MsiViewExecute(hview, 0);
3510 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3513 data_correct = TRUE;
3514 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3516 count = MsiRecordGetFieldCount( hrec );
3517 ok( count == 4, "Expected 4 record fields, got %d\n", count );
3520 r = MsiRecordGetString( hrec, 1, buf, &size );
3521 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3522 if( lstrcmp( buf, join_res_eighth[i].one ))
3523 data_correct = FALSE;
3526 r = MsiRecordGetString( hrec, 2, buf, &size );
3527 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3528 if( lstrcmp( buf, join_res_eighth[i].two ))
3529 data_correct = FALSE;
3532 r = MsiRecordGetString( hrec, 3, buf, &size );
3533 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3534 if( lstrcmp( buf, join_res_eighth[i].three ))
3535 data_correct = FALSE;
3538 r = MsiRecordGetString( hrec, 4, buf, &size );
3539 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3540 if( lstrcmp( buf, join_res_eighth[i].four ))
3541 data_correct = FALSE;
3544 MsiCloseHandle(hrec);
3546 ok( data_correct, "data returned in the wrong order\n");
3548 ok( i == 6, "Expected 6 rows, got %d\n", i );
3549 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3551 MsiViewClose(hview);
3552 MsiCloseHandle(hview);
3554 query = "SELECT * FROM `One`, `Two`, `Three` ";
3555 r = MsiDatabaseOpenView(hdb, query, &hview);
3556 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3558 r = MsiViewExecute(hview, 0);
3559 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3562 data_correct = TRUE;
3563 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3565 count = MsiRecordGetFieldCount( hrec );
3566 ok( count == 6, "Expected 6 record fields, got %d\n", count );
3568 r = MsiRecordGetInteger( hrec, 1 );
3569 if( r != join_res_ninth[i].one )
3570 data_correct = FALSE;
3572 r = MsiRecordGetInteger( hrec, 2 );
3573 if( r != join_res_ninth[i].two )
3574 data_correct = FALSE;
3576 r = MsiRecordGetInteger( hrec, 3 );
3577 if( r != join_res_ninth[i].three )
3578 data_correct = FALSE;
3580 r = MsiRecordGetInteger( hrec, 4 );
3581 if( r != join_res_ninth[i].four )
3582 data_correct = FALSE;
3584 r = MsiRecordGetInteger( hrec, 5 );
3585 if( r != join_res_ninth[i].five )
3586 data_correct = FALSE;
3588 r = MsiRecordGetInteger( hrec, 6);
3589 if( r != join_res_ninth[i].six )
3590 data_correct = FALSE;
3593 MsiCloseHandle(hrec);
3595 ok( data_correct, "data returned in the wrong order\n");
3597 ok( i == 6, "Expected 6 rows, got %d\n", i );
3598 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3600 MsiViewClose(hview);
3601 MsiCloseHandle(hview);
3603 query = "SELECT * FROM `Four`, `Five`";
3604 r = MsiDatabaseOpenView(hdb, query, &hview);
3605 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3607 r = MsiViewExecute(hview, 0);
3608 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3610 r = MsiViewFetch(hview, &hrec);
3611 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3613 MsiViewClose(hview);
3614 MsiCloseHandle(hview);
3616 query = "SELECT * FROM `Nonexistent`, `One`";
3617 r = MsiDatabaseOpenView(hdb, query, &hview);
3618 ok( r == ERROR_BAD_QUERY_SYNTAX,
3619 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r );
3621 MsiCloseHandle(hdb);
3622 DeleteFile(msifile);
3625 static void test_temporary_table(void)
3628 MSIHANDLE hdb = 0, view = 0, rec;
3634 cond = MsiDatabaseIsTablePersistent(0, NULL);
3635 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3638 ok( hdb, "failed to create db\n");
3640 cond = MsiDatabaseIsTablePersistent(hdb, NULL);
3641 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3643 cond = MsiDatabaseIsTablePersistent(hdb, "_Tables");
3644 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3646 cond = MsiDatabaseIsTablePersistent(hdb, "_Columns");
3647 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3649 cond = MsiDatabaseIsTablePersistent(hdb, "_Storages");
3650 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3652 cond = MsiDatabaseIsTablePersistent(hdb, "_Streams");
3653 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3655 query = "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
3656 r = run_query(hdb, 0, query);
3657 ok(r == ERROR_SUCCESS, "failed to add table\n");
3659 cond = MsiDatabaseIsTablePersistent(hdb, "P");
3660 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3662 query = "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
3663 r = run_query(hdb, 0, query);
3664 ok(r == ERROR_SUCCESS, "failed to add table\n");
3666 cond = MsiDatabaseIsTablePersistent(hdb, "P2");
3667 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3669 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3670 r = run_query(hdb, 0, query);
3671 ok(r == ERROR_SUCCESS, "failed to add table\n");
3673 cond = MsiDatabaseIsTablePersistent(hdb, "T");
3674 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
3676 query = "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3677 r = run_query(hdb, 0, query);
3678 ok(r == ERROR_SUCCESS, "failed to add table\n");
3680 query = "SELECT * FROM `T2`";
3681 r = MsiDatabaseOpenView(hdb, query, &view);
3682 ok(r == ERROR_BAD_QUERY_SYNTAX,
3683 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3685 cond = MsiDatabaseIsTablePersistent(hdb, "T2");
3686 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3688 query = "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
3689 r = run_query(hdb, 0, query);
3690 ok(r == ERROR_SUCCESS, "failed to add table\n");
3692 cond = MsiDatabaseIsTablePersistent(hdb, "T3");
3693 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3695 query = "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3696 r = run_query(hdb, 0, query);
3697 ok(r == ERROR_FUNCTION_FAILED, "failed to add table\n");
3699 cond = MsiDatabaseIsTablePersistent(hdb, "T4");
3700 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3702 query = "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
3703 r = run_query(hdb, 0, query);
3704 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add table\n");
3706 query = "select * from `T`";
3707 r = MsiDatabaseOpenView(hdb, query, &view);
3708 ok(r == ERROR_SUCCESS, "failed to query table\n");
3709 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
3710 ok(r == ERROR_SUCCESS, "failed to get column info\n");
3713 r = MsiRecordGetString(rec, 1, buf, &sz);
3714 ok(r == ERROR_SUCCESS, "failed to get string\n");
3715 ok( 0 == strcmp("G255", buf), "wrong column type\n");
3718 r = MsiRecordGetString(rec, 2, buf, &sz);
3719 ok(r == ERROR_SUCCESS, "failed to get string\n");
3720 ok( 0 == strcmp("j2", buf), "wrong column type\n");
3722 MsiCloseHandle( rec );
3723 MsiViewClose( view );
3724 MsiCloseHandle( view );
3726 /* query the table data */
3728 r = do_query(hdb, "select * from `_Tables` where `Name` = 'T'", &rec);
3729 ok( r == ERROR_SUCCESS, "temporary table exists in _Tables\n");
3730 MsiCloseHandle( rec );
3732 /* query the column data */
3734 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec);
3735 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3736 if (rec) MsiCloseHandle( rec );
3738 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec);
3739 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3740 if (rec) MsiCloseHandle( rec );
3742 MsiCloseHandle( hdb );
3744 DeleteFile(msifile);
3747 static void test_alter(void)
3755 ok( hdb, "failed to create db\n");
3757 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3758 r = run_query(hdb, 0, query);
3759 ok(r == ERROR_SUCCESS, "failed to add table\n");
3761 cond = MsiDatabaseIsTablePersistent(hdb, "T");
3762 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
3764 query = "ALTER TABLE `T` HOLD";
3765 r = run_query(hdb, 0, query);
3766 ok(r == ERROR_SUCCESS, "failed to hold table %d\n", r);
3768 query = "ALTER TABLE `T` FREE";
3769 r = run_query(hdb, 0, query);
3770 ok(r == ERROR_SUCCESS, "failed to free table\n");
3772 query = "ALTER TABLE `T` FREE";
3773 r = run_query(hdb, 0, query);
3774 ok(r == ERROR_SUCCESS, "failed to free table\n");
3776 query = "ALTER TABLE `T` FREE";
3777 r = run_query(hdb, 0, query);
3778 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to free table\n");
3780 query = "ALTER TABLE `T` HOLD";
3781 r = run_query(hdb, 0, query);
3782 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to hold table %d\n", r);
3784 /* table T is removed */
3785 query = "SELECT * FROM `T`";
3786 r = run_query(hdb, 0, query);
3787 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3789 /* create the table again */
3790 query = "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
3791 r = run_query(hdb, 0, query);
3792 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3794 /* up the ref count */
3795 query = "ALTER TABLE `U` HOLD";
3796 r = run_query(hdb, 0, query);
3797 ok(r == ERROR_SUCCESS, "failed to free table\n");
3799 /* add column, no data type */
3800 query = "ALTER TABLE `U` ADD `C`";
3801 r = run_query(hdb, 0, query);
3802 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3804 query = "ALTER TABLE `U` ADD `C` INTEGER";
3805 r = run_query(hdb, 0, query);
3806 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3808 /* add column C again */
3809 query = "ALTER TABLE `U` ADD `C` INTEGER";
3810 r = run_query(hdb, 0, query);
3811 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3813 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
3814 r = run_query(hdb, 0, query);
3815 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3817 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
3818 r = run_query(hdb, 0, query);
3819 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3821 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
3822 r = run_query(hdb, 0, query);
3823 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3825 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
3826 r = run_query(hdb, 0, query);
3827 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3829 query = "SELECT * FROM `U` WHERE `D` = 8";
3830 r = run_query(hdb, 0, query);
3831 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3833 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
3834 r = run_query(hdb, 0, query);
3835 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3837 query = "ALTER COLUMN `D` FREE";
3838 r = run_query(hdb, 0, query);
3839 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3841 /* drop the ref count */
3842 query = "ALTER TABLE `U` FREE";
3843 r = run_query(hdb, 0, query);
3844 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3846 /* table is not empty */
3847 query = "SELECT * FROM `U`";
3848 r = run_query(hdb, 0, query);
3849 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3851 /* column D is removed */
3852 query = "SELECT * FROM `U` WHERE `D` = 8";
3853 r = run_query(hdb, 0, query);
3854 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3856 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
3857 r = run_query(hdb, 0, query);
3858 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3860 /* add the column again */
3861 query = "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
3862 r = run_query(hdb, 0, query);
3863 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3865 /* up the ref count */
3866 query = "ALTER TABLE `U` HOLD";
3867 r = run_query(hdb, 0, query);
3868 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3870 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
3871 r = run_query(hdb, 0, query);
3872 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3874 query = "SELECT * FROM `U` WHERE `E` = 16";
3875 r = run_query(hdb, 0, query);
3876 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3878 /* drop the ref count */
3879 query = "ALTER TABLE `U` FREE";
3880 r = run_query(hdb, 0, query);
3881 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3883 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
3884 r = run_query(hdb, 0, query);
3885 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3887 query = "SELECT * FROM `U` WHERE `E` = 20";
3888 r = run_query(hdb, 0, query);
3889 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3891 /* drop the ref count */
3892 query = "ALTER TABLE `U` FREE";
3893 r = run_query(hdb, 0, query);
3894 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3896 /* table still exists */
3897 query = "SELECT * FROM `U`";
3898 r = run_query(hdb, 0, query);
3899 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3901 /* col E is removed */
3902 query = "SELECT * FROM `U` WHERE `E` = 20";
3903 r = run_query(hdb, 0, query);
3904 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3906 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
3907 r = run_query(hdb, 0, query);
3908 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3910 /* drop the ref count once more */
3911 query = "ALTER TABLE `U` FREE";
3912 r = run_query(hdb, 0, query);
3913 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3915 /* table still exists */
3916 query = "SELECT * FROM `U`";
3917 r = run_query(hdb, 0, query);
3918 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3920 MsiCloseHandle( hdb );
3921 DeleteFile(msifile);
3924 static void test_integers(void)
3926 MSIHANDLE hdb = 0, view = 0, rec = 0;
3931 /* just MsiOpenDatabase should not create a file */
3932 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3933 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3935 /* create a table */
3936 query = "CREATE TABLE `integers` ( "
3937 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
3938 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
3939 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
3940 "PRIMARY KEY `one`)";
3941 r = MsiDatabaseOpenView(hdb, query, &view);
3942 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3943 r = MsiViewExecute(view, 0);
3944 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3945 r = MsiViewClose(view);
3946 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3947 r = MsiCloseHandle(view);
3948 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3950 query = "SELECT * FROM `integers`";
3951 r = MsiDatabaseOpenView(hdb, query, &view);
3952 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3954 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
3955 count = MsiRecordGetFieldCount(rec);
3956 ok(count == 8, "Expected 8, got %d\n", count);
3957 ok(check_record(rec, 1, "one"), "Expected one\n");
3958 ok(check_record(rec, 2, "two"), "Expected two\n");
3959 ok(check_record(rec, 3, "three"), "Expected three\n");
3960 ok(check_record(rec, 4, "four"), "Expected four\n");
3961 ok(check_record(rec, 5, "five"), "Expected five\n");
3962 ok(check_record(rec, 6, "six"), "Expected six\n");
3963 ok(check_record(rec, 7, "seven"), "Expected seven\n");
3964 ok(check_record(rec, 8, "eight"), "Expected eight\n");
3965 MsiCloseHandle(rec);
3967 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
3968 count = MsiRecordGetFieldCount(rec);
3969 ok(count == 8, "Expected 8, got %d\n", count);
3970 ok(check_record(rec, 1, "I2"), "Expected I2\n");
3971 ok(check_record(rec, 2, "I2"), "Expected I2\n");
3972 ok(check_record(rec, 3, "I2"), "Expected I2\n");
3973 ok(check_record(rec, 4, "I4"), "Expected I4\n");
3974 ok(check_record(rec, 5, "i2"), "Expected i2\n");
3975 ok(check_record(rec, 6, "i2"), "Expected i2\n");
3976 ok(check_record(rec, 7, "i2"), "Expected i2\n");
3977 ok(check_record(rec, 8, "i4"), "Expected i4\n");
3978 MsiCloseHandle(rec);
3981 MsiCloseHandle(view);
3983 /* insert values into it, NULL where NOT NULL is specified */
3984 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3985 "VALUES('', '', '', '', '', '', '', '')";
3986 r = MsiDatabaseOpenView(hdb, query, &view);
3987 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3988 r = MsiViewExecute(view, 0);
3989 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
3992 MsiCloseHandle(view);
3994 query = "SELECT * FROM `integers`";
3995 r = do_query(hdb, query, &rec);
3996 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3998 r = MsiRecordGetFieldCount(rec);
3999 ok(r == -1, "record count wrong: %d\n", r);
4001 MsiCloseHandle(rec);
4003 /* insert legitimate values into it */
4004 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
4005 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
4006 r = MsiDatabaseOpenView(hdb, query, &view);
4007 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4008 r = MsiViewExecute(view, 0);
4009 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4011 query = "SELECT * FROM `integers`";
4012 r = do_query(hdb, query, &rec);
4013 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4015 r = MsiRecordGetFieldCount(rec);
4016 ok(r == 8, "record count wrong: %d\n", r);
4018 i = MsiRecordGetInteger(rec, 1);
4019 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
4020 i = MsiRecordGetInteger(rec, 3);
4021 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
4022 i = MsiRecordGetInteger(rec, 2);
4023 ok(i == 2, "Expected 2, got %d\n", i);
4024 i = MsiRecordGetInteger(rec, 4);
4025 ok(i == 4, "Expected 4, got %d\n", i);
4026 i = MsiRecordGetInteger(rec, 5);
4027 ok(i == 5, "Expected 5, got %d\n", i);
4028 i = MsiRecordGetInteger(rec, 6);
4029 ok(i == 6, "Expected 6, got %d\n", i);
4030 i = MsiRecordGetInteger(rec, 7);
4031 ok(i == 7, "Expected 7, got %d\n", i);
4032 i = MsiRecordGetInteger(rec, 8);
4033 ok(i == 8, "Expected 8, got %d\n", i);
4035 MsiCloseHandle(rec);
4037 MsiCloseHandle(view);
4039 r = MsiDatabaseCommit(hdb);
4040 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
4042 r = MsiCloseHandle(hdb);
4043 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4045 r = DeleteFile(msifile);
4046 ok(r == TRUE, "file didn't exist after commit\n");
4049 static void test_update(void)
4051 MSIHANDLE hdb = 0, view = 0, rec = 0;
4052 CHAR result[MAX_PATH];
4057 /* just MsiOpenDatabase should not create a file */
4058 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4059 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4061 /* create the Control table */
4062 query = "CREATE TABLE `Control` ( "
4063 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
4064 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
4065 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
4066 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
4067 r = MsiDatabaseOpenView(hdb, query, &view);
4068 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4069 r = MsiViewExecute(view, 0);
4070 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4071 r = MsiViewClose(view);
4072 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4073 r = MsiCloseHandle(view);
4074 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4077 query = "INSERT INTO `Control` ( "
4078 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4079 "`Property`, `Text`, `Control_Next`, `Help` )"
4080 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
4081 r = MsiDatabaseOpenView(hdb, query, &view);
4082 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4083 r = MsiViewExecute(view, 0);
4084 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4085 r = MsiViewClose(view);
4086 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4087 r = MsiCloseHandle(view);
4088 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4090 /* add a second control */
4091 query = "INSERT INTO `Control` ( "
4092 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4093 "`Property`, `Text`, `Control_Next`, `Help` )"
4094 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
4095 r = MsiDatabaseOpenView(hdb, query, &view);
4096 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4097 r = MsiViewExecute(view, 0);
4098 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4099 r = MsiViewClose(view);
4100 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4101 r = MsiCloseHandle(view);
4102 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4104 /* add a third control */
4105 query = "INSERT INTO `Control` ( "
4106 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4107 "`Property`, `Text`, `Control_Next`, `Help` )"
4108 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
4109 r = MsiDatabaseOpenView(hdb, query, &view);
4110 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4111 r = MsiViewExecute(view, 0);
4112 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4113 r = MsiViewClose(view);
4114 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4115 r = MsiCloseHandle(view);
4116 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4119 query = "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4120 r = MsiDatabaseOpenView(hdb, query, &view);
4121 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4123 /* bad set column */
4124 query = "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4125 r = MsiDatabaseOpenView(hdb, query, &view);
4126 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4128 /* bad where condition */
4129 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
4130 r = MsiDatabaseOpenView(hdb, query, &view);
4131 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4133 /* just the dialog_ specified */
4134 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4135 r = MsiDatabaseOpenView(hdb, query, &view);
4136 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4137 r = MsiViewExecute(view, 0);
4138 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4139 r = MsiViewClose(view);
4140 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4141 r = MsiCloseHandle(view);
4142 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4144 /* check the modified text */
4145 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
4146 r = MsiDatabaseOpenView(hdb, query, &view);
4147 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4148 r = MsiViewExecute(view, 0);
4149 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4151 r = MsiViewFetch(view, &rec);
4152 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4155 r = MsiRecordGetString(rec, 1, result, &size);
4156 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4157 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4159 MsiCloseHandle(rec);
4161 r = MsiViewFetch(view, &rec);
4162 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4165 r = MsiRecordGetString(rec, 1, result, &size);
4166 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4167 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
4169 MsiCloseHandle(rec);
4171 r = MsiViewFetch(view, &rec);
4172 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4174 r = MsiViewClose(view);
4175 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4176 r = MsiCloseHandle(view);
4177 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4179 /* dialog_ and control specified */
4180 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
4181 r = MsiDatabaseOpenView(hdb, query, &view);
4182 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4183 r = MsiViewExecute(view, 0);
4184 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4185 r = MsiViewClose(view);
4186 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4187 r = MsiCloseHandle(view);
4188 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4190 /* check the modified text */
4191 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
4192 r = MsiDatabaseOpenView(hdb, query, &view);
4193 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4194 r = MsiViewExecute(view, 0);
4195 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4197 r = MsiViewFetch(view, &rec);
4198 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4201 r = MsiRecordGetString(rec, 1, result, &size);
4202 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4203 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4205 MsiCloseHandle(rec);
4207 r = MsiViewFetch(view, &rec);
4208 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4211 r = MsiRecordGetString(rec, 1, result, &size);
4212 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4213 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
4215 MsiCloseHandle(rec);
4217 r = MsiViewFetch(view, &rec);
4218 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4220 r = MsiViewClose(view);
4221 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4222 r = MsiCloseHandle(view);
4223 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4225 /* no where condition */
4226 query = "UPDATE `Control` SET `Text` = 'this is text'";
4227 r = MsiDatabaseOpenView(hdb, query, &view);
4228 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4229 r = MsiViewExecute(view, 0);
4230 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4231 r = MsiViewClose(view);
4232 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4233 r = MsiCloseHandle(view);
4234 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4236 /* check the modified text */
4237 query = "SELECT `Text` FROM `Control`";
4238 r = MsiDatabaseOpenView(hdb, query, &view);
4239 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4240 r = MsiViewExecute(view, 0);
4241 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4243 r = MsiViewFetch(view, &rec);
4244 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4247 r = MsiRecordGetString(rec, 1, result, &size);
4248 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4249 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4251 MsiCloseHandle(rec);
4253 r = MsiViewFetch(view, &rec);
4254 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4257 r = MsiRecordGetString(rec, 1, result, &size);
4258 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4259 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4261 MsiCloseHandle(rec);
4263 r = MsiViewFetch(view, &rec);
4264 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4267 r = MsiRecordGetString(rec, 1, result, &size);
4268 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4269 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4271 MsiCloseHandle(rec);
4273 r = MsiViewFetch(view, &rec);
4274 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4276 r = MsiViewClose(view);
4277 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4278 r = MsiCloseHandle(view);
4279 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4281 query = "CREATE TABLE `Apple` ( `Banana` CHAR(72) NOT NULL, "
4282 "`Orange` CHAR(72), `Pear` INT PRIMARY KEY `Banana`)";
4283 r = run_query(hdb, 0, query);
4284 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4286 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4287 "VALUES('one', 'two', 3)";
4288 r = run_query(hdb, 0, query);
4289 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4291 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4292 "VALUES('three', 'four', 5)";
4293 r = run_query(hdb, 0, query);
4294 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4296 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4297 "VALUES('six', 'two', 7)";
4298 r = run_query(hdb, 0, query);
4299 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4301 rec = MsiCreateRecord(2);
4302 MsiRecordSetInteger(rec, 1, 8);
4303 MsiRecordSetString(rec, 2, "two");
4305 query = "UPDATE `Apple` SET `Pear` = ? WHERE `Orange` = ?";
4306 r = run_query(hdb, rec, query);
4307 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4309 MsiCloseHandle(rec);
4311 query = "SELECT `Pear` FROM `Apple` ORDER BY `Orange`";
4312 r = MsiDatabaseOpenView(hdb, query, &view);
4313 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4314 r = MsiViewExecute(view, 0);
4315 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4317 r = MsiViewFetch(view, &rec);
4318 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4320 r = MsiRecordGetInteger(rec, 1);
4321 ok(r == 8, "Expected 8, got %d\n", r);
4323 MsiCloseHandle(rec);
4325 r = MsiViewFetch(view, &rec);
4326 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4328 r = MsiRecordGetInteger(rec, 1);
4329 ok(r == 8, "Expected 8, got %d\n", r);
4331 MsiCloseHandle(rec);
4333 r = MsiViewFetch(view, &rec);
4334 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4336 r = MsiRecordGetInteger(rec, 1);
4337 ok(r == 5, "Expected 5, got %d\n", r);
4339 MsiCloseHandle(rec);
4341 r = MsiViewFetch(view, &rec);
4342 ok(r == ERROR_NO_MORE_ITEMS, "Expectd ERROR_NO_MORE_ITEMS, got %d\n", r);
4345 MsiCloseHandle(view);
4347 r = MsiDatabaseCommit(hdb);
4348 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
4349 r = MsiCloseHandle(hdb);
4350 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4352 DeleteFile(msifile);
4355 static void test_special_tables(void)
4361 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4362 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4364 query = "CREATE TABLE `_Properties` ( "
4365 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4366 r = run_query(hdb, 0, query);
4367 ok(r == ERROR_SUCCESS, "failed to create table\n");
4369 query = "CREATE TABLE `_Storages` ( "
4370 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4371 r = run_query(hdb, 0, query);
4372 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Streams table\n");
4374 query = "CREATE TABLE `_Streams` ( "
4375 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4376 r = run_query(hdb, 0, query);
4377 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Streams table\n");
4379 query = "CREATE TABLE `_Tables` ( "
4380 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4381 r = run_query(hdb, 0, query);
4382 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Tables table\n");
4384 query = "CREATE TABLE `_Columns` ( "
4385 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4386 r = run_query(hdb, 0, query);
4387 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Columns table\n");
4389 r = MsiCloseHandle(hdb);
4390 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4393 static void test_tables_order(void)
4396 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
4401 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4402 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4404 query = "CREATE TABLE `foo` ( "
4405 "`baz` INT NOT NULL PRIMARY KEY `baz`)";
4406 r = run_query(hdb, 0, query);
4407 ok(r == ERROR_SUCCESS, "failed to create table\n");
4409 query = "CREATE TABLE `bar` ( "
4410 "`foo` INT NOT NULL PRIMARY KEY `foo`)";
4411 r = run_query(hdb, 0, query);
4412 ok(r == ERROR_SUCCESS, "failed to create table\n");
4414 query = "CREATE TABLE `baz` ( "
4415 "`bar` INT NOT NULL, "
4416 "`baz` INT NOT NULL, "
4417 "`foo` INT NOT NULL PRIMARY KEY `bar`)";
4418 r = run_query(hdb, 0, query);
4419 ok(r == ERROR_SUCCESS, "failed to create table\n");
4421 /* The names of the tables in the _Tables table must
4422 be in the same order as these names are created in
4423 the strings table. */
4424 query = "SELECT * FROM `_Tables`";
4425 r = MsiDatabaseOpenView(hdb, query, &hview);
4426 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4427 r = MsiViewExecute(hview, 0);
4428 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4430 r = MsiViewFetch(hview, &hrec);
4431 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4432 sz = sizeof(buffer);
4433 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4434 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4435 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4436 r = MsiCloseHandle(hrec);
4437 ok(r == ERROR_SUCCESS, "failed to close record\n");
4439 r = MsiViewFetch(hview, &hrec);
4440 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4441 sz = sizeof(buffer);
4442 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4443 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4444 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4445 r = MsiCloseHandle(hrec);
4446 ok(r == ERROR_SUCCESS, "failed to close record\n");
4448 r = MsiViewFetch(hview, &hrec);
4449 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4450 sz = sizeof(buffer);
4451 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4452 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4453 ok(!lstrcmp(buffer, "bar"), "Expected bar, got %s\n", buffer);
4454 r = MsiCloseHandle(hrec);
4455 ok(r == ERROR_SUCCESS, "failed to close record\n");
4457 r = MsiViewClose(hview);
4458 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4459 r = MsiCloseHandle(hview);
4460 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4462 /* The names of the tables in the _Columns table must
4463 be in the same order as these names are created in
4464 the strings table. */
4465 query = "SELECT * FROM `_Columns`";
4466 r = MsiDatabaseOpenView(hdb, query, &hview);
4467 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4468 r = MsiViewExecute(hview, 0);
4469 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4471 r = MsiViewFetch(hview, &hrec);
4472 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4473 sz = sizeof(buffer);
4474 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4475 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4476 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4477 sz = sizeof(buffer);
4478 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4479 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4480 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4481 r = MsiCloseHandle(hrec);
4482 ok(r == ERROR_SUCCESS, "failed to close record\n");
4484 r = MsiViewFetch(hview, &hrec);
4485 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4486 sz = sizeof(buffer);
4487 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4488 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4489 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4490 sz = sizeof(buffer);
4491 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4492 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4493 ok(!lstrcmp(buffer, "bar"), "Expected bar, got %s\n", buffer);
4494 r = MsiCloseHandle(hrec);
4495 ok(r == ERROR_SUCCESS, "failed to close record\n");
4497 r = MsiViewFetch(hview, &hrec);
4498 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4499 sz = sizeof(buffer);
4500 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4501 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4502 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4503 sz = sizeof(buffer);
4504 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4505 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4506 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4507 r = MsiCloseHandle(hrec);
4508 ok(r == ERROR_SUCCESS, "failed to close record\n");
4510 r = MsiViewFetch(hview, &hrec);
4511 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4512 sz = sizeof(buffer);
4513 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4514 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4515 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4516 sz = sizeof(buffer);
4517 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4518 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4519 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4520 r = MsiCloseHandle(hrec);
4521 ok(r == ERROR_SUCCESS, "failed to close record\n");
4523 r = MsiViewFetch(hview, &hrec);
4524 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4525 sz = sizeof(buffer);
4526 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4527 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4528 ok(!lstrcmp(buffer, "bar"), "Expected bar, got %s\n", buffer);
4529 sz = sizeof(buffer);
4530 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4531 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4532 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4533 r = MsiCloseHandle(hrec);
4534 ok(r == ERROR_SUCCESS, "failed to close record\n");
4536 r = MsiViewClose(hview);
4537 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4538 r = MsiCloseHandle(hview);
4539 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4541 r = MsiCloseHandle(hdb);
4542 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4544 DeleteFile(msifile);
4547 static void test_rows_order(void)
4550 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
4555 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4556 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4558 query = "CREATE TABLE `foo` ( "
4559 "`bar` LONGCHAR NOT NULL PRIMARY KEY `bar`)";
4560 r = run_query(hdb, 0, query);
4561 ok(r == ERROR_SUCCESS, "failed to create table\n");
4563 r = run_query(hdb, 0, "INSERT INTO `foo` "
4564 "( `bar` ) VALUES ( 'A' )");
4565 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4567 r = run_query(hdb, 0, "INSERT INTO `foo` "
4568 "( `bar` ) VALUES ( 'B' )");
4569 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4571 r = run_query(hdb, 0, "INSERT INTO `foo` "
4572 "( `bar` ) VALUES ( 'C' )");
4573 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4575 r = run_query(hdb, 0, "INSERT INTO `foo` "
4576 "( `bar` ) VALUES ( 'D' )");
4577 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4579 r = run_query(hdb, 0, "INSERT INTO `foo` "
4580 "( `bar` ) VALUES ( 'E' )");
4581 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4583 r = run_query(hdb, 0, "INSERT INTO `foo` "
4584 "( `bar` ) VALUES ( 'F' )");
4585 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4587 query = "CREATE TABLE `bar` ( "
4588 "`foo` LONGCHAR NOT NULL, "
4589 "`baz` LONGCHAR NOT NULL "
4590 "PRIMARY KEY `foo` )";
4591 r = run_query(hdb, 0, query);
4592 ok(r == ERROR_SUCCESS, "failed to create table\n");
4594 r = run_query(hdb, 0, "INSERT INTO `bar` "
4595 "( `foo`, `baz` ) VALUES ( 'C', 'E' )");
4596 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4598 r = run_query(hdb, 0, "INSERT INTO `bar` "
4599 "( `foo`, `baz` ) VALUES ( 'F', 'A' )");
4600 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4602 r = run_query(hdb, 0, "INSERT INTO `bar` "
4603 "( `foo`, `baz` ) VALUES ( 'A', 'B' )");
4604 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4606 r = run_query(hdb, 0, "INSERT INTO `bar` "
4607 "( `foo`, `baz` ) VALUES ( 'D', 'E' )");
4608 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4610 /* The rows of the table must be ordered by the column values of
4611 each row. For strings, the column value is the string id
4612 in the string table. */
4614 query = "SELECT * FROM `bar`";
4615 r = MsiDatabaseOpenView(hdb, query, &hview);
4616 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4617 r = MsiViewExecute(hview, 0);
4618 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4620 r = MsiViewFetch(hview, &hrec);
4621 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4622 sz = sizeof(buffer);
4623 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4624 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4625 ok(!lstrcmp(buffer, "A"), "Expected A, got %s\n", buffer);
4626 sz = sizeof(buffer);
4627 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4628 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4629 ok(!lstrcmp(buffer, "B"), "Expected B, got %s\n", buffer);
4630 r = MsiCloseHandle(hrec);
4631 ok(r == ERROR_SUCCESS, "failed to close record\n");
4633 r = MsiViewFetch(hview, &hrec);
4634 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4635 sz = sizeof(buffer);
4636 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4637 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4638 ok(!lstrcmp(buffer, "C"), "Expected E, got %s\n", buffer);
4639 sz = sizeof(buffer);
4640 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4641 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4642 ok(!lstrcmp(buffer, "E"), "Expected E, got %s\n", buffer);
4643 r = MsiCloseHandle(hrec);
4644 ok(r == ERROR_SUCCESS, "failed to close record\n");
4646 r = MsiViewFetch(hview, &hrec);
4647 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4648 sz = sizeof(buffer);
4649 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4650 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4651 ok(!lstrcmp(buffer, "D"), "Expected D, got %s\n", buffer);
4652 sz = sizeof(buffer);
4653 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4654 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4655 ok(!lstrcmp(buffer, "E"), "Expected E, got %s\n", buffer);
4656 r = MsiCloseHandle(hrec);
4657 ok(r == ERROR_SUCCESS, "failed to close record\n");
4659 r = MsiViewFetch(hview, &hrec);
4660 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4661 sz = sizeof(buffer);
4662 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4663 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4664 ok(!lstrcmp(buffer, "F"), "Expected F, got %s\n", buffer);
4665 sz = sizeof(buffer);
4666 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4667 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4668 ok(!lstrcmp(buffer, "A"), "Expected A, got %s\n", buffer);
4669 r = MsiCloseHandle(hrec);
4670 ok(r == ERROR_SUCCESS, "failed to close record\n");
4672 r = MsiViewClose(hview);
4673 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4674 r = MsiCloseHandle(hview);
4675 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4677 r = MsiCloseHandle(hdb);
4678 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4680 DeleteFile(msifile);
4683 static void test_select_markers(void)
4685 MSIHANDLE hdb = 0, rec, view, res;
4692 ok( hdb, "failed to create db\n");
4694 r = run_query(hdb, 0,
4695 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
4696 ok(r == S_OK, "cannot create table: %d\n", r);
4698 r = run_query(hdb, 0, "INSERT INTO `Table` "
4699 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
4700 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4702 r = run_query(hdb, 0, "INSERT INTO `Table` "
4703 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
4704 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4706 r = run_query(hdb, 0, "INSERT INTO `Table` "
4707 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
4708 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4710 r = run_query(hdb, 0, "INSERT INTO `Table` "
4711 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
4712 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4714 rec = MsiCreateRecord(2);
4715 MsiRecordSetString(rec, 1, "apple");
4716 MsiRecordSetString(rec, 2, "two");
4718 query = "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
4719 r = MsiDatabaseOpenView(hdb, query, &view);
4720 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4722 r = MsiViewExecute(view, rec);
4723 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4725 r = MsiViewFetch(view, &res);
4726 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4729 r = MsiRecordGetString(res, 1, buf, &size);
4730 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4731 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
4734 r = MsiRecordGetString(res, 2, buf, &size);
4735 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4736 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
4738 r = MsiRecordGetInteger(res, 3);
4739 ok(r == 1, "Expected 1, got %d\n", r);
4741 MsiCloseHandle(res);
4743 r = MsiViewFetch(view, &res);
4744 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4747 r = MsiRecordGetString(res, 1, buf, &size);
4748 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4749 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
4752 r = MsiRecordGetString(res, 2, buf, &size);
4753 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4754 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
4756 r = MsiRecordGetInteger(res, 3);
4757 ok(r == 2, "Expected 2, got %d\n", r);
4759 MsiCloseHandle(res);
4761 r = MsiViewFetch(view, &res);
4762 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4764 MsiCloseHandle(rec);
4766 MsiCloseHandle(view);
4768 rec = MsiCreateRecord(2);
4769 MsiRecordSetString(rec, 1, "one");
4770 MsiRecordSetInteger(rec, 2, 1);
4772 query = "SELECT * FROM `Table` WHERE `Two`<>? AND `Three`>? ORDER BY `Three`";
4773 r = MsiDatabaseOpenView(hdb, query, &view);
4774 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4775 r = MsiViewExecute(view, rec);
4776 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4778 r = MsiViewFetch(view, &res);
4779 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4782 r = MsiRecordGetString(res, 1, buf, &size);
4783 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4784 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
4787 r = MsiRecordGetString(res, 2, buf, &size);
4788 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4789 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
4791 r = MsiRecordGetInteger(res, 3);
4792 ok(r == 2, "Expected 2, got %d\n", r);
4794 MsiCloseHandle(res);
4796 r = MsiViewFetch(view, &res);
4797 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4800 r = MsiRecordGetString(res, 1, buf, &size);
4801 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4802 ok(!lstrcmp(buf, "banana"), "Expected banana, got %s\n", buf);
4805 r = MsiRecordGetString(res, 2, buf, &size);
4806 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4807 ok(!lstrcmp(buf, "three"), "Expected three, got %s\n", buf);
4809 r = MsiRecordGetInteger(res, 3);
4810 ok(r == 3, "Expected 3, got %d\n", r);
4812 MsiCloseHandle(res);
4814 r = MsiViewFetch(view, &res);
4815 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4817 MsiCloseHandle(rec);
4819 MsiCloseHandle(view);
4820 MsiCloseHandle(hdb);
4821 DeleteFile(msifile);
4824 static void test_viewmodify_update(void)
4826 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
4830 DeleteFile(msifile);
4832 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4833 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4835 query = "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
4836 r = run_query( hdb, 0, query );
4837 ok(r == ERROR_SUCCESS, "query failed\n");
4839 query = "INSERT INTO `table` (`A`, `B`) VALUES (1, 2)";
4840 r = run_query( hdb, 0, query );
4841 ok(r == ERROR_SUCCESS, "query failed\n");
4843 query = "INSERT INTO `table` (`A`, `B`) VALUES (3, 4)";
4844 r = run_query( hdb, 0, query );
4845 ok(r == ERROR_SUCCESS, "query failed\n");
4847 query = "INSERT INTO `table` (`A`, `B`) VALUES (5, 6)";
4848 r = run_query( hdb, 0, query );
4849 ok(r == ERROR_SUCCESS, "query failed\n");
4851 query = "SELECT `B` FROM `table`";
4852 r = MsiDatabaseOpenView(hdb, query, &hview);
4853 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4854 r = MsiViewExecute(hview, 0);
4855 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4856 r = MsiViewFetch(hview, &hrec);
4857 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4859 r = MsiRecordSetInteger(hrec, 1, 0);
4860 ok(r == ERROR_SUCCESS, "failed to set integer\n");
4862 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
4863 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
4865 r = MsiCloseHandle(hrec);
4866 ok(r == ERROR_SUCCESS, "failed to close record\n");
4868 r = MsiViewClose(hview);
4869 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4870 r = MsiCloseHandle(hview);
4871 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4873 query = "SELECT * FROM `table`";
4874 r = MsiDatabaseOpenView(hdb, query, &hview);
4875 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4876 r = MsiViewExecute(hview, 0);
4877 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4878 r = MsiViewFetch(hview, &hrec);
4879 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4881 r = MsiRecordGetInteger(hrec, 1);
4882 ok(r == 1, "Expected 1, got %d\n", r);
4883 r = MsiRecordGetInteger(hrec, 2);
4884 ok(r == 0, "Expected 0, got %d\n", r);
4886 r = MsiCloseHandle(hrec);
4887 ok(r == ERROR_SUCCESS, "failed to close record\n");
4889 r = MsiViewFetch(hview, &hrec);
4890 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4892 r = MsiRecordGetInteger(hrec, 1);
4893 ok(r == 3, "Expected 3, got %d\n", r);
4894 r = MsiRecordGetInteger(hrec, 2);
4895 ok(r == 4, "Expected 4, got %d\n", r);
4897 r = MsiCloseHandle(hrec);
4898 ok(r == ERROR_SUCCESS, "failed to close record\n");
4900 r = MsiViewFetch(hview, &hrec);
4901 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4903 r = MsiRecordGetInteger(hrec, 1);
4904 ok(r == 5, "Expected 5, got %d\n", r);
4905 r = MsiRecordGetInteger(hrec, 2);
4906 ok(r == 6, "Expected 6, got %d\n", r);
4908 r = MsiCloseHandle(hrec);
4909 ok(r == ERROR_SUCCESS, "failed to close record\n");
4911 r = MsiViewFetch(hview, &hrec);
4912 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4914 r = MsiViewClose(hview);
4915 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4916 r = MsiCloseHandle(hview);
4917 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4919 /* loop through all elements */
4920 query = "SELECT `B` FROM `table`";
4921 r = MsiDatabaseOpenView(hdb, query, &hview);
4922 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4923 r = MsiViewExecute(hview, 0);
4924 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4928 r = MsiViewFetch(hview, &hrec);
4929 if (r != ERROR_SUCCESS)
4932 r = MsiRecordSetInteger(hrec, 1, 0);
4933 ok(r == ERROR_SUCCESS, "failed to set integer\n");
4935 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
4936 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
4938 r = MsiCloseHandle(hrec);
4939 ok(r == ERROR_SUCCESS, "failed to close record\n");
4942 r = MsiViewClose(hview);
4943 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4944 r = MsiCloseHandle(hview);
4945 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4947 query = "SELECT * FROM `table`";
4948 r = MsiDatabaseOpenView(hdb, query, &hview);
4949 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4950 r = MsiViewExecute(hview, 0);
4951 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4952 r = MsiViewFetch(hview, &hrec);
4953 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4955 r = MsiRecordGetInteger(hrec, 1);
4956 ok(r == 1, "Expected 1, got %d\n", r);
4957 r = MsiRecordGetInteger(hrec, 2);
4958 ok(r == 0, "Expected 0, got %d\n", r);
4960 r = MsiCloseHandle(hrec);
4961 ok(r == ERROR_SUCCESS, "failed to close record\n");
4963 r = MsiViewFetch(hview, &hrec);
4964 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4966 r = MsiRecordGetInteger(hrec, 1);
4967 ok(r == 3, "Expected 3, got %d\n", r);
4968 r = MsiRecordGetInteger(hrec, 2);
4969 ok(r == 0, "Expected 0, got %d\n", r);
4971 r = MsiCloseHandle(hrec);
4972 ok(r == ERROR_SUCCESS, "failed to close record\n");
4974 r = MsiViewFetch(hview, &hrec);
4975 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4977 r = MsiRecordGetInteger(hrec, 1);
4978 ok(r == 5, "Expected 5, got %d\n", r);
4979 r = MsiRecordGetInteger(hrec, 2);
4980 ok(r == 0, "Expected 0, got %d\n", r);
4982 r = MsiCloseHandle(hrec);
4983 ok(r == ERROR_SUCCESS, "failed to close record\n");
4985 r = MsiViewFetch(hview, &hrec);
4986 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4988 r = MsiViewClose(hview);
4989 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4990 r = MsiCloseHandle(hview);
4991 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4993 r = MsiCloseHandle( hdb );
4994 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
4997 static void test_viewmodify_assign(void)
4999 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5003 /* setup database */
5004 DeleteFile(msifile);
5006 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5007 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
5009 query = "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
5010 r = run_query( hdb, 0, query );
5011 ok(r == ERROR_SUCCESS, "query failed\n");
5013 /* assign to view, new primary key */
5014 query = "SELECT * FROM `table`";
5015 r = MsiDatabaseOpenView(hdb, query, &hview);
5016 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5017 r = MsiViewExecute(hview, 0);
5018 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5020 hrec = MsiCreateRecord(2);
5021 ok(hrec != 0, "MsiCreateRecord failed\n");
5023 r = MsiRecordSetInteger(hrec, 1, 1);
5024 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5025 r = MsiRecordSetInteger(hrec, 2, 2);
5026 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5028 r = MsiViewModify(hview, MSIMODIFY_ASSIGN, hrec);
5029 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5031 r = MsiCloseHandle(hrec);
5032 ok(r == ERROR_SUCCESS, "failed to close record\n");
5034 r = MsiViewClose(hview);
5035 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5036 r = MsiCloseHandle(hview);
5037 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5039 query = "SELECT * FROM `table`";
5040 r = MsiDatabaseOpenView(hdb, query, &hview);
5041 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5042 r = MsiViewExecute(hview, 0);
5043 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5044 r = MsiViewFetch(hview, &hrec);
5045 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5047 r = MsiRecordGetInteger(hrec, 1);
5048 ok(r == 1, "Expected 1, got %d\n", r);
5049 r = MsiRecordGetInteger(hrec, 2);
5050 ok(r == 2, "Expected 2, got %d\n", r);
5052 r = MsiCloseHandle(hrec);
5053 ok(r == ERROR_SUCCESS, "failed to close record\n");
5055 r = MsiViewFetch(hview, &hrec);
5056 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5058 r = MsiViewClose(hview);
5059 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5060 r = MsiCloseHandle(hview);
5061 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5063 /* assign to view, primary key matches */
5064 query = "SELECT * FROM `table`";
5065 r = MsiDatabaseOpenView(hdb, query, &hview);
5066 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5067 r = MsiViewExecute(hview, 0);
5068 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5070 hrec = MsiCreateRecord(2);
5071 ok(hrec != 0, "MsiCreateRecord failed\n");
5073 r = MsiRecordSetInteger(hrec, 1, 1);
5074 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5075 r = MsiRecordSetInteger(hrec, 2, 4);
5076 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5078 r = MsiViewModify(hview, MSIMODIFY_ASSIGN, hrec);
5079 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5081 r = MsiCloseHandle(hrec);
5082 ok(r == ERROR_SUCCESS, "failed to close record\n");
5084 r = MsiViewClose(hview);
5085 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5086 r = MsiCloseHandle(hview);
5087 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5089 query = "SELECT * FROM `table`";
5090 r = MsiDatabaseOpenView(hdb, query, &hview);
5091 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5092 r = MsiViewExecute(hview, 0);
5093 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5094 r = MsiViewFetch(hview, &hrec);
5095 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5097 r = MsiRecordGetInteger(hrec, 1);
5098 ok(r == 1, "Expected 1, got %d\n", r);
5099 r = MsiRecordGetInteger(hrec, 2);
5100 ok(r == 4, "Expected 4, got %d\n", r);
5102 r = MsiCloseHandle(hrec);
5103 ok(r == ERROR_SUCCESS, "failed to close record\n");
5105 r = MsiViewFetch(hview, &hrec);
5106 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5108 r = MsiViewClose(hview);
5109 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5110 r = MsiCloseHandle(hview);
5111 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5113 /* close database */
5114 r = MsiCloseHandle( hdb );
5115 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
5118 static const WCHAR data10[] = { /* MOO */
5121 static const WCHAR data11[] = { /* AAR */
5125 static const char data12[] = /* _StringData */
5126 "MOOABAARCDonetwofourfive";
5127 static const WCHAR data13[] = { /* _StringPool */
5129 0, 0, /* string 0 '' */
5130 0, 0, /* string 1 '' */
5131 0, 0, /* string 2 '' */
5132 0, 0, /* string 3 '' */
5133 0, 0, /* string 4 '' */
5134 3, 3, /* string 5 'MOO' */
5135 1, 1, /* string 6 'A' */
5136 1, 1, /* string 7 'B' */
5137 3, 3, /* string 8 'AAR' */
5138 1, 1, /* string 9 'C' */
5139 1, 1, /* string a 'D' */
5140 3, 1, /* string b 'one' */
5141 3, 1, /* string c 'two' */
5142 0, 0, /* string d '' */
5143 4, 1, /* string e 'four' */
5144 4, 1, /* string f 'five' */
5147 static void test_stringtable(void)
5149 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5150 IStorage *stg = NULL;
5155 char buffer[MAX_PATH];
5156 WCHAR data[MAX_PATH];
5160 static const DWORD mode = STGM_DIRECT | STGM_READ | STGM_SHARE_DENY_WRITE;
5161 static const WCHAR stringdata[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0}; /* _StringData */
5162 static const WCHAR stringpool[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0}; /* _StringPool */
5163 static const WCHAR moo[] = {0x4840, 0x3e16, 0x4818, 0}; /* MOO */
5164 static const WCHAR aar[] = {0x4840, 0x3a8a, 0x481b, 0}; /* AAR */
5166 DeleteFile(msifile);
5168 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5169 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5171 query = "CREATE TABLE `MOO` (`A` INT, `B` CHAR(72) PRIMARY KEY `A`)";
5172 r = run_query(hdb, 0, query);
5173 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5175 query = "CREATE TABLE `AAR` (`C` INT, `D` CHAR(72) PRIMARY KEY `C`)";
5176 r = run_query(hdb, 0, query);
5177 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5179 /* insert persistent row */
5180 query = "INSERT INTO `MOO` (`A`, `B`) VALUES (1, 'one')";
5181 r = run_query(hdb, 0, query);
5182 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5184 /* insert persistent row */
5185 query = "INSERT INTO `AAR` (`C`, `D`) VALUES (2, 'two')";
5186 r = run_query(hdb, 0, query);
5187 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5190 query = "SELECT * FROM `MOO`";
5191 r = MsiDatabaseOpenView(hdb, query, &hview);
5192 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5193 r = MsiViewExecute(hview, 0);
5194 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5196 hrec = MsiCreateRecord(2);
5198 r = MsiRecordSetInteger(hrec, 1, 3);
5199 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5200 r = MsiRecordSetString(hrec, 2, "three");
5201 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5203 /* insert a nonpersistent row */
5204 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
5205 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5207 r = MsiCloseHandle(hrec);
5208 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5209 r = MsiViewClose(hview);
5210 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5211 r = MsiCloseHandle(hview);
5212 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5214 /* insert persistent row */
5215 query = "INSERT INTO `MOO` (`A`, `B`) VALUES (4, 'four')";
5216 r = run_query(hdb, 0, query);
5217 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5219 /* insert persistent row */
5220 query = "INSERT INTO `AAR` (`C`, `D`) VALUES (5, 'five')";
5221 r = run_query(hdb, 0, query);
5222 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5224 r = MsiDatabaseCommit(hdb);
5225 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5227 r = MsiCloseHandle(hdb);
5228 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5230 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
5231 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5233 query = "SELECT * FROM `MOO`";
5234 r = MsiDatabaseOpenView(hdb, query, &hview);
5235 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5237 r = MsiViewExecute(hview, 0);
5238 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5240 r = MsiViewFetch(hview, &hrec);
5241 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5243 r = MsiRecordGetFieldCount(hrec);
5244 ok(r == 2, "Expected 2, got %d\n", r);
5246 r = MsiRecordGetInteger(hrec, 1);
5247 ok(r == 1, "Expected 1, got %d\n", r);
5249 sz = sizeof(buffer);
5250 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5251 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5252 ok(!lstrcmp(buffer, "one"), "Expected one, got %s\n", buffer);
5254 r = MsiCloseHandle(hrec);
5255 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5257 r = MsiViewFetch(hview, &hrec);
5260 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5263 r = MsiViewClose(hview);
5264 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5265 r = MsiCloseHandle(hview);
5266 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5267 r = MsiCloseHandle(hrec);
5268 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5270 query = "SELECT * FROM `AAR`";
5271 r = MsiDatabaseOpenView(hdb, query, &hview);
5272 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5274 r = MsiViewExecute(hview, 0);
5275 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5277 r = MsiViewFetch(hview, &hrec);
5278 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5280 r = MsiRecordGetFieldCount(hrec);
5281 ok(r == 2, "Expected 2, got %d\n", r);
5283 r = MsiRecordGetInteger(hrec, 1);
5284 ok(r == 2, "Expected 2, got %d\n", r);
5286 sz = sizeof(buffer);
5287 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5288 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5289 ok(!lstrcmp(buffer, "two"), "Expected two, got %s\n", buffer);
5291 r = MsiCloseHandle(hrec);
5292 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5294 r = MsiViewFetch(hview, &hrec);
5295 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5297 r = MsiRecordGetFieldCount(hrec);
5298 ok(r == 2, "Expected 2, got %d\n", r);
5300 r = MsiRecordGetInteger(hrec, 1);
5301 ok(r == 5, "Expected 5, got %d\n", r);
5303 sz = sizeof(buffer);
5304 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5305 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5306 ok(!lstrcmp(buffer, "five"), "Expected five, got %s\n", buffer);
5308 r = MsiCloseHandle(hrec);
5309 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5311 r = MsiViewFetch(hview, &hrec);
5312 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5314 r = MsiViewClose(hview);
5315 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5316 r = MsiCloseHandle(hview);
5317 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5318 r = MsiCloseHandle(hrec);
5319 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5320 r = MsiCloseHandle(hdb);
5321 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5323 MultiByteToWideChar(CP_ACP, 0, msifile, -1, name, 0x20);
5324 hr = StgOpenStorage(name, NULL, mode, NULL, 0, &stg);
5325 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5326 ok(stg != NULL, "Expected non-NULL storage\n");
5328 hr = IStorage_OpenStream(stg, moo, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5329 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5330 ok(stm != NULL, "Expected non-NULL stream\n");
5332 hr = IStream_Read(stm, data, MAX_PATH, &read);
5333 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5336 ok(read == 4, "Expected 4, got %d\n", read);
5337 ok(!memcmp(data, data10, read), "Unexpected data\n");
5340 hr = IStream_Release(stm);
5341 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5343 hr = IStorage_OpenStream(stg, aar, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5344 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5345 ok(stm != NULL, "Expected non-NULL stream\n");
5347 hr = IStream_Read(stm, data, MAX_PATH, &read);
5348 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5349 ok(read == 8, "Expected 8, got %d\n", read);
5352 ok(!memcmp(data, data11, read), "Unexpected data\n");
5355 hr = IStream_Release(stm);
5356 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5358 hr = IStorage_OpenStream(stg, stringdata, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5359 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5360 ok(stm != NULL, "Expected non-NULL stream\n");
5362 hr = IStream_Read(stm, buffer, MAX_PATH, &read);
5363 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5364 ok(read == 24, "Expected 24, got %d\n", read);
5365 ok(!memcmp(buffer, data12, read), "Unexpected data\n");
5367 hr = IStream_Release(stm);
5368 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5370 hr = IStorage_OpenStream(stg, stringpool, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5371 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5372 ok(stm != NULL, "Expected non-NULL stream\n");
5374 hr = IStream_Read(stm, data, MAX_PATH, &read);
5375 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5378 ok(read == 64, "Expected 64, got %d\n", read);
5379 ok(!memcmp(data, data13, read), "Unexpected data\n");
5382 hr = IStream_Release(stm);
5383 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5385 hr = IStorage_Release(stg);
5386 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5388 DeleteFileA(msifile);
5391 static void test_viewmodify_delete(void)
5393 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5399 DeleteFile(msifile);
5401 /* just MsiOpenDatabase should not create a file */
5402 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5403 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5405 query = "CREATE TABLE `phone` ( "
5406 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
5407 "PRIMARY KEY `id`)";
5408 r = run_query(hdb, 0, query);
5409 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5411 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
5412 "VALUES('1', 'Alan', '5030581')";
5413 r = run_query(hdb, 0, query);
5414 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5416 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
5417 "VALUES('2', 'Barry', '928440')";
5418 r = run_query(hdb, 0, query);
5419 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5421 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
5422 "VALUES('3', 'Cindy', '2937550')";
5423 r = run_query(hdb, 0, query);
5424 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5426 query = "SELECT * FROM `phone` WHERE `id` <= 2";
5427 r = MsiDatabaseOpenView(hdb, query, &hview);
5428 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5429 r = MsiViewExecute(hview, 0);
5430 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5431 r = MsiViewFetch(hview, &hrec);
5432 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5435 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
5436 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5438 r = MsiCloseHandle(hrec);
5439 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5440 r = MsiViewFetch(hview, &hrec);
5441 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5444 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
5445 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5447 r = MsiCloseHandle(hrec);
5448 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5449 r = MsiViewClose(hview);
5450 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5451 r = MsiCloseHandle(hview);
5452 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5454 query = "SELECT * FROM `phone`";
5455 r = MsiDatabaseOpenView(hdb, query, &hview);
5456 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5457 r = MsiViewExecute(hview, 0);
5458 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5459 r = MsiViewFetch(hview, &hrec);
5460 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5462 r = MsiRecordGetInteger(hrec, 1);
5463 ok(r == 3, "Expected 3, got %d\n", r);
5465 sz = sizeof(buffer);
5466 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5467 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5468 ok(!lstrcmp(buffer, "Cindy"), "Expected Cindy, got %s\n", buffer);
5470 sz = sizeof(buffer);
5471 r = MsiRecordGetString(hrec, 3, buffer, &sz);
5472 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5473 ok(!lstrcmp(buffer, "2937550"), "Expected 2937550, got %s\n", buffer);
5475 r = MsiCloseHandle(hrec);
5476 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5478 r = MsiViewFetch(hview, &hrec);
5479 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5481 r = MsiViewClose(hview);
5482 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5483 r = MsiCloseHandle(hview);
5484 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5485 r = MsiCloseHandle(hdb);
5486 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5489 static const WCHAR _Tables[] = {0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0};
5490 static const WCHAR _StringData[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0};
5491 static const WCHAR _StringPool[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0};
5493 static const WCHAR data14[] = { /* _StringPool */
5495 0, 0, /* string 0 '' */
5498 static const struct {
5502 } database_table_data[] =
5505 {_StringData, NULL, 0},
5506 {_StringPool, data14, sizeof data14},
5509 static void enum_stream_names(IStorage *stg)
5511 IEnumSTATSTG *stgenum = NULL;
5516 BYTE data[MAX_PATH];
5517 BYTE check[MAX_PATH];
5520 memset(check, 'a', MAX_PATH);
5522 hr = IStorage_EnumElements(stg, 0, NULL, 0, &stgenum);
5523 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
5529 hr = IEnumSTATSTG_Next(stgenum, 1, &stat, &count);
5530 if(FAILED(hr) || !count)
5533 ok(!lstrcmpW(stat.pwcsName, database_table_data[n].name),
5534 "Expected table %d name to match\n", n);
5537 hr = IStorage_OpenStream(stg, stat.pwcsName, NULL,
5538 STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5539 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
5540 ok(stm != NULL, "Expected non-NULL stream\n");
5543 memset(data, 'a', MAX_PATH);
5544 hr = IStream_Read(stm, data, sz, &count);
5545 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
5547 ok(count == database_table_data[n].size,
5548 "Expected %d, got %d\n", database_table_data[n].size, count);
5550 if (!database_table_data[n].size)
5551 ok(!memcmp(data, check, MAX_PATH), "data should not be changed\n");
5553 ok(!memcmp(data, database_table_data[n].data, database_table_data[n].size),
5554 "Expected table %d data to match\n", n);
5556 IStream_Release(stm);
5560 ok(n == 3, "Expected 3, got %d\n", n);
5562 IEnumSTATSTG_Release(stgenum);
5565 static void test_defaultdatabase(void)
5570 IStorage *stg = NULL;
5572 static const WCHAR msifileW[] = {'w','i','n','e','t','e','s','t','.','m','s','i',0};
5574 DeleteFile(msifile);
5576 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5577 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5579 r = MsiDatabaseCommit(hdb);
5580 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5582 MsiCloseHandle(hdb);
5584 hr = StgOpenStorage(msifileW, NULL, STGM_READ | STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
5585 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
5586 ok(stg != NULL, "Expected non-NULL stg\n");
5588 enum_stream_names(stg);
5590 IStorage_Release(stg);
5591 DeleteFileA(msifile);
5594 static void test_order(void)
5596 MSIHANDLE hdb, hview, hrec;
5597 CHAR buffer[MAX_PATH];
5603 ok(hdb, "failed to create db\n");
5605 query = "CREATE TABLE `Empty` ( `A` SHORT NOT NULL PRIMARY KEY `A`)";
5606 r = run_query(hdb, 0, query);
5607 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5609 query = "CREATE TABLE `Mesa` ( `A` SHORT NOT NULL, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
5610 r = run_query(hdb, 0, query);
5611 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5613 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 1, 2, 9 )";
5614 r = run_query(hdb, 0, query);
5615 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5617 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 3, 4, 7 )";
5618 r = run_query(hdb, 0, query);
5619 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5621 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 5, 6, 8 )";
5622 r = run_query(hdb, 0, query);
5623 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5625 query = "CREATE TABLE `Sideboard` ( `D` SHORT NOT NULL, `E` SHORT, `F` SHORT PRIMARY KEY `D`)";
5626 r = run_query(hdb, 0, query);
5627 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5629 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 10, 11, 18 )";
5630 r = run_query(hdb, 0, query);
5631 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5633 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 12, 13, 16 )";
5634 r = run_query(hdb, 0, query);
5635 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5637 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 14, 15, 17 )";
5638 r = run_query(hdb, 0, query);
5639 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5641 query = "SELECT `A`, `B` FROM `Mesa` ORDER BY `C`";
5642 r = MsiDatabaseOpenView(hdb, query, &hview);
5643 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5644 r = MsiViewExecute(hview, 0);
5645 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5647 r = MsiViewFetch(hview, &hrec);
5648 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5650 val = MsiRecordGetInteger(hrec, 1);
5651 ok(val == 3, "Expected 3, got %d\n", val);
5653 val = MsiRecordGetInteger(hrec, 2);
5654 ok(val == 4, "Expected 3, got %d\n", val);
5656 MsiCloseHandle(hrec);
5658 r = MsiViewFetch(hview, &hrec);
5659 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5661 val = MsiRecordGetInteger(hrec, 1);
5662 ok(val == 5, "Expected 5, got %d\n", val);
5664 val = MsiRecordGetInteger(hrec, 2);
5665 ok(val == 6, "Expected 6, got %d\n", val);
5667 MsiCloseHandle(hrec);
5669 r = MsiViewFetch(hview, &hrec);
5670 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5672 val = MsiRecordGetInteger(hrec, 1);
5673 ok(val == 1, "Expected 1, got %d\n", val);
5675 val = MsiRecordGetInteger(hrec, 2);
5676 ok(val == 2, "Expected 2, got %d\n", val);
5678 MsiCloseHandle(hrec);
5680 r = MsiViewFetch(hview, &hrec);
5681 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5683 MsiViewClose(hview);
5684 MsiCloseHandle(hview);
5686 query = "SELECT `A`, `D` FROM `Mesa`, `Sideboard` ORDER BY `F`";
5687 r = MsiDatabaseOpenView(hdb, query, &hview);
5688 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5689 r = MsiViewExecute(hview, 0);
5690 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5692 r = MsiViewFetch(hview, &hrec);
5693 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5695 val = MsiRecordGetInteger(hrec, 1);
5696 ok(val == 1, "Expected 1, got %d\n", val);
5698 val = MsiRecordGetInteger(hrec, 2);
5699 ok(val == 12, "Expected 12, got %d\n", val);
5701 MsiCloseHandle(hrec);
5703 r = MsiViewFetch(hview, &hrec);
5704 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5706 val = MsiRecordGetInteger(hrec, 1);
5707 ok(val == 3, "Expected 3, got %d\n", val);
5709 val = MsiRecordGetInteger(hrec, 2);
5710 ok(val == 12, "Expected 12, got %d\n", val);
5712 MsiCloseHandle(hrec);
5714 r = MsiViewFetch(hview, &hrec);
5715 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5717 val = MsiRecordGetInteger(hrec, 1);
5718 ok(val == 5, "Expected 5, got %d\n", val);
5720 val = MsiRecordGetInteger(hrec, 2);
5721 ok(val == 12, "Expected 12, got %d\n", val);
5723 MsiCloseHandle(hrec);
5725 r = MsiViewFetch(hview, &hrec);
5726 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5728 val = MsiRecordGetInteger(hrec, 1);
5729 ok(val == 1, "Expected 1, got %d\n", val);
5731 val = MsiRecordGetInteger(hrec, 2);
5732 ok(val == 14, "Expected 14, got %d\n", val);
5734 MsiCloseHandle(hrec);
5736 r = MsiViewFetch(hview, &hrec);
5737 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5739 val = MsiRecordGetInteger(hrec, 1);
5740 ok(val == 3, "Expected 3, got %d\n", val);
5742 val = MsiRecordGetInteger(hrec, 2);
5743 ok(val == 14, "Expected 14, got %d\n", val);
5745 MsiCloseHandle(hrec);
5747 r = MsiViewFetch(hview, &hrec);
5748 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5750 val = MsiRecordGetInteger(hrec, 1);
5751 ok(val == 5, "Expected 5, got %d\n", val);
5753 val = MsiRecordGetInteger(hrec, 2);
5754 ok(val == 14, "Expected 14, got %d\n", val);
5756 MsiCloseHandle(hrec);
5758 r = MsiViewFetch(hview, &hrec);
5759 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5761 val = MsiRecordGetInteger(hrec, 1);
5762 ok(val == 1, "Expected 1, got %d\n", val);
5764 val = MsiRecordGetInteger(hrec, 2);
5765 ok(val == 10, "Expected 10, got %d\n", val);
5767 MsiCloseHandle(hrec);
5769 r = MsiViewFetch(hview, &hrec);
5770 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5772 val = MsiRecordGetInteger(hrec, 1);
5773 ok(val == 3, "Expected 3, got %d\n", val);
5775 val = MsiRecordGetInteger(hrec, 2);
5776 ok(val == 10, "Expected 10, got %d\n", val);
5778 MsiCloseHandle(hrec);
5780 r = MsiViewFetch(hview, &hrec);
5781 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5783 val = MsiRecordGetInteger(hrec, 1);
5784 ok(val == 5, "Expected 5, got %d\n", val);
5786 val = MsiRecordGetInteger(hrec, 2);
5787 ok(val == 10, "Expected 10, got %d\n", val);
5789 MsiCloseHandle(hrec);
5791 r = MsiViewFetch(hview, &hrec);
5792 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5794 MsiViewClose(hview);
5795 MsiCloseHandle(hview);
5797 query = "SELECT * FROM `Empty` ORDER BY `A`";
5798 r = MsiDatabaseOpenView(hdb, query, &hview);
5799 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5800 r = MsiViewExecute(hview, 0);
5801 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5803 r = MsiViewFetch(hview, &hrec);
5804 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5806 MsiViewClose(hview);
5807 MsiCloseHandle(hview);
5809 query = "CREATE TABLE `Buffet` ( `One` CHAR(72), `Two` SHORT PRIMARY KEY `One`)";
5810 r = run_query(hdb, 0, query);
5811 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5813 query = "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'uno', 2)";
5814 r = run_query(hdb, 0, query);
5815 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5817 query = "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'dos', 3)";
5818 r = run_query(hdb, 0, query);
5819 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5821 query = "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'tres', 1)";
5822 r = run_query(hdb, 0, query);
5823 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5825 query = "SELECT * FROM `Buffet` WHERE `One` = 'dos' ORDER BY `Two`";
5826 r = MsiDatabaseOpenView(hdb, query, &hview);
5827 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5828 r = MsiViewExecute(hview, 0);
5829 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5831 r = MsiViewFetch(hview, &hrec);
5832 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5834 sz = sizeof(buffer);
5835 r = MsiRecordGetString(hrec, 1, buffer, &sz);
5836 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5837 ok(!lstrcmp(buffer, "dos"), "Expected \"dos\", got \"%s\"\n", buffer);
5839 r = MsiRecordGetInteger(hrec, 2);
5840 ok(r == 3, "Expected 3, got %d\n", r);
5842 MsiCloseHandle(hrec);
5844 r = MsiViewFetch(hview, &hrec);
5845 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5847 MsiViewClose(hview);
5848 MsiCloseHandle(hview);
5849 MsiCloseHandle(hdb);
5852 static void test_viewmodify_delete_temporary(void)
5854 MSIHANDLE hdb, hview, hrec;
5858 DeleteFile(msifile);
5860 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5861 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5863 query = "CREATE TABLE `Table` ( `A` SHORT PRIMARY KEY `A` )";
5864 r = run_query(hdb, 0, query);
5865 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5867 query = "SELECT * FROM `Table`";
5868 r = MsiDatabaseOpenView(hdb, query, &hview);
5869 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5870 r = MsiViewExecute(hview, 0);
5871 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5873 hrec = MsiCreateRecord(1);
5874 MsiRecordSetInteger(hrec, 1, 1);
5876 r = MsiViewModify(hview, MSIMODIFY_INSERT, hrec);
5877 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5879 MsiCloseHandle(hrec);
5881 hrec = MsiCreateRecord(1);
5882 MsiRecordSetInteger(hrec, 1, 2);
5884 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
5885 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5887 MsiCloseHandle(hrec);
5889 hrec = MsiCreateRecord(1);
5890 MsiRecordSetInteger(hrec, 1, 3);
5892 r = MsiViewModify(hview, MSIMODIFY_INSERT, hrec);
5893 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5895 MsiCloseHandle(hrec);
5897 hrec = MsiCreateRecord(1);
5898 MsiRecordSetInteger(hrec, 1, 4);
5900 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
5901 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5903 MsiCloseHandle(hrec);
5904 MsiViewClose(hview);
5905 MsiCloseHandle(hview);
5907 query = "SELECT * FROM `Table` WHERE `A` = 2";
5908 r = MsiDatabaseOpenView(hdb, query, &hview);
5909 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5910 r = MsiViewExecute(hview, 0);
5911 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5912 r = MsiViewFetch(hview, &hrec);
5913 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5915 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
5916 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5918 MsiCloseHandle(hrec);
5919 MsiViewClose(hview);
5920 MsiCloseHandle(hview);
5922 query = "SELECT * FROM `Table` WHERE `A` = 3";
5923 r = MsiDatabaseOpenView(hdb, query, &hview);
5924 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5925 r = MsiViewExecute(hview, 0);
5926 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5927 r = MsiViewFetch(hview, &hrec);
5928 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5930 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
5931 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5933 MsiCloseHandle(hrec);
5934 MsiViewClose(hview);
5935 MsiCloseHandle(hview);
5937 query = "SELECT * FROM `Table` ORDER BY `A`";
5938 r = MsiDatabaseOpenView(hdb, query, &hview);
5939 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5940 r = MsiViewExecute(hview, 0);
5941 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5943 r = MsiViewFetch(hview, &hrec);
5944 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5946 r = MsiRecordGetInteger(hrec, 1);
5947 ok(r == 1, "Expected 1, got %d\n", r);
5949 MsiCloseHandle(hrec);
5951 r = MsiViewFetch(hview, &hrec);
5952 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5954 r = MsiRecordGetInteger(hrec, 1);
5955 ok(r == 4, "Expected 4, got %d\n", r);
5957 MsiCloseHandle(hrec);
5959 r = MsiViewFetch(hview, &hrec);
5960 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5962 MsiViewClose(hview);
5963 MsiCloseHandle(hview);
5964 MsiCloseHandle(hdb);
5965 DeleteFileA(msifile);
5968 static void test_deleterow(void)
5970 MSIHANDLE hdb, hview, hrec;
5976 DeleteFile(msifile);
5978 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5979 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5981 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5982 r = run_query(hdb, 0, query);
5983 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5985 query = "INSERT INTO `Table` (`A`) VALUES ('one')";
5986 r = run_query(hdb, 0, query);
5987 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5989 query = "INSERT INTO `Table` (`A`) VALUES ('two')";
5990 r = run_query(hdb, 0, query);
5991 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5993 query = "DELETE FROM `Table` WHERE `A` = 'one'";
5994 r = run_query(hdb, 0, query);
5995 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5997 r = MsiDatabaseCommit(hdb);
5998 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6000 MsiCloseHandle(hdb);
6002 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
6003 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6005 query = "SELECT * FROM `Table`";
6006 r = MsiDatabaseOpenView(hdb, query, &hview);
6007 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6008 r = MsiViewExecute(hview, 0);
6009 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6011 r = MsiViewFetch(hview, &hrec);
6012 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6015 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6016 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6017 ok(!lstrcmpA(buf, "two"), "Expected two, got %s\n", buf);
6019 MsiCloseHandle(hrec);
6021 r = MsiViewFetch(hview, &hrec);
6022 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6024 MsiViewClose(hview);
6025 MsiCloseHandle(hview);
6026 MsiCloseHandle(hdb);
6027 DeleteFileA(msifile);
6030 static const CHAR import_dat[] = "A\n"
6033 "This is a new 'string' ok\n";
6035 static void test_quotes(void)
6037 MSIHANDLE hdb, hview, hrec;
6043 DeleteFile(msifile);
6045 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6046 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6048 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6049 r = run_query(hdb, 0, query);
6050 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6052 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a 'string' ok' )";
6053 r = run_query(hdb, 0, query);
6054 ok(r == ERROR_BAD_QUERY_SYNTAX,
6055 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6057 query = "INSERT INTO `Table` ( `A` ) VALUES ( \"This is a 'string' ok\" )";
6058 r = run_query(hdb, 0, query);
6059 ok(r == ERROR_BAD_QUERY_SYNTAX,
6060 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6062 query = "INSERT INTO `Table` ( `A` ) VALUES ( \"test\" )";
6063 r = run_query(hdb, 0, query);
6064 ok(r == ERROR_BAD_QUERY_SYNTAX,
6065 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6067 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a ''string'' ok' )";
6068 r = run_query(hdb, 0, query);
6069 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6071 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a '''string''' ok' )";
6072 r = run_query(hdb, 0, query);
6073 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6075 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \'string\' ok' )";
6076 r = run_query(hdb, 0, query);
6077 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6079 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \"string\" ok' )";
6080 r = run_query(hdb, 0, query);
6081 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6083 query = "SELECT * FROM `Table`";
6084 r = MsiDatabaseOpenView(hdb, query, &hview);
6085 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6087 r = MsiViewExecute(hview, 0);
6088 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6090 r = MsiViewFetch(hview, &hrec);
6091 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6094 r = MsiRecordGetString(hrec, 1, buf, &size);
6095 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6096 ok(!lstrcmp(buf, "This is a \"string\" ok"),
6097 "Expected \"This is a \"string\" ok\", got %s\n", buf);
6099 MsiCloseHandle(hrec);
6101 r = MsiViewFetch(hview, &hrec);
6102 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6104 MsiViewClose(hview);
6105 MsiCloseHandle(hview);
6107 write_file("import.idt", import_dat, (sizeof(import_dat) - 1) * sizeof(char));
6109 r = MsiDatabaseImportA(hdb, CURR_DIR, "import.idt");
6110 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6112 DeleteFileA("import.idt");
6114 query = "SELECT * FROM `Table`";
6115 r = MsiDatabaseOpenView(hdb, query, &hview);
6116 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6118 r = MsiViewExecute(hview, 0);
6119 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6121 r = MsiViewFetch(hview, &hrec);
6122 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6125 r = MsiRecordGetString(hrec, 1, buf, &size);
6126 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6127 ok(!lstrcmp(buf, "This is a new 'string' ok"),
6128 "Expected \"This is a new 'string' ok\", got %s\n", buf);
6130 MsiCloseHandle(hrec);
6132 r = MsiViewFetch(hview, &hrec);
6133 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6135 MsiViewClose(hview);
6136 MsiCloseHandle(hview);
6137 MsiCloseHandle(hdb);
6138 DeleteFileA(msifile);
6141 static void test_carriagereturn(void)
6143 MSIHANDLE hdb, hview, hrec;
6149 DeleteFile(msifile);
6151 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6152 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6154 query = "CREATE TABLE `Table`\r ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6155 r = run_query(hdb, 0, query);
6156 ok(r == ERROR_BAD_QUERY_SYNTAX,
6157 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6159 query = "CREATE TABLE `Table` \r( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6160 r = run_query(hdb, 0, query);
6161 ok(r == ERROR_BAD_QUERY_SYNTAX,
6162 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6164 query = "CREATE\r TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6165 r = run_query(hdb, 0, query);
6166 ok(r == ERROR_BAD_QUERY_SYNTAX,
6167 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6169 query = "CREATE TABLE\r `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6170 r = run_query(hdb, 0, query);
6171 ok(r == ERROR_BAD_QUERY_SYNTAX,
6172 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6174 query = "CREATE TABLE `Table` (\r `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6175 r = run_query(hdb, 0, query);
6176 ok(r == ERROR_BAD_QUERY_SYNTAX,
6177 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6179 query = "CREATE TABLE `Table` ( `A`\r CHAR(72) NOT NULL PRIMARY KEY `A` )";
6180 r = run_query(hdb, 0, query);
6181 ok(r == ERROR_BAD_QUERY_SYNTAX,
6182 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6184 query = "CREATE TABLE `Table` ( `A` CHAR(72)\r NOT NULL PRIMARY KEY `A` )";
6185 r = run_query(hdb, 0, query);
6186 ok(r == ERROR_BAD_QUERY_SYNTAX,
6187 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6189 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT\r NULL PRIMARY KEY `A` )";
6190 r = run_query(hdb, 0, query);
6191 ok(r == ERROR_BAD_QUERY_SYNTAX,
6192 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6194 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT \rNULL PRIMARY KEY `A` )";
6195 r = run_query(hdb, 0, query);
6196 ok(r == ERROR_BAD_QUERY_SYNTAX,
6197 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6199 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL\r PRIMARY KEY `A` )";
6200 r = run_query(hdb, 0, query);
6201 ok(r == ERROR_BAD_QUERY_SYNTAX,
6202 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6204 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL \rPRIMARY KEY `A` )";
6205 r = run_query(hdb, 0, query);
6206 ok(r == ERROR_BAD_QUERY_SYNTAX,
6207 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6209 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY\r KEY `A` )";
6210 r = run_query(hdb, 0, query);
6211 ok(r == ERROR_BAD_QUERY_SYNTAX,
6212 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6214 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY \rKEY `A` )";
6215 r = run_query(hdb, 0, query);
6216 ok(r == ERROR_BAD_QUERY_SYNTAX,
6217 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6219 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY\r `A` )";
6220 r = run_query(hdb, 0, query);
6221 ok(r == ERROR_BAD_QUERY_SYNTAX,
6222 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6224 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A`\r )";
6225 r = run_query(hdb, 0, query);
6226 ok(r == ERROR_BAD_QUERY_SYNTAX,
6227 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6229 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )\r";
6230 r = run_query(hdb, 0, query);
6231 ok(r == ERROR_BAD_QUERY_SYNTAX,
6232 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6234 query = "CREATE TABLE `\rOne` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6235 r = run_query(hdb, 0, query);
6236 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6238 query = "CREATE TABLE `Tw\ro` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6239 r = run_query(hdb, 0, query);
6240 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6242 query = "CREATE TABLE `Three\r` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6243 r = run_query(hdb, 0, query);
6244 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6246 query = "CREATE TABLE `Four` ( `A\r` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6247 r = run_query(hdb, 0, query);
6248 ok(r == ERROR_BAD_QUERY_SYNTAX,
6249 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6251 query = "CREATE TABLE `Four` ( `\rA` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6252 r = run_query(hdb, 0, query);
6253 ok(r == ERROR_BAD_QUERY_SYNTAX,
6254 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6256 query = "CREATE TABLE `Four` ( `A` CHAR(72\r) NOT NULL PRIMARY KEY `A` )";
6257 r = run_query(hdb, 0, query);
6258 ok(r == ERROR_BAD_QUERY_SYNTAX,
6259 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6261 query = "CREATE TABLE `Four` ( `A` CHAR(\r72) NOT NULL PRIMARY KEY `A` )";
6262 r = run_query(hdb, 0, query);
6263 ok(r == ERROR_BAD_QUERY_SYNTAX,
6264 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6266 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `\rA` )";
6267 r = run_query(hdb, 0, query);
6268 ok(r == ERROR_BAD_QUERY_SYNTAX,
6269 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6271 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
6272 r = run_query(hdb, 0, query);
6273 ok(r == ERROR_BAD_QUERY_SYNTAX,
6274 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6276 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
6277 r = run_query(hdb, 0, query);
6278 ok(r == ERROR_BAD_QUERY_SYNTAX,
6279 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6281 query = "SELECT * FROM `_Tables`";
6282 r = MsiDatabaseOpenView(hdb, query, &hview);
6283 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6284 r = MsiViewExecute(hview, 0);
6285 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6287 r = MsiViewFetch(hview, &hrec);
6288 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6291 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6292 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6293 ok(!lstrcmpA(buf, "\rOne"), "Expected \"\\rOne\", got \"%s\"\n", buf);
6295 MsiCloseHandle(hrec);
6297 r = MsiViewFetch(hview, &hrec);
6298 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6301 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6302 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6303 ok(!lstrcmpA(buf, "Tw\ro"), "Expected \"Tw\\ro\", got \"%s\"\n", buf);
6305 MsiCloseHandle(hrec);
6307 r = MsiViewFetch(hview, &hrec);
6308 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6311 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6312 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6313 ok(!lstrcmpA(buf, "Three\r"), "Expected \"Three\r\", got \"%s\"\n", buf);
6315 MsiCloseHandle(hrec);
6317 r = MsiViewFetch(hview, &hrec);
6318 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6320 MsiViewClose(hview);
6321 MsiCloseHandle(hview);
6323 MsiCloseHandle(hdb);
6324 DeleteFileA(msifile);
6327 static void test_noquotes(void)
6329 MSIHANDLE hdb, hview, hrec;
6335 DeleteFile(msifile);
6337 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6338 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6340 query = "CREATE TABLE Table ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6341 r = run_query(hdb, 0, query);
6342 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6344 query = "CREATE TABLE `Table` ( A CHAR(72) NOT NULL PRIMARY KEY `A` )";
6345 r = run_query(hdb, 0, query);
6346 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6348 query = "CREATE TABLE `Table2` ( `A` CHAR(72) NOT NULL PRIMARY KEY A )";
6349 r = run_query(hdb, 0, query);
6350 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6352 query = "CREATE TABLE `Table3` ( A CHAR(72) NOT NULL PRIMARY KEY A )";
6353 r = run_query(hdb, 0, query);
6354 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6356 query = "SELECT * FROM `_Tables`";
6357 r = MsiDatabaseOpenView(hdb, query, &hview);
6358 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6359 r = MsiViewExecute(hview, 0);
6360 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6362 r = MsiViewFetch(hview, &hrec);
6363 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6366 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6367 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6368 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
6370 MsiCloseHandle(hrec);
6372 r = MsiViewFetch(hview, &hrec);
6373 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6376 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6377 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6378 ok(!lstrcmpA(buf, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf);
6380 MsiCloseHandle(hrec);
6382 r = MsiViewFetch(hview, &hrec);
6383 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6386 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6387 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6388 ok(!lstrcmpA(buf, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf);
6390 MsiCloseHandle(hrec);
6392 r = MsiViewFetch(hview, &hrec);
6393 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6395 MsiViewClose(hview);
6396 MsiCloseHandle(hview);
6398 query = "SELECT * FROM `_Columns`";
6399 r = MsiDatabaseOpenView(hdb, query, &hview);
6400 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6401 r = MsiViewExecute(hview, 0);
6402 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6404 r = MsiViewFetch(hview, &hrec);
6405 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6408 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6409 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6410 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
6412 r = MsiRecordGetInteger(hrec, 2);
6413 ok(r == 1, "Expected 1, got %d\n", r);
6416 r = MsiRecordGetStringA(hrec, 3, buf, &size);
6417 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6418 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
6420 MsiCloseHandle(hrec);
6422 r = MsiViewFetch(hview, &hrec);
6423 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6426 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6427 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6428 ok(!lstrcmpA(buf, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf);
6430 r = MsiRecordGetInteger(hrec, 2);
6431 ok(r == 1, "Expected 1, got %d\n", r);
6434 r = MsiRecordGetStringA(hrec, 3, buf, &size);
6435 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6436 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
6438 MsiCloseHandle(hrec);
6440 r = MsiViewFetch(hview, &hrec);
6441 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6444 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6445 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6446 ok(!lstrcmpA(buf, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf);
6448 r = MsiRecordGetInteger(hrec, 2);
6449 ok(r == 1, "Expected 1, got %d\n", r);
6452 r = MsiRecordGetStringA(hrec, 3, buf, &size);
6453 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6454 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
6456 MsiCloseHandle(hrec);
6458 r = MsiViewFetch(hview, &hrec);
6459 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6461 MsiViewClose(hview);
6462 MsiCloseHandle(hview);
6464 query = "INSERT INTO Table ( `A` ) VALUES ( 'hi' )";
6465 r = run_query(hdb, 0, query);
6466 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6468 query = "INSERT INTO `Table` ( A ) VALUES ( 'hi' )";
6469 r = run_query(hdb, 0, query);
6470 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6472 query = "INSERT INTO `Table` ( `A` ) VALUES ( hi )";
6473 r = run_query(hdb, 0, query);
6474 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6476 query = "SELECT * FROM Table WHERE `A` = 'hi'";
6477 r = run_query(hdb, 0, query);
6478 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6480 query = "SELECT * FROM `Table` WHERE `A` = hi";
6481 r = run_query(hdb, 0, query);
6482 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6484 query = "SELECT * FROM Table";
6485 r = run_query(hdb, 0, query);
6486 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6488 query = "SELECT * FROM Table2";
6489 r = MsiDatabaseOpenView(hdb, query, &hview);
6490 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6491 r = MsiViewExecute(hview, 0);
6492 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6494 r = MsiViewFetch(hview, &hrec);
6495 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6497 MsiViewClose(hview);
6498 MsiCloseHandle(hview);
6500 query = "SELECT * FROM `Table` WHERE A = 'hi'";
6501 r = MsiDatabaseOpenView(hdb, query, &hview);
6502 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6503 r = MsiViewExecute(hview, 0);
6504 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6506 r = MsiViewFetch(hview, &hrec);
6507 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6510 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6511 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6512 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
6514 MsiCloseHandle(hrec);
6516 r = MsiViewFetch(hview, &hrec);
6517 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6519 MsiViewClose(hview);
6520 MsiCloseHandle(hview);
6521 MsiCloseHandle(hdb);
6522 DeleteFileA(msifile);
6525 static void read_file_data(LPCSTR filename, LPSTR buffer)
6530 file = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
6531 ZeroMemory(buffer, MAX_PATH);
6532 ReadFile(file, buffer, MAX_PATH, &read, NULL);
6536 static void test_forcecodepage(void)
6540 char buffer[MAX_PATH];
6543 DeleteFile(msifile);
6545 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6546 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6548 query = "SELECT * FROM `_ForceCodepage`";
6549 r = run_query(hdb, 0, query);
6550 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6552 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6553 r = run_query(hdb, 0, query);
6554 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6556 query = "SELECT * FROM `_ForceCodepage`";
6557 r = run_query(hdb, 0, query);
6558 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6560 r = MsiDatabaseCommit(hdb);
6561 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6563 query = "SELECT * FROM `_ForceCodepage`";
6564 r = run_query(hdb, 0, query);
6565 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6567 MsiCloseHandle(hdb);
6569 r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb);
6570 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6572 query = "SELECT * FROM `_ForceCodepage`";
6573 r = run_query(hdb, 0, query);
6574 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6576 r = MsiDatabaseExport(hdb, "_ForceCodepage", CURR_DIR, "forcecodepage.idt");
6577 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6579 read_file_data("forcecodepage.idt", buffer);
6580 ok(!lstrcmpA(buffer, "\r\n\r\n0\t_ForceCodepage\r\n"),
6581 "Expected \"\r\n\r\n0\t_ForceCodepage\r\n\", got \"%s\"", buffer);
6583 MsiCloseHandle(hdb);
6584 DeleteFileA(msifile);
6585 DeleteFileA("forcecodepage.idt");
6588 static void test_viewmodify_refresh(void)
6590 MSIHANDLE hdb, hview, hrec;
6592 char buffer[MAX_PATH];
6596 DeleteFile(msifile);
6598 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6599 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6601 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL, `B` INT PRIMARY KEY `A` )";
6602 r = run_query(hdb, 0, query);
6603 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6605 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hi', 1 )";
6606 r = run_query(hdb, 0, query);
6607 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6609 query = "SELECT * FROM `Table`";
6610 r = MsiDatabaseOpenView(hdb, query, &hview);
6611 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6612 r = MsiViewExecute(hview, 0);
6613 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6615 r = MsiViewFetch(hview, &hrec);
6616 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6618 query = "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hi'";
6619 r = run_query(hdb, 0, query);
6620 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6622 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
6623 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6626 r = MsiRecordGetStringA(hrec, 1, buffer, &size);
6627 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6628 ok(!lstrcmpA(buffer, "hi"), "Expected \"hi\", got \"%s\"\n", buffer);
6629 ok(size == 2, "Expected 2, got %d\n", size);
6631 r = MsiRecordGetInteger(hrec, 2);
6632 ok(r == 2, "Expected 2, got %d\n", r);
6634 MsiCloseHandle(hrec);
6635 MsiViewClose(hview);
6636 MsiCloseHandle(hview);
6638 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hello', 3 )";
6639 r = run_query(hdb, 0, query);
6640 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6642 query = "SELECT * FROM `Table` WHERE `B` = 3";
6643 r = MsiDatabaseOpenView(hdb, query, &hview);
6644 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6645 r = MsiViewExecute(hview, 0);
6646 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6648 r = MsiViewFetch(hview, &hrec);
6649 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6651 query = "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hello'";
6652 r = run_query(hdb, 0, query);
6653 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6655 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hithere', 3 )";
6656 r = run_query(hdb, 0, query);
6657 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6659 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
6660 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6663 r = MsiRecordGetStringA(hrec, 1, buffer, &size);
6664 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6665 ok(!lstrcmpA(buffer, "hello"), "Expected \"hello\", got \"%s\"\n", buffer);
6666 ok(size == 5, "Expected 5, got %d\n", size);
6668 r = MsiRecordGetInteger(hrec, 2);
6669 ok(r == 2, "Expected 2, got %d\n", r);
6671 MsiCloseHandle(hrec);
6672 MsiViewClose(hview);
6673 MsiCloseHandle(hview);
6674 MsiCloseHandle(hdb);
6675 DeleteFileA(msifile);
6678 static void test_where_viewmodify(void)
6680 MSIHANDLE hdb, hview, hrec;
6684 DeleteFile(msifile);
6686 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6687 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6689 query = "CREATE TABLE `Table` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6690 r = run_query(hdb, 0, query);
6691 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6693 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 1, 2 )";
6694 r = run_query(hdb, 0, query);
6695 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6697 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 3, 4 )";
6698 r = run_query(hdb, 0, query);
6699 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6701 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 5, 6 )";
6702 r = run_query(hdb, 0, query);
6703 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6705 /* `B` = 3 doesn't match, but the view shouldn't be executed */
6706 query = "SELECT * FROM `Table` WHERE `B` = 3";
6707 r = MsiDatabaseOpenView(hdb, query, &hview);
6708 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6710 hrec = MsiCreateRecord(2);
6711 MsiRecordSetInteger(hrec, 1, 7);
6712 MsiRecordSetInteger(hrec, 2, 8);
6714 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
6715 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6717 MsiCloseHandle(hrec);
6718 MsiViewClose(hview);
6719 MsiCloseHandle(hview);
6721 query = "SELECT * FROM `Table` WHERE `A` = 7";
6722 r = MsiDatabaseOpenView(hdb, query, &hview);
6723 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6724 r = MsiViewExecute(hview, 0);
6725 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6727 r = MsiViewFetch(hview, &hrec);
6728 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6730 r = MsiRecordGetInteger(hrec, 1);
6731 ok(r == 7, "Expected 7, got %d\n", r);
6733 r = MsiRecordGetInteger(hrec, 2);
6734 ok(r == 8, "Expected 8, got %d\n", r);
6736 MsiRecordSetInteger(hrec, 2, 9);
6738 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
6739 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6741 MsiCloseHandle(hrec);
6742 MsiViewClose(hview);
6743 MsiCloseHandle(hview);
6745 query = "SELECT * FROM `Table` WHERE `A` = 7";
6746 r = MsiDatabaseOpenView(hdb, query, &hview);
6747 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6748 r = MsiViewExecute(hview, 0);
6749 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6751 r = MsiViewFetch(hview, &hrec);
6752 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6754 r = MsiRecordGetInteger(hrec, 1);
6755 ok(r == 7, "Expected 7, got %d\n", r);
6757 r = MsiRecordGetInteger(hrec, 2);
6758 ok(r == 9, "Expected 9, got %d\n", r);
6760 query = "UPDATE `Table` SET `B` = 10 WHERE `A` = 7";
6761 r = run_query(hdb, 0, query);
6762 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6764 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
6765 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6767 r = MsiRecordGetInteger(hrec, 1);
6768 ok(r == 7, "Expected 7, got %d\n", r);
6770 r = MsiRecordGetInteger(hrec, 2);
6771 ok(r == 10, "Expected 10, got %d\n", r);
6773 MsiCloseHandle(hrec);
6774 MsiViewClose(hview);
6775 MsiCloseHandle(hview);
6776 MsiCloseHandle(hdb);
6779 static BOOL create_storage(LPCSTR name)
6781 WCHAR nameW[MAX_PATH];
6788 MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, MAX_PATH);
6789 hr = StgCreateDocfile(nameW, STGM_CREATE | STGM_READWRITE |
6790 STGM_DIRECT | STGM_SHARE_EXCLUSIVE, 0, &stg);
6794 hr = IStorage_CreateStream(stg, nameW, STGM_WRITE | STGM_SHARE_EXCLUSIVE,
6799 hr = IStream_Write(stm, "stgdata", 8, &count);
6804 IStream_Release(stm);
6805 IStorage_Release(stg);
6810 static void test_storages_table(void)
6812 MSIHANDLE hdb, hview, hrec;
6813 IStorage *stg, *inner;
6815 char file[MAX_PATH];
6817 WCHAR name[MAX_PATH];
6824 ok(hdb, "failed to create db\n");
6826 r = MsiDatabaseCommit(hdb);
6827 ok(r == ERROR_SUCCESS , "Failed to commit database\n");
6829 MsiCloseHandle(hdb);
6831 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb);
6832 ok(r == ERROR_SUCCESS , "Failed to open database\n");
6834 /* check the column types */
6835 hrec = get_column_info(hdb, "SELECT * FROM `_Storages`", MSICOLINFO_TYPES);
6836 ok(hrec, "failed to get column info hrecord\n");
6837 ok(check_record(hrec, 1, "s62"), "wrong hrecord type\n");
6838 ok(check_record(hrec, 2, "V0"), "wrong hrecord type\n");
6840 MsiCloseHandle(hrec);
6842 /* now try the names */
6843 hrec = get_column_info(hdb, "SELECT * FROM `_Storages`", MSICOLINFO_NAMES);
6844 ok(hrec, "failed to get column info hrecord\n");
6845 ok(check_record(hrec, 1, "Name"), "wrong hrecord type\n");
6846 ok(check_record(hrec, 2, "Data"), "wrong hrecord type\n");
6848 MsiCloseHandle(hrec);
6850 create_storage("storage.bin");
6852 hrec = MsiCreateRecord(2);
6853 MsiRecordSetString(hrec, 1, "stgname");
6855 r = MsiRecordSetStream(hrec, 2, "storage.bin");
6856 ok(r == ERROR_SUCCESS, "Failed to add stream data to the hrecord: %d\n", r);
6858 DeleteFileA("storage.bin");
6860 query = "INSERT INTO `_Storages` (`Name`, `Data`) VALUES (?, ?)";
6861 r = MsiDatabaseOpenView(hdb, query, &hview);
6862 ok(r == ERROR_SUCCESS, "Failed to open database hview: %d\n", r);
6864 r = MsiViewExecute(hview, hrec);
6865 ok(r == ERROR_SUCCESS, "Failed to execute hview: %d\n", r);
6867 MsiCloseHandle(hrec);
6868 MsiViewClose(hview);
6869 MsiCloseHandle(hview);
6871 query = "SELECT `Name`, `Data` FROM `_Storages`";
6872 r = MsiDatabaseOpenView(hdb, query, &hview);
6873 ok(r == ERROR_SUCCESS, "Failed to open database hview: %d\n", r);
6875 r = MsiViewExecute(hview, 0);
6876 ok(r == ERROR_SUCCESS, "Failed to execute hview: %d\n", r);
6878 r = MsiViewFetch(hview, &hrec);
6879 ok(r == ERROR_SUCCESS, "Failed to fetch hrecord: %d\n", r);
6882 r = MsiRecordGetString(hrec, 1, file, &size);
6883 ok(r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
6884 ok(!lstrcmp(file, "stgname"), "Expected \"stgname\", got \"%s\"\n", file);
6887 lstrcpyA(buf, "apple");
6888 r = MsiRecordReadStream(hrec, 2, buf, &size);
6889 ok(r == ERROR_INVALID_DATA, "Expected ERROR_INVALID_DATA, got %d\n", r);
6890 ok(!lstrcmp(buf, "apple"), "Expected buf to be unchanged, got %s\n", buf);
6891 ok(size == 0, "Expected 0, got %d\n", size);
6893 MsiCloseHandle(hrec);
6895 r = MsiViewFetch(hview, &hrec);
6896 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6898 MsiViewClose(hview);
6899 MsiCloseHandle(hview);
6901 MsiDatabaseCommit(hdb);
6902 MsiCloseHandle(hdb);
6904 MultiByteToWideChar(CP_ACP, 0, msifile, -1, name, MAX_PATH);
6905 hr = StgOpenStorage(name, NULL, STGM_DIRECT | STGM_READ |
6906 STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
6907 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
6908 ok(stg != NULL, "Expected non-NULL storage\n");
6910 MultiByteToWideChar(CP_ACP, 0, "stgname", -1, name, MAX_PATH);
6911 hr = IStorage_OpenStorage(stg, name, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE,
6913 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
6914 ok(inner != NULL, "Expected non-NULL storage\n");
6916 MultiByteToWideChar(CP_ACP, 0, "storage.bin", -1, name, MAX_PATH);
6917 hr = IStorage_OpenStream(inner, name, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
6918 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
6919 ok(stm != NULL, "Expected non-NULL stream\n");
6921 hr = IStream_Read(stm, buf, MAX_PATH, &size);
6922 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
6923 ok(size == 8, "Expected 8, got %d\n", size);
6924 ok(!lstrcmpA(buf, "stgdata"), "Expected \"stgdata\", got \"%s\"\n", buf);
6926 IStream_Release(stm);
6927 IStorage_Release(inner);
6929 IStorage_Release(stg);
6930 DeleteFileA(msifile);
6933 static void test_dbtopackage(void)
6935 MSIHANDLE hdb, hpkg;
6941 /* create an empty database, transact mode */
6942 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6943 ok(r == ERROR_SUCCESS, "Failed to create database\n");
6945 set_summary_info(hdb);
6947 r = create_directory_table(hdb);
6948 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6950 r = create_custom_action_table(hdb);
6951 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6953 r = add_custom_action_entry(hdb, "'SetProp', 51, 'MYPROP', 'grape'");
6954 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6956 sprintf(package, "#%i", hdb);
6957 r = MsiOpenPackage(package, &hpkg);
6958 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6960 /* property is not set yet */
6962 lstrcpyA(buf, "kiwi");
6963 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
6964 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6965 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
6966 ok(size == 0, "Expected 0, got %d\n", size);
6968 /* run the custom action to set the property */
6969 r = MsiDoAction(hpkg, "SetProp");
6970 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6972 /* property is now set */
6974 lstrcpyA(buf, "kiwi");
6975 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
6976 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6977 ok(!lstrcmpA(buf, "grape"), "Expected \"grape\", got \"%s\"\n", buf);
6978 ok(size == 5, "Expected 5, got %d\n", size);
6980 MsiCloseHandle(hpkg);
6982 /* reset the package */
6983 r = MsiOpenPackage(package, &hpkg);
6984 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6986 /* property is not set anymore */
6988 lstrcpyA(buf, "kiwi");
6989 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
6990 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6993 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
6994 ok(size == 0, "Expected 0, got %d\n", size);
6997 MsiCloseHandle(hdb);
6998 MsiCloseHandle(hpkg);
7000 /* create an empty database, direct mode */
7001 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATEDIRECT, &hdb);
7002 ok(r == ERROR_SUCCESS, "Failed to create database\n");
7004 set_summary_info(hdb);
7006 r = create_directory_table(hdb);
7007 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7009 r = create_custom_action_table(hdb);
7010 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7012 r = add_custom_action_entry(hdb, "'SetProp', 51, 'MYPROP', 'grape'");
7013 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7015 sprintf(package, "#%i", hdb);
7016 r = MsiOpenPackage(package, &hpkg);
7017 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7019 /* property is not set yet */
7021 lstrcpyA(buf, "kiwi");
7022 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7023 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7024 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7025 ok(size == 0, "Expected 0, got %d\n", size);
7027 /* run the custom action to set the property */
7028 r = MsiDoAction(hpkg, "SetProp");
7029 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7031 /* property is now set */
7033 lstrcpyA(buf, "kiwi");
7034 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7035 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7036 ok(!lstrcmpA(buf, "grape"), "Expected \"grape\", got \"%s\"\n", buf);
7037 ok(size == 5, "Expected 5, got %d\n", size);
7039 MsiCloseHandle(hpkg);
7041 /* reset the package */
7042 r = MsiOpenPackage(package, &hpkg);
7043 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7045 /* property is not set anymore */
7047 lstrcpyA(buf, "kiwi");
7048 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7049 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7052 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7053 ok(size == 0, "Expected 0, got %d\n", size);
7056 MsiCloseHandle(hdb);
7057 MsiCloseHandle(hpkg);
7058 DeleteFileA(msifile);
7061 static void test_droptable(void)
7063 MSIHANDLE hdb, hview, hrec;
7069 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7070 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7072 query = "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7073 r = run_query(hdb, 0, query);
7074 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7076 query = "SELECT * FROM `One`";
7077 r = do_query(hdb, query, &hrec);
7078 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7080 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7081 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7082 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7083 r = MsiViewExecute(hview, 0);
7084 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7086 r = MsiViewFetch(hview, &hrec);
7087 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7090 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7091 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7092 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7094 MsiCloseHandle(hrec);
7095 MsiViewClose(hview);
7096 MsiCloseHandle(hview);
7098 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7099 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7100 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7101 r = MsiViewExecute(hview, 0);
7102 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7104 r = MsiViewFetch(hview, &hrec);
7105 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7108 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7109 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7110 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7112 r = MsiRecordGetInteger(hrec, 2);
7113 ok(r == 1, "Expected 1, got %d\n", r);
7116 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7117 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7118 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
7120 MsiCloseHandle(hrec);
7122 r = MsiViewFetch(hview, &hrec);
7123 ok(r == ERROR_NO_MORE_ITEMS,
7124 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7126 MsiViewClose(hview);
7127 MsiCloseHandle(hview);
7129 query = "DROP `One`";
7130 r = run_query(hdb, 0, query);
7131 ok(r == ERROR_BAD_QUERY_SYNTAX,
7132 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7134 query = "DROP TABLE";
7135 r = run_query(hdb, 0, query);
7136 ok(r == ERROR_BAD_QUERY_SYNTAX,
7137 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7139 query = "DROP TABLE `One`";
7141 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7142 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7143 r = MsiViewExecute(hview, 0);
7144 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7146 r = MsiViewFetch(hview, &hrec);
7147 ok(r == ERROR_FUNCTION_FAILED,
7148 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
7150 MsiViewClose(hview);
7151 MsiCloseHandle(hview);
7153 query = "SELECT * FROM `IDontExist`";
7154 r = do_query(hdb, query, &hrec);
7155 ok(r == ERROR_BAD_QUERY_SYNTAX,
7156 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7158 query = "SELECT * FROM `One`";
7159 r = do_query(hdb, query, &hrec);
7160 ok(r == ERROR_BAD_QUERY_SYNTAX,
7161 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7163 query = "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7164 r = run_query(hdb, 0, query);
7165 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7167 query = "DROP TABLE One";
7168 r = run_query(hdb, 0, query);
7169 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7171 query = "SELECT * FROM `One`";
7172 r = do_query(hdb, query, &hrec);
7173 ok(r == ERROR_BAD_QUERY_SYNTAX,
7174 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7176 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7177 r = do_query(hdb, query, &hrec);
7178 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7180 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7181 r = do_query(hdb, query, &hrec);
7182 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7184 query = "CREATE TABLE `One` ( `B` INT, `C` INT PRIMARY KEY `B` )";
7185 r = run_query(hdb, 0, query);
7186 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7188 query = "SELECT * FROM `One`";
7189 r = do_query(hdb, query, &hrec);
7190 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7192 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7193 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7194 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7195 r = MsiViewExecute(hview, 0);
7196 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7198 r = MsiViewFetch(hview, &hrec);
7199 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7202 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7203 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7204 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7206 MsiCloseHandle(hrec);
7207 MsiViewClose(hview);
7208 MsiCloseHandle(hview);
7210 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7211 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7212 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7213 r = MsiViewExecute(hview, 0);
7214 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7216 r = MsiViewFetch(hview, &hrec);
7217 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7220 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7221 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7222 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7224 r = MsiRecordGetInteger(hrec, 2);
7225 ok(r == 1, "Expected 1, got %d\n", r);
7228 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7229 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7230 ok(!lstrcmpA(buf, "B"), "Expected \"B\", got \"%s\"\n", buf);
7232 MsiCloseHandle(hrec);
7234 r = MsiViewFetch(hview, &hrec);
7235 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7238 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7239 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7240 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7242 r = MsiRecordGetInteger(hrec, 2);
7243 ok(r == 2, "Expected 2, got %d\n", r);
7246 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7247 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7248 ok(!lstrcmpA(buf, "C"), "Expected \"C\", got \"%s\"\n", buf);
7250 MsiCloseHandle(hrec);
7252 r = MsiViewFetch(hview, &hrec);
7253 ok(r == ERROR_NO_MORE_ITEMS,
7254 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7256 MsiViewClose(hview);
7257 MsiCloseHandle(hview);
7259 query = "DROP TABLE One";
7260 r = run_query(hdb, 0, query);
7261 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7263 query = "SELECT * FROM `One`";
7264 r = do_query(hdb, query, &hrec);
7265 ok(r == ERROR_BAD_QUERY_SYNTAX,
7266 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7268 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7269 r = do_query(hdb, query, &hrec);
7270 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7272 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7273 r = do_query(hdb, query, &hrec);
7274 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7276 MsiCloseHandle(hdb);
7277 DeleteFileA(msifile);
7280 static void test_dbmerge(void)
7282 MSIHANDLE hdb, href, hview, hrec;
7288 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7289 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7291 r = MsiOpenDatabase("refdb.msi", MSIDBOPEN_CREATE, &href);
7292 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7294 /* hDatabase is invalid */
7295 r = MsiDatabaseMergeA(0, href, "MergeErrors");
7296 ok(r == ERROR_INVALID_HANDLE,
7297 "Expected ERROR_INVALID_HANDLE, got %d\n", r);
7299 /* hDatabaseMerge is invalid */
7300 r = MsiDatabaseMergeA(hdb, 0, "MergeErrors");
7301 ok(r == ERROR_INVALID_HANDLE,
7302 "Expected ERROR_INVALID_HANDLE, got %d\n", r);
7304 /* szTableName is NULL */
7305 r = MsiDatabaseMergeA(hdb, href, NULL);
7306 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7308 /* szTableName is empty */
7309 r = MsiDatabaseMergeA(hdb, href, "");
7310 ok(r == ERROR_INVALID_TABLE, "Expected ERROR_INVALID_TABLE, got %d\n", r);
7312 /* both DBs empty, szTableName is valid */
7313 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7314 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7316 query = "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7317 r = run_query(hdb, 0, query);
7318 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7320 query = "CREATE TABLE `One` ( `A` CHAR(72) PRIMARY KEY `A` )";
7321 r = run_query(href, 0, query);
7322 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7324 /* column types don't match */
7325 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7326 ok(r == ERROR_DATATYPE_MISMATCH,
7327 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7329 /* nothing in MergeErrors */
7330 query = "SELECT * FROM `MergeErrors`";
7331 r = do_query(hdb, query, &hrec);
7332 ok(r == ERROR_BAD_QUERY_SYNTAX,
7333 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7335 query = "DROP TABLE `One`";
7336 r = run_query(hdb, 0, query);
7337 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7339 query = "DROP TABLE `One`";
7340 r = run_query(href, 0, query);
7341 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7343 query = "CREATE TABLE `One` ( "
7346 "`C` CHAR(64) LOCALIZABLE, "
7348 "`E` CHAR(72) NOT NULL, "
7349 "`F` CHAR(56) NOT NULL, "
7350 "`G` CHAR(64) NOT NULL LOCALIZABLE, "
7351 "`H` LONGCHAR NOT NULL "
7352 "PRIMARY KEY `A` )";
7353 r = run_query(hdb, 0, query);
7354 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7356 query = "CREATE TABLE `One` ( "
7361 "`E` CHAR(64) NOT NULL, "
7362 "`F` CHAR(64) NOT NULL, "
7363 "`G` CHAR(64) NOT NULL, "
7364 "`H` CHAR(64) NOT NULL "
7365 "PRIMARY KEY `A` )";
7366 r = run_query(href, 0, query);
7367 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7369 /* column sting types don't match exactly */
7370 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7371 ok(r == ERROR_SUCCESS,
7372 "Expected ERROR_SUCCESS, got %d\n", r);
7374 /* nothing in MergeErrors */
7375 query = "SELECT * FROM `MergeErrors`";
7376 r = do_query(hdb, query, &hrec);
7377 ok(r == ERROR_BAD_QUERY_SYNTAX,
7378 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7380 query = "DROP TABLE `One`";
7381 r = run_query(hdb, 0, query);
7382 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7384 query = "DROP TABLE `One`";
7385 r = run_query(href, 0, query);
7386 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7388 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7389 r = run_query(hdb, 0, query);
7390 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7392 query = "CREATE TABLE `One` ( `A` INT, `C` INT PRIMARY KEY `A` )";
7393 r = run_query(href, 0, query);
7394 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7396 /* column names don't match */
7397 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7398 ok(r == ERROR_DATATYPE_MISMATCH,
7399 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7401 /* nothing in MergeErrors */
7402 query = "SELECT * FROM `MergeErrors`";
7403 r = do_query(hdb, query, &hrec);
7404 ok(r == ERROR_BAD_QUERY_SYNTAX,
7405 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7407 query = "DROP TABLE `One`";
7408 r = run_query(hdb, 0, query);
7409 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7411 query = "DROP TABLE `One`";
7412 r = run_query(href, 0, query);
7413 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7415 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7416 r = run_query(hdb, 0, query);
7417 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7419 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `B` )";
7420 r = run_query(href, 0, query);
7421 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7423 /* primary keys don't match */
7424 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7425 ok(r == ERROR_DATATYPE_MISMATCH,
7426 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7428 /* nothing in MergeErrors */
7429 query = "SELECT * FROM `MergeErrors`";
7430 r = do_query(hdb, query, &hrec);
7431 ok(r == ERROR_BAD_QUERY_SYNTAX,
7432 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7434 query = "DROP TABLE `One`";
7435 r = run_query(hdb, 0, query);
7436 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7438 query = "DROP TABLE `One`";
7439 r = run_query(href, 0, query);
7440 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7442 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7443 r = run_query(hdb, 0, query);
7444 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7446 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A`, `B` )";
7447 r = run_query(href, 0, query);
7448 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7450 /* number of primary keys doesn't match */
7451 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7452 ok(r == ERROR_DATATYPE_MISMATCH,
7453 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7455 /* nothing in MergeErrors */
7456 query = "SELECT * FROM `MergeErrors`";
7457 r = do_query(hdb, query, &hrec);
7458 ok(r == ERROR_BAD_QUERY_SYNTAX,
7459 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7461 query = "DROP TABLE `One`";
7462 r = run_query(hdb, 0, query);
7463 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7465 query = "DROP TABLE `One`";
7466 r = run_query(href, 0, query);
7467 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7469 query = "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
7470 r = run_query(hdb, 0, query);
7471 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7473 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7474 r = run_query(href, 0, query);
7475 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7477 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
7478 r = run_query(href, 0, query);
7479 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7481 /* number of columns doesn't match */
7482 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7483 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7485 query = "SELECT * FROM `One`";
7486 r = do_query(hdb, query, &hrec);
7487 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7489 r = MsiRecordGetInteger(hrec, 1);
7490 ok(r == 1, "Expected 1, got %d\n", r);
7492 r = MsiRecordGetInteger(hrec, 2);
7493 ok(r == 2, "Expected 2, got %d\n", r);
7495 r = MsiRecordGetInteger(hrec, 3);
7496 ok(r == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", r);
7498 MsiCloseHandle(hrec);
7500 /* nothing in MergeErrors */
7501 query = "SELECT * FROM `MergeErrors`";
7502 r = do_query(hdb, query, &hrec);
7503 ok(r == ERROR_BAD_QUERY_SYNTAX,
7504 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7506 query = "DROP TABLE `One`";
7507 r = run_query(hdb, 0, query);
7508 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7510 query = "DROP TABLE `One`";
7511 r = run_query(href, 0, query);
7512 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7514 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7515 r = run_query(hdb, 0, query);
7516 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7518 query = "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
7519 r = run_query(href, 0, query);
7520 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7522 query = "INSERT INTO `One` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
7523 r = run_query(href, 0, query);
7524 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7526 /* number of columns doesn't match */
7527 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7528 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7530 query = "SELECT * FROM `One`";
7531 r = do_query(hdb, query, &hrec);
7532 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7534 r = MsiRecordGetInteger(hrec, 1);
7535 ok(r == 1, "Expected 1, got %d\n", r);
7537 r = MsiRecordGetInteger(hrec, 2);
7538 ok(r == 2, "Expected 2, got %d\n", r);
7540 r = MsiRecordGetInteger(hrec, 3);
7541 ok(r == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", r);
7543 MsiCloseHandle(hrec);
7545 /* nothing in MergeErrors */
7546 query = "SELECT * FROM `MergeErrors`";
7547 r = do_query(hdb, query, &hrec);
7548 ok(r == ERROR_BAD_QUERY_SYNTAX,
7549 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7551 query = "DROP TABLE `One`";
7552 r = run_query(hdb, 0, query);
7553 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7555 query = "DROP TABLE `One`";
7556 r = run_query(href, 0, query);
7557 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7559 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7560 r = run_query(hdb, 0, query);
7561 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7563 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 1 )";
7564 r = run_query(hdb, 0, query);
7565 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7567 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 2 )";
7568 r = run_query(hdb, 0, query);
7569 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7571 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7572 r = run_query(href, 0, query);
7573 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7575 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
7576 r = run_query(href, 0, query);
7577 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7579 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 3 )";
7580 r = run_query(href, 0, query);
7581 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7583 /* primary keys match, rows do not */
7584 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7585 ok(r == ERROR_FUNCTION_FAILED,
7586 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
7588 /* nothing in MergeErrors */
7589 query = "SELECT * FROM `MergeErrors`";
7590 r = do_query(hdb, query, &hrec);
7591 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7594 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7595 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7596 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7598 r = MsiRecordGetInteger(hrec, 2);
7599 ok(r == 2, "Expected 2, got %d\n", r);
7601 MsiCloseHandle(hrec);
7603 r = MsiDatabaseOpenViewA(hdb, "SELECT * FROM `MergeErrors`", &hview);
7604 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7606 r = MsiViewGetColumnInfo(hview, MSICOLINFO_NAMES, &hrec);
7607 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7610 r = MsiRecordGetString(hrec, 1, buf, &size);
7611 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
7614 r = MsiRecordGetString(hrec, 2, buf, &size);
7615 ok(!lstrcmpA(buf, "NumRowMergeConflicts"),
7616 "Expected \"NumRowMergeConflicts\", got \"%s\"\n", buf);
7618 MsiCloseHandle(hrec);
7620 r = MsiViewGetColumnInfo(hview, MSICOLINFO_TYPES, &hrec);
7621 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7624 r = MsiRecordGetString(hrec, 1, buf, &size);
7625 ok(!lstrcmpA(buf, "s255"), "Expected \"s255\", got \"%s\"\n", buf);
7628 r = MsiRecordGetString(hrec, 2, buf, &size);
7629 ok(!lstrcmpA(buf, "i2"), "Expected \"i2\", got \"%s\"\n", buf);
7631 MsiCloseHandle(hrec);
7632 MsiViewClose(hview);
7633 MsiCloseHandle(hview);
7635 query = "DROP TABLE `MergeErrors`";
7636 r = run_query(hdb, 0, query);
7637 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7639 query = "DROP TABLE `One`";
7640 r = run_query(hdb, 0, query);
7641 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7643 query = "DROP TABLE `One`";
7644 r = run_query(href, 0, query);
7645 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7647 query = "CREATE TABLE `One` ( `A` INT, `B` CHAR(72) PRIMARY KEY `A` )";
7648 r = run_query(href, 0, query);
7649 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7651 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
7652 r = run_query(href, 0, query);
7653 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7655 /* table from merged database is not in target database */
7656 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7657 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7659 query = "SELECT * FROM `One`";
7660 r = do_query(hdb, query, &hrec);
7661 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7663 r = MsiRecordGetInteger(hrec, 1);
7664 ok(r == 1, "Expected 1, got %d\n", r);
7667 r = MsiRecordGetStringA(hrec, 2, buf, &size);
7668 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7669 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
7671 MsiCloseHandle(hrec);
7673 /* nothing in MergeErrors */
7674 query = "SELECT * FROM `MergeErrors`";
7675 r = do_query(hdb, query, &hrec);
7676 ok(r == ERROR_BAD_QUERY_SYNTAX,
7677 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7679 query = "DROP TABLE `One`";
7680 r = run_query(hdb, 0, query);
7681 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7683 query = "DROP TABLE `One`";
7684 r = run_query(href, 0, query);
7685 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7687 query = "CREATE TABLE `One` ( "
7688 "`A` CHAR(72), `B` INT PRIMARY KEY `A` )";
7689 r = run_query(hdb, 0, query);
7690 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7692 query = "CREATE TABLE `One` ( "
7693 "`A` CHAR(72), `B` INT PRIMARY KEY `A` )";
7694 r = run_query(href, 0, query);
7695 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7697 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 'hi', 1 )";
7698 r = run_query(href, 0, query);
7699 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7701 /* primary key is string */
7702 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7703 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7705 query = "SELECT * FROM `One`";
7706 r = do_query(hdb, query, &hrec);
7707 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7710 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7711 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7712 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
7714 r = MsiRecordGetInteger(hrec, 2);
7715 ok(r == 1, "Expected 1, got %d\n", r);
7717 MsiCloseHandle(hrec);
7719 /* nothing in MergeErrors */
7720 query = "SELECT * FROM `MergeErrors`";
7721 r = do_query(hdb, query, &hrec);
7722 ok(r == ERROR_BAD_QUERY_SYNTAX,
7723 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7725 create_file_data("codepage.idt", "\r\n\r\n850\t_ForceCodepage\r\n", 0);
7727 GetCurrentDirectoryA(MAX_PATH, buf);
7728 r = MsiDatabaseImportA(hdb, buf, "codepage.idt");
7731 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7734 query = "DROP TABLE `One`";
7735 r = run_query(hdb, 0, query);
7736 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7738 query = "DROP TABLE `One`";
7739 r = run_query(href, 0, query);
7740 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7742 query = "CREATE TABLE `One` ( "
7743 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
7744 r = run_query(hdb, 0, query);
7745 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7747 query = "CREATE TABLE `One` ( "
7748 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
7749 r = run_query(href, 0, query);
7750 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7752 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
7753 r = run_query(href, 0, query);
7754 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7756 /* code page does not match */
7757 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7758 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7760 query = "SELECT * FROM `One`";
7761 r = do_query(hdb, query, &hrec);
7762 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7764 r = MsiRecordGetInteger(hrec, 1);
7765 ok(r == 1, "Expected 1, got %d\n", r);
7768 r = MsiRecordGetStringA(hrec, 2, buf, &size);
7769 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7770 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
7772 MsiCloseHandle(hrec);
7774 /* nothing in MergeErrors */
7775 query = "SELECT * FROM `MergeErrors`";
7776 r = do_query(hdb, query, &hrec);
7777 ok(r == ERROR_BAD_QUERY_SYNTAX,
7778 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7780 query = "DROP TABLE `One`";
7781 r = run_query(hdb, 0, query);
7782 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7784 query = "DROP TABLE `One`";
7785 r = run_query(href, 0, query);
7786 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7788 query = "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
7789 r = run_query(hdb, 0, query);
7790 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7792 query = "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
7793 r = run_query(href, 0, query);
7794 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7796 create_file("binary.dat");
7797 hrec = MsiCreateRecord(1);
7798 MsiRecordSetStreamA(hrec, 1, "binary.dat");
7800 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, ? )";
7801 r = run_query(href, hrec, query);
7802 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7804 MsiCloseHandle(hrec);
7806 /* binary data to merge */
7807 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7808 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7810 query = "SELECT * FROM `One`";
7811 r = do_query(hdb, query, &hrec);
7812 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7814 r = MsiRecordGetInteger(hrec, 1);
7815 ok(r == 1, "Expected 1, got %d\n", r);
7818 ZeroMemory(buf, MAX_PATH);
7819 r = MsiRecordReadStream(hrec, 2, buf, &size);
7820 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7821 ok(!lstrcmpA(buf, "binary.dat\n"),
7822 "Expected \"binary.dat\\n\", got \"%s\"\n", buf);
7824 MsiCloseHandle(hrec);
7826 /* nothing in MergeErrors */
7827 query = "SELECT * FROM `MergeErrors`";
7828 r = do_query(hdb, query, &hrec);
7829 ok(r == ERROR_BAD_QUERY_SYNTAX,
7830 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7832 query = "DROP TABLE `One`";
7833 r = run_query(hdb, 0, query);
7834 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7836 query = "DROP TABLE `One`";
7837 r = run_query(href, 0, query);
7838 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7840 query = "CREATE TABLE `One` ( `A` INT, `B` CHAR(72) PRIMARY KEY `A` )";
7841 r = run_query(hdb, 0, query);
7842 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7843 r = run_query(href, 0, query);
7844 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7846 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'foo' )";
7847 r = run_query(href, 0, query);
7848 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7850 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 'bar' )";
7851 r = run_query(href, 0, query);
7852 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7854 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7855 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7857 query = "SELECT * FROM `One`";
7858 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7859 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7860 r = MsiViewExecute(hview, 0);
7861 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7863 r = MsiViewFetch(hview, &hrec);
7864 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7866 r = MsiRecordGetInteger(hrec, 1);
7867 ok(r == 1, "Expected 1, got %d\n", r);
7870 r = MsiRecordGetStringA(hrec, 2, buf, &size);
7871 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7872 ok(!lstrcmpA(buf, "foo"), "Expected \"foo\", got \"%s\"\n", buf);
7874 MsiCloseHandle(hrec);
7876 r = MsiViewFetch(hview, &hrec);
7877 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7879 r = MsiRecordGetInteger(hrec, 1);
7880 ok(r == 2, "Expected 2, got %d\n", r);
7883 r = MsiRecordGetStringA(hrec, 2, buf, &size);
7884 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7885 ok(!lstrcmpA(buf, "bar"), "Expected \"bar\", got \"%s\"\n", buf);
7887 MsiCloseHandle(hrec);
7889 r = MsiViewFetch(hview, &hrec);
7890 ok(r == ERROR_NO_MORE_ITEMS,
7891 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7893 MsiViewClose(hview);
7894 MsiCloseHandle(hview);
7896 MsiCloseHandle(hdb);
7897 MsiCloseHandle(href);
7898 DeleteFileA(msifile);
7899 DeleteFileA("refdb.msi");
7900 DeleteFileA("codepage.idt");
7901 DeleteFileA("binary.dat");
7904 UINT ordervals[6][3] =
7906 { MSI_NULL_INTEGER, 12, 13 },
7910 { 10, 11, MSI_NULL_INTEGER },
7911 { 14, MSI_NULL_INTEGER, 15 }
7914 static void test_insertorder(void)
7916 MSIHANDLE hdb, view, rec;
7922 ok(hdb, "failed to create db\n");
7924 query = "CREATE TABLE `T` ( `A` SHORT, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
7925 r = run_query(hdb, 0, query);
7926 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7928 query = "INSERT INTO `T` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
7929 r = run_query(hdb, 0, query);
7930 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7932 query = "INSERT INTO `T` ( `B`, `C`, `A` ) VALUES ( 4, 5, 6 )";
7933 r = run_query(hdb, 0, query);
7934 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7936 query = "INSERT INTO `T` ( `C`, `A`, `B` ) VALUES ( 7, 8, 9 )";
7937 r = run_query(hdb, 0, query);
7938 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7940 query = "INSERT INTO `T` ( `A`, `B` ) VALUES ( 10, 11 )";
7941 r = run_query(hdb, 0, query);
7942 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7944 query = "INSERT INTO `T` ( `B`, `C` ) VALUES ( 12, 13 )";
7945 r = run_query(hdb, 0, query);
7946 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7948 /* fails because the primary key already
7949 * has an MSI_NULL_INTEGER value set above
7951 query = "INSERT INTO `T` ( `C` ) VALUES ( 14 )";
7952 r = run_query(hdb, 0, query);
7953 ok(r == ERROR_FUNCTION_FAILED,
7954 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
7956 /* replicate the error where primary key is set twice */
7957 query = "INSERT INTO `T` ( `A`, `C` ) VALUES ( 1, 14 )";
7958 r = run_query(hdb, 0, query);
7959 ok(r == ERROR_FUNCTION_FAILED,
7960 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
7962 query = "INSERT INTO `T` ( `A`, `C` ) VALUES ( 14, 15 )";
7963 r = run_query(hdb, 0, query);
7964 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7966 query = "INSERT INTO `T` VALUES ( 16 )";
7967 r = run_query(hdb, 0, query);
7968 ok(r == ERROR_BAD_QUERY_SYNTAX,
7969 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7971 query = "INSERT INTO `T` VALUES ( 17, 18 )";
7972 r = run_query(hdb, 0, query);
7973 ok(r == ERROR_BAD_QUERY_SYNTAX,
7974 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7976 query = "INSERT INTO `T` VALUES ( 19, 20, 21 )";
7977 r = run_query(hdb, 0, query);
7978 ok(r == ERROR_BAD_QUERY_SYNTAX,
7979 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7981 query = "SELECT * FROM `T`";
7982 r = MsiDatabaseOpenView(hdb, query, &view);
7983 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7984 r = MsiViewExecute(view, 0);
7985 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7987 for (i = 0; i < 6; i++)
7989 r = MsiViewFetch(view, &rec);
7990 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7992 r = MsiRecordGetInteger(rec, 1);
7993 ok(r == ordervals[i][0], "Expected %d, got %d\n", ordervals[i][0], r);
7995 r = MsiRecordGetInteger(rec, 2);
7996 ok(r == ordervals[i][1], "Expected %d, got %d\n", ordervals[i][1], r);
7998 r = MsiRecordGetInteger(rec, 3);
7999 ok(r == ordervals[i][2], "Expected %d, got %d\n", ordervals[i][2], r);
8001 MsiCloseHandle(rec);
8004 r = MsiViewFetch(view, &rec);
8005 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8008 MsiCloseHandle(view);
8010 query = "DELETE FROM `T` WHERE `A` IS NULL";
8011 r = run_query(hdb, 0, query);
8012 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8014 query = "INSERT INTO `T` ( `B`, `C` ) VALUES ( 12, 13 ) TEMPORARY";
8015 r = run_query(hdb, 0, query);
8016 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8018 query = "SELECT * FROM `T`";
8019 r = MsiDatabaseOpenView(hdb, query, &view);
8020 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8021 r = MsiViewExecute(view, 0);
8022 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8024 for (i = 0; i < 6; i++)
8026 r = MsiViewFetch(view, &rec);
8027 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8029 r = MsiRecordGetInteger(rec, 1);
8030 ok(r == ordervals[i][0], "Expected %d, got %d\n", ordervals[i][0], r);
8032 r = MsiRecordGetInteger(rec, 2);
8033 ok(r == ordervals[i][1], "Expected %d, got %d\n", ordervals[i][1], r);
8035 r = MsiRecordGetInteger(rec, 3);
8036 ok(r == ordervals[i][2], "Expected %d, got %d\n", ordervals[i][2], r);
8038 MsiCloseHandle(rec);
8041 r = MsiViewFetch(view, &rec);
8042 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8045 MsiCloseHandle(view);
8046 MsiCloseHandle(hdb);
8047 DeleteFileA(msifile);
8050 static void test_columnorder(void)
8052 MSIHANDLE hdb, view, rec;
8059 ok(hdb, "failed to create db\n");
8061 /* Each column is a slot:
8062 * ---------------------
8063 * | B | C | A | E | D |
8064 * ---------------------
8066 * When a column is selected as a primary key,
8067 * the column occupying the nth primary key slot is swapped
8068 * with the current position of the primary key in question:
8070 * set primary key `D`
8071 * --------------------- ---------------------
8072 * | B | C | A | E | D | -> | D | C | A | E | B |
8073 * --------------------- ---------------------
8075 * set primary key `E`
8076 * --------------------- ---------------------
8077 * | D | C | A | E | B | -> | D | E | A | C | B |
8078 * --------------------- ---------------------
8081 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL, `C` SHORT NOT NULL, "
8082 "`A` CHAR(255), `E` INT, `D` CHAR(255) NOT NULL "
8083 "PRIMARY KEY `D`, `E`)";
8084 r = run_query(hdb, 0, query);
8085 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8087 query = "SELECT * FROM `T`";
8088 r = MsiDatabaseOpenView(hdb, query, &view);
8089 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8091 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
8092 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8095 lstrcpyA(buf, "kiwi");
8096 r = MsiRecordGetString(rec, 1, buf, &sz);
8097 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8098 ok(!lstrcmpA("s255", buf), "Expected \"s255\", got \"%s\"\n", buf);
8101 lstrcpyA(buf, "kiwi");
8102 r = MsiRecordGetString(rec, 2, buf, &sz);
8103 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8104 ok(!lstrcmpA("I2", buf), "Expected \"I2\", got \"%s\"\n", buf);
8107 lstrcpyA(buf, "kiwi");
8108 r = MsiRecordGetString(rec, 3, buf, &sz);
8109 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8110 ok(!lstrcmpA("S255", buf), "Expected \"S255\", got \"%s\"\n", buf);
8113 lstrcpyA(buf, "kiwi");
8114 r = MsiRecordGetString(rec, 4, buf, &sz);
8115 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8116 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8119 lstrcpyA(buf, "kiwi");
8120 r = MsiRecordGetString(rec, 5, buf, &sz);
8121 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8122 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8124 MsiCloseHandle(rec);
8126 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
8127 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8130 lstrcpyA(buf, "kiwi");
8131 r = MsiRecordGetString(rec, 1, buf, &sz);
8132 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8133 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8136 lstrcpyA(buf, "kiwi");
8137 r = MsiRecordGetString(rec, 2, buf, &sz);
8138 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8139 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8142 lstrcpyA(buf, "kiwi");
8143 r = MsiRecordGetString(rec, 3, buf, &sz);
8144 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8145 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8148 lstrcpyA(buf, "kiwi");
8149 r = MsiRecordGetString(rec, 4, buf, &sz);
8150 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8151 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8154 lstrcpyA(buf, "kiwi");
8155 r = MsiRecordGetString(rec, 5, buf, &sz);
8156 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8157 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8159 MsiCloseHandle(rec);
8161 MsiCloseHandle(view);
8163 query = "INSERT INTO `T` ( `B`, `C`, `A`, `E`, `D` ) "
8164 "VALUES ( 1, 2, 'a', 3, 'bc' )";
8165 r = run_query(hdb, 0, query);
8166 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8168 query = "SELECT * FROM `T`";
8169 r = do_query(hdb, query, &rec);
8172 lstrcpyA(buf, "kiwi");
8173 r = MsiRecordGetString(rec, 1, buf, &sz);
8174 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8175 ok(!lstrcmpA("bc", buf), "Expected \"bc\", got \"%s\"\n", buf);
8177 r = MsiRecordGetInteger(rec, 2);
8178 ok(r == 3, "Expected 3, got %d\n", r);
8181 lstrcpyA(buf, "kiwi");
8182 r = MsiRecordGetString(rec, 3, buf, &sz);
8183 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8184 ok(!lstrcmpA("a", buf), "Expected \"a\", got \"%s\"\n", buf);
8186 r = MsiRecordGetInteger(rec, 4);
8187 ok(r == 2, "Expected 2, got %d\n", r);
8189 r = MsiRecordGetInteger(rec, 5);
8190 ok(r == 1, "Expected 1, got %d\n", r);
8192 MsiCloseHandle(rec);
8194 query = "SELECT * FROM `_Columns` WHERE `Table` = 'T'";
8195 r = MsiDatabaseOpenView(hdb, query, &view);
8196 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8197 r = MsiViewExecute(view, 0);
8198 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8200 r = MsiViewFetch(view, &rec);
8201 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8204 lstrcpyA(buf, "kiwi");
8205 r = MsiRecordGetString(rec, 1, buf, &sz);
8206 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8207 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8209 r = MsiRecordGetInteger(rec, 2);
8210 ok(r == 1, "Expected 1, got %d\n", r);
8213 lstrcpyA(buf, "kiwi");
8214 r = MsiRecordGetString(rec, 3, buf, &sz);
8215 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8216 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8218 MsiCloseHandle(rec);
8220 r = MsiViewFetch(view, &rec);
8221 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8224 lstrcpyA(buf, "kiwi");
8225 r = MsiRecordGetString(rec, 1, buf, &sz);
8226 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8227 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8229 r = MsiRecordGetInteger(rec, 2);
8230 ok(r == 2, "Expected 2, got %d\n", r);
8233 lstrcpyA(buf, "kiwi");
8234 r = MsiRecordGetString(rec, 3, buf, &sz);
8235 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8236 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8238 MsiCloseHandle(rec);
8240 r = MsiViewFetch(view, &rec);
8241 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8244 lstrcpyA(buf, "kiwi");
8245 r = MsiRecordGetString(rec, 1, buf, &sz);
8246 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8247 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8249 r = MsiRecordGetInteger(rec, 2);
8250 ok(r == 3, "Expected 3, got %d\n", r);
8253 lstrcpyA(buf, "kiwi");
8254 r = MsiRecordGetString(rec, 3, buf, &sz);
8255 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8256 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8258 MsiCloseHandle(rec);
8260 r = MsiViewFetch(view, &rec);
8261 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8264 lstrcpyA(buf, "kiwi");
8265 r = MsiRecordGetString(rec, 1, buf, &sz);
8266 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8267 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8269 r = MsiRecordGetInteger(rec, 2);
8270 ok(r == 4, "Expected 4, got %d\n", r);
8273 lstrcpyA(buf, "kiwi");
8274 r = MsiRecordGetString(rec, 3, buf, &sz);
8275 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8276 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8278 MsiCloseHandle(rec);
8280 r = MsiViewFetch(view, &rec);
8281 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8284 lstrcpyA(buf, "kiwi");
8285 r = MsiRecordGetString(rec, 1, buf, &sz);
8286 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8287 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8289 r = MsiRecordGetInteger(rec, 2);
8290 ok(r == 5, "Expected 5, got %d\n", r);
8293 lstrcpyA(buf, "kiwi");
8294 r = MsiRecordGetString(rec, 3, buf, &sz);
8295 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8296 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8298 MsiCloseHandle(rec);
8300 r = MsiViewFetch(view, &rec);
8301 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8304 MsiCloseHandle(view);
8306 query = "CREATE TABLE `Z` ( `B` SHORT NOT NULL, `C` SHORT NOT NULL, "
8307 "`A` CHAR(255), `E` INT, `D` CHAR(255) NOT NULL "
8308 "PRIMARY KEY `C`, `A`, `D`)";
8309 r = run_query(hdb, 0, query);
8310 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8312 query = "SELECT * FROM `Z`";
8313 r = MsiDatabaseOpenView(hdb, query, &view);
8314 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8316 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
8317 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8320 lstrcpyA(buf, "kiwi");
8321 r = MsiRecordGetString(rec, 1, buf, &sz);
8322 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8323 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8326 lstrcpyA(buf, "kiwi");
8327 r = MsiRecordGetString(rec, 2, buf, &sz);
8328 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8329 ok(!lstrcmpA("S255", buf), "Expected \"S255\", got \"%s\"\n", buf);
8332 lstrcpyA(buf, "kiwi");
8333 r = MsiRecordGetString(rec, 3, buf, &sz);
8334 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8335 ok(!lstrcmpA("s255", buf), "Expected \"s255\", got \"%s\"\n", buf);
8338 lstrcpyA(buf, "kiwi");
8339 r = MsiRecordGetString(rec, 4, buf, &sz);
8340 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8341 ok(!lstrcmpA("I2", buf), "Expected \"I2\", got \"%s\"\n", buf);
8344 lstrcpyA(buf, "kiwi");
8345 r = MsiRecordGetString(rec, 5, buf, &sz);
8346 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8347 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8349 MsiCloseHandle(rec);
8351 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
8352 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8355 lstrcpyA(buf, "kiwi");
8356 r = MsiRecordGetString(rec, 1, buf, &sz);
8357 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8358 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8361 lstrcpyA(buf, "kiwi");
8362 r = MsiRecordGetString(rec, 2, buf, &sz);
8363 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8364 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8367 lstrcpyA(buf, "kiwi");
8368 r = MsiRecordGetString(rec, 3, buf, &sz);
8369 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8370 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8373 lstrcpyA(buf, "kiwi");
8374 r = MsiRecordGetString(rec, 4, buf, &sz);
8375 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8376 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8379 lstrcpyA(buf, "kiwi");
8380 r = MsiRecordGetString(rec, 5, buf, &sz);
8381 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8382 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8384 MsiCloseHandle(rec);
8386 MsiCloseHandle(view);
8388 query = "INSERT INTO `Z` ( `B`, `C`, `A`, `E`, `D` ) "
8389 "VALUES ( 1, 2, 'a', 3, 'bc' )";
8390 r = run_query(hdb, 0, query);
8391 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8393 query = "SELECT * FROM `Z`";
8394 r = do_query(hdb, query, &rec);
8396 r = MsiRecordGetInteger(rec, 1);
8397 ok(r == 2, "Expected 2, got %d\n", r);
8400 lstrcpyA(buf, "kiwi");
8401 r = MsiRecordGetString(rec, 2, buf, &sz);
8402 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8403 ok(!lstrcmpA("a", buf), "Expected \"a\", got \"%s\"\n", buf);
8406 lstrcpyA(buf, "kiwi");
8407 r = MsiRecordGetString(rec, 3, buf, &sz);
8408 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8409 ok(!lstrcmpA("bc", buf), "Expected \"bc\", got \"%s\"\n", buf);
8411 r = MsiRecordGetInteger(rec, 4);
8412 ok(r == 3, "Expected 3, got %d\n", r);
8414 r = MsiRecordGetInteger(rec, 5);
8415 ok(r == 1, "Expected 1, got %d\n", r);
8417 MsiCloseHandle(rec);
8419 query = "SELECT * FROM `_Columns` WHERE `Table` = 'T'";
8420 r = MsiDatabaseOpenView(hdb, query, &view);
8421 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8422 r = MsiViewExecute(view, 0);
8423 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8425 r = MsiViewFetch(view, &rec);
8426 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8429 lstrcpyA(buf, "kiwi");
8430 r = MsiRecordGetString(rec, 1, buf, &sz);
8431 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8432 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8434 r = MsiRecordGetInteger(rec, 2);
8435 ok(r == 1, "Expected 1, got %d\n", r);
8438 lstrcpyA(buf, "kiwi");
8439 r = MsiRecordGetString(rec, 3, buf, &sz);
8440 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8441 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8443 MsiCloseHandle(rec);
8445 r = MsiViewFetch(view, &rec);
8446 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8449 lstrcpyA(buf, "kiwi");
8450 r = MsiRecordGetString(rec, 1, buf, &sz);
8451 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8452 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8454 r = MsiRecordGetInteger(rec, 2);
8455 ok(r == 2, "Expected 2, got %d\n", r);
8458 lstrcpyA(buf, "kiwi");
8459 r = MsiRecordGetString(rec, 3, buf, &sz);
8460 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8461 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8463 MsiCloseHandle(rec);
8465 r = MsiViewFetch(view, &rec);
8466 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8469 lstrcpyA(buf, "kiwi");
8470 r = MsiRecordGetString(rec, 1, buf, &sz);
8471 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8472 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8474 r = MsiRecordGetInteger(rec, 2);
8475 ok(r == 3, "Expected 3, got %d\n", r);
8478 lstrcpyA(buf, "kiwi");
8479 r = MsiRecordGetString(rec, 3, buf, &sz);
8480 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8481 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8483 MsiCloseHandle(rec);
8485 r = MsiViewFetch(view, &rec);
8486 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8489 lstrcpyA(buf, "kiwi");
8490 r = MsiRecordGetString(rec, 1, buf, &sz);
8491 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8492 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8494 r = MsiRecordGetInteger(rec, 2);
8495 ok(r == 4, "Expected 4, got %d\n", r);
8498 lstrcpyA(buf, "kiwi");
8499 r = MsiRecordGetString(rec, 3, buf, &sz);
8500 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8501 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8503 MsiCloseHandle(rec);
8505 r = MsiViewFetch(view, &rec);
8506 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8509 lstrcpyA(buf, "kiwi");
8510 r = MsiRecordGetString(rec, 1, buf, &sz);
8511 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8512 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8514 r = MsiRecordGetInteger(rec, 2);
8515 ok(r == 5, "Expected 5, got %d\n", r);
8518 lstrcpyA(buf, "kiwi");
8519 r = MsiRecordGetString(rec, 3, buf, &sz);
8520 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8521 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8523 MsiCloseHandle(rec);
8525 r = MsiViewFetch(view, &rec);
8526 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8529 MsiCloseHandle(view);
8531 MsiCloseHandle(hdb);
8532 DeleteFileA(msifile);
8539 test_msidecomposedesc();
8540 test_msibadqueries();
8542 test_viewgetcolumninfo();
8548 test_where_not_in_selected();
8551 test_binary_import();
8553 test_handle_limit();
8554 test_try_transform();
8556 test_temporary_table();
8560 test_special_tables();
8561 test_tables_order();
8563 test_select_markers();
8564 test_viewmodify_update();
8565 test_viewmodify_assign();
8567 test_viewmodify_delete();
8568 test_defaultdatabase();
8570 test_viewmodify_delete_temporary();
8573 test_carriagereturn();
8575 test_forcecodepage();
8576 test_viewmodify_refresh();
8577 test_where_viewmodify();
8578 test_storages_table();
8584 test_suminfo_import();