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, 1, 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 string\n");
781 r = MsiRecordSetString(hrec, 3, "7654321");
782 ok(r == ERROR_SUCCESS, "failed to set string\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 query = "SELECT * FROM `phone`";
808 r = MsiDatabaseOpenView(hdb, query, &hview);
809 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
811 r = MsiViewExecute(hview, 0);
812 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
814 r = MsiViewFetch(hview, &hrec);
815 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
817 r = MsiRecordGetInteger(hrec, 1);
818 ok(r == 1, "Expected 1, got %d\n", r);
821 r = MsiRecordGetString(hrec, 2, buffer, &sz);
822 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
823 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
826 r = MsiRecordGetString(hrec, 3, buffer, &sz);
827 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
828 ok(!lstrcmp(buffer, "7654321"), "Expected 7654321, got %s\n", buffer);
830 /* update the view, non-primary key */
831 r = MsiRecordSetString(hrec, 3, "3141592");
832 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
834 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
837 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
841 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
844 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
847 /* update the view, primary key */
848 r = MsiRecordSetInteger(hrec, 1, 5);
849 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
851 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
854 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
857 r = MsiCloseHandle(hrec);
858 ok(r == ERROR_SUCCESS, "failed to close record\n");
860 r = MsiViewClose(hview);
861 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
862 r = MsiCloseHandle(hview);
863 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
865 query = "SELECT * FROM `phone`";
866 r = MsiDatabaseOpenView(hdb, query, &hview);
867 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
869 r = MsiViewExecute(hview, 0);
870 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
872 r = MsiViewFetch(hview, &hrec);
873 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
875 r = MsiRecordGetInteger(hrec, 1);
876 ok(r == 1, "Expected 1, got %d\n", r);
879 r = MsiRecordGetString(hrec, 2, buffer, &sz);
880 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
881 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
884 r = MsiRecordGetString(hrec, 3, buffer, &sz);
885 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
888 ok(!lstrcmp(buffer, "3141592"), "Expected 3141592, got %s\n", buffer);
891 r = MsiCloseHandle(hrec);
892 ok(r == ERROR_SUCCESS, "failed to close record\n");
894 /* use a record that doesn't come from a view fetch */
895 hrec = MsiCreateRecord(3);
896 ok(hrec != 0, "MsiCreateRecord failed\n");
898 r = MsiRecordSetInteger(hrec, 1, 3);
899 ok(r == ERROR_SUCCESS, "failed to set integer\n");
900 r = MsiRecordSetString(hrec, 2, "jane");
901 ok(r == ERROR_SUCCESS, "failed to set string\n");
902 r = MsiRecordSetString(hrec, 3, "112358");
903 ok(r == ERROR_SUCCESS, "failed to set string\n");
905 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
908 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
911 r = MsiCloseHandle(hrec);
912 ok(r == ERROR_SUCCESS, "failed to close record\n");
914 /* use a record that doesn't come from a view fetch, primary key matches */
915 hrec = MsiCreateRecord(3);
916 ok(hrec != 0, "MsiCreateRecord failed\n");
918 r = MsiRecordSetInteger(hrec, 1, 1);
919 ok(r == ERROR_SUCCESS, "failed to set integer\n");
920 r = MsiRecordSetString(hrec, 2, "jane");
921 ok(r == ERROR_SUCCESS, "failed to set string\n");
922 r = MsiRecordSetString(hrec, 3, "112358");
923 ok(r == ERROR_SUCCESS, "failed to set string\n");
925 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
928 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
931 r = MsiCloseHandle(hrec);
932 ok(r == ERROR_SUCCESS, "failed to close record\n");
934 hrec = MsiCreateRecord(3);
936 r = MsiRecordSetInteger(hrec, 1, 2);
937 ok(r == ERROR_SUCCESS, "failed to set integer\n");
938 r = MsiRecordSetString(hrec, 2, "nick");
939 ok(r == ERROR_SUCCESS, "failed to set string\n");
940 r = MsiRecordSetString(hrec, 3, "141421");
941 ok(r == ERROR_SUCCESS, "failed to set string\n");
943 r = MsiViewExecute(hview, 0);
944 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
945 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
946 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
948 r = MsiViewClose(hview);
949 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
950 r = MsiCloseHandle(hview);
951 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
953 query = "SELECT * FROM `phone` WHERE `id` = 1";
954 r = MsiDatabaseOpenView(hdb, query, &hview);
955 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
956 r = MsiViewExecute(hview, 0);
957 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
958 r = MsiViewFetch(hview, &hrec);
959 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
961 /* change the id to match the second row */
962 r = MsiRecordSetInteger(hrec, 1, 2);
963 ok(r == ERROR_SUCCESS, "failed to set integer\n");
964 r = MsiRecordSetString(hrec, 2, "jerry");
965 ok(r == ERROR_SUCCESS, "failed to set string\n");
967 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
970 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
973 r = MsiCloseHandle(hrec);
974 ok(r == ERROR_SUCCESS, "failed to close record\n");
975 r = MsiViewClose(hview);
976 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
977 r = MsiCloseHandle(hview);
978 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
981 query = "SELECT * FROM `phone` ORDER BY `id`";
982 r = MsiDatabaseOpenView(hdb, query, &hview);
983 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
984 r = MsiViewExecute(hview, 0);
985 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
986 r = MsiViewFetch(hview, &hrec);
987 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
989 /* change the id to match the second row */
990 r = MsiRecordSetInteger(hrec, 1, 2);
991 ok(r == ERROR_SUCCESS, "failed to set integer\n");
992 r = MsiRecordSetString(hrec, 2, "jerry");
993 ok(r == ERROR_SUCCESS, "failed to set string\n");
995 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
998 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
1001 r = MsiCloseHandle(hrec);
1002 ok(r == ERROR_SUCCESS, "failed to close record\n");
1003 r = MsiViewClose(hview);
1004 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1005 r = MsiCloseHandle(hview);
1006 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1008 r = MsiCloseHandle( hdb );
1009 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
1012 static MSIHANDLE create_db(void)
1017 DeleteFile(msifile);
1019 /* create an empty database */
1020 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
1021 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
1022 if( res != ERROR_SUCCESS )
1025 res = MsiDatabaseCommit( hdb );
1026 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
1031 static void test_getcolinfo(void)
1033 MSIHANDLE hdb, hview = 0, rec = 0;
1038 /* create an empty db */
1040 ok( hdb, "failed to create db\n");
1042 /* tables should be present */
1043 r = MsiDatabaseOpenView(hdb, "select * from _Tables", &hview);
1044 ok( r == ERROR_SUCCESS, "failed to open query\n");
1046 r = MsiViewExecute(hview, 0);
1047 ok( r == ERROR_SUCCESS, "failed to execute query\n");
1049 /* check that NAMES works */
1051 r = MsiViewGetColumnInfo( hview, MSICOLINFO_NAMES, &rec );
1052 ok( r == ERROR_SUCCESS, "failed to get names\n");
1054 r = MsiRecordGetString(rec, 1, buffer, &sz );
1055 ok( r == ERROR_SUCCESS, "failed to get string\n");
1056 ok( !strcmp(buffer,"Name"), "_Tables has wrong column name\n");
1057 r = MsiCloseHandle( rec );
1058 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1060 /* check that TYPES works */
1062 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, &rec );
1063 ok( r == ERROR_SUCCESS, "failed to get names\n");
1065 r = MsiRecordGetString(rec, 1, buffer, &sz );
1066 ok( r == ERROR_SUCCESS, "failed to get string\n");
1067 ok( !strcmp(buffer,"s64"), "_Tables has wrong column type\n");
1068 r = MsiCloseHandle( rec );
1069 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1071 /* check that invalid values fail */
1073 r = MsiViewGetColumnInfo( hview, 100, &rec );
1074 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1075 ok( rec == 0, "returned a record\n");
1077 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, NULL );
1078 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1080 r = MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES, &rec );
1081 ok( r == ERROR_INVALID_HANDLE, "wrong error code\n");
1083 r = MsiViewClose(hview);
1084 ok( r == ERROR_SUCCESS, "failed to close view\n");
1085 r = MsiCloseHandle(hview);
1086 ok( r == ERROR_SUCCESS, "failed to close view handle\n");
1087 r = MsiCloseHandle(hdb);
1088 ok( r == ERROR_SUCCESS, "failed to close database\n");
1091 static MSIHANDLE get_column_info(MSIHANDLE hdb, const char *query, MSICOLINFO type)
1093 MSIHANDLE hview = 0, rec = 0;
1096 r = MsiDatabaseOpenView(hdb, query, &hview);
1097 if( r != ERROR_SUCCESS )
1100 r = MsiViewExecute(hview, 0);
1101 if( r == ERROR_SUCCESS )
1103 MsiViewGetColumnInfo( hview, type, &rec );
1104 MsiViewClose(hview);
1106 MsiCloseHandle(hview);
1110 static UINT get_columns_table_type(MSIHANDLE hdb, const char *table, UINT field)
1112 MSIHANDLE hview = 0, rec = 0;
1116 sprintf(query, "select * from `_Columns` where `Table` = '%s'", table );
1118 r = MsiDatabaseOpenView(hdb, query, &hview);
1119 if( r != ERROR_SUCCESS )
1122 r = MsiViewExecute(hview, 0);
1123 if( r == ERROR_SUCCESS )
1127 r = MsiViewFetch( hview, &rec );
1128 if( r != ERROR_SUCCESS)
1130 r = MsiRecordGetInteger( rec, 2 );
1132 type = MsiRecordGetInteger( rec, 4 );
1133 MsiCloseHandle( rec );
1136 MsiViewClose(hview);
1138 MsiCloseHandle(hview);
1142 static BOOL check_record( MSIHANDLE rec, UINT field, LPCSTR val )
1149 r = MsiRecordGetString( rec, field, buffer, &sz );
1150 return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
1153 static void test_viewgetcolumninfo(void)
1155 MSIHANDLE hdb = 0, rec;
1159 ok( hdb, "failed to create db\n");
1161 r = run_query( hdb, 0,
1162 "CREATE TABLE `Properties` "
1163 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1164 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1166 /* check the column types */
1167 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_TYPES );
1168 ok( rec, "failed to get column info record\n" );
1170 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1171 ok( check_record( rec, 2, "S1"), "wrong record type\n");
1173 MsiCloseHandle( rec );
1175 /* check the type in _Columns */
1176 ok( 0x3dff == get_columns_table_type(hdb, "Properties", 1 ), "_columns table wrong\n");
1177 ok( 0x1d01 == get_columns_table_type(hdb, "Properties", 2 ), "_columns table wrong\n");
1179 /* now try the names */
1180 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_NAMES );
1181 ok( rec, "failed to get column info record\n" );
1183 ok( check_record( rec, 1, "Property"), "wrong record type\n");
1184 ok( check_record( rec, 2, "Value"), "wrong record type\n");
1186 MsiCloseHandle( rec );
1188 r = run_query( hdb, 0,
1189 "CREATE TABLE `Binary` "
1190 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
1191 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1193 /* check the column types */
1194 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_TYPES );
1195 ok( rec, "failed to get column info record\n" );
1197 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1198 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1200 MsiCloseHandle( rec );
1202 /* check the type in _Columns */
1203 ok( 0x3dff == get_columns_table_type(hdb, "Binary", 1 ), "_columns table wrong\n");
1204 ok( 0x1900 == get_columns_table_type(hdb, "Binary", 2 ), "_columns table wrong\n");
1206 /* now try the names */
1207 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_NAMES );
1208 ok( rec, "failed to get column info record\n" );
1210 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1211 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1212 MsiCloseHandle( rec );
1214 r = run_query( hdb, 0,
1215 "CREATE TABLE `UIText` "
1216 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1217 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1219 ok( 0x2d48 == get_columns_table_type(hdb, "UIText", 1 ), "_columns table wrong\n");
1220 ok( 0x1fff == get_columns_table_type(hdb, "UIText", 2 ), "_columns table wrong\n");
1222 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_NAMES );
1223 ok( rec, "failed to get column info record\n" );
1224 ok( check_record( rec, 1, "Key"), "wrong record type\n");
1225 ok( check_record( rec, 2, "Text"), "wrong record type\n");
1226 MsiCloseHandle( rec );
1228 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_TYPES );
1229 ok( rec, "failed to get column info record\n" );
1230 ok( check_record( rec, 1, "s72"), "wrong record type\n");
1231 ok( check_record( rec, 2, "L255"), "wrong record type\n");
1232 MsiCloseHandle( rec );
1234 MsiCloseHandle( hdb );
1237 static void test_msiexport(void)
1239 MSIHANDLE hdb = 0, hview = 0;
1242 char path[MAX_PATH];
1243 const char file[] = "phone.txt";
1247 const char expected[] =
1248 "id\tname\tnumber\r\n"
1251 "1\tAbe\t8675309\r\n";
1253 DeleteFile(msifile);
1255 /* just MsiOpenDatabase should not create a file */
1256 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1257 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1259 /* create a table */
1260 query = "CREATE TABLE `phone` ( "
1261 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1262 "PRIMARY KEY `id`)";
1263 r = MsiDatabaseOpenView(hdb, query, &hview);
1264 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1265 r = MsiViewExecute(hview, 0);
1266 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1267 r = MsiViewClose(hview);
1268 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1269 r = MsiCloseHandle(hview);
1270 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1272 /* insert a value into it */
1273 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
1274 "VALUES('1', 'Abe', '8675309')";
1275 r = MsiDatabaseOpenView(hdb, query, &hview);
1276 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1277 r = MsiViewExecute(hview, 0);
1278 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1279 r = MsiViewClose(hview);
1280 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1281 r = MsiCloseHandle(hview);
1282 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1284 GetCurrentDirectory(MAX_PATH, path);
1286 r = MsiDatabaseExport(hdb, "phone", path, file);
1287 ok(r == ERROR_SUCCESS, "MsiDatabaseExport failed\n");
1289 MsiCloseHandle(hdb);
1291 lstrcat(path, "\\");
1292 lstrcat(path, file);
1294 /* check the data that was written */
1296 memset(buffer, 0, sizeof buffer);
1297 handle = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
1298 if (handle != INVALID_HANDLE_VALUE)
1300 ReadFile(handle, buffer, sizeof buffer, &length, NULL);
1301 CloseHandle(handle);
1305 ok(0, "failed to open file %s\n", path);
1307 ok( length == strlen(expected), "length of data wrong\n");
1308 ok( !lstrcmp(buffer, expected), "data doesn't match\n");
1309 DeleteFile(msifile);
1312 static void test_longstrings(void)
1314 const char insert_query[] =
1315 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1317 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
1320 const DWORD STRING_LENGTH = 0x10005;
1322 DeleteFile(msifile);
1323 /* just MsiOpenDatabase should not create a file */
1324 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1325 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1327 /* create a table */
1329 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1330 ok(r == ERROR_SUCCESS, "query failed\n");
1332 /* try a insert a very long string */
1333 str = HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH+sizeof insert_query);
1334 len = strchr(insert_query, 'Z') - insert_query;
1335 strcpy(str, insert_query);
1336 memset(str+len, 'Z', STRING_LENGTH);
1337 strcpy(str+len+STRING_LENGTH, insert_query+len+1);
1338 r = try_query( hdb, str );
1339 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1341 HeapFree(GetProcessHeap(), 0, str);
1343 MsiDatabaseCommit(hdb);
1344 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
1345 MsiCloseHandle(hdb);
1347 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
1348 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1350 r = MsiDatabaseOpenView(hdb, "select * from `strings` where `id` = 1", &hview);
1351 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1353 r = MsiViewExecute(hview, 0);
1354 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1356 r = MsiViewFetch(hview, &hrec);
1357 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1359 MsiCloseHandle(hview);
1361 r = MsiRecordGetString(hrec, 2, NULL, &len);
1362 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1363 ok(len == STRING_LENGTH, "string length wrong\n");
1365 MsiCloseHandle(hrec);
1366 MsiCloseHandle(hdb);
1367 DeleteFile(msifile);
1370 static void create_file(const CHAR *name)
1375 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1376 ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
1377 WriteFile(file, name, strlen(name), &written, NULL);
1378 WriteFile(file, "\n", strlen("\n"), &written, NULL);
1382 static void test_streamtable(void)
1384 MSIHANDLE hdb = 0, rec, view;
1385 char file[MAX_PATH];
1391 ok( hdb, "failed to create db\n");
1393 r = run_query( hdb, 0,
1394 "CREATE TABLE `Properties` "
1395 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1396 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1398 r = run_query( hdb, 0,
1399 "INSERT INTO `Properties` "
1400 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1401 ok( r == ERROR_SUCCESS, "Failed to add to table\n" );
1403 r = MsiDatabaseCommit( hdb );
1404 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1406 MsiCloseHandle( hdb );
1408 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
1409 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1411 /* check the column types */
1412 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_TYPES );
1413 ok( rec, "failed to get column info record\n" );
1415 ok( check_record( rec, 1, "s62"), "wrong record type\n");
1416 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1418 MsiCloseHandle( rec );
1420 /* now try the names */
1421 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_NAMES );
1422 ok( rec, "failed to get column info record\n" );
1424 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1425 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1427 MsiCloseHandle( rec );
1429 /* insert a file into the _Streams table */
1430 create_file( "test.txt" );
1432 rec = MsiCreateRecord( 2 );
1433 MsiRecordSetString( rec, 1, "data" );
1435 r = MsiRecordSetStream( rec, 2, "test.txt" );
1436 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1438 DeleteFile("test.txt");
1440 r = MsiDatabaseOpenView( hdb,
1441 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view );
1442 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1444 r = MsiViewExecute( view, rec );
1445 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1447 MsiCloseHandle( rec );
1448 MsiCloseHandle( view );
1450 r = MsiDatabaseOpenView( hdb,
1451 "SELECT `Name`, `Data` FROM `_Streams`", &view );
1452 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1454 r = MsiViewExecute( view, 0 );
1455 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1457 r = MsiViewFetch( view, &rec );
1458 ok( r == ERROR_SUCCESS, "Failed to fetch record: %d\n", r);
1461 r = MsiRecordGetString( rec, 1, file, &size );
1462 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1463 ok( !lstrcmp(file, "data"), "Expected 'data', got %s\n", file);
1466 memset(buf, 0, MAX_PATH);
1467 r = MsiRecordReadStream( rec, 2, buf, &size );
1468 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1469 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf);
1471 MsiCloseHandle( rec );
1473 r = MsiViewFetch( view, &rec );
1474 ok( r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
1476 MsiCloseHandle( view );
1477 MsiCloseHandle( hdb );
1478 DeleteFile(msifile);
1481 static void test_where(void)
1483 MSIHANDLE hdb = 0, rec, view;
1491 ok( hdb, "failed to create db\n");
1493 r = run_query( hdb, 0,
1494 "CREATE TABLE `Media` ("
1495 "`DiskId` SHORT NOT NULL, "
1496 "`LastSequence` LONG, "
1497 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1498 "`Cabinet` CHAR(255), "
1499 "`VolumeLabel` CHAR(32), "
1500 "`Source` CHAR(72) "
1501 "PRIMARY KEY `DiskId`)" );
1502 ok( r == S_OK, "cannot create Media table: %d\n", r );
1504 r = run_query( hdb, 0, "INSERT INTO `Media` "
1505 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1506 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1507 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1509 r = run_query( hdb, 0, "INSERT INTO `Media` "
1510 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1511 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1512 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1514 r = run_query( hdb, 0, "INSERT INTO `Media` "
1515 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1516 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1517 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1519 query = "SELECT * FROM `Media`";
1520 r = do_query(hdb, query, &rec);
1521 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1522 ok( check_record( rec, 4, "zero.cab"), "wrong cabinet\n");
1523 MsiCloseHandle( rec );
1525 query = "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1526 r = do_query(hdb, query, &rec);
1527 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1528 ok( check_record( rec, 4, "one.cab"), "wrong cabinet\n");
1530 r = MsiRecordGetInteger(rec, 1);
1531 ok( 2 == r, "field wrong\n");
1532 r = MsiRecordGetInteger(rec, 2);
1533 ok( 1 == r, "field wrong\n");
1534 MsiCloseHandle( rec );
1536 query = "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1537 r = MsiDatabaseOpenView(hdb, query, &view);
1538 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1540 r = MsiViewExecute(view, 0);
1541 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1543 r = MsiViewFetch(view, &rec);
1544 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1546 count = MsiRecordGetFieldCount( rec );
1547 ok( count == 1, "Expected 1 record fields, got %d\n", count );
1550 r = MsiRecordGetString( rec, 1, buf, &size );
1551 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1552 ok( !lstrcmp( buf, "2" ),
1553 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf );
1554 MsiCloseHandle( rec );
1556 r = MsiViewFetch(view, &rec);
1557 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1560 r = MsiRecordGetString( rec, 1, buf, &size );
1561 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1562 ok( !lstrcmp( buf, "3" ),
1563 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf );
1564 MsiCloseHandle( rec );
1566 r = MsiViewFetch(view, &rec);
1567 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
1570 MsiCloseHandle(view);
1572 MsiCloseHandle( rec );
1575 query = "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1576 r = do_query(hdb, query, &rec);
1577 ok( r == ERROR_SUCCESS, "query failed: %d\n", r );
1578 MsiCloseHandle( rec );
1580 MsiCloseHandle( hdb );
1581 DeleteFile(msifile);
1584 static CHAR CURR_DIR[MAX_PATH];
1586 static const CHAR test_data[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1587 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1588 "TestTable\tFirstPrimaryColumn\n"
1589 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1591 static const CHAR two_primary[] = "PrimaryOne\tPrimaryTwo\n"
1593 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1597 static void write_file(const CHAR *filename, const char *data, int data_size)
1601 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
1602 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1604 WriteFile(hf, data, data_size, &size, NULL);
1608 static UINT add_table_to_db(MSIHANDLE hdb, LPCSTR table_data)
1612 write_file("temp_file", table_data, (lstrlen(table_data) - 1) * sizeof(char));
1613 r = MsiDatabaseImportA(hdb, CURR_DIR, "temp_file");
1614 DeleteFileA("temp_file");
1619 static void test_msiimport(void)
1621 MSIHANDLE hdb, view, rec;
1626 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
1628 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
1629 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1631 r = add_table_to_db(hdb, test_data);
1632 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1634 r = add_table_to_db(hdb, two_primary);
1635 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1637 query = "SELECT * FROM `TestTable`";
1638 r = MsiDatabaseOpenView(hdb, query, &view);
1639 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1641 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
1642 count = MsiRecordGetFieldCount(rec);
1643 ok(count == 9, "Expected 9, got %d\n", count);
1644 ok(check_record(rec, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
1645 ok(check_record(rec, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
1646 ok(check_record(rec, 3, "ShortInt"), "Expected ShortInt\n");
1647 ok(check_record(rec, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
1648 ok(check_record(rec, 5, "LongInt"), "Expected LongInt\n");
1649 ok(check_record(rec, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
1650 ok(check_record(rec, 7, "String"), "Expected String\n");
1651 ok(check_record(rec, 8, "LocalizableString"), "Expected LocalizableString\n");
1652 ok(check_record(rec, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
1653 MsiCloseHandle(rec);
1655 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
1656 count = MsiRecordGetFieldCount(rec);
1657 ok(count == 9, "Expected 9, got %d\n", count);
1658 ok(check_record(rec, 1, "s255"), "Expected s255\n");
1659 ok(check_record(rec, 2, "i2"), "Expected i2\n");
1660 ok(check_record(rec, 3, "i2"), "Expected i2\n");
1661 ok(check_record(rec, 4, "I2"), "Expected I2\n");
1662 ok(check_record(rec, 5, "i4"), "Expected i4\n");
1663 ok(check_record(rec, 6, "I4"), "Expected I4\n");
1664 ok(check_record(rec, 7, "S255"), "Expected S255\n");
1665 ok(check_record(rec, 8, "S0"), "Expected S0\n");
1666 ok(check_record(rec, 9, "s0"), "Expected s0\n");
1667 MsiCloseHandle(rec);
1669 query = "SELECT * FROM `TestTable`";
1670 r = do_query(hdb, query, &rec);
1671 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1672 ok(check_record(rec, 1, "stringage"), "Expected 'stringage'\n");
1673 ok(check_record(rec, 7, "another string"), "Expected 'another string'\n");
1674 ok(check_record(rec, 8, "localizable"), "Expected 'localizable'\n");
1675 ok(check_record(rec, 9, "duh"), "Expected 'duh'\n");
1677 i = MsiRecordGetInteger(rec, 2);
1678 ok(i == 5, "Expected 5, got %d\n", i);
1680 i = MsiRecordGetInteger(rec, 3);
1681 ok(i == 2, "Expected 2, got %d\n", i);
1683 i = MsiRecordGetInteger(rec, 4);
1684 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
1686 i = MsiRecordGetInteger(rec, 5);
1687 ok(i == 2147483640, "Expected 2147483640, got %d\n", i);
1689 i = MsiRecordGetInteger(rec, 6);
1690 ok(i == -2147483640, "Expected -2147483640, got %d\n", i);
1692 MsiCloseHandle(rec);
1693 MsiCloseHandle(view);
1695 query = "SELECT * FROM `TwoPrimary`";
1696 r = MsiDatabaseOpenView(hdb, query, &view);
1697 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1699 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
1700 count = MsiRecordGetFieldCount(rec);
1701 ok(count == 2, "Expected 2, got %d\n", count);
1702 ok(check_record(rec, 1, "PrimaryOne"), "Expected PrimaryOne\n");
1703 ok(check_record(rec, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
1705 MsiCloseHandle(rec);
1707 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
1708 count = MsiRecordGetFieldCount(rec);
1709 ok(count == 2, "Expected 2, got %d\n", count);
1710 ok(check_record(rec, 1, "s255"), "Expected s255\n");
1711 ok(check_record(rec, 2, "s255"), "Expected s255\n");
1712 MsiCloseHandle(rec);
1714 r = MsiViewExecute(view, 0);
1715 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1717 r = MsiViewFetch(view, &rec);
1718 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1720 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
1721 ok(check_record(rec, 2, "leaf"), "Expected 'leaf'\n");
1723 MsiCloseHandle(rec);
1725 r = MsiViewFetch(view, &rec);
1726 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1728 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
1729 ok(check_record(rec, 2, "flower"), "Expected 'flower'\n");
1731 MsiCloseHandle(rec);
1733 r = MsiViewFetch(view, &rec);
1734 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
1736 r = MsiViewClose(view);
1737 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1739 MsiCloseHandle(view);
1740 MsiCloseHandle(hdb);
1741 DeleteFileA(msifile);
1744 static void test_markers(void)
1751 ok( hdb, "failed to create db\n");
1753 rec = MsiCreateRecord(3);
1754 MsiRecordSetString(rec, 1, "Table");
1755 MsiRecordSetString(rec, 2, "Apples");
1756 MsiRecordSetString(rec, 3, "Oranges");
1758 /* try a legit create */
1759 query = "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1760 r = run_query(hdb, 0, query);
1761 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1762 MsiCloseHandle(rec);
1764 /* try table name as marker */
1765 rec = MsiCreateRecord(1);
1766 MsiRecordSetString(rec, 1, "Fable");
1767 query = "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1768 r = run_query(hdb, rec, query);
1769 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1771 /* verify that we just created a table called '?', not 'Fable' */
1772 r = try_query(hdb, "SELECT * from `Fable`");
1773 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1775 r = try_query(hdb, "SELECT * from `?`");
1776 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1778 /* try table name as marker without backticks */
1779 MsiRecordSetString(rec, 1, "Mable");
1780 query = "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1781 r = run_query(hdb, rec, query);
1782 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1784 /* try one column name as marker */
1785 MsiRecordSetString(rec, 1, "One");
1786 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1787 r = run_query(hdb, rec, query);
1788 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1789 MsiCloseHandle(rec);
1791 /* try column names as markers */
1792 rec = MsiCreateRecord(2);
1793 MsiRecordSetString(rec, 1, "One");
1794 MsiRecordSetString(rec, 2, "Two");
1795 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
1796 r = run_query(hdb, rec, query);
1797 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1798 MsiCloseHandle(rec);
1800 /* try names with backticks */
1801 rec = MsiCreateRecord(3);
1802 MsiRecordSetString(rec, 1, "One");
1803 MsiRecordSetString(rec, 2, "Two");
1804 MsiRecordSetString(rec, 3, "One");
1805 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1806 r = run_query(hdb, rec, query);
1807 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1809 /* try names with backticks, minus definitions */
1810 query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
1811 r = run_query(hdb, rec, query);
1812 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1814 /* try names without backticks */
1815 query = "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
1816 r = run_query(hdb, rec, query);
1817 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1818 MsiCloseHandle(rec);
1820 /* try one long marker */
1821 rec = MsiCreateRecord(1);
1822 MsiRecordSetString(rec, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
1823 query = "CREATE TABLE `Mable` ( ? )";
1824 r = run_query(hdb, rec, query);
1825 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1826 MsiCloseHandle(rec);
1828 /* try all names as markers */
1829 rec = MsiCreateRecord(4);
1830 MsiRecordSetString(rec, 1, "Mable");
1831 MsiRecordSetString(rec, 2, "One");
1832 MsiRecordSetString(rec, 3, "Two");
1833 MsiRecordSetString(rec, 4, "One");
1834 query = "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1835 r = run_query(hdb, rec, query);
1836 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1837 MsiCloseHandle(rec);
1839 /* try a legit insert */
1840 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
1841 r = run_query(hdb, 0, query);
1842 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1844 r = try_query(hdb, "SELECT * from `Table`");
1845 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1847 /* try values as markers */
1848 rec = MsiCreateRecord(2);
1849 MsiRecordSetInteger(rec, 1, 4);
1850 MsiRecordSetString(rec, 2, "hi");
1851 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1852 r = run_query(hdb, rec, query);
1853 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1854 MsiCloseHandle(rec);
1856 /* try column names and values as markers */
1857 rec = MsiCreateRecord(4);
1858 MsiRecordSetString(rec, 1, "One");
1859 MsiRecordSetString(rec, 2, "Two");
1860 MsiRecordSetInteger(rec, 3, 5);
1861 MsiRecordSetString(rec, 4, "hi");
1862 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
1863 r = run_query(hdb, rec, query);
1864 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1865 MsiCloseHandle(rec);
1867 /* try column names as markers */
1868 rec = MsiCreateRecord(2);
1869 MsiRecordSetString(rec, 1, "One");
1870 MsiRecordSetString(rec, 2, "Two");
1871 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
1872 r = run_query(hdb, rec, query);
1873 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1874 MsiCloseHandle(rec);
1876 /* try table name as a marker */
1877 rec = MsiCreateRecord(1);
1878 MsiRecordSetString(rec, 1, "Table");
1879 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
1880 r = run_query(hdb, rec, query);
1881 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1882 MsiCloseHandle(rec);
1884 /* try table name and values as markers */
1885 rec = MsiCreateRecord(3);
1886 MsiRecordSetString(rec, 1, "Table");
1887 MsiRecordSetInteger(rec, 2, 10);
1888 MsiRecordSetString(rec, 3, "haha");
1889 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
1890 r = run_query(hdb, rec, query);
1891 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
1892 MsiCloseHandle(rec);
1894 /* try all markers */
1895 rec = MsiCreateRecord(5);
1896 MsiRecordSetString(rec, 1, "Table");
1897 MsiRecordSetString(rec, 1, "One");
1898 MsiRecordSetString(rec, 1, "Two");
1899 MsiRecordSetInteger(rec, 2, 10);
1900 MsiRecordSetString(rec, 3, "haha");
1901 query = "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
1902 r = run_query(hdb, rec, query);
1903 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1904 MsiCloseHandle(rec);
1906 /* insert an integer as a string */
1907 rec = MsiCreateRecord(2);
1908 MsiRecordSetString(rec, 1, "11");
1909 MsiRecordSetString(rec, 2, "hi");
1910 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1911 r = run_query(hdb, rec, query);
1912 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1913 MsiCloseHandle(rec);
1915 /* leave off the '' for the string */
1916 rec = MsiCreateRecord(2);
1917 MsiRecordSetInteger(rec, 1, 12);
1918 MsiRecordSetString(rec, 2, "hi");
1919 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
1920 r = run_query(hdb, rec, query);
1921 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1922 MsiCloseHandle(rec);
1924 MsiCloseHandle(hdb);
1925 DeleteFileA(msifile);
1928 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
1929 static void test_handle_limit(void)
1933 MSIHANDLE hviews[MY_NVIEWS];
1936 /* create an empty db */
1938 ok( hdb, "failed to create db\n");
1940 memset(hviews, 0, sizeof(hviews));
1942 for (i=0; i<MY_NVIEWS; i++) {
1943 static char szQueryBuf[256] = "SELECT * from `_Tables`";
1944 hviews[i] = 0xdeadbeeb;
1945 r = MsiDatabaseOpenView(hdb, szQueryBuf, &hviews[i]);
1946 if( r != ERROR_SUCCESS || hviews[i] == 0xdeadbeeb ||
1947 hviews[i] == 0 || (i && (hviews[i] == hviews[i-1])))
1951 ok( i == MY_NVIEWS, "problem opening views\n");
1953 for (i=0; i<MY_NVIEWS; i++) {
1954 if (hviews[i] != 0 && hviews[i] != 0xdeadbeeb) {
1955 r = MsiCloseHandle(hviews[i]);
1956 if (r != ERROR_SUCCESS)
1961 ok( i == MY_NVIEWS, "problem closing views\n");
1963 r = MsiCloseHandle(hdb);
1964 ok( r == ERROR_SUCCESS, "failed to close database\n");
1967 static void generate_transform(void)
1969 MSIHANDLE hdb1, hdb2, hrec;
1973 /* start with two identical databases */
1974 CopyFile(msifile2, msifile, FALSE);
1976 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb1 );
1977 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
1979 r = MsiDatabaseCommit( hdb1 );
1980 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1982 r = MsiOpenDatabase(msifile2, MSIDBOPEN_READONLY, &hdb2 );
1983 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
1985 /* the transform between two identical database should be empty */
1986 r = MsiDatabaseGenerateTransform(hdb1, hdb2, NULL, 0, 0);
1988 ok( r == ERROR_NO_DATA, "return code %d, should be ERROR_NO_DATA\n", r );
1991 query = "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
1992 r = run_query(hdb1, 0, query);
1993 ok(r == ERROR_SUCCESS, "failed to add table\n");
1995 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
1996 r = run_query(hdb1, 0, query);
1997 ok(r == ERROR_SUCCESS, "failed to add row 1\n");
1999 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
2000 r = run_query(hdb1, 0, query);
2001 ok(r == ERROR_SUCCESS, "failed to add row 2\n");
2003 query = "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
2004 r = run_query(hdb1, 0, query);
2005 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2007 query = "DELETE FROM `MOO` WHERE `NOO` = 3";
2008 r = run_query(hdb1, 0, query);
2009 ok(r == ERROR_SUCCESS, "failed to delete row\n");
2011 hrec = MsiCreateRecord(2);
2012 r = MsiRecordSetInteger(hrec, 1, 1);
2013 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2015 write_file("testdata.bin", "naengmyon", 9);
2016 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2017 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2019 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2020 r = run_query(hdb1, hrec, query);
2021 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2023 MsiCloseHandle(hrec);
2025 query = "ALTER TABLE `MOO` ADD `COW` INTEGER";
2026 r = run_query(hdb1, 0, query);
2027 ok(r == ERROR_SUCCESS, "failed to add column\n");
2029 query = "ALTER TABLE `MOO` ADD `PIG` INTEGER";
2030 r = run_query(hdb1, 0, query);
2031 ok(r == ERROR_SUCCESS, "failed to add column\n");
2033 query = "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
2034 r = run_query(hdb1, 0, query);
2035 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2037 query = "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
2038 "`Value` CHAR(0) PRIMARY KEY `Property`)";
2039 r = run_query(hdb1, 0, query);
2040 ok(r == ERROR_SUCCESS, "failed to add property table\n");
2042 query = "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2043 r = run_query(hdb1, 0, query);
2044 ok(r == ERROR_SUCCESS, "failed to add property\n");
2046 /* database needs to be committed */
2047 MsiDatabaseCommit(hdb1);
2049 r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
2050 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
2052 MsiCloseHandle( hdb1 );
2053 MsiCloseHandle( hdb2 );
2055 DeleteFile("testdata.bin");
2058 /* data for generating a transform */
2060 /* tables transform names - encoded as they would be in an msi database file */
2061 static const WCHAR name1[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
2062 static const WCHAR name2[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
2063 static const WCHAR name3[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
2064 static const WCHAR name4[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2065 static const WCHAR name5[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2066 static const WCHAR name6[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
2067 static const WCHAR name7[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
2068 static const WCHAR name8[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
2069 static const WCHAR name9[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2071 /* data in each table */
2072 static const WCHAR data1[] = { /* AAR */
2073 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
2074 0x0201, 0x0009, 0x8002,
2076 static const WCHAR data2[] = { /* _Columns */
2077 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
2078 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
2079 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
2080 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
2081 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
2082 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
2084 static const WCHAR data3[] = { /* _Tables */
2085 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
2088 static const char data4[] = /* _StringData */
2089 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
2090 static const WCHAR data5[] = { /* _StringPool */
2092 0, 0, /* string 0 '' */
2093 3, 2, /* string 1 'MOO' */
2094 3, 1, /* string 2 'COW' */
2095 3, 1, /* string 3 'PIG' */
2096 1, 1, /* string 4 'c' */
2097 3, 3, /* string 5 'AAR' */
2098 3, 1, /* string 6 'CAR' */
2099 3, 1, /* string 7 'BAR' */
2100 2, 1, /* string 8 'vw' */
2101 3, 1, /* string 9 'bmw' */
2102 8, 4, /* string 10 'Property' */
2103 5, 1, /* string 11 'Value' */
2104 4, 1, /* string 12 'prop' */
2105 3, 1, /* string 13 'val' */
2107 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
2108 static const WCHAR data6[] = { /* MOO */
2109 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
2110 0x0000, 0x8003, /* delete row */
2113 static const WCHAR data7[] = { /* BINARY */
2114 0x0201, 0x8001, 0x0001,
2117 static const char data8[] = /* stream data for the BINARY table */
2120 static const WCHAR data9[] = { /* Property */
2121 0x0201, 0x000c, 0x000d,
2124 static const struct {
2128 } table_transform_data[] =
2130 { name1, data1, sizeof data1 },
2131 { name2, data2, sizeof data2 },
2132 { name3, data3, sizeof data3 },
2133 { name4, data4, sizeof data4 - 1 },
2134 { name5, data5, sizeof data5 },
2135 { name6, data6, sizeof data6 },
2136 { name7, data7, sizeof data7 },
2137 { name8, data8, sizeof data8 - 1 },
2138 { name9, data9, sizeof data9 },
2141 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2143 static void generate_transform_manual(void)
2145 IStorage *stg = NULL;
2150 const DWORD mode = STGM_CREATE|STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE;
2152 const CLSID CLSID_MsiTransform = { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2154 MultiByteToWideChar(CP_ACP, 0, mstfile, -1, name, 0x20);
2156 r = StgCreateDocfile(name, mode, 0, &stg);
2157 ok(r == S_OK, "failed to create storage\n");
2161 r = IStorage_SetClass( stg, &CLSID_MsiTransform );
2162 ok(r == S_OK, "failed to set storage type\n");
2164 for (i=0; i<NUM_TRANSFORM_TABLES; i++)
2166 r = IStorage_CreateStream( stg, table_transform_data[i].name,
2167 STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm );
2170 ok(0, "failed to create stream %08x\n", r);
2174 r = IStream_Write( stm, table_transform_data[i].data,
2175 table_transform_data[i].size, &count );
2176 if (FAILED(r) || count != table_transform_data[i].size)
2177 ok(0, "failed to write stream\n");
2178 IStream_Release(stm);
2181 IStorage_Release(stg);
2184 static UINT set_summary_info(MSIHANDLE hdb)
2189 /* build summmary info */
2190 res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
2191 ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );
2193 res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
2194 "Installation Database");
2195 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2197 res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
2198 "Installation Database");
2199 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2201 res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
2203 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2205 res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
2207 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2209 res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
2210 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2211 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2213 res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
2214 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2216 res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
2217 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2219 res = MsiSummaryInfoPersist(suminfo);
2220 ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );
2222 res = MsiCloseHandle( suminfo);
2223 ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );
2228 static MSIHANDLE create_package_db(LPCSTR filename)
2233 DeleteFile(msifile);
2235 /* create an empty database */
2236 res = MsiOpenDatabase(filename, MSIDBOPEN_CREATE, &hdb );
2237 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
2238 if( res != ERROR_SUCCESS )
2241 res = MsiDatabaseCommit( hdb );
2242 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
2244 res = set_summary_info(hdb);
2246 res = run_query( hdb, 0,
2247 "CREATE TABLE `Directory` ( "
2248 "`Directory` CHAR(255) NOT NULL, "
2249 "`Directory_Parent` CHAR(255), "
2250 "`DefaultDir` CHAR(255) NOT NULL "
2251 "PRIMARY KEY `Directory`)" );
2252 ok( res == ERROR_SUCCESS , "Failed to create directory table\n" );
2257 static void test_try_transform(void)
2259 MSIHANDLE hdb, hview, hrec, hpkg;
2263 char buffer[MAX_PATH];
2265 DeleteFile(msifile);
2266 DeleteFile(msifile2);
2267 DeleteFile(mstfile);
2269 /* create the database */
2270 hdb = create_package_db(msifile2);
2271 ok(hdb, "Failed to create package db\n");
2273 query = "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
2274 r = run_query(hdb, 0, query);
2275 ok(r == ERROR_SUCCESS, "failed to add table\n");
2277 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
2278 r = run_query(hdb, 0, query);
2279 ok(r == ERROR_SUCCESS, "failed to add row\n");
2281 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
2282 r = run_query(hdb, 0, query);
2283 ok(r == ERROR_SUCCESS, "failed to add row\n");
2285 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
2286 r = run_query(hdb, 0, query);
2287 ok(r == ERROR_SUCCESS, "failed to add row\n");
2289 query = "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
2290 r = run_query(hdb, 0, query);
2291 ok(r == ERROR_SUCCESS, "failed to add table\n");
2293 hrec = MsiCreateRecord(2);
2294 r = MsiRecordSetInteger(hrec, 1, 2);
2295 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2297 write_file("testdata.bin", "lamyon", 6);
2298 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2299 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2301 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2302 r = run_query(hdb, hrec, query);
2303 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2305 MsiCloseHandle(hrec);
2307 r = MsiDatabaseCommit( hdb );
2308 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
2310 MsiCloseHandle( hdb );
2311 DeleteFileA("testdata.bin");
2314 * Both these generate an equivilent transform,
2315 * but the first doesn't work in Wine yet
2316 * because MsiDatabaseGenerateTransform is unimplemented.
2319 generate_transform();
2321 generate_transform_manual();
2323 r = MsiOpenDatabase(msifile2, MSIDBOPEN_DIRECT, &hdb );
2324 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2326 r = MsiDatabaseApplyTransform( hdb, mstfile, 0 );
2327 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
2329 MsiDatabaseCommit( hdb );
2331 /* check new values */
2333 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
2334 r = do_query(hdb, query, &hrec);
2335 ok(r == ERROR_SUCCESS, "select query failed\n");
2336 MsiCloseHandle(hrec);
2338 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
2340 r = do_query(hdb, query, &hrec);
2341 ok(r == ERROR_SUCCESS, "select query failed\n");
2342 MsiCloseHandle(hrec);
2344 /* check updated values */
2346 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
2347 r = do_query(hdb, query, &hrec);
2348 ok(r == ERROR_SUCCESS, "select query failed\n");
2349 MsiCloseHandle(hrec);
2351 /* check unchanged value */
2353 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
2354 r = do_query(hdb, query, &hrec);
2355 ok(r == ERROR_SUCCESS, "select query failed\n");
2356 MsiCloseHandle(hrec);
2358 /* check deleted value */
2360 query = "select * from `MOO` where `NOO` = 3";
2361 r = do_query(hdb, query, &hrec);
2362 ok(r == ERROR_NO_MORE_ITEMS, "select query failed\n");
2363 if (hrec) MsiCloseHandle(hrec);
2365 /* check added stream */
2367 query = "select `BLOB` from `BINARY` where `ID` = 1";
2368 r = do_query(hdb, query, &hrec);
2369 ok(r == ERROR_SUCCESS, "select query failed\n");
2371 /* check the contents of the stream */
2373 r = MsiRecordReadStream( hrec, 1, buffer, &sz );
2374 ok(r == ERROR_SUCCESS, "read stream failed\n");
2375 ok(!memcmp(buffer, "naengmyon", 9), "stream data was wrong\n");
2376 ok(sz == 9, "stream data was wrong size\n");
2377 if (hrec) MsiCloseHandle(hrec);
2379 /* check the validity of the table with a deleted row */
2381 query = "select * from `MOO`";
2382 r = MsiDatabaseOpenView(hdb, query, &hview);
2383 ok(r == ERROR_SUCCESS, "open view failed\n");
2385 r = MsiViewExecute(hview, 0);
2386 ok(r == ERROR_SUCCESS, "view execute failed\n");
2388 r = MsiViewFetch(hview, &hrec);
2389 ok(r == ERROR_SUCCESS, "view fetch failed\n");
2391 r = MsiRecordGetInteger(hrec, 1);
2392 ok(r == 1, "Expected 1, got %d\n", r);
2395 r = MsiRecordGetString(hrec, 2, buffer, &sz);
2396 ok(r == ERROR_SUCCESS, "record get string failed\n");
2397 ok(!lstrcmpA(buffer, "c"), "Expected c, got %s\n", buffer);
2399 r = MsiRecordGetInteger(hrec, 3);
2400 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2402 r = MsiRecordGetInteger(hrec, 4);
2403 ok(r == 5, "Expected 5, got %d\n", r);
2405 MsiCloseHandle(hrec);
2407 r = MsiViewFetch(hview, &hrec);
2408 ok(r == ERROR_SUCCESS, "view fetch failed\n");
2410 r = MsiRecordGetInteger(hrec, 1);
2411 ok(r == 2, "Expected 2, got %d\n", r);
2414 r = MsiRecordGetString(hrec, 2, buffer, &sz);
2415 ok(r == ERROR_SUCCESS, "record get string failed\n");
2416 ok(!lstrcmpA(buffer, "b"), "Expected b, got %s\n", buffer);
2418 r = MsiRecordGetInteger(hrec, 3);
2419 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2421 r = MsiRecordGetInteger(hrec, 4);
2422 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2424 MsiCloseHandle(hrec);
2426 r = MsiViewFetch(hview, &hrec);
2427 ok(r == ERROR_NO_MORE_ITEMS, "view fetch succeeded\n");
2429 MsiCloseHandle(hrec);
2430 MsiCloseHandle(hview);
2431 MsiCloseHandle(hdb);
2433 /* check that the property was added */
2434 r = MsiOpenPackage(msifile2, &hpkg);
2435 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2438 r = MsiGetProperty(hpkg, "prop", buffer, &sz);
2439 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2440 ok(!lstrcmp(buffer, "val"), "Expected val, got %s\n", buffer);
2442 MsiCloseHandle(hpkg);
2444 DeleteFile(msifile);
2445 DeleteFile(msifile2);
2446 DeleteFile(mstfile);
2451 const CHAR one[MAX_PATH];
2452 const CHAR two[MAX_PATH];
2455 struct join_res_4col
2457 const CHAR one[MAX_PATH];
2458 const CHAR two[MAX_PATH];
2459 const CHAR three[MAX_PATH];
2460 const CHAR four[MAX_PATH];
2463 static const struct join_res join_res_first[] =
2465 { "alveolar", "procerus" },
2466 { "septum", "procerus" },
2467 { "septum", "nasalis" },
2468 { "ramus", "nasalis" },
2469 { "malar", "mentalis" },
2472 static const struct join_res join_res_second[] =
2474 { "nasal", "septum" },
2475 { "mandible", "ramus" },
2478 static const struct join_res join_res_third[] =
2480 { "msvcp.dll", "abcdefgh" },
2481 { "msvcr.dll", "ijklmnop" },
2484 static const struct join_res join_res_fourth[] =
2486 { "msvcp.dll.01234", "single.dll.31415" },
2489 static const struct join_res join_res_fifth[] =
2491 { "malar", "procerus" },
2494 static const struct join_res join_res_sixth[] =
2496 { "malar", "procerus" },
2497 { "malar", "procerus" },
2498 { "malar", "nasalis" },
2499 { "malar", "nasalis" },
2500 { "malar", "nasalis" },
2501 { "malar", "mentalis" },
2504 static const struct join_res join_res_seventh[] =
2506 { "malar", "nasalis" },
2507 { "malar", "nasalis" },
2508 { "malar", "nasalis" },
2511 static const struct join_res_4col join_res_eighth[] =
2513 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
2514 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
2515 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
2516 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
2517 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
2518 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
2521 static void test_join(void)
2523 MSIHANDLE hdb, hview, hrec;
2531 ok( hdb, "failed to create db\n");
2533 r = create_component_table( hdb );
2534 ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
2536 r = add_component_entry( hdb, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
2537 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2539 r = add_component_entry( hdb, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
2540 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2542 r = add_component_entry( hdb, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
2543 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2545 r = add_component_entry( hdb, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
2546 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2548 r = create_feature_components_table( hdb );
2549 ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
2551 r = add_feature_components_entry( hdb, "'procerus', 'maxilla'" );
2552 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2554 r = add_feature_components_entry( hdb, "'procerus', 'nasal'" );
2555 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2557 r = add_feature_components_entry( hdb, "'nasalis', 'nasal'" );
2558 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2560 r = add_feature_components_entry( hdb, "'nasalis', 'mandible'" );
2561 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2563 r = add_feature_components_entry( hdb, "'nasalis', 'notacomponent'" );
2564 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2566 r = add_feature_components_entry( hdb, "'mentalis', 'zygomatic'" );
2567 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2569 r = create_std_dlls_table( hdb );
2570 ok( r == ERROR_SUCCESS, "cannot create StdDlls table: %d\n", r );
2572 r = add_std_dlls_entry( hdb, "'msvcp.dll', 'msvcp.dll.01234'" );
2573 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
2575 r = add_std_dlls_entry( hdb, "'msvcr.dll', 'msvcr.dll.56789'" );
2576 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
2578 r = create_binary_table( hdb );
2579 ok( r == ERROR_SUCCESS, "cannot create Binary table: %d\n", r );
2581 r = add_binary_entry( hdb, "'msvcp.dll.01234', 'abcdefgh'" );
2582 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
2584 r = add_binary_entry( hdb, "'msvcr.dll.56789', 'ijklmnop'" );
2585 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
2587 r = add_binary_entry( hdb, "'single.dll.31415', 'msvcp.dll'" );
2588 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
2590 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2591 "FROM `Component`, `FeatureComponents` "
2592 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
2593 "ORDER BY `Feature_`";
2594 r = MsiDatabaseOpenView(hdb, query, &hview);
2595 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2597 r = MsiViewExecute(hview, 0);
2598 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2601 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2603 count = MsiRecordGetFieldCount( hrec );
2604 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2607 r = MsiRecordGetString( hrec, 1, buf, &size );
2608 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2609 ok( !lstrcmp( buf, join_res_first[i].one ),
2610 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_first[i].one, buf );
2613 r = MsiRecordGetString( hrec, 2, buf, &size );
2614 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2615 ok( !lstrcmp( buf, join_res_first[i].two ),
2616 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_first[i].two, buf );
2619 MsiCloseHandle(hrec);
2622 ok( i == 5, "Expected 5 rows, got %d\n", i );
2623 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2625 MsiViewClose(hview);
2626 MsiCloseHandle(hview);
2628 /* try a join without a WHERE condition */
2629 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2630 "FROM `Component`, `FeatureComponents` ";
2631 r = MsiDatabaseOpenView(hdb, query, &hview);
2632 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2634 r = MsiViewExecute(hview, 0);
2635 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2638 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2641 MsiCloseHandle(hrec);
2643 ok( i == 24, "Expected 24 rows, got %d\n", i );
2645 MsiViewClose(hview);
2646 MsiCloseHandle(hview);
2648 query = "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
2649 "WHERE FeatureComponents.Component_=Component.Component "
2650 "AND (Feature_='nasalis') ORDER BY Feature_";
2651 r = MsiDatabaseOpenView(hdb, query, &hview);
2652 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2654 r = MsiViewExecute(hview, 0);
2655 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2658 data_correct = TRUE;
2659 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2661 count = MsiRecordGetFieldCount( hrec );
2662 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2665 r = MsiRecordGetString( hrec, 1, buf, &size );
2666 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2667 if( lstrcmp( buf, join_res_second[i].one ))
2668 data_correct = FALSE;
2671 r = MsiRecordGetString( hrec, 2, buf, &size );
2672 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2673 if( lstrcmp( buf, join_res_second[i].two ))
2674 data_correct = FALSE;
2677 MsiCloseHandle(hrec);
2680 ok( data_correct, "data returned in the wrong order\n");
2682 ok( i == 2, "Expected 2 rows, got %d\n", i );
2683 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2685 MsiViewClose(hview);
2686 MsiCloseHandle(hview);
2688 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2689 "FROM `StdDlls`, `Binary` "
2690 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
2692 r = MsiDatabaseOpenView(hdb, query, &hview);
2693 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2695 r = MsiViewExecute(hview, 0);
2696 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2699 data_correct = TRUE;
2700 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2702 count = MsiRecordGetFieldCount( hrec );
2703 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2706 r = MsiRecordGetString( hrec, 1, buf, &size );
2707 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2708 if( lstrcmp( buf, join_res_third[i].one ) )
2709 data_correct = FALSE;
2712 r = MsiRecordGetString( hrec, 2, buf, &size );
2713 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2714 if( lstrcmp( buf, join_res_third[i].two ) )
2715 data_correct = FALSE;
2718 MsiCloseHandle(hrec);
2720 ok( data_correct, "data returned in the wrong order\n");
2722 ok( i == 2, "Expected 2 rows, got %d\n", i );
2724 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2726 MsiViewClose(hview);
2727 MsiCloseHandle(hview);
2729 query = "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
2730 "FROM `StdDlls`, `Binary` "
2731 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
2733 r = MsiDatabaseOpenView(hdb, query, &hview);
2734 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2736 r = MsiViewExecute(hview, 0);
2737 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2740 data_correct = TRUE;
2741 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2743 count = MsiRecordGetFieldCount( hrec );
2744 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2747 r = MsiRecordGetString( hrec, 1, buf, &size );
2748 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2749 if( lstrcmp( buf, join_res_fourth[i].one ))
2750 data_correct = FALSE;
2753 r = MsiRecordGetString( hrec, 2, buf, &size );
2754 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2755 if( lstrcmp( buf, join_res_fourth[i].two ))
2756 data_correct = FALSE;
2759 MsiCloseHandle(hrec);
2761 ok( data_correct, "data returned in the wrong order\n");
2763 ok( i == 1, "Expected 1 rows, got %d\n", i );
2764 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2766 MsiViewClose(hview);
2767 MsiCloseHandle(hview);
2769 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2770 "FROM `Component`, `FeatureComponents` "
2771 "WHERE `Component`.`Component` = 'zygomatic' "
2772 "AND `FeatureComponents`.`Component_` = 'maxilla' "
2773 "ORDER BY `Feature_`";
2774 r = MsiDatabaseOpenView(hdb, query, &hview);
2775 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2777 r = MsiViewExecute(hview, 0);
2778 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2781 data_correct = TRUE;
2782 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2784 count = MsiRecordGetFieldCount( hrec );
2785 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2788 r = MsiRecordGetString( hrec, 1, buf, &size );
2789 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2790 if( lstrcmp( buf, join_res_fifth[i].one ))
2791 data_correct = FALSE;
2794 r = MsiRecordGetString( hrec, 2, buf, &size );
2795 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2796 if( lstrcmp( buf, join_res_fifth[i].two ))
2797 data_correct = FALSE;
2800 MsiCloseHandle(hrec);
2802 ok( data_correct, "data returned in the wrong order\n");
2804 ok( i == 1, "Expected 1 rows, got %d\n", i );
2805 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2807 MsiViewClose(hview);
2808 MsiCloseHandle(hview);
2810 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2811 "FROM `Component`, `FeatureComponents` "
2812 "WHERE `Component` = 'zygomatic' "
2813 "ORDER BY `Feature_`";
2814 r = MsiDatabaseOpenView(hdb, query, &hview);
2815 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2817 r = MsiViewExecute(hview, 0);
2820 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2824 data_correct = TRUE;
2825 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2827 count = MsiRecordGetFieldCount( hrec );
2828 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2831 r = MsiRecordGetString( hrec, 1, buf, &size );
2832 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2833 if( lstrcmp( buf, join_res_sixth[i].one ))
2834 data_correct = FALSE;
2837 r = MsiRecordGetString( hrec, 2, buf, &size );
2838 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2839 if( lstrcmp( buf, join_res_sixth[i].two ))
2840 data_correct = FALSE;
2843 MsiCloseHandle(hrec);
2845 ok( data_correct, "data returned in the wrong order\n");
2849 ok( i == 6, "Expected 6 rows, got %d\n", i );
2851 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2853 MsiViewClose(hview);
2854 MsiCloseHandle(hview);
2856 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2857 "FROM `Component`, `FeatureComponents` "
2858 "WHERE `Component` = 'zygomatic' "
2859 "AND `Feature_` = 'nasalis' "
2860 "ORDER BY `Feature_`";
2861 r = MsiDatabaseOpenView(hdb, query, &hview);
2862 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2864 r = MsiViewExecute(hview, 0);
2865 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2868 data_correct = TRUE;
2869 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2871 count = MsiRecordGetFieldCount( hrec );
2872 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2875 r = MsiRecordGetString( hrec, 1, buf, &size );
2876 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2877 if( lstrcmp( buf, join_res_seventh[i].one ))
2878 data_correct = FALSE;
2881 r = MsiRecordGetString( hrec, 2, buf, &size );
2882 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2883 if( lstrcmp( buf, join_res_seventh[i].two ))
2884 data_correct = FALSE;
2887 MsiCloseHandle(hrec);
2890 ok( data_correct, "data returned in the wrong order\n");
2891 ok( i == 3, "Expected 3 rows, got %d\n", i );
2892 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2894 MsiViewClose(hview);
2895 MsiCloseHandle(hview);
2897 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2898 "FROM `StdDlls`, `Binary` ";
2899 r = MsiDatabaseOpenView(hdb, query, &hview);
2900 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2902 r = MsiViewExecute(hview, 0);
2903 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2906 data_correct = TRUE;
2907 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2909 count = MsiRecordGetFieldCount( hrec );
2910 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2913 r = MsiRecordGetString( hrec, 1, buf, &size );
2914 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2915 if( lstrcmp( buf, join_res_eighth[i].one ))
2916 data_correct = FALSE;
2919 r = MsiRecordGetString( hrec, 2, buf, &size );
2920 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2921 if( lstrcmp( buf, join_res_eighth[i].four ))
2922 data_correct = FALSE;
2925 MsiCloseHandle(hrec);
2928 todo_wine ok( data_correct, "data returned in the wrong order\n");
2929 ok( i == 6, "Expected 6 rows, got %d\n", i );
2930 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2932 MsiViewClose(hview);
2933 MsiCloseHandle(hview);
2935 query = "SELECT * FROM `StdDlls`, `Binary` ";
2936 r = MsiDatabaseOpenView(hdb, query, &hview);
2937 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2939 r = MsiViewExecute(hview, 0);
2940 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2943 data_correct = TRUE;
2944 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2946 count = MsiRecordGetFieldCount( hrec );
2947 ok( count == 4, "Expected 4 record fields, got %d\n", count );
2950 r = MsiRecordGetString( hrec, 1, buf, &size );
2951 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2952 if( lstrcmp( buf, join_res_eighth[i].one ))
2953 data_correct = FALSE;
2956 r = MsiRecordGetString( hrec, 2, buf, &size );
2957 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2958 if( lstrcmp( buf, join_res_eighth[i].two ))
2959 data_correct = FALSE;
2962 r = MsiRecordGetString( hrec, 3, buf, &size );
2963 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2964 if( lstrcmp( buf, join_res_eighth[i].three ))
2965 data_correct = FALSE;
2968 r = MsiRecordGetString( hrec, 4, buf, &size );
2969 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2970 if( lstrcmp( buf, join_res_eighth[i].four ))
2971 data_correct = FALSE;
2974 MsiCloseHandle(hrec);
2976 todo_wine ok( data_correct, "data returned in the wrong order\n");
2978 ok( i == 6, "Expected 6 rows, got %d\n", i );
2979 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2981 MsiViewClose(hview);
2982 MsiCloseHandle(hview);
2984 MsiCloseHandle(hdb);
2985 DeleteFile(msifile);
2988 static void test_temporary_table(void)
2991 MSIHANDLE hdb = 0, view = 0, rec;
2997 cond = MsiDatabaseIsTablePersistent(0, NULL);
2998 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3001 ok( hdb, "failed to create db\n");
3003 cond = MsiDatabaseIsTablePersistent(hdb, NULL);
3004 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3007 cond = MsiDatabaseIsTablePersistent(hdb, "_Tables");
3008 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3010 cond = MsiDatabaseIsTablePersistent(hdb, "_Columns");
3011 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3014 cond = MsiDatabaseIsTablePersistent(hdb, "_Streams");
3015 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3017 query = "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
3018 r = run_query(hdb, 0, query);
3019 ok(r == ERROR_SUCCESS, "failed to add table\n");
3021 cond = MsiDatabaseIsTablePersistent(hdb, "P");
3022 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3024 query = "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
3025 r = run_query(hdb, 0, query);
3026 ok(r == ERROR_SUCCESS, "failed to add table\n");
3028 cond = MsiDatabaseIsTablePersistent(hdb, "P2");
3029 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3031 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3032 r = run_query(hdb, 0, query);
3033 ok(r == ERROR_SUCCESS, "failed to add table\n");
3035 cond = MsiDatabaseIsTablePersistent(hdb, "T");
3036 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
3038 query = "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3039 r = run_query(hdb, 0, query);
3040 ok(r == ERROR_SUCCESS, "failed to add table\n");
3043 cond = MsiDatabaseIsTablePersistent(hdb, "T2");
3044 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3047 query = "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
3048 r = run_query(hdb, 0, query);
3049 ok(r == ERROR_SUCCESS, "failed to add table\n");
3051 cond = MsiDatabaseIsTablePersistent(hdb, "T3");
3052 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3055 query = "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3056 r = run_query(hdb, 0, query);
3057 ok(r == ERROR_FUNCTION_FAILED, "failed to add table\n");
3059 cond = MsiDatabaseIsTablePersistent(hdb, "T4");
3060 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3063 query = "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
3064 r = run_query(hdb, 0, query);
3065 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add table\n");
3067 query = "select * from `T`";
3068 r = MsiDatabaseOpenView(hdb, query, &view);
3069 ok(r == ERROR_SUCCESS, "failed to query table\n");
3070 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
3071 ok(r == ERROR_SUCCESS, "failed to get column info\n");
3074 r = MsiRecordGetString(rec, 1, buf, &sz);
3075 ok(r == ERROR_SUCCESS, "failed to get string\n");
3076 todo_wine ok( 0 == strcmp("G255", buf), "wrong column type\n");
3079 r = MsiRecordGetString(rec, 2, buf, &sz);
3080 ok(r == ERROR_SUCCESS, "failed to get string\n");
3081 todo_wine ok( 0 == strcmp("j2", buf), "wrong column type\n");
3083 MsiCloseHandle( rec );
3084 MsiCloseHandle( view );
3086 /* query the table data */
3088 r = do_query(hdb, "select * from `_Tables` where `Name` = 'T'", &rec);
3089 ok( r == ERROR_SUCCESS, "temporary table exists in _Tables\n");
3090 MsiCloseHandle( rec );
3092 /* query the column data */
3094 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec);
3095 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3096 if (rec) MsiCloseHandle( rec );
3098 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec);
3099 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3100 if (rec) MsiCloseHandle( rec );
3102 MsiCloseHandle( hdb );
3104 DeleteFile(msifile);
3107 static void test_alter(void)
3115 ok( hdb, "failed to create db\n");
3117 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3118 r = run_query(hdb, 0, query);
3119 ok(r == ERROR_SUCCESS, "failed to add table\n");
3121 cond = MsiDatabaseIsTablePersistent(hdb, "T");
3122 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
3124 query = "ALTER TABLE `T` HOLD";
3125 r = run_query(hdb, 0, query);
3126 ok(r == ERROR_SUCCESS, "failed to hold table %d\n", r);
3128 query = "ALTER TABLE `T` FREE";
3129 r = run_query(hdb, 0, query);
3130 ok(r == ERROR_SUCCESS, "failed to free table\n");
3132 query = "ALTER TABLE `T` FREE";
3133 r = run_query(hdb, 0, query);
3134 ok(r == ERROR_SUCCESS, "failed to free table\n");
3136 query = "ALTER TABLE `T` FREE";
3137 r = run_query(hdb, 0, query);
3138 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to free table\n");
3140 query = "ALTER TABLE `T` HOLD";
3141 r = run_query(hdb, 0, query);
3142 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to hold table %d\n", r);
3144 /* table T is removed */
3145 query = "SELECT * FROM `T`";
3146 r = run_query(hdb, 0, query);
3147 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3149 /* create the table again */
3150 query = "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
3151 r = run_query(hdb, 0, query);
3152 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3154 /* up the ref count */
3155 query = "ALTER TABLE `U` HOLD";
3156 r = run_query(hdb, 0, query);
3157 ok(r == ERROR_SUCCESS, "failed to free table\n");
3159 /* add column, no data type */
3160 query = "ALTER TABLE `U` ADD `C`";
3161 r = run_query(hdb, 0, query);
3162 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3164 query = "ALTER TABLE `U` ADD `C` INTEGER";
3165 r = run_query(hdb, 0, query);
3166 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3168 /* add column C again */
3169 query = "ALTER TABLE `U` ADD `C` INTEGER";
3170 r = run_query(hdb, 0, query);
3171 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3173 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
3174 r = run_query(hdb, 0, query);
3175 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3177 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
3178 r = run_query(hdb, 0, query);
3179 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3181 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
3182 r = run_query(hdb, 0, query);
3183 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3185 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
3186 r = run_query(hdb, 0, query);
3187 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3189 query = "SELECT * FROM `U` WHERE `D` = 8";
3190 r = run_query(hdb, 0, query);
3191 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3193 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
3194 r = run_query(hdb, 0, query);
3195 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3197 query = "ALTER COLUMN `D` FREE";
3198 r = run_query(hdb, 0, query);
3199 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3201 /* drop the ref count */
3202 query = "ALTER TABLE `U` FREE";
3203 r = run_query(hdb, 0, query);
3204 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3206 /* table is not empty */
3207 query = "SELECT * FROM `U`";
3208 r = run_query(hdb, 0, query);
3209 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3211 /* column D is removed */
3212 query = "SELECT * FROM `U` WHERE `D` = 8";
3213 r = run_query(hdb, 0, query);
3214 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3216 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
3217 r = run_query(hdb, 0, query);
3218 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3220 /* add the column again */
3221 query = "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
3222 r = run_query(hdb, 0, query);
3223 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3225 /* up the ref count */
3226 query = "ALTER TABLE `U` HOLD";
3227 r = run_query(hdb, 0, query);
3228 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3230 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
3231 r = run_query(hdb, 0, query);
3232 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3234 query = "SELECT * FROM `U` WHERE `E` = 16";
3235 r = run_query(hdb, 0, query);
3236 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3238 /* drop the ref count */
3239 query = "ALTER TABLE `U` FREE";
3240 r = run_query(hdb, 0, query);
3241 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3243 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
3244 r = run_query(hdb, 0, query);
3245 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3247 query = "SELECT * FROM `U` WHERE `E` = 20";
3248 r = run_query(hdb, 0, query);
3249 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3251 /* drop the ref count */
3252 query = "ALTER TABLE `U` FREE";
3253 r = run_query(hdb, 0, query);
3254 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3256 /* table still exists */
3257 query = "SELECT * FROM `U`";
3258 r = run_query(hdb, 0, query);
3259 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3261 /* col E is removed */
3262 query = "SELECT * FROM `U` WHERE `E` = 20";
3263 r = run_query(hdb, 0, query);
3264 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3266 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
3267 r = run_query(hdb, 0, query);
3268 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3270 /* drop the ref count once more */
3271 query = "ALTER TABLE `U` FREE";
3272 r = run_query(hdb, 0, query);
3273 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3275 /* table still exists */
3276 query = "SELECT * FROM `U`";
3277 r = run_query(hdb, 0, query);
3278 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3280 MsiCloseHandle( hdb );
3281 DeleteFile(msifile);
3284 static void test_integers(void)
3286 MSIHANDLE hdb = 0, view = 0, rec = 0;
3291 /* just MsiOpenDatabase should not create a file */
3292 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3293 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3295 /* create a table */
3296 query = "CREATE TABLE `integers` ( "
3297 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
3298 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
3299 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
3300 "PRIMARY KEY `one`)";
3301 r = MsiDatabaseOpenView(hdb, query, &view);
3302 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3303 r = MsiViewExecute(view, 0);
3304 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3305 r = MsiViewClose(view);
3306 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3307 r = MsiCloseHandle(view);
3308 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3310 query = "SELECT * FROM `integers`";
3311 r = MsiDatabaseOpenView(hdb, query, &view);
3312 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3314 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
3315 count = MsiRecordGetFieldCount(rec);
3316 ok(count == 8, "Expected 8, got %d\n", count);
3317 ok(check_record(rec, 1, "one"), "Expected one\n");
3318 ok(check_record(rec, 2, "two"), "Expected two\n");
3319 ok(check_record(rec, 3, "three"), "Expected three\n");
3320 ok(check_record(rec, 4, "four"), "Expected four\n");
3321 ok(check_record(rec, 5, "five"), "Expected five\n");
3322 ok(check_record(rec, 6, "six"), "Expected six\n");
3323 ok(check_record(rec, 7, "seven"), "Expected seven\n");
3324 ok(check_record(rec, 8, "eight"), "Expected eight\n");
3325 MsiCloseHandle(rec);
3327 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
3328 count = MsiRecordGetFieldCount(rec);
3329 ok(count == 8, "Expected 8, got %d\n", count);
3330 ok(check_record(rec, 1, "I2"), "Expected I2\n");
3331 ok(check_record(rec, 2, "I2"), "Expected I2\n");
3332 ok(check_record(rec, 3, "I2"), "Expected I2\n");
3333 ok(check_record(rec, 4, "I4"), "Expected I4\n");
3334 ok(check_record(rec, 5, "i2"), "Expected i2\n");
3335 ok(check_record(rec, 6, "i2"), "Expected i2\n");
3336 ok(check_record(rec, 7, "i2"), "Expected i2\n");
3337 ok(check_record(rec, 8, "i4"), "Expected i4\n");
3338 MsiCloseHandle(rec);
3341 MsiCloseHandle(view);
3343 /* insert values into it, NULL where NOT NULL is specified */
3344 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3345 "VALUES('', '', '', '', '', '', '', '')";
3346 r = MsiDatabaseOpenView(hdb, query, &view);
3347 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3348 r = MsiViewExecute(view, 0);
3349 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
3352 MsiCloseHandle(view);
3354 query = "SELECT * FROM `integers`";
3355 r = do_query(hdb, query, &rec);
3356 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3358 r = MsiRecordGetFieldCount(rec);
3359 ok(r == -1, "record count wrong: %d\n", r);
3361 MsiCloseHandle(rec);
3363 /* insert legitimate values into it */
3364 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3365 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
3366 r = MsiDatabaseOpenView(hdb, query, &view);
3367 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3368 r = MsiViewExecute(view, 0);
3369 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3371 query = "SELECT * FROM `integers`";
3372 r = do_query(hdb, query, &rec);
3373 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3375 r = MsiRecordGetFieldCount(rec);
3376 ok(r == 8, "record count wrong: %d\n", r);
3378 i = MsiRecordGetInteger(rec, 1);
3379 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
3380 i = MsiRecordGetInteger(rec, 3);
3381 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
3382 i = MsiRecordGetInteger(rec, 2);
3383 ok(i == 2, "Expected 2, got %d\n", i);
3384 i = MsiRecordGetInteger(rec, 4);
3385 ok(i == 4, "Expected 4, got %d\n", i);
3386 i = MsiRecordGetInteger(rec, 5);
3387 ok(i == 5, "Expected 5, got %d\n", i);
3388 i = MsiRecordGetInteger(rec, 6);
3389 ok(i == 6, "Expected 6, got %d\n", i);
3390 i = MsiRecordGetInteger(rec, 7);
3391 ok(i == 7, "Expected 7, got %d\n", i);
3392 i = MsiRecordGetInteger(rec, 8);
3393 ok(i == 8, "Expected 8, got %d\n", i);
3395 MsiCloseHandle(rec);
3397 MsiCloseHandle(view);
3399 r = MsiDatabaseCommit(hdb);
3400 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
3402 r = MsiCloseHandle(hdb);
3403 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3405 r = DeleteFile(msifile);
3406 ok(r == TRUE, "file didn't exist after commit\n");
3409 static void test_update(void)
3411 MSIHANDLE hdb = 0, view = 0, rec = 0;
3412 CHAR result[MAX_PATH];
3417 /* just MsiOpenDatabase should not create a file */
3418 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3419 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3421 /* create the Control table */
3422 query = "CREATE TABLE `Control` ( "
3423 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
3424 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
3425 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
3426 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
3427 r = MsiDatabaseOpenView(hdb, query, &view);
3428 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3429 r = MsiViewExecute(view, 0);
3430 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3431 r = MsiViewClose(view);
3432 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3433 r = MsiCloseHandle(view);
3434 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3437 query = "INSERT INTO `Control` ( "
3438 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3439 "`Property`, `Text`, `Control_Next`, `Help` )"
3440 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3441 r = MsiDatabaseOpenView(hdb, query, &view);
3442 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3443 r = MsiViewExecute(view, 0);
3444 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3445 r = MsiViewClose(view);
3446 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3447 r = MsiCloseHandle(view);
3448 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3450 /* add a second control */
3451 query = "INSERT INTO `Control` ( "
3452 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3453 "`Property`, `Text`, `Control_Next`, `Help` )"
3454 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
3455 r = MsiDatabaseOpenView(hdb, query, &view);
3456 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3457 r = MsiViewExecute(view, 0);
3458 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3459 r = MsiViewClose(view);
3460 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3461 r = MsiCloseHandle(view);
3462 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3464 /* add a third control */
3465 query = "INSERT INTO `Control` ( "
3466 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3467 "`Property`, `Text`, `Control_Next`, `Help` )"
3468 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3469 r = MsiDatabaseOpenView(hdb, query, &view);
3470 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3471 r = MsiViewExecute(view, 0);
3472 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3473 r = MsiViewClose(view);
3474 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3475 r = MsiCloseHandle(view);
3476 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3479 query = "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3480 r = MsiDatabaseOpenView(hdb, query, &view);
3481 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3483 /* bad set column */
3484 query = "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3485 r = MsiDatabaseOpenView(hdb, query, &view);
3486 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3488 /* bad where condition */
3489 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
3490 r = MsiDatabaseOpenView(hdb, query, &view);
3491 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3493 /* just the dialog_ specified */
3494 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3495 r = MsiDatabaseOpenView(hdb, query, &view);
3496 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3497 r = MsiViewExecute(view, 0);
3498 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3499 r = MsiViewClose(view);
3500 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3501 r = MsiCloseHandle(view);
3502 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3504 /* check the modified text */
3505 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3506 r = MsiDatabaseOpenView(hdb, query, &view);
3507 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3508 r = MsiViewExecute(view, 0);
3509 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3511 r = MsiViewFetch(view, &rec);
3512 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3515 r = MsiRecordGetString(rec, 1, result, &size);
3516 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3517 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3519 MsiCloseHandle(rec);
3521 r = MsiViewFetch(view, &rec);
3522 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3525 r = MsiRecordGetString(rec, 1, result, &size);
3526 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3527 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
3529 MsiCloseHandle(rec);
3531 r = MsiViewFetch(view, &rec);
3532 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3534 r = MsiViewClose(view);
3535 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3536 r = MsiCloseHandle(view);
3537 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3539 /* dialog_ and control specified */
3540 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
3541 r = MsiDatabaseOpenView(hdb, query, &view);
3542 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3543 r = MsiViewExecute(view, 0);
3544 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3545 r = MsiViewClose(view);
3546 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3547 r = MsiCloseHandle(view);
3548 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3550 /* check the modified text */
3551 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3552 r = MsiDatabaseOpenView(hdb, query, &view);
3553 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3554 r = MsiViewExecute(view, 0);
3555 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3557 r = MsiViewFetch(view, &rec);
3558 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3561 r = MsiRecordGetString(rec, 1, result, &size);
3562 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3563 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3565 MsiCloseHandle(rec);
3567 r = MsiViewFetch(view, &rec);
3568 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3571 r = MsiRecordGetString(rec, 1, result, &size);
3572 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3573 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
3575 MsiCloseHandle(rec);
3577 r = MsiViewFetch(view, &rec);
3578 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3580 r = MsiViewClose(view);
3581 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3582 r = MsiCloseHandle(view);
3583 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3585 /* no where condition */
3586 query = "UPDATE `Control` SET `Text` = 'this is text'";
3587 r = MsiDatabaseOpenView(hdb, query, &view);
3588 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3589 r = MsiViewExecute(view, 0);
3590 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3591 r = MsiViewClose(view);
3592 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3593 r = MsiCloseHandle(view);
3594 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3596 /* check the modified text */
3597 query = "SELECT `Text` FROM `Control`";
3598 r = MsiDatabaseOpenView(hdb, query, &view);
3599 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3600 r = MsiViewExecute(view, 0);
3601 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3603 r = MsiViewFetch(view, &rec);
3604 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3607 r = MsiRecordGetString(rec, 1, result, &size);
3608 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3609 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3611 MsiCloseHandle(rec);
3613 r = MsiViewFetch(view, &rec);
3614 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3617 r = MsiRecordGetString(rec, 1, result, &size);
3618 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3619 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3621 MsiCloseHandle(rec);
3623 r = MsiViewFetch(view, &rec);
3624 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3627 r = MsiRecordGetString(rec, 1, result, &size);
3628 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3629 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3631 MsiCloseHandle(rec);
3633 r = MsiViewFetch(view, &rec);
3634 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3636 r = MsiViewClose(view);
3637 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3638 r = MsiCloseHandle(view);
3639 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3640 r = MsiDatabaseCommit(hdb);
3641 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
3642 r = MsiCloseHandle(hdb);
3643 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3645 DeleteFile(msifile);
3648 static void test_special_tables(void)
3654 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3655 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3657 query = "CREATE TABLE `_Properties` ( "
3658 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3659 r = run_query(hdb, 0, query);
3660 ok(r == ERROR_SUCCESS, "failed to create table\n");
3662 query = "CREATE TABLE `_Streams` ( "
3663 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3664 r = run_query(hdb, 0, query);
3665 todo_wine ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Streams table\n");
3667 query = "CREATE TABLE `_Tables` ( "
3668 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3669 r = run_query(hdb, 0, query);
3670 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Tables table\n");
3672 query = "CREATE TABLE `_Columns` ( "
3673 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3674 r = run_query(hdb, 0, query);
3675 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Columns table\n");
3677 r = MsiCloseHandle(hdb);
3678 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3681 static void test_select_markers(void)
3683 MSIHANDLE hdb = 0, rec, view, res;
3690 ok( hdb, "failed to create db\n");
3692 r = run_query(hdb, 0,
3693 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
3694 ok(r == S_OK, "cannot create table: %d\n", r);
3696 r = run_query(hdb, 0, "INSERT INTO `Table` "
3697 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
3698 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3700 r = run_query(hdb, 0, "INSERT INTO `Table` "
3701 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
3702 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3704 r = run_query(hdb, 0, "INSERT INTO `Table` "
3705 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
3706 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3708 r = run_query(hdb, 0, "INSERT INTO `Table` "
3709 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
3710 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3712 rec = MsiCreateRecord(2);
3713 MsiRecordSetString(rec, 1, "apple");
3714 MsiRecordSetString(rec, 2, "two");
3716 query = "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
3717 r = MsiDatabaseOpenView(hdb, query, &view);
3718 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3720 r = MsiViewExecute(view, rec);
3723 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3726 r = MsiViewFetch(view, &res);
3729 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3733 r = MsiRecordGetString(res, 1, buf, &size);
3736 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3737 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
3741 r = MsiRecordGetString(res, 2, buf, &size);
3744 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3745 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
3748 r = MsiRecordGetInteger(res, 3);
3751 ok(r == 1, "Expected 1, got %d\n", r);
3754 MsiCloseHandle(res);
3756 r = MsiViewFetch(view, &res);
3759 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3763 r = MsiRecordGetString(res, 1, buf, &size);
3766 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3767 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
3771 r = MsiRecordGetString(res, 2, buf, &size);
3774 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3775 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
3778 r = MsiRecordGetInteger(res, 3);
3781 ok(r == 2, "Expected 2, got %d\n", r);
3784 MsiCloseHandle(res);
3786 r = MsiViewFetch(view, &res);
3787 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3789 r = MsiViewClose(view);
3790 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3791 r = MsiCloseHandle(view);
3792 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3793 r = MsiCloseHandle(hdb);
3794 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3796 DeleteFile(msifile);
3803 test_msidecomposedesc();
3804 test_msibadqueries();
3806 test_viewgetcolumninfo();
3814 test_handle_limit();
3815 test_try_transform();
3817 test_temporary_table();
3821 test_special_tables();
3822 test_select_markers();