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);
835 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
838 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
839 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
841 /* update the view, primary key */
842 r = MsiRecordSetInteger(hrec, 1, 5);
843 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
845 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
848 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
851 r = MsiCloseHandle(hrec);
852 ok(r == ERROR_SUCCESS, "failed to close record\n");
854 r = MsiViewClose(hview);
855 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
856 r = MsiCloseHandle(hview);
857 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
859 query = "SELECT * FROM `phone`";
860 r = MsiDatabaseOpenView(hdb, query, &hview);
861 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
863 r = MsiViewExecute(hview, 0);
864 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
866 r = MsiViewFetch(hview, &hrec);
867 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
869 r = MsiRecordGetInteger(hrec, 1);
870 ok(r == 1, "Expected 1, got %d\n", r);
873 r = MsiRecordGetString(hrec, 2, buffer, &sz);
874 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
875 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
878 r = MsiRecordGetString(hrec, 3, buffer, &sz);
879 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
880 ok(!lstrcmp(buffer, "3141592"), "Expected 3141592, got %s\n", buffer);
882 r = MsiCloseHandle(hrec);
883 ok(r == ERROR_SUCCESS, "failed to close record\n");
885 /* use a record that doesn't come from a view fetch */
886 hrec = MsiCreateRecord(3);
887 ok(hrec != 0, "MsiCreateRecord failed\n");
889 r = MsiRecordSetInteger(hrec, 1, 3);
890 ok(r == ERROR_SUCCESS, "failed to set integer\n");
891 r = MsiRecordSetString(hrec, 2, "jane");
892 ok(r == ERROR_SUCCESS, "failed to set string\n");
893 r = MsiRecordSetString(hrec, 3, "112358");
894 ok(r == ERROR_SUCCESS, "failed to set string\n");
896 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
899 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
902 r = MsiCloseHandle(hrec);
903 ok(r == ERROR_SUCCESS, "failed to close record\n");
905 /* use a record that doesn't come from a view fetch, primary key matches */
906 hrec = MsiCreateRecord(3);
907 ok(hrec != 0, "MsiCreateRecord failed\n");
909 r = MsiRecordSetInteger(hrec, 1, 1);
910 ok(r == ERROR_SUCCESS, "failed to set integer\n");
911 r = MsiRecordSetString(hrec, 2, "jane");
912 ok(r == ERROR_SUCCESS, "failed to set string\n");
913 r = MsiRecordSetString(hrec, 3, "112358");
914 ok(r == ERROR_SUCCESS, "failed to set string\n");
916 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
919 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
922 r = MsiCloseHandle(hrec);
923 ok(r == ERROR_SUCCESS, "failed to close record\n");
925 hrec = MsiCreateRecord(3);
927 r = MsiRecordSetInteger(hrec, 1, 2);
928 ok(r == ERROR_SUCCESS, "failed to set integer\n");
929 r = MsiRecordSetString(hrec, 2, "nick");
930 ok(r == ERROR_SUCCESS, "failed to set string\n");
931 r = MsiRecordSetString(hrec, 3, "141421");
932 ok(r == ERROR_SUCCESS, "failed to set string\n");
934 r = MsiViewExecute(hview, 0);
935 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
936 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
937 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
939 r = MsiViewClose(hview);
940 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
941 r = MsiCloseHandle(hview);
942 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
944 query = "SELECT * FROM `phone` WHERE `id` = 1";
945 r = MsiDatabaseOpenView(hdb, query, &hview);
946 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
947 r = MsiViewExecute(hview, 0);
948 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
949 r = MsiViewFetch(hview, &hrec);
950 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
952 /* change the id to match the second row */
953 r = MsiRecordSetInteger(hrec, 1, 2);
954 ok(r == ERROR_SUCCESS, "failed to set integer\n");
955 r = MsiRecordSetString(hrec, 2, "jerry");
956 ok(r == ERROR_SUCCESS, "failed to set string\n");
958 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
959 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
961 r = MsiCloseHandle(hrec);
962 ok(r == ERROR_SUCCESS, "failed to close record\n");
963 r = MsiViewClose(hview);
964 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
965 r = MsiCloseHandle(hview);
966 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
969 query = "SELECT * FROM `phone` ORDER BY `id`";
970 r = MsiDatabaseOpenView(hdb, query, &hview);
971 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
972 r = MsiViewExecute(hview, 0);
973 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
974 r = MsiViewFetch(hview, &hrec);
975 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
977 /* change the id to match the second row */
978 r = MsiRecordSetInteger(hrec, 1, 2);
979 ok(r == ERROR_SUCCESS, "failed to set integer\n");
980 r = MsiRecordSetString(hrec, 2, "jerry");
981 ok(r == ERROR_SUCCESS, "failed to set string\n");
983 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
984 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
986 r = MsiCloseHandle(hrec);
987 ok(r == ERROR_SUCCESS, "failed to close record\n");
988 r = MsiViewClose(hview);
989 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
990 r = MsiCloseHandle(hview);
991 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
993 r = MsiCloseHandle( hdb );
994 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
997 static MSIHANDLE create_db(void)
1002 DeleteFile(msifile);
1004 /* create an empty database */
1005 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
1006 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
1007 if( res != ERROR_SUCCESS )
1010 res = MsiDatabaseCommit( hdb );
1011 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
1016 static void test_getcolinfo(void)
1018 MSIHANDLE hdb, hview = 0, rec = 0;
1023 /* create an empty db */
1025 ok( hdb, "failed to create db\n");
1027 /* tables should be present */
1028 r = MsiDatabaseOpenView(hdb, "select * from _Tables", &hview);
1029 ok( r == ERROR_SUCCESS, "failed to open query\n");
1031 r = MsiViewExecute(hview, 0);
1032 ok( r == ERROR_SUCCESS, "failed to execute query\n");
1034 /* check that NAMES works */
1036 r = MsiViewGetColumnInfo( hview, MSICOLINFO_NAMES, &rec );
1037 ok( r == ERROR_SUCCESS, "failed to get names\n");
1039 r = MsiRecordGetString(rec, 1, buffer, &sz );
1040 ok( r == ERROR_SUCCESS, "failed to get string\n");
1041 ok( !strcmp(buffer,"Name"), "_Tables has wrong column name\n");
1042 r = MsiCloseHandle( rec );
1043 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1045 /* check that TYPES works */
1047 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, &rec );
1048 ok( r == ERROR_SUCCESS, "failed to get names\n");
1050 r = MsiRecordGetString(rec, 1, buffer, &sz );
1051 ok( r == ERROR_SUCCESS, "failed to get string\n");
1052 ok( !strcmp(buffer,"s64"), "_Tables has wrong column type\n");
1053 r = MsiCloseHandle( rec );
1054 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1056 /* check that invalid values fail */
1058 r = MsiViewGetColumnInfo( hview, 100, &rec );
1059 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1060 ok( rec == 0, "returned a record\n");
1062 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, NULL );
1063 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1065 r = MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES, &rec );
1066 ok( r == ERROR_INVALID_HANDLE, "wrong error code\n");
1068 r = MsiViewClose(hview);
1069 ok( r == ERROR_SUCCESS, "failed to close view\n");
1070 r = MsiCloseHandle(hview);
1071 ok( r == ERROR_SUCCESS, "failed to close view handle\n");
1072 r = MsiCloseHandle(hdb);
1073 ok( r == ERROR_SUCCESS, "failed to close database\n");
1076 static MSIHANDLE get_column_info(MSIHANDLE hdb, const char *query, MSICOLINFO type)
1078 MSIHANDLE hview = 0, rec = 0;
1081 r = MsiDatabaseOpenView(hdb, query, &hview);
1082 if( r != ERROR_SUCCESS )
1085 r = MsiViewExecute(hview, 0);
1086 if( r == ERROR_SUCCESS )
1088 MsiViewGetColumnInfo( hview, type, &rec );
1089 MsiViewClose(hview);
1091 MsiCloseHandle(hview);
1095 static UINT get_columns_table_type(MSIHANDLE hdb, const char *table, UINT field)
1097 MSIHANDLE hview = 0, rec = 0;
1101 sprintf(query, "select * from `_Columns` where `Table` = '%s'", table );
1103 r = MsiDatabaseOpenView(hdb, query, &hview);
1104 if( r != ERROR_SUCCESS )
1107 r = MsiViewExecute(hview, 0);
1108 if( r == ERROR_SUCCESS )
1112 r = MsiViewFetch( hview, &rec );
1113 if( r != ERROR_SUCCESS)
1115 r = MsiRecordGetInteger( rec, 2 );
1117 type = MsiRecordGetInteger( rec, 4 );
1118 MsiCloseHandle( rec );
1121 MsiViewClose(hview);
1123 MsiCloseHandle(hview);
1127 static BOOL check_record( MSIHANDLE rec, UINT field, LPCSTR val )
1134 r = MsiRecordGetString( rec, field, buffer, &sz );
1135 return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
1138 static void test_viewgetcolumninfo(void)
1140 MSIHANDLE hdb = 0, rec;
1144 ok( hdb, "failed to create db\n");
1146 r = run_query( hdb, 0,
1147 "CREATE TABLE `Properties` "
1148 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1149 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1151 /* check the column types */
1152 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_TYPES );
1153 ok( rec, "failed to get column info record\n" );
1155 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1156 ok( check_record( rec, 2, "S1"), "wrong record type\n");
1158 MsiCloseHandle( rec );
1160 /* check the type in _Columns */
1161 ok( 0x3dff == get_columns_table_type(hdb, "Properties", 1 ), "_columns table wrong\n");
1162 ok( 0x1d01 == get_columns_table_type(hdb, "Properties", 2 ), "_columns table wrong\n");
1164 /* now try the names */
1165 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_NAMES );
1166 ok( rec, "failed to get column info record\n" );
1168 ok( check_record( rec, 1, "Property"), "wrong record type\n");
1169 ok( check_record( rec, 2, "Value"), "wrong record type\n");
1171 MsiCloseHandle( rec );
1173 r = run_query( hdb, 0,
1174 "CREATE TABLE `Binary` "
1175 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
1176 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1178 /* check the column types */
1179 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_TYPES );
1180 ok( rec, "failed to get column info record\n" );
1182 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1183 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1185 MsiCloseHandle( rec );
1187 /* check the type in _Columns */
1188 ok( 0x3dff == get_columns_table_type(hdb, "Binary", 1 ), "_columns table wrong\n");
1189 ok( 0x1900 == get_columns_table_type(hdb, "Binary", 2 ), "_columns table wrong\n");
1191 /* now try the names */
1192 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_NAMES );
1193 ok( rec, "failed to get column info record\n" );
1195 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1196 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1197 MsiCloseHandle( rec );
1199 r = run_query( hdb, 0,
1200 "CREATE TABLE `UIText` "
1201 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1202 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1204 ok( 0x2d48 == get_columns_table_type(hdb, "UIText", 1 ), "_columns table wrong\n");
1205 ok( 0x1fff == get_columns_table_type(hdb, "UIText", 2 ), "_columns table wrong\n");
1207 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_NAMES );
1208 ok( rec, "failed to get column info record\n" );
1209 ok( check_record( rec, 1, "Key"), "wrong record type\n");
1210 ok( check_record( rec, 2, "Text"), "wrong record type\n");
1211 MsiCloseHandle( rec );
1213 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_TYPES );
1214 ok( rec, "failed to get column info record\n" );
1215 ok( check_record( rec, 1, "s72"), "wrong record type\n");
1216 ok( check_record( rec, 2, "L255"), "wrong record type\n");
1217 MsiCloseHandle( rec );
1219 MsiCloseHandle( hdb );
1222 static void test_msiexport(void)
1224 MSIHANDLE hdb = 0, hview = 0;
1227 char path[MAX_PATH];
1228 const char file[] = "phone.txt";
1232 const char expected[] =
1233 "id\tname\tnumber\r\n"
1236 "1\tAbe\t8675309\r\n";
1238 DeleteFile(msifile);
1240 /* just MsiOpenDatabase should not create a file */
1241 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1242 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1244 /* create a table */
1245 query = "CREATE TABLE `phone` ( "
1246 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1247 "PRIMARY KEY `id`)";
1248 r = MsiDatabaseOpenView(hdb, query, &hview);
1249 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1250 r = MsiViewExecute(hview, 0);
1251 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1252 r = MsiViewClose(hview);
1253 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1254 r = MsiCloseHandle(hview);
1255 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1257 /* insert a value into it */
1258 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
1259 "VALUES('1', 'Abe', '8675309')";
1260 r = MsiDatabaseOpenView(hdb, query, &hview);
1261 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1262 r = MsiViewExecute(hview, 0);
1263 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1264 r = MsiViewClose(hview);
1265 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1266 r = MsiCloseHandle(hview);
1267 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1269 GetCurrentDirectory(MAX_PATH, path);
1271 r = MsiDatabaseExport(hdb, "phone", path, file);
1272 ok(r == ERROR_SUCCESS, "MsiDatabaseExport failed\n");
1274 MsiCloseHandle(hdb);
1276 lstrcat(path, "\\");
1277 lstrcat(path, file);
1279 /* check the data that was written */
1281 memset(buffer, 0, sizeof buffer);
1282 handle = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
1283 if (handle != INVALID_HANDLE_VALUE)
1285 ReadFile(handle, buffer, sizeof buffer, &length, NULL);
1286 CloseHandle(handle);
1290 ok(0, "failed to open file %s\n", path);
1292 ok( length == strlen(expected), "length of data wrong\n");
1293 ok( !lstrcmp(buffer, expected), "data doesn't match\n");
1294 DeleteFile(msifile);
1297 static void test_longstrings(void)
1299 const char insert_query[] =
1300 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1302 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
1305 const DWORD STRING_LENGTH = 0x10005;
1307 DeleteFile(msifile);
1308 /* just MsiOpenDatabase should not create a file */
1309 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1310 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1312 /* create a table */
1314 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1315 ok(r == ERROR_SUCCESS, "query failed\n");
1317 /* try a insert a very long string */
1318 str = HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH+sizeof insert_query);
1319 len = strchr(insert_query, 'Z') - insert_query;
1320 strcpy(str, insert_query);
1321 memset(str+len, 'Z', STRING_LENGTH);
1322 strcpy(str+len+STRING_LENGTH, insert_query+len+1);
1323 r = try_query( hdb, str );
1324 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1326 HeapFree(GetProcessHeap(), 0, str);
1328 MsiDatabaseCommit(hdb);
1329 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
1330 MsiCloseHandle(hdb);
1332 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
1333 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1335 r = MsiDatabaseOpenView(hdb, "select * from `strings` where `id` = 1", &hview);
1336 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1338 r = MsiViewExecute(hview, 0);
1339 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1341 r = MsiViewFetch(hview, &hrec);
1342 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1344 MsiCloseHandle(hview);
1346 r = MsiRecordGetString(hrec, 2, NULL, &len);
1347 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1348 ok(len == STRING_LENGTH, "string length wrong\n");
1350 MsiCloseHandle(hrec);
1351 MsiCloseHandle(hdb);
1352 DeleteFile(msifile);
1355 static void create_file(const CHAR *name)
1360 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1361 ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
1362 WriteFile(file, name, strlen(name), &written, NULL);
1363 WriteFile(file, "\n", strlen("\n"), &written, NULL);
1367 static void test_streamtable(void)
1369 MSIHANDLE hdb = 0, rec, view;
1370 char file[MAX_PATH];
1376 ok( hdb, "failed to create db\n");
1378 r = run_query( hdb, 0,
1379 "CREATE TABLE `Properties` "
1380 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1381 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1383 r = run_query( hdb, 0,
1384 "INSERT INTO `Properties` "
1385 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1386 ok( r == ERROR_SUCCESS, "Failed to add to table\n" );
1388 r = MsiDatabaseCommit( hdb );
1389 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1391 MsiCloseHandle( hdb );
1393 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
1394 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1396 /* check the column types */
1397 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_TYPES );
1398 ok( rec, "failed to get column info record\n" );
1400 ok( check_record( rec, 1, "s62"), "wrong record type\n");
1401 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1403 MsiCloseHandle( rec );
1405 /* now try the names */
1406 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_NAMES );
1407 ok( rec, "failed to get column info record\n" );
1409 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1410 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1412 MsiCloseHandle( rec );
1414 /* insert a file into the _Streams table */
1415 create_file( "test.txt" );
1417 rec = MsiCreateRecord( 2 );
1418 MsiRecordSetString( rec, 1, "data" );
1420 r = MsiRecordSetStream( rec, 2, "test.txt" );
1421 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1423 DeleteFile("test.txt");
1425 r = MsiDatabaseOpenView( hdb,
1426 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view );
1427 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1429 r = MsiViewExecute( view, rec );
1430 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1432 MsiCloseHandle( rec );
1433 MsiCloseHandle( view );
1435 r = MsiDatabaseOpenView( hdb,
1436 "SELECT `Name`, `Data` FROM `_Streams`", &view );
1437 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1439 r = MsiViewExecute( view, 0 );
1440 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1442 r = MsiViewFetch( view, &rec );
1443 ok( r == ERROR_SUCCESS, "Failed to fetch record: %d\n", r);
1446 r = MsiRecordGetString( rec, 1, file, &size );
1447 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1448 ok( !lstrcmp(file, "data"), "Expected 'data', got %s\n", file);
1451 memset(buf, 0, MAX_PATH);
1452 r = MsiRecordReadStream( rec, 2, buf, &size );
1453 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1454 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf);
1456 MsiCloseHandle( rec );
1458 r = MsiViewFetch( view, &rec );
1459 ok( r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
1461 MsiCloseHandle( view );
1462 MsiCloseHandle( hdb );
1463 DeleteFile(msifile);
1466 static void test_where(void)
1468 MSIHANDLE hdb = 0, rec, view;
1476 ok( hdb, "failed to create db\n");
1478 r = run_query( hdb, 0,
1479 "CREATE TABLE `Media` ("
1480 "`DiskId` SHORT NOT NULL, "
1481 "`LastSequence` LONG, "
1482 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1483 "`Cabinet` CHAR(255), "
1484 "`VolumeLabel` CHAR(32), "
1485 "`Source` CHAR(72) "
1486 "PRIMARY KEY `DiskId`)" );
1487 ok( r == S_OK, "cannot create Media table: %d\n", r );
1489 r = run_query( hdb, 0, "INSERT INTO `Media` "
1490 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1491 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1492 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1494 r = run_query( hdb, 0, "INSERT INTO `Media` "
1495 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1496 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1497 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1499 r = run_query( hdb, 0, "INSERT INTO `Media` "
1500 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1501 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1502 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1504 query = "SELECT * FROM `Media`";
1505 r = do_query(hdb, query, &rec);
1506 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1507 ok( check_record( rec, 4, "zero.cab"), "wrong cabinet\n");
1508 MsiCloseHandle( rec );
1510 query = "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1511 r = do_query(hdb, query, &rec);
1512 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1513 ok( check_record( rec, 4, "one.cab"), "wrong cabinet\n");
1515 r = MsiRecordGetInteger(rec, 1);
1516 ok( 2 == r, "field wrong\n");
1517 r = MsiRecordGetInteger(rec, 2);
1518 ok( 1 == r, "field wrong\n");
1519 MsiCloseHandle( rec );
1521 query = "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1522 r = MsiDatabaseOpenView(hdb, query, &view);
1523 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1525 r = MsiViewExecute(view, 0);
1526 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1528 r = MsiViewFetch(view, &rec);
1529 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1531 count = MsiRecordGetFieldCount( rec );
1532 ok( count == 1, "Expected 1 record fields, got %d\n", count );
1535 r = MsiRecordGetString( rec, 1, buf, &size );
1536 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1537 ok( !lstrcmp( buf, "2" ),
1538 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf );
1539 MsiCloseHandle( rec );
1541 r = MsiViewFetch(view, &rec);
1542 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1545 r = MsiRecordGetString( rec, 1, buf, &size );
1546 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1547 ok( !lstrcmp( buf, "3" ),
1548 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf );
1549 MsiCloseHandle( rec );
1551 r = MsiViewFetch(view, &rec);
1552 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
1555 MsiCloseHandle(view);
1557 MsiCloseHandle( rec );
1560 query = "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1561 r = do_query(hdb, query, &rec);
1562 ok( r == ERROR_SUCCESS, "query failed: %d\n", r );
1563 MsiCloseHandle( rec );
1565 rec = MsiCreateRecord(1);
1566 MsiRecordSetString(rec, 1, "");
1568 query = "SELECT * FROM `Media` WHERE `DiskPrompt` = ?";
1569 r = MsiDatabaseOpenView(hdb, query, &view);
1570 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1571 r = MsiViewExecute(view, rec);
1572 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1574 MsiCloseHandle(rec);
1576 r = MsiViewFetch(view, &rec);
1577 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1579 MsiCloseHandle(rec);
1581 MsiCloseHandle(view);
1583 MsiCloseHandle( hdb );
1584 DeleteFile(msifile);
1587 static CHAR CURR_DIR[MAX_PATH];
1589 static const CHAR test_data[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1590 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1591 "TestTable\tFirstPrimaryColumn\n"
1592 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1594 static const CHAR two_primary[] = "PrimaryOne\tPrimaryTwo\n"
1596 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1600 static void write_file(const CHAR *filename, const char *data, int data_size)
1604 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
1605 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1607 WriteFile(hf, data, data_size, &size, NULL);
1611 static UINT add_table_to_db(MSIHANDLE hdb, LPCSTR table_data)
1615 write_file("temp_file", table_data, (lstrlen(table_data) - 1) * sizeof(char));
1616 r = MsiDatabaseImportA(hdb, CURR_DIR, "temp_file");
1617 DeleteFileA("temp_file");
1622 static void test_msiimport(void)
1624 MSIHANDLE hdb, view, rec;
1629 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
1631 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
1632 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1634 r = add_table_to_db(hdb, test_data);
1635 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1637 r = add_table_to_db(hdb, two_primary);
1638 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1640 query = "SELECT * FROM `TestTable`";
1641 r = MsiDatabaseOpenView(hdb, query, &view);
1642 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1644 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
1645 count = MsiRecordGetFieldCount(rec);
1646 ok(count == 9, "Expected 9, got %d\n", count);
1647 ok(check_record(rec, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
1648 ok(check_record(rec, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
1649 ok(check_record(rec, 3, "ShortInt"), "Expected ShortInt\n");
1650 ok(check_record(rec, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
1651 ok(check_record(rec, 5, "LongInt"), "Expected LongInt\n");
1652 ok(check_record(rec, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
1653 ok(check_record(rec, 7, "String"), "Expected String\n");
1654 ok(check_record(rec, 8, "LocalizableString"), "Expected LocalizableString\n");
1655 ok(check_record(rec, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
1656 MsiCloseHandle(rec);
1658 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
1659 count = MsiRecordGetFieldCount(rec);
1660 ok(count == 9, "Expected 9, got %d\n", count);
1661 ok(check_record(rec, 1, "s255"), "Expected s255\n");
1662 ok(check_record(rec, 2, "i2"), "Expected i2\n");
1663 ok(check_record(rec, 3, "i2"), "Expected i2\n");
1664 ok(check_record(rec, 4, "I2"), "Expected I2\n");
1665 ok(check_record(rec, 5, "i4"), "Expected i4\n");
1666 ok(check_record(rec, 6, "I4"), "Expected I4\n");
1667 ok(check_record(rec, 7, "S255"), "Expected S255\n");
1668 ok(check_record(rec, 8, "S0"), "Expected S0\n");
1669 ok(check_record(rec, 9, "s0"), "Expected s0\n");
1670 MsiCloseHandle(rec);
1672 query = "SELECT * FROM `TestTable`";
1673 r = do_query(hdb, query, &rec);
1674 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1675 ok(check_record(rec, 1, "stringage"), "Expected 'stringage'\n");
1676 ok(check_record(rec, 7, "another string"), "Expected 'another string'\n");
1677 ok(check_record(rec, 8, "localizable"), "Expected 'localizable'\n");
1678 ok(check_record(rec, 9, "duh"), "Expected 'duh'\n");
1680 i = MsiRecordGetInteger(rec, 2);
1681 ok(i == 5, "Expected 5, got %d\n", i);
1683 i = MsiRecordGetInteger(rec, 3);
1684 ok(i == 2, "Expected 2, got %d\n", i);
1686 i = MsiRecordGetInteger(rec, 4);
1687 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
1689 i = MsiRecordGetInteger(rec, 5);
1690 ok(i == 2147483640, "Expected 2147483640, got %d\n", i);
1692 i = MsiRecordGetInteger(rec, 6);
1693 ok(i == -2147483640, "Expected -2147483640, got %d\n", i);
1695 MsiCloseHandle(rec);
1696 MsiCloseHandle(view);
1698 query = "SELECT * FROM `TwoPrimary`";
1699 r = MsiDatabaseOpenView(hdb, query, &view);
1700 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1702 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
1703 count = MsiRecordGetFieldCount(rec);
1704 ok(count == 2, "Expected 2, got %d\n", count);
1705 ok(check_record(rec, 1, "PrimaryOne"), "Expected PrimaryOne\n");
1706 ok(check_record(rec, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
1708 MsiCloseHandle(rec);
1710 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
1711 count = MsiRecordGetFieldCount(rec);
1712 ok(count == 2, "Expected 2, got %d\n", count);
1713 ok(check_record(rec, 1, "s255"), "Expected s255\n");
1714 ok(check_record(rec, 2, "s255"), "Expected s255\n");
1715 MsiCloseHandle(rec);
1717 r = MsiViewExecute(view, 0);
1718 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1720 r = MsiViewFetch(view, &rec);
1721 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1723 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
1724 ok(check_record(rec, 2, "leaf"), "Expected 'leaf'\n");
1726 MsiCloseHandle(rec);
1728 r = MsiViewFetch(view, &rec);
1729 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1731 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
1732 ok(check_record(rec, 2, "flower"), "Expected 'flower'\n");
1734 MsiCloseHandle(rec);
1736 r = MsiViewFetch(view, &rec);
1737 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
1739 r = MsiViewClose(view);
1740 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1742 MsiCloseHandle(view);
1743 MsiCloseHandle(hdb);
1744 DeleteFileA(msifile);
1747 static void test_markers(void)
1754 ok( hdb, "failed to create db\n");
1756 rec = MsiCreateRecord(3);
1757 MsiRecordSetString(rec, 1, "Table");
1758 MsiRecordSetString(rec, 2, "Apples");
1759 MsiRecordSetString(rec, 3, "Oranges");
1761 /* try a legit create */
1762 query = "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1763 r = run_query(hdb, 0, query);
1764 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1765 MsiCloseHandle(rec);
1767 /* try table name as marker */
1768 rec = MsiCreateRecord(1);
1769 MsiRecordSetString(rec, 1, "Fable");
1770 query = "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1771 r = run_query(hdb, rec, query);
1772 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1774 /* verify that we just created a table called '?', not 'Fable' */
1775 r = try_query(hdb, "SELECT * from `Fable`");
1776 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1778 r = try_query(hdb, "SELECT * from `?`");
1779 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1781 /* try table name as marker without backticks */
1782 MsiRecordSetString(rec, 1, "Mable");
1783 query = "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1784 r = run_query(hdb, rec, query);
1785 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1787 /* try one column name as marker */
1788 MsiRecordSetString(rec, 1, "One");
1789 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1790 r = run_query(hdb, rec, query);
1791 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1792 MsiCloseHandle(rec);
1794 /* try column names as markers */
1795 rec = MsiCreateRecord(2);
1796 MsiRecordSetString(rec, 1, "One");
1797 MsiRecordSetString(rec, 2, "Two");
1798 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
1799 r = run_query(hdb, rec, query);
1800 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1801 MsiCloseHandle(rec);
1803 /* try names with backticks */
1804 rec = MsiCreateRecord(3);
1805 MsiRecordSetString(rec, 1, "One");
1806 MsiRecordSetString(rec, 2, "Two");
1807 MsiRecordSetString(rec, 3, "One");
1808 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1809 r = run_query(hdb, rec, query);
1810 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1812 /* try names with backticks, minus definitions */
1813 query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
1814 r = run_query(hdb, rec, query);
1815 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1817 /* try names without backticks */
1818 query = "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
1819 r = run_query(hdb, rec, query);
1820 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1821 MsiCloseHandle(rec);
1823 /* try one long marker */
1824 rec = MsiCreateRecord(1);
1825 MsiRecordSetString(rec, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
1826 query = "CREATE TABLE `Mable` ( ? )";
1827 r = run_query(hdb, rec, query);
1828 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1829 MsiCloseHandle(rec);
1831 /* try all names as markers */
1832 rec = MsiCreateRecord(4);
1833 MsiRecordSetString(rec, 1, "Mable");
1834 MsiRecordSetString(rec, 2, "One");
1835 MsiRecordSetString(rec, 3, "Two");
1836 MsiRecordSetString(rec, 4, "One");
1837 query = "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1838 r = run_query(hdb, rec, query);
1839 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1840 MsiCloseHandle(rec);
1842 /* try a legit insert */
1843 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
1844 r = run_query(hdb, 0, query);
1845 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1847 r = try_query(hdb, "SELECT * from `Table`");
1848 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1850 /* try values as markers */
1851 rec = MsiCreateRecord(2);
1852 MsiRecordSetInteger(rec, 1, 4);
1853 MsiRecordSetString(rec, 2, "hi");
1854 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1855 r = run_query(hdb, rec, query);
1856 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1857 MsiCloseHandle(rec);
1859 /* try column names and values as markers */
1860 rec = MsiCreateRecord(4);
1861 MsiRecordSetString(rec, 1, "One");
1862 MsiRecordSetString(rec, 2, "Two");
1863 MsiRecordSetInteger(rec, 3, 5);
1864 MsiRecordSetString(rec, 4, "hi");
1865 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
1866 r = run_query(hdb, rec, query);
1867 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1868 MsiCloseHandle(rec);
1870 /* try column names as markers */
1871 rec = MsiCreateRecord(2);
1872 MsiRecordSetString(rec, 1, "One");
1873 MsiRecordSetString(rec, 2, "Two");
1874 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
1875 r = run_query(hdb, rec, query);
1876 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1877 MsiCloseHandle(rec);
1879 /* try table name as a marker */
1880 rec = MsiCreateRecord(1);
1881 MsiRecordSetString(rec, 1, "Table");
1882 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
1883 r = run_query(hdb, rec, query);
1884 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1885 MsiCloseHandle(rec);
1887 /* try table name and values as markers */
1888 rec = MsiCreateRecord(3);
1889 MsiRecordSetString(rec, 1, "Table");
1890 MsiRecordSetInteger(rec, 2, 10);
1891 MsiRecordSetString(rec, 3, "haha");
1892 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
1893 r = run_query(hdb, rec, query);
1894 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
1895 MsiCloseHandle(rec);
1897 /* try all markers */
1898 rec = MsiCreateRecord(5);
1899 MsiRecordSetString(rec, 1, "Table");
1900 MsiRecordSetString(rec, 1, "One");
1901 MsiRecordSetString(rec, 1, "Two");
1902 MsiRecordSetInteger(rec, 2, 10);
1903 MsiRecordSetString(rec, 3, "haha");
1904 query = "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
1905 r = run_query(hdb, rec, query);
1906 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
1907 MsiCloseHandle(rec);
1909 /* insert an integer as a string */
1910 rec = MsiCreateRecord(2);
1911 MsiRecordSetString(rec, 1, "11");
1912 MsiRecordSetString(rec, 2, "hi");
1913 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1914 r = run_query(hdb, rec, query);
1915 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1916 MsiCloseHandle(rec);
1918 /* leave off the '' for the string */
1919 rec = MsiCreateRecord(2);
1920 MsiRecordSetInteger(rec, 1, 12);
1921 MsiRecordSetString(rec, 2, "hi");
1922 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
1923 r = run_query(hdb, rec, query);
1924 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1925 MsiCloseHandle(rec);
1927 MsiCloseHandle(hdb);
1928 DeleteFileA(msifile);
1931 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
1932 static void test_handle_limit(void)
1936 MSIHANDLE hviews[MY_NVIEWS];
1939 /* create an empty db */
1941 ok( hdb, "failed to create db\n");
1943 memset(hviews, 0, sizeof(hviews));
1945 for (i=0; i<MY_NVIEWS; i++) {
1946 static char szQueryBuf[256] = "SELECT * from `_Tables`";
1947 hviews[i] = 0xdeadbeeb;
1948 r = MsiDatabaseOpenView(hdb, szQueryBuf, &hviews[i]);
1949 if( r != ERROR_SUCCESS || hviews[i] == 0xdeadbeeb ||
1950 hviews[i] == 0 || (i && (hviews[i] == hviews[i-1])))
1954 ok( i == MY_NVIEWS, "problem opening views\n");
1956 for (i=0; i<MY_NVIEWS; i++) {
1957 if (hviews[i] != 0 && hviews[i] != 0xdeadbeeb) {
1958 r = MsiCloseHandle(hviews[i]);
1959 if (r != ERROR_SUCCESS)
1964 ok( i == MY_NVIEWS, "problem closing views\n");
1966 r = MsiCloseHandle(hdb);
1967 ok( r == ERROR_SUCCESS, "failed to close database\n");
1970 static void generate_transform(void)
1972 MSIHANDLE hdb1, hdb2, hrec;
1976 /* start with two identical databases */
1977 CopyFile(msifile2, msifile, FALSE);
1979 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb1 );
1980 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
1982 r = MsiDatabaseCommit( hdb1 );
1983 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1985 r = MsiOpenDatabase(msifile2, MSIDBOPEN_READONLY, &hdb2 );
1986 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
1988 /* the transform between two identical database should be empty */
1989 r = MsiDatabaseGenerateTransform(hdb1, hdb2, NULL, 0, 0);
1991 ok( r == ERROR_NO_DATA, "return code %d, should be ERROR_NO_DATA\n", r );
1994 query = "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
1995 r = run_query(hdb1, 0, query);
1996 ok(r == ERROR_SUCCESS, "failed to add table\n");
1998 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
1999 r = run_query(hdb1, 0, query);
2000 ok(r == ERROR_SUCCESS, "failed to add row 1\n");
2002 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
2003 r = run_query(hdb1, 0, query);
2004 ok(r == ERROR_SUCCESS, "failed to add row 2\n");
2006 query = "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
2007 r = run_query(hdb1, 0, query);
2008 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2010 query = "DELETE FROM `MOO` WHERE `NOO` = 3";
2011 r = run_query(hdb1, 0, query);
2012 ok(r == ERROR_SUCCESS, "failed to delete row\n");
2014 hrec = MsiCreateRecord(2);
2015 r = MsiRecordSetInteger(hrec, 1, 1);
2016 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2018 write_file("testdata.bin", "naengmyon", 9);
2019 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2020 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2022 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2023 r = run_query(hdb1, hrec, query);
2024 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2026 MsiCloseHandle(hrec);
2028 query = "ALTER TABLE `MOO` ADD `COW` INTEGER";
2029 r = run_query(hdb1, 0, query);
2030 ok(r == ERROR_SUCCESS, "failed to add column\n");
2032 query = "ALTER TABLE `MOO` ADD `PIG` INTEGER";
2033 r = run_query(hdb1, 0, query);
2034 ok(r == ERROR_SUCCESS, "failed to add column\n");
2036 query = "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
2037 r = run_query(hdb1, 0, query);
2038 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2040 query = "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
2041 "`Value` CHAR(0) PRIMARY KEY `Property`)";
2042 r = run_query(hdb1, 0, query);
2043 ok(r == ERROR_SUCCESS, "failed to add property table\n");
2045 query = "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2046 r = run_query(hdb1, 0, query);
2047 ok(r == ERROR_SUCCESS, "failed to add property\n");
2049 /* database needs to be committed */
2050 MsiDatabaseCommit(hdb1);
2052 r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
2053 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
2055 MsiCloseHandle( hdb1 );
2056 MsiCloseHandle( hdb2 );
2058 DeleteFile("testdata.bin");
2061 /* data for generating a transform */
2063 /* tables transform names - encoded as they would be in an msi database file */
2064 static const WCHAR name1[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
2065 static const WCHAR name2[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
2066 static const WCHAR name3[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
2067 static const WCHAR name4[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2068 static const WCHAR name5[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2069 static const WCHAR name6[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
2070 static const WCHAR name7[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
2071 static const WCHAR name8[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
2072 static const WCHAR name9[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2074 /* data in each table */
2075 static const WCHAR data1[] = { /* AAR */
2076 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
2077 0x0201, 0x0009, 0x8002,
2079 static const WCHAR data2[] = { /* _Columns */
2080 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
2081 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
2082 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
2083 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
2084 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
2085 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
2087 static const WCHAR data3[] = { /* _Tables */
2088 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
2091 static const char data4[] = /* _StringData */
2092 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
2093 static const WCHAR data5[] = { /* _StringPool */
2095 0, 0, /* string 0 '' */
2096 3, 2, /* string 1 'MOO' */
2097 3, 1, /* string 2 'COW' */
2098 3, 1, /* string 3 'PIG' */
2099 1, 1, /* string 4 'c' */
2100 3, 3, /* string 5 'AAR' */
2101 3, 1, /* string 6 'CAR' */
2102 3, 1, /* string 7 'BAR' */
2103 2, 1, /* string 8 'vw' */
2104 3, 1, /* string 9 'bmw' */
2105 8, 4, /* string 10 'Property' */
2106 5, 1, /* string 11 'Value' */
2107 4, 1, /* string 12 'prop' */
2108 3, 1, /* string 13 'val' */
2110 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
2111 static const WCHAR data6[] = { /* MOO */
2112 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
2113 0x0000, 0x8003, /* delete row */
2116 static const WCHAR data7[] = { /* BINARY */
2117 0x0201, 0x8001, 0x0001,
2120 static const char data8[] = /* stream data for the BINARY table */
2123 static const WCHAR data9[] = { /* Property */
2124 0x0201, 0x000c, 0x000d,
2127 static const struct {
2131 } table_transform_data[] =
2133 { name1, data1, sizeof data1 },
2134 { name2, data2, sizeof data2 },
2135 { name3, data3, sizeof data3 },
2136 { name4, data4, sizeof data4 - 1 },
2137 { name5, data5, sizeof data5 },
2138 { name6, data6, sizeof data6 },
2139 { name7, data7, sizeof data7 },
2140 { name8, data8, sizeof data8 - 1 },
2141 { name9, data9, sizeof data9 },
2144 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2146 static void generate_transform_manual(void)
2148 IStorage *stg = NULL;
2153 const DWORD mode = STGM_CREATE|STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE;
2155 const CLSID CLSID_MsiTransform = { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2157 MultiByteToWideChar(CP_ACP, 0, mstfile, -1, name, 0x20);
2159 r = StgCreateDocfile(name, mode, 0, &stg);
2160 ok(r == S_OK, "failed to create storage\n");
2164 r = IStorage_SetClass( stg, &CLSID_MsiTransform );
2165 ok(r == S_OK, "failed to set storage type\n");
2167 for (i=0; i<NUM_TRANSFORM_TABLES; i++)
2169 r = IStorage_CreateStream( stg, table_transform_data[i].name,
2170 STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm );
2173 ok(0, "failed to create stream %08x\n", r);
2177 r = IStream_Write( stm, table_transform_data[i].data,
2178 table_transform_data[i].size, &count );
2179 if (FAILED(r) || count != table_transform_data[i].size)
2180 ok(0, "failed to write stream\n");
2181 IStream_Release(stm);
2184 IStorage_Release(stg);
2187 static UINT set_summary_info(MSIHANDLE hdb)
2192 /* build summmary info */
2193 res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
2194 ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );
2196 res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
2197 "Installation Database");
2198 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2200 res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
2201 "Installation Database");
2202 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2204 res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
2206 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2208 res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
2210 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2212 res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
2213 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2214 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2216 res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
2217 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2219 res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
2220 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2222 res = MsiSummaryInfoPersist(suminfo);
2223 ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );
2225 res = MsiCloseHandle( suminfo);
2226 ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );
2231 static MSIHANDLE create_package_db(LPCSTR filename)
2236 DeleteFile(msifile);
2238 /* create an empty database */
2239 res = MsiOpenDatabase(filename, MSIDBOPEN_CREATE, &hdb );
2240 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
2241 if( res != ERROR_SUCCESS )
2244 res = MsiDatabaseCommit( hdb );
2245 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
2247 res = set_summary_info(hdb);
2249 res = run_query( hdb, 0,
2250 "CREATE TABLE `Directory` ( "
2251 "`Directory` CHAR(255) NOT NULL, "
2252 "`Directory_Parent` CHAR(255), "
2253 "`DefaultDir` CHAR(255) NOT NULL "
2254 "PRIMARY KEY `Directory`)" );
2255 ok( res == ERROR_SUCCESS , "Failed to create directory table\n" );
2260 static void test_try_transform(void)
2262 MSIHANDLE hdb, hview, hrec, hpkg;
2266 char buffer[MAX_PATH];
2268 DeleteFile(msifile);
2269 DeleteFile(msifile2);
2270 DeleteFile(mstfile);
2272 /* create the database */
2273 hdb = create_package_db(msifile2);
2274 ok(hdb, "Failed to create package db\n");
2276 query = "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
2277 r = run_query(hdb, 0, query);
2278 ok(r == ERROR_SUCCESS, "failed to add table\n");
2280 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
2281 r = run_query(hdb, 0, query);
2282 ok(r == ERROR_SUCCESS, "failed to add row\n");
2284 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
2285 r = run_query(hdb, 0, query);
2286 ok(r == ERROR_SUCCESS, "failed to add row\n");
2288 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
2289 r = run_query(hdb, 0, query);
2290 ok(r == ERROR_SUCCESS, "failed to add row\n");
2292 query = "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
2293 r = run_query(hdb, 0, query);
2294 ok(r == ERROR_SUCCESS, "failed to add table\n");
2296 hrec = MsiCreateRecord(2);
2297 r = MsiRecordSetInteger(hrec, 1, 2);
2298 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2300 write_file("testdata.bin", "lamyon", 6);
2301 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2302 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2304 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2305 r = run_query(hdb, hrec, query);
2306 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2308 MsiCloseHandle(hrec);
2310 r = MsiDatabaseCommit( hdb );
2311 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
2313 MsiCloseHandle( hdb );
2314 DeleteFileA("testdata.bin");
2317 * Both these generate an equivilent transform,
2318 * but the first doesn't work in Wine yet
2319 * because MsiDatabaseGenerateTransform is unimplemented.
2322 generate_transform();
2324 generate_transform_manual();
2326 r = MsiOpenDatabase(msifile2, MSIDBOPEN_DIRECT, &hdb );
2327 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2329 r = MsiDatabaseApplyTransform( hdb, mstfile, 0 );
2330 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
2332 MsiDatabaseCommit( hdb );
2334 /* check new values */
2336 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
2337 r = do_query(hdb, query, &hrec);
2338 ok(r == ERROR_SUCCESS, "select query failed\n");
2339 MsiCloseHandle(hrec);
2341 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
2343 r = do_query(hdb, query, &hrec);
2344 ok(r == ERROR_SUCCESS, "select query failed\n");
2345 MsiCloseHandle(hrec);
2347 /* check updated values */
2349 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
2350 r = do_query(hdb, query, &hrec);
2351 ok(r == ERROR_SUCCESS, "select query failed\n");
2352 MsiCloseHandle(hrec);
2354 /* check unchanged value */
2356 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
2357 r = do_query(hdb, query, &hrec);
2358 ok(r == ERROR_SUCCESS, "select query failed\n");
2359 MsiCloseHandle(hrec);
2361 /* check deleted value */
2363 query = "select * from `MOO` where `NOO` = 3";
2364 r = do_query(hdb, query, &hrec);
2365 ok(r == ERROR_NO_MORE_ITEMS, "select query failed\n");
2366 if (hrec) MsiCloseHandle(hrec);
2368 /* check added stream */
2370 query = "select `BLOB` from `BINARY` where `ID` = 1";
2371 r = do_query(hdb, query, &hrec);
2372 ok(r == ERROR_SUCCESS, "select query failed\n");
2374 /* check the contents of the stream */
2376 r = MsiRecordReadStream( hrec, 1, buffer, &sz );
2377 ok(r == ERROR_SUCCESS, "read stream failed\n");
2378 ok(!memcmp(buffer, "naengmyon", 9), "stream data was wrong\n");
2379 ok(sz == 9, "stream data was wrong size\n");
2380 if (hrec) MsiCloseHandle(hrec);
2382 /* check the validity of the table with a deleted row */
2384 query = "select * from `MOO`";
2385 r = MsiDatabaseOpenView(hdb, query, &hview);
2386 ok(r == ERROR_SUCCESS, "open view failed\n");
2388 r = MsiViewExecute(hview, 0);
2389 ok(r == ERROR_SUCCESS, "view execute failed\n");
2391 r = MsiViewFetch(hview, &hrec);
2392 ok(r == ERROR_SUCCESS, "view fetch failed\n");
2394 r = MsiRecordGetInteger(hrec, 1);
2395 ok(r == 1, "Expected 1, got %d\n", r);
2398 r = MsiRecordGetString(hrec, 2, buffer, &sz);
2399 ok(r == ERROR_SUCCESS, "record get string failed\n");
2400 ok(!lstrcmpA(buffer, "c"), "Expected c, got %s\n", buffer);
2402 r = MsiRecordGetInteger(hrec, 3);
2403 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2405 r = MsiRecordGetInteger(hrec, 4);
2406 ok(r == 5, "Expected 5, got %d\n", r);
2408 MsiCloseHandle(hrec);
2410 r = MsiViewFetch(hview, &hrec);
2411 ok(r == ERROR_SUCCESS, "view fetch failed\n");
2413 r = MsiRecordGetInteger(hrec, 1);
2414 ok(r == 2, "Expected 2, got %d\n", r);
2417 r = MsiRecordGetString(hrec, 2, buffer, &sz);
2418 ok(r == ERROR_SUCCESS, "record get string failed\n");
2419 ok(!lstrcmpA(buffer, "b"), "Expected b, got %s\n", buffer);
2421 r = MsiRecordGetInteger(hrec, 3);
2422 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2424 r = MsiRecordGetInteger(hrec, 4);
2425 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
2427 MsiCloseHandle(hrec);
2429 r = MsiViewFetch(hview, &hrec);
2430 ok(r == ERROR_NO_MORE_ITEMS, "view fetch succeeded\n");
2432 MsiCloseHandle(hrec);
2433 MsiCloseHandle(hview);
2434 MsiCloseHandle(hdb);
2436 /* check that the property was added */
2437 r = MsiOpenPackage(msifile2, &hpkg);
2438 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2441 r = MsiGetProperty(hpkg, "prop", buffer, &sz);
2442 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2443 ok(!lstrcmp(buffer, "val"), "Expected val, got %s\n", buffer);
2445 MsiCloseHandle(hpkg);
2447 DeleteFile(msifile);
2448 DeleteFile(msifile2);
2449 DeleteFile(mstfile);
2454 const CHAR one[MAX_PATH];
2455 const CHAR two[MAX_PATH];
2458 struct join_res_4col
2460 const CHAR one[MAX_PATH];
2461 const CHAR two[MAX_PATH];
2462 const CHAR three[MAX_PATH];
2463 const CHAR four[MAX_PATH];
2466 struct join_res_uint
2476 static const struct join_res join_res_first[] =
2478 { "alveolar", "procerus" },
2479 { "septum", "procerus" },
2480 { "septum", "nasalis" },
2481 { "ramus", "nasalis" },
2482 { "malar", "mentalis" },
2485 static const struct join_res join_res_second[] =
2487 { "nasal", "septum" },
2488 { "mandible", "ramus" },
2491 static const struct join_res join_res_third[] =
2493 { "msvcp.dll", "abcdefgh" },
2494 { "msvcr.dll", "ijklmnop" },
2497 static const struct join_res join_res_fourth[] =
2499 { "msvcp.dll.01234", "single.dll.31415" },
2502 static const struct join_res join_res_fifth[] =
2504 { "malar", "procerus" },
2507 static const struct join_res join_res_sixth[] =
2509 { "malar", "procerus" },
2510 { "malar", "procerus" },
2511 { "malar", "nasalis" },
2512 { "malar", "nasalis" },
2513 { "malar", "nasalis" },
2514 { "malar", "mentalis" },
2517 static const struct join_res join_res_seventh[] =
2519 { "malar", "nasalis" },
2520 { "malar", "nasalis" },
2521 { "malar", "nasalis" },
2524 static const struct join_res_4col join_res_eighth[] =
2526 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
2527 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
2528 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
2529 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
2530 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
2531 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
2534 static const struct join_res_uint join_res_ninth[] =
2536 { 1, 2, 3, 4, 7, 8 },
2537 { 1, 2, 5, 6, 7, 8 },
2538 { 1, 2, 3, 4, 9, 10 },
2539 { 1, 2, 5, 6, 9, 10 },
2540 { 1, 2, 3, 4, 11, 12 },
2541 { 1, 2, 5, 6, 11, 12 },
2544 static void test_join(void)
2546 MSIHANDLE hdb, hview, hrec;
2554 ok( hdb, "failed to create db\n");
2556 r = create_component_table( hdb );
2557 ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
2559 r = add_component_entry( hdb, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
2560 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2562 r = add_component_entry( hdb, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
2563 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2565 r = add_component_entry( hdb, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
2566 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2568 r = add_component_entry( hdb, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
2569 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
2571 r = create_feature_components_table( hdb );
2572 ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
2574 r = add_feature_components_entry( hdb, "'procerus', 'maxilla'" );
2575 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2577 r = add_feature_components_entry( hdb, "'procerus', 'nasal'" );
2578 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2580 r = add_feature_components_entry( hdb, "'nasalis', 'nasal'" );
2581 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2583 r = add_feature_components_entry( hdb, "'nasalis', 'mandible'" );
2584 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2586 r = add_feature_components_entry( hdb, "'nasalis', 'notacomponent'" );
2587 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2589 r = add_feature_components_entry( hdb, "'mentalis', 'zygomatic'" );
2590 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
2592 r = create_std_dlls_table( hdb );
2593 ok( r == ERROR_SUCCESS, "cannot create StdDlls table: %d\n", r );
2595 r = add_std_dlls_entry( hdb, "'msvcp.dll', 'msvcp.dll.01234'" );
2596 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
2598 r = add_std_dlls_entry( hdb, "'msvcr.dll', 'msvcr.dll.56789'" );
2599 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
2601 r = create_binary_table( hdb );
2602 ok( r == ERROR_SUCCESS, "cannot create Binary table: %d\n", r );
2604 r = add_binary_entry( hdb, "'msvcp.dll.01234', 'abcdefgh'" );
2605 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
2607 r = add_binary_entry( hdb, "'msvcr.dll.56789', 'ijklmnop'" );
2608 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
2610 r = add_binary_entry( hdb, "'single.dll.31415', 'msvcp.dll'" );
2611 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
2613 query = "CREATE TABLE `One` (`A` SHORT, `B` SHORT PRIMARY KEY `A`)";
2614 r = run_query( hdb, 0, query);
2615 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
2617 query = "CREATE TABLE `Two` (`C` SHORT, `D` SHORT PRIMARY KEY `C`)";
2618 r = run_query( hdb, 0, query);
2619 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
2621 query = "CREATE TABLE `Three` (`E` SHORT, `F` SHORT PRIMARY KEY `E`)";
2622 r = run_query( hdb, 0, query);
2623 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
2625 query = "INSERT INTO `One` (`A`, `B`) VALUES (1, 2)";
2626 r = run_query( hdb, 0, query);
2627 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2629 query = "INSERT INTO `Two` (`C`, `D`) VALUES (3, 4)";
2630 r = run_query( hdb, 0, query);
2631 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2633 query = "INSERT INTO `Two` (`C`, `D`) VALUES (5, 6)";
2634 r = run_query( hdb, 0, query);
2635 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2637 query = "INSERT INTO `Three` (`E`, `F`) VALUES (7, 8)";
2638 r = run_query( hdb, 0, query);
2639 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2641 query = "INSERT INTO `Three` (`E`, `F`) VALUES (9, 10)";
2642 r = run_query( hdb, 0, query);
2643 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2645 query = "INSERT INTO `Three` (`E`, `F`) VALUES (11, 12)";
2646 r = run_query( hdb, 0, query);
2647 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2649 query = "CREATE TABLE `Four` (`G` SHORT, `H` SHORT PRIMARY KEY `G`)";
2650 r = run_query( hdb, 0, query);
2651 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
2653 query = "CREATE TABLE `Five` (`I` SHORT, `J` SHORT PRIMARY KEY `I`)";
2654 r = run_query( hdb, 0, query);
2655 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
2657 query = "INSERT INTO `Five` (`I`, `J`) VALUES (13, 14)";
2658 r = run_query( hdb, 0, query);
2659 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2661 query = "INSERT INTO `Five` (`I`, `J`) VALUES (15, 16)";
2662 r = run_query( hdb, 0, query);
2663 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
2665 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2666 "FROM `Component`, `FeatureComponents` "
2667 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
2668 "ORDER BY `Feature_`";
2669 r = MsiDatabaseOpenView(hdb, query, &hview);
2670 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2672 r = MsiViewExecute(hview, 0);
2673 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2676 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2678 count = MsiRecordGetFieldCount( hrec );
2679 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2682 r = MsiRecordGetString( hrec, 1, buf, &size );
2683 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2684 ok( !lstrcmp( buf, join_res_first[i].one ),
2685 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_first[i].one, buf );
2688 r = MsiRecordGetString( hrec, 2, buf, &size );
2689 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2690 ok( !lstrcmp( buf, join_res_first[i].two ),
2691 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_first[i].two, buf );
2694 MsiCloseHandle(hrec);
2697 ok( i == 5, "Expected 5 rows, got %d\n", i );
2698 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2700 MsiViewClose(hview);
2701 MsiCloseHandle(hview);
2703 /* try a join without a WHERE condition */
2704 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2705 "FROM `Component`, `FeatureComponents` ";
2706 r = MsiDatabaseOpenView(hdb, query, &hview);
2707 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2709 r = MsiViewExecute(hview, 0);
2710 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2713 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2716 MsiCloseHandle(hrec);
2718 ok( i == 24, "Expected 24 rows, got %d\n", i );
2720 MsiViewClose(hview);
2721 MsiCloseHandle(hview);
2723 query = "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
2724 "WHERE FeatureComponents.Component_=Component.Component "
2725 "AND (Feature_='nasalis') ORDER BY Feature_";
2726 r = MsiDatabaseOpenView(hdb, query, &hview);
2727 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2729 r = MsiViewExecute(hview, 0);
2730 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2733 data_correct = TRUE;
2734 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2736 count = MsiRecordGetFieldCount( hrec );
2737 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2740 r = MsiRecordGetString( hrec, 1, buf, &size );
2741 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2742 if( lstrcmp( buf, join_res_second[i].one ))
2743 data_correct = FALSE;
2746 r = MsiRecordGetString( hrec, 2, buf, &size );
2747 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2748 if( lstrcmp( buf, join_res_second[i].two ))
2749 data_correct = FALSE;
2752 MsiCloseHandle(hrec);
2755 ok( data_correct, "data returned in the wrong order\n");
2757 ok( i == 2, "Expected 2 rows, got %d\n", i );
2758 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2760 MsiViewClose(hview);
2761 MsiCloseHandle(hview);
2763 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2764 "FROM `StdDlls`, `Binary` "
2765 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
2767 r = MsiDatabaseOpenView(hdb, query, &hview);
2768 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2770 r = MsiViewExecute(hview, 0);
2771 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2774 data_correct = TRUE;
2775 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2777 count = MsiRecordGetFieldCount( hrec );
2778 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2781 r = MsiRecordGetString( hrec, 1, buf, &size );
2782 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2783 if( lstrcmp( buf, join_res_third[i].one ) )
2784 data_correct = FALSE;
2787 r = MsiRecordGetString( hrec, 2, buf, &size );
2788 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2789 if( lstrcmp( buf, join_res_third[i].two ) )
2790 data_correct = FALSE;
2793 MsiCloseHandle(hrec);
2795 ok( data_correct, "data returned in the wrong order\n");
2797 ok( i == 2, "Expected 2 rows, got %d\n", i );
2799 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2801 MsiViewClose(hview);
2802 MsiCloseHandle(hview);
2804 query = "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
2805 "FROM `StdDlls`, `Binary` "
2806 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
2808 r = MsiDatabaseOpenView(hdb, query, &hview);
2809 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2811 r = MsiViewExecute(hview, 0);
2812 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2815 data_correct = TRUE;
2816 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2818 count = MsiRecordGetFieldCount( hrec );
2819 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2822 r = MsiRecordGetString( hrec, 1, buf, &size );
2823 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2824 if( lstrcmp( buf, join_res_fourth[i].one ))
2825 data_correct = FALSE;
2828 r = MsiRecordGetString( hrec, 2, buf, &size );
2829 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2830 if( lstrcmp( buf, join_res_fourth[i].two ))
2831 data_correct = FALSE;
2834 MsiCloseHandle(hrec);
2836 ok( data_correct, "data returned in the wrong order\n");
2838 ok( i == 1, "Expected 1 rows, got %d\n", i );
2839 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2841 MsiViewClose(hview);
2842 MsiCloseHandle(hview);
2844 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2845 "FROM `Component`, `FeatureComponents` "
2846 "WHERE `Component`.`Component` = 'zygomatic' "
2847 "AND `FeatureComponents`.`Component_` = 'maxilla' "
2848 "ORDER BY `Feature_`";
2849 r = MsiDatabaseOpenView(hdb, query, &hview);
2850 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2852 r = MsiViewExecute(hview, 0);
2853 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2856 data_correct = TRUE;
2857 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2859 count = MsiRecordGetFieldCount( hrec );
2860 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2863 r = MsiRecordGetString( hrec, 1, buf, &size );
2864 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2865 if( lstrcmp( buf, join_res_fifth[i].one ))
2866 data_correct = FALSE;
2869 r = MsiRecordGetString( hrec, 2, buf, &size );
2870 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2871 if( lstrcmp( buf, join_res_fifth[i].two ))
2872 data_correct = FALSE;
2875 MsiCloseHandle(hrec);
2877 ok( data_correct, "data returned in the wrong order\n");
2879 ok( i == 1, "Expected 1 rows, got %d\n", i );
2880 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2882 MsiViewClose(hview);
2883 MsiCloseHandle(hview);
2885 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2886 "FROM `Component`, `FeatureComponents` "
2887 "WHERE `Component` = 'zygomatic' "
2888 "ORDER BY `Feature_`";
2889 r = MsiDatabaseOpenView(hdb, query, &hview);
2890 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2892 r = MsiViewExecute(hview, 0);
2893 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2896 data_correct = TRUE;
2897 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2899 count = MsiRecordGetFieldCount( hrec );
2900 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2903 r = MsiRecordGetString( hrec, 1, buf, &size );
2904 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2905 if( lstrcmp( buf, join_res_sixth[i].one ))
2906 data_correct = FALSE;
2909 r = MsiRecordGetString( hrec, 2, buf, &size );
2910 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2911 if( lstrcmp( buf, join_res_sixth[i].two ))
2912 data_correct = FALSE;
2915 MsiCloseHandle(hrec);
2917 ok( data_correct, "data returned in the wrong order\n");
2919 ok( i == 6, "Expected 6 rows, got %d\n", i );
2920 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2922 MsiViewClose(hview);
2923 MsiCloseHandle(hview);
2925 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2926 "FROM `Component`, `FeatureComponents` "
2927 "WHERE `Component` = 'zygomatic' "
2928 "AND `Feature_` = 'nasalis' "
2929 "ORDER BY `Feature_`";
2930 r = MsiDatabaseOpenView(hdb, query, &hview);
2931 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2933 r = MsiViewExecute(hview, 0);
2934 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2937 data_correct = TRUE;
2938 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2940 count = MsiRecordGetFieldCount( hrec );
2941 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2944 r = MsiRecordGetString( hrec, 1, buf, &size );
2945 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2946 if( lstrcmp( buf, join_res_seventh[i].one ))
2947 data_correct = FALSE;
2950 r = MsiRecordGetString( hrec, 2, buf, &size );
2951 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2952 if( lstrcmp( buf, join_res_seventh[i].two ))
2953 data_correct = FALSE;
2956 MsiCloseHandle(hrec);
2959 ok( data_correct, "data returned in the wrong order\n");
2960 ok( i == 3, "Expected 3 rows, got %d\n", i );
2961 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
2963 MsiViewClose(hview);
2964 MsiCloseHandle(hview);
2966 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2967 "FROM `StdDlls`, `Binary` ";
2968 r = MsiDatabaseOpenView(hdb, query, &hview);
2969 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
2971 r = MsiViewExecute(hview, 0);
2972 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
2975 data_correct = TRUE;
2976 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
2978 count = MsiRecordGetFieldCount( hrec );
2979 ok( count == 2, "Expected 2 record fields, got %d\n", count );
2982 r = MsiRecordGetString( hrec, 1, buf, &size );
2983 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2984 if( lstrcmp( buf, join_res_eighth[i].one ))
2985 data_correct = FALSE;
2988 r = MsiRecordGetString( hrec, 2, buf, &size );
2989 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
2990 if( lstrcmp( buf, join_res_eighth[i].four ))
2991 data_correct = FALSE;
2994 MsiCloseHandle(hrec);
2997 ok( data_correct, "data returned in the wrong order\n");
2998 ok( i == 6, "Expected 6 rows, got %d\n", i );
2999 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3001 MsiViewClose(hview);
3002 MsiCloseHandle(hview);
3004 query = "SELECT * FROM `StdDlls`, `Binary` ";
3005 r = MsiDatabaseOpenView(hdb, query, &hview);
3006 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3008 r = MsiViewExecute(hview, 0);
3009 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3012 data_correct = TRUE;
3013 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3015 count = MsiRecordGetFieldCount( hrec );
3016 ok( count == 4, "Expected 4 record fields, got %d\n", count );
3019 r = MsiRecordGetString( hrec, 1, buf, &size );
3020 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3021 if( lstrcmp( buf, join_res_eighth[i].one ))
3022 data_correct = FALSE;
3025 r = MsiRecordGetString( hrec, 2, buf, &size );
3026 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3027 if( lstrcmp( buf, join_res_eighth[i].two ))
3028 data_correct = FALSE;
3031 r = MsiRecordGetString( hrec, 3, buf, &size );
3032 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3033 if( lstrcmp( buf, join_res_eighth[i].three ))
3034 data_correct = FALSE;
3037 r = MsiRecordGetString( hrec, 4, buf, &size );
3038 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3039 if( lstrcmp( buf, join_res_eighth[i].four ))
3040 data_correct = FALSE;
3043 MsiCloseHandle(hrec);
3045 ok( data_correct, "data returned in the wrong order\n");
3047 ok( i == 6, "Expected 6 rows, got %d\n", i );
3048 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3050 MsiViewClose(hview);
3051 MsiCloseHandle(hview);
3053 query = "SELECT * FROM `One`, `Two`, `Three` ";
3054 r = MsiDatabaseOpenView(hdb, query, &hview);
3055 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3057 r = MsiViewExecute(hview, 0);
3058 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3061 data_correct = TRUE;
3062 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3064 count = MsiRecordGetFieldCount( hrec );
3065 ok( count == 6, "Expected 6 record fields, got %d\n", count );
3067 r = MsiRecordGetInteger( hrec, 1 );
3068 if( r != join_res_ninth[i].one )
3069 data_correct = FALSE;
3071 r = MsiRecordGetInteger( hrec, 2 );
3072 if( r != join_res_ninth[i].two )
3073 data_correct = FALSE;
3075 r = MsiRecordGetInteger( hrec, 3 );
3076 if( r != join_res_ninth[i].three )
3077 data_correct = FALSE;
3079 r = MsiRecordGetInteger( hrec, 4 );
3080 if( r != join_res_ninth[i].four )
3081 data_correct = FALSE;
3083 r = MsiRecordGetInteger( hrec, 5 );
3084 if( r != join_res_ninth[i].five )
3085 data_correct = FALSE;
3087 r = MsiRecordGetInteger( hrec, 6);
3088 if( r != join_res_ninth[i].six )
3089 data_correct = FALSE;
3092 MsiCloseHandle(hrec);
3094 ok( data_correct, "data returned in the wrong order\n");
3096 ok( i == 6, "Expected 6 rows, got %d\n", i );
3097 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3099 MsiViewClose(hview);
3100 MsiCloseHandle(hview);
3102 query = "SELECT * FROM `Four`, `Five`";
3103 r = MsiDatabaseOpenView(hdb, query, &hview);
3104 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3106 r = MsiViewExecute(hview, 0);
3107 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3109 r = MsiViewFetch(hview, &hrec);
3110 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3112 MsiViewClose(hview);
3113 MsiCloseHandle(hview);
3115 MsiCloseHandle(hdb);
3116 DeleteFile(msifile);
3119 static void test_temporary_table(void)
3122 MSIHANDLE hdb = 0, view = 0, rec;
3128 cond = MsiDatabaseIsTablePersistent(0, NULL);
3129 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3132 ok( hdb, "failed to create db\n");
3134 cond = MsiDatabaseIsTablePersistent(hdb, NULL);
3135 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3138 cond = MsiDatabaseIsTablePersistent(hdb, "_Tables");
3139 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3141 cond = MsiDatabaseIsTablePersistent(hdb, "_Columns");
3142 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3145 cond = MsiDatabaseIsTablePersistent(hdb, "_Streams");
3146 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3148 query = "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
3149 r = run_query(hdb, 0, query);
3150 ok(r == ERROR_SUCCESS, "failed to add table\n");
3152 cond = MsiDatabaseIsTablePersistent(hdb, "P");
3153 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3155 query = "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
3156 r = run_query(hdb, 0, query);
3157 ok(r == ERROR_SUCCESS, "failed to add table\n");
3159 cond = MsiDatabaseIsTablePersistent(hdb, "P2");
3160 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3162 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3163 r = run_query(hdb, 0, query);
3164 ok(r == ERROR_SUCCESS, "failed to add table\n");
3166 cond = MsiDatabaseIsTablePersistent(hdb, "T");
3167 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
3169 query = "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3170 r = run_query(hdb, 0, query);
3171 ok(r == ERROR_SUCCESS, "failed to add table\n");
3174 cond = MsiDatabaseIsTablePersistent(hdb, "T2");
3175 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3178 query = "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
3179 r = run_query(hdb, 0, query);
3180 ok(r == ERROR_SUCCESS, "failed to add table\n");
3182 cond = MsiDatabaseIsTablePersistent(hdb, "T3");
3183 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3186 query = "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3187 r = run_query(hdb, 0, query);
3188 ok(r == ERROR_FUNCTION_FAILED, "failed to add table\n");
3190 cond = MsiDatabaseIsTablePersistent(hdb, "T4");
3191 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3194 query = "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
3195 r = run_query(hdb, 0, query);
3196 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add table\n");
3198 query = "select * from `T`";
3199 r = MsiDatabaseOpenView(hdb, query, &view);
3200 ok(r == ERROR_SUCCESS, "failed to query table\n");
3201 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
3202 ok(r == ERROR_SUCCESS, "failed to get column info\n");
3205 r = MsiRecordGetString(rec, 1, buf, &sz);
3206 ok(r == ERROR_SUCCESS, "failed to get string\n");
3207 todo_wine ok( 0 == strcmp("G255", buf), "wrong column type\n");
3210 r = MsiRecordGetString(rec, 2, buf, &sz);
3211 ok(r == ERROR_SUCCESS, "failed to get string\n");
3212 todo_wine ok( 0 == strcmp("j2", buf), "wrong column type\n");
3214 MsiCloseHandle( rec );
3215 MsiCloseHandle( view );
3217 /* query the table data */
3219 r = do_query(hdb, "select * from `_Tables` where `Name` = 'T'", &rec);
3220 ok( r == ERROR_SUCCESS, "temporary table exists in _Tables\n");
3221 MsiCloseHandle( rec );
3223 /* query the column data */
3225 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec);
3226 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3227 if (rec) MsiCloseHandle( rec );
3229 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec);
3230 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3231 if (rec) MsiCloseHandle( rec );
3233 MsiCloseHandle( hdb );
3235 DeleteFile(msifile);
3238 static void test_alter(void)
3246 ok( hdb, "failed to create db\n");
3248 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3249 r = run_query(hdb, 0, query);
3250 ok(r == ERROR_SUCCESS, "failed to add table\n");
3252 cond = MsiDatabaseIsTablePersistent(hdb, "T");
3253 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
3255 query = "ALTER TABLE `T` HOLD";
3256 r = run_query(hdb, 0, query);
3257 ok(r == ERROR_SUCCESS, "failed to hold table %d\n", r);
3259 query = "ALTER TABLE `T` FREE";
3260 r = run_query(hdb, 0, query);
3261 ok(r == ERROR_SUCCESS, "failed to free table\n");
3263 query = "ALTER TABLE `T` FREE";
3264 r = run_query(hdb, 0, query);
3265 ok(r == ERROR_SUCCESS, "failed to free table\n");
3267 query = "ALTER TABLE `T` FREE";
3268 r = run_query(hdb, 0, query);
3269 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to free table\n");
3271 query = "ALTER TABLE `T` HOLD";
3272 r = run_query(hdb, 0, query);
3273 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to hold table %d\n", r);
3275 /* table T is removed */
3276 query = "SELECT * FROM `T`";
3277 r = run_query(hdb, 0, query);
3278 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3280 /* create the table again */
3281 query = "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
3282 r = run_query(hdb, 0, query);
3283 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3285 /* up the ref count */
3286 query = "ALTER TABLE `U` HOLD";
3287 r = run_query(hdb, 0, query);
3288 ok(r == ERROR_SUCCESS, "failed to free table\n");
3290 /* add column, no data type */
3291 query = "ALTER TABLE `U` ADD `C`";
3292 r = run_query(hdb, 0, query);
3293 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3295 query = "ALTER TABLE `U` ADD `C` INTEGER";
3296 r = run_query(hdb, 0, query);
3297 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3299 /* add column C again */
3300 query = "ALTER TABLE `U` ADD `C` INTEGER";
3301 r = run_query(hdb, 0, query);
3302 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3304 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
3305 r = run_query(hdb, 0, query);
3306 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3308 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
3309 r = run_query(hdb, 0, query);
3310 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3312 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
3313 r = run_query(hdb, 0, query);
3314 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3316 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
3317 r = run_query(hdb, 0, query);
3318 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3320 query = "SELECT * FROM `U` WHERE `D` = 8";
3321 r = run_query(hdb, 0, query);
3322 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3324 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
3325 r = run_query(hdb, 0, query);
3326 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3328 query = "ALTER COLUMN `D` FREE";
3329 r = run_query(hdb, 0, query);
3330 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3332 /* drop the ref count */
3333 query = "ALTER TABLE `U` FREE";
3334 r = run_query(hdb, 0, query);
3335 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3337 /* table is not empty */
3338 query = "SELECT * FROM `U`";
3339 r = run_query(hdb, 0, query);
3340 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3342 /* column D is removed */
3343 query = "SELECT * FROM `U` WHERE `D` = 8";
3344 r = run_query(hdb, 0, query);
3345 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3347 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
3348 r = run_query(hdb, 0, query);
3349 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3351 /* add the column again */
3352 query = "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
3353 r = run_query(hdb, 0, query);
3354 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3356 /* up the ref count */
3357 query = "ALTER TABLE `U` HOLD";
3358 r = run_query(hdb, 0, query);
3359 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3361 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
3362 r = run_query(hdb, 0, query);
3363 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3365 query = "SELECT * FROM `U` WHERE `E` = 16";
3366 r = run_query(hdb, 0, query);
3367 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3369 /* drop the ref count */
3370 query = "ALTER TABLE `U` FREE";
3371 r = run_query(hdb, 0, query);
3372 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3374 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
3375 r = run_query(hdb, 0, query);
3376 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3378 query = "SELECT * FROM `U` WHERE `E` = 20";
3379 r = run_query(hdb, 0, query);
3380 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3382 /* drop the ref count */
3383 query = "ALTER TABLE `U` FREE";
3384 r = run_query(hdb, 0, query);
3385 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3387 /* table still exists */
3388 query = "SELECT * FROM `U`";
3389 r = run_query(hdb, 0, query);
3390 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3392 /* col E is removed */
3393 query = "SELECT * FROM `U` WHERE `E` = 20";
3394 r = run_query(hdb, 0, query);
3395 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3397 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
3398 r = run_query(hdb, 0, query);
3399 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3401 /* drop the ref count once more */
3402 query = "ALTER TABLE `U` FREE";
3403 r = run_query(hdb, 0, query);
3404 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3406 /* table still exists */
3407 query = "SELECT * FROM `U`";
3408 r = run_query(hdb, 0, query);
3409 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3411 MsiCloseHandle( hdb );
3412 DeleteFile(msifile);
3415 static void test_integers(void)
3417 MSIHANDLE hdb = 0, view = 0, rec = 0;
3422 /* just MsiOpenDatabase should not create a file */
3423 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3424 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3426 /* create a table */
3427 query = "CREATE TABLE `integers` ( "
3428 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
3429 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
3430 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
3431 "PRIMARY KEY `one`)";
3432 r = MsiDatabaseOpenView(hdb, query, &view);
3433 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3434 r = MsiViewExecute(view, 0);
3435 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3436 r = MsiViewClose(view);
3437 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3438 r = MsiCloseHandle(view);
3439 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3441 query = "SELECT * FROM `integers`";
3442 r = MsiDatabaseOpenView(hdb, query, &view);
3443 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3445 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
3446 count = MsiRecordGetFieldCount(rec);
3447 ok(count == 8, "Expected 8, got %d\n", count);
3448 ok(check_record(rec, 1, "one"), "Expected one\n");
3449 ok(check_record(rec, 2, "two"), "Expected two\n");
3450 ok(check_record(rec, 3, "three"), "Expected three\n");
3451 ok(check_record(rec, 4, "four"), "Expected four\n");
3452 ok(check_record(rec, 5, "five"), "Expected five\n");
3453 ok(check_record(rec, 6, "six"), "Expected six\n");
3454 ok(check_record(rec, 7, "seven"), "Expected seven\n");
3455 ok(check_record(rec, 8, "eight"), "Expected eight\n");
3456 MsiCloseHandle(rec);
3458 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
3459 count = MsiRecordGetFieldCount(rec);
3460 ok(count == 8, "Expected 8, got %d\n", count);
3461 ok(check_record(rec, 1, "I2"), "Expected I2\n");
3462 ok(check_record(rec, 2, "I2"), "Expected I2\n");
3463 ok(check_record(rec, 3, "I2"), "Expected I2\n");
3464 ok(check_record(rec, 4, "I4"), "Expected I4\n");
3465 ok(check_record(rec, 5, "i2"), "Expected i2\n");
3466 ok(check_record(rec, 6, "i2"), "Expected i2\n");
3467 ok(check_record(rec, 7, "i2"), "Expected i2\n");
3468 ok(check_record(rec, 8, "i4"), "Expected i4\n");
3469 MsiCloseHandle(rec);
3472 MsiCloseHandle(view);
3474 /* insert values into it, NULL where NOT NULL is specified */
3475 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3476 "VALUES('', '', '', '', '', '', '', '')";
3477 r = MsiDatabaseOpenView(hdb, query, &view);
3478 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3479 r = MsiViewExecute(view, 0);
3480 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
3483 MsiCloseHandle(view);
3485 query = "SELECT * FROM `integers`";
3486 r = do_query(hdb, query, &rec);
3487 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3489 r = MsiRecordGetFieldCount(rec);
3490 ok(r == -1, "record count wrong: %d\n", r);
3492 MsiCloseHandle(rec);
3494 /* insert legitimate values into it */
3495 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3496 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
3497 r = MsiDatabaseOpenView(hdb, query, &view);
3498 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3499 r = MsiViewExecute(view, 0);
3500 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3502 query = "SELECT * FROM `integers`";
3503 r = do_query(hdb, query, &rec);
3504 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3506 r = MsiRecordGetFieldCount(rec);
3507 ok(r == 8, "record count wrong: %d\n", r);
3509 i = MsiRecordGetInteger(rec, 1);
3510 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
3511 i = MsiRecordGetInteger(rec, 3);
3512 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
3513 i = MsiRecordGetInteger(rec, 2);
3514 ok(i == 2, "Expected 2, got %d\n", i);
3515 i = MsiRecordGetInteger(rec, 4);
3516 ok(i == 4, "Expected 4, got %d\n", i);
3517 i = MsiRecordGetInteger(rec, 5);
3518 ok(i == 5, "Expected 5, got %d\n", i);
3519 i = MsiRecordGetInteger(rec, 6);
3520 ok(i == 6, "Expected 6, got %d\n", i);
3521 i = MsiRecordGetInteger(rec, 7);
3522 ok(i == 7, "Expected 7, got %d\n", i);
3523 i = MsiRecordGetInteger(rec, 8);
3524 ok(i == 8, "Expected 8, got %d\n", i);
3526 MsiCloseHandle(rec);
3528 MsiCloseHandle(view);
3530 r = MsiDatabaseCommit(hdb);
3531 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
3533 r = MsiCloseHandle(hdb);
3534 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3536 r = DeleteFile(msifile);
3537 ok(r == TRUE, "file didn't exist after commit\n");
3540 static void test_update(void)
3542 MSIHANDLE hdb = 0, view = 0, rec = 0;
3543 CHAR result[MAX_PATH];
3548 /* just MsiOpenDatabase should not create a file */
3549 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3550 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3552 /* create the Control table */
3553 query = "CREATE TABLE `Control` ( "
3554 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
3555 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
3556 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
3557 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
3558 r = MsiDatabaseOpenView(hdb, query, &view);
3559 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3560 r = MsiViewExecute(view, 0);
3561 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3562 r = MsiViewClose(view);
3563 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3564 r = MsiCloseHandle(view);
3565 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3568 query = "INSERT INTO `Control` ( "
3569 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3570 "`Property`, `Text`, `Control_Next`, `Help` )"
3571 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3572 r = MsiDatabaseOpenView(hdb, query, &view);
3573 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3574 r = MsiViewExecute(view, 0);
3575 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3576 r = MsiViewClose(view);
3577 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3578 r = MsiCloseHandle(view);
3579 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3581 /* add a second control */
3582 query = "INSERT INTO `Control` ( "
3583 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3584 "`Property`, `Text`, `Control_Next`, `Help` )"
3585 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
3586 r = MsiDatabaseOpenView(hdb, query, &view);
3587 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3588 r = MsiViewExecute(view, 0);
3589 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3590 r = MsiViewClose(view);
3591 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3592 r = MsiCloseHandle(view);
3593 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3595 /* add a third control */
3596 query = "INSERT INTO `Control` ( "
3597 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3598 "`Property`, `Text`, `Control_Next`, `Help` )"
3599 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3600 r = MsiDatabaseOpenView(hdb, query, &view);
3601 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3602 r = MsiViewExecute(view, 0);
3603 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3604 r = MsiViewClose(view);
3605 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3606 r = MsiCloseHandle(view);
3607 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3610 query = "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3611 r = MsiDatabaseOpenView(hdb, query, &view);
3612 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3614 /* bad set column */
3615 query = "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3616 r = MsiDatabaseOpenView(hdb, query, &view);
3617 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3619 /* bad where condition */
3620 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
3621 r = MsiDatabaseOpenView(hdb, query, &view);
3622 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3624 /* just the dialog_ specified */
3625 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3626 r = MsiDatabaseOpenView(hdb, query, &view);
3627 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3628 r = MsiViewExecute(view, 0);
3629 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3630 r = MsiViewClose(view);
3631 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3632 r = MsiCloseHandle(view);
3633 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3635 /* check the modified text */
3636 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3637 r = MsiDatabaseOpenView(hdb, query, &view);
3638 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3639 r = MsiViewExecute(view, 0);
3640 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3642 r = MsiViewFetch(view, &rec);
3643 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3646 r = MsiRecordGetString(rec, 1, result, &size);
3647 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3648 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3650 MsiCloseHandle(rec);
3652 r = MsiViewFetch(view, &rec);
3653 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3656 r = MsiRecordGetString(rec, 1, result, &size);
3657 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3658 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
3660 MsiCloseHandle(rec);
3662 r = MsiViewFetch(view, &rec);
3663 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3665 r = MsiViewClose(view);
3666 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3667 r = MsiCloseHandle(view);
3668 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3670 /* dialog_ and control specified */
3671 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
3672 r = MsiDatabaseOpenView(hdb, query, &view);
3673 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3674 r = MsiViewExecute(view, 0);
3675 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3676 r = MsiViewClose(view);
3677 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3678 r = MsiCloseHandle(view);
3679 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3681 /* check the modified text */
3682 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3683 r = MsiDatabaseOpenView(hdb, query, &view);
3684 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3685 r = MsiViewExecute(view, 0);
3686 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3688 r = MsiViewFetch(view, &rec);
3689 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3692 r = MsiRecordGetString(rec, 1, result, &size);
3693 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3694 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3696 MsiCloseHandle(rec);
3698 r = MsiViewFetch(view, &rec);
3699 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3702 r = MsiRecordGetString(rec, 1, result, &size);
3703 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3704 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
3706 MsiCloseHandle(rec);
3708 r = MsiViewFetch(view, &rec);
3709 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3711 r = MsiViewClose(view);
3712 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3713 r = MsiCloseHandle(view);
3714 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3716 /* no where condition */
3717 query = "UPDATE `Control` SET `Text` = 'this is text'";
3718 r = MsiDatabaseOpenView(hdb, query, &view);
3719 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3720 r = MsiViewExecute(view, 0);
3721 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3722 r = MsiViewClose(view);
3723 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3724 r = MsiCloseHandle(view);
3725 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3727 /* check the modified text */
3728 query = "SELECT `Text` FROM `Control`";
3729 r = MsiDatabaseOpenView(hdb, query, &view);
3730 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3731 r = MsiViewExecute(view, 0);
3732 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3734 r = MsiViewFetch(view, &rec);
3735 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3738 r = MsiRecordGetString(rec, 1, result, &size);
3739 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3740 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3742 MsiCloseHandle(rec);
3744 r = MsiViewFetch(view, &rec);
3745 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3748 r = MsiRecordGetString(rec, 1, result, &size);
3749 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3750 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3752 MsiCloseHandle(rec);
3754 r = MsiViewFetch(view, &rec);
3755 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3758 r = MsiRecordGetString(rec, 1, result, &size);
3759 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3760 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
3762 MsiCloseHandle(rec);
3764 r = MsiViewFetch(view, &rec);
3765 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3767 r = MsiViewClose(view);
3768 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3769 r = MsiCloseHandle(view);
3770 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3771 r = MsiDatabaseCommit(hdb);
3772 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
3773 r = MsiCloseHandle(hdb);
3774 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3776 DeleteFile(msifile);
3779 static void test_special_tables(void)
3785 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3786 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3788 query = "CREATE TABLE `_Properties` ( "
3789 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3790 r = run_query(hdb, 0, query);
3791 ok(r == ERROR_SUCCESS, "failed to create table\n");
3793 query = "CREATE TABLE `_Streams` ( "
3794 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3795 r = run_query(hdb, 0, query);
3796 todo_wine ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Streams table\n");
3798 query = "CREATE TABLE `_Tables` ( "
3799 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3800 r = run_query(hdb, 0, query);
3801 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Tables table\n");
3803 query = "CREATE TABLE `_Columns` ( "
3804 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3805 r = run_query(hdb, 0, query);
3806 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Columns table\n");
3808 r = MsiCloseHandle(hdb);
3809 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3812 static void test_select_markers(void)
3814 MSIHANDLE hdb = 0, rec, view, res;
3821 ok( hdb, "failed to create db\n");
3823 r = run_query(hdb, 0,
3824 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
3825 ok(r == S_OK, "cannot create table: %d\n", r);
3827 r = run_query(hdb, 0, "INSERT INTO `Table` "
3828 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
3829 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3831 r = run_query(hdb, 0, "INSERT INTO `Table` "
3832 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
3833 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3835 r = run_query(hdb, 0, "INSERT INTO `Table` "
3836 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
3837 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3839 r = run_query(hdb, 0, "INSERT INTO `Table` "
3840 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
3841 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
3843 rec = MsiCreateRecord(2);
3844 MsiRecordSetString(rec, 1, "apple");
3845 MsiRecordSetString(rec, 2, "two");
3847 query = "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
3848 r = MsiDatabaseOpenView(hdb, query, &view);
3849 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3851 r = MsiViewExecute(view, rec);
3852 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3854 r = MsiViewFetch(view, &res);
3855 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3858 r = MsiRecordGetString(res, 1, buf, &size);
3859 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3860 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
3863 r = MsiRecordGetString(res, 2, buf, &size);
3864 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3865 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
3867 r = MsiRecordGetInteger(res, 3);
3868 ok(r == 1, "Expected 1, got %d\n", r);
3870 MsiCloseHandle(res);
3872 r = MsiViewFetch(view, &res);
3873 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3876 r = MsiRecordGetString(res, 1, buf, &size);
3877 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3878 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
3881 r = MsiRecordGetString(res, 2, buf, &size);
3882 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3883 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
3885 r = MsiRecordGetInteger(res, 3);
3886 ok(r == 2, "Expected 2, got %d\n", r);
3888 MsiCloseHandle(res);
3890 r = MsiViewFetch(view, &res);
3891 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3893 r = MsiViewClose(view);
3894 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3895 r = MsiCloseHandle(view);
3896 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3897 r = MsiCloseHandle(hdb);
3898 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3900 DeleteFile(msifile);
3903 static void test_viewmodify_update(void)
3905 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
3909 DeleteFile(msifile);
3911 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
3912 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
3914 query = "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
3915 r = run_query( hdb, 0, query );
3916 ok(r == ERROR_SUCCESS, "query failed\n");
3918 query = "INSERT INTO `table` (`A`, `B`) VALUES (1, 2)";
3919 r = run_query( hdb, 0, query );
3920 ok(r == ERROR_SUCCESS, "query failed\n");
3922 query = "INSERT INTO `table` (`A`, `B`) VALUES (3, 4)";
3923 r = run_query( hdb, 0, query );
3924 ok(r == ERROR_SUCCESS, "query failed\n");
3926 query = "INSERT INTO `table` (`A`, `B`) VALUES (5, 6)";
3927 r = run_query( hdb, 0, query );
3928 ok(r == ERROR_SUCCESS, "query failed\n");
3930 query = "SELECT `B` FROM `table`";
3931 r = MsiDatabaseOpenView(hdb, query, &hview);
3932 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3933 r = MsiViewExecute(hview, 0);
3934 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3935 r = MsiViewFetch(hview, &hrec);
3936 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
3938 r = MsiRecordSetInteger(hrec, 1, 0);
3939 ok(r == ERROR_SUCCESS, "failed to set integer\n");
3941 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
3942 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
3944 r = MsiCloseHandle(hrec);
3945 ok(r == ERROR_SUCCESS, "failed to close record\n");
3947 r = MsiViewClose(hview);
3948 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3949 r = MsiCloseHandle(hview);
3950 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3952 query = "SELECT * FROM `table`";
3953 r = MsiDatabaseOpenView(hdb, query, &hview);
3954 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3955 r = MsiViewExecute(hview, 0);
3956 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3957 r = MsiViewFetch(hview, &hrec);
3958 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
3960 r = MsiRecordGetInteger(hrec, 1);
3961 ok(r == 1, "Expected 1, got %d\n", r);
3962 r = MsiRecordGetInteger(hrec, 2);
3963 ok(r == 0, "Expected 0, got %d\n", r);
3965 r = MsiCloseHandle(hrec);
3966 ok(r == ERROR_SUCCESS, "failed to close record\n");
3968 r = MsiViewFetch(hview, &hrec);
3969 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
3971 r = MsiRecordGetInteger(hrec, 1);
3972 ok(r == 3, "Expected 3, got %d\n", r);
3973 r = MsiRecordGetInteger(hrec, 2);
3974 ok(r == 4, "Expected 4, got %d\n", r);
3976 r = MsiCloseHandle(hrec);
3977 ok(r == ERROR_SUCCESS, "failed to close record\n");
3979 r = MsiViewFetch(hview, &hrec);
3980 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
3982 r = MsiRecordGetInteger(hrec, 1);
3983 ok(r == 5, "Expected 5, got %d\n", r);
3984 r = MsiRecordGetInteger(hrec, 2);
3985 ok(r == 6, "Expected 6, got %d\n", r);
3987 r = MsiCloseHandle(hrec);
3988 ok(r == ERROR_SUCCESS, "failed to close record\n");
3990 r = MsiViewFetch(hview, &hrec);
3991 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3993 r = MsiViewClose(hview);
3994 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
3995 r = MsiCloseHandle(hview);
3996 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
3998 /* loop through all elements */
3999 query = "SELECT `B` FROM `table`";
4000 r = MsiDatabaseOpenView(hdb, query, &hview);
4001 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4002 r = MsiViewExecute(hview, 0);
4003 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4007 r = MsiViewFetch(hview, &hrec);
4008 if (r != ERROR_SUCCESS)
4011 r = MsiRecordSetInteger(hrec, 1, 0);
4012 ok(r == ERROR_SUCCESS, "failed to set integer\n");
4014 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
4015 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
4017 r = MsiCloseHandle(hrec);
4018 ok(r == ERROR_SUCCESS, "failed to close record\n");
4021 r = MsiViewClose(hview);
4022 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4023 r = MsiCloseHandle(hview);
4024 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4026 query = "SELECT * FROM `table`";
4027 r = MsiDatabaseOpenView(hdb, query, &hview);
4028 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4029 r = MsiViewExecute(hview, 0);
4030 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4031 r = MsiViewFetch(hview, &hrec);
4032 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4034 r = MsiRecordGetInteger(hrec, 1);
4035 ok(r == 1, "Expected 1, got %d\n", r);
4036 r = MsiRecordGetInteger(hrec, 2);
4037 ok(r == 0, "Expected 0, got %d\n", r);
4039 r = MsiCloseHandle(hrec);
4040 ok(r == ERROR_SUCCESS, "failed to close record\n");
4042 r = MsiViewFetch(hview, &hrec);
4043 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4045 r = MsiRecordGetInteger(hrec, 1);
4046 ok(r == 3, "Expected 3, got %d\n", r);
4047 r = MsiRecordGetInteger(hrec, 2);
4048 ok(r == 0, "Expected 0, got %d\n", r);
4050 r = MsiCloseHandle(hrec);
4051 ok(r == ERROR_SUCCESS, "failed to close record\n");
4053 r = MsiViewFetch(hview, &hrec);
4054 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4056 r = MsiRecordGetInteger(hrec, 1);
4057 ok(r == 5, "Expected 5, got %d\n", r);
4058 r = MsiRecordGetInteger(hrec, 2);
4059 ok(r == 0, "Expected 0, got %d\n", r);
4061 r = MsiCloseHandle(hrec);
4062 ok(r == ERROR_SUCCESS, "failed to close record\n");
4064 r = MsiViewFetch(hview, &hrec);
4065 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4067 r = MsiViewClose(hview);
4068 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4069 r = MsiCloseHandle(hview);
4070 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4072 r = MsiCloseHandle( hdb );
4073 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
4080 test_msidecomposedesc();
4081 test_msibadqueries();
4083 test_viewgetcolumninfo();
4091 test_handle_limit();
4092 test_try_transform();
4094 test_temporary_table();
4098 test_special_tables();
4099 test_select_markers();
4100 test_viewmodify_update();