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
31 #include "wine/test.h"
33 static const char *msifile = "winetest.msi";
34 static const char *msifile2 = "winetst2.msi";
35 static const char *mstfile = "winetst.mst";
37 static void test_msidatabase(void)
39 MSIHANDLE hdb = 0, hdb2 = 0;
44 res = MsiOpenDatabase( msifile, msifile2, &hdb );
45 ok( res == ERROR_OPEN_FAILED, "expected failure\n");
47 res = MsiOpenDatabase( msifile, (LPSTR) 0xff, &hdb );
48 ok( res == ERROR_INVALID_PARAMETER, "expected failure\n");
50 res = MsiCloseHandle( hdb );
51 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
53 /* create an empty database */
54 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
55 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
57 res = MsiDatabaseCommit( hdb );
58 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
60 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
62 res = MsiCloseHandle( hdb );
63 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
64 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
65 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
67 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile2 ), "database should exist\n");
69 res = MsiDatabaseCommit( hdb2 );
70 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
72 res = MsiCloseHandle( hdb2 );
73 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
75 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
76 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
78 res = MsiCloseHandle( hdb2 );
79 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
81 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile2 ), "uncommitted database should not exist\n");
83 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
84 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
86 res = MsiDatabaseCommit( hdb2 );
87 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
89 res = MsiCloseHandle( hdb2 );
90 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
92 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile2 ), "committed database should exist\n");
94 res = MsiOpenDatabase( msifile, MSIDBOPEN_READONLY, &hdb );
95 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
97 res = MsiCloseHandle( hdb );
98 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
100 res = MsiOpenDatabase( msifile, MSIDBOPEN_DIRECT, &hdb );
101 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
103 res = MsiCloseHandle( hdb );
104 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
106 res = MsiOpenDatabase( msifile, MSIDBOPEN_TRANSACT, &hdb );
107 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
109 res = MsiCloseHandle( hdb );
110 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
111 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
113 /* MSIDBOPEN_CREATE deletes the database if MsiCommitDatabase isn't called */
114 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
115 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
117 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
119 res = MsiCloseHandle( hdb );
120 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
122 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile ), "database should exist\n");
124 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
125 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
127 res = MsiDatabaseCommit( hdb );
128 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
130 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
132 res = MsiCloseHandle( hdb );
133 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
135 res = DeleteFile( msifile2 );
136 ok( res == TRUE, "Failed to delete database\n" );
138 res = DeleteFile( msifile );
139 ok( res == TRUE, "Failed to delete database\n" );
142 static UINT do_query(MSIHANDLE hdb, const char *query, MSIHANDLE *phrec)
147 /* open a select query */
148 r = MsiDatabaseOpenView(hdb, query, &hview);
149 if (r != ERROR_SUCCESS)
151 r = MsiViewExecute(hview, 0);
152 if (r != ERROR_SUCCESS)
154 ret = MsiViewFetch(hview, phrec);
155 r = MsiViewClose(hview);
156 if (r != ERROR_SUCCESS)
158 r = MsiCloseHandle(hview);
159 if (r != ERROR_SUCCESS)
164 static UINT run_query( MSIHANDLE hdb, MSIHANDLE hrec, const char *query )
169 r = MsiDatabaseOpenView(hdb, query, &hview);
170 if( r != ERROR_SUCCESS )
173 r = MsiViewExecute(hview, hrec);
174 if( r == ERROR_SUCCESS )
175 r = MsiViewClose(hview);
176 MsiCloseHandle(hview);
180 static UINT create_component_table( MSIHANDLE hdb )
182 return run_query( hdb, 0,
183 "CREATE TABLE `Component` ( "
184 "`Component` CHAR(72) NOT NULL, "
185 "`ComponentId` CHAR(38), "
186 "`Directory_` CHAR(72) NOT NULL, "
187 "`Attributes` SHORT NOT NULL, "
188 "`Condition` CHAR(255), "
189 "`KeyPath` CHAR(72) "
190 "PRIMARY KEY `Component`)" );
193 static UINT create_feature_components_table( MSIHANDLE hdb )
195 return run_query( hdb, 0,
196 "CREATE TABLE `FeatureComponents` ( "
197 "`Feature_` CHAR(38) NOT NULL, "
198 "`Component_` CHAR(72) NOT NULL "
199 "PRIMARY KEY `Feature_`, `Component_` )" );
202 static UINT create_std_dlls_table( MSIHANDLE hdb )
204 return run_query( hdb, 0,
205 "CREATE TABLE `StdDlls` ( "
206 "`File` CHAR(255) NOT NULL, "
207 "`Binary_` CHAR(72) NOT NULL "
208 "PRIMARY KEY `File` )" );
211 static UINT create_binary_table( MSIHANDLE hdb )
213 return run_query( hdb, 0,
214 "CREATE TABLE `Binary` ( "
215 "`Name` CHAR(72) NOT NULL, "
216 "`Data` CHAR(72) NOT NULL "
217 "PRIMARY KEY `Name` )" );
220 static UINT add_component_entry( MSIHANDLE hdb, const char *values )
222 char insert[] = "INSERT INTO `Component` "
223 "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `Condition`, `KeyPath`) "
228 sz = strlen(values) + sizeof insert;
229 query = HeapAlloc(GetProcessHeap(),0,sz);
230 sprintf(query,insert,values);
231 r = run_query( hdb, 0, query );
232 HeapFree(GetProcessHeap(), 0, query);
236 static UINT add_feature_components_entry( MSIHANDLE hdb, const char *values )
238 char insert[] = "INSERT INTO `FeatureComponents` "
239 "(`Feature_`, `Component_`) "
244 sz = strlen(values) + sizeof insert;
245 query = HeapAlloc(GetProcessHeap(),0,sz);
246 sprintf(query,insert,values);
247 r = run_query( hdb, 0, query );
248 HeapFree(GetProcessHeap(), 0, query);
252 static UINT add_std_dlls_entry( MSIHANDLE hdb, const char *values )
254 char insert[] = "INSERT INTO `StdDlls` "
255 "(`File`, `Binary_`) "
260 sz = strlen(values) + sizeof insert;
261 query = HeapAlloc(GetProcessHeap(),0,sz);
262 sprintf(query,insert,values);
263 r = run_query( hdb, 0, query );
264 HeapFree(GetProcessHeap(), 0, query);
268 static UINT add_binary_entry( MSIHANDLE hdb, const char *values )
270 char insert[] = "INSERT INTO `Binary` "
276 sz = strlen(values) + sizeof insert;
277 query = HeapAlloc(GetProcessHeap(),0,sz);
278 sprintf(query,insert,values);
279 r = run_query( hdb, 0, query );
280 HeapFree(GetProcessHeap(), 0, query);
284 static void test_msiinsert(void)
286 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
294 /* just MsiOpenDatabase should not create a file */
295 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
296 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
299 query = "CREATE TABLE `phone` ( "
300 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
302 r = MsiDatabaseOpenView(hdb, query, &hview);
303 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
304 r = MsiViewExecute(hview, 0);
305 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
306 r = MsiViewClose(hview);
307 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
308 r = MsiCloseHandle(hview);
309 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
311 /* insert a value into it */
312 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
313 "VALUES('1', 'Abe', '8675309')";
314 r = MsiDatabaseOpenView(hdb, query, &hview);
315 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
316 r = MsiViewExecute(hview, 0);
317 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
318 r = MsiViewClose(hview);
319 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
320 r = MsiCloseHandle(hview);
321 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
323 query = "SELECT * FROM `phone` WHERE `id` = 1";
324 r = do_query(hdb, query, &hrec);
325 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
327 /* check the record contains what we put in it */
328 r = MsiRecordGetFieldCount(hrec);
329 ok(r == 3, "record count wrong\n");
332 r = MsiRecordIsNull(hrec, 0);
333 ok(r == FALSE, "field 0 not null\n");
336 r = MsiRecordGetInteger(hrec, 1);
337 ok(r == 1, "field 1 contents wrong\n");
339 r = MsiRecordGetString(hrec, 2, buf, &sz);
340 ok(r == ERROR_SUCCESS, "field 2 content fetch failed\n");
341 ok(!strcmp(buf,"Abe"), "field 2 content incorrect\n");
343 r = MsiRecordGetString(hrec, 3, buf, &sz);
344 ok(r == ERROR_SUCCESS, "field 3 content fetch failed\n");
345 ok(!strcmp(buf,"8675309"), "field 3 content incorrect\n");
347 r = MsiCloseHandle(hrec);
348 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
350 /* open a select query */
352 query = "SELECT * FROM `phone` WHERE `id` >= 10";
353 r = do_query(hdb, query, &hrec);
354 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
355 ok(hrec == 0, "hrec should be null\n");
357 r = MsiCloseHandle(hrec);
358 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
360 query = "SELECT * FROM `phone` WHERE `id` < 0";
361 r = do_query(hdb, query, &hrec);
362 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
364 query = "SELECT * FROM `phone` WHERE `id` <= 0";
365 r = do_query(hdb, query, &hrec);
366 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
368 query = "SELECT * FROM `phone` WHERE `id` <> 1";
369 r = do_query(hdb, query, &hrec);
370 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
372 query = "SELECT * FROM `phone` WHERE `id` > 10";
373 r = do_query(hdb, query, &hrec);
374 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
376 /* now try a few bad INSERT xqueries */
377 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
379 r = MsiDatabaseOpenView(hdb, query, &hview);
380 ok(r == ERROR_BAD_QUERY_SYNTAX, "MsiDatabaseOpenView failed\n");
382 /* construct a record to insert */
383 hrec = MsiCreateRecord(4);
384 r = MsiRecordSetInteger(hrec, 1, 2);
385 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
386 r = MsiRecordSetString(hrec, 2, "Adam");
387 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
388 r = MsiRecordSetString(hrec, 3, "96905305");
389 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
391 /* insert another value, using a record and wildcards */
392 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
394 r = MsiDatabaseOpenView(hdb, query, &hview);
395 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
397 if (r == ERROR_SUCCESS)
399 r = MsiViewExecute(hview, hrec);
400 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
401 r = MsiViewClose(hview);
402 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
403 r = MsiCloseHandle(hview);
404 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
406 r = MsiCloseHandle(hrec);
407 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
409 r = MsiViewFetch(0, NULL);
410 ok(r == ERROR_INVALID_PARAMETER, "MsiViewFetch failed\n");
412 r = MsiDatabaseCommit(hdb);
413 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
415 r = MsiCloseHandle(hdb);
416 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
418 r = DeleteFile(msifile);
419 ok(r == TRUE, "file didn't exist after commit\n");
422 typedef UINT (WINAPI *fnMsiDecomposeDescriptorA)(LPCSTR, LPCSTR, LPSTR, LPSTR, DWORD *);
423 static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA;
425 static void test_msidecomposedesc(void)
427 char prod[MAX_FEATURE_CHARS+1], comp[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1];
433 hmod = GetModuleHandle("msi.dll");
434 pMsiDecomposeDescriptorA = (fnMsiDecomposeDescriptorA)
435 GetProcAddress(hmod, "MsiDecomposeDescriptorA");
436 if (!pMsiDecomposeDescriptorA)
439 /* test a valid feature descriptor */
440 desc = "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
442 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
443 ok(r == ERROR_SUCCESS, "returned an error\n");
444 ok(len == strlen(desc), "length was wrong\n");
445 ok(strcmp(prod,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
446 ok(strcmp(feature,"FollowTheWhiteRabbit")==0, "feature wrong\n");
447 ok(strcmp(comp,"{A7CD68DB-EF74-49C8-FBB2-A7C463B2AC24}")==0,"component wrong\n");
449 /* test an invalid feature descriptor with too many characters */
450 desc = "']gAVn-}f(ZXfeAR6.ji"
451 "ThisWillFailIfTheresMoreThanAGuidsChars>"
452 "3w2x^IGfe?CxI5heAvk.";
454 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
455 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
458 * Test a valid feature descriptor with the
459 * maximum number of characters and some trailing characters.
461 desc = "']gAVn-}f(ZXfeAR6.ji"
462 "ThisWillWorkIfTheresLTEThanAGuidsChars>"
463 "3w2x^IGfe?CxI5heAvk."
466 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
467 ok(r == ERROR_SUCCESS, "returned wrong error\n");
468 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
471 r = pMsiDecomposeDescriptorA(desc, prod, feature, NULL, &len);
472 ok(r == ERROR_SUCCESS, "returned wrong error\n");
473 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
476 r = pMsiDecomposeDescriptorA(desc, prod, NULL, NULL, &len);
477 ok(r == ERROR_SUCCESS, "returned wrong error\n");
478 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
481 r = pMsiDecomposeDescriptorA(desc, NULL, NULL, NULL, &len);
482 ok(r == ERROR_SUCCESS, "returned wrong error\n");
483 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
486 r = pMsiDecomposeDescriptorA(NULL, NULL, NULL, NULL, &len);
487 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
488 ok(len == 0, "length wrong\n");
491 static UINT try_query_param( MSIHANDLE hdb, LPCSTR szQuery, MSIHANDLE hrec )
496 res = MsiDatabaseOpenView( hdb, szQuery, &htab );
497 if(res == ERROR_SUCCESS )
501 r = MsiViewExecute( htab, hrec );
502 if(r != ERROR_SUCCESS )
505 r = MsiViewClose( htab );
506 if(r != ERROR_SUCCESS )
509 r = MsiCloseHandle( htab );
510 if(r != ERROR_SUCCESS )
516 static UINT try_query( MSIHANDLE hdb, LPCSTR szQuery )
518 return try_query_param( hdb, szQuery, 0 );
521 static UINT try_insert_query( MSIHANDLE hdb, LPCSTR szQuery )
526 hrec = MsiCreateRecord( 1 );
527 MsiRecordSetString( hrec, 1, "Hello");
529 r = try_query_param( hdb, szQuery, hrec );
531 MsiCloseHandle( hrec );
535 static void test_msibadqueries(void)
542 /* just MsiOpenDatabase should not create a file */
543 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
544 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
546 r = MsiDatabaseCommit( hdb );
547 ok(r == ERROR_SUCCESS , "Failed to commit database\n");
549 r = MsiCloseHandle( hdb );
550 ok(r == ERROR_SUCCESS , "Failed to close database\n");
552 /* open it readonly */
553 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb );
554 ok(r == ERROR_SUCCESS , "Failed to open database r/o\n");
556 /* add a table to it */
557 r = try_query( hdb, "select * from _Tables");
558 ok(r == ERROR_SUCCESS , "query 1 failed\n");
560 r = MsiCloseHandle( hdb );
561 ok(r == ERROR_SUCCESS , "Failed to close database r/o\n");
563 /* open it read/write */
564 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
565 ok(r == ERROR_SUCCESS , "Failed to open database r/w\n");
567 /* a bunch of test queries that fail with the native MSI */
569 r = try_query( hdb, "CREATE TABLE");
570 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2a return code\n");
572 r = try_query( hdb, "CREATE TABLE `a`");
573 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2b return code\n");
575 r = try_query( hdb, "CREATE TABLE `a` ()");
576 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2c return code\n");
578 r = try_query( hdb, "CREATE TABLE `a` (`b`)");
579 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2d return code\n");
581 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) )");
582 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2e return code\n");
584 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
585 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2f return code\n");
587 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
588 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2g return code\n");
590 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
591 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2h return code\n");
593 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
594 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2i return code\n");
596 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
597 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2j return code\n");
599 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
600 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2k return code\n");
602 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
603 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2l return code\n");
605 r = try_query( hdb, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
606 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2m return code\n");
608 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
609 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2n return code\n");
611 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
612 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2o return code\n");
614 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
615 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
617 r = try_query( hdb, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
618 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
620 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
621 ok(r == ERROR_SUCCESS , "valid query 2z failed\n");
623 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
624 ok(r == ERROR_BAD_QUERY_SYNTAX , "created same table again\n");
626 r = try_query( hdb, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
627 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
628 ok(r == ERROR_SUCCESS , "query 4 failed\n");
630 r = MsiDatabaseCommit( hdb );
631 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
633 r = try_query( hdb, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
634 "PRIMARY KEY `foo`)");
635 ok(r == ERROR_SUCCESS , "query 4 failed\n");
637 r = try_insert_query( hdb, "insert into a ( `b` ) VALUES ( ? )");
638 ok(r == ERROR_SUCCESS , "failed to insert record in db\n");
640 r = MsiDatabaseCommit( hdb );
641 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
643 r = try_query( hdb, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
644 "PRIMARY KEY `ba`)");
645 ok(r != ERROR_SUCCESS , "query 5 succeeded\n");
647 r = try_query( hdb,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
648 ok(r != ERROR_SUCCESS , "query 6 succeeded\n");
650 r = try_query( hdb, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
652 ok(r == ERROR_SUCCESS , "query 7 failed\n");
654 r = try_query( hdb, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
655 ok(r == ERROR_SUCCESS , "query 8 failed\n");
657 r = try_query( hdb, "select * from c");
658 ok(r == ERROR_SUCCESS , "query failed\n");
660 r = try_query( hdb, "select * from c where b = 'x");
661 todo_wine ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
663 r = try_query( hdb, "select * from 'c'");
664 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
666 r = try_query( hdb, "select * from ''");
667 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
669 r = try_query( hdb, "select * from c where b = x");
670 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
672 r = try_query( hdb, "select * from c where b = \"x\"");
673 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
675 r = try_query( hdb, "select * from c where b = 'x'");
676 ok(r == ERROR_SUCCESS, "query failed\n");
678 r = try_query( hdb, "select * from c where b = '\"x'");
679 ok(r == ERROR_SUCCESS, "query failed\n");
681 if (0) /* FIXME: this query causes trouble with other tests */
683 r = try_query( hdb, "select * from c where b = '\\\'x'");
684 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
687 r = try_query( hdb, "select * from 'c'");
688 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
690 r = MsiCloseHandle( hdb );
691 ok(r == ERROR_SUCCESS , "Failed to close database transact\n");
693 r = DeleteFile( msifile );
694 ok(r == TRUE, "file didn't exist after commit\n");
697 static void test_viewmodify(void)
699 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
707 /* just MsiOpenDatabase should not create a file */
708 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
709 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
711 query = "CREATE TABLE `phone` ( "
712 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
714 r = run_query( hdb, 0, query );
715 ok(r == ERROR_SUCCESS, "query failed\n");
717 /* check what the error function reports without doing anything */
719 /* passing NULL as the 3rd param make function to crash on older platforms */
720 r = MsiViewGetError( 0, NULL, &sz );
721 ok(r == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
724 query = "SELECT * FROM `phone`";
725 r = MsiDatabaseOpenView(hdb, query, &hview);
726 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
728 /* see what happens with a good hview and bad args */
729 r = MsiViewGetError( hview, NULL, NULL );
730 ok(r == MSIDBERROR_INVALIDARG || r == MSIDBERROR_NOERROR,
731 "MsiViewGetError returns %u (expected -3)\n", r);
732 r = MsiViewGetError( hview, buffer, NULL );
733 ok(r == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
735 /* see what happens with a zero length buffer */
738 r = MsiViewGetError( hview, buffer, &sz );
739 ok(r == MSIDBERROR_MOREDATA, "MsiViewGetError return\n");
740 ok(buffer[0] == 'x', "buffer cleared\n");
741 ok(sz == 0, "size not zero\n");
743 /* ok this one is strange */
745 r = MsiViewGetError( hview, NULL, &sz );
746 ok(r == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
747 ok(sz == 0, "size not zero\n");
749 /* see if it really has an error */
752 r = MsiViewGetError( hview, buffer, &sz );
753 ok(r == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
754 ok(buffer[0] == 0, "buffer not cleared\n");
755 ok(sz == 0, "size not zero\n");
757 r = MsiViewExecute(hview, 0);
758 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
760 /* try some invalid records */
761 r = MsiViewModify(hview, MSIMODIFY_INSERT, 0 );
762 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
763 r = MsiViewModify(hview, -1, 0 );
764 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
766 /* try an small record */
767 hrec = MsiCreateRecord(1);
768 r = MsiViewModify(hview, -1, hrec );
769 ok(r == ERROR_INVALID_DATA, "MsiViewModify failed\n");
771 r = MsiCloseHandle(hrec);
772 ok(r == ERROR_SUCCESS, "failed to close record\n");
774 /* insert a valid record */
775 hrec = MsiCreateRecord(3);
777 r = MsiRecordSetInteger(hrec, 2, 1);
778 ok(r == ERROR_SUCCESS, "failed to set integer\n");
779 r = MsiRecordSetString(hrec, 2, "bob");
780 ok(r == ERROR_SUCCESS, "failed to set integer\n");
781 r = MsiRecordSetString(hrec, 3, "7654321");
782 ok(r == ERROR_SUCCESS, "failed to set integer\n");
784 r = MsiViewExecute(hview, 0);
785 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
786 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
787 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
789 /* insert the same thing again */
790 r = MsiViewExecute(hview, 0);
791 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
793 /* should fail ... */
795 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
796 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
799 r = MsiCloseHandle(hrec);
800 ok(r == ERROR_SUCCESS, "failed to close record\n");
802 r = MsiViewClose(hview);
803 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
804 r = MsiCloseHandle(hview);
805 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
807 r = MsiCloseHandle( hdb );
808 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
811 static MSIHANDLE create_db(void)
818 /* create an empty database */
819 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
820 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
821 if( res != ERROR_SUCCESS )
824 res = MsiDatabaseCommit( hdb );
825 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
830 static void test_getcolinfo(void)
832 MSIHANDLE hdb, hview = 0, rec = 0;
837 /* create an empty db */
839 ok( hdb, "failed to create db\n");
841 /* tables should be present */
842 r = MsiDatabaseOpenView(hdb, "select * from _Tables", &hview);
843 ok( r == ERROR_SUCCESS, "failed to open query\n");
845 r = MsiViewExecute(hview, 0);
846 ok( r == ERROR_SUCCESS, "failed to execute query\n");
848 /* check that NAMES works */
850 r = MsiViewGetColumnInfo( hview, MSICOLINFO_NAMES, &rec );
851 ok( r == ERROR_SUCCESS, "failed to get names\n");
853 r = MsiRecordGetString(rec, 1, buffer, &sz );
854 ok( r == ERROR_SUCCESS, "failed to get string\n");
855 ok( !strcmp(buffer,"Name"), "_Tables has wrong column name\n");
856 r = MsiCloseHandle( rec );
857 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
859 /* check that TYPES works */
861 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, &rec );
862 ok( r == ERROR_SUCCESS, "failed to get names\n");
864 r = MsiRecordGetString(rec, 1, buffer, &sz );
865 ok( r == ERROR_SUCCESS, "failed to get string\n");
866 ok( !strcmp(buffer,"s64"), "_Tables has wrong column type\n");
867 r = MsiCloseHandle( rec );
868 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
870 /* check that invalid values fail */
872 r = MsiViewGetColumnInfo( hview, 100, &rec );
873 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
874 ok( rec == 0, "returned a record\n");
876 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, NULL );
877 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
879 r = MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES, &rec );
880 ok( r == ERROR_INVALID_HANDLE, "wrong error code\n");
882 r = MsiViewClose(hview);
883 ok( r == ERROR_SUCCESS, "failed to close view\n");
884 r = MsiCloseHandle(hview);
885 ok( r == ERROR_SUCCESS, "failed to close view handle\n");
886 r = MsiCloseHandle(hdb);
887 ok( r == ERROR_SUCCESS, "failed to close database\n");
890 static MSIHANDLE get_column_info(MSIHANDLE hdb, const char *query, MSICOLINFO type)
892 MSIHANDLE hview = 0, rec = 0;
895 r = MsiDatabaseOpenView(hdb, query, &hview);
896 if( r != ERROR_SUCCESS )
899 r = MsiViewExecute(hview, 0);
900 if( r == ERROR_SUCCESS )
902 MsiViewGetColumnInfo( hview, type, &rec );
905 MsiCloseHandle(hview);
909 static UINT get_columns_table_type(MSIHANDLE hdb, const char *table, UINT field)
911 MSIHANDLE hview = 0, rec = 0;
915 sprintf(query, "select * from `_Columns` where `Table` = '%s'", table );
917 r = MsiDatabaseOpenView(hdb, query, &hview);
918 if( r != ERROR_SUCCESS )
921 r = MsiViewExecute(hview, 0);
922 if( r == ERROR_SUCCESS )
926 r = MsiViewFetch( hview, &rec );
927 if( r != ERROR_SUCCESS)
929 r = MsiRecordGetInteger( rec, 2 );
931 type = MsiRecordGetInteger( rec, 4 );
932 MsiCloseHandle( rec );
937 MsiCloseHandle(hview);
941 static BOOL check_record( MSIHANDLE rec, UINT field, LPCSTR val )
948 r = MsiRecordGetString( rec, field, buffer, &sz );
949 return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
952 static void test_viewgetcolumninfo(void)
954 MSIHANDLE hdb = 0, rec;
958 ok( hdb, "failed to create db\n");
960 r = run_query( hdb, 0,
961 "CREATE TABLE `Properties` "
962 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
963 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
965 /* check the column types */
966 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_TYPES );
967 ok( rec, "failed to get column info record\n" );
969 ok( check_record( rec, 1, "S255"), "wrong record type\n");
970 ok( check_record( rec, 2, "S1"), "wrong record type\n");
972 MsiCloseHandle( rec );
974 /* check the type in _Columns */
975 ok( 0x3dff == get_columns_table_type(hdb, "Properties", 1 ), "_columns table wrong\n");
976 ok( 0x1d01 == get_columns_table_type(hdb, "Properties", 2 ), "_columns table wrong\n");
978 /* now try the names */
979 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_NAMES );
980 ok( rec, "failed to get column info record\n" );
982 ok( check_record( rec, 1, "Property"), "wrong record type\n");
983 ok( check_record( rec, 2, "Value"), "wrong record type\n");
985 MsiCloseHandle( rec );
987 r = run_query( hdb, 0,
988 "CREATE TABLE `Binary` "
989 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
990 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
992 /* check the column types */
993 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_TYPES );
994 ok( rec, "failed to get column info record\n" );
996 ok( check_record( rec, 1, "S255"), "wrong record type\n");
997 ok( check_record( rec, 2, "V0"), "wrong record type\n");
999 MsiCloseHandle( rec );
1001 /* check the type in _Columns */
1002 ok( 0x3dff == get_columns_table_type(hdb, "Binary", 1 ), "_columns table wrong\n");
1003 ok( 0x1900 == get_columns_table_type(hdb, "Binary", 2 ), "_columns table wrong\n");
1005 /* now try the names */
1006 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_NAMES );
1007 ok( rec, "failed to get column info record\n" );
1009 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1010 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1011 MsiCloseHandle( rec );
1013 r = run_query( hdb, 0,
1014 "CREATE TABLE `UIText` "
1015 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1016 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1018 ok( 0x2d48 == get_columns_table_type(hdb, "UIText", 1 ), "_columns table wrong\n");
1019 ok( 0x1fff == get_columns_table_type(hdb, "UIText", 2 ), "_columns table wrong\n");
1021 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_NAMES );
1022 ok( rec, "failed to get column info record\n" );
1023 ok( check_record( rec, 1, "Key"), "wrong record type\n");
1024 ok( check_record( rec, 2, "Text"), "wrong record type\n");
1025 MsiCloseHandle( rec );
1027 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_TYPES );
1028 ok( rec, "failed to get column info record\n" );
1029 ok( check_record( rec, 1, "s72"), "wrong record type\n");
1030 ok( check_record( rec, 2, "L255"), "wrong record type\n");
1031 MsiCloseHandle( rec );
1033 MsiCloseHandle( hdb );
1036 static void test_msiexport(void)
1038 MSIHANDLE hdb = 0, hview = 0;
1041 char path[MAX_PATH];
1042 const char file[] = "phone.txt";
1046 const char expected[] =
1047 "id\tname\tnumber\r\n"
1050 "1\tAbe\t8675309\r\n";
1052 DeleteFile(msifile);
1054 /* just MsiOpenDatabase should not create a file */
1055 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1056 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1058 /* create a table */
1059 query = "CREATE TABLE `phone` ( "
1060 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1061 "PRIMARY KEY `id`)";
1062 r = MsiDatabaseOpenView(hdb, query, &hview);
1063 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1064 r = MsiViewExecute(hview, 0);
1065 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1066 r = MsiViewClose(hview);
1067 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1068 r = MsiCloseHandle(hview);
1069 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1071 /* insert a value into it */
1072 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
1073 "VALUES('1', 'Abe', '8675309')";
1074 r = MsiDatabaseOpenView(hdb, query, &hview);
1075 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1076 r = MsiViewExecute(hview, 0);
1077 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1078 r = MsiViewClose(hview);
1079 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1080 r = MsiCloseHandle(hview);
1081 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1083 GetCurrentDirectory(MAX_PATH, path);
1085 r = MsiDatabaseExport(hdb, "phone", path, file);
1086 ok(r == ERROR_SUCCESS, "MsiDatabaseExport failed\n");
1088 MsiCloseHandle(hdb);
1090 lstrcat(path, "\\");
1091 lstrcat(path, file);
1093 /* check the data that was written */
1095 memset(buffer, 0, sizeof buffer);
1096 handle = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
1097 if (handle != INVALID_HANDLE_VALUE)
1099 ReadFile(handle, buffer, sizeof buffer, &length, NULL);
1100 CloseHandle(handle);
1104 ok(0, "failed to open file %s\n", path);
1106 ok( length == strlen(expected), "length of data wrong\n");
1107 ok( !lstrcmp(buffer, expected), "data doesn't match\n");
1108 DeleteFile(msifile);
1111 static void test_longstrings(void)
1113 const char insert_query[] =
1114 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1116 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
1119 const DWORD STRING_LENGTH = 0x10005;
1121 DeleteFile(msifile);
1122 /* just MsiOpenDatabase should not create a file */
1123 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1124 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1126 /* create a table */
1128 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1129 ok(r == ERROR_SUCCESS, "query failed\n");
1131 /* try a insert a very long string */
1132 str = HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH+sizeof insert_query);
1133 len = strchr(insert_query, 'Z') - insert_query;
1134 strcpy(str, insert_query);
1135 memset(str+len, 'Z', STRING_LENGTH);
1136 strcpy(str+len+STRING_LENGTH, insert_query+len+1);
1137 r = try_query( hdb, str );
1138 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1140 HeapFree(GetProcessHeap(), 0, str);
1142 MsiDatabaseCommit(hdb);
1143 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
1144 MsiCloseHandle(hdb);
1146 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
1147 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1149 r = MsiDatabaseOpenView(hdb, "select * from `strings` where `id` = 1", &hview);
1150 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1152 r = MsiViewExecute(hview, 0);
1153 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1155 r = MsiViewFetch(hview, &hrec);
1156 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1158 MsiCloseHandle(hview);
1160 r = MsiRecordGetString(hrec, 2, NULL, &len);
1161 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1162 ok(len == STRING_LENGTH, "string length wrong\n");
1164 MsiCloseHandle(hrec);
1165 MsiCloseHandle(hdb);
1166 DeleteFile(msifile);
1169 static void create_file(const CHAR *name)
1174 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1175 ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
1176 WriteFile(file, name, strlen(name), &written, NULL);
1177 WriteFile(file, "\n", strlen("\n"), &written, NULL);
1181 static void test_streamtable(void)
1183 MSIHANDLE hdb = 0, rec, view;
1184 char file[MAX_PATH];
1190 ok( hdb, "failed to create db\n");
1192 r = run_query( hdb, 0,
1193 "CREATE TABLE `Properties` "
1194 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1195 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1197 r = run_query( hdb, 0,
1198 "INSERT INTO `Properties` "
1199 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1200 ok( r == ERROR_SUCCESS, "Failed to add to table\n" );
1202 r = MsiDatabaseCommit( hdb );
1203 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1205 MsiCloseHandle( hdb );
1207 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
1208 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1210 /* check the column types */
1211 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_TYPES );
1212 ok( rec, "failed to get column info record\n" );
1214 ok( check_record( rec, 1, "s62"), "wrong record type\n");
1215 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1217 MsiCloseHandle( rec );
1219 /* now try the names */
1220 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_NAMES );
1221 ok( rec, "failed to get column info record\n" );
1223 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1224 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1226 MsiCloseHandle( rec );
1228 /* insert a file into the _Streams table */
1229 create_file( "test.txt" );
1231 rec = MsiCreateRecord( 2 );
1232 MsiRecordSetString( rec, 1, "data" );
1234 r = MsiRecordSetStream( rec, 2, "test.txt" );
1235 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1237 DeleteFile("test.txt");
1239 r = MsiDatabaseOpenView( hdb,
1240 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view );
1241 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1243 r = MsiViewExecute( view, rec );
1244 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1246 MsiCloseHandle( rec );
1247 MsiCloseHandle( view );
1249 r = MsiDatabaseOpenView( hdb,
1250 "SELECT `Name`, `Data` FROM `_Streams`", &view );
1251 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1253 r = MsiViewExecute( view, 0 );
1254 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1256 r = MsiViewFetch( view, &rec );
1257 ok( r == ERROR_SUCCESS, "Failed to fetch record: %d\n", r);
1260 r = MsiRecordGetString( rec, 1, file, &size );
1261 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1262 ok( !lstrcmp(file, "data"), "Expected 'data', got %s\n", file);
1265 memset(buf, 0, MAX_PATH);
1266 r = MsiRecordReadStream( rec, 2, buf, &size );
1267 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1268 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf);
1270 MsiCloseHandle( rec );
1272 r = MsiViewFetch( view, &rec );
1273 ok( r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
1275 MsiCloseHandle( view );
1276 MsiCloseHandle( hdb );
1277 DeleteFile(msifile);
1280 static void test_where(void)
1282 MSIHANDLE hdb = 0, rec, view;
1290 ok( hdb, "failed to create db\n");
1292 r = run_query( hdb, 0,
1293 "CREATE TABLE `Media` ("
1294 "`DiskId` SHORT NOT NULL, "
1295 "`LastSequence` LONG, "
1296 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1297 "`Cabinet` CHAR(255), "
1298 "`VolumeLabel` CHAR(32), "
1299 "`Source` CHAR(72) "
1300 "PRIMARY KEY `DiskId`)" );
1301 ok( r == S_OK, "cannot create Media table: %d\n", r );
1303 r = run_query( hdb, 0, "INSERT INTO `Media` "
1304 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1305 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1306 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1308 r = run_query( hdb, 0, "INSERT INTO `Media` "
1309 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1310 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1311 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1313 r = run_query( hdb, 0, "INSERT INTO `Media` "
1314 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1315 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1316 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1318 query = "SELECT * FROM `Media`";
1319 r = do_query(hdb, query, &rec);
1320 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1321 ok( check_record( rec, 4, "zero.cab"), "wrong cabinet\n");
1322 MsiCloseHandle( rec );
1324 query = "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1325 r = do_query(hdb, query, &rec);
1326 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1327 ok( check_record( rec, 4, "one.cab"), "wrong cabinet\n");
1329 r = MsiRecordGetInteger(rec, 1);
1330 ok( 2 == r, "field wrong\n");
1331 r = MsiRecordGetInteger(rec, 2);
1332 ok( 1 == r, "field wrong\n");
1333 MsiCloseHandle( rec );
1335 query = "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1336 r = MsiDatabaseOpenView(hdb, query, &view);
1337 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1339 r = MsiViewExecute(view, 0);
1340 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1342 r = MsiViewFetch(view, &rec);
1343 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1345 count = MsiRecordGetFieldCount( rec );
1346 ok( count == 1, "Expected 1 record fields, got %d\n", count );
1349 r = MsiRecordGetString( rec, 1, buf, &size );
1350 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1351 ok( !lstrcmp( buf, "2" ),
1352 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf );
1353 MsiCloseHandle( rec );
1355 r = MsiViewFetch(view, &rec);
1356 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1359 r = MsiRecordGetString( rec, 1, buf, &size );
1360 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1361 ok( !lstrcmp( buf, "3" ),
1362 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf );
1363 MsiCloseHandle( rec );
1365 r = MsiViewFetch(view, &rec);
1366 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
1369 MsiCloseHandle(view);
1371 MsiCloseHandle( rec );
1374 query = "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1375 r = do_query(hdb, query, &rec);
1376 ok( r == ERROR_SUCCESS, "query failed: %d\n", r );
1377 MsiCloseHandle( rec );
1379 MsiCloseHandle( hdb );
1380 DeleteFile(msifile);
1383 static CHAR CURR_DIR[MAX_PATH];
1385 static const CHAR test_data[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1386 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1387 "TestTable\tFirstPrimaryColumn\n"
1388 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1390 static const CHAR two_primary[] = "PrimaryOne\tPrimaryTwo\n"
1392 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1396 static void write_file(const CHAR *filename, const char *data, int data_size)
1400 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
1401 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1403 WriteFile(hf, data, data_size, &size, NULL);
1407 static UINT add_table_to_db(MSIHANDLE hdb, LPCSTR table_data)
1411 write_file("temp_file", table_data, (lstrlen(table_data) - 1) * sizeof(char));
1412 r = MsiDatabaseImportA(hdb, CURR_DIR, "temp_file");
1413 DeleteFileA("temp_file");
1418 static void test_msiimport(void)
1420 MSIHANDLE hdb, view, rec;
1425 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
1427 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
1428 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1430 r = add_table_to_db(hdb, test_data);
1431 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1433 r = add_table_to_db(hdb, two_primary);
1434 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1436 query = "SELECT * FROM `TestTable`";
1437 r = MsiDatabaseOpenView(hdb, query, &view);
1438 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1440 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
1441 count = MsiRecordGetFieldCount(rec);
1442 ok(count == 9, "Expected 9, got %d\n", count);
1443 ok(check_record(rec, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
1444 ok(check_record(rec, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
1445 ok(check_record(rec, 3, "ShortInt"), "Expected ShortInt\n");
1446 ok(check_record(rec, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
1447 ok(check_record(rec, 5, "LongInt"), "Expected LongInt\n");
1448 ok(check_record(rec, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
1449 ok(check_record(rec, 7, "String"), "Expected String\n");
1450 ok(check_record(rec, 8, "LocalizableString"), "Expected LocalizableString\n");
1451 ok(check_record(rec, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
1452 MsiCloseHandle(rec);
1454 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
1455 count = MsiRecordGetFieldCount(rec);
1456 ok(count == 9, "Expected 9, got %d\n", count);
1457 ok(check_record(rec, 1, "s255"), "Expected s255\n");
1458 ok(check_record(rec, 2, "i2"), "Expected i2\n");
1459 ok(check_record(rec, 3, "i2"), "Expected i2\n");
1460 ok(check_record(rec, 4, "I2"), "Expected I2\n");
1461 ok(check_record(rec, 5, "i4"), "Expected i4\n");
1462 ok(check_record(rec, 6, "I4"), "Expected I4\n");
1463 ok(check_record(rec, 7, "S255"), "Expected S255\n");
1464 ok(check_record(rec, 8, "S0"), "Expected S0\n");
1465 ok(check_record(rec, 9, "s0"), "Expected s0\n");
1466 MsiCloseHandle(rec);
1468 query = "SELECT * FROM `TestTable`";
1469 r = do_query(hdb, query, &rec);
1470 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1471 ok(check_record(rec, 1, "stringage"), "Expected 'stringage'\n");
1472 ok(check_record(rec, 7, "another string"), "Expected 'another string'\n");
1473 ok(check_record(rec, 8, "localizable"), "Expected 'localizable'\n");
1474 ok(check_record(rec, 9, "duh"), "Expected 'duh'\n");
1476 i = MsiRecordGetInteger(rec, 2);
1477 ok(i == 5, "Expected 5, got %d\n", i);
1479 i = MsiRecordGetInteger(rec, 3);
1480 ok(i == 2, "Expected 2, got %d\n", i);
1482 i = MsiRecordGetInteger(rec, 4);
1483 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
1485 i = MsiRecordGetInteger(rec, 5);
1486 ok(i == 2147483640, "Expected 2147483640, got %d\n", i);
1488 i = MsiRecordGetInteger(rec, 6);
1489 ok(i == -2147483640, "Expected -2147483640, got %d\n", i);
1491 MsiCloseHandle(rec);
1492 MsiCloseHandle(view);
1494 query = "SELECT * FROM `TwoPrimary`";
1495 r = MsiDatabaseOpenView(hdb, query, &view);
1496 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1498 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
1499 count = MsiRecordGetFieldCount(rec);
1500 ok(count == 2, "Expected 2, got %d\n", count);
1501 ok(check_record(rec, 1, "PrimaryOne"), "Expected PrimaryOne\n");
1502 ok(check_record(rec, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
1504 MsiCloseHandle(rec);
1506 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
1507 count = MsiRecordGetFieldCount(rec);
1508 ok(count == 2, "Expected 2, got %d\n", count);
1509 ok(check_record(rec, 1, "s255"), "Expected s255\n");
1510 ok(check_record(rec, 2, "s255"), "Expected s255\n");
1511 MsiCloseHandle(rec);
1513 r = MsiViewExecute(view, 0);
1514 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1516 r = MsiViewFetch(view, &rec);
1517 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1519 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
1520 ok(check_record(rec, 2, "leaf"), "Expected 'leaf'\n");
1522 MsiCloseHandle(rec);
1524 r = MsiViewFetch(view, &rec);
1525 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1527 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
1528 ok(check_record(rec, 2, "flower"), "Expected 'flower'\n");
1530 MsiCloseHandle(rec);
1532 r = MsiViewFetch(view, &rec);
1533 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
1535 r = MsiViewClose(view);
1536 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1538 MsiCloseHandle(view);
1539 MsiCloseHandle(hdb);
1540 DeleteFileA(msifile);
1543 static void test_markers(void)
1550 ok( hdb, "failed to create db\n");
1552 rec = MsiCreateRecord(3);
1553 MsiRecordSetString(rec, 1, "Table");
1554 MsiRecordSetString(rec, 2, "Apples");
1555 MsiRecordSetString(rec, 3, "Oranges");
1557 /* try a legit create */
1558 query = "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1559 r = run_query(hdb, 0, query);
1560 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1561 MsiCloseHandle(rec);
1563 /* try table name as marker */
1564 rec = MsiCreateRecord(1);
1565 MsiRecordSetString(rec, 1, "Fable");
1566 query = "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1567 r = run_query(hdb, rec, query);
1568 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1570 /* verify that we just created a table called '?', not 'Fable' */
1571 r = try_query(hdb, "SELECT * from `Fable`");
1572 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1574 r = try_query(hdb, "SELECT * from `?`");
1575 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1577 /* try table name as marker without backticks */
1578 MsiRecordSetString(rec, 1, "Mable");
1579 query = "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1580 r = run_query(hdb, rec, query);
1581 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1583 /* try one column name as marker */
1584 MsiRecordSetString(rec, 1, "One");
1585 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1586 r = run_query(hdb, rec, query);
1587 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1588 MsiCloseHandle(rec);
1590 /* try column names as markers */
1591 rec = MsiCreateRecord(2);
1592 MsiRecordSetString(rec, 1, "One");
1593 MsiRecordSetString(rec, 2, "Two");
1594 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
1595 r = run_query(hdb, rec, query);
1596 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1597 MsiCloseHandle(rec);
1599 /* try names with backticks */
1600 rec = MsiCreateRecord(3);
1601 MsiRecordSetString(rec, 1, "One");
1602 MsiRecordSetString(rec, 2, "Two");
1603 MsiRecordSetString(rec, 3, "One");
1604 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1605 r = run_query(hdb, rec, query);
1606 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1608 /* try names with backticks, minus definitions */
1609 query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
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 names without backticks */
1614 query = "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
1615 r = run_query(hdb, rec, query);
1616 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1617 MsiCloseHandle(rec);
1619 /* try one long marker */
1620 rec = MsiCreateRecord(1);
1621 MsiRecordSetString(rec, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
1622 query = "CREATE TABLE `Mable` ( ? )";
1623 r = run_query(hdb, rec, query);
1624 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1625 MsiCloseHandle(rec);
1627 /* try all names as markers */
1628 rec = MsiCreateRecord(4);
1629 MsiRecordSetString(rec, 1, "Mable");
1630 MsiRecordSetString(rec, 2, "One");
1631 MsiRecordSetString(rec, 3, "Two");
1632 MsiRecordSetString(rec, 4, "One");
1633 query = "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1634 r = run_query(hdb, rec, query);
1635 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1636 MsiCloseHandle(rec);
1638 /* try a legit insert */
1639 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
1640 r = run_query(hdb, 0, query);
1641 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1643 r = try_query(hdb, "SELECT * from `Table`");
1644 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1646 /* try values as markers */
1647 rec = MsiCreateRecord(2);
1648 MsiRecordSetInteger(rec, 1, 4);
1649 MsiRecordSetString(rec, 2, "hi");
1650 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1651 r = run_query(hdb, rec, query);
1652 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1653 MsiCloseHandle(rec);
1655 /* try column names and values as markers */
1656 rec = MsiCreateRecord(4);
1657 MsiRecordSetString(rec, 1, "One");
1658 MsiRecordSetString(rec, 2, "Two");
1659 MsiRecordSetInteger(rec, 3, 5);
1660 MsiRecordSetString(rec, 4, "hi");
1661 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
1662 r = run_query(hdb, rec, query);
1663 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1664 MsiCloseHandle(rec);
1666 /* try column names as markers */
1667 rec = MsiCreateRecord(2);
1668 MsiRecordSetString(rec, 1, "One");
1669 MsiRecordSetString(rec, 2, "Two");
1670 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
1671 r = run_query(hdb, rec, query);
1672 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1673 MsiCloseHandle(rec);
1675 /* try table name as a marker */
1676 rec = MsiCreateRecord(1);
1677 MsiRecordSetString(rec, 1, "Table");
1678 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
1679 r = run_query(hdb, rec, query);
1680 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1681 MsiCloseHandle(rec);
1683 /* try table name and values as markers */
1684 rec = MsiCreateRecord(3);
1685 MsiRecordSetString(rec, 1, "Table");
1686 MsiRecordSetInteger(rec, 2, 10);
1687 MsiRecordSetString(rec, 3, "haha");
1688 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
1689 r = run_query(hdb, rec, query);
1690 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
1691 MsiCloseHandle(rec);
1693 /* try all markers */
1694 rec = MsiCreateRecord(5);
1695 MsiRecordSetString(rec, 1, "Table");
1696 MsiRecordSetString(rec, 1, "One");
1697 MsiRecordSetString(rec, 1, "Two");
1698 MsiRecordSetInteger(rec, 2, 10);
1699 MsiRecordSetString(rec, 3, "haha");
1700 query = "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
1701 r = run_query(hdb, rec, query);
1702 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1703 MsiCloseHandle(rec);
1705 /* insert an integer as a string */
1706 rec = MsiCreateRecord(2);
1707 MsiRecordSetString(rec, 1, "11");
1708 MsiRecordSetString(rec, 2, "hi");
1709 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1710 r = run_query(hdb, rec, query);
1711 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1712 MsiCloseHandle(rec);
1714 /* leave off the '' for the string */
1715 rec = MsiCreateRecord(2);
1716 MsiRecordSetInteger(rec, 1, 12);
1717 MsiRecordSetString(rec, 2, "hi");
1718 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
1719 r = run_query(hdb, rec, query);
1720 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1721 MsiCloseHandle(rec);
1723 MsiCloseHandle(hdb);
1724 DeleteFileA(msifile);
1727 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
1728 static void test_handle_limit(void)
1732 MSIHANDLE hviews[MY_NVIEWS];
1735 /* create an empty db */
1737 ok( hdb, "failed to create db\n");
1739 memset(hviews, 0, sizeof(hviews));
1741 for (i=0; i<MY_NVIEWS; i++) {
1742 static char szQueryBuf[256] = "SELECT * from `_Tables`";
1743 hviews[i] = 0xdeadbeeb;
1744 r = MsiDatabaseOpenView(hdb, szQueryBuf, &hviews[i]);
1745 if( r != ERROR_SUCCESS || hviews[i] == 0xdeadbeeb ||
1746 hviews[i] == 0 || (i && (hviews[i] == hviews[i-1])))
1750 ok( i == MY_NVIEWS, "problem opening views\n");
1752 for (i=0; i<MY_NVIEWS; i++) {
1753 if (hviews[i] != 0 && hviews[i] != 0xdeadbeeb) {
1754 r = MsiCloseHandle(hviews[i]);
1755 if (r != ERROR_SUCCESS)
1760 ok( i == MY_NVIEWS, "problem closing views\n");
1762 r = MsiCloseHandle(hdb);
1763 ok( r == ERROR_SUCCESS, "failed to close database\n");
1766 static void generate_transform(void)
1768 MSIHANDLE hdb1, hdb2, hrec;
1772 /* start with two identical databases */
1773 CopyFile(msifile2, msifile, FALSE);
1775 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb1 );
1776 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
1778 r = MsiDatabaseCommit( hdb1 );
1779 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1781 r = MsiOpenDatabase(msifile2, MSIDBOPEN_READONLY, &hdb2 );
1782 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
1784 /* the transform between two identical database should be empty */
1785 r = MsiDatabaseGenerateTransform(hdb1, hdb2, NULL, 0, 0);
1787 ok( r == ERROR_NO_DATA, "return code %d, should be ERROR_NO_DATA\n", r );
1790 query = "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
1791 r = run_query(hdb1, 0, query);
1792 ok(r == ERROR_SUCCESS, "failed to add table\n");
1794 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
1795 r = run_query(hdb1, 0, query);
1796 ok(r == ERROR_SUCCESS, "failed to add row 1\n");
1798 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
1799 r = run_query(hdb1, 0, query);
1800 ok(r == ERROR_SUCCESS, "failed to add row 2\n");
1802 query = "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
1803 r = run_query(hdb1, 0, query);
1804 ok(r == ERROR_SUCCESS, "failed to modify row\n");
1806 query = "DELETE FROM `MOO` WHERE `NOO` = 3";
1807 r = run_query(hdb1, 0, query);
1808 ok(r == ERROR_SUCCESS, "failed to delete row\n");
1810 hrec = MsiCreateRecord(2);
1811 r = MsiRecordSetInteger(hrec, 1, 1);
1812 ok(r == ERROR_SUCCESS, "failed to set integer\n");
1814 write_file("testdata.bin", "naengmyon", 9);
1815 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
1816 ok(r == ERROR_SUCCESS, "failed to set stream\n");
1818 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
1819 r = run_query(hdb1, hrec, query);
1820 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
1822 MsiCloseHandle(hrec);
1824 query = "ALTER TABLE `MOO` ADD `COW` INTEGER";
1825 r = run_query(hdb1, 0, query);
1826 ok(r == ERROR_SUCCESS, "failed to add column\n");
1828 query = "ALTER TABLE `MOO` ADD `PIG` INTEGER";
1829 r = run_query(hdb1, 0, query);
1830 ok(r == ERROR_SUCCESS, "failed to add column\n");
1832 query = "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
1833 r = run_query(hdb1, 0, query);
1834 ok(r == ERROR_SUCCESS, "failed to modify row\n");
1836 query = "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
1837 "`Value` CHAR(0) PRIMARY KEY `Property`)";
1838 r = run_query(hdb1, 0, query);
1839 ok(r == ERROR_SUCCESS, "failed to add property table\n");
1841 query = "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
1842 r = run_query(hdb1, 0, query);
1843 ok(r == ERROR_SUCCESS, "failed to add property\n");
1845 /* database needs to be committed */
1846 MsiDatabaseCommit(hdb1);
1848 r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
1849 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
1851 MsiCloseHandle( hdb1 );
1852 MsiCloseHandle( hdb2 );
1854 DeleteFile("testdata.bin");
1857 /* data for generating a transform */
1859 /* tables transform names - encoded as they would be in an msi database file */
1860 static const WCHAR name1[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
1861 static const WCHAR name2[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
1862 static const WCHAR name3[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
1863 static const WCHAR name4[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
1864 static const WCHAR name5[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
1865 static const WCHAR name6[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
1866 static const WCHAR name7[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
1867 static const WCHAR name8[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
1868 static const WCHAR name9[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
1870 /* data in each table */
1871 static const WCHAR data1[] = { /* AAR */
1872 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
1873 0x0201, 0x0009, 0x8002,
1875 static const WCHAR data2[] = { /* _Columns */
1876 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
1877 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
1878 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
1879 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
1880 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
1881 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
1883 static const WCHAR data3[] = { /* _Tables */
1884 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
1887 static const char data4[] = /* _StringData */
1888 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
1889 static const WCHAR data5[] = { /* _StringPool */
1891 0, 0, /* string 0 '' */
1892 3, 2, /* string 1 'MOO' */
1893 3, 1, /* string 2 'COW' */
1894 3, 1, /* string 3 'PIG' */
1895 1, 1, /* string 4 'c' */
1896 3, 3, /* string 5 'AAR' */
1897 3, 1, /* string 6 'CAR' */
1898 3, 1, /* string 7 'BAR' */
1899 2, 1, /* string 8 'vw' */
1900 3, 1, /* string 9 'bmw' */
1901 8, 4, /* string 10 'Property' */
1902 5, 1, /* string 11 'Value' */
1903 4, 1, /* string 12 'prop' */
1904 3, 1, /* string 13 'val' */
1906 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
1907 static const WCHAR data6[] = { /* MOO */
1908 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
1909 0x0000, 0x8003, /* delete row */
1912 static const WCHAR data7[] = { /* BINARY */
1913 0x0201, 0x8001, 0x0001,
1916 static const char data8[] = /* stream data for the BINARY table */
1919 static const WCHAR data9[] = { /* Property */
1920 0x0201, 0x000c, 0x000d,
1923 static const struct {
1927 } table_transform_data[] =
1929 { name1, data1, sizeof data1 },
1930 { name2, data2, sizeof data2 },
1931 { name3, data3, sizeof data3 },
1932 { name4, data4, sizeof data4 - 1 },
1933 { name5, data5, sizeof data5 },
1934 { name6, data6, sizeof data6 },
1935 { name7, data7, sizeof data7 },
1936 { name8, data8, sizeof data8 - 1 },
1937 { name9, data9, sizeof data9 },
1940 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
1942 static void generate_transform_manual(void)
1944 IStorage *stg = NULL;
1949 const DWORD mode = STGM_CREATE|STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE;
1951 const CLSID CLSID_MsiTransform = { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
1953 MultiByteToWideChar(CP_ACP, 0, mstfile, -1, name, 0x20);
1955 r = StgCreateDocfile(name, mode, 0, &stg);
1956 ok(r == S_OK, "failed to create storage\n");
1960 r = IStorage_SetClass( stg, &CLSID_MsiTransform );
1961 ok(r == S_OK, "failed to set storage type\n");
1963 for (i=0; i<NUM_TRANSFORM_TABLES; i++)
1965 r = IStorage_CreateStream( stg, table_transform_data[i].name,
1966 STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm );
1969 ok(0, "failed to create stream %08x\n", r);
1973 r = IStream_Write( stm, table_transform_data[i].data,
1974 table_transform_data[i].size, &count );
1975 if (FAILED(r) || count != table_transform_data[i].size)
1976 ok(0, "failed to write stream\n");
1977 IStream_Release(stm);
1980 IStorage_Release(stg);
1983 static UINT set_summary_info(MSIHANDLE hdb)
1988 /* build summmary info */
1989 res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
1990 ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );
1992 res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
1993 "Installation Database");
1994 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
1996 res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
1997 "Installation Database");
1998 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2000 res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
2002 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2004 res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
2006 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2008 res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
2009 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2010 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2012 res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
2013 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2015 res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
2016 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2018 res = MsiSummaryInfoPersist(suminfo);
2019 ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );
2021 res = MsiCloseHandle( suminfo);
2022 ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );
2027 static MSIHANDLE create_package_db(LPCSTR filename)
2032 DeleteFile(msifile);
2034 /* create an empty database */
2035 res = MsiOpenDatabase(filename, MSIDBOPEN_CREATE, &hdb );
2036 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
2037 if( res != ERROR_SUCCESS )
2040 res = MsiDatabaseCommit( hdb );
2041 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
2043 res = set_summary_info(hdb);
2045 res = run_query( hdb, 0,
2046 "CREATE TABLE `Directory` ( "
2047 "`Directory` CHAR(255) NOT NULL, "
2048 "`Directory_Parent` CHAR(255), "
2049 "`DefaultDir` CHAR(255) NOT NULL "
2050 "PRIMARY KEY `Directory`)" );
2051 ok( res == ERROR_SUCCESS , "Failed to create directory table\n" );
2056 static void test_try_transform(void)
2058 MSIHANDLE hdb, hview, hrec, hpkg;
2062 char buffer[MAX_PATH];
2064 DeleteFile(msifile);
2065 DeleteFile(msifile2);
2066 DeleteFile(mstfile);
2068 /* create the database */
2069 hdb = create_package_db(msifile2);
2070 ok(hdb, "Failed to create package db\n");
2072 query = "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
2073 r = run_query(hdb, 0, query);
2074 ok(r == ERROR_SUCCESS, "failed to add table\n");
2076 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
2077 r = run_query(hdb, 0, query);
2078 ok(r == ERROR_SUCCESS, "failed to add row\n");
2080 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
2081 r = run_query(hdb, 0, query);
2082 ok(r == ERROR_SUCCESS, "failed to add row\n");
2084 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
2085 r = run_query(hdb, 0, query);
2086 ok(r == ERROR_SUCCESS, "failed to add row\n");
2088 query = "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
2089 r = run_query(hdb, 0, query);
2090 ok(r == ERROR_SUCCESS, "failed to add table\n");
2092 hrec = MsiCreateRecord(2);
2093 r = MsiRecordSetInteger(hrec, 1, 2);
2094 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2096 write_file("testdata.bin", "lamyon", 6);
2097 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2098 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2100 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2101 r = run_query(hdb, hrec, query);
2102 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2104 MsiCloseHandle(hrec);
2106 r = MsiDatabaseCommit( hdb );
2107 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
2109 MsiCloseHandle( hdb );
2110 DeleteFileA("testdata.bin");
2113 * Both these generate an equivilent transform,
2114 * but the first doesn't work in Wine yet
2115 * because MsiDatabaseGenerateTransform is unimplemented.
2118 generate_transform();
2120 generate_transform_manual();
2122 r = MsiOpenDatabase(msifile2, MSIDBOPEN_DIRECT, &hdb );
2123 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2125 r = MsiDatabaseApplyTransform( hdb, mstfile, 0 );
2126 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
2128 MsiDatabaseCommit( hdb );
2130 /* check new values */
2132 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
2133 r = do_query(hdb, query, &hrec);
2134 ok(r == ERROR_SUCCESS, "select query failed\n");
2135 MsiCloseHandle(hrec);
2137 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
2139 r = do_query(hdb, query, &hrec);
2140 ok(r == ERROR_SUCCESS, "select query failed\n");
2141 MsiCloseHandle(hrec);
2143 /* check updated values */
2145 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
2146 r = do_query(hdb, query, &hrec);
2147 ok(r == ERROR_SUCCESS, "select query failed\n");
2148 MsiCloseHandle(hrec);
2150 /* check unchanged value */
2152 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
2153 r = do_query(hdb, query, &hrec);
2154 ok(r == ERROR_SUCCESS, "select query failed\n");
2155 MsiCloseHandle(hrec);
2157 /* check deleted value */
2159 query = "select * from `MOO` where `NOO` = 3";
2160 r = do_query(hdb, query, &hrec);
2161 ok(r == ERROR_NO_MORE_ITEMS, "select query failed\n");
2162 if (hrec) MsiCloseHandle(hrec);
2164 /* check added stream */
2166 query = "select `BLOB` from `BINARY` where `ID` = 1";
2167 r = do_query(hdb, query, &hrec);
2168 ok(r == ERROR_SUCCESS, "select query failed\n");
2170 /* check the contents of the stream */
2172 r = MsiRecordReadStream( hrec, 1, buffer, &sz );
2173 ok(r == ERROR_SUCCESS, "read stream failed\n");
2174 ok(!memcmp(buffer, "naengmyon", 9), "stream data was wrong\n");
2175 ok(sz == 9, "stream data was wrong size\n");
2176 if (hrec) MsiCloseHandle(hrec);
2178 /* check the validity of the table with a deleted row */
2180 query = "select * from `MOO`";
2181 r = MsiDatabaseOpenView(hdb, query, &hview);
2182 ok(r == ERROR_SUCCESS, "open view failed\n");
2184 r = MsiViewExecute(hview, 0);
2185 ok(r == ERROR_SUCCESS, "view execute failed\n");
2187 r = MsiViewFetch(hview, &hrec);
2188 ok(r == ERROR_SUCCESS, "view fetch failed\n");
2190 r = MsiRecordGetInteger(hrec, 1);
2191 ok(r == 1, "Expected 1, got %d\n", r);
2194 r = MsiRecordGetString(hrec, 2, buffer, &sz);
2195 ok(r == ERROR_SUCCESS, "record get string failed\n");
2196 ok(!lstrcmpA(buffer, "c"), "Expected c, got %s\n", buffer);
2198 r = MsiRecordGetInteger(hrec, 3);
2199 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2201 r = MsiRecordGetInteger(hrec, 4);
2202 ok(r == 5, "Expected 5, got %d\n", r);
2204 MsiCloseHandle(hrec);
2206 r = MsiViewFetch(hview, &hrec);
2207 ok(r == ERROR_SUCCESS, "view fetch failed\n");
2209 r = MsiRecordGetInteger(hrec, 1);
2210 ok(r == 2, "Expected 2, got %d\n", r);
2213 r = MsiRecordGetString(hrec, 2, buffer, &sz);
2214 ok(r == ERROR_SUCCESS, "record get string failed\n");
2215 ok(!lstrcmpA(buffer, "b"), "Expected b, got %s\n", buffer);
2217 r = MsiRecordGetInteger(hrec, 3);
2218 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2220 r = MsiRecordGetInteger(hrec, 4);
2221 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2223 MsiCloseHandle(hrec);
2225 r = MsiViewFetch(hview, &hrec);
2226 ok(r == ERROR_NO_MORE_ITEMS, "view fetch succeeded\n");
2228 MsiCloseHandle(hrec);
2229 MsiCloseHandle(hview);
2230 MsiCloseHandle(hdb);
2232 /* check that the property was added */
2233 r = MsiOpenPackage(msifile2, &hpkg);
2234 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2237 r = MsiGetProperty(hpkg, "prop", buffer, &sz);
2238 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2239 ok(!lstrcmp(buffer, "val"), "Expected val, got %s\n", buffer);
2241 MsiCloseHandle(hpkg);
2243 DeleteFile(msifile);
2244 DeleteFile(msifile2);
2245 DeleteFile(mstfile);
2250 const CHAR one[MAX_PATH];
2251 const CHAR two[MAX_PATH];
2254 struct join_res_4col
2256 const CHAR one[MAX_PATH];
2257 const CHAR two[MAX_PATH];
2258 const CHAR three[MAX_PATH];
2259 const CHAR four[MAX_PATH];
2262 static const struct join_res join_res_first[] =
2264 { "alveolar", "procerus" },
2265 { "septum", "procerus" },
2266 { "septum", "nasalis" },
2267 { "ramus", "nasalis" },
2268 { "malar", "mentalis" },
2271 static const struct join_res join_res_second[] =
2273 { "nasal", "septum" },
2274 { "mandible", "ramus" },
2277 static const struct join_res join_res_third[] =
2279 { "msvcp.dll", "abcdefgh" },
2280 { "msvcr.dll", "ijklmnop" },
2283 static const struct join_res join_res_fourth[] =
2285 { "msvcp.dll.01234", "single.dll.31415" },
2288 static const struct join_res join_res_fifth[] =
2290 { "malar", "procerus" },
2293 static const struct join_res join_res_sixth[] =
2295 { "malar", "procerus" },
2296 { "malar", "procerus" },
2297 { "malar", "nasalis" },
2298 { "malar", "nasalis" },
2299 { "malar", "nasalis" },
2300 { "malar", "mentalis" },
2303 static const struct join_res join_res_seventh[] =
2305 { "malar", "nasalis" },
2306 { "malar", "nasalis" },
2307 { "malar", "nasalis" },
2310 static const struct join_res_4col join_res_eighth[] =
2312 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
2313 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
2314 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
2315 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
2316 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
2317 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
2320 static void test_join(void)
2322 MSIHANDLE hdb, hview, hrec;
2330 ok( hdb, "failed to create db\n");
2332 r = create_component_table( hdb );
2333 ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
2335 r = add_component_entry( hdb, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
2336 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2338 r = add_component_entry( hdb, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
2339 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2341 r = add_component_entry( hdb, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
2342 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2344 r = add_component_entry( hdb, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
2345 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2347 r = create_feature_components_table( hdb );
2348 ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
2350 r = add_feature_components_entry( hdb, "'procerus', 'maxilla'" );
2351 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2353 r = add_feature_components_entry( hdb, "'procerus', 'nasal'" );
2354 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2356 r = add_feature_components_entry( hdb, "'nasalis', 'nasal'" );
2357 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2359 r = add_feature_components_entry( hdb, "'nasalis', 'mandible'" );
2360 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2362 r = add_feature_components_entry( hdb, "'nasalis', 'notacomponent'" );
2363 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2365 r = add_feature_components_entry( hdb, "'mentalis', 'zygomatic'" );
2366 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2368 r = create_std_dlls_table( hdb );
2369 ok( r == ERROR_SUCCESS, "cannot create StdDlls table: %d\n", r );
2371 r = add_std_dlls_entry( hdb, "'msvcp.dll', 'msvcp.dll.01234'" );
2372 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
2374 r = add_std_dlls_entry( hdb, "'msvcr.dll', 'msvcr.dll.56789'" );
2375 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
2377 r = create_binary_table( hdb );
2378 ok( r == ERROR_SUCCESS, "cannot create Binary table: %d\n", r );
2380 r = add_binary_entry( hdb, "'msvcp.dll.01234', 'abcdefgh'" );
2381 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
2383 r = add_binary_entry( hdb, "'msvcr.dll.56789', 'ijklmnop'" );
2384 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
2386 r = add_binary_entry( hdb, "'single.dll.31415', 'msvcp.dll'" );
2387 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
2389 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2390 "FROM `Component`, `FeatureComponents` "
2391 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
2392 "ORDER BY `Feature_`";
2393 r = MsiDatabaseOpenView(hdb, query, &hview);
2394 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2396 r = MsiViewExecute(hview, 0);
2397 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2400 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2402 count = MsiRecordGetFieldCount( hrec );
2403 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2406 r = MsiRecordGetString( hrec, 1, buf, &size );
2407 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2408 ok( !lstrcmp( buf, join_res_first[i].one ),
2409 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_first[i].one, buf );
2412 r = MsiRecordGetString( hrec, 2, buf, &size );
2413 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2414 ok( !lstrcmp( buf, join_res_first[i].two ),
2415 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_first[i].two, buf );
2418 MsiCloseHandle(hrec);
2421 ok( i == 5, "Expected 5 rows, got %d\n", i );
2422 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2424 MsiViewClose(hview);
2425 MsiCloseHandle(hview);
2427 /* try a join without a WHERE condition */
2428 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2429 "FROM `Component`, `FeatureComponents` ";
2430 r = MsiDatabaseOpenView(hdb, query, &hview);
2431 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2433 r = MsiViewExecute(hview, 0);
2434 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2437 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2440 MsiCloseHandle(hrec);
2442 ok( i == 24, "Expected 24 rows, got %d\n", i );
2444 MsiViewClose(hview);
2445 MsiCloseHandle(hview);
2447 query = "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
2448 "WHERE FeatureComponents.Component_=Component.Component "
2449 "AND (Feature_='nasalis') ORDER BY Feature_";
2450 r = MsiDatabaseOpenView(hdb, query, &hview);
2451 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2453 r = MsiViewExecute(hview, 0);
2454 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2457 data_correct = TRUE;
2458 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2460 count = MsiRecordGetFieldCount( hrec );
2461 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2464 r = MsiRecordGetString( hrec, 1, buf, &size );
2465 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2466 if( lstrcmp( buf, join_res_second[i].one ))
2467 data_correct = FALSE;
2470 r = MsiRecordGetString( hrec, 2, buf, &size );
2471 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2472 if( lstrcmp( buf, join_res_second[i].two ))
2473 data_correct = FALSE;
2476 MsiCloseHandle(hrec);
2479 ok( data_correct, "data returned in the wrong order\n");
2481 ok( i == 2, "Expected 2 rows, got %d\n", i );
2482 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2484 MsiViewClose(hview);
2485 MsiCloseHandle(hview);
2487 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2488 "FROM `StdDlls`, `Binary` "
2489 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
2491 r = MsiDatabaseOpenView(hdb, query, &hview);
2492 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2494 r = MsiViewExecute(hview, 0);
2495 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2498 data_correct = TRUE;
2499 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2501 count = MsiRecordGetFieldCount( hrec );
2502 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2505 r = MsiRecordGetString( hrec, 1, buf, &size );
2506 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2507 if( lstrcmp( buf, join_res_third[i].one ) )
2508 data_correct = FALSE;
2511 r = MsiRecordGetString( hrec, 2, buf, &size );
2512 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2513 if( lstrcmp( buf, join_res_third[i].two ) )
2514 data_correct = FALSE;
2517 MsiCloseHandle(hrec);
2519 ok( data_correct, "data returned in the wrong order\n");
2521 ok( i == 2, "Expected 2 rows, got %d\n", i );
2523 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2525 MsiViewClose(hview);
2526 MsiCloseHandle(hview);
2528 query = "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
2529 "FROM `StdDlls`, `Binary` "
2530 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
2532 r = MsiDatabaseOpenView(hdb, query, &hview);
2533 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2535 r = MsiViewExecute(hview, 0);
2536 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2539 data_correct = TRUE;
2540 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2542 count = MsiRecordGetFieldCount( hrec );
2543 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2546 r = MsiRecordGetString( hrec, 1, buf, &size );
2547 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2548 if( lstrcmp( buf, join_res_fourth[i].one ))
2549 data_correct = FALSE;
2552 r = MsiRecordGetString( hrec, 2, buf, &size );
2553 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2554 if( lstrcmp( buf, join_res_fourth[i].two ))
2555 data_correct = FALSE;
2558 MsiCloseHandle(hrec);
2560 ok( data_correct, "data returned in the wrong order\n");
2562 ok( i == 1, "Expected 1 rows, got %d\n", i );
2563 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2565 MsiViewClose(hview);
2566 MsiCloseHandle(hview);
2568 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2569 "FROM `Component`, `FeatureComponents` "
2570 "WHERE `Component`.`Component` = 'zygomatic' "
2571 "AND `FeatureComponents`.`Component_` = 'maxilla' "
2572 "ORDER BY `Feature_`";
2573 r = MsiDatabaseOpenView(hdb, query, &hview);
2574 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2576 r = MsiViewExecute(hview, 0);
2577 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2580 data_correct = TRUE;
2581 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2583 count = MsiRecordGetFieldCount( hrec );
2584 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2587 r = MsiRecordGetString( hrec, 1, buf, &size );
2588 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2589 if( lstrcmp( buf, join_res_fifth[i].one ))
2590 data_correct = FALSE;
2593 r = MsiRecordGetString( hrec, 2, buf, &size );
2594 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2595 if( lstrcmp( buf, join_res_fifth[i].two ))
2596 data_correct = FALSE;
2599 MsiCloseHandle(hrec);
2601 ok( data_correct, "data returned in the wrong order\n");
2603 ok( i == 1, "Expected 1 rows, got %d\n", i );
2604 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2606 MsiViewClose(hview);
2607 MsiCloseHandle(hview);
2609 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2610 "FROM `Component`, `FeatureComponents` "
2611 "WHERE `Component` = 'zygomatic' "
2612 "ORDER BY `Feature_`";
2613 r = MsiDatabaseOpenView(hdb, query, &hview);
2614 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2616 r = MsiViewExecute(hview, 0);
2619 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2623 data_correct = TRUE;
2624 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2626 count = MsiRecordGetFieldCount( hrec );
2627 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2630 r = MsiRecordGetString( hrec, 1, buf, &size );
2631 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2632 if( lstrcmp( buf, join_res_sixth[i].one ))
2633 data_correct = FALSE;
2636 r = MsiRecordGetString( hrec, 2, buf, &size );
2637 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2638 if( lstrcmp( buf, join_res_sixth[i].two ))
2639 data_correct = FALSE;
2642 MsiCloseHandle(hrec);
2644 ok( data_correct, "data returned in the wrong order\n");
2648 ok( i == 6, "Expected 6 rows, got %d\n", i );
2650 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2652 MsiViewClose(hview);
2653 MsiCloseHandle(hview);
2655 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2656 "FROM `Component`, `FeatureComponents` "
2657 "WHERE `Component` = 'zygomatic' "
2658 "AND `Feature_` = 'nasalis' "
2659 "ORDER BY `Feature_`";
2660 r = MsiDatabaseOpenView(hdb, query, &hview);
2661 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2663 r = MsiViewExecute(hview, 0);
2664 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2667 data_correct = TRUE;
2668 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2670 count = MsiRecordGetFieldCount( hrec );
2671 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2674 r = MsiRecordGetString( hrec, 1, buf, &size );
2675 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2676 if( lstrcmp( buf, join_res_seventh[i].one ))
2677 data_correct = FALSE;
2680 r = MsiRecordGetString( hrec, 2, buf, &size );
2681 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2682 if( lstrcmp( buf, join_res_seventh[i].two ))
2683 data_correct = FALSE;
2686 MsiCloseHandle(hrec);
2689 ok( data_correct, "data returned in the wrong order\n");
2690 ok( i == 3, "Expected 3 rows, got %d\n", i );
2691 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2693 MsiViewClose(hview);
2694 MsiCloseHandle(hview);
2696 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2697 "FROM `StdDlls`, `Binary` ";
2698 r = MsiDatabaseOpenView(hdb, query, &hview);
2699 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2701 r = MsiViewExecute(hview, 0);
2702 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2705 data_correct = TRUE;
2706 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2708 count = MsiRecordGetFieldCount( hrec );
2709 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2712 r = MsiRecordGetString( hrec, 1, buf, &size );
2713 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2714 if( lstrcmp( buf, join_res_eighth[i].one ))
2715 data_correct = FALSE;
2718 r = MsiRecordGetString( hrec, 2, buf, &size );
2719 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2720 if( lstrcmp( buf, join_res_eighth[i].four ))
2721 data_correct = FALSE;
2724 MsiCloseHandle(hrec);
2727 todo_wine ok( data_correct, "data returned in the wrong order\n");
2728 ok( i == 6, "Expected 6 rows, got %d\n", i );
2729 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2731 MsiViewClose(hview);
2732 MsiCloseHandle(hview);
2734 query = "SELECT * FROM `StdDlls`, `Binary` ";
2735 r = MsiDatabaseOpenView(hdb, query, &hview);
2736 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2738 r = MsiViewExecute(hview, 0);
2739 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2742 data_correct = TRUE;
2743 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2745 count = MsiRecordGetFieldCount( hrec );
2746 ok( count == 4, "Expected 4 record fields, got %d\n", count );
2749 r = MsiRecordGetString( hrec, 1, buf, &size );
2750 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2751 if( lstrcmp( buf, join_res_eighth[i].one ))
2752 data_correct = FALSE;
2755 r = MsiRecordGetString( hrec, 2, buf, &size );
2756 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2757 if( lstrcmp( buf, join_res_eighth[i].two ))
2758 data_correct = FALSE;
2761 r = MsiRecordGetString( hrec, 3, buf, &size );
2762 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2763 if( lstrcmp( buf, join_res_eighth[i].three ))
2764 data_correct = FALSE;
2767 r = MsiRecordGetString( hrec, 4, buf, &size );
2768 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2769 if( lstrcmp( buf, join_res_eighth[i].four ))
2770 data_correct = FALSE;
2773 MsiCloseHandle(hrec);
2775 todo_wine ok( data_correct, "data returned in the wrong order\n");
2777 ok( i == 6, "Expected 6 rows, got %d\n", i );
2778 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2780 MsiViewClose(hview);
2781 MsiCloseHandle(hview);
2783 MsiCloseHandle(hdb);
2784 DeleteFile(msifile);
2787 static void test_temporary_table(void)
2790 MSIHANDLE hdb = 0, view = 0, rec;
2796 cond = MsiDatabaseIsTablePersistent(0, NULL);
2797 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
2800 ok( hdb, "failed to create db\n");
2802 cond = MsiDatabaseIsTablePersistent(hdb, NULL);
2803 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
2806 cond = MsiDatabaseIsTablePersistent(hdb, "_Tables");
2807 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2809 cond = MsiDatabaseIsTablePersistent(hdb, "_Columns");
2810 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2813 cond = MsiDatabaseIsTablePersistent(hdb, "_Streams");
2814 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2816 query = "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
2817 r = run_query(hdb, 0, query);
2818 ok(r == ERROR_SUCCESS, "failed to add table\n");
2820 cond = MsiDatabaseIsTablePersistent(hdb, "P");
2821 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
2823 query = "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
2824 r = run_query(hdb, 0, query);
2825 ok(r == ERROR_SUCCESS, "failed to add table\n");
2827 cond = MsiDatabaseIsTablePersistent(hdb, "P2");
2828 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
2830 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
2831 r = run_query(hdb, 0, query);
2832 ok(r == ERROR_SUCCESS, "failed to add table\n");
2834 cond = MsiDatabaseIsTablePersistent(hdb, "T");
2835 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
2837 query = "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
2838 r = run_query(hdb, 0, query);
2839 ok(r == ERROR_SUCCESS, "failed to add table\n");
2842 cond = MsiDatabaseIsTablePersistent(hdb, "T2");
2843 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2846 query = "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
2847 r = run_query(hdb, 0, query);
2848 ok(r == ERROR_SUCCESS, "failed to add table\n");
2850 cond = MsiDatabaseIsTablePersistent(hdb, "T3");
2851 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
2854 query = "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
2855 r = run_query(hdb, 0, query);
2856 ok(r == ERROR_FUNCTION_FAILED, "failed to add table\n");
2858 cond = MsiDatabaseIsTablePersistent(hdb, "T4");
2859 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
2862 query = "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
2863 r = run_query(hdb, 0, query);
2864 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add table\n");
2866 query = "select * from `T`";
2867 r = MsiDatabaseOpenView(hdb, query, &view);
2868 ok(r == ERROR_SUCCESS, "failed to query table\n");
2869 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2870 ok(r == ERROR_SUCCESS, "failed to get column info\n");
2873 r = MsiRecordGetString(rec, 1, buf, &sz);
2874 ok(r == ERROR_SUCCESS, "failed to get string\n");
2875 todo_wine ok( 0 == strcmp("G255", buf), "wrong column type\n");
2878 r = MsiRecordGetString(rec, 2, buf, &sz);
2879 ok(r == ERROR_SUCCESS, "failed to get string\n");
2880 todo_wine ok( 0 == strcmp("j2", buf), "wrong column type\n");
2882 MsiCloseHandle( rec );
2883 MsiCloseHandle( view );
2885 /* query the table data */
2887 r = do_query(hdb, "select * from `_Tables` where `Name` = 'T'", &rec);
2888 ok( r == ERROR_SUCCESS, "temporary table exists in _Tables\n");
2889 MsiCloseHandle( rec );
2891 /* query the column data */
2893 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec);
2894 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
2895 if (rec) MsiCloseHandle( rec );
2897 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec);
2898 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
2899 if (rec) MsiCloseHandle( rec );
2901 MsiCloseHandle( hdb );
2903 DeleteFile(msifile);
2906 static void test_alter(void)
2914 ok( hdb, "failed to create db\n");
2916 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
2917 r = run_query(hdb, 0, query);
2918 ok(r == ERROR_SUCCESS, "failed to add table\n");
2920 cond = MsiDatabaseIsTablePersistent(hdb, "T");
2921 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
2923 query = "ALTER TABLE `T` HOLD";
2924 r = run_query(hdb, 0, query);
2925 ok(r == ERROR_SUCCESS, "failed to hold table %d\n", r);
2927 query = "ALTER TABLE `T` FREE";
2928 r = run_query(hdb, 0, query);
2929 ok(r == ERROR_SUCCESS, "failed to free table\n");
2931 query = "ALTER TABLE `T` FREE";
2932 r = run_query(hdb, 0, query);
2933 ok(r == ERROR_SUCCESS, "failed to free table\n");
2936 query = "ALTER TABLE `T` FREE";
2937 r = run_query(hdb, 0, query);
2938 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to free table\n");
2940 query = "ALTER TABLE `T` HOLD";
2941 r = run_query(hdb, 0, query);
2942 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to hold table %d\n", r);
2945 /* table T is removed */
2946 query = "SELECT * FROM `T`";
2947 r = run_query(hdb, 0, query);
2950 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2953 /* create the table again */
2954 query = "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
2955 r = run_query(hdb, 0, query);
2956 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2958 /* up the ref count */
2959 query = "ALTER TABLE `U` HOLD";
2960 r = run_query(hdb, 0, query);
2961 ok(r == ERROR_SUCCESS, "failed to free table\n");
2963 /* add column, no data type */
2964 query = "ALTER TABLE `U` ADD `C`";
2965 r = run_query(hdb, 0, query);
2966 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2968 query = "ALTER TABLE `U` ADD `C` INTEGER";
2969 r = run_query(hdb, 0, query);
2972 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2975 /* add column C again */
2976 query = "ALTER TABLE `U` ADD `C` INTEGER";
2977 r = run_query(hdb, 0, query);
2978 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2980 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
2981 r = run_query(hdb, 0, query);
2984 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2987 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
2988 r = run_query(hdb, 0, query);
2991 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2994 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
2995 r = run_query(hdb, 0, query);
2996 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2998 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
2999 r = run_query(hdb, 0, query);
3002 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3005 query = "SELECT * FROM `U` WHERE `D` = 8";
3006 r = run_query(hdb, 0, query);
3009 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3012 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
3013 r = run_query(hdb, 0, query);
3014 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3016 query = "ALTER COLUMN `D` FREE";
3017 r = run_query(hdb, 0, query);
3018 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3020 /* drop the ref count */
3021 query = "ALTER TABLE `U` FREE";
3022 r = run_query(hdb, 0, query);
3023 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3025 /* table is not empty */
3026 query = "SELECT * FROM `U`";
3027 r = run_query(hdb, 0, query);
3028 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3030 /* column D is removed */
3031 query = "SELECT * FROM `U` WHERE `D` = 8";
3032 r = run_query(hdb, 0, query);
3033 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3035 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
3036 r = run_query(hdb, 0, query);
3037 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3039 /* add the column again */
3040 query = "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
3041 r = run_query(hdb, 0, query);
3044 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3047 /* up the ref count */
3048 query = "ALTER TABLE `U` HOLD";
3049 r = run_query(hdb, 0, query);
3050 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3052 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
3053 r = run_query(hdb, 0, query);
3056 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3059 query = "SELECT * FROM `U` WHERE `E` = 16";
3060 r = run_query(hdb, 0, query);
3063 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3066 /* drop the ref count */
3067 query = "ALTER TABLE `U` FREE";
3068 r = run_query(hdb, 0, query);
3069 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3071 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
3072 r = run_query(hdb, 0, query);
3075 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3078 query = "SELECT * FROM `U` WHERE `E` = 20";
3079 r = run_query(hdb, 0, query);
3082 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3085 /* drop the ref count */
3086 query = "ALTER TABLE `U` FREE";
3087 r = run_query(hdb, 0, query);
3088 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3090 /* table still exists */
3091 query = "SELECT * FROM `U`";
3092 r = run_query(hdb, 0, query);
3093 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3095 /* col E is removed */
3096 query = "SELECT * FROM `U` WHERE `E` = 20";
3097 r = run_query(hdb, 0, query);
3098 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3100 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
3101 r = run_query(hdb, 0, query);
3102 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3104 /* drop the ref count once more */
3105 query = "ALTER TABLE `U` FREE";
3106 r = run_query(hdb, 0, query);
3107 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3109 /* table still exists */
3110 query = "SELECT * FROM `U`";
3111 r = run_query(hdb, 0, query);
3112 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3114 MsiCloseHandle( hdb );
3115 DeleteFile(msifile);
3118 static void test_integers(void)
3120 MSIHANDLE hdb = 0, view = 0, rec = 0;
3125 /* just MsiOpenDatabase should not create a file */
3126 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3127 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3129 /* create a table */
3130 query = "CREATE TABLE `integers` ( "
3131 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
3132 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
3133 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
3134 "PRIMARY KEY `one`)";
3135 r = MsiDatabaseOpenView(hdb, query, &view);
3136 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3137 r = MsiViewExecute(view, 0);
3138 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3139 r = MsiViewClose(view);
3140 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3141 r = MsiCloseHandle(view);
3142 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3144 query = "SELECT * FROM `integers`";
3145 r = MsiDatabaseOpenView(hdb, query, &view);
3146 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3148 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
3149 count = MsiRecordGetFieldCount(rec);
3150 ok(count == 8, "Expected 8, got %d\n", count);
3151 ok(check_record(rec, 1, "one"), "Expected one\n");
3152 ok(check_record(rec, 2, "two"), "Expected two\n");
3153 ok(check_record(rec, 3, "three"), "Expected three\n");
3154 ok(check_record(rec, 4, "four"), "Expected four\n");
3155 ok(check_record(rec, 5, "five"), "Expected five\n");
3156 ok(check_record(rec, 6, "six"), "Expected six\n");
3157 ok(check_record(rec, 7, "seven"), "Expected seven\n");
3158 ok(check_record(rec, 8, "eight"), "Expected eight\n");
3159 MsiCloseHandle(rec);
3161 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
3162 count = MsiRecordGetFieldCount(rec);
3163 ok(count == 8, "Expected 8, got %d\n", count);
3164 ok(check_record(rec, 1, "I2"), "Expected I2\n");
3165 ok(check_record(rec, 2, "I2"), "Expected I2\n");
3166 ok(check_record(rec, 3, "I2"), "Expected I2\n");
3167 ok(check_record(rec, 4, "I4"), "Expected I4\n");
3168 ok(check_record(rec, 5, "i2"), "Expected i2\n");
3169 ok(check_record(rec, 6, "i2"), "Expected i2\n");
3170 ok(check_record(rec, 7, "i2"), "Expected i2\n");
3171 ok(check_record(rec, 8, "i4"), "Expected i4\n");
3172 MsiCloseHandle(rec);
3175 MsiCloseHandle(view);
3177 /* insert values into it, NULL where NOT NULL is specified */
3178 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3179 "VALUES('', '', '', '', '', '', '', '')";
3180 r = MsiDatabaseOpenView(hdb, query, &view);
3181 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3182 r = MsiViewExecute(view, 0);
3183 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
3186 MsiCloseHandle(view);
3188 query = "SELECT * FROM `integers`";
3189 r = do_query(hdb, query, &rec);
3190 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3192 r = MsiRecordGetFieldCount(rec);
3193 ok(r == -1, "record count wrong: %d\n", r);
3195 MsiCloseHandle(rec);
3197 /* insert legitimate values into it */
3198 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3199 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
3200 r = MsiDatabaseOpenView(hdb, query, &view);
3201 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3202 r = MsiViewExecute(view, 0);
3203 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3205 query = "SELECT * FROM `integers`";
3206 r = do_query(hdb, query, &rec);
3207 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3209 r = MsiRecordGetFieldCount(rec);
3210 ok(r == 8, "record count wrong: %d\n", r);
3212 i = MsiRecordGetInteger(rec, 1);
3213 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
3214 i = MsiRecordGetInteger(rec, 3);
3215 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
3216 i = MsiRecordGetInteger(rec, 2);
3217 ok(i == 2, "Expected 2, got %d\n", i);
3218 i = MsiRecordGetInteger(rec, 4);
3219 ok(i == 4, "Expected 4, got %d\n", i);
3220 i = MsiRecordGetInteger(rec, 5);
3221 ok(i == 5, "Expected 5, got %d\n", i);
3222 i = MsiRecordGetInteger(rec, 6);
3223 ok(i == 6, "Expected 6, got %d\n", i);
3224 i = MsiRecordGetInteger(rec, 7);
3225 ok(i == 7, "Expected 7, got %d\n", i);
3226 i = MsiRecordGetInteger(rec, 8);
3227 ok(i == 8, "Expected 8, got %d\n", i);
3229 MsiCloseHandle(rec);
3231 MsiCloseHandle(view);
3233 r = MsiDatabaseCommit(hdb);
3234 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
3236 r = MsiCloseHandle(hdb);
3237 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3239 r = DeleteFile(msifile);
3240 ok(r == TRUE, "file didn't exist after commit\n");
3243 static void test_update(void)
3245 MSIHANDLE hdb = 0, view = 0, rec = 0;
3246 CHAR result[MAX_PATH];
3251 /* just MsiOpenDatabase should not create a file */
3252 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3253 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3255 /* create the Control table */
3256 query = "CREATE TABLE `Control` ( "
3257 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
3258 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
3259 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
3260 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
3261 r = MsiDatabaseOpenView(hdb, query, &view);
3262 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3263 r = MsiViewExecute(view, 0);
3264 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3265 r = MsiViewClose(view);
3266 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3267 r = MsiCloseHandle(view);
3268 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3271 query = "INSERT INTO `Control` ( "
3272 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3273 "`Property`, `Text`, `Control_Next`, `Help` )"
3274 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3275 r = MsiDatabaseOpenView(hdb, query, &view);
3276 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3277 r = MsiViewExecute(view, 0);
3278 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3279 r = MsiViewClose(view);
3280 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3281 r = MsiCloseHandle(view);
3282 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3284 /* add a second control */
3285 query = "INSERT INTO `Control` ( "
3286 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3287 "`Property`, `Text`, `Control_Next`, `Help` )"
3288 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
3289 r = MsiDatabaseOpenView(hdb, query, &view);
3290 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3291 r = MsiViewExecute(view, 0);
3292 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3293 r = MsiViewClose(view);
3294 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3295 r = MsiCloseHandle(view);
3296 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3298 /* add a third control */
3299 query = "INSERT INTO `Control` ( "
3300 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3301 "`Property`, `Text`, `Control_Next`, `Help` )"
3302 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3303 r = MsiDatabaseOpenView(hdb, query, &view);
3304 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3305 r = MsiViewExecute(view, 0);
3306 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3307 r = MsiViewClose(view);
3308 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3309 r = MsiCloseHandle(view);
3310 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3313 query = "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3314 r = MsiDatabaseOpenView(hdb, query, &view);
3315 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3317 /* bad set column */
3318 query = "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3319 r = MsiDatabaseOpenView(hdb, query, &view);
3320 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3322 /* bad where condition */
3323 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
3324 r = MsiDatabaseOpenView(hdb, query, &view);
3325 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3327 /* just the dialog_ specified */
3328 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3329 r = MsiDatabaseOpenView(hdb, query, &view);
3330 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3331 r = MsiViewExecute(view, 0);
3332 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3333 r = MsiViewClose(view);
3334 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3335 r = MsiCloseHandle(view);
3336 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3338 /* check the modified text */
3339 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3340 r = MsiDatabaseOpenView(hdb, query, &view);
3341 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3342 r = MsiViewExecute(view, 0);
3343 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3345 r = MsiViewFetch(view, &rec);
3346 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3349 r = MsiRecordGetString(rec, 1, result, &size);
3350 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3351 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3353 MsiCloseHandle(rec);
3355 r = MsiViewFetch(view, &rec);
3356 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3359 r = MsiRecordGetString(rec, 1, result, &size);
3360 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3361 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
3363 MsiCloseHandle(rec);
3365 r = MsiViewFetch(view, &rec);
3366 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3368 r = MsiViewClose(view);
3369 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3370 r = MsiCloseHandle(view);
3371 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3373 /* dialog_ and control specified */
3374 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
3375 r = MsiDatabaseOpenView(hdb, query, &view);
3376 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3377 r = MsiViewExecute(view, 0);
3378 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3379 r = MsiViewClose(view);
3380 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3381 r = MsiCloseHandle(view);
3382 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3384 /* check the modified text */
3385 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3386 r = MsiDatabaseOpenView(hdb, query, &view);
3387 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3388 r = MsiViewExecute(view, 0);
3389 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3391 r = MsiViewFetch(view, &rec);
3392 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3395 r = MsiRecordGetString(rec, 1, result, &size);
3396 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3397 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3399 MsiCloseHandle(rec);
3401 r = MsiViewFetch(view, &rec);
3402 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3405 r = MsiRecordGetString(rec, 1, result, &size);
3406 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3407 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
3409 MsiCloseHandle(rec);
3411 r = MsiViewFetch(view, &rec);
3412 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3414 r = MsiViewClose(view);
3415 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3416 r = MsiCloseHandle(view);
3417 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3419 /* no where condition */
3420 query = "UPDATE `Control` SET `Text` = 'this is text'";
3421 r = MsiDatabaseOpenView(hdb, query, &view);
3422 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3423 r = MsiViewExecute(view, 0);
3424 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3425 r = MsiViewClose(view);
3426 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3427 r = MsiCloseHandle(view);
3428 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3430 /* check the modified text */
3431 query = "SELECT `Text` FROM `Control`";
3432 r = MsiDatabaseOpenView(hdb, query, &view);
3433 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3434 r = MsiViewExecute(view, 0);
3435 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3437 r = MsiViewFetch(view, &rec);
3438 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3441 r = MsiRecordGetString(rec, 1, result, &size);
3442 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3443 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3445 MsiCloseHandle(rec);
3447 r = MsiViewFetch(view, &rec);
3448 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3451 r = MsiRecordGetString(rec, 1, result, &size);
3452 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3453 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3455 MsiCloseHandle(rec);
3457 r = MsiViewFetch(view, &rec);
3458 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3461 r = MsiRecordGetString(rec, 1, result, &size);
3462 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3463 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3465 MsiCloseHandle(rec);
3467 r = MsiViewFetch(view, &rec);
3468 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3470 r = MsiViewClose(view);
3471 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3472 r = MsiCloseHandle(view);
3473 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3474 r = MsiDatabaseCommit(hdb);
3475 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
3476 r = MsiCloseHandle(hdb);
3477 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3479 DeleteFile(msifile);
3482 static void test_special_tables(void)
3488 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3489 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3491 query = "CREATE TABLE `_Properties` ( "
3492 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3493 r = run_query(hdb, 0, query);
3494 ok(r == ERROR_SUCCESS, "failed to create table\n");
3496 query = "CREATE TABLE `_Streams` ( "
3497 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3498 r = run_query(hdb, 0, query);
3499 todo_wine ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Streams table\n");
3501 query = "CREATE TABLE `_Tables` ( "
3502 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3503 r = run_query(hdb, 0, query);
3504 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Tables table\n");
3506 query = "CREATE TABLE `_Columns` ( "
3507 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3508 r = run_query(hdb, 0, query);
3509 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Columns table\n");
3511 r = MsiCloseHandle(hdb);
3512 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3515 static void test_select_markers(void)
3517 MSIHANDLE hdb = 0, rec, view, res;
3524 ok( hdb, "failed to create db\n");
3526 r = run_query(hdb, 0,
3527 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
3528 ok(r == S_OK, "cannot create table: %d\n", r);
3530 r = run_query(hdb, 0, "INSERT INTO `Table` "
3531 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
3532 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3534 r = run_query(hdb, 0, "INSERT INTO `Table` "
3535 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
3536 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3538 r = run_query(hdb, 0, "INSERT INTO `Table` "
3539 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
3540 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3542 r = run_query(hdb, 0, "INSERT INTO `Table` "
3543 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
3544 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3546 rec = MsiCreateRecord(2);
3547 MsiRecordSetString(rec, 1, "apple");
3548 MsiRecordSetString(rec, 2, "two");
3550 query = "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
3551 r = MsiDatabaseOpenView(hdb, query, &view);
3552 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3554 r = MsiViewExecute(view, rec);
3557 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3560 r = MsiViewFetch(view, &res);
3563 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3567 r = MsiRecordGetString(res, 1, buf, &size);
3570 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3571 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
3575 r = MsiRecordGetString(res, 2, buf, &size);
3578 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3579 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
3582 r = MsiRecordGetInteger(res, 3);
3585 ok(r == 1, "Expected 1, got %d\n", r);
3588 MsiCloseHandle(res);
3590 r = MsiViewFetch(view, &res);
3593 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3597 r = MsiRecordGetString(res, 1, buf, &size);
3600 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3601 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
3605 r = MsiRecordGetString(res, 2, buf, &size);
3608 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3609 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
3612 r = MsiRecordGetInteger(res, 3);
3615 ok(r == 2, "Expected 2, got %d\n", r);
3618 MsiCloseHandle(res);
3620 r = MsiViewFetch(view, &res);
3621 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3623 r = MsiViewClose(view);
3624 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3625 r = MsiCloseHandle(view);
3626 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3627 r = MsiCloseHandle(hdb);
3628 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3630 DeleteFile(msifile);
3637 test_msidecomposedesc();
3638 test_msibadqueries();
3640 test_viewgetcolumninfo();
3648 test_handle_limit();
3649 test_try_transform();
3651 test_temporary_table();
3655 test_special_tables();
3656 test_select_markers();