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-db.msi";
35 static const char *msifile2 = "winetst2-db.msi";
36 static const char *mstfile = "winetst-db.mst";
37 static const WCHAR msifileW[] = {'w','i','n','e','t','e','s','t','-','d','b','.','m','s','i',0};
39 static void test_msidatabase(void)
41 MSIHANDLE hdb = 0, hdb2 = 0;
46 res = MsiOpenDatabase( msifile, msifile2, &hdb );
47 ok( res == ERROR_OPEN_FAILED, "expected failure\n");
49 res = MsiOpenDatabase( msifile, (LPSTR) 0xff, &hdb );
50 ok( res == ERROR_INVALID_PARAMETER, "expected failure\n");
52 res = MsiCloseHandle( hdb );
53 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
55 /* create an empty database */
56 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
57 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
59 res = MsiDatabaseCommit( hdb );
60 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
62 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
64 res = MsiCloseHandle( hdb );
65 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
66 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
67 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
69 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile2 ), "database should exist\n");
71 res = MsiDatabaseCommit( hdb2 );
72 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
74 res = MsiCloseHandle( hdb2 );
75 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
77 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
78 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
80 res = MsiCloseHandle( hdb2 );
81 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
83 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile2 ), "uncommitted database should not exist\n");
85 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
86 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
88 res = MsiDatabaseCommit( hdb2 );
89 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
91 res = MsiCloseHandle( hdb2 );
92 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
94 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile2 ), "committed database should exist\n");
96 res = MsiOpenDatabase( msifile, MSIDBOPEN_READONLY, &hdb );
97 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
99 res = MsiCloseHandle( hdb );
100 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
102 res = MsiOpenDatabase( msifile, MSIDBOPEN_DIRECT, &hdb );
103 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
105 res = MsiCloseHandle( hdb );
106 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
108 res = MsiOpenDatabase( msifile, MSIDBOPEN_TRANSACT, &hdb );
109 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
111 res = MsiCloseHandle( hdb );
112 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
113 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
115 /* MSIDBOPEN_CREATE deletes the database if MsiCommitDatabase isn't called */
116 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
117 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
119 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
121 res = MsiCloseHandle( hdb );
122 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
124 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile ), "database should exist\n");
126 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
127 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
129 res = MsiDatabaseCommit( hdb );
130 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
132 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
134 res = MsiCloseHandle( hdb );
135 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
137 res = DeleteFile( msifile2 );
138 ok( res == TRUE, "Failed to delete database\n" );
140 res = DeleteFile( msifile );
141 ok( res == TRUE, "Failed to delete database\n" );
144 static UINT do_query(MSIHANDLE hdb, const char *query, MSIHANDLE *phrec)
152 /* open a select query */
153 r = MsiDatabaseOpenView(hdb, query, &hview);
154 if (r != ERROR_SUCCESS)
156 r = MsiViewExecute(hview, 0);
157 if (r != ERROR_SUCCESS)
159 ret = MsiViewFetch(hview, phrec);
160 r = MsiViewClose(hview);
161 if (r != ERROR_SUCCESS)
163 r = MsiCloseHandle(hview);
164 if (r != ERROR_SUCCESS)
169 static UINT run_query( MSIHANDLE hdb, MSIHANDLE hrec, const char *query )
174 r = MsiDatabaseOpenView(hdb, query, &hview);
175 if( r != ERROR_SUCCESS )
178 r = MsiViewExecute(hview, hrec);
179 if( r == ERROR_SUCCESS )
180 r = MsiViewClose(hview);
181 MsiCloseHandle(hview);
185 static UINT create_component_table( MSIHANDLE hdb )
187 return run_query( hdb, 0,
188 "CREATE TABLE `Component` ( "
189 "`Component` CHAR(72) NOT NULL, "
190 "`ComponentId` CHAR(38), "
191 "`Directory_` CHAR(72) NOT NULL, "
192 "`Attributes` SHORT NOT NULL, "
193 "`Condition` CHAR(255), "
194 "`KeyPath` CHAR(72) "
195 "PRIMARY KEY `Component`)" );
198 static UINT create_custom_action_table( MSIHANDLE hdb )
200 return run_query( hdb, 0,
201 "CREATE TABLE `CustomAction` ( "
202 "`Action` CHAR(72) NOT NULL, "
203 "`Type` SHORT NOT NULL, "
204 "`Source` CHAR(72), "
205 "`Target` CHAR(255) "
206 "PRIMARY KEY `Action`)" );
209 static UINT create_directory_table( MSIHANDLE hdb )
211 return run_query( hdb, 0,
212 "CREATE TABLE `Directory` ( "
213 "`Directory` CHAR(255) NOT NULL, "
214 "`Directory_Parent` CHAR(255), "
215 "`DefaultDir` CHAR(255) NOT NULL "
216 "PRIMARY KEY `Directory`)" );
219 static UINT create_feature_components_table( MSIHANDLE hdb )
221 return run_query( hdb, 0,
222 "CREATE TABLE `FeatureComponents` ( "
223 "`Feature_` CHAR(38) NOT NULL, "
224 "`Component_` CHAR(72) NOT NULL "
225 "PRIMARY KEY `Feature_`, `Component_` )" );
228 static UINT create_std_dlls_table( MSIHANDLE hdb )
230 return run_query( hdb, 0,
231 "CREATE TABLE `StdDlls` ( "
232 "`File` CHAR(255) NOT NULL, "
233 "`Binary_` CHAR(72) NOT NULL "
234 "PRIMARY KEY `File` )" );
237 static UINT create_binary_table( MSIHANDLE hdb )
239 return run_query( hdb, 0,
240 "CREATE TABLE `Binary` ( "
241 "`Name` CHAR(72) NOT NULL, "
242 "`Data` CHAR(72) NOT NULL "
243 "PRIMARY KEY `Name` )" );
246 #define make_add_entry(type, qtext) \
247 static UINT add##_##type##_##entry( MSIHANDLE hdb, const char *values ) \
249 char insert[] = qtext; \
252 sz = strlen(values) + sizeof insert; \
253 query = HeapAlloc(GetProcessHeap(),0,sz); \
254 sprintf(query,insert,values); \
255 r = run_query( hdb, 0, query ); \
256 HeapFree(GetProcessHeap(), 0, query); \
260 make_add_entry(component,
261 "INSERT INTO `Component` "
262 "(`Component`, `ComponentId`, `Directory_`, "
263 "`Attributes`, `Condition`, `KeyPath`) VALUES( %s )")
265 make_add_entry(custom_action,
266 "INSERT INTO `CustomAction` "
267 "(`Action`, `Type`, `Source`, `Target`) VALUES( %s )")
269 make_add_entry(feature_components,
270 "INSERT INTO `FeatureComponents` "
271 "(`Feature_`, `Component_`) VALUES( %s )")
273 make_add_entry(std_dlls,
274 "INSERT INTO `StdDlls` (`File`, `Binary_`) VALUES( %s )")
276 make_add_entry(binary,
277 "INSERT INTO `Binary` (`Name`, `Data`) VALUES( %s )")
279 static void test_msiinsert(void)
281 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
289 /* just MsiOpenDatabase should not create a file */
290 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
291 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
294 query = "CREATE TABLE `phone` ( "
295 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
297 r = MsiDatabaseOpenView(hdb, query, &hview);
298 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
299 r = MsiViewExecute(hview, 0);
300 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
301 r = MsiViewClose(hview);
302 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
303 r = MsiCloseHandle(hview);
304 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
306 /* insert a value into it */
307 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
308 "VALUES('1', 'Abe', '8675309')";
309 r = MsiDatabaseOpenView(hdb, query, &hview);
310 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
311 r = MsiViewExecute(hview, 0);
312 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
313 r = MsiViewClose(hview);
314 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
315 r = MsiCloseHandle(hview);
316 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
318 query = "SELECT * FROM `phone` WHERE `id` = 1";
319 r = do_query(hdb, query, &hrec);
320 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
322 /* check the record contains what we put in it */
323 r = MsiRecordGetFieldCount(hrec);
324 ok(r == 3, "record count wrong\n");
326 r = MsiRecordIsNull(hrec, 0);
327 ok(r == FALSE, "field 0 not null\n");
329 r = MsiRecordGetInteger(hrec, 1);
330 ok(r == 1, "field 1 contents wrong\n");
332 r = MsiRecordGetString(hrec, 2, buf, &sz);
333 ok(r == ERROR_SUCCESS, "field 2 content fetch failed\n");
334 ok(!strcmp(buf,"Abe"), "field 2 content incorrect\n");
336 r = MsiRecordGetString(hrec, 3, buf, &sz);
337 ok(r == ERROR_SUCCESS, "field 3 content fetch failed\n");
338 ok(!strcmp(buf,"8675309"), "field 3 content incorrect\n");
340 r = MsiCloseHandle(hrec);
341 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
343 /* open a select query */
345 query = "SELECT * FROM `phone` WHERE `id` >= 10";
346 r = do_query(hdb, query, &hrec);
347 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
348 ok(hrec == 0, "hrec should be null\n");
350 r = MsiCloseHandle(hrec);
351 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
353 query = "SELECT * FROM `phone` WHERE `id` < 0";
354 r = do_query(hdb, query, &hrec);
355 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
357 query = "SELECT * FROM `phone` WHERE `id` <= 0";
358 r = do_query(hdb, query, &hrec);
359 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
361 query = "SELECT * FROM `phone` WHERE `id` <> 1";
362 r = do_query(hdb, query, &hrec);
363 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
365 query = "SELECT * FROM `phone` WHERE `id` > 10";
366 r = do_query(hdb, query, &hrec);
367 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
369 /* now try a few bad INSERT xqueries */
370 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
372 r = MsiDatabaseOpenView(hdb, query, &hview);
373 ok(r == ERROR_BAD_QUERY_SYNTAX, "MsiDatabaseOpenView failed\n");
375 /* construct a record to insert */
376 hrec = MsiCreateRecord(4);
377 r = MsiRecordSetInteger(hrec, 1, 2);
378 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
379 r = MsiRecordSetString(hrec, 2, "Adam");
380 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
381 r = MsiRecordSetString(hrec, 3, "96905305");
382 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
384 /* insert another value, using a record and wildcards */
385 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
387 r = MsiDatabaseOpenView(hdb, query, &hview);
388 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
390 if (r == ERROR_SUCCESS)
392 r = MsiViewExecute(hview, hrec);
393 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
394 r = MsiViewClose(hview);
395 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
396 r = MsiCloseHandle(hview);
397 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
399 r = MsiCloseHandle(hrec);
400 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
402 r = MsiViewFetch(0, NULL);
403 ok(r == ERROR_INVALID_PARAMETER, "MsiViewFetch failed\n");
405 r = MsiDatabaseCommit(hdb);
406 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
408 r = MsiCloseHandle(hdb);
409 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
411 r = DeleteFile(msifile);
412 ok(r == TRUE, "file didn't exist after commit\n");
415 typedef UINT (WINAPI *fnMsiDecomposeDescriptorA)(LPCSTR, LPCSTR, LPSTR, LPSTR, DWORD *);
416 static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA;
418 static void test_msidecomposedesc(void)
420 char prod[MAX_FEATURE_CHARS+1], comp[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1];
426 hmod = GetModuleHandle("msi.dll");
427 pMsiDecomposeDescriptorA = (fnMsiDecomposeDescriptorA)
428 GetProcAddress(hmod, "MsiDecomposeDescriptorA");
429 if (!pMsiDecomposeDescriptorA)
432 /* test a valid feature descriptor */
433 desc = "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
435 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
436 ok(r == ERROR_SUCCESS, "returned an error\n");
437 ok(len == strlen(desc), "length was wrong\n");
438 ok(strcmp(prod,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
439 ok(strcmp(feature,"FollowTheWhiteRabbit")==0, "feature wrong\n");
440 ok(strcmp(comp,"{A7CD68DB-EF74-49C8-FBB2-A7C463B2AC24}")==0,"component wrong\n");
442 /* test an invalid feature descriptor with too many characters */
443 desc = "']gAVn-}f(ZXfeAR6.ji"
444 "ThisWillFailIfTheresMoreThanAGuidsChars>"
445 "3w2x^IGfe?CxI5heAvk.";
447 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
448 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
451 * Test a valid feature descriptor with the
452 * maximum number of characters and some trailing characters.
454 desc = "']gAVn-}f(ZXfeAR6.ji"
455 "ThisWillWorkIfTheresLTEThanAGuidsChars>"
456 "3w2x^IGfe?CxI5heAvk."
459 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
460 ok(r == ERROR_SUCCESS, "returned wrong error\n");
461 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
464 r = pMsiDecomposeDescriptorA(desc, prod, feature, NULL, &len);
465 ok(r == ERROR_SUCCESS, "returned wrong error\n");
466 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
469 r = pMsiDecomposeDescriptorA(desc, prod, NULL, NULL, &len);
470 ok(r == ERROR_SUCCESS, "returned wrong error\n");
471 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
474 r = pMsiDecomposeDescriptorA(desc, NULL, NULL, NULL, &len);
475 ok(r == ERROR_SUCCESS, "returned wrong error\n");
476 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
479 r = pMsiDecomposeDescriptorA(NULL, NULL, NULL, NULL, &len);
480 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
481 ok(len == 0, "length wrong\n");
483 r = pMsiDecomposeDescriptorA(desc, NULL, NULL, NULL, NULL);
484 ok(r == ERROR_SUCCESS, "returned wrong error\n");
487 static UINT try_query_param( MSIHANDLE hdb, LPCSTR szQuery, MSIHANDLE hrec )
492 res = MsiDatabaseOpenView( hdb, szQuery, &htab );
493 if(res == ERROR_SUCCESS )
497 r = MsiViewExecute( htab, hrec );
498 if(r != ERROR_SUCCESS )
501 r = MsiViewClose( htab );
502 if(r != ERROR_SUCCESS )
505 r = MsiCloseHandle( htab );
506 if(r != ERROR_SUCCESS )
512 static UINT try_query( MSIHANDLE hdb, LPCSTR szQuery )
514 return try_query_param( hdb, szQuery, 0 );
517 static UINT try_insert_query( MSIHANDLE hdb, LPCSTR szQuery )
522 hrec = MsiCreateRecord( 1 );
523 MsiRecordSetString( hrec, 1, "Hello");
525 r = try_query_param( hdb, szQuery, hrec );
527 MsiCloseHandle( hrec );
531 static void test_msibadqueries(void)
538 /* just MsiOpenDatabase should not create a file */
539 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
540 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
542 r = MsiDatabaseCommit( hdb );
543 ok(r == ERROR_SUCCESS , "Failed to commit database\n");
545 r = MsiCloseHandle( hdb );
546 ok(r == ERROR_SUCCESS , "Failed to close database\n");
548 /* open it readonly */
549 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb );
550 ok(r == ERROR_SUCCESS , "Failed to open database r/o\n");
552 /* add a table to it */
553 r = try_query( hdb, "select * from _Tables");
554 ok(r == ERROR_SUCCESS , "query 1 failed\n");
556 r = MsiCloseHandle( hdb );
557 ok(r == ERROR_SUCCESS , "Failed to close database r/o\n");
559 /* open it read/write */
560 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
561 ok(r == ERROR_SUCCESS , "Failed to open database r/w\n");
563 /* a bunch of test queries that fail with the native MSI */
565 r = try_query( hdb, "CREATE TABLE");
566 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2a return code\n");
568 r = try_query( hdb, "CREATE TABLE `a`");
569 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2b return code\n");
571 r = try_query( hdb, "CREATE TABLE `a` ()");
572 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2c return code\n");
574 r = try_query( hdb, "CREATE TABLE `a` (`b`)");
575 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2d return code\n");
577 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) )");
578 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2e return code\n");
580 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
581 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2f return code\n");
583 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
584 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2g return code\n");
586 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
587 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2h return code\n");
589 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
590 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2i return code\n");
592 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
593 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2j return code\n");
595 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
596 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2k return code\n");
598 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
599 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2l return code\n");
601 r = try_query( hdb, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
602 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2m return code\n");
604 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
605 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2n return code\n");
607 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
608 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2o return code\n");
610 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
611 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
613 r = try_query( hdb, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
614 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
616 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
617 ok(r == ERROR_SUCCESS , "valid query 2z failed\n");
619 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
620 ok(r == ERROR_BAD_QUERY_SYNTAX , "created same table again\n");
622 r = try_query( hdb, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
623 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
624 ok(r == ERROR_SUCCESS , "query 4 failed\n");
626 r = MsiDatabaseCommit( hdb );
627 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
629 r = try_query( hdb, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
630 "PRIMARY KEY `foo`)");
631 ok(r == ERROR_SUCCESS , "query 4 failed\n");
633 r = try_insert_query( hdb, "insert into a ( `b` ) VALUES ( ? )");
634 ok(r == ERROR_SUCCESS , "failed to insert record in db\n");
636 r = MsiDatabaseCommit( hdb );
637 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
639 r = try_query( hdb, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
640 "PRIMARY KEY `ba`)");
641 ok(r != ERROR_SUCCESS , "query 5 succeeded\n");
643 r = try_query( hdb,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
644 ok(r != ERROR_SUCCESS , "query 6 succeeded\n");
646 r = try_query( hdb, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
648 ok(r == ERROR_SUCCESS , "query 7 failed\n");
650 r = try_query( hdb, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
651 ok(r == ERROR_SUCCESS , "query 8 failed\n");
653 r = try_query( hdb, "select * from c");
654 ok(r == ERROR_SUCCESS , "query failed\n");
656 r = try_query( hdb, "select * from c where b = 'x");
657 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
659 r = try_query( hdb, "select * from c where b = 'x'");
660 ok(r == ERROR_SUCCESS, "query failed\n");
662 r = try_query( hdb, "select * from 'c'");
663 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
665 r = try_query( hdb, "select * from ''");
666 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
668 r = try_query( hdb, "select * from c where b = x");
669 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
671 r = try_query( hdb, "select * from c where b = \"x\"");
672 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
674 r = try_query( hdb, "select * from c where b = 'x'");
675 ok(r == ERROR_SUCCESS, "query failed\n");
677 r = try_query( hdb, "select * from c where b = '\"x'");
678 ok(r == ERROR_SUCCESS, "query failed\n");
680 if (0) /* FIXME: this query causes trouble with other tests */
682 r = try_query( hdb, "select * from c where b = '\\\'x'");
683 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
686 r = try_query( hdb, "select * from 'c'");
687 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
689 r = try_query( hdb, "CREATE TABLE `\5a` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
690 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
692 r = try_query( hdb, "SELECT * FROM \5a" );
693 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
695 r = try_query( hdb, "CREATE TABLE `a\5` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
696 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
698 r = try_query( hdb, "SELECT * FROM a\5" );
699 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
701 r = try_query( hdb, "CREATE TABLE `-a` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
702 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
704 r = try_query( hdb, "SELECT * FROM -a" );
705 todo_wine ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
707 r = try_query( hdb, "CREATE TABLE `a-` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
708 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
710 r = try_query( hdb, "SELECT * FROM a-" );
711 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
713 r = MsiCloseHandle( hdb );
714 ok(r == ERROR_SUCCESS , "Failed to close database transact\n");
716 r = DeleteFile( msifile );
717 ok(r == TRUE, "file didn't exist after commit\n");
720 static void test_viewmodify(void)
722 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
731 /* just MsiOpenDatabase should not create a file */
732 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
733 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
735 query = "CREATE TABLE `phone` ( "
736 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
738 r = run_query( hdb, 0, query );
739 ok(r == ERROR_SUCCESS, "query failed\n");
741 /* check what the error function reports without doing anything */
743 /* passing NULL as the 3rd param make function to crash on older platforms */
744 err = MsiViewGetError( 0, NULL, &sz );
745 ok(err == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
748 query = "SELECT * FROM `phone`";
749 r = MsiDatabaseOpenView(hdb, query, &hview);
750 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
752 /* see what happens with a good hview and bad args */
753 err = MsiViewGetError( hview, NULL, NULL );
754 ok(err == MSIDBERROR_INVALIDARG || err == MSIDBERROR_NOERROR,
755 "MsiViewGetError returns %u (expected -3)\n", err);
756 err = MsiViewGetError( hview, buffer, NULL );
757 ok(err == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
759 /* see what happens with a zero length buffer */
762 err = MsiViewGetError( hview, buffer, &sz );
763 ok(err == MSIDBERROR_MOREDATA, "MsiViewGetError return\n");
764 ok(buffer[0] == 'x', "buffer cleared\n");
765 ok(sz == 0, "size not zero\n");
767 /* ok this one is strange */
769 err = MsiViewGetError( hview, NULL, &sz );
770 ok(err == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
771 ok(sz == 0, "size not zero\n");
773 /* see if it really has an error */
776 err = MsiViewGetError( hview, buffer, &sz );
777 ok(err == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
778 ok(buffer[0] == 0, "buffer not cleared\n");
779 ok(sz == 0, "size not zero\n");
781 r = MsiViewExecute(hview, 0);
782 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
784 /* try some invalid records */
785 r = MsiViewModify(hview, MSIMODIFY_INSERT, 0 );
786 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
787 r = MsiViewModify(hview, -1, 0 );
788 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
790 /* try an small record */
791 hrec = MsiCreateRecord(1);
792 r = MsiViewModify(hview, -1, hrec );
793 ok(r == ERROR_INVALID_DATA, "MsiViewModify failed\n");
795 r = MsiCloseHandle(hrec);
796 ok(r == ERROR_SUCCESS, "failed to close record\n");
798 /* insert a valid record */
799 hrec = MsiCreateRecord(3);
801 r = MsiRecordSetInteger(hrec, 1, 1);
802 ok(r == ERROR_SUCCESS, "failed to set integer\n");
803 r = MsiRecordSetString(hrec, 2, "bob");
804 ok(r == ERROR_SUCCESS, "failed to set string\n");
805 r = MsiRecordSetString(hrec, 3, "7654321");
806 ok(r == ERROR_SUCCESS, "failed to set string\n");
808 r = MsiViewExecute(hview, 0);
809 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
810 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
811 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
813 /* insert the same thing again */
814 r = MsiViewExecute(hview, 0);
815 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
817 /* should fail ... */
818 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
819 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
821 r = MsiCloseHandle(hrec);
822 ok(r == ERROR_SUCCESS, "failed to close record\n");
824 r = MsiViewClose(hview);
825 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
826 r = MsiCloseHandle(hview);
827 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
829 query = "SELECT * FROM `phone`";
830 r = MsiDatabaseOpenView(hdb, query, &hview);
831 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
833 r = MsiViewExecute(hview, 0);
834 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
836 r = MsiViewFetch(hview, &hrec);
837 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
839 r = MsiRecordGetInteger(hrec, 1);
840 ok(r == 1, "Expected 1, got %d\n", r);
843 r = MsiRecordGetString(hrec, 2, buffer, &sz);
844 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
845 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
848 r = MsiRecordGetString(hrec, 3, buffer, &sz);
849 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
850 ok(!lstrcmp(buffer, "7654321"), "Expected 7654321, got %s\n", buffer);
852 /* update the view, non-primary key */
853 r = MsiRecordSetString(hrec, 3, "3141592");
854 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
856 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
857 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
860 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
861 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
863 /* update the view, primary key */
864 r = MsiRecordSetInteger(hrec, 1, 5);
865 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
867 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
868 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
870 r = MsiCloseHandle(hrec);
871 ok(r == ERROR_SUCCESS, "failed to close record\n");
873 r = MsiViewClose(hview);
874 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
875 r = MsiCloseHandle(hview);
876 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
878 query = "SELECT * FROM `phone`";
879 r = MsiDatabaseOpenView(hdb, query, &hview);
880 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
882 r = MsiViewExecute(hview, 0);
883 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
885 r = MsiViewFetch(hview, &hrec);
886 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
888 r = MsiRecordGetInteger(hrec, 1);
889 ok(r == 1, "Expected 1, got %d\n", r);
892 r = MsiRecordGetString(hrec, 2, buffer, &sz);
893 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
894 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
897 r = MsiRecordGetString(hrec, 3, buffer, &sz);
898 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
899 ok(!lstrcmp(buffer, "3141592"), "Expected 3141592, got %s\n", buffer);
901 r = MsiCloseHandle(hrec);
902 ok(r == ERROR_SUCCESS, "failed to close record\n");
904 /* use a record that doesn't come from a view fetch */
905 hrec = MsiCreateRecord(3);
906 ok(hrec != 0, "MsiCreateRecord failed\n");
908 r = MsiRecordSetInteger(hrec, 1, 3);
909 ok(r == ERROR_SUCCESS, "failed to set integer\n");
910 r = MsiRecordSetString(hrec, 2, "jane");
911 ok(r == ERROR_SUCCESS, "failed to set string\n");
912 r = MsiRecordSetString(hrec, 3, "112358");
913 ok(r == ERROR_SUCCESS, "failed to set string\n");
915 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
916 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
918 r = MsiCloseHandle(hrec);
919 ok(r == ERROR_SUCCESS, "failed to close record\n");
921 /* use a record that doesn't come from a view fetch, primary key matches */
922 hrec = MsiCreateRecord(3);
923 ok(hrec != 0, "MsiCreateRecord failed\n");
925 r = MsiRecordSetInteger(hrec, 1, 1);
926 ok(r == ERROR_SUCCESS, "failed to set integer\n");
927 r = MsiRecordSetString(hrec, 2, "jane");
928 ok(r == ERROR_SUCCESS, "failed to set string\n");
929 r = MsiRecordSetString(hrec, 3, "112358");
930 ok(r == ERROR_SUCCESS, "failed to set string\n");
932 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
933 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
935 r = MsiCloseHandle(hrec);
936 ok(r == ERROR_SUCCESS, "failed to close record\n");
938 hrec = MsiCreateRecord(3);
940 r = MsiRecordSetInteger(hrec, 1, 2);
941 ok(r == ERROR_SUCCESS, "failed to set integer\n");
942 r = MsiRecordSetString(hrec, 2, "nick");
943 ok(r == ERROR_SUCCESS, "failed to set string\n");
944 r = MsiRecordSetString(hrec, 3, "141421");
945 ok(r == ERROR_SUCCESS, "failed to set string\n");
947 r = MsiViewExecute(hview, 0);
948 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
949 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
950 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
952 r = MsiCloseHandle(hrec);
953 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
954 r = MsiViewClose(hview);
955 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
956 r = MsiCloseHandle(hview);
957 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
959 query = "SELECT * FROM `phone` WHERE `id` = 1";
960 r = MsiDatabaseOpenView(hdb, query, &hview);
961 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
962 r = MsiViewExecute(hview, 0);
963 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
964 r = MsiViewFetch(hview, &hrec);
965 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
967 /* change the id to match the second row */
968 r = MsiRecordSetInteger(hrec, 1, 2);
969 ok(r == ERROR_SUCCESS, "failed to set integer\n");
970 r = MsiRecordSetString(hrec, 2, "jerry");
971 ok(r == ERROR_SUCCESS, "failed to set string\n");
973 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
974 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
976 r = MsiCloseHandle(hrec);
977 ok(r == ERROR_SUCCESS, "failed to close record\n");
978 r = MsiViewClose(hview);
979 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
980 r = MsiCloseHandle(hview);
981 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
984 query = "SELECT * FROM `phone` ORDER BY `id`";
985 r = MsiDatabaseOpenView(hdb, query, &hview);
986 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
987 r = MsiViewExecute(hview, 0);
988 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
989 r = MsiViewFetch(hview, &hrec);
990 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
992 /* change the id to match the second row */
993 r = MsiRecordSetInteger(hrec, 1, 2);
994 ok(r == ERROR_SUCCESS, "failed to set integer\n");
995 r = MsiRecordSetString(hrec, 2, "jerry");
996 ok(r == ERROR_SUCCESS, "failed to set string\n");
998 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
999 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
1001 r = MsiCloseHandle(hrec);
1002 ok(r == ERROR_SUCCESS, "failed to close record\n");
1003 r = MsiViewClose(hview);
1004 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1005 r = MsiCloseHandle(hview);
1006 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1008 r = MsiCloseHandle( hdb );
1009 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
1012 static MSIHANDLE create_db(void)
1017 DeleteFile(msifile);
1019 /* create an empty database */
1020 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
1021 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
1022 if( res != ERROR_SUCCESS )
1025 res = MsiDatabaseCommit( hdb );
1026 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
1031 static void test_getcolinfo(void)
1033 MSIHANDLE hdb, hview = 0, rec = 0;
1038 /* create an empty db */
1040 ok( hdb, "failed to create db\n");
1042 /* tables should be present */
1043 r = MsiDatabaseOpenView(hdb, "select * from _Tables", &hview);
1044 ok( r == ERROR_SUCCESS, "failed to open query\n");
1046 r = MsiViewExecute(hview, 0);
1047 ok( r == ERROR_SUCCESS, "failed to execute query\n");
1049 /* check that NAMES works */
1051 r = MsiViewGetColumnInfo( hview, MSICOLINFO_NAMES, &rec );
1052 ok( r == ERROR_SUCCESS, "failed to get names\n");
1054 r = MsiRecordGetString(rec, 1, buffer, &sz );
1055 ok( r == ERROR_SUCCESS, "failed to get string\n");
1056 ok( !strcmp(buffer,"Name"), "_Tables has wrong column name\n");
1057 r = MsiCloseHandle( rec );
1058 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1060 /* check that TYPES works */
1062 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, &rec );
1063 ok( r == ERROR_SUCCESS, "failed to get names\n");
1065 r = MsiRecordGetString(rec, 1, buffer, &sz );
1066 ok( r == ERROR_SUCCESS, "failed to get string\n");
1067 ok( !strcmp(buffer,"s64"), "_Tables has wrong column type\n");
1068 r = MsiCloseHandle( rec );
1069 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1071 /* check that invalid values fail */
1073 r = MsiViewGetColumnInfo( hview, 100, &rec );
1074 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1075 ok( rec == 0, "returned a record\n");
1077 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, NULL );
1078 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1080 r = MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES, &rec );
1081 ok( r == ERROR_INVALID_HANDLE, "wrong error code\n");
1083 r = MsiViewClose(hview);
1084 ok( r == ERROR_SUCCESS, "failed to close view\n");
1085 r = MsiCloseHandle(hview);
1086 ok( r == ERROR_SUCCESS, "failed to close view handle\n");
1087 r = MsiCloseHandle(hdb);
1088 ok( r == ERROR_SUCCESS, "failed to close database\n");
1091 static MSIHANDLE get_column_info(MSIHANDLE hdb, const char *query, MSICOLINFO type)
1093 MSIHANDLE hview = 0, rec = 0;
1096 r = MsiDatabaseOpenView(hdb, query, &hview);
1097 if( r != ERROR_SUCCESS )
1100 r = MsiViewExecute(hview, 0);
1101 if( r == ERROR_SUCCESS )
1103 MsiViewGetColumnInfo( hview, type, &rec );
1105 MsiViewClose(hview);
1106 MsiCloseHandle(hview);
1110 static UINT get_columns_table_type(MSIHANDLE hdb, const char *table, UINT field)
1112 MSIHANDLE hview = 0, rec = 0;
1116 sprintf(query, "select * from `_Columns` where `Table` = '%s'", table );
1118 r = MsiDatabaseOpenView(hdb, query, &hview);
1119 if( r != ERROR_SUCCESS )
1122 r = MsiViewExecute(hview, 0);
1123 if( r == ERROR_SUCCESS )
1127 r = MsiViewFetch( hview, &rec );
1128 if( r != ERROR_SUCCESS)
1130 r = MsiRecordGetInteger( rec, 2 );
1132 type = MsiRecordGetInteger( rec, 4 );
1133 MsiCloseHandle( rec );
1136 MsiViewClose(hview);
1137 MsiCloseHandle(hview);
1141 static BOOL check_record( MSIHANDLE rec, UINT field, LPCSTR val )
1148 r = MsiRecordGetString( rec, field, buffer, &sz );
1149 return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
1152 static void test_viewgetcolumninfo(void)
1154 MSIHANDLE hdb = 0, rec;
1158 ok( hdb, "failed to create db\n");
1160 r = run_query( hdb, 0,
1161 "CREATE TABLE `Properties` "
1162 "( `Property` CHAR(255), "
1163 " `Value` CHAR(1), "
1165 " `Integervalue` INTEGER, "
1166 " `Shortvalue` SHORT, "
1167 " `Longvalue` LONG, "
1168 " `Longcharvalue` LONGCHAR "
1169 " PRIMARY KEY `Property`)" );
1170 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1172 /* check the column types */
1173 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_TYPES );
1174 ok( rec, "failed to get column info record\n" );
1176 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1177 ok( check_record( rec, 2, "S1"), "wrong record type\n");
1178 ok( check_record( rec, 3, "I2"), "wrong record type\n");
1179 ok( check_record( rec, 4, "I2"), "wrong record type\n");
1180 ok( check_record( rec, 5, "I2"), "wrong record type\n");
1181 ok( check_record( rec, 6, "I4"), "wrong record type\n");
1182 ok( check_record( rec, 7, "S0"), "wrong record type\n");
1184 MsiCloseHandle( rec );
1186 /* check the type in _Columns */
1187 ok( 0x3dff == get_columns_table_type(hdb, "Properties", 1 ), "_columns table wrong\n");
1188 ok( 0x1d01 == get_columns_table_type(hdb, "Properties", 2 ), "_columns table wrong\n");
1189 ok( 0x1502 == get_columns_table_type(hdb, "Properties", 3 ), "_columns table wrong\n");
1190 ok( 0x1502 == get_columns_table_type(hdb, "Properties", 4 ), "_columns table wrong\n");
1191 ok( 0x1502 == get_columns_table_type(hdb, "Properties", 5 ), "_columns table wrong\n");
1192 ok( 0x1104 == get_columns_table_type(hdb, "Properties", 6 ), "_columns table wrong\n");
1193 ok( 0x1d00 == get_columns_table_type(hdb, "Properties", 7 ), "_columns table wrong\n");
1195 /* now try the names */
1196 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_NAMES );
1197 ok( rec, "failed to get column info record\n" );
1199 ok( check_record( rec, 1, "Property"), "wrong record type\n");
1200 ok( check_record( rec, 2, "Value"), "wrong record type\n");
1201 ok( check_record( rec, 3, "Intvalue"), "wrong record type\n");
1202 ok( check_record( rec, 4, "Integervalue"), "wrong record type\n");
1203 ok( check_record( rec, 5, "Shortvalue"), "wrong record type\n");
1204 ok( check_record( rec, 6, "Longvalue"), "wrong record type\n");
1205 ok( check_record( rec, 7, "Longcharvalue"), "wrong record type\n");
1207 MsiCloseHandle( rec );
1209 r = run_query( hdb, 0,
1210 "CREATE TABLE `Binary` "
1211 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
1212 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1214 /* check the column types */
1215 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_TYPES );
1216 ok( rec, "failed to get column info record\n" );
1218 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1219 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1221 MsiCloseHandle( rec );
1223 /* check the type in _Columns */
1224 ok( 0x3dff == get_columns_table_type(hdb, "Binary", 1 ), "_columns table wrong\n");
1225 ok( 0x1900 == get_columns_table_type(hdb, "Binary", 2 ), "_columns table wrong\n");
1227 /* now try the names */
1228 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_NAMES );
1229 ok( rec, "failed to get column info record\n" );
1231 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1232 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1233 MsiCloseHandle( rec );
1235 r = run_query( hdb, 0,
1236 "CREATE TABLE `UIText` "
1237 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1238 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1240 ok( 0x2d48 == get_columns_table_type(hdb, "UIText", 1 ), "_columns table wrong\n");
1241 ok( 0x1fff == get_columns_table_type(hdb, "UIText", 2 ), "_columns table wrong\n");
1243 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_NAMES );
1244 ok( rec, "failed to get column info record\n" );
1245 ok( check_record( rec, 1, "Key"), "wrong record type\n");
1246 ok( check_record( rec, 2, "Text"), "wrong record type\n");
1247 MsiCloseHandle( rec );
1249 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_TYPES );
1250 ok( rec, "failed to get column info record\n" );
1251 ok( check_record( rec, 1, "s72"), "wrong record type\n");
1252 ok( check_record( rec, 2, "L255"), "wrong record type\n");
1253 MsiCloseHandle( rec );
1255 MsiCloseHandle( hdb );
1258 static void test_msiexport(void)
1260 MSIHANDLE hdb = 0, hview = 0;
1263 char path[MAX_PATH];
1264 const char file[] = "phone.txt";
1268 const char expected[] =
1269 "id\tname\tnumber\r\n"
1272 "1\tAbe\t8675309\r\n";
1274 DeleteFile(msifile);
1276 /* just MsiOpenDatabase should not create a file */
1277 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1278 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1280 /* create a table */
1281 query = "CREATE TABLE `phone` ( "
1282 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1283 "PRIMARY KEY `id`)";
1284 r = MsiDatabaseOpenView(hdb, query, &hview);
1285 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1286 r = MsiViewExecute(hview, 0);
1287 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1288 r = MsiViewClose(hview);
1289 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1290 r = MsiCloseHandle(hview);
1291 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1293 /* insert a value into it */
1294 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
1295 "VALUES('1', 'Abe', '8675309')";
1296 r = MsiDatabaseOpenView(hdb, query, &hview);
1297 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1298 r = MsiViewExecute(hview, 0);
1299 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1300 r = MsiViewClose(hview);
1301 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1302 r = MsiCloseHandle(hview);
1303 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1305 GetCurrentDirectory(MAX_PATH, path);
1307 r = MsiDatabaseExport(hdb, "phone", path, file);
1308 ok(r == ERROR_SUCCESS, "MsiDatabaseExport failed\n");
1310 MsiCloseHandle(hdb);
1312 lstrcat(path, "\\");
1313 lstrcat(path, file);
1315 /* check the data that was written */
1317 memset(buffer, 0, sizeof buffer);
1318 handle = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
1319 if (handle != INVALID_HANDLE_VALUE)
1321 ReadFile(handle, buffer, sizeof buffer, &length, NULL);
1322 CloseHandle(handle);
1326 ok(0, "failed to open file %s\n", path);
1328 ok( length == strlen(expected), "length of data wrong\n");
1329 ok( !lstrcmp(buffer, expected), "data doesn't match\n");
1330 DeleteFile(msifile);
1333 static void test_longstrings(void)
1335 const char insert_query[] =
1336 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1338 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
1341 const DWORD STRING_LENGTH = 0x10005;
1343 DeleteFile(msifile);
1344 /* just MsiOpenDatabase should not create a file */
1345 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1346 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1348 /* create a table */
1350 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1351 ok(r == ERROR_SUCCESS, "query failed\n");
1353 /* try a insert a very long string */
1354 str = HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH+sizeof insert_query);
1355 len = strchr(insert_query, 'Z') - insert_query;
1356 strcpy(str, insert_query);
1357 memset(str+len, 'Z', STRING_LENGTH);
1358 strcpy(str+len+STRING_LENGTH, insert_query+len+1);
1359 r = try_query( hdb, str );
1360 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1362 HeapFree(GetProcessHeap(), 0, str);
1364 MsiDatabaseCommit(hdb);
1365 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
1366 MsiCloseHandle(hdb);
1368 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
1369 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1371 r = MsiDatabaseOpenView(hdb, "select * from `strings` where `id` = 1", &hview);
1372 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1374 r = MsiViewExecute(hview, 0);
1375 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1377 r = MsiViewFetch(hview, &hrec);
1378 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1380 MsiViewClose(hview);
1381 MsiCloseHandle(hview);
1383 r = MsiRecordGetString(hrec, 2, NULL, &len);
1384 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1385 ok(len == STRING_LENGTH, "string length wrong\n");
1387 MsiCloseHandle(hrec);
1388 MsiCloseHandle(hdb);
1389 DeleteFile(msifile);
1392 static void create_file_data(LPCSTR name, LPCSTR data, DWORD size)
1397 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1398 if (file == INVALID_HANDLE_VALUE)
1401 WriteFile(file, data, strlen(data), &written, NULL);
1402 WriteFile(file, "\n", strlen("\n"), &written, NULL);
1406 SetFilePointer(file, size, NULL, FILE_BEGIN);
1413 #define create_file(name) create_file_data(name, name, 0)
1415 static void test_streamtable(void)
1417 MSIHANDLE hdb = 0, rec, view, hsi;
1418 char file[MAX_PATH];
1424 ok( hdb, "failed to create db\n");
1426 r = run_query( hdb, 0,
1427 "CREATE TABLE `Properties` "
1428 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1429 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1431 r = run_query( hdb, 0,
1432 "INSERT INTO `Properties` "
1433 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1434 ok( r == ERROR_SUCCESS, "Failed to add to table\n" );
1436 r = MsiDatabaseCommit( hdb );
1437 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1439 MsiCloseHandle( hdb );
1441 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
1442 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1444 /* check the column types */
1445 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_TYPES );
1446 ok( rec, "failed to get column info record\n" );
1448 ok( check_record( rec, 1, "s62"), "wrong record type\n");
1449 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1451 MsiCloseHandle( rec );
1453 /* now try the names */
1454 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_NAMES );
1455 ok( rec, "failed to get column info record\n" );
1457 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1458 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1460 MsiCloseHandle( rec );
1462 r = MsiDatabaseOpenView( hdb,
1463 "SELECT * FROM `_Streams` WHERE `Name` = '\5SummaryInformation'", &view );
1464 ok( r == ERROR_SUCCESS, "Failed to open database view: %u\n", r );
1466 r = MsiViewExecute( view, 0 );
1467 ok( r == ERROR_SUCCESS, "Failed to execute view: %u\n", r );
1469 r = MsiViewFetch( view, &rec );
1470 ok( r == ERROR_NO_MORE_ITEMS, "Unexpected result: %u\n", r );
1472 MsiCloseHandle( rec );
1473 MsiViewClose( view );
1474 MsiCloseHandle( view );
1476 /* create a summary information stream */
1477 r = MsiGetSummaryInformationA( hdb, NULL, 1, &hsi );
1478 ok( r == ERROR_SUCCESS, "Failed to get summary information handle: %u\n", r );
1480 r = MsiSummaryInfoSetPropertyA( hsi, PID_SECURITY, VT_I4, 2, NULL, NULL );
1481 ok( r == ERROR_SUCCESS, "Failed to set property: %u\n", r );
1483 r = MsiSummaryInfoPersist( hsi );
1484 ok( r == ERROR_SUCCESS, "Failed to save summary information: %u\n", r );
1486 MsiCloseHandle( hsi );
1488 r = MsiDatabaseOpenView( hdb,
1489 "SELECT * FROM `_Streams` WHERE `Name` = '\5SummaryInformation'", &view );
1490 ok( r == ERROR_SUCCESS, "Failed to open database view: %u\n", r );
1492 r = MsiViewExecute( view, 0 );
1493 ok( r == ERROR_SUCCESS, "Failed to execute view: %u\n", r );
1495 r = MsiViewFetch( view, &rec );
1496 ok( r == ERROR_SUCCESS, "Unexpected result: %u\n", r );
1498 MsiCloseHandle( rec );
1499 MsiViewClose( view );
1500 MsiCloseHandle( view );
1502 /* insert a file into the _Streams table */
1503 create_file( "test.txt" );
1505 rec = MsiCreateRecord( 2 );
1506 MsiRecordSetString( rec, 1, "data" );
1508 r = MsiRecordSetStream( rec, 2, "test.txt" );
1509 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1511 DeleteFile("test.txt");
1513 r = MsiDatabaseOpenView( hdb,
1514 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view );
1515 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1517 r = MsiViewExecute( view, rec );
1518 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1520 MsiCloseHandle( rec );
1521 MsiViewClose( view );
1522 MsiCloseHandle( view );
1524 /* insert another one */
1525 create_file( "test1.txt" );
1527 rec = MsiCreateRecord( 2 );
1528 MsiRecordSetString( rec, 1, "data1" );
1530 r = MsiRecordSetStream( rec, 2, "test1.txt" );
1531 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1533 DeleteFile("test1.txt");
1535 r = MsiDatabaseOpenView( hdb,
1536 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view );
1537 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1539 r = MsiViewExecute( view, rec );
1540 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1542 MsiCloseHandle( rec );
1543 MsiViewClose( view );
1544 MsiCloseHandle( view );
1546 r = MsiDatabaseOpenView( hdb,
1547 "SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = 'data'", &view );
1548 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1550 r = MsiViewExecute( view, 0 );
1551 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1553 r = MsiViewFetch( view, &rec );
1554 ok( r == ERROR_SUCCESS, "Failed to fetch record: %d\n", r);
1557 r = MsiRecordGetString( rec, 1, file, &size );
1558 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1559 ok( !lstrcmp(file, "data"), "Expected 'data', got %s\n", file);
1562 memset(buf, 0, MAX_PATH);
1563 r = MsiRecordReadStream( rec, 2, buf, &size );
1564 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1565 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf);
1567 MsiCloseHandle( rec );
1568 MsiViewClose( view );
1569 MsiCloseHandle( view );
1571 r = MsiDatabaseOpenView( hdb,
1572 "SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = 'data1'", &view );
1573 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1575 r = MsiViewExecute( view, 0 );
1576 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1578 r = MsiViewFetch( view, &rec );
1579 ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1582 r = MsiRecordGetString( rec, 1, file, &size );
1583 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1584 ok( !lstrcmp(file, "data1"), "Expected 'data1', got %s\n", file);
1587 memset(buf, 0, MAX_PATH);
1588 r = MsiRecordReadStream( rec, 2, buf, &size );
1589 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1590 ok( !lstrcmp(buf, "test1.txt\n"), "Expected 'test1.txt\\n', got %s\n", buf);
1592 MsiCloseHandle( rec );
1593 MsiViewClose( view );
1594 MsiCloseHandle( view );
1596 /* perform an update */
1597 create_file( "test2.txt" );
1598 rec = MsiCreateRecord( 1 );
1600 r = MsiRecordSetStream( rec, 1, "test2.txt" );
1601 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1603 DeleteFile("test2.txt");
1605 r = MsiDatabaseOpenView( hdb,
1606 "UPDATE `_Streams` SET `Data` = ? WHERE `Name` = 'data1'", &view );
1607 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1609 r = MsiViewExecute( view, rec );
1610 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1612 MsiCloseHandle( rec );
1613 MsiViewClose( view );
1614 MsiCloseHandle( view );
1616 r = MsiDatabaseOpenView( hdb,
1617 "SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = 'data1'", &view );
1618 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1620 r = MsiViewExecute( view, 0 );
1621 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1623 r = MsiViewFetch( view, &rec );
1624 ok( r == ERROR_SUCCESS, "Failed to fetch record: %d\n", r);
1627 r = MsiRecordGetString( rec, 1, file, &size );
1628 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1629 ok( !lstrcmp(file, "data1"), "Expected 'data1', got %s\n", file);
1632 memset(buf, 0, MAX_PATH);
1633 r = MsiRecordReadStream( rec, 2, buf, &size );
1634 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1635 todo_wine ok( !lstrcmp(buf, "test2.txt\n"), "Expected 'test2.txt\\n', got %s\n", buf);
1637 MsiCloseHandle( rec );
1638 MsiViewClose( view );
1639 MsiCloseHandle( view );
1640 MsiCloseHandle( hdb );
1641 DeleteFile(msifile);
1644 static void test_binary(void)
1646 MSIHANDLE hdb = 0, rec;
1647 char file[MAX_PATH];
1653 /* insert a file into the Binary table */
1654 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
1655 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1657 query = "CREATE TABLE `Binary` ( `Name` CHAR(72) NOT NULL, `ID` INT NOT NULL, `Data` OBJECT PRIMARY KEY `Name`, `ID`)";
1658 r = run_query( hdb, 0, query );
1659 ok( r == ERROR_SUCCESS, "Cannot create Binary table: %d\n", r );
1661 create_file( "test.txt" );
1662 rec = MsiCreateRecord( 1 );
1663 r = MsiRecordSetStream( rec, 1, "test.txt" );
1664 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1665 DeleteFile( "test.txt" );
1667 query = "INSERT INTO `Binary` ( `Name`, `ID`, `Data` ) VALUES ( 'filename1', 1, ? )";
1668 r = run_query( hdb, rec, query );
1669 ok( r == ERROR_SUCCESS, "Insert into Binary table failed: %d\n", r );
1671 r = MsiCloseHandle( rec );
1672 ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
1674 r = MsiDatabaseCommit( hdb );
1675 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1677 r = MsiCloseHandle( hdb );
1678 ok( r == ERROR_SUCCESS , "Failed to close database\n" );
1680 /* read file from the Stream table */
1681 r = MsiOpenDatabase( msifile, MSIDBOPEN_READONLY, &hdb );
1682 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1684 query = "SELECT * FROM `_Streams`";
1685 r = do_query( hdb, query, &rec );
1686 ok( r == ERROR_SUCCESS, "SELECT query failed: %d\n", r );
1689 r = MsiRecordGetString( rec, 1, file, &size );
1690 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r );
1691 ok( !lstrcmp(file, "Binary.filename1.1"), "Expected 'Binary.filename1.1', got %s\n", file );
1694 memset( buf, 0, MAX_PATH );
1695 r = MsiRecordReadStream( rec, 2, buf, &size );
1696 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r );
1697 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf );
1699 r = MsiCloseHandle( rec );
1700 ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
1702 /* read file from the Binary table */
1703 query = "SELECT * FROM `Binary`";
1704 r = do_query( hdb, query, &rec );
1705 ok( r == ERROR_SUCCESS, "SELECT query failed: %d\n", r );
1708 r = MsiRecordGetString( rec, 1, file, &size );
1709 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r );
1710 ok( !lstrcmp(file, "filename1"), "Expected 'filename1', got %s\n", file );
1713 memset( buf, 0, MAX_PATH );
1714 r = MsiRecordReadStream( rec, 3, buf, &size );
1715 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r );
1716 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf );
1718 r = MsiCloseHandle( rec );
1719 ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
1721 r = MsiCloseHandle( hdb );
1722 ok( r == ERROR_SUCCESS , "Failed to close database\n" );
1724 DeleteFile( msifile );
1727 static void test_where_not_in_selected(void)
1729 MSIHANDLE hdb = 0, rec, view;
1734 ok( hdb, "failed to create db\n");
1736 r = run_query(hdb, 0,
1737 "CREATE TABLE `IESTable` ("
1738 "`Action` CHAR(64), "
1739 "`Condition` CHAR(64), "
1740 "`Sequence` LONG PRIMARY KEY `Sequence`)");
1741 ok( r == S_OK, "Cannot create IESTable table: %d\n", r);
1743 r = run_query(hdb, 0,
1744 "CREATE TABLE `CATable` ("
1745 "`Action` CHAR(64), "
1746 "`Type` LONG PRIMARY KEY `Type`)");
1747 ok( r == S_OK, "Cannot create CATable table: %d\n", r);
1749 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1750 "( `Action`, `Condition`, `Sequence`) "
1751 "VALUES ( 'clean', 'cond4', 4)");
1752 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1754 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1755 "( `Action`, `Condition`, `Sequence`) "
1756 "VALUES ( 'depends', 'cond1', 1)");
1757 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1759 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1760 "( `Action`, `Condition`, `Sequence`) "
1761 "VALUES ( 'build', 'cond2', 2)");
1762 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1764 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1765 "( `Action`, `Condition`, `Sequence`) "
1766 "VALUES ( 'build2', 'cond6', 6)");
1767 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1769 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1770 "( `Action`, `Condition`, `Sequence`) "
1771 "VALUES ( 'build', 'cond3', 3)");
1772 ok(r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1774 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1775 "( `Action`, `Type` ) "
1776 "VALUES ( 'build', 32)");
1777 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1779 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1780 "( `Action`, `Type` ) "
1781 "VALUES ( 'depends', 64)");
1782 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1784 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1785 "( `Action`, `Type` ) "
1786 "VALUES ( 'clean', 63)");
1787 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1789 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1790 "( `Action`, `Type` ) "
1791 "VALUES ( 'build2', 34)");
1792 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1793 query = "Select IESTable.Condition from CATable, IESTable where "
1794 "CATable.Action = IESTable.Action and CATable.Type = 32";
1795 r = MsiDatabaseOpenView(hdb, query, &view);
1796 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1798 r = MsiViewExecute(view, 0);
1799 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1801 r = MsiViewFetch(view, &rec);
1802 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1804 ok( check_record( rec, 1, "cond2"), "wrong condition\n");
1806 MsiCloseHandle( rec );
1807 r = MsiViewFetch(view, &rec);
1808 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1810 ok( check_record( rec, 1, "cond3"), "wrong condition\n");
1812 MsiCloseHandle( rec );
1814 MsiCloseHandle(view);
1816 MsiCloseHandle( hdb );
1817 DeleteFile(msifile);
1822 static void test_where(void)
1824 MSIHANDLE hdb = 0, rec, view;
1832 ok( hdb, "failed to create db\n");
1834 r = run_query( hdb, 0,
1835 "CREATE TABLE `Media` ("
1836 "`DiskId` SHORT NOT NULL, "
1837 "`LastSequence` LONG, "
1838 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1839 "`Cabinet` CHAR(255), "
1840 "`VolumeLabel` CHAR(32), "
1841 "`Source` CHAR(72) "
1842 "PRIMARY KEY `DiskId`)" );
1843 ok( r == S_OK, "cannot create Media table: %d\n", r );
1845 r = run_query( hdb, 0, "INSERT INTO `Media` "
1846 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1847 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1848 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1850 r = run_query( hdb, 0, "INSERT INTO `Media` "
1851 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1852 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1853 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1855 r = run_query( hdb, 0, "INSERT INTO `Media` "
1856 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1857 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1858 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1860 query = "SELECT * FROM `Media`";
1861 r = do_query(hdb, query, &rec);
1862 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1863 ok( check_record( rec, 4, "zero.cab"), "wrong cabinet\n");
1864 MsiCloseHandle( rec );
1866 query = "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1867 r = do_query(hdb, query, &rec);
1868 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1869 ok( check_record( rec, 4, "one.cab"), "wrong cabinet\n");
1871 r = MsiRecordGetInteger(rec, 1);
1872 ok( 2 == r, "field wrong\n");
1873 r = MsiRecordGetInteger(rec, 2);
1874 ok( 1 == r, "field wrong\n");
1875 MsiCloseHandle( rec );
1877 query = "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1878 r = MsiDatabaseOpenView(hdb, query, &view);
1879 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1881 r = MsiViewExecute(view, 0);
1882 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1884 r = MsiViewFetch(view, &rec);
1885 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1887 count = MsiRecordGetFieldCount( rec );
1888 ok( count == 1, "Expected 1 record fields, got %d\n", count );
1891 r = MsiRecordGetString( rec, 1, buf, &size );
1892 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1893 ok( !lstrcmp( buf, "2" ),
1894 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf );
1895 MsiCloseHandle( rec );
1897 r = MsiViewFetch(view, &rec);
1898 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1901 r = MsiRecordGetString( rec, 1, buf, &size );
1902 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1903 ok( !lstrcmp( buf, "3" ),
1904 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf );
1905 MsiCloseHandle( rec );
1907 r = MsiViewFetch(view, &rec);
1908 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
1911 MsiCloseHandle(view);
1913 MsiCloseHandle( rec );
1916 query = "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1917 r = do_query(hdb, query, &rec);
1918 ok( r == ERROR_SUCCESS, "query failed: %d\n", r );
1919 MsiCloseHandle( rec );
1922 query = "SELECT * FROM `Media` WHERE `DiskPrompt` < 'Cabinet'";
1923 r = do_query(hdb, query, &rec);
1924 ok( r == ERROR_BAD_QUERY_SYNTAX, "query failed: %d\n", r );
1925 MsiCloseHandle( rec );
1928 query = "SELECT * FROM `Media` WHERE `DiskPrompt` > 'Cabinet'";
1929 r = do_query(hdb, query, &rec);
1930 ok( r == ERROR_BAD_QUERY_SYNTAX, "query failed: %d\n", r );
1931 MsiCloseHandle( rec );
1934 query = "SELECT * FROM `Media` WHERE `DiskPrompt` <> 'Cabinet'";
1935 r = do_query(hdb, query, &rec);
1936 ok( r == ERROR_SUCCESS, "query failed: %d\n", r );
1937 MsiCloseHandle( rec );
1940 query = "SELECT * FROM `Media` WHERE `DiskPrompt` = 'Cabinet'";
1941 r = do_query(hdb, query, &rec);
1942 ok( r == ERROR_NO_MORE_ITEMS, "query failed: %d\n", r );
1943 MsiCloseHandle( rec );
1945 rec = MsiCreateRecord(1);
1946 MsiRecordSetString(rec, 1, "");
1948 query = "SELECT * FROM `Media` WHERE `DiskPrompt` = ?";
1949 r = MsiDatabaseOpenView(hdb, query, &view);
1950 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1951 r = MsiViewExecute(view, rec);
1952 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1954 MsiCloseHandle(rec);
1956 r = MsiViewFetch(view, &rec);
1957 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1959 MsiCloseHandle(rec);
1961 MsiCloseHandle(view);
1963 MsiCloseHandle( hdb );
1964 DeleteFile(msifile);
1967 static CHAR CURR_DIR[MAX_PATH];
1969 static const CHAR test_data[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1970 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1971 "TestTable\tFirstPrimaryColumn\n"
1972 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1974 static const CHAR two_primary[] = "PrimaryOne\tPrimaryTwo\n"
1976 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1980 static const CHAR endlines1[] = "A\tB\tC\tD\tE\tF\r\n"
1981 "s72\ts72\ts72\ts72\ts72\ts72\n"
1983 "a\tb\tc\td\te\tf\n"
1984 "g\th\ti\t\rj\tk\tl\r\n";
1986 static const CHAR endlines2[] = "A\tB\tC\tD\tE\tF\r"
1987 "s72\ts72\ts72\ts72\ts72\ts72\n"
1989 "a\tb\tc\td\te\tf\n"
1990 "g\th\ti\tj\tk\tl\r\n";
1992 static const CHAR suminfo[] = "PropertyId\tValue\n"
1994 "_SummaryInformation\tPropertyId\n"
1996 "2\tInstaller Database\n"
1997 "3\tInstaller description\n"
2000 "6\tInstaller comments\n"
2002 "9\t{12345678-1234-1234-1234-123456789012}\n"
2003 "12\t2009/04/12 15:46:11\n"
2004 "13\t2009/04/12 15:46:11\n"
2010 static void write_file(const CHAR *filename, const char *data, int data_size)
2014 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
2015 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2017 WriteFile(hf, data, data_size, &size, NULL);
2021 static UINT add_table_to_db(MSIHANDLE hdb, LPCSTR table_data)
2025 write_file("temp_file", table_data, (lstrlen(table_data) - 1) * sizeof(char));
2026 r = MsiDatabaseImportA(hdb, CURR_DIR, "temp_file");
2027 DeleteFileA("temp_file");
2032 static void test_suminfo_import(void)
2034 MSIHANDLE hdb, hsi, view = 0;
2036 UINT r, count, size, type;
2041 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
2043 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
2044 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2046 r = add_table_to_db(hdb, suminfo);
2047 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2049 /* _SummaryInformation is not imported as a regular table... */
2051 query = "SELECT * FROM `_SummaryInformation`";
2052 r = MsiDatabaseOpenViewA(hdb, query, &view);
2053 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %u\n", r);
2054 MsiCloseHandle(view);
2056 /* ...its data is added to the special summary information stream */
2058 r = MsiGetSummaryInformationA(hdb, NULL, 0, &hsi);
2059 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2061 r = MsiSummaryInfoGetPropertyCount(hsi, &count);
2062 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2063 ok(count == 14, "Expected 14, got %u\n", count);
2065 r = MsiSummaryInfoGetPropertyA(hsi, PID_CODEPAGE, &type, &int_value, NULL, NULL, NULL);
2066 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2067 ok(type == VT_I2, "Expected VT_I2, got %u\n", type);
2068 ok(int_value == 1252, "Expected 1252, got %d\n", int_value);
2070 size = sizeof(str_value);
2071 r = MsiSummaryInfoGetPropertyA(hsi, PID_TITLE, &type, NULL, NULL, str_value, &size);
2072 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2073 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2074 ok(size == 18, "Expected 18, got %u\n", size);
2075 ok(!strcmp(str_value, "Installer Database"),
2076 "Expected \"Installer Database\", got %s\n", str_value);
2078 size = sizeof(str_value);
2079 r = MsiSummaryInfoGetPropertyA(hsi, PID_SUBJECT, &type, NULL, NULL, str_value, &size);
2080 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2081 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2082 ok(!strcmp(str_value, "Installer description"),
2083 "Expected \"Installer description\", got %s\n", str_value);
2085 size = sizeof(str_value);
2086 r = MsiSummaryInfoGetPropertyA(hsi, PID_AUTHOR, &type, NULL, NULL, str_value, &size);
2087 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2088 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2089 ok(!strcmp(str_value, "WineHQ"),
2090 "Expected \"WineHQ\", got %s\n", str_value);
2092 size = sizeof(str_value);
2093 r = MsiSummaryInfoGetPropertyA(hsi, PID_KEYWORDS, &type, NULL, NULL, str_value, &size);
2094 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2095 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2096 ok(!strcmp(str_value, "Installer"),
2097 "Expected \"Installer\", got %s\n", str_value);
2099 size = sizeof(str_value);
2100 r = MsiSummaryInfoGetPropertyA(hsi, PID_COMMENTS, &type, NULL, NULL, str_value, &size);
2101 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2102 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2103 ok(!strcmp(str_value, "Installer comments"),
2104 "Expected \"Installer comments\", got %s\n", str_value);
2106 size = sizeof(str_value);
2107 r = MsiSummaryInfoGetPropertyA(hsi, PID_TEMPLATE, &type, NULL, NULL, str_value, &size);
2108 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2109 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2110 ok(!strcmp(str_value, "Intel;1033"),
2111 "Expected \"Intel;1033\", got %s\n", str_value);
2113 size = sizeof(str_value);
2114 r = MsiSummaryInfoGetPropertyA(hsi, PID_REVNUMBER, &type, NULL, NULL, str_value, &size);
2115 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2116 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2117 ok(!strcmp(str_value, "{12345678-1234-1234-1234-123456789012}"),
2118 "Expected \"{12345678-1234-1234-1234-123456789012}\", got %s\n", str_value);
2120 r = MsiSummaryInfoGetPropertyA(hsi, PID_CREATE_DTM, &type, NULL, &ft_value, NULL, NULL);
2121 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2122 ok(type == VT_FILETIME, "Expected VT_FILETIME, got %u\n", type);
2124 r = MsiSummaryInfoGetPropertyA(hsi, PID_LASTSAVE_DTM, &type, NULL, &ft_value, NULL, NULL);
2125 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2126 ok(type == VT_FILETIME, "Expected VT_FILETIME, got %u\n", type);
2128 r = MsiSummaryInfoGetPropertyA(hsi, PID_PAGECOUNT, &type, &int_value, NULL, NULL, NULL);
2129 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2130 ok(type == VT_I4, "Expected VT_I4, got %u\n", type);
2131 ok(int_value == 200, "Expected 200, got %d\n", int_value);
2133 r = MsiSummaryInfoGetPropertyA(hsi, PID_WORDCOUNT, &type, &int_value, NULL, NULL, NULL);
2134 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2135 ok(type == VT_I4, "Expected VT_I4, got %u\n", type);
2136 ok(int_value == 2, "Expected 2, got %d\n", int_value);
2138 r = MsiSummaryInfoGetPropertyA(hsi, PID_SECURITY, &type, &int_value, NULL, NULL, NULL);
2139 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2140 ok(type == VT_I4, "Expected VT_I4, got %u\n", type);
2141 ok(int_value == 2, "Expected 2, got %d\n", int_value);
2143 size = sizeof(str_value);
2144 r = MsiSummaryInfoGetPropertyA(hsi, PID_APPNAME, &type, NULL, NULL, str_value, &size);
2145 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2146 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2147 ok(!strcmp(str_value, "Vim"), "Expected \"Vim\", got %s\n", str_value);
2149 MsiCloseHandle(hsi);
2150 MsiCloseHandle(hdb);
2151 DeleteFileA(msifile);
2154 static void test_msiimport(void)
2156 MSIHANDLE hdb, view, rec;
2161 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
2163 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
2164 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2166 r = add_table_to_db(hdb, test_data);
2167 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2169 r = add_table_to_db(hdb, two_primary);
2170 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2172 r = add_table_to_db(hdb, endlines1);
2173 if (r == ERROR_FUNCTION_FAILED)
2175 /* win9x doesn't handle this case */
2176 skip("endlines not handled correctly.\n");
2177 MsiCloseHandle(hdb);
2178 DeleteFileA(msifile);
2182 r = add_table_to_db(hdb, endlines2);
2183 ok(r == ERROR_FUNCTION_FAILED,
2184 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
2186 query = "SELECT * FROM `TestTable`";
2187 r = MsiDatabaseOpenView(hdb, query, &view);
2188 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2190 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
2191 count = MsiRecordGetFieldCount(rec);
2192 ok(count == 9, "Expected 9, got %d\n", count);
2193 ok(check_record(rec, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
2194 ok(check_record(rec, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
2195 ok(check_record(rec, 3, "ShortInt"), "Expected ShortInt\n");
2196 ok(check_record(rec, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
2197 ok(check_record(rec, 5, "LongInt"), "Expected LongInt\n");
2198 ok(check_record(rec, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
2199 ok(check_record(rec, 7, "String"), "Expected String\n");
2200 ok(check_record(rec, 8, "LocalizableString"), "Expected LocalizableString\n");
2201 ok(check_record(rec, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
2202 MsiCloseHandle(rec);
2204 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2205 count = MsiRecordGetFieldCount(rec);
2206 ok(count == 9, "Expected 9, got %d\n", count);
2207 ok(check_record(rec, 1, "s255"), "Expected s255\n");
2208 ok(check_record(rec, 2, "i2"), "Expected i2\n");
2209 ok(check_record(rec, 3, "i2"), "Expected i2\n");
2210 ok(check_record(rec, 4, "I2"), "Expected I2\n");
2211 ok(check_record(rec, 5, "i4"), "Expected i4\n");
2212 ok(check_record(rec, 6, "I4"), "Expected I4\n");
2213 ok(check_record(rec, 7, "S255"), "Expected S255\n");
2214 ok(check_record(rec, 8, "S0"), "Expected S0\n");
2215 ok(check_record(rec, 9, "s0"), "Expected s0\n");
2216 MsiCloseHandle(rec);
2218 query = "SELECT * FROM `TestTable`";
2219 r = do_query(hdb, query, &rec);
2220 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2221 ok(check_record(rec, 1, "stringage"), "Expected 'stringage'\n");
2222 ok(check_record(rec, 7, "another string"), "Expected 'another string'\n");
2223 ok(check_record(rec, 8, "localizable"), "Expected 'localizable'\n");
2224 ok(check_record(rec, 9, "duh"), "Expected 'duh'\n");
2226 i = MsiRecordGetInteger(rec, 2);
2227 ok(i == 5, "Expected 5, got %d\n", i);
2229 i = MsiRecordGetInteger(rec, 3);
2230 ok(i == 2, "Expected 2, got %d\n", i);
2232 i = MsiRecordGetInteger(rec, 4);
2233 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
2235 i = MsiRecordGetInteger(rec, 5);
2236 ok(i == 2147483640, "Expected 2147483640, got %d\n", i);
2238 i = MsiRecordGetInteger(rec, 6);
2239 ok(i == -2147483640, "Expected -2147483640, got %d\n", i);
2241 MsiCloseHandle(rec);
2243 MsiCloseHandle(view);
2245 query = "SELECT * FROM `TwoPrimary`";
2246 r = MsiDatabaseOpenView(hdb, query, &view);
2247 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2249 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
2250 count = MsiRecordGetFieldCount(rec);
2251 ok(count == 2, "Expected 2, got %d\n", count);
2252 ok(check_record(rec, 1, "PrimaryOne"), "Expected PrimaryOne\n");
2253 ok(check_record(rec, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
2255 MsiCloseHandle(rec);
2257 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2258 count = MsiRecordGetFieldCount(rec);
2259 ok(count == 2, "Expected 2, got %d\n", count);
2260 ok(check_record(rec, 1, "s255"), "Expected s255\n");
2261 ok(check_record(rec, 2, "s255"), "Expected s255\n");
2262 MsiCloseHandle(rec);
2264 r = MsiViewExecute(view, 0);
2265 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2267 r = MsiViewFetch(view, &rec);
2268 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2270 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
2271 ok(check_record(rec, 2, "leaf"), "Expected 'leaf'\n");
2273 MsiCloseHandle(rec);
2275 r = MsiViewFetch(view, &rec);
2276 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2278 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
2279 ok(check_record(rec, 2, "flower"), "Expected 'flower'\n");
2281 MsiCloseHandle(rec);
2283 r = MsiViewFetch(view, &rec);
2284 ok(r == ERROR_NO_MORE_ITEMS,
2285 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
2287 r = MsiViewClose(view);
2288 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2290 MsiCloseHandle(view);
2292 query = "SELECT * FROM `Table`";
2293 r = MsiDatabaseOpenView(hdb, query, &view);
2294 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2296 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
2297 count = MsiRecordGetFieldCount(rec);
2298 ok(count == 6, "Expected 6, got %d\n", count);
2299 ok(check_record(rec, 1, "A"), "Expected A\n");
2300 ok(check_record(rec, 2, "B"), "Expected B\n");
2301 ok(check_record(rec, 3, "C"), "Expected C\n");
2302 ok(check_record(rec, 4, "D"), "Expected D\n");
2303 ok(check_record(rec, 5, "E"), "Expected E\n");
2304 ok(check_record(rec, 6, "F"), "Expected F\n");
2305 MsiCloseHandle(rec);
2307 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2308 count = MsiRecordGetFieldCount(rec);
2309 ok(count == 6, "Expected 6, got %d\n", count);
2310 ok(check_record(rec, 1, "s72"), "Expected s72\n");
2311 ok(check_record(rec, 2, "s72"), "Expected s72\n");
2312 ok(check_record(rec, 3, "s72"), "Expected s72\n");
2313 ok(check_record(rec, 4, "s72"), "Expected s72\n");
2314 ok(check_record(rec, 5, "s72"), "Expected s72\n");
2315 ok(check_record(rec, 6, "s72"), "Expected s72\n");
2316 MsiCloseHandle(rec);
2319 MsiCloseHandle(view);
2321 query = "SELECT * FROM `Table`";
2322 r = MsiDatabaseOpenView(hdb, query, &view);
2323 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2325 r = MsiViewExecute(view, 0);
2326 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2328 r = MsiViewFetch(view, &rec);
2329 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2330 ok(check_record(rec, 1, "a"), "Expected 'a'\n");
2331 ok(check_record(rec, 2, "b"), "Expected 'b'\n");
2332 ok(check_record(rec, 3, "c"), "Expected 'c'\n");
2333 ok(check_record(rec, 4, "d"), "Expected 'd'\n");
2334 ok(check_record(rec, 5, "e"), "Expected 'e'\n");
2335 ok(check_record(rec, 6, "f"), "Expected 'f'\n");
2337 MsiCloseHandle(rec);
2339 r = MsiViewFetch(view, &rec);
2340 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2341 ok(check_record(rec, 1, "g"), "Expected 'g'\n");
2342 ok(check_record(rec, 2, "h"), "Expected 'h'\n");
2343 ok(check_record(rec, 3, "i"), "Expected 'i'\n");
2344 ok(check_record(rec, 4, "j"), "Expected 'j'\n");
2345 ok(check_record(rec, 5, "k"), "Expected 'k'\n");
2346 ok(check_record(rec, 6, "l"), "Expected 'l'\n");
2348 MsiCloseHandle(rec);
2350 r = MsiViewFetch(view, &rec);
2351 ok(r == ERROR_NO_MORE_ITEMS,
2352 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
2355 MsiCloseHandle(view);
2356 MsiCloseHandle(hdb);
2357 DeleteFileA(msifile);
2360 static const CHAR bin_import_dat[] = "Name\tData\r\n"
2363 "filename1\tfilename1.ibd\r\n";
2365 static void test_binary_import(void)
2367 MSIHANDLE hdb = 0, rec;
2368 char file[MAX_PATH];
2370 char path[MAX_PATH];
2375 /* create files to import */
2376 write_file("bin_import.idt", bin_import_dat,
2377 (sizeof(bin_import_dat) - 1) * sizeof(char));
2378 CreateDirectory("bin_import", NULL);
2379 create_file_data("bin_import/filename1.ibd", "just some words", 15);
2381 /* import files into database */
2382 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
2383 ok( r == ERROR_SUCCESS , "Failed to open database\n");
2385 GetCurrentDirectory(MAX_PATH, path);
2386 r = MsiDatabaseImport(hdb, path, "bin_import.idt");
2387 ok(r == ERROR_SUCCESS , "Failed to import Binary table\n");
2389 /* read file from the Binary table */
2390 query = "SELECT * FROM `Binary`";
2391 r = do_query(hdb, query, &rec);
2392 ok(r == ERROR_SUCCESS, "SELECT query failed: %d\n", r);
2395 r = MsiRecordGetString(rec, 1, file, &size);
2396 ok(r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
2397 ok(!lstrcmp(file, "filename1"), "Expected 'filename1', got %s\n", file);
2400 memset(buf, 0, MAX_PATH);
2401 r = MsiRecordReadStream(rec, 2, buf, &size);
2402 ok(r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
2403 ok(!lstrcmp(buf, "just some words"),
2404 "Expected 'just some words', got %s\n", buf);
2406 r = MsiCloseHandle(rec);
2407 ok(r == ERROR_SUCCESS , "Failed to close record handle\n");
2409 r = MsiCloseHandle(hdb);
2410 ok(r == ERROR_SUCCESS , "Failed to close database\n");
2412 DeleteFile("bin_import/filename1.ibd");
2413 RemoveDirectory("bin_import");
2414 DeleteFile("bin_import.idt");
2417 static void test_markers(void)
2424 ok( hdb, "failed to create db\n");
2426 rec = MsiCreateRecord(3);
2427 MsiRecordSetString(rec, 1, "Table");
2428 MsiRecordSetString(rec, 2, "Apples");
2429 MsiRecordSetString(rec, 3, "Oranges");
2431 /* try a legit create */
2432 query = "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2433 r = run_query(hdb, 0, query);
2434 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2435 MsiCloseHandle(rec);
2437 /* try table name as marker */
2438 rec = MsiCreateRecord(1);
2439 MsiRecordSetString(rec, 1, "Fable");
2440 query = "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2441 r = run_query(hdb, rec, query);
2442 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2444 /* verify that we just created a table called '?', not 'Fable' */
2445 r = try_query(hdb, "SELECT * from `Fable`");
2446 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2448 r = try_query(hdb, "SELECT * from `?`");
2449 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2451 /* try table name as marker without backticks */
2452 MsiRecordSetString(rec, 1, "Mable");
2453 query = "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2454 r = run_query(hdb, rec, query);
2455 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2457 /* try one column name as marker */
2458 MsiRecordSetString(rec, 1, "One");
2459 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2460 r = run_query(hdb, rec, query);
2461 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2462 MsiCloseHandle(rec);
2464 /* try column names as markers */
2465 rec = MsiCreateRecord(2);
2466 MsiRecordSetString(rec, 1, "One");
2467 MsiRecordSetString(rec, 2, "Two");
2468 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
2469 r = run_query(hdb, rec, query);
2470 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2471 MsiCloseHandle(rec);
2473 /* try names with backticks */
2474 rec = MsiCreateRecord(3);
2475 MsiRecordSetString(rec, 1, "One");
2476 MsiRecordSetString(rec, 2, "Two");
2477 MsiRecordSetString(rec, 3, "One");
2478 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
2479 r = run_query(hdb, rec, query);
2480 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2482 /* try names with backticks, minus definitions */
2483 query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
2484 r = run_query(hdb, rec, query);
2485 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2487 /* try names without backticks */
2488 query = "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
2489 r = run_query(hdb, rec, query);
2490 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2491 MsiCloseHandle(rec);
2493 /* try one long marker */
2494 rec = MsiCreateRecord(1);
2495 MsiRecordSetString(rec, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
2496 query = "CREATE TABLE `Mable` ( ? )";
2497 r = run_query(hdb, rec, query);
2498 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2499 MsiCloseHandle(rec);
2501 /* try all names as markers */
2502 rec = MsiCreateRecord(4);
2503 MsiRecordSetString(rec, 1, "Mable");
2504 MsiRecordSetString(rec, 2, "One");
2505 MsiRecordSetString(rec, 3, "Two");
2506 MsiRecordSetString(rec, 4, "One");
2507 query = "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
2508 r = run_query(hdb, rec, query);
2509 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2510 MsiCloseHandle(rec);
2512 /* try a legit insert */
2513 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
2514 r = run_query(hdb, 0, query);
2515 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2517 r = try_query(hdb, "SELECT * from `Table`");
2518 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2520 /* try values as markers */
2521 rec = MsiCreateRecord(2);
2522 MsiRecordSetInteger(rec, 1, 4);
2523 MsiRecordSetString(rec, 2, "hi");
2524 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2525 r = run_query(hdb, rec, query);
2526 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2527 MsiCloseHandle(rec);
2529 /* try column names and values as markers */
2530 rec = MsiCreateRecord(4);
2531 MsiRecordSetString(rec, 1, "One");
2532 MsiRecordSetString(rec, 2, "Two");
2533 MsiRecordSetInteger(rec, 3, 5);
2534 MsiRecordSetString(rec, 4, "hi");
2535 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
2536 r = run_query(hdb, rec, query);
2537 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2538 MsiCloseHandle(rec);
2540 /* try column names as markers */
2541 rec = MsiCreateRecord(2);
2542 MsiRecordSetString(rec, 1, "One");
2543 MsiRecordSetString(rec, 2, "Two");
2544 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
2545 r = run_query(hdb, rec, query);
2546 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2547 MsiCloseHandle(rec);
2549 /* try table name as a marker */
2550 rec = MsiCreateRecord(1);
2551 MsiRecordSetString(rec, 1, "Table");
2552 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
2553 r = run_query(hdb, rec, query);
2554 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2555 MsiCloseHandle(rec);
2557 /* try table name and values as markers */
2558 rec = MsiCreateRecord(3);
2559 MsiRecordSetString(rec, 1, "Table");
2560 MsiRecordSetInteger(rec, 2, 10);
2561 MsiRecordSetString(rec, 3, "haha");
2562 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
2563 r = run_query(hdb, rec, query);
2564 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
2565 MsiCloseHandle(rec);
2567 /* try all markers */
2568 rec = MsiCreateRecord(5);
2569 MsiRecordSetString(rec, 1, "Table");
2570 MsiRecordSetString(rec, 1, "One");
2571 MsiRecordSetString(rec, 1, "Two");
2572 MsiRecordSetInteger(rec, 2, 10);
2573 MsiRecordSetString(rec, 3, "haha");
2574 query = "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
2575 r = run_query(hdb, rec, query);
2576 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2577 MsiCloseHandle(rec);
2579 /* insert an integer as a string */
2580 rec = MsiCreateRecord(2);
2581 MsiRecordSetString(rec, 1, "11");
2582 MsiRecordSetString(rec, 2, "hi");
2583 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2584 r = run_query(hdb, rec, query);
2585 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2586 MsiCloseHandle(rec);
2588 /* leave off the '' for the string */
2589 rec = MsiCreateRecord(2);
2590 MsiRecordSetInteger(rec, 1, 12);
2591 MsiRecordSetString(rec, 2, "hi");
2592 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
2593 r = run_query(hdb, rec, query);
2594 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2595 MsiCloseHandle(rec);
2597 MsiCloseHandle(hdb);
2598 DeleteFileA(msifile);
2601 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
2602 static void test_handle_limit(void)
2606 MSIHANDLE hviews[MY_NVIEWS];
2609 /* create an empty db */
2611 ok( hdb, "failed to create db\n");
2613 memset(hviews, 0, sizeof(hviews));
2615 for (i=0; i<MY_NVIEWS; i++) {
2616 static char szQueryBuf[256] = "SELECT * from `_Tables`";
2617 hviews[i] = 0xdeadbeeb;
2618 r = MsiDatabaseOpenView(hdb, szQueryBuf, &hviews[i]);
2619 if( r != ERROR_SUCCESS || hviews[i] == 0xdeadbeeb ||
2620 hviews[i] == 0 || (i && (hviews[i] == hviews[i-1])))
2624 ok( i == MY_NVIEWS, "problem opening views\n");
2626 for (i=0; i<MY_NVIEWS; i++) {
2627 if (hviews[i] != 0 && hviews[i] != 0xdeadbeeb) {
2628 MsiViewClose(hviews[i]);
2629 r = MsiCloseHandle(hviews[i]);
2630 if (r != ERROR_SUCCESS)
2635 ok( i == MY_NVIEWS, "problem closing views\n");
2637 r = MsiCloseHandle(hdb);
2638 ok( r == ERROR_SUCCESS, "failed to close database\n");
2641 static void generate_transform(void)
2643 MSIHANDLE hdb1, hdb2, hrec;
2647 /* start with two identical databases */
2648 CopyFile(msifile2, msifile, FALSE);
2650 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb1 );
2651 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2653 r = MsiDatabaseCommit( hdb1 );
2654 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
2656 r = MsiOpenDatabase(msifile2, MSIDBOPEN_READONLY, &hdb2 );
2657 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2659 /* the transform between two identical database should be empty */
2660 r = MsiDatabaseGenerateTransform(hdb1, hdb2, NULL, 0, 0);
2662 ok( r == ERROR_NO_DATA, "return code %d, should be ERROR_NO_DATA\n", r );
2665 query = "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
2666 r = run_query(hdb1, 0, query);
2667 ok(r == ERROR_SUCCESS, "failed to add table\n");
2669 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
2670 r = run_query(hdb1, 0, query);
2671 ok(r == ERROR_SUCCESS, "failed to add row 1\n");
2673 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
2674 r = run_query(hdb1, 0, query);
2675 ok(r == ERROR_SUCCESS, "failed to add row 2\n");
2677 query = "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
2678 r = run_query(hdb1, 0, query);
2679 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2681 query = "DELETE FROM `MOO` WHERE `NOO` = 3";
2682 r = run_query(hdb1, 0, query);
2683 ok(r == ERROR_SUCCESS, "failed to delete row\n");
2685 hrec = MsiCreateRecord(2);
2686 r = MsiRecordSetInteger(hrec, 1, 1);
2687 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2689 write_file("testdata.bin", "naengmyon", 9);
2690 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2691 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2693 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2694 r = run_query(hdb1, hrec, query);
2695 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2697 MsiCloseHandle(hrec);
2699 query = "ALTER TABLE `MOO` ADD `COW` INTEGER";
2700 r = run_query(hdb1, 0, query);
2701 ok(r == ERROR_SUCCESS, "failed to add column\n");
2703 query = "ALTER TABLE `MOO` ADD `PIG` INTEGER";
2704 r = run_query(hdb1, 0, query);
2705 ok(r == ERROR_SUCCESS, "failed to add column\n");
2707 query = "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
2708 r = run_query(hdb1, 0, query);
2709 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2711 query = "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
2712 "`Value` CHAR(0) PRIMARY KEY `Property`)";
2713 r = run_query(hdb1, 0, query);
2714 ok(r == ERROR_SUCCESS, "failed to add property table\n");
2716 query = "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2717 r = run_query(hdb1, 0, query);
2718 ok(r == ERROR_SUCCESS, "failed to add property\n");
2720 /* database needs to be committed */
2721 MsiDatabaseCommit(hdb1);
2723 r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
2724 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
2726 MsiCloseHandle( hdb1 );
2727 MsiCloseHandle( hdb2 );
2729 DeleteFile("testdata.bin");
2732 /* data for generating a transform */
2734 /* tables transform names - encoded as they would be in an msi database file */
2735 static const WCHAR name1[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
2736 static const WCHAR name2[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
2737 static const WCHAR name3[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
2738 static const WCHAR name4[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2739 static const WCHAR name5[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2740 static const WCHAR name6[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
2741 static const WCHAR name7[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
2742 static const WCHAR name8[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
2743 static const WCHAR name9[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2745 /* data in each table */
2746 static const WCHAR data1[] = { /* AAR */
2747 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
2748 0x0201, 0x0009, 0x8002,
2750 static const WCHAR data2[] = { /* _Columns */
2751 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
2752 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
2753 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
2754 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
2755 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
2756 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
2758 static const WCHAR data3[] = { /* _Tables */
2759 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
2762 static const char data4[] = /* _StringData */
2763 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
2764 static const WCHAR data5[] = { /* _StringPool */
2766 0, 0, /* string 0 '' */
2767 3, 2, /* string 1 'MOO' */
2768 3, 1, /* string 2 'COW' */
2769 3, 1, /* string 3 'PIG' */
2770 1, 1, /* string 4 'c' */
2771 3, 3, /* string 5 'AAR' */
2772 3, 1, /* string 6 'CAR' */
2773 3, 1, /* string 7 'BAR' */
2774 2, 1, /* string 8 'vw' */
2775 3, 1, /* string 9 'bmw' */
2776 8, 4, /* string 10 'Property' */
2777 5, 1, /* string 11 'Value' */
2778 4, 1, /* string 12 'prop' */
2779 3, 1, /* string 13 'val' */
2781 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
2782 static const WCHAR data6[] = { /* MOO */
2783 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
2784 0x0000, 0x8003, /* delete row */
2787 static const WCHAR data7[] = { /* BINARY */
2788 0x0201, 0x8001, 0x0001,
2791 static const char data8[] = /* stream data for the BINARY table */
2794 static const WCHAR data9[] = { /* Property */
2795 0x0201, 0x000c, 0x000d,
2798 static const struct {
2802 } table_transform_data[] =
2804 { name1, data1, sizeof data1 },
2805 { name2, data2, sizeof data2 },
2806 { name3, data3, sizeof data3 },
2807 { name4, data4, sizeof data4 - 1 },
2808 { name5, data5, sizeof data5 },
2809 { name6, data6, sizeof data6 },
2810 { name7, data7, sizeof data7 },
2811 { name8, data8, sizeof data8 - 1 },
2812 { name9, data9, sizeof data9 },
2815 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2817 static void generate_transform_manual(void)
2819 IStorage *stg = NULL;
2824 const DWORD mode = STGM_CREATE|STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE;
2826 const CLSID CLSID_MsiTransform = { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2828 MultiByteToWideChar(CP_ACP, 0, mstfile, -1, name, 0x20);
2830 r = StgCreateDocfile(name, mode, 0, &stg);
2831 ok(r == S_OK, "failed to create storage\n");
2835 r = IStorage_SetClass( stg, &CLSID_MsiTransform );
2836 ok(r == S_OK, "failed to set storage type\n");
2838 for (i=0; i<NUM_TRANSFORM_TABLES; i++)
2840 r = IStorage_CreateStream( stg, table_transform_data[i].name,
2841 STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm );
2844 ok(0, "failed to create stream %08x\n", r);
2848 r = IStream_Write( stm, table_transform_data[i].data,
2849 table_transform_data[i].size, &count );
2850 if (FAILED(r) || count != table_transform_data[i].size)
2851 ok(0, "failed to write stream\n");
2852 IStream_Release(stm);
2855 IStorage_Release(stg);
2858 static UINT set_summary_info(MSIHANDLE hdb)
2863 /* build summary info */
2864 res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
2865 ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );
2867 res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
2868 "Installation Database");
2869 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2871 res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
2872 "Installation Database");
2873 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2875 res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
2877 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2879 res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
2881 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2883 res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
2884 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2885 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2887 res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
2888 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2890 res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
2891 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2893 res = MsiSummaryInfoPersist(suminfo);
2894 ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );
2896 res = MsiCloseHandle( suminfo);
2897 ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );
2902 static MSIHANDLE create_package_db(LPCSTR filename)
2907 DeleteFile(msifile);
2909 /* create an empty database */
2910 res = MsiOpenDatabase(filename, MSIDBOPEN_CREATE, &hdb );
2911 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
2912 if( res != ERROR_SUCCESS )
2915 res = MsiDatabaseCommit( hdb );
2916 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
2918 res = set_summary_info(hdb);
2920 res = create_directory_table(hdb);
2921 ok( res == ERROR_SUCCESS , "Failed to create directory table\n" );
2926 static UINT package_from_db(MSIHANDLE hdb, MSIHANDLE *handle)
2932 sprintf(szPackage, "#%u", hdb);
2933 res = MsiOpenPackage(szPackage, &hPackage);
2934 if (res != ERROR_SUCCESS)
2937 res = MsiCloseHandle(hdb);
2938 if (res != ERROR_SUCCESS)
2940 MsiCloseHandle(hPackage);
2945 return ERROR_SUCCESS;
2948 static void test_try_transform(void)
2950 MSIHANDLE hdb, hview, hrec, hpkg = 0;
2954 char buffer[MAX_PATH];
2956 DeleteFile(msifile);
2957 DeleteFile(mstfile);
2959 /* create the database */
2960 hdb = create_package_db(msifile);
2961 ok(hdb, "Failed to create package db\n");
2963 query = "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
2964 r = run_query(hdb, 0, query);
2965 ok(r == ERROR_SUCCESS, "failed to add table\n");
2967 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
2968 r = run_query(hdb, 0, query);
2969 ok(r == ERROR_SUCCESS, "failed to add row\n");
2971 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
2972 r = run_query(hdb, 0, query);
2973 ok(r == ERROR_SUCCESS, "failed to add row\n");
2975 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
2976 r = run_query(hdb, 0, query);
2977 ok(r == ERROR_SUCCESS, "failed to add row\n");
2979 query = "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
2980 r = run_query(hdb, 0, query);
2981 ok(r == ERROR_SUCCESS, "failed to add table\n");
2983 hrec = MsiCreateRecord(2);
2984 r = MsiRecordSetInteger(hrec, 1, 2);
2985 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2987 write_file("testdata.bin", "lamyon", 6);
2988 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2989 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2991 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2992 r = run_query(hdb, hrec, query);
2993 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2995 MsiCloseHandle(hrec);
2997 r = MsiDatabaseCommit( hdb );
2998 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
3000 MsiCloseHandle( hdb );
3001 DeleteFileA("testdata.bin");
3004 * Both these generate an equivalent transform,
3005 * but the first doesn't work in Wine yet
3006 * because MsiDatabaseGenerateTransform is unimplemented.
3009 generate_transform();
3011 generate_transform_manual();
3013 r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb );
3014 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
3016 r = MsiDatabaseApplyTransform( hdb, mstfile, 0 );
3017 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
3019 MsiDatabaseCommit( hdb );
3021 /* check new values */
3023 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
3024 r = do_query(hdb, query, &hrec);
3025 ok(r == ERROR_SUCCESS, "select query failed\n");
3026 MsiCloseHandle(hrec);
3028 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
3030 r = do_query(hdb, query, &hrec);
3031 ok(r == ERROR_SUCCESS, "select query failed\n");
3032 MsiCloseHandle(hrec);
3034 /* check updated values */
3036 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
3037 r = do_query(hdb, query, &hrec);
3038 ok(r == ERROR_SUCCESS, "select query failed\n");
3039 MsiCloseHandle(hrec);
3041 /* check unchanged value */
3043 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
3044 r = do_query(hdb, query, &hrec);
3045 ok(r == ERROR_SUCCESS, "select query failed\n");
3046 MsiCloseHandle(hrec);
3048 /* check deleted value */
3050 query = "select * from `MOO` where `NOO` = 3";
3051 r = do_query(hdb, query, &hrec);
3052 ok(r == ERROR_NO_MORE_ITEMS, "select query failed\n");
3053 if (hrec) MsiCloseHandle(hrec);
3055 /* check added stream */
3057 query = "select `BLOB` from `BINARY` where `ID` = 1";
3058 r = do_query(hdb, query, &hrec);
3059 ok(r == ERROR_SUCCESS, "select query failed\n");
3061 /* check the contents of the stream */
3063 r = MsiRecordReadStream( hrec, 1, buffer, &sz );
3064 ok(r == ERROR_SUCCESS, "read stream failed\n");
3065 ok(!memcmp(buffer, "naengmyon", 9), "stream data was wrong\n");
3066 ok(sz == 9, "stream data was wrong size\n");
3067 if (hrec) MsiCloseHandle(hrec);
3069 /* check the validity of the table with a deleted row */
3071 query = "select * from `MOO`";
3072 r = MsiDatabaseOpenView(hdb, query, &hview);
3073 ok(r == ERROR_SUCCESS, "open view failed\n");
3075 r = MsiViewExecute(hview, 0);
3076 ok(r == ERROR_SUCCESS, "view execute failed\n");
3078 r = MsiViewFetch(hview, &hrec);
3079 ok(r == ERROR_SUCCESS, "view fetch failed\n");
3081 r = MsiRecordGetInteger(hrec, 1);
3082 ok(r == 1, "Expected 1, got %d\n", r);
3085 r = MsiRecordGetString(hrec, 2, buffer, &sz);
3086 ok(r == ERROR_SUCCESS, "record get string failed\n");
3087 ok(!lstrcmpA(buffer, "c"), "Expected c, got %s\n", buffer);
3089 r = MsiRecordGetInteger(hrec, 3);
3090 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
3092 r = MsiRecordGetInteger(hrec, 4);
3093 ok(r == 5, "Expected 5, got %d\n", r);
3095 MsiCloseHandle(hrec);
3097 r = MsiViewFetch(hview, &hrec);
3098 ok(r == ERROR_SUCCESS, "view fetch failed\n");
3100 r = MsiRecordGetInteger(hrec, 1);
3101 ok(r == 2, "Expected 2, got %d\n", r);
3104 r = MsiRecordGetString(hrec, 2, buffer, &sz);
3105 ok(r == ERROR_SUCCESS, "record get string failed\n");
3106 ok(!lstrcmpA(buffer, "b"), "Expected b, got %s\n", buffer);
3108 r = MsiRecordGetInteger(hrec, 3);
3109 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
3111 r = MsiRecordGetInteger(hrec, 4);
3112 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
3114 MsiCloseHandle(hrec);
3116 r = MsiViewFetch(hview, &hrec);
3117 ok(r == ERROR_NO_MORE_ITEMS, "view fetch succeeded\n");
3119 MsiCloseHandle(hrec);
3120 MsiViewClose(hview);
3121 MsiCloseHandle(hview);
3123 /* check that the property was added */
3124 r = package_from_db(hdb, &hpkg);
3125 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
3128 r = MsiGetProperty(hpkg, "prop", buffer, &sz);
3129 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3130 ok(!lstrcmp(buffer, "val"), "Expected val, got %s\n", buffer);
3132 MsiCloseHandle(hpkg);
3133 MsiCloseHandle(hdb);
3135 DeleteFile(msifile);
3136 DeleteFile(mstfile);
3141 const CHAR one[MAX_PATH];
3142 const CHAR two[MAX_PATH];
3145 struct join_res_4col
3147 const CHAR one[MAX_PATH];
3148 const CHAR two[MAX_PATH];
3149 const CHAR three[MAX_PATH];
3150 const CHAR four[MAX_PATH];
3153 struct join_res_uint
3163 static const struct join_res join_res_first[] =
3165 { "alveolar", "procerus" },
3166 { "septum", "procerus" },
3167 { "septum", "nasalis" },
3168 { "ramus", "nasalis" },
3169 { "malar", "mentalis" },
3172 static const struct join_res join_res_second[] =
3174 { "nasal", "septum" },
3175 { "mandible", "ramus" },
3178 static const struct join_res join_res_third[] =
3180 { "msvcp.dll", "abcdefgh" },
3181 { "msvcr.dll", "ijklmnop" },
3184 static const struct join_res join_res_fourth[] =
3186 { "msvcp.dll.01234", "single.dll.31415" },
3189 static const struct join_res join_res_fifth[] =
3191 { "malar", "procerus" },
3194 static const struct join_res join_res_sixth[] =
3196 { "malar", "procerus" },
3197 { "malar", "procerus" },
3198 { "malar", "nasalis" },
3199 { "malar", "nasalis" },
3200 { "malar", "nasalis" },
3201 { "malar", "mentalis" },
3204 static const struct join_res join_res_seventh[] =
3206 { "malar", "nasalis" },
3207 { "malar", "nasalis" },
3208 { "malar", "nasalis" },
3211 static const struct join_res_4col join_res_eighth[] =
3213 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
3214 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
3215 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
3216 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
3217 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
3218 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
3221 static const struct join_res_uint join_res_ninth[] =
3223 { 1, 2, 3, 4, 7, 8 },
3224 { 1, 2, 5, 6, 7, 8 },
3225 { 1, 2, 3, 4, 9, 10 },
3226 { 1, 2, 5, 6, 9, 10 },
3227 { 1, 2, 3, 4, 11, 12 },
3228 { 1, 2, 5, 6, 11, 12 },
3231 static void test_join(void)
3233 MSIHANDLE hdb, hview, hrec;
3241 ok( hdb, "failed to create db\n");
3243 r = create_component_table( hdb );
3244 ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
3246 r = add_component_entry( hdb, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
3247 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3249 r = add_component_entry( hdb, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
3250 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3252 r = add_component_entry( hdb, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
3253 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3255 r = add_component_entry( hdb, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
3256 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3258 r = create_feature_components_table( hdb );
3259 ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
3261 r = add_feature_components_entry( hdb, "'procerus', 'maxilla'" );
3262 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3264 r = add_feature_components_entry( hdb, "'procerus', 'nasal'" );
3265 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3267 r = add_feature_components_entry( hdb, "'nasalis', 'nasal'" );
3268 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3270 r = add_feature_components_entry( hdb, "'nasalis', 'mandible'" );
3271 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3273 r = add_feature_components_entry( hdb, "'nasalis', 'notacomponent'" );
3274 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3276 r = add_feature_components_entry( hdb, "'mentalis', 'zygomatic'" );
3277 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3279 r = create_std_dlls_table( hdb );
3280 ok( r == ERROR_SUCCESS, "cannot create StdDlls table: %d\n", r );
3282 r = add_std_dlls_entry( hdb, "'msvcp.dll', 'msvcp.dll.01234'" );
3283 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
3285 r = add_std_dlls_entry( hdb, "'msvcr.dll', 'msvcr.dll.56789'" );
3286 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
3288 r = create_binary_table( hdb );
3289 ok( r == ERROR_SUCCESS, "cannot create Binary table: %d\n", r );
3291 r = add_binary_entry( hdb, "'msvcp.dll.01234', 'abcdefgh'" );
3292 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
3294 r = add_binary_entry( hdb, "'msvcr.dll.56789', 'ijklmnop'" );
3295 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
3297 r = add_binary_entry( hdb, "'single.dll.31415', 'msvcp.dll'" );
3298 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
3300 query = "CREATE TABLE `One` (`A` SHORT, `B` SHORT PRIMARY KEY `A`)";
3301 r = run_query( hdb, 0, query);
3302 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3304 query = "CREATE TABLE `Two` (`C` SHORT, `D` SHORT PRIMARY KEY `C`)";
3305 r = run_query( hdb, 0, query);
3306 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3308 query = "CREATE TABLE `Three` (`E` SHORT, `F` SHORT PRIMARY KEY `E`)";
3309 r = run_query( hdb, 0, query);
3310 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3312 query = "INSERT INTO `One` (`A`, `B`) VALUES (1, 2)";
3313 r = run_query( hdb, 0, query);
3314 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3316 query = "INSERT INTO `Two` (`C`, `D`) VALUES (3, 4)";
3317 r = run_query( hdb, 0, query);
3318 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3320 query = "INSERT INTO `Two` (`C`, `D`) VALUES (5, 6)";
3321 r = run_query( hdb, 0, query);
3322 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3324 query = "INSERT INTO `Three` (`E`, `F`) VALUES (7, 8)";
3325 r = run_query( hdb, 0, query);
3326 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3328 query = "INSERT INTO `Three` (`E`, `F`) VALUES (9, 10)";
3329 r = run_query( hdb, 0, query);
3330 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3332 query = "INSERT INTO `Three` (`E`, `F`) VALUES (11, 12)";
3333 r = run_query( hdb, 0, query);
3334 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3336 query = "CREATE TABLE `Four` (`G` SHORT, `H` SHORT PRIMARY KEY `G`)";
3337 r = run_query( hdb, 0, query);
3338 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3340 query = "CREATE TABLE `Five` (`I` SHORT, `J` SHORT PRIMARY KEY `I`)";
3341 r = run_query( hdb, 0, query);
3342 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3344 query = "INSERT INTO `Five` (`I`, `J`) VALUES (13, 14)";
3345 r = run_query( hdb, 0, query);
3346 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3348 query = "INSERT INTO `Five` (`I`, `J`) VALUES (15, 16)";
3349 r = run_query( hdb, 0, query);
3350 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3352 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3353 "FROM `Component`, `FeatureComponents` "
3354 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
3355 "ORDER BY `Feature_`";
3356 r = MsiDatabaseOpenView(hdb, query, &hview);
3357 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3359 r = MsiViewExecute(hview, 0);
3360 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3363 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3365 count = MsiRecordGetFieldCount( hrec );
3366 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3369 r = MsiRecordGetString( hrec, 1, buf, &size );
3370 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3371 ok( !lstrcmp( buf, join_res_first[i].one ),
3372 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_first[i].one, buf );
3375 r = MsiRecordGetString( hrec, 2, buf, &size );
3376 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3377 ok( !lstrcmp( buf, join_res_first[i].two ),
3378 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_first[i].two, buf );
3381 MsiCloseHandle(hrec);
3384 ok( i == 5, "Expected 5 rows, got %d\n", i );
3385 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3387 MsiViewClose(hview);
3388 MsiCloseHandle(hview);
3390 /* try a join without a WHERE condition */
3391 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3392 "FROM `Component`, `FeatureComponents` ";
3393 r = MsiDatabaseOpenView(hdb, query, &hview);
3394 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3396 r = MsiViewExecute(hview, 0);
3397 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3400 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3403 MsiCloseHandle(hrec);
3405 ok( i == 24, "Expected 24 rows, got %d\n", i );
3407 MsiViewClose(hview);
3408 MsiCloseHandle(hview);
3410 query = "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
3411 "WHERE FeatureComponents.Component_=Component.Component "
3412 "AND (Feature_='nasalis') ORDER BY Feature_";
3413 r = MsiDatabaseOpenView(hdb, query, &hview);
3414 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3416 r = MsiViewExecute(hview, 0);
3417 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3420 data_correct = TRUE;
3421 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3423 count = MsiRecordGetFieldCount( hrec );
3424 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3427 r = MsiRecordGetString( hrec, 1, buf, &size );
3428 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3429 if( lstrcmp( buf, join_res_second[i].one ))
3430 data_correct = FALSE;
3433 r = MsiRecordGetString( hrec, 2, buf, &size );
3434 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3435 if( lstrcmp( buf, join_res_second[i].two ))
3436 data_correct = FALSE;
3439 MsiCloseHandle(hrec);
3442 ok( data_correct, "data returned in the wrong order\n");
3444 ok( i == 2, "Expected 2 rows, got %d\n", i );
3445 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3447 MsiViewClose(hview);
3448 MsiCloseHandle(hview);
3450 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3451 "FROM `StdDlls`, `Binary` "
3452 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
3454 r = MsiDatabaseOpenView(hdb, query, &hview);
3455 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3457 r = MsiViewExecute(hview, 0);
3458 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3461 data_correct = TRUE;
3462 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3464 count = MsiRecordGetFieldCount( hrec );
3465 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3468 r = MsiRecordGetString( hrec, 1, buf, &size );
3469 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3470 if( lstrcmp( buf, join_res_third[i].one ) )
3471 data_correct = FALSE;
3474 r = MsiRecordGetString( hrec, 2, buf, &size );
3475 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3476 if( lstrcmp( buf, join_res_third[i].two ) )
3477 data_correct = FALSE;
3480 MsiCloseHandle(hrec);
3482 ok( data_correct, "data returned in the wrong order\n");
3484 ok( i == 2, "Expected 2 rows, got %d\n", i );
3486 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3488 MsiViewClose(hview);
3489 MsiCloseHandle(hview);
3491 query = "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
3492 "FROM `StdDlls`, `Binary` "
3493 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
3495 r = MsiDatabaseOpenView(hdb, query, &hview);
3496 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3498 r = MsiViewExecute(hview, 0);
3499 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3502 data_correct = TRUE;
3503 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3505 count = MsiRecordGetFieldCount( hrec );
3506 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3509 r = MsiRecordGetString( hrec, 1, buf, &size );
3510 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3511 if( lstrcmp( buf, join_res_fourth[i].one ))
3512 data_correct = FALSE;
3515 r = MsiRecordGetString( hrec, 2, buf, &size );
3516 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3517 if( lstrcmp( buf, join_res_fourth[i].two ))
3518 data_correct = FALSE;
3521 MsiCloseHandle(hrec);
3523 ok( data_correct, "data returned in the wrong order\n");
3525 ok( i == 1, "Expected 1 rows, got %d\n", i );
3526 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3528 MsiViewClose(hview);
3529 MsiCloseHandle(hview);
3531 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3532 "FROM `Component`, `FeatureComponents` "
3533 "WHERE `Component`.`Component` = 'zygomatic' "
3534 "AND `FeatureComponents`.`Component_` = 'maxilla' "
3535 "ORDER BY `Feature_`";
3536 r = MsiDatabaseOpenView(hdb, query, &hview);
3537 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3539 r = MsiViewExecute(hview, 0);
3540 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3543 data_correct = TRUE;
3544 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3546 count = MsiRecordGetFieldCount( hrec );
3547 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3550 r = MsiRecordGetString( hrec, 1, buf, &size );
3551 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3552 if( lstrcmp( buf, join_res_fifth[i].one ))
3553 data_correct = FALSE;
3556 r = MsiRecordGetString( hrec, 2, buf, &size );
3557 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3558 if( lstrcmp( buf, join_res_fifth[i].two ))
3559 data_correct = FALSE;
3562 MsiCloseHandle(hrec);
3564 ok( data_correct, "data returned in the wrong order\n");
3566 ok( i == 1, "Expected 1 rows, got %d\n", i );
3567 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3569 MsiViewClose(hview);
3570 MsiCloseHandle(hview);
3572 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3573 "FROM `Component`, `FeatureComponents` "
3574 "WHERE `Component` = 'zygomatic' "
3575 "ORDER BY `Feature_`";
3576 r = MsiDatabaseOpenView(hdb, query, &hview);
3577 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3579 r = MsiViewExecute(hview, 0);
3580 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3583 data_correct = TRUE;
3584 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3586 count = MsiRecordGetFieldCount( hrec );
3587 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3590 r = MsiRecordGetString( hrec, 1, buf, &size );
3591 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3592 if( lstrcmp( buf, join_res_sixth[i].one ))
3593 data_correct = FALSE;
3596 r = MsiRecordGetString( hrec, 2, buf, &size );
3597 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3598 if( lstrcmp( buf, join_res_sixth[i].two ))
3599 data_correct = FALSE;
3602 MsiCloseHandle(hrec);
3604 ok( data_correct, "data returned in the wrong order\n");
3606 ok( i == 6, "Expected 6 rows, got %d\n", i );
3607 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3609 MsiViewClose(hview);
3610 MsiCloseHandle(hview);
3612 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3613 "FROM `Component`, `FeatureComponents` "
3614 "WHERE `Component` = 'zygomatic' "
3615 "AND `Feature_` = 'nasalis' "
3616 "ORDER BY `Feature_`";
3617 r = MsiDatabaseOpenView(hdb, query, &hview);
3618 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3620 r = MsiViewExecute(hview, 0);
3621 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3624 data_correct = TRUE;
3625 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3627 count = MsiRecordGetFieldCount( hrec );
3628 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3631 r = MsiRecordGetString( hrec, 1, buf, &size );
3632 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3633 if( lstrcmp( buf, join_res_seventh[i].one ))
3634 data_correct = FALSE;
3637 r = MsiRecordGetString( hrec, 2, buf, &size );
3638 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3639 if( lstrcmp( buf, join_res_seventh[i].two ))
3640 data_correct = FALSE;
3643 MsiCloseHandle(hrec);
3646 ok( data_correct, "data returned in the wrong order\n");
3647 ok( i == 3, "Expected 3 rows, got %d\n", i );
3648 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3650 MsiViewClose(hview);
3651 MsiCloseHandle(hview);
3653 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3654 "FROM `StdDlls`, `Binary` ";
3655 r = MsiDatabaseOpenView(hdb, query, &hview);
3656 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3658 r = MsiViewExecute(hview, 0);
3659 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3662 data_correct = TRUE;
3663 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3665 count = MsiRecordGetFieldCount( hrec );
3666 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3669 r = MsiRecordGetString( hrec, 1, buf, &size );
3670 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3671 if( lstrcmp( buf, join_res_eighth[i].one ))
3672 data_correct = FALSE;
3675 r = MsiRecordGetString( hrec, 2, buf, &size );
3676 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3677 if( lstrcmp( buf, join_res_eighth[i].four ))
3678 data_correct = FALSE;
3681 MsiCloseHandle(hrec);
3684 ok( data_correct, "data returned in the wrong order\n");
3685 ok( i == 6, "Expected 6 rows, got %d\n", i );
3686 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3688 MsiViewClose(hview);
3689 MsiCloseHandle(hview);
3691 query = "SELECT * FROM `StdDlls`, `Binary` ";
3692 r = MsiDatabaseOpenView(hdb, query, &hview);
3693 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3695 r = MsiViewExecute(hview, 0);
3696 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3699 data_correct = TRUE;
3700 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3702 count = MsiRecordGetFieldCount( hrec );
3703 ok( count == 4, "Expected 4 record fields, got %d\n", count );
3706 r = MsiRecordGetString( hrec, 1, buf, &size );
3707 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3708 if( lstrcmp( buf, join_res_eighth[i].one ))
3709 data_correct = FALSE;
3712 r = MsiRecordGetString( hrec, 2, buf, &size );
3713 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3714 if( lstrcmp( buf, join_res_eighth[i].two ))
3715 data_correct = FALSE;
3718 r = MsiRecordGetString( hrec, 3, buf, &size );
3719 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3720 if( lstrcmp( buf, join_res_eighth[i].three ))
3721 data_correct = FALSE;
3724 r = MsiRecordGetString( hrec, 4, buf, &size );
3725 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3726 if( lstrcmp( buf, join_res_eighth[i].four ))
3727 data_correct = FALSE;
3730 MsiCloseHandle(hrec);
3732 ok( data_correct, "data returned in the wrong order\n");
3734 ok( i == 6, "Expected 6 rows, got %d\n", i );
3735 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3737 MsiViewClose(hview);
3738 MsiCloseHandle(hview);
3740 query = "SELECT * FROM `One`, `Two`, `Three` ";
3741 r = MsiDatabaseOpenView(hdb, query, &hview);
3742 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3744 r = MsiViewExecute(hview, 0);
3745 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3748 data_correct = TRUE;
3749 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3751 count = MsiRecordGetFieldCount( hrec );
3752 ok( count == 6, "Expected 6 record fields, got %d\n", count );
3754 r = MsiRecordGetInteger( hrec, 1 );
3755 if( r != join_res_ninth[i].one )
3756 data_correct = FALSE;
3758 r = MsiRecordGetInteger( hrec, 2 );
3759 if( r != join_res_ninth[i].two )
3760 data_correct = FALSE;
3762 r = MsiRecordGetInteger( hrec, 3 );
3763 if( r != join_res_ninth[i].three )
3764 data_correct = FALSE;
3766 r = MsiRecordGetInteger( hrec, 4 );
3767 if( r != join_res_ninth[i].four )
3768 data_correct = FALSE;
3770 r = MsiRecordGetInteger( hrec, 5 );
3771 if( r != join_res_ninth[i].five )
3772 data_correct = FALSE;
3774 r = MsiRecordGetInteger( hrec, 6);
3775 if( r != join_res_ninth[i].six )
3776 data_correct = FALSE;
3779 MsiCloseHandle(hrec);
3781 ok( data_correct, "data returned in the wrong order\n");
3783 ok( i == 6, "Expected 6 rows, got %d\n", i );
3784 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3786 MsiViewClose(hview);
3787 MsiCloseHandle(hview);
3789 query = "SELECT * FROM `Four`, `Five`";
3790 r = MsiDatabaseOpenView(hdb, query, &hview);
3791 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3793 r = MsiViewExecute(hview, 0);
3794 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3796 r = MsiViewFetch(hview, &hrec);
3797 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3799 MsiViewClose(hview);
3800 MsiCloseHandle(hview);
3802 query = "SELECT * FROM `Nonexistent`, `One`";
3803 r = MsiDatabaseOpenView(hdb, query, &hview);
3804 ok( r == ERROR_BAD_QUERY_SYNTAX,
3805 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r );
3807 /* try updating a row in a join table */
3808 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3809 "FROM `Component`, `FeatureComponents` "
3810 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
3811 "ORDER BY `Feature_`";
3812 r = MsiDatabaseOpenView(hdb, query, &hview);
3813 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3815 r = MsiViewExecute(hview, 0);
3816 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3818 r = MsiViewFetch(hview, &hrec);
3819 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
3821 r = MsiRecordSetString( hrec, 1, "epicranius" );
3822 ok( r == ERROR_SUCCESS, "failed to set string: %d\n", r );
3824 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
3825 ok( r == ERROR_SUCCESS, "failed to update row: %d\n", r );
3827 /* try another valid operation for joins */
3828 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
3829 todo_wine ok( r == ERROR_SUCCESS, "failed to refresh row: %d\n", r );
3831 /* try an invalid operation for joins */
3832 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
3833 ok( r == ERROR_FUNCTION_FAILED, "unexpected result: %d\n", r );
3835 r = MsiRecordSetString( hrec, 2, "epicranius" );
3836 ok( r == ERROR_SUCCESS, "failed to set string: %d\n", r );
3838 /* primary key cannot be updated */
3839 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
3840 todo_wine ok( r == ERROR_FUNCTION_FAILED, "failed to update row: %d\n", r );
3842 MsiCloseHandle(hrec);
3843 MsiViewClose(hview);
3844 MsiCloseHandle(hview);
3846 r = MsiDatabaseOpenView(hdb, query, &hview);
3847 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3849 r = MsiViewExecute(hview, 0);
3850 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3852 r = MsiViewFetch(hview, &hrec);
3853 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
3856 r = MsiRecordGetString( hrec, 1, buf, &size );
3857 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3858 ok( !lstrcmp( buf, "epicranius" ), "expected 'epicranius', got %s\n", buf );
3860 MsiCloseHandle(hrec);
3861 MsiViewClose(hview);
3862 MsiCloseHandle(hview);
3864 MsiCloseHandle(hdb);
3865 DeleteFile(msifile);
3868 static void test_temporary_table(void)
3871 MSIHANDLE hdb = 0, view = 0, rec;
3877 cond = MsiDatabaseIsTablePersistent(0, NULL);
3878 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3881 ok( hdb, "failed to create db\n");
3883 cond = MsiDatabaseIsTablePersistent(hdb, NULL);
3884 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3886 cond = MsiDatabaseIsTablePersistent(hdb, "_Tables");
3887 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3889 cond = MsiDatabaseIsTablePersistent(hdb, "_Columns");
3890 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3892 cond = MsiDatabaseIsTablePersistent(hdb, "_Storages");
3893 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3895 cond = MsiDatabaseIsTablePersistent(hdb, "_Streams");
3896 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3898 query = "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
3899 r = run_query(hdb, 0, query);
3900 ok(r == ERROR_SUCCESS, "failed to add table\n");
3902 cond = MsiDatabaseIsTablePersistent(hdb, "P");
3903 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3905 query = "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
3906 r = run_query(hdb, 0, query);
3907 ok(r == ERROR_SUCCESS, "failed to add table\n");
3909 cond = MsiDatabaseIsTablePersistent(hdb, "P2");
3910 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3912 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3913 r = run_query(hdb, 0, query);
3914 ok(r == ERROR_SUCCESS, "failed to add table\n");
3916 cond = MsiDatabaseIsTablePersistent(hdb, "T");
3917 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
3919 query = "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3920 r = run_query(hdb, 0, query);
3921 ok(r == ERROR_SUCCESS, "failed to add table\n");
3923 query = "SELECT * FROM `T2`";
3924 r = MsiDatabaseOpenView(hdb, query, &view);
3925 ok(r == ERROR_BAD_QUERY_SYNTAX,
3926 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3928 cond = MsiDatabaseIsTablePersistent(hdb, "T2");
3929 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3931 query = "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
3932 r = run_query(hdb, 0, query);
3933 ok(r == ERROR_SUCCESS, "failed to add table\n");
3935 cond = MsiDatabaseIsTablePersistent(hdb, "T3");
3936 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3938 query = "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3939 r = run_query(hdb, 0, query);
3940 ok(r == ERROR_FUNCTION_FAILED, "failed to add table\n");
3942 cond = MsiDatabaseIsTablePersistent(hdb, "T4");
3943 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3945 query = "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
3946 r = run_query(hdb, 0, query);
3947 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add table\n");
3949 query = "select * from `T`";
3950 r = MsiDatabaseOpenView(hdb, query, &view);
3951 ok(r == ERROR_SUCCESS, "failed to query table\n");
3952 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
3953 ok(r == ERROR_SUCCESS, "failed to get column info\n");
3956 r = MsiRecordGetString(rec, 1, buf, &sz);
3957 ok(r == ERROR_SUCCESS, "failed to get string\n");
3958 ok( 0 == strcmp("G255", buf), "wrong column type\n");
3961 r = MsiRecordGetString(rec, 2, buf, &sz);
3962 ok(r == ERROR_SUCCESS, "failed to get string\n");
3963 ok( 0 == strcmp("j2", buf), "wrong column type\n");
3965 MsiCloseHandle( rec );
3966 MsiViewClose( view );
3967 MsiCloseHandle( view );
3969 /* query the table data */
3971 r = do_query(hdb, "select * from `_Tables` where `Name` = 'T'", &rec);
3972 ok( r == ERROR_SUCCESS, "temporary table exists in _Tables\n");
3973 MsiCloseHandle( rec );
3975 /* query the column data */
3977 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec);
3978 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3979 if (rec) MsiCloseHandle( rec );
3981 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec);
3982 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3983 if (rec) MsiCloseHandle( rec );
3985 MsiCloseHandle( hdb );
3987 DeleteFile(msifile);
3990 static void test_alter(void)
3998 ok( hdb, "failed to create db\n");
4000 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
4001 r = run_query(hdb, 0, query);
4002 ok(r == ERROR_SUCCESS, "failed to add table\n");
4004 cond = MsiDatabaseIsTablePersistent(hdb, "T");
4005 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
4007 query = "ALTER TABLE `T` HOLD";
4008 r = run_query(hdb, 0, query);
4009 ok(r == ERROR_SUCCESS, "failed to hold table %d\n", r);
4011 query = "ALTER TABLE `T` FREE";
4012 r = run_query(hdb, 0, query);
4013 ok(r == ERROR_SUCCESS, "failed to free table\n");
4015 query = "ALTER TABLE `T` FREE";
4016 r = run_query(hdb, 0, query);
4017 ok(r == ERROR_SUCCESS, "failed to free table\n");
4019 query = "ALTER TABLE `T` FREE";
4020 r = run_query(hdb, 0, query);
4021 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to free table\n");
4023 query = "ALTER TABLE `T` HOLD";
4024 r = run_query(hdb, 0, query);
4025 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to hold table %d\n", r);
4027 /* table T is removed */
4028 query = "SELECT * FROM `T`";
4029 r = run_query(hdb, 0, query);
4030 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4032 /* create the table again */
4033 query = "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
4034 r = run_query(hdb, 0, query);
4035 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4037 /* up the ref count */
4038 query = "ALTER TABLE `U` HOLD";
4039 r = run_query(hdb, 0, query);
4040 ok(r == ERROR_SUCCESS, "failed to free table\n");
4042 /* add column, no data type */
4043 query = "ALTER TABLE `U` ADD `C`";
4044 r = run_query(hdb, 0, query);
4045 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4047 query = "ALTER TABLE `U` ADD `C` INTEGER";
4048 r = run_query(hdb, 0, query);
4049 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4051 /* add column C again */
4052 query = "ALTER TABLE `U` ADD `C` INTEGER";
4053 r = run_query(hdb, 0, query);
4054 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4056 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
4057 r = run_query(hdb, 0, query);
4058 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4060 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
4061 r = run_query(hdb, 0, query);
4062 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4064 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
4065 r = run_query(hdb, 0, query);
4066 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4068 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
4069 r = run_query(hdb, 0, query);
4070 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4072 query = "SELECT * FROM `U` WHERE `D` = 8";
4073 r = run_query(hdb, 0, query);
4074 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4076 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
4077 r = run_query(hdb, 0, query);
4078 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4080 query = "ALTER COLUMN `D` FREE";
4081 r = run_query(hdb, 0, query);
4082 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4084 /* drop the ref count */
4085 query = "ALTER TABLE `U` FREE";
4086 r = run_query(hdb, 0, query);
4087 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4089 /* table is not empty */
4090 query = "SELECT * FROM `U`";
4091 r = run_query(hdb, 0, query);
4092 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4094 /* column D is removed */
4095 query = "SELECT * FROM `U` WHERE `D` = 8";
4096 r = run_query(hdb, 0, query);
4097 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4099 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
4100 r = run_query(hdb, 0, query);
4101 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4103 /* add the column again */
4104 query = "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
4105 r = run_query(hdb, 0, query);
4106 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4108 /* up the ref count */
4109 query = "ALTER TABLE `U` HOLD";
4110 r = run_query(hdb, 0, query);
4111 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4113 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
4114 r = run_query(hdb, 0, query);
4115 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4117 query = "SELECT * FROM `U` WHERE `E` = 16";
4118 r = run_query(hdb, 0, query);
4119 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4121 /* drop the ref count */
4122 query = "ALTER TABLE `U` FREE";
4123 r = run_query(hdb, 0, query);
4124 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4126 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
4127 r = run_query(hdb, 0, query);
4128 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4130 query = "SELECT * FROM `U` WHERE `E` = 20";
4131 r = run_query(hdb, 0, query);
4132 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4134 /* drop the ref count */
4135 query = "ALTER TABLE `U` FREE";
4136 r = run_query(hdb, 0, query);
4137 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4139 /* table still exists */
4140 query = "SELECT * FROM `U`";
4141 r = run_query(hdb, 0, query);
4142 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4144 /* col E is removed */
4145 query = "SELECT * FROM `U` WHERE `E` = 20";
4146 r = run_query(hdb, 0, query);
4147 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4149 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
4150 r = run_query(hdb, 0, query);
4151 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4153 /* drop the ref count once more */
4154 query = "ALTER TABLE `U` FREE";
4155 r = run_query(hdb, 0, query);
4156 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4158 /* table still exists */
4159 query = "SELECT * FROM `U`";
4160 r = run_query(hdb, 0, query);
4161 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4163 MsiCloseHandle( hdb );
4164 DeleteFile(msifile);
4167 static void test_integers(void)
4169 MSIHANDLE hdb = 0, view = 0, rec = 0;
4174 /* just MsiOpenDatabase should not create a file */
4175 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4176 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4178 /* create a table */
4179 query = "CREATE TABLE `integers` ( "
4180 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
4181 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
4182 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
4183 "PRIMARY KEY `one`)";
4184 r = MsiDatabaseOpenView(hdb, query, &view);
4185 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4186 r = MsiViewExecute(view, 0);
4187 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4188 r = MsiViewClose(view);
4189 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4190 r = MsiCloseHandle(view);
4191 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4193 query = "SELECT * FROM `integers`";
4194 r = MsiDatabaseOpenView(hdb, query, &view);
4195 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4197 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
4198 count = MsiRecordGetFieldCount(rec);
4199 ok(count == 8, "Expected 8, got %d\n", count);
4200 ok(check_record(rec, 1, "one"), "Expected one\n");
4201 ok(check_record(rec, 2, "two"), "Expected two\n");
4202 ok(check_record(rec, 3, "three"), "Expected three\n");
4203 ok(check_record(rec, 4, "four"), "Expected four\n");
4204 ok(check_record(rec, 5, "five"), "Expected five\n");
4205 ok(check_record(rec, 6, "six"), "Expected six\n");
4206 ok(check_record(rec, 7, "seven"), "Expected seven\n");
4207 ok(check_record(rec, 8, "eight"), "Expected eight\n");
4208 MsiCloseHandle(rec);
4210 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
4211 count = MsiRecordGetFieldCount(rec);
4212 ok(count == 8, "Expected 8, got %d\n", count);
4213 ok(check_record(rec, 1, "I2"), "Expected I2\n");
4214 ok(check_record(rec, 2, "I2"), "Expected I2\n");
4215 ok(check_record(rec, 3, "I2"), "Expected I2\n");
4216 ok(check_record(rec, 4, "I4"), "Expected I4\n");
4217 ok(check_record(rec, 5, "i2"), "Expected i2\n");
4218 ok(check_record(rec, 6, "i2"), "Expected i2\n");
4219 ok(check_record(rec, 7, "i2"), "Expected i2\n");
4220 ok(check_record(rec, 8, "i4"), "Expected i4\n");
4221 MsiCloseHandle(rec);
4224 MsiCloseHandle(view);
4226 /* insert values into it, NULL where NOT NULL is specified */
4227 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
4228 "VALUES('', '', '', '', '', '', '', '')";
4229 r = MsiDatabaseOpenView(hdb, query, &view);
4230 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4231 r = MsiViewExecute(view, 0);
4232 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
4235 MsiCloseHandle(view);
4237 query = "SELECT * FROM `integers`";
4238 r = do_query(hdb, query, &rec);
4239 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4241 r = MsiRecordGetFieldCount(rec);
4242 ok(r == -1, "record count wrong: %d\n", r);
4244 MsiCloseHandle(rec);
4246 /* insert legitimate values into it */
4247 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
4248 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
4249 r = MsiDatabaseOpenView(hdb, query, &view);
4250 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4251 r = MsiViewExecute(view, 0);
4252 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4254 query = "SELECT * FROM `integers`";
4255 r = do_query(hdb, query, &rec);
4256 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4258 r = MsiRecordGetFieldCount(rec);
4259 ok(r == 8, "record count wrong: %d\n", r);
4261 i = MsiRecordGetInteger(rec, 1);
4262 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
4263 i = MsiRecordGetInteger(rec, 3);
4264 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
4265 i = MsiRecordGetInteger(rec, 2);
4266 ok(i == 2, "Expected 2, got %d\n", i);
4267 i = MsiRecordGetInteger(rec, 4);
4268 ok(i == 4, "Expected 4, got %d\n", i);
4269 i = MsiRecordGetInteger(rec, 5);
4270 ok(i == 5, "Expected 5, got %d\n", i);
4271 i = MsiRecordGetInteger(rec, 6);
4272 ok(i == 6, "Expected 6, got %d\n", i);
4273 i = MsiRecordGetInteger(rec, 7);
4274 ok(i == 7, "Expected 7, got %d\n", i);
4275 i = MsiRecordGetInteger(rec, 8);
4276 ok(i == 8, "Expected 8, got %d\n", i);
4278 MsiCloseHandle(rec);
4280 MsiCloseHandle(view);
4282 r = MsiDatabaseCommit(hdb);
4283 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
4285 r = MsiCloseHandle(hdb);
4286 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4288 r = DeleteFile(msifile);
4289 ok(r == TRUE, "file didn't exist after commit\n");
4292 static void test_update(void)
4294 MSIHANDLE hdb = 0, view = 0, rec = 0;
4295 CHAR result[MAX_PATH];
4300 /* just MsiOpenDatabase should not create a file */
4301 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4302 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4304 /* create the Control table */
4305 query = "CREATE TABLE `Control` ( "
4306 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
4307 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
4308 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
4309 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
4310 r = MsiDatabaseOpenView(hdb, query, &view);
4311 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4312 r = MsiViewExecute(view, 0);
4313 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4314 r = MsiViewClose(view);
4315 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4316 r = MsiCloseHandle(view);
4317 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4320 query = "INSERT INTO `Control` ( "
4321 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4322 "`Property`, `Text`, `Control_Next`, `Help` )"
4323 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
4324 r = MsiDatabaseOpenView(hdb, query, &view);
4325 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4326 r = MsiViewExecute(view, 0);
4327 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4328 r = MsiViewClose(view);
4329 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4330 r = MsiCloseHandle(view);
4331 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4333 /* add a second control */
4334 query = "INSERT INTO `Control` ( "
4335 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4336 "`Property`, `Text`, `Control_Next`, `Help` )"
4337 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
4338 r = MsiDatabaseOpenView(hdb, query, &view);
4339 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4340 r = MsiViewExecute(view, 0);
4341 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4342 r = MsiViewClose(view);
4343 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4344 r = MsiCloseHandle(view);
4345 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4347 /* add a third control */
4348 query = "INSERT INTO `Control` ( "
4349 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4350 "`Property`, `Text`, `Control_Next`, `Help` )"
4351 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
4352 r = MsiDatabaseOpenView(hdb, query, &view);
4353 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4354 r = MsiViewExecute(view, 0);
4355 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4356 r = MsiViewClose(view);
4357 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4358 r = MsiCloseHandle(view);
4359 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4362 query = "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4363 r = MsiDatabaseOpenView(hdb, query, &view);
4364 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4366 /* bad set column */
4367 query = "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4368 r = MsiDatabaseOpenView(hdb, query, &view);
4369 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4371 /* bad where condition */
4372 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
4373 r = MsiDatabaseOpenView(hdb, query, &view);
4374 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4376 /* just the dialog_ specified */
4377 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4378 r = MsiDatabaseOpenView(hdb, query, &view);
4379 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4380 r = MsiViewExecute(view, 0);
4381 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4382 r = MsiViewClose(view);
4383 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4384 r = MsiCloseHandle(view);
4385 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4387 /* check the modified text */
4388 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
4389 r = MsiDatabaseOpenView(hdb, query, &view);
4390 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4391 r = MsiViewExecute(view, 0);
4392 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4394 r = MsiViewFetch(view, &rec);
4395 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4398 r = MsiRecordGetString(rec, 1, result, &size);
4399 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4400 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4402 MsiCloseHandle(rec);
4404 r = MsiViewFetch(view, &rec);
4405 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4408 r = MsiRecordGetString(rec, 1, result, &size);
4409 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4410 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
4412 MsiCloseHandle(rec);
4414 r = MsiViewFetch(view, &rec);
4415 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4417 r = MsiViewClose(view);
4418 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4419 r = MsiCloseHandle(view);
4420 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4422 /* dialog_ and control specified */
4423 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
4424 r = MsiDatabaseOpenView(hdb, query, &view);
4425 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4426 r = MsiViewExecute(view, 0);
4427 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4428 r = MsiViewClose(view);
4429 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4430 r = MsiCloseHandle(view);
4431 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4433 /* check the modified text */
4434 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
4435 r = MsiDatabaseOpenView(hdb, query, &view);
4436 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4437 r = MsiViewExecute(view, 0);
4438 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4440 r = MsiViewFetch(view, &rec);
4441 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4444 r = MsiRecordGetString(rec, 1, result, &size);
4445 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4446 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4448 MsiCloseHandle(rec);
4450 r = MsiViewFetch(view, &rec);
4451 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4454 r = MsiRecordGetString(rec, 1, result, &size);
4455 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4456 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
4458 MsiCloseHandle(rec);
4460 r = MsiViewFetch(view, &rec);
4461 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4463 r = MsiViewClose(view);
4464 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4465 r = MsiCloseHandle(view);
4466 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4468 /* no where condition */
4469 query = "UPDATE `Control` SET `Text` = 'this is text'";
4470 r = MsiDatabaseOpenView(hdb, query, &view);
4471 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4472 r = MsiViewExecute(view, 0);
4473 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4474 r = MsiViewClose(view);
4475 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4476 r = MsiCloseHandle(view);
4477 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4479 /* check the modified text */
4480 query = "SELECT `Text` FROM `Control`";
4481 r = MsiDatabaseOpenView(hdb, query, &view);
4482 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4483 r = MsiViewExecute(view, 0);
4484 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4486 r = MsiViewFetch(view, &rec);
4487 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4490 r = MsiRecordGetString(rec, 1, result, &size);
4491 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4492 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4494 MsiCloseHandle(rec);
4496 r = MsiViewFetch(view, &rec);
4497 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4500 r = MsiRecordGetString(rec, 1, result, &size);
4501 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4502 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4504 MsiCloseHandle(rec);
4506 r = MsiViewFetch(view, &rec);
4507 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4510 r = MsiRecordGetString(rec, 1, result, &size);
4511 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4512 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4514 MsiCloseHandle(rec);
4516 r = MsiViewFetch(view, &rec);
4517 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4519 r = MsiViewClose(view);
4520 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4521 r = MsiCloseHandle(view);
4522 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4524 query = "CREATE TABLE `Apple` ( `Banana` CHAR(72) NOT NULL, "
4525 "`Orange` CHAR(72), `Pear` INT PRIMARY KEY `Banana`)";
4526 r = run_query(hdb, 0, query);
4527 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4529 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4530 "VALUES('one', 'two', 3)";
4531 r = run_query(hdb, 0, query);
4532 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4534 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4535 "VALUES('three', 'four', 5)";
4536 r = run_query(hdb, 0, query);
4537 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4539 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4540 "VALUES('six', 'two', 7)";
4541 r = run_query(hdb, 0, query);
4542 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4544 rec = MsiCreateRecord(2);
4545 MsiRecordSetInteger(rec, 1, 8);
4546 MsiRecordSetString(rec, 2, "two");
4548 query = "UPDATE `Apple` SET `Pear` = ? WHERE `Orange` = ?";
4549 r = run_query(hdb, rec, query);
4550 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4552 MsiCloseHandle(rec);
4554 query = "SELECT `Pear` FROM `Apple` ORDER BY `Orange`";
4555 r = MsiDatabaseOpenView(hdb, query, &view);
4556 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4557 r = MsiViewExecute(view, 0);
4558 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4560 r = MsiViewFetch(view, &rec);
4561 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4563 r = MsiRecordGetInteger(rec, 1);
4564 ok(r == 8, "Expected 8, got %d\n", r);
4566 MsiCloseHandle(rec);
4568 r = MsiViewFetch(view, &rec);
4569 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4571 r = MsiRecordGetInteger(rec, 1);
4572 ok(r == 8, "Expected 8, got %d\n", r);
4574 MsiCloseHandle(rec);
4576 r = MsiViewFetch(view, &rec);
4577 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4579 r = MsiRecordGetInteger(rec, 1);
4580 ok(r == 5, "Expected 5, got %d\n", r);
4582 MsiCloseHandle(rec);
4584 r = MsiViewFetch(view, &rec);
4585 ok(r == ERROR_NO_MORE_ITEMS, "Expectd ERROR_NO_MORE_ITEMS, got %d\n", r);
4588 MsiCloseHandle(view);
4590 r = MsiDatabaseCommit(hdb);
4591 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
4592 r = MsiCloseHandle(hdb);
4593 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4595 DeleteFile(msifile);
4598 static void test_special_tables(void)
4604 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4605 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4607 query = "CREATE TABLE `_Properties` ( "
4608 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4609 r = run_query(hdb, 0, query);
4610 ok(r == ERROR_SUCCESS, "failed to create table\n");
4612 query = "CREATE TABLE `_Storages` ( "
4613 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4614 r = run_query(hdb, 0, query);
4615 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Streams table\n");
4617 query = "CREATE TABLE `_Streams` ( "
4618 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4619 r = run_query(hdb, 0, query);
4620 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Streams table\n");
4622 query = "CREATE TABLE `_Tables` ( "
4623 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4624 r = run_query(hdb, 0, query);
4625 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Tables table\n");
4627 query = "CREATE TABLE `_Columns` ( "
4628 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4629 r = run_query(hdb, 0, query);
4630 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Columns table\n");
4632 r = MsiCloseHandle(hdb);
4633 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4636 static void test_tables_order(void)
4639 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
4644 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4645 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4647 query = "CREATE TABLE `foo` ( "
4648 "`baz` INT NOT NULL PRIMARY KEY `baz`)";
4649 r = run_query(hdb, 0, query);
4650 ok(r == ERROR_SUCCESS, "failed to create table\n");
4652 query = "CREATE TABLE `bar` ( "
4653 "`foo` INT NOT NULL PRIMARY KEY `foo`)";
4654 r = run_query(hdb, 0, query);
4655 ok(r == ERROR_SUCCESS, "failed to create table\n");
4657 query = "CREATE TABLE `baz` ( "
4658 "`bar` INT NOT NULL, "
4659 "`baz` INT NOT NULL, "
4660 "`foo` INT NOT NULL PRIMARY KEY `bar`)";
4661 r = run_query(hdb, 0, query);
4662 ok(r == ERROR_SUCCESS, "failed to create table\n");
4664 /* The names of the tables in the _Tables table must
4665 be in the same order as these names are created in
4666 the strings table. */
4667 query = "SELECT * FROM `_Tables`";
4668 r = MsiDatabaseOpenView(hdb, query, &hview);
4669 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4670 r = MsiViewExecute(hview, 0);
4671 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4673 r = MsiViewFetch(hview, &hrec);
4674 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4675 sz = sizeof(buffer);
4676 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4677 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4678 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4679 r = MsiCloseHandle(hrec);
4680 ok(r == ERROR_SUCCESS, "failed to close record\n");
4682 r = MsiViewFetch(hview, &hrec);
4683 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4684 sz = sizeof(buffer);
4685 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4686 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4687 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4688 r = MsiCloseHandle(hrec);
4689 ok(r == ERROR_SUCCESS, "failed to close record\n");
4691 r = MsiViewFetch(hview, &hrec);
4692 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4693 sz = sizeof(buffer);
4694 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4695 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4696 ok(!lstrcmp(buffer, "bar"), "Expected bar, got %s\n", buffer);
4697 r = MsiCloseHandle(hrec);
4698 ok(r == ERROR_SUCCESS, "failed to close record\n");
4700 r = MsiViewClose(hview);
4701 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4702 r = MsiCloseHandle(hview);
4703 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4705 /* The names of the tables in the _Columns table must
4706 be in the same order as these names are created in
4707 the strings table. */
4708 query = "SELECT * FROM `_Columns`";
4709 r = MsiDatabaseOpenView(hdb, query, &hview);
4710 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4711 r = MsiViewExecute(hview, 0);
4712 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4714 r = MsiViewFetch(hview, &hrec);
4715 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4716 sz = sizeof(buffer);
4717 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4718 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4719 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4720 sz = sizeof(buffer);
4721 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4722 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4723 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4724 r = MsiCloseHandle(hrec);
4725 ok(r == ERROR_SUCCESS, "failed to close record\n");
4727 r = MsiViewFetch(hview, &hrec);
4728 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4729 sz = sizeof(buffer);
4730 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4731 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4732 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4733 sz = sizeof(buffer);
4734 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4735 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4736 ok(!lstrcmp(buffer, "bar"), "Expected bar, got %s\n", buffer);
4737 r = MsiCloseHandle(hrec);
4738 ok(r == ERROR_SUCCESS, "failed to close record\n");
4740 r = MsiViewFetch(hview, &hrec);
4741 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4742 sz = sizeof(buffer);
4743 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4744 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4745 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4746 sz = sizeof(buffer);
4747 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4748 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4749 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4750 r = MsiCloseHandle(hrec);
4751 ok(r == ERROR_SUCCESS, "failed to close record\n");
4753 r = MsiViewFetch(hview, &hrec);
4754 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4755 sz = sizeof(buffer);
4756 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4757 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4758 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4759 sz = sizeof(buffer);
4760 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4761 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4762 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4763 r = MsiCloseHandle(hrec);
4764 ok(r == ERROR_SUCCESS, "failed to close record\n");
4766 r = MsiViewFetch(hview, &hrec);
4767 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4768 sz = sizeof(buffer);
4769 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4770 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4771 ok(!lstrcmp(buffer, "bar"), "Expected bar, got %s\n", buffer);
4772 sz = sizeof(buffer);
4773 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4774 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4775 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4776 r = MsiCloseHandle(hrec);
4777 ok(r == ERROR_SUCCESS, "failed to close record\n");
4779 r = MsiViewClose(hview);
4780 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4781 r = MsiCloseHandle(hview);
4782 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4784 r = MsiCloseHandle(hdb);
4785 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4787 DeleteFile(msifile);
4790 static void test_rows_order(void)
4793 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
4798 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4799 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4801 query = "CREATE TABLE `foo` ( "
4802 "`bar` LONGCHAR NOT NULL PRIMARY KEY `bar`)";
4803 r = run_query(hdb, 0, query);
4804 ok(r == ERROR_SUCCESS, "failed to create table\n");
4806 r = run_query(hdb, 0, "INSERT INTO `foo` "
4807 "( `bar` ) VALUES ( 'A' )");
4808 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4810 r = run_query(hdb, 0, "INSERT INTO `foo` "
4811 "( `bar` ) VALUES ( 'B' )");
4812 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4814 r = run_query(hdb, 0, "INSERT INTO `foo` "
4815 "( `bar` ) VALUES ( 'C' )");
4816 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4818 r = run_query(hdb, 0, "INSERT INTO `foo` "
4819 "( `bar` ) VALUES ( 'D' )");
4820 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4822 r = run_query(hdb, 0, "INSERT INTO `foo` "
4823 "( `bar` ) VALUES ( 'E' )");
4824 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4826 r = run_query(hdb, 0, "INSERT INTO `foo` "
4827 "( `bar` ) VALUES ( 'F' )");
4828 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4830 query = "CREATE TABLE `bar` ( "
4831 "`foo` LONGCHAR NOT NULL, "
4832 "`baz` LONGCHAR NOT NULL "
4833 "PRIMARY KEY `foo` )";
4834 r = run_query(hdb, 0, query);
4835 ok(r == ERROR_SUCCESS, "failed to create table\n");
4837 r = run_query(hdb, 0, "INSERT INTO `bar` "
4838 "( `foo`, `baz` ) VALUES ( 'C', 'E' )");
4839 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4841 r = run_query(hdb, 0, "INSERT INTO `bar` "
4842 "( `foo`, `baz` ) VALUES ( 'F', 'A' )");
4843 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4845 r = run_query(hdb, 0, "INSERT INTO `bar` "
4846 "( `foo`, `baz` ) VALUES ( 'A', 'B' )");
4847 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4849 r = run_query(hdb, 0, "INSERT INTO `bar` "
4850 "( `foo`, `baz` ) VALUES ( 'D', 'E' )");
4851 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4853 /* The rows of the table must be ordered by the column values of
4854 each row. For strings, the column value is the string id
4855 in the string table. */
4857 query = "SELECT * FROM `bar`";
4858 r = MsiDatabaseOpenView(hdb, query, &hview);
4859 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4860 r = MsiViewExecute(hview, 0);
4861 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4863 r = MsiViewFetch(hview, &hrec);
4864 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4865 sz = sizeof(buffer);
4866 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4867 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4868 ok(!lstrcmp(buffer, "A"), "Expected A, got %s\n", buffer);
4869 sz = sizeof(buffer);
4870 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4871 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4872 ok(!lstrcmp(buffer, "B"), "Expected B, got %s\n", buffer);
4873 r = MsiCloseHandle(hrec);
4874 ok(r == ERROR_SUCCESS, "failed to close record\n");
4876 r = MsiViewFetch(hview, &hrec);
4877 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4878 sz = sizeof(buffer);
4879 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4880 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4881 ok(!lstrcmp(buffer, "C"), "Expected E, got %s\n", buffer);
4882 sz = sizeof(buffer);
4883 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4884 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4885 ok(!lstrcmp(buffer, "E"), "Expected E, got %s\n", buffer);
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");
4891 sz = sizeof(buffer);
4892 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4893 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4894 ok(!lstrcmp(buffer, "D"), "Expected D, got %s\n", buffer);
4895 sz = sizeof(buffer);
4896 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4897 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4898 ok(!lstrcmp(buffer, "E"), "Expected E, got %s\n", buffer);
4899 r = MsiCloseHandle(hrec);
4900 ok(r == ERROR_SUCCESS, "failed to close record\n");
4902 r = MsiViewFetch(hview, &hrec);
4903 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4904 sz = sizeof(buffer);
4905 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4906 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4907 ok(!lstrcmp(buffer, "F"), "Expected F, got %s\n", buffer);
4908 sz = sizeof(buffer);
4909 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4910 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4911 ok(!lstrcmp(buffer, "A"), "Expected A, got %s\n", buffer);
4912 r = MsiCloseHandle(hrec);
4913 ok(r == ERROR_SUCCESS, "failed to close record\n");
4915 r = MsiViewClose(hview);
4916 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4917 r = MsiCloseHandle(hview);
4918 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4920 r = MsiCloseHandle(hdb);
4921 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4923 DeleteFile(msifile);
4926 static void test_select_markers(void)
4928 MSIHANDLE hdb = 0, rec, view, res;
4935 ok( hdb, "failed to create db\n");
4937 r = run_query(hdb, 0,
4938 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
4939 ok(r == S_OK, "cannot create table: %d\n", r);
4941 r = run_query(hdb, 0, "INSERT INTO `Table` "
4942 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
4943 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4945 r = run_query(hdb, 0, "INSERT INTO `Table` "
4946 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
4947 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4949 r = run_query(hdb, 0, "INSERT INTO `Table` "
4950 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
4951 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4953 r = run_query(hdb, 0, "INSERT INTO `Table` "
4954 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
4955 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4957 rec = MsiCreateRecord(2);
4958 MsiRecordSetString(rec, 1, "apple");
4959 MsiRecordSetString(rec, 2, "two");
4961 query = "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
4962 r = MsiDatabaseOpenView(hdb, query, &view);
4963 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4965 r = MsiViewExecute(view, rec);
4966 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4968 r = MsiViewFetch(view, &res);
4969 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4972 r = MsiRecordGetString(res, 1, buf, &size);
4973 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4974 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
4977 r = MsiRecordGetString(res, 2, buf, &size);
4978 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4979 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
4981 r = MsiRecordGetInteger(res, 3);
4982 ok(r == 1, "Expected 1, got %d\n", r);
4984 MsiCloseHandle(res);
4986 r = MsiViewFetch(view, &res);
4987 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4990 r = MsiRecordGetString(res, 1, buf, &size);
4991 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4992 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
4995 r = MsiRecordGetString(res, 2, buf, &size);
4996 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4997 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
4999 r = MsiRecordGetInteger(res, 3);
5000 ok(r == 2, "Expected 2, got %d\n", r);
5002 MsiCloseHandle(res);
5004 r = MsiViewFetch(view, &res);
5005 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5007 MsiCloseHandle(rec);
5009 MsiCloseHandle(view);
5011 rec = MsiCreateRecord(2);
5012 MsiRecordSetString(rec, 1, "one");
5013 MsiRecordSetInteger(rec, 2, 1);
5015 query = "SELECT * FROM `Table` WHERE `Two`<>? AND `Three`>? ORDER BY `Three`";
5016 r = MsiDatabaseOpenView(hdb, query, &view);
5017 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5018 r = MsiViewExecute(view, rec);
5019 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5021 r = MsiViewFetch(view, &res);
5022 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5025 r = MsiRecordGetString(res, 1, buf, &size);
5026 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5027 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
5030 r = MsiRecordGetString(res, 2, buf, &size);
5031 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5032 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
5034 r = MsiRecordGetInteger(res, 3);
5035 ok(r == 2, "Expected 2, got %d\n", r);
5037 MsiCloseHandle(res);
5039 r = MsiViewFetch(view, &res);
5040 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5043 r = MsiRecordGetString(res, 1, buf, &size);
5044 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5045 ok(!lstrcmp(buf, "banana"), "Expected banana, got %s\n", buf);
5048 r = MsiRecordGetString(res, 2, buf, &size);
5049 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5050 ok(!lstrcmp(buf, "three"), "Expected three, got %s\n", buf);
5052 r = MsiRecordGetInteger(res, 3);
5053 ok(r == 3, "Expected 3, got %d\n", r);
5055 MsiCloseHandle(res);
5057 r = MsiViewFetch(view, &res);
5058 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5060 MsiCloseHandle(rec);
5062 MsiCloseHandle(view);
5063 MsiCloseHandle(hdb);
5064 DeleteFile(msifile);
5067 static void test_viewmodify_update(void)
5069 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5073 DeleteFile(msifile);
5075 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5076 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
5078 query = "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
5079 r = run_query( hdb, 0, query );
5080 ok(r == ERROR_SUCCESS, "query failed\n");
5082 query = "INSERT INTO `table` (`A`, `B`) VALUES (1, 2)";
5083 r = run_query( hdb, 0, query );
5084 ok(r == ERROR_SUCCESS, "query failed\n");
5086 query = "INSERT INTO `table` (`A`, `B`) VALUES (3, 4)";
5087 r = run_query( hdb, 0, query );
5088 ok(r == ERROR_SUCCESS, "query failed\n");
5090 query = "INSERT INTO `table` (`A`, `B`) VALUES (5, 6)";
5091 r = run_query( hdb, 0, query );
5092 ok(r == ERROR_SUCCESS, "query failed\n");
5094 query = "SELECT `B` FROM `table`";
5095 r = MsiDatabaseOpenView(hdb, query, &hview);
5096 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5097 r = MsiViewExecute(hview, 0);
5098 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5099 r = MsiViewFetch(hview, &hrec);
5100 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5102 r = MsiRecordSetInteger(hrec, 1, 0);
5103 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5105 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
5106 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5108 r = MsiCloseHandle(hrec);
5109 ok(r == ERROR_SUCCESS, "failed to close record\n");
5111 r = MsiViewClose(hview);
5112 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5113 r = MsiCloseHandle(hview);
5114 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5116 query = "SELECT * FROM `table`";
5117 r = MsiDatabaseOpenView(hdb, query, &hview);
5118 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5119 r = MsiViewExecute(hview, 0);
5120 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5121 r = MsiViewFetch(hview, &hrec);
5122 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5124 r = MsiRecordGetInteger(hrec, 1);
5125 ok(r == 1, "Expected 1, got %d\n", r);
5126 r = MsiRecordGetInteger(hrec, 2);
5127 ok(r == 0, "Expected 0, got %d\n", r);
5129 r = MsiCloseHandle(hrec);
5130 ok(r == ERROR_SUCCESS, "failed to close record\n");
5132 r = MsiViewFetch(hview, &hrec);
5133 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5135 r = MsiRecordGetInteger(hrec, 1);
5136 ok(r == 3, "Expected 3, got %d\n", r);
5137 r = MsiRecordGetInteger(hrec, 2);
5138 ok(r == 4, "Expected 4, got %d\n", r);
5140 r = MsiCloseHandle(hrec);
5141 ok(r == ERROR_SUCCESS, "failed to close record\n");
5143 r = MsiViewFetch(hview, &hrec);
5144 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5146 r = MsiRecordGetInteger(hrec, 1);
5147 ok(r == 5, "Expected 5, got %d\n", r);
5148 r = MsiRecordGetInteger(hrec, 2);
5149 ok(r == 6, "Expected 6, got %d\n", r);
5151 r = MsiCloseHandle(hrec);
5152 ok(r == ERROR_SUCCESS, "failed to close record\n");
5154 r = MsiViewFetch(hview, &hrec);
5155 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5157 r = MsiViewClose(hview);
5158 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5159 r = MsiCloseHandle(hview);
5160 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5162 /* loop through all elements */
5163 query = "SELECT `B` FROM `table`";
5164 r = MsiDatabaseOpenView(hdb, query, &hview);
5165 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5166 r = MsiViewExecute(hview, 0);
5167 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5171 r = MsiViewFetch(hview, &hrec);
5172 if (r != ERROR_SUCCESS)
5175 r = MsiRecordSetInteger(hrec, 1, 0);
5176 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5178 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
5179 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5181 r = MsiCloseHandle(hrec);
5182 ok(r == ERROR_SUCCESS, "failed to close record\n");
5185 r = MsiViewClose(hview);
5186 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5187 r = MsiCloseHandle(hview);
5188 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5190 query = "SELECT * FROM `table`";
5191 r = MsiDatabaseOpenView(hdb, query, &hview);
5192 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5193 r = MsiViewExecute(hview, 0);
5194 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5195 r = MsiViewFetch(hview, &hrec);
5196 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5198 r = MsiRecordGetInteger(hrec, 1);
5199 ok(r == 1, "Expected 1, got %d\n", r);
5200 r = MsiRecordGetInteger(hrec, 2);
5201 ok(r == 0, "Expected 0, got %d\n", r);
5203 r = MsiCloseHandle(hrec);
5204 ok(r == ERROR_SUCCESS, "failed to close record\n");
5206 r = MsiViewFetch(hview, &hrec);
5207 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5209 r = MsiRecordGetInteger(hrec, 1);
5210 ok(r == 3, "Expected 3, got %d\n", r);
5211 r = MsiRecordGetInteger(hrec, 2);
5212 ok(r == 0, "Expected 0, got %d\n", r);
5214 r = MsiCloseHandle(hrec);
5215 ok(r == ERROR_SUCCESS, "failed to close record\n");
5217 r = MsiViewFetch(hview, &hrec);
5218 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5220 r = MsiRecordGetInteger(hrec, 1);
5221 ok(r == 5, "Expected 5, got %d\n", r);
5222 r = MsiRecordGetInteger(hrec, 2);
5223 ok(r == 0, "Expected 0, got %d\n", r);
5225 r = MsiCloseHandle(hrec);
5226 ok(r == ERROR_SUCCESS, "failed to close record\n");
5228 r = MsiViewFetch(hview, &hrec);
5229 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5231 r = MsiViewClose(hview);
5232 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5233 r = MsiCloseHandle(hview);
5234 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5236 r = MsiCloseHandle( hdb );
5237 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
5240 static void test_viewmodify_assign(void)
5242 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5246 /* setup database */
5247 DeleteFile(msifile);
5249 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5250 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
5252 query = "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
5253 r = run_query( hdb, 0, query );
5254 ok(r == ERROR_SUCCESS, "query failed\n");
5256 /* assign to view, new primary key */
5257 query = "SELECT * FROM `table`";
5258 r = MsiDatabaseOpenView(hdb, query, &hview);
5259 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5260 r = MsiViewExecute(hview, 0);
5261 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5263 hrec = MsiCreateRecord(2);
5264 ok(hrec != 0, "MsiCreateRecord failed\n");
5266 r = MsiRecordSetInteger(hrec, 1, 1);
5267 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5268 r = MsiRecordSetInteger(hrec, 2, 2);
5269 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5271 r = MsiViewModify(hview, MSIMODIFY_ASSIGN, hrec);
5272 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5274 r = MsiCloseHandle(hrec);
5275 ok(r == ERROR_SUCCESS, "failed to close record\n");
5277 r = MsiViewClose(hview);
5278 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5279 r = MsiCloseHandle(hview);
5280 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5282 query = "SELECT * FROM `table`";
5283 r = MsiDatabaseOpenView(hdb, query, &hview);
5284 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5285 r = MsiViewExecute(hview, 0);
5286 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5287 r = MsiViewFetch(hview, &hrec);
5288 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5290 r = MsiRecordGetInteger(hrec, 1);
5291 ok(r == 1, "Expected 1, got %d\n", r);
5292 r = MsiRecordGetInteger(hrec, 2);
5293 ok(r == 2, "Expected 2, got %d\n", r);
5295 r = MsiCloseHandle(hrec);
5296 ok(r == ERROR_SUCCESS, "failed to close record\n");
5298 r = MsiViewFetch(hview, &hrec);
5299 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5301 r = MsiViewClose(hview);
5302 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5303 r = MsiCloseHandle(hview);
5304 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5306 /* assign to view, primary key matches */
5307 query = "SELECT * FROM `table`";
5308 r = MsiDatabaseOpenView(hdb, query, &hview);
5309 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5310 r = MsiViewExecute(hview, 0);
5311 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5313 hrec = MsiCreateRecord(2);
5314 ok(hrec != 0, "MsiCreateRecord failed\n");
5316 r = MsiRecordSetInteger(hrec, 1, 1);
5317 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5318 r = MsiRecordSetInteger(hrec, 2, 4);
5319 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5321 r = MsiViewModify(hview, MSIMODIFY_ASSIGN, hrec);
5322 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5324 r = MsiCloseHandle(hrec);
5325 ok(r == ERROR_SUCCESS, "failed to close record\n");
5327 r = MsiViewClose(hview);
5328 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5329 r = MsiCloseHandle(hview);
5330 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5332 query = "SELECT * FROM `table`";
5333 r = MsiDatabaseOpenView(hdb, query, &hview);
5334 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5335 r = MsiViewExecute(hview, 0);
5336 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5337 r = MsiViewFetch(hview, &hrec);
5338 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5340 r = MsiRecordGetInteger(hrec, 1);
5341 ok(r == 1, "Expected 1, got %d\n", r);
5342 r = MsiRecordGetInteger(hrec, 2);
5343 ok(r == 4, "Expected 4, got %d\n", r);
5345 r = MsiCloseHandle(hrec);
5346 ok(r == ERROR_SUCCESS, "failed to close record\n");
5348 r = MsiViewFetch(hview, &hrec);
5349 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5351 r = MsiViewClose(hview);
5352 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5353 r = MsiCloseHandle(hview);
5354 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5356 /* close database */
5357 r = MsiCloseHandle( hdb );
5358 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
5361 static const WCHAR data10[] = { /* MOO */
5364 static const WCHAR data11[] = { /* AAR */
5368 static const char data12[] = /* _StringData */
5369 "MOOABAARCDonetwofourfive";
5370 static const WCHAR data13[] = { /* _StringPool */
5372 0, 0, /* string 0 '' */
5373 0, 0, /* string 1 '' */
5374 0, 0, /* string 2 '' */
5375 0, 0, /* string 3 '' */
5376 0, 0, /* string 4 '' */
5377 3, 3, /* string 5 'MOO' */
5378 1, 1, /* string 6 'A' */
5379 1, 1, /* string 7 'B' */
5380 3, 3, /* string 8 'AAR' */
5381 1, 1, /* string 9 'C' */
5382 1, 1, /* string a 'D' */
5383 3, 1, /* string b 'one' */
5384 3, 1, /* string c 'two' */
5385 0, 0, /* string d '' */
5386 4, 1, /* string e 'four' */
5387 4, 1, /* string f 'five' */
5390 static void test_stringtable(void)
5392 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5393 IStorage *stg = NULL;
5398 char buffer[MAX_PATH];
5399 WCHAR data[MAX_PATH];
5403 static const DWORD mode = STGM_DIRECT | STGM_READ | STGM_SHARE_DENY_WRITE;
5404 static const WCHAR stringdata[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0}; /* _StringData */
5405 static const WCHAR stringpool[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0}; /* _StringPool */
5406 static const WCHAR moo[] = {0x4840, 0x3e16, 0x4818, 0}; /* MOO */
5407 static const WCHAR aar[] = {0x4840, 0x3a8a, 0x481b, 0}; /* AAR */
5409 DeleteFile(msifile);
5411 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5412 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5414 query = "CREATE TABLE `MOO` (`A` INT, `B` CHAR(72) PRIMARY KEY `A`)";
5415 r = run_query(hdb, 0, query);
5416 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5418 query = "CREATE TABLE `AAR` (`C` INT, `D` CHAR(72) PRIMARY KEY `C`)";
5419 r = run_query(hdb, 0, query);
5420 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5422 /* insert persistent row */
5423 query = "INSERT INTO `MOO` (`A`, `B`) VALUES (1, 'one')";
5424 r = run_query(hdb, 0, query);
5425 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5427 /* insert persistent row */
5428 query = "INSERT INTO `AAR` (`C`, `D`) VALUES (2, 'two')";
5429 r = run_query(hdb, 0, query);
5430 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5433 query = "SELECT * FROM `MOO`";
5434 r = MsiDatabaseOpenView(hdb, query, &hview);
5435 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5436 r = MsiViewExecute(hview, 0);
5437 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5439 hrec = MsiCreateRecord(2);
5441 r = MsiRecordSetInteger(hrec, 1, 3);
5442 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5443 r = MsiRecordSetString(hrec, 2, "three");
5444 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5446 /* insert a nonpersistent row */
5447 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
5448 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5450 r = MsiCloseHandle(hrec);
5451 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5452 r = MsiViewClose(hview);
5453 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5454 r = MsiCloseHandle(hview);
5455 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5457 /* insert persistent row */
5458 query = "INSERT INTO `MOO` (`A`, `B`) VALUES (4, 'four')";
5459 r = run_query(hdb, 0, query);
5460 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5462 /* insert persistent row */
5463 query = "INSERT INTO `AAR` (`C`, `D`) VALUES (5, 'five')";
5464 r = run_query(hdb, 0, query);
5465 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5467 r = MsiDatabaseCommit(hdb);
5468 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5470 r = MsiCloseHandle(hdb);
5471 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5473 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
5474 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5476 query = "SELECT * FROM `MOO`";
5477 r = MsiDatabaseOpenView(hdb, query, &hview);
5478 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5480 r = MsiViewExecute(hview, 0);
5481 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5483 r = MsiViewFetch(hview, &hrec);
5484 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5486 r = MsiRecordGetFieldCount(hrec);
5487 ok(r == 2, "Expected 2, got %d\n", r);
5489 r = MsiRecordGetInteger(hrec, 1);
5490 ok(r == 1, "Expected 1, got %d\n", r);
5492 sz = sizeof(buffer);
5493 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5494 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5495 ok(!lstrcmp(buffer, "one"), "Expected one, got %s\n", buffer);
5497 r = MsiCloseHandle(hrec);
5498 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5500 r = MsiViewFetch(hview, &hrec);
5503 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5506 r = MsiViewClose(hview);
5507 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5508 r = MsiCloseHandle(hview);
5509 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5510 r = MsiCloseHandle(hrec);
5511 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5513 query = "SELECT * FROM `AAR`";
5514 r = MsiDatabaseOpenView(hdb, query, &hview);
5515 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5517 r = MsiViewExecute(hview, 0);
5518 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5520 r = MsiViewFetch(hview, &hrec);
5521 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5523 r = MsiRecordGetFieldCount(hrec);
5524 ok(r == 2, "Expected 2, got %d\n", r);
5526 r = MsiRecordGetInteger(hrec, 1);
5527 ok(r == 2, "Expected 2, got %d\n", r);
5529 sz = sizeof(buffer);
5530 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5531 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5532 ok(!lstrcmp(buffer, "two"), "Expected two, got %s\n", buffer);
5534 r = MsiCloseHandle(hrec);
5535 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5537 r = MsiViewFetch(hview, &hrec);
5538 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5540 r = MsiRecordGetFieldCount(hrec);
5541 ok(r == 2, "Expected 2, got %d\n", r);
5543 r = MsiRecordGetInteger(hrec, 1);
5544 ok(r == 5, "Expected 5, got %d\n", r);
5546 sz = sizeof(buffer);
5547 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5548 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5549 ok(!lstrcmp(buffer, "five"), "Expected five, got %s\n", buffer);
5551 r = MsiCloseHandle(hrec);
5552 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5554 r = MsiViewFetch(hview, &hrec);
5555 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5557 r = MsiViewClose(hview);
5558 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5559 r = MsiCloseHandle(hview);
5560 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5561 r = MsiCloseHandle(hrec);
5562 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5563 r = MsiCloseHandle(hdb);
5564 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5566 MultiByteToWideChar(CP_ACP, 0, msifile, -1, name, 0x20);
5567 hr = StgOpenStorage(name, NULL, mode, NULL, 0, &stg);
5568 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5569 ok(stg != NULL, "Expected non-NULL storage\n");
5571 hr = IStorage_OpenStream(stg, moo, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5572 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5573 ok(stm != NULL, "Expected non-NULL stream\n");
5575 hr = IStream_Read(stm, data, MAX_PATH, &read);
5576 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5579 ok(read == 4, "Expected 4, got %d\n", read);
5580 ok(!memcmp(data, data10, read), "Unexpected data\n");
5583 hr = IStream_Release(stm);
5584 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5586 hr = IStorage_OpenStream(stg, aar, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5587 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5588 ok(stm != NULL, "Expected non-NULL stream\n");
5590 hr = IStream_Read(stm, data, MAX_PATH, &read);
5591 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5592 ok(read == 8, "Expected 8, got %d\n", read);
5595 ok(!memcmp(data, data11, read), "Unexpected data\n");
5598 hr = IStream_Release(stm);
5599 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5601 hr = IStorage_OpenStream(stg, stringdata, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5602 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5603 ok(stm != NULL, "Expected non-NULL stream\n");
5605 hr = IStream_Read(stm, buffer, MAX_PATH, &read);
5606 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5607 ok(read == 24, "Expected 24, got %d\n", read);
5608 ok(!memcmp(buffer, data12, read), "Unexpected data\n");
5610 hr = IStream_Release(stm);
5611 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5613 hr = IStorage_OpenStream(stg, stringpool, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5614 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5615 ok(stm != NULL, "Expected non-NULL stream\n");
5617 hr = IStream_Read(stm, data, MAX_PATH, &read);
5618 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5621 ok(read == 64, "Expected 64, got %d\n", read);
5622 ok(!memcmp(data, data13, read), "Unexpected data\n");
5625 hr = IStream_Release(stm);
5626 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5628 hr = IStorage_Release(stg);
5629 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5631 DeleteFileA(msifile);
5634 static void test_viewmodify_delete(void)
5636 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5642 DeleteFile(msifile);
5644 /* just MsiOpenDatabase should not create a file */
5645 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5646 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5648 query = "CREATE TABLE `phone` ( "
5649 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
5650 "PRIMARY KEY `id`)";
5651 r = run_query(hdb, 0, query);
5652 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5654 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
5655 "VALUES('1', 'Alan', '5030581')";
5656 r = run_query(hdb, 0, query);
5657 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5659 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
5660 "VALUES('2', 'Barry', '928440')";
5661 r = run_query(hdb, 0, query);
5662 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5664 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
5665 "VALUES('3', 'Cindy', '2937550')";
5666 r = run_query(hdb, 0, query);
5667 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5669 query = "SELECT * FROM `phone` WHERE `id` <= 2";
5670 r = MsiDatabaseOpenView(hdb, query, &hview);
5671 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5672 r = MsiViewExecute(hview, 0);
5673 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5674 r = MsiViewFetch(hview, &hrec);
5675 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5678 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
5679 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5681 r = MsiCloseHandle(hrec);
5682 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5683 r = MsiViewFetch(hview, &hrec);
5684 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5687 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
5688 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5690 r = MsiCloseHandle(hrec);
5691 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5692 r = MsiViewClose(hview);
5693 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5694 r = MsiCloseHandle(hview);
5695 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5697 query = "SELECT * FROM `phone`";
5698 r = MsiDatabaseOpenView(hdb, query, &hview);
5699 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5700 r = MsiViewExecute(hview, 0);
5701 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5702 r = MsiViewFetch(hview, &hrec);
5703 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5705 r = MsiRecordGetInteger(hrec, 1);
5706 ok(r == 3, "Expected 3, got %d\n", r);
5708 sz = sizeof(buffer);
5709 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5710 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5711 ok(!lstrcmp(buffer, "Cindy"), "Expected Cindy, got %s\n", buffer);
5713 sz = sizeof(buffer);
5714 r = MsiRecordGetString(hrec, 3, buffer, &sz);
5715 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5716 ok(!lstrcmp(buffer, "2937550"), "Expected 2937550, got %s\n", buffer);
5718 r = MsiCloseHandle(hrec);
5719 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5721 r = MsiViewFetch(hview, &hrec);
5722 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5724 r = MsiViewClose(hview);
5725 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5726 r = MsiCloseHandle(hview);
5727 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5728 r = MsiCloseHandle(hdb);
5729 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5732 static const WCHAR _Tables[] = {0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0};
5733 static const WCHAR _StringData[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0};
5734 static const WCHAR _StringPool[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0};
5736 static const WCHAR data14[] = { /* _StringPool */
5738 0, 0, /* string 0 '' */
5741 static const struct {
5745 } database_table_data[] =
5748 {_StringData, NULL, 0},
5749 {_StringPool, data14, sizeof data14},
5752 static void enum_stream_names(IStorage *stg)
5754 IEnumSTATSTG *stgenum = NULL;
5759 BYTE data[MAX_PATH];
5760 BYTE check[MAX_PATH];
5763 memset(check, 'a', MAX_PATH);
5765 hr = IStorage_EnumElements(stg, 0, NULL, 0, &stgenum);
5766 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
5772 hr = IEnumSTATSTG_Next(stgenum, 1, &stat, &count);
5773 if(FAILED(hr) || !count)
5776 ok(!lstrcmpW(stat.pwcsName, database_table_data[n].name),
5777 "Expected table %d name to match\n", n);
5780 hr = IStorage_OpenStream(stg, stat.pwcsName, NULL,
5781 STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5782 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
5783 ok(stm != NULL, "Expected non-NULL stream\n");
5785 CoTaskMemFree(stat.pwcsName);
5788 memset(data, 'a', MAX_PATH);
5789 hr = IStream_Read(stm, data, sz, &count);
5790 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
5792 ok(count == database_table_data[n].size,
5793 "Expected %d, got %d\n", database_table_data[n].size, count);
5795 if (!database_table_data[n].size)
5796 ok(!memcmp(data, check, MAX_PATH), "data should not be changed\n");
5798 ok(!memcmp(data, database_table_data[n].data, database_table_data[n].size),
5799 "Expected table %d data to match\n", n);
5801 IStream_Release(stm);
5805 ok(n == 3, "Expected 3, got %d\n", n);
5807 IEnumSTATSTG_Release(stgenum);
5810 static void test_defaultdatabase(void)
5815 IStorage *stg = NULL;
5817 DeleteFile(msifile);
5819 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5820 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5822 r = MsiDatabaseCommit(hdb);
5823 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5825 MsiCloseHandle(hdb);
5827 hr = StgOpenStorage(msifileW, NULL, STGM_READ | STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
5828 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
5829 ok(stg != NULL, "Expected non-NULL stg\n");
5831 enum_stream_names(stg);
5833 IStorage_Release(stg);
5834 DeleteFileA(msifile);
5837 static void test_order(void)
5839 MSIHANDLE hdb, hview, hrec;
5840 CHAR buffer[MAX_PATH];
5846 ok(hdb, "failed to create db\n");
5848 query = "CREATE TABLE `Empty` ( `A` SHORT NOT NULL PRIMARY KEY `A`)";
5849 r = run_query(hdb, 0, query);
5850 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5852 query = "CREATE TABLE `Mesa` ( `A` SHORT NOT NULL, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
5853 r = run_query(hdb, 0, query);
5854 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5856 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 1, 2, 9 )";
5857 r = run_query(hdb, 0, query);
5858 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5860 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 3, 4, 7 )";
5861 r = run_query(hdb, 0, query);
5862 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5864 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 5, 6, 8 )";
5865 r = run_query(hdb, 0, query);
5866 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5868 query = "CREATE TABLE `Sideboard` ( `D` SHORT NOT NULL, `E` SHORT, `F` SHORT PRIMARY KEY `D`)";
5869 r = run_query(hdb, 0, query);
5870 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5872 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 10, 11, 18 )";
5873 r = run_query(hdb, 0, query);
5874 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5876 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 12, 13, 16 )";
5877 r = run_query(hdb, 0, query);
5878 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5880 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 14, 15, 17 )";
5881 r = run_query(hdb, 0, query);
5882 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5884 query = "SELECT `A`, `B` FROM `Mesa` ORDER BY `C`";
5885 r = MsiDatabaseOpenView(hdb, query, &hview);
5886 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5887 r = MsiViewExecute(hview, 0);
5888 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5890 r = MsiViewFetch(hview, &hrec);
5891 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5893 val = MsiRecordGetInteger(hrec, 1);
5894 ok(val == 3, "Expected 3, got %d\n", val);
5896 val = MsiRecordGetInteger(hrec, 2);
5897 ok(val == 4, "Expected 3, got %d\n", val);
5899 MsiCloseHandle(hrec);
5901 r = MsiViewFetch(hview, &hrec);
5902 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5904 val = MsiRecordGetInteger(hrec, 1);
5905 ok(val == 5, "Expected 5, got %d\n", val);
5907 val = MsiRecordGetInteger(hrec, 2);
5908 ok(val == 6, "Expected 6, got %d\n", val);
5910 MsiCloseHandle(hrec);
5912 r = MsiViewFetch(hview, &hrec);
5913 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5915 val = MsiRecordGetInteger(hrec, 1);
5916 ok(val == 1, "Expected 1, got %d\n", val);
5918 val = MsiRecordGetInteger(hrec, 2);
5919 ok(val == 2, "Expected 2, got %d\n", val);
5921 MsiCloseHandle(hrec);
5923 r = MsiViewFetch(hview, &hrec);
5924 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5926 MsiViewClose(hview);
5927 MsiCloseHandle(hview);
5929 query = "SELECT `A`, `D` FROM `Mesa`, `Sideboard` ORDER BY `F`";
5930 r = MsiDatabaseOpenView(hdb, query, &hview);
5931 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5932 r = MsiViewExecute(hview, 0);
5933 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5935 r = MsiViewFetch(hview, &hrec);
5936 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5938 val = MsiRecordGetInteger(hrec, 1);
5939 ok(val == 1, "Expected 1, got %d\n", val);
5941 val = MsiRecordGetInteger(hrec, 2);
5942 ok(val == 12, "Expected 12, got %d\n", val);
5944 MsiCloseHandle(hrec);
5946 r = MsiViewFetch(hview, &hrec);
5947 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5949 val = MsiRecordGetInteger(hrec, 1);
5950 ok(val == 3, "Expected 3, got %d\n", val);
5952 val = MsiRecordGetInteger(hrec, 2);
5953 ok(val == 12, "Expected 12, got %d\n", val);
5955 MsiCloseHandle(hrec);
5957 r = MsiViewFetch(hview, &hrec);
5958 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5960 val = MsiRecordGetInteger(hrec, 1);
5961 ok(val == 5, "Expected 5, got %d\n", val);
5963 val = MsiRecordGetInteger(hrec, 2);
5964 ok(val == 12, "Expected 12, got %d\n", val);
5966 MsiCloseHandle(hrec);
5968 r = MsiViewFetch(hview, &hrec);
5969 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5971 val = MsiRecordGetInteger(hrec, 1);
5972 ok(val == 1, "Expected 1, got %d\n", val);
5974 val = MsiRecordGetInteger(hrec, 2);
5975 ok(val == 14, "Expected 14, got %d\n", val);
5977 MsiCloseHandle(hrec);
5979 r = MsiViewFetch(hview, &hrec);
5980 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5982 val = MsiRecordGetInteger(hrec, 1);
5983 ok(val == 3, "Expected 3, got %d\n", val);
5985 val = MsiRecordGetInteger(hrec, 2);
5986 ok(val == 14, "Expected 14, got %d\n", val);
5988 MsiCloseHandle(hrec);
5990 r = MsiViewFetch(hview, &hrec);
5991 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5993 val = MsiRecordGetInteger(hrec, 1);
5994 ok(val == 5, "Expected 5, got %d\n", val);
5996 val = MsiRecordGetInteger(hrec, 2);
5997 ok(val == 14, "Expected 14, got %d\n", val);
5999 MsiCloseHandle(hrec);
6001 r = MsiViewFetch(hview, &hrec);
6002 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6004 val = MsiRecordGetInteger(hrec, 1);
6005 ok(val == 1, "Expected 1, got %d\n", val);
6007 val = MsiRecordGetInteger(hrec, 2);
6008 ok(val == 10, "Expected 10, got %d\n", val);
6010 MsiCloseHandle(hrec);
6012 r = MsiViewFetch(hview, &hrec);
6013 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6015 val = MsiRecordGetInteger(hrec, 1);
6016 ok(val == 3, "Expected 3, got %d\n", val);
6018 val = MsiRecordGetInteger(hrec, 2);
6019 ok(val == 10, "Expected 10, got %d\n", val);
6021 MsiCloseHandle(hrec);
6023 r = MsiViewFetch(hview, &hrec);
6024 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6026 val = MsiRecordGetInteger(hrec, 1);
6027 ok(val == 5, "Expected 5, got %d\n", val);
6029 val = MsiRecordGetInteger(hrec, 2);
6030 ok(val == 10, "Expected 10, got %d\n", val);
6032 MsiCloseHandle(hrec);
6034 r = MsiViewFetch(hview, &hrec);
6035 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6037 MsiViewClose(hview);
6038 MsiCloseHandle(hview);
6040 query = "SELECT * FROM `Empty` ORDER BY `A`";
6041 r = MsiDatabaseOpenView(hdb, query, &hview);
6042 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6043 r = MsiViewExecute(hview, 0);
6044 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6046 r = MsiViewFetch(hview, &hrec);
6047 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6049 MsiViewClose(hview);
6050 MsiCloseHandle(hview);
6052 query = "CREATE TABLE `Buffet` ( `One` CHAR(72), `Two` SHORT PRIMARY KEY `One`)";
6053 r = run_query(hdb, 0, query);
6054 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6056 query = "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'uno', 2)";
6057 r = run_query(hdb, 0, query);
6058 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6060 query = "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'dos', 3)";
6061 r = run_query(hdb, 0, query);
6062 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6064 query = "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'tres', 1)";
6065 r = run_query(hdb, 0, query);
6066 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6068 query = "SELECT * FROM `Buffet` WHERE `One` = 'dos' ORDER BY `Two`";
6069 r = MsiDatabaseOpenView(hdb, query, &hview);
6070 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6071 r = MsiViewExecute(hview, 0);
6072 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6074 r = MsiViewFetch(hview, &hrec);
6075 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6077 sz = sizeof(buffer);
6078 r = MsiRecordGetString(hrec, 1, buffer, &sz);
6079 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6080 ok(!lstrcmp(buffer, "dos"), "Expected \"dos\", got \"%s\"\n", buffer);
6082 r = MsiRecordGetInteger(hrec, 2);
6083 ok(r == 3, "Expected 3, got %d\n", r);
6085 MsiCloseHandle(hrec);
6087 r = MsiViewFetch(hview, &hrec);
6088 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6090 MsiViewClose(hview);
6091 MsiCloseHandle(hview);
6092 MsiCloseHandle(hdb);
6095 static void test_viewmodify_delete_temporary(void)
6097 MSIHANDLE hdb, hview, hrec;
6101 DeleteFile(msifile);
6103 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6104 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6106 query = "CREATE TABLE `Table` ( `A` SHORT PRIMARY KEY `A` )";
6107 r = run_query(hdb, 0, query);
6108 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6110 query = "SELECT * FROM `Table`";
6111 r = MsiDatabaseOpenView(hdb, query, &hview);
6112 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6113 r = MsiViewExecute(hview, 0);
6114 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6116 hrec = MsiCreateRecord(1);
6117 MsiRecordSetInteger(hrec, 1, 1);
6119 r = MsiViewModify(hview, MSIMODIFY_INSERT, hrec);
6120 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6122 MsiCloseHandle(hrec);
6124 hrec = MsiCreateRecord(1);
6125 MsiRecordSetInteger(hrec, 1, 2);
6127 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
6128 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6130 MsiCloseHandle(hrec);
6132 hrec = MsiCreateRecord(1);
6133 MsiRecordSetInteger(hrec, 1, 3);
6135 r = MsiViewModify(hview, MSIMODIFY_INSERT, hrec);
6136 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6138 MsiCloseHandle(hrec);
6140 hrec = MsiCreateRecord(1);
6141 MsiRecordSetInteger(hrec, 1, 4);
6143 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
6144 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6146 MsiCloseHandle(hrec);
6147 MsiViewClose(hview);
6148 MsiCloseHandle(hview);
6150 query = "SELECT * FROM `Table` WHERE `A` = 2";
6151 r = MsiDatabaseOpenView(hdb, query, &hview);
6152 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6153 r = MsiViewExecute(hview, 0);
6154 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6155 r = MsiViewFetch(hview, &hrec);
6156 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6158 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
6159 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6161 MsiCloseHandle(hrec);
6162 MsiViewClose(hview);
6163 MsiCloseHandle(hview);
6165 query = "SELECT * FROM `Table` WHERE `A` = 3";
6166 r = MsiDatabaseOpenView(hdb, query, &hview);
6167 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6168 r = MsiViewExecute(hview, 0);
6169 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6170 r = MsiViewFetch(hview, &hrec);
6171 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6173 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
6174 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6176 MsiCloseHandle(hrec);
6177 MsiViewClose(hview);
6178 MsiCloseHandle(hview);
6180 query = "SELECT * FROM `Table` ORDER BY `A`";
6181 r = MsiDatabaseOpenView(hdb, query, &hview);
6182 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6183 r = MsiViewExecute(hview, 0);
6184 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6186 r = MsiViewFetch(hview, &hrec);
6187 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6189 r = MsiRecordGetInteger(hrec, 1);
6190 ok(r == 1, "Expected 1, got %d\n", r);
6192 MsiCloseHandle(hrec);
6194 r = MsiViewFetch(hview, &hrec);
6195 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6197 r = MsiRecordGetInteger(hrec, 1);
6198 ok(r == 4, "Expected 4, got %d\n", r);
6200 MsiCloseHandle(hrec);
6202 r = MsiViewFetch(hview, &hrec);
6203 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6205 MsiViewClose(hview);
6206 MsiCloseHandle(hview);
6207 MsiCloseHandle(hdb);
6208 DeleteFileA(msifile);
6211 static void test_deleterow(void)
6213 MSIHANDLE hdb, hview, hrec;
6219 DeleteFile(msifile);
6221 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6222 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6224 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6225 r = run_query(hdb, 0, query);
6226 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6228 query = "INSERT INTO `Table` (`A`) VALUES ('one')";
6229 r = run_query(hdb, 0, query);
6230 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6232 query = "INSERT INTO `Table` (`A`) VALUES ('two')";
6233 r = run_query(hdb, 0, query);
6234 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6236 query = "DELETE FROM `Table` WHERE `A` = 'one'";
6237 r = run_query(hdb, 0, query);
6238 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6240 r = MsiDatabaseCommit(hdb);
6241 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6243 MsiCloseHandle(hdb);
6245 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
6246 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6248 query = "SELECT * FROM `Table`";
6249 r = MsiDatabaseOpenView(hdb, query, &hview);
6250 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6251 r = MsiViewExecute(hview, 0);
6252 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6254 r = MsiViewFetch(hview, &hrec);
6255 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6258 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6259 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6260 ok(!lstrcmpA(buf, "two"), "Expected two, got %s\n", buf);
6262 MsiCloseHandle(hrec);
6264 r = MsiViewFetch(hview, &hrec);
6265 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6267 MsiViewClose(hview);
6268 MsiCloseHandle(hview);
6269 MsiCloseHandle(hdb);
6270 DeleteFileA(msifile);
6273 static const CHAR import_dat[] = "A\n"
6276 "This is a new 'string' ok\n";
6278 static void test_quotes(void)
6280 MSIHANDLE hdb, hview, hrec;
6286 DeleteFile(msifile);
6288 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6289 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6291 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6292 r = run_query(hdb, 0, query);
6293 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6295 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a 'string' ok' )";
6296 r = run_query(hdb, 0, query);
6297 ok(r == ERROR_BAD_QUERY_SYNTAX,
6298 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6300 query = "INSERT INTO `Table` ( `A` ) VALUES ( \"This is a 'string' ok\" )";
6301 r = run_query(hdb, 0, query);
6302 ok(r == ERROR_BAD_QUERY_SYNTAX,
6303 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6305 query = "INSERT INTO `Table` ( `A` ) VALUES ( \"test\" )";
6306 r = run_query(hdb, 0, query);
6307 ok(r == ERROR_BAD_QUERY_SYNTAX,
6308 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6310 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a ''string'' ok' )";
6311 r = run_query(hdb, 0, query);
6312 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6314 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a '''string''' ok' )";
6315 r = run_query(hdb, 0, query);
6316 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6318 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \'string\' ok' )";
6319 r = run_query(hdb, 0, query);
6320 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6322 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \"string\" ok' )";
6323 r = run_query(hdb, 0, query);
6324 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6326 query = "SELECT * FROM `Table`";
6327 r = MsiDatabaseOpenView(hdb, query, &hview);
6328 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6330 r = MsiViewExecute(hview, 0);
6331 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6333 r = MsiViewFetch(hview, &hrec);
6334 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6337 r = MsiRecordGetString(hrec, 1, buf, &size);
6338 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6339 ok(!lstrcmp(buf, "This is a \"string\" ok"),
6340 "Expected \"This is a \"string\" ok\", got %s\n", buf);
6342 MsiCloseHandle(hrec);
6344 r = MsiViewFetch(hview, &hrec);
6345 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6347 MsiViewClose(hview);
6348 MsiCloseHandle(hview);
6350 write_file("import.idt", import_dat, (sizeof(import_dat) - 1) * sizeof(char));
6352 r = MsiDatabaseImportA(hdb, CURR_DIR, "import.idt");
6353 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6355 DeleteFileA("import.idt");
6357 query = "SELECT * FROM `Table`";
6358 r = MsiDatabaseOpenView(hdb, query, &hview);
6359 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6361 r = MsiViewExecute(hview, 0);
6362 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6364 r = MsiViewFetch(hview, &hrec);
6365 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6368 r = MsiRecordGetString(hrec, 1, buf, &size);
6369 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6370 ok(!lstrcmp(buf, "This is a new 'string' ok"),
6371 "Expected \"This is a new 'string' ok\", got %s\n", buf);
6373 MsiCloseHandle(hrec);
6375 r = MsiViewFetch(hview, &hrec);
6376 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6378 MsiViewClose(hview);
6379 MsiCloseHandle(hview);
6380 MsiCloseHandle(hdb);
6381 DeleteFileA(msifile);
6384 static void test_carriagereturn(void)
6386 MSIHANDLE hdb, hview, hrec;
6392 DeleteFile(msifile);
6394 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6395 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6397 query = "CREATE TABLE `Table`\r ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6398 r = run_query(hdb, 0, query);
6399 ok(r == ERROR_BAD_QUERY_SYNTAX,
6400 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6402 query = "CREATE TABLE `Table` \r( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6403 r = run_query(hdb, 0, query);
6404 ok(r == ERROR_BAD_QUERY_SYNTAX,
6405 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6407 query = "CREATE\r TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6408 r = run_query(hdb, 0, query);
6409 ok(r == ERROR_BAD_QUERY_SYNTAX,
6410 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6412 query = "CREATE TABLE\r `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6413 r = run_query(hdb, 0, query);
6414 ok(r == ERROR_BAD_QUERY_SYNTAX,
6415 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6417 query = "CREATE TABLE `Table` (\r `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6418 r = run_query(hdb, 0, query);
6419 ok(r == ERROR_BAD_QUERY_SYNTAX,
6420 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6422 query = "CREATE TABLE `Table` ( `A`\r CHAR(72) NOT NULL PRIMARY KEY `A` )";
6423 r = run_query(hdb, 0, query);
6424 ok(r == ERROR_BAD_QUERY_SYNTAX,
6425 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6427 query = "CREATE TABLE `Table` ( `A` CHAR(72)\r NOT NULL PRIMARY KEY `A` )";
6428 r = run_query(hdb, 0, query);
6429 ok(r == ERROR_BAD_QUERY_SYNTAX,
6430 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6432 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT\r NULL PRIMARY KEY `A` )";
6433 r = run_query(hdb, 0, query);
6434 ok(r == ERROR_BAD_QUERY_SYNTAX,
6435 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6437 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT \rNULL PRIMARY KEY `A` )";
6438 r = run_query(hdb, 0, query);
6439 ok(r == ERROR_BAD_QUERY_SYNTAX,
6440 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6442 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL\r PRIMARY KEY `A` )";
6443 r = run_query(hdb, 0, query);
6444 ok(r == ERROR_BAD_QUERY_SYNTAX,
6445 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6447 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL \rPRIMARY KEY `A` )";
6448 r = run_query(hdb, 0, query);
6449 ok(r == ERROR_BAD_QUERY_SYNTAX,
6450 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6452 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY\r KEY `A` )";
6453 r = run_query(hdb, 0, query);
6454 ok(r == ERROR_BAD_QUERY_SYNTAX,
6455 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6457 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY \rKEY `A` )";
6458 r = run_query(hdb, 0, query);
6459 ok(r == ERROR_BAD_QUERY_SYNTAX,
6460 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6462 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY\r `A` )";
6463 r = run_query(hdb, 0, query);
6464 ok(r == ERROR_BAD_QUERY_SYNTAX,
6465 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6467 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A`\r )";
6468 r = run_query(hdb, 0, query);
6469 ok(r == ERROR_BAD_QUERY_SYNTAX,
6470 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6472 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )\r";
6473 r = run_query(hdb, 0, query);
6474 ok(r == ERROR_BAD_QUERY_SYNTAX,
6475 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6477 query = "CREATE TABLE `\rOne` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6478 r = run_query(hdb, 0, query);
6479 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6481 query = "CREATE TABLE `Tw\ro` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6482 r = run_query(hdb, 0, query);
6483 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6485 query = "CREATE TABLE `Three\r` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6486 r = run_query(hdb, 0, query);
6487 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6489 query = "CREATE TABLE `Four` ( `A\r` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6490 r = run_query(hdb, 0, query);
6491 ok(r == ERROR_BAD_QUERY_SYNTAX,
6492 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6494 query = "CREATE TABLE `Four` ( `\rA` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6495 r = run_query(hdb, 0, query);
6496 ok(r == ERROR_BAD_QUERY_SYNTAX,
6497 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6499 query = "CREATE TABLE `Four` ( `A` CHAR(72\r) NOT NULL PRIMARY KEY `A` )";
6500 r = run_query(hdb, 0, query);
6501 ok(r == ERROR_BAD_QUERY_SYNTAX,
6502 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6504 query = "CREATE TABLE `Four` ( `A` CHAR(\r72) NOT NULL PRIMARY KEY `A` )";
6505 r = run_query(hdb, 0, query);
6506 ok(r == ERROR_BAD_QUERY_SYNTAX,
6507 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6509 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `\rA` )";
6510 r = run_query(hdb, 0, query);
6511 ok(r == ERROR_BAD_QUERY_SYNTAX,
6512 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6514 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
6515 r = run_query(hdb, 0, query);
6516 ok(r == ERROR_BAD_QUERY_SYNTAX,
6517 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6519 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
6520 r = run_query(hdb, 0, query);
6521 ok(r == ERROR_BAD_QUERY_SYNTAX,
6522 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6524 query = "SELECT * FROM `_Tables`";
6525 r = MsiDatabaseOpenView(hdb, query, &hview);
6526 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6527 r = MsiViewExecute(hview, 0);
6528 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6530 r = MsiViewFetch(hview, &hrec);
6531 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6534 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6535 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6536 ok(!lstrcmpA(buf, "\rOne"), "Expected \"\\rOne\", got \"%s\"\n", buf);
6538 MsiCloseHandle(hrec);
6540 r = MsiViewFetch(hview, &hrec);
6541 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6544 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6545 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6546 ok(!lstrcmpA(buf, "Tw\ro"), "Expected \"Tw\\ro\", got \"%s\"\n", buf);
6548 MsiCloseHandle(hrec);
6550 r = MsiViewFetch(hview, &hrec);
6551 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6554 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6555 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6556 ok(!lstrcmpA(buf, "Three\r"), "Expected \"Three\r\", got \"%s\"\n", buf);
6558 MsiCloseHandle(hrec);
6560 r = MsiViewFetch(hview, &hrec);
6561 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6563 MsiViewClose(hview);
6564 MsiCloseHandle(hview);
6566 MsiCloseHandle(hdb);
6567 DeleteFileA(msifile);
6570 static void test_noquotes(void)
6572 MSIHANDLE hdb, hview, hrec;
6578 DeleteFile(msifile);
6580 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6581 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6583 query = "CREATE TABLE Table ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6584 r = run_query(hdb, 0, query);
6585 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6587 query = "CREATE TABLE `Table` ( A CHAR(72) NOT NULL PRIMARY KEY `A` )";
6588 r = run_query(hdb, 0, query);
6589 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6591 query = "CREATE TABLE `Table2` ( `A` CHAR(72) NOT NULL PRIMARY KEY A )";
6592 r = run_query(hdb, 0, query);
6593 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6595 query = "CREATE TABLE `Table3` ( A CHAR(72) NOT NULL PRIMARY KEY A )";
6596 r = run_query(hdb, 0, query);
6597 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6599 query = "SELECT * FROM `_Tables`";
6600 r = MsiDatabaseOpenView(hdb, query, &hview);
6601 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6602 r = MsiViewExecute(hview, 0);
6603 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6605 r = MsiViewFetch(hview, &hrec);
6606 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6609 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6610 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6611 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
6613 MsiCloseHandle(hrec);
6615 r = MsiViewFetch(hview, &hrec);
6616 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6619 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6620 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6621 ok(!lstrcmpA(buf, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf);
6623 MsiCloseHandle(hrec);
6625 r = MsiViewFetch(hview, &hrec);
6626 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6629 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6630 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6631 ok(!lstrcmpA(buf, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf);
6633 MsiCloseHandle(hrec);
6635 r = MsiViewFetch(hview, &hrec);
6636 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6638 MsiViewClose(hview);
6639 MsiCloseHandle(hview);
6641 query = "SELECT * FROM `_Columns`";
6642 r = MsiDatabaseOpenView(hdb, query, &hview);
6643 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6644 r = MsiViewExecute(hview, 0);
6645 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6647 r = MsiViewFetch(hview, &hrec);
6648 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6651 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6652 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6653 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
6655 r = MsiRecordGetInteger(hrec, 2);
6656 ok(r == 1, "Expected 1, got %d\n", r);
6659 r = MsiRecordGetStringA(hrec, 3, buf, &size);
6660 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6661 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
6663 MsiCloseHandle(hrec);
6665 r = MsiViewFetch(hview, &hrec);
6666 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6669 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6670 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6671 ok(!lstrcmpA(buf, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf);
6673 r = MsiRecordGetInteger(hrec, 2);
6674 ok(r == 1, "Expected 1, got %d\n", r);
6677 r = MsiRecordGetStringA(hrec, 3, buf, &size);
6678 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6679 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
6681 MsiCloseHandle(hrec);
6683 r = MsiViewFetch(hview, &hrec);
6684 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6687 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6688 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6689 ok(!lstrcmpA(buf, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf);
6691 r = MsiRecordGetInteger(hrec, 2);
6692 ok(r == 1, "Expected 1, got %d\n", r);
6695 r = MsiRecordGetStringA(hrec, 3, buf, &size);
6696 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6697 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
6699 MsiCloseHandle(hrec);
6701 r = MsiViewFetch(hview, &hrec);
6702 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6704 MsiViewClose(hview);
6705 MsiCloseHandle(hview);
6707 query = "INSERT INTO Table ( `A` ) VALUES ( 'hi' )";
6708 r = run_query(hdb, 0, query);
6709 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6711 query = "INSERT INTO `Table` ( A ) VALUES ( 'hi' )";
6712 r = run_query(hdb, 0, query);
6713 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6715 query = "INSERT INTO `Table` ( `A` ) VALUES ( hi )";
6716 r = run_query(hdb, 0, query);
6717 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6719 query = "SELECT * FROM Table WHERE `A` = 'hi'";
6720 r = run_query(hdb, 0, query);
6721 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6723 query = "SELECT * FROM `Table` WHERE `A` = hi";
6724 r = run_query(hdb, 0, query);
6725 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6727 query = "SELECT * FROM Table";
6728 r = run_query(hdb, 0, query);
6729 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6731 query = "SELECT * FROM Table2";
6732 r = MsiDatabaseOpenView(hdb, query, &hview);
6733 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6734 r = MsiViewExecute(hview, 0);
6735 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6737 r = MsiViewFetch(hview, &hrec);
6738 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6740 MsiViewClose(hview);
6741 MsiCloseHandle(hview);
6743 query = "SELECT * FROM `Table` WHERE A = 'hi'";
6744 r = MsiDatabaseOpenView(hdb, query, &hview);
6745 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6746 r = MsiViewExecute(hview, 0);
6747 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6749 r = MsiViewFetch(hview, &hrec);
6750 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6753 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6754 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6755 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
6757 MsiCloseHandle(hrec);
6759 r = MsiViewFetch(hview, &hrec);
6760 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6762 MsiViewClose(hview);
6763 MsiCloseHandle(hview);
6764 MsiCloseHandle(hdb);
6765 DeleteFileA(msifile);
6768 static void read_file_data(LPCSTR filename, LPSTR buffer)
6773 file = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
6774 ZeroMemory(buffer, MAX_PATH);
6775 ReadFile(file, buffer, MAX_PATH, &read, NULL);
6779 static void test_forcecodepage(void)
6783 char buffer[MAX_PATH];
6786 DeleteFile(msifile);
6788 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6789 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6791 query = "SELECT * FROM `_ForceCodepage`";
6792 r = run_query(hdb, 0, query);
6793 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6795 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6796 r = run_query(hdb, 0, query);
6797 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6799 query = "SELECT * FROM `_ForceCodepage`";
6800 r = run_query(hdb, 0, query);
6801 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6803 r = MsiDatabaseCommit(hdb);
6804 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6806 query = "SELECT * FROM `_ForceCodepage`";
6807 r = run_query(hdb, 0, query);
6808 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6810 MsiCloseHandle(hdb);
6812 r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb);
6813 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6815 query = "SELECT * FROM `_ForceCodepage`";
6816 r = run_query(hdb, 0, query);
6817 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6819 r = MsiDatabaseExport(hdb, "_ForceCodepage", CURR_DIR, "forcecodepage.idt");
6820 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6822 read_file_data("forcecodepage.idt", buffer);
6823 ok(!lstrcmpA(buffer, "\r\n\r\n0\t_ForceCodepage\r\n"),
6824 "Expected \"\r\n\r\n0\t_ForceCodepage\r\n\", got \"%s\"", buffer);
6826 MsiCloseHandle(hdb);
6827 DeleteFileA(msifile);
6828 DeleteFileA("forcecodepage.idt");
6831 static void test_viewmodify_refresh(void)
6833 MSIHANDLE hdb, hview, hrec;
6835 char buffer[MAX_PATH];
6839 DeleteFile(msifile);
6841 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6842 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6844 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL, `B` INT PRIMARY KEY `A` )";
6845 r = run_query(hdb, 0, query);
6846 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6848 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hi', 1 )";
6849 r = run_query(hdb, 0, query);
6850 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6852 query = "SELECT * FROM `Table`";
6853 r = MsiDatabaseOpenView(hdb, query, &hview);
6854 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6855 r = MsiViewExecute(hview, 0);
6856 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6858 r = MsiViewFetch(hview, &hrec);
6859 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6861 query = "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hi'";
6862 r = run_query(hdb, 0, query);
6863 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6865 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
6866 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6869 r = MsiRecordGetStringA(hrec, 1, buffer, &size);
6870 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6871 ok(!lstrcmpA(buffer, "hi"), "Expected \"hi\", got \"%s\"\n", buffer);
6872 ok(size == 2, "Expected 2, got %d\n", size);
6874 r = MsiRecordGetInteger(hrec, 2);
6875 ok(r == 2, "Expected 2, got %d\n", r);
6877 MsiCloseHandle(hrec);
6878 MsiViewClose(hview);
6879 MsiCloseHandle(hview);
6881 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hello', 3 )";
6882 r = run_query(hdb, 0, query);
6883 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6885 query = "SELECT * FROM `Table` WHERE `B` = 3";
6886 r = MsiDatabaseOpenView(hdb, query, &hview);
6887 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6888 r = MsiViewExecute(hview, 0);
6889 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6891 r = MsiViewFetch(hview, &hrec);
6892 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6894 query = "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hello'";
6895 r = run_query(hdb, 0, query);
6896 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6898 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hithere', 3 )";
6899 r = run_query(hdb, 0, query);
6900 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6902 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
6903 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6906 r = MsiRecordGetStringA(hrec, 1, buffer, &size);
6907 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6908 ok(!lstrcmpA(buffer, "hello"), "Expected \"hello\", got \"%s\"\n", buffer);
6909 ok(size == 5, "Expected 5, got %d\n", size);
6911 r = MsiRecordGetInteger(hrec, 2);
6912 ok(r == 2, "Expected 2, got %d\n", r);
6914 MsiCloseHandle(hrec);
6915 MsiViewClose(hview);
6916 MsiCloseHandle(hview);
6917 MsiCloseHandle(hdb);
6918 DeleteFileA(msifile);
6921 static void test_where_viewmodify(void)
6923 MSIHANDLE hdb, hview, hrec;
6927 DeleteFile(msifile);
6929 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6930 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6932 query = "CREATE TABLE `Table` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6933 r = run_query(hdb, 0, query);
6934 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6936 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 1, 2 )";
6937 r = run_query(hdb, 0, query);
6938 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6940 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 3, 4 )";
6941 r = run_query(hdb, 0, query);
6942 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6944 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 5, 6 )";
6945 r = run_query(hdb, 0, query);
6946 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6948 /* `B` = 3 doesn't match, but the view shouldn't be executed */
6949 query = "SELECT * FROM `Table` WHERE `B` = 3";
6950 r = MsiDatabaseOpenView(hdb, query, &hview);
6951 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6953 hrec = MsiCreateRecord(2);
6954 MsiRecordSetInteger(hrec, 1, 7);
6955 MsiRecordSetInteger(hrec, 2, 8);
6957 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
6958 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6960 MsiCloseHandle(hrec);
6961 MsiViewClose(hview);
6962 MsiCloseHandle(hview);
6964 query = "SELECT * FROM `Table` WHERE `A` = 7";
6965 r = MsiDatabaseOpenView(hdb, query, &hview);
6966 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6967 r = MsiViewExecute(hview, 0);
6968 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6970 r = MsiViewFetch(hview, &hrec);
6971 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6973 r = MsiRecordGetInteger(hrec, 1);
6974 ok(r == 7, "Expected 7, got %d\n", r);
6976 r = MsiRecordGetInteger(hrec, 2);
6977 ok(r == 8, "Expected 8, got %d\n", r);
6979 MsiRecordSetInteger(hrec, 2, 9);
6981 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
6982 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6984 MsiCloseHandle(hrec);
6985 MsiViewClose(hview);
6986 MsiCloseHandle(hview);
6988 query = "SELECT * FROM `Table` WHERE `A` = 7";
6989 r = MsiDatabaseOpenView(hdb, query, &hview);
6990 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6991 r = MsiViewExecute(hview, 0);
6992 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6994 r = MsiViewFetch(hview, &hrec);
6995 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6997 r = MsiRecordGetInteger(hrec, 1);
6998 ok(r == 7, "Expected 7, got %d\n", r);
7000 r = MsiRecordGetInteger(hrec, 2);
7001 ok(r == 9, "Expected 9, got %d\n", r);
7003 query = "UPDATE `Table` SET `B` = 10 WHERE `A` = 7";
7004 r = run_query(hdb, 0, query);
7005 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7007 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
7008 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7010 r = MsiRecordGetInteger(hrec, 1);
7011 ok(r == 7, "Expected 7, got %d\n", r);
7013 r = MsiRecordGetInteger(hrec, 2);
7014 ok(r == 10, "Expected 10, got %d\n", r);
7016 MsiCloseHandle(hrec);
7017 MsiViewClose(hview);
7018 MsiCloseHandle(hview);
7019 MsiCloseHandle(hdb);
7022 static BOOL create_storage(LPCSTR name)
7024 WCHAR nameW[MAX_PATH];
7031 MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, MAX_PATH);
7032 hr = StgCreateDocfile(nameW, STGM_CREATE | STGM_READWRITE |
7033 STGM_DIRECT | STGM_SHARE_EXCLUSIVE, 0, &stg);
7037 hr = IStorage_CreateStream(stg, nameW, STGM_WRITE | STGM_SHARE_EXCLUSIVE,
7042 hr = IStream_Write(stm, "stgdata", 8, &count);
7047 IStream_Release(stm);
7048 IStorage_Release(stg);
7053 static void test_storages_table(void)
7055 MSIHANDLE hdb, hview, hrec;
7056 IStorage *stg, *inner;
7058 char file[MAX_PATH];
7060 WCHAR name[MAX_PATH];
7067 ok(hdb, "failed to create db\n");
7069 r = MsiDatabaseCommit(hdb);
7070 ok(r == ERROR_SUCCESS , "Failed to commit database\n");
7072 MsiCloseHandle(hdb);
7074 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb);
7075 ok(r == ERROR_SUCCESS , "Failed to open database\n");
7077 /* check the column types */
7078 hrec = get_column_info(hdb, "SELECT * FROM `_Storages`", MSICOLINFO_TYPES);
7079 ok(hrec, "failed to get column info hrecord\n");
7080 ok(check_record(hrec, 1, "s62"), "wrong hrecord type\n");
7081 ok(check_record(hrec, 2, "V0"), "wrong hrecord type\n");
7083 MsiCloseHandle(hrec);
7085 /* now try the names */
7086 hrec = get_column_info(hdb, "SELECT * FROM `_Storages`", MSICOLINFO_NAMES);
7087 ok(hrec, "failed to get column info hrecord\n");
7088 ok(check_record(hrec, 1, "Name"), "wrong hrecord type\n");
7089 ok(check_record(hrec, 2, "Data"), "wrong hrecord type\n");
7091 MsiCloseHandle(hrec);
7093 create_storage("storage.bin");
7095 hrec = MsiCreateRecord(2);
7096 MsiRecordSetString(hrec, 1, "stgname");
7098 r = MsiRecordSetStream(hrec, 2, "storage.bin");
7099 ok(r == ERROR_SUCCESS, "Failed to add stream data to the hrecord: %d\n", r);
7101 DeleteFileA("storage.bin");
7103 query = "INSERT INTO `_Storages` (`Name`, `Data`) VALUES (?, ?)";
7104 r = MsiDatabaseOpenView(hdb, query, &hview);
7105 ok(r == ERROR_SUCCESS, "Failed to open database hview: %d\n", r);
7107 r = MsiViewExecute(hview, hrec);
7108 ok(r == ERROR_SUCCESS, "Failed to execute hview: %d\n", r);
7110 MsiCloseHandle(hrec);
7111 MsiViewClose(hview);
7112 MsiCloseHandle(hview);
7114 query = "SELECT `Name`, `Data` FROM `_Storages`";
7115 r = MsiDatabaseOpenView(hdb, query, &hview);
7116 ok(r == ERROR_SUCCESS, "Failed to open database hview: %d\n", r);
7118 r = MsiViewExecute(hview, 0);
7119 ok(r == ERROR_SUCCESS, "Failed to execute hview: %d\n", r);
7121 r = MsiViewFetch(hview, &hrec);
7122 ok(r == ERROR_SUCCESS, "Failed to fetch hrecord: %d\n", r);
7125 r = MsiRecordGetString(hrec, 1, file, &size);
7126 ok(r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
7127 ok(!lstrcmp(file, "stgname"), "Expected \"stgname\", got \"%s\"\n", file);
7130 lstrcpyA(buf, "apple");
7131 r = MsiRecordReadStream(hrec, 2, buf, &size);
7132 ok(r == ERROR_INVALID_DATA, "Expected ERROR_INVALID_DATA, got %d\n", r);
7133 ok(!lstrcmp(buf, "apple"), "Expected buf to be unchanged, got %s\n", buf);
7134 ok(size == 0, "Expected 0, got %d\n", size);
7136 MsiCloseHandle(hrec);
7138 r = MsiViewFetch(hview, &hrec);
7139 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7141 MsiViewClose(hview);
7142 MsiCloseHandle(hview);
7144 MsiDatabaseCommit(hdb);
7145 MsiCloseHandle(hdb);
7147 MultiByteToWideChar(CP_ACP, 0, msifile, -1, name, MAX_PATH);
7148 hr = StgOpenStorage(name, NULL, STGM_DIRECT | STGM_READ |
7149 STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
7150 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
7151 ok(stg != NULL, "Expected non-NULL storage\n");
7153 MultiByteToWideChar(CP_ACP, 0, "stgname", -1, name, MAX_PATH);
7154 hr = IStorage_OpenStorage(stg, name, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE,
7156 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
7157 ok(inner != NULL, "Expected non-NULL storage\n");
7159 MultiByteToWideChar(CP_ACP, 0, "storage.bin", -1, name, MAX_PATH);
7160 hr = IStorage_OpenStream(inner, name, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
7161 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
7162 ok(stm != NULL, "Expected non-NULL stream\n");
7164 hr = IStream_Read(stm, buf, MAX_PATH, &size);
7165 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
7166 ok(size == 8, "Expected 8, got %d\n", size);
7167 ok(!lstrcmpA(buf, "stgdata"), "Expected \"stgdata\", got \"%s\"\n", buf);
7169 IStream_Release(stm);
7170 IStorage_Release(inner);
7172 IStorage_Release(stg);
7173 DeleteFileA(msifile);
7176 static void test_dbtopackage(void)
7178 MSIHANDLE hdb, hpkg;
7184 /* create an empty database, transact mode */
7185 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7186 ok(r == ERROR_SUCCESS, "Failed to create database\n");
7188 set_summary_info(hdb);
7190 r = create_directory_table(hdb);
7191 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7193 r = create_custom_action_table(hdb);
7194 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7196 r = add_custom_action_entry(hdb, "'SetProp', 51, 'MYPROP', 'grape'");
7197 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7199 sprintf(package, "#%i", hdb);
7200 r = MsiOpenPackage(package, &hpkg);
7201 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7203 /* property is not set yet */
7205 lstrcpyA(buf, "kiwi");
7206 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7207 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7208 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7209 ok(size == 0, "Expected 0, got %d\n", size);
7211 /* run the custom action to set the property */
7212 r = MsiDoAction(hpkg, "SetProp");
7213 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7215 /* property is now set */
7217 lstrcpyA(buf, "kiwi");
7218 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7219 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7220 ok(!lstrcmpA(buf, "grape"), "Expected \"grape\", got \"%s\"\n", buf);
7221 ok(size == 5, "Expected 5, got %d\n", size);
7223 MsiCloseHandle(hpkg);
7225 /* reset the package */
7226 r = MsiOpenPackage(package, &hpkg);
7227 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7229 /* property is not set anymore */
7231 lstrcpyA(buf, "kiwi");
7232 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7233 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7236 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7237 ok(size == 0, "Expected 0, got %d\n", size);
7240 MsiCloseHandle(hdb);
7241 MsiCloseHandle(hpkg);
7243 /* create an empty database, direct mode */
7244 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATEDIRECT, &hdb);
7245 ok(r == ERROR_SUCCESS, "Failed to create database\n");
7247 set_summary_info(hdb);
7249 r = create_directory_table(hdb);
7250 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7252 r = create_custom_action_table(hdb);
7253 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7255 r = add_custom_action_entry(hdb, "'SetProp', 51, 'MYPROP', 'grape'");
7256 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7258 sprintf(package, "#%i", hdb);
7259 r = MsiOpenPackage(package, &hpkg);
7260 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7262 /* property is not set yet */
7264 lstrcpyA(buf, "kiwi");
7265 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7266 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7267 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7268 ok(size == 0, "Expected 0, got %d\n", size);
7270 /* run the custom action to set the property */
7271 r = MsiDoAction(hpkg, "SetProp");
7272 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7274 /* property is now set */
7276 lstrcpyA(buf, "kiwi");
7277 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7278 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7279 ok(!lstrcmpA(buf, "grape"), "Expected \"grape\", got \"%s\"\n", buf);
7280 ok(size == 5, "Expected 5, got %d\n", size);
7282 MsiCloseHandle(hpkg);
7284 /* reset the package */
7285 r = MsiOpenPackage(package, &hpkg);
7286 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7288 /* property is not set anymore */
7290 lstrcpyA(buf, "kiwi");
7291 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7292 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7295 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7296 ok(size == 0, "Expected 0, got %d\n", size);
7299 MsiCloseHandle(hdb);
7300 MsiCloseHandle(hpkg);
7301 DeleteFileA(msifile);
7304 static void test_droptable(void)
7306 MSIHANDLE hdb, hview, hrec;
7312 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7313 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7315 query = "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7316 r = run_query(hdb, 0, query);
7317 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7319 query = "SELECT * FROM `One`";
7320 r = do_query(hdb, query, &hrec);
7321 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7323 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7324 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7325 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7326 r = MsiViewExecute(hview, 0);
7327 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7329 r = MsiViewFetch(hview, &hrec);
7330 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7333 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7334 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7335 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7337 MsiCloseHandle(hrec);
7338 MsiViewClose(hview);
7339 MsiCloseHandle(hview);
7341 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7342 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7343 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7344 r = MsiViewExecute(hview, 0);
7345 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7347 r = MsiViewFetch(hview, &hrec);
7348 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7351 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7352 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7353 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7355 r = MsiRecordGetInteger(hrec, 2);
7356 ok(r == 1, "Expected 1, got %d\n", r);
7359 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7360 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7361 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
7363 MsiCloseHandle(hrec);
7365 r = MsiViewFetch(hview, &hrec);
7366 ok(r == ERROR_NO_MORE_ITEMS,
7367 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7369 MsiViewClose(hview);
7370 MsiCloseHandle(hview);
7372 query = "DROP `One`";
7373 r = run_query(hdb, 0, query);
7374 ok(r == ERROR_BAD_QUERY_SYNTAX,
7375 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7377 query = "DROP TABLE";
7378 r = run_query(hdb, 0, query);
7379 ok(r == ERROR_BAD_QUERY_SYNTAX,
7380 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7382 query = "DROP TABLE `One`";
7384 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7385 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7386 r = MsiViewExecute(hview, 0);
7387 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7389 r = MsiViewFetch(hview, &hrec);
7390 ok(r == ERROR_FUNCTION_FAILED,
7391 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
7393 MsiViewClose(hview);
7394 MsiCloseHandle(hview);
7396 query = "SELECT * FROM `IDontExist`";
7397 r = do_query(hdb, query, &hrec);
7398 ok(r == ERROR_BAD_QUERY_SYNTAX,
7399 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7401 query = "SELECT * FROM `One`";
7402 r = do_query(hdb, query, &hrec);
7403 ok(r == ERROR_BAD_QUERY_SYNTAX,
7404 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7406 query = "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7407 r = run_query(hdb, 0, query);
7408 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7410 query = "DROP TABLE One";
7411 r = run_query(hdb, 0, query);
7412 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7414 query = "SELECT * FROM `One`";
7415 r = do_query(hdb, query, &hrec);
7416 ok(r == ERROR_BAD_QUERY_SYNTAX,
7417 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7419 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7420 r = do_query(hdb, query, &hrec);
7421 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7423 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7424 r = do_query(hdb, query, &hrec);
7425 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7427 query = "CREATE TABLE `One` ( `B` INT, `C` INT PRIMARY KEY `B` )";
7428 r = run_query(hdb, 0, query);
7429 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7431 query = "SELECT * FROM `One`";
7432 r = do_query(hdb, query, &hrec);
7433 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7435 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7436 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7437 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7438 r = MsiViewExecute(hview, 0);
7439 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7441 r = MsiViewFetch(hview, &hrec);
7442 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7445 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7446 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7447 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7449 MsiCloseHandle(hrec);
7450 MsiViewClose(hview);
7451 MsiCloseHandle(hview);
7453 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7454 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7455 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7456 r = MsiViewExecute(hview, 0);
7457 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7459 r = MsiViewFetch(hview, &hrec);
7460 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7463 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7464 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7465 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7467 r = MsiRecordGetInteger(hrec, 2);
7468 ok(r == 1, "Expected 1, got %d\n", r);
7471 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7472 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7473 ok(!lstrcmpA(buf, "B"), "Expected \"B\", got \"%s\"\n", buf);
7475 MsiCloseHandle(hrec);
7477 r = MsiViewFetch(hview, &hrec);
7478 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7481 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7482 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7483 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7485 r = MsiRecordGetInteger(hrec, 2);
7486 ok(r == 2, "Expected 2, got %d\n", r);
7489 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7490 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7491 ok(!lstrcmpA(buf, "C"), "Expected \"C\", got \"%s\"\n", buf);
7493 MsiCloseHandle(hrec);
7495 r = MsiViewFetch(hview, &hrec);
7496 ok(r == ERROR_NO_MORE_ITEMS,
7497 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7499 MsiViewClose(hview);
7500 MsiCloseHandle(hview);
7502 query = "DROP TABLE One";
7503 r = run_query(hdb, 0, query);
7504 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7506 query = "SELECT * FROM `One`";
7507 r = do_query(hdb, query, &hrec);
7508 ok(r == ERROR_BAD_QUERY_SYNTAX,
7509 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7511 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7512 r = do_query(hdb, query, &hrec);
7513 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7515 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7516 r = do_query(hdb, query, &hrec);
7517 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7519 MsiCloseHandle(hdb);
7520 DeleteFileA(msifile);
7523 static void test_dbmerge(void)
7525 MSIHANDLE hdb, href, hview, hrec;
7531 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7532 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7534 r = MsiOpenDatabase("refdb.msi", MSIDBOPEN_CREATE, &href);
7535 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7537 /* hDatabase is invalid */
7538 r = MsiDatabaseMergeA(0, href, "MergeErrors");
7539 ok(r == ERROR_INVALID_HANDLE,
7540 "Expected ERROR_INVALID_HANDLE, got %d\n", r);
7542 /* hDatabaseMerge is invalid */
7543 r = MsiDatabaseMergeA(hdb, 0, "MergeErrors");
7544 ok(r == ERROR_INVALID_HANDLE,
7545 "Expected ERROR_INVALID_HANDLE, got %d\n", r);
7547 /* szTableName is NULL */
7548 r = MsiDatabaseMergeA(hdb, href, NULL);
7549 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7551 /* szTableName is empty */
7552 r = MsiDatabaseMergeA(hdb, href, "");
7553 ok(r == ERROR_INVALID_TABLE, "Expected ERROR_INVALID_TABLE, got %d\n", r);
7555 /* both DBs empty, szTableName is valid */
7556 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7557 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7559 query = "CREATE TABLE `One` ( `A` 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 = "CREATE TABLE `One` ( `A` CHAR(72) PRIMARY KEY `A` )";
7564 r = run_query(href, 0, query);
7565 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7567 /* column types don't match */
7568 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7569 ok(r == ERROR_DATATYPE_MISMATCH,
7570 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7572 /* nothing in MergeErrors */
7573 query = "SELECT * FROM `MergeErrors`";
7574 r = do_query(hdb, query, &hrec);
7575 ok(r == ERROR_BAD_QUERY_SYNTAX,
7576 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7578 query = "DROP TABLE `One`";
7579 r = run_query(hdb, 0, query);
7580 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7582 query = "DROP TABLE `One`";
7583 r = run_query(href, 0, query);
7584 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7586 query = "CREATE TABLE `One` ( "
7589 "`C` CHAR(64) LOCALIZABLE, "
7591 "`E` CHAR(72) NOT NULL, "
7592 "`F` CHAR(56) NOT NULL, "
7593 "`G` CHAR(64) NOT NULL LOCALIZABLE, "
7594 "`H` LONGCHAR NOT NULL "
7595 "PRIMARY KEY `A` )";
7596 r = run_query(hdb, 0, query);
7597 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7599 query = "CREATE TABLE `One` ( "
7604 "`E` CHAR(64) NOT NULL, "
7605 "`F` CHAR(64) NOT NULL, "
7606 "`G` CHAR(64) NOT NULL, "
7607 "`H` CHAR(64) NOT NULL "
7608 "PRIMARY KEY `A` )";
7609 r = run_query(href, 0, query);
7610 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7612 /* column sting types don't match exactly */
7613 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7614 ok(r == ERROR_SUCCESS,
7615 "Expected ERROR_SUCCESS, got %d\n", r);
7617 /* nothing in MergeErrors */
7618 query = "SELECT * FROM `MergeErrors`";
7619 r = do_query(hdb, query, &hrec);
7620 ok(r == ERROR_BAD_QUERY_SYNTAX,
7621 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7623 query = "DROP TABLE `One`";
7624 r = run_query(hdb, 0, query);
7625 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7627 query = "DROP TABLE `One`";
7628 r = run_query(href, 0, query);
7629 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7631 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7632 r = run_query(hdb, 0, query);
7633 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7635 query = "CREATE TABLE `One` ( `A` INT, `C` INT PRIMARY KEY `A` )";
7636 r = run_query(href, 0, query);
7637 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7639 /* column names don't match */
7640 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7641 ok(r == ERROR_DATATYPE_MISMATCH,
7642 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7644 /* nothing in MergeErrors */
7645 query = "SELECT * FROM `MergeErrors`";
7646 r = do_query(hdb, query, &hrec);
7647 ok(r == ERROR_BAD_QUERY_SYNTAX,
7648 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7650 query = "DROP TABLE `One`";
7651 r = run_query(hdb, 0, query);
7652 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7654 query = "DROP TABLE `One`";
7655 r = run_query(href, 0, query);
7656 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7658 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7659 r = run_query(hdb, 0, query);
7660 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7662 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `B` )";
7663 r = run_query(href, 0, query);
7664 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7666 /* primary keys don't match */
7667 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7668 ok(r == ERROR_DATATYPE_MISMATCH,
7669 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7671 /* nothing in MergeErrors */
7672 query = "SELECT * FROM `MergeErrors`";
7673 r = do_query(hdb, query, &hrec);
7674 ok(r == ERROR_BAD_QUERY_SYNTAX,
7675 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7677 query = "DROP TABLE `One`";
7678 r = run_query(hdb, 0, query);
7679 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7681 query = "DROP TABLE `One`";
7682 r = run_query(href, 0, query);
7683 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7685 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7686 r = run_query(hdb, 0, query);
7687 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7689 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A`, `B` )";
7690 r = run_query(href, 0, query);
7691 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7693 /* number of primary keys doesn't match */
7694 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7695 ok(r == ERROR_DATATYPE_MISMATCH,
7696 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7698 /* nothing in MergeErrors */
7699 query = "SELECT * FROM `MergeErrors`";
7700 r = do_query(hdb, query, &hrec);
7701 ok(r == ERROR_BAD_QUERY_SYNTAX,
7702 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7704 query = "DROP TABLE `One`";
7705 r = run_query(hdb, 0, query);
7706 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7708 query = "DROP TABLE `One`";
7709 r = run_query(href, 0, query);
7710 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7712 query = "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
7713 r = run_query(hdb, 0, query);
7714 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7716 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7717 r = run_query(href, 0, query);
7718 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7720 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
7721 r = run_query(href, 0, query);
7722 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7724 /* number of columns doesn't match */
7725 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7726 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7728 query = "SELECT * FROM `One`";
7729 r = do_query(hdb, query, &hrec);
7730 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7732 r = MsiRecordGetInteger(hrec, 1);
7733 ok(r == 1, "Expected 1, got %d\n", r);
7735 r = MsiRecordGetInteger(hrec, 2);
7736 ok(r == 2, "Expected 2, got %d\n", r);
7738 r = MsiRecordGetInteger(hrec, 3);
7739 ok(r == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", r);
7741 MsiCloseHandle(hrec);
7743 /* nothing in MergeErrors */
7744 query = "SELECT * FROM `MergeErrors`";
7745 r = do_query(hdb, query, &hrec);
7746 ok(r == ERROR_BAD_QUERY_SYNTAX,
7747 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7749 query = "DROP TABLE `One`";
7750 r = run_query(hdb, 0, query);
7751 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7753 query = "DROP TABLE `One`";
7754 r = run_query(href, 0, query);
7755 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7757 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7758 r = run_query(hdb, 0, query);
7759 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7761 query = "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
7762 r = run_query(href, 0, query);
7763 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7765 query = "INSERT INTO `One` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
7766 r = run_query(href, 0, query);
7767 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7769 /* number of columns doesn't match */
7770 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7771 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7773 query = "SELECT * FROM `One`";
7774 r = do_query(hdb, query, &hrec);
7775 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7777 r = MsiRecordGetInteger(hrec, 1);
7778 ok(r == 1, "Expected 1, got %d\n", r);
7780 r = MsiRecordGetInteger(hrec, 2);
7781 ok(r == 2, "Expected 2, got %d\n", r);
7783 r = MsiRecordGetInteger(hrec, 3);
7784 ok(r == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", r);
7786 MsiCloseHandle(hrec);
7788 /* nothing in MergeErrors */
7789 query = "SELECT * FROM `MergeErrors`";
7790 r = do_query(hdb, query, &hrec);
7791 ok(r == ERROR_BAD_QUERY_SYNTAX,
7792 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7794 query = "DROP TABLE `One`";
7795 r = run_query(hdb, 0, query);
7796 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7798 query = "DROP TABLE `One`";
7799 r = run_query(href, 0, query);
7800 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7802 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7803 r = run_query(hdb, 0, query);
7804 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7806 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 1 )";
7807 r = run_query(hdb, 0, query);
7808 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7810 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 2 )";
7811 r = run_query(hdb, 0, query);
7812 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7814 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7815 r = run_query(href, 0, query);
7816 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7818 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
7819 r = run_query(href, 0, query);
7820 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7822 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 3 )";
7823 r = run_query(href, 0, query);
7824 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7826 /* primary keys match, rows do not */
7827 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7828 ok(r == ERROR_FUNCTION_FAILED,
7829 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
7831 /* nothing in MergeErrors */
7832 query = "SELECT * FROM `MergeErrors`";
7833 r = do_query(hdb, query, &hrec);
7834 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7837 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7838 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7839 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7841 r = MsiRecordGetInteger(hrec, 2);
7842 ok(r == 2, "Expected 2, got %d\n", r);
7844 MsiCloseHandle(hrec);
7846 r = MsiDatabaseOpenViewA(hdb, "SELECT * FROM `MergeErrors`", &hview);
7847 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7849 r = MsiViewGetColumnInfo(hview, MSICOLINFO_NAMES, &hrec);
7850 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7853 r = MsiRecordGetString(hrec, 1, buf, &size);
7854 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
7857 r = MsiRecordGetString(hrec, 2, buf, &size);
7858 ok(!lstrcmpA(buf, "NumRowMergeConflicts"),
7859 "Expected \"NumRowMergeConflicts\", got \"%s\"\n", buf);
7861 MsiCloseHandle(hrec);
7863 r = MsiViewGetColumnInfo(hview, MSICOLINFO_TYPES, &hrec);
7864 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7867 r = MsiRecordGetString(hrec, 1, buf, &size);
7868 ok(!lstrcmpA(buf, "s255"), "Expected \"s255\", got \"%s\"\n", buf);
7871 r = MsiRecordGetString(hrec, 2, buf, &size);
7872 ok(!lstrcmpA(buf, "i2"), "Expected \"i2\", got \"%s\"\n", buf);
7874 MsiCloseHandle(hrec);
7875 MsiViewClose(hview);
7876 MsiCloseHandle(hview);
7878 query = "DROP TABLE `MergeErrors`";
7879 r = run_query(hdb, 0, query);
7880 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7882 query = "DROP TABLE `One`";
7883 r = run_query(hdb, 0, query);
7884 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7886 query = "DROP TABLE `One`";
7887 r = run_query(href, 0, query);
7888 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7890 query = "CREATE TABLE `One` ( `A` INT, `B` CHAR(72) PRIMARY KEY `A` )";
7891 r = run_query(href, 0, query);
7892 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7894 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
7895 r = run_query(href, 0, query);
7896 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7898 /* table from merged database is not in target database */
7899 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7900 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7902 query = "SELECT * FROM `One`";
7903 r = do_query(hdb, query, &hrec);
7904 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7906 r = MsiRecordGetInteger(hrec, 1);
7907 ok(r == 1, "Expected 1, got %d\n", r);
7910 r = MsiRecordGetStringA(hrec, 2, buf, &size);
7911 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7912 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
7914 MsiCloseHandle(hrec);
7916 /* nothing in MergeErrors */
7917 query = "SELECT * FROM `MergeErrors`";
7918 r = do_query(hdb, query, &hrec);
7919 ok(r == ERROR_BAD_QUERY_SYNTAX,
7920 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7922 query = "DROP TABLE `One`";
7923 r = run_query(hdb, 0, query);
7924 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7926 query = "DROP TABLE `One`";
7927 r = run_query(href, 0, query);
7928 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7930 query = "CREATE TABLE `One` ( "
7931 "`A` CHAR(72), `B` INT PRIMARY KEY `A` )";
7932 r = run_query(hdb, 0, query);
7933 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7935 query = "CREATE TABLE `One` ( "
7936 "`A` CHAR(72), `B` INT PRIMARY KEY `A` )";
7937 r = run_query(href, 0, query);
7938 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7940 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 'hi', 1 )";
7941 r = run_query(href, 0, query);
7942 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7944 /* primary key is string */
7945 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7946 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7948 query = "SELECT * FROM `One`";
7949 r = do_query(hdb, query, &hrec);
7950 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7953 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7954 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7955 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
7957 r = MsiRecordGetInteger(hrec, 2);
7958 ok(r == 1, "Expected 1, got %d\n", r);
7960 MsiCloseHandle(hrec);
7962 /* nothing in MergeErrors */
7963 query = "SELECT * FROM `MergeErrors`";
7964 r = do_query(hdb, query, &hrec);
7965 ok(r == ERROR_BAD_QUERY_SYNTAX,
7966 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7968 create_file_data("codepage.idt", "\r\n\r\n850\t_ForceCodepage\r\n", 0);
7970 GetCurrentDirectoryA(MAX_PATH, buf);
7971 r = MsiDatabaseImportA(hdb, buf, "codepage.idt");
7974 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7977 query = "DROP TABLE `One`";
7978 r = run_query(hdb, 0, query);
7979 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7981 query = "DROP TABLE `One`";
7982 r = run_query(href, 0, query);
7983 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7985 query = "CREATE TABLE `One` ( "
7986 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
7987 r = run_query(hdb, 0, query);
7988 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7990 query = "CREATE TABLE `One` ( "
7991 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
7992 r = run_query(href, 0, query);
7993 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7995 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
7996 r = run_query(href, 0, query);
7997 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7999 /* code page does not match */
8000 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8001 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8003 query = "SELECT * FROM `One`";
8004 r = do_query(hdb, query, &hrec);
8005 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8007 r = MsiRecordGetInteger(hrec, 1);
8008 ok(r == 1, "Expected 1, got %d\n", r);
8011 r = MsiRecordGetStringA(hrec, 2, buf, &size);
8012 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8013 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
8015 MsiCloseHandle(hrec);
8017 /* nothing in MergeErrors */
8018 query = "SELECT * FROM `MergeErrors`";
8019 r = do_query(hdb, query, &hrec);
8020 ok(r == ERROR_BAD_QUERY_SYNTAX,
8021 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8023 query = "DROP TABLE `One`";
8024 r = run_query(hdb, 0, query);
8025 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8027 query = "DROP TABLE `One`";
8028 r = run_query(href, 0, query);
8029 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8031 query = "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
8032 r = run_query(hdb, 0, query);
8033 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8035 query = "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
8036 r = run_query(href, 0, query);
8037 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8039 create_file("binary.dat");
8040 hrec = MsiCreateRecord(1);
8041 MsiRecordSetStreamA(hrec, 1, "binary.dat");
8043 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, ? )";
8044 r = run_query(href, hrec, query);
8045 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8047 MsiCloseHandle(hrec);
8049 /* binary data to merge */
8050 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8051 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8053 query = "SELECT * FROM `One`";
8054 r = do_query(hdb, query, &hrec);
8055 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8057 r = MsiRecordGetInteger(hrec, 1);
8058 ok(r == 1, "Expected 1, got %d\n", r);
8061 ZeroMemory(buf, MAX_PATH);
8062 r = MsiRecordReadStream(hrec, 2, buf, &size);
8063 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8064 ok(!lstrcmpA(buf, "binary.dat\n"),
8065 "Expected \"binary.dat\\n\", got \"%s\"\n", buf);
8067 MsiCloseHandle(hrec);
8069 /* nothing in MergeErrors */
8070 query = "SELECT * FROM `MergeErrors`";
8071 r = do_query(hdb, query, &hrec);
8072 ok(r == ERROR_BAD_QUERY_SYNTAX,
8073 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8075 query = "DROP TABLE `One`";
8076 r = run_query(hdb, 0, query);
8077 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8079 query = "DROP TABLE `One`";
8080 r = run_query(href, 0, query);
8081 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8083 query = "CREATE TABLE `One` ( `A` INT, `B` CHAR(72) PRIMARY KEY `A` )";
8084 r = run_query(hdb, 0, query);
8085 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8086 r = run_query(href, 0, query);
8087 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8089 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'foo' )";
8090 r = run_query(href, 0, query);
8091 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8093 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 'bar' )";
8094 r = run_query(href, 0, query);
8095 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8097 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8098 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8100 query = "SELECT * FROM `One`";
8101 r = MsiDatabaseOpenViewA(hdb, query, &hview);
8102 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8103 r = MsiViewExecute(hview, 0);
8104 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8106 r = MsiViewFetch(hview, &hrec);
8107 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8109 r = MsiRecordGetInteger(hrec, 1);
8110 ok(r == 1, "Expected 1, got %d\n", r);
8113 r = MsiRecordGetStringA(hrec, 2, buf, &size);
8114 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8115 ok(!lstrcmpA(buf, "foo"), "Expected \"foo\", got \"%s\"\n", buf);
8117 MsiCloseHandle(hrec);
8119 r = MsiViewFetch(hview, &hrec);
8120 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8122 r = MsiRecordGetInteger(hrec, 1);
8123 ok(r == 2, "Expected 2, got %d\n", r);
8126 r = MsiRecordGetStringA(hrec, 2, buf, &size);
8127 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8128 ok(!lstrcmpA(buf, "bar"), "Expected \"bar\", got \"%s\"\n", buf);
8130 MsiCloseHandle(hrec);
8132 r = MsiViewFetch(hview, &hrec);
8133 ok(r == ERROR_NO_MORE_ITEMS,
8134 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8136 MsiViewClose(hview);
8137 MsiCloseHandle(hview);
8139 MsiCloseHandle(hdb);
8140 MsiCloseHandle(href);
8141 DeleteFileA(msifile);
8142 DeleteFileA("refdb.msi");
8143 DeleteFileA("codepage.idt");
8144 DeleteFileA("binary.dat");
8147 static void test_select_with_tablenames(void)
8149 MSIHANDLE hdb, view, rec;
8161 ok(hdb, "failed to create db\n");
8163 /* Build a pair of tables with the same column names, but unique data */
8164 query = "CREATE TABLE `T1` ( `A` SHORT, `B` SHORT PRIMARY KEY `A`)";
8165 r = run_query(hdb, 0, query);
8166 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8168 query = "INSERT INTO `T1` ( `A`, `B` ) VALUES ( 1, 2 )";
8169 r = run_query(hdb, 0, query);
8170 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8172 query = "INSERT INTO `T1` ( `A`, `B` ) VALUES ( 4, 5 )";
8173 r = run_query(hdb, 0, query);
8174 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8176 query = "CREATE TABLE `T2` ( `A` SHORT, `B` SHORT PRIMARY KEY `A`)";
8177 r = run_query(hdb, 0, query);
8178 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8180 query = "INSERT INTO `T2` ( `A`, `B` ) VALUES ( 11, 12 )";
8181 r = run_query(hdb, 0, query);
8182 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8184 query = "INSERT INTO `T2` ( `A`, `B` ) VALUES ( 14, 15 )";
8185 r = run_query(hdb, 0, query);
8186 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8189 /* Test that selection based on prefixing the column with the table
8190 * actually selects the right data */
8192 query = "SELECT T1.A, T2.B FROM T1,T2";
8193 r = MsiDatabaseOpenView(hdb, query, &view);
8194 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8195 r = MsiViewExecute(view, 0);
8196 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8198 for (i = 0; i < 4; i++)
8200 r = MsiViewFetch(view, &rec);
8201 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8203 r = MsiRecordGetInteger(rec, 1);
8204 ok(r == vals[i][0], "Expected %d, got %d\n", vals[i][0], r);
8206 r = MsiRecordGetInteger(rec, 2);
8207 ok(r == vals[i][1], "Expected %d, got %d\n", vals[i][1], r);
8209 MsiCloseHandle(rec);
8212 r = MsiViewFetch(view, &rec);
8213 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8216 MsiCloseHandle(view);
8217 MsiCloseHandle(hdb);
8218 DeleteFileA(msifile);
8221 UINT ordervals[6][3] =
8223 { MSI_NULL_INTEGER, 12, 13 },
8227 { 10, 11, MSI_NULL_INTEGER },
8228 { 14, MSI_NULL_INTEGER, 15 }
8231 static void test_insertorder(void)
8233 MSIHANDLE hdb, view, rec;
8239 ok(hdb, "failed to create db\n");
8241 query = "CREATE TABLE `T` ( `A` SHORT, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
8242 r = run_query(hdb, 0, query);
8243 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8245 query = "INSERT INTO `T` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
8246 r = run_query(hdb, 0, query);
8247 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8249 query = "INSERT INTO `T` ( `B`, `C`, `A` ) VALUES ( 4, 5, 6 )";
8250 r = run_query(hdb, 0, query);
8251 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8253 query = "INSERT INTO `T` ( `C`, `A`, `B` ) VALUES ( 7, 8, 9 )";
8254 r = run_query(hdb, 0, query);
8255 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8257 query = "INSERT INTO `T` ( `A`, `B` ) VALUES ( 10, 11 )";
8258 r = run_query(hdb, 0, query);
8259 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8261 query = "INSERT INTO `T` ( `B`, `C` ) VALUES ( 12, 13 )";
8262 r = run_query(hdb, 0, query);
8263 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8265 /* fails because the primary key already
8266 * has an MSI_NULL_INTEGER value set above
8268 query = "INSERT INTO `T` ( `C` ) VALUES ( 14 )";
8269 r = run_query(hdb, 0, query);
8270 ok(r == ERROR_FUNCTION_FAILED,
8271 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
8273 /* replicate the error where primary key is set twice */
8274 query = "INSERT INTO `T` ( `A`, `C` ) VALUES ( 1, 14 )";
8275 r = run_query(hdb, 0, query);
8276 ok(r == ERROR_FUNCTION_FAILED,
8277 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
8279 query = "INSERT INTO `T` ( `A`, `C` ) VALUES ( 14, 15 )";
8280 r = run_query(hdb, 0, query);
8281 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8283 query = "INSERT INTO `T` VALUES ( 16 )";
8284 r = run_query(hdb, 0, query);
8285 ok(r == ERROR_BAD_QUERY_SYNTAX,
8286 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8288 query = "INSERT INTO `T` VALUES ( 17, 18 )";
8289 r = run_query(hdb, 0, query);
8290 ok(r == ERROR_BAD_QUERY_SYNTAX,
8291 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8293 query = "INSERT INTO `T` VALUES ( 19, 20, 21 )";
8294 r = run_query(hdb, 0, query);
8295 ok(r == ERROR_BAD_QUERY_SYNTAX,
8296 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8298 query = "SELECT * FROM `T`";
8299 r = MsiDatabaseOpenView(hdb, query, &view);
8300 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8301 r = MsiViewExecute(view, 0);
8302 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8304 for (i = 0; i < 6; i++)
8306 r = MsiViewFetch(view, &rec);
8307 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8309 r = MsiRecordGetInteger(rec, 1);
8310 ok(r == ordervals[i][0], "Expected %d, got %d\n", ordervals[i][0], r);
8312 r = MsiRecordGetInteger(rec, 2);
8313 ok(r == ordervals[i][1], "Expected %d, got %d\n", ordervals[i][1], r);
8315 r = MsiRecordGetInteger(rec, 3);
8316 ok(r == ordervals[i][2], "Expected %d, got %d\n", ordervals[i][2], r);
8318 MsiCloseHandle(rec);
8321 r = MsiViewFetch(view, &rec);
8322 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8325 MsiCloseHandle(view);
8327 query = "DELETE FROM `T` WHERE `A` IS NULL";
8328 r = run_query(hdb, 0, query);
8329 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8331 query = "INSERT INTO `T` ( `B`, `C` ) VALUES ( 12, 13 ) TEMPORARY";
8332 r = run_query(hdb, 0, query);
8333 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8335 query = "SELECT * FROM `T`";
8336 r = MsiDatabaseOpenView(hdb, query, &view);
8337 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8338 r = MsiViewExecute(view, 0);
8339 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8341 for (i = 0; i < 6; i++)
8343 r = MsiViewFetch(view, &rec);
8344 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8346 r = MsiRecordGetInteger(rec, 1);
8347 ok(r == ordervals[i][0], "Expected %d, got %d\n", ordervals[i][0], r);
8349 r = MsiRecordGetInteger(rec, 2);
8350 ok(r == ordervals[i][1], "Expected %d, got %d\n", ordervals[i][1], r);
8352 r = MsiRecordGetInteger(rec, 3);
8353 ok(r == ordervals[i][2], "Expected %d, got %d\n", ordervals[i][2], r);
8355 MsiCloseHandle(rec);
8358 r = MsiViewFetch(view, &rec);
8359 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8362 MsiCloseHandle(view);
8363 MsiCloseHandle(hdb);
8364 DeleteFileA(msifile);
8367 static void test_columnorder(void)
8369 MSIHANDLE hdb, view, rec;
8376 ok(hdb, "failed to create db\n");
8378 /* Each column is a slot:
8379 * ---------------------
8380 * | B | C | A | E | D |
8381 * ---------------------
8383 * When a column is selected as a primary key,
8384 * the column occupying the nth primary key slot is swapped
8385 * with the current position of the primary key in question:
8387 * set primary key `D`
8388 * --------------------- ---------------------
8389 * | B | C | A | E | D | -> | D | C | A | E | B |
8390 * --------------------- ---------------------
8392 * set primary key `E`
8393 * --------------------- ---------------------
8394 * | D | C | A | E | B | -> | D | E | A | C | B |
8395 * --------------------- ---------------------
8398 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL, `C` SHORT NOT NULL, "
8399 "`A` CHAR(255), `E` INT, `D` CHAR(255) NOT NULL "
8400 "PRIMARY KEY `D`, `E`)";
8401 r = run_query(hdb, 0, query);
8402 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8404 query = "SELECT * FROM `T`";
8405 r = MsiDatabaseOpenView(hdb, query, &view);
8406 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8408 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
8409 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8412 lstrcpyA(buf, "kiwi");
8413 r = MsiRecordGetString(rec, 1, buf, &sz);
8414 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8415 ok(!lstrcmpA("s255", buf), "Expected \"s255\", got \"%s\"\n", buf);
8418 lstrcpyA(buf, "kiwi");
8419 r = MsiRecordGetString(rec, 2, buf, &sz);
8420 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8421 ok(!lstrcmpA("I2", buf), "Expected \"I2\", got \"%s\"\n", buf);
8424 lstrcpyA(buf, "kiwi");
8425 r = MsiRecordGetString(rec, 3, buf, &sz);
8426 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8427 ok(!lstrcmpA("S255", buf), "Expected \"S255\", got \"%s\"\n", buf);
8430 lstrcpyA(buf, "kiwi");
8431 r = MsiRecordGetString(rec, 4, buf, &sz);
8432 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8433 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8436 lstrcpyA(buf, "kiwi");
8437 r = MsiRecordGetString(rec, 5, buf, &sz);
8438 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8439 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8441 MsiCloseHandle(rec);
8443 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
8444 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8447 lstrcpyA(buf, "kiwi");
8448 r = MsiRecordGetString(rec, 1, buf, &sz);
8449 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8450 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8453 lstrcpyA(buf, "kiwi");
8454 r = MsiRecordGetString(rec, 2, buf, &sz);
8455 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8456 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8459 lstrcpyA(buf, "kiwi");
8460 r = MsiRecordGetString(rec, 3, buf, &sz);
8461 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8462 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8465 lstrcpyA(buf, "kiwi");
8466 r = MsiRecordGetString(rec, 4, buf, &sz);
8467 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8468 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8471 lstrcpyA(buf, "kiwi");
8472 r = MsiRecordGetString(rec, 5, buf, &sz);
8473 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8474 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8476 MsiCloseHandle(rec);
8478 MsiCloseHandle(view);
8480 query = "INSERT INTO `T` ( `B`, `C`, `A`, `E`, `D` ) "
8481 "VALUES ( 1, 2, 'a', 3, 'bc' )";
8482 r = run_query(hdb, 0, query);
8483 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8485 query = "SELECT * FROM `T`";
8486 r = do_query(hdb, query, &rec);
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("bc", buf), "Expected \"bc\", got \"%s\"\n", buf);
8494 r = MsiRecordGetInteger(rec, 2);
8495 ok(r == 3, "Expected 3, 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("a", buf), "Expected \"a\", got \"%s\"\n", buf);
8503 r = MsiRecordGetInteger(rec, 4);
8504 ok(r == 2, "Expected 2, got %d\n", r);
8506 r = MsiRecordGetInteger(rec, 5);
8507 ok(r == 1, "Expected 1, got %d\n", r);
8509 MsiCloseHandle(rec);
8511 query = "SELECT * FROM `_Columns` WHERE `Table` = 'T'";
8512 r = MsiDatabaseOpenView(hdb, query, &view);
8513 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8514 r = MsiViewExecute(view, 0);
8515 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8517 r = MsiViewFetch(view, &rec);
8518 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8521 lstrcpyA(buf, "kiwi");
8522 r = MsiRecordGetString(rec, 1, buf, &sz);
8523 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8524 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8526 r = MsiRecordGetInteger(rec, 2);
8527 ok(r == 1, "Expected 1, got %d\n", r);
8530 lstrcpyA(buf, "kiwi");
8531 r = MsiRecordGetString(rec, 3, buf, &sz);
8532 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8533 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8535 MsiCloseHandle(rec);
8537 r = MsiViewFetch(view, &rec);
8538 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8541 lstrcpyA(buf, "kiwi");
8542 r = MsiRecordGetString(rec, 1, buf, &sz);
8543 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8544 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8546 r = MsiRecordGetInteger(rec, 2);
8547 ok(r == 2, "Expected 2, got %d\n", r);
8550 lstrcpyA(buf, "kiwi");
8551 r = MsiRecordGetString(rec, 3, buf, &sz);
8552 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8553 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8555 MsiCloseHandle(rec);
8557 r = MsiViewFetch(view, &rec);
8558 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8561 lstrcpyA(buf, "kiwi");
8562 r = MsiRecordGetString(rec, 1, buf, &sz);
8563 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8564 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8566 r = MsiRecordGetInteger(rec, 2);
8567 ok(r == 3, "Expected 3, got %d\n", r);
8570 lstrcpyA(buf, "kiwi");
8571 r = MsiRecordGetString(rec, 3, buf, &sz);
8572 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8573 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8575 MsiCloseHandle(rec);
8577 r = MsiViewFetch(view, &rec);
8578 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8581 lstrcpyA(buf, "kiwi");
8582 r = MsiRecordGetString(rec, 1, buf, &sz);
8583 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8584 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8586 r = MsiRecordGetInteger(rec, 2);
8587 ok(r == 4, "Expected 4, got %d\n", r);
8590 lstrcpyA(buf, "kiwi");
8591 r = MsiRecordGetString(rec, 3, buf, &sz);
8592 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8593 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8595 MsiCloseHandle(rec);
8597 r = MsiViewFetch(view, &rec);
8598 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8601 lstrcpyA(buf, "kiwi");
8602 r = MsiRecordGetString(rec, 1, buf, &sz);
8603 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8604 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8606 r = MsiRecordGetInteger(rec, 2);
8607 ok(r == 5, "Expected 5, got %d\n", r);
8610 lstrcpyA(buf, "kiwi");
8611 r = MsiRecordGetString(rec, 3, buf, &sz);
8612 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8613 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8615 MsiCloseHandle(rec);
8617 r = MsiViewFetch(view, &rec);
8618 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8621 MsiCloseHandle(view);
8623 query = "CREATE TABLE `Z` ( `B` SHORT NOT NULL, `C` SHORT NOT NULL, "
8624 "`A` CHAR(255), `E` INT, `D` CHAR(255) NOT NULL "
8625 "PRIMARY KEY `C`, `A`, `D`)";
8626 r = run_query(hdb, 0, query);
8627 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8629 query = "SELECT * FROM `Z`";
8630 r = MsiDatabaseOpenView(hdb, query, &view);
8631 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8633 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
8634 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8637 lstrcpyA(buf, "kiwi");
8638 r = MsiRecordGetString(rec, 1, buf, &sz);
8639 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8640 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8643 lstrcpyA(buf, "kiwi");
8644 r = MsiRecordGetString(rec, 2, buf, &sz);
8645 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8646 ok(!lstrcmpA("S255", buf), "Expected \"S255\", got \"%s\"\n", buf);
8649 lstrcpyA(buf, "kiwi");
8650 r = MsiRecordGetString(rec, 3, buf, &sz);
8651 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8652 ok(!lstrcmpA("s255", buf), "Expected \"s255\", got \"%s\"\n", buf);
8655 lstrcpyA(buf, "kiwi");
8656 r = MsiRecordGetString(rec, 4, buf, &sz);
8657 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8658 ok(!lstrcmpA("I2", buf), "Expected \"I2\", got \"%s\"\n", buf);
8661 lstrcpyA(buf, "kiwi");
8662 r = MsiRecordGetString(rec, 5, buf, &sz);
8663 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8664 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8666 MsiCloseHandle(rec);
8668 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
8669 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8672 lstrcpyA(buf, "kiwi");
8673 r = MsiRecordGetString(rec, 1, buf, &sz);
8674 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8675 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8678 lstrcpyA(buf, "kiwi");
8679 r = MsiRecordGetString(rec, 2, buf, &sz);
8680 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8681 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8684 lstrcpyA(buf, "kiwi");
8685 r = MsiRecordGetString(rec, 3, buf, &sz);
8686 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8687 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8690 lstrcpyA(buf, "kiwi");
8691 r = MsiRecordGetString(rec, 4, buf, &sz);
8692 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8693 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8696 lstrcpyA(buf, "kiwi");
8697 r = MsiRecordGetString(rec, 5, buf, &sz);
8698 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8699 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8701 MsiCloseHandle(rec);
8703 MsiCloseHandle(view);
8705 query = "INSERT INTO `Z` ( `B`, `C`, `A`, `E`, `D` ) "
8706 "VALUES ( 1, 2, 'a', 3, 'bc' )";
8707 r = run_query(hdb, 0, query);
8708 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8710 query = "SELECT * FROM `Z`";
8711 r = do_query(hdb, query, &rec);
8713 r = MsiRecordGetInteger(rec, 1);
8714 ok(r == 2, "Expected 2, got %d\n", r);
8717 lstrcpyA(buf, "kiwi");
8718 r = MsiRecordGetString(rec, 2, buf, &sz);
8719 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8720 ok(!lstrcmpA("a", buf), "Expected \"a\", got \"%s\"\n", buf);
8723 lstrcpyA(buf, "kiwi");
8724 r = MsiRecordGetString(rec, 3, buf, &sz);
8725 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8726 ok(!lstrcmpA("bc", buf), "Expected \"bc\", got \"%s\"\n", buf);
8728 r = MsiRecordGetInteger(rec, 4);
8729 ok(r == 3, "Expected 3, got %d\n", r);
8731 r = MsiRecordGetInteger(rec, 5);
8732 ok(r == 1, "Expected 1, got %d\n", r);
8734 MsiCloseHandle(rec);
8736 query = "SELECT * FROM `_Columns` WHERE `Table` = 'T'";
8737 r = MsiDatabaseOpenView(hdb, query, &view);
8738 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8739 r = MsiViewExecute(view, 0);
8740 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8742 r = MsiViewFetch(view, &rec);
8743 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8746 lstrcpyA(buf, "kiwi");
8747 r = MsiRecordGetString(rec, 1, buf, &sz);
8748 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8749 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8751 r = MsiRecordGetInteger(rec, 2);
8752 ok(r == 1, "Expected 1, got %d\n", r);
8755 lstrcpyA(buf, "kiwi");
8756 r = MsiRecordGetString(rec, 3, buf, &sz);
8757 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8758 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8760 MsiCloseHandle(rec);
8762 r = MsiViewFetch(view, &rec);
8763 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8766 lstrcpyA(buf, "kiwi");
8767 r = MsiRecordGetString(rec, 1, buf, &sz);
8768 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8769 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8771 r = MsiRecordGetInteger(rec, 2);
8772 ok(r == 2, "Expected 2, got %d\n", r);
8775 lstrcpyA(buf, "kiwi");
8776 r = MsiRecordGetString(rec, 3, buf, &sz);
8777 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8778 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8780 MsiCloseHandle(rec);
8782 r = MsiViewFetch(view, &rec);
8783 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8786 lstrcpyA(buf, "kiwi");
8787 r = MsiRecordGetString(rec, 1, buf, &sz);
8788 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8789 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8791 r = MsiRecordGetInteger(rec, 2);
8792 ok(r == 3, "Expected 3, got %d\n", r);
8795 lstrcpyA(buf, "kiwi");
8796 r = MsiRecordGetString(rec, 3, buf, &sz);
8797 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8798 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8800 MsiCloseHandle(rec);
8802 r = MsiViewFetch(view, &rec);
8803 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8806 lstrcpyA(buf, "kiwi");
8807 r = MsiRecordGetString(rec, 1, buf, &sz);
8808 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8809 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8811 r = MsiRecordGetInteger(rec, 2);
8812 ok(r == 4, "Expected 4, got %d\n", r);
8815 lstrcpyA(buf, "kiwi");
8816 r = MsiRecordGetString(rec, 3, buf, &sz);
8817 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8818 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8820 MsiCloseHandle(rec);
8822 r = MsiViewFetch(view, &rec);
8823 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8826 lstrcpyA(buf, "kiwi");
8827 r = MsiRecordGetString(rec, 1, buf, &sz);
8828 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8829 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8831 r = MsiRecordGetInteger(rec, 2);
8832 ok(r == 5, "Expected 5, got %d\n", r);
8835 lstrcpyA(buf, "kiwi");
8836 r = MsiRecordGetString(rec, 3, buf, &sz);
8837 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8838 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8840 MsiCloseHandle(rec);
8842 r = MsiViewFetch(view, &rec);
8843 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8846 MsiCloseHandle(view);
8848 MsiCloseHandle(hdb);
8849 DeleteFileA(msifile);
8852 static void test_createtable(void)
8854 MSIHANDLE hdb, htab = 0, hrec = 0;
8861 ok(hdb, "failed to create db\n");
8863 query = "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL PRIMARY KEY `foo`)";
8864 res = MsiDatabaseOpenView( hdb, query, &htab );
8865 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8866 if(res == ERROR_SUCCESS )
8868 res = MsiViewExecute( htab, hrec );
8869 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8871 res = MsiViewGetColumnInfo( htab, MSICOLINFO_NAMES, &hrec );
8872 todo_wine ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8874 size = sizeof(buffer);
8875 res = MsiRecordGetString(hrec, 1, buffer, &size );
8876 todo_wine ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8878 res = MsiViewClose( htab );
8879 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8881 res = MsiCloseHandle( htab );
8882 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8885 query = "CREATE TABLE `a` (`b` INT PRIMARY KEY `b`)";
8886 res = MsiDatabaseOpenView( hdb, query, &htab );
8887 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8888 if(res == ERROR_SUCCESS )
8890 res = MsiViewExecute( htab, 0 );
8891 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8893 res = MsiViewClose( htab );
8894 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8896 res = MsiCloseHandle( htab );
8897 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8899 query = "SELECT * FROM `a`";
8900 res = MsiDatabaseOpenView( hdb, query, &htab );
8901 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8903 res = MsiViewGetColumnInfo( htab, MSICOLINFO_NAMES, &hrec );
8904 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8906 size = sizeof(buffer);
8907 res = MsiRecordGetString(hrec, 1, buffer, &size );
8908 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8909 ok(!strcmp(buffer,"b"), "b != %s\n", buffer);
8911 res = MsiViewClose( htab );
8912 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8914 res = MsiCloseHandle( htab );
8915 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8917 res = MsiDatabaseCommit(hdb);
8918 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8920 res = MsiCloseHandle(hdb);
8921 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8923 res = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
8924 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8926 query = "SELECT * FROM `a`";
8927 res = MsiDatabaseOpenView( hdb, query, &htab );
8928 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8930 res = MsiViewGetColumnInfo( htab, MSICOLINFO_NAMES, &hrec );
8931 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8933 size = sizeof(buffer);
8934 res = MsiRecordGetString(hrec, 1, buffer, &size );
8935 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8936 todo_wine ok(!strcmp(buffer,"b"), "b != %s\n", buffer);
8938 res = MsiCloseHandle( hrec );
8939 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8941 res = MsiViewClose( htab );
8942 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8944 res = MsiCloseHandle( htab );
8945 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8948 res = MsiDatabaseCommit(hdb);
8949 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8951 res = MsiCloseHandle(hdb);
8952 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8954 DeleteFileA(msifile);
8962 test_msidecomposedesc();
8963 test_msibadqueries();
8965 test_viewgetcolumninfo();
8971 test_where_not_in_selected();
8974 test_binary_import();
8976 test_handle_limit();
8977 test_try_transform();
8979 test_temporary_table();
8983 test_special_tables();
8984 test_tables_order();
8986 test_select_markers();
8987 test_viewmodify_update();
8988 test_viewmodify_assign();
8990 test_viewmodify_delete();
8991 test_defaultdatabase();
8993 test_viewmodify_delete_temporary();
8996 test_carriagereturn();
8998 test_forcecodepage();
8999 test_viewmodify_refresh();
9000 test_where_viewmodify();
9001 test_storages_table();
9005 test_select_with_tablenames();
9008 test_suminfo_import();