wined3d: read_from_framebuffer_texture() isn't suitable for readback of onscreen...
[wine/testsucceed.git] / dlls / msi / tests / db.c
blob5e8505ad109fef032010a569d339919be374771c
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 = MsiCloseHandle( hdb );
100 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
102 res = MsiOpenDatabase( msifile, MSIDBOPEN_DIRECT, &hdb );
103 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
105 res = MsiCloseHandle( hdb );
106 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
108 res = MsiOpenDatabase( msifile, MSIDBOPEN_TRANSACT, &hdb );
109 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
111 res = MsiCloseHandle( hdb );
112 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
113 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
115 /* MSIDBOPEN_CREATE deletes the database if MsiCommitDatabase isn't called */
116 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
117 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
119 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
121 res = MsiCloseHandle( hdb );
122 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
124 ok( INVALID_FILE_ATTRIBUTES == GetFileAttributes( msifile ), "database should exist\n");
126 res = MsiOpenDatabase( msifile, MSIDBOPEN_CREATE, &hdb );
127 ok( res == ERROR_SUCCESS , "Failed to open database\n" );
129 res = MsiDatabaseCommit( hdb );
130 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
132 ok( INVALID_FILE_ATTRIBUTES != GetFileAttributes( msifile ), "database should exist\n");
134 res = MsiCloseHandle( hdb );
135 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
137 res = DeleteFile( msifile2 );
138 ok( res == TRUE, "Failed to delete database\n" );
140 res = DeleteFile( msifile );
141 ok( res == TRUE, "Failed to delete database\n" );
144 static UINT do_query(MSIHANDLE hdb, const char *query, MSIHANDLE *phrec)
146 MSIHANDLE hview = 0;
147 UINT r, ret;
149 if (phrec)
150 *phrec = 0;
152 /* open a select query */
153 r = MsiDatabaseOpenView(hdb, query, &hview);
154 if (r != ERROR_SUCCESS)
155 return r;
156 r = MsiViewExecute(hview, 0);
157 if (r != ERROR_SUCCESS)
158 return r;
159 ret = MsiViewFetch(hview, phrec);
160 r = MsiViewClose(hview);
161 if (r != ERROR_SUCCESS)
162 return r;
163 r = MsiCloseHandle(hview);
164 if (r != ERROR_SUCCESS)
165 return r;
166 return ret;
169 static UINT run_query( MSIHANDLE hdb, MSIHANDLE hrec, const char *query )
171 MSIHANDLE hview = 0;
172 UINT r;
174 r = MsiDatabaseOpenView(hdb, query, &hview);
175 if( r != ERROR_SUCCESS )
176 return r;
178 r = MsiViewExecute(hview, hrec);
179 if( r == ERROR_SUCCESS )
180 r = MsiViewClose(hview);
181 MsiCloseHandle(hview);
182 return r;
185 static UINT create_component_table( MSIHANDLE hdb )
187 return run_query( hdb, 0,
188 "CREATE TABLE `Component` ( "
189 "`Component` CHAR(72) NOT NULL, "
190 "`ComponentId` CHAR(38), "
191 "`Directory_` CHAR(72) NOT NULL, "
192 "`Attributes` SHORT NOT NULL, "
193 "`Condition` CHAR(255), "
194 "`KeyPath` CHAR(72) "
195 "PRIMARY KEY `Component`)" );
198 static UINT create_custom_action_table( MSIHANDLE hdb )
200 return run_query( hdb, 0,
201 "CREATE TABLE `CustomAction` ( "
202 "`Action` CHAR(72) NOT NULL, "
203 "`Type` SHORT NOT NULL, "
204 "`Source` CHAR(72), "
205 "`Target` CHAR(255) "
206 "PRIMARY KEY `Action`)" );
209 static UINT create_directory_table( MSIHANDLE hdb )
211 return run_query( hdb, 0,
212 "CREATE TABLE `Directory` ( "
213 "`Directory` CHAR(255) NOT NULL, "
214 "`Directory_Parent` CHAR(255), "
215 "`DefaultDir` CHAR(255) NOT NULL "
216 "PRIMARY KEY `Directory`)" );
219 static UINT create_feature_components_table( MSIHANDLE hdb )
221 return run_query( hdb, 0,
222 "CREATE TABLE `FeatureComponents` ( "
223 "`Feature_` CHAR(38) NOT NULL, "
224 "`Component_` CHAR(72) NOT NULL "
225 "PRIMARY KEY `Feature_`, `Component_` )" );
228 static UINT create_std_dlls_table( MSIHANDLE hdb )
230 return run_query( hdb, 0,
231 "CREATE TABLE `StdDlls` ( "
232 "`File` CHAR(255) NOT NULL, "
233 "`Binary_` CHAR(72) NOT NULL "
234 "PRIMARY KEY `File` )" );
237 static UINT create_binary_table( MSIHANDLE hdb )
239 return run_query( hdb, 0,
240 "CREATE TABLE `Binary` ( "
241 "`Name` CHAR(72) NOT NULL, "
242 "`Data` CHAR(72) NOT NULL "
243 "PRIMARY KEY `Name` )" );
246 #define make_add_entry(type, qtext) \
247 static UINT add##_##type##_##entry( MSIHANDLE hdb, const char *values ) \
249 char insert[] = qtext; \
250 char *query; \
251 UINT sz, r; \
252 sz = strlen(values) + sizeof insert; \
253 query = HeapAlloc(GetProcessHeap(),0,sz); \
254 sprintf(query,insert,values); \
255 r = run_query( hdb, 0, query ); \
256 HeapFree(GetProcessHeap(), 0, query); \
257 return r; \
260 make_add_entry(component,
261 "INSERT INTO `Component` "
262 "(`Component`, `ComponentId`, `Directory_`, "
263 "`Attributes`, `Condition`, `KeyPath`) VALUES( %s )")
265 make_add_entry(custom_action,
266 "INSERT INTO `CustomAction` "
267 "(`Action`, `Type`, `Source`, `Target`) VALUES( %s )")
269 make_add_entry(feature_components,
270 "INSERT INTO `FeatureComponents` "
271 "(`Feature_`, `Component_`) VALUES( %s )")
273 make_add_entry(std_dlls,
274 "INSERT INTO `StdDlls` (`File`, `Binary_`) VALUES( %s )")
276 make_add_entry(binary,
277 "INSERT INTO `Binary` (`Name`, `Data`) VALUES( %s )")
279 static void test_msiinsert(void)
281 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
282 UINT r;
283 const char *query;
284 char buf[80];
285 DWORD sz;
287 DeleteFile(msifile);
289 /* just MsiOpenDatabase should not create a file */
290 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
291 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
293 /* create a table */
294 query = "CREATE TABLE `phone` ( "
295 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
296 "PRIMARY KEY `id`)";
297 r = MsiDatabaseOpenView(hdb, query, &hview);
298 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
299 r = MsiViewExecute(hview, 0);
300 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
301 r = MsiViewClose(hview);
302 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
303 r = MsiCloseHandle(hview);
304 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
306 /* insert a value into it */
307 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
308 "VALUES('1', 'Abe', '8675309')";
309 r = MsiDatabaseOpenView(hdb, query, &hview);
310 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
311 r = MsiViewExecute(hview, 0);
312 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
313 r = MsiViewClose(hview);
314 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
315 r = MsiCloseHandle(hview);
316 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
318 query = "SELECT * FROM `phone` WHERE `id` = 1";
319 r = do_query(hdb, query, &hrec);
320 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
322 /* check the record contains what we put in it */
323 r = MsiRecordGetFieldCount(hrec);
324 ok(r == 3, "record count wrong\n");
326 r = MsiRecordIsNull(hrec, 0);
327 ok(r == FALSE, "field 0 not null\n");
329 r = MsiRecordGetInteger(hrec, 1);
330 ok(r == 1, "field 1 contents wrong\n");
331 sz = sizeof buf;
332 r = MsiRecordGetString(hrec, 2, buf, &sz);
333 ok(r == ERROR_SUCCESS, "field 2 content fetch failed\n");
334 ok(!strcmp(buf,"Abe"), "field 2 content incorrect\n");
335 sz = sizeof buf;
336 r = MsiRecordGetString(hrec, 3, buf, &sz);
337 ok(r == ERROR_SUCCESS, "field 3 content fetch failed\n");
338 ok(!strcmp(buf,"8675309"), "field 3 content incorrect\n");
340 r = MsiCloseHandle(hrec);
341 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
343 /* open a select query */
344 hrec = 100;
345 query = "SELECT * FROM `phone` WHERE `id` >= 10";
346 r = do_query(hdb, query, &hrec);
347 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
348 ok(hrec == 0, "hrec should be null\n");
350 r = MsiCloseHandle(hrec);
351 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
353 query = "SELECT * FROM `phone` WHERE `id` < 0";
354 r = do_query(hdb, query, &hrec);
355 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
357 query = "SELECT * FROM `phone` WHERE `id` <= 0";
358 r = do_query(hdb, query, &hrec);
359 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
361 query = "SELECT * FROM `phone` WHERE `id` <> 1";
362 r = do_query(hdb, query, &hrec);
363 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
365 query = "SELECT * FROM `phone` WHERE `id` > 10";
366 r = do_query(hdb, query, &hrec);
367 ok(r == ERROR_NO_MORE_ITEMS, "MsiViewFetch failed\n");
369 /* now try a few bad INSERT xqueries */
370 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
371 "VALUES(?, ?)";
372 r = MsiDatabaseOpenView(hdb, query, &hview);
373 ok(r == ERROR_BAD_QUERY_SYNTAX, "MsiDatabaseOpenView failed\n");
375 /* construct a record to insert */
376 hrec = MsiCreateRecord(4);
377 r = MsiRecordSetInteger(hrec, 1, 2);
378 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
379 r = MsiRecordSetString(hrec, 2, "Adam");
380 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
381 r = MsiRecordSetString(hrec, 3, "96905305");
382 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
384 /* insert another value, using a record and wildcards */
385 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
386 "VALUES(?, ?, ?)";
387 r = MsiDatabaseOpenView(hdb, query, &hview);
388 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
390 if (r == ERROR_SUCCESS)
392 r = MsiViewExecute(hview, hrec);
393 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
394 r = MsiViewClose(hview);
395 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
396 r = MsiCloseHandle(hview);
397 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
399 r = MsiCloseHandle(hrec);
400 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
402 r = MsiViewFetch(0, NULL);
403 ok(r == ERROR_INVALID_PARAMETER, "MsiViewFetch failed\n");
405 r = MsiDatabaseCommit(hdb);
406 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
408 r = MsiCloseHandle(hdb);
409 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
411 r = DeleteFile(msifile);
412 ok(r == TRUE, "file didn't exist after commit\n");
415 typedef UINT (WINAPI *fnMsiDecomposeDescriptorA)(LPCSTR, LPCSTR, LPSTR, LPSTR, DWORD *);
416 static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA;
418 static void test_msidecomposedesc(void)
420 char prod[MAX_FEATURE_CHARS+1], comp[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1];
421 const char *desc;
422 UINT r;
423 DWORD len;
424 HMODULE hmod;
426 hmod = GetModuleHandle("msi.dll");
427 pMsiDecomposeDescriptorA = (fnMsiDecomposeDescriptorA)
428 GetProcAddress(hmod, "MsiDecomposeDescriptorA");
429 if (!pMsiDecomposeDescriptorA)
430 return;
432 /* test a valid feature descriptor */
433 desc = "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
434 len = 0;
435 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
436 ok(r == ERROR_SUCCESS, "returned an error\n");
437 ok(len == strlen(desc), "length was wrong\n");
438 ok(strcmp(prod,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
439 ok(strcmp(feature,"FollowTheWhiteRabbit")==0, "feature wrong\n");
440 ok(strcmp(comp,"{A7CD68DB-EF74-49C8-FBB2-A7C463B2AC24}")==0,"component wrong\n");
442 /* test an invalid feature descriptor with too many characters */
443 desc = "']gAVn-}f(ZXfeAR6.ji"
444 "ThisWillFailIfTheresMoreThanAGuidsChars>"
445 "3w2x^IGfe?CxI5heAvk.";
446 len = 0;
447 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
448 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
451 * Test a valid feature descriptor with the
452 * maximum number of characters and some trailing characters.
454 desc = "']gAVn-}f(ZXfeAR6.ji"
455 "ThisWillWorkIfTheresLTEThanAGuidsChars>"
456 "3w2x^IGfe?CxI5heAvk."
457 "extra";
458 len = 0;
459 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
460 ok(r == ERROR_SUCCESS, "returned wrong error\n");
461 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
463 len = 0;
464 r = pMsiDecomposeDescriptorA(desc, prod, feature, NULL, &len);
465 ok(r == ERROR_SUCCESS, "returned wrong error\n");
466 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
468 len = 0;
469 r = pMsiDecomposeDescriptorA(desc, prod, NULL, NULL, &len);
470 ok(r == ERROR_SUCCESS, "returned wrong error\n");
471 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
473 len = 0;
474 r = pMsiDecomposeDescriptorA(desc, NULL, NULL, NULL, &len);
475 ok(r == ERROR_SUCCESS, "returned wrong error\n");
476 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
478 len = 0;
479 r = pMsiDecomposeDescriptorA(NULL, NULL, NULL, NULL, &len);
480 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
481 ok(len == 0, "length wrong\n");
483 r = pMsiDecomposeDescriptorA(desc, NULL, NULL, NULL, NULL);
484 ok(r == ERROR_SUCCESS, "returned wrong error\n");
487 static UINT try_query_param( MSIHANDLE hdb, LPCSTR szQuery, MSIHANDLE hrec )
489 MSIHANDLE htab = 0;
490 UINT res;
492 res = MsiDatabaseOpenView( hdb, szQuery, &htab );
493 if(res == ERROR_SUCCESS )
495 UINT r;
497 r = MsiViewExecute( htab, hrec );
498 if(r != ERROR_SUCCESS )
499 res = r;
501 r = MsiViewClose( htab );
502 if(r != ERROR_SUCCESS )
503 res = r;
505 r = MsiCloseHandle( htab );
506 if(r != ERROR_SUCCESS )
507 res = r;
509 return res;
512 static UINT try_query( MSIHANDLE hdb, LPCSTR szQuery )
514 return try_query_param( hdb, szQuery, 0 );
517 static UINT try_insert_query( MSIHANDLE hdb, LPCSTR szQuery )
519 MSIHANDLE hrec = 0;
520 UINT r;
522 hrec = MsiCreateRecord( 1 );
523 MsiRecordSetString( hrec, 1, "Hello");
525 r = try_query_param( hdb, szQuery, hrec );
527 MsiCloseHandle( hrec );
528 return r;
531 static void test_msibadqueries(void)
533 MSIHANDLE hdb = 0;
534 UINT r;
536 DeleteFile(msifile);
538 /* just MsiOpenDatabase should not create a file */
539 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
540 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
542 r = MsiDatabaseCommit( hdb );
543 ok(r == ERROR_SUCCESS , "Failed to commit database\n");
545 r = MsiCloseHandle( hdb );
546 ok(r == ERROR_SUCCESS , "Failed to close database\n");
548 /* open it readonly */
549 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb );
550 ok(r == ERROR_SUCCESS , "Failed to open database r/o\n");
552 /* add a table to it */
553 r = try_query( hdb, "select * from _Tables");
554 ok(r == ERROR_SUCCESS , "query 1 failed\n");
556 r = MsiCloseHandle( hdb );
557 ok(r == ERROR_SUCCESS , "Failed to close database r/o\n");
559 /* open it read/write */
560 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
561 ok(r == ERROR_SUCCESS , "Failed to open database r/w\n");
563 /* a bunch of test queries that fail with the native MSI */
565 r = try_query( hdb, "CREATE TABLE");
566 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2a return code\n");
568 r = try_query( hdb, "CREATE TABLE `a`");
569 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2b return code\n");
571 r = try_query( hdb, "CREATE TABLE `a` ()");
572 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2c return code\n");
574 r = try_query( hdb, "CREATE TABLE `a` (`b`)");
575 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2d return code\n");
577 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) )");
578 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2e return code\n");
580 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
581 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2f return code\n");
583 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
584 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2g return code\n");
586 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
587 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2h return code\n");
589 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
590 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2i return code\n");
592 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
593 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2j return code\n");
595 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
596 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2k return code\n");
598 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
599 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2l return code\n");
601 r = try_query( hdb, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
602 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2m return code\n");
604 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
605 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2n return code\n");
607 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
608 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2o return code\n");
610 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
611 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
613 r = try_query( hdb, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
614 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
616 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
617 ok(r == ERROR_SUCCESS , "valid query 2z failed\n");
619 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
620 ok(r == ERROR_BAD_QUERY_SYNTAX , "created same table again\n");
622 r = try_query( hdb, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
623 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
624 ok(r == ERROR_SUCCESS , "query 4 failed\n");
626 r = MsiDatabaseCommit( hdb );
627 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
629 r = try_query( hdb, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
630 "PRIMARY KEY `foo`)");
631 ok(r == ERROR_SUCCESS , "query 4 failed\n");
633 r = try_insert_query( hdb, "insert into a ( `b` ) VALUES ( ? )");
634 ok(r == ERROR_SUCCESS , "failed to insert record in db\n");
636 r = MsiDatabaseCommit( hdb );
637 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
639 r = try_query( hdb, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
640 "PRIMARY KEY `ba`)");
641 ok(r != ERROR_SUCCESS , "query 5 succeeded\n");
643 r = try_query( hdb,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
644 ok(r != ERROR_SUCCESS , "query 6 succeeded\n");
646 r = try_query( hdb, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
647 "PRIMARY KEY `t`)");
648 ok(r == ERROR_SUCCESS , "query 7 failed\n");
650 r = try_query( hdb, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
651 ok(r == ERROR_SUCCESS , "query 8 failed\n");
653 r = try_query( hdb, "select * from c");
654 ok(r == ERROR_SUCCESS , "query failed\n");
656 r = try_query( hdb, "select * from c where b = 'x");
657 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
659 r = try_query( hdb, "select * from c where b = 'x'");
660 ok(r == ERROR_SUCCESS, "query failed\n");
662 r = try_query( hdb, "select * from 'c'");
663 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
665 r = try_query( hdb, "select * from ''");
666 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
668 r = try_query( hdb, "select * from c where b = x");
669 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
671 r = try_query( hdb, "select * from c where b = \"x\"");
672 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
674 r = try_query( hdb, "select * from c where b = 'x'");
675 ok(r == ERROR_SUCCESS, "query failed\n");
677 r = try_query( hdb, "select * from c where b = '\"x'");
678 ok(r == ERROR_SUCCESS, "query failed\n");
680 if (0) /* FIXME: this query causes trouble with other tests */
682 r = try_query( hdb, "select * from c where b = '\\\'x'");
683 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
686 r = try_query( hdb, "select * from 'c'");
687 ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
689 r = try_query( hdb, "CREATE TABLE `\5a` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
690 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
692 r = try_query( hdb, "SELECT * FROM \5a" );
693 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
695 r = try_query( hdb, "CREATE TABLE `a\5` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
696 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
698 r = try_query( hdb, "SELECT * FROM a\5" );
699 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
701 r = try_query( hdb, "CREATE TABLE `-a` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
702 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
704 r = try_query( hdb, "SELECT * FROM -a" );
705 todo_wine ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
707 r = try_query( hdb, "CREATE TABLE `a-` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
708 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
710 r = try_query( hdb, "SELECT * FROM a-" );
711 ok( r == ERROR_SUCCESS , "query failed: %u\n", r );
713 r = MsiCloseHandle( hdb );
714 ok(r == ERROR_SUCCESS , "Failed to close database transact\n");
716 r = DeleteFile( msifile );
717 ok(r == TRUE, "file didn't exist after commit\n");
720 static void test_viewmodify(void)
722 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
723 UINT r;
724 MSIDBERROR err;
725 const char *query;
726 char buffer[0x100];
727 DWORD sz;
729 DeleteFile(msifile);
731 /* just MsiOpenDatabase should not create a file */
732 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
733 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
735 query = "CREATE TABLE `phone` ( "
736 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
737 "PRIMARY KEY `id`)";
738 r = run_query( hdb, 0, query );
739 ok(r == ERROR_SUCCESS, "query failed\n");
741 /* check what the error function reports without doing anything */
742 sz = 0;
743 /* passing NULL as the 3rd param make function to crash on older platforms */
744 err = MsiViewGetError( 0, NULL, &sz );
745 ok(err == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
747 /* open a view */
748 query = "SELECT * FROM `phone`";
749 r = MsiDatabaseOpenView(hdb, query, &hview);
750 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
752 /* see what happens with a good hview and bad args */
753 err = MsiViewGetError( hview, NULL, NULL );
754 ok(err == MSIDBERROR_INVALIDARG || err == MSIDBERROR_NOERROR,
755 "MsiViewGetError returns %u (expected -3)\n", err);
756 err = MsiViewGetError( hview, buffer, NULL );
757 ok(err == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
759 /* see what happens with a zero length buffer */
760 sz = 0;
761 buffer[0] = 'x';
762 err = MsiViewGetError( hview, buffer, &sz );
763 ok(err == MSIDBERROR_MOREDATA, "MsiViewGetError return\n");
764 ok(buffer[0] == 'x', "buffer cleared\n");
765 ok(sz == 0, "size not zero\n");
767 /* ok this one is strange */
768 sz = 0;
769 err = MsiViewGetError( hview, NULL, &sz );
770 ok(err == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
771 ok(sz == 0, "size not zero\n");
773 /* see if it really has an error */
774 sz = sizeof buffer;
775 buffer[0] = 'x';
776 err = MsiViewGetError( hview, buffer, &sz );
777 ok(err == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
778 ok(buffer[0] == 0, "buffer not cleared\n");
779 ok(sz == 0, "size not zero\n");
781 r = MsiViewExecute(hview, 0);
782 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
784 /* try some invalid records */
785 r = MsiViewModify(hview, MSIMODIFY_INSERT, 0 );
786 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
787 r = MsiViewModify(hview, -1, 0 );
788 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
790 /* try an small record */
791 hrec = MsiCreateRecord(1);
792 r = MsiViewModify(hview, -1, hrec );
793 ok(r == ERROR_INVALID_DATA, "MsiViewModify failed\n");
795 r = MsiCloseHandle(hrec);
796 ok(r == ERROR_SUCCESS, "failed to close record\n");
798 /* insert a valid record */
799 hrec = MsiCreateRecord(3);
801 r = MsiRecordSetInteger(hrec, 1, 1);
802 ok(r == ERROR_SUCCESS, "failed to set integer\n");
803 r = MsiRecordSetString(hrec, 2, "bob");
804 ok(r == ERROR_SUCCESS, "failed to set string\n");
805 r = MsiRecordSetString(hrec, 3, "7654321");
806 ok(r == ERROR_SUCCESS, "failed to set string\n");
808 r = MsiViewExecute(hview, 0);
809 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
810 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
811 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
813 /* insert the same thing again */
814 r = MsiViewExecute(hview, 0);
815 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
817 /* should fail ... */
818 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
819 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
821 r = MsiCloseHandle(hrec);
822 ok(r == ERROR_SUCCESS, "failed to close record\n");
824 r = MsiViewClose(hview);
825 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
826 r = MsiCloseHandle(hview);
827 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
829 query = "SELECT * FROM `phone`";
830 r = MsiDatabaseOpenView(hdb, query, &hview);
831 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
833 r = MsiViewExecute(hview, 0);
834 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
836 r = MsiViewFetch(hview, &hrec);
837 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
839 r = MsiRecordGetInteger(hrec, 1);
840 ok(r == 1, "Expected 1, got %d\n", r);
842 sz = sizeof(buffer);
843 r = MsiRecordGetString(hrec, 2, buffer, &sz);
844 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
845 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
847 sz = sizeof(buffer);
848 r = MsiRecordGetString(hrec, 3, buffer, &sz);
849 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
850 ok(!lstrcmp(buffer, "7654321"), "Expected 7654321, got %s\n", buffer);
852 /* update the view, non-primary key */
853 r = MsiRecordSetString(hrec, 3, "3141592");
854 ok(r == ERROR_SUCCESS, "MsiRecordSetString failed\n");
856 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
857 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
859 /* do it again */
860 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
861 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
863 /* update the view, primary key */
864 r = MsiRecordSetInteger(hrec, 1, 5);
865 ok(r == ERROR_SUCCESS, "MsiRecordSetInteger failed\n");
867 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
868 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
870 r = MsiCloseHandle(hrec);
871 ok(r == ERROR_SUCCESS, "failed to close record\n");
873 r = MsiViewClose(hview);
874 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
875 r = MsiCloseHandle(hview);
876 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
878 query = "SELECT * FROM `phone`";
879 r = MsiDatabaseOpenView(hdb, query, &hview);
880 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
882 r = MsiViewExecute(hview, 0);
883 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
885 r = MsiViewFetch(hview, &hrec);
886 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
888 r = MsiRecordGetInteger(hrec, 1);
889 ok(r == 1, "Expected 1, got %d\n", r);
891 sz = sizeof(buffer);
892 r = MsiRecordGetString(hrec, 2, buffer, &sz);
893 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
894 ok(!lstrcmp(buffer, "bob"), "Expected bob, got %s\n", buffer);
896 sz = sizeof(buffer);
897 r = MsiRecordGetString(hrec, 3, buffer, &sz);
898 ok(r == ERROR_SUCCESS, "MsiRecordGetString failed\n");
899 ok(!lstrcmp(buffer, "3141592"), "Expected 3141592, got %s\n", buffer);
901 r = MsiCloseHandle(hrec);
902 ok(r == ERROR_SUCCESS, "failed to close record\n");
904 /* use a record that doesn't come from a view fetch */
905 hrec = MsiCreateRecord(3);
906 ok(hrec != 0, "MsiCreateRecord failed\n");
908 r = MsiRecordSetInteger(hrec, 1, 3);
909 ok(r == ERROR_SUCCESS, "failed to set integer\n");
910 r = MsiRecordSetString(hrec, 2, "jane");
911 ok(r == ERROR_SUCCESS, "failed to set string\n");
912 r = MsiRecordSetString(hrec, 3, "112358");
913 ok(r == ERROR_SUCCESS, "failed to set string\n");
915 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
916 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
918 r = MsiCloseHandle(hrec);
919 ok(r == ERROR_SUCCESS, "failed to close record\n");
921 /* use a record that doesn't come from a view fetch, primary key matches */
922 hrec = MsiCreateRecord(3);
923 ok(hrec != 0, "MsiCreateRecord failed\n");
925 r = MsiRecordSetInteger(hrec, 1, 1);
926 ok(r == ERROR_SUCCESS, "failed to set integer\n");
927 r = MsiRecordSetString(hrec, 2, "jane");
928 ok(r == ERROR_SUCCESS, "failed to set string\n");
929 r = MsiRecordSetString(hrec, 3, "112358");
930 ok(r == ERROR_SUCCESS, "failed to set string\n");
932 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
933 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
935 r = MsiCloseHandle(hrec);
936 ok(r == ERROR_SUCCESS, "failed to close record\n");
938 hrec = MsiCreateRecord(3);
940 r = MsiRecordSetInteger(hrec, 1, 2);
941 ok(r == ERROR_SUCCESS, "failed to set integer\n");
942 r = MsiRecordSetString(hrec, 2, "nick");
943 ok(r == ERROR_SUCCESS, "failed to set string\n");
944 r = MsiRecordSetString(hrec, 3, "141421");
945 ok(r == ERROR_SUCCESS, "failed to set string\n");
947 r = MsiViewExecute(hview, 0);
948 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
949 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
950 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
952 r = MsiCloseHandle(hrec);
953 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
954 r = MsiViewClose(hview);
955 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
956 r = MsiCloseHandle(hview);
957 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
959 query = "SELECT * FROM `phone` WHERE `id` = 1";
960 r = MsiDatabaseOpenView(hdb, query, &hview);
961 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
962 r = MsiViewExecute(hview, 0);
963 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
964 r = MsiViewFetch(hview, &hrec);
965 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
967 /* change the id to match the second row */
968 r = MsiRecordSetInteger(hrec, 1, 2);
969 ok(r == ERROR_SUCCESS, "failed to set integer\n");
970 r = MsiRecordSetString(hrec, 2, "jerry");
971 ok(r == ERROR_SUCCESS, "failed to set string\n");
973 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
974 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
976 r = MsiCloseHandle(hrec);
977 ok(r == ERROR_SUCCESS, "failed to close record\n");
978 r = MsiViewClose(hview);
979 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
980 r = MsiCloseHandle(hview);
981 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
983 /* broader search */
984 query = "SELECT * FROM `phone` ORDER BY `id`";
985 r = MsiDatabaseOpenView(hdb, query, &hview);
986 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
987 r = MsiViewExecute(hview, 0);
988 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
989 r = MsiViewFetch(hview, &hrec);
990 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
992 /* change the id to match the second row */
993 r = MsiRecordSetInteger(hrec, 1, 2);
994 ok(r == ERROR_SUCCESS, "failed to set integer\n");
995 r = MsiRecordSetString(hrec, 2, "jerry");
996 ok(r == ERROR_SUCCESS, "failed to set string\n");
998 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
999 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
1001 r = MsiCloseHandle(hrec);
1002 ok(r == ERROR_SUCCESS, "failed to close record\n");
1003 r = MsiViewClose(hview);
1004 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1005 r = MsiCloseHandle(hview);
1006 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1008 r = MsiCloseHandle( hdb );
1009 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
1012 static MSIHANDLE create_db(void)
1014 MSIHANDLE hdb = 0;
1015 UINT res;
1017 DeleteFile(msifile);
1019 /* create an empty database */
1020 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
1021 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
1022 if( res != ERROR_SUCCESS )
1023 return hdb;
1025 res = MsiDatabaseCommit( hdb );
1026 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
1028 return hdb;
1031 static void test_getcolinfo(void)
1033 MSIHANDLE hdb, hview = 0, rec = 0;
1034 UINT r;
1035 DWORD sz;
1036 char buffer[0x20];
1038 /* create an empty db */
1039 hdb = create_db();
1040 ok( hdb, "failed to create db\n");
1042 /* tables should be present */
1043 r = MsiDatabaseOpenView(hdb, "select * from _Tables", &hview);
1044 ok( r == ERROR_SUCCESS, "failed to open query\n");
1046 r = MsiViewExecute(hview, 0);
1047 ok( r == ERROR_SUCCESS, "failed to execute query\n");
1049 /* check that NAMES works */
1050 rec = 0;
1051 r = MsiViewGetColumnInfo( hview, MSICOLINFO_NAMES, &rec );
1052 ok( r == ERROR_SUCCESS, "failed to get names\n");
1053 sz = sizeof buffer;
1054 r = MsiRecordGetString(rec, 1, buffer, &sz );
1055 ok( r == ERROR_SUCCESS, "failed to get string\n");
1056 ok( !strcmp(buffer,"Name"), "_Tables has wrong column name\n");
1057 r = MsiCloseHandle( rec );
1058 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1060 /* check that TYPES works */
1061 rec = 0;
1062 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, &rec );
1063 ok( r == ERROR_SUCCESS, "failed to get names\n");
1064 sz = sizeof buffer;
1065 r = MsiRecordGetString(rec, 1, buffer, &sz );
1066 ok( r == ERROR_SUCCESS, "failed to get string\n");
1067 ok( !strcmp(buffer,"s64"), "_Tables has wrong column type\n");
1068 r = MsiCloseHandle( rec );
1069 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
1071 /* check that invalid values fail */
1072 rec = 0;
1073 r = MsiViewGetColumnInfo( hview, 100, &rec );
1074 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1075 ok( rec == 0, "returned a record\n");
1077 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, NULL );
1078 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
1080 r = MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES, &rec );
1081 ok( r == ERROR_INVALID_HANDLE, "wrong error code\n");
1083 r = MsiViewClose(hview);
1084 ok( r == ERROR_SUCCESS, "failed to close view\n");
1085 r = MsiCloseHandle(hview);
1086 ok( r == ERROR_SUCCESS, "failed to close view handle\n");
1087 r = MsiCloseHandle(hdb);
1088 ok( r == ERROR_SUCCESS, "failed to close database\n");
1091 static MSIHANDLE get_column_info(MSIHANDLE hdb, const char *query, MSICOLINFO type)
1093 MSIHANDLE hview = 0, rec = 0;
1094 UINT r;
1096 r = MsiDatabaseOpenView(hdb, query, &hview);
1097 if( r != ERROR_SUCCESS )
1098 return r;
1100 r = MsiViewExecute(hview, 0);
1101 if( r == ERROR_SUCCESS )
1103 MsiViewGetColumnInfo( hview, type, &rec );
1105 MsiViewClose(hview);
1106 MsiCloseHandle(hview);
1107 return rec;
1110 static UINT get_columns_table_type(MSIHANDLE hdb, const char *table, UINT field)
1112 MSIHANDLE hview = 0, rec = 0;
1113 UINT r, type = 0;
1114 char query[0x100];
1116 sprintf(query, "select * from `_Columns` where `Table` = '%s'", table );
1118 r = MsiDatabaseOpenView(hdb, query, &hview);
1119 if( r != ERROR_SUCCESS )
1120 return r;
1122 r = MsiViewExecute(hview, 0);
1123 if( r == ERROR_SUCCESS )
1125 while (1)
1127 r = MsiViewFetch( hview, &rec );
1128 if( r != ERROR_SUCCESS)
1129 break;
1130 r = MsiRecordGetInteger( rec, 2 );
1131 if (r == field)
1132 type = MsiRecordGetInteger( rec, 4 );
1133 MsiCloseHandle( rec );
1136 MsiViewClose(hview);
1137 MsiCloseHandle(hview);
1138 return type;
1141 static BOOL check_record( MSIHANDLE rec, UINT field, LPCSTR val )
1143 CHAR buffer[0x20];
1144 UINT r;
1145 DWORD sz;
1147 sz = sizeof buffer;
1148 r = MsiRecordGetString( rec, field, buffer, &sz );
1149 return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
1152 static void test_viewgetcolumninfo(void)
1154 MSIHANDLE hdb = 0, rec;
1155 UINT r;
1157 hdb = create_db();
1158 ok( hdb, "failed to create db\n");
1160 r = run_query( hdb, 0,
1161 "CREATE TABLE `Properties` "
1162 "( `Property` CHAR(255), "
1163 " `Value` CHAR(1), "
1164 " `Intvalue` INT, "
1165 " `Integervalue` INTEGER, "
1166 " `Shortvalue` SHORT, "
1167 " `Longvalue` LONG, "
1168 " `Longcharvalue` LONGCHAR "
1169 " PRIMARY KEY `Property`)" );
1170 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1172 /* check the column types */
1173 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_TYPES );
1174 ok( rec, "failed to get column info record\n" );
1176 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1177 ok( check_record( rec, 2, "S1"), "wrong record type\n");
1178 ok( check_record( rec, 3, "I2"), "wrong record type\n");
1179 ok( check_record( rec, 4, "I2"), "wrong record type\n");
1180 ok( check_record( rec, 5, "I2"), "wrong record type\n");
1181 ok( check_record( rec, 6, "I4"), "wrong record type\n");
1182 ok( check_record( rec, 7, "S0"), "wrong record type\n");
1184 MsiCloseHandle( rec );
1186 /* check the type in _Columns */
1187 ok( 0x3dff == get_columns_table_type(hdb, "Properties", 1 ), "_columns table wrong\n");
1188 ok( 0x1d01 == get_columns_table_type(hdb, "Properties", 2 ), "_columns table wrong\n");
1189 ok( 0x1502 == get_columns_table_type(hdb, "Properties", 3 ), "_columns table wrong\n");
1190 ok( 0x1502 == get_columns_table_type(hdb, "Properties", 4 ), "_columns table wrong\n");
1191 ok( 0x1502 == get_columns_table_type(hdb, "Properties", 5 ), "_columns table wrong\n");
1192 ok( 0x1104 == get_columns_table_type(hdb, "Properties", 6 ), "_columns table wrong\n");
1193 ok( 0x1d00 == get_columns_table_type(hdb, "Properties", 7 ), "_columns table wrong\n");
1195 /* now try the names */
1196 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_NAMES );
1197 ok( rec, "failed to get column info record\n" );
1199 ok( check_record( rec, 1, "Property"), "wrong record type\n");
1200 ok( check_record( rec, 2, "Value"), "wrong record type\n");
1201 ok( check_record( rec, 3, "Intvalue"), "wrong record type\n");
1202 ok( check_record( rec, 4, "Integervalue"), "wrong record type\n");
1203 ok( check_record( rec, 5, "Shortvalue"), "wrong record type\n");
1204 ok( check_record( rec, 6, "Longvalue"), "wrong record type\n");
1205 ok( check_record( rec, 7, "Longcharvalue"), "wrong record type\n");
1207 MsiCloseHandle( rec );
1209 r = run_query( hdb, 0,
1210 "CREATE TABLE `Binary` "
1211 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
1212 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1214 /* check the column types */
1215 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_TYPES );
1216 ok( rec, "failed to get column info record\n" );
1218 ok( check_record( rec, 1, "S255"), "wrong record type\n");
1219 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1221 MsiCloseHandle( rec );
1223 /* check the type in _Columns */
1224 ok( 0x3dff == get_columns_table_type(hdb, "Binary", 1 ), "_columns table wrong\n");
1225 ok( 0x1900 == get_columns_table_type(hdb, "Binary", 2 ), "_columns table wrong\n");
1227 /* now try the names */
1228 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_NAMES );
1229 ok( rec, "failed to get column info record\n" );
1231 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1232 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1233 MsiCloseHandle( rec );
1235 r = run_query( hdb, 0,
1236 "CREATE TABLE `UIText` "
1237 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1238 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1240 ok( 0x2d48 == get_columns_table_type(hdb, "UIText", 1 ), "_columns table wrong\n");
1241 ok( 0x1fff == get_columns_table_type(hdb, "UIText", 2 ), "_columns table wrong\n");
1243 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_NAMES );
1244 ok( rec, "failed to get column info record\n" );
1245 ok( check_record( rec, 1, "Key"), "wrong record type\n");
1246 ok( check_record( rec, 2, "Text"), "wrong record type\n");
1247 MsiCloseHandle( rec );
1249 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_TYPES );
1250 ok( rec, "failed to get column info record\n" );
1251 ok( check_record( rec, 1, "s72"), "wrong record type\n");
1252 ok( check_record( rec, 2, "L255"), "wrong record type\n");
1253 MsiCloseHandle( rec );
1255 MsiCloseHandle( hdb );
1258 static void test_msiexport(void)
1260 MSIHANDLE hdb = 0, hview = 0;
1261 UINT r;
1262 const char *query;
1263 char path[MAX_PATH];
1264 const char file[] = "phone.txt";
1265 HANDLE handle;
1266 char buffer[0x100];
1267 DWORD length;
1268 const char expected[] =
1269 "id\tname\tnumber\r\n"
1270 "I2\tS32\tS32\r\n"
1271 "phone\tid\r\n"
1272 "1\tAbe\t8675309\r\n";
1274 DeleteFile(msifile);
1276 /* just MsiOpenDatabase should not create a file */
1277 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1278 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1280 /* create a table */
1281 query = "CREATE TABLE `phone` ( "
1282 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1283 "PRIMARY KEY `id`)";
1284 r = MsiDatabaseOpenView(hdb, query, &hview);
1285 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1286 r = MsiViewExecute(hview, 0);
1287 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1288 r = MsiViewClose(hview);
1289 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1290 r = MsiCloseHandle(hview);
1291 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1293 /* insert a value into it */
1294 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
1295 "VALUES('1', 'Abe', '8675309')";
1296 r = MsiDatabaseOpenView(hdb, query, &hview);
1297 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1298 r = MsiViewExecute(hview, 0);
1299 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1300 r = MsiViewClose(hview);
1301 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
1302 r = MsiCloseHandle(hview);
1303 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
1305 GetCurrentDirectory(MAX_PATH, path);
1307 r = MsiDatabaseExport(hdb, "phone", path, file);
1308 ok(r == ERROR_SUCCESS, "MsiDatabaseExport failed\n");
1310 MsiCloseHandle(hdb);
1312 lstrcat(path, "\\");
1313 lstrcat(path, file);
1315 /* check the data that was written */
1316 length = 0;
1317 memset(buffer, 0, sizeof buffer);
1318 handle = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
1319 if (handle != INVALID_HANDLE_VALUE)
1321 ReadFile(handle, buffer, sizeof buffer, &length, NULL);
1322 CloseHandle(handle);
1323 DeleteFile(path);
1325 else
1326 ok(0, "failed to open file %s\n", path);
1328 ok( length == strlen(expected), "length of data wrong\n");
1329 ok( !lstrcmp(buffer, expected), "data doesn't match\n");
1330 DeleteFile(msifile);
1333 static void test_longstrings(void)
1335 const char insert_query[] =
1336 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1337 char *str;
1338 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
1339 DWORD len;
1340 UINT r;
1341 const DWORD STRING_LENGTH = 0x10005;
1343 DeleteFile(msifile);
1344 /* just MsiOpenDatabase should not create a file */
1345 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
1346 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1348 /* create a table */
1349 r = try_query( hdb,
1350 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1351 ok(r == ERROR_SUCCESS, "query failed\n");
1353 /* try a insert a very long string */
1354 str = HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH+sizeof insert_query);
1355 len = strchr(insert_query, 'Z') - insert_query;
1356 strcpy(str, insert_query);
1357 memset(str+len, 'Z', STRING_LENGTH);
1358 strcpy(str+len+STRING_LENGTH, insert_query+len+1);
1359 r = try_query( hdb, str );
1360 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1362 HeapFree(GetProcessHeap(), 0, str);
1364 MsiDatabaseCommit(hdb);
1365 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
1366 MsiCloseHandle(hdb);
1368 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
1369 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
1371 r = MsiDatabaseOpenView(hdb, "select * from `strings` where `id` = 1", &hview);
1372 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
1374 r = MsiViewExecute(hview, 0);
1375 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
1377 r = MsiViewFetch(hview, &hrec);
1378 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1380 MsiViewClose(hview);
1381 MsiCloseHandle(hview);
1383 r = MsiRecordGetString(hrec, 2, NULL, &len);
1384 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
1385 ok(len == STRING_LENGTH, "string length wrong\n");
1387 MsiCloseHandle(hrec);
1388 MsiCloseHandle(hdb);
1389 DeleteFile(msifile);
1392 static void create_file_data(LPCSTR name, LPCSTR data, DWORD size)
1394 HANDLE file;
1395 DWORD written;
1397 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1398 if (file == INVALID_HANDLE_VALUE)
1399 return;
1401 WriteFile(file, data, strlen(data), &written, NULL);
1402 WriteFile(file, "\n", strlen("\n"), &written, NULL);
1404 if (size)
1406 SetFilePointer(file, size, NULL, FILE_BEGIN);
1407 SetEndOfFile(file);
1410 CloseHandle(file);
1413 #define create_file(name) create_file_data(name, name, 0)
1415 static void test_streamtable(void)
1417 MSIHANDLE hdb = 0, rec, view, hsi;
1418 char file[MAX_PATH];
1419 char buf[MAX_PATH];
1420 DWORD size;
1421 UINT r;
1423 hdb = create_db();
1424 ok( hdb, "failed to create db\n");
1426 r = run_query( hdb, 0,
1427 "CREATE TABLE `Properties` "
1428 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1429 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
1431 r = run_query( hdb, 0,
1432 "INSERT INTO `Properties` "
1433 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1434 ok( r == ERROR_SUCCESS, "Failed to add to table\n" );
1436 r = MsiDatabaseCommit( hdb );
1437 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1439 MsiCloseHandle( hdb );
1441 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
1442 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1444 /* check the column types */
1445 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_TYPES );
1446 ok( rec, "failed to get column info record\n" );
1448 ok( check_record( rec, 1, "s62"), "wrong record type\n");
1449 ok( check_record( rec, 2, "V0"), "wrong record type\n");
1451 MsiCloseHandle( rec );
1453 /* now try the names */
1454 rec = get_column_info( hdb, "select * from `_Streams`", MSICOLINFO_NAMES );
1455 ok( rec, "failed to get column info record\n" );
1457 ok( check_record( rec, 1, "Name"), "wrong record type\n");
1458 ok( check_record( rec, 2, "Data"), "wrong record type\n");
1460 MsiCloseHandle( rec );
1462 r = MsiDatabaseOpenView( hdb,
1463 "SELECT * FROM `_Streams` WHERE `Name` = '\5SummaryInformation'", &view );
1464 ok( r == ERROR_SUCCESS, "Failed to open database view: %u\n", r );
1466 r = MsiViewExecute( view, 0 );
1467 ok( r == ERROR_SUCCESS, "Failed to execute view: %u\n", r );
1469 r = MsiViewFetch( view, &rec );
1470 ok( r == ERROR_NO_MORE_ITEMS, "Unexpected result: %u\n", r );
1472 MsiCloseHandle( rec );
1473 MsiViewClose( view );
1474 MsiCloseHandle( view );
1476 /* create a summary information stream */
1477 r = MsiGetSummaryInformationA( hdb, NULL, 1, &hsi );
1478 ok( r == ERROR_SUCCESS, "Failed to get summary information handle: %u\n", r );
1480 r = MsiSummaryInfoSetPropertyA( hsi, PID_SECURITY, VT_I4, 2, NULL, NULL );
1481 ok( r == ERROR_SUCCESS, "Failed to set property: %u\n", r );
1483 r = MsiSummaryInfoPersist( hsi );
1484 ok( r == ERROR_SUCCESS, "Failed to save summary information: %u\n", r );
1486 MsiCloseHandle( hsi );
1488 r = MsiDatabaseOpenView( hdb,
1489 "SELECT * FROM `_Streams` WHERE `Name` = '\5SummaryInformation'", &view );
1490 ok( r == ERROR_SUCCESS, "Failed to open database view: %u\n", r );
1492 r = MsiViewExecute( view, 0 );
1493 ok( r == ERROR_SUCCESS, "Failed to execute view: %u\n", r );
1495 r = MsiViewFetch( view, &rec );
1496 ok( r == ERROR_SUCCESS, "Unexpected result: %u\n", r );
1498 MsiCloseHandle( rec );
1499 MsiViewClose( view );
1500 MsiCloseHandle( view );
1502 /* insert a file into the _Streams table */
1503 create_file( "test.txt" );
1505 rec = MsiCreateRecord( 2 );
1506 MsiRecordSetString( rec, 1, "data" );
1508 r = MsiRecordSetStream( rec, 2, "test.txt" );
1509 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1511 DeleteFile("test.txt");
1513 r = MsiDatabaseOpenView( hdb,
1514 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view );
1515 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1517 r = MsiViewExecute( view, rec );
1518 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1520 MsiCloseHandle( rec );
1521 MsiViewClose( view );
1522 MsiCloseHandle( view );
1524 /* insert another one */
1525 create_file( "test1.txt" );
1527 rec = MsiCreateRecord( 2 );
1528 MsiRecordSetString( rec, 1, "data1" );
1530 r = MsiRecordSetStream( rec, 2, "test1.txt" );
1531 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1533 DeleteFile("test1.txt");
1535 r = MsiDatabaseOpenView( hdb,
1536 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view );
1537 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1539 r = MsiViewExecute( view, rec );
1540 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1542 MsiCloseHandle( rec );
1543 MsiViewClose( view );
1544 MsiCloseHandle( view );
1546 r = MsiDatabaseOpenView( hdb,
1547 "SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = 'data'", &view );
1548 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1550 r = MsiViewExecute( view, 0 );
1551 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1553 r = MsiViewFetch( view, &rec );
1554 ok( r == ERROR_SUCCESS, "Failed to fetch record: %d\n", r);
1556 size = MAX_PATH;
1557 r = MsiRecordGetString( rec, 1, file, &size );
1558 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1559 ok( !lstrcmp(file, "data"), "Expected 'data', got %s\n", file);
1561 size = MAX_PATH;
1562 memset(buf, 0, MAX_PATH);
1563 r = MsiRecordReadStream( rec, 2, buf, &size );
1564 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1565 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf);
1567 MsiCloseHandle( rec );
1568 MsiViewClose( view );
1569 MsiCloseHandle( view );
1571 r = MsiDatabaseOpenView( hdb,
1572 "SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = 'data1'", &view );
1573 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1575 r = MsiViewExecute( view, 0 );
1576 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1578 r = MsiViewFetch( view, &rec );
1579 ok( r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1581 size = MAX_PATH;
1582 r = MsiRecordGetString( rec, 1, file, &size );
1583 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1584 ok( !lstrcmp(file, "data1"), "Expected 'data1', got %s\n", file);
1586 size = MAX_PATH;
1587 memset(buf, 0, MAX_PATH);
1588 r = MsiRecordReadStream( rec, 2, buf, &size );
1589 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1590 ok( !lstrcmp(buf, "test1.txt\n"), "Expected 'test1.txt\\n', got %s\n", buf);
1592 MsiCloseHandle( rec );
1593 MsiViewClose( view );
1594 MsiCloseHandle( view );
1596 /* perform an update */
1597 create_file( "test2.txt" );
1598 rec = MsiCreateRecord( 1 );
1600 r = MsiRecordSetStream( rec, 1, "test2.txt" );
1601 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1603 DeleteFile("test2.txt");
1605 r = MsiDatabaseOpenView( hdb,
1606 "UPDATE `_Streams` SET `Data` = ? WHERE `Name` = 'data1'", &view );
1607 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1609 r = MsiViewExecute( view, rec );
1610 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1612 MsiCloseHandle( rec );
1613 MsiViewClose( view );
1614 MsiCloseHandle( view );
1616 r = MsiDatabaseOpenView( hdb,
1617 "SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = 'data1'", &view );
1618 ok( r == ERROR_SUCCESS, "Failed to open database view: %d\n", r);
1620 r = MsiViewExecute( view, 0 );
1621 ok( r == ERROR_SUCCESS, "Failed to execute view: %d\n", r);
1623 r = MsiViewFetch( view, &rec );
1624 ok( r == ERROR_SUCCESS, "Failed to fetch record: %d\n", r);
1626 size = MAX_PATH;
1627 r = MsiRecordGetString( rec, 1, file, &size );
1628 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
1629 ok( !lstrcmp(file, "data1"), "Expected 'data1', got %s\n", file);
1631 size = MAX_PATH;
1632 memset(buf, 0, MAX_PATH);
1633 r = MsiRecordReadStream( rec, 2, buf, &size );
1634 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
1635 todo_wine ok( !lstrcmp(buf, "test2.txt\n"), "Expected 'test2.txt\\n', got %s\n", buf);
1637 MsiCloseHandle( rec );
1638 MsiViewClose( view );
1639 MsiCloseHandle( view );
1640 MsiCloseHandle( hdb );
1641 DeleteFile(msifile);
1644 static void test_binary(void)
1646 MSIHANDLE hdb = 0, rec;
1647 char file[MAX_PATH];
1648 char buf[MAX_PATH];
1649 DWORD size;
1650 LPCSTR query;
1651 UINT r;
1653 /* insert a file into the Binary table */
1654 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
1655 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1657 query = "CREATE TABLE `Binary` ( `Name` CHAR(72) NOT NULL, `ID` INT NOT NULL, `Data` OBJECT PRIMARY KEY `Name`, `ID`)";
1658 r = run_query( hdb, 0, query );
1659 ok( r == ERROR_SUCCESS, "Cannot create Binary table: %d\n", r );
1661 create_file( "test.txt" );
1662 rec = MsiCreateRecord( 1 );
1663 r = MsiRecordSetStream( rec, 1, "test.txt" );
1664 ok( r == ERROR_SUCCESS, "Failed to add stream data to the record: %d\n", r);
1665 DeleteFile( "test.txt" );
1667 query = "INSERT INTO `Binary` ( `Name`, `ID`, `Data` ) VALUES ( 'filename1', 1, ? )";
1668 r = run_query( hdb, rec, query );
1669 ok( r == ERROR_SUCCESS, "Insert into Binary table failed: %d\n", r );
1671 r = MsiCloseHandle( rec );
1672 ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
1674 r = MsiDatabaseCommit( hdb );
1675 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
1677 r = MsiCloseHandle( hdb );
1678 ok( r == ERROR_SUCCESS , "Failed to close database\n" );
1680 /* read file from the Stream table */
1681 r = MsiOpenDatabase( msifile, MSIDBOPEN_READONLY, &hdb );
1682 ok( r == ERROR_SUCCESS , "Failed to open database\n" );
1684 query = "SELECT * FROM `_Streams`";
1685 r = do_query( hdb, query, &rec );
1686 ok( r == ERROR_SUCCESS, "SELECT query failed: %d\n", r );
1688 size = MAX_PATH;
1689 r = MsiRecordGetString( rec, 1, file, &size );
1690 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r );
1691 ok( !lstrcmp(file, "Binary.filename1.1"), "Expected 'Binary.filename1.1', got %s\n", file );
1693 size = MAX_PATH;
1694 memset( buf, 0, MAX_PATH );
1695 r = MsiRecordReadStream( rec, 2, buf, &size );
1696 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r );
1697 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf );
1699 r = MsiCloseHandle( rec );
1700 ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
1702 /* read file from the Binary table */
1703 query = "SELECT * FROM `Binary`";
1704 r = do_query( hdb, query, &rec );
1705 ok( r == ERROR_SUCCESS, "SELECT query failed: %d\n", r );
1707 size = MAX_PATH;
1708 r = MsiRecordGetString( rec, 1, file, &size );
1709 ok( r == ERROR_SUCCESS, "Failed to get string: %d\n", r );
1710 ok( !lstrcmp(file, "filename1"), "Expected 'filename1', got %s\n", file );
1712 size = MAX_PATH;
1713 memset( buf, 0, MAX_PATH );
1714 r = MsiRecordReadStream( rec, 3, buf, &size );
1715 ok( r == ERROR_SUCCESS, "Failed to get stream: %d\n", r );
1716 ok( !lstrcmp(buf, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf );
1718 r = MsiCloseHandle( rec );
1719 ok( r == ERROR_SUCCESS , "Failed to close record handle\n" );
1721 r = MsiCloseHandle( hdb );
1722 ok( r == ERROR_SUCCESS , "Failed to close database\n" );
1724 DeleteFile( msifile );
1727 static void test_where_not_in_selected(void)
1729 MSIHANDLE hdb = 0, rec, view;
1730 LPCSTR query;
1731 UINT r;
1733 hdb = create_db();
1734 ok( hdb, "failed to create db\n");
1736 r = run_query(hdb, 0,
1737 "CREATE TABLE `IESTable` ("
1738 "`Action` CHAR(64), "
1739 "`Condition` CHAR(64), "
1740 "`Sequence` LONG PRIMARY KEY `Sequence`)");
1741 ok( r == S_OK, "Cannot create IESTable table: %d\n", r);
1743 r = run_query(hdb, 0,
1744 "CREATE TABLE `CATable` ("
1745 "`Action` CHAR(64), "
1746 "`Type` LONG PRIMARY KEY `Type`)");
1747 ok( r == S_OK, "Cannot create CATable table: %d\n", r);
1749 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1750 "( `Action`, `Condition`, `Sequence`) "
1751 "VALUES ( 'clean', 'cond4', 4)");
1752 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1754 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1755 "( `Action`, `Condition`, `Sequence`) "
1756 "VALUES ( 'depends', 'cond1', 1)");
1757 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1759 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1760 "( `Action`, `Condition`, `Sequence`) "
1761 "VALUES ( 'build', 'cond2', 2)");
1762 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1764 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1765 "( `Action`, `Condition`, `Sequence`) "
1766 "VALUES ( 'build2', 'cond6', 6)");
1767 ok( r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1769 r = run_query(hdb, 0, "INSERT INTO `IESTable` "
1770 "( `Action`, `Condition`, `Sequence`) "
1771 "VALUES ( 'build', 'cond3', 3)");
1772 ok(r == S_OK, "cannot add entry to IESTable table:%d\n", r );
1774 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1775 "( `Action`, `Type` ) "
1776 "VALUES ( 'build', 32)");
1777 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1779 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1780 "( `Action`, `Type` ) "
1781 "VALUES ( 'depends', 64)");
1782 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1784 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1785 "( `Action`, `Type` ) "
1786 "VALUES ( 'clean', 63)");
1787 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1789 r = run_query(hdb, 0, "INSERT INTO `CATable` "
1790 "( `Action`, `Type` ) "
1791 "VALUES ( 'build2', 34)");
1792 ok(r == S_OK, "cannot add entry to CATable table:%d\n", r );
1793 query = "Select IESTable.Condition from CATable, IESTable where "
1794 "CATable.Action = IESTable.Action and CATable.Type = 32";
1795 r = MsiDatabaseOpenView(hdb, query, &view);
1796 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1798 r = MsiViewExecute(view, 0);
1799 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1801 r = MsiViewFetch(view, &rec);
1802 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1804 ok( check_record( rec, 1, "cond2"), "wrong condition\n");
1806 MsiCloseHandle( rec );
1807 r = MsiViewFetch(view, &rec);
1808 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1810 ok( check_record( rec, 1, "cond3"), "wrong condition\n");
1812 MsiCloseHandle( rec );
1813 MsiViewClose(view);
1814 MsiCloseHandle(view);
1816 MsiCloseHandle( hdb );
1817 DeleteFile(msifile);
1822 static void test_where(void)
1824 MSIHANDLE hdb = 0, rec, view;
1825 LPCSTR query;
1826 UINT r;
1827 DWORD size;
1828 CHAR buf[MAX_PATH];
1829 UINT count;
1831 hdb = create_db();
1832 ok( hdb, "failed to create db\n");
1834 r = run_query( hdb, 0,
1835 "CREATE TABLE `Media` ("
1836 "`DiskId` SHORT NOT NULL, "
1837 "`LastSequence` LONG, "
1838 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1839 "`Cabinet` CHAR(255), "
1840 "`VolumeLabel` CHAR(32), "
1841 "`Source` CHAR(72) "
1842 "PRIMARY KEY `DiskId`)" );
1843 ok( r == S_OK, "cannot create Media table: %d\n", r );
1845 r = run_query( hdb, 0, "INSERT INTO `Media` "
1846 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1847 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1848 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1850 r = run_query( hdb, 0, "INSERT INTO `Media` "
1851 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1852 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1853 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1855 r = run_query( hdb, 0, "INSERT INTO `Media` "
1856 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1857 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1858 ok( r == S_OK, "cannot add file to the Media table: %d\n", r );
1860 query = "SELECT * FROM `Media`";
1861 r = do_query(hdb, query, &rec);
1862 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1863 ok( check_record( rec, 4, "zero.cab"), "wrong cabinet\n");
1864 MsiCloseHandle( rec );
1866 query = "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1867 r = do_query(hdb, query, &rec);
1868 ok(r == ERROR_SUCCESS, "MsiViewFetch failed: %d\n", r);
1869 ok( check_record( rec, 4, "one.cab"), "wrong cabinet\n");
1871 r = MsiRecordGetInteger(rec, 1);
1872 ok( 2 == r, "field wrong\n");
1873 r = MsiRecordGetInteger(rec, 2);
1874 ok( 1 == r, "field wrong\n");
1875 MsiCloseHandle( rec );
1877 query = "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1878 r = MsiDatabaseOpenView(hdb, query, &view);
1879 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
1881 r = MsiViewExecute(view, 0);
1882 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
1884 r = MsiViewFetch(view, &rec);
1885 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1887 count = MsiRecordGetFieldCount( rec );
1888 ok( count == 1, "Expected 1 record fields, got %d\n", count );
1890 size = MAX_PATH;
1891 r = MsiRecordGetString( rec, 1, buf, &size );
1892 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1893 ok( !lstrcmp( buf, "2" ),
1894 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf );
1895 MsiCloseHandle( rec );
1897 r = MsiViewFetch(view, &rec);
1898 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
1900 size = MAX_PATH;
1901 r = MsiRecordGetString( rec, 1, buf, &size );
1902 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
1903 ok( !lstrcmp( buf, "3" ),
1904 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf );
1905 MsiCloseHandle( rec );
1907 r = MsiViewFetch(view, &rec);
1908 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
1910 MsiViewClose(view);
1911 MsiCloseHandle(view);
1913 MsiCloseHandle( rec );
1915 rec = 0;
1916 query = "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1917 r = do_query(hdb, query, &rec);
1918 ok( r == ERROR_SUCCESS, "query failed: %d\n", r );
1919 MsiCloseHandle( rec );
1921 rec = 0;
1922 query = "SELECT * FROM `Media` WHERE `DiskPrompt` < 'Cabinet'";
1923 r = do_query(hdb, query, &rec);
1924 ok( r == ERROR_BAD_QUERY_SYNTAX, "query failed: %d\n", r );
1925 MsiCloseHandle( rec );
1927 rec = 0;
1928 query = "SELECT * FROM `Media` WHERE `DiskPrompt` > 'Cabinet'";
1929 r = do_query(hdb, query, &rec);
1930 ok( r == ERROR_BAD_QUERY_SYNTAX, "query failed: %d\n", r );
1931 MsiCloseHandle( rec );
1933 rec = 0;
1934 query = "SELECT * FROM `Media` WHERE `DiskPrompt` <> 'Cabinet'";
1935 r = do_query(hdb, query, &rec);
1936 ok( r == ERROR_SUCCESS, "query failed: %d\n", r );
1937 MsiCloseHandle( rec );
1939 rec = 0;
1940 query = "SELECT * FROM `Media` WHERE `DiskPrompt` = 'Cabinet'";
1941 r = do_query(hdb, query, &rec);
1942 ok( r == ERROR_NO_MORE_ITEMS, "query failed: %d\n", r );
1943 MsiCloseHandle( rec );
1945 rec = MsiCreateRecord(1);
1946 MsiRecordSetString(rec, 1, "");
1948 query = "SELECT * FROM `Media` WHERE `DiskPrompt` = ?";
1949 r = MsiDatabaseOpenView(hdb, query, &view);
1950 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1951 r = MsiViewExecute(view, rec);
1952 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1954 MsiCloseHandle(rec);
1956 r = MsiViewFetch(view, &rec);
1957 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
1959 MsiCloseHandle(rec);
1960 MsiViewClose(view);
1961 MsiCloseHandle(view);
1963 MsiCloseHandle( hdb );
1964 DeleteFile(msifile);
1967 static CHAR CURR_DIR[MAX_PATH];
1969 static const CHAR test_data[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1970 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1971 "TestTable\tFirstPrimaryColumn\n"
1972 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1974 static const CHAR two_primary[] = "PrimaryOne\tPrimaryTwo\n"
1975 "s255\ts255\n"
1976 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1977 "papaya\tleaf\n"
1978 "papaya\tflower\n";
1980 static const CHAR endlines1[] = "A\tB\tC\tD\tE\tF\r\n"
1981 "s72\ts72\ts72\ts72\ts72\ts72\n"
1982 "Table\tA\r\n"
1983 "a\tb\tc\td\te\tf\n"
1984 "g\th\ti\t\rj\tk\tl\r\n";
1986 static const CHAR endlines2[] = "A\tB\tC\tD\tE\tF\r"
1987 "s72\ts72\ts72\ts72\ts72\ts72\n"
1988 "Table2\tA\r\n"
1989 "a\tb\tc\td\te\tf\n"
1990 "g\th\ti\tj\tk\tl\r\n";
1992 static const CHAR suminfo[] = "PropertyId\tValue\n"
1993 "i2\tl255\n"
1994 "_SummaryInformation\tPropertyId\n"
1995 "1\t1252\n"
1996 "2\tInstaller Database\n"
1997 "3\tInstaller description\n"
1998 "4\tWineHQ\n"
1999 "5\tInstaller\n"
2000 "6\tInstaller comments\n"
2001 "7\tIntel;1033\n"
2002 "9\t{12345678-1234-1234-1234-123456789012}\n"
2003 "12\t2009/04/12 15:46:11\n"
2004 "13\t2009/04/12 15:46:11\n"
2005 "14\t200\n"
2006 "15\t2\n"
2007 "18\tVim\n"
2008 "19\t2\n";
2010 static void write_file(const CHAR *filename, const char *data, int data_size)
2012 DWORD size;
2014 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
2015 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2017 WriteFile(hf, data, data_size, &size, NULL);
2018 CloseHandle(hf);
2021 static UINT add_table_to_db(MSIHANDLE hdb, LPCSTR table_data)
2023 UINT r;
2025 write_file("temp_file", table_data, (lstrlen(table_data) - 1) * sizeof(char));
2026 r = MsiDatabaseImportA(hdb, CURR_DIR, "temp_file");
2027 DeleteFileA("temp_file");
2029 return r;
2032 static void test_suminfo_import(void)
2034 MSIHANDLE hdb, hsi, view = 0;
2035 LPCSTR query;
2036 UINT r, count, size, type;
2037 char str_value[50];
2038 INT int_value;
2039 FILETIME ft_value;
2041 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
2043 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
2044 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2046 r = add_table_to_db(hdb, suminfo);
2047 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2049 /* _SummaryInformation is not imported as a regular table... */
2051 query = "SELECT * FROM `_SummaryInformation`";
2052 r = MsiDatabaseOpenViewA(hdb, query, &view);
2053 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %u\n", r);
2054 MsiCloseHandle(view);
2056 /* ...its data is added to the special summary information stream */
2058 r = MsiGetSummaryInformationA(hdb, NULL, 0, &hsi);
2059 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2061 r = MsiSummaryInfoGetPropertyCount(hsi, &count);
2062 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2063 ok(count == 14, "Expected 14, got %u\n", count);
2065 r = MsiSummaryInfoGetPropertyA(hsi, PID_CODEPAGE, &type, &int_value, NULL, NULL, NULL);
2066 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2067 ok(type == VT_I2, "Expected VT_I2, got %u\n", type);
2068 ok(int_value == 1252, "Expected 1252, got %d\n", int_value);
2070 size = sizeof(str_value);
2071 r = MsiSummaryInfoGetPropertyA(hsi, PID_TITLE, &type, NULL, NULL, str_value, &size);
2072 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2073 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2074 ok(size == 18, "Expected 18, got %u\n", size);
2075 ok(!strcmp(str_value, "Installer Database"),
2076 "Expected \"Installer Database\", got %s\n", str_value);
2078 size = sizeof(str_value);
2079 r = MsiSummaryInfoGetPropertyA(hsi, PID_SUBJECT, &type, NULL, NULL, str_value, &size);
2080 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2081 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2082 ok(!strcmp(str_value, "Installer description"),
2083 "Expected \"Installer description\", got %s\n", str_value);
2085 size = sizeof(str_value);
2086 r = MsiSummaryInfoGetPropertyA(hsi, PID_AUTHOR, &type, NULL, NULL, str_value, &size);
2087 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2088 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2089 ok(!strcmp(str_value, "WineHQ"),
2090 "Expected \"WineHQ\", got %s\n", str_value);
2092 size = sizeof(str_value);
2093 r = MsiSummaryInfoGetPropertyA(hsi, PID_KEYWORDS, &type, NULL, NULL, str_value, &size);
2094 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2095 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2096 ok(!strcmp(str_value, "Installer"),
2097 "Expected \"Installer\", got %s\n", str_value);
2099 size = sizeof(str_value);
2100 r = MsiSummaryInfoGetPropertyA(hsi, PID_COMMENTS, &type, NULL, NULL, str_value, &size);
2101 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2102 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2103 ok(!strcmp(str_value, "Installer comments"),
2104 "Expected \"Installer comments\", got %s\n", str_value);
2106 size = sizeof(str_value);
2107 r = MsiSummaryInfoGetPropertyA(hsi, PID_TEMPLATE, &type, NULL, NULL, str_value, &size);
2108 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2109 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2110 ok(!strcmp(str_value, "Intel;1033"),
2111 "Expected \"Intel;1033\", got %s\n", str_value);
2113 size = sizeof(str_value);
2114 r = MsiSummaryInfoGetPropertyA(hsi, PID_REVNUMBER, &type, NULL, NULL, str_value, &size);
2115 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2116 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2117 ok(!strcmp(str_value, "{12345678-1234-1234-1234-123456789012}"),
2118 "Expected \"{12345678-1234-1234-1234-123456789012}\", got %s\n", str_value);
2120 r = MsiSummaryInfoGetPropertyA(hsi, PID_CREATE_DTM, &type, NULL, &ft_value, NULL, NULL);
2121 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2122 ok(type == VT_FILETIME, "Expected VT_FILETIME, got %u\n", type);
2124 r = MsiSummaryInfoGetPropertyA(hsi, PID_LASTSAVE_DTM, &type, NULL, &ft_value, NULL, NULL);
2125 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2126 ok(type == VT_FILETIME, "Expected VT_FILETIME, got %u\n", type);
2128 r = MsiSummaryInfoGetPropertyA(hsi, PID_PAGECOUNT, &type, &int_value, NULL, NULL, NULL);
2129 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2130 ok(type == VT_I4, "Expected VT_I4, got %u\n", type);
2131 ok(int_value == 200, "Expected 200, got %d\n", int_value);
2133 r = MsiSummaryInfoGetPropertyA(hsi, PID_WORDCOUNT, &type, &int_value, NULL, NULL, NULL);
2134 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2135 ok(type == VT_I4, "Expected VT_I4, got %u\n", type);
2136 ok(int_value == 2, "Expected 2, got %d\n", int_value);
2138 r = MsiSummaryInfoGetPropertyA(hsi, PID_SECURITY, &type, &int_value, NULL, NULL, NULL);
2139 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2140 ok(type == VT_I4, "Expected VT_I4, got %u\n", type);
2141 ok(int_value == 2, "Expected 2, got %d\n", int_value);
2143 size = sizeof(str_value);
2144 r = MsiSummaryInfoGetPropertyA(hsi, PID_APPNAME, &type, NULL, NULL, str_value, &size);
2145 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
2146 ok(type == VT_LPSTR, "Expected VT_LPSTR, got %u\n", type);
2147 ok(!strcmp(str_value, "Vim"), "Expected \"Vim\", got %s\n", str_value);
2149 MsiCloseHandle(hsi);
2150 MsiCloseHandle(hdb);
2151 DeleteFileA(msifile);
2154 static void test_msiimport(void)
2156 MSIHANDLE hdb, view, rec;
2157 LPCSTR query;
2158 UINT r, count;
2159 signed int i;
2161 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
2163 r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
2164 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2166 r = add_table_to_db(hdb, test_data);
2167 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2169 r = add_table_to_db(hdb, two_primary);
2170 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2172 r = add_table_to_db(hdb, endlines1);
2173 if (r == ERROR_FUNCTION_FAILED)
2175 /* win9x doesn't handle this case */
2176 skip("endlines not handled correctly.\n");
2177 MsiCloseHandle(hdb);
2178 DeleteFileA(msifile);
2179 return;
2182 r = add_table_to_db(hdb, endlines2);
2183 ok(r == ERROR_FUNCTION_FAILED,
2184 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
2186 query = "SELECT * FROM `TestTable`";
2187 r = MsiDatabaseOpenView(hdb, query, &view);
2188 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2190 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
2191 count = MsiRecordGetFieldCount(rec);
2192 ok(count == 9, "Expected 9, got %d\n", count);
2193 ok(check_record(rec, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
2194 ok(check_record(rec, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
2195 ok(check_record(rec, 3, "ShortInt"), "Expected ShortInt\n");
2196 ok(check_record(rec, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
2197 ok(check_record(rec, 5, "LongInt"), "Expected LongInt\n");
2198 ok(check_record(rec, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
2199 ok(check_record(rec, 7, "String"), "Expected String\n");
2200 ok(check_record(rec, 8, "LocalizableString"), "Expected LocalizableString\n");
2201 ok(check_record(rec, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
2202 MsiCloseHandle(rec);
2204 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2205 count = MsiRecordGetFieldCount(rec);
2206 ok(count == 9, "Expected 9, got %d\n", count);
2207 ok(check_record(rec, 1, "s255"), "Expected s255\n");
2208 ok(check_record(rec, 2, "i2"), "Expected i2\n");
2209 ok(check_record(rec, 3, "i2"), "Expected i2\n");
2210 ok(check_record(rec, 4, "I2"), "Expected I2\n");
2211 ok(check_record(rec, 5, "i4"), "Expected i4\n");
2212 ok(check_record(rec, 6, "I4"), "Expected I4\n");
2213 ok(check_record(rec, 7, "S255"), "Expected S255\n");
2214 ok(check_record(rec, 8, "S0"), "Expected S0\n");
2215 ok(check_record(rec, 9, "s0"), "Expected s0\n");
2216 MsiCloseHandle(rec);
2218 query = "SELECT * FROM `TestTable`";
2219 r = do_query(hdb, query, &rec);
2220 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2221 ok(check_record(rec, 1, "stringage"), "Expected 'stringage'\n");
2222 ok(check_record(rec, 7, "another string"), "Expected 'another string'\n");
2223 ok(check_record(rec, 8, "localizable"), "Expected 'localizable'\n");
2224 ok(check_record(rec, 9, "duh"), "Expected 'duh'\n");
2226 i = MsiRecordGetInteger(rec, 2);
2227 ok(i == 5, "Expected 5, got %d\n", i);
2229 i = MsiRecordGetInteger(rec, 3);
2230 ok(i == 2, "Expected 2, got %d\n", i);
2232 i = MsiRecordGetInteger(rec, 4);
2233 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
2235 i = MsiRecordGetInteger(rec, 5);
2236 ok(i == 2147483640, "Expected 2147483640, got %d\n", i);
2238 i = MsiRecordGetInteger(rec, 6);
2239 ok(i == -2147483640, "Expected -2147483640, got %d\n", i);
2241 MsiCloseHandle(rec);
2242 MsiViewClose(view);
2243 MsiCloseHandle(view);
2245 query = "SELECT * FROM `TwoPrimary`";
2246 r = MsiDatabaseOpenView(hdb, query, &view);
2247 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2249 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
2250 count = MsiRecordGetFieldCount(rec);
2251 ok(count == 2, "Expected 2, got %d\n", count);
2252 ok(check_record(rec, 1, "PrimaryOne"), "Expected PrimaryOne\n");
2253 ok(check_record(rec, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
2255 MsiCloseHandle(rec);
2257 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2258 count = MsiRecordGetFieldCount(rec);
2259 ok(count == 2, "Expected 2, got %d\n", count);
2260 ok(check_record(rec, 1, "s255"), "Expected s255\n");
2261 ok(check_record(rec, 2, "s255"), "Expected s255\n");
2262 MsiCloseHandle(rec);
2264 r = MsiViewExecute(view, 0);
2265 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2267 r = MsiViewFetch(view, &rec);
2268 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2270 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
2271 ok(check_record(rec, 2, "leaf"), "Expected 'leaf'\n");
2273 MsiCloseHandle(rec);
2275 r = MsiViewFetch(view, &rec);
2276 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2278 ok(check_record(rec, 1, "papaya"), "Expected 'papaya'\n");
2279 ok(check_record(rec, 2, "flower"), "Expected 'flower'\n");
2281 MsiCloseHandle(rec);
2283 r = MsiViewFetch(view, &rec);
2284 ok(r == ERROR_NO_MORE_ITEMS,
2285 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
2287 r = MsiViewClose(view);
2288 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2290 MsiCloseHandle(view);
2292 query = "SELECT * FROM `Table`";
2293 r = MsiDatabaseOpenView(hdb, query, &view);
2294 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2296 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
2297 count = MsiRecordGetFieldCount(rec);
2298 ok(count == 6, "Expected 6, got %d\n", count);
2299 ok(check_record(rec, 1, "A"), "Expected A\n");
2300 ok(check_record(rec, 2, "B"), "Expected B\n");
2301 ok(check_record(rec, 3, "C"), "Expected C\n");
2302 ok(check_record(rec, 4, "D"), "Expected D\n");
2303 ok(check_record(rec, 5, "E"), "Expected E\n");
2304 ok(check_record(rec, 6, "F"), "Expected F\n");
2305 MsiCloseHandle(rec);
2307 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
2308 count = MsiRecordGetFieldCount(rec);
2309 ok(count == 6, "Expected 6, got %d\n", count);
2310 ok(check_record(rec, 1, "s72"), "Expected s72\n");
2311 ok(check_record(rec, 2, "s72"), "Expected s72\n");
2312 ok(check_record(rec, 3, "s72"), "Expected s72\n");
2313 ok(check_record(rec, 4, "s72"), "Expected s72\n");
2314 ok(check_record(rec, 5, "s72"), "Expected s72\n");
2315 ok(check_record(rec, 6, "s72"), "Expected s72\n");
2316 MsiCloseHandle(rec);
2318 MsiViewClose(view);
2319 MsiCloseHandle(view);
2321 query = "SELECT * FROM `Table`";
2322 r = MsiDatabaseOpenView(hdb, query, &view);
2323 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2325 r = MsiViewExecute(view, 0);
2326 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2328 r = MsiViewFetch(view, &rec);
2329 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2330 ok(check_record(rec, 1, "a"), "Expected 'a'\n");
2331 ok(check_record(rec, 2, "b"), "Expected 'b'\n");
2332 ok(check_record(rec, 3, "c"), "Expected 'c'\n");
2333 ok(check_record(rec, 4, "d"), "Expected 'd'\n");
2334 ok(check_record(rec, 5, "e"), "Expected 'e'\n");
2335 ok(check_record(rec, 6, "f"), "Expected 'f'\n");
2337 MsiCloseHandle(rec);
2339 r = MsiViewFetch(view, &rec);
2340 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2341 ok(check_record(rec, 1, "g"), "Expected 'g'\n");
2342 ok(check_record(rec, 2, "h"), "Expected 'h'\n");
2343 ok(check_record(rec, 3, "i"), "Expected 'i'\n");
2344 ok(check_record(rec, 4, "j"), "Expected 'j'\n");
2345 ok(check_record(rec, 5, "k"), "Expected 'k'\n");
2346 ok(check_record(rec, 6, "l"), "Expected 'l'\n");
2348 MsiCloseHandle(rec);
2350 r = MsiViewFetch(view, &rec);
2351 ok(r == ERROR_NO_MORE_ITEMS,
2352 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
2354 MsiViewClose(view);
2355 MsiCloseHandle(view);
2356 MsiCloseHandle(hdb);
2357 DeleteFileA(msifile);
2360 static const CHAR bin_import_dat[] = "Name\tData\r\n"
2361 "s72\tV0\r\n"
2362 "Binary\tName\r\n"
2363 "filename1\tfilename1.ibd\r\n";
2365 static void test_binary_import(void)
2367 MSIHANDLE hdb = 0, rec;
2368 char file[MAX_PATH];
2369 char buf[MAX_PATH];
2370 char path[MAX_PATH];
2371 DWORD size;
2372 LPCSTR query;
2373 UINT r;
2375 /* create files to import */
2376 write_file("bin_import.idt", bin_import_dat,
2377 (sizeof(bin_import_dat) - 1) * sizeof(char));
2378 CreateDirectory("bin_import", NULL);
2379 create_file_data("bin_import/filename1.ibd", "just some words", 15);
2381 /* import files into database */
2382 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
2383 ok( r == ERROR_SUCCESS , "Failed to open database\n");
2385 GetCurrentDirectory(MAX_PATH, path);
2386 r = MsiDatabaseImport(hdb, path, "bin_import.idt");
2387 ok(r == ERROR_SUCCESS , "Failed to import Binary table\n");
2389 /* read file from the Binary table */
2390 query = "SELECT * FROM `Binary`";
2391 r = do_query(hdb, query, &rec);
2392 ok(r == ERROR_SUCCESS, "SELECT query failed: %d\n", r);
2394 size = MAX_PATH;
2395 r = MsiRecordGetString(rec, 1, file, &size);
2396 ok(r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
2397 ok(!lstrcmp(file, "filename1"), "Expected 'filename1', got %s\n", file);
2399 size = MAX_PATH;
2400 memset(buf, 0, MAX_PATH);
2401 r = MsiRecordReadStream(rec, 2, buf, &size);
2402 ok(r == ERROR_SUCCESS, "Failed to get stream: %d\n", r);
2403 ok(!lstrcmp(buf, "just some words"),
2404 "Expected 'just some words', got %s\n", buf);
2406 r = MsiCloseHandle(rec);
2407 ok(r == ERROR_SUCCESS , "Failed to close record handle\n");
2409 r = MsiCloseHandle(hdb);
2410 ok(r == ERROR_SUCCESS , "Failed to close database\n");
2412 DeleteFile("bin_import/filename1.ibd");
2413 RemoveDirectory("bin_import");
2414 DeleteFile("bin_import.idt");
2417 static void test_markers(void)
2419 MSIHANDLE hdb, rec;
2420 LPCSTR query;
2421 UINT r;
2423 hdb = create_db();
2424 ok( hdb, "failed to create db\n");
2426 rec = MsiCreateRecord(3);
2427 MsiRecordSetString(rec, 1, "Table");
2428 MsiRecordSetString(rec, 2, "Apples");
2429 MsiRecordSetString(rec, 3, "Oranges");
2431 /* try a legit create */
2432 query = "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2433 r = run_query(hdb, 0, query);
2434 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2435 MsiCloseHandle(rec);
2437 /* try table name as marker */
2438 rec = MsiCreateRecord(1);
2439 MsiRecordSetString(rec, 1, "Fable");
2440 query = "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2441 r = run_query(hdb, rec, query);
2442 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2444 /* verify that we just created a table called '?', not 'Fable' */
2445 r = try_query(hdb, "SELECT * from `Fable`");
2446 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2448 r = try_query(hdb, "SELECT * from `?`");
2449 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2451 /* try table name as marker without backticks */
2452 MsiRecordSetString(rec, 1, "Mable");
2453 query = "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2454 r = run_query(hdb, rec, query);
2455 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2457 /* try one column name as marker */
2458 MsiRecordSetString(rec, 1, "One");
2459 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2460 r = run_query(hdb, rec, query);
2461 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2462 MsiCloseHandle(rec);
2464 /* try column names as markers */
2465 rec = MsiCreateRecord(2);
2466 MsiRecordSetString(rec, 1, "One");
2467 MsiRecordSetString(rec, 2, "Two");
2468 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
2469 r = run_query(hdb, rec, query);
2470 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2471 MsiCloseHandle(rec);
2473 /* try names with backticks */
2474 rec = MsiCreateRecord(3);
2475 MsiRecordSetString(rec, 1, "One");
2476 MsiRecordSetString(rec, 2, "Two");
2477 MsiRecordSetString(rec, 3, "One");
2478 query = "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
2479 r = run_query(hdb, rec, query);
2480 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2482 /* try names with backticks, minus definitions */
2483 query = "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
2484 r = run_query(hdb, rec, query);
2485 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2487 /* try names without backticks */
2488 query = "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
2489 r = run_query(hdb, rec, query);
2490 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2491 MsiCloseHandle(rec);
2493 /* try one long marker */
2494 rec = MsiCreateRecord(1);
2495 MsiRecordSetString(rec, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
2496 query = "CREATE TABLE `Mable` ( ? )";
2497 r = run_query(hdb, rec, query);
2498 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2499 MsiCloseHandle(rec);
2501 /* try all names as markers */
2502 rec = MsiCreateRecord(4);
2503 MsiRecordSetString(rec, 1, "Mable");
2504 MsiRecordSetString(rec, 2, "One");
2505 MsiRecordSetString(rec, 3, "Two");
2506 MsiRecordSetString(rec, 4, "One");
2507 query = "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
2508 r = run_query(hdb, rec, query);
2509 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2510 MsiCloseHandle(rec);
2512 /* try a legit insert */
2513 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
2514 r = run_query(hdb, 0, query);
2515 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2517 r = try_query(hdb, "SELECT * from `Table`");
2518 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2520 /* try values as markers */
2521 rec = MsiCreateRecord(2);
2522 MsiRecordSetInteger(rec, 1, 4);
2523 MsiRecordSetString(rec, 2, "hi");
2524 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2525 r = run_query(hdb, rec, query);
2526 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2527 MsiCloseHandle(rec);
2529 /* try column names and values as markers */
2530 rec = MsiCreateRecord(4);
2531 MsiRecordSetString(rec, 1, "One");
2532 MsiRecordSetString(rec, 2, "Two");
2533 MsiRecordSetInteger(rec, 3, 5);
2534 MsiRecordSetString(rec, 4, "hi");
2535 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
2536 r = run_query(hdb, rec, query);
2537 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2538 MsiCloseHandle(rec);
2540 /* try column names as markers */
2541 rec = MsiCreateRecord(2);
2542 MsiRecordSetString(rec, 1, "One");
2543 MsiRecordSetString(rec, 2, "Two");
2544 query = "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
2545 r = run_query(hdb, rec, query);
2546 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2547 MsiCloseHandle(rec);
2549 /* try table name as a marker */
2550 rec = MsiCreateRecord(1);
2551 MsiRecordSetString(rec, 1, "Table");
2552 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
2553 r = run_query(hdb, rec, query);
2554 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2555 MsiCloseHandle(rec);
2557 /* try table name and values as markers */
2558 rec = MsiCreateRecord(3);
2559 MsiRecordSetString(rec, 1, "Table");
2560 MsiRecordSetInteger(rec, 2, 10);
2561 MsiRecordSetString(rec, 3, "haha");
2562 query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
2563 r = run_query(hdb, rec, query);
2564 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
2565 MsiCloseHandle(rec);
2567 /* try all markers */
2568 rec = MsiCreateRecord(5);
2569 MsiRecordSetString(rec, 1, "Table");
2570 MsiRecordSetString(rec, 1, "One");
2571 MsiRecordSetString(rec, 1, "Two");
2572 MsiRecordSetInteger(rec, 2, 10);
2573 MsiRecordSetString(rec, 3, "haha");
2574 query = "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
2575 r = run_query(hdb, rec, query);
2576 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
2577 MsiCloseHandle(rec);
2579 /* insert an integer as a string */
2580 rec = MsiCreateRecord(2);
2581 MsiRecordSetString(rec, 1, "11");
2582 MsiRecordSetString(rec, 2, "hi");
2583 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2584 r = run_query(hdb, rec, query);
2585 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2586 MsiCloseHandle(rec);
2588 /* leave off the '' for the string */
2589 rec = MsiCreateRecord(2);
2590 MsiRecordSetInteger(rec, 1, 12);
2591 MsiRecordSetString(rec, 2, "hi");
2592 query = "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
2593 r = run_query(hdb, rec, query);
2594 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
2595 MsiCloseHandle(rec);
2597 MsiCloseHandle(hdb);
2598 DeleteFileA(msifile);
2601 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
2602 static void test_handle_limit(void)
2604 int i;
2605 MSIHANDLE hdb;
2606 MSIHANDLE hviews[MY_NVIEWS];
2607 UINT r;
2609 /* create an empty db */
2610 hdb = create_db();
2611 ok( hdb, "failed to create db\n");
2613 memset(hviews, 0, sizeof(hviews));
2615 for (i=0; i<MY_NVIEWS; i++) {
2616 static char szQueryBuf[256] = "SELECT * from `_Tables`";
2617 hviews[i] = 0xdeadbeeb;
2618 r = MsiDatabaseOpenView(hdb, szQueryBuf, &hviews[i]);
2619 if( r != ERROR_SUCCESS || hviews[i] == 0xdeadbeeb ||
2620 hviews[i] == 0 || (i && (hviews[i] == hviews[i-1])))
2621 break;
2624 ok( i == MY_NVIEWS, "problem opening views\n");
2626 for (i=0; i<MY_NVIEWS; i++) {
2627 if (hviews[i] != 0 && hviews[i] != 0xdeadbeeb) {
2628 MsiViewClose(hviews[i]);
2629 r = MsiCloseHandle(hviews[i]);
2630 if (r != ERROR_SUCCESS)
2631 break;
2635 ok( i == MY_NVIEWS, "problem closing views\n");
2637 r = MsiCloseHandle(hdb);
2638 ok( r == ERROR_SUCCESS, "failed to close database\n");
2641 static void generate_transform(void)
2643 MSIHANDLE hdb1, hdb2, hrec;
2644 LPCSTR query;
2645 UINT r;
2647 /* start with two identical databases */
2648 CopyFile(msifile2, msifile, FALSE);
2650 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb1 );
2651 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2653 r = MsiDatabaseCommit( hdb1 );
2654 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
2656 r = MsiOpenDatabase(msifile2, MSIDBOPEN_READONLY, &hdb2 );
2657 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
2659 /* the transform between two identical database should be empty */
2660 r = MsiDatabaseGenerateTransform(hdb1, hdb2, NULL, 0, 0);
2661 todo_wine {
2662 ok( r == ERROR_NO_DATA, "return code %d, should be ERROR_NO_DATA\n", r );
2665 query = "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
2666 r = run_query(hdb1, 0, query);
2667 ok(r == ERROR_SUCCESS, "failed to add table\n");
2669 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
2670 r = run_query(hdb1, 0, query);
2671 ok(r == ERROR_SUCCESS, "failed to add row 1\n");
2673 query = "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
2674 r = run_query(hdb1, 0, query);
2675 ok(r == ERROR_SUCCESS, "failed to add row 2\n");
2677 query = "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
2678 r = run_query(hdb1, 0, query);
2679 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2681 query = "DELETE FROM `MOO` WHERE `NOO` = 3";
2682 r = run_query(hdb1, 0, query);
2683 ok(r == ERROR_SUCCESS, "failed to delete row\n");
2685 hrec = MsiCreateRecord(2);
2686 r = MsiRecordSetInteger(hrec, 1, 1);
2687 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2689 write_file("testdata.bin", "naengmyon", 9);
2690 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2691 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2693 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2694 r = run_query(hdb1, hrec, query);
2695 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2697 MsiCloseHandle(hrec);
2699 query = "ALTER TABLE `MOO` ADD `COW` INTEGER";
2700 r = run_query(hdb1, 0, query);
2701 ok(r == ERROR_SUCCESS, "failed to add column\n");
2703 query = "ALTER TABLE `MOO` ADD `PIG` INTEGER";
2704 r = run_query(hdb1, 0, query);
2705 ok(r == ERROR_SUCCESS, "failed to add column\n");
2707 query = "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
2708 r = run_query(hdb1, 0, query);
2709 ok(r == ERROR_SUCCESS, "failed to modify row\n");
2711 query = "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
2712 "`Value` CHAR(0) PRIMARY KEY `Property`)";
2713 r = run_query(hdb1, 0, query);
2714 ok(r == ERROR_SUCCESS, "failed to add property table\n");
2716 query = "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2717 r = run_query(hdb1, 0, query);
2718 ok(r == ERROR_SUCCESS, "failed to add property\n");
2720 /* database needs to be committed */
2721 MsiDatabaseCommit(hdb1);
2723 r = MsiDatabaseGenerateTransform(hdb1, hdb2, mstfile, 0, 0);
2724 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
2726 MsiCloseHandle( hdb1 );
2727 MsiCloseHandle( hdb2 );
2729 DeleteFile("testdata.bin");
2732 /* data for generating a transform */
2734 /* tables transform names - encoded as they would be in an msi database file */
2735 static const WCHAR name1[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
2736 static const WCHAR name2[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
2737 static const WCHAR name3[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
2738 static const WCHAR name4[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2739 static const WCHAR name5[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2740 static const WCHAR name6[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
2741 static const WCHAR name7[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
2742 static const WCHAR name8[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
2743 static const WCHAR name9[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2745 /* data in each table */
2746 static const WCHAR data1[] = { /* AAR */
2747 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
2748 0x0201, 0x0009, 0x8002,
2750 static const WCHAR data2[] = { /* _Columns */
2751 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
2752 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
2753 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
2754 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
2755 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
2756 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
2758 static const WCHAR data3[] = { /* _Tables */
2759 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
2760 0x0101, 0x000a,
2762 static const char data4[] = /* _StringData */
2763 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
2764 static const WCHAR data5[] = { /* _StringPool */
2765 /* len, refs */
2766 0, 0, /* string 0 '' */
2767 3, 2, /* string 1 'MOO' */
2768 3, 1, /* string 2 'COW' */
2769 3, 1, /* string 3 'PIG' */
2770 1, 1, /* string 4 'c' */
2771 3, 3, /* string 5 'AAR' */
2772 3, 1, /* string 6 'CAR' */
2773 3, 1, /* string 7 'BAR' */
2774 2, 1, /* string 8 'vw' */
2775 3, 1, /* string 9 'bmw' */
2776 8, 4, /* string 10 'Property' */
2777 5, 1, /* string 11 'Value' */
2778 4, 1, /* string 12 'prop' */
2779 3, 1, /* string 13 'val' */
2781 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
2782 static const WCHAR data6[] = { /* MOO */
2783 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
2784 0x0000, 0x8003, /* delete row */
2787 static const WCHAR data7[] = { /* BINARY */
2788 0x0201, 0x8001, 0x0001,
2791 static const char data8[] = /* stream data for the BINARY table */
2792 "naengmyon";
2794 static const WCHAR data9[] = { /* Property */
2795 0x0201, 0x000c, 0x000d,
2798 static const struct {
2799 LPCWSTR name;
2800 const void *data;
2801 DWORD size;
2802 } table_transform_data[] =
2804 { name1, data1, sizeof data1 },
2805 { name2, data2, sizeof data2 },
2806 { name3, data3, sizeof data3 },
2807 { name4, data4, sizeof data4 - 1 },
2808 { name5, data5, sizeof data5 },
2809 { name6, data6, sizeof data6 },
2810 { name7, data7, sizeof data7 },
2811 { name8, data8, sizeof data8 - 1 },
2812 { name9, data9, sizeof data9 },
2815 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2817 static void generate_transform_manual(void)
2819 IStorage *stg = NULL;
2820 IStream *stm;
2821 WCHAR name[0x20];
2822 HRESULT r;
2823 DWORD i, count;
2824 const DWORD mode = STGM_CREATE|STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE;
2826 const CLSID CLSID_MsiTransform = { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2828 MultiByteToWideChar(CP_ACP, 0, mstfile, -1, name, 0x20);
2830 r = StgCreateDocfile(name, mode, 0, &stg);
2831 ok(r == S_OK, "failed to create storage\n");
2832 if (!stg)
2833 return;
2835 r = IStorage_SetClass( stg, &CLSID_MsiTransform );
2836 ok(r == S_OK, "failed to set storage type\n");
2838 for (i=0; i<NUM_TRANSFORM_TABLES; i++)
2840 r = IStorage_CreateStream( stg, table_transform_data[i].name,
2841 STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm );
2842 if (FAILED(r))
2844 ok(0, "failed to create stream %08x\n", r);
2845 continue;
2848 r = IStream_Write( stm, table_transform_data[i].data,
2849 table_transform_data[i].size, &count );
2850 if (FAILED(r) || count != table_transform_data[i].size)
2851 ok(0, "failed to write stream\n");
2852 IStream_Release(stm);
2855 IStorage_Release(stg);
2858 static UINT set_summary_info(MSIHANDLE hdb)
2860 UINT res;
2861 MSIHANDLE suminfo;
2863 /* build summary info */
2864 res = MsiGetSummaryInformation(hdb, NULL, 7, &suminfo);
2865 ok( res == ERROR_SUCCESS , "Failed to open summaryinfo\n" );
2867 res = MsiSummaryInfoSetProperty(suminfo,2, VT_LPSTR, 0,NULL,
2868 "Installation Database");
2869 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2871 res = MsiSummaryInfoSetProperty(suminfo,3, VT_LPSTR, 0,NULL,
2872 "Installation Database");
2873 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2875 res = MsiSummaryInfoSetProperty(suminfo,4, VT_LPSTR, 0,NULL,
2876 "Wine Hackers");
2877 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2879 res = MsiSummaryInfoSetProperty(suminfo,7, VT_LPSTR, 0,NULL,
2880 ";1033");
2881 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2883 res = MsiSummaryInfoSetProperty(suminfo,9, VT_LPSTR, 0,NULL,
2884 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2885 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2887 res = MsiSummaryInfoSetProperty(suminfo, 14, VT_I4, 100, NULL, NULL);
2888 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2890 res = MsiSummaryInfoSetProperty(suminfo, 15, VT_I4, 0, NULL, NULL);
2891 ok( res == ERROR_SUCCESS , "Failed to set summary info\n" );
2893 res = MsiSummaryInfoPersist(suminfo);
2894 ok( res == ERROR_SUCCESS , "Failed to make summary info persist\n" );
2896 res = MsiCloseHandle( suminfo);
2897 ok( res == ERROR_SUCCESS , "Failed to close suminfo\n" );
2899 return res;
2902 static MSIHANDLE create_package_db(LPCSTR filename)
2904 MSIHANDLE hdb = 0;
2905 UINT res;
2907 DeleteFile(msifile);
2909 /* create an empty database */
2910 res = MsiOpenDatabase(filename, MSIDBOPEN_CREATE, &hdb );
2911 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
2912 if( res != ERROR_SUCCESS )
2913 return hdb;
2915 res = MsiDatabaseCommit( hdb );
2916 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
2918 res = set_summary_info(hdb);
2920 res = create_directory_table(hdb);
2921 ok( res == ERROR_SUCCESS , "Failed to create directory table\n" );
2923 return hdb;
2926 static MSIHANDLE package_from_db(MSIHANDLE hdb)
2928 UINT res;
2929 CHAR szPackage[10];
2930 MSIHANDLE hPackage;
2932 sprintf(szPackage,"#%i",hdb);
2933 res = MsiOpenPackage(szPackage,&hPackage);
2934 if (res != ERROR_SUCCESS)
2935 return 0;
2937 res = MsiCloseHandle(hdb);
2938 if (res != ERROR_SUCCESS)
2939 return 0;
2941 return hPackage;
2944 static void test_try_transform(void)
2946 MSIHANDLE hdb, hview, hrec, hpkg;
2947 LPCSTR query;
2948 UINT r;
2949 DWORD sz;
2950 char buffer[MAX_PATH];
2952 DeleteFile(msifile);
2953 DeleteFile(mstfile);
2955 /* create the database */
2956 hdb = create_package_db(msifile);
2957 ok(hdb, "Failed to create package db\n");
2959 query = "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
2960 r = run_query(hdb, 0, query);
2961 ok(r == ERROR_SUCCESS, "failed to add table\n");
2963 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
2964 r = run_query(hdb, 0, query);
2965 ok(r == ERROR_SUCCESS, "failed to add row\n");
2967 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
2968 r = run_query(hdb, 0, query);
2969 ok(r == ERROR_SUCCESS, "failed to add row\n");
2971 query = "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
2972 r = run_query(hdb, 0, query);
2973 ok(r == ERROR_SUCCESS, "failed to add row\n");
2975 query = "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
2976 r = run_query(hdb, 0, query);
2977 ok(r == ERROR_SUCCESS, "failed to add table\n");
2979 hrec = MsiCreateRecord(2);
2980 r = MsiRecordSetInteger(hrec, 1, 2);
2981 ok(r == ERROR_SUCCESS, "failed to set integer\n");
2983 write_file("testdata.bin", "lamyon", 6);
2984 r = MsiRecordSetStream(hrec, 2, "testdata.bin");
2985 ok(r == ERROR_SUCCESS, "failed to set stream\n");
2987 query = "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2988 r = run_query(hdb, hrec, query);
2989 ok(r == ERROR_SUCCESS, "failed to add row with blob\n");
2991 MsiCloseHandle(hrec);
2993 r = MsiDatabaseCommit( hdb );
2994 ok( r == ERROR_SUCCESS , "Failed to commit database\n" );
2996 MsiCloseHandle( hdb );
2997 DeleteFileA("testdata.bin");
3000 * Both these generate an equivalent transform,
3001 * but the first doesn't work in Wine yet
3002 * because MsiDatabaseGenerateTransform is unimplemented.
3004 if (0)
3005 generate_transform();
3006 else
3007 generate_transform_manual();
3009 r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb );
3010 ok( r == ERROR_SUCCESS , "Failed to create database\n" );
3012 r = MsiDatabaseApplyTransform( hdb, mstfile, 0 );
3013 ok( r == ERROR_SUCCESS, "return code %d, should be ERROR_SUCCESS\n", r );
3015 MsiDatabaseCommit( hdb );
3017 /* check new values */
3018 hrec = 0;
3019 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
3020 r = do_query(hdb, query, &hrec);
3021 ok(r == ERROR_SUCCESS, "select query failed\n");
3022 MsiCloseHandle(hrec);
3024 query = "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
3025 hrec = 0;
3026 r = do_query(hdb, query, &hrec);
3027 ok(r == ERROR_SUCCESS, "select query failed\n");
3028 MsiCloseHandle(hrec);
3030 /* check updated values */
3031 hrec = 0;
3032 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
3033 r = do_query(hdb, query, &hrec);
3034 ok(r == ERROR_SUCCESS, "select query failed\n");
3035 MsiCloseHandle(hrec);
3037 /* check unchanged value */
3038 hrec = 0;
3039 query = "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
3040 r = do_query(hdb, query, &hrec);
3041 ok(r == ERROR_SUCCESS, "select query failed\n");
3042 MsiCloseHandle(hrec);
3044 /* check deleted value */
3045 hrec = 0;
3046 query = "select * from `MOO` where `NOO` = 3";
3047 r = do_query(hdb, query, &hrec);
3048 ok(r == ERROR_NO_MORE_ITEMS, "select query failed\n");
3049 if (hrec) MsiCloseHandle(hrec);
3051 /* check added stream */
3052 hrec = 0;
3053 query = "select `BLOB` from `BINARY` where `ID` = 1";
3054 r = do_query(hdb, query, &hrec);
3055 ok(r == ERROR_SUCCESS, "select query failed\n");
3057 /* check the contents of the stream */
3058 sz = sizeof buffer;
3059 r = MsiRecordReadStream( hrec, 1, buffer, &sz );
3060 ok(r == ERROR_SUCCESS, "read stream failed\n");
3061 ok(!memcmp(buffer, "naengmyon", 9), "stream data was wrong\n");
3062 ok(sz == 9, "stream data was wrong size\n");
3063 if (hrec) MsiCloseHandle(hrec);
3065 /* check the validity of the table with a deleted row */
3066 hrec = 0;
3067 query = "select * from `MOO`";
3068 r = MsiDatabaseOpenView(hdb, query, &hview);
3069 ok(r == ERROR_SUCCESS, "open view failed\n");
3071 r = MsiViewExecute(hview, 0);
3072 ok(r == ERROR_SUCCESS, "view execute failed\n");
3074 r = MsiViewFetch(hview, &hrec);
3075 ok(r == ERROR_SUCCESS, "view fetch failed\n");
3077 r = MsiRecordGetInteger(hrec, 1);
3078 ok(r == 1, "Expected 1, got %d\n", r);
3080 sz = sizeof buffer;
3081 r = MsiRecordGetString(hrec, 2, buffer, &sz);
3082 ok(r == ERROR_SUCCESS, "record get string failed\n");
3083 ok(!lstrcmpA(buffer, "c"), "Expected c, got %s\n", buffer);
3085 r = MsiRecordGetInteger(hrec, 3);
3086 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
3088 r = MsiRecordGetInteger(hrec, 4);
3089 ok(r == 5, "Expected 5, got %d\n", r);
3091 MsiCloseHandle(hrec);
3093 r = MsiViewFetch(hview, &hrec);
3094 ok(r == ERROR_SUCCESS, "view fetch failed\n");
3096 r = MsiRecordGetInteger(hrec, 1);
3097 ok(r == 2, "Expected 2, got %d\n", r);
3099 sz = sizeof buffer;
3100 r = MsiRecordGetString(hrec, 2, buffer, &sz);
3101 ok(r == ERROR_SUCCESS, "record get string failed\n");
3102 ok(!lstrcmpA(buffer, "b"), "Expected b, got %s\n", buffer);
3104 r = MsiRecordGetInteger(hrec, 3);
3105 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
3107 r = MsiRecordGetInteger(hrec, 4);
3108 ok(r == 0x80000000, "Expected 0x80000000, got %d\n", r);
3110 MsiCloseHandle(hrec);
3112 r = MsiViewFetch(hview, &hrec);
3113 ok(r == ERROR_NO_MORE_ITEMS, "view fetch succeeded\n");
3115 MsiCloseHandle(hrec);
3116 MsiViewClose(hview);
3117 MsiCloseHandle(hview);
3119 /* check that the property was added */
3120 hpkg = package_from_db(hdb);
3121 ok(hpkg != 0, "Expected non-NULL hpkg\n");
3123 sz = MAX_PATH;
3124 r = MsiGetProperty(hpkg, "prop", buffer, &sz);
3125 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
3126 ok(!lstrcmp(buffer, "val"), "Expected val, got %s\n", buffer);
3128 MsiCloseHandle(hpkg);
3129 MsiCloseHandle(hdb);
3131 DeleteFile(msifile);
3132 DeleteFile(mstfile);
3135 struct join_res
3137 const CHAR one[MAX_PATH];
3138 const CHAR two[MAX_PATH];
3141 struct join_res_4col
3143 const CHAR one[MAX_PATH];
3144 const CHAR two[MAX_PATH];
3145 const CHAR three[MAX_PATH];
3146 const CHAR four[MAX_PATH];
3149 struct join_res_uint
3151 UINT one;
3152 UINT two;
3153 UINT three;
3154 UINT four;
3155 UINT five;
3156 UINT six;
3159 static const struct join_res join_res_first[] =
3161 { "alveolar", "procerus" },
3162 { "septum", "procerus" },
3163 { "septum", "nasalis" },
3164 { "ramus", "nasalis" },
3165 { "malar", "mentalis" },
3168 static const struct join_res join_res_second[] =
3170 { "nasal", "septum" },
3171 { "mandible", "ramus" },
3174 static const struct join_res join_res_third[] =
3176 { "msvcp.dll", "abcdefgh" },
3177 { "msvcr.dll", "ijklmnop" },
3180 static const struct join_res join_res_fourth[] =
3182 { "msvcp.dll.01234", "single.dll.31415" },
3185 static const struct join_res join_res_fifth[] =
3187 { "malar", "procerus" },
3190 static const struct join_res join_res_sixth[] =
3192 { "malar", "procerus" },
3193 { "malar", "procerus" },
3194 { "malar", "nasalis" },
3195 { "malar", "nasalis" },
3196 { "malar", "nasalis" },
3197 { "malar", "mentalis" },
3200 static const struct join_res join_res_seventh[] =
3202 { "malar", "nasalis" },
3203 { "malar", "nasalis" },
3204 { "malar", "nasalis" },
3207 static const struct join_res_4col join_res_eighth[] =
3209 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
3210 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
3211 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
3212 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
3213 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
3214 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
3217 static const struct join_res_uint join_res_ninth[] =
3219 { 1, 2, 3, 4, 7, 8 },
3220 { 1, 2, 5, 6, 7, 8 },
3221 { 1, 2, 3, 4, 9, 10 },
3222 { 1, 2, 5, 6, 9, 10 },
3223 { 1, 2, 3, 4, 11, 12 },
3224 { 1, 2, 5, 6, 11, 12 },
3227 static void test_join(void)
3229 MSIHANDLE hdb, hview, hrec;
3230 LPCSTR query;
3231 CHAR buf[MAX_PATH];
3232 UINT r, count;
3233 DWORD size, i;
3234 BOOL data_correct;
3236 hdb = create_db();
3237 ok( hdb, "failed to create db\n");
3239 r = create_component_table( hdb );
3240 ok( r == ERROR_SUCCESS, "cannot create Component table: %d\n", r );
3242 r = add_component_entry( hdb, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
3243 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3245 r = add_component_entry( hdb, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
3246 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3248 r = add_component_entry( hdb, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
3249 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3251 r = add_component_entry( hdb, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
3252 ok( r == ERROR_SUCCESS, "cannot add component: %d\n", r );
3254 r = create_feature_components_table( hdb );
3255 ok( r == ERROR_SUCCESS, "cannot create FeatureComponents table: %d\n", r );
3257 r = add_feature_components_entry( hdb, "'procerus', 'maxilla'" );
3258 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3260 r = add_feature_components_entry( hdb, "'procerus', 'nasal'" );
3261 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3263 r = add_feature_components_entry( hdb, "'nasalis', 'nasal'" );
3264 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3266 r = add_feature_components_entry( hdb, "'nasalis', 'mandible'" );
3267 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3269 r = add_feature_components_entry( hdb, "'nasalis', 'notacomponent'" );
3270 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3272 r = add_feature_components_entry( hdb, "'mentalis', 'zygomatic'" );
3273 ok( r == ERROR_SUCCESS, "cannot add feature components: %d\n", r );
3275 r = create_std_dlls_table( hdb );
3276 ok( r == ERROR_SUCCESS, "cannot create StdDlls table: %d\n", r );
3278 r = add_std_dlls_entry( hdb, "'msvcp.dll', 'msvcp.dll.01234'" );
3279 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
3281 r = add_std_dlls_entry( hdb, "'msvcr.dll', 'msvcr.dll.56789'" );
3282 ok( r == ERROR_SUCCESS, "cannot add std dlls: %d\n", r );
3284 r = create_binary_table( hdb );
3285 ok( r == ERROR_SUCCESS, "cannot create Binary table: %d\n", r );
3287 r = add_binary_entry( hdb, "'msvcp.dll.01234', 'abcdefgh'" );
3288 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
3290 r = add_binary_entry( hdb, "'msvcr.dll.56789', 'ijklmnop'" );
3291 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
3293 r = add_binary_entry( hdb, "'single.dll.31415', 'msvcp.dll'" );
3294 ok( r == ERROR_SUCCESS, "cannot add binary: %d\n", r );
3296 query = "CREATE TABLE `One` (`A` SHORT, `B` SHORT PRIMARY KEY `A`)";
3297 r = run_query( hdb, 0, query);
3298 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3300 query = "CREATE TABLE `Two` (`C` SHORT, `D` SHORT PRIMARY KEY `C`)";
3301 r = run_query( hdb, 0, query);
3302 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3304 query = "CREATE TABLE `Three` (`E` SHORT, `F` SHORT PRIMARY KEY `E`)";
3305 r = run_query( hdb, 0, query);
3306 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3308 query = "INSERT INTO `One` (`A`, `B`) VALUES (1, 2)";
3309 r = run_query( hdb, 0, query);
3310 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3312 query = "INSERT INTO `Two` (`C`, `D`) VALUES (3, 4)";
3313 r = run_query( hdb, 0, query);
3314 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3316 query = "INSERT INTO `Two` (`C`, `D`) VALUES (5, 6)";
3317 r = run_query( hdb, 0, query);
3318 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3320 query = "INSERT INTO `Three` (`E`, `F`) VALUES (7, 8)";
3321 r = run_query( hdb, 0, query);
3322 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3324 query = "INSERT INTO `Three` (`E`, `F`) VALUES (9, 10)";
3325 r = run_query( hdb, 0, query);
3326 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3328 query = "INSERT INTO `Three` (`E`, `F`) VALUES (11, 12)";
3329 r = run_query( hdb, 0, query);
3330 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3332 query = "CREATE TABLE `Four` (`G` SHORT, `H` SHORT PRIMARY KEY `G`)";
3333 r = run_query( hdb, 0, query);
3334 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3336 query = "CREATE TABLE `Five` (`I` SHORT, `J` SHORT PRIMARY KEY `I`)";
3337 r = run_query( hdb, 0, query);
3338 ok(r == ERROR_SUCCESS, "cannot create table: %d\n", r );
3340 query = "INSERT INTO `Five` (`I`, `J`) VALUES (13, 14)";
3341 r = run_query( hdb, 0, query);
3342 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3344 query = "INSERT INTO `Five` (`I`, `J`) VALUES (15, 16)";
3345 r = run_query( hdb, 0, query);
3346 ok(r == ERROR_SUCCESS, "cannot insert into table: %d\n", r );
3348 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3349 "FROM `Component`, `FeatureComponents` "
3350 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
3351 "ORDER BY `Feature_`";
3352 r = MsiDatabaseOpenView(hdb, query, &hview);
3353 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3355 r = MsiViewExecute(hview, 0);
3356 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3358 i = 0;
3359 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3361 count = MsiRecordGetFieldCount( hrec );
3362 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3364 size = MAX_PATH;
3365 r = MsiRecordGetString( hrec, 1, buf, &size );
3366 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3367 ok( !lstrcmp( buf, join_res_first[i].one ),
3368 "For (row %d, column 1) expected '%s', got %s\n", i, join_res_first[i].one, buf );
3370 size = MAX_PATH;
3371 r = MsiRecordGetString( hrec, 2, buf, &size );
3372 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3373 ok( !lstrcmp( buf, join_res_first[i].two ),
3374 "For (row %d, column 2) expected '%s', got %s\n", i, join_res_first[i].two, buf );
3376 i++;
3377 MsiCloseHandle(hrec);
3380 ok( i == 5, "Expected 5 rows, got %d\n", i );
3381 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3383 MsiViewClose(hview);
3384 MsiCloseHandle(hview);
3386 /* try a join without a WHERE condition */
3387 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3388 "FROM `Component`, `FeatureComponents` ";
3389 r = MsiDatabaseOpenView(hdb, query, &hview);
3390 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3392 r = MsiViewExecute(hview, 0);
3393 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3395 i = 0;
3396 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3398 i++;
3399 MsiCloseHandle(hrec);
3401 ok( i == 24, "Expected 24 rows, got %d\n", i );
3403 MsiViewClose(hview);
3404 MsiCloseHandle(hview);
3406 query = "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
3407 "WHERE FeatureComponents.Component_=Component.Component "
3408 "AND (Feature_='nasalis') ORDER BY Feature_";
3409 r = MsiDatabaseOpenView(hdb, query, &hview);
3410 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3412 r = MsiViewExecute(hview, 0);
3413 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3415 i = 0;
3416 data_correct = TRUE;
3417 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3419 count = MsiRecordGetFieldCount( hrec );
3420 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3422 size = MAX_PATH;
3423 r = MsiRecordGetString( hrec, 1, buf, &size );
3424 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3425 if( lstrcmp( buf, join_res_second[i].one ))
3426 data_correct = FALSE;
3428 size = MAX_PATH;
3429 r = MsiRecordGetString( hrec, 2, buf, &size );
3430 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3431 if( lstrcmp( buf, join_res_second[i].two ))
3432 data_correct = FALSE;
3434 i++;
3435 MsiCloseHandle(hrec);
3438 ok( data_correct, "data returned in the wrong order\n");
3440 ok( i == 2, "Expected 2 rows, got %d\n", i );
3441 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3443 MsiViewClose(hview);
3444 MsiCloseHandle(hview);
3446 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3447 "FROM `StdDlls`, `Binary` "
3448 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
3449 "ORDER BY `File`";
3450 r = MsiDatabaseOpenView(hdb, query, &hview);
3451 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3453 r = MsiViewExecute(hview, 0);
3454 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3456 i = 0;
3457 data_correct = TRUE;
3458 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3460 count = MsiRecordGetFieldCount( hrec );
3461 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3463 size = MAX_PATH;
3464 r = MsiRecordGetString( hrec, 1, buf, &size );
3465 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3466 if( lstrcmp( buf, join_res_third[i].one ) )
3467 data_correct = FALSE;
3469 size = MAX_PATH;
3470 r = MsiRecordGetString( hrec, 2, buf, &size );
3471 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3472 if( lstrcmp( buf, join_res_third[i].two ) )
3473 data_correct = FALSE;
3475 i++;
3476 MsiCloseHandle(hrec);
3478 ok( data_correct, "data returned in the wrong order\n");
3480 ok( i == 2, "Expected 2 rows, got %d\n", i );
3482 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3484 MsiViewClose(hview);
3485 MsiCloseHandle(hview);
3487 query = "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
3488 "FROM `StdDlls`, `Binary` "
3489 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
3490 "ORDER BY `Name`";
3491 r = MsiDatabaseOpenView(hdb, query, &hview);
3492 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3494 r = MsiViewExecute(hview, 0);
3495 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3497 i = 0;
3498 data_correct = TRUE;
3499 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3501 count = MsiRecordGetFieldCount( hrec );
3502 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3504 size = MAX_PATH;
3505 r = MsiRecordGetString( hrec, 1, buf, &size );
3506 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3507 if( lstrcmp( buf, join_res_fourth[i].one ))
3508 data_correct = FALSE;
3510 size = MAX_PATH;
3511 r = MsiRecordGetString( hrec, 2, buf, &size );
3512 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3513 if( lstrcmp( buf, join_res_fourth[i].two ))
3514 data_correct = FALSE;
3516 i++;
3517 MsiCloseHandle(hrec);
3519 ok( data_correct, "data returned in the wrong order\n");
3521 ok( i == 1, "Expected 1 rows, got %d\n", i );
3522 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3524 MsiViewClose(hview);
3525 MsiCloseHandle(hview);
3527 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3528 "FROM `Component`, `FeatureComponents` "
3529 "WHERE `Component`.`Component` = 'zygomatic' "
3530 "AND `FeatureComponents`.`Component_` = 'maxilla' "
3531 "ORDER BY `Feature_`";
3532 r = MsiDatabaseOpenView(hdb, query, &hview);
3533 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3535 r = MsiViewExecute(hview, 0);
3536 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3538 i = 0;
3539 data_correct = TRUE;
3540 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3542 count = MsiRecordGetFieldCount( hrec );
3543 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3545 size = MAX_PATH;
3546 r = MsiRecordGetString( hrec, 1, buf, &size );
3547 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3548 if( lstrcmp( buf, join_res_fifth[i].one ))
3549 data_correct = FALSE;
3551 size = MAX_PATH;
3552 r = MsiRecordGetString( hrec, 2, buf, &size );
3553 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3554 if( lstrcmp( buf, join_res_fifth[i].two ))
3555 data_correct = FALSE;
3557 i++;
3558 MsiCloseHandle(hrec);
3560 ok( data_correct, "data returned in the wrong order\n");
3562 ok( i == 1, "Expected 1 rows, got %d\n", i );
3563 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3565 MsiViewClose(hview);
3566 MsiCloseHandle(hview);
3568 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3569 "FROM `Component`, `FeatureComponents` "
3570 "WHERE `Component` = 'zygomatic' "
3571 "ORDER BY `Feature_`";
3572 r = MsiDatabaseOpenView(hdb, query, &hview);
3573 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3575 r = MsiViewExecute(hview, 0);
3576 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3578 i = 0;
3579 data_correct = TRUE;
3580 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3582 count = MsiRecordGetFieldCount( hrec );
3583 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3585 size = MAX_PATH;
3586 r = MsiRecordGetString( hrec, 1, buf, &size );
3587 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3588 if( lstrcmp( buf, join_res_sixth[i].one ))
3589 data_correct = FALSE;
3591 size = MAX_PATH;
3592 r = MsiRecordGetString( hrec, 2, buf, &size );
3593 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3594 if( lstrcmp( buf, join_res_sixth[i].two ))
3595 data_correct = FALSE;
3597 i++;
3598 MsiCloseHandle(hrec);
3600 ok( data_correct, "data returned in the wrong order\n");
3602 ok( i == 6, "Expected 6 rows, got %d\n", i );
3603 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3605 MsiViewClose(hview);
3606 MsiCloseHandle(hview);
3608 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3609 "FROM `Component`, `FeatureComponents` "
3610 "WHERE `Component` = 'zygomatic' "
3611 "AND `Feature_` = 'nasalis' "
3612 "ORDER BY `Feature_`";
3613 r = MsiDatabaseOpenView(hdb, query, &hview);
3614 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3616 r = MsiViewExecute(hview, 0);
3617 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3619 i = 0;
3620 data_correct = TRUE;
3621 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3623 count = MsiRecordGetFieldCount( hrec );
3624 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3626 size = MAX_PATH;
3627 r = MsiRecordGetString( hrec, 1, buf, &size );
3628 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3629 if( lstrcmp( buf, join_res_seventh[i].one ))
3630 data_correct = FALSE;
3632 size = MAX_PATH;
3633 r = MsiRecordGetString( hrec, 2, buf, &size );
3634 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3635 if( lstrcmp( buf, join_res_seventh[i].two ))
3636 data_correct = FALSE;
3638 i++;
3639 MsiCloseHandle(hrec);
3642 ok( data_correct, "data returned in the wrong order\n");
3643 ok( i == 3, "Expected 3 rows, got %d\n", i );
3644 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3646 MsiViewClose(hview);
3647 MsiCloseHandle(hview);
3649 query = "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3650 "FROM `StdDlls`, `Binary` ";
3651 r = MsiDatabaseOpenView(hdb, query, &hview);
3652 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3654 r = MsiViewExecute(hview, 0);
3655 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3657 i = 0;
3658 data_correct = TRUE;
3659 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3661 count = MsiRecordGetFieldCount( hrec );
3662 ok( count == 2, "Expected 2 record fields, got %d\n", count );
3664 size = MAX_PATH;
3665 r = MsiRecordGetString( hrec, 1, buf, &size );
3666 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3667 if( lstrcmp( buf, join_res_eighth[i].one ))
3668 data_correct = FALSE;
3670 size = MAX_PATH;
3671 r = MsiRecordGetString( hrec, 2, buf, &size );
3672 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3673 if( lstrcmp( buf, join_res_eighth[i].four ))
3674 data_correct = FALSE;
3676 i++;
3677 MsiCloseHandle(hrec);
3680 ok( data_correct, "data returned in the wrong order\n");
3681 ok( i == 6, "Expected 6 rows, got %d\n", i );
3682 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3684 MsiViewClose(hview);
3685 MsiCloseHandle(hview);
3687 query = "SELECT * FROM `StdDlls`, `Binary` ";
3688 r = MsiDatabaseOpenView(hdb, query, &hview);
3689 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3691 r = MsiViewExecute(hview, 0);
3692 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3694 i = 0;
3695 data_correct = TRUE;
3696 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3698 count = MsiRecordGetFieldCount( hrec );
3699 ok( count == 4, "Expected 4 record fields, got %d\n", count );
3701 size = MAX_PATH;
3702 r = MsiRecordGetString( hrec, 1, buf, &size );
3703 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3704 if( lstrcmp( buf, join_res_eighth[i].one ))
3705 data_correct = FALSE;
3707 size = MAX_PATH;
3708 r = MsiRecordGetString( hrec, 2, buf, &size );
3709 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3710 if( lstrcmp( buf, join_res_eighth[i].two ))
3711 data_correct = FALSE;
3713 size = MAX_PATH;
3714 r = MsiRecordGetString( hrec, 3, buf, &size );
3715 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3716 if( lstrcmp( buf, join_res_eighth[i].three ))
3717 data_correct = FALSE;
3719 size = MAX_PATH;
3720 r = MsiRecordGetString( hrec, 4, buf, &size );
3721 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3722 if( lstrcmp( buf, join_res_eighth[i].four ))
3723 data_correct = FALSE;
3725 i++;
3726 MsiCloseHandle(hrec);
3728 ok( data_correct, "data returned in the wrong order\n");
3730 ok( i == 6, "Expected 6 rows, got %d\n", i );
3731 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3733 MsiViewClose(hview);
3734 MsiCloseHandle(hview);
3736 query = "SELECT * FROM `One`, `Two`, `Three` ";
3737 r = MsiDatabaseOpenView(hdb, query, &hview);
3738 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3740 r = MsiViewExecute(hview, 0);
3741 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3743 i = 0;
3744 data_correct = TRUE;
3745 while ((r = MsiViewFetch(hview, &hrec)) == ERROR_SUCCESS)
3747 count = MsiRecordGetFieldCount( hrec );
3748 ok( count == 6, "Expected 6 record fields, got %d\n", count );
3750 r = MsiRecordGetInteger( hrec, 1 );
3751 if( r != join_res_ninth[i].one )
3752 data_correct = FALSE;
3754 r = MsiRecordGetInteger( hrec, 2 );
3755 if( r != join_res_ninth[i].two )
3756 data_correct = FALSE;
3758 r = MsiRecordGetInteger( hrec, 3 );
3759 if( r != join_res_ninth[i].three )
3760 data_correct = FALSE;
3762 r = MsiRecordGetInteger( hrec, 4 );
3763 if( r != join_res_ninth[i].four )
3764 data_correct = FALSE;
3766 r = MsiRecordGetInteger( hrec, 5 );
3767 if( r != join_res_ninth[i].five )
3768 data_correct = FALSE;
3770 r = MsiRecordGetInteger( hrec, 6);
3771 if( r != join_res_ninth[i].six )
3772 data_correct = FALSE;
3774 i++;
3775 MsiCloseHandle(hrec);
3777 ok( data_correct, "data returned in the wrong order\n");
3779 ok( i == 6, "Expected 6 rows, got %d\n", i );
3780 ok( r == ERROR_NO_MORE_ITEMS, "expected no more items: %d\n", r );
3782 MsiViewClose(hview);
3783 MsiCloseHandle(hview);
3785 query = "SELECT * FROM `Four`, `Five`";
3786 r = MsiDatabaseOpenView(hdb, query, &hview);
3787 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3789 r = MsiViewExecute(hview, 0);
3790 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3792 r = MsiViewFetch(hview, &hrec);
3793 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
3795 MsiViewClose(hview);
3796 MsiCloseHandle(hview);
3798 query = "SELECT * FROM `Nonexistent`, `One`";
3799 r = MsiDatabaseOpenView(hdb, query, &hview);
3800 ok( r == ERROR_BAD_QUERY_SYNTAX,
3801 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r );
3803 /* try updating a row in a join table */
3804 query = "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3805 "FROM `Component`, `FeatureComponents` "
3806 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
3807 "ORDER BY `Feature_`";
3808 r = MsiDatabaseOpenView(hdb, query, &hview);
3809 ok( r == ERROR_SUCCESS, "failed to open view: %d\n", r );
3811 r = MsiViewExecute(hview, 0);
3812 ok( r == ERROR_SUCCESS, "failed to execute view: %d\n", r );
3814 r = MsiViewFetch(hview, &hrec);
3815 ok( r == ERROR_SUCCESS, "failed to fetch view: %d\n", r );
3817 r = MsiRecordSetString( hrec, 1, "epicranius" );
3818 ok( r == ERROR_SUCCESS, "failed to set string: %d\n", r );
3820 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
3821 ok( r == ERROR_SUCCESS, "failed to update row: %d\n", r );
3823 /* try another valid operation for joins */
3824 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
3825 todo_wine ok( r == ERROR_SUCCESS, "failed to refresh row: %d\n", r );
3827 /* try an invalid operation for joins */
3828 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
3829 ok( r == ERROR_FUNCTION_FAILED, "unexpected result: %d\n", r );
3831 r = MsiRecordSetString( hrec, 2, "epicranius" );
3832 ok( r == ERROR_SUCCESS, "failed to set string: %d\n", r );
3834 /* primary key cannot be updated */
3835 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
3836 todo_wine ok( r == ERROR_FUNCTION_FAILED, "failed to update row: %d\n", r );
3838 MsiCloseHandle(hrec);
3839 MsiViewClose(hview);
3840 MsiCloseHandle(hview);
3842 r = MsiDatabaseOpenView(hdb, query, &hview);
3843 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
3845 r = MsiViewExecute(hview, 0);
3846 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
3848 r = MsiViewFetch(hview, &hrec);
3849 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
3851 size = MAX_PATH;
3852 r = MsiRecordGetString( hrec, 1, buf, &size );
3853 ok( r == ERROR_SUCCESS, "failed to get record string: %d\n", r );
3854 ok( !lstrcmp( buf, "epicranius" ), "expected 'epicranius', got %s\n", buf );
3856 MsiCloseHandle(hrec);
3857 MsiViewClose(hview);
3858 MsiCloseHandle(hview);
3860 MsiCloseHandle(hdb);
3861 DeleteFile(msifile);
3864 static void test_temporary_table(void)
3866 MSICONDITION cond;
3867 MSIHANDLE hdb = 0, view = 0, rec;
3868 const char *query;
3869 UINT r;
3870 char buf[0x10];
3871 DWORD sz;
3873 cond = MsiDatabaseIsTablePersistent(0, NULL);
3874 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3876 hdb = create_db();
3877 ok( hdb, "failed to create db\n");
3879 cond = MsiDatabaseIsTablePersistent(hdb, NULL);
3880 ok( cond == MSICONDITION_ERROR, "wrong return condition\n");
3882 cond = MsiDatabaseIsTablePersistent(hdb, "_Tables");
3883 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3885 cond = MsiDatabaseIsTablePersistent(hdb, "_Columns");
3886 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3888 cond = MsiDatabaseIsTablePersistent(hdb, "_Storages");
3889 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3891 cond = MsiDatabaseIsTablePersistent(hdb, "_Streams");
3892 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3894 query = "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
3895 r = run_query(hdb, 0, query);
3896 ok(r == ERROR_SUCCESS, "failed to add table\n");
3898 cond = MsiDatabaseIsTablePersistent(hdb, "P");
3899 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3901 query = "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
3902 r = run_query(hdb, 0, query);
3903 ok(r == ERROR_SUCCESS, "failed to add table\n");
3905 cond = MsiDatabaseIsTablePersistent(hdb, "P2");
3906 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3908 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3909 r = run_query(hdb, 0, query);
3910 ok(r == ERROR_SUCCESS, "failed to add table\n");
3912 cond = MsiDatabaseIsTablePersistent(hdb, "T");
3913 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
3915 query = "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3916 r = run_query(hdb, 0, query);
3917 ok(r == ERROR_SUCCESS, "failed to add table\n");
3919 query = "SELECT * FROM `T2`";
3920 r = MsiDatabaseOpenView(hdb, query, &view);
3921 ok(r == ERROR_BAD_QUERY_SYNTAX,
3922 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
3924 cond = MsiDatabaseIsTablePersistent(hdb, "T2");
3925 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3927 query = "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
3928 r = run_query(hdb, 0, query);
3929 ok(r == ERROR_SUCCESS, "failed to add table\n");
3931 cond = MsiDatabaseIsTablePersistent(hdb, "T3");
3932 ok( cond == MSICONDITION_TRUE, "wrong return condition\n");
3934 query = "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3935 r = run_query(hdb, 0, query);
3936 ok(r == ERROR_FUNCTION_FAILED, "failed to add table\n");
3938 cond = MsiDatabaseIsTablePersistent(hdb, "T4");
3939 ok( cond == MSICONDITION_NONE, "wrong return condition\n");
3941 query = "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
3942 r = run_query(hdb, 0, query);
3943 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to add table\n");
3945 query = "select * from `T`";
3946 r = MsiDatabaseOpenView(hdb, query, &view);
3947 ok(r == ERROR_SUCCESS, "failed to query table\n");
3948 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
3949 ok(r == ERROR_SUCCESS, "failed to get column info\n");
3951 sz = sizeof buf;
3952 r = MsiRecordGetString(rec, 1, buf, &sz);
3953 ok(r == ERROR_SUCCESS, "failed to get string\n");
3954 ok( 0 == strcmp("G255", buf), "wrong column type\n");
3956 sz = sizeof buf;
3957 r = MsiRecordGetString(rec, 2, buf, &sz);
3958 ok(r == ERROR_SUCCESS, "failed to get string\n");
3959 ok( 0 == strcmp("j2", buf), "wrong column type\n");
3961 MsiCloseHandle( rec );
3962 MsiViewClose( view );
3963 MsiCloseHandle( view );
3965 /* query the table data */
3966 rec = 0;
3967 r = do_query(hdb, "select * from `_Tables` where `Name` = 'T'", &rec);
3968 ok( r == ERROR_SUCCESS, "temporary table exists in _Tables\n");
3969 MsiCloseHandle( rec );
3971 /* query the column data */
3972 rec = 0;
3973 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec);
3974 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3975 if (rec) MsiCloseHandle( rec );
3977 r = do_query(hdb, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec);
3978 ok( r == ERROR_NO_MORE_ITEMS, "temporary table exists in _Columns\n");
3979 if (rec) MsiCloseHandle( rec );
3981 MsiCloseHandle( hdb );
3983 DeleteFile(msifile);
3986 static void test_alter(void)
3988 MSICONDITION cond;
3989 MSIHANDLE hdb = 0;
3990 const char *query;
3991 UINT r;
3993 hdb = create_db();
3994 ok( hdb, "failed to create db\n");
3996 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3997 r = run_query(hdb, 0, query);
3998 ok(r == ERROR_SUCCESS, "failed to add table\n");
4000 cond = MsiDatabaseIsTablePersistent(hdb, "T");
4001 ok( cond == MSICONDITION_FALSE, "wrong return condition\n");
4003 query = "ALTER TABLE `T` HOLD";
4004 r = run_query(hdb, 0, query);
4005 ok(r == ERROR_SUCCESS, "failed to hold table %d\n", r);
4007 query = "ALTER TABLE `T` FREE";
4008 r = run_query(hdb, 0, query);
4009 ok(r == ERROR_SUCCESS, "failed to free table\n");
4011 query = "ALTER TABLE `T` FREE";
4012 r = run_query(hdb, 0, query);
4013 ok(r == ERROR_SUCCESS, "failed to free table\n");
4015 query = "ALTER TABLE `T` FREE";
4016 r = run_query(hdb, 0, query);
4017 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to free table\n");
4019 query = "ALTER TABLE `T` HOLD";
4020 r = run_query(hdb, 0, query);
4021 ok(r == ERROR_BAD_QUERY_SYNTAX, "failed to hold table %d\n", r);
4023 /* table T is removed */
4024 query = "SELECT * FROM `T`";
4025 r = run_query(hdb, 0, query);
4026 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4028 /* create the table again */
4029 query = "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
4030 r = run_query(hdb, 0, query);
4031 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4033 /* up the ref count */
4034 query = "ALTER TABLE `U` HOLD";
4035 r = run_query(hdb, 0, query);
4036 ok(r == ERROR_SUCCESS, "failed to free table\n");
4038 /* add column, no data type */
4039 query = "ALTER TABLE `U` ADD `C`";
4040 r = run_query(hdb, 0, query);
4041 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4043 query = "ALTER TABLE `U` ADD `C` INTEGER";
4044 r = run_query(hdb, 0, query);
4045 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4047 /* add column C again */
4048 query = "ALTER TABLE `U` ADD `C` INTEGER";
4049 r = run_query(hdb, 0, query);
4050 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4052 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
4053 r = run_query(hdb, 0, query);
4054 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4056 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
4057 r = run_query(hdb, 0, query);
4058 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4060 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
4061 r = run_query(hdb, 0, query);
4062 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4064 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
4065 r = run_query(hdb, 0, query);
4066 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4068 query = "SELECT * FROM `U` WHERE `D` = 8";
4069 r = run_query(hdb, 0, query);
4070 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4072 query = "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
4073 r = run_query(hdb, 0, query);
4074 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4076 query = "ALTER COLUMN `D` FREE";
4077 r = run_query(hdb, 0, query);
4078 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4080 /* drop the ref count */
4081 query = "ALTER TABLE `U` FREE";
4082 r = run_query(hdb, 0, query);
4083 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4085 /* table is not empty */
4086 query = "SELECT * FROM `U`";
4087 r = run_query(hdb, 0, query);
4088 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4090 /* column D is removed */
4091 query = "SELECT * FROM `U` WHERE `D` = 8";
4092 r = run_query(hdb, 0, query);
4093 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4095 query = "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
4096 r = run_query(hdb, 0, query);
4097 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4099 /* add the column again */
4100 query = "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
4101 r = run_query(hdb, 0, query);
4102 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4104 /* up the ref count */
4105 query = "ALTER TABLE `U` HOLD";
4106 r = run_query(hdb, 0, query);
4107 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4109 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
4110 r = run_query(hdb, 0, query);
4111 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4113 query = "SELECT * FROM `U` WHERE `E` = 16";
4114 r = run_query(hdb, 0, query);
4115 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4117 /* drop the ref count */
4118 query = "ALTER TABLE `U` FREE";
4119 r = run_query(hdb, 0, query);
4120 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4122 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
4123 r = run_query(hdb, 0, query);
4124 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4126 query = "SELECT * FROM `U` WHERE `E` = 20";
4127 r = run_query(hdb, 0, query);
4128 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4130 /* drop the ref count */
4131 query = "ALTER TABLE `U` FREE";
4132 r = run_query(hdb, 0, query);
4133 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4135 /* table still exists */
4136 query = "SELECT * FROM `U`";
4137 r = run_query(hdb, 0, query);
4138 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4140 /* col E is removed */
4141 query = "SELECT * FROM `U` WHERE `E` = 20";
4142 r = run_query(hdb, 0, query);
4143 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4145 query = "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
4146 r = run_query(hdb, 0, query);
4147 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4149 /* drop the ref count once more */
4150 query = "ALTER TABLE `U` FREE";
4151 r = run_query(hdb, 0, query);
4152 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4154 /* table still exists */
4155 query = "SELECT * FROM `U`";
4156 r = run_query(hdb, 0, query);
4157 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4159 MsiCloseHandle( hdb );
4160 DeleteFile(msifile);
4163 static void test_integers(void)
4165 MSIHANDLE hdb = 0, view = 0, rec = 0;
4166 DWORD count, i;
4167 const char *query;
4168 UINT r;
4170 /* just MsiOpenDatabase should not create a file */
4171 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4172 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4174 /* create a table */
4175 query = "CREATE TABLE `integers` ( "
4176 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
4177 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
4178 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
4179 "PRIMARY KEY `one`)";
4180 r = MsiDatabaseOpenView(hdb, query, &view);
4181 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4182 r = MsiViewExecute(view, 0);
4183 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4184 r = MsiViewClose(view);
4185 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4186 r = MsiCloseHandle(view);
4187 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4189 query = "SELECT * FROM `integers`";
4190 r = MsiDatabaseOpenView(hdb, query, &view);
4191 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4193 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
4194 count = MsiRecordGetFieldCount(rec);
4195 ok(count == 8, "Expected 8, got %d\n", count);
4196 ok(check_record(rec, 1, "one"), "Expected one\n");
4197 ok(check_record(rec, 2, "two"), "Expected two\n");
4198 ok(check_record(rec, 3, "three"), "Expected three\n");
4199 ok(check_record(rec, 4, "four"), "Expected four\n");
4200 ok(check_record(rec, 5, "five"), "Expected five\n");
4201 ok(check_record(rec, 6, "six"), "Expected six\n");
4202 ok(check_record(rec, 7, "seven"), "Expected seven\n");
4203 ok(check_record(rec, 8, "eight"), "Expected eight\n");
4204 MsiCloseHandle(rec);
4206 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
4207 count = MsiRecordGetFieldCount(rec);
4208 ok(count == 8, "Expected 8, got %d\n", count);
4209 ok(check_record(rec, 1, "I2"), "Expected I2\n");
4210 ok(check_record(rec, 2, "I2"), "Expected I2\n");
4211 ok(check_record(rec, 3, "I2"), "Expected I2\n");
4212 ok(check_record(rec, 4, "I4"), "Expected I4\n");
4213 ok(check_record(rec, 5, "i2"), "Expected i2\n");
4214 ok(check_record(rec, 6, "i2"), "Expected i2\n");
4215 ok(check_record(rec, 7, "i2"), "Expected i2\n");
4216 ok(check_record(rec, 8, "i4"), "Expected i4\n");
4217 MsiCloseHandle(rec);
4219 MsiViewClose(view);
4220 MsiCloseHandle(view);
4222 /* insert values into it, NULL where NOT NULL is specified */
4223 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
4224 "VALUES('', '', '', '', '', '', '', '')";
4225 r = MsiDatabaseOpenView(hdb, query, &view);
4226 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4227 r = MsiViewExecute(view, 0);
4228 ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
4230 MsiViewClose(view);
4231 MsiCloseHandle(view);
4233 query = "SELECT * FROM `integers`";
4234 r = do_query(hdb, query, &rec);
4235 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4237 r = MsiRecordGetFieldCount(rec);
4238 ok(r == -1, "record count wrong: %d\n", r);
4240 MsiCloseHandle(rec);
4242 /* insert legitimate values into it */
4243 query = "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
4244 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
4245 r = MsiDatabaseOpenView(hdb, query, &view);
4246 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4247 r = MsiViewExecute(view, 0);
4248 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4250 query = "SELECT * FROM `integers`";
4251 r = do_query(hdb, query, &rec);
4252 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4254 r = MsiRecordGetFieldCount(rec);
4255 ok(r == 8, "record count wrong: %d\n", r);
4257 i = MsiRecordGetInteger(rec, 1);
4258 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
4259 i = MsiRecordGetInteger(rec, 3);
4260 ok(i == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", i);
4261 i = MsiRecordGetInteger(rec, 2);
4262 ok(i == 2, "Expected 2, got %d\n", i);
4263 i = MsiRecordGetInteger(rec, 4);
4264 ok(i == 4, "Expected 4, got %d\n", i);
4265 i = MsiRecordGetInteger(rec, 5);
4266 ok(i == 5, "Expected 5, got %d\n", i);
4267 i = MsiRecordGetInteger(rec, 6);
4268 ok(i == 6, "Expected 6, got %d\n", i);
4269 i = MsiRecordGetInteger(rec, 7);
4270 ok(i == 7, "Expected 7, got %d\n", i);
4271 i = MsiRecordGetInteger(rec, 8);
4272 ok(i == 8, "Expected 8, got %d\n", i);
4274 MsiCloseHandle(rec);
4275 MsiViewClose(view);
4276 MsiCloseHandle(view);
4278 r = MsiDatabaseCommit(hdb);
4279 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
4281 r = MsiCloseHandle(hdb);
4282 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4284 r = DeleteFile(msifile);
4285 ok(r == TRUE, "file didn't exist after commit\n");
4288 static void test_update(void)
4290 MSIHANDLE hdb = 0, view = 0, rec = 0;
4291 CHAR result[MAX_PATH];
4292 const char *query;
4293 DWORD size;
4294 UINT r;
4296 /* just MsiOpenDatabase should not create a file */
4297 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4298 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4300 /* create the Control table */
4301 query = "CREATE TABLE `Control` ( "
4302 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
4303 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
4304 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
4305 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
4306 r = MsiDatabaseOpenView(hdb, query, &view);
4307 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4308 r = MsiViewExecute(view, 0);
4309 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4310 r = MsiViewClose(view);
4311 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4312 r = MsiCloseHandle(view);
4313 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4315 /* add a control */
4316 query = "INSERT INTO `Control` ( "
4317 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4318 "`Property`, `Text`, `Control_Next`, `Help` )"
4319 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
4320 r = MsiDatabaseOpenView(hdb, query, &view);
4321 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4322 r = MsiViewExecute(view, 0);
4323 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4324 r = MsiViewClose(view);
4325 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4326 r = MsiCloseHandle(view);
4327 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4329 /* add a second control */
4330 query = "INSERT INTO `Control` ( "
4331 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4332 "`Property`, `Text`, `Control_Next`, `Help` )"
4333 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
4334 r = MsiDatabaseOpenView(hdb, query, &view);
4335 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4336 r = MsiViewExecute(view, 0);
4337 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4338 r = MsiViewClose(view);
4339 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4340 r = MsiCloseHandle(view);
4341 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4343 /* add a third control */
4344 query = "INSERT INTO `Control` ( "
4345 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4346 "`Property`, `Text`, `Control_Next`, `Help` )"
4347 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
4348 r = MsiDatabaseOpenView(hdb, query, &view);
4349 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4350 r = MsiViewExecute(view, 0);
4351 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4352 r = MsiViewClose(view);
4353 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4354 r = MsiCloseHandle(view);
4355 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4357 /* bad table */
4358 query = "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4359 r = MsiDatabaseOpenView(hdb, query, &view);
4360 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4362 /* bad set column */
4363 query = "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4364 r = MsiDatabaseOpenView(hdb, query, &view);
4365 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4367 /* bad where condition */
4368 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
4369 r = MsiDatabaseOpenView(hdb, query, &view);
4370 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
4372 /* just the dialog_ specified */
4373 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4374 r = MsiDatabaseOpenView(hdb, query, &view);
4375 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4376 r = MsiViewExecute(view, 0);
4377 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4378 r = MsiViewClose(view);
4379 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4380 r = MsiCloseHandle(view);
4381 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4383 /* check the modified text */
4384 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
4385 r = MsiDatabaseOpenView(hdb, query, &view);
4386 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4387 r = MsiViewExecute(view, 0);
4388 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4390 r = MsiViewFetch(view, &rec);
4391 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4393 size = MAX_PATH;
4394 r = MsiRecordGetString(rec, 1, result, &size);
4395 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4396 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4398 MsiCloseHandle(rec);
4400 r = MsiViewFetch(view, &rec);
4401 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4403 size = MAX_PATH;
4404 r = MsiRecordGetString(rec, 1, result, &size);
4405 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4406 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
4408 MsiCloseHandle(rec);
4410 r = MsiViewFetch(view, &rec);
4411 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4413 r = MsiViewClose(view);
4414 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4415 r = MsiCloseHandle(view);
4416 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4418 /* dialog_ and control specified */
4419 query = "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
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 /* check the modified text */
4430 query = "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
4431 r = MsiDatabaseOpenView(hdb, query, &view);
4432 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4433 r = MsiViewExecute(view, 0);
4434 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4436 r = MsiViewFetch(view, &rec);
4437 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4439 size = MAX_PATH;
4440 r = MsiRecordGetString(rec, 1, result, &size);
4441 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4442 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4444 MsiCloseHandle(rec);
4446 r = MsiViewFetch(view, &rec);
4447 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4449 size = MAX_PATH;
4450 r = MsiRecordGetString(rec, 1, result, &size);
4451 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4452 ok(!lstrlen(result), "Expected an empty string, got %s\n", result);
4454 MsiCloseHandle(rec);
4456 r = MsiViewFetch(view, &rec);
4457 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4459 r = MsiViewClose(view);
4460 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4461 r = MsiCloseHandle(view);
4462 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4464 /* no where condition */
4465 query = "UPDATE `Control` SET `Text` = 'this is text'";
4466 r = MsiDatabaseOpenView(hdb, query, &view);
4467 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4468 r = MsiViewExecute(view, 0);
4469 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4470 r = MsiViewClose(view);
4471 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4472 r = MsiCloseHandle(view);
4473 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4475 /* check the modified text */
4476 query = "SELECT `Text` FROM `Control`";
4477 r = MsiDatabaseOpenView(hdb, query, &view);
4478 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4479 r = MsiViewExecute(view, 0);
4480 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4482 r = MsiViewFetch(view, &rec);
4483 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4485 size = MAX_PATH;
4486 r = MsiRecordGetString(rec, 1, result, &size);
4487 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4488 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4490 MsiCloseHandle(rec);
4492 r = MsiViewFetch(view, &rec);
4493 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4495 size = MAX_PATH;
4496 r = MsiRecordGetString(rec, 1, result, &size);
4497 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4498 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4500 MsiCloseHandle(rec);
4502 r = MsiViewFetch(view, &rec);
4503 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4505 size = MAX_PATH;
4506 r = MsiRecordGetString(rec, 1, result, &size);
4507 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4508 ok(!lstrcmp(result, "this is text"), "Expected `this is text`, got %s\n", result);
4510 MsiCloseHandle(rec);
4512 r = MsiViewFetch(view, &rec);
4513 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
4515 r = MsiViewClose(view);
4516 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4517 r = MsiCloseHandle(view);
4518 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4520 query = "CREATE TABLE `Apple` ( `Banana` CHAR(72) NOT NULL, "
4521 "`Orange` CHAR(72), `Pear` INT PRIMARY KEY `Banana`)";
4522 r = run_query(hdb, 0, query);
4523 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4525 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4526 "VALUES('one', 'two', 3)";
4527 r = run_query(hdb, 0, query);
4528 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4530 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4531 "VALUES('three', 'four', 5)";
4532 r = run_query(hdb, 0, query);
4533 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4535 query = "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4536 "VALUES('six', 'two', 7)";
4537 r = run_query(hdb, 0, query);
4538 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4540 rec = MsiCreateRecord(2);
4541 MsiRecordSetInteger(rec, 1, 8);
4542 MsiRecordSetString(rec, 2, "two");
4544 query = "UPDATE `Apple` SET `Pear` = ? WHERE `Orange` = ?";
4545 r = run_query(hdb, rec, query);
4546 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4548 MsiCloseHandle(rec);
4550 query = "SELECT `Pear` FROM `Apple` ORDER BY `Orange`";
4551 r = MsiDatabaseOpenView(hdb, query, &view);
4552 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4553 r = MsiViewExecute(view, 0);
4554 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4556 r = MsiViewFetch(view, &rec);
4557 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4559 r = MsiRecordGetInteger(rec, 1);
4560 ok(r == 8, "Expected 8, got %d\n", r);
4562 MsiCloseHandle(rec);
4564 r = MsiViewFetch(view, &rec);
4565 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4567 r = MsiRecordGetInteger(rec, 1);
4568 ok(r == 8, "Expected 8, got %d\n", r);
4570 MsiCloseHandle(rec);
4572 r = MsiViewFetch(view, &rec);
4573 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4575 r = MsiRecordGetInteger(rec, 1);
4576 ok(r == 5, "Expected 5, got %d\n", r);
4578 MsiCloseHandle(rec);
4580 r = MsiViewFetch(view, &rec);
4581 ok(r == ERROR_NO_MORE_ITEMS, "Expectd ERROR_NO_MORE_ITEMS, got %d\n", r);
4583 MsiViewClose(view);
4584 MsiCloseHandle(view);
4586 r = MsiDatabaseCommit(hdb);
4587 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
4588 r = MsiCloseHandle(hdb);
4589 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4591 DeleteFile(msifile);
4594 static void test_special_tables(void)
4596 const char *query;
4597 MSIHANDLE hdb = 0;
4598 UINT r;
4600 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4601 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4603 query = "CREATE TABLE `_Properties` ( "
4604 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4605 r = run_query(hdb, 0, query);
4606 ok(r == ERROR_SUCCESS, "failed to create table\n");
4608 query = "CREATE TABLE `_Storages` ( "
4609 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4610 r = run_query(hdb, 0, query);
4611 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Streams table\n");
4613 query = "CREATE TABLE `_Streams` ( "
4614 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4615 r = run_query(hdb, 0, query);
4616 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Streams table\n");
4618 query = "CREATE TABLE `_Tables` ( "
4619 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4620 r = run_query(hdb, 0, query);
4621 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Tables table\n");
4623 query = "CREATE TABLE `_Columns` ( "
4624 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4625 r = run_query(hdb, 0, query);
4626 ok(r == ERROR_BAD_QUERY_SYNTAX, "created _Columns table\n");
4628 r = MsiCloseHandle(hdb);
4629 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4632 static void test_tables_order(void)
4634 const char *query;
4635 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
4636 UINT r;
4637 char buffer[100];
4638 DWORD sz;
4640 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4641 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4643 query = "CREATE TABLE `foo` ( "
4644 "`baz` INT NOT NULL PRIMARY KEY `baz`)";
4645 r = run_query(hdb, 0, query);
4646 ok(r == ERROR_SUCCESS, "failed to create table\n");
4648 query = "CREATE TABLE `bar` ( "
4649 "`foo` INT NOT NULL PRIMARY KEY `foo`)";
4650 r = run_query(hdb, 0, query);
4651 ok(r == ERROR_SUCCESS, "failed to create table\n");
4653 query = "CREATE TABLE `baz` ( "
4654 "`bar` INT NOT NULL, "
4655 "`baz` INT NOT NULL, "
4656 "`foo` INT NOT NULL PRIMARY KEY `bar`)";
4657 r = run_query(hdb, 0, query);
4658 ok(r == ERROR_SUCCESS, "failed to create table\n");
4660 /* The names of the tables in the _Tables table must
4661 be in the same order as these names are created in
4662 the strings table. */
4663 query = "SELECT * FROM `_Tables`";
4664 r = MsiDatabaseOpenView(hdb, query, &hview);
4665 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4666 r = MsiViewExecute(hview, 0);
4667 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4669 r = MsiViewFetch(hview, &hrec);
4670 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4671 sz = sizeof(buffer);
4672 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4673 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4674 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4675 r = MsiCloseHandle(hrec);
4676 ok(r == ERROR_SUCCESS, "failed to close record\n");
4678 r = MsiViewFetch(hview, &hrec);
4679 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4680 sz = sizeof(buffer);
4681 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4682 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4683 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4684 r = MsiCloseHandle(hrec);
4685 ok(r == ERROR_SUCCESS, "failed to close record\n");
4687 r = MsiViewFetch(hview, &hrec);
4688 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4689 sz = sizeof(buffer);
4690 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4691 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4692 ok(!lstrcmp(buffer, "bar"), "Expected bar, got %s\n", buffer);
4693 r = MsiCloseHandle(hrec);
4694 ok(r == ERROR_SUCCESS, "failed to close record\n");
4696 r = MsiViewClose(hview);
4697 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4698 r = MsiCloseHandle(hview);
4699 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4701 /* The names of the tables in the _Columns table must
4702 be in the same order as these names are created in
4703 the strings table. */
4704 query = "SELECT * FROM `_Columns`";
4705 r = MsiDatabaseOpenView(hdb, query, &hview);
4706 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4707 r = MsiViewExecute(hview, 0);
4708 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4710 r = MsiViewFetch(hview, &hrec);
4711 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4712 sz = sizeof(buffer);
4713 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4714 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4715 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4716 sz = sizeof(buffer);
4717 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4718 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4719 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4720 r = MsiCloseHandle(hrec);
4721 ok(r == ERROR_SUCCESS, "failed to close record\n");
4723 r = MsiViewFetch(hview, &hrec);
4724 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4725 sz = sizeof(buffer);
4726 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4727 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4728 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4729 sz = sizeof(buffer);
4730 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4731 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4732 ok(!lstrcmp(buffer, "bar"), "Expected bar, got %s\n", buffer);
4733 r = MsiCloseHandle(hrec);
4734 ok(r == ERROR_SUCCESS, "failed to close record\n");
4736 r = MsiViewFetch(hview, &hrec);
4737 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4738 sz = sizeof(buffer);
4739 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4740 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4741 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4742 sz = sizeof(buffer);
4743 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4744 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4745 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4746 r = MsiCloseHandle(hrec);
4747 ok(r == ERROR_SUCCESS, "failed to close record\n");
4749 r = MsiViewFetch(hview, &hrec);
4750 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4751 sz = sizeof(buffer);
4752 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4753 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4754 ok(!lstrcmp(buffer, "baz"), "Expected baz, got %s\n", buffer);
4755 sz = sizeof(buffer);
4756 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4757 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4758 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4759 r = MsiCloseHandle(hrec);
4760 ok(r == ERROR_SUCCESS, "failed to close record\n");
4762 r = MsiViewFetch(hview, &hrec);
4763 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4764 sz = sizeof(buffer);
4765 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4766 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4767 ok(!lstrcmp(buffer, "bar"), "Expected bar, got %s\n", buffer);
4768 sz = sizeof(buffer);
4769 r = MsiRecordGetString(hrec, 3, buffer, &sz);
4770 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4771 ok(!lstrcmp(buffer, "foo"), "Expected foo, got %s\n", buffer);
4772 r = MsiCloseHandle(hrec);
4773 ok(r == ERROR_SUCCESS, "failed to close record\n");
4775 r = MsiViewClose(hview);
4776 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4777 r = MsiCloseHandle(hview);
4778 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4780 r = MsiCloseHandle(hdb);
4781 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4783 DeleteFile(msifile);
4786 static void test_rows_order(void)
4788 const char *query;
4789 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
4790 UINT r;
4791 char buffer[100];
4792 DWORD sz;
4794 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
4795 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
4797 query = "CREATE TABLE `foo` ( "
4798 "`bar` LONGCHAR NOT NULL PRIMARY KEY `bar`)";
4799 r = run_query(hdb, 0, query);
4800 ok(r == ERROR_SUCCESS, "failed to create table\n");
4802 r = run_query(hdb, 0, "INSERT INTO `foo` "
4803 "( `bar` ) VALUES ( 'A' )");
4804 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4806 r = run_query(hdb, 0, "INSERT INTO `foo` "
4807 "( `bar` ) VALUES ( 'B' )");
4808 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4810 r = run_query(hdb, 0, "INSERT INTO `foo` "
4811 "( `bar` ) VALUES ( 'C' )");
4812 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4814 r = run_query(hdb, 0, "INSERT INTO `foo` "
4815 "( `bar` ) VALUES ( 'D' )");
4816 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4818 r = run_query(hdb, 0, "INSERT INTO `foo` "
4819 "( `bar` ) VALUES ( 'E' )");
4820 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4822 r = run_query(hdb, 0, "INSERT INTO `foo` "
4823 "( `bar` ) VALUES ( 'F' )");
4824 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4826 query = "CREATE TABLE `bar` ( "
4827 "`foo` LONGCHAR NOT NULL, "
4828 "`baz` LONGCHAR NOT NULL "
4829 "PRIMARY KEY `foo` )";
4830 r = run_query(hdb, 0, query);
4831 ok(r == ERROR_SUCCESS, "failed to create table\n");
4833 r = run_query(hdb, 0, "INSERT INTO `bar` "
4834 "( `foo`, `baz` ) VALUES ( 'C', 'E' )");
4835 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4837 r = run_query(hdb, 0, "INSERT INTO `bar` "
4838 "( `foo`, `baz` ) VALUES ( 'F', 'A' )");
4839 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4841 r = run_query(hdb, 0, "INSERT INTO `bar` "
4842 "( `foo`, `baz` ) VALUES ( 'A', 'B' )");
4843 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4845 r = run_query(hdb, 0, "INSERT INTO `bar` "
4846 "( `foo`, `baz` ) VALUES ( 'D', 'E' )");
4847 ok(r == ERROR_SUCCESS, "cannot add value to table\n");
4849 /* The rows of the table must be ordered by the column values of
4850 each row. For strings, the column value is the string id
4851 in the string table. */
4853 query = "SELECT * FROM `bar`";
4854 r = MsiDatabaseOpenView(hdb, query, &hview);
4855 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
4856 r = MsiViewExecute(hview, 0);
4857 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
4859 r = MsiViewFetch(hview, &hrec);
4860 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4861 sz = sizeof(buffer);
4862 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4863 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4864 ok(!lstrcmp(buffer, "A"), "Expected A, got %s\n", buffer);
4865 sz = sizeof(buffer);
4866 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4867 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4868 ok(!lstrcmp(buffer, "B"), "Expected B, got %s\n", buffer);
4869 r = MsiCloseHandle(hrec);
4870 ok(r == ERROR_SUCCESS, "failed to close record\n");
4872 r = MsiViewFetch(hview, &hrec);
4873 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4874 sz = sizeof(buffer);
4875 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4876 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4877 ok(!lstrcmp(buffer, "C"), "Expected E, got %s\n", buffer);
4878 sz = sizeof(buffer);
4879 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4880 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4881 ok(!lstrcmp(buffer, "E"), "Expected E, got %s\n", buffer);
4882 r = MsiCloseHandle(hrec);
4883 ok(r == ERROR_SUCCESS, "failed to close record\n");
4885 r = MsiViewFetch(hview, &hrec);
4886 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4887 sz = sizeof(buffer);
4888 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4889 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4890 ok(!lstrcmp(buffer, "D"), "Expected D, got %s\n", buffer);
4891 sz = sizeof(buffer);
4892 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4893 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4894 ok(!lstrcmp(buffer, "E"), "Expected E, got %s\n", buffer);
4895 r = MsiCloseHandle(hrec);
4896 ok(r == ERROR_SUCCESS, "failed to close record\n");
4898 r = MsiViewFetch(hview, &hrec);
4899 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
4900 sz = sizeof(buffer);
4901 r = MsiRecordGetString(hrec, 1, buffer, &sz);
4902 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4903 ok(!lstrcmp(buffer, "F"), "Expected F, got %s\n", buffer);
4904 sz = sizeof(buffer);
4905 r = MsiRecordGetString(hrec, 2, buffer, &sz);
4906 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4907 ok(!lstrcmp(buffer, "A"), "Expected A, got %s\n", buffer);
4908 r = MsiCloseHandle(hrec);
4909 ok(r == ERROR_SUCCESS, "failed to close record\n");
4911 r = MsiViewClose(hview);
4912 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
4913 r = MsiCloseHandle(hview);
4914 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4916 r = MsiCloseHandle(hdb);
4917 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
4919 DeleteFile(msifile);
4922 static void test_select_markers(void)
4924 MSIHANDLE hdb = 0, rec, view, res;
4925 LPCSTR query;
4926 UINT r;
4927 DWORD size;
4928 CHAR buf[MAX_PATH];
4930 hdb = create_db();
4931 ok( hdb, "failed to create db\n");
4933 r = run_query(hdb, 0,
4934 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
4935 ok(r == S_OK, "cannot create table: %d\n", r);
4937 r = run_query(hdb, 0, "INSERT INTO `Table` "
4938 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
4939 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4941 r = run_query(hdb, 0, "INSERT INTO `Table` "
4942 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
4943 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4945 r = run_query(hdb, 0, "INSERT INTO `Table` "
4946 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
4947 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4949 r = run_query(hdb, 0, "INSERT INTO `Table` "
4950 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
4951 ok(r == S_OK, "cannot add file to the Media table: %d\n", r);
4953 rec = MsiCreateRecord(2);
4954 MsiRecordSetString(rec, 1, "apple");
4955 MsiRecordSetString(rec, 2, "two");
4957 query = "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
4958 r = MsiDatabaseOpenView(hdb, query, &view);
4959 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4961 r = MsiViewExecute(view, rec);
4962 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4964 r = MsiViewFetch(view, &res);
4965 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4967 size = MAX_PATH;
4968 r = MsiRecordGetString(res, 1, buf, &size);
4969 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4970 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
4972 size = MAX_PATH;
4973 r = MsiRecordGetString(res, 2, buf, &size);
4974 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4975 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
4977 r = MsiRecordGetInteger(res, 3);
4978 ok(r == 1, "Expected 1, got %d\n", r);
4980 MsiCloseHandle(res);
4982 r = MsiViewFetch(view, &res);
4983 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4985 size = MAX_PATH;
4986 r = MsiRecordGetString(res, 1, buf, &size);
4987 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4988 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
4990 size = MAX_PATH;
4991 r = MsiRecordGetString(res, 2, buf, &size);
4992 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
4993 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
4995 r = MsiRecordGetInteger(res, 3);
4996 ok(r == 2, "Expected 2, got %d\n", r);
4998 MsiCloseHandle(res);
5000 r = MsiViewFetch(view, &res);
5001 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5003 MsiCloseHandle(rec);
5004 MsiViewClose(view);
5005 MsiCloseHandle(view);
5007 rec = MsiCreateRecord(2);
5008 MsiRecordSetString(rec, 1, "one");
5009 MsiRecordSetInteger(rec, 2, 1);
5011 query = "SELECT * FROM `Table` WHERE `Two`<>? AND `Three`>? ORDER BY `Three`";
5012 r = MsiDatabaseOpenView(hdb, query, &view);
5013 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5014 r = MsiViewExecute(view, rec);
5015 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5017 r = MsiViewFetch(view, &res);
5018 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5020 size = MAX_PATH;
5021 r = MsiRecordGetString(res, 1, buf, &size);
5022 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5023 ok(!lstrcmp(buf, "apple"), "Expected apple, got %s\n", buf);
5025 size = MAX_PATH;
5026 r = MsiRecordGetString(res, 2, buf, &size);
5027 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5028 ok(!lstrcmp(buf, "two"), "Expected two, got %s\n", buf);
5030 r = MsiRecordGetInteger(res, 3);
5031 ok(r == 2, "Expected 2, got %d\n", r);
5033 MsiCloseHandle(res);
5035 r = MsiViewFetch(view, &res);
5036 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5038 size = MAX_PATH;
5039 r = MsiRecordGetString(res, 1, buf, &size);
5040 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5041 ok(!lstrcmp(buf, "banana"), "Expected banana, got %s\n", buf);
5043 size = MAX_PATH;
5044 r = MsiRecordGetString(res, 2, buf, &size);
5045 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5046 ok(!lstrcmp(buf, "three"), "Expected three, got %s\n", buf);
5048 r = MsiRecordGetInteger(res, 3);
5049 ok(r == 3, "Expected 3, got %d\n", r);
5051 MsiCloseHandle(res);
5053 r = MsiViewFetch(view, &res);
5054 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5056 MsiCloseHandle(rec);
5057 MsiViewClose(view);
5058 MsiCloseHandle(view);
5059 MsiCloseHandle(hdb);
5060 DeleteFile(msifile);
5063 static void test_viewmodify_update(void)
5065 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5066 const char *query;
5067 UINT r;
5069 DeleteFile(msifile);
5071 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5072 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
5074 query = "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
5075 r = run_query( hdb, 0, query );
5076 ok(r == ERROR_SUCCESS, "query failed\n");
5078 query = "INSERT INTO `table` (`A`, `B`) VALUES (1, 2)";
5079 r = run_query( hdb, 0, query );
5080 ok(r == ERROR_SUCCESS, "query failed\n");
5082 query = "INSERT INTO `table` (`A`, `B`) VALUES (3, 4)";
5083 r = run_query( hdb, 0, query );
5084 ok(r == ERROR_SUCCESS, "query failed\n");
5086 query = "INSERT INTO `table` (`A`, `B`) VALUES (5, 6)";
5087 r = run_query( hdb, 0, query );
5088 ok(r == ERROR_SUCCESS, "query failed\n");
5090 query = "SELECT `B` FROM `table`";
5091 r = MsiDatabaseOpenView(hdb, query, &hview);
5092 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5093 r = MsiViewExecute(hview, 0);
5094 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5095 r = MsiViewFetch(hview, &hrec);
5096 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5098 r = MsiRecordSetInteger(hrec, 1, 0);
5099 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5101 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
5102 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5104 r = MsiCloseHandle(hrec);
5105 ok(r == ERROR_SUCCESS, "failed to close record\n");
5107 r = MsiViewClose(hview);
5108 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5109 r = MsiCloseHandle(hview);
5110 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5112 query = "SELECT * FROM `table`";
5113 r = MsiDatabaseOpenView(hdb, query, &hview);
5114 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5115 r = MsiViewExecute(hview, 0);
5116 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5117 r = MsiViewFetch(hview, &hrec);
5118 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5120 r = MsiRecordGetInteger(hrec, 1);
5121 ok(r == 1, "Expected 1, got %d\n", r);
5122 r = MsiRecordGetInteger(hrec, 2);
5123 ok(r == 0, "Expected 0, got %d\n", r);
5125 r = MsiCloseHandle(hrec);
5126 ok(r == ERROR_SUCCESS, "failed to close record\n");
5128 r = MsiViewFetch(hview, &hrec);
5129 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5131 r = MsiRecordGetInteger(hrec, 1);
5132 ok(r == 3, "Expected 3, got %d\n", r);
5133 r = MsiRecordGetInteger(hrec, 2);
5134 ok(r == 4, "Expected 4, got %d\n", r);
5136 r = MsiCloseHandle(hrec);
5137 ok(r == ERROR_SUCCESS, "failed to close record\n");
5139 r = MsiViewFetch(hview, &hrec);
5140 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5142 r = MsiRecordGetInteger(hrec, 1);
5143 ok(r == 5, "Expected 5, got %d\n", r);
5144 r = MsiRecordGetInteger(hrec, 2);
5145 ok(r == 6, "Expected 6, got %d\n", r);
5147 r = MsiCloseHandle(hrec);
5148 ok(r == ERROR_SUCCESS, "failed to close record\n");
5150 r = MsiViewFetch(hview, &hrec);
5151 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5153 r = MsiViewClose(hview);
5154 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5155 r = MsiCloseHandle(hview);
5156 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5158 /* loop through all elements */
5159 query = "SELECT `B` FROM `table`";
5160 r = MsiDatabaseOpenView(hdb, query, &hview);
5161 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5162 r = MsiViewExecute(hview, 0);
5163 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5165 while (TRUE)
5167 r = MsiViewFetch(hview, &hrec);
5168 if (r != ERROR_SUCCESS)
5169 break;
5171 r = MsiRecordSetInteger(hrec, 1, 0);
5172 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5174 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
5175 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5177 r = MsiCloseHandle(hrec);
5178 ok(r == ERROR_SUCCESS, "failed to close record\n");
5181 r = MsiViewClose(hview);
5182 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5183 r = MsiCloseHandle(hview);
5184 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5186 query = "SELECT * FROM `table`";
5187 r = MsiDatabaseOpenView(hdb, query, &hview);
5188 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5189 r = MsiViewExecute(hview, 0);
5190 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5191 r = MsiViewFetch(hview, &hrec);
5192 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5194 r = MsiRecordGetInteger(hrec, 1);
5195 ok(r == 1, "Expected 1, got %d\n", r);
5196 r = MsiRecordGetInteger(hrec, 2);
5197 ok(r == 0, "Expected 0, got %d\n", r);
5199 r = MsiCloseHandle(hrec);
5200 ok(r == ERROR_SUCCESS, "failed to close record\n");
5202 r = MsiViewFetch(hview, &hrec);
5203 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5205 r = MsiRecordGetInteger(hrec, 1);
5206 ok(r == 3, "Expected 3, got %d\n", r);
5207 r = MsiRecordGetInteger(hrec, 2);
5208 ok(r == 0, "Expected 0, got %d\n", r);
5210 r = MsiCloseHandle(hrec);
5211 ok(r == ERROR_SUCCESS, "failed to close record\n");
5213 r = MsiViewFetch(hview, &hrec);
5214 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5216 r = MsiRecordGetInteger(hrec, 1);
5217 ok(r == 5, "Expected 5, got %d\n", r);
5218 r = MsiRecordGetInteger(hrec, 2);
5219 ok(r == 0, "Expected 0, got %d\n", r);
5221 r = MsiCloseHandle(hrec);
5222 ok(r == ERROR_SUCCESS, "failed to close record\n");
5224 r = MsiViewFetch(hview, &hrec);
5225 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5227 r = MsiViewClose(hview);
5228 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5229 r = MsiCloseHandle(hview);
5230 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5232 r = MsiCloseHandle( hdb );
5233 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
5236 static void test_viewmodify_assign(void)
5238 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5239 const char *query;
5240 UINT r;
5242 /* setup database */
5243 DeleteFile(msifile);
5245 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5246 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
5248 query = "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
5249 r = run_query( hdb, 0, query );
5250 ok(r == ERROR_SUCCESS, "query failed\n");
5252 /* assign to view, new primary key */
5253 query = "SELECT * FROM `table`";
5254 r = MsiDatabaseOpenView(hdb, query, &hview);
5255 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5256 r = MsiViewExecute(hview, 0);
5257 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5259 hrec = MsiCreateRecord(2);
5260 ok(hrec != 0, "MsiCreateRecord failed\n");
5262 r = MsiRecordSetInteger(hrec, 1, 1);
5263 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5264 r = MsiRecordSetInteger(hrec, 2, 2);
5265 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5267 r = MsiViewModify(hview, MSIMODIFY_ASSIGN, hrec);
5268 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5270 r = MsiCloseHandle(hrec);
5271 ok(r == ERROR_SUCCESS, "failed to close record\n");
5273 r = MsiViewClose(hview);
5274 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5275 r = MsiCloseHandle(hview);
5276 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5278 query = "SELECT * FROM `table`";
5279 r = MsiDatabaseOpenView(hdb, query, &hview);
5280 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5281 r = MsiViewExecute(hview, 0);
5282 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5283 r = MsiViewFetch(hview, &hrec);
5284 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5286 r = MsiRecordGetInteger(hrec, 1);
5287 ok(r == 1, "Expected 1, got %d\n", r);
5288 r = MsiRecordGetInteger(hrec, 2);
5289 ok(r == 2, "Expected 2, got %d\n", r);
5291 r = MsiCloseHandle(hrec);
5292 ok(r == ERROR_SUCCESS, "failed to close record\n");
5294 r = MsiViewFetch(hview, &hrec);
5295 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5297 r = MsiViewClose(hview);
5298 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5299 r = MsiCloseHandle(hview);
5300 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5302 /* assign to view, primary key matches */
5303 query = "SELECT * FROM `table`";
5304 r = MsiDatabaseOpenView(hdb, query, &hview);
5305 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5306 r = MsiViewExecute(hview, 0);
5307 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5309 hrec = MsiCreateRecord(2);
5310 ok(hrec != 0, "MsiCreateRecord failed\n");
5312 r = MsiRecordSetInteger(hrec, 1, 1);
5313 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5314 r = MsiRecordSetInteger(hrec, 2, 4);
5315 ok(r == ERROR_SUCCESS, "failed to set integer\n");
5317 r = MsiViewModify(hview, MSIMODIFY_ASSIGN, hrec);
5318 ok(r == ERROR_SUCCESS, "MsiViewModify failed: %d\n", r);
5320 r = MsiCloseHandle(hrec);
5321 ok(r == ERROR_SUCCESS, "failed to close record\n");
5323 r = MsiViewClose(hview);
5324 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5325 r = MsiCloseHandle(hview);
5326 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5328 query = "SELECT * FROM `table`";
5329 r = MsiDatabaseOpenView(hdb, query, &hview);
5330 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
5331 r = MsiViewExecute(hview, 0);
5332 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
5333 r = MsiViewFetch(hview, &hrec);
5334 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
5336 r = MsiRecordGetInteger(hrec, 1);
5337 ok(r == 1, "Expected 1, got %d\n", r);
5338 r = MsiRecordGetInteger(hrec, 2);
5339 ok(r == 4, "Expected 4, got %d\n", r);
5341 r = MsiCloseHandle(hrec);
5342 ok(r == ERROR_SUCCESS, "failed to close record\n");
5344 r = MsiViewFetch(hview, &hrec);
5345 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5347 r = MsiViewClose(hview);
5348 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
5349 r = MsiCloseHandle(hview);
5350 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
5352 /* close database */
5353 r = MsiCloseHandle( hdb );
5354 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
5357 static const WCHAR data10[] = { /* MOO */
5358 0x8001, 0x000b,
5360 static const WCHAR data11[] = { /* AAR */
5361 0x8002, 0x8005,
5362 0x000c, 0x000f,
5364 static const char data12[] = /* _StringData */
5365 "MOOABAARCDonetwofourfive";
5366 static const WCHAR data13[] = { /* _StringPool */
5367 /* len, refs */
5368 0, 0, /* string 0 '' */
5369 0, 0, /* string 1 '' */
5370 0, 0, /* string 2 '' */
5371 0, 0, /* string 3 '' */
5372 0, 0, /* string 4 '' */
5373 3, 3, /* string 5 'MOO' */
5374 1, 1, /* string 6 'A' */
5375 1, 1, /* string 7 'B' */
5376 3, 3, /* string 8 'AAR' */
5377 1, 1, /* string 9 'C' */
5378 1, 1, /* string a 'D' */
5379 3, 1, /* string b 'one' */
5380 3, 1, /* string c 'two' */
5381 0, 0, /* string d '' */
5382 4, 1, /* string e 'four' */
5383 4, 1, /* string f 'five' */
5386 static void test_stringtable(void)
5388 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5389 IStorage *stg = NULL;
5390 IStream *stm;
5391 WCHAR name[0x20];
5392 HRESULT hr;
5393 const char *query;
5394 char buffer[MAX_PATH];
5395 WCHAR data[MAX_PATH];
5396 DWORD sz, read;
5397 UINT r;
5399 static const DWORD mode = STGM_DIRECT | STGM_READ | STGM_SHARE_DENY_WRITE;
5400 static const WCHAR stringdata[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0}; /* _StringData */
5401 static const WCHAR stringpool[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0}; /* _StringPool */
5402 static const WCHAR moo[] = {0x4840, 0x3e16, 0x4818, 0}; /* MOO */
5403 static const WCHAR aar[] = {0x4840, 0x3a8a, 0x481b, 0}; /* AAR */
5405 DeleteFile(msifile);
5407 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5408 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5410 query = "CREATE TABLE `MOO` (`A` INT, `B` CHAR(72) PRIMARY KEY `A`)";
5411 r = run_query(hdb, 0, query);
5412 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5414 query = "CREATE TABLE `AAR` (`C` INT, `D` CHAR(72) PRIMARY KEY `C`)";
5415 r = run_query(hdb, 0, query);
5416 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5418 /* insert persistent row */
5419 query = "INSERT INTO `MOO` (`A`, `B`) VALUES (1, 'one')";
5420 r = run_query(hdb, 0, query);
5421 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5423 /* insert persistent row */
5424 query = "INSERT INTO `AAR` (`C`, `D`) VALUES (2, 'two')";
5425 r = run_query(hdb, 0, query);
5426 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5428 /* open a view */
5429 query = "SELECT * FROM `MOO`";
5430 r = MsiDatabaseOpenView(hdb, query, &hview);
5431 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5432 r = MsiViewExecute(hview, 0);
5433 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5435 hrec = MsiCreateRecord(2);
5437 r = MsiRecordSetInteger(hrec, 1, 3);
5438 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5439 r = MsiRecordSetString(hrec, 2, "three");
5440 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5442 /* insert a nonpersistent row */
5443 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
5444 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5446 r = MsiCloseHandle(hrec);
5447 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5448 r = MsiViewClose(hview);
5449 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5450 r = MsiCloseHandle(hview);
5451 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5453 /* insert persistent row */
5454 query = "INSERT INTO `MOO` (`A`, `B`) VALUES (4, 'four')";
5455 r = run_query(hdb, 0, query);
5456 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5458 /* insert persistent row */
5459 query = "INSERT INTO `AAR` (`C`, `D`) VALUES (5, 'five')";
5460 r = run_query(hdb, 0, query);
5461 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5463 r = MsiDatabaseCommit(hdb);
5464 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5466 r = MsiCloseHandle(hdb);
5467 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5469 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
5470 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5472 query = "SELECT * FROM `MOO`";
5473 r = MsiDatabaseOpenView(hdb, query, &hview);
5474 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5476 r = MsiViewExecute(hview, 0);
5477 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5479 r = MsiViewFetch(hview, &hrec);
5480 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5482 r = MsiRecordGetFieldCount(hrec);
5483 ok(r == 2, "Expected 2, got %d\n", r);
5485 r = MsiRecordGetInteger(hrec, 1);
5486 ok(r == 1, "Expected 1, got %d\n", r);
5488 sz = sizeof(buffer);
5489 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5490 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5491 ok(!lstrcmp(buffer, "one"), "Expected one, got %s\n", buffer);
5493 r = MsiCloseHandle(hrec);
5494 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5496 r = MsiViewFetch(hview, &hrec);
5497 todo_wine
5499 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5502 r = MsiViewClose(hview);
5503 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5504 r = MsiCloseHandle(hview);
5505 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5506 r = MsiCloseHandle(hrec);
5507 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5509 query = "SELECT * FROM `AAR`";
5510 r = MsiDatabaseOpenView(hdb, query, &hview);
5511 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5513 r = MsiViewExecute(hview, 0);
5514 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5516 r = MsiViewFetch(hview, &hrec);
5517 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5519 r = MsiRecordGetFieldCount(hrec);
5520 ok(r == 2, "Expected 2, got %d\n", r);
5522 r = MsiRecordGetInteger(hrec, 1);
5523 ok(r == 2, "Expected 2, got %d\n", r);
5525 sz = sizeof(buffer);
5526 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5527 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5528 ok(!lstrcmp(buffer, "two"), "Expected two, got %s\n", buffer);
5530 r = MsiCloseHandle(hrec);
5531 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5533 r = MsiViewFetch(hview, &hrec);
5534 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5536 r = MsiRecordGetFieldCount(hrec);
5537 ok(r == 2, "Expected 2, got %d\n", r);
5539 r = MsiRecordGetInteger(hrec, 1);
5540 ok(r == 5, "Expected 5, got %d\n", r);
5542 sz = sizeof(buffer);
5543 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5544 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5545 ok(!lstrcmp(buffer, "five"), "Expected five, got %s\n", buffer);
5547 r = MsiCloseHandle(hrec);
5548 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5550 r = MsiViewFetch(hview, &hrec);
5551 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5553 r = MsiViewClose(hview);
5554 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5555 r = MsiCloseHandle(hview);
5556 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5557 r = MsiCloseHandle(hrec);
5558 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5559 r = MsiCloseHandle(hdb);
5560 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5562 MultiByteToWideChar(CP_ACP, 0, msifile, -1, name, 0x20);
5563 hr = StgOpenStorage(name, NULL, mode, NULL, 0, &stg);
5564 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5565 ok(stg != NULL, "Expected non-NULL storage\n");
5567 hr = IStorage_OpenStream(stg, moo, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5568 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5569 ok(stm != NULL, "Expected non-NULL stream\n");
5571 hr = IStream_Read(stm, data, MAX_PATH, &read);
5572 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5573 todo_wine
5575 ok(read == 4, "Expected 4, got %d\n", read);
5576 ok(!memcmp(data, data10, read), "Unexpected data\n");
5579 hr = IStream_Release(stm);
5580 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5582 hr = IStorage_OpenStream(stg, aar, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5583 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5584 ok(stm != NULL, "Expected non-NULL stream\n");
5586 hr = IStream_Read(stm, data, MAX_PATH, &read);
5587 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5588 ok(read == 8, "Expected 8, got %d\n", read);
5589 todo_wine
5591 ok(!memcmp(data, data11, read), "Unexpected data\n");
5594 hr = IStream_Release(stm);
5595 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5597 hr = IStorage_OpenStream(stg, stringdata, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5598 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5599 ok(stm != NULL, "Expected non-NULL stream\n");
5601 hr = IStream_Read(stm, buffer, MAX_PATH, &read);
5602 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5603 ok(read == 24, "Expected 24, got %d\n", read);
5604 ok(!memcmp(buffer, data12, read), "Unexpected data\n");
5606 hr = IStream_Release(stm);
5607 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5609 hr = IStorage_OpenStream(stg, stringpool, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5610 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5611 ok(stm != NULL, "Expected non-NULL stream\n");
5613 hr = IStream_Read(stm, data, MAX_PATH, &read);
5614 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5615 todo_wine
5617 ok(read == 64, "Expected 64, got %d\n", read);
5618 ok(!memcmp(data, data13, read), "Unexpected data\n");
5621 hr = IStream_Release(stm);
5622 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5624 hr = IStorage_Release(stg);
5625 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
5627 DeleteFileA(msifile);
5630 static void test_viewmodify_delete(void)
5632 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
5633 UINT r;
5634 const char *query;
5635 char buffer[0x100];
5636 DWORD sz;
5638 DeleteFile(msifile);
5640 /* just MsiOpenDatabase should not create a file */
5641 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5642 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5644 query = "CREATE TABLE `phone` ( "
5645 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
5646 "PRIMARY KEY `id`)";
5647 r = run_query(hdb, 0, query);
5648 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5650 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
5651 "VALUES('1', 'Alan', '5030581')";
5652 r = run_query(hdb, 0, query);
5653 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5655 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
5656 "VALUES('2', 'Barry', '928440')";
5657 r = run_query(hdb, 0, query);
5658 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5660 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
5661 "VALUES('3', 'Cindy', '2937550')";
5662 r = run_query(hdb, 0, query);
5663 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5665 query = "SELECT * FROM `phone` WHERE `id` <= 2";
5666 r = MsiDatabaseOpenView(hdb, query, &hview);
5667 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5668 r = MsiViewExecute(hview, 0);
5669 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5670 r = MsiViewFetch(hview, &hrec);
5671 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5673 /* delete 1 */
5674 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
5675 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5677 r = MsiCloseHandle(hrec);
5678 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5679 r = MsiViewFetch(hview, &hrec);
5680 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5682 /* delete 2 */
5683 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
5684 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5686 r = MsiCloseHandle(hrec);
5687 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5688 r = MsiViewClose(hview);
5689 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5690 r = MsiCloseHandle(hview);
5691 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5693 query = "SELECT * FROM `phone`";
5694 r = MsiDatabaseOpenView(hdb, query, &hview);
5695 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5696 r = MsiViewExecute(hview, 0);
5697 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5698 r = MsiViewFetch(hview, &hrec);
5699 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5701 r = MsiRecordGetInteger(hrec, 1);
5702 ok(r == 3, "Expected 3, got %d\n", r);
5704 sz = sizeof(buffer);
5705 r = MsiRecordGetString(hrec, 2, buffer, &sz);
5706 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5707 ok(!lstrcmp(buffer, "Cindy"), "Expected Cindy, got %s\n", buffer);
5709 sz = sizeof(buffer);
5710 r = MsiRecordGetString(hrec, 3, buffer, &sz);
5711 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5712 ok(!lstrcmp(buffer, "2937550"), "Expected 2937550, got %s\n", buffer);
5714 r = MsiCloseHandle(hrec);
5715 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5717 r = MsiViewFetch(hview, &hrec);
5718 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5720 r = MsiViewClose(hview);
5721 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5722 r = MsiCloseHandle(hview);
5723 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5724 r = MsiCloseHandle(hdb);
5725 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5728 static const WCHAR _Tables[] = {0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0};
5729 static const WCHAR _StringData[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0};
5730 static const WCHAR _StringPool[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0};
5732 static const WCHAR data14[] = { /* _StringPool */
5733 /* len, refs */
5734 0, 0, /* string 0 '' */
5737 static const struct {
5738 LPCWSTR name;
5739 const void *data;
5740 DWORD size;
5741 } database_table_data[] =
5743 {_Tables, NULL, 0},
5744 {_StringData, NULL, 0},
5745 {_StringPool, data14, sizeof data14},
5748 static void enum_stream_names(IStorage *stg)
5750 IEnumSTATSTG *stgenum = NULL;
5751 IStream *stm;
5752 HRESULT hr;
5753 STATSTG stat;
5754 ULONG n, count;
5755 BYTE data[MAX_PATH];
5756 BYTE check[MAX_PATH];
5757 DWORD sz;
5759 memset(check, 'a', MAX_PATH);
5761 hr = IStorage_EnumElements(stg, 0, NULL, 0, &stgenum);
5762 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
5764 n = 0;
5765 while(TRUE)
5767 count = 0;
5768 hr = IEnumSTATSTG_Next(stgenum, 1, &stat, &count);
5769 if(FAILED(hr) || !count)
5770 break;
5772 ok(!lstrcmpW(stat.pwcsName, database_table_data[n].name),
5773 "Expected table %d name to match\n", n);
5775 stm = NULL;
5776 hr = IStorage_OpenStream(stg, stat.pwcsName, NULL,
5777 STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
5778 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
5779 ok(stm != NULL, "Expected non-NULL stream\n");
5781 CoTaskMemFree(stat.pwcsName);
5783 sz = MAX_PATH;
5784 memset(data, 'a', MAX_PATH);
5785 hr = IStream_Read(stm, data, sz, &count);
5786 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
5788 ok(count == database_table_data[n].size,
5789 "Expected %d, got %d\n", database_table_data[n].size, count);
5791 if (!database_table_data[n].size)
5792 ok(!memcmp(data, check, MAX_PATH), "data should not be changed\n");
5793 else
5794 ok(!memcmp(data, database_table_data[n].data, database_table_data[n].size),
5795 "Expected table %d data to match\n", n);
5797 IStream_Release(stm);
5798 n++;
5801 ok(n == 3, "Expected 3, got %d\n", n);
5803 IEnumSTATSTG_Release(stgenum);
5806 static void test_defaultdatabase(void)
5808 UINT r;
5809 HRESULT hr;
5810 MSIHANDLE hdb;
5811 IStorage *stg = NULL;
5813 DeleteFile(msifile);
5815 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
5816 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5818 r = MsiDatabaseCommit(hdb);
5819 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5821 MsiCloseHandle(hdb);
5823 hr = StgOpenStorage(msifileW, NULL, STGM_READ | STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
5824 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
5825 ok(stg != NULL, "Expected non-NULL stg\n");
5827 enum_stream_names(stg);
5829 IStorage_Release(stg);
5830 DeleteFileA(msifile);
5833 static void test_order(void)
5835 MSIHANDLE hdb, hview, hrec;
5836 CHAR buffer[MAX_PATH];
5837 LPCSTR query;
5838 UINT r, sz;
5839 int val;
5841 hdb = create_db();
5842 ok(hdb, "failed to create db\n");
5844 query = "CREATE TABLE `Empty` ( `A` SHORT NOT NULL PRIMARY KEY `A`)";
5845 r = run_query(hdb, 0, query);
5846 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5848 query = "CREATE TABLE `Mesa` ( `A` SHORT NOT NULL, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
5849 r = run_query(hdb, 0, query);
5850 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5852 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 1, 2, 9 )";
5853 r = run_query(hdb, 0, query);
5854 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5856 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 3, 4, 7 )";
5857 r = run_query(hdb, 0, query);
5858 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5860 query = "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 5, 6, 8 )";
5861 r = run_query(hdb, 0, query);
5862 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5864 query = "CREATE TABLE `Sideboard` ( `D` SHORT NOT NULL, `E` SHORT, `F` SHORT PRIMARY KEY `D`)";
5865 r = run_query(hdb, 0, query);
5866 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5868 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 10, 11, 18 )";
5869 r = run_query(hdb, 0, query);
5870 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5872 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 12, 13, 16 )";
5873 r = run_query(hdb, 0, query);
5874 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5876 query = "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 14, 15, 17 )";
5877 r = run_query(hdb, 0, query);
5878 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5880 query = "SELECT `A`, `B` FROM `Mesa` ORDER BY `C`";
5881 r = MsiDatabaseOpenView(hdb, query, &hview);
5882 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5883 r = MsiViewExecute(hview, 0);
5884 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5886 r = MsiViewFetch(hview, &hrec);
5887 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5889 val = MsiRecordGetInteger(hrec, 1);
5890 ok(val == 3, "Expected 3, got %d\n", val);
5892 val = MsiRecordGetInteger(hrec, 2);
5893 ok(val == 4, "Expected 3, got %d\n", val);
5895 MsiCloseHandle(hrec);
5897 r = MsiViewFetch(hview, &hrec);
5898 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5900 val = MsiRecordGetInteger(hrec, 1);
5901 ok(val == 5, "Expected 5, got %d\n", val);
5903 val = MsiRecordGetInteger(hrec, 2);
5904 ok(val == 6, "Expected 6, got %d\n", val);
5906 MsiCloseHandle(hrec);
5908 r = MsiViewFetch(hview, &hrec);
5909 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5911 val = MsiRecordGetInteger(hrec, 1);
5912 ok(val == 1, "Expected 1, got %d\n", val);
5914 val = MsiRecordGetInteger(hrec, 2);
5915 ok(val == 2, "Expected 2, got %d\n", val);
5917 MsiCloseHandle(hrec);
5919 r = MsiViewFetch(hview, &hrec);
5920 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
5922 MsiViewClose(hview);
5923 MsiCloseHandle(hview);
5925 query = "SELECT `A`, `D` FROM `Mesa`, `Sideboard` ORDER BY `F`";
5926 r = MsiDatabaseOpenView(hdb, query, &hview);
5927 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5928 r = MsiViewExecute(hview, 0);
5929 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5931 r = MsiViewFetch(hview, &hrec);
5932 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5934 val = MsiRecordGetInteger(hrec, 1);
5935 ok(val == 1, "Expected 1, got %d\n", val);
5937 val = MsiRecordGetInteger(hrec, 2);
5938 ok(val == 12, "Expected 12, got %d\n", val);
5940 MsiCloseHandle(hrec);
5942 r = MsiViewFetch(hview, &hrec);
5943 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5945 val = MsiRecordGetInteger(hrec, 1);
5946 ok(val == 3, "Expected 3, got %d\n", val);
5948 val = MsiRecordGetInteger(hrec, 2);
5949 ok(val == 12, "Expected 12, got %d\n", val);
5951 MsiCloseHandle(hrec);
5953 r = MsiViewFetch(hview, &hrec);
5954 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5956 val = MsiRecordGetInteger(hrec, 1);
5957 ok(val == 5, "Expected 5, got %d\n", val);
5959 val = MsiRecordGetInteger(hrec, 2);
5960 ok(val == 12, "Expected 12, got %d\n", val);
5962 MsiCloseHandle(hrec);
5964 r = MsiViewFetch(hview, &hrec);
5965 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5967 val = MsiRecordGetInteger(hrec, 1);
5968 ok(val == 1, "Expected 1, got %d\n", val);
5970 val = MsiRecordGetInteger(hrec, 2);
5971 ok(val == 14, "Expected 14, got %d\n", val);
5973 MsiCloseHandle(hrec);
5975 r = MsiViewFetch(hview, &hrec);
5976 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5978 val = MsiRecordGetInteger(hrec, 1);
5979 ok(val == 3, "Expected 3, got %d\n", val);
5981 val = MsiRecordGetInteger(hrec, 2);
5982 ok(val == 14, "Expected 14, got %d\n", val);
5984 MsiCloseHandle(hrec);
5986 r = MsiViewFetch(hview, &hrec);
5987 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
5989 val = MsiRecordGetInteger(hrec, 1);
5990 ok(val == 5, "Expected 5, got %d\n", val);
5992 val = MsiRecordGetInteger(hrec, 2);
5993 ok(val == 14, "Expected 14, got %d\n", val);
5995 MsiCloseHandle(hrec);
5997 r = MsiViewFetch(hview, &hrec);
5998 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6000 val = MsiRecordGetInteger(hrec, 1);
6001 ok(val == 1, "Expected 1, got %d\n", val);
6003 val = MsiRecordGetInteger(hrec, 2);
6004 ok(val == 10, "Expected 10, got %d\n", val);
6006 MsiCloseHandle(hrec);
6008 r = MsiViewFetch(hview, &hrec);
6009 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6011 val = MsiRecordGetInteger(hrec, 1);
6012 ok(val == 3, "Expected 3, got %d\n", val);
6014 val = MsiRecordGetInteger(hrec, 2);
6015 ok(val == 10, "Expected 10, got %d\n", val);
6017 MsiCloseHandle(hrec);
6019 r = MsiViewFetch(hview, &hrec);
6020 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6022 val = MsiRecordGetInteger(hrec, 1);
6023 ok(val == 5, "Expected 5, got %d\n", val);
6025 val = MsiRecordGetInteger(hrec, 2);
6026 ok(val == 10, "Expected 10, got %d\n", val);
6028 MsiCloseHandle(hrec);
6030 r = MsiViewFetch(hview, &hrec);
6031 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6033 MsiViewClose(hview);
6034 MsiCloseHandle(hview);
6036 query = "SELECT * FROM `Empty` ORDER BY `A`";
6037 r = MsiDatabaseOpenView(hdb, query, &hview);
6038 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6039 r = MsiViewExecute(hview, 0);
6040 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6042 r = MsiViewFetch(hview, &hrec);
6043 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6045 MsiViewClose(hview);
6046 MsiCloseHandle(hview);
6048 query = "CREATE TABLE `Buffet` ( `One` CHAR(72), `Two` SHORT PRIMARY KEY `One`)";
6049 r = run_query(hdb, 0, query);
6050 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6052 query = "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'uno', 2)";
6053 r = run_query(hdb, 0, query);
6054 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6056 query = "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'dos', 3)";
6057 r = run_query(hdb, 0, query);
6058 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6060 query = "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'tres', 1)";
6061 r = run_query(hdb, 0, query);
6062 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6064 query = "SELECT * FROM `Buffet` WHERE `One` = 'dos' ORDER BY `Two`";
6065 r = MsiDatabaseOpenView(hdb, query, &hview);
6066 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6067 r = MsiViewExecute(hview, 0);
6068 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6070 r = MsiViewFetch(hview, &hrec);
6071 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6073 sz = sizeof(buffer);
6074 r = MsiRecordGetString(hrec, 1, buffer, &sz);
6075 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6076 ok(!lstrcmp(buffer, "dos"), "Expected \"dos\", got \"%s\"\n", buffer);
6078 r = MsiRecordGetInteger(hrec, 2);
6079 ok(r == 3, "Expected 3, got %d\n", r);
6081 MsiCloseHandle(hrec);
6083 r = MsiViewFetch(hview, &hrec);
6084 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6086 MsiViewClose(hview);
6087 MsiCloseHandle(hview);
6088 MsiCloseHandle(hdb);
6091 static void test_viewmodify_delete_temporary(void)
6093 MSIHANDLE hdb, hview, hrec;
6094 const char *query;
6095 UINT r;
6097 DeleteFile(msifile);
6099 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6100 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6102 query = "CREATE TABLE `Table` ( `A` SHORT PRIMARY KEY `A` )";
6103 r = run_query(hdb, 0, query);
6104 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6106 query = "SELECT * FROM `Table`";
6107 r = MsiDatabaseOpenView(hdb, query, &hview);
6108 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6109 r = MsiViewExecute(hview, 0);
6110 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6112 hrec = MsiCreateRecord(1);
6113 MsiRecordSetInteger(hrec, 1, 1);
6115 r = MsiViewModify(hview, MSIMODIFY_INSERT, hrec);
6116 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6118 MsiCloseHandle(hrec);
6120 hrec = MsiCreateRecord(1);
6121 MsiRecordSetInteger(hrec, 1, 2);
6123 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
6124 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6126 MsiCloseHandle(hrec);
6128 hrec = MsiCreateRecord(1);
6129 MsiRecordSetInteger(hrec, 1, 3);
6131 r = MsiViewModify(hview, MSIMODIFY_INSERT, hrec);
6132 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6134 MsiCloseHandle(hrec);
6136 hrec = MsiCreateRecord(1);
6137 MsiRecordSetInteger(hrec, 1, 4);
6139 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
6140 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6142 MsiCloseHandle(hrec);
6143 MsiViewClose(hview);
6144 MsiCloseHandle(hview);
6146 query = "SELECT * FROM `Table` WHERE `A` = 2";
6147 r = MsiDatabaseOpenView(hdb, query, &hview);
6148 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6149 r = MsiViewExecute(hview, 0);
6150 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6151 r = MsiViewFetch(hview, &hrec);
6152 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6154 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
6155 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6157 MsiCloseHandle(hrec);
6158 MsiViewClose(hview);
6159 MsiCloseHandle(hview);
6161 query = "SELECT * FROM `Table` WHERE `A` = 3";
6162 r = MsiDatabaseOpenView(hdb, query, &hview);
6163 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6164 r = MsiViewExecute(hview, 0);
6165 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6166 r = MsiViewFetch(hview, &hrec);
6167 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6169 r = MsiViewModify(hview, MSIMODIFY_DELETE, hrec);
6170 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6172 MsiCloseHandle(hrec);
6173 MsiViewClose(hview);
6174 MsiCloseHandle(hview);
6176 query = "SELECT * FROM `Table` ORDER BY `A`";
6177 r = MsiDatabaseOpenView(hdb, query, &hview);
6178 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6179 r = MsiViewExecute(hview, 0);
6180 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6182 r = MsiViewFetch(hview, &hrec);
6183 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6185 r = MsiRecordGetInteger(hrec, 1);
6186 ok(r == 1, "Expected 1, got %d\n", r);
6188 MsiCloseHandle(hrec);
6190 r = MsiViewFetch(hview, &hrec);
6191 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6193 r = MsiRecordGetInteger(hrec, 1);
6194 ok(r == 4, "Expected 4, got %d\n", r);
6196 MsiCloseHandle(hrec);
6198 r = MsiViewFetch(hview, &hrec);
6199 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6201 MsiViewClose(hview);
6202 MsiCloseHandle(hview);
6203 MsiCloseHandle(hdb);
6204 DeleteFileA(msifile);
6207 static void test_deleterow(void)
6209 MSIHANDLE hdb, hview, hrec;
6210 const char *query;
6211 char buf[MAX_PATH];
6212 UINT r;
6213 DWORD size;
6215 DeleteFile(msifile);
6217 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6218 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6220 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6221 r = run_query(hdb, 0, query);
6222 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6224 query = "INSERT INTO `Table` (`A`) VALUES ('one')";
6225 r = run_query(hdb, 0, query);
6226 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6228 query = "INSERT INTO `Table` (`A`) VALUES ('two')";
6229 r = run_query(hdb, 0, query);
6230 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6232 query = "DELETE FROM `Table` WHERE `A` = 'one'";
6233 r = run_query(hdb, 0, query);
6234 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6236 r = MsiDatabaseCommit(hdb);
6237 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6239 MsiCloseHandle(hdb);
6241 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb);
6242 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6244 query = "SELECT * FROM `Table`";
6245 r = MsiDatabaseOpenView(hdb, query, &hview);
6246 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6247 r = MsiViewExecute(hview, 0);
6248 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6250 r = MsiViewFetch(hview, &hrec);
6251 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6253 size = MAX_PATH;
6254 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6255 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6256 ok(!lstrcmpA(buf, "two"), "Expected two, got %s\n", buf);
6258 MsiCloseHandle(hrec);
6260 r = MsiViewFetch(hview, &hrec);
6261 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6263 MsiViewClose(hview);
6264 MsiCloseHandle(hview);
6265 MsiCloseHandle(hdb);
6266 DeleteFileA(msifile);
6269 static const CHAR import_dat[] = "A\n"
6270 "s72\n"
6271 "Table\tA\n"
6272 "This is a new 'string' ok\n";
6274 static void test_quotes(void)
6276 MSIHANDLE hdb, hview, hrec;
6277 const char *query;
6278 char buf[MAX_PATH];
6279 UINT r;
6280 DWORD size;
6282 DeleteFile(msifile);
6284 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6285 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6287 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6288 r = run_query(hdb, 0, query);
6289 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6291 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a 'string' ok' )";
6292 r = run_query(hdb, 0, query);
6293 ok(r == ERROR_BAD_QUERY_SYNTAX,
6294 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6296 query = "INSERT INTO `Table` ( `A` ) VALUES ( \"This is a 'string' ok\" )";
6297 r = run_query(hdb, 0, query);
6298 ok(r == ERROR_BAD_QUERY_SYNTAX,
6299 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6301 query = "INSERT INTO `Table` ( `A` ) VALUES ( \"test\" )";
6302 r = run_query(hdb, 0, query);
6303 ok(r == ERROR_BAD_QUERY_SYNTAX,
6304 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6306 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a ''string'' ok' )";
6307 r = run_query(hdb, 0, query);
6308 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6310 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a '''string''' ok' )";
6311 r = run_query(hdb, 0, query);
6312 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6314 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \'string\' ok' )";
6315 r = run_query(hdb, 0, query);
6316 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6318 query = "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \"string\" ok' )";
6319 r = run_query(hdb, 0, query);
6320 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6322 query = "SELECT * FROM `Table`";
6323 r = MsiDatabaseOpenView(hdb, query, &hview);
6324 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6326 r = MsiViewExecute(hview, 0);
6327 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6329 r = MsiViewFetch(hview, &hrec);
6330 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6332 size = MAX_PATH;
6333 r = MsiRecordGetString(hrec, 1, buf, &size);
6334 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6335 ok(!lstrcmp(buf, "This is a \"string\" ok"),
6336 "Expected \"This is a \"string\" ok\", got %s\n", buf);
6338 MsiCloseHandle(hrec);
6340 r = MsiViewFetch(hview, &hrec);
6341 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6343 MsiViewClose(hview);
6344 MsiCloseHandle(hview);
6346 write_file("import.idt", import_dat, (sizeof(import_dat) - 1) * sizeof(char));
6348 r = MsiDatabaseImportA(hdb, CURR_DIR, "import.idt");
6349 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6351 DeleteFileA("import.idt");
6353 query = "SELECT * FROM `Table`";
6354 r = MsiDatabaseOpenView(hdb, query, &hview);
6355 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6357 r = MsiViewExecute(hview, 0);
6358 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6360 r = MsiViewFetch(hview, &hrec);
6361 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6363 size = MAX_PATH;
6364 r = MsiRecordGetString(hrec, 1, buf, &size);
6365 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6366 ok(!lstrcmp(buf, "This is a new 'string' ok"),
6367 "Expected \"This is a new 'string' ok\", got %s\n", buf);
6369 MsiCloseHandle(hrec);
6371 r = MsiViewFetch(hview, &hrec);
6372 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6374 MsiViewClose(hview);
6375 MsiCloseHandle(hview);
6376 MsiCloseHandle(hdb);
6377 DeleteFileA(msifile);
6380 static void test_carriagereturn(void)
6382 MSIHANDLE hdb, hview, hrec;
6383 const char *query;
6384 char buf[MAX_PATH];
6385 UINT r;
6386 DWORD size;
6388 DeleteFile(msifile);
6390 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6391 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6393 query = "CREATE TABLE `Table`\r ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6394 r = run_query(hdb, 0, query);
6395 ok(r == ERROR_BAD_QUERY_SYNTAX,
6396 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6398 query = "CREATE TABLE `Table` \r( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6399 r = run_query(hdb, 0, query);
6400 ok(r == ERROR_BAD_QUERY_SYNTAX,
6401 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6403 query = "CREATE\r TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6404 r = run_query(hdb, 0, query);
6405 ok(r == ERROR_BAD_QUERY_SYNTAX,
6406 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6408 query = "CREATE TABLE\r `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6409 r = run_query(hdb, 0, query);
6410 ok(r == ERROR_BAD_QUERY_SYNTAX,
6411 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6413 query = "CREATE TABLE `Table` (\r `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6414 r = run_query(hdb, 0, query);
6415 ok(r == ERROR_BAD_QUERY_SYNTAX,
6416 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6418 query = "CREATE TABLE `Table` ( `A`\r CHAR(72) NOT NULL PRIMARY KEY `A` )";
6419 r = run_query(hdb, 0, query);
6420 ok(r == ERROR_BAD_QUERY_SYNTAX,
6421 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6423 query = "CREATE TABLE `Table` ( `A` CHAR(72)\r NOT NULL PRIMARY KEY `A` )";
6424 r = run_query(hdb, 0, query);
6425 ok(r == ERROR_BAD_QUERY_SYNTAX,
6426 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6428 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT\r NULL PRIMARY KEY `A` )";
6429 r = run_query(hdb, 0, query);
6430 ok(r == ERROR_BAD_QUERY_SYNTAX,
6431 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6433 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT \rNULL PRIMARY KEY `A` )";
6434 r = run_query(hdb, 0, query);
6435 ok(r == ERROR_BAD_QUERY_SYNTAX,
6436 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6438 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL\r PRIMARY KEY `A` )";
6439 r = run_query(hdb, 0, query);
6440 ok(r == ERROR_BAD_QUERY_SYNTAX,
6441 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6443 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL \rPRIMARY KEY `A` )";
6444 r = run_query(hdb, 0, query);
6445 ok(r == ERROR_BAD_QUERY_SYNTAX,
6446 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6448 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY\r KEY `A` )";
6449 r = run_query(hdb, 0, query);
6450 ok(r == ERROR_BAD_QUERY_SYNTAX,
6451 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6453 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY \rKEY `A` )";
6454 r = run_query(hdb, 0, query);
6455 ok(r == ERROR_BAD_QUERY_SYNTAX,
6456 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6458 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY\r `A` )";
6459 r = run_query(hdb, 0, query);
6460 ok(r == ERROR_BAD_QUERY_SYNTAX,
6461 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6463 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A`\r )";
6464 r = run_query(hdb, 0, query);
6465 ok(r == ERROR_BAD_QUERY_SYNTAX,
6466 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6468 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )\r";
6469 r = run_query(hdb, 0, query);
6470 ok(r == ERROR_BAD_QUERY_SYNTAX,
6471 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6473 query = "CREATE TABLE `\rOne` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6474 r = run_query(hdb, 0, query);
6475 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6477 query = "CREATE TABLE `Tw\ro` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6478 r = run_query(hdb, 0, query);
6479 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6481 query = "CREATE TABLE `Three\r` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6482 r = run_query(hdb, 0, query);
6483 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6485 query = "CREATE TABLE `Four` ( `A\r` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6486 r = run_query(hdb, 0, query);
6487 ok(r == ERROR_BAD_QUERY_SYNTAX,
6488 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6490 query = "CREATE TABLE `Four` ( `\rA` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6491 r = run_query(hdb, 0, query);
6492 ok(r == ERROR_BAD_QUERY_SYNTAX,
6493 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6495 query = "CREATE TABLE `Four` ( `A` CHAR(72\r) NOT NULL PRIMARY KEY `A` )";
6496 r = run_query(hdb, 0, query);
6497 ok(r == ERROR_BAD_QUERY_SYNTAX,
6498 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6500 query = "CREATE TABLE `Four` ( `A` CHAR(\r72) NOT NULL PRIMARY KEY `A` )";
6501 r = run_query(hdb, 0, query);
6502 ok(r == ERROR_BAD_QUERY_SYNTAX,
6503 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6505 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `\rA` )";
6506 r = run_query(hdb, 0, query);
6507 ok(r == ERROR_BAD_QUERY_SYNTAX,
6508 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6510 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
6511 r = run_query(hdb, 0, query);
6512 ok(r == ERROR_BAD_QUERY_SYNTAX,
6513 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6515 query = "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
6516 r = run_query(hdb, 0, query);
6517 ok(r == ERROR_BAD_QUERY_SYNTAX,
6518 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6520 query = "SELECT * FROM `_Tables`";
6521 r = MsiDatabaseOpenView(hdb, query, &hview);
6522 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6523 r = MsiViewExecute(hview, 0);
6524 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6526 r = MsiViewFetch(hview, &hrec);
6527 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6529 size = MAX_PATH;
6530 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6531 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6532 ok(!lstrcmpA(buf, "\rOne"), "Expected \"\\rOne\", got \"%s\"\n", buf);
6534 MsiCloseHandle(hrec);
6536 r = MsiViewFetch(hview, &hrec);
6537 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6539 size = MAX_PATH;
6540 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6541 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6542 ok(!lstrcmpA(buf, "Tw\ro"), "Expected \"Tw\\ro\", got \"%s\"\n", buf);
6544 MsiCloseHandle(hrec);
6546 r = MsiViewFetch(hview, &hrec);
6547 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6549 size = MAX_PATH;
6550 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6551 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6552 ok(!lstrcmpA(buf, "Three\r"), "Expected \"Three\r\", got \"%s\"\n", buf);
6554 MsiCloseHandle(hrec);
6556 r = MsiViewFetch(hview, &hrec);
6557 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6559 MsiViewClose(hview);
6560 MsiCloseHandle(hview);
6562 MsiCloseHandle(hdb);
6563 DeleteFileA(msifile);
6566 static void test_noquotes(void)
6568 MSIHANDLE hdb, hview, hrec;
6569 const char *query;
6570 char buf[MAX_PATH];
6571 UINT r;
6572 DWORD size;
6574 DeleteFile(msifile);
6576 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6577 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6579 query = "CREATE TABLE Table ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6580 r = run_query(hdb, 0, query);
6581 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6583 query = "CREATE TABLE `Table` ( A CHAR(72) NOT NULL PRIMARY KEY `A` )";
6584 r = run_query(hdb, 0, query);
6585 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6587 query = "CREATE TABLE `Table2` ( `A` CHAR(72) NOT NULL PRIMARY KEY A )";
6588 r = run_query(hdb, 0, query);
6589 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6591 query = "CREATE TABLE `Table3` ( A CHAR(72) NOT NULL PRIMARY KEY A )";
6592 r = run_query(hdb, 0, query);
6593 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6595 query = "SELECT * FROM `_Tables`";
6596 r = MsiDatabaseOpenView(hdb, query, &hview);
6597 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6598 r = MsiViewExecute(hview, 0);
6599 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6601 r = MsiViewFetch(hview, &hrec);
6602 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6604 size = MAX_PATH;
6605 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6606 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6607 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
6609 MsiCloseHandle(hrec);
6611 r = MsiViewFetch(hview, &hrec);
6612 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6614 size = MAX_PATH;
6615 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6616 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6617 ok(!lstrcmpA(buf, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf);
6619 MsiCloseHandle(hrec);
6621 r = MsiViewFetch(hview, &hrec);
6622 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6624 size = MAX_PATH;
6625 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6626 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6627 ok(!lstrcmpA(buf, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf);
6629 MsiCloseHandle(hrec);
6631 r = MsiViewFetch(hview, &hrec);
6632 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6634 MsiViewClose(hview);
6635 MsiCloseHandle(hview);
6637 query = "SELECT * FROM `_Columns`";
6638 r = MsiDatabaseOpenView(hdb, query, &hview);
6639 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6640 r = MsiViewExecute(hview, 0);
6641 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6643 r = MsiViewFetch(hview, &hrec);
6644 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6646 size = MAX_PATH;
6647 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6648 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6649 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
6651 r = MsiRecordGetInteger(hrec, 2);
6652 ok(r == 1, "Expected 1, got %d\n", r);
6654 size = MAX_PATH;
6655 r = MsiRecordGetStringA(hrec, 3, buf, &size);
6656 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6657 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
6659 MsiCloseHandle(hrec);
6661 r = MsiViewFetch(hview, &hrec);
6662 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6664 size = MAX_PATH;
6665 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6666 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6667 ok(!lstrcmpA(buf, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf);
6669 r = MsiRecordGetInteger(hrec, 2);
6670 ok(r == 1, "Expected 1, got %d\n", r);
6672 size = MAX_PATH;
6673 r = MsiRecordGetStringA(hrec, 3, buf, &size);
6674 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6675 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
6677 MsiCloseHandle(hrec);
6679 r = MsiViewFetch(hview, &hrec);
6680 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6682 size = MAX_PATH;
6683 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6684 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6685 ok(!lstrcmpA(buf, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf);
6687 r = MsiRecordGetInteger(hrec, 2);
6688 ok(r == 1, "Expected 1, got %d\n", r);
6690 size = MAX_PATH;
6691 r = MsiRecordGetStringA(hrec, 3, buf, &size);
6692 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6693 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
6695 MsiCloseHandle(hrec);
6697 r = MsiViewFetch(hview, &hrec);
6698 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6700 MsiViewClose(hview);
6701 MsiCloseHandle(hview);
6703 query = "INSERT INTO Table ( `A` ) VALUES ( 'hi' )";
6704 r = run_query(hdb, 0, query);
6705 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6707 query = "INSERT INTO `Table` ( A ) VALUES ( 'hi' )";
6708 r = run_query(hdb, 0, query);
6709 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6711 query = "INSERT INTO `Table` ( `A` ) VALUES ( hi )";
6712 r = run_query(hdb, 0, query);
6713 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6715 query = "SELECT * FROM Table WHERE `A` = 'hi'";
6716 r = run_query(hdb, 0, query);
6717 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6719 query = "SELECT * FROM `Table` WHERE `A` = hi";
6720 r = run_query(hdb, 0, query);
6721 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6723 query = "SELECT * FROM Table";
6724 r = run_query(hdb, 0, query);
6725 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6727 query = "SELECT * FROM Table2";
6728 r = MsiDatabaseOpenView(hdb, query, &hview);
6729 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6730 r = MsiViewExecute(hview, 0);
6731 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6733 r = MsiViewFetch(hview, &hrec);
6734 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6736 MsiViewClose(hview);
6737 MsiCloseHandle(hview);
6739 query = "SELECT * FROM `Table` WHERE A = 'hi'";
6740 r = MsiDatabaseOpenView(hdb, query, &hview);
6741 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6742 r = MsiViewExecute(hview, 0);
6743 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6745 r = MsiViewFetch(hview, &hrec);
6746 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6748 size = MAX_PATH;
6749 r = MsiRecordGetStringA(hrec, 1, buf, &size);
6750 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6751 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
6753 MsiCloseHandle(hrec);
6755 r = MsiViewFetch(hview, &hrec);
6756 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
6758 MsiViewClose(hview);
6759 MsiCloseHandle(hview);
6760 MsiCloseHandle(hdb);
6761 DeleteFileA(msifile);
6764 static void read_file_data(LPCSTR filename, LPSTR buffer)
6766 HANDLE file;
6767 DWORD read;
6769 file = CreateFileA( filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
6770 ZeroMemory(buffer, MAX_PATH);
6771 ReadFile(file, buffer, MAX_PATH, &read, NULL);
6772 CloseHandle(file);
6775 static void test_forcecodepage(void)
6777 MSIHANDLE hdb;
6778 const char *query;
6779 char buffer[MAX_PATH];
6780 UINT r;
6782 DeleteFile(msifile);
6784 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6785 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6787 query = "SELECT * FROM `_ForceCodepage`";
6788 r = run_query(hdb, 0, query);
6789 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6791 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6792 r = run_query(hdb, 0, query);
6793 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6795 query = "SELECT * FROM `_ForceCodepage`";
6796 r = run_query(hdb, 0, query);
6797 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6799 r = MsiDatabaseCommit(hdb);
6800 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6802 query = "SELECT * FROM `_ForceCodepage`";
6803 r = run_query(hdb, 0, query);
6804 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6806 MsiCloseHandle(hdb);
6808 r = MsiOpenDatabase(msifile, MSIDBOPEN_DIRECT, &hdb);
6809 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6811 query = "SELECT * FROM `_ForceCodepage`";
6812 r = run_query(hdb, 0, query);
6813 ok(r == ERROR_BAD_QUERY_SYNTAX, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
6815 r = MsiDatabaseExport(hdb, "_ForceCodepage", CURR_DIR, "forcecodepage.idt");
6816 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6818 read_file_data("forcecodepage.idt", buffer);
6819 ok(!lstrcmpA(buffer, "\r\n\r\n0\t_ForceCodepage\r\n"),
6820 "Expected \"\r\n\r\n0\t_ForceCodepage\r\n\", got \"%s\"", buffer);
6822 MsiCloseHandle(hdb);
6823 DeleteFileA(msifile);
6824 DeleteFileA("forcecodepage.idt");
6827 static void test_viewmodify_refresh(void)
6829 MSIHANDLE hdb, hview, hrec;
6830 const char *query;
6831 char buffer[MAX_PATH];
6832 UINT r;
6833 DWORD size;
6835 DeleteFile(msifile);
6837 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6838 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6840 query = "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL, `B` INT PRIMARY KEY `A` )";
6841 r = run_query(hdb, 0, query);
6842 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6844 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hi', 1 )";
6845 r = run_query(hdb, 0, query);
6846 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6848 query = "SELECT * FROM `Table`";
6849 r = MsiDatabaseOpenView(hdb, query, &hview);
6850 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6851 r = MsiViewExecute(hview, 0);
6852 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6854 r = MsiViewFetch(hview, &hrec);
6855 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6857 query = "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hi'";
6858 r = run_query(hdb, 0, query);
6859 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6861 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
6862 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6864 size = MAX_PATH;
6865 r = MsiRecordGetStringA(hrec, 1, buffer, &size);
6866 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6867 ok(!lstrcmpA(buffer, "hi"), "Expected \"hi\", got \"%s\"\n", buffer);
6868 ok(size == 2, "Expected 2, got %d\n", size);
6870 r = MsiRecordGetInteger(hrec, 2);
6871 ok(r == 2, "Expected 2, got %d\n", r);
6873 MsiCloseHandle(hrec);
6874 MsiViewClose(hview);
6875 MsiCloseHandle(hview);
6877 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hello', 3 )";
6878 r = run_query(hdb, 0, query);
6879 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6881 query = "SELECT * FROM `Table` WHERE `B` = 3";
6882 r = MsiDatabaseOpenView(hdb, query, &hview);
6883 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6884 r = MsiViewExecute(hview, 0);
6885 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6887 r = MsiViewFetch(hview, &hrec);
6888 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6890 query = "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hello'";
6891 r = run_query(hdb, 0, query);
6892 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6894 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hithere', 3 )";
6895 r = run_query(hdb, 0, query);
6896 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6898 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
6899 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6901 size = MAX_PATH;
6902 r = MsiRecordGetStringA(hrec, 1, buffer, &size);
6903 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6904 ok(!lstrcmpA(buffer, "hello"), "Expected \"hello\", got \"%s\"\n", buffer);
6905 ok(size == 5, "Expected 5, got %d\n", size);
6907 r = MsiRecordGetInteger(hrec, 2);
6908 ok(r == 2, "Expected 2, got %d\n", r);
6910 MsiCloseHandle(hrec);
6911 MsiViewClose(hview);
6912 MsiCloseHandle(hview);
6913 MsiCloseHandle(hdb);
6914 DeleteFileA(msifile);
6917 static void test_where_viewmodify(void)
6919 MSIHANDLE hdb, hview, hrec;
6920 const char *query;
6921 UINT r;
6923 DeleteFile(msifile);
6925 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
6926 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6928 query = "CREATE TABLE `Table` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6929 r = run_query(hdb, 0, query);
6930 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6932 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 1, 2 )";
6933 r = run_query(hdb, 0, query);
6934 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6936 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 3, 4 )";
6937 r = run_query(hdb, 0, query);
6938 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6940 query = "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 5, 6 )";
6941 r = run_query(hdb, 0, query);
6942 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6944 /* `B` = 3 doesn't match, but the view shouldn't be executed */
6945 query = "SELECT * FROM `Table` WHERE `B` = 3";
6946 r = MsiDatabaseOpenView(hdb, query, &hview);
6947 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6949 hrec = MsiCreateRecord(2);
6950 MsiRecordSetInteger(hrec, 1, 7);
6951 MsiRecordSetInteger(hrec, 2, 8);
6953 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec);
6954 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6956 MsiCloseHandle(hrec);
6957 MsiViewClose(hview);
6958 MsiCloseHandle(hview);
6960 query = "SELECT * FROM `Table` WHERE `A` = 7";
6961 r = MsiDatabaseOpenView(hdb, query, &hview);
6962 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6963 r = MsiViewExecute(hview, 0);
6964 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6966 r = MsiViewFetch(hview, &hrec);
6967 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6969 r = MsiRecordGetInteger(hrec, 1);
6970 ok(r == 7, "Expected 7, got %d\n", r);
6972 r = MsiRecordGetInteger(hrec, 2);
6973 ok(r == 8, "Expected 8, got %d\n", r);
6975 MsiRecordSetInteger(hrec, 2, 9);
6977 r = MsiViewModify(hview, MSIMODIFY_UPDATE, hrec);
6978 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6980 MsiCloseHandle(hrec);
6981 MsiViewClose(hview);
6982 MsiCloseHandle(hview);
6984 query = "SELECT * FROM `Table` WHERE `A` = 7";
6985 r = MsiDatabaseOpenView(hdb, query, &hview);
6986 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6987 r = MsiViewExecute(hview, 0);
6988 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6990 r = MsiViewFetch(hview, &hrec);
6991 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
6993 r = MsiRecordGetInteger(hrec, 1);
6994 ok(r == 7, "Expected 7, got %d\n", r);
6996 r = MsiRecordGetInteger(hrec, 2);
6997 ok(r == 9, "Expected 9, got %d\n", r);
6999 query = "UPDATE `Table` SET `B` = 10 WHERE `A` = 7";
7000 r = run_query(hdb, 0, query);
7001 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7003 r = MsiViewModify(hview, MSIMODIFY_REFRESH, hrec);
7004 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7006 r = MsiRecordGetInteger(hrec, 1);
7007 ok(r == 7, "Expected 7, got %d\n", r);
7009 r = MsiRecordGetInteger(hrec, 2);
7010 ok(r == 10, "Expected 10, got %d\n", r);
7012 MsiCloseHandle(hrec);
7013 MsiViewClose(hview);
7014 MsiCloseHandle(hview);
7015 MsiCloseHandle(hdb);
7018 static BOOL create_storage(LPCSTR name)
7020 WCHAR nameW[MAX_PATH];
7021 IStorage *stg;
7022 IStream *stm;
7023 HRESULT hr;
7024 DWORD count;
7025 BOOL res = FALSE;
7027 MultiByteToWideChar(CP_ACP, 0, name, -1, nameW, MAX_PATH);
7028 hr = StgCreateDocfile(nameW, STGM_CREATE | STGM_READWRITE |
7029 STGM_DIRECT | STGM_SHARE_EXCLUSIVE, 0, &stg);
7030 if (FAILED(hr))
7031 return FALSE;
7033 hr = IStorage_CreateStream(stg, nameW, STGM_WRITE | STGM_SHARE_EXCLUSIVE,
7034 0, 0, &stm);
7035 if (FAILED(hr))
7036 goto done;
7038 hr = IStream_Write(stm, "stgdata", 8, &count);
7039 if (SUCCEEDED(hr))
7040 res = TRUE;
7042 done:
7043 IStream_Release(stm);
7044 IStorage_Release(stg);
7046 return res;
7049 static void test_storages_table(void)
7051 MSIHANDLE hdb, hview, hrec;
7052 IStorage *stg, *inner;
7053 IStream *stm;
7054 char file[MAX_PATH];
7055 char buf[MAX_PATH];
7056 WCHAR name[MAX_PATH];
7057 LPCSTR query;
7058 HRESULT hr;
7059 DWORD size;
7060 UINT r;
7062 hdb = create_db();
7063 ok(hdb, "failed to create db\n");
7065 r = MsiDatabaseCommit(hdb);
7066 ok(r == ERROR_SUCCESS , "Failed to commit database\n");
7068 MsiCloseHandle(hdb);
7070 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb);
7071 ok(r == ERROR_SUCCESS , "Failed to open database\n");
7073 /* check the column types */
7074 hrec = get_column_info(hdb, "SELECT * FROM `_Storages`", MSICOLINFO_TYPES);
7075 ok(hrec, "failed to get column info hrecord\n");
7076 ok(check_record(hrec, 1, "s62"), "wrong hrecord type\n");
7077 ok(check_record(hrec, 2, "V0"), "wrong hrecord type\n");
7079 MsiCloseHandle(hrec);
7081 /* now try the names */
7082 hrec = get_column_info(hdb, "SELECT * FROM `_Storages`", MSICOLINFO_NAMES);
7083 ok(hrec, "failed to get column info hrecord\n");
7084 ok(check_record(hrec, 1, "Name"), "wrong hrecord type\n");
7085 ok(check_record(hrec, 2, "Data"), "wrong hrecord type\n");
7087 MsiCloseHandle(hrec);
7089 create_storage("storage.bin");
7091 hrec = MsiCreateRecord(2);
7092 MsiRecordSetString(hrec, 1, "stgname");
7094 r = MsiRecordSetStream(hrec, 2, "storage.bin");
7095 ok(r == ERROR_SUCCESS, "Failed to add stream data to the hrecord: %d\n", r);
7097 DeleteFileA("storage.bin");
7099 query = "INSERT INTO `_Storages` (`Name`, `Data`) VALUES (?, ?)";
7100 r = MsiDatabaseOpenView(hdb, query, &hview);
7101 ok(r == ERROR_SUCCESS, "Failed to open database hview: %d\n", r);
7103 r = MsiViewExecute(hview, hrec);
7104 ok(r == ERROR_SUCCESS, "Failed to execute hview: %d\n", r);
7106 MsiCloseHandle(hrec);
7107 MsiViewClose(hview);
7108 MsiCloseHandle(hview);
7110 query = "SELECT `Name`, `Data` FROM `_Storages`";
7111 r = MsiDatabaseOpenView(hdb, query, &hview);
7112 ok(r == ERROR_SUCCESS, "Failed to open database hview: %d\n", r);
7114 r = MsiViewExecute(hview, 0);
7115 ok(r == ERROR_SUCCESS, "Failed to execute hview: %d\n", r);
7117 r = MsiViewFetch(hview, &hrec);
7118 ok(r == ERROR_SUCCESS, "Failed to fetch hrecord: %d\n", r);
7120 size = MAX_PATH;
7121 r = MsiRecordGetString(hrec, 1, file, &size);
7122 ok(r == ERROR_SUCCESS, "Failed to get string: %d\n", r);
7123 ok(!lstrcmp(file, "stgname"), "Expected \"stgname\", got \"%s\"\n", file);
7125 size = MAX_PATH;
7126 lstrcpyA(buf, "apple");
7127 r = MsiRecordReadStream(hrec, 2, buf, &size);
7128 ok(r == ERROR_INVALID_DATA, "Expected ERROR_INVALID_DATA, got %d\n", r);
7129 ok(!lstrcmp(buf, "apple"), "Expected buf to be unchanged, got %s\n", buf);
7130 ok(size == 0, "Expected 0, got %d\n", size);
7132 MsiCloseHandle(hrec);
7134 r = MsiViewFetch(hview, &hrec);
7135 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7137 MsiViewClose(hview);
7138 MsiCloseHandle(hview);
7140 MsiDatabaseCommit(hdb);
7141 MsiCloseHandle(hdb);
7143 MultiByteToWideChar(CP_ACP, 0, msifile, -1, name, MAX_PATH);
7144 hr = StgOpenStorage(name, NULL, STGM_DIRECT | STGM_READ |
7145 STGM_SHARE_DENY_WRITE, NULL, 0, &stg);
7146 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
7147 ok(stg != NULL, "Expected non-NULL storage\n");
7149 MultiByteToWideChar(CP_ACP, 0, "stgname", -1, name, MAX_PATH);
7150 hr = IStorage_OpenStorage(stg, name, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE,
7151 NULL, 0, &inner);
7152 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
7153 ok(inner != NULL, "Expected non-NULL storage\n");
7155 MultiByteToWideChar(CP_ACP, 0, "storage.bin", -1, name, MAX_PATH);
7156 hr = IStorage_OpenStream(inner, name, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
7157 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
7158 ok(stm != NULL, "Expected non-NULL stream\n");
7160 hr = IStream_Read(stm, buf, MAX_PATH, &size);
7161 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
7162 ok(size == 8, "Expected 8, got %d\n", size);
7163 ok(!lstrcmpA(buf, "stgdata"), "Expected \"stgdata\", got \"%s\"\n", buf);
7165 IStream_Release(stm);
7166 IStorage_Release(inner);
7168 IStorage_Release(stg);
7169 DeleteFileA(msifile);
7172 static void test_dbtopackage(void)
7174 MSIHANDLE hdb, hpkg;
7175 CHAR package[10];
7176 CHAR buf[MAX_PATH];
7177 DWORD size;
7178 UINT r;
7180 /* create an empty database, transact mode */
7181 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7182 ok(r == ERROR_SUCCESS, "Failed to create database\n");
7184 set_summary_info(hdb);
7186 r = create_directory_table(hdb);
7187 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7189 r = create_custom_action_table(hdb);
7190 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7192 r = add_custom_action_entry(hdb, "'SetProp', 51, 'MYPROP', 'grape'");
7193 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7195 sprintf(package, "#%i", hdb);
7196 r = MsiOpenPackage(package, &hpkg);
7197 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7199 /* property is not set yet */
7200 size = MAX_PATH;
7201 lstrcpyA(buf, "kiwi");
7202 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7203 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7204 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7205 ok(size == 0, "Expected 0, got %d\n", size);
7207 /* run the custom action to set the property */
7208 r = MsiDoAction(hpkg, "SetProp");
7209 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7211 /* property is now set */
7212 size = MAX_PATH;
7213 lstrcpyA(buf, "kiwi");
7214 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7215 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7216 ok(!lstrcmpA(buf, "grape"), "Expected \"grape\", got \"%s\"\n", buf);
7217 ok(size == 5, "Expected 5, got %d\n", size);
7219 MsiCloseHandle(hpkg);
7221 /* reset the package */
7222 r = MsiOpenPackage(package, &hpkg);
7223 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7225 /* property is not set anymore */
7226 size = MAX_PATH;
7227 lstrcpyA(buf, "kiwi");
7228 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7229 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7230 todo_wine
7232 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7233 ok(size == 0, "Expected 0, got %d\n", size);
7236 MsiCloseHandle(hdb);
7237 MsiCloseHandle(hpkg);
7239 /* create an empty database, direct mode */
7240 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATEDIRECT, &hdb);
7241 ok(r == ERROR_SUCCESS, "Failed to create database\n");
7243 set_summary_info(hdb);
7245 r = create_directory_table(hdb);
7246 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7248 r = create_custom_action_table(hdb);
7249 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7251 r = add_custom_action_entry(hdb, "'SetProp', 51, 'MYPROP', 'grape'");
7252 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7254 sprintf(package, "#%i", hdb);
7255 r = MsiOpenPackage(package, &hpkg);
7256 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7258 /* property is not set yet */
7259 size = MAX_PATH;
7260 lstrcpyA(buf, "kiwi");
7261 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7262 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7263 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7264 ok(size == 0, "Expected 0, got %d\n", size);
7266 /* run the custom action to set the property */
7267 r = MsiDoAction(hpkg, "SetProp");
7268 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7270 /* property is now set */
7271 size = MAX_PATH;
7272 lstrcpyA(buf, "kiwi");
7273 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7274 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7275 ok(!lstrcmpA(buf, "grape"), "Expected \"grape\", got \"%s\"\n", buf);
7276 ok(size == 5, "Expected 5, got %d\n", size);
7278 MsiCloseHandle(hpkg);
7280 /* reset the package */
7281 r = MsiOpenPackage(package, &hpkg);
7282 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7284 /* property is not set anymore */
7285 size = MAX_PATH;
7286 lstrcpyA(buf, "kiwi");
7287 r = MsiGetProperty(hpkg, "MYPROP", buf, &size);
7288 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7289 todo_wine
7291 ok(!lstrcmpA(buf, ""), "Expected \"\", got \"%s\"\n", buf);
7292 ok(size == 0, "Expected 0, got %d\n", size);
7295 MsiCloseHandle(hdb);
7296 MsiCloseHandle(hpkg);
7297 DeleteFileA(msifile);
7300 static void test_droptable(void)
7302 MSIHANDLE hdb, hview, hrec;
7303 CHAR buf[MAX_PATH];
7304 LPCSTR query;
7305 DWORD size;
7306 UINT r;
7308 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7309 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7311 query = "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7312 r = run_query(hdb, 0, query);
7313 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7315 query = "SELECT * FROM `One`";
7316 r = do_query(hdb, query, &hrec);
7317 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7319 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7320 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7321 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7322 r = MsiViewExecute(hview, 0);
7323 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7325 r = MsiViewFetch(hview, &hrec);
7326 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7328 size = MAX_PATH;
7329 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7330 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7331 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7333 MsiCloseHandle(hrec);
7334 MsiViewClose(hview);
7335 MsiCloseHandle(hview);
7337 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7338 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7339 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7340 r = MsiViewExecute(hview, 0);
7341 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7343 r = MsiViewFetch(hview, &hrec);
7344 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7346 size = MAX_PATH;
7347 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7348 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7349 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7351 r = MsiRecordGetInteger(hrec, 2);
7352 ok(r == 1, "Expected 1, got %d\n", r);
7354 size = MAX_PATH;
7355 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7356 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7357 ok(!lstrcmpA(buf, "A"), "Expected \"A\", got \"%s\"\n", buf);
7359 MsiCloseHandle(hrec);
7361 r = MsiViewFetch(hview, &hrec);
7362 ok(r == ERROR_NO_MORE_ITEMS,
7363 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7365 MsiViewClose(hview);
7366 MsiCloseHandle(hview);
7368 query = "DROP `One`";
7369 r = run_query(hdb, 0, query);
7370 ok(r == ERROR_BAD_QUERY_SYNTAX,
7371 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7373 query = "DROP TABLE";
7374 r = run_query(hdb, 0, query);
7375 ok(r == ERROR_BAD_QUERY_SYNTAX,
7376 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7378 query = "DROP TABLE `One`";
7379 hview = 0;
7380 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7381 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7382 r = MsiViewExecute(hview, 0);
7383 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7385 r = MsiViewFetch(hview, &hrec);
7386 ok(r == ERROR_FUNCTION_FAILED,
7387 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
7389 MsiViewClose(hview);
7390 MsiCloseHandle(hview);
7392 query = "SELECT * FROM `IDontExist`";
7393 r = do_query(hdb, query, &hrec);
7394 ok(r == ERROR_BAD_QUERY_SYNTAX,
7395 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7397 query = "SELECT * FROM `One`";
7398 r = do_query(hdb, query, &hrec);
7399 ok(r == ERROR_BAD_QUERY_SYNTAX,
7400 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7402 query = "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7403 r = run_query(hdb, 0, query);
7404 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7406 query = "DROP TABLE One";
7407 r = run_query(hdb, 0, query);
7408 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7410 query = "SELECT * FROM `One`";
7411 r = do_query(hdb, query, &hrec);
7412 ok(r == ERROR_BAD_QUERY_SYNTAX,
7413 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7415 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7416 r = do_query(hdb, query, &hrec);
7417 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7419 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7420 r = do_query(hdb, query, &hrec);
7421 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7423 query = "CREATE TABLE `One` ( `B` INT, `C` INT PRIMARY KEY `B` )";
7424 r = run_query(hdb, 0, query);
7425 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7427 query = "SELECT * FROM `One`";
7428 r = do_query(hdb, query, &hrec);
7429 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7431 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7432 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7433 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7434 r = MsiViewExecute(hview, 0);
7435 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7437 r = MsiViewFetch(hview, &hrec);
7438 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7440 size = MAX_PATH;
7441 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7442 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7443 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7445 MsiCloseHandle(hrec);
7446 MsiViewClose(hview);
7447 MsiCloseHandle(hview);
7449 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7450 r = MsiDatabaseOpenViewA(hdb, query, &hview);
7451 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7452 r = MsiViewExecute(hview, 0);
7453 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7455 r = MsiViewFetch(hview, &hrec);
7456 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7458 size = MAX_PATH;
7459 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7460 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7461 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7463 r = MsiRecordGetInteger(hrec, 2);
7464 ok(r == 1, "Expected 1, got %d\n", r);
7466 size = MAX_PATH;
7467 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7468 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7469 ok(!lstrcmpA(buf, "B"), "Expected \"B\", got \"%s\"\n", buf);
7471 MsiCloseHandle(hrec);
7473 r = MsiViewFetch(hview, &hrec);
7474 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7476 size = MAX_PATH;
7477 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7478 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7479 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7481 r = MsiRecordGetInteger(hrec, 2);
7482 ok(r == 2, "Expected 2, got %d\n", r);
7484 size = MAX_PATH;
7485 r = MsiRecordGetStringA(hrec, 3, buf, &size);
7486 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7487 ok(!lstrcmpA(buf, "C"), "Expected \"C\", got \"%s\"\n", buf);
7489 MsiCloseHandle(hrec);
7491 r = MsiViewFetch(hview, &hrec);
7492 ok(r == ERROR_NO_MORE_ITEMS,
7493 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7495 MsiViewClose(hview);
7496 MsiCloseHandle(hview);
7498 query = "DROP TABLE One";
7499 r = run_query(hdb, 0, query);
7500 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7502 query = "SELECT * FROM `One`";
7503 r = do_query(hdb, query, &hrec);
7504 ok(r == ERROR_BAD_QUERY_SYNTAX,
7505 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7507 query = "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7508 r = do_query(hdb, query, &hrec);
7509 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7511 query = "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7512 r = do_query(hdb, query, &hrec);
7513 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
7515 MsiCloseHandle(hdb);
7516 DeleteFileA(msifile);
7519 static void test_dbmerge(void)
7521 MSIHANDLE hdb, href, hview, hrec;
7522 CHAR buf[MAX_PATH];
7523 LPCSTR query;
7524 DWORD size;
7525 UINT r;
7527 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
7528 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7530 r = MsiOpenDatabase("refdb.msi", MSIDBOPEN_CREATE, &href);
7531 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7533 /* hDatabase is invalid */
7534 r = MsiDatabaseMergeA(0, href, "MergeErrors");
7535 ok(r == ERROR_INVALID_HANDLE,
7536 "Expected ERROR_INVALID_HANDLE, got %d\n", r);
7538 /* hDatabaseMerge is invalid */
7539 r = MsiDatabaseMergeA(hdb, 0, "MergeErrors");
7540 ok(r == ERROR_INVALID_HANDLE,
7541 "Expected ERROR_INVALID_HANDLE, got %d\n", r);
7543 /* szTableName is NULL */
7544 r = MsiDatabaseMergeA(hdb, href, NULL);
7545 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7547 /* szTableName is empty */
7548 r = MsiDatabaseMergeA(hdb, href, "");
7549 ok(r == ERROR_INVALID_TABLE, "Expected ERROR_INVALID_TABLE, got %d\n", r);
7551 /* both DBs empty, szTableName is valid */
7552 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7553 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7555 query = "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7556 r = run_query(hdb, 0, query);
7557 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7559 query = "CREATE TABLE `One` ( `A` CHAR(72) PRIMARY KEY `A` )";
7560 r = run_query(href, 0, query);
7561 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7563 /* column types don't match */
7564 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7565 ok(r == ERROR_DATATYPE_MISMATCH,
7566 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7568 /* nothing in MergeErrors */
7569 query = "SELECT * FROM `MergeErrors`";
7570 r = do_query(hdb, query, &hrec);
7571 ok(r == ERROR_BAD_QUERY_SYNTAX,
7572 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7574 query = "DROP TABLE `One`";
7575 r = run_query(hdb, 0, query);
7576 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7578 query = "DROP TABLE `One`";
7579 r = run_query(href, 0, query);
7580 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7582 query = "CREATE TABLE `One` ( "
7583 "`A` CHAR(72), "
7584 "`B` CHAR(56), "
7585 "`C` CHAR(64) LOCALIZABLE, "
7586 "`D` LONGCHAR, "
7587 "`E` CHAR(72) NOT NULL, "
7588 "`F` CHAR(56) NOT NULL, "
7589 "`G` CHAR(64) NOT NULL LOCALIZABLE, "
7590 "`H` LONGCHAR NOT NULL "
7591 "PRIMARY KEY `A` )";
7592 r = run_query(hdb, 0, query);
7593 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7595 query = "CREATE TABLE `One` ( "
7596 "`A` CHAR(64), "
7597 "`B` CHAR(64), "
7598 "`C` CHAR(64), "
7599 "`D` CHAR(64), "
7600 "`E` CHAR(64) NOT NULL, "
7601 "`F` CHAR(64) NOT NULL, "
7602 "`G` CHAR(64) NOT NULL, "
7603 "`H` CHAR(64) NOT NULL "
7604 "PRIMARY KEY `A` )";
7605 r = run_query(href, 0, query);
7606 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7608 /* column sting types don't match exactly */
7609 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7610 ok(r == ERROR_SUCCESS,
7611 "Expected ERROR_SUCCESS, got %d\n", r);
7613 /* nothing in MergeErrors */
7614 query = "SELECT * FROM `MergeErrors`";
7615 r = do_query(hdb, query, &hrec);
7616 ok(r == ERROR_BAD_QUERY_SYNTAX,
7617 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7619 query = "DROP TABLE `One`";
7620 r = run_query(hdb, 0, query);
7621 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7623 query = "DROP TABLE `One`";
7624 r = run_query(href, 0, query);
7625 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7627 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7628 r = run_query(hdb, 0, query);
7629 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7631 query = "CREATE TABLE `One` ( `A` INT, `C` INT PRIMARY KEY `A` )";
7632 r = run_query(href, 0, query);
7633 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7635 /* column names don't match */
7636 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7637 ok(r == ERROR_DATATYPE_MISMATCH,
7638 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7640 /* nothing in MergeErrors */
7641 query = "SELECT * FROM `MergeErrors`";
7642 r = do_query(hdb, query, &hrec);
7643 ok(r == ERROR_BAD_QUERY_SYNTAX,
7644 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7646 query = "DROP TABLE `One`";
7647 r = run_query(hdb, 0, query);
7648 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7650 query = "DROP TABLE `One`";
7651 r = run_query(href, 0, query);
7652 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7654 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7655 r = run_query(hdb, 0, query);
7656 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7658 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `B` )";
7659 r = run_query(href, 0, query);
7660 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7662 /* primary keys don't match */
7663 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7664 ok(r == ERROR_DATATYPE_MISMATCH,
7665 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7667 /* nothing in MergeErrors */
7668 query = "SELECT * FROM `MergeErrors`";
7669 r = do_query(hdb, query, &hrec);
7670 ok(r == ERROR_BAD_QUERY_SYNTAX,
7671 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7673 query = "DROP TABLE `One`";
7674 r = run_query(hdb, 0, query);
7675 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7677 query = "DROP TABLE `One`";
7678 r = run_query(href, 0, query);
7679 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7681 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7682 r = run_query(hdb, 0, query);
7683 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7685 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A`, `B` )";
7686 r = run_query(href, 0, query);
7687 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7689 /* number of primary keys doesn't match */
7690 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7691 ok(r == ERROR_DATATYPE_MISMATCH,
7692 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r);
7694 /* nothing in MergeErrors */
7695 query = "SELECT * FROM `MergeErrors`";
7696 r = do_query(hdb, query, &hrec);
7697 ok(r == ERROR_BAD_QUERY_SYNTAX,
7698 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7700 query = "DROP TABLE `One`";
7701 r = run_query(hdb, 0, query);
7702 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7704 query = "DROP TABLE `One`";
7705 r = run_query(href, 0, query);
7706 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7708 query = "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
7709 r = run_query(hdb, 0, query);
7710 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7712 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7713 r = run_query(href, 0, query);
7714 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7716 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
7717 r = run_query(href, 0, query);
7718 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7720 /* number of columns doesn't match */
7721 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7722 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7724 query = "SELECT * FROM `One`";
7725 r = do_query(hdb, query, &hrec);
7726 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7728 r = MsiRecordGetInteger(hrec, 1);
7729 ok(r == 1, "Expected 1, got %d\n", r);
7731 r = MsiRecordGetInteger(hrec, 2);
7732 ok(r == 2, "Expected 2, got %d\n", r);
7734 r = MsiRecordGetInteger(hrec, 3);
7735 ok(r == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", r);
7737 MsiCloseHandle(hrec);
7739 /* nothing in MergeErrors */
7740 query = "SELECT * FROM `MergeErrors`";
7741 r = do_query(hdb, query, &hrec);
7742 ok(r == ERROR_BAD_QUERY_SYNTAX,
7743 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7745 query = "DROP TABLE `One`";
7746 r = run_query(hdb, 0, query);
7747 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7749 query = "DROP TABLE `One`";
7750 r = run_query(href, 0, query);
7751 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7753 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7754 r = run_query(hdb, 0, query);
7755 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7757 query = "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
7758 r = run_query(href, 0, query);
7759 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7761 query = "INSERT INTO `One` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
7762 r = run_query(href, 0, query);
7763 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7765 /* number of columns doesn't match */
7766 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7767 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7769 query = "SELECT * FROM `One`";
7770 r = do_query(hdb, query, &hrec);
7771 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7773 r = MsiRecordGetInteger(hrec, 1);
7774 ok(r == 1, "Expected 1, got %d\n", r);
7776 r = MsiRecordGetInteger(hrec, 2);
7777 ok(r == 2, "Expected 2, got %d\n", r);
7779 r = MsiRecordGetInteger(hrec, 3);
7780 ok(r == MSI_NULL_INTEGER, "Expected MSI_NULL_INTEGER, got %d\n", r);
7782 MsiCloseHandle(hrec);
7784 /* nothing in MergeErrors */
7785 query = "SELECT * FROM `MergeErrors`";
7786 r = do_query(hdb, query, &hrec);
7787 ok(r == ERROR_BAD_QUERY_SYNTAX,
7788 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7790 query = "DROP TABLE `One`";
7791 r = run_query(hdb, 0, query);
7792 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7794 query = "DROP TABLE `One`";
7795 r = run_query(href, 0, query);
7796 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7798 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7799 r = run_query(hdb, 0, query);
7800 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7802 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 1 )";
7803 r = run_query(hdb, 0, query);
7804 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7806 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 2 )";
7807 r = run_query(hdb, 0, query);
7808 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7810 query = "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7811 r = run_query(href, 0, query);
7812 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7814 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
7815 r = run_query(href, 0, query);
7816 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7818 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 3 )";
7819 r = run_query(href, 0, query);
7820 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7822 /* primary keys match, rows do not */
7823 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7824 ok(r == ERROR_FUNCTION_FAILED,
7825 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
7827 /* nothing in MergeErrors */
7828 query = "SELECT * FROM `MergeErrors`";
7829 r = do_query(hdb, query, &hrec);
7830 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7832 size = MAX_PATH;
7833 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7834 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7835 ok(!lstrcmpA(buf, "One"), "Expected \"One\", got \"%s\"\n", buf);
7837 r = MsiRecordGetInteger(hrec, 2);
7838 ok(r == 2, "Expected 2, got %d\n", r);
7840 MsiCloseHandle(hrec);
7842 r = MsiDatabaseOpenViewA(hdb, "SELECT * FROM `MergeErrors`", &hview);
7843 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7845 r = MsiViewGetColumnInfo(hview, MSICOLINFO_NAMES, &hrec);
7846 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7848 size = MAX_PATH;
7849 r = MsiRecordGetString(hrec, 1, buf, &size);
7850 ok(!lstrcmpA(buf, "Table"), "Expected \"Table\", got \"%s\"\n", buf);
7852 size = MAX_PATH;
7853 r = MsiRecordGetString(hrec, 2, buf, &size);
7854 ok(!lstrcmpA(buf, "NumRowMergeConflicts"),
7855 "Expected \"NumRowMergeConflicts\", got \"%s\"\n", buf);
7857 MsiCloseHandle(hrec);
7859 r = MsiViewGetColumnInfo(hview, MSICOLINFO_TYPES, &hrec);
7860 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7862 size = MAX_PATH;
7863 r = MsiRecordGetString(hrec, 1, buf, &size);
7864 ok(!lstrcmpA(buf, "s255"), "Expected \"s255\", got \"%s\"\n", buf);
7866 size = MAX_PATH;
7867 r = MsiRecordGetString(hrec, 2, buf, &size);
7868 ok(!lstrcmpA(buf, "i2"), "Expected \"i2\", got \"%s\"\n", buf);
7870 MsiCloseHandle(hrec);
7871 MsiViewClose(hview);
7872 MsiCloseHandle(hview);
7874 query = "DROP TABLE `MergeErrors`";
7875 r = run_query(hdb, 0, query);
7876 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7878 query = "DROP TABLE `One`";
7879 r = run_query(hdb, 0, query);
7880 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7882 query = "DROP TABLE `One`";
7883 r = run_query(href, 0, query);
7884 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7886 query = "CREATE TABLE `One` ( `A` INT, `B` CHAR(72) PRIMARY KEY `A` )";
7887 r = run_query(href, 0, query);
7888 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7890 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
7891 r = run_query(href, 0, query);
7892 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7894 /* table from merged database is not in target database */
7895 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7896 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7898 query = "SELECT * FROM `One`";
7899 r = do_query(hdb, query, &hrec);
7900 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7902 r = MsiRecordGetInteger(hrec, 1);
7903 ok(r == 1, "Expected 1, got %d\n", r);
7905 size = MAX_PATH;
7906 r = MsiRecordGetStringA(hrec, 2, buf, &size);
7907 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7908 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
7910 MsiCloseHandle(hrec);
7912 /* nothing in MergeErrors */
7913 query = "SELECT * FROM `MergeErrors`";
7914 r = do_query(hdb, query, &hrec);
7915 ok(r == ERROR_BAD_QUERY_SYNTAX,
7916 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7918 query = "DROP TABLE `One`";
7919 r = run_query(hdb, 0, query);
7920 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7922 query = "DROP TABLE `One`";
7923 r = run_query(href, 0, query);
7924 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7926 query = "CREATE TABLE `One` ( "
7927 "`A` CHAR(72), `B` INT PRIMARY KEY `A` )";
7928 r = run_query(hdb, 0, query);
7929 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7931 query = "CREATE TABLE `One` ( "
7932 "`A` CHAR(72), `B` INT PRIMARY KEY `A` )";
7933 r = run_query(href, 0, query);
7934 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7936 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 'hi', 1 )";
7937 r = run_query(href, 0, query);
7938 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7940 /* primary key is string */
7941 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7942 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7944 query = "SELECT * FROM `One`";
7945 r = do_query(hdb, query, &hrec);
7946 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7948 size = MAX_PATH;
7949 r = MsiRecordGetStringA(hrec, 1, buf, &size);
7950 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7951 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
7953 r = MsiRecordGetInteger(hrec, 2);
7954 ok(r == 1, "Expected 1, got %d\n", r);
7956 MsiCloseHandle(hrec);
7958 /* nothing in MergeErrors */
7959 query = "SELECT * FROM `MergeErrors`";
7960 r = do_query(hdb, query, &hrec);
7961 ok(r == ERROR_BAD_QUERY_SYNTAX,
7962 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
7964 create_file_data("codepage.idt", "\r\n\r\n850\t_ForceCodepage\r\n", 0);
7966 GetCurrentDirectoryA(MAX_PATH, buf);
7967 r = MsiDatabaseImportA(hdb, buf, "codepage.idt");
7968 todo_wine
7970 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7973 query = "DROP TABLE `One`";
7974 r = run_query(hdb, 0, query);
7975 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7977 query = "DROP TABLE `One`";
7978 r = run_query(href, 0, query);
7979 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7981 query = "CREATE TABLE `One` ( "
7982 "`A` INT, `B` CHAR(72) LOCALIZABLE 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` ( "
7987 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
7988 r = run_query(href, 0, query);
7989 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7991 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
7992 r = run_query(href, 0, query);
7993 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7995 /* code page does not match */
7996 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
7997 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
7999 query = "SELECT * FROM `One`";
8000 r = do_query(hdb, query, &hrec);
8001 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8003 r = MsiRecordGetInteger(hrec, 1);
8004 ok(r == 1, "Expected 1, got %d\n", r);
8006 size = MAX_PATH;
8007 r = MsiRecordGetStringA(hrec, 2, buf, &size);
8008 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8009 ok(!lstrcmpA(buf, "hi"), "Expected \"hi\", got \"%s\"\n", buf);
8011 MsiCloseHandle(hrec);
8013 /* nothing in MergeErrors */
8014 query = "SELECT * FROM `MergeErrors`";
8015 r = do_query(hdb, query, &hrec);
8016 ok(r == ERROR_BAD_QUERY_SYNTAX,
8017 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8019 query = "DROP TABLE `One`";
8020 r = run_query(hdb, 0, query);
8021 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8023 query = "DROP TABLE `One`";
8024 r = run_query(href, 0, query);
8025 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8027 query = "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
8028 r = run_query(hdb, 0, query);
8029 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8031 query = "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
8032 r = run_query(href, 0, query);
8033 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8035 create_file("binary.dat");
8036 hrec = MsiCreateRecord(1);
8037 MsiRecordSetStreamA(hrec, 1, "binary.dat");
8039 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, ? )";
8040 r = run_query(href, hrec, query);
8041 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8043 MsiCloseHandle(hrec);
8045 /* binary data to merge */
8046 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8047 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8049 query = "SELECT * FROM `One`";
8050 r = do_query(hdb, query, &hrec);
8051 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8053 r = MsiRecordGetInteger(hrec, 1);
8054 ok(r == 1, "Expected 1, got %d\n", r);
8056 size = MAX_PATH;
8057 ZeroMemory(buf, MAX_PATH);
8058 r = MsiRecordReadStream(hrec, 2, buf, &size);
8059 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8060 ok(!lstrcmpA(buf, "binary.dat\n"),
8061 "Expected \"binary.dat\\n\", got \"%s\"\n", buf);
8063 MsiCloseHandle(hrec);
8065 /* nothing in MergeErrors */
8066 query = "SELECT * FROM `MergeErrors`";
8067 r = do_query(hdb, query, &hrec);
8068 ok(r == ERROR_BAD_QUERY_SYNTAX,
8069 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8071 query = "DROP TABLE `One`";
8072 r = run_query(hdb, 0, query);
8073 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8075 query = "DROP TABLE `One`";
8076 r = run_query(href, 0, query);
8077 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8079 query = "CREATE TABLE `One` ( `A` INT, `B` CHAR(72) PRIMARY KEY `A` )";
8080 r = run_query(hdb, 0, query);
8081 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8082 r = run_query(href, 0, query);
8083 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8085 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'foo' )";
8086 r = run_query(href, 0, query);
8087 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8089 query = "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 'bar' )";
8090 r = run_query(href, 0, query);
8091 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8093 r = MsiDatabaseMergeA(hdb, href, "MergeErrors");
8094 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8096 query = "SELECT * FROM `One`";
8097 r = MsiDatabaseOpenViewA(hdb, query, &hview);
8098 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8099 r = MsiViewExecute(hview, 0);
8100 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8102 r = MsiViewFetch(hview, &hrec);
8103 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8105 r = MsiRecordGetInteger(hrec, 1);
8106 ok(r == 1, "Expected 1, got %d\n", r);
8108 size = MAX_PATH;
8109 r = MsiRecordGetStringA(hrec, 2, buf, &size);
8110 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8111 ok(!lstrcmpA(buf, "foo"), "Expected \"foo\", got \"%s\"\n", buf);
8113 MsiCloseHandle(hrec);
8115 r = MsiViewFetch(hview, &hrec);
8116 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8118 r = MsiRecordGetInteger(hrec, 1);
8119 ok(r == 2, "Expected 2, got %d\n", r);
8121 size = MAX_PATH;
8122 r = MsiRecordGetStringA(hrec, 2, buf, &size);
8123 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8124 ok(!lstrcmpA(buf, "bar"), "Expected \"bar\", got \"%s\"\n", buf);
8126 MsiCloseHandle(hrec);
8128 r = MsiViewFetch(hview, &hrec);
8129 ok(r == ERROR_NO_MORE_ITEMS,
8130 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8132 MsiViewClose(hview);
8133 MsiCloseHandle(hview);
8135 MsiCloseHandle(hdb);
8136 MsiCloseHandle(href);
8137 DeleteFileA(msifile);
8138 DeleteFileA("refdb.msi");
8139 DeleteFileA("codepage.idt");
8140 DeleteFileA("binary.dat");
8143 static void test_select_with_tablenames(void)
8145 MSIHANDLE hdb, view, rec;
8146 LPCSTR query;
8147 UINT r;
8148 int i;
8150 int vals[4][2] = {
8151 {1,12},
8152 {4,12},
8153 {1,15},
8154 {4,15}};
8156 hdb = create_db();
8157 ok(hdb, "failed to create db\n");
8159 /* Build a pair of tables with the same column names, but unique data */
8160 query = "CREATE TABLE `T1` ( `A` SHORT, `B` SHORT PRIMARY KEY `A`)";
8161 r = run_query(hdb, 0, query);
8162 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8164 query = "INSERT INTO `T1` ( `A`, `B` ) VALUES ( 1, 2 )";
8165 r = run_query(hdb, 0, query);
8166 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8168 query = "INSERT INTO `T1` ( `A`, `B` ) VALUES ( 4, 5 )";
8169 r = run_query(hdb, 0, query);
8170 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8172 query = "CREATE TABLE `T2` ( `A` SHORT, `B` SHORT PRIMARY KEY `A`)";
8173 r = run_query(hdb, 0, query);
8174 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8176 query = "INSERT INTO `T2` ( `A`, `B` ) VALUES ( 11, 12 )";
8177 r = run_query(hdb, 0, query);
8178 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8180 query = "INSERT INTO `T2` ( `A`, `B` ) VALUES ( 14, 15 )";
8181 r = run_query(hdb, 0, query);
8182 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8185 /* Test that selection based on prefixing the column with the table
8186 * actually selects the right data */
8188 query = "SELECT T1.A, T2.B FROM T1,T2";
8189 r = MsiDatabaseOpenView(hdb, query, &view);
8190 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8191 r = MsiViewExecute(view, 0);
8192 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8194 for (i = 0; i < 4; i++)
8196 r = MsiViewFetch(view, &rec);
8197 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8199 r = MsiRecordGetInteger(rec, 1);
8200 ok(r == vals[i][0], "Expected %d, got %d\n", vals[i][0], r);
8202 r = MsiRecordGetInteger(rec, 2);
8203 ok(r == vals[i][1], "Expected %d, got %d\n", vals[i][1], r);
8205 MsiCloseHandle(rec);
8208 r = MsiViewFetch(view, &rec);
8209 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8211 MsiViewClose(view);
8212 MsiCloseHandle(view);
8213 MsiCloseHandle(hdb);
8214 DeleteFileA(msifile);
8217 UINT ordervals[6][3] =
8219 { MSI_NULL_INTEGER, 12, 13 },
8220 { 1, 2, 3 },
8221 { 6, 4, 5 },
8222 { 8, 9, 7 },
8223 { 10, 11, MSI_NULL_INTEGER },
8224 { 14, MSI_NULL_INTEGER, 15 }
8227 static void test_insertorder(void)
8229 MSIHANDLE hdb, view, rec;
8230 LPCSTR query;
8231 UINT r;
8232 int i;
8234 hdb = create_db();
8235 ok(hdb, "failed to create db\n");
8237 query = "CREATE TABLE `T` ( `A` SHORT, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
8238 r = run_query(hdb, 0, query);
8239 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8241 query = "INSERT INTO `T` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
8242 r = run_query(hdb, 0, query);
8243 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8245 query = "INSERT INTO `T` ( `B`, `C`, `A` ) VALUES ( 4, 5, 6 )";
8246 r = run_query(hdb, 0, query);
8247 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8249 query = "INSERT INTO `T` ( `C`, `A`, `B` ) VALUES ( 7, 8, 9 )";
8250 r = run_query(hdb, 0, query);
8251 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8253 query = "INSERT INTO `T` ( `A`, `B` ) VALUES ( 10, 11 )";
8254 r = run_query(hdb, 0, query);
8255 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8257 query = "INSERT INTO `T` ( `B`, `C` ) VALUES ( 12, 13 )";
8258 r = run_query(hdb, 0, query);
8259 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8261 /* fails because the primary key already
8262 * has an MSI_NULL_INTEGER value set above
8264 query = "INSERT INTO `T` ( `C` ) VALUES ( 14 )";
8265 r = run_query(hdb, 0, query);
8266 ok(r == ERROR_FUNCTION_FAILED,
8267 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
8269 /* replicate the error where primary key is set twice */
8270 query = "INSERT INTO `T` ( `A`, `C` ) VALUES ( 1, 14 )";
8271 r = run_query(hdb, 0, query);
8272 ok(r == ERROR_FUNCTION_FAILED,
8273 "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
8275 query = "INSERT INTO `T` ( `A`, `C` ) VALUES ( 14, 15 )";
8276 r = run_query(hdb, 0, query);
8277 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8279 query = "INSERT INTO `T` VALUES ( 16 )";
8280 r = run_query(hdb, 0, query);
8281 ok(r == ERROR_BAD_QUERY_SYNTAX,
8282 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8284 query = "INSERT INTO `T` VALUES ( 17, 18 )";
8285 r = run_query(hdb, 0, query);
8286 ok(r == ERROR_BAD_QUERY_SYNTAX,
8287 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8289 query = "INSERT INTO `T` VALUES ( 19, 20, 21 )";
8290 r = run_query(hdb, 0, query);
8291 ok(r == ERROR_BAD_QUERY_SYNTAX,
8292 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r);
8294 query = "SELECT * FROM `T`";
8295 r = MsiDatabaseOpenView(hdb, query, &view);
8296 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8297 r = MsiViewExecute(view, 0);
8298 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8300 for (i = 0; i < 6; i++)
8302 r = MsiViewFetch(view, &rec);
8303 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8305 r = MsiRecordGetInteger(rec, 1);
8306 ok(r == ordervals[i][0], "Expected %d, got %d\n", ordervals[i][0], r);
8308 r = MsiRecordGetInteger(rec, 2);
8309 ok(r == ordervals[i][1], "Expected %d, got %d\n", ordervals[i][1], r);
8311 r = MsiRecordGetInteger(rec, 3);
8312 ok(r == ordervals[i][2], "Expected %d, got %d\n", ordervals[i][2], r);
8314 MsiCloseHandle(rec);
8317 r = MsiViewFetch(view, &rec);
8318 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8320 MsiViewClose(view);
8321 MsiCloseHandle(view);
8323 query = "DELETE FROM `T` WHERE `A` IS NULL";
8324 r = run_query(hdb, 0, query);
8325 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8327 query = "INSERT INTO `T` ( `B`, `C` ) VALUES ( 12, 13 ) TEMPORARY";
8328 r = run_query(hdb, 0, query);
8329 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8331 query = "SELECT * FROM `T`";
8332 r = MsiDatabaseOpenView(hdb, query, &view);
8333 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8334 r = MsiViewExecute(view, 0);
8335 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8337 for (i = 0; i < 6; i++)
8339 r = MsiViewFetch(view, &rec);
8340 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8342 r = MsiRecordGetInteger(rec, 1);
8343 ok(r == ordervals[i][0], "Expected %d, got %d\n", ordervals[i][0], r);
8345 r = MsiRecordGetInteger(rec, 2);
8346 ok(r == ordervals[i][1], "Expected %d, got %d\n", ordervals[i][1], r);
8348 r = MsiRecordGetInteger(rec, 3);
8349 ok(r == ordervals[i][2], "Expected %d, got %d\n", ordervals[i][2], r);
8351 MsiCloseHandle(rec);
8354 r = MsiViewFetch(view, &rec);
8355 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8357 MsiViewClose(view);
8358 MsiCloseHandle(view);
8359 MsiCloseHandle(hdb);
8360 DeleteFileA(msifile);
8363 static void test_columnorder(void)
8365 MSIHANDLE hdb, view, rec;
8366 char buf[MAX_PATH];
8367 LPCSTR query;
8368 DWORD sz;
8369 UINT r;
8371 hdb = create_db();
8372 ok(hdb, "failed to create db\n");
8374 /* Each column is a slot:
8375 * ---------------------
8376 * | B | C | A | E | D |
8377 * ---------------------
8379 * When a column is selected as a primary key,
8380 * the column occupying the nth primary key slot is swapped
8381 * with the current position of the primary key in question:
8383 * set primary key `D`
8384 * --------------------- ---------------------
8385 * | B | C | A | E | D | -> | D | C | A | E | B |
8386 * --------------------- ---------------------
8388 * set primary key `E`
8389 * --------------------- ---------------------
8390 * | D | C | A | E | B | -> | D | E | A | C | B |
8391 * --------------------- ---------------------
8394 query = "CREATE TABLE `T` ( `B` SHORT NOT NULL, `C` SHORT NOT NULL, "
8395 "`A` CHAR(255), `E` INT, `D` CHAR(255) NOT NULL "
8396 "PRIMARY KEY `D`, `E`)";
8397 r = run_query(hdb, 0, query);
8398 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8400 query = "SELECT * FROM `T`";
8401 r = MsiDatabaseOpenView(hdb, query, &view);
8402 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8404 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
8405 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8407 sz = MAX_PATH;
8408 lstrcpyA(buf, "kiwi");
8409 r = MsiRecordGetString(rec, 1, buf, &sz);
8410 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8411 ok(!lstrcmpA("s255", buf), "Expected \"s255\", got \"%s\"\n", buf);
8413 sz = MAX_PATH;
8414 lstrcpyA(buf, "kiwi");
8415 r = MsiRecordGetString(rec, 2, buf, &sz);
8416 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8417 ok(!lstrcmpA("I2", buf), "Expected \"I2\", got \"%s\"\n", buf);
8419 sz = MAX_PATH;
8420 lstrcpyA(buf, "kiwi");
8421 r = MsiRecordGetString(rec, 3, buf, &sz);
8422 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8423 ok(!lstrcmpA("S255", buf), "Expected \"S255\", got \"%s\"\n", buf);
8425 sz = MAX_PATH;
8426 lstrcpyA(buf, "kiwi");
8427 r = MsiRecordGetString(rec, 4, buf, &sz);
8428 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8429 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8431 sz = MAX_PATH;
8432 lstrcpyA(buf, "kiwi");
8433 r = MsiRecordGetString(rec, 5, buf, &sz);
8434 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8435 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8437 MsiCloseHandle(rec);
8439 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
8440 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8442 sz = MAX_PATH;
8443 lstrcpyA(buf, "kiwi");
8444 r = MsiRecordGetString(rec, 1, buf, &sz);
8445 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8446 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8448 sz = MAX_PATH;
8449 lstrcpyA(buf, "kiwi");
8450 r = MsiRecordGetString(rec, 2, buf, &sz);
8451 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8452 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8454 sz = MAX_PATH;
8455 lstrcpyA(buf, "kiwi");
8456 r = MsiRecordGetString(rec, 3, buf, &sz);
8457 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8458 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8460 sz = MAX_PATH;
8461 lstrcpyA(buf, "kiwi");
8462 r = MsiRecordGetString(rec, 4, buf, &sz);
8463 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8464 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8466 sz = MAX_PATH;
8467 lstrcpyA(buf, "kiwi");
8468 r = MsiRecordGetString(rec, 5, buf, &sz);
8469 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8470 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8472 MsiCloseHandle(rec);
8473 MsiViewClose(view);
8474 MsiCloseHandle(view);
8476 query = "INSERT INTO `T` ( `B`, `C`, `A`, `E`, `D` ) "
8477 "VALUES ( 1, 2, 'a', 3, 'bc' )";
8478 r = run_query(hdb, 0, query);
8479 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8481 query = "SELECT * FROM `T`";
8482 r = do_query(hdb, query, &rec);
8484 sz = MAX_PATH;
8485 lstrcpyA(buf, "kiwi");
8486 r = MsiRecordGetString(rec, 1, buf, &sz);
8487 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8488 ok(!lstrcmpA("bc", buf), "Expected \"bc\", got \"%s\"\n", buf);
8490 r = MsiRecordGetInteger(rec, 2);
8491 ok(r == 3, "Expected 3, got %d\n", r);
8493 sz = MAX_PATH;
8494 lstrcpyA(buf, "kiwi");
8495 r = MsiRecordGetString(rec, 3, buf, &sz);
8496 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8497 ok(!lstrcmpA("a", buf), "Expected \"a\", got \"%s\"\n", buf);
8499 r = MsiRecordGetInteger(rec, 4);
8500 ok(r == 2, "Expected 2, got %d\n", r);
8502 r = MsiRecordGetInteger(rec, 5);
8503 ok(r == 1, "Expected 1, got %d\n", r);
8505 MsiCloseHandle(rec);
8507 query = "SELECT * FROM `_Columns` WHERE `Table` = 'T'";
8508 r = MsiDatabaseOpenView(hdb, query, &view);
8509 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8510 r = MsiViewExecute(view, 0);
8511 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8513 r = MsiViewFetch(view, &rec);
8514 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8516 sz = MAX_PATH;
8517 lstrcpyA(buf, "kiwi");
8518 r = MsiRecordGetString(rec, 1, buf, &sz);
8519 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8520 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8522 r = MsiRecordGetInteger(rec, 2);
8523 ok(r == 1, "Expected 1, got %d\n", r);
8525 sz = MAX_PATH;
8526 lstrcpyA(buf, "kiwi");
8527 r = MsiRecordGetString(rec, 3, buf, &sz);
8528 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8529 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8531 MsiCloseHandle(rec);
8533 r = MsiViewFetch(view, &rec);
8534 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8536 sz = MAX_PATH;
8537 lstrcpyA(buf, "kiwi");
8538 r = MsiRecordGetString(rec, 1, buf, &sz);
8539 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8540 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8542 r = MsiRecordGetInteger(rec, 2);
8543 ok(r == 2, "Expected 2, got %d\n", r);
8545 sz = MAX_PATH;
8546 lstrcpyA(buf, "kiwi");
8547 r = MsiRecordGetString(rec, 3, buf, &sz);
8548 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8549 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8551 MsiCloseHandle(rec);
8553 r = MsiViewFetch(view, &rec);
8554 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8556 sz = MAX_PATH;
8557 lstrcpyA(buf, "kiwi");
8558 r = MsiRecordGetString(rec, 1, buf, &sz);
8559 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8560 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8562 r = MsiRecordGetInteger(rec, 2);
8563 ok(r == 3, "Expected 3, got %d\n", r);
8565 sz = MAX_PATH;
8566 lstrcpyA(buf, "kiwi");
8567 r = MsiRecordGetString(rec, 3, buf, &sz);
8568 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8569 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8571 MsiCloseHandle(rec);
8573 r = MsiViewFetch(view, &rec);
8574 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8576 sz = MAX_PATH;
8577 lstrcpyA(buf, "kiwi");
8578 r = MsiRecordGetString(rec, 1, buf, &sz);
8579 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8580 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8582 r = MsiRecordGetInteger(rec, 2);
8583 ok(r == 4, "Expected 4, got %d\n", r);
8585 sz = MAX_PATH;
8586 lstrcpyA(buf, "kiwi");
8587 r = MsiRecordGetString(rec, 3, buf, &sz);
8588 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8589 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8591 MsiCloseHandle(rec);
8593 r = MsiViewFetch(view, &rec);
8594 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8596 sz = MAX_PATH;
8597 lstrcpyA(buf, "kiwi");
8598 r = MsiRecordGetString(rec, 1, buf, &sz);
8599 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8600 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8602 r = MsiRecordGetInteger(rec, 2);
8603 ok(r == 5, "Expected 5, got %d\n", r);
8605 sz = MAX_PATH;
8606 lstrcpyA(buf, "kiwi");
8607 r = MsiRecordGetString(rec, 3, buf, &sz);
8608 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8609 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8611 MsiCloseHandle(rec);
8613 r = MsiViewFetch(view, &rec);
8614 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8616 MsiViewClose(view);
8617 MsiCloseHandle(view);
8619 query = "CREATE TABLE `Z` ( `B` SHORT NOT NULL, `C` SHORT NOT NULL, "
8620 "`A` CHAR(255), `E` INT, `D` CHAR(255) NOT NULL "
8621 "PRIMARY KEY `C`, `A`, `D`)";
8622 r = run_query(hdb, 0, query);
8623 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8625 query = "SELECT * FROM `Z`";
8626 r = MsiDatabaseOpenView(hdb, query, &view);
8627 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8629 r = MsiViewGetColumnInfo(view, MSICOLINFO_TYPES, &rec);
8630 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8632 sz = MAX_PATH;
8633 lstrcpyA(buf, "kiwi");
8634 r = MsiRecordGetString(rec, 1, buf, &sz);
8635 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8636 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8638 sz = MAX_PATH;
8639 lstrcpyA(buf, "kiwi");
8640 r = MsiRecordGetString(rec, 2, buf, &sz);
8641 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8642 ok(!lstrcmpA("S255", buf), "Expected \"S255\", got \"%s\"\n", buf);
8644 sz = MAX_PATH;
8645 lstrcpyA(buf, "kiwi");
8646 r = MsiRecordGetString(rec, 3, buf, &sz);
8647 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8648 ok(!lstrcmpA("s255", buf), "Expected \"s255\", got \"%s\"\n", buf);
8650 sz = MAX_PATH;
8651 lstrcpyA(buf, "kiwi");
8652 r = MsiRecordGetString(rec, 4, buf, &sz);
8653 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8654 ok(!lstrcmpA("I2", buf), "Expected \"I2\", got \"%s\"\n", buf);
8656 sz = MAX_PATH;
8657 lstrcpyA(buf, "kiwi");
8658 r = MsiRecordGetString(rec, 5, buf, &sz);
8659 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8660 ok(!lstrcmpA("i2", buf), "Expected \"i2\", got \"%s\"\n", buf);
8662 MsiCloseHandle(rec);
8664 r = MsiViewGetColumnInfo(view, MSICOLINFO_NAMES, &rec);
8665 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8667 sz = MAX_PATH;
8668 lstrcpyA(buf, "kiwi");
8669 r = MsiRecordGetString(rec, 1, buf, &sz);
8670 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8671 ok(!lstrcmpA("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8673 sz = MAX_PATH;
8674 lstrcpyA(buf, "kiwi");
8675 r = MsiRecordGetString(rec, 2, buf, &sz);
8676 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8677 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8679 sz = MAX_PATH;
8680 lstrcpyA(buf, "kiwi");
8681 r = MsiRecordGetString(rec, 3, buf, &sz);
8682 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8683 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8685 sz = MAX_PATH;
8686 lstrcpyA(buf, "kiwi");
8687 r = MsiRecordGetString(rec, 4, buf, &sz);
8688 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8689 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8691 sz = MAX_PATH;
8692 lstrcpyA(buf, "kiwi");
8693 r = MsiRecordGetString(rec, 5, buf, &sz);
8694 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8695 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8697 MsiCloseHandle(rec);
8698 MsiViewClose(view);
8699 MsiCloseHandle(view);
8701 query = "INSERT INTO `Z` ( `B`, `C`, `A`, `E`, `D` ) "
8702 "VALUES ( 1, 2, 'a', 3, 'bc' )";
8703 r = run_query(hdb, 0, query);
8704 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8706 query = "SELECT * FROM `Z`";
8707 r = do_query(hdb, query, &rec);
8709 r = MsiRecordGetInteger(rec, 1);
8710 ok(r == 2, "Expected 2, got %d\n", r);
8712 sz = MAX_PATH;
8713 lstrcpyA(buf, "kiwi");
8714 r = MsiRecordGetString(rec, 2, buf, &sz);
8715 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8716 ok(!lstrcmpA("a", buf), "Expected \"a\", got \"%s\"\n", buf);
8718 sz = MAX_PATH;
8719 lstrcpyA(buf, "kiwi");
8720 r = MsiRecordGetString(rec, 3, buf, &sz);
8721 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8722 ok(!lstrcmpA("bc", buf), "Expected \"bc\", got \"%s\"\n", buf);
8724 r = MsiRecordGetInteger(rec, 4);
8725 ok(r == 3, "Expected 3, got %d\n", r);
8727 r = MsiRecordGetInteger(rec, 5);
8728 ok(r == 1, "Expected 1, got %d\n", r);
8730 MsiCloseHandle(rec);
8732 query = "SELECT * FROM `_Columns` WHERE `Table` = 'T'";
8733 r = MsiDatabaseOpenView(hdb, query, &view);
8734 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8735 r = MsiViewExecute(view, 0);
8736 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8738 r = MsiViewFetch(view, &rec);
8739 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8741 sz = MAX_PATH;
8742 lstrcpyA(buf, "kiwi");
8743 r = MsiRecordGetString(rec, 1, buf, &sz);
8744 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8745 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8747 r = MsiRecordGetInteger(rec, 2);
8748 ok(r == 1, "Expected 1, got %d\n", r);
8750 sz = MAX_PATH;
8751 lstrcpyA(buf, "kiwi");
8752 r = MsiRecordGetString(rec, 3, buf, &sz);
8753 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8754 ok(!lstrcmpA("D", buf), "Expected \"D\", got \"%s\"\n", buf);
8756 MsiCloseHandle(rec);
8758 r = MsiViewFetch(view, &rec);
8759 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8761 sz = MAX_PATH;
8762 lstrcpyA(buf, "kiwi");
8763 r = MsiRecordGetString(rec, 1, buf, &sz);
8764 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8765 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8767 r = MsiRecordGetInteger(rec, 2);
8768 ok(r == 2, "Expected 2, got %d\n", r);
8770 sz = MAX_PATH;
8771 lstrcpyA(buf, "kiwi");
8772 r = MsiRecordGetString(rec, 3, buf, &sz);
8773 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8774 ok(!lstrcmpA("E", buf), "Expected \"E\", got \"%s\"\n", buf);
8776 MsiCloseHandle(rec);
8778 r = MsiViewFetch(view, &rec);
8779 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8781 sz = MAX_PATH;
8782 lstrcpyA(buf, "kiwi");
8783 r = MsiRecordGetString(rec, 1, buf, &sz);
8784 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8785 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8787 r = MsiRecordGetInteger(rec, 2);
8788 ok(r == 3, "Expected 3, got %d\n", r);
8790 sz = MAX_PATH;
8791 lstrcpyA(buf, "kiwi");
8792 r = MsiRecordGetString(rec, 3, buf, &sz);
8793 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8794 ok(!lstrcmpA("A", buf), "Expected \"A\", got \"%s\"\n", buf);
8796 MsiCloseHandle(rec);
8798 r = MsiViewFetch(view, &rec);
8799 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8801 sz = MAX_PATH;
8802 lstrcpyA(buf, "kiwi");
8803 r = MsiRecordGetString(rec, 1, buf, &sz);
8804 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8805 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8807 r = MsiRecordGetInteger(rec, 2);
8808 ok(r == 4, "Expected 4, got %d\n", r);
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("C", buf), "Expected \"C\", got \"%s\"\n", buf);
8816 MsiCloseHandle(rec);
8818 r = MsiViewFetch(view, &rec);
8819 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8821 sz = MAX_PATH;
8822 lstrcpyA(buf, "kiwi");
8823 r = MsiRecordGetString(rec, 1, buf, &sz);
8824 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8825 ok(!lstrcmpA("T", buf), "Expected \"T\", got \"%s\"\n", buf);
8827 r = MsiRecordGetInteger(rec, 2);
8828 ok(r == 5, "Expected 5, got %d\n", r);
8830 sz = MAX_PATH;
8831 lstrcpyA(buf, "kiwi");
8832 r = MsiRecordGetString(rec, 3, buf, &sz);
8833 ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
8834 ok(!lstrcmpA("B", buf), "Expected \"B\", got \"%s\"\n", buf);
8836 MsiCloseHandle(rec);
8838 r = MsiViewFetch(view, &rec);
8839 ok(r == ERROR_NO_MORE_ITEMS, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r);
8841 MsiViewClose(view);
8842 MsiCloseHandle(view);
8844 MsiCloseHandle(hdb);
8845 DeleteFileA(msifile);
8848 static void test_createtable(void)
8850 MSIHANDLE hdb, htab = 0, hrec = 0;
8851 LPCSTR query;
8852 UINT res;
8853 DWORD size;
8854 char buffer[0x20];
8856 hdb = create_db();
8857 ok(hdb, "failed to create db\n");
8859 query = "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL PRIMARY KEY `foo`)";
8860 res = MsiDatabaseOpenView( hdb, query, &htab );
8861 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8862 if(res == ERROR_SUCCESS )
8864 res = MsiViewExecute( htab, hrec );
8865 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8867 res = MsiViewGetColumnInfo( htab, MSICOLINFO_NAMES, &hrec );
8868 todo_wine ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8870 size = sizeof(buffer);
8871 res = MsiRecordGetString(hrec, 1, buffer, &size );
8872 todo_wine ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8874 res = MsiViewClose( htab );
8875 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8877 res = MsiCloseHandle( htab );
8878 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8881 query = "CREATE TABLE `a` (`b` INT PRIMARY KEY `b`)";
8882 res = MsiDatabaseOpenView( hdb, query, &htab );
8883 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8884 if(res == ERROR_SUCCESS )
8886 res = MsiViewExecute( htab, 0 );
8887 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8889 res = MsiViewClose( htab );
8890 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8892 res = MsiCloseHandle( htab );
8893 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8895 query = "SELECT * FROM `a`";
8896 res = MsiDatabaseOpenView( hdb, query, &htab );
8897 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8899 res = MsiViewGetColumnInfo( htab, MSICOLINFO_NAMES, &hrec );
8900 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8902 size = sizeof(buffer);
8903 res = MsiRecordGetString(hrec, 1, buffer, &size );
8904 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8905 ok(!strcmp(buffer,"b"), "b != %s\n", buffer);
8907 res = MsiViewClose( htab );
8908 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8910 res = MsiCloseHandle( htab );
8911 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8913 res = MsiDatabaseCommit(hdb);
8914 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8916 res = MsiCloseHandle(hdb);
8917 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8919 res = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
8920 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8922 query = "SELECT * FROM `a`";
8923 res = MsiDatabaseOpenView( hdb, query, &htab );
8924 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8926 res = MsiViewGetColumnInfo( htab, MSICOLINFO_NAMES, &hrec );
8927 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8929 size = sizeof(buffer);
8930 res = MsiRecordGetString(hrec, 1, buffer, &size );
8931 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8932 todo_wine ok(!strcmp(buffer,"b"), "b != %s\n", buffer);
8934 res = MsiCloseHandle( hrec );
8935 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8937 res = MsiViewClose( htab );
8938 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8940 res = MsiCloseHandle( htab );
8941 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8944 res = MsiDatabaseCommit(hdb);
8945 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8947 res = MsiCloseHandle(hdb);
8948 ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
8950 DeleteFileA(msifile);
8954 START_TEST(db)
8956 test_msidatabase();
8957 test_msiinsert();
8958 test_msidecomposedesc();
8959 test_msibadqueries();
8960 test_viewmodify();
8961 test_viewgetcolumninfo();
8962 test_getcolinfo();
8963 test_msiexport();
8964 test_longstrings();
8965 test_streamtable();
8966 test_binary();
8967 test_where_not_in_selected();
8968 test_where();
8969 test_msiimport();
8970 test_binary_import();
8971 test_markers();
8972 test_handle_limit();
8973 test_try_transform();
8974 test_join();
8975 test_temporary_table();
8976 test_alter();
8977 test_integers();
8978 test_update();
8979 test_special_tables();
8980 test_tables_order();
8981 test_rows_order();
8982 test_select_markers();
8983 test_viewmodify_update();
8984 test_viewmodify_assign();
8985 test_stringtable();
8986 test_viewmodify_delete();
8987 test_defaultdatabase();
8988 test_order();
8989 test_viewmodify_delete_temporary();
8990 test_deleterow();
8991 test_quotes();
8992 test_carriagereturn();
8993 test_noquotes();
8994 test_forcecodepage();
8995 test_viewmodify_refresh();
8996 test_where_viewmodify();
8997 test_storages_table();
8998 test_dbtopackage();
8999 test_droptable();
9000 test_dbmerge();
9001 test_select_with_tablenames();
9002 test_insertorder();
9003 test_columnorder();
9004 test_suminfo_import();
9005 test_createtable();