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");
1317 query = "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1318 r = MsiDatabaseOpenView(hdb, query, &view);
1319 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1321 r = MsiViewExecute(view, 0);
1322 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1324 r = MsiViewFetch(view, &rec);
1325 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1327 count = MsiRecordGetFieldCount( rec );
1328 ok( count == 1, "Expected 1 record fields, got %d\n", count );
1331 r = MsiRecordGetString( rec, 1, buf, &size );
1332 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1333 ok( !lstrcmp( buf, "2" ),
1334 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf );
1336 r = MsiViewFetch(view, &rec);
1337 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1340 r = MsiRecordGetString( rec, 1, buf, &size );
1341 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1342 ok( !lstrcmp( buf, "3" ),
1343 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf );
1345 r = MsiViewFetch(view, &rec);
1346 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
1349 MsiCloseHandle(view);
1351 MsiCloseHandle( rec );
1353 MsiCloseHandle( hdb );
1354 DeleteFile(msifile);
1357 static CHAR CURR_DIR[MAX_PATH];
1359 static const CHAR test_data[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1360 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1361 "TestTable\tFirstPrimaryColumn\n"
1362 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1364 static void write_file(const CHAR *filename, const char *data, int data_size)
1368 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
1369 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1371 WriteFile(hf, data, data_size, &size, NULL);
1375 static UINT add_table_to_db(MSIHANDLE hdb, LPCSTR table_data)
1379 write_file("temp_file", table_data, (lstrlen(table_data) - 1) * sizeof(char));
1380 r = MsiDatabaseImportA(hdb, CURR_DIR, "temp_file");
1381 DeleteFileA("temp_file");
1386 static void test_msiimport(void)
1388 MSIHANDLE hdb, view, rec;
1393 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
1395 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
1396 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1398 r = add_table_to_db(hdb, test_data);
1401 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1404 query = "SELECT * FROM `TestTable`";
1405 r = MsiDatabaseOpenView(hdb, query, &view);
1408 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1411 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
1412 count = MsiRecordGetFieldCount(rec);
1415 ok(count == 9, "Expected 9, got %d\n", count);
1416 ok(check_record(rec, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
1417 ok(check_record(rec, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
1418 ok(check_record(rec, 3, "ShortInt"), "Expected ShortInt\n");
1419 ok(check_record(rec, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
1420 ok(check_record(rec, 5, "LongInt"), "Expected LongInt\n");
1421 ok(check_record(rec, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
1422 ok(check_record(rec, 7, "String"), "Expected String\n");
1423 ok(check_record(rec, 8, "LocalizableString"), "Expected LocalizableString\n");
1424 ok(check_record(rec, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
1427 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
1428 count = MsiRecordGetFieldCount(rec);
1431 ok(count == 9, "Expected 9, got %d\n", count);
1432 ok(check_record(rec, 1, "s255"), "Expected s255\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, 4, "I2"), "Expected I2\n");
1436 ok(check_record(rec, 5, "i4"), "Expected i4\n");
1437 ok(check_record(rec, 6, "I4"), "Expected I4\n");
1438 ok(check_record(rec, 7, "S255"), "Expected S255\n");
1439 ok(check_record(rec, 8, "S0"), "Expected S0\n");
1440 ok(check_record(rec, 9, "s0"), "Expected s0\n");
1443 query = "SELECT * FROM `TestTable`";
1444 r = do_query(hdb, query, &rec);
1447 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1452 ok(check_record(rec, 1, "stringage"), "Expected 'stringage'\n");
1453 ok(check_record(rec, 7, "another string"), "Expected 'another string'\n");
1454 ok(check_record(rec, 8, "localizable"), "Expected 'localizable'\n");
1455 ok(check_record(rec, 9, "duh"), "Expected 'duh'\n");
1458 i = MsiRecordGetInteger(rec, 2);
1461 ok(i == 5, "Expected 5, got %d\n", i);
1464 i = MsiRecordGetInteger(rec, 3);
1467 ok(i == 2, "Expected 2, got %d\n", i);
1470 i = MsiRecordGetInteger(rec, 4);
1471 ok(i == 0x80000000, "Expected 0x80000000, got %d\n", i);
1473 i = MsiRecordGetInteger(rec, 5);
1476 ok(i == 2147483640, "Expected 2147483640, got %d\n", i);
1479 i = MsiRecordGetInteger(rec, 6);
1482 ok(i == -2147483640, "Expected -2147483640, got %d\n", i);
1485 MsiCloseHandle(rec);
1486 MsiCloseHandle(view);
1487 MsiCloseHandle(hdb);
1488 DeleteFileA(msifile);
1491 static void test_markers(void)
1498 ok( hdb, "failed to create db\n");
1500 rec = MsiCreateRecord(3);
1501 MsiRecordSetString(rec, 1, "Table");
1502 MsiRecordSetString(rec, 2, "Apples");
1503 MsiRecordSetString(rec, 3, "Oranges");
1505 /* try a legit create */
1506 query = "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1507 r = run_query(hdb, 0, query);
1508 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1509 MsiCloseHandle(rec);
1511 /* try table name as marker */
1512 rec = MsiCreateRecord(1);
1513 MsiRecordSetString(rec, 1, "Fable");
1514 query = "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1515 r = run_query(hdb, rec, query);
1516 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1518 /* verify that we just created a table called '?', not 'Fable' */
1519 r = try_query(hdb, "SELECT * from `Fable`");
1520 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1522 r = try_query(hdb, "SELECT * from `?`");
1523 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1525 /* try table name as marker without backticks */
1526 MsiRecordSetString(rec, 1, "Mable");
1527 query = "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1528 r = run_query(hdb, rec, query);
1529 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1531 /* try one column name as marker */
1532 MsiRecordSetString(rec, 1, "One");
1533 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1534 r = run_query(hdb, rec, query);
1535 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1537 /* try column names as markers */
1538 MsiCloseHandle(rec);
1539 rec = MsiCreateRecord(2);
1540 MsiRecordSetString(rec, 1, "One");
1541 MsiRecordSetString(rec, 2, "Two");
1542 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
1543 r = run_query(hdb, rec, query);
1544 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1546 /* try names with backticks */
1547 MsiCloseHandle(rec);
1548 rec = MsiCreateRecord(3);
1549 MsiRecordSetString(rec, 1, "One");
1550 MsiRecordSetString(rec, 2, "Two");
1551 MsiRecordSetString(rec, 3, "One");
1552 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1553 r = run_query(hdb, rec, query);
1554 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1556 /* try names with backticks, minus definitions */
1557 query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
1558 r = run_query(hdb, rec, query);
1559 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1561 /* try names without backticks */
1562 query = "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
1563 r = run_query(hdb, rec, query);
1564 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1566 /* try one long marker */
1567 MsiCloseHandle(rec);
1568 rec = MsiCreateRecord(1);
1569 MsiRecordSetString(rec, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
1570 query = "CREATE TABLE `Mable` ( ? )";
1571 r = run_query(hdb, rec, query);
1572 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1574 /* try all names as markers */
1575 MsiCloseHandle(rec);
1576 rec = MsiCreateRecord(4);
1577 MsiRecordSetString(rec, 1, "Mable");
1578 MsiRecordSetString(rec, 2, "One");
1579 MsiRecordSetString(rec, 3, "Two");
1580 MsiRecordSetString(rec, 4, "One");
1581 query = "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1582 r = run_query(hdb, rec, query);
1583 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1585 /* try a legit insert */
1586 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
1587 r = run_query(hdb, 0, query);
1588 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1590 r = try_query(hdb, "SELECT * from `Table`");
1591 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1593 /* try values as markers */
1594 MsiCloseHandle(rec);
1595 rec = MsiCreateRecord(2);
1596 MsiRecordSetInteger(rec, 1, 4);
1597 MsiRecordSetString(rec, 2, "hi");
1598 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1599 r = run_query(hdb, rec, query);
1600 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1602 /* try column names and values as markers */
1603 MsiCloseHandle(rec);
1604 rec = MsiCreateRecord(4);
1605 MsiRecordSetString(rec, 1, "One");
1606 MsiRecordSetString(rec, 2, "Two");
1607 MsiRecordSetInteger(rec, 3, 5);
1608 MsiRecordSetString(rec, 4, "hi");
1609 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
1610 r = run_query(hdb, rec, query);
1611 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1613 /* try column names as markers */
1614 MsiCloseHandle(rec);
1615 rec = MsiCreateRecord(2);
1616 MsiRecordSetString(rec, 1, "One");
1617 MsiRecordSetString(rec, 2, "Two");
1618 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
1619 r = run_query(hdb, rec, query);
1620 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1622 /* try table name as a marker */
1623 MsiCloseHandle(rec);
1624 rec = MsiCreateRecord(1);
1625 MsiRecordSetString(rec, 1, "Table");
1626 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
1627 r = run_query(hdb, rec, query);
1628 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1630 /* try table name and values as markers */
1631 MsiCloseHandle(rec);
1632 rec = MsiCreateRecord(3);
1633 MsiRecordSetString(rec, 1, "Table");
1634 MsiRecordSetInteger(rec, 2, 10);
1635 MsiRecordSetString(rec, 3, "haha");
1636 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
1637 r = run_query(hdb, rec, query);
1638 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
1640 /* try all markers */
1641 MsiCloseHandle(rec);
1642 rec = MsiCreateRecord(5);
1643 MsiRecordSetString(rec, 1, "Table");
1644 MsiRecordSetString(rec, 1, "One");
1645 MsiRecordSetString(rec, 1, "Two");
1646 MsiRecordSetInteger(rec, 2, 10);
1647 MsiRecordSetString(rec, 3, "haha");
1648 query = "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
1649 r = run_query(hdb, rec, query);
1650 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1652 /* insert an integer as a string */
1653 MsiCloseHandle(rec);
1654 rec = MsiCreateRecord(2);
1655 MsiRecordSetString(rec, 1, "11");
1656 MsiRecordSetString(rec, 2, "hi");
1657 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1658 r = run_query(hdb, rec, query);
1659 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1661 /* leave off the '' for the string */
1662 MsiCloseHandle(rec);
1663 rec = MsiCreateRecord(2);
1664 MsiRecordSetInteger(rec, 1, 12);
1665 MsiRecordSetString(rec, 2, "hi");
1666 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
1667 r = run_query(hdb, rec, query);
1668 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1669 MsiCloseHandle(rec);
1671 MsiCloseHandle(hdb);
1672 DeleteFileA(msifile);
1675 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
1676 static void test_handle_limit(void)
1680 MSIHANDLE hviews[MY_NVIEWS];
1683 /* create an empty db */
1685 ok( hdb, "failed to create db\n");
1687 memset(hviews, 0, sizeof(hviews));
1689 for (i=0; i<MY_NVIEWS; i++) {
1690 static char szQueryBuf[256] = "SELECT * from `_Tables`";
1691 hviews[i] = 0xdeadbeeb;
1692 r = MsiDatabaseOpenView(hdb, szQueryBuf, &hviews[i]);
1693 if( r != ERROR_SUCCESS || hviews[i] == 0xdeadbeeb ||
1694 hviews[i] == 0 || (i && (hviews[i] == hviews[i-1])))
1698 ok( i == MY_NVIEWS, "problem opening views\n");
1700 for (i=0; i<MY_NVIEWS; i++) {
1701 if (hviews[i] != 0 && hviews[i] != 0xdeadbeeb) {
1702 r = MsiCloseHandle(hviews[i]);
1703 if (r != ERROR_SUCCESS)
1708 ok( i == MY_NVIEWS, "problem closing views\n");
1710 r = MsiCloseHandle(hdb);
1711 ok( r == ERROR_SUCCESS, "failed to close database\n");
1714 static void test_generate_transform(void)
1716 MSIHANDLE hdb1, hdb2;
1720 DeleteFile(msifile);
1721 DeleteFile(msifile2);
1722 DeleteFile(mstfile);
1724 /* create an empty database */
1725 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb1 );
1726 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
1728 r = MsiDatabaseCommit( hdb1 );
1729 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1731 /* create another empty database */
1732 r = MsiOpenDatabase(msifile2, MSIDBOPEN_CREATE, &hdb2 );
1733 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
1735 r = MsiDatabaseCommit( hdb2 );
1736 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1738 /* the transform between two empty database should be empty */
1739 r = MsiDatabaseGenerateTransform(hdb1, hdb2, NULL, 0, 0);
1741 ok( r == ERROR_NO_DATA, "return code %d, should be ERROR_NO_DATA\n", r );
1744 query = "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
1745 r = run_query(hdb1, 0, query);
1746 ok(r == ERROR_SUCCESS, "failed to add table\n");
1749 r = MsiDatabaseGenerateTransform(hdb1, hdb2, NULL, 0, 0);
1750 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
1752 r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
1753 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
1755 MsiCloseHandle( hdb1 );
1757 r = MsiDatabaseApplyTransform( hdb2, mstfile, 0 );
1758 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
1760 /* apply the same transform again? */
1761 r = MsiDatabaseApplyTransform( hdb2, mstfile, 0 );
1762 ok( r == ERROR_INSTALL_TRANSFORM_FAILURE,
1763 "return code %d, should be ERROR_INSTALL_TRANSFORM_FAILURE\n", r );
1766 MsiCloseHandle( hdb2 );
1768 DeleteFile(msifile);
1769 DeleteFile(msifile2);
1770 DeleteFile(mstfile);
1775 const CHAR one[MAX_PATH];
1776 const CHAR two[MAX_PATH];
1779 struct join_res_4col
1781 const CHAR one[MAX_PATH];
1782 const CHAR two[MAX_PATH];
1783 const CHAR three[MAX_PATH];
1784 const CHAR four[MAX_PATH];
1787 static const struct join_res join_res_first[] =
1789 { "alveolar", "procerus" },
1790 { "septum", "procerus" },
1791 { "septum", "nasalis" },
1792 { "ramus", "nasalis" },
1793 { "malar", "mentalis" },
1796 static const struct join_res join_res_second[] =
1798 { "nasal", "septum" },
1799 { "mandible", "ramus" },
1802 static const struct join_res join_res_third[] =
1804 { "msvcp.dll", "abcdefgh" },
1805 { "msvcr.dll", "ijklmnop" },
1808 static const struct join_res join_res_fourth[] =
1810 { "msvcp.dll.01234", "single.dll.31415" },
1813 static const struct join_res join_res_fifth[] =
1815 { "malar", "procerus" },
1818 static const struct join_res join_res_sixth[] =
1820 { "malar", "procerus" },
1821 { "malar", "procerus" },
1822 { "malar", "nasalis" },
1823 { "malar", "nasalis" },
1824 { "malar", "nasalis" },
1825 { "malar", "mentalis" },
1828 static const struct join_res join_res_seventh[] =
1830 { "malar", "nasalis" },
1831 { "malar", "nasalis" },
1832 { "malar", "nasalis" },
1835 static const struct join_res_4col join_res_eighth[] =
1837 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
1838 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
1839 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
1840 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
1841 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
1842 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
1845 static void test_join(void)
1847 MSIHANDLE hdb, hview, hrec;
1854 ok( hdb, "failed to create db\n");
1856 r = create_component_table( hdb );
1857 ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
1859 r = add_component_entry( hdb, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
1860 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1862 r = add_component_entry( hdb, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
1863 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1865 r = add_component_entry( hdb, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
1866 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1868 r = add_component_entry( hdb, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
1869 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
1871 r = create_feature_components_table( hdb );
1872 ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
1874 r = add_feature_components_entry( hdb, "'procerus', 'maxilla'" );
1875 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1877 r = add_feature_components_entry( hdb, "'procerus', 'nasal'" );
1878 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1880 r = add_feature_components_entry( hdb, "'nasalis', 'nasal'" );
1881 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1883 r = add_feature_components_entry( hdb, "'nasalis', 'mandible'" );
1884 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1886 r = add_feature_components_entry( hdb, "'nasalis', 'notacomponent'" );
1887 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1889 r = add_feature_components_entry( hdb, "'mentalis', 'zygomatic'" );
1890 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
1892 r = create_std_dlls_table( hdb );
1893 ok( r == ERROR_SUCCESS, "cannot create StdDlls table: %d\n", r );
1895 r = add_std_dlls_entry( hdb, "'msvcp.dll', 'msvcp.dll.01234'" );
1896 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
1898 r = add_std_dlls_entry( hdb, "'msvcr.dll', 'msvcr.dll.56789'" );
1899 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
1901 r = create_binary_table( hdb );
1902 ok( r == ERROR_SUCCESS, "cannot create Binary table: %d\n", r );
1904 r = add_binary_entry( hdb, "'msvcp.dll.01234', 'abcdefgh'" );
1905 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
1907 r = add_binary_entry( hdb, "'msvcr.dll.56789', 'ijklmnop'" );
1908 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
1910 r = add_binary_entry( hdb, "'single.dll.31415', 'msvcp.dll'" );
1911 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
1913 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
1914 "FROM `Component`, `FeatureComponents` "
1915 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
1916 "ORDER BY `Feature_`";
1917 r = MsiDatabaseOpenView(hdb, query, &hview);
1918 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1920 r = MsiViewExecute(hview, 0);
1921 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1924 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
1926 count = MsiRecordGetFieldCount( hrec );
1927 ok( count == 2, "Expected 2 record fields, got %d\n", count );
1930 r = MsiRecordGetString( hrec, 1, buf, &size );
1931 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1932 if (i == 2 || i == 3) todo_wine
1934 ok( !lstrcmp( buf, join_res_first[i].one ),
1935 "For (row %ld, column 1) expected '%s', got %s\n", i, join_res_first[i].one, buf );
1939 r = MsiRecordGetString( hrec, 2, buf, &size );
1940 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1941 if (i == 3) todo_wine
1943 ok( !lstrcmp( buf, join_res_first[i].two ),
1944 "For (row %ld, column 2) expected '%s', got %s\n", i, join_res_first[i].two, buf );
1948 MsiCloseHandle(hrec);
1953 ok( i == 5, "Expected 5 rows, got %ld\n", i );
1956 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
1958 MsiViewClose(hview);
1959 MsiCloseHandle(hview);
1961 query = "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
1962 "WHERE FeatureComponents.Component_=Component.Component "
1963 "AND (Feature_='nasalis') ORDER BY Feature_";
1964 r = MsiDatabaseOpenView(hdb, query, &hview);
1967 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1970 r = MsiViewExecute(hview, 0);
1973 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1977 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
1979 count = MsiRecordGetFieldCount( hrec );
1980 ok( count == 2, "Expected 2 record fields, got %d\n", count );
1983 r = MsiRecordGetString( hrec, 1, buf, &size );
1984 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1985 ok( !lstrcmp( buf, join_res_second[i].one ),
1986 "For (row %ld, column 1) expected '%s', got %s\n", i, join_res_second[i].one, buf );
1989 r = MsiRecordGetString( hrec, 2, buf, &size );
1990 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1991 ok( !lstrcmp( buf, join_res_second[i].two ),
1992 "For (row %ld, column 2) expected '%s', got %s\n", i, join_res_second[i].two, buf );
1995 MsiCloseHandle(hrec);
2000 ok( i == 2, "Expected 2 rows, got %ld\n", i );
2005 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2008 MsiViewClose(hview);
2009 MsiCloseHandle(hview);
2011 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2012 "FROM `StdDlls`, `Binary` "
2013 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
2015 r = MsiDatabaseOpenView(hdb, query, &hview);
2016 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2018 r = MsiViewExecute(hview, 0);
2019 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2022 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2024 count = MsiRecordGetFieldCount( hrec );
2025 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2028 r = MsiRecordGetString( hrec, 1, buf, &size );
2029 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2030 ok( !lstrcmp( buf, join_res_third[i].one ),
2031 "For (row %ld, column 1) expected '%s', got %s\n", i, join_res_third[i].one, buf );
2034 r = MsiRecordGetString( hrec, 2, buf, &size );
2035 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2036 ok( !lstrcmp( buf, join_res_third[i].two ),
2037 "For (row %ld, column 2) expected '%s', got %s\n", i, join_res_third[i].two, buf );
2040 MsiCloseHandle(hrec);
2043 ok( i == 2, "Expected 2 rows, got %ld\n", i );
2045 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2047 MsiViewClose(hview);
2048 MsiCloseHandle(hview);
2050 query = "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
2051 "FROM `StdDlls`, `Binary` "
2052 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
2054 r = MsiDatabaseOpenView(hdb, query, &hview);
2055 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2057 r = MsiViewExecute(hview, 0);
2058 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2061 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2063 count = MsiRecordGetFieldCount( hrec );
2064 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2067 r = MsiRecordGetString( hrec, 1, buf, &size );
2068 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2069 ok( !lstrcmp( buf, join_res_fourth[i].one ),
2070 "For (row %ld, column 1) expected '%s', got %s\n", i, join_res_fourth[i].one, buf );
2073 r = MsiRecordGetString( hrec, 2, buf, &size );
2074 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2075 ok( !lstrcmp( buf, join_res_fourth[i].two ),
2076 "For (row %ld, column 2) expected '%s', got %s\n", i, join_res_fourth[i].two, buf );
2079 MsiCloseHandle(hrec);
2082 ok( i == 1, "Expected 1 rows, got %ld\n", i );
2084 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2086 MsiViewClose(hview);
2087 MsiCloseHandle(hview);
2089 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2090 "FROM `Component`, `FeatureComponents` "
2091 "WHERE `Component`.`Component` = 'zygomatic' "
2092 "AND `FeatureComponents`.`Component_` = 'maxilla' "
2093 "ORDER BY `Feature_`";
2094 r = MsiDatabaseOpenView(hdb, query, &hview);
2097 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2100 r = MsiViewExecute(hview, 0);
2103 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2107 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2109 count = MsiRecordGetFieldCount( hrec );
2110 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2113 r = MsiRecordGetString( hrec, 1, buf, &size );
2114 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2115 ok( !lstrcmp( buf, join_res_fifth[i].one ),
2116 "For (row %ld, column 1) expected '%s', got %s\n", i, join_res_fifth[i].one, buf );
2119 r = MsiRecordGetString( hrec, 2, buf, &size );
2120 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2121 ok( !lstrcmp( buf, join_res_fifth[i].two ),
2122 "For (row %ld, column 2) expected '%s', got %s\n", i, join_res_fifth[i].two, buf );
2125 MsiCloseHandle(hrec);
2130 ok( i == 1, "Expected 1 rows, got %ld\n", i );
2135 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2138 MsiViewClose(hview);
2139 MsiCloseHandle(hview);
2141 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2142 "FROM `Component`, `FeatureComponents` "
2143 "WHERE `Component` = 'zygomatic' "
2144 "ORDER BY `Feature_`";
2145 r = MsiDatabaseOpenView(hdb, query, &hview);
2148 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2151 r = MsiViewExecute(hview, 0);
2154 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2158 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2160 count = MsiRecordGetFieldCount( hrec );
2161 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2164 r = MsiRecordGetString( hrec, 1, buf, &size );
2165 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2166 ok( !lstrcmp( buf, join_res_sixth[i].one ),
2167 "For (row %ld, column 1) expected '%s', got %s\n", i, join_res_sixth[i].one, buf );
2170 r = MsiRecordGetString( hrec, 2, buf, &size );
2171 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2172 ok( !lstrcmp( buf, join_res_sixth[i].two ),
2173 "For (row %ld, column 2) expected '%s', got %s\n", i, join_res_sixth[i].two, buf );
2176 MsiCloseHandle(hrec);
2181 ok( i == 6, "Expected 6 rows, got %ld\n", i );
2186 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2189 MsiViewClose(hview);
2190 MsiCloseHandle(hview);
2192 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2193 "FROM `Component`, `FeatureComponents` "
2194 "WHERE `Component` = 'zygomatic' "
2195 "AND `Feature_` = 'nasalis' "
2196 "ORDER BY `Feature_`";
2197 r = MsiDatabaseOpenView(hdb, query, &hview);
2200 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2203 r = MsiViewExecute(hview, 0);
2206 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2210 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2212 count = MsiRecordGetFieldCount( hrec );
2213 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2216 r = MsiRecordGetString( hrec, 1, buf, &size );
2217 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2218 ok( !lstrcmp( buf, join_res_seventh[i].one ),
2219 "For (row %ld, column 1) expected '%s', got %s\n", i, join_res_seventh[i].one, buf );
2222 r = MsiRecordGetString( hrec, 2, buf, &size );
2223 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2224 ok( !lstrcmp( buf, join_res_seventh[i].two ),
2225 "For (row %ld, column 2) expected '%s', got %s\n", i, join_res_seventh[i].two, buf );
2228 MsiCloseHandle(hrec);
2233 ok( i == 3, "Expected 3 rows, got %ld\n", i );
2238 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2241 MsiViewClose(hview);
2242 MsiCloseHandle(hview);
2244 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2245 "FROM `StdDlls`, `Binary` ";
2246 r = MsiDatabaseOpenView(hdb, query, &hview);
2249 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2252 r = MsiViewExecute(hview, 0);
2255 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2259 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2261 count = MsiRecordGetFieldCount( hrec );
2262 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2265 r = MsiRecordGetString( hrec, 1, buf, &size );
2266 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2267 ok( !lstrcmp( buf, join_res_eighth[i].one ),
2268 "For (row %ld, column 1) expected '%s', got %s\n", i, join_res_eighth[i].one, buf );
2271 r = MsiRecordGetString( hrec, 2, buf, &size );
2272 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2273 ok( !lstrcmp( buf, join_res_eighth[i].four ),
2274 "For (row %ld, column 2) expected '%s', got %s\n", i, join_res_eighth[i].four, buf );
2277 MsiCloseHandle(hrec);
2282 ok( i == 6, "Expected 6 rows, got %ld\n", i );
2283 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2286 MsiViewClose(hview);
2287 MsiCloseHandle(hview);
2289 MsiCloseHandle(hdb);
2290 DeleteFile(msifile);
2293 static void test_temporary_table(void)
2296 MSIHANDLE hdb = 0, view = 0, rec;
2302 cond = MsiDatabaseIsTablePersistent(0, NULL);
2303 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
2306 ok( hdb, "failed to create db\n");
2308 cond = MsiDatabaseIsTablePersistent(hdb, NULL);
2309 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
2312 cond = MsiDatabaseIsTablePersistent(hdb, "_Tables");
2313 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2315 cond = MsiDatabaseIsTablePersistent(hdb, "_Columns");
2316 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2318 cond = MsiDatabaseIsTablePersistent(hdb, "_Streams");
2319 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2322 query = "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
2323 r = run_query(hdb, 0, query);
2324 ok(r == ERROR_SUCCESS, "failed to add table\n");
2326 cond = MsiDatabaseIsTablePersistent(hdb, "P");
2327 todo_wine ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
2329 query = "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
2330 r = run_query(hdb, 0, query);
2331 ok(r == ERROR_SUCCESS, "failed to add table\n");
2334 cond = MsiDatabaseIsTablePersistent(hdb, "P");
2335 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
2338 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
2339 r = run_query(hdb, 0, query);
2340 ok(r == ERROR_SUCCESS, "failed to add table\n");
2342 cond = MsiDatabaseIsTablePersistent(hdb, "T");
2343 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
2345 query = "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
2346 r = run_query(hdb, 0, query);
2347 ok(r == ERROR_SUCCESS, "failed to add table\n");
2350 cond = MsiDatabaseIsTablePersistent(hdb, "T2");
2351 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2354 query = "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
2355 r = run_query(hdb, 0, query);
2356 ok(r == ERROR_SUCCESS, "failed to add table\n");
2359 cond = MsiDatabaseIsTablePersistent(hdb, "T3");
2360 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
2362 query = "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
2363 r = run_query(hdb, 0, query);
2364 ok(r == ERROR_FUNCTION_FAILED, "failed to add table\n");
2366 cond = MsiDatabaseIsTablePersistent(hdb, "T4");
2367 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2370 query = "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
2371 r = run_query(hdb, 0, query);
2372 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add table\n");
2374 query = "select * from `T`";
2375 r = MsiDatabaseOpenView(hdb, query, &view);
2376 ok(r == ERROR_SUCCESS, "failed to query table\n");
2377 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2378 ok(r == ERROR_SUCCESS, "failed to get column info\n");
2381 r = MsiRecordGetString(rec, 1, buf, &sz);
2382 ok(r == ERROR_SUCCESS, "failed to get string\n");
2383 todo_wine ok( 0 == strcmp("G255", buf), "wrong column type\n");
2386 r = MsiRecordGetString(rec, 2, buf, &sz);
2387 ok(r == ERROR_SUCCESS, "failed to get string\n");
2388 todo_wine ok( 0 == strcmp("j2", buf), "wrong column type\n");
2390 MsiCloseHandle( rec );
2391 MsiCloseHandle( view );
2393 /* query the table data */
2395 r = do_query(hdb, "select * from `_Tables` where `Name` = 'T'", &rec);
2396 ok( r == ERROR_SUCCESS, "temporary table exists in _Tables\n");
2397 MsiCloseHandle( rec );
2400 /* query the column data */
2402 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec);
2403 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
2405 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec);
2406 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
2409 MsiCloseHandle( hdb );
2411 DeleteFile(msifile);
2414 static void test_alter(void)
2422 ok( hdb, "failed to create db\n");
2424 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
2425 r = run_query(hdb, 0, query);
2426 ok(r == ERROR_SUCCESS, "failed to add table\n");
2428 cond = MsiDatabaseIsTablePersistent(hdb, "T");
2429 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
2432 query = "ALTER TABLE `T` HOLD";
2433 r = run_query(hdb, 0, query);
2434 ok(r == ERROR_SUCCESS, "failed to hold table %d\n", r);
2436 query = "ALTER TABLE `T` FREE";
2437 r = run_query(hdb, 0, query);
2438 ok(r == ERROR_SUCCESS, "failed to free table\n");
2440 query = "ALTER TABLE `T` FREE";
2441 r = run_query(hdb, 0, query);
2442 ok(r == ERROR_SUCCESS, "failed to free table\n");
2445 query = "ALTER TABLE `T` FREE";
2446 r = run_query(hdb, 0, query);
2447 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to free table\n");
2449 query = "ALTER TABLE `T` HOLD";
2450 r = run_query(hdb, 0, query);
2451 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to hold table %d\n", r);
2453 MsiCloseHandle( hdb );
2455 DeleteFile(msifile);
2462 test_msidecomposedesc();
2463 test_msibadqueries();
2465 test_viewgetcolumninfo();
2473 test_handle_limit();
2474 test_generate_transform();
2476 test_temporary_table();