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
26 #include "wine/test.h"
28 static const char *msifile = "winetest.msi";
29 static const char *msifile2 = "winetst2.msi";
30 static const char *mstfile = "winetst.mst";
32 #ifndef ERROR_INSTALL_TRANSFORM_FAILURE
33 #define ERROR_INSTALL_TRANSFORM_FAILURE 1624
36 static void test_msidatabase(void)
38 MSIHANDLE hdb = 0, hdb2 = 0;
43 res = MsiOpenDatabase( msifile, msifile2, &hdb );
44 ok( res == ERROR_OPEN_FAILED, "expected failure\n");
46 res = MsiOpenDatabase( msifile, (LPSTR) 0xff, &hdb );
47 ok( res == ERROR_INVALID_PARAMETER, "expected failure\n");
49 res = MsiCloseHandle( hdb );
50 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
52 /* create an empty database */
53 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
54 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
56 res = MsiDatabaseCommit( hdb );
57 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
59 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
61 res = MsiCloseHandle( hdb );
62 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
63 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
64 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
66 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile2 ), "database should exist\n");
68 res = MsiDatabaseCommit( hdb2 );
69 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
71 res = MsiCloseHandle( hdb2 );
72 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
74 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
75 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
77 res = MsiCloseHandle( hdb2 );
78 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
80 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile2 ), "uncommitted database should not exist\n");
82 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
83 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
85 res = MsiDatabaseCommit( hdb2 );
86 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
88 res = MsiCloseHandle( hdb2 );
89 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
91 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile2 ), "committed database should exist\n");
93 res = MsiOpenDatabase( msifile, MSIDBOPEN_READONLY, &hdb );
94 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
96 res = MsiCloseHandle( hdb );
97 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
99 res = MsiOpenDatabase( msifile, MSIDBOPEN_DIRECT, &hdb );
100 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
102 res = MsiCloseHandle( hdb );
103 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
105 res = MsiOpenDatabase( msifile, MSIDBOPEN_TRANSACT, &hdb );
106 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
108 res = MsiCloseHandle( hdb );
109 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
110 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
112 /* MSIDBOPEN_CREATE deletes the database if MsiCommitDatabase isn't called */
113 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
114 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
116 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
118 res = MsiCloseHandle( hdb );
119 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
121 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile ), "database should exist\n");
123 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
124 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
126 res = MsiDatabaseCommit( hdb );
127 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
129 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
131 res = MsiCloseHandle( hdb );
132 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
134 res = DeleteFile( msifile2 );
135 ok( res == TRUE, "Failed to delete database\n" );
137 res = DeleteFile( msifile );
138 ok( res == TRUE, "Failed to delete database\n" );
141 static UINT do_query(MSIHANDLE hdb, const char *query, MSIHANDLE *phrec)
146 /* open a select query */
147 r = MsiDatabaseOpenView(hdb, query, &hview);
148 if (r != ERROR_SUCCESS)
150 r = MsiViewExecute(hview, 0);
151 if (r != ERROR_SUCCESS)
153 ret = MsiViewFetch(hview, phrec);
154 r = MsiViewClose(hview);
155 if (r != ERROR_SUCCESS)
157 r = MsiCloseHandle(hview);
158 if (r != ERROR_SUCCESS)
163 static UINT run_query( MSIHANDLE hdb, MSIHANDLE hrec, const char *query )
168 r = MsiDatabaseOpenView(hdb, query, &hview);
169 if( r != ERROR_SUCCESS )
172 r = MsiViewExecute(hview, hrec);
173 if( r == ERROR_SUCCESS )
174 r = MsiViewClose(hview);
175 MsiCloseHandle(hview);
179 static UINT create_component_table( MSIHANDLE hdb )
181 return run_query( hdb, 0,
182 "CREATE TABLE `Component` ( "
183 "`Component` CHAR(72) NOT NULL, "
184 "`ComponentId` CHAR(38), "
185 "`Directory_` CHAR(72) NOT NULL, "
186 "`Attributes` SHORT NOT NULL, "
187 "`Condition` CHAR(255), "
188 "`KeyPath` CHAR(72) "
189 "PRIMARY KEY `Component`)" );
192 static UINT create_feature_components_table( MSIHANDLE hdb )
194 return run_query( hdb, 0,
195 "CREATE TABLE `FeatureComponents` ( "
196 "`Feature_` CHAR(38) NOT NULL, "
197 "`Component_` CHAR(72) NOT NULL "
198 "PRIMARY KEY `Feature_`, `Component_` )" );
201 static UINT create_std_dlls_table( MSIHANDLE hdb )
203 return run_query( hdb, 0,
204 "CREATE TABLE `StdDlls` ( "
205 "`File` CHAR(255) NOT NULL, "
206 "`Binary_` CHAR(72) NOT NULL "
207 "PRIMARY KEY `File` )" );
210 static UINT create_binary_table( MSIHANDLE hdb )
212 return run_query( hdb, 0,
213 "CREATE TABLE `Binary` ( "
214 "`Name` CHAR(72) NOT NULL, "
215 "`Data` CHAR(72) NOT NULL "
216 "PRIMARY KEY `Name` )" );
219 static UINT add_component_entry( MSIHANDLE hdb, const char *values )
221 char insert[] = "INSERT INTO `Component` "
222 "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `Condition`, `KeyPath`) "
227 sz = strlen(values) + sizeof insert;
228 query = HeapAlloc(GetProcessHeap(),0,sz);
229 sprintf(query,insert,values);
230 r = run_query( hdb, 0, query );
231 HeapFree(GetProcessHeap(), 0, query);
235 static UINT add_feature_components_entry( MSIHANDLE hdb, const char *values )
237 char insert[] = "INSERT INTO `FeatureComponents` "
238 "(`Feature_`, `Component_`) "
243 sz = strlen(values) + sizeof insert;
244 query = HeapAlloc(GetProcessHeap(),0,sz);
245 sprintf(query,insert,values);
246 r = run_query( hdb, 0, query );
247 HeapFree(GetProcessHeap(), 0, query);
251 static UINT add_std_dlls_entry( MSIHANDLE hdb, const char *values )
253 char insert[] = "INSERT INTO `StdDlls` "
254 "(`File`, `Binary_`) "
259 sz = strlen(values) + sizeof insert;
260 query = HeapAlloc(GetProcessHeap(),0,sz);
261 sprintf(query,insert,values);
262 r = run_query( hdb, 0, query );
263 HeapFree(GetProcessHeap(), 0, query);
267 static UINT add_binary_entry( MSIHANDLE hdb, const char *values )
269 char insert[] = "INSERT INTO `Binary` "
275 sz = strlen(values) + sizeof insert;
276 query = HeapAlloc(GetProcessHeap(),0,sz);
277 sprintf(query,insert,values);
278 r = run_query( hdb, 0, query );
279 HeapFree(GetProcessHeap(), 0, query);
283 static void test_msiinsert(void)
285 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
293 /* just MsiOpenDatabase should not create a file */
294 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
295 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
298 query = "CREATE TABLE `phone` ( "
299 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
301 r = MsiDatabaseOpenView(hdb, query, &hview);
302 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
303 r = MsiViewExecute(hview, 0);
304 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
305 r = MsiViewClose(hview);
306 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
307 r = MsiCloseHandle(hview);
308 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
310 /* insert a value into it */
311 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
312 "VALUES('1', 'Abe', '8675309')";
313 r = MsiDatabaseOpenView(hdb, query, &hview);
314 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
315 r = MsiViewExecute(hview, 0);
316 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
317 r = MsiViewClose(hview);
318 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
319 r = MsiCloseHandle(hview);
320 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
322 query = "SELECT * FROM `phone` WHERE `id` = 1";
323 r = do_query(hdb, query, &hrec);
324 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
326 /* check the record contains what we put in it */
327 r = MsiRecordGetFieldCount(hrec);
328 ok(r == 3, "record count wrong\n");
331 r = MsiRecordIsNull(hrec, 0);
332 ok(r == FALSE, "field 0 not null\n");
335 r = MsiRecordGetInteger(hrec, 1);
336 ok(r == 1, "field 1 contents wrong\n");
338 r = MsiRecordGetString(hrec, 2, buf, &sz);
339 ok(r == ERROR_SUCCESS, "field 2 content fetch failed\n");
340 ok(!strcmp(buf,"Abe"), "field 2 content incorrect\n");
342 r = MsiRecordGetString(hrec, 3, buf, &sz);
343 ok(r == ERROR_SUCCESS, "field 3 content fetch failed\n");
344 ok(!strcmp(buf,"8675309"), "field 3 content incorrect\n");
346 r = MsiCloseHandle(hrec);
347 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
349 /* open a select query */
351 query = "SELECT * FROM `phone` WHERE `id` >= 10";
352 r = do_query(hdb, query, &hrec);
353 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
354 ok(hrec == 0, "hrec should be null\n");
356 r = MsiCloseHandle(hrec);
357 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
359 query = "SELECT * FROM `phone` WHERE `id` < 0";
360 r = do_query(hdb, query, &hrec);
361 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
363 query = "SELECT * FROM `phone` WHERE `id` <= 0";
364 r = do_query(hdb, query, &hrec);
365 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
367 query = "SELECT * FROM `phone` WHERE `id` <> 1";
368 r = do_query(hdb, query, &hrec);
369 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
371 query = "SELECT * FROM `phone` WHERE `id` > 10";
372 r = do_query(hdb, query, &hrec);
373 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
375 /* now try a few bad INSERT xqueries */
376 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
378 r = MsiDatabaseOpenView(hdb, query, &hview);
379 ok(r == ERROR_BAD_QUERY_SYNTAX, "MsiDatabaseOpenView failed\n");
381 /* construct a record to insert */
382 hrec = MsiCreateRecord(4);
383 r = MsiRecordSetInteger(hrec, 1, 2);
384 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
385 r = MsiRecordSetString(hrec, 2, "Adam");
386 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
387 r = MsiRecordSetString(hrec, 3, "96905305");
388 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
390 /* insert another value, using a record and wildcards */
391 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
393 r = MsiDatabaseOpenView(hdb, query, &hview);
394 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
396 if (r == ERROR_SUCCESS)
398 r = MsiViewExecute(hview, hrec);
399 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
400 r = MsiViewClose(hview);
401 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
402 r = MsiCloseHandle(hview);
403 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
405 r = MsiCloseHandle(hrec);
406 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
408 r = MsiViewFetch(0, NULL);
409 ok(r == ERROR_INVALID_PARAMETER, "MsiViewFetch failed\n");
411 r = MsiDatabaseCommit(hdb);
412 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
414 r = MsiCloseHandle(hdb);
415 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
417 r = DeleteFile(msifile);
418 ok(r == TRUE, "file didn't exist after commit\n");
421 typedef UINT (WINAPI *fnMsiDecomposeDescriptorA)(LPCSTR, LPCSTR, LPSTR, LPSTR, DWORD *);
422 static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA;
424 static void test_msidecomposedesc(void)
426 char prod[MAX_FEATURE_CHARS+1], comp[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1];
432 hmod = GetModuleHandle("msi.dll");
435 pMsiDecomposeDescriptorA = (fnMsiDecomposeDescriptorA)
436 GetProcAddress(hmod, "MsiDecomposeDescriptorA");
437 if (!pMsiDecomposeDescriptorA)
440 /* test a valid feature descriptor */
441 desc = "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
443 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
444 ok(r == ERROR_SUCCESS, "returned an error\n");
445 ok(len == strlen(desc), "length was wrong\n");
446 ok(strcmp(prod,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
447 ok(strcmp(feature,"FollowTheWhiteRabbit")==0, "feature wrong\n");
448 ok(strcmp(comp,"{A7CD68DB-EF74-49C8-FBB2-A7C463B2AC24}")==0,"component wrong\n");
450 /* test an invalid feature descriptor with too many characters */
451 desc = "']gAVn-}f(ZXfeAR6.ji"
452 "ThisWillFailIfTheresMoreThanAGuidsChars>"
453 "3w2x^IGfe?CxI5heAvk.";
455 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
456 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
459 * Test a valid feature descriptor with the
460 * maximum number of characters and some trailing characters.
462 desc = "']gAVn-}f(ZXfeAR6.ji"
463 "ThisWillWorkIfTheresLTEThanAGuidsChars>"
464 "3w2x^IGfe?CxI5heAvk."
467 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
468 ok(r == ERROR_SUCCESS, "returned wrong error\n");
469 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
472 r = pMsiDecomposeDescriptorA(desc, prod, feature, NULL, &len);
473 ok(r == ERROR_SUCCESS, "returned wrong error\n");
474 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
477 r = pMsiDecomposeDescriptorA(desc, prod, NULL, NULL, &len);
478 ok(r == ERROR_SUCCESS, "returned wrong error\n");
479 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
482 r = pMsiDecomposeDescriptorA(desc, NULL, NULL, NULL, &len);
483 ok(r == ERROR_SUCCESS, "returned wrong error\n");
484 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
487 r = pMsiDecomposeDescriptorA(NULL, NULL, NULL, NULL, &len);
488 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
489 ok(len == 0, "length wrong\n");
492 static UINT try_query_param( MSIHANDLE hdb, LPCSTR szQuery, MSIHANDLE hrec )
497 res = MsiDatabaseOpenView( hdb, szQuery, &htab );
498 if(res == ERROR_SUCCESS )
502 r = MsiViewExecute( htab, hrec );
503 if(r != ERROR_SUCCESS )
506 r = MsiViewClose( htab );
507 if(r != ERROR_SUCCESS )
510 r = MsiCloseHandle( htab );
511 if(r != ERROR_SUCCESS )
517 static UINT try_query( MSIHANDLE hdb, LPCSTR szQuery )
519 return try_query_param( hdb, szQuery, 0 );
522 static UINT try_insert_query( MSIHANDLE hdb, LPCSTR szQuery )
527 hrec = MsiCreateRecord( 1 );
528 MsiRecordSetString( hrec, 1, "Hello");
530 r = try_query_param( hdb, szQuery, hrec );
532 MsiCloseHandle( hrec );
536 static void test_msibadqueries(void)
543 /* just MsiOpenDatabase should not create a file */
544 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
545 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
547 r = MsiDatabaseCommit( hdb );
548 ok(r == ERROR_SUCCESS , "Failed to commit database\n");
550 r = MsiCloseHandle( hdb );
551 ok(r == ERROR_SUCCESS , "Failed to close database\n");
553 /* open it readonly */
554 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb );
555 ok(r == ERROR_SUCCESS , "Failed to open database r/o\n");
557 /* add a table to it */
558 r = try_query( hdb, "select * from _Tables");
559 ok(r == ERROR_SUCCESS , "query 1 failed\n");
561 r = MsiCloseHandle( hdb );
562 ok(r == ERROR_SUCCESS , "Failed to close database r/o\n");
564 /* open it read/write */
565 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
566 ok(r == ERROR_SUCCESS , "Failed to open database r/w\n");
568 /* a bunch of test queries that fail with the native MSI */
570 r = try_query( hdb, "CREATE TABLE");
571 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2a return code\n");
573 r = try_query( hdb, "CREATE TABLE `a`");
574 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2b return code\n");
576 r = try_query( hdb, "CREATE TABLE `a` ()");
577 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2c return code\n");
579 r = try_query( hdb, "CREATE TABLE `a` (`b`)");
580 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2d return code\n");
582 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) )");
583 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2e return code\n");
585 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
586 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2f return code\n");
588 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
589 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2g return code\n");
591 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
592 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2h return code\n");
594 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
595 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2i return code\n");
597 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
598 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2j return code\n");
600 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
601 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2k return code\n");
603 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
604 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2l return code\n");
606 r = try_query( hdb, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
607 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2m return code\n");
609 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
610 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2n return code\n");
612 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
613 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2o return code\n");
615 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
616 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
618 r = try_query( hdb, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
619 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
621 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
622 ok(r == ERROR_SUCCESS , "valid query 2z failed\n");
624 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
625 ok(r == ERROR_BAD_QUERY_SYNTAX , "created same table again\n");
627 r = try_query( hdb, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
628 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
629 ok(r == ERROR_SUCCESS , "query 4 failed\n");
631 r = MsiDatabaseCommit( hdb );
632 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
634 r = try_query( hdb, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
635 "PRIMARY KEY `foo`)");
636 ok(r == ERROR_SUCCESS , "query 4 failed\n");
638 r = try_insert_query( hdb, "insert into a ( `b` ) VALUES ( ? )");
639 ok(r == ERROR_SUCCESS , "failed to insert record in db\n");
641 r = MsiDatabaseCommit( hdb );
642 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
644 r = try_query( hdb, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
645 "PRIMARY KEY `ba`)");
646 ok(r != ERROR_SUCCESS , "query 5 succeeded\n");
648 r = try_query( hdb,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
649 ok(r != ERROR_SUCCESS , "query 6 succeeded\n");
651 r = try_query( hdb, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
653 ok(r == ERROR_SUCCESS , "query 7 failed\n");
655 r = try_query( hdb, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
656 ok(r == ERROR_SUCCESS , "query 8 failed\n");
658 r = MsiCloseHandle( hdb );
659 ok(r == ERROR_SUCCESS , "Failed to close database transact\n");
661 r = DeleteFile( msifile );
662 ok(r == TRUE, "file didn't exist after commit\n");
665 static void test_viewmodify(void)
667 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
675 /* just MsiOpenDatabase should not create a file */
676 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
677 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
679 query = "CREATE TABLE `phone` ( "
680 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
682 r = run_query( hdb, 0, query );
683 ok(r == ERROR_SUCCESS, "query failed\n");
685 /* check what the error function reports without doing anything */
687 /* passing NULL as the 3rd param make function to crash on older platforms */
688 r = MsiViewGetError( 0, NULL, &sz );
689 ok(r == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
692 query = "SELECT * FROM `phone`";
693 r = MsiDatabaseOpenView(hdb, query, &hview);
694 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
696 /* see what happens with a good hview and bad args */
697 r = MsiViewGetError( hview, NULL, NULL );
698 ok(r == MSIDBERROR_INVALIDARG || r == MSIDBERROR_NOERROR,
699 "MsiViewGetError returns %u (expected -3)\n", r);
700 r = MsiViewGetError( hview, buffer, NULL );
701 ok(r == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
703 /* see what happens with a zero length buffer */
706 r = MsiViewGetError( hview, buffer, &sz );
707 ok(r == MSIDBERROR_MOREDATA, "MsiViewGetError return\n");
708 ok(buffer[0] == 'x', "buffer cleared\n");
709 ok(sz == 0, "size not zero\n");
711 /* ok this one is strange */
713 r = MsiViewGetError( hview, NULL, &sz );
714 ok(r == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
715 ok(sz == 0, "size not zero\n");
717 /* see if it really has an error */
720 r = MsiViewGetError( hview, buffer, &sz );
721 ok(r == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
722 ok(buffer[0] == 0, "buffer not cleared\n");
723 ok(sz == 0, "size not zero\n");
725 r = MsiViewExecute(hview, 0);
726 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
728 /* try some invalid records */
729 r = MsiViewModify(hview, MSIMODIFY_INSERT, 0 );
730 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
731 r = MsiViewModify(hview, -1, 0 );
732 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
734 /* try an small record */
735 hrec = MsiCreateRecord(1);
736 r = MsiViewModify(hview, -1, hrec );
737 ok(r == ERROR_INVALID_DATA, "MsiViewModify failed\n");
739 r = MsiCloseHandle(hrec);
740 ok(r == ERROR_SUCCESS, "failed to close record\n");
742 /* insert a valid record */
743 hrec = MsiCreateRecord(3);
745 r = MsiRecordSetInteger(hrec, 2, 1);
746 ok(r == ERROR_SUCCESS, "failed to set integer\n");
747 r = MsiRecordSetString(hrec, 2, "bob");
748 ok(r == ERROR_SUCCESS, "failed to set integer\n");
749 r = MsiRecordSetString(hrec, 3, "7654321");
750 ok(r == ERROR_SUCCESS, "failed to set integer\n");
752 r = MsiViewExecute(hview, 0);
753 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
754 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
755 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
757 /* insert the same thing again */
758 r = MsiViewExecute(hview, 0);
759 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
761 /* should fail ... */
763 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
764 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
767 r = MsiCloseHandle(hrec);
768 ok(r == ERROR_SUCCESS, "failed to close record\n");
770 r = MsiViewClose(hview);
771 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
772 r = MsiCloseHandle(hview);
773 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
775 r = MsiCloseHandle( hdb );
776 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
779 static MSIHANDLE create_db(void)
786 /* create an empty database */
787 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
788 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
789 if( res != ERROR_SUCCESS )
792 res = MsiDatabaseCommit( hdb );
793 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
798 static void test_getcolinfo(void)
800 MSIHANDLE hdb, hview = 0, rec = 0;
805 /* create an empty db */
807 ok( hdb, "failed to create db\n");
809 /* tables should be present */
810 r = MsiDatabaseOpenView(hdb, "select * from _Tables", &hview);
811 ok( r == ERROR_SUCCESS, "failed to open query\n");
813 r = MsiViewExecute(hview, 0);
814 ok( r == ERROR_SUCCESS, "failed to execute query\n");
816 /* check that NAMES works */
818 r = MsiViewGetColumnInfo( hview, MSICOLINFO_NAMES, &rec );
819 ok( r == ERROR_SUCCESS, "failed to get names\n");
821 r = MsiRecordGetString(rec, 1, buffer, &sz );
822 ok( r == ERROR_SUCCESS, "failed to get string\n");
823 ok( !strcmp(buffer,"Name"), "_Tables has wrong column name\n");
824 r = MsiCloseHandle( rec );
825 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
827 /* check that TYPES works */
829 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, &rec );
830 ok( r == ERROR_SUCCESS, "failed to get names\n");
832 r = MsiRecordGetString(rec, 1, buffer, &sz );
833 ok( r == ERROR_SUCCESS, "failed to get string\n");
834 ok( !strcmp(buffer,"s64"), "_Tables has wrong column type\n");
835 r = MsiCloseHandle( rec );
836 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
838 /* check that invalid values fail */
840 r = MsiViewGetColumnInfo( hview, 100, &rec );
841 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
842 ok( rec == 0, "returned a record\n");
844 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, NULL );
845 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
847 r = MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES, &rec );
848 ok( r == ERROR_INVALID_HANDLE, "wrong error code\n");
850 r = MsiViewClose(hview);
851 ok( r == ERROR_SUCCESS, "failed to close view\n");
852 r = MsiCloseHandle(hview);
853 ok( r == ERROR_SUCCESS, "failed to close view handle\n");
854 r = MsiCloseHandle(hdb);
855 ok( r == ERROR_SUCCESS, "failed to close database\n");
858 static MSIHANDLE get_column_info(MSIHANDLE hdb, const char *query, MSICOLINFO type)
860 MSIHANDLE hview = 0, rec = 0;
863 r = MsiDatabaseOpenView(hdb, query, &hview);
864 if( r != ERROR_SUCCESS )
867 r = MsiViewExecute(hview, 0);
868 if( r == ERROR_SUCCESS )
870 MsiViewGetColumnInfo( hview, type, &rec );
873 MsiCloseHandle(hview);
877 static UINT get_columns_table_type(MSIHANDLE hdb, const char *table, UINT field)
879 MSIHANDLE hview = 0, rec = 0;
883 sprintf(query, "select * from `_Columns` where `Table` = '%s'", table );
885 r = MsiDatabaseOpenView(hdb, query, &hview);
886 if( r != ERROR_SUCCESS )
889 r = MsiViewExecute(hview, 0);
890 if( r == ERROR_SUCCESS )
894 r = MsiViewFetch( hview, &rec );
895 if( r != ERROR_SUCCESS)
897 r = MsiRecordGetInteger( rec, 2 );
899 type = MsiRecordGetInteger( rec, 4 );
900 MsiCloseHandle( rec );
905 MsiCloseHandle(hview);
909 static BOOL check_record( MSIHANDLE rec, UINT field, LPCSTR val )
916 r = MsiRecordGetString( rec, field, buffer, &sz );
917 return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
920 static void test_viewgetcolumninfo(void)
922 MSIHANDLE hdb = 0, rec;
926 ok( hdb, "failed to create db\n");
928 r = run_query( hdb, 0,
929 "CREATE TABLE `Properties` "
930 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
931 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
933 /* check the column types */
934 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_TYPES );
935 ok( rec, "failed to get column info record\n" );
937 ok( check_record( rec, 1, "S255"), "wrong record type\n");
938 ok( check_record( rec, 2, "S1"), "wrong record type\n");
940 MsiCloseHandle( rec );
942 /* check the type in _Columns */
943 ok( 0x3dff == get_columns_table_type(hdb, "Properties", 1 ), "_columns table wrong\n");
944 ok( 0x1d01 == get_columns_table_type(hdb, "Properties", 2 ), "_columns table wrong\n");
946 /* now try the names */
947 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_NAMES );
948 ok( rec, "failed to get column info record\n" );
950 ok( check_record( rec, 1, "Property"), "wrong record type\n");
951 ok( check_record( rec, 2, "Value"), "wrong record type\n");
953 MsiCloseHandle( rec );
955 r = run_query( hdb, 0,
956 "CREATE TABLE `Binary` "
957 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
958 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
960 /* check the column types */
961 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_TYPES );
962 ok( rec, "failed to get column info record\n" );
964 ok( check_record( rec, 1, "S255"), "wrong record type\n");
965 ok( check_record( rec, 2, "V0"), "wrong record type\n");
967 MsiCloseHandle( rec );
969 /* check the type in _Columns */
970 ok( 0x3dff == get_columns_table_type(hdb, "Binary", 1 ), "_columns table wrong\n");
971 ok( 0x1900 == get_columns_table_type(hdb, "Binary", 2 ), "_columns table wrong\n");
973 /* now try the names */
974 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_NAMES );
975 ok( rec, "failed to get column info record\n" );
977 ok( check_record( rec, 1, "Name"), "wrong record type\n");
978 ok( check_record( rec, 2, "Data"), "wrong record type\n");
979 MsiCloseHandle( rec );
981 r = run_query( hdb, 0,
982 "CREATE TABLE `UIText` "
983 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
984 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
986 ok( 0x2d48 == get_columns_table_type(hdb, "UIText", 1 ), "_columns table wrong\n");
987 ok( 0x1fff == get_columns_table_type(hdb, "UIText", 2 ), "_columns table wrong\n");
989 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_NAMES );
990 ok( rec, "failed to get column info record\n" );
991 ok( check_record( rec, 1, "Key"), "wrong record type\n");
992 ok( check_record( rec, 2, "Text"), "wrong record type\n");
993 MsiCloseHandle( rec );
995 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_TYPES );
996 ok( rec, "failed to get column info record\n" );
997 ok( check_record( rec, 1, "s72"), "wrong record type\n");
998 ok( check_record( rec, 2, "L255"), "wrong record type\n");
999 MsiCloseHandle( rec );
1001 MsiCloseHandle( hdb );
1004 static void test_msiexport(void)
1006 MSIHANDLE hdb = 0, hview = 0;
1009 char path[MAX_PATH];
1010 const char file[] = "phone.txt";
1014 const char expected[] =
1015 "id\tname\tnumber\r\n"
1018 "1\tAbe\t8675309\r\n";
1020 DeleteFile(msifile);
1022 /* just MsiOpenDatabase should not create a file */
1023 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1024 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1026 /* create a table */
1027 query = "CREATE TABLE `phone` ( "
1028 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1029 "PRIMARY KEY `id`)";
1030 r = MsiDatabaseOpenView(hdb, query, &hview);
1031 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1032 r = MsiViewExecute(hview, 0);
1033 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1034 r = MsiViewClose(hview);
1035 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1036 r = MsiCloseHandle(hview);
1037 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1039 /* insert a value into it */
1040 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
1041 "VALUES('1', 'Abe', '8675309')";
1042 r = MsiDatabaseOpenView(hdb, query, &hview);
1043 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1044 r = MsiViewExecute(hview, 0);
1045 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1046 r = MsiViewClose(hview);
1047 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1048 r = MsiCloseHandle(hview);
1049 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1051 GetCurrentDirectory(MAX_PATH, path);
1053 r = MsiDatabaseExport(hdb, "phone", path, file);
1054 ok(r == ERROR_SUCCESS, "MsiDatabaseExport failed\n");
1056 MsiCloseHandle(hdb);
1058 lstrcat(path, "\\");
1059 lstrcat(path, file);
1061 /* check the data that was written */
1063 memset(buffer, 0, sizeof buffer);
1064 handle = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
1065 if (handle != INVALID_HANDLE_VALUE)
1067 ReadFile(handle, buffer, sizeof buffer, &length, NULL);
1068 CloseHandle(handle);
1072 ok(0, "failed to open file %s\n", path);
1074 ok( length == strlen(expected), "length of data wrong\n");
1075 ok( !lstrcmp(buffer, expected), "data doesn't match\n");
1076 DeleteFile(msifile);
1079 static void test_longstrings(void)
1081 const char insert_query[] =
1082 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1084 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
1087 const DWORD STRING_LENGTH = 0x10005;
1089 DeleteFile(msifile);
1090 /* just MsiOpenDatabase should not create a file */
1091 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1092 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1094 /* create a table */
1096 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1097 ok(r == ERROR_SUCCESS, "query failed\n");
1099 /* try a insert a very long string */
1100 str = HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH+sizeof insert_query);
1101 len = strchr(insert_query, 'Z') - insert_query;
1102 strcpy(str, insert_query);
1103 memset(str+len, 'Z', STRING_LENGTH);
1104 strcpy(str+len+STRING_LENGTH, insert_query+len+1);
1105 r = try_query( hdb, str );
1106 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1108 HeapFree(GetProcessHeap(), 0, str);
1110 MsiDatabaseCommit(hdb);
1111 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
1112 MsiCloseHandle(hdb);
1114 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
1115 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1117 r = MsiDatabaseOpenView(hdb, "select * from `strings` where `id` = 1", &hview);
1118 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1120 r = MsiViewExecute(hview, 0);
1121 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1123 r = MsiViewFetch(hview, &hrec);
1124 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1126 MsiCloseHandle(hview);
1128 r = MsiRecordGetString(hrec, 2, NULL, &len);
1129 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1130 ok(len == STRING_LENGTH, "string length wrong\n");
1132 MsiCloseHandle(hrec);
1133 MsiCloseHandle(hdb);
1134 DeleteFile(msifile);
1137 static void create_file(const CHAR *name)
1142 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1143 ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
1144 WriteFile(file, name, strlen(name), &written, NULL);
1145 WriteFile(file, "\n", strlen("\n"), &written, NULL);
1149 static void test_streamtable(void)
1151 MSIHANDLE hdb = 0, rec, view;
1152 char file[MAX_PATH];
1158 ok( hdb, "failed to create db\n");
1160 r = run_query( hdb, 0,
1161 "CREATE TABLE `Properties` "
1162 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1163 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1165 /* check the column types */
1166 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_TYPES );
1167 ok( rec, "failed to get column info record\n" );
1170 ok( check_record( rec, 1, "s62"), "wrong record type\n");
1171 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1174 MsiCloseHandle( rec );
1176 /* now try the names */
1177 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_NAMES );
1178 ok( rec, "failed to get column info record\n" );
1181 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1182 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1185 MsiCloseHandle( rec );
1187 /* insert a file into the _Streams table */
1188 create_file( "test.txt" );
1190 rec = MsiCreateRecord( 2 );
1191 MsiRecordSetString( rec, 1, "data" );
1193 r = MsiRecordSetStream( rec, 2, "test.txt" );
1194 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1196 DeleteFile("test.txt");
1198 r = MsiDatabaseOpenView( hdb,
1199 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view );
1202 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1205 r = MsiViewExecute( view, rec );
1208 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1211 MsiCloseHandle( rec );
1212 MsiCloseHandle( view );
1214 r = MsiDatabaseOpenView( hdb,
1215 "SELECT `Name`, `Data` FROM `_Streams`", &view );
1218 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1221 r = MsiViewExecute( view, 0 );
1224 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1227 r = MsiViewFetch( view, &rec );
1230 ok( r == ERROR_SUCCESS, "Failed to fetch record: %d\n", r);
1234 r = MsiRecordGetString( rec, 1, file, &size );
1237 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1238 ok( !lstrcmp(file, "data"), "Expected 'data', got %s\n", file);
1242 memset(buf, 0, MAX_PATH);
1243 r = MsiRecordReadStream( rec, 2, buf, &size );
1246 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1247 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf);
1250 MsiCloseHandle( rec );
1252 r = MsiViewFetch( view, &rec );
1255 ok( r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
1258 MsiCloseHandle( view );
1259 MsiCloseHandle( hdb );
1260 DeleteFile(msifile);
1263 static void test_where(void)
1265 MSIHANDLE hdb = 0, rec, view;
1273 ok( hdb, "failed to create db\n");
1275 r = run_query( hdb, 0,
1276 "CREATE TABLE `Media` ("
1277 "`DiskId` SHORT NOT NULL, "
1278 "`LastSequence` LONG, "
1279 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1280 "`Cabinet` CHAR(255), "
1281 "`VolumeLabel` CHAR(32), "
1282 "`Source` CHAR(72) "
1283 "PRIMARY KEY `DiskId`)" );
1284 ok( r == S_OK, "cannot create Media table: %d\n", r );
1286 r = run_query( hdb, 0, "INSERT INTO `Media` "
1287 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1288 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1289 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1291 r = run_query( hdb, 0, "INSERT INTO `Media` "
1292 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1293 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1294 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1296 r = run_query( hdb, 0, "INSERT INTO `Media` "
1297 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1298 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1299 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1301 query = "SELECT * FROM `Media`";
1302 r = do_query(hdb, query, &rec);
1303 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1304 ok( check_record( rec, 4, "zero.cab"), "wrong cabinet\n");
1305 MsiCloseHandle( rec );
1307 query = "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1308 r = do_query(hdb, query, &rec);
1309 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1310 ok( check_record( rec, 4, "one.cab"), "wrong cabinet\n");
1312 r = MsiRecordGetInteger(rec, 1);
1313 ok( 2 == r, "field wrong\n");
1314 r = MsiRecordGetInteger(rec, 2);
1315 ok( 1 == r, "field wrong\n");
1316 MsiCloseHandle( rec );
1318 query = "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1319 r = MsiDatabaseOpenView(hdb, query, &view);
1320 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1322 r = MsiViewExecute(view, 0);
1323 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1325 r = MsiViewFetch(view, &rec);
1326 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1328 count = MsiRecordGetFieldCount( rec );
1329 ok( count == 1, "Expected 1 record fields, got %d\n", count );
1332 r = MsiRecordGetString( rec, 1, buf, &size );
1333 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1334 ok( !lstrcmp( buf, "2" ),
1335 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf );
1336 MsiCloseHandle( rec );
1338 r = MsiViewFetch(view, &rec);
1339 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1342 r = MsiRecordGetString( rec, 1, buf, &size );
1343 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1344 ok( !lstrcmp( buf, "3" ),
1345 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf );
1346 MsiCloseHandle( rec );
1348 r = MsiViewFetch(view, &rec);
1349 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
1352 MsiCloseHandle(view);
1354 MsiCloseHandle( rec );
1356 MsiCloseHandle( hdb );
1357 DeleteFile(msifile);
1360 static CHAR CURR_DIR[MAX_PATH];
1362 static const CHAR test_data[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1363 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1364 "TestTable\tFirstPrimaryColumn\n"
1365 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1367 static void write_file(const CHAR *filename, const char *data, int data_size)
1371 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
1372 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1374 WriteFile(hf, data, data_size, &size, NULL);
1378 static UINT add_table_to_db(MSIHANDLE hdb, LPCSTR table_data)
1382 write_file("temp_file", table_data, (lstrlen(table_data) - 1) * sizeof(char));
1383 r = MsiDatabaseImportA(hdb, CURR_DIR, "temp_file");
1384 DeleteFileA("temp_file");
1389 static void test_msiimport(void)
1391 MSIHANDLE hdb, view, rec;
1396 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
1398 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
1399 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1401 r = add_table_to_db(hdb, test_data);
1402 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1404 query = "SELECT * FROM `TestTable`";
1405 r = MsiDatabaseOpenView(hdb, query, &view);
1406 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1408 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
1409 count = MsiRecordGetFieldCount(rec);
1410 ok(count == 9, "Expected 9, got %d\n", count);
1411 ok(check_record(rec, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
1412 ok(check_record(rec, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
1413 ok(check_record(rec, 3, "ShortInt"), "Expected ShortInt\n");
1414 ok(check_record(rec, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
1415 ok(check_record(rec, 5, "LongInt"), "Expected LongInt\n");
1416 ok(check_record(rec, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
1417 ok(check_record(rec, 7, "String"), "Expected String\n");
1418 ok(check_record(rec, 8, "LocalizableString"), "Expected LocalizableString\n");
1419 ok(check_record(rec, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
1420 MsiCloseHandle(rec);
1422 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
1423 count = MsiRecordGetFieldCount(rec);
1424 ok(count == 9, "Expected 9, got %d\n", count);
1425 ok(check_record(rec, 1, "s255"), "Expected s255\n");
1426 ok(check_record(rec, 4, "I2"), "Expected I2\n");
1427 ok(check_record(rec, 6, "I4"), "Expected I4\n");
1428 ok(check_record(rec, 7, "S255"), "Expected S255\n");
1429 ok(check_record(rec, 8, "S0"), "Expected S0\n");
1430 ok(check_record(rec, 9, "s0"), "Expected s0\n");
1433 ok(check_record(rec, 2, "i2"), "Expected i2\n");
1434 ok(check_record(rec, 3, "i2"), "Expected i2\n");
1435 ok(check_record(rec, 5, "i4"), "Expected i4\n");
1437 MsiCloseHandle(rec);
1439 query = "SELECT * FROM `TestTable`";
1440 r = do_query(hdb, query, &rec);
1441 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1442 ok(check_record(rec, 1, "stringage"), "Expected 'stringage'\n");
1443 ok(check_record(rec, 7, "another string"), "Expected 'another string'\n");
1444 ok(check_record(rec, 8, "localizable"), "Expected 'localizable'\n");
1445 ok(check_record(rec, 9, "duh"), "Expected 'duh'\n");
1447 i = MsiRecordGetInteger(rec, 2);
1448 ok(i == 5, "Expected 5, got %d\n", i);
1450 i = MsiRecordGetInteger(rec, 3);
1451 ok(i == 2, "Expected 2, got %d\n", i);
1453 i = MsiRecordGetInteger(rec, 4);
1456 ok(i == 0x80000000, "Expected 0x80000000, got %d\n", i);
1459 i = MsiRecordGetInteger(rec, 5);
1460 ok(i == 2147483640, "Expected 2147483640, got %d\n", i);
1462 i = MsiRecordGetInteger(rec, 6);
1463 ok(i == -2147483640, "Expected -2147483640, got %d\n", i);
1465 MsiCloseHandle(rec);
1466 MsiCloseHandle(view);
1467 MsiCloseHandle(hdb);
1468 DeleteFileA(msifile);
1471 static void test_markers(void)
1478 ok( hdb, "failed to create db\n");
1480 rec = MsiCreateRecord(3);
1481 MsiRecordSetString(rec, 1, "Table");
1482 MsiRecordSetString(rec, 2, "Apples");
1483 MsiRecordSetString(rec, 3, "Oranges");
1485 /* try a legit create */
1486 query = "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1487 r = run_query(hdb, 0, query);
1488 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1489 MsiCloseHandle(rec);
1491 /* try table name as marker */
1492 rec = MsiCreateRecord(1);
1493 MsiRecordSetString(rec, 1, "Fable");
1494 query = "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1495 r = run_query(hdb, rec, query);
1496 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1498 /* verify that we just created a table called '?', not 'Fable' */
1499 r = try_query(hdb, "SELECT * from `Fable`");
1500 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1502 r = try_query(hdb, "SELECT * from `?`");
1503 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1505 /* try table name as marker without backticks */
1506 MsiRecordSetString(rec, 1, "Mable");
1507 query = "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1508 r = run_query(hdb, rec, query);
1509 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1511 /* try one column name as marker */
1512 MsiRecordSetString(rec, 1, "One");
1513 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1514 r = run_query(hdb, rec, query);
1515 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1516 MsiCloseHandle(rec);
1518 /* try column names as markers */
1519 rec = MsiCreateRecord(2);
1520 MsiRecordSetString(rec, 1, "One");
1521 MsiRecordSetString(rec, 2, "Two");
1522 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
1523 r = run_query(hdb, rec, query);
1524 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1525 MsiCloseHandle(rec);
1527 /* try names with backticks */
1528 rec = MsiCreateRecord(3);
1529 MsiRecordSetString(rec, 1, "One");
1530 MsiRecordSetString(rec, 2, "Two");
1531 MsiRecordSetString(rec, 3, "One");
1532 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1533 r = run_query(hdb, rec, query);
1534 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1536 /* try names with backticks, minus definitions */
1537 query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
1538 r = run_query(hdb, rec, query);
1539 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1541 /* try names without backticks */
1542 query = "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
1543 r = run_query(hdb, rec, query);
1544 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1545 MsiCloseHandle(rec);
1547 /* try one long marker */
1548 rec = MsiCreateRecord(1);
1549 MsiRecordSetString(rec, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
1550 query = "CREATE TABLE `Mable` ( ? )";
1551 r = run_query(hdb, rec, query);
1552 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1553 MsiCloseHandle(rec);
1555 /* try all names as markers */
1556 rec = MsiCreateRecord(4);
1557 MsiRecordSetString(rec, 1, "Mable");
1558 MsiRecordSetString(rec, 2, "One");
1559 MsiRecordSetString(rec, 3, "Two");
1560 MsiRecordSetString(rec, 4, "One");
1561 query = "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1562 r = run_query(hdb, rec, query);
1563 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1564 MsiCloseHandle(rec);
1566 /* try a legit insert */
1567 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
1568 r = run_query(hdb, 0, query);
1569 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1571 r = try_query(hdb, "SELECT * from `Table`");
1572 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1574 /* try values as markers */
1575 rec = MsiCreateRecord(2);
1576 MsiRecordSetInteger(rec, 1, 4);
1577 MsiRecordSetString(rec, 2, "hi");
1578 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1579 r = run_query(hdb, rec, query);
1580 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1581 MsiCloseHandle(rec);
1583 /* try column names and values as markers */
1584 rec = MsiCreateRecord(4);
1585 MsiRecordSetString(rec, 1, "One");
1586 MsiRecordSetString(rec, 2, "Two");
1587 MsiRecordSetInteger(rec, 3, 5);
1588 MsiRecordSetString(rec, 4, "hi");
1589 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
1590 r = run_query(hdb, rec, query);
1591 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1592 MsiCloseHandle(rec);
1594 /* try column names as markers */
1595 rec = MsiCreateRecord(2);
1596 MsiRecordSetString(rec, 1, "One");
1597 MsiRecordSetString(rec, 2, "Two");
1598 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
1599 r = run_query(hdb, rec, query);
1600 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1601 MsiCloseHandle(rec);
1603 /* try table name as a marker */
1604 rec = MsiCreateRecord(1);
1605 MsiRecordSetString(rec, 1, "Table");
1606 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
1607 r = run_query(hdb, rec, query);
1608 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1609 MsiCloseHandle(rec);
1611 /* try table name and values as markers */
1612 rec = MsiCreateRecord(3);
1613 MsiRecordSetString(rec, 1, "Table");
1614 MsiRecordSetInteger(rec, 2, 10);
1615 MsiRecordSetString(rec, 3, "haha");
1616 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
1617 r = run_query(hdb, rec, query);
1618 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
1619 MsiCloseHandle(rec);
1621 /* try all markers */
1622 rec = MsiCreateRecord(5);
1623 MsiRecordSetString(rec, 1, "Table");
1624 MsiRecordSetString(rec, 1, "One");
1625 MsiRecordSetString(rec, 1, "Two");
1626 MsiRecordSetInteger(rec, 2, 10);
1627 MsiRecordSetString(rec, 3, "haha");
1628 query = "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
1629 r = run_query(hdb, rec, query);
1630 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1631 MsiCloseHandle(rec);
1633 /* insert an integer as a string */
1634 rec = MsiCreateRecord(2);
1635 MsiRecordSetString(rec, 1, "11");
1636 MsiRecordSetString(rec, 2, "hi");
1637 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1638 r = run_query(hdb, rec, query);
1639 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1640 MsiCloseHandle(rec);
1642 /* leave off the '' for the string */
1643 rec = MsiCreateRecord(2);
1644 MsiRecordSetInteger(rec, 1, 12);
1645 MsiRecordSetString(rec, 2, "hi");
1646 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
1647 r = run_query(hdb, rec, query);
1648 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1649 MsiCloseHandle(rec);
1651 MsiCloseHandle(hdb);
1652 DeleteFileA(msifile);
1655 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
1656 static void test_handle_limit(void)
1660 MSIHANDLE hviews[MY_NVIEWS];
1663 /* create an empty db */
1665 ok( hdb, "failed to create db\n");
1667 memset(hviews, 0, sizeof(hviews));
1669 for (i=0; i<MY_NVIEWS; i++) {
1670 static char szQueryBuf[256] = "SELECT * from `_Tables`";
1671 hviews[i] = 0xdeadbeeb;
1672 r = MsiDatabaseOpenView(hdb, szQueryBuf, &hviews[i]);
1673 if( r != ERROR_SUCCESS || hviews[i] == 0xdeadbeeb ||
1674 hviews[i] == 0 || (i && (hviews[i] == hviews[i-1])))
1678 ok( i == MY_NVIEWS, "problem opening views\n");
1680 for (i=0; i<MY_NVIEWS; i++) {
1681 if (hviews[i] != 0 && hviews[i] != 0xdeadbeeb) {
1682 r = MsiCloseHandle(hviews[i]);
1683 if (r != ERROR_SUCCESS)
1688 ok( i == MY_NVIEWS, "problem closing views\n");
1690 r = MsiCloseHandle(hdb);
1691 ok( r == ERROR_SUCCESS, "failed to close database\n");
1694 static void test_generate_transform(void)
1696 MSIHANDLE hdb1, hdb2;
1700 DeleteFile(msifile);
1701 DeleteFile(msifile2);
1702 DeleteFile(mstfile);
1704 /* create an empty database */
1705 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb1 );
1706 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
1708 r = MsiDatabaseCommit( hdb1 );
1709 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1711 /* create another empty database */
1712 r = MsiOpenDatabase(msifile2, MSIDBOPEN_CREATE, &hdb2 );
1713 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
1715 r = MsiDatabaseCommit( hdb2 );
1716 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1718 /* the transform between two empty database should be empty */
1719 r = MsiDatabaseGenerateTransform(hdb1, hdb2, NULL, 0, 0);
1721 ok( r == ERROR_NO_DATA, "return code %d, should be ERROR_NO_DATA\n", r );
1724 query = "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
1725 r = run_query(hdb1, 0, query);
1726 ok(r == ERROR_SUCCESS, "failed to add table\n");
1728 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
1729 r = run_query(hdb1, 0, query);
1730 ok(r == ERROR_SUCCESS, "failed to add row 1\n");
1732 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
1733 r = run_query(hdb1, 0, query);
1734 ok(r == ERROR_SUCCESS, "failed to add row 2\n");
1737 r = MsiDatabaseGenerateTransform(hdb1, hdb2, NULL, 0, 0);
1738 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
1740 r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
1741 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
1743 /* database needs to be committed */
1744 MsiDatabaseCommit(hdb1);
1746 r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
1747 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
1749 MsiCloseHandle( hdb1 );
1751 r = MsiDatabaseApplyTransform( hdb2, mstfile, 0 );
1752 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
1754 MsiDatabaseCommit(hdb2);
1756 /* apply the same transform again? */
1757 r = MsiDatabaseApplyTransform( hdb2, mstfile, 0 );
1758 ok( r == ERROR_INSTALL_TRANSFORM_FAILURE,
1759 "return code %d, should be ERROR_INSTALL_TRANSFORM_FAILURE\n", r );
1762 MsiCloseHandle( hdb2 );
1764 DeleteFile(msifile);
1766 r = MsiOpenDatabase(msifile2, MSIDBOPEN_READONLY, &hdb1 );
1767 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
1770 query = "select `BAR`,`CAR` from `AAR`";
1771 r = run_query(hdb1, 0, query);
1772 ok(r == ERROR_SUCCESS, "select query failed\n");
1775 MsiCloseHandle( hdb1 );
1777 DeleteFile(msifile2);
1778 DeleteFile(mstfile);
1783 const CHAR one[MAX_PATH];
1784 const CHAR two[MAX_PATH];
1787 struct join_res_4col
1789 const CHAR one[MAX_PATH];
1790 const CHAR two[MAX_PATH];
1791 const CHAR three[MAX_PATH];
1792 const CHAR four[MAX_PATH];
1795 static const struct join_res join_res_first[] =
1797 { "alveolar", "procerus" },
1798 { "septum", "procerus" },
1799 { "septum", "nasalis" },
1800 { "ramus", "nasalis" },
1801 { "malar", "mentalis" },
1804 static const struct join_res join_res_second[] =
1806 { "nasal", "septum" },
1807 { "mandible", "ramus" },
1810 static const struct join_res join_res_third[] =
1812 { "msvcp.dll", "abcdefgh" },
1813 { "msvcr.dll", "ijklmnop" },
1816 static const struct join_res join_res_fourth[] =
1818 { "msvcp.dll.01234", "single.dll.31415" },
1821 static const struct join_res join_res_fifth[] =
1823 { "malar", "procerus" },
1826 static const struct join_res join_res_sixth[] =
1828 { "malar", "procerus" },
1829 { "malar", "procerus" },
1830 { "malar", "nasalis" },
1831 { "malar", "nasalis" },
1832 { "malar", "nasalis" },
1833 { "malar", "mentalis" },
1836 static const struct join_res join_res_seventh[] =
1838 { "malar", "nasalis" },
1839 { "malar", "nasalis" },
1840 { "malar", "nasalis" },
1843 static const struct join_res_4col join_res_eighth[] =
1845 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
1846 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
1847 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
1848 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
1849 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
1850 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
1853 static void test_join(void)
1855 MSIHANDLE hdb, hview, hrec;
1862 ok( hdb, "failed to create db\n");
1864 r = create_component_table( hdb );
1865 ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
1867 r = add_component_entry( hdb, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
1868 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1870 r = add_component_entry( hdb, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
1871 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1873 r = add_component_entry( hdb, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
1874 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1876 r = add_component_entry( hdb, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
1877 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1879 r = create_feature_components_table( hdb );
1880 ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
1882 r = add_feature_components_entry( hdb, "'procerus', 'maxilla'" );
1883 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1885 r = add_feature_components_entry( hdb, "'procerus', 'nasal'" );
1886 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1888 r = add_feature_components_entry( hdb, "'nasalis', 'nasal'" );
1889 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1891 r = add_feature_components_entry( hdb, "'nasalis', 'mandible'" );
1892 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1894 r = add_feature_components_entry( hdb, "'nasalis', 'notacomponent'" );
1895 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1897 r = add_feature_components_entry( hdb, "'mentalis', 'zygomatic'" );
1898 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1900 r = create_std_dlls_table( hdb );
1901 ok( r == ERROR_SUCCESS, "cannot create StdDlls table: %d\n", r );
1903 r = add_std_dlls_entry( hdb, "'msvcp.dll', 'msvcp.dll.01234'" );
1904 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
1906 r = add_std_dlls_entry( hdb, "'msvcr.dll', 'msvcr.dll.56789'" );
1907 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
1909 r = create_binary_table( hdb );
1910 ok( r == ERROR_SUCCESS, "cannot create Binary table: %d\n", r );
1912 r = add_binary_entry( hdb, "'msvcp.dll.01234', 'abcdefgh'" );
1913 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
1915 r = add_binary_entry( hdb, "'msvcr.dll.56789', 'ijklmnop'" );
1916 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
1918 r = add_binary_entry( hdb, "'single.dll.31415', 'msvcp.dll'" );
1919 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
1921 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
1922 "FROM `Component`, `FeatureComponents` "
1923 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
1924 "ORDER BY `Feature_`";
1925 r = MsiDatabaseOpenView(hdb, query, &hview);
1926 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1928 r = MsiViewExecute(hview, 0);
1929 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1932 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
1934 count = MsiRecordGetFieldCount( hrec );
1935 ok( count == 2, "Expected 2 record fields, got %d\n", count );
1938 r = MsiRecordGetString( hrec, 1, buf, &size );
1939 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1940 if (i == 2 || i == 3) todo_wine
1942 ok( !lstrcmp( buf, join_res_first[i].one ),
1943 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_first[i].one, buf );
1947 r = MsiRecordGetString( hrec, 2, buf, &size );
1948 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1949 if (i == 3) todo_wine
1951 ok( !lstrcmp( buf, join_res_first[i].two ),
1952 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_first[i].two, buf );
1956 MsiCloseHandle(hrec);
1961 ok( i == 5, "Expected 5 rows, got %d\n", i );
1964 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
1966 MsiViewClose(hview);
1967 MsiCloseHandle(hview);
1969 query = "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
1970 "WHERE FeatureComponents.Component_=Component.Component "
1971 "AND (Feature_='nasalis') ORDER BY Feature_";
1972 r = MsiDatabaseOpenView(hdb, query, &hview);
1975 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1978 r = MsiViewExecute(hview, 0);
1981 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1985 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
1987 count = MsiRecordGetFieldCount( hrec );
1988 ok( count == 2, "Expected 2 record fields, got %d\n", count );
1991 r = MsiRecordGetString( hrec, 1, buf, &size );
1992 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1993 ok( !lstrcmp( buf, join_res_second[i].one ),
1994 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_second[i].one, buf );
1997 r = MsiRecordGetString( hrec, 2, buf, &size );
1998 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1999 ok( !lstrcmp( buf, join_res_second[i].two ),
2000 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_second[i].two, buf );
2003 MsiCloseHandle(hrec);
2008 ok( i == 2, "Expected 2 rows, got %d\n", i );
2013 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2016 MsiViewClose(hview);
2017 MsiCloseHandle(hview);
2019 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2020 "FROM `StdDlls`, `Binary` "
2021 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
2023 r = MsiDatabaseOpenView(hdb, query, &hview);
2024 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2026 r = MsiViewExecute(hview, 0);
2027 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2030 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2032 count = MsiRecordGetFieldCount( hrec );
2033 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2036 r = MsiRecordGetString( hrec, 1, buf, &size );
2037 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2038 ok( !lstrcmp( buf, join_res_third[i].one ),
2039 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_third[i].one, buf );
2042 r = MsiRecordGetString( hrec, 2, buf, &size );
2043 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2044 ok( !lstrcmp( buf, join_res_third[i].two ),
2045 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_third[i].two, buf );
2048 MsiCloseHandle(hrec);
2051 ok( i == 2, "Expected 2 rows, got %d\n", i );
2053 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2055 MsiViewClose(hview);
2056 MsiCloseHandle(hview);
2058 query = "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
2059 "FROM `StdDlls`, `Binary` "
2060 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
2062 r = MsiDatabaseOpenView(hdb, query, &hview);
2063 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2065 r = MsiViewExecute(hview, 0);
2066 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2069 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2071 count = MsiRecordGetFieldCount( hrec );
2072 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2075 r = MsiRecordGetString( hrec, 1, buf, &size );
2076 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2077 ok( !lstrcmp( buf, join_res_fourth[i].one ),
2078 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_fourth[i].one, buf );
2081 r = MsiRecordGetString( hrec, 2, buf, &size );
2082 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2083 ok( !lstrcmp( buf, join_res_fourth[i].two ),
2084 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_fourth[i].two, buf );
2087 MsiCloseHandle(hrec);
2090 ok( i == 1, "Expected 1 rows, got %d\n", i );
2092 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2094 MsiViewClose(hview);
2095 MsiCloseHandle(hview);
2097 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2098 "FROM `Component`, `FeatureComponents` "
2099 "WHERE `Component`.`Component` = 'zygomatic' "
2100 "AND `FeatureComponents`.`Component_` = 'maxilla' "
2101 "ORDER BY `Feature_`";
2102 r = MsiDatabaseOpenView(hdb, query, &hview);
2105 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2108 r = MsiViewExecute(hview, 0);
2111 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2115 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2117 count = MsiRecordGetFieldCount( hrec );
2118 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2121 r = MsiRecordGetString( hrec, 1, buf, &size );
2122 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2123 ok( !lstrcmp( buf, join_res_fifth[i].one ),
2124 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_fifth[i].one, buf );
2127 r = MsiRecordGetString( hrec, 2, buf, &size );
2128 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2129 ok( !lstrcmp( buf, join_res_fifth[i].two ),
2130 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_fifth[i].two, buf );
2133 MsiCloseHandle(hrec);
2138 ok( i == 1, "Expected 1 rows, got %d\n", i );
2143 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2146 MsiViewClose(hview);
2147 MsiCloseHandle(hview);
2149 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2150 "FROM `Component`, `FeatureComponents` "
2151 "WHERE `Component` = 'zygomatic' "
2152 "ORDER BY `Feature_`";
2153 r = MsiDatabaseOpenView(hdb, query, &hview);
2156 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2159 r = MsiViewExecute(hview, 0);
2162 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2166 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2168 count = MsiRecordGetFieldCount( hrec );
2169 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2172 r = MsiRecordGetString( hrec, 1, buf, &size );
2173 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2174 ok( !lstrcmp( buf, join_res_sixth[i].one ),
2175 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_sixth[i].one, buf );
2178 r = MsiRecordGetString( hrec, 2, buf, &size );
2179 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2180 ok( !lstrcmp( buf, join_res_sixth[i].two ),
2181 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_sixth[i].two, buf );
2184 MsiCloseHandle(hrec);
2189 ok( i == 6, "Expected 6 rows, got %d\n", i );
2194 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2197 MsiViewClose(hview);
2198 MsiCloseHandle(hview);
2200 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2201 "FROM `Component`, `FeatureComponents` "
2202 "WHERE `Component` = 'zygomatic' "
2203 "AND `Feature_` = 'nasalis' "
2204 "ORDER BY `Feature_`";
2205 r = MsiDatabaseOpenView(hdb, query, &hview);
2208 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2211 r = MsiViewExecute(hview, 0);
2214 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2218 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2220 count = MsiRecordGetFieldCount( hrec );
2221 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2224 r = MsiRecordGetString( hrec, 1, buf, &size );
2225 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2226 ok( !lstrcmp( buf, join_res_seventh[i].one ),
2227 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_seventh[i].one, buf );
2230 r = MsiRecordGetString( hrec, 2, buf, &size );
2231 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2232 ok( !lstrcmp( buf, join_res_seventh[i].two ),
2233 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_seventh[i].two, buf );
2236 MsiCloseHandle(hrec);
2241 ok( i == 3, "Expected 3 rows, got %d\n", i );
2246 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2249 MsiViewClose(hview);
2250 MsiCloseHandle(hview);
2252 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2253 "FROM `StdDlls`, `Binary` ";
2254 r = MsiDatabaseOpenView(hdb, query, &hview);
2257 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2260 r = MsiViewExecute(hview, 0);
2263 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2267 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2269 count = MsiRecordGetFieldCount( hrec );
2270 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2273 r = MsiRecordGetString( hrec, 1, buf, &size );
2274 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2275 ok( !lstrcmp( buf, join_res_eighth[i].one ),
2276 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_eighth[i].one, buf );
2279 r = MsiRecordGetString( hrec, 2, buf, &size );
2280 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2281 ok( !lstrcmp( buf, join_res_eighth[i].four ),
2282 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_eighth[i].four, buf );
2285 MsiCloseHandle(hrec);
2290 ok( i == 6, "Expected 6 rows, got %d\n", i );
2291 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2294 MsiViewClose(hview);
2295 MsiCloseHandle(hview);
2297 query = "SELECT * FROM `StdDlls`, `Binary` ";
2298 r = MsiDatabaseOpenView(hdb, query, &hview);
2301 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2304 r = MsiViewExecute(hview, 0);
2307 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2311 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2313 count = MsiRecordGetFieldCount( hrec );
2314 ok( count == 4, "Expected 4 record fields, got %d\n", count );
2317 r = MsiRecordGetString( hrec, 1, buf, &size );
2318 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2319 ok( !lstrcmp( buf, join_res_eighth[i].one ),
2320 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_eighth[i].one, buf );
2323 r = MsiRecordGetString( hrec, 2, buf, &size );
2324 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2325 ok( !lstrcmp( buf, join_res_eighth[i].two ),
2326 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_eighth[i].two, buf );
2329 r = MsiRecordGetString( hrec, 3, buf, &size );
2330 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2331 ok( !lstrcmp( buf, join_res_eighth[i].three ),
2332 "For (row %d, column 3) expected '%s', go %s\n", i, join_res_eighth[i].three, buf );
2335 r = MsiRecordGetString( hrec, 4, buf, &size );
2336 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2337 ok( !lstrcmp( buf, join_res_eighth[i].four ),
2338 "For (row %d, column 4) expected '%s', got %s\n", i, join_res_eighth[i].four, buf );
2341 MsiCloseHandle(hrec);
2346 ok( i == 6, "Expected 6 rows, got %d\n", i );
2347 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2350 MsiViewClose(hview);
2351 MsiCloseHandle(hview);
2353 MsiCloseHandle(hdb);
2354 DeleteFile(msifile);
2357 static void test_temporary_table(void)
2360 MSIHANDLE hdb = 0, view = 0, rec;
2366 cond = MsiDatabaseIsTablePersistent(0, NULL);
2367 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
2370 ok( hdb, "failed to create db\n");
2372 cond = MsiDatabaseIsTablePersistent(hdb, NULL);
2373 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
2376 cond = MsiDatabaseIsTablePersistent(hdb, "_Tables");
2377 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2379 cond = MsiDatabaseIsTablePersistent(hdb, "_Columns");
2380 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2382 cond = MsiDatabaseIsTablePersistent(hdb, "_Streams");
2383 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2386 query = "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
2387 r = run_query(hdb, 0, query);
2388 ok(r == ERROR_SUCCESS, "failed to add table\n");
2390 cond = MsiDatabaseIsTablePersistent(hdb, "P");
2391 todo_wine ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
2393 query = "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
2394 r = run_query(hdb, 0, query);
2395 ok(r == ERROR_SUCCESS, "failed to add table\n");
2398 cond = MsiDatabaseIsTablePersistent(hdb, "P");
2399 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
2402 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
2403 r = run_query(hdb, 0, query);
2404 ok(r == ERROR_SUCCESS, "failed to add table\n");
2406 cond = MsiDatabaseIsTablePersistent(hdb, "T");
2407 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
2409 query = "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
2410 r = run_query(hdb, 0, query);
2411 ok(r == ERROR_SUCCESS, "failed to add table\n");
2414 cond = MsiDatabaseIsTablePersistent(hdb, "T2");
2415 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2418 query = "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
2419 r = run_query(hdb, 0, query);
2420 ok(r == ERROR_SUCCESS, "failed to add table\n");
2423 cond = MsiDatabaseIsTablePersistent(hdb, "T3");
2424 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
2426 query = "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
2427 r = run_query(hdb, 0, query);
2428 ok(r == ERROR_FUNCTION_FAILED, "failed to add table\n");
2430 cond = MsiDatabaseIsTablePersistent(hdb, "T4");
2431 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2434 query = "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
2435 r = run_query(hdb, 0, query);
2436 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add table\n");
2438 query = "select * from `T`";
2439 r = MsiDatabaseOpenView(hdb, query, &view);
2440 ok(r == ERROR_SUCCESS, "failed to query table\n");
2441 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2442 ok(r == ERROR_SUCCESS, "failed to get column info\n");
2445 r = MsiRecordGetString(rec, 1, buf, &sz);
2446 ok(r == ERROR_SUCCESS, "failed to get string\n");
2447 todo_wine ok( 0 == strcmp("G255", buf), "wrong column type\n");
2450 r = MsiRecordGetString(rec, 2, buf, &sz);
2451 ok(r == ERROR_SUCCESS, "failed to get string\n");
2452 todo_wine ok( 0 == strcmp("j2", buf), "wrong column type\n");
2454 MsiCloseHandle( rec );
2455 MsiCloseHandle( view );
2457 /* query the table data */
2459 r = do_query(hdb, "select * from `_Tables` where `Name` = 'T'", &rec);
2460 ok( r == ERROR_SUCCESS, "temporary table exists in _Tables\n");
2461 MsiCloseHandle( rec );
2464 /* query the column data */
2466 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec);
2467 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
2468 if (rec) MsiCloseHandle( rec );
2470 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec);
2471 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
2472 if (rec) MsiCloseHandle( rec );
2475 MsiCloseHandle( hdb );
2477 DeleteFile(msifile);
2480 static void test_alter(void)
2488 ok( hdb, "failed to create db\n");
2490 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
2491 r = run_query(hdb, 0, query);
2492 ok(r == ERROR_SUCCESS, "failed to add table\n");
2494 cond = MsiDatabaseIsTablePersistent(hdb, "T");
2495 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
2498 query = "ALTER TABLE `T` HOLD";
2499 r = run_query(hdb, 0, query);
2500 ok(r == ERROR_SUCCESS, "failed to hold table %d\n", r);
2502 query = "ALTER TABLE `T` FREE";
2503 r = run_query(hdb, 0, query);
2504 ok(r == ERROR_SUCCESS, "failed to free table\n");
2506 query = "ALTER TABLE `T` FREE";
2507 r = run_query(hdb, 0, query);
2508 ok(r == ERROR_SUCCESS, "failed to free table\n");
2511 query = "ALTER TABLE `T` FREE";
2512 r = run_query(hdb, 0, query);
2513 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to free table\n");
2515 query = "ALTER TABLE `T` HOLD";
2516 r = run_query(hdb, 0, query);
2517 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to hold table %d\n", r);
2519 MsiCloseHandle( hdb );
2521 DeleteFile(msifile);
2528 test_msidecomposedesc();
2529 test_msibadqueries();
2531 test_viewgetcolumninfo();
2539 test_handle_limit();
2540 test_generate_transform();
2542 test_temporary_table();