wineps: Fix a couple of typos in the path painting function.
[wine/testsucceed.git] / dlls / msi / tests / db.c
blobb915fa07ff5ddecb9120a74b1712feae93b28f1b
1 /*
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
21 #define COBJMACROS
23 #include <stdio.h>
25 #include <windows.h>
26 #include <msi.h>
27 #include <msidefs.h>
28 #include <msiquery.h>
30 #include <objidl.h>
32 #include "wine/test.h"
34 static const char *msifile = "winetest-db.msi";
35 static const char *msifile2 = "winetst2-db.msi";
36 static const char *mstfile = "winetst-db.mst";
37 static const WCHAR msifileW[] = {'w','i','n','e','t','e','s','t','-','d','b','.','m','s','i',0};
39 static void test_msidatabase(void)
41 MSIHANDLE hdb = 0, hdb2 = 0;
42 UINT res;
44 DeleteFile(msifile);
46 res = MsiOpenDatabase( msifile, msifile2, &hdb );
47 ok( res == ERROR_OPEN_FAILED, "expected failure\n");
49 res = MsiOpenDatabase( msifile, (LPSTR) 0xff, &hdb );
50 ok( res == ERROR_INVALID_PARAMETER, "expected failure\n");
52 res = MsiCloseHandle( hdb );
53 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
55 /* create an empty database */
56 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
57 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
59 res = MsiDatabaseCommit( hdb );
60 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
62 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
64 res = MsiCloseHandle( hdb );
65 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
66 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
67 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
69 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile2 ), "database should exist\n");
71 res = MsiDatabaseCommit( hdb2 );
72 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
74 res = MsiCloseHandle( hdb2 );
75 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
77 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
78 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
80 res = MsiCloseHandle( hdb2 );
81 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
83 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile2 ), "uncommitted database should not exist\n");
85 res = MsiOpenDatabase( msifile, msifile2, &hdb2 );
86 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
88 res = MsiDatabaseCommit( hdb2 );
89 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
91 res = MsiCloseHandle( hdb2 );
92 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
94 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile2 ), "committed database should exist\n");
96 res = MsiOpenDatabase( msifile, MSIDBOPEN_READONLY, &hdb );
97 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
99 res = MsiDatabaseCommit( hdb );
100 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
102 res = MsiCloseHandle( hdb );
103 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
105 res = MsiOpenDatabase( msifile, MSIDBOPEN_DIRECT, &hdb );
106 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
108 res = MsiCloseHandle( hdb );
109 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
111 res = MsiOpenDatabase( msifile, MSIDBOPEN_TRANSACT, &hdb );
112 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
114 res = MsiCloseHandle( hdb );
115 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
116 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
118 /* MSIDBOPEN_CREATE deletes the database if MsiCommitDatabase isn't called */
119 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
120 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
122 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
124 res = MsiCloseHandle( hdb );
125 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
127 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile ), "database should exist\n");
129 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
130 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
132 res = MsiDatabaseCommit( hdb );
133 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
135 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
137 res = MsiCloseHandle( hdb );
138 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
140 res = DeleteFile( msifile2 );
141 ok( res == TRUE, "Failed to delete database\n" );
143 res = DeleteFile( msifile );
144 ok( res == TRUE, "Failed to delete database\n" );
147 static UINT do_query(MSIHANDLE hdb, const char *query, MSIHANDLE *phrec)
149 MSIHANDLE hview = 0;
150 UINT r, ret;
152 if (phrec)
153 *phrec = 0;
155 /* open a select query */
156 r = MsiDatabaseOpenView(hdb, query, &hview);
157 if (r != ERROR_SUCCESS)
158 return r;
159 r = MsiViewExecute(hview, 0);
160 if (r != ERROR_SUCCESS)
161 return r;
162 ret = MsiViewFetch(hview, phrec);
163 r = MsiViewClose(hview);
164 if (r != ERROR_SUCCESS)
165 return r;
166 r = MsiCloseHandle(hview);
167 if (r != ERROR_SUCCESS)
168 return r;
169 return ret;
172 static UINT run_query( MSIHANDLE hdb, MSIHANDLE hrec, const char *query )
174 MSIHANDLE hview = 0;
175 UINT r;
177 r = MsiDatabaseOpenView(hdb, query, &hview);
178 if( r != ERROR_SUCCESS )
179 return r;
181 r = MsiViewExecute(hview, hrec);
182 if( r == ERROR_SUCCESS )
183 r = MsiViewClose(hview);
184 MsiCloseHandle(hview);
185 return r;
188 static UINT run_queryW( MSIHANDLE hdb, MSIHANDLE hrec, const WCHAR *query )
190 MSIHANDLE hview = 0;
191 UINT r;
193 r = MsiDatabaseOpenViewW(hdb, query, &hview);
194 if( r != ERROR_SUCCESS )
195 return r;
197 r = MsiViewExecute(hview, hrec);
198 if( r == ERROR_SUCCESS )
199 r = MsiViewClose(hview);
200 MsiCloseHandle(hview);
201 return r;
204 static UINT create_component_table( MSIHANDLE hdb )
206 return run_query( hdb, 0,
207 "CREATE TABLE `Component` ( "
208 "`Component` CHAR(72) NOT NULL, "
209 "`ComponentId` CHAR(38), "
210 "`Directory_` CHAR(72) NOT NULL, "
211 "`Attributes` SHORT NOT NULL, "
212 "`Condition` CHAR(255), "
213 "`KeyPath` CHAR(72) "
214 "PRIMARY KEY `Component`)" );
217 static UINT create_custom_action_table( MSIHANDLE hdb )
219 return run_query( hdb, 0,
220 "CREATE TABLE `CustomAction` ( "
221 "`Action` CHAR(72) NOT NULL, "
222 "`Type` SHORT NOT NULL, "
223 "`Source` CHAR(72), "
224 "`Target` CHAR(255) "
225 "PRIMARY KEY `Action`)" );
228 static UINT create_directory_table( MSIHANDLE hdb )
230 return run_query( hdb, 0,
231 "CREATE TABLE `Directory` ( "
232 "`Directory` CHAR(255) NOT NULL, "
233 "`Directory_Parent` CHAR(255), "
234 "`DefaultDir` CHAR(255) NOT NULL "
235 "PRIMARY KEY `Directory`)" );
238 static UINT create_feature_components_table( MSIHANDLE hdb )
240 return run_query( hdb, 0,
241 "CREATE TABLE `FeatureComponents` ( "
242 "`Feature_` CHAR(38) NOT NULL, "
243 "`Component_` CHAR(72) NOT NULL "
244 "PRIMARY KEY `Feature_`, `Component_` )" );
247 static UINT create_std_dlls_table( MSIHANDLE hdb )
249 return run_query( hdb, 0,
250 "CREATE TABLE `StdDlls` ( "
251 "`File` CHAR(255) NOT NULL, "
252 "`Binary_` CHAR(72) NOT NULL "
253 "PRIMARY KEY `File` )" );
256 static UINT create_binary_table( MSIHANDLE hdb )
258 return run_query( hdb, 0,
259 "CREATE TABLE `Binary` ( "
260 "`Name` CHAR(72) NOT NULL, "
261 "`Data` CHAR(72) NOT NULL "
262 "PRIMARY KEY `Name` )" );
265 #define make_add_entry(type, qtext) \
266 static UINT add##_##type##_##entry( MSIHANDLE hdb, const char *values ) \
268 char insert[] = qtext; \
269 char *query; \
270 UINT sz, r; \
271 sz = strlen(values) + sizeof insert; \
272 query = HeapAlloc(GetProcessHeap(),0,sz); \
273 sprintf(query,insert,values); \
274 r = run_query( hdb, 0, query ); \
275 HeapFree(GetProcessHeap(), 0, query); \
276 return r; \
279 make_add_entry(component,
280 "INSERT INTO `Component` "
281 "(`Component`, `ComponentId`, `Directory_`, "
282 "`Attributes`, `Condition`, `KeyPath`) VALUES( %s )")
284 make_add_entry(custom_action,
285 "INSERT INTO `CustomAction` "
286 "(`Action`, `Type`, `Source`, `Target`) VALUES( %s )")
288 make_add_entry(feature_components,
289 "INSERT INTO `FeatureComponents` "
290 "(`Feature_`, `Component_`) VALUES( %s )")
292 make_add_entry(std_dlls,
293 "INSERT INTO `StdDlls` (`File`, `Binary_`) VALUES( %s )")
295 make_add_entry(binary,
296 "INSERT INTO `Binary` (`Name`, `Data`) VALUES( %s )")
298 static void test_msiinsert(void)
300 MSIHANDLE hdb = 0, hview = 0, hview2 = 0, hrec = 0;
301 UINT r;
302 const char *query;
303 char buf[80];
304 DWORD sz;
306 DeleteFile(msifile);
308 /* just MsiOpenDatabase should not create a file */
309 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
310 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
312 /* create a table */
313 query = "CREATE TABLE `phone` ( "
314 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
315 "PRIMARY KEY `id`)";
316 r = MsiDatabaseOpenView(hdb, query, &hview);
317 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
318 r = MsiViewExecute(hview, 0);
319 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
320 r = MsiViewClose(hview);
321 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
322 r = MsiCloseHandle(hview);
323 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
325 query = "SELECT * FROM phone WHERE number = '8675309'";
326 r = MsiDatabaseOpenView(hdb, query, &hview2);
327 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
328 r = MsiViewExecute(hview2, 0);
329 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
330 r = MsiViewFetch(hview2, &hrec);
331 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch produced items\n");
333 /* insert a value into it */
334 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
335 "VALUES('1', 'Abe', '8675309')";
336 r = MsiDatabaseOpenView(hdb, query, &hview);
337 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
338 r = MsiViewExecute(hview, 0);
339 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
340 r = MsiViewClose(hview);
341 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
342 r = MsiCloseHandle(hview);
343 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
345 r = MsiViewFetch(hview2, &hrec);
346 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch produced items\n");
347 r = MsiViewExecute(hview2, 0);
348 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
349 r = MsiViewFetch(hview2, &hrec);
350 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %u\n", r);
352 r = MsiCloseHandle(hrec);
353 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
354 r = MsiViewClose(hview2);
355 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
356 r = MsiCloseHandle(hview2);
357 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
359 query = "SELECT * FROM `phone` WHERE `id` = 1";
360 r = do_query(hdb, query, &hrec);
361 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
363 /* check the record contains what we put in it */
364 r = MsiRecordGetFieldCount(hrec);
365 ok(r == 3, "record count wrong\n");
367 r = MsiRecordIsNull(hrec, 0);
368 ok(r == FALSE, "field 0 not null\n");
370 r = MsiRecordGetInteger(hrec, 1);
371 ok(r == 1, "field 1 contents wrong\n");
372 sz = sizeof buf;
373 r = MsiRecordGetString(hrec, 2, buf, &sz);
374 ok(r == ERROR_SUCCESS, "field 2 content fetch failed\n");
375 ok(!strcmp(buf,"Abe"), "field 2 content incorrect\n");
376 sz = sizeof buf;
377 r = MsiRecordGetString(hrec, 3, buf, &sz);
378 ok(r == ERROR_SUCCESS, "field 3 content fetch failed\n");
379 ok(!strcmp(buf,"8675309"), "field 3 content incorrect\n");
381 r = MsiCloseHandle(hrec);
382 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
384 /* open a select query */
385 hrec = 100;
386 query = "SELECT * FROM `phone` WHERE `id` >= 10";
387 r = do_query(hdb, query, &hrec);
388 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
389 ok(hrec == 0, "hrec should be null\n");
391 r = MsiCloseHandle(hrec);
392 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
394 query = "SELECT * FROM `phone` WHERE `id` < 0";
395 r = do_query(hdb, query, &hrec);
396 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
398 query = "SELECT * FROM `phone` WHERE `id` <= 0";
399 r = do_query(hdb, query, &hrec);
400 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
402 query = "SELECT * FROM `phone` WHERE `id` <> 1";
403 r = do_query(hdb, query, &hrec);
404 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
406 query = "SELECT * FROM `phone` WHERE `id` > 10";
407 r = do_query(hdb, query, &hrec);
408 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
410 /* now try a few bad INSERT xqueries */
411 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
412 "VALUES(?, ?)";
413 r = MsiDatabaseOpenView(hdb, query, &hview);
414 ok(r == ERROR_BAD_QUERY_SYNTAX, "MsiDatabaseOpenView failed\n");
416 /* construct a record to insert */
417 hrec = MsiCreateRecord(4);
418 r = MsiRecordSetInteger(hrec, 1, 2);
419 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
420 r = MsiRecordSetString(hrec, 2, "Adam");
421 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
422 r = MsiRecordSetString(hrec, 3, "96905305");
423 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
425 /* insert another value, using a record and wildcards */
426 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
427 "VALUES(?, ?, ?)";
428 r = MsiDatabaseOpenView(hdb, query, &hview);
429 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
431 if (r == ERROR_SUCCESS)
433 r = MsiViewExecute(hview, hrec);
434 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
435 r = MsiViewClose(hview);
436 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
437 r = MsiCloseHandle(hview);
438 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
440 r = MsiCloseHandle(hrec);
441 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
443 r = MsiViewFetch(0, NULL);
444 ok(r == ERROR_INVALID_PARAMETER, "MsiViewFetch failed\n");
446 r = MsiDatabaseCommit(hdb);
447 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
449 r = MsiCloseHandle(hdb);
450 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
452 r = DeleteFile(msifile);
453 ok(r == TRUE, "file didn't exist after commit\n");
456 typedef UINT (WINAPI *fnMsiDecomposeDescriptorA)(LPCSTR, LPCSTR, LPSTR, LPSTR, DWORD *);
457 static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA;
459 static void test_msidecomposedesc(void)
461 char prod[MAX_FEATURE_CHARS+1], comp[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1];
462 const char *desc;
463 UINT r;
464 DWORD len;
465 HMODULE hmod;
467 hmod = GetModuleHandle("msi.dll");
468 pMsiDecomposeDescriptorA = (fnMsiDecomposeDescriptorA)
469 GetProcAddress(hmod, "MsiDecomposeDescriptorA");
470 if (!pMsiDecomposeDescriptorA)
471 return;
473 /* test a valid feature descriptor */
474 desc = "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
475 len = 0;
476 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
477 ok(r == ERROR_SUCCESS, "returned an error\n");
478 ok(len == strlen(desc), "length was wrong\n");
479 ok(strcmp(prod,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
480 ok(strcmp(feature,"FollowTheWhiteRabbit")==0, "feature wrong\n");
481 ok(strcmp(comp,"{A7CD68DB-EF74-49C8-FBB2-A7C463B2AC24}")==0,"component wrong\n");
483 /* test an invalid feature descriptor with too many characters */
484 desc = "']gAVn-}f(ZXfeAR6.ji"
485 "ThisWillFailIfTheresMoreThanAGuidsChars>"
486 "3w2x^IGfe?CxI5heAvk.";
487 len = 0;
488 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
489 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
492 * Test a valid feature descriptor with the
493 * maximum number of characters and some trailing characters.
495 desc = "']gAVn-}f(ZXfeAR6.ji"
496 "ThisWillWorkIfTheresLTEThanAGuidsChars>"
497 "3w2x^IGfe?CxI5heAvk."
498 "extra";
499 len = 0;
500 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
501 ok(r == ERROR_SUCCESS, "returned wrong error\n");
502 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
504 len = 0;
505 r = pMsiDecomposeDescriptorA(desc, prod, feature, NULL, &len);
506 ok(r == ERROR_SUCCESS, "returned wrong error\n");
507 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
509 len = 0;
510 r = pMsiDecomposeDescriptorA(desc, prod, NULL, NULL, &len);
511 ok(r == ERROR_SUCCESS, "returned wrong error\n");
512 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
514 len = 0;
515 r = pMsiDecomposeDescriptorA(desc, NULL, NULL, NULL, &len);
516 ok(r == ERROR_SUCCESS, "returned wrong error\n");
517 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
519 len = 0;
520 r = pMsiDecomposeDescriptorA(NULL, NULL, NULL, NULL, &len);
521 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
522 ok(len == 0, "length wrong\n");
524 r = pMsiDecomposeDescriptorA(desc, NULL, NULL, NULL, NULL);
525 ok(r == ERROR_SUCCESS, "returned wrong error\n");
528 static UINT try_query_param( MSIHANDLE hdb, LPCSTR szQuery, MSIHANDLE hrec )
530 MSIHANDLE htab = 0;
531 UINT res;
533 res = MsiDatabaseOpenView( hdb, szQuery, &htab );
534 if(res == ERROR_SUCCESS )
536 UINT r;
538 r = MsiViewExecute( htab, hrec );
539 if(r != ERROR_SUCCESS )
540 res = r;
542 r = MsiViewClose( htab );
543 if(r != ERROR_SUCCESS )
544 res = r;
546 r = MsiCloseHandle( htab );
547 if(r != ERROR_SUCCESS )
548 res = r;
550 return res;
553 static UINT try_query( MSIHANDLE hdb, LPCSTR szQuery )
555 return try_query_param( hdb, szQuery, 0 );
558 static UINT try_insert_query( MSIHANDLE hdb, LPCSTR szQuery )
560 MSIHANDLE hrec = 0;
561 UINT r;
563 hrec = MsiCreateRecord( 1 );
564 MsiRecordSetString( hrec, 1, "Hello");
566 r = try_query_param( hdb, szQuery, hrec );
568 MsiCloseHandle( hrec );
569 return r;
572 static void test_msibadqueries(void)
574 MSIHANDLE hdb = 0;
575 UINT r;
577 DeleteFile(msifile);
579 /* just MsiOpenDatabase should not create a file */
580 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
581 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
583 r = MsiDatabaseCommit( hdb );
584 ok(r == ERROR_SUCCESS , "Failed to commit database\n");
586 r = MsiCloseHandle( hdb );
587 ok(r == ERROR_SUCCESS , "Failed to close database\n");
589 /* open it readonly */
590 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb );
591 ok(r == ERROR_SUCCESS , "Failed to open database r/o\n");
593 /* add a table to it */
594 r = try_query( hdb, "select * from _Tables");
595 ok(r == ERROR_SUCCESS , "query 1 failed\n");
597 r = MsiCloseHandle( hdb );
598 ok(r == ERROR_SUCCESS , "Failed to close database r/o\n");
600 /* open it read/write */
601 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
602 ok(r == ERROR_SUCCESS , "Failed to open database r/w\n");
604 /* a bunch of test queries that fail with the native MSI */
606 r = try_query( hdb, "CREATE TABLE");
607 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2a return code\n");
609 r = try_query( hdb, "CREATE TABLE `a`");
610 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2b return code\n");
612 r = try_query( hdb, "CREATE TABLE `a` ()");
613 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2c return code\n");
615 r = try_query( hdb, "CREATE TABLE `a` (`b`)");
616 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2d return code\n");
618 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) )");
619 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2e return code\n");
621 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
622 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2f return code\n");
624 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
625 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2g return code\n");
627 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
628 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2h return code\n");
630 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
631 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2i return code\n");
633 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
634 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2j return code\n");
636 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
637 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2k return code\n");
639 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
640 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2l return code\n");
642 r = try_query( hdb, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
643 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2m return code\n");
645 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
646 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2n return code\n");
648 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
649 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2o return code\n");
651 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
652 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
654 r = try_query( hdb, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
655 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
657 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
658 ok(r == ERROR_SUCCESS , "valid query 2z failed\n");
660 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
661 ok(r == ERROR_BAD_QUERY_SYNTAX , "created same table again\n");
663 r = try_query( hdb, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
664 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
665 ok(r == ERROR_SUCCESS , "query 4 failed\n");
667 r = MsiDatabaseCommit( hdb );
668 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
670 r = try_query( hdb, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
671 "PRIMARY KEY `foo`)");
672 ok(r == ERROR_SUCCESS , "query 4 failed\n");
674 r = try_insert_query( hdb, "insert into a ( `b` ) VALUES ( ? )");
675 ok(r == ERROR_SUCCESS , "failed to insert record in db\n");
677 r = MsiDatabaseCommit( hdb );
678 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
680 r = try_query( hdb, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
681 "PRIMARY KEY `ba`)");
682 ok(r != ERROR_SUCCESS , "query 5 succeeded\n");
684 r = try_query( hdb,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
685 ok(r != ERROR_SUCCESS , "query 6 succeeded\n");
687 r = try_query( hdb, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
688 "PRIMARY KEY `t`)");
689 ok(r == ERROR_SUCCESS , "query 7 failed\n");
691 r = try_query( hdb, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
692 ok(r == ERROR_SUCCESS , "query 8 failed\n");
694 r = try_query( hdb, "select * from c");
695 ok(r == ERROR_SUCCESS , "query failed\n");
697 r = try_query( hdb, "select * from c where b = 'x");
698 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
700 r = try_query( hdb, "select * from c where b = 'x'");
701 ok(r == ERROR_SUCCESS, "query failed\n");
703 r = try_query( hdb, "select * from 'c'");
704 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
706 r = try_query( hdb, "select * from ''");
707 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
709 r = try_query( hdb, "select * from c where b = x");
710 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
712 r = try_query( hdb, "select * from c where b = \"x\"");
713 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
715 r = try_query( hdb, "select * from c where b = 'x'");
716 ok(r == ERROR_SUCCESS, "query failed\n");
718 r = try_query( hdb, "select * from c where b = '\"x'");
719 ok(r == ERROR_SUCCESS, "query failed\n");
721 if (0) /* FIXME: this query causes trouble with other tests */
723 r = try_query( hdb, "select * from c where b = '\\\'x'");
724 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
727 r = try_query( hdb, "select * from 'c'");
728 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
730 r = try_query( hdb, "CREATE TABLE `\5a` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
731 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
733 r = try_query( hdb, "SELECT * FROM \5a" );
734 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
736 r = try_query( hdb, "CREATE TABLE `a\5` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
737 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
739 r = try_query( hdb, "SELECT * FROM a\5" );
740 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
742 r = try_query( hdb, "CREATE TABLE `-a` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
743 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
745 r = try_query( hdb, "SELECT * FROM -a" );
746 todo_wine ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
748 r = try_query( hdb, "CREATE TABLE `a-` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
749 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
751 r = try_query( hdb, "SELECT * FROM a-" );
752 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
754 r = MsiCloseHandle( hdb );
755 ok(r == ERROR_SUCCESS , "Failed to close database transact\n");
757 r = DeleteFile( msifile );
758 ok(r == TRUE, "file didn't exist after commit\n");
761 static void test_viewmodify(void)
763 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
764 UINT r;
765 MSIDBERROR err;
766 const char *query;
767 char buffer[0x100];
768 DWORD sz;
770 DeleteFile(msifile);
772 /* just MsiOpenDatabase should not create a file */
773 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
774 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
776 query = "CREATE TABLE `phone` ( "
777 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
778 "PRIMARY KEY `id`)";
779 r = run_query( hdb, 0, query );
780 ok(r == ERROR_SUCCESS, "query failed\n");
782 query = "CREATE TABLE `_Validation` ( "
783 "`Table` CHAR(32) NOT NULL, `Column` CHAR(32) NOT NULL, "
784 "`Nullable` CHAR(4) NOT NULL, `MinValue` INT, `MaxValue` INT, "
785 "`KeyTable` CHAR(255), `KeyColumn` SHORT, `Category` CHAR(32), "
786 "`Set` CHAR(255), `Description` CHAR(255) PRIMARY KEY `Table`, `Column`)";
787 r = run_query( hdb, 0, query );
788 ok(r == ERROR_SUCCESS, "query failed\n");
790 query = "INSERT INTO `_Validation` ( `Table`, `Column`, `Nullable` ) "
791 "VALUES('phone', 'id', 'N')";
792 r = run_query( hdb, 0, query );
793 ok(r == ERROR_SUCCESS, "query failed\n");
795 /* check what the error function reports without doing anything */
796 sz = 0;
797 /* passing NULL as the 3rd param make function to crash on older platforms */
798 err = MsiViewGetError( 0, NULL, &sz );
799 ok(err == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
801 /* open a view */
802 query = "SELECT * FROM `phone`";
803 r = MsiDatabaseOpenView(hdb, query, &hview);
804 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
806 /* see what happens with a good hview and bad args */
807 err = MsiViewGetError( hview, NULL, NULL );
808 ok(err == MSIDBERROR_INVALIDARG || err == MSIDBERROR_NOERROR,
809 "MsiViewGetError returns %u (expected -3)\n", err);
810 err = MsiViewGetError( hview, buffer, NULL );
811 ok(err == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
813 /* see what happens with a zero length buffer */
814 sz = 0;
815 buffer[0] = 'x';
816 err = MsiViewGetError( hview, buffer, &sz );
817 ok(err == MSIDBERROR_MOREDATA, "MsiViewGetError return\n");
818 ok(buffer[0] == 'x', "buffer cleared\n");
819 ok(sz == 0, "size not zero\n");
821 /* ok this one is strange */
822 sz = 0;
823 err = MsiViewGetError( hview, NULL, &sz );
824 ok(err == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
825 ok(sz == 0, "size not zero\n");
827 /* see if it really has an error */
828 sz = sizeof buffer;
829 buffer[0] = 'x';
830 err = MsiViewGetError( hview, buffer, &sz );
831 ok(err == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
832 ok(buffer[0] == 0, "buffer not cleared\n");
833 ok(sz == 0, "size not zero\n");
835 r = MsiViewExecute(hview, 0);
836 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
838 /* try some invalid records */
839 r = MsiViewModify(hview, MSIMODIFY_INSERT, 0 );
840 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
841 r = MsiViewModify(hview, -1, 0 );
842 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
844 /* try an small record */
845 hrec = MsiCreateRecord(1);
846 r = MsiViewModify(hview, -1, hrec );
847 ok(r == ERROR_INVALID_DATA, "MsiViewModify failed\n");
849 sz = sizeof buffer;
850 buffer[0] = 'x';
851 err = MsiViewGetError( hview, buffer, &sz );
852 ok(err == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
853 ok(buffer[0] == 0, "buffer not cleared\n");
854 ok(sz == 0, "size not zero\n");
856 r = MsiCloseHandle(hrec);
857 ok(r == ERROR_SUCCESS, "failed to close record\n");
859 /* insert a valid record */
860 hrec = MsiCreateRecord(3);
862 r = MsiRecordSetInteger(hrec, 1, 1);
863 ok(r == ERROR_SUCCESS, "failed to set integer\n");
864 r = MsiRecordSetString(hrec, 2, "bob");
865 ok(r == ERROR_SUCCESS, "failed to set string\n");
866 r = MsiRecordSetString(hrec, 3, "7654321");
867 ok(r == ERROR_SUCCESS, "failed to set string\n");
869 r = MsiViewExecute(hview, 0);
870 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
871 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
872 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
874 /* validate it */
875 r = MsiViewExecute(hview, 0);
876 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
878 r = MsiViewModify(hview, MSIMODIFY_VALIDATE_NEW, hrec );
879 ok(r == ERROR_INVALID_DATA, "MsiViewModify failed %u\n", r);
881 sz = sizeof buffer;
882 buffer[0] = 'x';
883 err = MsiViewGetError( hview, buffer, &sz );
884 ok(err == MSIDBERROR_DUPLICATEKEY, "MsiViewGetError returned %u\n", err);
885 ok(!strcmp(buffer, "id"), "expected \"id\" c, got \"%s\"\n", buffer);
886 ok(sz == 2, "size not 2\n");
888 /* insert the same thing again */
889 r = MsiViewExecute(hview, 0);
890 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
892 /* should fail ... */
893 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
894 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
896 r = MsiCloseHandle(hrec);
897 ok(r == ERROR_SUCCESS, "failed to close record\n");
899 r = MsiViewClose(hview);
900 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
901 r = MsiCloseHandle(hview);
902 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
904 query = "SELECT * FROM `phone`";
905 r = MsiDatabaseOpenView(hdb, query, &hview);
906 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
908 r = MsiViewExecute(hview, 0);
909 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
911 r = MsiViewFetch(hview, &hrec);
912 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
914 r = MsiRecordGetInteger(hrec, 1);
915 ok(r == 1, "Expected 1, got %d\n", r);
917 sz = sizeof(buffer);
918 r = MsiRecordGetString(hrec, 2, buffer, &sz);
919 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
920 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
922 sz = sizeof(buffer);
923 r = MsiRecordGetString(hrec, 3, buffer, &sz);
924 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
925 ok(!lstrcmp(buffer, "7654321"), "Expected 7654321, got %s\n", buffer);
927 /* update the view, non-primary key */
928 r = MsiRecordSetString(hrec, 3, "3141592");
929 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
931 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
932 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
934 /* do it again */
935 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
936 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
938 /* update the view, primary key */
939 r = MsiRecordSetInteger(hrec, 1, 5);
940 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
942 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
943 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
945 r = MsiCloseHandle(hrec);
946 ok(r == ERROR_SUCCESS, "failed to close record\n");
948 r = MsiViewClose(hview);
949 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
950 r = MsiCloseHandle(hview);
951 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
953 query = "SELECT * FROM `phone`";
954 r = MsiDatabaseOpenView(hdb, query, &hview);
955 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
957 r = MsiViewExecute(hview, 0);
958 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
960 r = MsiViewFetch(hview, &hrec);
961 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
963 r = MsiRecordGetInteger(hrec, 1);
964 ok(r == 1, "Expected 1, got %d\n", r);
966 sz = sizeof(buffer);
967 r = MsiRecordGetString(hrec, 2, buffer, &sz);
968 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
969 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
971 sz = sizeof(buffer);
972 r = MsiRecordGetString(hrec, 3, buffer, &sz);
973 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
974 ok(!lstrcmp(buffer, "3141592"), "Expected 3141592, got %s\n", buffer);
976 r = MsiCloseHandle(hrec);
977 ok(r == ERROR_SUCCESS, "failed to close record\n");
979 /* use a record that doesn't come from a view fetch */
980 hrec = MsiCreateRecord(3);
981 ok(hrec != 0, "MsiCreateRecord failed\n");
983 r = MsiRecordSetInteger(hrec, 1, 3);
984 ok(r == ERROR_SUCCESS, "failed to set integer\n");
985 r = MsiRecordSetString(hrec, 2, "jane");
986 ok(r == ERROR_SUCCESS, "failed to set string\n");
987 r = MsiRecordSetString(hrec, 3, "112358");
988 ok(r == ERROR_SUCCESS, "failed to set string\n");
990 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
991 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
993 r = MsiCloseHandle(hrec);
994 ok(r == ERROR_SUCCESS, "failed to close record\n");
996 /* use a record that doesn't come from a view fetch, primary key matches */
997 hrec = MsiCreateRecord(3);
998 ok(hrec != 0, "MsiCreateRecord failed\n");
1000 r = MsiRecordSetInteger(hrec, 1, 1);
1001 ok(r == ERROR_SUCCESS, "failed to set integer\n");
1002 r = MsiRecordSetString(hrec, 2, "jane");
1003 ok(r == ERROR_SUCCESS, "failed to set string\n");
1004 r = MsiRecordSetString(hrec, 3, "112358");
1005 ok(r == ERROR_SUCCESS, "failed to set string\n");
1007 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
1008 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
1010 r = MsiCloseHandle(hrec);
1011 ok(r == ERROR_SUCCESS, "failed to close record\n");
1013 hrec = MsiCreateRecord(3);
1015 r = MsiRecordSetInteger(hrec, 1, 2);
1016 ok(r == ERROR_SUCCESS, "failed to set integer\n");
1017 r = MsiRecordSetString(hrec, 2, "nick");
1018 ok(r == ERROR_SUCCESS, "failed to set string\n");
1019 r = MsiRecordSetString(hrec, 3, "141421");
1020 ok(r == ERROR_SUCCESS, "failed to set string\n");
1022 r = MsiViewExecute(hview, 0);
1023 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1024 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
1025 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
1027 r = MsiCloseHandle(hrec);
1028 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1029 r = MsiViewClose(hview);
1030 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1031 r = MsiCloseHandle(hview);
1032 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1034 query = "SELECT * FROM `phone` WHERE `id` = 1";
1035 r = MsiDatabaseOpenView(hdb, query, &hview);
1036 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1037 r = MsiViewExecute(hview, 0);
1038 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1039 r = MsiViewFetch(hview, &hrec);
1040 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1042 /* change the id to match the second row */
1043 r = MsiRecordSetInteger(hrec, 1, 2);
1044 ok(r == ERROR_SUCCESS, "failed to set integer\n");
1045 r = MsiRecordSetString(hrec, 2, "jerry");
1046 ok(r == ERROR_SUCCESS, "failed to set string\n");
1048 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
1049 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
1051 r = MsiCloseHandle(hrec);
1052 ok(r == ERROR_SUCCESS, "failed to close record\n");
1053 r = MsiViewClose(hview);
1054 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1055 r = MsiCloseHandle(hview);
1056 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1058 /* broader search */
1059 query = "SELECT * FROM `phone` ORDER BY `id`";
1060 r = MsiDatabaseOpenView(hdb, query, &hview);
1061 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1062 r = MsiViewExecute(hview, 0);
1063 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1064 r = MsiViewFetch(hview, &hrec);
1065 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1067 /* change the id to match the second row */
1068 r = MsiRecordSetInteger(hrec, 1, 2);
1069 ok(r == ERROR_SUCCESS, "failed to set integer\n");
1070 r = MsiRecordSetString(hrec, 2, "jerry");
1071 ok(r == ERROR_SUCCESS, "failed to set string\n");
1073 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
1074 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
1076 r = MsiCloseHandle(hrec);
1077 ok(r == ERROR_SUCCESS, "failed to close record\n");
1078 r = MsiViewClose(hview);
1079 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1080 r = MsiCloseHandle(hview);
1081 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1083 r = MsiCloseHandle( hdb );
1084 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
1087 static MSIHANDLE create_db(void)
1089 MSIHANDLE hdb = 0;
1090 UINT res;
1092 DeleteFile(msifile);
1094 /* create an empty database */
1095 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
1096 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
1097 if( res != ERROR_SUCCESS )
1098 return hdb;
1100 res = MsiDatabaseCommit( hdb );
1101 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
1103 return hdb;
1106 static void test_getcolinfo(void)
1108 MSIHANDLE hdb, hview = 0, rec = 0;
1109 UINT r;
1110 DWORD sz;
1111 char buffer[0x20];
1113 /* create an empty db */
1114 hdb = create_db();
1115 ok( hdb, "failed to create db\n");
1117 /* tables should be present */
1118 r = MsiDatabaseOpenView(hdb, "select * from _Tables", &hview);
1119 ok( r == ERROR_SUCCESS, "failed to open query\n");
1121 r = MsiViewExecute(hview, 0);
1122 ok( r == ERROR_SUCCESS, "failed to execute query\n");
1124 /* check that NAMES works */
1125 rec = 0;
1126 r = MsiViewGetColumnInfo( hview, MSICOLINFO_NAMES, &rec );
1127 ok( r == ERROR_SUCCESS, "failed to get names\n");
1128 sz = sizeof buffer;
1129 r = MsiRecordGetString(rec, 1, buffer, &sz );
1130 ok( r == ERROR_SUCCESS, "failed to get string\n");
1131 ok( !strcmp(buffer,"Name"), "_Tables has wrong column name\n");
1132 r = MsiCloseHandle( rec );
1133 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1135 /* check that TYPES works */
1136 rec = 0;
1137 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, &rec );
1138 ok( r == ERROR_SUCCESS, "failed to get names\n");
1139 sz = sizeof buffer;
1140 r = MsiRecordGetString(rec, 1, buffer, &sz );
1141 ok( r == ERROR_SUCCESS, "failed to get string\n");
1142 ok( !strcmp(buffer,"s64"), "_Tables has wrong column type\n");
1143 r = MsiCloseHandle( rec );
1144 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1146 /* check that invalid values fail */
1147 rec = 0;
1148 r = MsiViewGetColumnInfo( hview, 100, &rec );
1149 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1150 ok( rec == 0, "returned a record\n");
1152 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, NULL );
1153 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1155 r = MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES, &rec );
1156 ok( r == ERROR_INVALID_HANDLE, "wrong error code\n");
1158 r = MsiViewClose(hview);
1159 ok( r == ERROR_SUCCESS, "failed to close view\n");
1160 r = MsiCloseHandle(hview);
1161 ok( r == ERROR_SUCCESS, "failed to close view handle\n");
1162 r = MsiCloseHandle(hdb);
1163 ok( r == ERROR_SUCCESS, "failed to close database\n");
1166 static MSIHANDLE get_column_info(MSIHANDLE hdb, const char *query, MSICOLINFO type)
1168 MSIHANDLE hview = 0, rec = 0;
1169 UINT r;
1171 r = MsiDatabaseOpenView(hdb, query, &hview);
1172 if( r != ERROR_SUCCESS )
1173 return r;
1175 r = MsiViewExecute(hview, 0);
1176 if( r == ERROR_SUCCESS )
1178 MsiViewGetColumnInfo( hview, type, &rec );
1180 MsiViewClose(hview);
1181 MsiCloseHandle(hview);
1182 return rec;
1185 static UINT get_columns_table_type(MSIHANDLE hdb, const char *table, UINT field)
1187 MSIHANDLE hview = 0, rec = 0;
1188 UINT r, type = 0;
1189 char query[0x100];
1191 sprintf(query, "select * from `_Columns` where `Table` = '%s'", table );
1193 r = MsiDatabaseOpenView(hdb, query, &hview);
1194 if( r != ERROR_SUCCESS )
1195 return r;
1197 r = MsiViewExecute(hview, 0);
1198 if( r == ERROR_SUCCESS )
1200 while (1)
1202 r = MsiViewFetch( hview, &rec );
1203 if( r != ERROR_SUCCESS)
1204 break;
1205 r = MsiRecordGetInteger( rec, 2 );
1206 if (r == field)
1207 type = MsiRecordGetInteger( rec, 4 );
1208 MsiCloseHandle( rec );
1211 MsiViewClose(hview);
1212 MsiCloseHandle(hview);
1213 return type;
1216 static BOOL check_record( MSIHANDLE rec, UINT field, LPCSTR val )
1218 CHAR buffer[0x20];
1219 UINT r;
1220 DWORD sz;
1222 sz = sizeof buffer;
1223 r = MsiRecordGetString( rec, field, buffer, &sz );
1224 return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
1227 static void test_viewgetcolumninfo(void)
1229 MSIHANDLE hdb = 0, rec;
1230 UINT r;
1232 hdb = create_db();
1233 ok( hdb, "failed to create db\n");
1235 r = run_query( hdb, 0,
1236 "CREATE TABLE `Properties` "
1237 "( `Property` CHAR(255), "
1238 " `Value` CHAR(1), "
1239 " `Intvalue` INT, "
1240 " `Integervalue` INTEGER, "
1241 " `Shortvalue` SHORT, "
1242 " `Longvalue` LONG, "
1243 " `Longcharvalue` LONGCHAR "
1244 " PRIMARY KEY `Property`)" );
1245 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1247 /* check the column types */
1248 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_TYPES );
1249 ok( rec, "failed to get column info record\n" );
1251 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1252 ok( check_record( rec, 2, "S1"), "wrong record type\n");
1253 ok( check_record( rec, 3, "I2"), "wrong record type\n");
1254 ok( check_record( rec, 4, "I2"), "wrong record type\n");
1255 ok( check_record( rec, 5, "I2"), "wrong record type\n");
1256 ok( check_record( rec, 6, "I4"), "wrong record type\n");
1257 ok( check_record( rec, 7, "S0"), "wrong record type\n");
1259 MsiCloseHandle( rec );
1261 /* check the type in _Columns */
1262 ok( 0x3dff == get_columns_table_type(hdb, "Properties", 1 ), "_columns table wrong\n");
1263 ok( 0x1d01 == get_columns_table_type(hdb, "Properties", 2 ), "_columns table wrong\n");
1264 ok( 0x1502 == get_columns_table_type(hdb, "Properties", 3 ), "_columns table wrong\n");
1265 ok( 0x1502 == get_columns_table_type(hdb, "Properties", 4 ), "_columns table wrong\n");
1266 ok( 0x1502 == get_columns_table_type(hdb, "Properties", 5 ), "_columns table wrong\n");
1267 ok( 0x1104 == get_columns_table_type(hdb, "Properties", 6 ), "_columns table wrong\n");
1268 ok( 0x1d00 == get_columns_table_type(hdb, "Properties", 7 ), "_columns table wrong\n");
1270 /* now try the names */
1271 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_NAMES );
1272 ok( rec, "failed to get column info record\n" );
1274 ok( check_record( rec, 1, "Property"), "wrong record type\n");
1275 ok( check_record( rec, 2, "Value"), "wrong record type\n");
1276 ok( check_record( rec, 3, "Intvalue"), "wrong record type\n");
1277 ok( check_record( rec, 4, "Integervalue"), "wrong record type\n");
1278 ok( check_record( rec, 5, "Shortvalue"), "wrong record type\n");
1279 ok( check_record( rec, 6, "Longvalue"), "wrong record type\n");
1280 ok( check_record( rec, 7, "Longcharvalue"), "wrong record type\n");
1282 MsiCloseHandle( rec );
1284 r = run_query( hdb, 0,
1285 "CREATE TABLE `Binary` "
1286 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
1287 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1289 /* check the column types */
1290 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_TYPES );
1291 ok( rec, "failed to get column info record\n" );
1293 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1294 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1296 MsiCloseHandle( rec );
1298 /* check the type in _Columns */
1299 ok( 0x3dff == get_columns_table_type(hdb, "Binary", 1 ), "_columns table wrong\n");
1300 ok( 0x1900 == get_columns_table_type(hdb, "Binary", 2 ), "_columns table wrong\n");
1302 /* now try the names */
1303 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_NAMES );
1304 ok( rec, "failed to get column info record\n" );
1306 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1307 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1308 MsiCloseHandle( rec );
1310 r = run_query( hdb, 0,
1311 "CREATE TABLE `UIText` "
1312 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1313 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1315 ok( 0x2d48 == get_columns_table_type(hdb, "UIText", 1 ), "_columns table wrong\n");
1316 ok( 0x1fff == get_columns_table_type(hdb, "UIText", 2 ), "_columns table wrong\n");
1318 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_NAMES );
1319 ok( rec, "failed to get column info record\n" );
1320 ok( check_record( rec, 1, "Key"), "wrong record type\n");
1321 ok( check_record( rec, 2, "Text"), "wrong record type\n");
1322 MsiCloseHandle( rec );
1324 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_TYPES );
1325 ok( rec, "failed to get column info record\n" );
1326 ok( check_record( rec, 1, "s72"), "wrong record type\n");
1327 ok( check_record( rec, 2, "L255"), "wrong record type\n");
1328 MsiCloseHandle( rec );
1330 MsiCloseHandle( hdb );
1333 static void test_msiexport(void)
1335 MSIHANDLE hdb = 0, hview = 0;
1336 UINT r;
1337 const char *query;
1338 char path[MAX_PATH];
1339 const char file[] = "phone.txt";
1340 HANDLE handle;
1341 char buffer[0x100];
1342 DWORD length;
1343 const char expected[] =
1344 "id\tname\tnumber\r\n"
1345 "I2\tS32\tS32\r\n"
1346 "phone\tid\r\n"
1347 "1\tAbe\t8675309\r\n";
1349 DeleteFile(msifile);
1351 /* just MsiOpenDatabase should not create a file */
1352 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1353 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1355 /* create a table */
1356 query = "CREATE TABLE `phone` ( "
1357 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1358 "PRIMARY KEY `id`)";
1359 r = MsiDatabaseOpenView(hdb, query, &hview);
1360 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1361 r = MsiViewExecute(hview, 0);
1362 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1363 r = MsiViewClose(hview);
1364 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1365 r = MsiCloseHandle(hview);
1366 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1368 /* insert a value into it */
1369 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
1370 "VALUES('1', 'Abe', '8675309')";
1371 r = MsiDatabaseOpenView(hdb, query, &hview);
1372 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1373 r = MsiViewExecute(hview, 0);
1374 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1375 r = MsiViewClose(hview);
1376 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1377 r = MsiCloseHandle(hview);
1378 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1380 GetCurrentDirectory(MAX_PATH, path);
1382 r = MsiDatabaseExport(hdb, "phone", path, file);
1383 ok(r == ERROR_SUCCESS, "MsiDatabaseExport failed\n");
1385 MsiCloseHandle(hdb);
1387 lstrcat(path, "\\");
1388 lstrcat(path, file);
1390 /* check the data that was written */
1391 length = 0;
1392 memset(buffer, 0, sizeof buffer);
1393 handle = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
1394 if (handle != INVALID_HANDLE_VALUE)
1396 ReadFile(handle, buffer, sizeof buffer, &length, NULL);
1397 CloseHandle(handle);
1398 DeleteFile(path);
1400 else
1401 ok(0, "failed to open file %s\n", path);
1403 ok( length == strlen(expected), "length of data wrong\n");
1404 ok( !lstrcmp(buffer, expected), "data doesn't match\n");
1405 DeleteFile(msifile);
1408 static void test_longstrings(void)
1410 const char insert_query[] =
1411 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1412 char *str;
1413 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
1414 DWORD len;
1415 UINT r;
1416 const DWORD STRING_LENGTH = 0x10005;
1418 DeleteFile(msifile);
1419 /* just MsiOpenDatabase should not create a file */
1420 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1421 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1423 /* create a table */
1424 r = try_query( hdb,
1425 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1426 ok(r == ERROR_SUCCESS, "query failed\n");
1428 /* try a insert a very long string */
1429 str = HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH+sizeof insert_query);
1430 len = strchr(insert_query, 'Z') - insert_query;
1431 strcpy(str, insert_query);
1432 memset(str+len, 'Z', STRING_LENGTH);
1433 strcpy(str+len+STRING_LENGTH, insert_query+len+1);
1434 r = try_query( hdb, str );
1435 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1437 HeapFree(GetProcessHeap(), 0, str);
1439 MsiDatabaseCommit(hdb);
1440 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
1441 MsiCloseHandle(hdb);
1443 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
1444 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1446 r = MsiDatabaseOpenView(hdb, "select * from `strings` where `id` = 1", &hview);
1447 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1449 r = MsiViewExecute(hview, 0);
1450 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1452 r = MsiViewFetch(hview, &hrec);
1453 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1455 MsiViewClose(hview);
1456 MsiCloseHandle(hview);
1458 r = MsiRecordGetString(hrec, 2, NULL, &len);
1459 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1460 ok(len == STRING_LENGTH, "string length wrong\n");
1462 MsiCloseHandle(hrec);
1463 MsiCloseHandle(hdb);
1464 DeleteFile(msifile);
1467 static void create_file_data(LPCSTR name, LPCSTR data, DWORD size)
1469 HANDLE file;
1470 DWORD written;
1472 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1473 if (file == INVALID_HANDLE_VALUE)
1474 return;
1476 WriteFile(file, data, strlen(data), &written, NULL);
1477 WriteFile(file, "\n", strlen("\n"), &written, NULL);
1479 if (size)
1481 SetFilePointer(file, size, NULL, FILE_BEGIN);
1482 SetEndOfFile(file);
1485 CloseHandle(file);
1488 #define create_file(name) create_file_data(name, name, 0)
1490 static void test_streamtable(void)
1492 MSIHANDLE hdb = 0, rec, view, hsi;
1493 char file[MAX_PATH];
1494 char buf[MAX_PATH];
1495 DWORD size;
1496 UINT r;
1498 hdb = create_db();
1499 ok( hdb, "failed to create db\n");
1501 r = run_query( hdb, 0,
1502 "CREATE TABLE `Properties` "
1503 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1504 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1506 r = run_query( hdb, 0,
1507 "INSERT INTO `Properties` "
1508 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1509 ok( r == ERROR_SUCCESS, "Failed to add to table\n" );
1511 r = MsiDatabaseCommit( hdb );
1512 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1514 MsiCloseHandle( hdb );
1516 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
1517 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1519 /* check the column types */
1520 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_TYPES );
1521 ok( rec, "failed to get column info record\n" );
1523 ok( check_record( rec, 1, "s62"), "wrong record type\n");
1524 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1526 MsiCloseHandle( rec );
1528 /* now try the names */
1529 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_NAMES );
1530 ok( rec, "failed to get column info record\n" );
1532 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1533 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1535 MsiCloseHandle( rec );
1537 r = MsiDatabaseOpenView( hdb,
1538 "SELECT * FROM `_Streams` WHERE `Name` = '\5SummaryInformation'", &view );
1539 ok( r == ERROR_SUCCESS, "Failed to open database view: %u\n", r );
1541 r = MsiViewExecute( view, 0 );
1542 ok( r == ERROR_SUCCESS, "Failed to execute view: %u\n", r );
1544 r = MsiViewFetch( view, &rec );
1545 ok( r == ERROR_NO_MORE_ITEMS, "Unexpected result: %u\n", r );
1547 MsiCloseHandle( rec );
1548 MsiViewClose( view );
1549 MsiCloseHandle( view );
1551 /* create a summary information stream */
1552 r = MsiGetSummaryInformationA( hdb, NULL, 1, &hsi );
1553 ok( r == ERROR_SUCCESS, "Failed to get summary information handle: %u\n", r );
1555 r = MsiSummaryInfoSetPropertyA( hsi, PID_SECURITY, VT_I4, 2, NULL, NULL );
1556 ok( r == ERROR_SUCCESS, "Failed to set property: %u\n", r );
1558 r = MsiSummaryInfoPersist( hsi );
1559 ok( r == ERROR_SUCCESS, "Failed to save summary information: %u\n", r );
1561 MsiCloseHandle( hsi );
1563 r = MsiDatabaseOpenView( hdb,
1564 "SELECT * FROM `_Streams` WHERE `Name` = '\5SummaryInformation'", &view );
1565 ok( r == ERROR_SUCCESS, "Failed to open database view: %u\n", r );
1567 r = MsiViewExecute( view, 0 );
1568 ok( r == ERROR_SUCCESS, "Failed to execute view: %u\n", r );
1570 r = MsiViewFetch( view, &rec );
1571 ok( r == ERROR_SUCCESS, "Unexpected result: %u\n", r );
1573 MsiCloseHandle( rec );
1574 MsiViewClose( view );
1575 MsiCloseHandle( view );
1577 /* insert a file into the _Streams table */
1578 create_file( "test.txt" );
1580 rec = MsiCreateRecord( 2 );
1581 MsiRecordSetString( rec, 1, "data" );
1583 r = MsiRecordSetStream( rec, 2, "test.txt" );
1584 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1586 DeleteFile("test.txt");
1588 r = MsiDatabaseOpenView( hdb,
1589 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view );
1590 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1592 r = MsiViewExecute( view, rec );
1593 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1595 MsiCloseHandle( rec );
1596 MsiViewClose( view );
1597 MsiCloseHandle( view );
1599 /* insert another one */
1600 create_file( "test1.txt" );
1602 rec = MsiCreateRecord( 2 );
1603 MsiRecordSetString( rec, 1, "data1" );
1605 r = MsiRecordSetStream( rec, 2, "test1.txt" );
1606 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1608 DeleteFile("test1.txt");
1610 r = MsiDatabaseOpenView( hdb,
1611 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view );
1612 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1614 r = MsiViewExecute( view, rec );
1615 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1617 MsiCloseHandle( rec );
1618 MsiViewClose( view );
1619 MsiCloseHandle( view );
1621 r = MsiDatabaseOpenView( hdb,
1622 "SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = 'data'", &view );
1623 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1625 r = MsiViewExecute( view, 0 );
1626 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1628 r = MsiViewFetch( view, &rec );
1629 ok( r == ERROR_SUCCESS, "Failed to fetch record: %d\n", r);
1631 size = MAX_PATH;
1632 r = MsiRecordGetString( rec, 1, file, &size );
1633 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1634 ok( !lstrcmp(file, "data"), "Expected 'data', got %s\n", file);
1636 size = MAX_PATH;
1637 memset(buf, 0, MAX_PATH);
1638 r = MsiRecordReadStream( rec, 2, buf, &size );
1639 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1640 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf);
1642 MsiCloseHandle( rec );
1643 MsiViewClose( view );
1644 MsiCloseHandle( view );
1646 r = MsiDatabaseOpenView( hdb,
1647 "SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = 'data1'", &view );
1648 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1650 r = MsiViewExecute( view, 0 );
1651 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1653 r = MsiViewFetch( view, &rec );
1654 ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1656 size = MAX_PATH;
1657 r = MsiRecordGetString( rec, 1, file, &size );
1658 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1659 ok( !lstrcmp(file, "data1"), "Expected 'data1', got %s\n", file);
1661 size = MAX_PATH;
1662 memset(buf, 0, MAX_PATH);
1663 r = MsiRecordReadStream( rec, 2, buf, &size );
1664 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1665 ok( !lstrcmp(buf, "test1.txt\n"), "Expected 'test1.txt\\n', got %s\n", buf);
1667 MsiCloseHandle( rec );
1668 MsiViewClose( view );
1669 MsiCloseHandle( view );
1671 /* perform an update */
1672 create_file( "test2.txt" );
1673 rec = MsiCreateRecord( 1 );
1675 r = MsiRecordSetStream( rec, 1, "test2.txt" );
1676 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1678 DeleteFile("test2.txt");
1680 r = MsiDatabaseOpenView( hdb,
1681 "UPDATE `_Streams` SET `Data` = ? WHERE `Name` = 'data1'", &view );
1682 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1684 r = MsiViewExecute( view, rec );
1685 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1687 MsiCloseHandle( rec );
1688 MsiViewClose( view );
1689 MsiCloseHandle( view );
1691 r = MsiDatabaseOpenView( hdb,
1692 "SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = 'data1'", &view );
1693 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1695 r = MsiViewExecute( view, 0 );
1696 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1698 r = MsiViewFetch( view, &rec );
1699 ok( r == ERROR_SUCCESS, "Failed to fetch record: %d\n", r);
1701 size = MAX_PATH;
1702 r = MsiRecordGetString( rec, 1, file, &size );
1703 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1704 ok( !lstrcmp(file, "data1"), "Expected 'data1', got %s\n", file);
1706 size = MAX_PATH;
1707 memset(buf, 0, MAX_PATH);
1708 r = MsiRecordReadStream( rec, 2, buf, &size );
1709 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1710 todo_wine ok( !lstrcmp(buf, "test2.txt\n"), "Expected 'test2.txt\\n', got %s\n", buf);
1712 MsiCloseHandle( rec );
1713 MsiViewClose( view );
1714 MsiCloseHandle( view );
1715 MsiCloseHandle( hdb );
1716 DeleteFile(msifile);
1719 static void test_binary(void)
1721 MSIHANDLE hdb = 0, rec;
1722 char file[MAX_PATH];
1723 char buf[MAX_PATH];
1724 DWORD size;
1725 LPCSTR query;
1726 UINT r;
1728 /* insert a file into the Binary table */
1729 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
1730 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1732 query = "CREATE TABLE `Binary` ( `Name` CHAR(72) NOT NULL, `ID` INT NOT NULL, `Data` OBJECT PRIMARY KEY `Name`, `ID`)";
1733 r = run_query( hdb, 0, query );
1734 ok( r == ERROR_SUCCESS, "Cannot create Binary table: %d\n", r );
1736 create_file( "test.txt" );
1737 rec = MsiCreateRecord( 1 );
1738 r = MsiRecordSetStream( rec, 1, "test.txt" );
1739 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1740 DeleteFile( "test.txt" );
1742 query = "INSERT INTO `Binary` ( `Name`, `ID`, `Data` ) VALUES ( 'filename1', 1, ? )";
1743 r = run_query( hdb, rec, query );
1744 ok( r == ERROR_SUCCESS, "Insert into Binary table failed: %d\n", r );
1746 r = MsiCloseHandle( rec );
1747 ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
1749 r = MsiDatabaseCommit( hdb );
1750 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1752 r = MsiCloseHandle( hdb );
1753 ok( r == ERROR_SUCCESS , "Failed to close database\n" );
1755 /* read file from the Stream table */
1756 r = MsiOpenDatabase( msifile, MSIDBOPEN_READONLY, &hdb );
1757 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1759 query = "SELECT * FROM `_Streams`";
1760 r = do_query( hdb, query, &rec );
1761 ok( r == ERROR_SUCCESS, "SELECT query failed: %d\n", r );
1763 size = MAX_PATH;
1764 r = MsiRecordGetString( rec, 1, file, &size );
1765 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r );
1766 ok( !lstrcmp(file, "Binary.filename1.1"), "Expected 'Binary.filename1.1', got %s\n", file );
1768 size = MAX_PATH;
1769 memset( buf, 0, MAX_PATH );
1770 r = MsiRecordReadStream( rec, 2, buf, &size );
1771 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r );
1772 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf );
1774 r = MsiCloseHandle( rec );
1775 ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
1777 /* read file from the Binary table */
1778 query = "SELECT * FROM `Binary`";
1779 r = do_query( hdb, query, &rec );
1780 ok( r == ERROR_SUCCESS, "SELECT query failed: %d\n", r );
1782 size = MAX_PATH;
1783 r = MsiRecordGetString( rec, 1, file, &size );
1784 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r );
1785 ok( !lstrcmp(file, "filename1"), "Expected 'filename1', got %s\n", file );
1787 size = MAX_PATH;
1788 memset( buf, 0, MAX_PATH );
1789 r = MsiRecordReadStream( rec, 3, buf, &size );
1790 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r );
1791 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf );
1793 r = MsiCloseHandle( rec );
1794 ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
1796 r = MsiCloseHandle( hdb );
1797 ok( r == ERROR_SUCCESS , "Failed to close database\n" );
1799 DeleteFile( msifile );
1802 static void test_where_not_in_selected(void)
1804 MSIHANDLE hdb = 0, rec, view;
1805 LPCSTR query;
1806 UINT r;
1808 hdb = create_db();
1809 ok( hdb, "failed to create db\n");
1811 r = run_query(hdb, 0,
1812 "CREATE TABLE `IESTable` ("
1813 "`Action` CHAR(64), "
1814 "`Condition` CHAR(64), "
1815 "`Sequence` LONG PRIMARY KEY `Sequence`)");
1816 ok( r == S_OK, "Cannot create IESTable table: %d\n", r);
1818 r = run_query(hdb, 0,
1819 "CREATE TABLE `CATable` ("
1820 "`Action` CHAR(64), "
1821 "`Type` LONG PRIMARY KEY `Type`)");
1822 ok( r == S_OK, "Cannot create CATable table: %d\n", r);
1824 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1825 "( `Action`, `Condition`, `Sequence`) "
1826 "VALUES ( 'clean', 'cond4', 4)");
1827 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1829 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1830 "( `Action`, `Condition`, `Sequence`) "
1831 "VALUES ( 'depends', 'cond1', 1)");
1832 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1834 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1835 "( `Action`, `Condition`, `Sequence`) "
1836 "VALUES ( 'build', 'cond2', 2)");
1837 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1839 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1840 "( `Action`, `Condition`, `Sequence`) "
1841 "VALUES ( 'build2', 'cond6', 6)");
1842 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1844 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1845 "( `Action`, `Condition`, `Sequence`) "
1846 "VALUES ( 'build', 'cond3', 3)");
1847 ok(r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1849 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1850 "( `Action`, `Type` ) "
1851 "VALUES ( 'build', 32)");
1852 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1854 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1855 "( `Action`, `Type` ) "
1856 "VALUES ( 'depends', 64)");
1857 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1859 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1860 "( `Action`, `Type` ) "
1861 "VALUES ( 'clean', 63)");
1862 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1864 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1865 "( `Action`, `Type` ) "
1866 "VALUES ( 'build2', 34)");
1867 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1868 query = "Select IESTable.Condition from CATable, IESTable where "
1869 "CATable.Action = IESTable.Action and CATable.Type = 32";
1870 r = MsiDatabaseOpenView(hdb, query, &view);
1871 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1873 r = MsiViewExecute(view, 0);
1874 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1876 r = MsiViewFetch(view, &rec);
1877 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1879 ok( check_record( rec, 1, "cond2"), "wrong condition\n");
1881 MsiCloseHandle( rec );
1882 r = MsiViewFetch(view, &rec);
1883 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1885 ok( check_record( rec, 1, "cond3"), "wrong condition\n");
1887 MsiCloseHandle( rec );
1888 MsiViewClose(view);
1889 MsiCloseHandle(view);
1891 MsiCloseHandle( hdb );
1892 DeleteFile(msifile);
1897 static void test_where(void)
1899 MSIHANDLE hdb = 0, rec, view;
1900 LPCSTR query;
1901 UINT r;
1902 DWORD size;
1903 CHAR buf[MAX_PATH];
1904 UINT count;
1906 hdb = create_db();
1907 ok( hdb, "failed to create db\n");
1909 r = run_query( hdb, 0,
1910 "CREATE TABLE `Media` ("
1911 "`DiskId` SHORT NOT NULL, "
1912 "`LastSequence` LONG, "
1913 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1914 "`Cabinet` CHAR(255), "
1915 "`VolumeLabel` CHAR(32), "
1916 "`Source` CHAR(72) "
1917 "PRIMARY KEY `DiskId`)" );
1918 ok( r == S_OK, "cannot create Media table: %d\n", r );
1920 r = run_query( hdb, 0, "INSERT INTO `Media` "
1921 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1922 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1923 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1925 r = run_query( hdb, 0, "INSERT INTO `Media` "
1926 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1927 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1928 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1930 r = run_query( hdb, 0, "INSERT INTO `Media` "
1931 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1932 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1933 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1935 query = "SELECT * FROM `Media`";
1936 r = do_query(hdb, query, &rec);
1937 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1938 ok( check_record( rec, 4, "zero.cab"), "wrong cabinet\n");
1939 MsiCloseHandle( rec );
1941 query = "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1942 r = do_query(hdb, query, &rec);
1943 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1944 ok( check_record( rec, 4, "one.cab"), "wrong cabinet\n");
1946 r = MsiRecordGetInteger(rec, 1);
1947 ok( 2 == r, "field wrong\n");
1948 r = MsiRecordGetInteger(rec, 2);
1949 ok( 1 == r, "field wrong\n");
1950 MsiCloseHandle( rec );
1952 query = "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1953 r = MsiDatabaseOpenView(hdb, query, &view);
1954 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1956 r = MsiViewExecute(view, 0);
1957 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1959 r = MsiViewFetch(view, &rec);
1960 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1962 count = MsiRecordGetFieldCount( rec );
1963 ok( count == 1, "Expected 1 record fields, got %d\n", count );
1965 size = MAX_PATH;
1966 r = MsiRecordGetString( rec, 1, buf, &size );
1967 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1968 ok( !lstrcmp( buf, "2" ),
1969 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf );
1970 MsiCloseHandle( rec );
1972 r = MsiViewFetch(view, &rec);
1973 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1975 size = MAX_PATH;
1976 r = MsiRecordGetString( rec, 1, buf, &size );
1977 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1978 ok( !lstrcmp( buf, "3" ),
1979 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf );
1980 MsiCloseHandle( rec );
1982 r = MsiViewFetch(view, &rec);
1983 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
1985 MsiViewClose(view);
1986 MsiCloseHandle(view);
1988 MsiCloseHandle( rec );
1990 rec = 0;
1991 query = "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1992 r = do_query(hdb, query, &rec);
1993 ok( r == ERROR_SUCCESS, "query failed: %d\n", r );
1994 MsiCloseHandle( rec );
1996 rec = 0;
1997 query = "SELECT * FROM `Media` WHERE `DiskPrompt` < 'Cabinet'";
1998 r = do_query(hdb, query, &rec);
1999 ok( r == ERROR_BAD_QUERY_SYNTAX, "query failed: %d\n", r );
2000 MsiCloseHandle( rec );
2002 rec = 0;
2003 query = "SELECT * FROM `Media` WHERE `DiskPrompt` > 'Cabinet'";
2004 r = do_query(hdb, query, &rec);
2005 ok( r == ERROR_BAD_QUERY_SYNTAX, "query failed: %d\n", r );
2006 MsiCloseHandle( rec );
2008 rec = 0;
2009 query = "SELECT * FROM `Media` WHERE `DiskPrompt` <> 'Cabinet'";
2010 r = do_query(hdb, query, &rec);
2011 ok( r == ERROR_SUCCESS, "query failed: %d\n", r );
2012 MsiCloseHandle( rec );
2014 rec = 0;
2015 query = "SELECT * FROM `Media` WHERE `DiskPrompt` = 'Cabinet'";
2016 r = do_query(hdb, query, &rec);
2017 ok( r == ERROR_NO_MORE_ITEMS, "query failed: %d\n", r );
2018 MsiCloseHandle( rec );
2020 rec = MsiCreateRecord(1);
2021 MsiRecordSetString(rec, 1, "");
2023 query = "SELECT * FROM `Media` WHERE `DiskPrompt` = ?";
2024 r = MsiDatabaseOpenView(hdb, query, &view);
2025 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2026 r = MsiViewExecute(view, rec);
2027 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2029 MsiCloseHandle(rec);
2031 r = MsiViewFetch(view, &rec);
2032 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2034 MsiCloseHandle(rec);
2035 MsiViewClose(view);
2036 MsiCloseHandle(view);
2038 MsiCloseHandle( hdb );
2039 DeleteFile(msifile);
2042 static CHAR CURR_DIR[MAX_PATH];
2044 static const CHAR test_data[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
2045 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
2046 "TestTable\tFirstPrimaryColumn\n"
2047 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
2049 static const CHAR two_primary[] = "PrimaryOne\tPrimaryTwo\n"
2050 "s255\ts255\n"
2051 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
2052 "papaya\tleaf\n"
2053 "papaya\tflower\n";
2055 static const CHAR endlines1[] = "A\tB\tC\tD\tE\tF\r\n"
2056 "s72\ts72\ts72\ts72\ts72\ts72\n"
2057 "Table\tA\r\n"
2058 "a\tb\tc\td\te\tf\n"
2059 "g\th\ti\t\rj\tk\tl\r\n";
2061 static const CHAR endlines2[] = "A\tB\tC\tD\tE\tF\r"
2062 "s72\ts72\ts72\ts72\ts72\ts72\n"
2063 "Table2\tA\r\n"
2064 "a\tb\tc\td\te\tf\n"
2065 "g\th\ti\tj\tk\tl\r\n";
2067 static const CHAR suminfo[] = "PropertyId\tValue\n"
2068 "i2\tl255\n"
2069 "_SummaryInformation\tPropertyId\n"
2070 "1\t1252\n"
2071 "2\tInstaller Database\n"
2072 "3\tInstaller description\n"
2073 "4\tWineHQ\n"
2074 "5\tInstaller\n"
2075 "6\tInstaller comments\n"
2076 "7\tIntel;1033,2057\n"
2077 "9\t{12345678-1234-1234-1234-123456789012}\n"
2078 "12\t2009/04/12 15:46:11\n"
2079 "13\t2009/04/12 15:46:11\n"
2080 "14\t200\n"
2081 "15\t2\n"
2082 "18\tVim\n"
2083 "19\t2\n";
2085 static void write_file(const CHAR *filename, const char *data, int data_size)
2087 DWORD size;
2089 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
2090 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2092 WriteFile(hf, data, data_size, &size, NULL);
2093 CloseHandle(hf);
2096 static UINT add_table_to_db(MSIHANDLE hdb, LPCSTR table_data)
2098 UINT r;
2100 write_file("temp_file", table_data, (lstrlen(table_data) - 1) * sizeof(char));
2101 r = MsiDatabaseImportA(hdb, CURR_DIR, "temp_file");
2102 DeleteFileA("temp_file");
2104 return r;
2107 static void test_suminfo_import(void)
2109 MSIHANDLE hdb, hsi, view = 0;
2110 LPCSTR query;
2111 UINT r, count, size, type;
2112 char str_value[50];
2113 INT int_value;
2114 FILETIME ft_value;
2116 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
2118 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
2119 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2121 r = add_table_to_db(hdb, suminfo);
2122 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2124 /* _SummaryInformation is not imported as a regular table... */
2126 query = "SELECT * FROM `_SummaryInformation`";
2127 r = MsiDatabaseOpenViewA(hdb, query, &view);
2128 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %u\n", r);
2129 MsiCloseHandle(view);
2131 /* ...its data is added to the special summary information stream */
2133 r = MsiGetSummaryInformationA(hdb, NULL, 0, &hsi);
2134 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2136 r = MsiSummaryInfoGetPropertyCount(hsi, &count);
2137 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2138 ok(count == 14, "Expected 14, got %u\n", count);
2140 r = MsiSummaryInfoGetPropertyA(hsi, PID_CODEPAGE, &type, &int_value, NULL, NULL, NULL);
2141 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2142 ok(type == VT_I2, "Expected VT_I2, got %u\n", type);
2143 ok(int_value == 1252, "Expected 1252, got %d\n", int_value);
2145 size = sizeof(str_value);
2146 r = MsiSummaryInfoGetPropertyA(hsi, PID_TITLE, &type, NULL, NULL, str_value, &size);
2147 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2148 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2149 ok(size == 18, "Expected 18, got %u\n", size);
2150 ok(!strcmp(str_value, "Installer Database"),
2151 "Expected \"Installer Database\", got %s\n", str_value);
2153 size = sizeof(str_value);
2154 r = MsiSummaryInfoGetPropertyA(hsi, PID_SUBJECT, &type, NULL, NULL, str_value, &size);
2155 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2156 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2157 ok(!strcmp(str_value, "Installer description"),
2158 "Expected \"Installer description\", got %s\n", str_value);
2160 size = sizeof(str_value);
2161 r = MsiSummaryInfoGetPropertyA(hsi, PID_AUTHOR, &type, NULL, NULL, str_value, &size);
2162 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2163 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2164 ok(!strcmp(str_value, "WineHQ"),
2165 "Expected \"WineHQ\", got %s\n", str_value);
2167 size = sizeof(str_value);
2168 r = MsiSummaryInfoGetPropertyA(hsi, PID_KEYWORDS, &type, NULL, NULL, str_value, &size);
2169 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2170 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2171 ok(!strcmp(str_value, "Installer"),
2172 "Expected \"Installer\", got %s\n", str_value);
2174 size = sizeof(str_value);
2175 r = MsiSummaryInfoGetPropertyA(hsi, PID_COMMENTS, &type, NULL, NULL, str_value, &size);
2176 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2177 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2178 ok(!strcmp(str_value, "Installer comments"),
2179 "Expected \"Installer comments\", got %s\n", str_value);
2181 size = sizeof(str_value);
2182 r = MsiSummaryInfoGetPropertyA(hsi, PID_TEMPLATE, &type, NULL, NULL, str_value, &size);
2183 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2184 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2185 ok(!strcmp(str_value, "Intel;1033,2057"),
2186 "Expected \"Intel;1033,2057\", got %s\n", str_value);
2188 size = sizeof(str_value);
2189 r = MsiSummaryInfoGetPropertyA(hsi, PID_REVNUMBER, &type, NULL, NULL, str_value, &size);
2190 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2191 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2192 ok(!strcmp(str_value, "{12345678-1234-1234-1234-123456789012}"),
2193 "Expected \"{12345678-1234-1234-1234-123456789012}\", got %s\n", str_value);
2195 r = MsiSummaryInfoGetPropertyA(hsi, PID_CREATE_DTM, &type, NULL, &ft_value, NULL, NULL);
2196 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2197 ok(type == VT_FILETIME, "Expected VT_FILETIME, got %u\n", type);
2199 r = MsiSummaryInfoGetPropertyA(hsi, PID_LASTSAVE_DTM, &type, NULL, &ft_value, NULL, NULL);
2200 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2201 ok(type == VT_FILETIME, "Expected VT_FILETIME, got %u\n", type);
2203 r = MsiSummaryInfoGetPropertyA(hsi, PID_PAGECOUNT, &type, &int_value, NULL, NULL, NULL);
2204 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2205 ok(type == VT_I4, "Expected VT_I4, got %u\n", type);
2206 ok(int_value == 200, "Expected 200, got %d\n", int_value);
2208 r = MsiSummaryInfoGetPropertyA(hsi, PID_WORDCOUNT, &type, &int_value, NULL, NULL, NULL);
2209 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2210 ok(type == VT_I4, "Expected VT_I4, got %u\n", type);
2211 ok(int_value == 2, "Expected 2, got %d\n", int_value);
2213 r = MsiSummaryInfoGetPropertyA(hsi, PID_SECURITY, &type, &int_value, NULL, NULL, NULL);
2214 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2215 ok(type == VT_I4, "Expected VT_I4, got %u\n", type);
2216 ok(int_value == 2, "Expected 2, got %d\n", int_value);
2218 size = sizeof(str_value);
2219 r = MsiSummaryInfoGetPropertyA(hsi, PID_APPNAME, &type, NULL, NULL, str_value, &size);
2220 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2221 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2222 ok(!strcmp(str_value, "Vim"), "Expected \"Vim\", got %s\n", str_value);
2224 MsiCloseHandle(hsi);
2225 MsiCloseHandle(hdb);
2226 DeleteFileA(msifile);
2229 static void test_msiimport(void)
2231 MSIHANDLE hdb, view, rec;
2232 LPCSTR query;
2233 UINT r, count;
2234 signed int i;
2236 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
2238 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
2239 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2241 r = add_table_to_db(hdb, test_data);
2242 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2244 r = add_table_to_db(hdb, two_primary);
2245 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2247 r = add_table_to_db(hdb, endlines1);
2248 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2250 r = add_table_to_db(hdb, endlines2);
2251 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
2253 query = "SELECT * FROM `TestTable`";
2254 r = MsiDatabaseOpenView(hdb, query, &view);
2255 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2257 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
2258 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2259 count = MsiRecordGetFieldCount(rec);
2260 ok(count == 9, "Expected 9, got %d\n", count);
2261 ok(check_record(rec, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
2262 ok(check_record(rec, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
2263 ok(check_record(rec, 3, "ShortInt"), "Expected ShortInt\n");
2264 ok(check_record(rec, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
2265 ok(check_record(rec, 5, "LongInt"), "Expected LongInt\n");
2266 ok(check_record(rec, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
2267 ok(check_record(rec, 7, "String"), "Expected String\n");
2268 ok(check_record(rec, 8, "LocalizableString"), "Expected LocalizableString\n");
2269 ok(check_record(rec, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
2270 MsiCloseHandle(rec);
2272 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2273 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2274 count = MsiRecordGetFieldCount(rec);
2275 ok(count == 9, "Expected 9, got %d\n", count);
2276 ok(check_record(rec, 1, "s255"), "Expected s255\n");
2277 ok(check_record(rec, 2, "i2"), "Expected i2\n");
2278 ok(check_record(rec, 3, "i2"), "Expected i2\n");
2279 ok(check_record(rec, 4, "I2"), "Expected I2\n");
2280 ok(check_record(rec, 5, "i4"), "Expected i4\n");
2281 ok(check_record(rec, 6, "I4"), "Expected I4\n");
2282 ok(check_record(rec, 7, "S255"), "Expected S255\n");
2283 ok(check_record(rec, 8, "S0"), "Expected S0\n");
2284 ok(check_record(rec, 9, "s0"), "Expected s0\n");
2285 MsiCloseHandle(rec);
2287 query = "SELECT * FROM `TestTable`";
2288 r = do_query(hdb, query, &rec);
2289 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2290 ok(check_record(rec, 1, "stringage"), "Expected 'stringage'\n");
2291 ok(check_record(rec, 7, "another string"), "Expected 'another string'\n");
2292 ok(check_record(rec, 8, "localizable"), "Expected 'localizable'\n");
2293 ok(check_record(rec, 9, "duh"), "Expected 'duh'\n");
2295 i = MsiRecordGetInteger(rec, 2);
2296 ok(i == 5, "Expected 5, got %d\n", i);
2298 i = MsiRecordGetInteger(rec, 3);
2299 ok(i == 2, "Expected 2, got %d\n", i);
2301 i = MsiRecordGetInteger(rec, 4);
2302 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
2304 i = MsiRecordGetInteger(rec, 5);
2305 ok(i == 2147483640, "Expected 2147483640, got %d\n", i);
2307 i = MsiRecordGetInteger(rec, 6);
2308 ok(i == -2147483640, "Expected -2147483640, got %d\n", i);
2310 MsiCloseHandle(rec);
2311 MsiViewClose(view);
2312 MsiCloseHandle(view);
2314 query = "SELECT * FROM `TwoPrimary`";
2315 r = MsiDatabaseOpenView(hdb, query, &view);
2316 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2318 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
2319 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2320 count = MsiRecordGetFieldCount(rec);
2321 ok(count == 2, "Expected 2, got %d\n", count);
2322 ok(check_record(rec, 1, "PrimaryOne"), "Expected PrimaryOne\n");
2323 ok(check_record(rec, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
2325 MsiCloseHandle(rec);
2327 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2328 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2329 count = MsiRecordGetFieldCount(rec);
2330 ok(count == 2, "Expected 2, got %d\n", count);
2331 ok(check_record(rec, 1, "s255"), "Expected s255\n");
2332 ok(check_record(rec, 2, "s255"), "Expected s255\n");
2333 MsiCloseHandle(rec);
2335 r = MsiViewExecute(view, 0);
2336 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2338 r = MsiViewFetch(view, &rec);
2339 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2341 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
2342 ok(check_record(rec, 2, "leaf"), "Expected 'leaf'\n");
2344 MsiCloseHandle(rec);
2346 r = MsiViewFetch(view, &rec);
2347 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2349 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
2350 ok(check_record(rec, 2, "flower"), "Expected 'flower'\n");
2352 MsiCloseHandle(rec);
2354 r = MsiViewFetch(view, &rec);
2355 ok(r == ERROR_NO_MORE_ITEMS,
2356 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
2358 r = MsiViewClose(view);
2359 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2361 MsiCloseHandle(view);
2363 query = "SELECT * FROM `Table`";
2364 r = MsiDatabaseOpenView(hdb, query, &view);
2365 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2367 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
2368 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2369 count = MsiRecordGetFieldCount(rec);
2370 ok(count == 6, "Expected 6, got %d\n", count);
2371 ok(check_record(rec, 1, "A"), "Expected A\n");
2372 ok(check_record(rec, 2, "B"), "Expected B\n");
2373 ok(check_record(rec, 3, "C"), "Expected C\n");
2374 ok(check_record(rec, 4, "D"), "Expected D\n");
2375 ok(check_record(rec, 5, "E"), "Expected E\n");
2376 ok(check_record(rec, 6, "F"), "Expected F\n");
2377 MsiCloseHandle(rec);
2379 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2380 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2381 count = MsiRecordGetFieldCount(rec);
2382 ok(count == 6, "Expected 6, got %d\n", count);
2383 ok(check_record(rec, 1, "s72"), "Expected s72\n");
2384 ok(check_record(rec, 2, "s72"), "Expected s72\n");
2385 ok(check_record(rec, 3, "s72"), "Expected s72\n");
2386 ok(check_record(rec, 4, "s72"), "Expected s72\n");
2387 ok(check_record(rec, 5, "s72"), "Expected s72\n");
2388 ok(check_record(rec, 6, "s72"), "Expected s72\n");
2389 MsiCloseHandle(rec);
2391 MsiViewClose(view);
2392 MsiCloseHandle(view);
2394 query = "SELECT * FROM `Table`";
2395 r = MsiDatabaseOpenView(hdb, query, &view);
2396 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2398 r = MsiViewExecute(view, 0);
2399 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2401 r = MsiViewFetch(view, &rec);
2402 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2403 ok(check_record(rec, 1, "a"), "Expected 'a'\n");
2404 ok(check_record(rec, 2, "b"), "Expected 'b'\n");
2405 ok(check_record(rec, 3, "c"), "Expected 'c'\n");
2406 ok(check_record(rec, 4, "d"), "Expected 'd'\n");
2407 ok(check_record(rec, 5, "e"), "Expected 'e'\n");
2408 ok(check_record(rec, 6, "f"), "Expected 'f'\n");
2410 MsiCloseHandle(rec);
2412 r = MsiViewFetch(view, &rec);
2413 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2414 ok(check_record(rec, 1, "g"), "Expected 'g'\n");
2415 ok(check_record(rec, 2, "h"), "Expected 'h'\n");
2416 ok(check_record(rec, 3, "i"), "Expected 'i'\n");
2417 ok(check_record(rec, 4, "j"), "Expected 'j'\n");
2418 ok(check_record(rec, 5, "k"), "Expected 'k'\n");
2419 ok(check_record(rec, 6, "l"), "Expected 'l'\n");
2421 MsiCloseHandle(rec);
2423 r = MsiViewFetch(view, &rec);
2424 ok(r == ERROR_NO_MORE_ITEMS,
2425 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
2427 MsiViewClose(view);
2428 MsiCloseHandle(view);
2429 MsiCloseHandle(hdb);
2430 DeleteFileA(msifile);
2433 static const CHAR bin_import_dat[] = "Name\tData\r\n"
2434 "s72\tV0\r\n"
2435 "Binary\tName\r\n"
2436 "filename1\tfilename1.ibd\r\n";
2438 static void test_binary_import(void)
2440 MSIHANDLE hdb = 0, rec;
2441 char file[MAX_PATH];
2442 char buf[MAX_PATH];
2443 char path[MAX_PATH];
2444 DWORD size;
2445 LPCSTR query;
2446 UINT r;
2448 /* create files to import */
2449 write_file("bin_import.idt", bin_import_dat,
2450 (sizeof(bin_import_dat) - 1) * sizeof(char));
2451 CreateDirectory("bin_import", NULL);
2452 create_file_data("bin_import/filename1.ibd", "just some words", 15);
2454 /* import files into database */
2455 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
2456 ok( r == ERROR_SUCCESS , "Failed to open database\n");
2458 GetCurrentDirectory(MAX_PATH, path);
2459 r = MsiDatabaseImport(hdb, path, "bin_import.idt");
2460 ok(r == ERROR_SUCCESS , "Failed to import Binary table\n");
2462 /* read file from the Binary table */
2463 query = "SELECT * FROM `Binary`";
2464 r = do_query(hdb, query, &rec);
2465 ok(r == ERROR_SUCCESS, "SELECT query failed: %d\n", r);
2467 size = MAX_PATH;
2468 r = MsiRecordGetString(rec, 1, file, &size);
2469 ok(r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
2470 ok(!lstrcmp(file, "filename1"), "Expected 'filename1', got %s\n", file);
2472 size = MAX_PATH;
2473 memset(buf, 0, MAX_PATH);
2474 r = MsiRecordReadStream(rec, 2, buf, &size);
2475 ok(r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
2476 ok(!lstrcmp(buf, "just some words"),
2477 "Expected 'just some words', got %s\n", buf);
2479 r = MsiCloseHandle(rec);
2480 ok(r == ERROR_SUCCESS , "Failed to close record handle\n");
2482 r = MsiCloseHandle(hdb);
2483 ok(r == ERROR_SUCCESS , "Failed to close database\n");
2485 DeleteFile("bin_import/filename1.ibd");
2486 RemoveDirectory("bin_import");
2487 DeleteFile("bin_import.idt");
2490 static void test_markers(void)
2492 MSIHANDLE hdb, rec;
2493 LPCSTR query;
2494 UINT r;
2496 hdb = create_db();
2497 ok( hdb, "failed to create db\n");
2499 rec = MsiCreateRecord(3);
2500 MsiRecordSetString(rec, 1, "Table");
2501 MsiRecordSetString(rec, 2, "Apples");
2502 MsiRecordSetString(rec, 3, "Oranges");
2504 /* try a legit create */
2505 query = "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2506 r = run_query(hdb, 0, query);
2507 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2508 MsiCloseHandle(rec);
2510 /* try table name as marker */
2511 rec = MsiCreateRecord(1);
2512 MsiRecordSetString(rec, 1, "Fable");
2513 query = "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2514 r = run_query(hdb, rec, query);
2515 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2517 /* verify that we just created a table called '?', not 'Fable' */
2518 r = try_query(hdb, "SELECT * from `Fable`");
2519 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2521 r = try_query(hdb, "SELECT * from `?`");
2522 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2524 /* try table name as marker without backticks */
2525 MsiRecordSetString(rec, 1, "Mable");
2526 query = "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2527 r = run_query(hdb, rec, query);
2528 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2530 /* try one column name as marker */
2531 MsiRecordSetString(rec, 1, "One");
2532 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2533 r = run_query(hdb, rec, query);
2534 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2535 MsiCloseHandle(rec);
2537 /* try column names as markers */
2538 rec = MsiCreateRecord(2);
2539 MsiRecordSetString(rec, 1, "One");
2540 MsiRecordSetString(rec, 2, "Two");
2541 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
2542 r = run_query(hdb, rec, query);
2543 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2544 MsiCloseHandle(rec);
2546 /* try names with backticks */
2547 rec = MsiCreateRecord(3);
2548 MsiRecordSetString(rec, 1, "One");
2549 MsiRecordSetString(rec, 2, "Two");
2550 MsiRecordSetString(rec, 3, "One");
2551 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
2552 r = run_query(hdb, rec, query);
2553 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2555 /* try names with backticks, minus definitions */
2556 query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
2557 r = run_query(hdb, rec, query);
2558 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2560 /* try names without backticks */
2561 query = "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
2562 r = run_query(hdb, rec, query);
2563 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2564 MsiCloseHandle(rec);
2566 /* try one long marker */
2567 rec = MsiCreateRecord(1);
2568 MsiRecordSetString(rec, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
2569 query = "CREATE TABLE `Mable` ( ? )";
2570 r = run_query(hdb, rec, query);
2571 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2572 MsiCloseHandle(rec);
2574 /* try all names as markers */
2575 rec = MsiCreateRecord(4);
2576 MsiRecordSetString(rec, 1, "Mable");
2577 MsiRecordSetString(rec, 2, "One");
2578 MsiRecordSetString(rec, 3, "Two");
2579 MsiRecordSetString(rec, 4, "One");
2580 query = "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
2581 r = run_query(hdb, rec, query);
2582 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2583 MsiCloseHandle(rec);
2585 /* try a legit insert */
2586 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
2587 r = run_query(hdb, 0, query);
2588 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2590 r = try_query(hdb, "SELECT * from `Table`");
2591 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2593 /* try values as markers */
2594 rec = MsiCreateRecord(2);
2595 MsiRecordSetInteger(rec, 1, 4);
2596 MsiRecordSetString(rec, 2, "hi");
2597 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2598 r = run_query(hdb, rec, query);
2599 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2600 MsiCloseHandle(rec);
2602 /* try column names and values as markers */
2603 rec = MsiCreateRecord(4);
2604 MsiRecordSetString(rec, 1, "One");
2605 MsiRecordSetString(rec, 2, "Two");
2606 MsiRecordSetInteger(rec, 3, 5);
2607 MsiRecordSetString(rec, 4, "hi");
2608 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
2609 r = run_query(hdb, rec, query);
2610 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2611 MsiCloseHandle(rec);
2613 /* try column names as markers */
2614 rec = MsiCreateRecord(2);
2615 MsiRecordSetString(rec, 1, "One");
2616 MsiRecordSetString(rec, 2, "Two");
2617 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
2618 r = run_query(hdb, rec, query);
2619 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2620 MsiCloseHandle(rec);
2622 /* try table name as a marker */
2623 rec = MsiCreateRecord(1);
2624 MsiRecordSetString(rec, 1, "Table");
2625 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
2626 r = run_query(hdb, rec, query);
2627 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2628 MsiCloseHandle(rec);
2630 /* try table name and values as markers */
2631 rec = MsiCreateRecord(3);
2632 MsiRecordSetString(rec, 1, "Table");
2633 MsiRecordSetInteger(rec, 2, 10);
2634 MsiRecordSetString(rec, 3, "haha");
2635 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
2636 r = run_query(hdb, rec, query);
2637 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
2638 MsiCloseHandle(rec);
2640 /* try all markers */
2641 rec = MsiCreateRecord(5);
2642 MsiRecordSetString(rec, 1, "Table");
2643 MsiRecordSetString(rec, 1, "One");
2644 MsiRecordSetString(rec, 1, "Two");
2645 MsiRecordSetInteger(rec, 2, 10);
2646 MsiRecordSetString(rec, 3, "haha");
2647 query = "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
2648 r = run_query(hdb, rec, query);
2649 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2650 MsiCloseHandle(rec);
2652 /* insert an integer as a string */
2653 rec = MsiCreateRecord(2);
2654 MsiRecordSetString(rec, 1, "11");
2655 MsiRecordSetString(rec, 2, "hi");
2656 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2657 r = run_query(hdb, rec, query);
2658 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2659 MsiCloseHandle(rec);
2661 /* leave off the '' for the string */
2662 rec = MsiCreateRecord(2);
2663 MsiRecordSetInteger(rec, 1, 12);
2664 MsiRecordSetString(rec, 2, "hi");
2665 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
2666 r = run_query(hdb, rec, query);
2667 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2668 MsiCloseHandle(rec);
2670 MsiCloseHandle(hdb);
2671 DeleteFileA(msifile);
2674 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
2675 static void test_handle_limit(void)
2677 int i;
2678 MSIHANDLE hdb;
2679 MSIHANDLE hviews[MY_NVIEWS];
2680 UINT r;
2682 /* create an empty db */
2683 hdb = create_db();
2684 ok( hdb, "failed to create db\n");
2686 memset(hviews, 0, sizeof(hviews));
2688 for (i=0; i<MY_NVIEWS; i++) {
2689 static char szQueryBuf[256] = "SELECT * from `_Tables`";
2690 hviews[i] = 0xdeadbeeb;
2691 r = MsiDatabaseOpenView(hdb, szQueryBuf, &hviews[i]);
2692 if( r != ERROR_SUCCESS || hviews[i] == 0xdeadbeeb ||
2693 hviews[i] == 0 || (i && (hviews[i] == hviews[i-1])))
2694 break;
2697 ok( i == MY_NVIEWS, "problem opening views\n");
2699 for (i=0; i<MY_NVIEWS; i++) {
2700 if (hviews[i] != 0 && hviews[i] != 0xdeadbeeb) {
2701 MsiViewClose(hviews[i]);
2702 r = MsiCloseHandle(hviews[i]);
2703 if (r != ERROR_SUCCESS)
2704 break;
2708 ok( i == MY_NVIEWS, "problem closing views\n");
2710 r = MsiCloseHandle(hdb);
2711 ok( r == ERROR_SUCCESS, "failed to close database\n");
2714 static void generate_transform(void)
2716 MSIHANDLE hdb1, hdb2, hrec;
2717 LPCSTR query;
2718 UINT r;
2720 /* start with two identical databases */
2721 CopyFile(msifile2, msifile, FALSE);
2723 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb1 );
2724 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2726 r = MsiDatabaseCommit( hdb1 );
2727 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
2729 r = MsiOpenDatabase(msifile2, MSIDBOPEN_READONLY, &hdb2 );
2730 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2732 /* the transform between two identical database should be empty */
2733 r = MsiDatabaseGenerateTransform(hdb1, hdb2, NULL, 0, 0);
2734 todo_wine {
2735 ok( r == ERROR_NO_DATA, "return code %d, should be ERROR_NO_DATA\n", r );
2738 query = "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
2739 r = run_query(hdb1, 0, query);
2740 ok(r == ERROR_SUCCESS, "failed to add table\n");
2742 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
2743 r = run_query(hdb1, 0, query);
2744 ok(r == ERROR_SUCCESS, "failed to add row 1\n");
2746 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
2747 r = run_query(hdb1, 0, query);
2748 ok(r == ERROR_SUCCESS, "failed to add row 2\n");
2750 query = "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
2751 r = run_query(hdb1, 0, query);
2752 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2754 query = "DELETE FROM `MOO` WHERE `NOO` = 3";
2755 r = run_query(hdb1, 0, query);
2756 ok(r == ERROR_SUCCESS, "failed to delete row\n");
2758 hrec = MsiCreateRecord(2);
2759 r = MsiRecordSetInteger(hrec, 1, 1);
2760 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2762 write_file("testdata.bin", "naengmyon", 9);
2763 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2764 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2766 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2767 r = run_query(hdb1, hrec, query);
2768 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2770 MsiCloseHandle(hrec);
2772 query = "ALTER TABLE `MOO` ADD `COW` INTEGER";
2773 r = run_query(hdb1, 0, query);
2774 ok(r == ERROR_SUCCESS, "failed to add column\n");
2776 query = "ALTER TABLE `MOO` ADD `PIG` INTEGER";
2777 r = run_query(hdb1, 0, query);
2778 ok(r == ERROR_SUCCESS, "failed to add column\n");
2780 query = "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
2781 r = run_query(hdb1, 0, query);
2782 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2784 query = "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
2785 "`Value` CHAR(0) PRIMARY KEY `Property`)";
2786 r = run_query(hdb1, 0, query);
2787 ok(r == ERROR_SUCCESS, "failed to add property table\n");
2789 query = "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2790 r = run_query(hdb1, 0, query);
2791 ok(r == ERROR_SUCCESS, "failed to add property\n");
2793 /* database needs to be committed */
2794 MsiDatabaseCommit(hdb1);
2796 r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
2797 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
2799 MsiCloseHandle( hdb1 );
2800 MsiCloseHandle( hdb2 );
2802 DeleteFile("testdata.bin");
2805 /* data for generating a transform */
2807 /* tables transform names - encoded as they would be in an msi database file */
2808 static const WCHAR name1[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
2809 static const WCHAR name2[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
2810 static const WCHAR name3[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
2811 static const WCHAR name4[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2812 static const WCHAR name5[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2813 static const WCHAR name6[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
2814 static const WCHAR name7[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
2815 static const WCHAR name8[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
2816 static const WCHAR name9[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2818 /* data in each table */
2819 static const WCHAR data1[] = { /* AAR */
2820 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
2821 0x0201, 0x0009, 0x8002,
2823 static const WCHAR data2[] = { /* _Columns */
2824 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
2825 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
2826 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
2827 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
2828 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
2829 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
2831 static const WCHAR data3[] = { /* _Tables */
2832 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
2833 0x0101, 0x000a,
2835 static const char data4[] = /* _StringData */
2836 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
2837 static const WCHAR data5[] = { /* _StringPool */
2838 /* len, refs */
2839 0, 0, /* string 0 '' */
2840 3, 2, /* string 1 'MOO' */
2841 3, 1, /* string 2 'COW' */
2842 3, 1, /* string 3 'PIG' */
2843 1, 1, /* string 4 'c' */
2844 3, 3, /* string 5 'AAR' */
2845 3, 1, /* string 6 'CAR' */
2846 3, 1, /* string 7 'BAR' */
2847 2, 1, /* string 8 'vw' */
2848 3, 1, /* string 9 'bmw' */
2849 8, 4, /* string 10 'Property' */
2850 5, 1, /* string 11 'Value' */
2851 4, 1, /* string 12 'prop' */
2852 3, 1, /* string 13 'val' */
2854 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
2855 static const WCHAR data6[] = { /* MOO */
2856 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
2857 0x0000, 0x8003, /* delete row */
2860 static const WCHAR data7[] = { /* BINARY */
2861 0x0201, 0x8001, 0x0001,
2864 static const char data8[] = /* stream data for the BINARY table */
2865 "naengmyon";
2867 static const WCHAR data9[] = { /* Property */
2868 0x0201, 0x000c, 0x000d,
2871 static const struct {
2872 LPCWSTR name;
2873 const void *data;
2874 DWORD size;
2875 } table_transform_data[] =
2877 { name1, data1, sizeof data1 },
2878 { name2, data2, sizeof data2 },
2879 { name3, data3, sizeof data3 },
2880 { name4, data4, sizeof data4 - 1 },
2881 { name5, data5, sizeof data5 },
2882 { name6, data6, sizeof data6 },
2883 { name7, data7, sizeof data7 },
2884 { name8, data8, sizeof data8 - 1 },
2885 { name9, data9, sizeof data9 },
2888 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2890 static void generate_transform_manual(void)
2892 IStorage *stg = NULL;
2893 IStream *stm;
2894 WCHAR name[0x20];
2895 HRESULT r;
2896 DWORD i, count;
2897 const DWORD mode = STGM_CREATE|STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE;
2899 const CLSID CLSID_MsiTransform = { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2901 MultiByteToWideChar(CP_ACP, 0, mstfile, -1, name, 0x20);
2903 r = StgCreateDocfile(name, mode, 0, &stg);
2904 ok(r == S_OK, "failed to create storage\n");
2905 if (!stg)
2906 return;
2908 r = IStorage_SetClass( stg, &CLSID_MsiTransform );
2909 ok(r == S_OK, "failed to set storage type\n");
2911 for (i=0; i<NUM_TRANSFORM_TABLES; i++)
2913 r = IStorage_CreateStream( stg, table_transform_data[i].name,
2914 STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm );
2915 if (FAILED(r))
2917 ok(0, "failed to create stream %08x\n", r);
2918 continue;
2921 r = IStream_Write( stm, table_transform_data[i].data,
2922 table_transform_data[i].size, &count );
2923 if (FAILED(r) || count != table_transform_data[i].size)
2924 ok(0, "failed to write stream\n");
2925 IStream_Release(stm);
2928 IStorage_Release(stg);
2931 static UINT set_summary_info(MSIHANDLE hdb)
2933 UINT res;
2934 MSIHANDLE suminfo;
2936 /* build summary info */
2937 res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
2938 ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );
2940 res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
2941 "Installation Database");
2942 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2944 res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
2945 "Installation Database");
2946 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2948 res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
2949 "Wine Hackers");
2950 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2952 res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
2953 ";1033,2057");
2954 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2956 res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
2957 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2958 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2960 res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
2961 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2963 res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
2964 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2966 res = MsiSummaryInfoPersist(suminfo);
2967 ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );
2969 res = MsiCloseHandle( suminfo);
2970 ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );
2972 return res;
2975 static MSIHANDLE create_package_db(LPCSTR filename)
2977 MSIHANDLE hdb = 0;
2978 UINT res;
2980 DeleteFile(msifile);
2982 /* create an empty database */
2983 res = MsiOpenDatabase(filename, MSIDBOPEN_CREATE, &hdb );
2984 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
2985 if( res != ERROR_SUCCESS )
2986 return hdb;
2988 res = MsiDatabaseCommit( hdb );
2989 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
2991 res = set_summary_info(hdb);
2992 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2994 res = create_directory_table(hdb);
2995 ok( res == ERROR_SUCCESS , "Failed to create directory table\n" );
2997 return hdb;
3000 static UINT package_from_db(MSIHANDLE hdb, MSIHANDLE *handle)
3002 UINT res;
3003 CHAR szPackage[12];
3004 MSIHANDLE hPackage;
3006 sprintf(szPackage, "#%u", hdb);
3007 res = MsiOpenPackage(szPackage, &hPackage);
3008 if (res != ERROR_SUCCESS)
3009 return res;
3011 res = MsiCloseHandle(hdb);
3012 if (res != ERROR_SUCCESS)
3014 MsiCloseHandle(hPackage);
3015 return res;
3018 *handle = hPackage;
3019 return ERROR_SUCCESS;
3022 static void test_try_transform(void)
3024 MSIHANDLE hdb, hview, hrec, hpkg = 0;
3025 LPCSTR query;
3026 UINT r;
3027 DWORD sz;
3028 char buffer[MAX_PATH];
3030 DeleteFile(msifile);
3031 DeleteFile(mstfile);
3033 /* create the database */
3034 hdb = create_package_db(msifile);
3035 ok(hdb, "Failed to create package db\n");
3037 query = "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
3038 r = run_query(hdb, 0, query);
3039 ok(r == ERROR_SUCCESS, "failed to add table\n");
3041 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
3042 r = run_query(hdb, 0, query);
3043 ok(r == ERROR_SUCCESS, "failed to add row\n");
3045 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
3046 r = run_query(hdb, 0, query);
3047 ok(r == ERROR_SUCCESS, "failed to add row\n");
3049 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
3050 r = run_query(hdb, 0, query);
3051 ok(r == ERROR_SUCCESS, "failed to add row\n");
3053 query = "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
3054 r = run_query(hdb, 0, query);
3055 ok(r == ERROR_SUCCESS, "failed to add table\n");
3057 hrec = MsiCreateRecord(2);
3058 r = MsiRecordSetInteger(hrec, 1, 2);
3059 ok(r == ERROR_SUCCESS, "failed to set integer\n");
3061 write_file("testdata.bin", "lamyon", 6);
3062 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
3063 ok(r == ERROR_SUCCESS, "failed to set stream\n");
3065 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
3066 r = run_query(hdb, hrec, query);
3067 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
3069 MsiCloseHandle(hrec);
3071 r = MsiDatabaseCommit( hdb );
3072 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
3074 MsiCloseHandle( hdb );
3075 DeleteFileA("testdata.bin");
3078 * Both these generate an equivalent transform,
3079 * but the first doesn't work in Wine yet
3080 * because MsiDatabaseGenerateTransform is unimplemented.
3082 if (0)
3083 generate_transform();
3084 else
3085 generate_transform_manual();
3087 r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb );
3088 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
3090 r = MsiDatabaseApplyTransform( hdb, mstfile, 0 );
3091 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
3093 MsiDatabaseCommit( hdb );
3095 /* check new values */
3096 hrec = 0;
3097 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
3098 r = do_query(hdb, query, &hrec);
3099 ok(r == ERROR_SUCCESS, "select query failed\n");
3100 MsiCloseHandle(hrec);
3102 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
3103 hrec = 0;
3104 r = do_query(hdb, query, &hrec);
3105 ok(r == ERROR_SUCCESS, "select query failed\n");
3106 MsiCloseHandle(hrec);
3108 /* check updated values */
3109 hrec = 0;
3110 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
3111 r = do_query(hdb, query, &hrec);
3112 ok(r == ERROR_SUCCESS, "select query failed\n");
3113 MsiCloseHandle(hrec);
3115 /* check unchanged value */
3116 hrec = 0;
3117 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
3118 r = do_query(hdb, query, &hrec);
3119 ok(r == ERROR_SUCCESS, "select query failed\n");
3120 MsiCloseHandle(hrec);
3122 /* check deleted value */
3123 hrec = 0;
3124 query = "select * from `MOO` where `NOO` = 3";
3125 r = do_query(hdb, query, &hrec);
3126 ok(r == ERROR_NO_MORE_ITEMS, "select query failed\n");
3127 if (hrec) MsiCloseHandle(hrec);
3129 /* check added stream */
3130 hrec = 0;
3131 query = "select `BLOB` from `BINARY` where `ID` = 1";
3132 r = do_query(hdb, query, &hrec);
3133 ok(r == ERROR_SUCCESS, "select query failed\n");
3135 /* check the contents of the stream */
3136 sz = sizeof buffer;
3137 r = MsiRecordReadStream( hrec, 1, buffer, &sz );
3138 ok(r == ERROR_SUCCESS, "read stream failed\n");
3139 ok(!memcmp(buffer, "naengmyon", 9), "stream data was wrong\n");
3140 ok(sz == 9, "stream data was wrong size\n");
3141 if (hrec) MsiCloseHandle(hrec);
3143 /* check the validity of the table with a deleted row */
3144 hrec = 0;
3145 query = "select * from `MOO`";
3146 r = MsiDatabaseOpenView(hdb, query, &hview);
3147 ok(r == ERROR_SUCCESS, "open view failed\n");
3149 r = MsiViewExecute(hview, 0);
3150 ok(r == ERROR_SUCCESS, "view execute failed\n");
3152 r = MsiViewFetch(hview, &hrec);
3153 ok(r == ERROR_SUCCESS, "view fetch failed\n");
3155 r = MsiRecordGetInteger(hrec, 1);
3156 ok(r == 1, "Expected 1, got %d\n", r);
3158 sz = sizeof buffer;
3159 r = MsiRecordGetString(hrec, 2, buffer, &sz);
3160 ok(r == ERROR_SUCCESS, "record get string failed\n");
3161 ok(!lstrcmpA(buffer, "c"), "Expected c, got %s\n", buffer);
3163 r = MsiRecordGetInteger(hrec, 3);
3164 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
3166 r = MsiRecordGetInteger(hrec, 4);
3167 ok(r == 5, "Expected 5, got %d\n", r);
3169 MsiCloseHandle(hrec);
3171 r = MsiViewFetch(hview, &hrec);
3172 ok(r == ERROR_SUCCESS, "view fetch failed\n");
3174 r = MsiRecordGetInteger(hrec, 1);
3175 ok(r == 2, "Expected 2, got %d\n", r);
3177 sz = sizeof buffer;
3178 r = MsiRecordGetString(hrec, 2, buffer, &sz);
3179 ok(r == ERROR_SUCCESS, "record get string failed\n");
3180 ok(!lstrcmpA(buffer, "b"), "Expected b, got %s\n", buffer);
3182 r = MsiRecordGetInteger(hrec, 3);
3183 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
3185 r = MsiRecordGetInteger(hrec, 4);
3186 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
3188 MsiCloseHandle(hrec);
3190 r = MsiViewFetch(hview, &hrec);
3191 ok(r == ERROR_NO_MORE_ITEMS, "view fetch succeeded\n");
3193 MsiCloseHandle(hrec);
3194 MsiViewClose(hview);
3195 MsiCloseHandle(hview);
3197 /* check that the property was added */
3198 r = package_from_db(hdb, &hpkg);
3199 if (r == ERROR_INSTALL_PACKAGE_REJECTED)
3201 skip("Not enough rights to perform tests\n");
3202 goto error;
3204 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
3206 sz = MAX_PATH;
3207 r = MsiGetProperty(hpkg, "prop", buffer, &sz);
3208 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3209 ok(!lstrcmp(buffer, "val"), "Expected val, got %s\n", buffer);
3211 MsiCloseHandle(hpkg);
3213 error:
3214 MsiCloseHandle(hdb);
3215 DeleteFile(msifile);
3216 DeleteFile(mstfile);
3219 struct join_res
3221 const CHAR one[MAX_PATH];
3222 const CHAR two[MAX_PATH];
3225 struct join_res_4col
3227 const CHAR one[MAX_PATH];
3228 const CHAR two[MAX_PATH];
3229 const CHAR three[MAX_PATH];
3230 const CHAR four[MAX_PATH];
3233 struct join_res_uint
3235 UINT one;
3236 UINT two;
3237 UINT three;
3238 UINT four;
3239 UINT five;
3240 UINT six;
3243 static const struct join_res join_res_first[] =
3245 { "alveolar", "procerus" },
3246 { "septum", "procerus" },
3247 { "septum", "nasalis" },
3248 { "ramus", "nasalis" },
3249 { "malar", "mentalis" },
3252 static const struct join_res join_res_second[] =
3254 { "nasal", "septum" },
3255 { "mandible", "ramus" },
3258 static const struct join_res join_res_third[] =
3260 { "msvcp.dll", "abcdefgh" },
3261 { "msvcr.dll", "ijklmnop" },
3264 static const struct join_res join_res_fourth[] =
3266 { "msvcp.dll.01234", "single.dll.31415" },
3269 static const struct join_res join_res_fifth[] =
3271 { "malar", "procerus" },
3274 static const struct join_res join_res_sixth[] =
3276 { "malar", "procerus" },
3277 { "malar", "procerus" },
3278 { "malar", "nasalis" },
3279 { "malar", "nasalis" },
3280 { "malar", "nasalis" },
3281 { "malar", "mentalis" },
3284 static const struct join_res join_res_seventh[] =
3286 { "malar", "nasalis" },
3287 { "malar", "nasalis" },
3288 { "malar", "nasalis" },
3291 static const struct join_res_4col join_res_eighth[] =
3293 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
3294 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
3295 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
3296 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
3297 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
3298 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
3301 static const struct join_res_uint join_res_ninth[] =
3303 { 1, 2, 3, 4, 7, 8 },
3304 { 1, 2, 5, 6, 7, 8 },
3305 { 1, 2, 3, 4, 9, 10 },
3306 { 1, 2, 5, 6, 9, 10 },
3307 { 1, 2, 3, 4, 11, 12 },
3308 { 1, 2, 5, 6, 11, 12 },
3311 static void test_join(void)
3313 MSIHANDLE hdb, hview, hrec;
3314 LPCSTR query;
3315 CHAR buf[MAX_PATH];
3316 UINT r, count;
3317 DWORD size, i;
3318 BOOL data_correct;
3320 hdb = create_db();
3321 ok( hdb, "failed to create db\n");
3323 r = create_component_table( hdb );
3324 ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
3326 r = add_component_entry( hdb, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
3327 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3329 r = add_component_entry( hdb, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
3330 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3332 r = add_component_entry( hdb, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
3333 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3335 r = add_component_entry( hdb, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
3336 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3338 r = create_feature_components_table( hdb );
3339 ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
3341 r = add_feature_components_entry( hdb, "'procerus', 'maxilla'" );
3342 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3344 r = add_feature_components_entry( hdb, "'procerus', 'nasal'" );
3345 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3347 r = add_feature_components_entry( hdb, "'nasalis', 'nasal'" );
3348 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3350 r = add_feature_components_entry( hdb, "'nasalis', 'mandible'" );
3351 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3353 r = add_feature_components_entry( hdb, "'nasalis', 'notacomponent'" );
3354 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3356 r = add_feature_components_entry( hdb, "'mentalis', 'zygomatic'" );
3357 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3359 r = create_std_dlls_table( hdb );
3360 ok( r == ERROR_SUCCESS, "cannot create StdDlls table: %d\n", r );
3362 r = add_std_dlls_entry( hdb, "'msvcp.dll', 'msvcp.dll.01234'" );
3363 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
3365 r = add_std_dlls_entry( hdb, "'msvcr.dll', 'msvcr.dll.56789'" );
3366 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
3368 r = create_binary_table( hdb );
3369 ok( r == ERROR_SUCCESS, "cannot create Binary table: %d\n", r );
3371 r = add_binary_entry( hdb, "'msvcp.dll.01234', 'abcdefgh'" );
3372 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
3374 r = add_binary_entry( hdb, "'msvcr.dll.56789', 'ijklmnop'" );
3375 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
3377 r = add_binary_entry( hdb, "'single.dll.31415', 'msvcp.dll'" );
3378 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
3380 query = "CREATE TABLE `One` (`A` SHORT, `B` SHORT PRIMARY KEY `A`)";
3381 r = run_query( hdb, 0, query);
3382 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3384 query = "CREATE TABLE `Two` (`C` SHORT, `D` SHORT PRIMARY KEY `C`)";
3385 r = run_query( hdb, 0, query);
3386 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3388 query = "CREATE TABLE `Three` (`E` SHORT, `F` SHORT PRIMARY KEY `E`)";
3389 r = run_query( hdb, 0, query);
3390 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3392 query = "INSERT INTO `One` (`A`, `B`) VALUES (1, 2)";
3393 r = run_query( hdb, 0, query);
3394 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3396 query = "INSERT INTO `Two` (`C`, `D`) VALUES (3, 4)";
3397 r = run_query( hdb, 0, query);
3398 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3400 query = "INSERT INTO `Two` (`C`, `D`) VALUES (5, 6)";
3401 r = run_query( hdb, 0, query);
3402 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3404 query = "INSERT INTO `Three` (`E`, `F`) VALUES (7, 8)";
3405 r = run_query( hdb, 0, query);
3406 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3408 query = "INSERT INTO `Three` (`E`, `F`) VALUES (9, 10)";
3409 r = run_query( hdb, 0, query);
3410 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3412 query = "INSERT INTO `Three` (`E`, `F`) VALUES (11, 12)";
3413 r = run_query( hdb, 0, query);
3414 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3416 query = "CREATE TABLE `Four` (`G` SHORT, `H` SHORT PRIMARY KEY `G`)";
3417 r = run_query( hdb, 0, query);
3418 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3420 query = "CREATE TABLE `Five` (`I` SHORT, `J` SHORT PRIMARY KEY `I`)";
3421 r = run_query( hdb, 0, query);
3422 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3424 query = "INSERT INTO `Five` (`I`, `J`) VALUES (13, 14)";
3425 r = run_query( hdb, 0, query);
3426 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3428 query = "INSERT INTO `Five` (`I`, `J`) VALUES (15, 16)";
3429 r = run_query( hdb, 0, query);
3430 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3432 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3433 "FROM `Component`, `FeatureComponents` "
3434 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
3435 "ORDER BY `Feature_`";
3436 r = MsiDatabaseOpenView(hdb, query, &hview);
3437 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3439 r = MsiViewExecute(hview, 0);
3440 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3442 i = 0;
3443 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3445 count = MsiRecordGetFieldCount( hrec );
3446 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3448 size = MAX_PATH;
3449 r = MsiRecordGetString( hrec, 1, buf, &size );
3450 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3451 ok( !lstrcmp( buf, join_res_first[i].one ),
3452 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_first[i].one, buf );
3454 size = MAX_PATH;
3455 r = MsiRecordGetString( hrec, 2, buf, &size );
3456 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3457 ok( !lstrcmp( buf, join_res_first[i].two ),
3458 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_first[i].two, buf );
3460 i++;
3461 MsiCloseHandle(hrec);
3464 ok( i == 5, "Expected 5 rows, got %d\n", i );
3465 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3467 MsiViewClose(hview);
3468 MsiCloseHandle(hview);
3470 /* try a join without a WHERE condition */
3471 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3472 "FROM `Component`, `FeatureComponents` ";
3473 r = MsiDatabaseOpenView(hdb, query, &hview);
3474 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3476 r = MsiViewExecute(hview, 0);
3477 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3479 i = 0;
3480 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3482 i++;
3483 MsiCloseHandle(hrec);
3485 ok( i == 24, "Expected 24 rows, got %d\n", i );
3487 MsiViewClose(hview);
3488 MsiCloseHandle(hview);
3490 query = "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
3491 "WHERE FeatureComponents.Component_=Component.Component "
3492 "AND (Feature_='nasalis') ORDER BY Feature_";
3493 r = MsiDatabaseOpenView(hdb, query, &hview);
3494 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3496 r = MsiViewExecute(hview, 0);
3497 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3499 i = 0;
3500 data_correct = TRUE;
3501 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3503 count = MsiRecordGetFieldCount( hrec );
3504 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3506 size = MAX_PATH;
3507 r = MsiRecordGetString( hrec, 1, buf, &size );
3508 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3509 if( lstrcmp( buf, join_res_second[i].one ))
3510 data_correct = FALSE;
3512 size = MAX_PATH;
3513 r = MsiRecordGetString( hrec, 2, buf, &size );
3514 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3515 if( lstrcmp( buf, join_res_second[i].two ))
3516 data_correct = FALSE;
3518 i++;
3519 MsiCloseHandle(hrec);
3522 ok( data_correct, "data returned in the wrong order\n");
3524 ok( i == 2, "Expected 2 rows, got %d\n", i );
3525 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3527 MsiViewClose(hview);
3528 MsiCloseHandle(hview);
3530 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3531 "FROM `StdDlls`, `Binary` "
3532 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
3533 "ORDER BY `File`";
3534 r = MsiDatabaseOpenView(hdb, query, &hview);
3535 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3537 r = MsiViewExecute(hview, 0);
3538 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3540 i = 0;
3541 data_correct = TRUE;
3542 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3544 count = MsiRecordGetFieldCount( hrec );
3545 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3547 size = MAX_PATH;
3548 r = MsiRecordGetString( hrec, 1, buf, &size );
3549 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3550 if( lstrcmp( buf, join_res_third[i].one ) )
3551 data_correct = FALSE;
3553 size = MAX_PATH;
3554 r = MsiRecordGetString( hrec, 2, buf, &size );
3555 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3556 if( lstrcmp( buf, join_res_third[i].two ) )
3557 data_correct = FALSE;
3559 i++;
3560 MsiCloseHandle(hrec);
3562 ok( data_correct, "data returned in the wrong order\n");
3564 ok( i == 2, "Expected 2 rows, got %d\n", i );
3566 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3568 MsiViewClose(hview);
3569 MsiCloseHandle(hview);
3571 query = "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
3572 "FROM `StdDlls`, `Binary` "
3573 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
3574 "ORDER BY `Name`";
3575 r = MsiDatabaseOpenView(hdb, query, &hview);
3576 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3578 r = MsiViewExecute(hview, 0);
3579 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3581 i = 0;
3582 data_correct = TRUE;
3583 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3585 count = MsiRecordGetFieldCount( hrec );
3586 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3588 size = MAX_PATH;
3589 r = MsiRecordGetString( hrec, 1, buf, &size );
3590 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3591 if( lstrcmp( buf, join_res_fourth[i].one ))
3592 data_correct = FALSE;
3594 size = MAX_PATH;
3595 r = MsiRecordGetString( hrec, 2, buf, &size );
3596 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3597 if( lstrcmp( buf, join_res_fourth[i].two ))
3598 data_correct = FALSE;
3600 i++;
3601 MsiCloseHandle(hrec);
3603 ok( data_correct, "data returned in the wrong order\n");
3605 ok( i == 1, "Expected 1 rows, got %d\n", i );
3606 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3608 MsiViewClose(hview);
3609 MsiCloseHandle(hview);
3611 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3612 "FROM `Component`, `FeatureComponents` "
3613 "WHERE `Component`.`Component` = 'zygomatic' "
3614 "AND `FeatureComponents`.`Component_` = 'maxilla' "
3615 "ORDER BY `Feature_`";
3616 r = MsiDatabaseOpenView(hdb, query, &hview);
3617 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3619 r = MsiViewExecute(hview, 0);
3620 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3622 i = 0;
3623 data_correct = TRUE;
3624 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3626 count = MsiRecordGetFieldCount( hrec );
3627 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3629 size = MAX_PATH;
3630 r = MsiRecordGetString( hrec, 1, buf, &size );
3631 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3632 if( lstrcmp( buf, join_res_fifth[i].one ))
3633 data_correct = FALSE;
3635 size = MAX_PATH;
3636 r = MsiRecordGetString( hrec, 2, buf, &size );
3637 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3638 if( lstrcmp( buf, join_res_fifth[i].two ))
3639 data_correct = FALSE;
3641 i++;
3642 MsiCloseHandle(hrec);
3644 ok( data_correct, "data returned in the wrong order\n");
3646 ok( i == 1, "Expected 1 rows, got %d\n", i );
3647 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3649 MsiViewClose(hview);
3650 MsiCloseHandle(hview);
3652 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3653 "FROM `Component`, `FeatureComponents` "
3654 "WHERE `Component` = 'zygomatic' "
3655 "ORDER BY `Feature_`";
3656 r = MsiDatabaseOpenView(hdb, query, &hview);
3657 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3659 r = MsiViewExecute(hview, 0);
3660 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3662 i = 0;
3663 data_correct = TRUE;
3664 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3666 count = MsiRecordGetFieldCount( hrec );
3667 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3669 size = MAX_PATH;
3670 r = MsiRecordGetString( hrec, 1, buf, &size );
3671 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3672 if( lstrcmp( buf, join_res_sixth[i].one ))
3673 data_correct = FALSE;
3675 size = MAX_PATH;
3676 r = MsiRecordGetString( hrec, 2, buf, &size );
3677 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3678 if( lstrcmp( buf, join_res_sixth[i].two ))
3679 data_correct = FALSE;
3681 i++;
3682 MsiCloseHandle(hrec);
3684 ok( data_correct, "data returned in the wrong order\n");
3686 ok( i == 6, "Expected 6 rows, got %d\n", i );
3687 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3689 MsiViewClose(hview);
3690 MsiCloseHandle(hview);
3692 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3693 "FROM `Component`, `FeatureComponents` "
3694 "WHERE `Component` = 'zygomatic' "
3695 "AND `Feature_` = 'nasalis' "
3696 "ORDER BY `Feature_`";
3697 r = MsiDatabaseOpenView(hdb, query, &hview);
3698 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3700 r = MsiViewExecute(hview, 0);
3701 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3703 i = 0;
3704 data_correct = TRUE;
3705 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3707 count = MsiRecordGetFieldCount( hrec );
3708 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3710 size = MAX_PATH;
3711 r = MsiRecordGetString( hrec, 1, buf, &size );
3712 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3713 if( lstrcmp( buf, join_res_seventh[i].one ))
3714 data_correct = FALSE;
3716 size = MAX_PATH;
3717 r = MsiRecordGetString( hrec, 2, buf, &size );
3718 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3719 if( lstrcmp( buf, join_res_seventh[i].two ))
3720 data_correct = FALSE;
3722 i++;
3723 MsiCloseHandle(hrec);
3726 ok( data_correct, "data returned in the wrong order\n");
3727 ok( i == 3, "Expected 3 rows, got %d\n", i );
3728 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3730 MsiViewClose(hview);
3731 MsiCloseHandle(hview);
3733 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3734 "FROM `StdDlls`, `Binary` ";
3735 r = MsiDatabaseOpenView(hdb, query, &hview);
3736 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3738 r = MsiViewExecute(hview, 0);
3739 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3741 i = 0;
3742 data_correct = TRUE;
3743 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3745 count = MsiRecordGetFieldCount( hrec );
3746 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3748 size = MAX_PATH;
3749 r = MsiRecordGetString( hrec, 1, buf, &size );
3750 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3751 if( lstrcmp( buf, join_res_eighth[i].one ))
3752 data_correct = FALSE;
3754 size = MAX_PATH;
3755 r = MsiRecordGetString( hrec, 2, buf, &size );
3756 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3757 if( lstrcmp( buf, join_res_eighth[i].four ))
3758 data_correct = FALSE;
3760 i++;
3761 MsiCloseHandle(hrec);
3764 ok( data_correct, "data returned in the wrong order\n");
3765 ok( i == 6, "Expected 6 rows, got %d\n", i );
3766 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3768 MsiViewClose(hview);
3769 MsiCloseHandle(hview);
3771 query = "SELECT * FROM `StdDlls`, `Binary` ";
3772 r = MsiDatabaseOpenView(hdb, query, &hview);
3773 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3775 r = MsiViewExecute(hview, 0);
3776 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3778 i = 0;
3779 data_correct = TRUE;
3780 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3782 count = MsiRecordGetFieldCount( hrec );
3783 ok( count == 4, "Expected 4 record fields, got %d\n", count );
3785 size = MAX_PATH;
3786 r = MsiRecordGetString( hrec, 1, buf, &size );
3787 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3788 if( lstrcmp( buf, join_res_eighth[i].one ))
3789 data_correct = FALSE;
3791 size = MAX_PATH;
3792 r = MsiRecordGetString( hrec, 2, buf, &size );
3793 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3794 if( lstrcmp( buf, join_res_eighth[i].two ))
3795 data_correct = FALSE;
3797 size = MAX_PATH;
3798 r = MsiRecordGetString( hrec, 3, buf, &size );
3799 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3800 if( lstrcmp( buf, join_res_eighth[i].three ))
3801 data_correct = FALSE;
3803 size = MAX_PATH;
3804 r = MsiRecordGetString( hrec, 4, buf, &size );
3805 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3806 if( lstrcmp( buf, join_res_eighth[i].four ))
3807 data_correct = FALSE;
3809 i++;
3810 MsiCloseHandle(hrec);
3812 ok( data_correct, "data returned in the wrong order\n");
3814 ok( i == 6, "Expected 6 rows, got %d\n", i );
3815 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3817 MsiViewClose(hview);
3818 MsiCloseHandle(hview);
3820 query = "SELECT * FROM `One`, `Two`, `Three` ";
3821 r = MsiDatabaseOpenView(hdb, query, &hview);
3822 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3824 r = MsiViewExecute(hview, 0);
3825 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3827 i = 0;
3828 data_correct = TRUE;
3829 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3831 count = MsiRecordGetFieldCount( hrec );
3832 ok( count == 6, "Expected 6 record fields, got %d\n", count );
3834 r = MsiRecordGetInteger( hrec, 1 );
3835 if( r != join_res_ninth[i].one )
3836 data_correct = FALSE;
3838 r = MsiRecordGetInteger( hrec, 2 );
3839 if( r != join_res_ninth[i].two )
3840 data_correct = FALSE;
3842 r = MsiRecordGetInteger( hrec, 3 );
3843 if( r != join_res_ninth[i].three )
3844 data_correct = FALSE;
3846 r = MsiRecordGetInteger( hrec, 4 );
3847 if( r != join_res_ninth[i].four )
3848 data_correct = FALSE;
3850 r = MsiRecordGetInteger( hrec, 5 );
3851 if( r != join_res_ninth[i].five )
3852 data_correct = FALSE;
3854 r = MsiRecordGetInteger( hrec, 6);
3855 if( r != join_res_ninth[i].six )
3856 data_correct = FALSE;
3858 i++;
3859 MsiCloseHandle(hrec);
3861 ok( data_correct, "data returned in the wrong order\n");
3863 ok( i == 6, "Expected 6 rows, got %d\n", i );
3864 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3866 MsiViewClose(hview);
3867 MsiCloseHandle(hview);
3869 query = "SELECT * FROM `Four`, `Five`";
3870 r = MsiDatabaseOpenView(hdb, query, &hview);
3871 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3873 r = MsiViewExecute(hview, 0);
3874 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3876 r = MsiViewFetch(hview, &hrec);
3877 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3879 MsiViewClose(hview);
3880 MsiCloseHandle(hview);
3882 query = "SELECT * FROM `Nonexistent`, `One`";
3883 r = MsiDatabaseOpenView(hdb, query, &hview);
3884 ok( r == ERROR_BAD_QUERY_SYNTAX,
3885 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r );
3887 /* try updating a row in a join table */
3888 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3889 "FROM `Component`, `FeatureComponents` "
3890 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
3891 "ORDER BY `Feature_`";
3892 r = MsiDatabaseOpenView(hdb, query, &hview);
3893 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3895 r = MsiViewExecute(hview, 0);
3896 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3898 r = MsiViewFetch(hview, &hrec);
3899 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
3901 r = MsiRecordSetString( hrec, 1, "epicranius" );
3902 ok( r == ERROR_SUCCESS, "failed to set string: %d\n", r );
3904 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
3905 ok( r == ERROR_SUCCESS, "failed to update row: %d\n", r );
3907 /* try another valid operation for joins */
3908 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
3909 todo_wine ok( r == ERROR_SUCCESS, "failed to refresh row: %d\n", r );
3911 /* try an invalid operation for joins */
3912 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
3913 ok( r == ERROR_FUNCTION_FAILED, "unexpected result: %d\n", r );
3915 r = MsiRecordSetString( hrec, 2, "epicranius" );
3916 ok( r == ERROR_SUCCESS, "failed to set string: %d\n", r );
3918 /* primary key cannot be updated */
3919 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
3920 ok( r == ERROR_FUNCTION_FAILED, "failed to update row: %d\n", r );
3922 MsiCloseHandle(hrec);
3923 MsiViewClose(hview);
3924 MsiCloseHandle(hview);
3926 r = MsiDatabaseOpenView(hdb, query, &hview);
3927 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3929 r = MsiViewExecute(hview, 0);
3930 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3932 r = MsiViewFetch(hview, &hrec);
3933 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
3935 size = MAX_PATH;
3936 r = MsiRecordGetString( hrec, 1, buf, &size );
3937 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3938 ok( !lstrcmp( buf, "epicranius" ), "expected 'epicranius', got %s\n", buf );
3940 MsiCloseHandle(hrec);
3941 MsiViewClose(hview);
3942 MsiCloseHandle(hview);
3944 MsiCloseHandle(hdb);
3945 DeleteFile(msifile);
3948 static void test_temporary_table(void)
3950 MSICONDITION cond;
3951 MSIHANDLE hdb = 0, view = 0, rec;
3952 const char *query;
3953 UINT r;
3954 char buf[0x10];
3955 DWORD sz;
3957 cond = MsiDatabaseIsTablePersistent(0, NULL);
3958 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3960 hdb = create_db();
3961 ok( hdb, "failed to create db\n");
3963 cond = MsiDatabaseIsTablePersistent(hdb, NULL);
3964 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3966 cond = MsiDatabaseIsTablePersistent(hdb, "_Tables");
3967 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3969 cond = MsiDatabaseIsTablePersistent(hdb, "_Columns");
3970 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3972 cond = MsiDatabaseIsTablePersistent(hdb, "_Storages");
3973 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3975 cond = MsiDatabaseIsTablePersistent(hdb, "_Streams");
3976 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3978 query = "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
3979 r = run_query(hdb, 0, query);
3980 ok(r == ERROR_SUCCESS, "failed to add table\n");
3982 cond = MsiDatabaseIsTablePersistent(hdb, "P");
3983 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3985 query = "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
3986 r = run_query(hdb, 0, query);
3987 ok(r == ERROR_SUCCESS, "failed to add table\n");
3989 cond = MsiDatabaseIsTablePersistent(hdb, "P2");
3990 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3992 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3993 r = run_query(hdb, 0, query);
3994 ok(r == ERROR_SUCCESS, "failed to add table\n");
3996 cond = MsiDatabaseIsTablePersistent(hdb, "T");
3997 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
3999 query = "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
4000 r = run_query(hdb, 0, query);
4001 ok(r == ERROR_SUCCESS, "failed to add table\n");
4003 query = "SELECT * FROM `T2`";
4004 r = MsiDatabaseOpenView(hdb, query, &view);
4005 ok(r == ERROR_BAD_QUERY_SYNTAX,
4006 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4008 cond = MsiDatabaseIsTablePersistent(hdb, "T2");
4009 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
4011 query = "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
4012 r = run_query(hdb, 0, query);
4013 ok(r == ERROR_SUCCESS, "failed to add table\n");
4015 cond = MsiDatabaseIsTablePersistent(hdb, "T3");
4016 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
4018 query = "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
4019 r = run_query(hdb, 0, query);
4020 ok(r == ERROR_FUNCTION_FAILED, "failed to add table\n");
4022 cond = MsiDatabaseIsTablePersistent(hdb, "T4");
4023 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
4025 query = "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
4026 r = run_query(hdb, 0, query);
4027 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add table\n");
4029 query = "select * from `T`";
4030 r = MsiDatabaseOpenView(hdb, query, &view);
4031 ok(r == ERROR_SUCCESS, "failed to query table\n");
4032 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
4033 ok(r == ERROR_SUCCESS, "failed to get column info\n");
4035 sz = sizeof buf;
4036 r = MsiRecordGetString(rec, 1, buf, &sz);
4037 ok(r == ERROR_SUCCESS, "failed to get string\n");
4038 ok( 0 == strcmp("G255", buf), "wrong column type\n");
4040 sz = sizeof buf;
4041 r = MsiRecordGetString(rec, 2, buf, &sz);
4042 ok(r == ERROR_SUCCESS, "failed to get string\n");
4043 ok( 0 == strcmp("j2", buf), "wrong column type\n");
4045 MsiCloseHandle( rec );
4046 MsiViewClose( view );
4047 MsiCloseHandle( view );
4049 /* query the table data */
4050 rec = 0;
4051 r = do_query(hdb, "select * from `_Tables` where `Name` = 'T'", &rec);
4052 ok( r == ERROR_SUCCESS, "temporary table exists in _Tables\n");
4053 MsiCloseHandle( rec );
4055 /* query the column data */
4056 rec = 0;
4057 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec);
4058 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
4059 if (rec) MsiCloseHandle( rec );
4061 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec);
4062 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
4063 if (rec) MsiCloseHandle( rec );
4065 MsiCloseHandle( hdb );
4067 DeleteFile(msifile);
4070 static void test_alter(void)
4072 MSICONDITION cond;
4073 MSIHANDLE hdb = 0;
4074 const char *query;
4075 UINT r;
4077 hdb = create_db();
4078 ok( hdb, "failed to create db\n");
4080 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
4081 r = run_query(hdb, 0, query);
4082 ok(r == ERROR_SUCCESS, "failed to add table\n");
4084 cond = MsiDatabaseIsTablePersistent(hdb, "T");
4085 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
4087 query = "ALTER TABLE `T` HOLD";
4088 r = run_query(hdb, 0, query);
4089 ok(r == ERROR_SUCCESS, "failed to hold table %d\n", r);
4091 query = "ALTER TABLE `T` FREE";
4092 r = run_query(hdb, 0, query);
4093 ok(r == ERROR_SUCCESS, "failed to free table\n");
4095 query = "ALTER TABLE `T` FREE";
4096 r = run_query(hdb, 0, query);
4097 ok(r == ERROR_SUCCESS, "failed to free table\n");
4099 query = "ALTER TABLE `T` FREE";
4100 r = run_query(hdb, 0, query);
4101 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to free table\n");
4103 query = "ALTER TABLE `T` HOLD";
4104 r = run_query(hdb, 0, query);
4105 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to hold table %d\n", r);
4107 /* table T is removed */
4108 query = "SELECT * FROM `T`";
4109 r = run_query(hdb, 0, query);
4110 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4112 /* create the table again */
4113 query = "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
4114 r = run_query(hdb, 0, query);
4115 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4117 /* up the ref count */
4118 query = "ALTER TABLE `U` HOLD";
4119 r = run_query(hdb, 0, query);
4120 ok(r == ERROR_SUCCESS, "failed to free table\n");
4122 /* add column, no data type */
4123 query = "ALTER TABLE `U` ADD `C`";
4124 r = run_query(hdb, 0, query);
4125 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4127 query = "ALTER TABLE `U` ADD `C` INTEGER";
4128 r = run_query(hdb, 0, query);
4129 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4131 /* add column C again */
4132 query = "ALTER TABLE `U` ADD `C` INTEGER";
4133 r = run_query(hdb, 0, query);
4134 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4136 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
4137 r = run_query(hdb, 0, query);
4138 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4140 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
4141 r = run_query(hdb, 0, query);
4142 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4144 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
4145 r = run_query(hdb, 0, query);
4146 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4148 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
4149 r = run_query(hdb, 0, query);
4150 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4152 query = "SELECT * FROM `U` WHERE `D` = 8";
4153 r = run_query(hdb, 0, query);
4154 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4156 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
4157 r = run_query(hdb, 0, query);
4158 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4160 query = "ALTER COLUMN `D` FREE";
4161 r = run_query(hdb, 0, query);
4162 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4164 /* drop the ref count */
4165 query = "ALTER TABLE `U` FREE";
4166 r = run_query(hdb, 0, query);
4167 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4169 /* table is not empty */
4170 query = "SELECT * FROM `U`";
4171 r = run_query(hdb, 0, query);
4172 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4174 /* column D is removed */
4175 query = "SELECT * FROM `U` WHERE `D` = 8";
4176 r = run_query(hdb, 0, query);
4177 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4179 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
4180 r = run_query(hdb, 0, query);
4181 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4183 /* add the column again */
4184 query = "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
4185 r = run_query(hdb, 0, query);
4186 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4188 /* up the ref count */
4189 query = "ALTER TABLE `U` HOLD";
4190 r = run_query(hdb, 0, query);
4191 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4193 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
4194 r = run_query(hdb, 0, query);
4195 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4197 query = "SELECT * FROM `U` WHERE `E` = 16";
4198 r = run_query(hdb, 0, query);
4199 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4201 /* drop the ref count */
4202 query = "ALTER TABLE `U` FREE";
4203 r = run_query(hdb, 0, query);
4204 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4206 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
4207 r = run_query(hdb, 0, query);
4208 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4210 query = "SELECT * FROM `U` WHERE `E` = 20";
4211 r = run_query(hdb, 0, query);
4212 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4214 /* drop the ref count */
4215 query = "ALTER TABLE `U` FREE";
4216 r = run_query(hdb, 0, query);
4217 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4219 /* table still exists */
4220 query = "SELECT * FROM `U`";
4221 r = run_query(hdb, 0, query);
4222 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4224 /* col E is removed */
4225 query = "SELECT * FROM `U` WHERE `E` = 20";
4226 r = run_query(hdb, 0, query);
4227 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4229 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
4230 r = run_query(hdb, 0, query);
4231 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4233 /* drop the ref count once more */
4234 query = "ALTER TABLE `U` FREE";
4235 r = run_query(hdb, 0, query);
4236 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4238 /* table still exists */
4239 query = "SELECT * FROM `U`";
4240 r = run_query(hdb, 0, query);
4241 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4243 MsiCloseHandle( hdb );
4244 DeleteFile(msifile);
4247 static void test_integers(void)
4249 MSIHANDLE hdb = 0, view = 0, rec = 0;
4250 DWORD count, i;
4251 const char *query;
4252 UINT r;
4254 /* just MsiOpenDatabase should not create a file */
4255 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4256 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4258 /* create a table */
4259 query = "CREATE TABLE `integers` ( "
4260 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
4261 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
4262 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
4263 "PRIMARY KEY `one`)";
4264 r = MsiDatabaseOpenView(hdb, query, &view);
4265 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4266 r = MsiViewExecute(view, 0);
4267 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4268 r = MsiViewClose(view);
4269 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4270 r = MsiCloseHandle(view);
4271 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4273 query = "SELECT * FROM `integers`";
4274 r = MsiDatabaseOpenView(hdb, query, &view);
4275 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4277 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
4278 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4279 count = MsiRecordGetFieldCount(rec);
4280 ok(count == 8, "Expected 8, got %d\n", count);
4281 ok(check_record(rec, 1, "one"), "Expected one\n");
4282 ok(check_record(rec, 2, "two"), "Expected two\n");
4283 ok(check_record(rec, 3, "three"), "Expected three\n");
4284 ok(check_record(rec, 4, "four"), "Expected four\n");
4285 ok(check_record(rec, 5, "five"), "Expected five\n");
4286 ok(check_record(rec, 6, "six"), "Expected six\n");
4287 ok(check_record(rec, 7, "seven"), "Expected seven\n");
4288 ok(check_record(rec, 8, "eight"), "Expected eight\n");
4289 MsiCloseHandle(rec);
4291 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
4292 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4293 count = MsiRecordGetFieldCount(rec);
4294 ok(count == 8, "Expected 8, got %d\n", count);
4295 ok(check_record(rec, 1, "I2"), "Expected I2\n");
4296 ok(check_record(rec, 2, "I2"), "Expected I2\n");
4297 ok(check_record(rec, 3, "I2"), "Expected I2\n");
4298 ok(check_record(rec, 4, "I4"), "Expected I4\n");
4299 ok(check_record(rec, 5, "i2"), "Expected i2\n");
4300 ok(check_record(rec, 6, "i2"), "Expected i2\n");
4301 ok(check_record(rec, 7, "i2"), "Expected i2\n");
4302 ok(check_record(rec, 8, "i4"), "Expected i4\n");
4303 MsiCloseHandle(rec);
4305 MsiViewClose(view);
4306 MsiCloseHandle(view);
4308 /* insert values into it, NULL where NOT NULL is specified */
4309 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
4310 "VALUES('', '', '', '', '', '', '', '')";
4311 r = MsiDatabaseOpenView(hdb, query, &view);
4312 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4313 r = MsiViewExecute(view, 0);
4314 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
4316 MsiViewClose(view);
4317 MsiCloseHandle(view);
4319 query = "SELECT * FROM `integers`";
4320 r = do_query(hdb, query, &rec);
4321 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4323 r = MsiRecordGetFieldCount(rec);
4324 ok(r == -1, "record count wrong: %d\n", r);
4326 MsiCloseHandle(rec);
4328 /* insert legitimate values into it */
4329 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
4330 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
4331 r = MsiDatabaseOpenView(hdb, query, &view);
4332 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4333 r = MsiViewExecute(view, 0);
4334 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4336 query = "SELECT * FROM `integers`";
4337 r = do_query(hdb, query, &rec);
4338 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4340 r = MsiRecordGetFieldCount(rec);
4341 ok(r == 8, "record count wrong: %d\n", r);
4343 i = MsiRecordGetInteger(rec, 1);
4344 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
4345 i = MsiRecordGetInteger(rec, 3);
4346 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
4347 i = MsiRecordGetInteger(rec, 2);
4348 ok(i == 2, "Expected 2, got %d\n", i);
4349 i = MsiRecordGetInteger(rec, 4);
4350 ok(i == 4, "Expected 4, got %d\n", i);
4351 i = MsiRecordGetInteger(rec, 5);
4352 ok(i == 5, "Expected 5, got %d\n", i);
4353 i = MsiRecordGetInteger(rec, 6);
4354 ok(i == 6, "Expected 6, got %d\n", i);
4355 i = MsiRecordGetInteger(rec, 7);
4356 ok(i == 7, "Expected 7, got %d\n", i);
4357 i = MsiRecordGetInteger(rec, 8);
4358 ok(i == 8, "Expected 8, got %d\n", i);
4360 MsiCloseHandle(rec);
4361 MsiViewClose(view);
4362 MsiCloseHandle(view);
4364 r = MsiDatabaseCommit(hdb);
4365 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
4367 r = MsiCloseHandle(hdb);
4368 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4370 r = DeleteFile(msifile);
4371 ok(r == TRUE, "file didn't exist after commit\n");
4374 static void test_update(void)
4376 MSIHANDLE hdb = 0, view = 0, rec = 0;
4377 CHAR result[MAX_PATH];
4378 const char *query;
4379 DWORD size;
4380 UINT r;
4382 /* just MsiOpenDatabase should not create a file */
4383 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4384 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4386 /* create the Control table */
4387 query = "CREATE TABLE `Control` ( "
4388 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
4389 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
4390 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
4391 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
4392 r = MsiDatabaseOpenView(hdb, query, &view);
4393 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4394 r = MsiViewExecute(view, 0);
4395 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4396 r = MsiViewClose(view);
4397 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4398 r = MsiCloseHandle(view);
4399 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4401 /* add a control */
4402 query = "INSERT INTO `Control` ( "
4403 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4404 "`Property`, `Text`, `Control_Next`, `Help` )"
4405 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
4406 r = MsiDatabaseOpenView(hdb, query, &view);
4407 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4408 r = MsiViewExecute(view, 0);
4409 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4410 r = MsiViewClose(view);
4411 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4412 r = MsiCloseHandle(view);
4413 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4415 /* add a second control */
4416 query = "INSERT INTO `Control` ( "
4417 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4418 "`Property`, `Text`, `Control_Next`, `Help` )"
4419 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
4420 r = MsiDatabaseOpenView(hdb, query, &view);
4421 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4422 r = MsiViewExecute(view, 0);
4423 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4424 r = MsiViewClose(view);
4425 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4426 r = MsiCloseHandle(view);
4427 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4429 /* add a third control */
4430 query = "INSERT INTO `Control` ( "
4431 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4432 "`Property`, `Text`, `Control_Next`, `Help` )"
4433 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
4434 r = MsiDatabaseOpenView(hdb, query, &view);
4435 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4436 r = MsiViewExecute(view, 0);
4437 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4438 r = MsiViewClose(view);
4439 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4440 r = MsiCloseHandle(view);
4441 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4443 /* bad table */
4444 query = "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4445 r = MsiDatabaseOpenView(hdb, query, &view);
4446 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4448 /* bad set column */
4449 query = "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4450 r = MsiDatabaseOpenView(hdb, query, &view);
4451 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4453 /* bad where condition */
4454 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
4455 r = MsiDatabaseOpenView(hdb, query, &view);
4456 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4458 /* just the dialog_ specified */
4459 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4460 r = MsiDatabaseOpenView(hdb, query, &view);
4461 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4462 r = MsiViewExecute(view, 0);
4463 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4464 r = MsiViewClose(view);
4465 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4466 r = MsiCloseHandle(view);
4467 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4469 /* check the modified text */
4470 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
4471 r = MsiDatabaseOpenView(hdb, query, &view);
4472 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4473 r = MsiViewExecute(view, 0);
4474 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4476 r = MsiViewFetch(view, &rec);
4477 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4479 size = MAX_PATH;
4480 r = MsiRecordGetString(rec, 1, result, &size);
4481 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4482 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4484 MsiCloseHandle(rec);
4486 r = MsiViewFetch(view, &rec);
4487 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4489 size = MAX_PATH;
4490 r = MsiRecordGetString(rec, 1, result, &size);
4491 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4492 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
4494 MsiCloseHandle(rec);
4496 r = MsiViewFetch(view, &rec);
4497 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4499 r = MsiViewClose(view);
4500 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4501 r = MsiCloseHandle(view);
4502 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4504 /* dialog_ and control specified */
4505 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
4506 r = MsiDatabaseOpenView(hdb, query, &view);
4507 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4508 r = MsiViewExecute(view, 0);
4509 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4510 r = MsiViewClose(view);
4511 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4512 r = MsiCloseHandle(view);
4513 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4515 /* check the modified text */
4516 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
4517 r = MsiDatabaseOpenView(hdb, query, &view);
4518 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4519 r = MsiViewExecute(view, 0);
4520 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4522 r = MsiViewFetch(view, &rec);
4523 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4525 size = MAX_PATH;
4526 r = MsiRecordGetString(rec, 1, result, &size);
4527 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4528 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4530 MsiCloseHandle(rec);
4532 r = MsiViewFetch(view, &rec);
4533 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4535 size = MAX_PATH;
4536 r = MsiRecordGetString(rec, 1, result, &size);
4537 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4538 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
4540 MsiCloseHandle(rec);
4542 r = MsiViewFetch(view, &rec);
4543 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4545 r = MsiViewClose(view);
4546 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4547 r = MsiCloseHandle(view);
4548 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4550 /* no where condition */
4551 query = "UPDATE `Control` SET `Text` = 'this is text'";
4552 r = MsiDatabaseOpenView(hdb, query, &view);
4553 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4554 r = MsiViewExecute(view, 0);
4555 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4556 r = MsiViewClose(view);
4557 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4558 r = MsiCloseHandle(view);
4559 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4561 /* check the modified text */
4562 query = "SELECT `Text` FROM `Control`";
4563 r = MsiDatabaseOpenView(hdb, query, &view);
4564 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4565 r = MsiViewExecute(view, 0);
4566 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4568 r = MsiViewFetch(view, &rec);
4569 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4571 size = MAX_PATH;
4572 r = MsiRecordGetString(rec, 1, result, &size);
4573 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4574 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4576 MsiCloseHandle(rec);
4578 r = MsiViewFetch(view, &rec);
4579 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4581 size = MAX_PATH;
4582 r = MsiRecordGetString(rec, 1, result, &size);
4583 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4584 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4586 MsiCloseHandle(rec);
4588 r = MsiViewFetch(view, &rec);
4589 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4591 size = MAX_PATH;
4592 r = MsiRecordGetString(rec, 1, result, &size);
4593 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4594 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4596 MsiCloseHandle(rec);
4598 r = MsiViewFetch(view, &rec);
4599 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4601 r = MsiViewClose(view);
4602 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4603 r = MsiCloseHandle(view);
4604 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4606 query = "CREATE TABLE `Apple` ( `Banana` CHAR(72) NOT NULL, "
4607 "`Orange` CHAR(72), `Pear` INT PRIMARY KEY `Banana`)";
4608 r = run_query(hdb, 0, query);
4609 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4611 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4612 "VALUES('one', 'two', 3)";
4613 r = run_query(hdb, 0, query);
4614 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4616 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4617 "VALUES('three', 'four', 5)";
4618 r = run_query(hdb, 0, query);
4619 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4621 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4622 "VALUES('six', 'two', 7)";
4623 r = run_query(hdb, 0, query);
4624 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4626 rec = MsiCreateRecord(2);
4627 MsiRecordSetInteger(rec, 1, 8);
4628 MsiRecordSetString(rec, 2, "two");
4630 query = "UPDATE `Apple` SET `Pear` = ? WHERE `Orange` = ?";
4631 r = run_query(hdb, rec, query);
4632 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4634 MsiCloseHandle(rec);
4636 query = "SELECT `Pear` FROM `Apple` ORDER BY `Orange`";
4637 r = MsiDatabaseOpenView(hdb, query, &view);
4638 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4639 r = MsiViewExecute(view, 0);
4640 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4642 r = MsiViewFetch(view, &rec);
4643 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4645 r = MsiRecordGetInteger(rec, 1);
4646 ok(r == 8, "Expected 8, got %d\n", r);
4648 MsiCloseHandle(rec);
4650 r = MsiViewFetch(view, &rec);
4651 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4653 r = MsiRecordGetInteger(rec, 1);
4654 ok(r == 8, "Expected 8, got %d\n", r);
4656 MsiCloseHandle(rec);
4658 r = MsiViewFetch(view, &rec);
4659 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4661 r = MsiRecordGetInteger(rec, 1);
4662 ok(r == 5, "Expected 5, got %d\n", r);
4664 MsiCloseHandle(rec);
4666 r = MsiViewFetch(view, &rec);
4667 ok(r == ERROR_NO_MORE_ITEMS, "Expectd ERROR_NO_MORE_ITEMS, got %d\n", r);
4669 MsiViewClose(view);
4670 MsiCloseHandle(view);
4672 r = MsiDatabaseCommit(hdb);
4673 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
4674 r = MsiCloseHandle(hdb);
4675 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4677 DeleteFile(msifile);
4680 static void test_special_tables(void)
4682 const char *query;
4683 MSIHANDLE hdb = 0;
4684 UINT r;
4686 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4687 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4689 query = "CREATE TABLE `_Properties` ( "
4690 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4691 r = run_query(hdb, 0, query);
4692 ok(r == ERROR_SUCCESS, "failed to create table\n");
4694 query = "CREATE TABLE `_Storages` ( "
4695 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4696 r = run_query(hdb, 0, query);
4697 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Streams table\n");
4699 query = "CREATE TABLE `_Streams` ( "
4700 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4701 r = run_query(hdb, 0, query);
4702 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Streams table\n");
4704 query = "CREATE TABLE `_Tables` ( "
4705 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4706 r = run_query(hdb, 0, query);
4707 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Tables table\n");
4709 query = "CREATE TABLE `_Columns` ( "
4710 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4711 r = run_query(hdb, 0, query);
4712 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Columns table\n");
4714 r = MsiCloseHandle(hdb);
4715 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4718 static void test_tables_order(void)
4720 const char *query;
4721 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
4722 UINT r;
4723 char buffer[100];
4724 DWORD sz;
4726 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4727 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4729 query = "CREATE TABLE `foo` ( "
4730 "`baz` INT NOT NULL PRIMARY KEY `baz`)";
4731 r = run_query(hdb, 0, query);
4732 ok(r == ERROR_SUCCESS, "failed to create table\n");
4734 query = "CREATE TABLE `bar` ( "
4735 "`foo` INT NOT NULL PRIMARY KEY `foo`)";
4736 r = run_query(hdb, 0, query);
4737 ok(r == ERROR_SUCCESS, "failed to create table\n");
4739 query = "CREATE TABLE `baz` ( "
4740 "`bar` INT NOT NULL, "
4741 "`baz` INT NOT NULL, "
4742 "`foo` INT NOT NULL PRIMARY KEY `bar`)";
4743 r = run_query(hdb, 0, query);
4744 ok(r == ERROR_SUCCESS, "failed to create table\n");
4746 /* The names of the tables in the _Tables table must
4747 be in the same order as these names are created in
4748 the strings table. */
4749 query = "SELECT * FROM `_Tables`";
4750 r = MsiDatabaseOpenView(hdb, query, &hview);
4751 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4752 r = MsiViewExecute(hview, 0);
4753 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4755 r = MsiViewFetch(hview, &hrec);
4756 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4757 sz = sizeof(buffer);
4758 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4759 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4760 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4761 r = MsiCloseHandle(hrec);
4762 ok(r == ERROR_SUCCESS, "failed to close record\n");
4764 r = MsiViewFetch(hview, &hrec);
4765 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4766 sz = sizeof(buffer);
4767 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4768 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4769 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4770 r = MsiCloseHandle(hrec);
4771 ok(r == ERROR_SUCCESS, "failed to close record\n");
4773 r = MsiViewFetch(hview, &hrec);
4774 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4775 sz = sizeof(buffer);
4776 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4777 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4778 ok(!lstrcmp(buffer, "bar"), "Expected bar, got %s\n", buffer);
4779 r = MsiCloseHandle(hrec);
4780 ok(r == ERROR_SUCCESS, "failed to close record\n");
4782 r = MsiViewClose(hview);
4783 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4784 r = MsiCloseHandle(hview);
4785 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4787 /* The names of the tables in the _Columns table must
4788 be in the same order as these names are created in
4789 the strings table. */
4790 query = "SELECT * FROM `_Columns`";
4791 r = MsiDatabaseOpenView(hdb, query, &hview);
4792 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4793 r = MsiViewExecute(hview, 0);
4794 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4796 r = MsiViewFetch(hview, &hrec);
4797 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4798 sz = sizeof(buffer);
4799 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4800 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4801 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4802 sz = sizeof(buffer);
4803 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4804 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4805 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4806 r = MsiCloseHandle(hrec);
4807 ok(r == ERROR_SUCCESS, "failed to close record\n");
4809 r = MsiViewFetch(hview, &hrec);
4810 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4811 sz = sizeof(buffer);
4812 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4813 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4814 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4815 sz = sizeof(buffer);
4816 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4817 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4818 ok(!lstrcmp(buffer, "bar"), "Expected bar, got %s\n", buffer);
4819 r = MsiCloseHandle(hrec);
4820 ok(r == ERROR_SUCCESS, "failed to close record\n");
4822 r = MsiViewFetch(hview, &hrec);
4823 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4824 sz = sizeof(buffer);
4825 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4826 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4827 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4828 sz = sizeof(buffer);
4829 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4830 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4831 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4832 r = MsiCloseHandle(hrec);
4833 ok(r == ERROR_SUCCESS, "failed to close record\n");
4835 r = MsiViewFetch(hview, &hrec);
4836 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4837 sz = sizeof(buffer);
4838 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4839 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4840 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4841 sz = sizeof(buffer);
4842 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4843 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4844 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4845 r = MsiCloseHandle(hrec);
4846 ok(r == ERROR_SUCCESS, "failed to close record\n");
4848 r = MsiViewFetch(hview, &hrec);
4849 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4850 sz = sizeof(buffer);
4851 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4852 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4853 ok(!lstrcmp(buffer, "bar"), "Expected bar, got %s\n", buffer);
4854 sz = sizeof(buffer);
4855 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4856 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4857 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4858 r = MsiCloseHandle(hrec);
4859 ok(r == ERROR_SUCCESS, "failed to close record\n");
4861 r = MsiViewClose(hview);
4862 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4863 r = MsiCloseHandle(hview);
4864 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4866 r = MsiCloseHandle(hdb);
4867 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4869 DeleteFile(msifile);
4872 static void test_rows_order(void)
4874 const char *query;
4875 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
4876 UINT r;
4877 char buffer[100];
4878 DWORD sz;
4880 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4881 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4883 query = "CREATE TABLE `foo` ( "
4884 "`bar` LONGCHAR NOT NULL PRIMARY KEY `bar`)";
4885 r = run_query(hdb, 0, query);
4886 ok(r == ERROR_SUCCESS, "failed to create table\n");
4888 r = run_query(hdb, 0, "INSERT INTO `foo` "
4889 "( `bar` ) VALUES ( 'A' )");
4890 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4892 r = run_query(hdb, 0, "INSERT INTO `foo` "
4893 "( `bar` ) VALUES ( 'B' )");
4894 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4896 r = run_query(hdb, 0, "INSERT INTO `foo` "
4897 "( `bar` ) VALUES ( 'C' )");
4898 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4900 r = run_query(hdb, 0, "INSERT INTO `foo` "
4901 "( `bar` ) VALUES ( 'D' )");
4902 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4904 r = run_query(hdb, 0, "INSERT INTO `foo` "
4905 "( `bar` ) VALUES ( 'E' )");
4906 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4908 r = run_query(hdb, 0, "INSERT INTO `foo` "
4909 "( `bar` ) VALUES ( 'F' )");
4910 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4912 query = "CREATE TABLE `bar` ( "
4913 "`foo` LONGCHAR NOT NULL, "
4914 "`baz` LONGCHAR NOT NULL "
4915 "PRIMARY KEY `foo` )";
4916 r = run_query(hdb, 0, query);
4917 ok(r == ERROR_SUCCESS, "failed to create table\n");
4919 r = run_query(hdb, 0, "INSERT INTO `bar` "
4920 "( `foo`, `baz` ) VALUES ( 'C', 'E' )");
4921 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4923 r = run_query(hdb, 0, "INSERT INTO `bar` "
4924 "( `foo`, `baz` ) VALUES ( 'F', 'A' )");
4925 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4927 r = run_query(hdb, 0, "INSERT INTO `bar` "
4928 "( `foo`, `baz` ) VALUES ( 'A', 'B' )");
4929 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4931 r = run_query(hdb, 0, "INSERT INTO `bar` "
4932 "( `foo`, `baz` ) VALUES ( 'D', 'E' )");
4933 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4935 /* The rows of the table must be ordered by the column values of
4936 each row. For strings, the column value is the string id
4937 in the string table. */
4939 query = "SELECT * FROM `bar`";
4940 r = MsiDatabaseOpenView(hdb, query, &hview);
4941 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4942 r = MsiViewExecute(hview, 0);
4943 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4945 r = MsiViewFetch(hview, &hrec);
4946 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4947 sz = sizeof(buffer);
4948 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4949 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4950 ok(!lstrcmp(buffer, "A"), "Expected A, got %s\n", buffer);
4951 sz = sizeof(buffer);
4952 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4953 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4954 ok(!lstrcmp(buffer, "B"), "Expected B, got %s\n", buffer);
4955 r = MsiCloseHandle(hrec);
4956 ok(r == ERROR_SUCCESS, "failed to close record\n");
4958 r = MsiViewFetch(hview, &hrec);
4959 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4960 sz = sizeof(buffer);
4961 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4962 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4963 ok(!lstrcmp(buffer, "C"), "Expected E, got %s\n", buffer);
4964 sz = sizeof(buffer);
4965 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4966 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4967 ok(!lstrcmp(buffer, "E"), "Expected E, got %s\n", buffer);
4968 r = MsiCloseHandle(hrec);
4969 ok(r == ERROR_SUCCESS, "failed to close record\n");
4971 r = MsiViewFetch(hview, &hrec);
4972 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4973 sz = sizeof(buffer);
4974 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4975 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4976 ok(!lstrcmp(buffer, "D"), "Expected D, got %s\n", buffer);
4977 sz = sizeof(buffer);
4978 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4979 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4980 ok(!lstrcmp(buffer, "E"), "Expected E, got %s\n", buffer);
4981 r = MsiCloseHandle(hrec);
4982 ok(r == ERROR_SUCCESS, "failed to close record\n");
4984 r = MsiViewFetch(hview, &hrec);
4985 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4986 sz = sizeof(buffer);
4987 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4988 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4989 ok(!lstrcmp(buffer, "F"), "Expected F, got %s\n", buffer);
4990 sz = sizeof(buffer);
4991 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4992 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4993 ok(!lstrcmp(buffer, "A"), "Expected A, got %s\n", buffer);
4994 r = MsiCloseHandle(hrec);
4995 ok(r == ERROR_SUCCESS, "failed to close record\n");
4997 r = MsiViewClose(hview);
4998 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4999 r = MsiCloseHandle(hview);
5000 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5002 r = MsiCloseHandle(hdb);
5003 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5005 DeleteFile(msifile);
5008 static void test_collation(void)
5010 static const WCHAR query1[] =
5011 {'I','N','S','E','R','T',' ','I','N','T','O',' ','`','b','a','r','`',' ',
5012 '(','`','f','o','o','`',',','`','b','a','z','`',')',' ','V','A','L','U','E','S',' ',
5013 '(','\'','a',0x30a,'\'',',','\'','C','\'',')',0};
5014 static const WCHAR query2[] =
5015 {'I','N','S','E','R','T',' ','I','N','T','O',' ','`','b','a','r','`',' ',
5016 '(','`','f','o','o','`',',','`','b','a','z','`',')',' ','V','A','L','U','E','S',' ',
5017 '(','\'',0xe5,'\'',',','\'','D','\'',')',0};
5018 static const WCHAR query3[] =
5019 {'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','b','a','z','`',' ',
5020 '(',' ','`','a',0x30a,'`',' ','L','O','N','G','C','H','A','R',' ','N','O','T',' ','N','U','L','L',',',
5021 ' ','`',0xe5,'`',' ','L','O','N','G','C','H','A','R',' ','N','O','T',' ','N','U','L','L',' ',
5022 'P','R','I','M','A','R','Y',' ','K','E','Y',' ','`','a',0x30a,'`',')',0};
5023 static const WCHAR query4[] =
5024 {'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','a',0x30a,'`',' ',
5025 '(',' ','`','f','o','o','`',' ','L','O','N','G','C','H','A','R',' ','N','O','T',' ',
5026 'N','U','L','L',' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ','`','f','o','o','`',')',0};
5027 static const WCHAR query5[] =
5028 {'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`',0xe5,'`',' ',
5029 '(',' ','`','f','o','o','`',' ','L','O','N','G','C','H','A','R',' ','N','O','T',' ',
5030 'N','U','L','L',' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ','`','f','o','o','`',')',0};
5031 static const WCHAR query6[] =
5032 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','b','a','r','`',' ','W','H','E','R','E',
5033 ' ','`','f','o','o','`',' ','=','\'',0xe5,'\'',0};
5034 static const WCHAR letter_C[] = {'C',0};
5035 static const WCHAR letter_D[] = {'D',0};
5036 static const WCHAR letter_a_ring[] = {'a',0x30a,0};
5037 static const WCHAR letter_a_with_ring[] = {0xe5,0};
5038 const char *query;
5039 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5040 UINT r;
5041 char buffer[100];
5042 WCHAR bufferW[100];
5043 DWORD sz;
5045 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5046 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
5048 query = "CREATE TABLE `bar` ( "
5049 "`foo` LONGCHAR NOT NULL, "
5050 "`baz` LONGCHAR NOT NULL "
5051 "PRIMARY KEY `foo` )";
5052 r = run_query(hdb, 0, query);
5053 ok(r == ERROR_SUCCESS, "failed to create table\n");
5055 r = run_query(hdb, 0, query);
5056 ok(r == ERROR_BAD_QUERY_SYNTAX, "wrong error %u\n", r);
5058 r = run_query(hdb, 0, "INSERT INTO `bar` "
5059 "( `foo`, `baz` ) VALUES ( '\2', 'A' )");
5060 ok(r == ERROR_SUCCESS, "cannot add value to table %u\n", r);
5062 r = run_query(hdb, 0, "INSERT INTO `bar` "
5063 "( `foo`, `baz` ) VALUES ( '\1', 'B' )");
5064 ok(r == ERROR_SUCCESS, "cannot add value to table %u\n", r);
5066 r = run_queryW(hdb, 0, query1);
5067 ok(r == ERROR_SUCCESS, "cannot add value to table %u\n", r);
5069 r = run_queryW(hdb, 0, query2);
5070 ok(r == ERROR_SUCCESS, "cannot add value to table %u\n", r);
5072 r = run_queryW(hdb, 0, query3);
5073 ok(r == ERROR_SUCCESS, "cannot create table %u\n", r);
5075 r = run_queryW(hdb, 0, query4);
5076 ok(r == ERROR_SUCCESS, "cannot create table %u\n", r);
5078 r = run_queryW(hdb, 0, query5);
5079 ok(r == ERROR_SUCCESS, "cannot create table %u\n", r);
5081 query = "SELECT * FROM `bar`";
5082 r = MsiDatabaseOpenView(hdb, query, &hview);
5083 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5084 r = MsiViewExecute(hview, 0);
5085 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5087 r = MsiViewFetch(hview, &hrec);
5088 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5089 sz = sizeof(buffer);
5090 r = MsiRecordGetString(hrec, 1, buffer, &sz);
5091 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5092 ok(!lstrcmp(buffer, "\2"), "Expected \\2, got '%s'\n", buffer);
5093 sz = sizeof(buffer);
5094 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5095 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5096 ok(!lstrcmp(buffer, "A"), "Expected A, got '%s'\n", buffer);
5097 MsiCloseHandle(hrec);
5099 r = MsiViewFetch(hview, &hrec);
5100 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5101 sz = sizeof(buffer);
5102 r = MsiRecordGetString(hrec, 1, buffer, &sz);
5103 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5104 ok(!lstrcmp(buffer, "\1"), "Expected \\1, got '%s'\n", buffer);
5105 sz = sizeof(buffer);
5106 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5107 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5108 ok(!lstrcmp(buffer, "B"), "Expected B, got '%s'\n", buffer);
5109 MsiCloseHandle(hrec);
5111 r = MsiViewFetch(hview, &hrec);
5112 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5113 sz = sizeof(bufferW) / sizeof(bufferW[0]);
5114 r = MsiRecordGetStringW(hrec, 1, bufferW, &sz);
5115 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5116 ok(!memcmp(bufferW, letter_a_ring, sizeof(letter_a_ring)),
5117 "Expected %s, got %s\n", wine_dbgstr_w(letter_a_ring), wine_dbgstr_w(bufferW));
5118 sz = sizeof(bufferW) / sizeof(bufferW[0]);
5119 r = MsiRecordGetStringW(hrec, 2, bufferW, &sz);
5120 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5121 ok(!lstrcmpW(bufferW, letter_C), "Expected C, got %s\n", wine_dbgstr_w(bufferW));
5122 MsiCloseHandle(hrec);
5124 r = MsiViewFetch(hview, &hrec);
5125 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5126 sz = sizeof(bufferW) / sizeof(bufferW[0]);
5127 r = MsiRecordGetStringW(hrec, 1, bufferW, &sz);
5128 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5129 ok(!memcmp(bufferW, letter_a_with_ring, sizeof(letter_a_with_ring)),
5130 "Expected %s, got %s\n", wine_dbgstr_w(letter_a_with_ring), wine_dbgstr_w(bufferW));
5131 sz = sizeof(bufferW) / sizeof(bufferW[0]);
5132 r = MsiRecordGetStringW(hrec, 2, bufferW, &sz);
5133 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5134 ok(!lstrcmpW(bufferW, letter_D), "Expected D, got %s\n", wine_dbgstr_w(bufferW));
5135 MsiCloseHandle(hrec);
5137 r = MsiViewClose(hview);
5138 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5139 r = MsiCloseHandle(hview);
5140 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5142 r = MsiDatabaseOpenViewW(hdb, query6, &hview);
5143 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5144 r = MsiViewExecute(hview, 0);
5145 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5147 r = MsiViewFetch(hview, &hrec);
5148 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5149 sz = sizeof(bufferW) / sizeof(bufferW[0]);
5150 r = MsiRecordGetStringW(hrec, 1, bufferW, &sz);
5151 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5152 ok(!memcmp(bufferW, letter_a_with_ring, sizeof(letter_a_with_ring)),
5153 "Expected %s, got %s\n", wine_dbgstr_w(letter_a_with_ring), wine_dbgstr_w(bufferW));
5154 sz = sizeof(bufferW) / sizeof(bufferW[0]);
5155 r = MsiRecordGetStringW(hrec, 2, bufferW, &sz);
5156 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5157 ok(!lstrcmpW(bufferW, letter_D), "Expected D, got %s\n", wine_dbgstr_w(bufferW));
5158 MsiCloseHandle(hrec);
5160 r = MsiViewFetch(hview, &hrec);
5161 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
5163 r = MsiViewClose(hview);
5164 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5165 r = MsiCloseHandle(hview);
5166 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5168 r = MsiCloseHandle(hdb);
5169 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5171 DeleteFile(msifile);
5174 static void test_select_markers(void)
5176 MSIHANDLE hdb = 0, rec, view, res;
5177 LPCSTR query;
5178 UINT r;
5179 DWORD size;
5180 CHAR buf[MAX_PATH];
5182 hdb = create_db();
5183 ok( hdb, "failed to create db\n");
5185 r = run_query(hdb, 0,
5186 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
5187 ok(r == S_OK, "cannot create table: %d\n", r);
5189 r = run_query(hdb, 0, "INSERT INTO `Table` "
5190 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
5191 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
5193 r = run_query(hdb, 0, "INSERT INTO `Table` "
5194 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
5195 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
5197 r = run_query(hdb, 0, "INSERT INTO `Table` "
5198 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
5199 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
5201 r = run_query(hdb, 0, "INSERT INTO `Table` "
5202 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
5203 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
5205 rec = MsiCreateRecord(2);
5206 MsiRecordSetString(rec, 1, "apple");
5207 MsiRecordSetString(rec, 2, "two");
5209 query = "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
5210 r = MsiDatabaseOpenView(hdb, query, &view);
5211 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5213 r = MsiViewExecute(view, rec);
5214 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5216 r = MsiViewFetch(view, &res);
5217 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5219 size = MAX_PATH;
5220 r = MsiRecordGetString(res, 1, buf, &size);
5221 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5222 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
5224 size = MAX_PATH;
5225 r = MsiRecordGetString(res, 2, buf, &size);
5226 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5227 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
5229 r = MsiRecordGetInteger(res, 3);
5230 ok(r == 1, "Expected 1, got %d\n", r);
5232 MsiCloseHandle(res);
5234 r = MsiViewFetch(view, &res);
5235 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5237 size = MAX_PATH;
5238 r = MsiRecordGetString(res, 1, buf, &size);
5239 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5240 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
5242 size = MAX_PATH;
5243 r = MsiRecordGetString(res, 2, buf, &size);
5244 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5245 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
5247 r = MsiRecordGetInteger(res, 3);
5248 ok(r == 2, "Expected 2, got %d\n", r);
5250 MsiCloseHandle(res);
5252 r = MsiViewFetch(view, &res);
5253 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5255 MsiCloseHandle(rec);
5256 MsiViewClose(view);
5257 MsiCloseHandle(view);
5259 rec = MsiCreateRecord(2);
5260 MsiRecordSetString(rec, 1, "one");
5261 MsiRecordSetInteger(rec, 2, 1);
5263 query = "SELECT * FROM `Table` WHERE `Two`<>? AND `Three`>? ORDER BY `Three`";
5264 r = MsiDatabaseOpenView(hdb, query, &view);
5265 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5266 r = MsiViewExecute(view, rec);
5267 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5269 r = MsiViewFetch(view, &res);
5270 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5272 size = MAX_PATH;
5273 r = MsiRecordGetString(res, 1, buf, &size);
5274 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5275 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
5277 size = MAX_PATH;
5278 r = MsiRecordGetString(res, 2, buf, &size);
5279 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5280 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
5282 r = MsiRecordGetInteger(res, 3);
5283 ok(r == 2, "Expected 2, got %d\n", r);
5285 MsiCloseHandle(res);
5287 r = MsiViewFetch(view, &res);
5288 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5290 size = MAX_PATH;
5291 r = MsiRecordGetString(res, 1, buf, &size);
5292 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5293 ok(!lstrcmp(buf, "banana"), "Expected banana, got %s\n", buf);
5295 size = MAX_PATH;
5296 r = MsiRecordGetString(res, 2, buf, &size);
5297 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5298 ok(!lstrcmp(buf, "three"), "Expected three, got %s\n", buf);
5300 r = MsiRecordGetInteger(res, 3);
5301 ok(r == 3, "Expected 3, got %d\n", r);
5303 MsiCloseHandle(res);
5305 r = MsiViewFetch(view, &res);
5306 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5308 MsiCloseHandle(rec);
5309 MsiViewClose(view);
5310 MsiCloseHandle(view);
5311 MsiCloseHandle(hdb);
5312 DeleteFile(msifile);
5315 static void test_viewmodify_update(void)
5317 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5318 UINT i, test_max, offset, count;
5319 const char *query;
5320 UINT r;
5322 DeleteFile(msifile);
5324 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5325 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
5327 query = "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
5328 r = run_query( hdb, 0, query );
5329 ok(r == ERROR_SUCCESS, "query failed\n");
5331 query = "INSERT INTO `table` (`A`, `B`) VALUES (1, 2)";
5332 r = run_query( hdb, 0, query );
5333 ok(r == ERROR_SUCCESS, "query failed\n");
5335 query = "INSERT INTO `table` (`A`, `B`) VALUES (3, 4)";
5336 r = run_query( hdb, 0, query );
5337 ok(r == ERROR_SUCCESS, "query failed\n");
5339 query = "INSERT INTO `table` (`A`, `B`) VALUES (5, 6)";
5340 r = run_query( hdb, 0, query );
5341 ok(r == ERROR_SUCCESS, "query failed\n");
5343 query = "SELECT `B` FROM `table`";
5344 r = MsiDatabaseOpenView(hdb, query, &hview);
5345 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5346 r = MsiViewExecute(hview, 0);
5347 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5348 r = MsiViewFetch(hview, &hrec);
5349 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5351 r = MsiRecordSetInteger(hrec, 1, 0);
5352 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5354 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
5355 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5357 r = MsiCloseHandle(hrec);
5358 ok(r == ERROR_SUCCESS, "failed to close record\n");
5360 r = MsiViewClose(hview);
5361 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5362 r = MsiCloseHandle(hview);
5363 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5365 query = "SELECT * FROM `table`";
5366 r = MsiDatabaseOpenView(hdb, query, &hview);
5367 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5368 r = MsiViewExecute(hview, 0);
5369 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5370 r = MsiViewFetch(hview, &hrec);
5371 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5373 r = MsiRecordGetInteger(hrec, 1);
5374 ok(r == 1, "Expected 1, got %d\n", r);
5375 r = MsiRecordGetInteger(hrec, 2);
5376 ok(r == 0, "Expected 0, got %d\n", r);
5378 r = MsiCloseHandle(hrec);
5379 ok(r == ERROR_SUCCESS, "failed to close record\n");
5381 r = MsiViewFetch(hview, &hrec);
5382 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5384 r = MsiRecordGetInteger(hrec, 1);
5385 ok(r == 3, "Expected 3, got %d\n", r);
5386 r = MsiRecordGetInteger(hrec, 2);
5387 ok(r == 4, "Expected 4, got %d\n", r);
5389 r = MsiCloseHandle(hrec);
5390 ok(r == ERROR_SUCCESS, "failed to close record\n");
5392 r = MsiViewFetch(hview, &hrec);
5393 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5395 r = MsiRecordGetInteger(hrec, 1);
5396 ok(r == 5, "Expected 5, got %d\n", r);
5397 r = MsiRecordGetInteger(hrec, 2);
5398 ok(r == 6, "Expected 6, got %d\n", r);
5400 r = MsiCloseHandle(hrec);
5401 ok(r == ERROR_SUCCESS, "failed to close record\n");
5403 r = MsiViewFetch(hview, &hrec);
5404 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5406 r = MsiViewClose(hview);
5407 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5408 r = MsiCloseHandle(hview);
5409 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5411 /* loop through all elements */
5412 query = "SELECT `B` FROM `table`";
5413 r = MsiDatabaseOpenView(hdb, query, &hview);
5414 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5415 r = MsiViewExecute(hview, 0);
5416 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5418 while (TRUE)
5420 r = MsiViewFetch(hview, &hrec);
5421 if (r != ERROR_SUCCESS)
5422 break;
5424 r = MsiRecordSetInteger(hrec, 1, 0);
5425 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5427 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
5428 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5430 r = MsiCloseHandle(hrec);
5431 ok(r == ERROR_SUCCESS, "failed to close record\n");
5434 r = MsiViewClose(hview);
5435 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5436 r = MsiCloseHandle(hview);
5437 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5439 query = "SELECT * FROM `table`";
5440 r = MsiDatabaseOpenView(hdb, query, &hview);
5441 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5442 r = MsiViewExecute(hview, 0);
5443 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5444 r = MsiViewFetch(hview, &hrec);
5445 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5447 r = MsiRecordGetInteger(hrec, 1);
5448 ok(r == 1, "Expected 1, got %d\n", r);
5449 r = MsiRecordGetInteger(hrec, 2);
5450 ok(r == 0, "Expected 0, got %d\n", r);
5452 r = MsiCloseHandle(hrec);
5453 ok(r == ERROR_SUCCESS, "failed to close record\n");
5455 r = MsiViewFetch(hview, &hrec);
5456 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5458 r = MsiRecordGetInteger(hrec, 1);
5459 ok(r == 3, "Expected 3, got %d\n", r);
5460 r = MsiRecordGetInteger(hrec, 2);
5461 ok(r == 0, "Expected 0, got %d\n", r);
5463 r = MsiCloseHandle(hrec);
5464 ok(r == ERROR_SUCCESS, "failed to close record\n");
5466 r = MsiViewFetch(hview, &hrec);
5467 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5469 r = MsiRecordGetInteger(hrec, 1);
5470 ok(r == 5, "Expected 5, got %d\n", r);
5471 r = MsiRecordGetInteger(hrec, 2);
5472 ok(r == 0, "Expected 0, got %d\n", r);
5474 r = MsiCloseHandle(hrec);
5475 ok(r == ERROR_SUCCESS, "failed to close record\n");
5477 r = MsiViewFetch(hview, &hrec);
5478 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5480 r = MsiViewClose(hview);
5481 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5482 r = MsiCloseHandle(hview);
5483 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5485 query = "CREATE TABLE `table2` (`A` INT, `B` INT PRIMARY KEY `A`)";
5486 r = run_query( hdb, 0, query );
5487 ok(r == ERROR_SUCCESS, "query failed\n");
5489 query = "INSERT INTO `table2` (`A`, `B`) VALUES (?, ?)";
5490 r = MsiDatabaseOpenView( hdb, query, &hview );
5491 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5493 test_max = 100;
5494 offset = 1234;
5495 for(i = 0; i < test_max; i++)
5498 hrec = MsiCreateRecord( 2 );
5499 MsiRecordSetInteger( hrec, 1, test_max - i );
5500 MsiRecordSetInteger( hrec, 2, i );
5502 r = MsiViewExecute( hview, hrec );
5503 ok(r == ERROR_SUCCESS, "Got %d\n", r);
5505 r = MsiCloseHandle( hrec );
5506 ok(r == ERROR_SUCCESS, "Got %d\n", r);
5509 r = MsiViewClose( hview );
5510 ok(r == ERROR_SUCCESS, "Got %d\n", r);
5511 r = MsiCloseHandle( hview );
5512 ok(r == ERROR_SUCCESS, "Got %d\n", r);
5514 /* Update. */
5515 query = "SELECT * FROM `table2` ORDER BY `B`";
5516 r = MsiDatabaseOpenView( hdb, query, &hview);
5517 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5518 r = MsiViewExecute( hview, 0 );
5519 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5521 count = 0;
5522 while (MsiViewFetch( hview, &hrec ) == ERROR_SUCCESS)
5524 UINT b = MsiRecordGetInteger( hrec, 2 );
5526 r = MsiRecordSetInteger( hrec, 2, b + offset);
5527 ok(r == ERROR_SUCCESS, "Got %d\n", r);
5529 r = MsiViewModify( hview, MSIMODIFY_UPDATE, hrec );
5530 ok(r == ERROR_SUCCESS, "Got %d\n", r);
5532 r = MsiCloseHandle(hrec);
5533 ok(r == ERROR_SUCCESS, "failed to close record\n");
5534 count++;
5536 ok(count == test_max, "Got count %d\n", count);
5538 r = MsiViewClose(hview);
5539 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5540 r = MsiCloseHandle(hview);
5541 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5543 /* Recheck. */
5544 query = "SELECT * FROM `table2` ORDER BY `B`";
5545 r = MsiDatabaseOpenView( hdb, query, &hview);
5546 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5547 r = MsiViewExecute( hview, 0 );
5548 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5550 count = 0;
5551 while (MsiViewFetch( hview, &hrec ) == ERROR_SUCCESS)
5553 UINT a = MsiRecordGetInteger( hrec, 1 );
5554 UINT b = MsiRecordGetInteger( hrec, 2 );
5555 ok( ( test_max - a + offset) == b, "Got (%d, %d), expected (%d, %d)\n",
5556 a, b, test_max - a + offset, b);
5558 r = MsiCloseHandle(hrec);
5559 ok(r == ERROR_SUCCESS, "failed to close record\n");
5560 count++;
5562 ok(count == test_max, "Got count %d\n", count);
5564 r = MsiViewClose(hview);
5565 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5566 r = MsiCloseHandle(hview);
5567 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5569 r = MsiCloseHandle( hdb );
5570 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
5573 static void test_viewmodify_assign(void)
5575 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5576 const char *query;
5577 UINT r;
5579 /* setup database */
5580 DeleteFile(msifile);
5582 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5583 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
5585 query = "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
5586 r = run_query( hdb, 0, query );
5587 ok(r == ERROR_SUCCESS, "query failed\n");
5589 /* assign to view, new primary key */
5590 query = "SELECT * FROM `table`";
5591 r = MsiDatabaseOpenView(hdb, query, &hview);
5592 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5593 r = MsiViewExecute(hview, 0);
5594 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5596 hrec = MsiCreateRecord(2);
5597 ok(hrec != 0, "MsiCreateRecord failed\n");
5599 r = MsiRecordSetInteger(hrec, 1, 1);
5600 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5601 r = MsiRecordSetInteger(hrec, 2, 2);
5602 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5604 r = MsiViewModify(hview, MSIMODIFY_ASSIGN, hrec);
5605 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5607 r = MsiCloseHandle(hrec);
5608 ok(r == ERROR_SUCCESS, "failed to close record\n");
5610 r = MsiViewClose(hview);
5611 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5612 r = MsiCloseHandle(hview);
5613 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5615 query = "SELECT * FROM `table`";
5616 r = MsiDatabaseOpenView(hdb, query, &hview);
5617 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5618 r = MsiViewExecute(hview, 0);
5619 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5620 r = MsiViewFetch(hview, &hrec);
5621 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5623 r = MsiRecordGetInteger(hrec, 1);
5624 ok(r == 1, "Expected 1, got %d\n", r);
5625 r = MsiRecordGetInteger(hrec, 2);
5626 ok(r == 2, "Expected 2, got %d\n", r);
5628 r = MsiCloseHandle(hrec);
5629 ok(r == ERROR_SUCCESS, "failed to close record\n");
5631 r = MsiViewFetch(hview, &hrec);
5632 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5634 r = MsiViewClose(hview);
5635 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5636 r = MsiCloseHandle(hview);
5637 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5639 /* assign to view, primary key matches */
5640 query = "SELECT * FROM `table`";
5641 r = MsiDatabaseOpenView(hdb, query, &hview);
5642 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5643 r = MsiViewExecute(hview, 0);
5644 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5646 hrec = MsiCreateRecord(2);
5647 ok(hrec != 0, "MsiCreateRecord failed\n");
5649 r = MsiRecordSetInteger(hrec, 1, 1);
5650 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5651 r = MsiRecordSetInteger(hrec, 2, 4);
5652 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5654 r = MsiViewModify(hview, MSIMODIFY_ASSIGN, hrec);
5655 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5657 r = MsiCloseHandle(hrec);
5658 ok(r == ERROR_SUCCESS, "failed to close record\n");
5660 r = MsiViewClose(hview);
5661 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5662 r = MsiCloseHandle(hview);
5663 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5665 query = "SELECT * FROM `table`";
5666 r = MsiDatabaseOpenView(hdb, query, &hview);
5667 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5668 r = MsiViewExecute(hview, 0);
5669 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5670 r = MsiViewFetch(hview, &hrec);
5671 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5673 r = MsiRecordGetInteger(hrec, 1);
5674 ok(r == 1, "Expected 1, got %d\n", r);
5675 r = MsiRecordGetInteger(hrec, 2);
5676 ok(r == 4, "Expected 4, got %d\n", r);
5678 r = MsiCloseHandle(hrec);
5679 ok(r == ERROR_SUCCESS, "failed to close record\n");
5681 r = MsiViewFetch(hview, &hrec);
5682 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5684 r = MsiViewClose(hview);
5685 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5686 r = MsiCloseHandle(hview);
5687 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5689 /* close database */
5690 r = MsiCloseHandle( hdb );
5691 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
5694 static const WCHAR data10[] = { /* MOO */
5695 0x8001, 0x000b,
5697 static const WCHAR data11[] = { /* AAR */
5698 0x8002, 0x8005,
5699 0x000c, 0x000f,
5701 static const char data12[] = /* _StringData */
5702 "MOOABAARCDonetwofourfive";
5703 static const WCHAR data13[] = { /* _StringPool */
5704 /* len, refs */
5705 0, 0, /* string 0 '' */
5706 0, 0, /* string 1 '' */
5707 0, 0, /* string 2 '' */
5708 0, 0, /* string 3 '' */
5709 0, 0, /* string 4 '' */
5710 3, 3, /* string 5 'MOO' */
5711 1, 1, /* string 6 'A' */
5712 1, 1, /* string 7 'B' */
5713 3, 3, /* string 8 'AAR' */
5714 1, 1, /* string 9 'C' */
5715 1, 1, /* string a 'D' */
5716 3, 1, /* string b 'one' */
5717 3, 1, /* string c 'two' */
5718 0, 0, /* string d '' */
5719 4, 1, /* string e 'four' */
5720 4, 1, /* string f 'five' */
5723 static void test_stringtable(void)
5725 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5726 IStorage *stg = NULL;
5727 IStream *stm;
5728 WCHAR name[0x20];
5729 HRESULT hr;
5730 const char *query;
5731 char buffer[MAX_PATH];
5732 WCHAR data[MAX_PATH];
5733 DWORD sz, read;
5734 UINT r;
5736 static const DWORD mode = STGM_DIRECT | STGM_READ | STGM_SHARE_DENY_WRITE;
5737 static const WCHAR stringdata[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0}; /* _StringData */
5738 static const WCHAR stringpool[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0}; /* _StringPool */
5739 static const WCHAR moo[] = {0x4840, 0x3e16, 0x4818, 0}; /* MOO */
5740 static const WCHAR aar[] = {0x4840, 0x3a8a, 0x481b, 0}; /* AAR */
5742 DeleteFile(msifile);
5744 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5745 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5747 query = "CREATE TABLE `MOO` (`A` INT, `B` CHAR(72) PRIMARY KEY `A`)";
5748 r = run_query(hdb, 0, query);
5749 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5751 query = "CREATE TABLE `AAR` (`C` INT, `D` CHAR(72) PRIMARY KEY `C`)";
5752 r = run_query(hdb, 0, query);
5753 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5755 /* insert persistent row */
5756 query = "INSERT INTO `MOO` (`A`, `B`) VALUES (1, 'one')";
5757 r = run_query(hdb, 0, query);
5758 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5760 /* insert persistent row */
5761 query = "INSERT INTO `AAR` (`C`, `D`) VALUES (2, 'two')";
5762 r = run_query(hdb, 0, query);
5763 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5765 /* open a view */
5766 query = "SELECT * FROM `MOO`";
5767 r = MsiDatabaseOpenView(hdb, query, &hview);
5768 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5769 r = MsiViewExecute(hview, 0);
5770 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5772 hrec = MsiCreateRecord(2);
5774 r = MsiRecordSetInteger(hrec, 1, 3);
5775 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5776 r = MsiRecordSetString(hrec, 2, "three");
5777 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5779 /* insert a nonpersistent row */
5780 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
5781 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5783 r = MsiCloseHandle(hrec);
5784 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5785 r = MsiViewClose(hview);
5786 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5787 r = MsiCloseHandle(hview);
5788 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5790 /* insert persistent row */
5791 query = "INSERT INTO `MOO` (`A`, `B`) VALUES (4, 'four')";
5792 r = run_query(hdb, 0, query);
5793 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5795 /* insert persistent row */
5796 query = "INSERT INTO `AAR` (`C`, `D`) VALUES (5, 'five')";
5797 r = run_query(hdb, 0, query);
5798 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5800 r = MsiDatabaseCommit(hdb);
5801 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5803 r = MsiCloseHandle(hdb);
5804 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5806 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
5807 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5809 query = "SELECT * FROM `MOO`";
5810 r = MsiDatabaseOpenView(hdb, query, &hview);
5811 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5813 r = MsiViewExecute(hview, 0);
5814 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5816 r = MsiViewFetch(hview, &hrec);
5817 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5819 r = MsiRecordGetFieldCount(hrec);
5820 ok(r == 2, "Expected 2, got %d\n", r);
5822 r = MsiRecordGetInteger(hrec, 1);
5823 ok(r == 1, "Expected 1, got %d\n", r);
5825 sz = sizeof(buffer);
5826 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5827 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5828 ok(!lstrcmp(buffer, "one"), "Expected one, got '%s'\n", buffer);
5830 r = MsiCloseHandle(hrec);
5831 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5833 r = MsiViewFetch(hview, &hrec);
5834 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5836 r = MsiViewClose(hview);
5837 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5838 r = MsiCloseHandle(hview);
5839 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5840 r = MsiCloseHandle(hrec);
5841 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5843 query = "SELECT * FROM `AAR`";
5844 r = MsiDatabaseOpenView(hdb, query, &hview);
5845 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5847 r = MsiViewExecute(hview, 0);
5848 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5850 r = MsiViewFetch(hview, &hrec);
5851 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5853 r = MsiRecordGetFieldCount(hrec);
5854 ok(r == 2, "Expected 2, got %d\n", r);
5856 r = MsiRecordGetInteger(hrec, 1);
5857 ok(r == 2, "Expected 2, got %d\n", r);
5859 sz = sizeof(buffer);
5860 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5861 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5862 ok(!lstrcmp(buffer, "two"), "Expected two, got '%s'\n", buffer);
5864 r = MsiCloseHandle(hrec);
5865 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5867 r = MsiViewFetch(hview, &hrec);
5868 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5870 r = MsiRecordGetFieldCount(hrec);
5871 ok(r == 2, "Expected 2, got %d\n", r);
5873 r = MsiRecordGetInteger(hrec, 1);
5874 ok(r == 5, "Expected 5, got %d\n", r);
5876 sz = sizeof(buffer);
5877 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5878 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5879 ok(!lstrcmp(buffer, "five"), "Expected five, got '%s'\n", buffer);
5881 r = MsiCloseHandle(hrec);
5882 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5884 r = MsiViewFetch(hview, &hrec);
5885 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5887 r = MsiViewClose(hview);
5888 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5889 r = MsiCloseHandle(hview);
5890 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5891 r = MsiCloseHandle(hrec);
5892 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5893 r = MsiCloseHandle(hdb);
5894 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5896 MultiByteToWideChar(CP_ACP, 0, msifile, -1, name, 0x20);
5897 hr = StgOpenStorage(name, NULL, mode, NULL, 0, &stg);
5898 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5899 ok(stg != NULL, "Expected non-NULL storage\n");
5901 hr = IStorage_OpenStream(stg, moo, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5902 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5903 ok(stm != NULL, "Expected non-NULL stream\n");
5905 hr = IStream_Read(stm, data, MAX_PATH, &read);
5906 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5907 ok(read == 4, "Expected 4, got %d\n", read);
5908 todo_wine ok(!memcmp(data, data10, read), "Unexpected data\n");
5910 hr = IStream_Release(stm);
5911 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5913 hr = IStorage_OpenStream(stg, aar, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5914 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5915 ok(stm != NULL, "Expected non-NULL stream\n");
5917 hr = IStream_Read(stm, data, MAX_PATH, &read);
5918 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5919 ok(read == 8, "Expected 8, got %d\n", read);
5920 todo_wine
5922 ok(!memcmp(data, data11, read), "Unexpected data\n");
5925 hr = IStream_Release(stm);
5926 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5928 hr = IStorage_OpenStream(stg, stringdata, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5929 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5930 ok(stm != NULL, "Expected non-NULL stream\n");
5932 hr = IStream_Read(stm, buffer, MAX_PATH, &read);
5933 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5934 ok(read == 24, "Expected 24, got %d\n", read);
5935 ok(!memcmp(buffer, data12, read), "Unexpected data\n");
5937 hr = IStream_Release(stm);
5938 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5940 hr = IStorage_OpenStream(stg, stringpool, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5941 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5942 ok(stm != NULL, "Expected non-NULL stream\n");
5944 hr = IStream_Read(stm, data, MAX_PATH, &read);
5945 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5946 todo_wine
5948 ok(read == 64, "Expected 64, got %d\n", read);
5949 ok(!memcmp(data, data13, read), "Unexpected data\n");
5952 hr = IStream_Release(stm);
5953 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5955 hr = IStorage_Release(stg);
5956 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5958 DeleteFileA(msifile);
5961 static void test_viewmodify_delete(void)
5963 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5964 UINT r;
5965 const char *query;
5966 char buffer[0x100];
5967 DWORD sz;
5969 DeleteFile(msifile);
5971 /* just MsiOpenDatabase should not create a file */
5972 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5973 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5975 query = "CREATE TABLE `phone` ( "
5976 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
5977 "PRIMARY KEY `id`)";
5978 r = run_query(hdb, 0, query);
5979 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5981 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
5982 "VALUES('1', 'Alan', '5030581')";
5983 r = run_query(hdb, 0, query);
5984 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5986 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
5987 "VALUES('2', 'Barry', '928440')";
5988 r = run_query(hdb, 0, query);
5989 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5991 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
5992 "VALUES('3', 'Cindy', '2937550')";
5993 r = run_query(hdb, 0, query);
5994 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5996 query = "SELECT * FROM `phone` WHERE `id` <= 2";
5997 r = MsiDatabaseOpenView(hdb, query, &hview);
5998 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5999 r = MsiViewExecute(hview, 0);
6000 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6001 r = MsiViewFetch(hview, &hrec);
6002 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6004 /* delete 1 */
6005 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
6006 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6008 r = MsiCloseHandle(hrec);
6009 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6010 r = MsiViewFetch(hview, &hrec);
6011 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6013 /* delete 2 */
6014 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
6015 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6017 r = MsiCloseHandle(hrec);
6018 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6019 r = MsiViewClose(hview);
6020 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6021 r = MsiCloseHandle(hview);
6022 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6024 query = "SELECT * FROM `phone`";
6025 r = MsiDatabaseOpenView(hdb, query, &hview);
6026 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6027 r = MsiViewExecute(hview, 0);
6028 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6029 r = MsiViewFetch(hview, &hrec);
6030 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6032 r = MsiRecordGetInteger(hrec, 1);
6033 ok(r == 3, "Expected 3, got %d\n", r);
6035 sz = sizeof(buffer);
6036 r = MsiRecordGetString(hrec, 2, buffer, &sz);
6037 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6038 ok(!lstrcmp(buffer, "Cindy"), "Expected Cindy, got %s\n", buffer);
6040 sz = sizeof(buffer);
6041 r = MsiRecordGetString(hrec, 3, buffer, &sz);
6042 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6043 ok(!lstrcmp(buffer, "2937550"), "Expected 2937550, got %s\n", buffer);
6045 r = MsiCloseHandle(hrec);
6046 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6048 r = MsiViewFetch(hview, &hrec);
6049 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6051 r = MsiViewClose(hview);
6052 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6053 r = MsiCloseHandle(hview);
6054 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6055 r = MsiCloseHandle(hdb);
6056 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6059 static const WCHAR _Tables[] = {0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0};
6060 static const WCHAR _StringData[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0};
6061 static const WCHAR _StringPool[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0};
6063 static const WCHAR data14[] = { /* _StringPool */
6064 /* len, refs */
6065 0, 0, /* string 0 '' */
6068 static const struct {
6069 LPCWSTR name;
6070 const void *data;
6071 DWORD size;
6072 } database_table_data[] =
6074 {_Tables, NULL, 0},
6075 {_StringData, NULL, 0},
6076 {_StringPool, data14, sizeof data14},
6079 static void enum_stream_names(IStorage *stg)
6081 IEnumSTATSTG *stgenum = NULL;
6082 IStream *stm;
6083 HRESULT hr;
6084 STATSTG stat;
6085 ULONG n, count;
6086 BYTE data[MAX_PATH];
6087 BYTE check[MAX_PATH];
6088 DWORD sz;
6090 memset(check, 'a', MAX_PATH);
6092 hr = IStorage_EnumElements(stg, 0, NULL, 0, &stgenum);
6093 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
6095 n = 0;
6096 while(TRUE)
6098 count = 0;
6099 hr = IEnumSTATSTG_Next(stgenum, 1, &stat, &count);
6100 if(FAILED(hr) || !count)
6101 break;
6103 ok(!lstrcmpW(stat.pwcsName, database_table_data[n].name),
6104 "Expected table %d name to match\n", n);
6106 stm = NULL;
6107 hr = IStorage_OpenStream(stg, stat.pwcsName, NULL,
6108 STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
6109 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
6110 ok(stm != NULL, "Expected non-NULL stream\n");
6112 CoTaskMemFree(stat.pwcsName);
6114 sz = MAX_PATH;
6115 memset(data, 'a', MAX_PATH);
6116 hr = IStream_Read(stm, data, sz, &count);
6117 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
6119 ok(count == database_table_data[n].size,
6120 "Expected %d, got %d\n", database_table_data[n].size, count);
6122 if (!database_table_data[n].size)
6123 ok(!memcmp(data, check, MAX_PATH), "data should not be changed\n");
6124 else
6125 ok(!memcmp(data, database_table_data[n].data, database_table_data[n].size),
6126 "Expected table %d data to match\n", n);
6128 IStream_Release(stm);
6129 n++;
6132 ok(n == 3, "Expected 3, got %d\n", n);
6134 IEnumSTATSTG_Release(stgenum);
6137 static void test_defaultdatabase(void)
6139 UINT r;
6140 HRESULT hr;
6141 MSIHANDLE hdb;
6142 IStorage *stg = NULL;
6144 DeleteFile(msifile);
6146 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6147 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6149 r = MsiDatabaseCommit(hdb);
6150 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6152 MsiCloseHandle(hdb);
6154 hr = StgOpenStorage(msifileW, NULL, STGM_READ | STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
6155 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
6156 ok(stg != NULL, "Expected non-NULL stg\n");
6158 enum_stream_names(stg);
6160 IStorage_Release(stg);
6161 DeleteFileA(msifile);
6164 static void test_order(void)
6166 MSIHANDLE hdb, hview, hrec;
6167 CHAR buffer[MAX_PATH];
6168 LPCSTR query;
6169 UINT r, sz;
6170 int val;
6172 hdb = create_db();
6173 ok(hdb, "failed to create db\n");
6175 query = "CREATE TABLE `Empty` ( `A` SHORT NOT NULL PRIMARY KEY `A`)";
6176 r = run_query(hdb, 0, query);
6177 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6179 query = "CREATE TABLE `Mesa` ( `A` SHORT NOT NULL, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
6180 r = run_query(hdb, 0, query);
6181 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6183 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 1, 2, 9 )";
6184 r = run_query(hdb, 0, query);
6185 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6187 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 3, 4, 7 )";
6188 r = run_query(hdb, 0, query);
6189 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6191 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 5, 6, 8 )";
6192 r = run_query(hdb, 0, query);
6193 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6195 query = "CREATE TABLE `Sideboard` ( `D` SHORT NOT NULL, `E` SHORT, `F` SHORT PRIMARY KEY `D`)";
6196 r = run_query(hdb, 0, query);
6197 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6199 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 10, 11, 18 )";
6200 r = run_query(hdb, 0, query);
6201 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6203 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 12, 13, 16 )";
6204 r = run_query(hdb, 0, query);
6205 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6207 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 14, 15, 17 )";
6208 r = run_query(hdb, 0, query);
6209 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6211 query = "SELECT `A`, `B` FROM `Mesa` ORDER BY `C`";
6212 r = MsiDatabaseOpenView(hdb, query, &hview);
6213 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6214 r = MsiViewExecute(hview, 0);
6215 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6217 r = MsiViewFetch(hview, &hrec);
6218 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6220 val = MsiRecordGetInteger(hrec, 1);
6221 ok(val == 3, "Expected 3, got %d\n", val);
6223 val = MsiRecordGetInteger(hrec, 2);
6224 ok(val == 4, "Expected 3, got %d\n", val);
6226 MsiCloseHandle(hrec);
6228 r = MsiViewFetch(hview, &hrec);
6229 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6231 val = MsiRecordGetInteger(hrec, 1);
6232 ok(val == 5, "Expected 5, got %d\n", val);
6234 val = MsiRecordGetInteger(hrec, 2);
6235 ok(val == 6, "Expected 6, got %d\n", val);
6237 MsiCloseHandle(hrec);
6239 r = MsiViewFetch(hview, &hrec);
6240 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6242 val = MsiRecordGetInteger(hrec, 1);
6243 ok(val == 1, "Expected 1, got %d\n", val);
6245 val = MsiRecordGetInteger(hrec, 2);
6246 ok(val == 2, "Expected 2, got %d\n", val);
6248 MsiCloseHandle(hrec);
6250 r = MsiViewFetch(hview, &hrec);
6251 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6253 MsiViewClose(hview);
6254 MsiCloseHandle(hview);
6256 query = "SELECT `A`, `D` FROM `Mesa`, `Sideboard` ORDER BY `F`";
6257 r = MsiDatabaseOpenView(hdb, query, &hview);
6258 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6259 r = MsiViewExecute(hview, 0);
6260 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6262 r = MsiViewFetch(hview, &hrec);
6263 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6265 val = MsiRecordGetInteger(hrec, 1);
6266 ok(val == 1, "Expected 1, got %d\n", val);
6268 val = MsiRecordGetInteger(hrec, 2);
6269 ok(val == 12, "Expected 12, got %d\n", val);
6271 MsiCloseHandle(hrec);
6273 r = MsiViewFetch(hview, &hrec);
6274 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6276 val = MsiRecordGetInteger(hrec, 1);
6277 ok(val == 3, "Expected 3, got %d\n", val);
6279 val = MsiRecordGetInteger(hrec, 2);
6280 ok(val == 12, "Expected 12, got %d\n", val);
6282 MsiCloseHandle(hrec);
6284 r = MsiViewFetch(hview, &hrec);
6285 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6287 val = MsiRecordGetInteger(hrec, 1);
6288 ok(val == 5, "Expected 5, got %d\n", val);
6290 val = MsiRecordGetInteger(hrec, 2);
6291 ok(val == 12, "Expected 12, got %d\n", val);
6293 MsiCloseHandle(hrec);
6295 r = MsiViewFetch(hview, &hrec);
6296 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6298 val = MsiRecordGetInteger(hrec, 1);
6299 ok(val == 1, "Expected 1, got %d\n", val);
6301 val = MsiRecordGetInteger(hrec, 2);
6302 ok(val == 14, "Expected 14, got %d\n", val);
6304 MsiCloseHandle(hrec);
6306 r = MsiViewFetch(hview, &hrec);
6307 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6309 val = MsiRecordGetInteger(hrec, 1);
6310 ok(val == 3, "Expected 3, got %d\n", val);
6312 val = MsiRecordGetInteger(hrec, 2);
6313 ok(val == 14, "Expected 14, got %d\n", val);
6315 MsiCloseHandle(hrec);
6317 r = MsiViewFetch(hview, &hrec);
6318 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6320 val = MsiRecordGetInteger(hrec, 1);
6321 ok(val == 5, "Expected 5, got %d\n", val);
6323 val = MsiRecordGetInteger(hrec, 2);
6324 ok(val == 14, "Expected 14, got %d\n", val);
6326 MsiCloseHandle(hrec);
6328 r = MsiViewFetch(hview, &hrec);
6329 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6331 val = MsiRecordGetInteger(hrec, 1);
6332 ok(val == 1, "Expected 1, got %d\n", val);
6334 val = MsiRecordGetInteger(hrec, 2);
6335 ok(val == 10, "Expected 10, got %d\n", val);
6337 MsiCloseHandle(hrec);
6339 r = MsiViewFetch(hview, &hrec);
6340 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6342 val = MsiRecordGetInteger(hrec, 1);
6343 ok(val == 3, "Expected 3, got %d\n", val);
6345 val = MsiRecordGetInteger(hrec, 2);
6346 ok(val == 10, "Expected 10, got %d\n", val);
6348 MsiCloseHandle(hrec);
6350 r = MsiViewFetch(hview, &hrec);
6351 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6353 val = MsiRecordGetInteger(hrec, 1);
6354 ok(val == 5, "Expected 5, got %d\n", val);
6356 val = MsiRecordGetInteger(hrec, 2);
6357 ok(val == 10, "Expected 10, got %d\n", val);
6359 MsiCloseHandle(hrec);
6361 r = MsiViewFetch(hview, &hrec);
6362 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6364 MsiViewClose(hview);
6365 MsiCloseHandle(hview);
6367 query = "SELECT * FROM `Empty` ORDER BY `A`";
6368 r = MsiDatabaseOpenView(hdb, query, &hview);
6369 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6370 r = MsiViewExecute(hview, 0);
6371 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6373 r = MsiViewFetch(hview, &hrec);
6374 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6376 MsiViewClose(hview);
6377 MsiCloseHandle(hview);
6379 query = "CREATE TABLE `Buffet` ( `One` CHAR(72), `Two` SHORT PRIMARY KEY `One`)";
6380 r = run_query(hdb, 0, query);
6381 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6383 query = "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'uno', 2)";
6384 r = run_query(hdb, 0, query);
6385 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6387 query = "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'dos', 3)";
6388 r = run_query(hdb, 0, query);
6389 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6391 query = "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'tres', 1)";
6392 r = run_query(hdb, 0, query);
6393 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6395 query = "SELECT * FROM `Buffet` WHERE `One` = 'dos' ORDER BY `Two`";
6396 r = MsiDatabaseOpenView(hdb, query, &hview);
6397 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6398 r = MsiViewExecute(hview, 0);
6399 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6401 r = MsiViewFetch(hview, &hrec);
6402 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6404 sz = sizeof(buffer);
6405 r = MsiRecordGetString(hrec, 1, buffer, &sz);
6406 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6407 ok(!lstrcmp(buffer, "dos"), "Expected \"dos\", got \"%s\"\n", buffer);
6409 r = MsiRecordGetInteger(hrec, 2);
6410 ok(r == 3, "Expected 3, got %d\n", r);
6412 MsiCloseHandle(hrec);
6414 r = MsiViewFetch(hview, &hrec);
6415 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6417 MsiViewClose(hview);
6418 MsiCloseHandle(hview);
6419 MsiCloseHandle(hdb);
6422 static void test_viewmodify_delete_temporary(void)
6424 MSIHANDLE hdb, hview, hrec;
6425 const char *query;
6426 UINT r;
6428 DeleteFile(msifile);
6430 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6431 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6433 query = "CREATE TABLE `Table` ( `A` SHORT PRIMARY KEY `A` )";
6434 r = run_query(hdb, 0, query);
6435 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6437 query = "SELECT * FROM `Table`";
6438 r = MsiDatabaseOpenView(hdb, query, &hview);
6439 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6440 r = MsiViewExecute(hview, 0);
6441 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6443 hrec = MsiCreateRecord(1);
6444 MsiRecordSetInteger(hrec, 1, 1);
6446 r = MsiViewModify(hview, MSIMODIFY_INSERT, hrec);
6447 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6449 MsiCloseHandle(hrec);
6451 hrec = MsiCreateRecord(1);
6452 MsiRecordSetInteger(hrec, 1, 2);
6454 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
6455 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6457 MsiCloseHandle(hrec);
6459 hrec = MsiCreateRecord(1);
6460 MsiRecordSetInteger(hrec, 1, 3);
6462 r = MsiViewModify(hview, MSIMODIFY_INSERT, hrec);
6463 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6465 MsiCloseHandle(hrec);
6467 hrec = MsiCreateRecord(1);
6468 MsiRecordSetInteger(hrec, 1, 4);
6470 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
6471 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6473 MsiCloseHandle(hrec);
6474 MsiViewClose(hview);
6475 MsiCloseHandle(hview);
6477 query = "SELECT * FROM `Table` WHERE `A` = 2";
6478 r = MsiDatabaseOpenView(hdb, query, &hview);
6479 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6480 r = MsiViewExecute(hview, 0);
6481 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6482 r = MsiViewFetch(hview, &hrec);
6483 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6485 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
6486 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6488 MsiCloseHandle(hrec);
6489 MsiViewClose(hview);
6490 MsiCloseHandle(hview);
6492 query = "SELECT * FROM `Table` WHERE `A` = 3";
6493 r = MsiDatabaseOpenView(hdb, query, &hview);
6494 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6495 r = MsiViewExecute(hview, 0);
6496 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6497 r = MsiViewFetch(hview, &hrec);
6498 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6500 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
6501 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6503 MsiCloseHandle(hrec);
6504 MsiViewClose(hview);
6505 MsiCloseHandle(hview);
6507 query = "SELECT * FROM `Table` ORDER BY `A`";
6508 r = MsiDatabaseOpenView(hdb, query, &hview);
6509 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6510 r = MsiViewExecute(hview, 0);
6511 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6513 r = MsiViewFetch(hview, &hrec);
6514 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6516 r = MsiRecordGetInteger(hrec, 1);
6517 ok(r == 1, "Expected 1, got %d\n", r);
6519 MsiCloseHandle(hrec);
6521 r = MsiViewFetch(hview, &hrec);
6522 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6524 r = MsiRecordGetInteger(hrec, 1);
6525 ok(r == 4, "Expected 4, got %d\n", r);
6527 MsiCloseHandle(hrec);
6529 r = MsiViewFetch(hview, &hrec);
6530 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6532 MsiViewClose(hview);
6533 MsiCloseHandle(hview);
6534 MsiCloseHandle(hdb);
6535 DeleteFileA(msifile);
6538 static void test_deleterow(void)
6540 MSIHANDLE hdb, hview, hrec;
6541 const char *query;
6542 char buf[MAX_PATH];
6543 UINT r;
6544 DWORD size;
6546 DeleteFile(msifile);
6548 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6549 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6551 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6552 r = run_query(hdb, 0, query);
6553 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6555 query = "INSERT INTO `Table` (`A`) VALUES ('one')";
6556 r = run_query(hdb, 0, query);
6557 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6559 query = "INSERT INTO `Table` (`A`) VALUES ('two')";
6560 r = run_query(hdb, 0, query);
6561 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6563 query = "DELETE FROM `Table` WHERE `A` = 'one'";
6564 r = run_query(hdb, 0, query);
6565 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6567 r = MsiDatabaseCommit(hdb);
6568 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6570 MsiCloseHandle(hdb);
6572 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
6573 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6575 query = "SELECT * FROM `Table`";
6576 r = MsiDatabaseOpenView(hdb, query, &hview);
6577 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6578 r = MsiViewExecute(hview, 0);
6579 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6581 r = MsiViewFetch(hview, &hrec);
6582 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6584 size = MAX_PATH;
6585 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6586 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6587 ok(!lstrcmpA(buf, "two"), "Expected two, got %s\n", buf);
6589 MsiCloseHandle(hrec);
6591 r = MsiViewFetch(hview, &hrec);
6592 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6594 MsiViewClose(hview);
6595 MsiCloseHandle(hview);
6596 MsiCloseHandle(hdb);
6597 DeleteFileA(msifile);
6600 static const CHAR import_dat[] = "A\n"
6601 "s72\n"
6602 "Table\tA\n"
6603 "This is a new 'string' ok\n";
6605 static void test_quotes(void)
6607 MSIHANDLE hdb, hview, hrec;
6608 const char *query;
6609 char buf[MAX_PATH];
6610 UINT r;
6611 DWORD size;
6613 DeleteFile(msifile);
6615 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6616 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6618 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6619 r = run_query(hdb, 0, query);
6620 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6622 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a 'string' ok' )";
6623 r = run_query(hdb, 0, query);
6624 ok(r == ERROR_BAD_QUERY_SYNTAX,
6625 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6627 query = "INSERT INTO `Table` ( `A` ) VALUES ( \"This is a 'string' ok\" )";
6628 r = run_query(hdb, 0, query);
6629 ok(r == ERROR_BAD_QUERY_SYNTAX,
6630 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6632 query = "INSERT INTO `Table` ( `A` ) VALUES ( \"test\" )";
6633 r = run_query(hdb, 0, query);
6634 ok(r == ERROR_BAD_QUERY_SYNTAX,
6635 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6637 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a ''string'' ok' )";
6638 r = run_query(hdb, 0, query);
6639 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6641 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a '''string''' ok' )";
6642 r = run_query(hdb, 0, query);
6643 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6645 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \'string\' ok' )";
6646 r = run_query(hdb, 0, query);
6647 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6649 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \"string\" ok' )";
6650 r = run_query(hdb, 0, query);
6651 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6653 query = "SELECT * FROM `Table`";
6654 r = MsiDatabaseOpenView(hdb, query, &hview);
6655 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6657 r = MsiViewExecute(hview, 0);
6658 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6660 r = MsiViewFetch(hview, &hrec);
6661 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6663 size = MAX_PATH;
6664 r = MsiRecordGetString(hrec, 1, buf, &size);
6665 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6666 ok(!lstrcmp(buf, "This is a \"string\" ok"),
6667 "Expected \"This is a \"string\" ok\", got %s\n", buf);
6669 MsiCloseHandle(hrec);
6671 r = MsiViewFetch(hview, &hrec);
6672 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6674 MsiViewClose(hview);
6675 MsiCloseHandle(hview);
6677 write_file("import.idt", import_dat, (sizeof(import_dat) - 1) * sizeof(char));
6679 r = MsiDatabaseImportA(hdb, CURR_DIR, "import.idt");
6680 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6682 DeleteFileA("import.idt");
6684 query = "SELECT * FROM `Table`";
6685 r = MsiDatabaseOpenView(hdb, query, &hview);
6686 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6688 r = MsiViewExecute(hview, 0);
6689 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6691 r = MsiViewFetch(hview, &hrec);
6692 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6694 size = MAX_PATH;
6695 r = MsiRecordGetString(hrec, 1, buf, &size);
6696 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6697 ok(!lstrcmp(buf, "This is a new 'string' ok"),
6698 "Expected \"This is a new 'string' ok\", got %s\n", buf);
6700 MsiCloseHandle(hrec);
6702 r = MsiViewFetch(hview, &hrec);
6703 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6705 MsiViewClose(hview);
6706 MsiCloseHandle(hview);
6707 MsiCloseHandle(hdb);
6708 DeleteFileA(msifile);
6711 static void test_carriagereturn(void)
6713 MSIHANDLE hdb, hview, hrec;
6714 const char *query;
6715 char buf[MAX_PATH];
6716 UINT r;
6717 DWORD size;
6719 DeleteFile(msifile);
6721 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6722 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6724 query = "CREATE TABLE `Table`\r ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6725 r = run_query(hdb, 0, query);
6726 ok(r == ERROR_BAD_QUERY_SYNTAX,
6727 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6729 query = "CREATE TABLE `Table` \r( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6730 r = run_query(hdb, 0, query);
6731 ok(r == ERROR_BAD_QUERY_SYNTAX,
6732 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6734 query = "CREATE\r TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6735 r = run_query(hdb, 0, query);
6736 ok(r == ERROR_BAD_QUERY_SYNTAX,
6737 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6739 query = "CREATE TABLE\r `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6740 r = run_query(hdb, 0, query);
6741 ok(r == ERROR_BAD_QUERY_SYNTAX,
6742 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6744 query = "CREATE TABLE `Table` (\r `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6745 r = run_query(hdb, 0, query);
6746 ok(r == ERROR_BAD_QUERY_SYNTAX,
6747 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6749 query = "CREATE TABLE `Table` ( `A`\r CHAR(72) NOT NULL PRIMARY KEY `A` )";
6750 r = run_query(hdb, 0, query);
6751 ok(r == ERROR_BAD_QUERY_SYNTAX,
6752 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6754 query = "CREATE TABLE `Table` ( `A` CHAR(72)\r NOT NULL PRIMARY KEY `A` )";
6755 r = run_query(hdb, 0, query);
6756 ok(r == ERROR_BAD_QUERY_SYNTAX,
6757 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6759 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT\r NULL PRIMARY KEY `A` )";
6760 r = run_query(hdb, 0, query);
6761 ok(r == ERROR_BAD_QUERY_SYNTAX,
6762 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6764 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT \rNULL PRIMARY KEY `A` )";
6765 r = run_query(hdb, 0, query);
6766 ok(r == ERROR_BAD_QUERY_SYNTAX,
6767 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6769 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL\r PRIMARY KEY `A` )";
6770 r = run_query(hdb, 0, query);
6771 ok(r == ERROR_BAD_QUERY_SYNTAX,
6772 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6774 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL \rPRIMARY KEY `A` )";
6775 r = run_query(hdb, 0, query);
6776 ok(r == ERROR_BAD_QUERY_SYNTAX,
6777 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6779 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY\r KEY `A` )";
6780 r = run_query(hdb, 0, query);
6781 ok(r == ERROR_BAD_QUERY_SYNTAX,
6782 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6784 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY \rKEY `A` )";
6785 r = run_query(hdb, 0, query);
6786 ok(r == ERROR_BAD_QUERY_SYNTAX,
6787 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6789 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY\r `A` )";
6790 r = run_query(hdb, 0, query);
6791 ok(r == ERROR_BAD_QUERY_SYNTAX,
6792 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6794 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A`\r )";
6795 r = run_query(hdb, 0, query);
6796 ok(r == ERROR_BAD_QUERY_SYNTAX,
6797 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6799 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )\r";
6800 r = run_query(hdb, 0, query);
6801 ok(r == ERROR_BAD_QUERY_SYNTAX,
6802 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6804 query = "CREATE TABLE `\rOne` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6805 r = run_query(hdb, 0, query);
6806 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6808 query = "CREATE TABLE `Tw\ro` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6809 r = run_query(hdb, 0, query);
6810 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6812 query = "CREATE TABLE `Three\r` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6813 r = run_query(hdb, 0, query);
6814 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6816 query = "CREATE TABLE `Four` ( `A\r` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6817 r = run_query(hdb, 0, query);
6818 ok(r == ERROR_BAD_QUERY_SYNTAX,
6819 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6821 query = "CREATE TABLE `Four` ( `\rA` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6822 r = run_query(hdb, 0, query);
6823 ok(r == ERROR_BAD_QUERY_SYNTAX,
6824 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6826 query = "CREATE TABLE `Four` ( `A` CHAR(72\r) NOT NULL PRIMARY KEY `A` )";
6827 r = run_query(hdb, 0, query);
6828 ok(r == ERROR_BAD_QUERY_SYNTAX,
6829 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6831 query = "CREATE TABLE `Four` ( `A` CHAR(\r72) NOT NULL PRIMARY KEY `A` )";
6832 r = run_query(hdb, 0, query);
6833 ok(r == ERROR_BAD_QUERY_SYNTAX,
6834 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6836 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `\rA` )";
6837 r = run_query(hdb, 0, query);
6838 ok(r == ERROR_BAD_QUERY_SYNTAX,
6839 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6841 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
6842 r = run_query(hdb, 0, query);
6843 ok(r == ERROR_BAD_QUERY_SYNTAX,
6844 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6846 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
6847 r = run_query(hdb, 0, query);
6848 ok(r == ERROR_BAD_QUERY_SYNTAX,
6849 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6851 query = "SELECT * FROM `_Tables`";
6852 r = MsiDatabaseOpenView(hdb, query, &hview);
6853 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6854 r = MsiViewExecute(hview, 0);
6855 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6857 r = MsiViewFetch(hview, &hrec);
6858 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6860 size = MAX_PATH;
6861 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6862 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6863 ok(!lstrcmpA(buf, "\rOne"), "Expected \"\\rOne\", got \"%s\"\n", buf);
6865 MsiCloseHandle(hrec);
6867 r = MsiViewFetch(hview, &hrec);
6868 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6870 size = MAX_PATH;
6871 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6872 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6873 ok(!lstrcmpA(buf, "Tw\ro"), "Expected \"Tw\\ro\", got \"%s\"\n", buf);
6875 MsiCloseHandle(hrec);
6877 r = MsiViewFetch(hview, &hrec);
6878 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6880 size = MAX_PATH;
6881 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6882 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6883 ok(!lstrcmpA(buf, "Three\r"), "Expected \"Three\r\", got \"%s\"\n", buf);
6885 MsiCloseHandle(hrec);
6887 r = MsiViewFetch(hview, &hrec);
6888 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6890 MsiViewClose(hview);
6891 MsiCloseHandle(hview);
6893 MsiCloseHandle(hdb);
6894 DeleteFileA(msifile);
6897 static void test_noquotes(void)
6899 MSIHANDLE hdb, hview, hrec;
6900 const char *query;
6901 char buf[MAX_PATH];
6902 UINT r;
6903 DWORD size;
6905 DeleteFile(msifile);
6907 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6908 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6910 query = "CREATE TABLE Table ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6911 r = run_query(hdb, 0, query);
6912 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6914 query = "CREATE TABLE `Table` ( A CHAR(72) NOT NULL PRIMARY KEY `A` )";
6915 r = run_query(hdb, 0, query);
6916 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6918 query = "CREATE TABLE `Table2` ( `A` CHAR(72) NOT NULL PRIMARY KEY A )";
6919 r = run_query(hdb, 0, query);
6920 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6922 query = "CREATE TABLE `Table3` ( A CHAR(72) NOT NULL PRIMARY KEY A )";
6923 r = run_query(hdb, 0, query);
6924 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6926 query = "SELECT * FROM `_Tables`";
6927 r = MsiDatabaseOpenView(hdb, query, &hview);
6928 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6929 r = MsiViewExecute(hview, 0);
6930 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6932 r = MsiViewFetch(hview, &hrec);
6933 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6935 size = MAX_PATH;
6936 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6937 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6938 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
6940 MsiCloseHandle(hrec);
6942 r = MsiViewFetch(hview, &hrec);
6943 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6945 size = MAX_PATH;
6946 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6947 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6948 ok(!lstrcmpA(buf, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf);
6950 MsiCloseHandle(hrec);
6952 r = MsiViewFetch(hview, &hrec);
6953 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6955 size = MAX_PATH;
6956 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6957 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6958 ok(!lstrcmpA(buf, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf);
6960 MsiCloseHandle(hrec);
6962 r = MsiViewFetch(hview, &hrec);
6963 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6965 MsiViewClose(hview);
6966 MsiCloseHandle(hview);
6968 query = "SELECT * FROM `_Columns`";
6969 r = MsiDatabaseOpenView(hdb, query, &hview);
6970 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6971 r = MsiViewExecute(hview, 0);
6972 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6974 r = MsiViewFetch(hview, &hrec);
6975 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6977 size = MAX_PATH;
6978 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6979 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6980 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
6982 r = MsiRecordGetInteger(hrec, 2);
6983 ok(r == 1, "Expected 1, got %d\n", r);
6985 size = MAX_PATH;
6986 r = MsiRecordGetStringA(hrec, 3, buf, &size);
6987 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6988 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
6990 MsiCloseHandle(hrec);
6992 r = MsiViewFetch(hview, &hrec);
6993 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6995 size = MAX_PATH;
6996 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6997 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6998 ok(!lstrcmpA(buf, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf);
7000 r = MsiRecordGetInteger(hrec, 2);
7001 ok(r == 1, "Expected 1, got %d\n", r);
7003 size = MAX_PATH;
7004 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7005 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7006 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
7008 MsiCloseHandle(hrec);
7010 r = MsiViewFetch(hview, &hrec);
7011 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7013 size = MAX_PATH;
7014 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7015 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7016 ok(!lstrcmpA(buf, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf);
7018 r = MsiRecordGetInteger(hrec, 2);
7019 ok(r == 1, "Expected 1, got %d\n", r);
7021 size = MAX_PATH;
7022 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7023 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7024 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
7026 MsiCloseHandle(hrec);
7028 r = MsiViewFetch(hview, &hrec);
7029 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7031 MsiViewClose(hview);
7032 MsiCloseHandle(hview);
7034 query = "INSERT INTO Table ( `A` ) VALUES ( 'hi' )";
7035 r = run_query(hdb, 0, query);
7036 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7038 query = "INSERT INTO `Table` ( A ) VALUES ( 'hi' )";
7039 r = run_query(hdb, 0, query);
7040 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7042 query = "INSERT INTO `Table` ( `A` ) VALUES ( hi )";
7043 r = run_query(hdb, 0, query);
7044 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7046 query = "SELECT * FROM Table WHERE `A` = 'hi'";
7047 r = run_query(hdb, 0, query);
7048 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7050 query = "SELECT * FROM `Table` WHERE `A` = hi";
7051 r = run_query(hdb, 0, query);
7052 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7054 query = "SELECT * FROM Table";
7055 r = run_query(hdb, 0, query);
7056 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7058 query = "SELECT * FROM Table2";
7059 r = MsiDatabaseOpenView(hdb, query, &hview);
7060 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7061 r = MsiViewExecute(hview, 0);
7062 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7064 r = MsiViewFetch(hview, &hrec);
7065 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7067 MsiViewClose(hview);
7068 MsiCloseHandle(hview);
7070 query = "SELECT * FROM `Table` WHERE A = 'hi'";
7071 r = MsiDatabaseOpenView(hdb, query, &hview);
7072 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7073 r = MsiViewExecute(hview, 0);
7074 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7076 r = MsiViewFetch(hview, &hrec);
7077 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7079 size = MAX_PATH;
7080 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7081 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7082 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
7084 MsiCloseHandle(hrec);
7086 r = MsiViewFetch(hview, &hrec);
7087 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7089 MsiViewClose(hview);
7090 MsiCloseHandle(hview);
7091 MsiCloseHandle(hdb);
7092 DeleteFileA(msifile);
7095 static void read_file_data(LPCSTR filename, LPSTR buffer)
7097 HANDLE file;
7098 DWORD read;
7100 file = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
7101 ZeroMemory(buffer, MAX_PATH);
7102 ReadFile(file, buffer, MAX_PATH, &read, NULL);
7103 CloseHandle(file);
7106 static void test_forcecodepage(void)
7108 MSIHANDLE hdb;
7109 const char *query;
7110 char buffer[MAX_PATH];
7111 UINT r;
7113 DeleteFile(msifile);
7114 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
7116 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7117 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7119 query = "SELECT * FROM `_ForceCodepage`";
7120 r = run_query(hdb, 0, query);
7121 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7123 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
7124 r = run_query(hdb, 0, query);
7125 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7127 query = "SELECT * FROM `_ForceCodepage`";
7128 r = run_query(hdb, 0, query);
7129 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7131 r = MsiDatabaseCommit(hdb);
7132 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7134 query = "SELECT * FROM `_ForceCodepage`";
7135 r = run_query(hdb, 0, query);
7136 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7138 MsiCloseHandle(hdb);
7140 r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb);
7141 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7143 query = "SELECT * FROM `_ForceCodepage`";
7144 r = run_query(hdb, 0, query);
7145 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7147 r = MsiDatabaseExport(hdb, "_ForceCodepage", CURR_DIR, "forcecodepage.idt");
7148 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7150 read_file_data("forcecodepage.idt", buffer);
7151 ok(!lstrcmpA(buffer, "\r\n\r\n0\t_ForceCodepage\r\n"),
7152 "Expected \"\r\n\r\n0\t_ForceCodepage\r\n\", got \"%s\"\n", buffer);
7154 create_file_data("forcecodepage.idt", "\r\n\r\n850\t_ForceCodepage\r\n", 0);
7156 r = MsiDatabaseImportA(hdb, CURR_DIR, "forcecodepage.idt");
7157 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7159 r = MsiDatabaseExport(hdb, "_ForceCodepage", CURR_DIR, "forcecodepage.idt");
7160 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7162 read_file_data("forcecodepage.idt", buffer);
7163 ok(!lstrcmpA(buffer, "\r\n\r\n850\t_ForceCodepage\r\n"),
7164 "Expected \"\r\n\r\n850\t_ForceCodepage\r\n\", got \"%s\"\n", buffer);
7166 create_file_data("forcecodepage.idt", "\r\n\r\n9999\t_ForceCodepage\r\n", 0);
7168 r = MsiDatabaseImportA(hdb, CURR_DIR, "forcecodepage.idt");
7169 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_SUCCESS, got %d\n", r);
7171 MsiCloseHandle(hdb);
7172 DeleteFileA(msifile);
7173 DeleteFileA("forcecodepage.idt");
7176 static void test_viewmodify_refresh(void)
7178 MSIHANDLE hdb, hview, hrec;
7179 const char *query;
7180 char buffer[MAX_PATH];
7181 UINT r;
7182 DWORD size;
7184 DeleteFile(msifile);
7186 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7187 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7189 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL, `B` INT PRIMARY KEY `A` )";
7190 r = run_query(hdb, 0, query);
7191 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7193 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hi', 1 )";
7194 r = run_query(hdb, 0, query);
7195 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7197 query = "SELECT * FROM `Table`";
7198 r = MsiDatabaseOpenView(hdb, query, &hview);
7199 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7200 r = MsiViewExecute(hview, 0);
7201 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7203 r = MsiViewFetch(hview, &hrec);
7204 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7206 query = "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hi'";
7207 r = run_query(hdb, 0, query);
7208 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7210 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
7211 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7213 size = MAX_PATH;
7214 r = MsiRecordGetStringA(hrec, 1, buffer, &size);
7215 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7216 ok(!lstrcmpA(buffer, "hi"), "Expected \"hi\", got \"%s\"\n", buffer);
7217 ok(size == 2, "Expected 2, got %d\n", size);
7219 r = MsiRecordGetInteger(hrec, 2);
7220 ok(r == 2, "Expected 2, got %d\n", r);
7222 MsiCloseHandle(hrec);
7223 MsiViewClose(hview);
7224 MsiCloseHandle(hview);
7226 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hello', 3 )";
7227 r = run_query(hdb, 0, query);
7228 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7230 query = "SELECT * FROM `Table` WHERE `B` = 3";
7231 r = MsiDatabaseOpenView(hdb, query, &hview);
7232 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7233 r = MsiViewExecute(hview, 0);
7234 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7236 r = MsiViewFetch(hview, &hrec);
7237 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7239 query = "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hello'";
7240 r = run_query(hdb, 0, query);
7241 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7243 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hithere', 3 )";
7244 r = run_query(hdb, 0, query);
7245 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7247 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
7248 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7250 size = MAX_PATH;
7251 r = MsiRecordGetStringA(hrec, 1, buffer, &size);
7252 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7253 ok(!lstrcmpA(buffer, "hello"), "Expected \"hello\", got \"%s\"\n", buffer);
7254 ok(size == 5, "Expected 5, got %d\n", size);
7256 r = MsiRecordGetInteger(hrec, 2);
7257 ok(r == 2, "Expected 2, got %d\n", r);
7259 MsiCloseHandle(hrec);
7260 MsiViewClose(hview);
7261 MsiCloseHandle(hview);
7262 MsiCloseHandle(hdb);
7263 DeleteFileA(msifile);
7266 static void test_where_viewmodify(void)
7268 MSIHANDLE hdb, hview, hrec;
7269 const char *query;
7270 UINT r;
7272 DeleteFile(msifile);
7274 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7275 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7277 query = "CREATE TABLE `Table` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7278 r = run_query(hdb, 0, query);
7279 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7281 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 1, 2 )";
7282 r = run_query(hdb, 0, query);
7283 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7285 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 3, 4 )";
7286 r = run_query(hdb, 0, query);
7287 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7289 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 5, 6 )";
7290 r = run_query(hdb, 0, query);
7291 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7293 /* `B` = 3 doesn't match, but the view shouldn't be executed */
7294 query = "SELECT * FROM `Table` WHERE `B` = 3";
7295 r = MsiDatabaseOpenView(hdb, query, &hview);
7296 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7298 hrec = MsiCreateRecord(2);
7299 MsiRecordSetInteger(hrec, 1, 7);
7300 MsiRecordSetInteger(hrec, 2, 8);
7302 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
7303 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7305 MsiCloseHandle(hrec);
7306 MsiViewClose(hview);
7307 MsiCloseHandle(hview);
7309 query = "SELECT * FROM `Table` WHERE `A` = 7";
7310 r = MsiDatabaseOpenView(hdb, query, &hview);
7311 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7312 r = MsiViewExecute(hview, 0);
7313 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7315 r = MsiViewFetch(hview, &hrec);
7316 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7318 r = MsiRecordGetInteger(hrec, 1);
7319 ok(r == 7, "Expected 7, got %d\n", r);
7321 r = MsiRecordGetInteger(hrec, 2);
7322 ok(r == 8, "Expected 8, got %d\n", r);
7324 MsiRecordSetInteger(hrec, 2, 9);
7326 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
7327 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7329 MsiCloseHandle(hrec);
7330 MsiViewClose(hview);
7331 MsiCloseHandle(hview);
7333 query = "SELECT * FROM `Table` WHERE `A` = 7";
7334 r = MsiDatabaseOpenView(hdb, query, &hview);
7335 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7336 r = MsiViewExecute(hview, 0);
7337 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7339 r = MsiViewFetch(hview, &hrec);
7340 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7342 r = MsiRecordGetInteger(hrec, 1);
7343 ok(r == 7, "Expected 7, got %d\n", r);
7345 r = MsiRecordGetInteger(hrec, 2);
7346 ok(r == 9, "Expected 9, got %d\n", r);
7348 query = "UPDATE `Table` SET `B` = 10 WHERE `A` = 7";
7349 r = run_query(hdb, 0, query);
7350 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7352 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
7353 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7355 r = MsiRecordGetInteger(hrec, 1);
7356 ok(r == 7, "Expected 7, got %d\n", r);
7358 r = MsiRecordGetInteger(hrec, 2);
7359 ok(r == 10, "Expected 10, got %d\n", r);
7361 MsiCloseHandle(hrec);
7362 MsiViewClose(hview);
7363 MsiCloseHandle(hview);
7364 MsiCloseHandle(hdb);
7367 static BOOL create_storage(LPCSTR name)
7369 WCHAR nameW[MAX_PATH];
7370 IStorage *stg;
7371 IStream *stm;
7372 HRESULT hr;
7373 DWORD count;
7374 BOOL res = FALSE;
7376 MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, MAX_PATH);
7377 hr = StgCreateDocfile(nameW, STGM_CREATE | STGM_READWRITE |
7378 STGM_DIRECT | STGM_SHARE_EXCLUSIVE, 0, &stg);
7379 if (FAILED(hr))
7380 return FALSE;
7382 hr = IStorage_CreateStream(stg, nameW, STGM_WRITE | STGM_SHARE_EXCLUSIVE,
7383 0, 0, &stm);
7384 if (FAILED(hr))
7385 goto done;
7387 hr = IStream_Write(stm, "stgdata", 8, &count);
7388 if (SUCCEEDED(hr))
7389 res = TRUE;
7391 done:
7392 IStream_Release(stm);
7393 IStorage_Release(stg);
7395 return res;
7398 static void test_storages_table(void)
7400 MSIHANDLE hdb, hview, hrec;
7401 IStorage *stg, *inner;
7402 IStream *stm;
7403 char file[MAX_PATH];
7404 char buf[MAX_PATH];
7405 WCHAR name[MAX_PATH];
7406 LPCSTR query;
7407 HRESULT hr;
7408 DWORD size;
7409 UINT r;
7411 hdb = create_db();
7412 ok(hdb, "failed to create db\n");
7414 r = MsiDatabaseCommit(hdb);
7415 ok(r == ERROR_SUCCESS , "Failed to commit database\n");
7417 MsiCloseHandle(hdb);
7419 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb);
7420 ok(r == ERROR_SUCCESS , "Failed to open database\n");
7422 /* check the column types */
7423 hrec = get_column_info(hdb, "SELECT * FROM `_Storages`", MSICOLINFO_TYPES);
7424 ok(hrec, "failed to get column info hrecord\n");
7425 ok(check_record(hrec, 1, "s62"), "wrong hrecord type\n");
7426 ok(check_record(hrec, 2, "V0"), "wrong hrecord type\n");
7428 MsiCloseHandle(hrec);
7430 /* now try the names */
7431 hrec = get_column_info(hdb, "SELECT * FROM `_Storages`", MSICOLINFO_NAMES);
7432 ok(hrec, "failed to get column info hrecord\n");
7433 ok(check_record(hrec, 1, "Name"), "wrong hrecord type\n");
7434 ok(check_record(hrec, 2, "Data"), "wrong hrecord type\n");
7436 MsiCloseHandle(hrec);
7438 create_storage("storage.bin");
7440 hrec = MsiCreateRecord(2);
7441 MsiRecordSetString(hrec, 1, "stgname");
7443 r = MsiRecordSetStream(hrec, 2, "storage.bin");
7444 ok(r == ERROR_SUCCESS, "Failed to add stream data to the hrecord: %d\n", r);
7446 DeleteFileA("storage.bin");
7448 query = "INSERT INTO `_Storages` (`Name`, `Data`) VALUES (?, ?)";
7449 r = MsiDatabaseOpenView(hdb, query, &hview);
7450 ok(r == ERROR_SUCCESS, "Failed to open database hview: %d\n", r);
7452 r = MsiViewExecute(hview, hrec);
7453 ok(r == ERROR_SUCCESS, "Failed to execute hview: %d\n", r);
7455 MsiCloseHandle(hrec);
7456 MsiViewClose(hview);
7457 MsiCloseHandle(hview);
7459 query = "SELECT `Name`, `Data` FROM `_Storages`";
7460 r = MsiDatabaseOpenView(hdb, query, &hview);
7461 ok(r == ERROR_SUCCESS, "Failed to open database hview: %d\n", r);
7463 r = MsiViewExecute(hview, 0);
7464 ok(r == ERROR_SUCCESS, "Failed to execute hview: %d\n", r);
7466 r = MsiViewFetch(hview, &hrec);
7467 ok(r == ERROR_SUCCESS, "Failed to fetch hrecord: %d\n", r);
7469 size = MAX_PATH;
7470 r = MsiRecordGetString(hrec, 1, file, &size);
7471 ok(r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
7472 ok(!lstrcmp(file, "stgname"), "Expected \"stgname\", got \"%s\"\n", file);
7474 size = MAX_PATH;
7475 lstrcpyA(buf, "apple");
7476 r = MsiRecordReadStream(hrec, 2, buf, &size);
7477 ok(r == ERROR_INVALID_DATA, "Expected ERROR_INVALID_DATA, got %d\n", r);
7478 ok(!lstrcmp(buf, "apple"), "Expected buf to be unchanged, got %s\n", buf);
7479 ok(size == 0, "Expected 0, got %d\n", size);
7481 MsiCloseHandle(hrec);
7483 r = MsiViewFetch(hview, &hrec);
7484 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7486 MsiViewClose(hview);
7487 MsiCloseHandle(hview);
7489 MsiDatabaseCommit(hdb);
7490 MsiCloseHandle(hdb);
7492 MultiByteToWideChar(CP_ACP, 0, msifile, -1, name, MAX_PATH);
7493 hr = StgOpenStorage(name, NULL, STGM_DIRECT | STGM_READ |
7494 STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
7495 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
7496 ok(stg != NULL, "Expected non-NULL storage\n");
7498 MultiByteToWideChar(CP_ACP, 0, "stgname", -1, name, MAX_PATH);
7499 hr = IStorage_OpenStorage(stg, name, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE,
7500 NULL, 0, &inner);
7501 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
7502 ok(inner != NULL, "Expected non-NULL storage\n");
7504 MultiByteToWideChar(CP_ACP, 0, "storage.bin", -1, name, MAX_PATH);
7505 hr = IStorage_OpenStream(inner, name, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
7506 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
7507 ok(stm != NULL, "Expected non-NULL stream\n");
7509 hr = IStream_Read(stm, buf, MAX_PATH, &size);
7510 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
7511 ok(size == 8, "Expected 8, got %d\n", size);
7512 ok(!lstrcmpA(buf, "stgdata"), "Expected \"stgdata\", got \"%s\"\n", buf);
7514 IStream_Release(stm);
7515 IStorage_Release(inner);
7517 IStorage_Release(stg);
7518 DeleteFileA(msifile);
7521 static void test_dbtopackage(void)
7523 MSIHANDLE hdb, hpkg;
7524 CHAR package[12], buf[MAX_PATH];
7525 DWORD size;
7526 UINT r;
7528 /* create an empty database, transact mode */
7529 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7530 ok(r == ERROR_SUCCESS, "Failed to create database\n");
7532 set_summary_info(hdb);
7534 r = create_directory_table(hdb);
7535 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7537 r = create_custom_action_table(hdb);
7538 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7540 r = add_custom_action_entry(hdb, "'SetProp', 51, 'MYPROP', 'grape'");
7541 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7543 sprintf(package, "#%u", hdb);
7544 r = MsiOpenPackage(package, &hpkg);
7545 if (r == ERROR_INSTALL_PACKAGE_REJECTED)
7547 skip("Not enough rights to perform tests\n");
7548 goto error;
7550 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7552 /* property is not set yet */
7553 size = MAX_PATH;
7554 lstrcpyA(buf, "kiwi");
7555 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7556 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7557 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7558 ok(size == 0, "Expected 0, got %d\n", size);
7560 /* run the custom action to set the property */
7561 r = MsiDoAction(hpkg, "SetProp");
7562 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7564 /* property is now set */
7565 size = MAX_PATH;
7566 lstrcpyA(buf, "kiwi");
7567 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7568 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7569 ok(!lstrcmpA(buf, "grape"), "Expected \"grape\", got \"%s\"\n", buf);
7570 ok(size == 5, "Expected 5, got %d\n", size);
7572 MsiCloseHandle(hpkg);
7574 /* reset the package */
7575 r = MsiOpenPackage(package, &hpkg);
7576 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7578 /* property is not set anymore */
7579 size = MAX_PATH;
7580 lstrcpyA(buf, "kiwi");
7581 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7582 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7583 todo_wine
7585 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7586 ok(size == 0, "Expected 0, got %d\n", size);
7589 MsiCloseHandle(hdb);
7590 MsiCloseHandle(hpkg);
7592 /* create an empty database, direct mode */
7593 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATEDIRECT, &hdb);
7594 ok(r == ERROR_SUCCESS, "Failed to create database\n");
7596 set_summary_info(hdb);
7598 r = create_directory_table(hdb);
7599 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7601 r = create_custom_action_table(hdb);
7602 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7604 r = add_custom_action_entry(hdb, "'SetProp', 51, 'MYPROP', 'grape'");
7605 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7607 sprintf(package, "#%u", hdb);
7608 r = MsiOpenPackage(package, &hpkg);
7609 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7611 /* property is not set yet */
7612 size = MAX_PATH;
7613 lstrcpyA(buf, "kiwi");
7614 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7615 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7616 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7617 ok(size == 0, "Expected 0, got %d\n", size);
7619 /* run the custom action to set the property */
7620 r = MsiDoAction(hpkg, "SetProp");
7621 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7623 /* property is now set */
7624 size = MAX_PATH;
7625 lstrcpyA(buf, "kiwi");
7626 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7627 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7628 ok(!lstrcmpA(buf, "grape"), "Expected \"grape\", got \"%s\"\n", buf);
7629 ok(size == 5, "Expected 5, got %d\n", size);
7631 MsiCloseHandle(hpkg);
7633 /* reset the package */
7634 r = MsiOpenPackage(package, &hpkg);
7635 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7637 /* property is not set anymore */
7638 size = MAX_PATH;
7639 lstrcpyA(buf, "kiwi");
7640 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7641 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7642 todo_wine
7644 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7645 ok(size == 0, "Expected 0, got %d\n", size);
7648 MsiCloseHandle(hpkg);
7650 error:
7651 MsiCloseHandle(hdb);
7652 DeleteFileA(msifile);
7655 static void test_droptable(void)
7657 MSIHANDLE hdb, hview, hrec;
7658 CHAR buf[MAX_PATH];
7659 LPCSTR query;
7660 DWORD size;
7661 UINT r;
7663 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7664 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7666 query = "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7667 r = run_query(hdb, 0, query);
7668 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7670 query = "SELECT * FROM `One`";
7671 r = do_query(hdb, query, &hrec);
7672 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7674 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7675 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7676 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7677 r = MsiViewExecute(hview, 0);
7678 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7680 r = MsiViewFetch(hview, &hrec);
7681 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7683 size = MAX_PATH;
7684 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7685 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7686 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7688 MsiCloseHandle(hrec);
7689 MsiViewClose(hview);
7690 MsiCloseHandle(hview);
7692 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7693 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7694 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7695 r = MsiViewExecute(hview, 0);
7696 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7698 r = MsiViewFetch(hview, &hrec);
7699 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7701 size = MAX_PATH;
7702 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7703 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7704 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7706 r = MsiRecordGetInteger(hrec, 2);
7707 ok(r == 1, "Expected 1, got %d\n", r);
7709 size = MAX_PATH;
7710 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7711 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7712 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
7714 MsiCloseHandle(hrec);
7716 r = MsiViewFetch(hview, &hrec);
7717 ok(r == ERROR_NO_MORE_ITEMS,
7718 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7720 MsiViewClose(hview);
7721 MsiCloseHandle(hview);
7723 query = "DROP `One`";
7724 r = run_query(hdb, 0, query);
7725 ok(r == ERROR_BAD_QUERY_SYNTAX,
7726 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7728 query = "DROP TABLE";
7729 r = run_query(hdb, 0, query);
7730 ok(r == ERROR_BAD_QUERY_SYNTAX,
7731 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7733 query = "DROP TABLE `One`";
7734 hview = 0;
7735 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7736 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7737 r = MsiViewExecute(hview, 0);
7738 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7740 r = MsiViewFetch(hview, &hrec);
7741 ok(r == ERROR_FUNCTION_FAILED,
7742 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
7744 MsiViewClose(hview);
7745 MsiCloseHandle(hview);
7747 query = "SELECT * FROM `IDontExist`";
7748 r = do_query(hdb, query, &hrec);
7749 ok(r == ERROR_BAD_QUERY_SYNTAX,
7750 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7752 query = "SELECT * FROM `One`";
7753 r = do_query(hdb, query, &hrec);
7754 ok(r == ERROR_BAD_QUERY_SYNTAX,
7755 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7757 query = "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7758 r = run_query(hdb, 0, query);
7759 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7761 query = "DROP TABLE One";
7762 r = run_query(hdb, 0, query);
7763 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7765 query = "SELECT * FROM `One`";
7766 r = do_query(hdb, query, &hrec);
7767 ok(r == ERROR_BAD_QUERY_SYNTAX,
7768 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7770 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7771 r = do_query(hdb, query, &hrec);
7772 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7774 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7775 r = do_query(hdb, query, &hrec);
7776 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7778 query = "CREATE TABLE `One` ( `B` INT, `C` INT PRIMARY KEY `B` )";
7779 r = run_query(hdb, 0, query);
7780 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7782 query = "SELECT * FROM `One`";
7783 r = do_query(hdb, query, &hrec);
7784 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7786 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7787 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7788 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7789 r = MsiViewExecute(hview, 0);
7790 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7792 r = MsiViewFetch(hview, &hrec);
7793 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7795 size = MAX_PATH;
7796 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7797 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7798 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7800 MsiCloseHandle(hrec);
7801 MsiViewClose(hview);
7802 MsiCloseHandle(hview);
7804 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7805 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7806 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7807 r = MsiViewExecute(hview, 0);
7808 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7810 r = MsiViewFetch(hview, &hrec);
7811 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7813 size = MAX_PATH;
7814 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7815 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7816 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7818 r = MsiRecordGetInteger(hrec, 2);
7819 ok(r == 1, "Expected 1, got %d\n", r);
7821 size = MAX_PATH;
7822 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7823 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7824 ok(!lstrcmpA(buf, "B"), "Expected \"B\", got \"%s\"\n", buf);
7826 MsiCloseHandle(hrec);
7828 r = MsiViewFetch(hview, &hrec);
7829 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7831 size = MAX_PATH;
7832 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7833 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7834 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7836 r = MsiRecordGetInteger(hrec, 2);
7837 ok(r == 2, "Expected 2, got %d\n", r);
7839 size = MAX_PATH;
7840 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7841 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7842 ok(!lstrcmpA(buf, "C"), "Expected \"C\", got \"%s\"\n", buf);
7844 MsiCloseHandle(hrec);
7846 r = MsiViewFetch(hview, &hrec);
7847 ok(r == ERROR_NO_MORE_ITEMS,
7848 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7850 MsiViewClose(hview);
7851 MsiCloseHandle(hview);
7853 query = "DROP TABLE One";
7854 r = run_query(hdb, 0, query);
7855 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7857 query = "SELECT * FROM `One`";
7858 r = do_query(hdb, query, &hrec);
7859 ok(r == ERROR_BAD_QUERY_SYNTAX,
7860 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7862 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7863 r = do_query(hdb, query, &hrec);
7864 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7866 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7867 r = do_query(hdb, query, &hrec);
7868 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7870 MsiCloseHandle(hdb);
7871 DeleteFileA(msifile);
7874 static void test_dbmerge(void)
7876 MSIHANDLE hdb, href, hview, hrec;
7877 CHAR buf[MAX_PATH];
7878 LPCSTR query;
7879 DWORD size;
7880 UINT r;
7882 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7883 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7885 r = MsiOpenDatabase("refdb.msi", MSIDBOPEN_CREATE, &href);
7886 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7888 /* hDatabase is invalid */
7889 r = MsiDatabaseMergeA(0, href, "MergeErrors");
7890 ok(r == ERROR_INVALID_HANDLE,
7891 "Expected ERROR_INVALID_HANDLE, got %d\n", r);
7893 /* hDatabaseMerge is invalid */
7894 r = MsiDatabaseMergeA(hdb, 0, "MergeErrors");
7895 ok(r == ERROR_INVALID_HANDLE,
7896 "Expected ERROR_INVALID_HANDLE, got %d\n", r);
7898 /* szTableName is NULL */
7899 r = MsiDatabaseMergeA(hdb, href, NULL);
7900 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7902 /* szTableName is empty */
7903 r = MsiDatabaseMergeA(hdb, href, "");
7904 ok(r == ERROR_INVALID_TABLE, "Expected ERROR_INVALID_TABLE, got %d\n", r);
7906 /* both DBs empty, szTableName is valid */
7907 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7908 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7910 query = "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7911 r = run_query(hdb, 0, query);
7912 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7914 query = "CREATE TABLE `One` ( `A` CHAR(72) PRIMARY KEY `A` )";
7915 r = run_query(href, 0, query);
7916 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7918 /* column types don't match */
7919 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7920 ok(r == ERROR_DATATYPE_MISMATCH,
7921 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7923 /* nothing in MergeErrors */
7924 query = "SELECT * FROM `MergeErrors`";
7925 r = do_query(hdb, query, &hrec);
7926 ok(r == ERROR_BAD_QUERY_SYNTAX,
7927 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7929 query = "DROP TABLE `One`";
7930 r = run_query(hdb, 0, query);
7931 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7933 query = "DROP TABLE `One`";
7934 r = run_query(href, 0, query);
7935 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7937 query = "CREATE TABLE `One` ( "
7938 "`A` CHAR(72), "
7939 "`B` CHAR(56), "
7940 "`C` CHAR(64) LOCALIZABLE, "
7941 "`D` LONGCHAR, "
7942 "`E` CHAR(72) NOT NULL, "
7943 "`F` CHAR(56) NOT NULL, "
7944 "`G` CHAR(64) NOT NULL LOCALIZABLE, "
7945 "`H` LONGCHAR NOT NULL "
7946 "PRIMARY KEY `A` )";
7947 r = run_query(hdb, 0, query);
7948 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7950 query = "CREATE TABLE `One` ( "
7951 "`A` CHAR(64), "
7952 "`B` CHAR(64), "
7953 "`C` CHAR(64), "
7954 "`D` CHAR(64), "
7955 "`E` CHAR(64) NOT NULL, "
7956 "`F` CHAR(64) NOT NULL, "
7957 "`G` CHAR(64) NOT NULL, "
7958 "`H` CHAR(64) NOT NULL "
7959 "PRIMARY KEY `A` )";
7960 r = run_query(href, 0, query);
7961 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7963 /* column sting types don't match exactly */
7964 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7965 ok(r == ERROR_SUCCESS,
7966 "Expected ERROR_SUCCESS, got %d\n", r);
7968 /* nothing in MergeErrors */
7969 query = "SELECT * FROM `MergeErrors`";
7970 r = do_query(hdb, query, &hrec);
7971 ok(r == ERROR_BAD_QUERY_SYNTAX,
7972 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7974 query = "DROP TABLE `One`";
7975 r = run_query(hdb, 0, query);
7976 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7978 query = "DROP TABLE `One`";
7979 r = run_query(href, 0, query);
7980 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7982 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7983 r = run_query(hdb, 0, query);
7984 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7986 query = "CREATE TABLE `One` ( `A` INT, `C` INT PRIMARY KEY `A` )";
7987 r = run_query(href, 0, query);
7988 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7990 /* column names don't match */
7991 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7992 ok(r == ERROR_DATATYPE_MISMATCH,
7993 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7995 /* nothing in MergeErrors */
7996 query = "SELECT * FROM `MergeErrors`";
7997 r = do_query(hdb, query, &hrec);
7998 ok(r == ERROR_BAD_QUERY_SYNTAX,
7999 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8001 query = "DROP TABLE `One`";
8002 r = run_query(hdb, 0, query);
8003 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8005 query = "DROP TABLE `One`";
8006 r = run_query(href, 0, query);
8007 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8009 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
8010 r = run_query(hdb, 0, query);
8011 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8013 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `B` )";
8014 r = run_query(href, 0, query);
8015 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8017 /* primary keys don't match */
8018 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8019 ok(r == ERROR_DATATYPE_MISMATCH,
8020 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
8022 /* nothing in MergeErrors */
8023 query = "SELECT * FROM `MergeErrors`";
8024 r = do_query(hdb, query, &hrec);
8025 ok(r == ERROR_BAD_QUERY_SYNTAX,
8026 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8028 query = "DROP TABLE `One`";
8029 r = run_query(hdb, 0, query);
8030 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8032 query = "DROP TABLE `One`";
8033 r = run_query(href, 0, query);
8034 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8036 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
8037 r = run_query(hdb, 0, query);
8038 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8040 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A`, `B` )";
8041 r = run_query(href, 0, query);
8042 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8044 /* number of primary keys doesn't match */
8045 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8046 ok(r == ERROR_DATATYPE_MISMATCH,
8047 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
8049 /* nothing in MergeErrors */
8050 query = "SELECT * FROM `MergeErrors`";
8051 r = do_query(hdb, query, &hrec);
8052 ok(r == ERROR_BAD_QUERY_SYNTAX,
8053 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8055 query = "DROP TABLE `One`";
8056 r = run_query(hdb, 0, query);
8057 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8059 query = "DROP TABLE `One`";
8060 r = run_query(href, 0, query);
8061 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8063 query = "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
8064 r = run_query(hdb, 0, query);
8065 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8067 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
8068 r = run_query(href, 0, query);
8069 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8071 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
8072 r = run_query(href, 0, query);
8073 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8075 /* number of columns doesn't match */
8076 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8077 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8079 query = "SELECT * FROM `One`";
8080 r = do_query(hdb, query, &hrec);
8081 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8083 r = MsiRecordGetInteger(hrec, 1);
8084 ok(r == 1, "Expected 1, got %d\n", r);
8086 r = MsiRecordGetInteger(hrec, 2);
8087 ok(r == 2, "Expected 2, got %d\n", r);
8089 r = MsiRecordGetInteger(hrec, 3);
8090 ok(r == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", r);
8092 MsiCloseHandle(hrec);
8094 /* nothing in MergeErrors */
8095 query = "SELECT * FROM `MergeErrors`";
8096 r = do_query(hdb, query, &hrec);
8097 ok(r == ERROR_BAD_QUERY_SYNTAX,
8098 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8100 query = "DROP TABLE `One`";
8101 r = run_query(hdb, 0, query);
8102 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8104 query = "DROP TABLE `One`";
8105 r = run_query(href, 0, query);
8106 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8108 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
8109 r = run_query(hdb, 0, query);
8110 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8112 query = "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
8113 r = run_query(href, 0, query);
8114 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8116 query = "INSERT INTO `One` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
8117 r = run_query(href, 0, query);
8118 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8120 /* number of columns doesn't match */
8121 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8122 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8124 query = "SELECT * FROM `One`";
8125 r = do_query(hdb, query, &hrec);
8126 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8128 r = MsiRecordGetInteger(hrec, 1);
8129 ok(r == 1, "Expected 1, got %d\n", r);
8131 r = MsiRecordGetInteger(hrec, 2);
8132 ok(r == 2, "Expected 2, got %d\n", r);
8134 r = MsiRecordGetInteger(hrec, 3);
8135 ok(r == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", r);
8137 MsiCloseHandle(hrec);
8139 /* nothing in MergeErrors */
8140 query = "SELECT * FROM `MergeErrors`";
8141 r = do_query(hdb, query, &hrec);
8142 ok(r == ERROR_BAD_QUERY_SYNTAX,
8143 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8145 query = "DROP TABLE `One`";
8146 r = run_query(hdb, 0, query);
8147 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8149 query = "DROP TABLE `One`";
8150 r = run_query(href, 0, query);
8151 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8153 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
8154 r = run_query(hdb, 0, query);
8155 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8157 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 1 )";
8158 r = run_query(hdb, 0, query);
8159 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8161 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 2 )";
8162 r = run_query(hdb, 0, query);
8163 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8165 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
8166 r = run_query(href, 0, query);
8167 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8169 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
8170 r = run_query(href, 0, query);
8171 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8173 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 3 )";
8174 r = run_query(href, 0, query);
8175 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8177 /* primary keys match, rows do not */
8178 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8179 ok(r == ERROR_FUNCTION_FAILED,
8180 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
8182 /* nothing in MergeErrors */
8183 query = "SELECT * FROM `MergeErrors`";
8184 r = do_query(hdb, query, &hrec);
8185 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8187 size = MAX_PATH;
8188 r = MsiRecordGetStringA(hrec, 1, buf, &size);
8189 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8190 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
8192 r = MsiRecordGetInteger(hrec, 2);
8193 ok(r == 2, "Expected 2, got %d\n", r);
8195 MsiCloseHandle(hrec);
8197 r = MsiDatabaseOpenViewA(hdb, "SELECT * FROM `MergeErrors`", &hview);
8198 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8200 r = MsiViewGetColumnInfo(hview, MSICOLINFO_NAMES, &hrec);
8201 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8203 size = MAX_PATH;
8204 r = MsiRecordGetString(hrec, 1, buf, &size);
8205 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8206 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
8208 size = MAX_PATH;
8209 r = MsiRecordGetString(hrec, 2, buf, &size);
8210 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8211 ok(!lstrcmpA(buf, "NumRowMergeConflicts"),
8212 "Expected \"NumRowMergeConflicts\", got \"%s\"\n", buf);
8214 MsiCloseHandle(hrec);
8216 r = MsiViewGetColumnInfo(hview, MSICOLINFO_TYPES, &hrec);
8217 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8219 size = MAX_PATH;
8220 r = MsiRecordGetString(hrec, 1, buf, &size);
8221 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8222 ok(!lstrcmpA(buf, "s255"), "Expected \"s255\", got \"%s\"\n", buf);
8224 size = MAX_PATH;
8225 r = MsiRecordGetString(hrec, 2, buf, &size);
8226 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8227 ok(!lstrcmpA(buf, "i2"), "Expected \"i2\", got \"%s\"\n", buf);
8229 MsiCloseHandle(hrec);
8230 MsiViewClose(hview);
8231 MsiCloseHandle(hview);
8233 query = "DROP TABLE `MergeErrors`";
8234 r = run_query(hdb, 0, query);
8235 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8237 query = "DROP TABLE `One`";
8238 r = run_query(hdb, 0, query);
8239 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8241 query = "DROP TABLE `One`";
8242 r = run_query(href, 0, query);
8243 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8245 query = "CREATE TABLE `One` ( `A` INT, `B` CHAR(72) PRIMARY KEY `A` )";
8246 r = run_query(href, 0, query);
8247 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8249 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
8250 r = run_query(href, 0, query);
8251 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8253 /* table from merged database is not in target database */
8254 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8255 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8257 query = "SELECT * FROM `One`";
8258 r = do_query(hdb, query, &hrec);
8259 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8261 r = MsiRecordGetInteger(hrec, 1);
8262 ok(r == 1, "Expected 1, got %d\n", r);
8264 size = MAX_PATH;
8265 r = MsiRecordGetStringA(hrec, 2, buf, &size);
8266 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8267 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
8269 MsiCloseHandle(hrec);
8271 /* nothing in MergeErrors */
8272 query = "SELECT * FROM `MergeErrors`";
8273 r = do_query(hdb, query, &hrec);
8274 ok(r == ERROR_BAD_QUERY_SYNTAX,
8275 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8277 query = "DROP TABLE `One`";
8278 r = run_query(hdb, 0, query);
8279 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8281 query = "DROP TABLE `One`";
8282 r = run_query(href, 0, query);
8283 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8285 query = "CREATE TABLE `One` ( "
8286 "`A` CHAR(72), `B` INT PRIMARY KEY `A` )";
8287 r = run_query(hdb, 0, query);
8288 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8290 query = "CREATE TABLE `One` ( "
8291 "`A` CHAR(72), `B` INT PRIMARY KEY `A` )";
8292 r = run_query(href, 0, query);
8293 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8295 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 'hi', 1 )";
8296 r = run_query(href, 0, query);
8297 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8299 /* primary key is string */
8300 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8301 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8303 query = "SELECT * FROM `One`";
8304 r = do_query(hdb, query, &hrec);
8305 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8307 size = MAX_PATH;
8308 r = MsiRecordGetStringA(hrec, 1, buf, &size);
8309 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8310 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
8312 r = MsiRecordGetInteger(hrec, 2);
8313 ok(r == 1, "Expected 1, got %d\n", r);
8315 MsiCloseHandle(hrec);
8317 /* nothing in MergeErrors */
8318 query = "SELECT * FROM `MergeErrors`";
8319 r = do_query(hdb, query, &hrec);
8320 ok(r == ERROR_BAD_QUERY_SYNTAX,
8321 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8323 create_file_data("codepage.idt", "\r\n\r\n850\t_ForceCodepage\r\n", 0);
8325 GetCurrentDirectoryA(MAX_PATH, buf);
8326 r = MsiDatabaseImportA(hdb, buf, "codepage.idt");
8327 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8329 query = "DROP TABLE `One`";
8330 r = run_query(hdb, 0, query);
8331 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8333 query = "DROP TABLE `One`";
8334 r = run_query(href, 0, query);
8335 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8337 query = "CREATE TABLE `One` ( "
8338 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
8339 r = run_query(hdb, 0, query);
8340 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8342 query = "CREATE TABLE `One` ( "
8343 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
8344 r = run_query(href, 0, query);
8345 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8347 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
8348 r = run_query(href, 0, query);
8349 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8351 /* code page does not match */
8352 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8353 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8355 query = "SELECT * FROM `One`";
8356 r = do_query(hdb, query, &hrec);
8357 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8359 r = MsiRecordGetInteger(hrec, 1);
8360 ok(r == 1, "Expected 1, got %d\n", r);
8362 size = MAX_PATH;
8363 r = MsiRecordGetStringA(hrec, 2, buf, &size);
8364 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8365 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
8367 MsiCloseHandle(hrec);
8369 /* nothing in MergeErrors */
8370 query = "SELECT * FROM `MergeErrors`";
8371 r = do_query(hdb, query, &hrec);
8372 ok(r == ERROR_BAD_QUERY_SYNTAX,
8373 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8375 query = "DROP TABLE `One`";
8376 r = run_query(hdb, 0, query);
8377 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8379 query = "DROP TABLE `One`";
8380 r = run_query(href, 0, query);
8381 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8383 query = "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
8384 r = run_query(hdb, 0, query);
8385 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8387 query = "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
8388 r = run_query(href, 0, query);
8389 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8391 create_file("binary.dat");
8392 hrec = MsiCreateRecord(1);
8393 MsiRecordSetStreamA(hrec, 1, "binary.dat");
8395 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, ? )";
8396 r = run_query(href, hrec, query);
8397 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8399 MsiCloseHandle(hrec);
8401 /* binary data to merge */
8402 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8403 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8405 query = "SELECT * FROM `One`";
8406 r = do_query(hdb, query, &hrec);
8407 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8409 r = MsiRecordGetInteger(hrec, 1);
8410 ok(r == 1, "Expected 1, got %d\n", r);
8412 size = MAX_PATH;
8413 ZeroMemory(buf, MAX_PATH);
8414 r = MsiRecordReadStream(hrec, 2, buf, &size);
8415 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8416 ok(!lstrcmpA(buf, "binary.dat\n"),
8417 "Expected \"binary.dat\\n\", got \"%s\"\n", buf);
8419 MsiCloseHandle(hrec);
8421 /* nothing in MergeErrors */
8422 query = "SELECT * FROM `MergeErrors`";
8423 r = do_query(hdb, query, &hrec);
8424 ok(r == ERROR_BAD_QUERY_SYNTAX,
8425 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8427 query = "DROP TABLE `One`";
8428 r = run_query(hdb, 0, query);
8429 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8431 query = "DROP TABLE `One`";
8432 r = run_query(href, 0, query);
8433 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8435 query = "CREATE TABLE `One` ( `A` INT, `B` CHAR(72) PRIMARY KEY `A` )";
8436 r = run_query(hdb, 0, query);
8437 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8438 r = run_query(href, 0, query);
8439 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8441 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'foo' )";
8442 r = run_query(href, 0, query);
8443 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8445 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 'bar' )";
8446 r = run_query(href, 0, query);
8447 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8449 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8450 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8452 query = "SELECT * FROM `One`";
8453 r = MsiDatabaseOpenViewA(hdb, query, &hview);
8454 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8455 r = MsiViewExecute(hview, 0);
8456 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8458 r = MsiViewFetch(hview, &hrec);
8459 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8461 r = MsiRecordGetInteger(hrec, 1);
8462 ok(r == 1, "Expected 1, got %d\n", r);
8464 size = MAX_PATH;
8465 r = MsiRecordGetStringA(hrec, 2, buf, &size);
8466 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8467 ok(!lstrcmpA(buf, "foo"), "Expected \"foo\", got \"%s\"\n", buf);
8469 MsiCloseHandle(hrec);
8471 r = MsiViewFetch(hview, &hrec);
8472 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8474 r = MsiRecordGetInteger(hrec, 1);
8475 ok(r == 2, "Expected 2, got %d\n", r);
8477 size = MAX_PATH;
8478 r = MsiRecordGetStringA(hrec, 2, buf, &size);
8479 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8480 ok(!lstrcmpA(buf, "bar"), "Expected \"bar\", got \"%s\"\n", buf);
8482 MsiCloseHandle(hrec);
8484 r = MsiViewFetch(hview, &hrec);
8485 ok(r == ERROR_NO_MORE_ITEMS,
8486 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8488 MsiViewClose(hview);
8489 MsiCloseHandle(hview);
8491 MsiCloseHandle(hdb);
8492 MsiCloseHandle(href);
8493 DeleteFileA(msifile);
8494 DeleteFileA("refdb.msi");
8495 DeleteFileA("codepage.idt");
8496 DeleteFileA("binary.dat");
8499 static void test_select_with_tablenames(void)
8501 MSIHANDLE hdb, view, rec;
8502 LPCSTR query;
8503 UINT r;
8504 int i;
8506 int vals[4][2] = {
8507 {1,12},
8508 {4,12},
8509 {1,15},
8510 {4,15}};
8512 hdb = create_db();
8513 ok(hdb, "failed to create db\n");
8515 /* Build a pair of tables with the same column names, but unique data */
8516 query = "CREATE TABLE `T1` ( `A` SHORT, `B` SHORT PRIMARY KEY `A`)";
8517 r = run_query(hdb, 0, query);
8518 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8520 query = "INSERT INTO `T1` ( `A`, `B` ) VALUES ( 1, 2 )";
8521 r = run_query(hdb, 0, query);
8522 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8524 query = "INSERT INTO `T1` ( `A`, `B` ) VALUES ( 4, 5 )";
8525 r = run_query(hdb, 0, query);
8526 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8528 query = "CREATE TABLE `T2` ( `A` SHORT, `B` SHORT PRIMARY KEY `A`)";
8529 r = run_query(hdb, 0, query);
8530 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8532 query = "INSERT INTO `T2` ( `A`, `B` ) VALUES ( 11, 12 )";
8533 r = run_query(hdb, 0, query);
8534 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8536 query = "INSERT INTO `T2` ( `A`, `B` ) VALUES ( 14, 15 )";
8537 r = run_query(hdb, 0, query);
8538 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8541 /* Test that selection based on prefixing the column with the table
8542 * actually selects the right data */
8544 query = "SELECT T1.A, T2.B FROM T1,T2";
8545 r = MsiDatabaseOpenView(hdb, query, &view);
8546 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8547 r = MsiViewExecute(view, 0);
8548 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8550 for (i = 0; i < 4; i++)
8552 r = MsiViewFetch(view, &rec);
8553 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8555 r = MsiRecordGetInteger(rec, 1);
8556 ok(r == vals[i][0], "Expected %d, got %d\n", vals[i][0], r);
8558 r = MsiRecordGetInteger(rec, 2);
8559 ok(r == vals[i][1], "Expected %d, got %d\n", vals[i][1], r);
8561 MsiCloseHandle(rec);
8564 r = MsiViewFetch(view, &rec);
8565 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8567 MsiViewClose(view);
8568 MsiCloseHandle(view);
8569 MsiCloseHandle(hdb);
8570 DeleteFileA(msifile);
8573 static const UINT ordervals[6][3] =
8575 { MSI_NULL_INTEGER, 12, 13 },
8576 { 1, 2, 3 },
8577 { 6, 4, 5 },
8578 { 8, 9, 7 },
8579 { 10, 11, MSI_NULL_INTEGER },
8580 { 14, MSI_NULL_INTEGER, 15 }
8583 static void test_insertorder(void)
8585 MSIHANDLE hdb, view, rec;
8586 LPCSTR query;
8587 UINT r;
8588 int i;
8590 hdb = create_db();
8591 ok(hdb, "failed to create db\n");
8593 query = "CREATE TABLE `T` ( `A` SHORT, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
8594 r = run_query(hdb, 0, query);
8595 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8597 query = "INSERT INTO `T` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
8598 r = run_query(hdb, 0, query);
8599 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8601 query = "INSERT INTO `T` ( `B`, `C`, `A` ) VALUES ( 4, 5, 6 )";
8602 r = run_query(hdb, 0, query);
8603 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8605 query = "INSERT INTO `T` ( `C`, `A`, `B` ) VALUES ( 7, 8, 9 )";
8606 r = run_query(hdb, 0, query);
8607 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8609 query = "INSERT INTO `T` ( `A`, `B` ) VALUES ( 10, 11 )";
8610 r = run_query(hdb, 0, query);
8611 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8613 query = "INSERT INTO `T` ( `B`, `C` ) VALUES ( 12, 13 )";
8614 r = run_query(hdb, 0, query);
8615 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8617 /* fails because the primary key already
8618 * has an MSI_NULL_INTEGER value set above
8620 query = "INSERT INTO `T` ( `C` ) VALUES ( 14 )";
8621 r = run_query(hdb, 0, query);
8622 ok(r == ERROR_FUNCTION_FAILED,
8623 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
8625 /* replicate the error where primary key is set twice */
8626 query = "INSERT INTO `T` ( `A`, `C` ) VALUES ( 1, 14 )";
8627 r = run_query(hdb, 0, query);
8628 ok(r == ERROR_FUNCTION_FAILED,
8629 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
8631 query = "INSERT INTO `T` ( `A`, `C` ) VALUES ( 14, 15 )";
8632 r = run_query(hdb, 0, query);
8633 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8635 query = "INSERT INTO `T` VALUES ( 16 )";
8636 r = run_query(hdb, 0, query);
8637 ok(r == ERROR_BAD_QUERY_SYNTAX,
8638 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8640 query = "INSERT INTO `T` VALUES ( 17, 18 )";
8641 r = run_query(hdb, 0, query);
8642 ok(r == ERROR_BAD_QUERY_SYNTAX,
8643 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8645 query = "INSERT INTO `T` VALUES ( 19, 20, 21 )";
8646 r = run_query(hdb, 0, query);
8647 ok(r == ERROR_BAD_QUERY_SYNTAX,
8648 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8650 query = "SELECT * FROM `T`";
8651 r = MsiDatabaseOpenView(hdb, query, &view);
8652 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8653 r = MsiViewExecute(view, 0);
8654 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8656 for (i = 0; i < 6; i++)
8658 r = MsiViewFetch(view, &rec);
8659 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8661 r = MsiRecordGetInteger(rec, 1);
8662 ok(r == ordervals[i][0], "Expected %d, got %d\n", ordervals[i][0], r);
8664 r = MsiRecordGetInteger(rec, 2);
8665 ok(r == ordervals[i][1], "Expected %d, got %d\n", ordervals[i][1], r);
8667 r = MsiRecordGetInteger(rec, 3);
8668 ok(r == ordervals[i][2], "Expected %d, got %d\n", ordervals[i][2], r);
8670 MsiCloseHandle(rec);
8673 r = MsiViewFetch(view, &rec);
8674 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8676 MsiViewClose(view);
8677 MsiCloseHandle(view);
8679 query = "DELETE FROM `T` WHERE `A` IS NULL";
8680 r = run_query(hdb, 0, query);
8681 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8683 query = "INSERT INTO `T` ( `B`, `C` ) VALUES ( 12, 13 ) TEMPORARY";
8684 r = run_query(hdb, 0, query);
8685 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8687 query = "SELECT * FROM `T`";
8688 r = MsiDatabaseOpenView(hdb, query, &view);
8689 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8690 r = MsiViewExecute(view, 0);
8691 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8693 for (i = 0; i < 6; i++)
8695 r = MsiViewFetch(view, &rec);
8696 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8698 r = MsiRecordGetInteger(rec, 1);
8699 ok(r == ordervals[i][0], "Expected %d, got %d\n", ordervals[i][0], r);
8701 r = MsiRecordGetInteger(rec, 2);
8702 ok(r == ordervals[i][1], "Expected %d, got %d\n", ordervals[i][1], r);
8704 r = MsiRecordGetInteger(rec, 3);
8705 ok(r == ordervals[i][2], "Expected %d, got %d\n", ordervals[i][2], r);
8707 MsiCloseHandle(rec);
8710 r = MsiViewFetch(view, &rec);
8711 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8713 MsiViewClose(view);
8714 MsiCloseHandle(view);
8715 MsiCloseHandle(hdb);
8716 DeleteFileA(msifile);
8719 static void test_columnorder(void)
8721 MSIHANDLE hdb, view, rec;
8722 char buf[MAX_PATH];
8723 LPCSTR query;
8724 DWORD sz;
8725 UINT r;
8727 hdb = create_db();
8728 ok(hdb, "failed to create db\n");
8730 /* Each column is a slot:
8731 * ---------------------
8732 * | B | C | A | E | D |
8733 * ---------------------
8735 * When a column is selected as a primary key,
8736 * the column occupying the nth primary key slot is swapped
8737 * with the current position of the primary key in question:
8739 * set primary key `D`
8740 * --------------------- ---------------------
8741 * | B | C | A | E | D | -> | D | C | A | E | B |
8742 * --------------------- ---------------------
8744 * set primary key `E`
8745 * --------------------- ---------------------
8746 * | D | C | A | E | B | -> | D | E | A | C | B |
8747 * --------------------- ---------------------
8750 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL, `C` SHORT NOT NULL, "
8751 "`A` CHAR(255), `E` INT, `D` CHAR(255) NOT NULL "
8752 "PRIMARY KEY `D`, `E`)";
8753 r = run_query(hdb, 0, query);
8754 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8756 query = "SELECT * FROM `T`";
8757 r = MsiDatabaseOpenView(hdb, query, &view);
8758 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8760 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
8761 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8763 sz = MAX_PATH;
8764 lstrcpyA(buf, "kiwi");
8765 r = MsiRecordGetString(rec, 1, buf, &sz);
8766 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8767 ok(!lstrcmpA("s255", buf), "Expected \"s255\", got \"%s\"\n", buf);
8769 sz = MAX_PATH;
8770 lstrcpyA(buf, "kiwi");
8771 r = MsiRecordGetString(rec, 2, buf, &sz);
8772 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8773 ok(!lstrcmpA("I2", buf), "Expected \"I2\", got \"%s\"\n", buf);
8775 sz = MAX_PATH;
8776 lstrcpyA(buf, "kiwi");
8777 r = MsiRecordGetString(rec, 3, buf, &sz);
8778 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8779 ok(!lstrcmpA("S255", buf), "Expected \"S255\", got \"%s\"\n", buf);
8781 sz = MAX_PATH;
8782 lstrcpyA(buf, "kiwi");
8783 r = MsiRecordGetString(rec, 4, buf, &sz);
8784 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8785 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8787 sz = MAX_PATH;
8788 lstrcpyA(buf, "kiwi");
8789 r = MsiRecordGetString(rec, 5, buf, &sz);
8790 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8791 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8793 MsiCloseHandle(rec);
8795 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
8796 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8798 sz = MAX_PATH;
8799 lstrcpyA(buf, "kiwi");
8800 r = MsiRecordGetString(rec, 1, buf, &sz);
8801 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8802 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8804 sz = MAX_PATH;
8805 lstrcpyA(buf, "kiwi");
8806 r = MsiRecordGetString(rec, 2, buf, &sz);
8807 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8808 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8810 sz = MAX_PATH;
8811 lstrcpyA(buf, "kiwi");
8812 r = MsiRecordGetString(rec, 3, buf, &sz);
8813 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8814 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8816 sz = MAX_PATH;
8817 lstrcpyA(buf, "kiwi");
8818 r = MsiRecordGetString(rec, 4, buf, &sz);
8819 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8820 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8822 sz = MAX_PATH;
8823 lstrcpyA(buf, "kiwi");
8824 r = MsiRecordGetString(rec, 5, buf, &sz);
8825 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8826 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8828 MsiCloseHandle(rec);
8829 MsiViewClose(view);
8830 MsiCloseHandle(view);
8832 query = "INSERT INTO `T` ( `B`, `C`, `A`, `E`, `D` ) "
8833 "VALUES ( 1, 2, 'a', 3, 'bc' )";
8834 r = run_query(hdb, 0, query);
8835 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8837 query = "SELECT * FROM `T`";
8838 r = do_query(hdb, query, &rec);
8839 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8841 sz = MAX_PATH;
8842 lstrcpyA(buf, "kiwi");
8843 r = MsiRecordGetString(rec, 1, buf, &sz);
8844 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8845 ok(!lstrcmpA("bc", buf), "Expected \"bc\", got \"%s\"\n", buf);
8847 r = MsiRecordGetInteger(rec, 2);
8848 ok(r == 3, "Expected 3, got %d\n", r);
8850 sz = MAX_PATH;
8851 lstrcpyA(buf, "kiwi");
8852 r = MsiRecordGetString(rec, 3, buf, &sz);
8853 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8854 ok(!lstrcmpA("a", buf), "Expected \"a\", got \"%s\"\n", buf);
8856 r = MsiRecordGetInteger(rec, 4);
8857 ok(r == 2, "Expected 2, got %d\n", r);
8859 r = MsiRecordGetInteger(rec, 5);
8860 ok(r == 1, "Expected 1, got %d\n", r);
8862 MsiCloseHandle(rec);
8864 query = "SELECT * FROM `_Columns` WHERE `Table` = 'T'";
8865 r = MsiDatabaseOpenView(hdb, query, &view);
8866 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8867 r = MsiViewExecute(view, 0);
8868 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8870 r = MsiViewFetch(view, &rec);
8871 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8873 sz = MAX_PATH;
8874 lstrcpyA(buf, "kiwi");
8875 r = MsiRecordGetString(rec, 1, buf, &sz);
8876 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8877 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8879 r = MsiRecordGetInteger(rec, 2);
8880 ok(r == 1, "Expected 1, got %d\n", r);
8882 sz = MAX_PATH;
8883 lstrcpyA(buf, "kiwi");
8884 r = MsiRecordGetString(rec, 3, buf, &sz);
8885 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8886 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8888 MsiCloseHandle(rec);
8890 r = MsiViewFetch(view, &rec);
8891 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8893 sz = MAX_PATH;
8894 lstrcpyA(buf, "kiwi");
8895 r = MsiRecordGetString(rec, 1, buf, &sz);
8896 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8897 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8899 r = MsiRecordGetInteger(rec, 2);
8900 ok(r == 2, "Expected 2, got %d\n", r);
8902 sz = MAX_PATH;
8903 lstrcpyA(buf, "kiwi");
8904 r = MsiRecordGetString(rec, 3, buf, &sz);
8905 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8906 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8908 MsiCloseHandle(rec);
8910 r = MsiViewFetch(view, &rec);
8911 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8913 sz = MAX_PATH;
8914 lstrcpyA(buf, "kiwi");
8915 r = MsiRecordGetString(rec, 1, buf, &sz);
8916 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8917 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8919 r = MsiRecordGetInteger(rec, 2);
8920 ok(r == 3, "Expected 3, got %d\n", r);
8922 sz = MAX_PATH;
8923 lstrcpyA(buf, "kiwi");
8924 r = MsiRecordGetString(rec, 3, buf, &sz);
8925 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8926 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8928 MsiCloseHandle(rec);
8930 r = MsiViewFetch(view, &rec);
8931 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8933 sz = MAX_PATH;
8934 lstrcpyA(buf, "kiwi");
8935 r = MsiRecordGetString(rec, 1, buf, &sz);
8936 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8937 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8939 r = MsiRecordGetInteger(rec, 2);
8940 ok(r == 4, "Expected 4, got %d\n", r);
8942 sz = MAX_PATH;
8943 lstrcpyA(buf, "kiwi");
8944 r = MsiRecordGetString(rec, 3, buf, &sz);
8945 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8946 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8948 MsiCloseHandle(rec);
8950 r = MsiViewFetch(view, &rec);
8951 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8953 sz = MAX_PATH;
8954 lstrcpyA(buf, "kiwi");
8955 r = MsiRecordGetString(rec, 1, buf, &sz);
8956 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8957 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8959 r = MsiRecordGetInteger(rec, 2);
8960 ok(r == 5, "Expected 5, got %d\n", r);
8962 sz = MAX_PATH;
8963 lstrcpyA(buf, "kiwi");
8964 r = MsiRecordGetString(rec, 3, buf, &sz);
8965 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8966 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8968 MsiCloseHandle(rec);
8970 r = MsiViewFetch(view, &rec);
8971 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8973 MsiViewClose(view);
8974 MsiCloseHandle(view);
8976 query = "CREATE TABLE `Z` ( `B` SHORT NOT NULL, `C` SHORT NOT NULL, "
8977 "`A` CHAR(255), `E` INT, `D` CHAR(255) NOT NULL "
8978 "PRIMARY KEY `C`, `A`, `D`)";
8979 r = run_query(hdb, 0, query);
8980 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8982 query = "SELECT * FROM `Z`";
8983 r = MsiDatabaseOpenView(hdb, query, &view);
8984 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8986 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
8987 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8989 sz = MAX_PATH;
8990 lstrcpyA(buf, "kiwi");
8991 r = MsiRecordGetString(rec, 1, buf, &sz);
8992 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8993 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8995 sz = MAX_PATH;
8996 lstrcpyA(buf, "kiwi");
8997 r = MsiRecordGetString(rec, 2, buf, &sz);
8998 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8999 ok(!lstrcmpA("S255", buf), "Expected \"S255\", got \"%s\"\n", buf);
9001 sz = MAX_PATH;
9002 lstrcpyA(buf, "kiwi");
9003 r = MsiRecordGetString(rec, 3, buf, &sz);
9004 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9005 ok(!lstrcmpA("s255", buf), "Expected \"s255\", got \"%s\"\n", buf);
9007 sz = MAX_PATH;
9008 lstrcpyA(buf, "kiwi");
9009 r = MsiRecordGetString(rec, 4, buf, &sz);
9010 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9011 ok(!lstrcmpA("I2", buf), "Expected \"I2\", got \"%s\"\n", buf);
9013 sz = MAX_PATH;
9014 lstrcpyA(buf, "kiwi");
9015 r = MsiRecordGetString(rec, 5, buf, &sz);
9016 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9017 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
9019 MsiCloseHandle(rec);
9021 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
9022 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9024 sz = MAX_PATH;
9025 lstrcpyA(buf, "kiwi");
9026 r = MsiRecordGetString(rec, 1, buf, &sz);
9027 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9028 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
9030 sz = MAX_PATH;
9031 lstrcpyA(buf, "kiwi");
9032 r = MsiRecordGetString(rec, 2, buf, &sz);
9033 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9034 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
9036 sz = MAX_PATH;
9037 lstrcpyA(buf, "kiwi");
9038 r = MsiRecordGetString(rec, 3, buf, &sz);
9039 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9040 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
9042 sz = MAX_PATH;
9043 lstrcpyA(buf, "kiwi");
9044 r = MsiRecordGetString(rec, 4, buf, &sz);
9045 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9046 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
9048 sz = MAX_PATH;
9049 lstrcpyA(buf, "kiwi");
9050 r = MsiRecordGetString(rec, 5, buf, &sz);
9051 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9052 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
9054 MsiCloseHandle(rec);
9055 MsiViewClose(view);
9056 MsiCloseHandle(view);
9058 query = "INSERT INTO `Z` ( `B`, `C`, `A`, `E`, `D` ) "
9059 "VALUES ( 1, 2, 'a', 3, 'bc' )";
9060 r = run_query(hdb, 0, query);
9061 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9063 query = "SELECT * FROM `Z`";
9064 r = do_query(hdb, query, &rec);
9065 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9067 r = MsiRecordGetInteger(rec, 1);
9068 ok(r == 2, "Expected 2, got %d\n", r);
9070 sz = MAX_PATH;
9071 lstrcpyA(buf, "kiwi");
9072 r = MsiRecordGetString(rec, 2, buf, &sz);
9073 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9074 ok(!lstrcmpA("a", buf), "Expected \"a\", got \"%s\"\n", buf);
9076 sz = MAX_PATH;
9077 lstrcpyA(buf, "kiwi");
9078 r = MsiRecordGetString(rec, 3, buf, &sz);
9079 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9080 ok(!lstrcmpA("bc", buf), "Expected \"bc\", got \"%s\"\n", buf);
9082 r = MsiRecordGetInteger(rec, 4);
9083 ok(r == 3, "Expected 3, got %d\n", r);
9085 r = MsiRecordGetInteger(rec, 5);
9086 ok(r == 1, "Expected 1, got %d\n", r);
9088 MsiCloseHandle(rec);
9090 query = "SELECT * FROM `_Columns` WHERE `Table` = 'T'";
9091 r = MsiDatabaseOpenView(hdb, query, &view);
9092 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9093 r = MsiViewExecute(view, 0);
9094 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9096 r = MsiViewFetch(view, &rec);
9097 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9099 sz = MAX_PATH;
9100 lstrcpyA(buf, "kiwi");
9101 r = MsiRecordGetString(rec, 1, buf, &sz);
9102 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9103 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
9105 r = MsiRecordGetInteger(rec, 2);
9106 ok(r == 1, "Expected 1, got %d\n", r);
9108 sz = MAX_PATH;
9109 lstrcpyA(buf, "kiwi");
9110 r = MsiRecordGetString(rec, 3, buf, &sz);
9111 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9112 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
9114 MsiCloseHandle(rec);
9116 r = MsiViewFetch(view, &rec);
9117 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9119 sz = MAX_PATH;
9120 lstrcpyA(buf, "kiwi");
9121 r = MsiRecordGetString(rec, 1, buf, &sz);
9122 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9123 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
9125 r = MsiRecordGetInteger(rec, 2);
9126 ok(r == 2, "Expected 2, got %d\n", r);
9128 sz = MAX_PATH;
9129 lstrcpyA(buf, "kiwi");
9130 r = MsiRecordGetString(rec, 3, buf, &sz);
9131 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9132 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
9134 MsiCloseHandle(rec);
9136 r = MsiViewFetch(view, &rec);
9137 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9139 sz = MAX_PATH;
9140 lstrcpyA(buf, "kiwi");
9141 r = MsiRecordGetString(rec, 1, buf, &sz);
9142 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9143 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
9145 r = MsiRecordGetInteger(rec, 2);
9146 ok(r == 3, "Expected 3, got %d\n", r);
9148 sz = MAX_PATH;
9149 lstrcpyA(buf, "kiwi");
9150 r = MsiRecordGetString(rec, 3, buf, &sz);
9151 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9152 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
9154 MsiCloseHandle(rec);
9156 r = MsiViewFetch(view, &rec);
9157 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9159 sz = MAX_PATH;
9160 lstrcpyA(buf, "kiwi");
9161 r = MsiRecordGetString(rec, 1, buf, &sz);
9162 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9163 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
9165 r = MsiRecordGetInteger(rec, 2);
9166 ok(r == 4, "Expected 4, got %d\n", r);
9168 sz = MAX_PATH;
9169 lstrcpyA(buf, "kiwi");
9170 r = MsiRecordGetString(rec, 3, buf, &sz);
9171 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9172 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
9174 MsiCloseHandle(rec);
9176 r = MsiViewFetch(view, &rec);
9177 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9179 sz = MAX_PATH;
9180 lstrcpyA(buf, "kiwi");
9181 r = MsiRecordGetString(rec, 1, buf, &sz);
9182 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9183 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
9185 r = MsiRecordGetInteger(rec, 2);
9186 ok(r == 5, "Expected 5, got %d\n", r);
9188 sz = MAX_PATH;
9189 lstrcpyA(buf, "kiwi");
9190 r = MsiRecordGetString(rec, 3, buf, &sz);
9191 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
9192 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
9194 MsiCloseHandle(rec);
9196 r = MsiViewFetch(view, &rec);
9197 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
9199 MsiViewClose(view);
9200 MsiCloseHandle(view);
9202 MsiCloseHandle(hdb);
9203 DeleteFileA(msifile);
9206 static void test_createtable(void)
9208 MSIHANDLE hdb, htab = 0, hrec = 0;
9209 LPCSTR query;
9210 UINT res;
9211 DWORD size;
9212 char buffer[0x20];
9214 hdb = create_db();
9215 ok(hdb, "failed to create db\n");
9217 query = "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL PRIMARY KEY `foo`)";
9218 res = MsiDatabaseOpenView( hdb, query, &htab );
9219 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9220 if(res == ERROR_SUCCESS )
9222 res = MsiViewExecute( htab, hrec );
9223 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9225 res = MsiViewGetColumnInfo( htab, MSICOLINFO_NAMES, &hrec );
9226 todo_wine ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9228 size = sizeof(buffer);
9229 res = MsiRecordGetString(hrec, 1, buffer, &size );
9230 todo_wine ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9231 MsiCloseHandle( hrec );
9233 res = MsiViewClose( htab );
9234 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9236 res = MsiCloseHandle( htab );
9237 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9240 query = "CREATE TABLE `a` (`b` INT PRIMARY KEY `b`)";
9241 res = MsiDatabaseOpenView( hdb, query, &htab );
9242 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9243 if(res == ERROR_SUCCESS )
9245 res = MsiViewExecute( htab, 0 );
9246 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9248 res = MsiViewClose( htab );
9249 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9251 res = MsiCloseHandle( htab );
9252 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9254 query = "SELECT * FROM `a`";
9255 res = MsiDatabaseOpenView( hdb, query, &htab );
9256 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9258 res = MsiViewGetColumnInfo( htab, MSICOLINFO_NAMES, &hrec );
9259 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9261 buffer[0] = 0;
9262 size = sizeof(buffer);
9263 res = MsiRecordGetString(hrec, 1, buffer, &size );
9264 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9265 ok(!strcmp(buffer,"b"), "b != %s\n", buffer);
9266 MsiCloseHandle( hrec );
9268 res = MsiViewClose( htab );
9269 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9271 res = MsiCloseHandle( htab );
9272 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9274 res = MsiDatabaseCommit(hdb);
9275 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9277 res = MsiCloseHandle(hdb);
9278 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9280 res = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
9281 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9283 query = "SELECT * FROM `a`";
9284 res = MsiDatabaseOpenView( hdb, query, &htab );
9285 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9287 res = MsiViewGetColumnInfo( htab, MSICOLINFO_NAMES, &hrec );
9288 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9290 buffer[0] = 0;
9291 size = sizeof(buffer);
9292 res = MsiRecordGetString(hrec, 1, buffer, &size );
9293 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9294 todo_wine ok(!strcmp(buffer,"b"), "b != %s\n", buffer);
9296 res = MsiCloseHandle( hrec );
9297 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9299 res = MsiViewClose( htab );
9300 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9302 res = MsiCloseHandle( htab );
9303 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9306 res = MsiDatabaseCommit(hdb);
9307 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9309 res = MsiCloseHandle(hdb);
9310 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
9312 DeleteFileA(msifile);
9315 static void test_embedded_nulls(void)
9317 static const char control_table[] =
9318 "Dialog\tText\n"
9319 "s72\tL0\n"
9320 "Control\tDialog\n"
9321 "LicenseAgreementDlg\ttext\x11\x19text\0text";
9322 UINT r, sz;
9323 MSIHANDLE hdb, hrec;
9324 char buffer[32];
9326 r = MsiOpenDatabaseA( msifile, MSIDBOPEN_CREATE, &hdb );
9327 ok( r == ERROR_SUCCESS, "failed to open database %u\n", r );
9329 GetCurrentDirectoryA( MAX_PATH, CURR_DIR );
9330 write_file( "temp_file", control_table, sizeof(control_table) );
9331 r = MsiDatabaseImportA( hdb, CURR_DIR, "temp_file" );
9332 ok( r == ERROR_SUCCESS, "failed to import table %u\n", r );
9333 DeleteFileA( "temp_file" );
9335 r = do_query( hdb, "SELECT `Text` FROM `Control` WHERE `Dialog` = 'LicenseAgreementDlg'", &hrec );
9336 ok( r == ERROR_SUCCESS, "query failed %u\n", r );
9338 buffer[0] = 0;
9339 sz = sizeof(buffer);
9340 r = MsiRecordGetStringA( hrec, 1, buffer, &sz );
9341 ok( r == ERROR_SUCCESS, "failed to get string %u\n", r );
9342 ok( !memcmp( "text\r\ntext\ntext", buffer, sizeof("text\r\ntext\ntext") - 1 ), "wrong buffer contents \"%s\"\n", buffer );
9344 MsiCloseHandle( hrec );
9345 MsiCloseHandle( hdb );
9346 DeleteFileA( msifile );
9349 START_TEST(db)
9351 test_msidatabase();
9352 test_msiinsert();
9353 test_msidecomposedesc();
9354 test_msibadqueries();
9355 test_viewmodify();
9356 test_viewgetcolumninfo();
9357 test_getcolinfo();
9358 test_msiexport();
9359 test_longstrings();
9360 test_streamtable();
9361 test_binary();
9362 test_where_not_in_selected();
9363 test_where();
9364 test_msiimport();
9365 test_binary_import();
9366 test_markers();
9367 test_handle_limit();
9368 test_try_transform();
9369 test_join();
9370 test_temporary_table();
9371 test_alter();
9372 test_integers();
9373 test_update();
9374 test_special_tables();
9375 test_tables_order();
9376 test_rows_order();
9377 test_select_markers();
9378 test_viewmodify_update();
9379 test_viewmodify_assign();
9380 test_stringtable();
9381 test_viewmodify_delete();
9382 test_defaultdatabase();
9383 test_order();
9384 test_viewmodify_delete_temporary();
9385 test_deleterow();
9386 test_quotes();
9387 test_carriagereturn();
9388 test_noquotes();
9389 test_forcecodepage();
9390 test_viewmodify_refresh();
9391 test_where_viewmodify();
9392 test_storages_table();
9393 test_dbtopackage();
9394 test_droptable();
9395 test_dbmerge();
9396 test_select_with_tablenames();
9397 test_insertorder();
9398 test_columnorder();
9399 test_suminfo_import();
9400 test_createtable();
9401 test_collation();
9402 test_embedded_nulls();