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
32 #include "wine/test.h"
34 static const char *msifile
= "winetest.msi";
35 static const char *msifile2
= "winetst2.msi";
36 static const char *mstfile
= "winetst.mst";
38 static void test_msidatabase(void)
40 MSIHANDLE hdb
= 0, hdb2
= 0;
45 res
= MsiOpenDatabase( msifile
, msifile2
, &hdb
);
46 ok( res
== ERROR_OPEN_FAILED
, "expected failure\n");
48 res
= MsiOpenDatabase( msifile
, (LPSTR
) 0xff, &hdb
);
49 ok( res
== ERROR_INVALID_PARAMETER
, "expected failure\n");
51 res
= MsiCloseHandle( hdb
);
52 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
54 /* create an empty database */
55 res
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
56 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
58 res
= MsiDatabaseCommit( hdb
);
59 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
61 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile
), "database should exist\n");
63 res
= MsiCloseHandle( hdb
);
64 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
65 res
= MsiOpenDatabase( msifile
, msifile2
, &hdb2
);
66 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
68 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile2
), "database should exist\n");
70 res
= MsiDatabaseCommit( hdb2
);
71 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
73 res
= MsiCloseHandle( hdb2
);
74 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
76 res
= MsiOpenDatabase( msifile
, msifile2
, &hdb2
);
77 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
79 res
= MsiCloseHandle( hdb2
);
80 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
82 ok( INVALID_FILE_ATTRIBUTES
== GetFileAttributes( msifile2
), "uncommitted database should not exist\n");
84 res
= MsiOpenDatabase( msifile
, msifile2
, &hdb2
);
85 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
87 res
= MsiDatabaseCommit( hdb2
);
88 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
90 res
= MsiCloseHandle( hdb2
);
91 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
93 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile2
), "committed database should exist\n");
95 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_READONLY
, &hdb
);
96 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
98 res
= MsiCloseHandle( hdb
);
99 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
101 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_DIRECT
, &hdb
);
102 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
104 res
= MsiCloseHandle( hdb
);
105 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
107 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
108 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
110 res
= MsiCloseHandle( hdb
);
111 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
112 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile
), "database should exist\n");
114 /* MSIDBOPEN_CREATE deletes the database if MsiCommitDatabase isn't called */
115 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_CREATE
, &hdb
);
116 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
118 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile
), "database should exist\n");
120 res
= MsiCloseHandle( hdb
);
121 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
123 ok( INVALID_FILE_ATTRIBUTES
== GetFileAttributes( msifile
), "database should exist\n");
125 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_CREATE
, &hdb
);
126 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
128 res
= MsiDatabaseCommit( hdb
);
129 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
131 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile
), "database should exist\n");
133 res
= MsiCloseHandle( hdb
);
134 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
136 res
= DeleteFile( msifile2
);
137 ok( res
== TRUE
, "Failed to delete database\n" );
139 res
= DeleteFile( msifile
);
140 ok( res
== TRUE
, "Failed to delete database\n" );
143 static UINT
do_query(MSIHANDLE hdb
, const char *query
, MSIHANDLE
*phrec
)
151 /* open a select query */
152 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
153 if (r
!= ERROR_SUCCESS
)
155 r
= MsiViewExecute(hview
, 0);
156 if (r
!= ERROR_SUCCESS
)
158 ret
= MsiViewFetch(hview
, phrec
);
159 r
= MsiViewClose(hview
);
160 if (r
!= ERROR_SUCCESS
)
162 r
= MsiCloseHandle(hview
);
163 if (r
!= ERROR_SUCCESS
)
168 static UINT
run_query( MSIHANDLE hdb
, MSIHANDLE hrec
, const char *query
)
173 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
174 if( r
!= ERROR_SUCCESS
)
177 r
= MsiViewExecute(hview
, hrec
);
178 if( r
== ERROR_SUCCESS
)
179 r
= MsiViewClose(hview
);
180 MsiCloseHandle(hview
);
184 static UINT
create_component_table( MSIHANDLE hdb
)
186 return run_query( hdb
, 0,
187 "CREATE TABLE `Component` ( "
188 "`Component` CHAR(72) NOT NULL, "
189 "`ComponentId` CHAR(38), "
190 "`Directory_` CHAR(72) NOT NULL, "
191 "`Attributes` SHORT NOT NULL, "
192 "`Condition` CHAR(255), "
193 "`KeyPath` CHAR(72) "
194 "PRIMARY KEY `Component`)" );
197 static UINT
create_custom_action_table( MSIHANDLE hdb
)
199 return run_query( hdb
, 0,
200 "CREATE TABLE `CustomAction` ( "
201 "`Action` CHAR(72) NOT NULL, "
202 "`Type` SHORT NOT NULL, "
203 "`Source` CHAR(72), "
204 "`Target` CHAR(255) "
205 "PRIMARY KEY `Action`)" );
208 static UINT
create_directory_table( MSIHANDLE hdb
)
210 return run_query( hdb
, 0,
211 "CREATE TABLE `Directory` ( "
212 "`Directory` CHAR(255) NOT NULL, "
213 "`Directory_Parent` CHAR(255), "
214 "`DefaultDir` CHAR(255) NOT NULL "
215 "PRIMARY KEY `Directory`)" );
218 static UINT
create_feature_components_table( MSIHANDLE hdb
)
220 return run_query( hdb
, 0,
221 "CREATE TABLE `FeatureComponents` ( "
222 "`Feature_` CHAR(38) NOT NULL, "
223 "`Component_` CHAR(72) NOT NULL "
224 "PRIMARY KEY `Feature_`, `Component_` )" );
227 static UINT
create_std_dlls_table( MSIHANDLE hdb
)
229 return run_query( hdb
, 0,
230 "CREATE TABLE `StdDlls` ( "
231 "`File` CHAR(255) NOT NULL, "
232 "`Binary_` CHAR(72) NOT NULL "
233 "PRIMARY KEY `File` )" );
236 static UINT
create_binary_table( MSIHANDLE hdb
)
238 return run_query( hdb
, 0,
239 "CREATE TABLE `Binary` ( "
240 "`Name` CHAR(72) NOT NULL, "
241 "`Data` CHAR(72) NOT NULL "
242 "PRIMARY KEY `Name` )" );
245 #define make_add_entry(type, qtext) \
246 static UINT add##_##type##_##entry( MSIHANDLE hdb, const char *values ) \
248 char insert[] = qtext; \
251 sz = strlen(values) + sizeof insert; \
252 query = HeapAlloc(GetProcessHeap(),0,sz); \
253 sprintf(query,insert,values); \
254 r = run_query( hdb, 0, query ); \
255 HeapFree(GetProcessHeap(), 0, query); \
259 make_add_entry(component
,
260 "INSERT INTO `Component` "
261 "(`Component`, `ComponentId`, `Directory_`, "
262 "`Attributes`, `Condition`, `KeyPath`) VALUES( %s )")
264 make_add_entry(custom_action
,
265 "INSERT INTO `CustomAction` "
266 "(`Action`, `Type`, `Source`, `Target`) VALUES( %s )")
268 make_add_entry(feature_components
,
269 "INSERT INTO `FeatureComponents` "
270 "(`Feature_`, `Component_`) VALUES( %s )")
272 make_add_entry(std_dlls
,
273 "INSERT INTO `StdDlls` (`File`, `Binary_`) VALUES( %s )")
275 make_add_entry(binary
,
276 "INSERT INTO `Binary` (`Name`, `Data`) VALUES( %s )")
278 static void test_msiinsert(void)
280 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
288 /* just MsiOpenDatabase should not create a file */
289 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
290 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
293 query
= "CREATE TABLE `phone` ( "
294 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
296 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
297 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
298 r
= MsiViewExecute(hview
, 0);
299 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
300 r
= MsiViewClose(hview
);
301 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
302 r
= MsiCloseHandle(hview
);
303 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
305 /* insert a value into it */
306 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
307 "VALUES('1', 'Abe', '8675309')";
308 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
309 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
310 r
= MsiViewExecute(hview
, 0);
311 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
312 r
= MsiViewClose(hview
);
313 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
314 r
= MsiCloseHandle(hview
);
315 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
317 query
= "SELECT * FROM `phone` WHERE `id` = 1";
318 r
= do_query(hdb
, query
, &hrec
);
319 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
321 /* check the record contains what we put in it */
322 r
= MsiRecordGetFieldCount(hrec
);
323 ok(r
== 3, "record count wrong\n");
325 r
= MsiRecordIsNull(hrec
, 0);
326 ok(r
== FALSE
, "field 0 not null\n");
328 r
= MsiRecordGetInteger(hrec
, 1);
329 ok(r
== 1, "field 1 contents wrong\n");
331 r
= MsiRecordGetString(hrec
, 2, buf
, &sz
);
332 ok(r
== ERROR_SUCCESS
, "field 2 content fetch failed\n");
333 ok(!strcmp(buf
,"Abe"), "field 2 content incorrect\n");
335 r
= MsiRecordGetString(hrec
, 3, buf
, &sz
);
336 ok(r
== ERROR_SUCCESS
, "field 3 content fetch failed\n");
337 ok(!strcmp(buf
,"8675309"), "field 3 content incorrect\n");
339 r
= MsiCloseHandle(hrec
);
340 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
342 /* open a select query */
344 query
= "SELECT * FROM `phone` WHERE `id` >= 10";
345 r
= do_query(hdb
, query
, &hrec
);
346 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
347 ok(hrec
== 0, "hrec should be null\n");
349 r
= MsiCloseHandle(hrec
);
350 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
352 query
= "SELECT * FROM `phone` WHERE `id` < 0";
353 r
= do_query(hdb
, query
, &hrec
);
354 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
356 query
= "SELECT * FROM `phone` WHERE `id` <= 0";
357 r
= do_query(hdb
, query
, &hrec
);
358 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
360 query
= "SELECT * FROM `phone` WHERE `id` <> 1";
361 r
= do_query(hdb
, query
, &hrec
);
362 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
364 query
= "SELECT * FROM `phone` WHERE `id` > 10";
365 r
= do_query(hdb
, query
, &hrec
);
366 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
368 /* now try a few bad INSERT xqueries */
369 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
371 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
372 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "MsiDatabaseOpenView failed\n");
374 /* construct a record to insert */
375 hrec
= MsiCreateRecord(4);
376 r
= MsiRecordSetInteger(hrec
, 1, 2);
377 ok(r
== ERROR_SUCCESS
, "MsiRecordSetInteger failed\n");
378 r
= MsiRecordSetString(hrec
, 2, "Adam");
379 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
380 r
= MsiRecordSetString(hrec
, 3, "96905305");
381 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
383 /* insert another value, using a record and wildcards */
384 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
386 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
387 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
389 if (r
== ERROR_SUCCESS
)
391 r
= MsiViewExecute(hview
, hrec
);
392 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
393 r
= MsiViewClose(hview
);
394 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
395 r
= MsiCloseHandle(hview
);
396 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
398 r
= MsiCloseHandle(hrec
);
399 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
401 r
= MsiViewFetch(0, NULL
);
402 ok(r
== ERROR_INVALID_PARAMETER
, "MsiViewFetch failed\n");
404 r
= MsiDatabaseCommit(hdb
);
405 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
407 r
= MsiCloseHandle(hdb
);
408 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
410 r
= DeleteFile(msifile
);
411 ok(r
== TRUE
, "file didn't exist after commit\n");
414 typedef UINT (WINAPI
*fnMsiDecomposeDescriptorA
)(LPCSTR
, LPCSTR
, LPSTR
, LPSTR
, DWORD
*);
415 static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA
;
417 static void test_msidecomposedesc(void)
419 char prod
[MAX_FEATURE_CHARS
+1], comp
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1];
425 hmod
= GetModuleHandle("msi.dll");
426 pMsiDecomposeDescriptorA
= (fnMsiDecomposeDescriptorA
)
427 GetProcAddress(hmod
, "MsiDecomposeDescriptorA");
428 if (!pMsiDecomposeDescriptorA
)
431 /* test a valid feature descriptor */
432 desc
= "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
434 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, comp
, &len
);
435 ok(r
== ERROR_SUCCESS
, "returned an error\n");
436 ok(len
== strlen(desc
), "length was wrong\n");
437 ok(strcmp(prod
,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
438 ok(strcmp(feature
,"FollowTheWhiteRabbit")==0, "feature wrong\n");
439 ok(strcmp(comp
,"{A7CD68DB-EF74-49C8-FBB2-A7C463B2AC24}")==0,"component wrong\n");
441 /* test an invalid feature descriptor with too many characters */
442 desc
= "']gAVn-}f(ZXfeAR6.ji"
443 "ThisWillFailIfTheresMoreThanAGuidsChars>"
444 "3w2x^IGfe?CxI5heAvk.";
446 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, comp
, &len
);
447 ok(r
== ERROR_INVALID_PARAMETER
, "returned wrong error\n");
450 * Test a valid feature descriptor with the
451 * maximum number of characters and some trailing characters.
453 desc
= "']gAVn-}f(ZXfeAR6.ji"
454 "ThisWillWorkIfTheresLTEThanAGuidsChars>"
455 "3w2x^IGfe?CxI5heAvk."
458 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, comp
, &len
);
459 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
460 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
463 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, NULL
, &len
);
464 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
465 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
468 r
= pMsiDecomposeDescriptorA(desc
, prod
, NULL
, NULL
, &len
);
469 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
470 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
473 r
= pMsiDecomposeDescriptorA(desc
, NULL
, NULL
, NULL
, &len
);
474 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
475 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
478 r
= pMsiDecomposeDescriptorA(NULL
, NULL
, NULL
, NULL
, &len
);
479 ok(r
== ERROR_INVALID_PARAMETER
, "returned wrong error\n");
480 ok(len
== 0, "length wrong\n");
483 static UINT
try_query_param( MSIHANDLE hdb
, LPCSTR szQuery
, MSIHANDLE hrec
)
488 res
= MsiDatabaseOpenView( hdb
, szQuery
, &htab
);
489 if(res
== ERROR_SUCCESS
)
493 r
= MsiViewExecute( htab
, hrec
);
494 if(r
!= ERROR_SUCCESS
)
497 r
= MsiViewClose( htab
);
498 if(r
!= ERROR_SUCCESS
)
501 r
= MsiCloseHandle( htab
);
502 if(r
!= ERROR_SUCCESS
)
508 static UINT
try_query( MSIHANDLE hdb
, LPCSTR szQuery
)
510 return try_query_param( hdb
, szQuery
, 0 );
513 static UINT
try_insert_query( MSIHANDLE hdb
, LPCSTR szQuery
)
518 hrec
= MsiCreateRecord( 1 );
519 MsiRecordSetString( hrec
, 1, "Hello");
521 r
= try_query_param( hdb
, szQuery
, hrec
);
523 MsiCloseHandle( hrec
);
527 static void test_msibadqueries(void)
534 /* just MsiOpenDatabase should not create a file */
535 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
536 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
538 r
= MsiDatabaseCommit( hdb
);
539 ok(r
== ERROR_SUCCESS
, "Failed to commit database\n");
541 r
= MsiCloseHandle( hdb
);
542 ok(r
== ERROR_SUCCESS
, "Failed to close database\n");
544 /* open it readonly */
545 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
546 ok(r
== ERROR_SUCCESS
, "Failed to open database r/o\n");
548 /* add a table to it */
549 r
= try_query( hdb
, "select * from _Tables");
550 ok(r
== ERROR_SUCCESS
, "query 1 failed\n");
552 r
= MsiCloseHandle( hdb
);
553 ok(r
== ERROR_SUCCESS
, "Failed to close database r/o\n");
555 /* open it read/write */
556 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
557 ok(r
== ERROR_SUCCESS
, "Failed to open database r/w\n");
559 /* a bunch of test queries that fail with the native MSI */
561 r
= try_query( hdb
, "CREATE TABLE");
562 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2a return code\n");
564 r
= try_query( hdb
, "CREATE TABLE `a`");
565 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2b return code\n");
567 r
= try_query( hdb
, "CREATE TABLE `a` ()");
568 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2c return code\n");
570 r
= try_query( hdb
, "CREATE TABLE `a` (`b`)");
571 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2d return code\n");
573 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) )");
574 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2e return code\n");
576 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
577 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2f return code\n");
579 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
580 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2g return code\n");
582 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
583 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2h return code\n");
585 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
586 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2i return code\n");
588 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
589 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2j return code\n");
591 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
592 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2k return code\n");
594 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
595 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2l return code\n");
597 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
598 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2m return code\n");
600 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
601 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2n return code\n");
603 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
604 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2o return code\n");
606 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
607 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2p return code\n");
609 r
= try_query( hdb
, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
610 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2p return code\n");
612 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
613 ok(r
== ERROR_SUCCESS
, "valid query 2z failed\n");
615 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
616 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created same table again\n");
618 r
= try_query( hdb
, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
619 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
620 ok(r
== ERROR_SUCCESS
, "query 4 failed\n");
622 r
= MsiDatabaseCommit( hdb
);
623 ok(r
== ERROR_SUCCESS
, "Failed to commit database after write\n");
625 r
= try_query( hdb
, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
626 "PRIMARY KEY `foo`)");
627 ok(r
== ERROR_SUCCESS
, "query 4 failed\n");
629 r
= try_insert_query( hdb
, "insert into a ( `b` ) VALUES ( ? )");
630 ok(r
== ERROR_SUCCESS
, "failed to insert record in db\n");
632 r
= MsiDatabaseCommit( hdb
);
633 ok(r
== ERROR_SUCCESS
, "Failed to commit database after write\n");
635 r
= try_query( hdb
, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
636 "PRIMARY KEY `ba`)");
637 ok(r
!= ERROR_SUCCESS
, "query 5 succeeded\n");
639 r
= try_query( hdb
,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
640 ok(r
!= ERROR_SUCCESS
, "query 6 succeeded\n");
642 r
= try_query( hdb
, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
644 ok(r
== ERROR_SUCCESS
, "query 7 failed\n");
646 r
= try_query( hdb
, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
647 ok(r
== ERROR_SUCCESS
, "query 8 failed\n");
649 r
= try_query( hdb
, "select * from c");
650 ok(r
== ERROR_SUCCESS
, "query failed\n");
652 r
= try_query( hdb
, "select * from c where b = 'x");
653 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
655 r
= try_query( hdb
, "select * from c where b = 'x'");
656 ok(r
== ERROR_SUCCESS
, "query failed\n");
658 r
= try_query( hdb
, "select * from 'c'");
659 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
661 r
= try_query( hdb
, "select * from ''");
662 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
664 r
= try_query( hdb
, "select * from c where b = x");
665 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
667 r
= try_query( hdb
, "select * from c where b = \"x\"");
668 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
670 r
= try_query( hdb
, "select * from c where b = 'x'");
671 ok(r
== ERROR_SUCCESS
, "query failed\n");
673 r
= try_query( hdb
, "select * from c where b = '\"x'");
674 ok(r
== ERROR_SUCCESS
, "query failed\n");
676 if (0) /* FIXME: this query causes trouble with other tests */
678 r
= try_query( hdb
, "select * from c where b = '\\\'x'");
679 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
682 r
= try_query( hdb
, "select * from 'c'");
683 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
685 r
= MsiCloseHandle( hdb
);
686 ok(r
== ERROR_SUCCESS
, "Failed to close database transact\n");
688 r
= DeleteFile( msifile
);
689 ok(r
== TRUE
, "file didn't exist after commit\n");
692 static void test_viewmodify(void)
694 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
703 /* just MsiOpenDatabase should not create a file */
704 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
705 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
707 query
= "CREATE TABLE `phone` ( "
708 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
710 r
= run_query( hdb
, 0, query
);
711 ok(r
== ERROR_SUCCESS
, "query failed\n");
713 /* check what the error function reports without doing anything */
715 /* passing NULL as the 3rd param make function to crash on older platforms */
716 err
= MsiViewGetError( 0, NULL
, &sz
);
717 ok(err
== MSIDBERROR_INVALIDARG
, "MsiViewGetError return\n");
720 query
= "SELECT * FROM `phone`";
721 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
722 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
724 /* see what happens with a good hview and bad args */
725 err
= MsiViewGetError( hview
, NULL
, NULL
);
726 ok(err
== MSIDBERROR_INVALIDARG
|| err
== MSIDBERROR_NOERROR
,
727 "MsiViewGetError returns %u (expected -3)\n", err
);
728 err
= MsiViewGetError( hview
, buffer
, NULL
);
729 ok(err
== MSIDBERROR_INVALIDARG
, "MsiViewGetError return\n");
731 /* see what happens with a zero length buffer */
734 err
= MsiViewGetError( hview
, buffer
, &sz
);
735 ok(err
== MSIDBERROR_MOREDATA
, "MsiViewGetError return\n");
736 ok(buffer
[0] == 'x', "buffer cleared\n");
737 ok(sz
== 0, "size not zero\n");
739 /* ok this one is strange */
741 err
= MsiViewGetError( hview
, NULL
, &sz
);
742 ok(err
== MSIDBERROR_NOERROR
, "MsiViewGetError return\n");
743 ok(sz
== 0, "size not zero\n");
745 /* see if it really has an error */
748 err
= MsiViewGetError( hview
, buffer
, &sz
);
749 ok(err
== MSIDBERROR_NOERROR
, "MsiViewGetError return\n");
750 ok(buffer
[0] == 0, "buffer not cleared\n");
751 ok(sz
== 0, "size not zero\n");
753 r
= MsiViewExecute(hview
, 0);
754 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
756 /* try some invalid records */
757 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, 0 );
758 ok(r
== ERROR_INVALID_HANDLE
, "MsiViewModify failed\n");
759 r
= MsiViewModify(hview
, -1, 0 );
760 ok(r
== ERROR_INVALID_HANDLE
, "MsiViewModify failed\n");
762 /* try an small record */
763 hrec
= MsiCreateRecord(1);
764 r
= MsiViewModify(hview
, -1, hrec
);
765 ok(r
== ERROR_INVALID_DATA
, "MsiViewModify failed\n");
767 r
= MsiCloseHandle(hrec
);
768 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
770 /* insert a valid record */
771 hrec
= MsiCreateRecord(3);
773 r
= MsiRecordSetInteger(hrec
, 1, 1);
774 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
775 r
= MsiRecordSetString(hrec
, 2, "bob");
776 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
777 r
= MsiRecordSetString(hrec
, 3, "7654321");
778 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
780 r
= MsiViewExecute(hview
, 0);
781 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
782 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
783 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
785 /* insert the same thing again */
786 r
= MsiViewExecute(hview
, 0);
787 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
789 /* should fail ... */
790 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
791 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
793 r
= MsiCloseHandle(hrec
);
794 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
796 r
= MsiViewClose(hview
);
797 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
798 r
= MsiCloseHandle(hview
);
799 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
801 query
= "SELECT * FROM `phone`";
802 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
803 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
805 r
= MsiViewExecute(hview
, 0);
806 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
808 r
= MsiViewFetch(hview
, &hrec
);
809 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
811 r
= MsiRecordGetInteger(hrec
, 1);
812 ok(r
== 1, "Expected 1, got %d\n", r
);
815 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
816 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
817 ok(!lstrcmp(buffer
, "bob"), "Expected bob, got %s\n", buffer
);
820 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
821 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
822 ok(!lstrcmp(buffer
, "7654321"), "Expected 7654321, got %s\n", buffer
);
824 /* update the view, non-primary key */
825 r
= MsiRecordSetString(hrec
, 3, "3141592");
826 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
828 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
829 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
832 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
833 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
835 /* update the view, primary key */
836 r
= MsiRecordSetInteger(hrec
, 1, 5);
837 ok(r
== ERROR_SUCCESS
, "MsiRecordSetInteger failed\n");
839 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
840 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
842 r
= MsiCloseHandle(hrec
);
843 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
845 r
= MsiViewClose(hview
);
846 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
847 r
= MsiCloseHandle(hview
);
848 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
850 query
= "SELECT * FROM `phone`";
851 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
852 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
854 r
= MsiViewExecute(hview
, 0);
855 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
857 r
= MsiViewFetch(hview
, &hrec
);
858 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
860 r
= MsiRecordGetInteger(hrec
, 1);
861 ok(r
== 1, "Expected 1, got %d\n", r
);
864 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
865 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
866 ok(!lstrcmp(buffer
, "bob"), "Expected bob, got %s\n", buffer
);
869 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
870 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
871 ok(!lstrcmp(buffer
, "3141592"), "Expected 3141592, got %s\n", buffer
);
873 r
= MsiCloseHandle(hrec
);
874 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
876 /* use a record that doesn't come from a view fetch */
877 hrec
= MsiCreateRecord(3);
878 ok(hrec
!= 0, "MsiCreateRecord failed\n");
880 r
= MsiRecordSetInteger(hrec
, 1, 3);
881 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
882 r
= MsiRecordSetString(hrec
, 2, "jane");
883 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
884 r
= MsiRecordSetString(hrec
, 3, "112358");
885 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
887 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
888 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
890 r
= MsiCloseHandle(hrec
);
891 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
893 /* use a record that doesn't come from a view fetch, primary key matches */
894 hrec
= MsiCreateRecord(3);
895 ok(hrec
!= 0, "MsiCreateRecord failed\n");
897 r
= MsiRecordSetInteger(hrec
, 1, 1);
898 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
899 r
= MsiRecordSetString(hrec
, 2, "jane");
900 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
901 r
= MsiRecordSetString(hrec
, 3, "112358");
902 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
904 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
905 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
907 r
= MsiCloseHandle(hrec
);
908 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
910 hrec
= MsiCreateRecord(3);
912 r
= MsiRecordSetInteger(hrec
, 1, 2);
913 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
914 r
= MsiRecordSetString(hrec
, 2, "nick");
915 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
916 r
= MsiRecordSetString(hrec
, 3, "141421");
917 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
919 r
= MsiViewExecute(hview
, 0);
920 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
921 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
922 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
924 r
= MsiViewClose(hview
);
925 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
926 r
= MsiCloseHandle(hview
);
927 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
929 query
= "SELECT * FROM `phone` WHERE `id` = 1";
930 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
931 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
932 r
= MsiViewExecute(hview
, 0);
933 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
934 r
= MsiViewFetch(hview
, &hrec
);
935 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
937 /* change the id to match the second row */
938 r
= MsiRecordSetInteger(hrec
, 1, 2);
939 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
940 r
= MsiRecordSetString(hrec
, 2, "jerry");
941 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
943 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
944 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
946 r
= MsiCloseHandle(hrec
);
947 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
948 r
= MsiViewClose(hview
);
949 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
950 r
= MsiCloseHandle(hview
);
951 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
954 query
= "SELECT * FROM `phone` ORDER BY `id`";
955 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
956 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
957 r
= MsiViewExecute(hview
, 0);
958 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
959 r
= MsiViewFetch(hview
, &hrec
);
960 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
962 /* change the id to match the second row */
963 r
= MsiRecordSetInteger(hrec
, 1, 2);
964 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
965 r
= MsiRecordSetString(hrec
, 2, "jerry");
966 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
968 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
969 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
971 r
= MsiCloseHandle(hrec
);
972 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
973 r
= MsiViewClose(hview
);
974 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
975 r
= MsiCloseHandle(hview
);
976 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
978 r
= MsiCloseHandle( hdb
);
979 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
982 static MSIHANDLE
create_db(void)
989 /* create an empty database */
990 res
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
991 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
992 if( res
!= ERROR_SUCCESS
)
995 res
= MsiDatabaseCommit( hdb
);
996 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
1001 static void test_getcolinfo(void)
1003 MSIHANDLE hdb
, hview
= 0, rec
= 0;
1008 /* create an empty db */
1010 ok( hdb
, "failed to create db\n");
1012 /* tables should be present */
1013 r
= MsiDatabaseOpenView(hdb
, "select * from _Tables", &hview
);
1014 ok( r
== ERROR_SUCCESS
, "failed to open query\n");
1016 r
= MsiViewExecute(hview
, 0);
1017 ok( r
== ERROR_SUCCESS
, "failed to execute query\n");
1019 /* check that NAMES works */
1021 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_NAMES
, &rec
);
1022 ok( r
== ERROR_SUCCESS
, "failed to get names\n");
1024 r
= MsiRecordGetString(rec
, 1, buffer
, &sz
);
1025 ok( r
== ERROR_SUCCESS
, "failed to get string\n");
1026 ok( !strcmp(buffer
,"Name"), "_Tables has wrong column name\n");
1027 r
= MsiCloseHandle( rec
);
1028 ok( r
== ERROR_SUCCESS
, "failed to close record handle\n");
1030 /* check that TYPES works */
1032 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_TYPES
, &rec
);
1033 ok( r
== ERROR_SUCCESS
, "failed to get names\n");
1035 r
= MsiRecordGetString(rec
, 1, buffer
, &sz
);
1036 ok( r
== ERROR_SUCCESS
, "failed to get string\n");
1037 ok( !strcmp(buffer
,"s64"), "_Tables has wrong column type\n");
1038 r
= MsiCloseHandle( rec
);
1039 ok( r
== ERROR_SUCCESS
, "failed to close record handle\n");
1041 /* check that invalid values fail */
1043 r
= MsiViewGetColumnInfo( hview
, 100, &rec
);
1044 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error code\n");
1045 ok( rec
== 0, "returned a record\n");
1047 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_TYPES
, NULL
);
1048 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error code\n");
1050 r
= MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES
, &rec
);
1051 ok( r
== ERROR_INVALID_HANDLE
, "wrong error code\n");
1053 r
= MsiViewClose(hview
);
1054 ok( r
== ERROR_SUCCESS
, "failed to close view\n");
1055 r
= MsiCloseHandle(hview
);
1056 ok( r
== ERROR_SUCCESS
, "failed to close view handle\n");
1057 r
= MsiCloseHandle(hdb
);
1058 ok( r
== ERROR_SUCCESS
, "failed to close database\n");
1061 static MSIHANDLE
get_column_info(MSIHANDLE hdb
, const char *query
, MSICOLINFO type
)
1063 MSIHANDLE hview
= 0, rec
= 0;
1066 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1067 if( r
!= ERROR_SUCCESS
)
1070 r
= MsiViewExecute(hview
, 0);
1071 if( r
== ERROR_SUCCESS
)
1073 MsiViewGetColumnInfo( hview
, type
, &rec
);
1075 MsiViewClose(hview
);
1076 MsiCloseHandle(hview
);
1080 static UINT
get_columns_table_type(MSIHANDLE hdb
, const char *table
, UINT field
)
1082 MSIHANDLE hview
= 0, rec
= 0;
1086 sprintf(query
, "select * from `_Columns` where `Table` = '%s'", table
);
1088 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1089 if( r
!= ERROR_SUCCESS
)
1092 r
= MsiViewExecute(hview
, 0);
1093 if( r
== ERROR_SUCCESS
)
1097 r
= MsiViewFetch( hview
, &rec
);
1098 if( r
!= ERROR_SUCCESS
)
1100 r
= MsiRecordGetInteger( rec
, 2 );
1102 type
= MsiRecordGetInteger( rec
, 4 );
1103 MsiCloseHandle( rec
);
1106 MsiViewClose(hview
);
1107 MsiCloseHandle(hview
);
1111 static BOOL
check_record( MSIHANDLE rec
, UINT field
, LPCSTR val
)
1118 r
= MsiRecordGetString( rec
, field
, buffer
, &sz
);
1119 return (r
== ERROR_SUCCESS
) && !strcmp(val
, buffer
);
1122 static void test_viewgetcolumninfo(void)
1124 MSIHANDLE hdb
= 0, rec
;
1128 ok( hdb
, "failed to create db\n");
1130 r
= run_query( hdb
, 0,
1131 "CREATE TABLE `Properties` "
1132 "( `Property` CHAR(255), "
1133 " `Value` CHAR(1), "
1135 " `Integervalue` INTEGER, "
1136 " `Shortvalue` SHORT, "
1137 " `Longvalue` LONG, "
1138 " `Longcharvalue` LONGCHAR "
1139 " PRIMARY KEY `Property`)" );
1140 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1142 /* check the column types */
1143 rec
= get_column_info( hdb
, "select * from `Properties`", MSICOLINFO_TYPES
);
1144 ok( rec
, "failed to get column info record\n" );
1146 ok( check_record( rec
, 1, "S255"), "wrong record type\n");
1147 ok( check_record( rec
, 2, "S1"), "wrong record type\n");
1148 ok( check_record( rec
, 3, "I2"), "wrong record type\n");
1149 ok( check_record( rec
, 4, "I2"), "wrong record type\n");
1150 ok( check_record( rec
, 5, "I2"), "wrong record type\n");
1151 ok( check_record( rec
, 6, "I4"), "wrong record type\n");
1152 ok( check_record( rec
, 7, "S0"), "wrong record type\n");
1154 MsiCloseHandle( rec
);
1156 /* check the type in _Columns */
1157 ok( 0x3dff == get_columns_table_type(hdb
, "Properties", 1 ), "_columns table wrong\n");
1158 ok( 0x1d01 == get_columns_table_type(hdb
, "Properties", 2 ), "_columns table wrong\n");
1159 ok( 0x1502 == get_columns_table_type(hdb
, "Properties", 3 ), "_columns table wrong\n");
1160 ok( 0x1502 == get_columns_table_type(hdb
, "Properties", 4 ), "_columns table wrong\n");
1161 ok( 0x1502 == get_columns_table_type(hdb
, "Properties", 5 ), "_columns table wrong\n");
1162 ok( 0x1104 == get_columns_table_type(hdb
, "Properties", 6 ), "_columns table wrong\n");
1163 ok( 0x1d00 == get_columns_table_type(hdb
, "Properties", 7 ), "_columns table wrong\n");
1165 /* now try the names */
1166 rec
= get_column_info( hdb
, "select * from `Properties`", MSICOLINFO_NAMES
);
1167 ok( rec
, "failed to get column info record\n" );
1169 ok( check_record( rec
, 1, "Property"), "wrong record type\n");
1170 ok( check_record( rec
, 2, "Value"), "wrong record type\n");
1171 ok( check_record( rec
, 3, "Intvalue"), "wrong record type\n");
1172 ok( check_record( rec
, 4, "Integervalue"), "wrong record type\n");
1173 ok( check_record( rec
, 5, "Shortvalue"), "wrong record type\n");
1174 ok( check_record( rec
, 6, "Longvalue"), "wrong record type\n");
1175 ok( check_record( rec
, 7, "Longcharvalue"), "wrong record type\n");
1177 MsiCloseHandle( rec
);
1179 r
= run_query( hdb
, 0,
1180 "CREATE TABLE `Binary` "
1181 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
1182 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1184 /* check the column types */
1185 rec
= get_column_info( hdb
, "select * from `Binary`", MSICOLINFO_TYPES
);
1186 ok( rec
, "failed to get column info record\n" );
1188 ok( check_record( rec
, 1, "S255"), "wrong record type\n");
1189 ok( check_record( rec
, 2, "V0"), "wrong record type\n");
1191 MsiCloseHandle( rec
);
1193 /* check the type in _Columns */
1194 ok( 0x3dff == get_columns_table_type(hdb
, "Binary", 1 ), "_columns table wrong\n");
1195 ok( 0x1900 == get_columns_table_type(hdb
, "Binary", 2 ), "_columns table wrong\n");
1197 /* now try the names */
1198 rec
= get_column_info( hdb
, "select * from `Binary`", MSICOLINFO_NAMES
);
1199 ok( rec
, "failed to get column info record\n" );
1201 ok( check_record( rec
, 1, "Name"), "wrong record type\n");
1202 ok( check_record( rec
, 2, "Data"), "wrong record type\n");
1203 MsiCloseHandle( rec
);
1205 r
= run_query( hdb
, 0,
1206 "CREATE TABLE `UIText` "
1207 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1208 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1210 ok( 0x2d48 == get_columns_table_type(hdb
, "UIText", 1 ), "_columns table wrong\n");
1211 ok( 0x1fff == get_columns_table_type(hdb
, "UIText", 2 ), "_columns table wrong\n");
1213 rec
= get_column_info( hdb
, "select * from `UIText`", MSICOLINFO_NAMES
);
1214 ok( rec
, "failed to get column info record\n" );
1215 ok( check_record( rec
, 1, "Key"), "wrong record type\n");
1216 ok( check_record( rec
, 2, "Text"), "wrong record type\n");
1217 MsiCloseHandle( rec
);
1219 rec
= get_column_info( hdb
, "select * from `UIText`", MSICOLINFO_TYPES
);
1220 ok( rec
, "failed to get column info record\n" );
1221 ok( check_record( rec
, 1, "s72"), "wrong record type\n");
1222 ok( check_record( rec
, 2, "L255"), "wrong record type\n");
1223 MsiCloseHandle( rec
);
1225 MsiCloseHandle( hdb
);
1228 static void test_msiexport(void)
1230 MSIHANDLE hdb
= 0, hview
= 0;
1233 char path
[MAX_PATH
];
1234 const char file
[] = "phone.txt";
1238 const char expected
[] =
1239 "id\tname\tnumber\r\n"
1242 "1\tAbe\t8675309\r\n";
1244 DeleteFile(msifile
);
1246 /* just MsiOpenDatabase should not create a file */
1247 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1248 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1250 /* create a table */
1251 query
= "CREATE TABLE `phone` ( "
1252 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1253 "PRIMARY KEY `id`)";
1254 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1255 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1256 r
= MsiViewExecute(hview
, 0);
1257 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1258 r
= MsiViewClose(hview
);
1259 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1260 r
= MsiCloseHandle(hview
);
1261 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1263 /* insert a value into it */
1264 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
1265 "VALUES('1', 'Abe', '8675309')";
1266 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1267 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1268 r
= MsiViewExecute(hview
, 0);
1269 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1270 r
= MsiViewClose(hview
);
1271 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1272 r
= MsiCloseHandle(hview
);
1273 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1275 GetCurrentDirectory(MAX_PATH
, path
);
1277 r
= MsiDatabaseExport(hdb
, "phone", path
, file
);
1278 ok(r
== ERROR_SUCCESS
, "MsiDatabaseExport failed\n");
1280 MsiCloseHandle(hdb
);
1282 lstrcat(path
, "\\");
1283 lstrcat(path
, file
);
1285 /* check the data that was written */
1287 memset(buffer
, 0, sizeof buffer
);
1288 handle
= CreateFile(path
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1289 if (handle
!= INVALID_HANDLE_VALUE
)
1291 ReadFile(handle
, buffer
, sizeof buffer
, &length
, NULL
);
1292 CloseHandle(handle
);
1296 ok(0, "failed to open file %s\n", path
);
1298 ok( length
== strlen(expected
), "length of data wrong\n");
1299 ok( !lstrcmp(buffer
, expected
), "data doesn't match\n");
1300 DeleteFile(msifile
);
1303 static void test_longstrings(void)
1305 const char insert_query
[] =
1306 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1308 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
1311 const DWORD STRING_LENGTH
= 0x10005;
1313 DeleteFile(msifile
);
1314 /* just MsiOpenDatabase should not create a file */
1315 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1316 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1318 /* create a table */
1320 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1321 ok(r
== ERROR_SUCCESS
, "query failed\n");
1323 /* try a insert a very long string */
1324 str
= HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH
+sizeof insert_query
);
1325 len
= strchr(insert_query
, 'Z') - insert_query
;
1326 strcpy(str
, insert_query
);
1327 memset(str
+len
, 'Z', STRING_LENGTH
);
1328 strcpy(str
+len
+STRING_LENGTH
, insert_query
+len
+1);
1329 r
= try_query( hdb
, str
);
1330 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1332 HeapFree(GetProcessHeap(), 0, str
);
1334 MsiDatabaseCommit(hdb
);
1335 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
1336 MsiCloseHandle(hdb
);
1338 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
1339 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1341 r
= MsiDatabaseOpenView(hdb
, "select * from `strings` where `id` = 1", &hview
);
1342 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1344 r
= MsiViewExecute(hview
, 0);
1345 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1347 r
= MsiViewFetch(hview
, &hrec
);
1348 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1350 MsiViewClose(hview
);
1351 MsiCloseHandle(hview
);
1353 r
= MsiRecordGetString(hrec
, 2, NULL
, &len
);
1354 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1355 ok(len
== STRING_LENGTH
, "string length wrong\n");
1357 MsiCloseHandle(hrec
);
1358 MsiCloseHandle(hdb
);
1359 DeleteFile(msifile
);
1362 static void create_file_data(LPCSTR name
, LPCSTR data
, DWORD size
)
1367 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
1368 if (file
== INVALID_HANDLE_VALUE
)
1371 WriteFile(file
, data
, strlen(data
), &written
, NULL
);
1372 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
1376 SetFilePointer(file
, size
, NULL
, FILE_BEGIN
);
1383 #define create_file(name) create_file_data(name, name, 0)
1385 static void test_streamtable(void)
1387 MSIHANDLE hdb
= 0, rec
, view
;
1388 char file
[MAX_PATH
];
1394 ok( hdb
, "failed to create db\n");
1396 r
= run_query( hdb
, 0,
1397 "CREATE TABLE `Properties` "
1398 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1399 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1401 r
= run_query( hdb
, 0,
1402 "INSERT INTO `Properties` "
1403 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1404 ok( r
== ERROR_SUCCESS
, "Failed to add to table\n" );
1406 r
= MsiDatabaseCommit( hdb
);
1407 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
1409 MsiCloseHandle( hdb
);
1411 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
1412 ok( r
== ERROR_SUCCESS
, "Failed to open database\n" );
1414 /* check the column types */
1415 rec
= get_column_info( hdb
, "select * from `_Streams`", MSICOLINFO_TYPES
);
1416 ok( rec
, "failed to get column info record\n" );
1418 ok( check_record( rec
, 1, "s62"), "wrong record type\n");
1419 ok( check_record( rec
, 2, "V0"), "wrong record type\n");
1421 MsiCloseHandle( rec
);
1423 /* now try the names */
1424 rec
= get_column_info( hdb
, "select * from `_Streams`", MSICOLINFO_NAMES
);
1425 ok( rec
, "failed to get column info record\n" );
1427 ok( check_record( rec
, 1, "Name"), "wrong record type\n");
1428 ok( check_record( rec
, 2, "Data"), "wrong record type\n");
1430 MsiCloseHandle( rec
);
1432 /* insert a file into the _Streams table */
1433 create_file( "test.txt" );
1435 rec
= MsiCreateRecord( 2 );
1436 MsiRecordSetString( rec
, 1, "data" );
1438 r
= MsiRecordSetStream( rec
, 2, "test.txt" );
1439 ok( r
== ERROR_SUCCESS
, "Failed to add stream data to the record: %d\n", r
);
1441 DeleteFile("test.txt");
1443 r
= MsiDatabaseOpenView( hdb
,
1444 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view
);
1445 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1447 r
= MsiViewExecute( view
, rec
);
1448 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1450 MsiCloseHandle( rec
);
1451 MsiViewClose( view
);
1452 MsiCloseHandle( view
);
1454 r
= MsiDatabaseOpenView( hdb
,
1455 "SELECT `Name`, `Data` FROM `_Streams`", &view
);
1456 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1458 r
= MsiViewExecute( view
, 0 );
1459 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1461 r
= MsiViewFetch( view
, &rec
);
1462 ok( r
== ERROR_SUCCESS
, "Failed to fetch record: %d\n", r
);
1465 r
= MsiRecordGetString( rec
, 1, file
, &size
);
1466 ok( r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
1467 ok( !lstrcmp(file
, "data"), "Expected 'data', got %s\n", file
);
1470 memset(buf
, 0, MAX_PATH
);
1471 r
= MsiRecordReadStream( rec
, 2, buf
, &size
);
1472 ok( r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
1473 ok( !lstrcmp(buf
, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf
);
1475 MsiCloseHandle( rec
);
1477 r
= MsiViewFetch( view
, &rec
);
1478 ok( r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
1480 MsiViewClose( view
);
1481 MsiCloseHandle( view
);
1482 MsiCloseHandle( hdb
);
1483 DeleteFile(msifile
);
1486 static void test_binary(void)
1488 MSIHANDLE hdb
= 0, rec
;
1489 char file
[MAX_PATH
];
1495 /* insert a file into the Binary table */
1496 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1497 ok( r
== ERROR_SUCCESS
, "Failed to open database\n" );
1499 query
= "CREATE TABLE `Binary` ( `Name` CHAR(72) NOT NULL, `ID` INT NOT NULL, `Data` OBJECT PRIMARY KEY `Name`, `ID`)";
1500 r
= run_query( hdb
, 0, query
);
1501 ok( r
== ERROR_SUCCESS
, "Cannot create Binary table: %d\n", r
);
1503 create_file( "test.txt" );
1504 rec
= MsiCreateRecord( 1 );
1505 r
= MsiRecordSetStream( rec
, 1, "test.txt" );
1506 ok( r
== ERROR_SUCCESS
, "Failed to add stream data to the record: %d\n", r
);
1507 DeleteFile( "test.txt" );
1509 query
= "INSERT INTO `Binary` ( `Name`, `ID`, `Data` ) VALUES ( 'filename1', 1, ? )";
1510 r
= run_query( hdb
, rec
, query
);
1511 ok( r
== ERROR_SUCCESS
, "Insert into Binary table failed: %d\n", r
);
1513 r
= MsiCloseHandle( rec
);
1514 ok( r
== ERROR_SUCCESS
, "Failed to close record handle\n" );
1516 r
= MsiDatabaseCommit( hdb
);
1517 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
1519 r
= MsiCloseHandle( hdb
);
1520 ok( r
== ERROR_SUCCESS
, "Failed to close database\n" );
1522 /* read file from the Stream table */
1523 r
= MsiOpenDatabase( msifile
, MSIDBOPEN_READONLY
, &hdb
);
1524 ok( r
== ERROR_SUCCESS
, "Failed to open database\n" );
1526 query
= "SELECT * FROM `_Streams`";
1527 r
= do_query( hdb
, query
, &rec
);
1528 ok( r
== ERROR_SUCCESS
, "SELECT query failed: %d\n", r
);
1531 r
= MsiRecordGetString( rec
, 1, file
, &size
);
1532 ok( r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
1533 ok( !lstrcmp(file
, "Binary.filename1.1"), "Expected 'Binary.filename1.1', got %s\n", file
);
1536 memset( buf
, 0, MAX_PATH
);
1537 r
= MsiRecordReadStream( rec
, 2, buf
, &size
);
1538 ok( r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
1539 ok( !lstrcmp(buf
, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf
);
1541 r
= MsiCloseHandle( rec
);
1542 ok( r
== ERROR_SUCCESS
, "Failed to close record handle\n" );
1544 /* read file from the Binary table */
1545 query
= "SELECT * FROM `Binary`";
1546 r
= do_query( hdb
, query
, &rec
);
1547 ok( r
== ERROR_SUCCESS
, "SELECT query failed: %d\n", r
);
1550 r
= MsiRecordGetString( rec
, 1, file
, &size
);
1551 ok( r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
1552 ok( !lstrcmp(file
, "filename1"), "Expected 'filename1', got %s\n", file
);
1555 memset( buf
, 0, MAX_PATH
);
1556 r
= MsiRecordReadStream( rec
, 3, buf
, &size
);
1557 ok( r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
1558 ok( !lstrcmp(buf
, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf
);
1560 r
= MsiCloseHandle( rec
);
1561 ok( r
== ERROR_SUCCESS
, "Failed to close record handle\n" );
1563 r
= MsiCloseHandle( hdb
);
1564 ok( r
== ERROR_SUCCESS
, "Failed to close database\n" );
1566 DeleteFile( msifile
);
1569 static void test_where(void)
1571 MSIHANDLE hdb
= 0, rec
, view
;
1579 ok( hdb
, "failed to create db\n");
1581 r
= run_query( hdb
, 0,
1582 "CREATE TABLE `Media` ("
1583 "`DiskId` SHORT NOT NULL, "
1584 "`LastSequence` LONG, "
1585 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1586 "`Cabinet` CHAR(255), "
1587 "`VolumeLabel` CHAR(32), "
1588 "`Source` CHAR(72) "
1589 "PRIMARY KEY `DiskId`)" );
1590 ok( r
== S_OK
, "cannot create Media table: %d\n", r
);
1592 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1593 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1594 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1595 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1597 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1598 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1599 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1600 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1602 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1603 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1604 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1605 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1607 query
= "SELECT * FROM `Media`";
1608 r
= do_query(hdb
, query
, &rec
);
1609 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed: %d\n", r
);
1610 ok( check_record( rec
, 4, "zero.cab"), "wrong cabinet\n");
1611 MsiCloseHandle( rec
);
1613 query
= "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1614 r
= do_query(hdb
, query
, &rec
);
1615 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed: %d\n", r
);
1616 ok( check_record( rec
, 4, "one.cab"), "wrong cabinet\n");
1618 r
= MsiRecordGetInteger(rec
, 1);
1619 ok( 2 == r
, "field wrong\n");
1620 r
= MsiRecordGetInteger(rec
, 2);
1621 ok( 1 == r
, "field wrong\n");
1622 MsiCloseHandle( rec
);
1624 query
= "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1625 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1626 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
1628 r
= MsiViewExecute(view
, 0);
1629 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
1631 r
= MsiViewFetch(view
, &rec
);
1632 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1634 count
= MsiRecordGetFieldCount( rec
);
1635 ok( count
== 1, "Expected 1 record fields, got %d\n", count
);
1638 r
= MsiRecordGetString( rec
, 1, buf
, &size
);
1639 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
1640 ok( !lstrcmp( buf
, "2" ),
1641 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf
);
1642 MsiCloseHandle( rec
);
1644 r
= MsiViewFetch(view
, &rec
);
1645 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1648 r
= MsiRecordGetString( rec
, 1, buf
, &size
);
1649 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
1650 ok( !lstrcmp( buf
, "3" ),
1651 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf
);
1652 MsiCloseHandle( rec
);
1654 r
= MsiViewFetch(view
, &rec
);
1655 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
1658 MsiCloseHandle(view
);
1660 MsiCloseHandle( rec
);
1663 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1664 r
= do_query(hdb
, query
, &rec
);
1665 ok( r
== ERROR_SUCCESS
, "query failed: %d\n", r
);
1666 MsiCloseHandle( rec
);
1668 rec
= MsiCreateRecord(1);
1669 MsiRecordSetString(rec
, 1, "");
1671 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` = ?";
1672 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1673 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1674 r
= MsiViewExecute(view
, rec
);
1675 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1677 MsiCloseHandle(rec
);
1679 r
= MsiViewFetch(view
, &rec
);
1680 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1682 MsiCloseHandle(rec
);
1684 MsiCloseHandle(view
);
1686 MsiCloseHandle( hdb
);
1687 DeleteFile(msifile
);
1690 static CHAR CURR_DIR
[MAX_PATH
];
1692 static const CHAR test_data
[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1693 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1694 "TestTable\tFirstPrimaryColumn\n"
1695 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1697 static const CHAR two_primary
[] = "PrimaryOne\tPrimaryTwo\n"
1699 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1703 static const CHAR endlines1
[] = "A\tB\tC\tD\tE\tF\r\n"
1704 "s72\ts72\ts72\ts72\ts72\ts72\n"
1706 "a\tb\tc\td\te\tf\n"
1707 "g\th\ti\t\rj\tk\tl\r\n";
1709 static const CHAR endlines2
[] = "A\tB\tC\tD\tE\tF\r"
1710 "s72\ts72\ts72\ts72\ts72\ts72\n"
1712 "a\tb\tc\td\te\tf\n"
1713 "g\th\ti\tj\tk\tl\r\n";
1715 static const CHAR suminfo
[] = "PropertyId\tValue\n"
1717 "_SummaryInformation\tPropertyId\n"
1719 "2\tInstaller Database\n"
1720 "3\tInstaller description\n"
1723 "6\tInstaller comments\n"
1725 "9\t{12345678-1234-1234-1234-123456789012}\n"
1726 "12\t2009/04/12 15:46:11\n"
1727 "13\t2009/04/12 15:46:11\n"
1733 static void write_file(const CHAR
*filename
, const char *data
, int data_size
)
1737 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
1738 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1740 WriteFile(hf
, data
, data_size
, &size
, NULL
);
1744 static UINT
add_table_to_db(MSIHANDLE hdb
, LPCSTR table_data
)
1748 write_file("temp_file", table_data
, (lstrlen(table_data
) - 1) * sizeof(char));
1749 r
= MsiDatabaseImportA(hdb
, CURR_DIR
, "temp_file");
1750 DeleteFileA("temp_file");
1755 static void test_suminfo_import(void)
1757 MSIHANDLE hdb
, hsi
, view
= 0;
1759 UINT r
, count
, size
, type
;
1764 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
1766 r
= MsiOpenDatabaseA(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1767 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1769 r
= add_table_to_db(hdb
, suminfo
);
1770 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1772 /* _SummaryInformation is not imported as a regular table... */
1774 query
= "SELECT * FROM `_SummaryInformation`";
1775 r
= MsiDatabaseOpenViewA(hdb
, query
, &view
);
1776 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %u\n", r
);
1777 MsiCloseHandle(view
);
1779 /* ...its data is added to the special summary information stream */
1781 r
= MsiGetSummaryInformationA(hdb
, NULL
, 0, &hsi
);
1782 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1784 r
= MsiSummaryInfoGetPropertyCount(hsi
, &count
);
1785 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1786 ok(count
== 14, "Expected 14, got %u\n", count
);
1788 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_CODEPAGE
, &type
, &int_value
, NULL
, NULL
, NULL
);
1789 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1790 ok(type
== VT_I2
, "Expected VT_I2, got %u\n", type
);
1791 ok(int_value
== 1252, "Expected 1252, got %d\n", int_value
);
1793 size
= sizeof(str_value
);
1794 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_TITLE
, &type
, NULL
, NULL
, str_value
, &size
);
1795 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1796 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
1797 ok(size
== 18, "Expected 18, got %u\n", size
);
1798 ok(!strcmp(str_value
, "Installer Database"),
1799 "Expected \"Installer Database\", got %s\n", str_value
);
1801 size
= sizeof(str_value
);
1802 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_SUBJECT
, &type
, NULL
, NULL
, str_value
, &size
);
1803 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1804 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
1805 ok(!strcmp(str_value
, "Installer description"),
1806 "Expected \"Installer description\", got %s\n", str_value
);
1808 size
= sizeof(str_value
);
1809 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_AUTHOR
, &type
, NULL
, NULL
, str_value
, &size
);
1810 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1811 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
1812 ok(!strcmp(str_value
, "WineHQ"),
1813 "Expected \"WineHQ\", got %s\n", str_value
);
1815 size
= sizeof(str_value
);
1816 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_KEYWORDS
, &type
, NULL
, NULL
, str_value
, &size
);
1817 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1818 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
1819 ok(!strcmp(str_value
, "Installer"),
1820 "Expected \"Installer\", got %s\n", str_value
);
1822 size
= sizeof(str_value
);
1823 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_COMMENTS
, &type
, NULL
, NULL
, str_value
, &size
);
1824 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1825 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
1826 ok(!strcmp(str_value
, "Installer comments"),
1827 "Expected \"Installer comments\", got %s\n", str_value
);
1829 size
= sizeof(str_value
);
1830 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_TEMPLATE
, &type
, NULL
, NULL
, str_value
, &size
);
1831 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1832 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
1833 ok(!strcmp(str_value
, "Intel;1033"),
1834 "Expected \"Intel;1033\", got %s\n", str_value
);
1836 size
= sizeof(str_value
);
1837 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_REVNUMBER
, &type
, NULL
, NULL
, str_value
, &size
);
1838 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1839 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
1840 ok(!strcmp(str_value
, "{12345678-1234-1234-1234-123456789012}"),
1841 "Expected \"{12345678-1234-1234-1234-123456789012}\", got %s\n", str_value
);
1843 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_CREATE_DTM
, &type
, NULL
, &ft_value
, NULL
, NULL
);
1844 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1845 ok(type
== VT_FILETIME
, "Expected VT_FILETIME, got %u\n", type
);
1847 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_LASTSAVE_DTM
, &type
, NULL
, &ft_value
, NULL
, NULL
);
1848 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1849 ok(type
== VT_FILETIME
, "Expected VT_FILETIME, got %u\n", type
);
1851 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_PAGECOUNT
, &type
, &int_value
, NULL
, NULL
, NULL
);
1852 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1853 ok(type
== VT_I4
, "Expected VT_I4, got %u\n", type
);
1854 ok(int_value
== 200, "Expected 200, got %d\n", int_value
);
1856 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_WORDCOUNT
, &type
, &int_value
, NULL
, NULL
, NULL
);
1857 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1858 ok(type
== VT_I4
, "Expected VT_I4, got %u\n", type
);
1859 ok(int_value
== 2, "Expected 2, got %d\n", int_value
);
1861 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_SECURITY
, &type
, &int_value
, NULL
, NULL
, NULL
);
1862 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1863 ok(type
== VT_I4
, "Expected VT_I4, got %u\n", type
);
1864 ok(int_value
== 2, "Expected 2, got %d\n", int_value
);
1866 size
= sizeof(str_value
);
1867 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_APPNAME
, &type
, NULL
, NULL
, str_value
, &size
);
1868 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
1869 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
1870 ok(!strcmp(str_value
, "Vim"), "Expected \"Vim\", got %s\n", str_value
);
1872 MsiCloseHandle(hsi
);
1873 MsiCloseHandle(hdb
);
1874 DeleteFileA(msifile
);
1877 static void test_msiimport(void)
1879 MSIHANDLE hdb
, view
, rec
;
1884 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
1886 r
= MsiOpenDatabaseA(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1887 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1889 r
= add_table_to_db(hdb
, test_data
);
1890 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1892 r
= add_table_to_db(hdb
, two_primary
);
1893 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1895 r
= add_table_to_db(hdb
, endlines1
);
1896 if (r
== ERROR_FUNCTION_FAILED
)
1898 /* win9x doesn't handle this case */
1899 skip("endlines not handled correctly.\n");
1900 MsiCloseHandle(hdb
);
1901 DeleteFileA(msifile
);
1905 r
= add_table_to_db(hdb
, endlines2
);
1906 ok(r
== ERROR_FUNCTION_FAILED
,
1907 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
1909 query
= "SELECT * FROM `TestTable`";
1910 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1911 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1913 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
1914 count
= MsiRecordGetFieldCount(rec
);
1915 ok(count
== 9, "Expected 9, got %d\n", count
);
1916 ok(check_record(rec
, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
1917 ok(check_record(rec
, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
1918 ok(check_record(rec
, 3, "ShortInt"), "Expected ShortInt\n");
1919 ok(check_record(rec
, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
1920 ok(check_record(rec
, 5, "LongInt"), "Expected LongInt\n");
1921 ok(check_record(rec
, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
1922 ok(check_record(rec
, 7, "String"), "Expected String\n");
1923 ok(check_record(rec
, 8, "LocalizableString"), "Expected LocalizableString\n");
1924 ok(check_record(rec
, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
1925 MsiCloseHandle(rec
);
1927 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1928 count
= MsiRecordGetFieldCount(rec
);
1929 ok(count
== 9, "Expected 9, got %d\n", count
);
1930 ok(check_record(rec
, 1, "s255"), "Expected s255\n");
1931 ok(check_record(rec
, 2, "i2"), "Expected i2\n");
1932 ok(check_record(rec
, 3, "i2"), "Expected i2\n");
1933 ok(check_record(rec
, 4, "I2"), "Expected I2\n");
1934 ok(check_record(rec
, 5, "i4"), "Expected i4\n");
1935 ok(check_record(rec
, 6, "I4"), "Expected I4\n");
1936 ok(check_record(rec
, 7, "S255"), "Expected S255\n");
1937 ok(check_record(rec
, 8, "S0"), "Expected S0\n");
1938 ok(check_record(rec
, 9, "s0"), "Expected s0\n");
1939 MsiCloseHandle(rec
);
1941 query
= "SELECT * FROM `TestTable`";
1942 r
= do_query(hdb
, query
, &rec
);
1943 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1944 ok(check_record(rec
, 1, "stringage"), "Expected 'stringage'\n");
1945 ok(check_record(rec
, 7, "another string"), "Expected 'another string'\n");
1946 ok(check_record(rec
, 8, "localizable"), "Expected 'localizable'\n");
1947 ok(check_record(rec
, 9, "duh"), "Expected 'duh'\n");
1949 i
= MsiRecordGetInteger(rec
, 2);
1950 ok(i
== 5, "Expected 5, got %d\n", i
);
1952 i
= MsiRecordGetInteger(rec
, 3);
1953 ok(i
== 2, "Expected 2, got %d\n", i
);
1955 i
= MsiRecordGetInteger(rec
, 4);
1956 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
1958 i
= MsiRecordGetInteger(rec
, 5);
1959 ok(i
== 2147483640, "Expected 2147483640, got %d\n", i
);
1961 i
= MsiRecordGetInteger(rec
, 6);
1962 ok(i
== -2147483640, "Expected -2147483640, got %d\n", i
);
1964 MsiCloseHandle(rec
);
1966 MsiCloseHandle(view
);
1968 query
= "SELECT * FROM `TwoPrimary`";
1969 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1970 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1972 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
1973 count
= MsiRecordGetFieldCount(rec
);
1974 ok(count
== 2, "Expected 2, got %d\n", count
);
1975 ok(check_record(rec
, 1, "PrimaryOne"), "Expected PrimaryOne\n");
1976 ok(check_record(rec
, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
1978 MsiCloseHandle(rec
);
1980 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1981 count
= MsiRecordGetFieldCount(rec
);
1982 ok(count
== 2, "Expected 2, got %d\n", count
);
1983 ok(check_record(rec
, 1, "s255"), "Expected s255\n");
1984 ok(check_record(rec
, 2, "s255"), "Expected s255\n");
1985 MsiCloseHandle(rec
);
1987 r
= MsiViewExecute(view
, 0);
1988 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1990 r
= MsiViewFetch(view
, &rec
);
1991 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1993 ok(check_record(rec
, 1, "papaya"), "Expected 'papaya'\n");
1994 ok(check_record(rec
, 2, "leaf"), "Expected 'leaf'\n");
1996 MsiCloseHandle(rec
);
1998 r
= MsiViewFetch(view
, &rec
);
1999 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2001 ok(check_record(rec
, 1, "papaya"), "Expected 'papaya'\n");
2002 ok(check_record(rec
, 2, "flower"), "Expected 'flower'\n");
2004 MsiCloseHandle(rec
);
2006 r
= MsiViewFetch(view
, &rec
);
2007 ok(r
== ERROR_NO_MORE_ITEMS
,
2008 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
2010 r
= MsiViewClose(view
);
2011 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2013 MsiCloseHandle(view
);
2015 query
= "SELECT * FROM `Table`";
2016 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2017 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2019 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
2020 count
= MsiRecordGetFieldCount(rec
);
2021 ok(count
== 6, "Expected 6, got %d\n", count
);
2022 ok(check_record(rec
, 1, "A"), "Expected A\n");
2023 ok(check_record(rec
, 2, "B"), "Expected B\n");
2024 ok(check_record(rec
, 3, "C"), "Expected C\n");
2025 ok(check_record(rec
, 4, "D"), "Expected D\n");
2026 ok(check_record(rec
, 5, "E"), "Expected E\n");
2027 ok(check_record(rec
, 6, "F"), "Expected F\n");
2028 MsiCloseHandle(rec
);
2030 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
2031 count
= MsiRecordGetFieldCount(rec
);
2032 ok(count
== 6, "Expected 6, got %d\n", count
);
2033 ok(check_record(rec
, 1, "s72"), "Expected s72\n");
2034 ok(check_record(rec
, 2, "s72"), "Expected s72\n");
2035 ok(check_record(rec
, 3, "s72"), "Expected s72\n");
2036 ok(check_record(rec
, 4, "s72"), "Expected s72\n");
2037 ok(check_record(rec
, 5, "s72"), "Expected s72\n");
2038 ok(check_record(rec
, 6, "s72"), "Expected s72\n");
2039 MsiCloseHandle(rec
);
2042 MsiCloseHandle(view
);
2044 query
= "SELECT * FROM `Table`";
2045 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2046 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2048 r
= MsiViewExecute(view
, 0);
2049 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2051 r
= MsiViewFetch(view
, &rec
);
2052 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2053 ok(check_record(rec
, 1, "a"), "Expected 'a'\n");
2054 ok(check_record(rec
, 2, "b"), "Expected 'b'\n");
2055 ok(check_record(rec
, 3, "c"), "Expected 'c'\n");
2056 ok(check_record(rec
, 4, "d"), "Expected 'd'\n");
2057 ok(check_record(rec
, 5, "e"), "Expected 'e'\n");
2058 ok(check_record(rec
, 6, "f"), "Expected 'f'\n");
2060 MsiCloseHandle(rec
);
2062 r
= MsiViewFetch(view
, &rec
);
2063 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2064 ok(check_record(rec
, 1, "g"), "Expected 'g'\n");
2065 ok(check_record(rec
, 2, "h"), "Expected 'h'\n");
2066 ok(check_record(rec
, 3, "i"), "Expected 'i'\n");
2067 ok(check_record(rec
, 4, "j"), "Expected 'j'\n");
2068 ok(check_record(rec
, 5, "k"), "Expected 'k'\n");
2069 ok(check_record(rec
, 6, "l"), "Expected 'l'\n");
2071 MsiCloseHandle(rec
);
2073 r
= MsiViewFetch(view
, &rec
);
2074 ok(r
== ERROR_NO_MORE_ITEMS
,
2075 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
2078 MsiCloseHandle(view
);
2079 MsiCloseHandle(hdb
);
2080 DeleteFileA(msifile
);
2083 static const CHAR bin_import_dat
[] = "Name\tData\r\n"
2086 "filename1\tfilename1.ibd\r\n";
2088 static void test_binary_import(void)
2090 MSIHANDLE hdb
= 0, rec
;
2091 char file
[MAX_PATH
];
2093 char path
[MAX_PATH
];
2098 /* create files to import */
2099 write_file("bin_import.idt", bin_import_dat
,
2100 (sizeof(bin_import_dat
) - 1) * sizeof(char));
2101 CreateDirectory("bin_import", NULL
);
2102 create_file_data("bin_import/filename1.ibd", "just some words", 15);
2104 /* import files into database */
2105 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
2106 ok( r
== ERROR_SUCCESS
, "Failed to open database\n");
2108 GetCurrentDirectory(MAX_PATH
, path
);
2109 r
= MsiDatabaseImport(hdb
, path
, "bin_import.idt");
2110 ok(r
== ERROR_SUCCESS
, "Failed to import Binary table\n");
2112 /* read file from the Binary table */
2113 query
= "SELECT * FROM `Binary`";
2114 r
= do_query(hdb
, query
, &rec
);
2115 ok(r
== ERROR_SUCCESS
, "SELECT query failed: %d\n", r
);
2118 r
= MsiRecordGetString(rec
, 1, file
, &size
);
2119 ok(r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
2120 ok(!lstrcmp(file
, "filename1"), "Expected 'filename1', got %s\n", file
);
2123 memset(buf
, 0, MAX_PATH
);
2124 r
= MsiRecordReadStream(rec
, 2, buf
, &size
);
2125 ok(r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
2126 ok(!lstrcmp(buf
, "just some words"),
2127 "Expected 'just some words', got %s\n", buf
);
2129 r
= MsiCloseHandle(rec
);
2130 ok(r
== ERROR_SUCCESS
, "Failed to close record handle\n");
2132 r
= MsiCloseHandle(hdb
);
2133 ok(r
== ERROR_SUCCESS
, "Failed to close database\n");
2135 DeleteFile("bin_import/filename1.ibd");
2136 RemoveDirectory("bin_import");
2137 DeleteFile("bin_import.idt");
2140 static void test_markers(void)
2147 ok( hdb
, "failed to create db\n");
2149 rec
= MsiCreateRecord(3);
2150 MsiRecordSetString(rec
, 1, "Table");
2151 MsiRecordSetString(rec
, 2, "Apples");
2152 MsiRecordSetString(rec
, 3, "Oranges");
2154 /* try a legit create */
2155 query
= "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2156 r
= run_query(hdb
, 0, query
);
2157 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2158 MsiCloseHandle(rec
);
2160 /* try table name as marker */
2161 rec
= MsiCreateRecord(1);
2162 MsiRecordSetString(rec
, 1, "Fable");
2163 query
= "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2164 r
= run_query(hdb
, rec
, query
);
2165 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2167 /* verify that we just created a table called '?', not 'Fable' */
2168 r
= try_query(hdb
, "SELECT * from `Fable`");
2169 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2171 r
= try_query(hdb
, "SELECT * from `?`");
2172 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2174 /* try table name as marker without backticks */
2175 MsiRecordSetString(rec
, 1, "Mable");
2176 query
= "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2177 r
= run_query(hdb
, rec
, query
);
2178 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2180 /* try one column name as marker */
2181 MsiRecordSetString(rec
, 1, "One");
2182 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2183 r
= run_query(hdb
, rec
, query
);
2184 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2185 MsiCloseHandle(rec
);
2187 /* try column names as markers */
2188 rec
= MsiCreateRecord(2);
2189 MsiRecordSetString(rec
, 1, "One");
2190 MsiRecordSetString(rec
, 2, "Two");
2191 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
2192 r
= run_query(hdb
, rec
, query
);
2193 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2194 MsiCloseHandle(rec
);
2196 /* try names with backticks */
2197 rec
= MsiCreateRecord(3);
2198 MsiRecordSetString(rec
, 1, "One");
2199 MsiRecordSetString(rec
, 2, "Two");
2200 MsiRecordSetString(rec
, 3, "One");
2201 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
2202 r
= run_query(hdb
, rec
, query
);
2203 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2205 /* try names with backticks, minus definitions */
2206 query
= "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
2207 r
= run_query(hdb
, rec
, query
);
2208 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2210 /* try names without backticks */
2211 query
= "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
2212 r
= run_query(hdb
, rec
, query
);
2213 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2214 MsiCloseHandle(rec
);
2216 /* try one long marker */
2217 rec
= MsiCreateRecord(1);
2218 MsiRecordSetString(rec
, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
2219 query
= "CREATE TABLE `Mable` ( ? )";
2220 r
= run_query(hdb
, rec
, query
);
2221 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2222 MsiCloseHandle(rec
);
2224 /* try all names as markers */
2225 rec
= MsiCreateRecord(4);
2226 MsiRecordSetString(rec
, 1, "Mable");
2227 MsiRecordSetString(rec
, 2, "One");
2228 MsiRecordSetString(rec
, 3, "Two");
2229 MsiRecordSetString(rec
, 4, "One");
2230 query
= "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
2231 r
= run_query(hdb
, rec
, query
);
2232 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2233 MsiCloseHandle(rec
);
2235 /* try a legit insert */
2236 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
2237 r
= run_query(hdb
, 0, query
);
2238 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2240 r
= try_query(hdb
, "SELECT * from `Table`");
2241 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2243 /* try values as markers */
2244 rec
= MsiCreateRecord(2);
2245 MsiRecordSetInteger(rec
, 1, 4);
2246 MsiRecordSetString(rec
, 2, "hi");
2247 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2248 r
= run_query(hdb
, rec
, query
);
2249 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2250 MsiCloseHandle(rec
);
2252 /* try column names and values as markers */
2253 rec
= MsiCreateRecord(4);
2254 MsiRecordSetString(rec
, 1, "One");
2255 MsiRecordSetString(rec
, 2, "Two");
2256 MsiRecordSetInteger(rec
, 3, 5);
2257 MsiRecordSetString(rec
, 4, "hi");
2258 query
= "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
2259 r
= run_query(hdb
, rec
, query
);
2260 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2261 MsiCloseHandle(rec
);
2263 /* try column names as markers */
2264 rec
= MsiCreateRecord(2);
2265 MsiRecordSetString(rec
, 1, "One");
2266 MsiRecordSetString(rec
, 2, "Two");
2267 query
= "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
2268 r
= run_query(hdb
, rec
, query
);
2269 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2270 MsiCloseHandle(rec
);
2272 /* try table name as a marker */
2273 rec
= MsiCreateRecord(1);
2274 MsiRecordSetString(rec
, 1, "Table");
2275 query
= "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
2276 r
= run_query(hdb
, rec
, query
);
2277 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2278 MsiCloseHandle(rec
);
2280 /* try table name and values as markers */
2281 rec
= MsiCreateRecord(3);
2282 MsiRecordSetString(rec
, 1, "Table");
2283 MsiRecordSetInteger(rec
, 2, 10);
2284 MsiRecordSetString(rec
, 3, "haha");
2285 query
= "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
2286 r
= run_query(hdb
, rec
, query
);
2287 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
2288 MsiCloseHandle(rec
);
2290 /* try all markers */
2291 rec
= MsiCreateRecord(5);
2292 MsiRecordSetString(rec
, 1, "Table");
2293 MsiRecordSetString(rec
, 1, "One");
2294 MsiRecordSetString(rec
, 1, "Two");
2295 MsiRecordSetInteger(rec
, 2, 10);
2296 MsiRecordSetString(rec
, 3, "haha");
2297 query
= "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
2298 r
= run_query(hdb
, rec
, query
);
2299 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2300 MsiCloseHandle(rec
);
2302 /* insert an integer as a string */
2303 rec
= MsiCreateRecord(2);
2304 MsiRecordSetString(rec
, 1, "11");
2305 MsiRecordSetString(rec
, 2, "hi");
2306 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2307 r
= run_query(hdb
, rec
, query
);
2308 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2309 MsiCloseHandle(rec
);
2311 /* leave off the '' for the string */
2312 rec
= MsiCreateRecord(2);
2313 MsiRecordSetInteger(rec
, 1, 12);
2314 MsiRecordSetString(rec
, 2, "hi");
2315 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
2316 r
= run_query(hdb
, rec
, query
);
2317 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2318 MsiCloseHandle(rec
);
2320 MsiCloseHandle(hdb
);
2321 DeleteFileA(msifile
);
2324 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
2325 static void test_handle_limit(void)
2329 MSIHANDLE hviews
[MY_NVIEWS
];
2332 /* create an empty db */
2334 ok( hdb
, "failed to create db\n");
2336 memset(hviews
, 0, sizeof(hviews
));
2338 for (i
=0; i
<MY_NVIEWS
; i
++) {
2339 static char szQueryBuf
[256] = "SELECT * from `_Tables`";
2340 hviews
[i
] = 0xdeadbeeb;
2341 r
= MsiDatabaseOpenView(hdb
, szQueryBuf
, &hviews
[i
]);
2342 if( r
!= ERROR_SUCCESS
|| hviews
[i
] == 0xdeadbeeb ||
2343 hviews
[i
] == 0 || (i
&& (hviews
[i
] == hviews
[i
-1])))
2347 ok( i
== MY_NVIEWS
, "problem opening views\n");
2349 for (i
=0; i
<MY_NVIEWS
; i
++) {
2350 if (hviews
[i
] != 0 && hviews
[i
] != 0xdeadbeeb) {
2351 MsiViewClose(hviews
[i
]);
2352 r
= MsiCloseHandle(hviews
[i
]);
2353 if (r
!= ERROR_SUCCESS
)
2358 ok( i
== MY_NVIEWS
, "problem closing views\n");
2360 r
= MsiCloseHandle(hdb
);
2361 ok( r
== ERROR_SUCCESS
, "failed to close database\n");
2364 static void generate_transform(void)
2366 MSIHANDLE hdb1
, hdb2
, hrec
;
2370 /* start with two identical databases */
2371 CopyFile(msifile2
, msifile
, FALSE
);
2373 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb1
);
2374 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2376 r
= MsiDatabaseCommit( hdb1
);
2377 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
2379 r
= MsiOpenDatabase(msifile2
, MSIDBOPEN_READONLY
, &hdb2
);
2380 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2382 /* the transform between two identical database should be empty */
2383 r
= MsiDatabaseGenerateTransform(hdb1
, hdb2
, NULL
, 0, 0);
2385 ok( r
== ERROR_NO_DATA
, "return code %d, should be ERROR_NO_DATA\n", r
);
2388 query
= "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
2389 r
= run_query(hdb1
, 0, query
);
2390 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2392 query
= "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
2393 r
= run_query(hdb1
, 0, query
);
2394 ok(r
== ERROR_SUCCESS
, "failed to add row 1\n");
2396 query
= "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
2397 r
= run_query(hdb1
, 0, query
);
2398 ok(r
== ERROR_SUCCESS
, "failed to add row 2\n");
2400 query
= "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
2401 r
= run_query(hdb1
, 0, query
);
2402 ok(r
== ERROR_SUCCESS
, "failed to modify row\n");
2404 query
= "DELETE FROM `MOO` WHERE `NOO` = 3";
2405 r
= run_query(hdb1
, 0, query
);
2406 ok(r
== ERROR_SUCCESS
, "failed to delete row\n");
2408 hrec
= MsiCreateRecord(2);
2409 r
= MsiRecordSetInteger(hrec
, 1, 1);
2410 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
2412 write_file("testdata.bin", "naengmyon", 9);
2413 r
= MsiRecordSetStream(hrec
, 2, "testdata.bin");
2414 ok(r
== ERROR_SUCCESS
, "failed to set stream\n");
2416 query
= "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2417 r
= run_query(hdb1
, hrec
, query
);
2418 ok(r
== ERROR_SUCCESS
, "failed to add row with blob\n");
2420 MsiCloseHandle(hrec
);
2422 query
= "ALTER TABLE `MOO` ADD `COW` INTEGER";
2423 r
= run_query(hdb1
, 0, query
);
2424 ok(r
== ERROR_SUCCESS
, "failed to add column\n");
2426 query
= "ALTER TABLE `MOO` ADD `PIG` INTEGER";
2427 r
= run_query(hdb1
, 0, query
);
2428 ok(r
== ERROR_SUCCESS
, "failed to add column\n");
2430 query
= "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
2431 r
= run_query(hdb1
, 0, query
);
2432 ok(r
== ERROR_SUCCESS
, "failed to modify row\n");
2434 query
= "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
2435 "`Value` CHAR(0) PRIMARY KEY `Property`)";
2436 r
= run_query(hdb1
, 0, query
);
2437 ok(r
== ERROR_SUCCESS
, "failed to add property table\n");
2439 query
= "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2440 r
= run_query(hdb1
, 0, query
);
2441 ok(r
== ERROR_SUCCESS
, "failed to add property\n");
2443 /* database needs to be committed */
2444 MsiDatabaseCommit(hdb1
);
2446 r
= MsiDatabaseGenerateTransform(hdb1
, hdb2
, mstfile
, 0, 0);
2447 ok( r
== ERROR_SUCCESS
, "return code %d, should be ERROR_SUCCESS\n", r
);
2449 MsiCloseHandle( hdb1
);
2450 MsiCloseHandle( hdb2
);
2452 DeleteFile("testdata.bin");
2455 /* data for generating a transform */
2457 /* tables transform names - encoded as they would be in an msi database file */
2458 static const WCHAR name1
[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
2459 static const WCHAR name2
[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
2460 static const WCHAR name3
[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
2461 static const WCHAR name4
[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2462 static const WCHAR name5
[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2463 static const WCHAR name6
[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
2464 static const WCHAR name7
[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
2465 static const WCHAR name8
[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
2466 static const WCHAR name9
[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2468 /* data in each table */
2469 static const WCHAR data1
[] = { /* AAR */
2470 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
2471 0x0201, 0x0009, 0x8002,
2473 static const WCHAR data2
[] = { /* _Columns */
2474 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
2475 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
2476 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
2477 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
2478 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
2479 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
2481 static const WCHAR data3
[] = { /* _Tables */
2482 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
2485 static const char data4
[] = /* _StringData */
2486 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
2487 static const WCHAR data5
[] = { /* _StringPool */
2489 0, 0, /* string 0 '' */
2490 3, 2, /* string 1 'MOO' */
2491 3, 1, /* string 2 'COW' */
2492 3, 1, /* string 3 'PIG' */
2493 1, 1, /* string 4 'c' */
2494 3, 3, /* string 5 'AAR' */
2495 3, 1, /* string 6 'CAR' */
2496 3, 1, /* string 7 'BAR' */
2497 2, 1, /* string 8 'vw' */
2498 3, 1, /* string 9 'bmw' */
2499 8, 4, /* string 10 'Property' */
2500 5, 1, /* string 11 'Value' */
2501 4, 1, /* string 12 'prop' */
2502 3, 1, /* string 13 'val' */
2504 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
2505 static const WCHAR data6
[] = { /* MOO */
2506 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
2507 0x0000, 0x8003, /* delete row */
2510 static const WCHAR data7
[] = { /* BINARY */
2511 0x0201, 0x8001, 0x0001,
2514 static const char data8
[] = /* stream data for the BINARY table */
2517 static const WCHAR data9
[] = { /* Property */
2518 0x0201, 0x000c, 0x000d,
2521 static const struct {
2525 } table_transform_data
[] =
2527 { name1
, data1
, sizeof data1
},
2528 { name2
, data2
, sizeof data2
},
2529 { name3
, data3
, sizeof data3
},
2530 { name4
, data4
, sizeof data4
- 1 },
2531 { name5
, data5
, sizeof data5
},
2532 { name6
, data6
, sizeof data6
},
2533 { name7
, data7
, sizeof data7
},
2534 { name8
, data8
, sizeof data8
- 1 },
2535 { name9
, data9
, sizeof data9
},
2538 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2540 static void generate_transform_manual(void)
2542 IStorage
*stg
= NULL
;
2547 const DWORD mode
= STGM_CREATE
|STGM_READWRITE
|STGM_DIRECT
|STGM_SHARE_EXCLUSIVE
;
2549 const CLSID CLSID_MsiTransform
= { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2551 MultiByteToWideChar(CP_ACP
, 0, mstfile
, -1, name
, 0x20);
2553 r
= StgCreateDocfile(name
, mode
, 0, &stg
);
2554 ok(r
== S_OK
, "failed to create storage\n");
2558 r
= IStorage_SetClass( stg
, &CLSID_MsiTransform
);
2559 ok(r
== S_OK
, "failed to set storage type\n");
2561 for (i
=0; i
<NUM_TRANSFORM_TABLES
; i
++)
2563 r
= IStorage_CreateStream( stg
, table_transform_data
[i
].name
,
2564 STGM_WRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
2567 ok(0, "failed to create stream %08x\n", r
);
2571 r
= IStream_Write( stm
, table_transform_data
[i
].data
,
2572 table_transform_data
[i
].size
, &count
);
2573 if (FAILED(r
) || count
!= table_transform_data
[i
].size
)
2574 ok(0, "failed to write stream\n");
2575 IStream_Release(stm
);
2578 IStorage_Release(stg
);
2581 static UINT
set_summary_info(MSIHANDLE hdb
)
2586 /* build summary info */
2587 res
= MsiGetSummaryInformation(hdb
, NULL
, 7, &suminfo
);
2588 ok( res
== ERROR_SUCCESS
, "Failed to open summaryinfo\n" );
2590 res
= MsiSummaryInfoSetProperty(suminfo
,2, VT_LPSTR
, 0,NULL
,
2591 "Installation Database");
2592 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2594 res
= MsiSummaryInfoSetProperty(suminfo
,3, VT_LPSTR
, 0,NULL
,
2595 "Installation Database");
2596 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2598 res
= MsiSummaryInfoSetProperty(suminfo
,4, VT_LPSTR
, 0,NULL
,
2600 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2602 res
= MsiSummaryInfoSetProperty(suminfo
,7, VT_LPSTR
, 0,NULL
,
2604 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2606 res
= MsiSummaryInfoSetProperty(suminfo
,9, VT_LPSTR
, 0,NULL
,
2607 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2608 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2610 res
= MsiSummaryInfoSetProperty(suminfo
, 14, VT_I4
, 100, NULL
, NULL
);
2611 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2613 res
= MsiSummaryInfoSetProperty(suminfo
, 15, VT_I4
, 0, NULL
, NULL
);
2614 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2616 res
= MsiSummaryInfoPersist(suminfo
);
2617 ok( res
== ERROR_SUCCESS
, "Failed to make summary info persist\n" );
2619 res
= MsiCloseHandle( suminfo
);
2620 ok( res
== ERROR_SUCCESS
, "Failed to close suminfo\n" );
2625 static MSIHANDLE
create_package_db(LPCSTR filename
)
2630 DeleteFile(msifile
);
2632 /* create an empty database */
2633 res
= MsiOpenDatabase(filename
, MSIDBOPEN_CREATE
, &hdb
);
2634 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
2635 if( res
!= ERROR_SUCCESS
)
2638 res
= MsiDatabaseCommit( hdb
);
2639 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
2641 res
= set_summary_info(hdb
);
2643 res
= create_directory_table(hdb
);
2644 ok( res
== ERROR_SUCCESS
, "Failed to create directory table\n" );
2649 static MSIHANDLE
package_from_db(MSIHANDLE hdb
)
2655 sprintf(szPackage
,"#%i",hdb
);
2656 res
= MsiOpenPackage(szPackage
,&hPackage
);
2657 if (res
!= ERROR_SUCCESS
)
2660 res
= MsiCloseHandle(hdb
);
2661 if (res
!= ERROR_SUCCESS
)
2667 static void test_try_transform(void)
2669 MSIHANDLE hdb
, hview
, hrec
, hpkg
;
2673 char buffer
[MAX_PATH
];
2675 DeleteFile(msifile
);
2676 DeleteFile(mstfile
);
2678 /* create the database */
2679 hdb
= create_package_db(msifile
);
2680 ok(hdb
, "Failed to create package db\n");
2682 query
= "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
2683 r
= run_query(hdb
, 0, query
);
2684 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2686 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
2687 r
= run_query(hdb
, 0, query
);
2688 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2690 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
2691 r
= run_query(hdb
, 0, query
);
2692 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2694 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
2695 r
= run_query(hdb
, 0, query
);
2696 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2698 query
= "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
2699 r
= run_query(hdb
, 0, query
);
2700 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2702 hrec
= MsiCreateRecord(2);
2703 r
= MsiRecordSetInteger(hrec
, 1, 2);
2704 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
2706 write_file("testdata.bin", "lamyon", 6);
2707 r
= MsiRecordSetStream(hrec
, 2, "testdata.bin");
2708 ok(r
== ERROR_SUCCESS
, "failed to set stream\n");
2710 query
= "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2711 r
= run_query(hdb
, hrec
, query
);
2712 ok(r
== ERROR_SUCCESS
, "failed to add row with blob\n");
2714 MsiCloseHandle(hrec
);
2716 r
= MsiDatabaseCommit( hdb
);
2717 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
2719 MsiCloseHandle( hdb
);
2720 DeleteFileA("testdata.bin");
2723 * Both these generate an equivalent transform,
2724 * but the first doesn't work in Wine yet
2725 * because MsiDatabaseGenerateTransform is unimplemented.
2728 generate_transform();
2730 generate_transform_manual();
2732 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_DIRECT
, &hdb
);
2733 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2735 r
= MsiDatabaseApplyTransform( hdb
, mstfile
, 0 );
2736 ok( r
== ERROR_SUCCESS
, "return code %d, should be ERROR_SUCCESS\n", r
);
2738 MsiDatabaseCommit( hdb
);
2740 /* check new values */
2742 query
= "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
2743 r
= do_query(hdb
, query
, &hrec
);
2744 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2745 MsiCloseHandle(hrec
);
2747 query
= "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
2749 r
= do_query(hdb
, query
, &hrec
);
2750 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2751 MsiCloseHandle(hrec
);
2753 /* check updated values */
2755 query
= "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
2756 r
= do_query(hdb
, query
, &hrec
);
2757 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2758 MsiCloseHandle(hrec
);
2760 /* check unchanged value */
2762 query
= "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
2763 r
= do_query(hdb
, query
, &hrec
);
2764 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2765 MsiCloseHandle(hrec
);
2767 /* check deleted value */
2769 query
= "select * from `MOO` where `NOO` = 3";
2770 r
= do_query(hdb
, query
, &hrec
);
2771 ok(r
== ERROR_NO_MORE_ITEMS
, "select query failed\n");
2772 if (hrec
) MsiCloseHandle(hrec
);
2774 /* check added stream */
2776 query
= "select `BLOB` from `BINARY` where `ID` = 1";
2777 r
= do_query(hdb
, query
, &hrec
);
2778 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2780 /* check the contents of the stream */
2782 r
= MsiRecordReadStream( hrec
, 1, buffer
, &sz
);
2783 ok(r
== ERROR_SUCCESS
, "read stream failed\n");
2784 ok(!memcmp(buffer
, "naengmyon", 9), "stream data was wrong\n");
2785 ok(sz
== 9, "stream data was wrong size\n");
2786 if (hrec
) MsiCloseHandle(hrec
);
2788 /* check the validity of the table with a deleted row */
2790 query
= "select * from `MOO`";
2791 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2792 ok(r
== ERROR_SUCCESS
, "open view failed\n");
2794 r
= MsiViewExecute(hview
, 0);
2795 ok(r
== ERROR_SUCCESS
, "view execute failed\n");
2797 r
= MsiViewFetch(hview
, &hrec
);
2798 ok(r
== ERROR_SUCCESS
, "view fetch failed\n");
2800 r
= MsiRecordGetInteger(hrec
, 1);
2801 ok(r
== 1, "Expected 1, got %d\n", r
);
2804 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
2805 ok(r
== ERROR_SUCCESS
, "record get string failed\n");
2806 ok(!lstrcmpA(buffer
, "c"), "Expected c, got %s\n", buffer
);
2808 r
= MsiRecordGetInteger(hrec
, 3);
2809 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
2811 r
= MsiRecordGetInteger(hrec
, 4);
2812 ok(r
== 5, "Expected 5, got %d\n", r
);
2814 MsiCloseHandle(hrec
);
2816 r
= MsiViewFetch(hview
, &hrec
);
2817 ok(r
== ERROR_SUCCESS
, "view fetch failed\n");
2819 r
= MsiRecordGetInteger(hrec
, 1);
2820 ok(r
== 2, "Expected 2, got %d\n", r
);
2823 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
2824 ok(r
== ERROR_SUCCESS
, "record get string failed\n");
2825 ok(!lstrcmpA(buffer
, "b"), "Expected b, got %s\n", buffer
);
2827 r
= MsiRecordGetInteger(hrec
, 3);
2828 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
2830 r
= MsiRecordGetInteger(hrec
, 4);
2831 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
2833 MsiCloseHandle(hrec
);
2835 r
= MsiViewFetch(hview
, &hrec
);
2836 ok(r
== ERROR_NO_MORE_ITEMS
, "view fetch succeeded\n");
2838 MsiCloseHandle(hrec
);
2839 MsiViewClose(hview
);
2840 MsiCloseHandle(hview
);
2842 /* check that the property was added */
2843 hpkg
= package_from_db(hdb
);
2844 ok(hpkg
!= 0, "Expected non-NULL hpkg\n");
2847 r
= MsiGetProperty(hpkg
, "prop", buffer
, &sz
);
2848 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2849 ok(!lstrcmp(buffer
, "val"), "Expected val, got %s\n", buffer
);
2851 MsiCloseHandle(hpkg
);
2852 MsiCloseHandle(hdb
);
2854 DeleteFile(msifile
);
2855 DeleteFile(mstfile
);
2860 const CHAR one
[MAX_PATH
];
2861 const CHAR two
[MAX_PATH
];
2864 struct join_res_4col
2866 const CHAR one
[MAX_PATH
];
2867 const CHAR two
[MAX_PATH
];
2868 const CHAR three
[MAX_PATH
];
2869 const CHAR four
[MAX_PATH
];
2872 struct join_res_uint
2882 static const struct join_res join_res_first
[] =
2884 { "alveolar", "procerus" },
2885 { "septum", "procerus" },
2886 { "septum", "nasalis" },
2887 { "ramus", "nasalis" },
2888 { "malar", "mentalis" },
2891 static const struct join_res join_res_second
[] =
2893 { "nasal", "septum" },
2894 { "mandible", "ramus" },
2897 static const struct join_res join_res_third
[] =
2899 { "msvcp.dll", "abcdefgh" },
2900 { "msvcr.dll", "ijklmnop" },
2903 static const struct join_res join_res_fourth
[] =
2905 { "msvcp.dll.01234", "single.dll.31415" },
2908 static const struct join_res join_res_fifth
[] =
2910 { "malar", "procerus" },
2913 static const struct join_res join_res_sixth
[] =
2915 { "malar", "procerus" },
2916 { "malar", "procerus" },
2917 { "malar", "nasalis" },
2918 { "malar", "nasalis" },
2919 { "malar", "nasalis" },
2920 { "malar", "mentalis" },
2923 static const struct join_res join_res_seventh
[] =
2925 { "malar", "nasalis" },
2926 { "malar", "nasalis" },
2927 { "malar", "nasalis" },
2930 static const struct join_res_4col join_res_eighth
[] =
2932 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
2933 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
2934 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
2935 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
2936 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
2937 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
2940 static const struct join_res_uint join_res_ninth
[] =
2942 { 1, 2, 3, 4, 7, 8 },
2943 { 1, 2, 5, 6, 7, 8 },
2944 { 1, 2, 3, 4, 9, 10 },
2945 { 1, 2, 5, 6, 9, 10 },
2946 { 1, 2, 3, 4, 11, 12 },
2947 { 1, 2, 5, 6, 11, 12 },
2950 static void test_join(void)
2952 MSIHANDLE hdb
, hview
, hrec
;
2960 ok( hdb
, "failed to create db\n");
2962 r
= create_component_table( hdb
);
2963 ok( r
== ERROR_SUCCESS
, "cannot create Component table: %d\n", r
);
2965 r
= add_component_entry( hdb
, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
2966 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2968 r
= add_component_entry( hdb
, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
2969 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2971 r
= add_component_entry( hdb
, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
2972 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2974 r
= add_component_entry( hdb
, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
2975 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2977 r
= create_feature_components_table( hdb
);
2978 ok( r
== ERROR_SUCCESS
, "cannot create FeatureComponents table: %d\n", r
);
2980 r
= add_feature_components_entry( hdb
, "'procerus', 'maxilla'" );
2981 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2983 r
= add_feature_components_entry( hdb
, "'procerus', 'nasal'" );
2984 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2986 r
= add_feature_components_entry( hdb
, "'nasalis', 'nasal'" );
2987 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2989 r
= add_feature_components_entry( hdb
, "'nasalis', 'mandible'" );
2990 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2992 r
= add_feature_components_entry( hdb
, "'nasalis', 'notacomponent'" );
2993 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2995 r
= add_feature_components_entry( hdb
, "'mentalis', 'zygomatic'" );
2996 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2998 r
= create_std_dlls_table( hdb
);
2999 ok( r
== ERROR_SUCCESS
, "cannot create StdDlls table: %d\n", r
);
3001 r
= add_std_dlls_entry( hdb
, "'msvcp.dll', 'msvcp.dll.01234'" );
3002 ok( r
== ERROR_SUCCESS
, "cannot add std dlls: %d\n", r
);
3004 r
= add_std_dlls_entry( hdb
, "'msvcr.dll', 'msvcr.dll.56789'" );
3005 ok( r
== ERROR_SUCCESS
, "cannot add std dlls: %d\n", r
);
3007 r
= create_binary_table( hdb
);
3008 ok( r
== ERROR_SUCCESS
, "cannot create Binary table: %d\n", r
);
3010 r
= add_binary_entry( hdb
, "'msvcp.dll.01234', 'abcdefgh'" );
3011 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
3013 r
= add_binary_entry( hdb
, "'msvcr.dll.56789', 'ijklmnop'" );
3014 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
3016 r
= add_binary_entry( hdb
, "'single.dll.31415', 'msvcp.dll'" );
3017 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
3019 query
= "CREATE TABLE `One` (`A` SHORT, `B` SHORT PRIMARY KEY `A`)";
3020 r
= run_query( hdb
, 0, query
);
3021 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
3023 query
= "CREATE TABLE `Two` (`C` SHORT, `D` SHORT PRIMARY KEY `C`)";
3024 r
= run_query( hdb
, 0, query
);
3025 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
3027 query
= "CREATE TABLE `Three` (`E` SHORT, `F` SHORT PRIMARY KEY `E`)";
3028 r
= run_query( hdb
, 0, query
);
3029 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
3031 query
= "INSERT INTO `One` (`A`, `B`) VALUES (1, 2)";
3032 r
= run_query( hdb
, 0, query
);
3033 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3035 query
= "INSERT INTO `Two` (`C`, `D`) VALUES (3, 4)";
3036 r
= run_query( hdb
, 0, query
);
3037 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3039 query
= "INSERT INTO `Two` (`C`, `D`) VALUES (5, 6)";
3040 r
= run_query( hdb
, 0, query
);
3041 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3043 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (7, 8)";
3044 r
= run_query( hdb
, 0, query
);
3045 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3047 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (9, 10)";
3048 r
= run_query( hdb
, 0, query
);
3049 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3051 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (11, 12)";
3052 r
= run_query( hdb
, 0, query
);
3053 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3055 query
= "CREATE TABLE `Four` (`G` SHORT, `H` SHORT PRIMARY KEY `G`)";
3056 r
= run_query( hdb
, 0, query
);
3057 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
3059 query
= "CREATE TABLE `Five` (`I` SHORT, `J` SHORT PRIMARY KEY `I`)";
3060 r
= run_query( hdb
, 0, query
);
3061 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
3063 query
= "INSERT INTO `Five` (`I`, `J`) VALUES (13, 14)";
3064 r
= run_query( hdb
, 0, query
);
3065 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3067 query
= "INSERT INTO `Five` (`I`, `J`) VALUES (15, 16)";
3068 r
= run_query( hdb
, 0, query
);
3069 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3071 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3072 "FROM `Component`, `FeatureComponents` "
3073 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
3074 "ORDER BY `Feature_`";
3075 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3076 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3078 r
= MsiViewExecute(hview
, 0);
3079 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3082 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3084 count
= MsiRecordGetFieldCount( hrec
);
3085 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3088 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3089 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3090 ok( !lstrcmp( buf
, join_res_first
[i
].one
),
3091 "For (row %d, column 1) expected '%s', got %s\n", i
, join_res_first
[i
].one
, buf
);
3094 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3095 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3096 ok( !lstrcmp( buf
, join_res_first
[i
].two
),
3097 "For (row %d, column 2) expected '%s', got %s\n", i
, join_res_first
[i
].two
, buf
);
3100 MsiCloseHandle(hrec
);
3103 ok( i
== 5, "Expected 5 rows, got %d\n", i
);
3104 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3106 MsiViewClose(hview
);
3107 MsiCloseHandle(hview
);
3109 /* try a join without a WHERE condition */
3110 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3111 "FROM `Component`, `FeatureComponents` ";
3112 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3113 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3115 r
= MsiViewExecute(hview
, 0);
3116 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3119 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3122 MsiCloseHandle(hrec
);
3124 ok( i
== 24, "Expected 24 rows, got %d\n", i
);
3126 MsiViewClose(hview
);
3127 MsiCloseHandle(hview
);
3129 query
= "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
3130 "WHERE FeatureComponents.Component_=Component.Component "
3131 "AND (Feature_='nasalis') ORDER BY Feature_";
3132 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3133 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3135 r
= MsiViewExecute(hview
, 0);
3136 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3139 data_correct
= TRUE
;
3140 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3142 count
= MsiRecordGetFieldCount( hrec
);
3143 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3146 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3147 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3148 if( lstrcmp( buf
, join_res_second
[i
].one
))
3149 data_correct
= FALSE
;
3152 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3153 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3154 if( lstrcmp( buf
, join_res_second
[i
].two
))
3155 data_correct
= FALSE
;
3158 MsiCloseHandle(hrec
);
3161 ok( data_correct
, "data returned in the wrong order\n");
3163 ok( i
== 2, "Expected 2 rows, got %d\n", i
);
3164 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3166 MsiViewClose(hview
);
3167 MsiCloseHandle(hview
);
3169 query
= "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3170 "FROM `StdDlls`, `Binary` "
3171 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
3173 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3174 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3176 r
= MsiViewExecute(hview
, 0);
3177 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3180 data_correct
= TRUE
;
3181 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3183 count
= MsiRecordGetFieldCount( hrec
);
3184 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3187 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3188 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3189 if( lstrcmp( buf
, join_res_third
[i
].one
) )
3190 data_correct
= FALSE
;
3193 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3194 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3195 if( lstrcmp( buf
, join_res_third
[i
].two
) )
3196 data_correct
= FALSE
;
3199 MsiCloseHandle(hrec
);
3201 ok( data_correct
, "data returned in the wrong order\n");
3203 ok( i
== 2, "Expected 2 rows, got %d\n", i
);
3205 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3207 MsiViewClose(hview
);
3208 MsiCloseHandle(hview
);
3210 query
= "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
3211 "FROM `StdDlls`, `Binary` "
3212 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
3214 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3215 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3217 r
= MsiViewExecute(hview
, 0);
3218 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3221 data_correct
= TRUE
;
3222 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3224 count
= MsiRecordGetFieldCount( hrec
);
3225 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3228 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3229 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3230 if( lstrcmp( buf
, join_res_fourth
[i
].one
))
3231 data_correct
= FALSE
;
3234 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3235 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3236 if( lstrcmp( buf
, join_res_fourth
[i
].two
))
3237 data_correct
= FALSE
;
3240 MsiCloseHandle(hrec
);
3242 ok( data_correct
, "data returned in the wrong order\n");
3244 ok( i
== 1, "Expected 1 rows, got %d\n", i
);
3245 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3247 MsiViewClose(hview
);
3248 MsiCloseHandle(hview
);
3250 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3251 "FROM `Component`, `FeatureComponents` "
3252 "WHERE `Component`.`Component` = 'zygomatic' "
3253 "AND `FeatureComponents`.`Component_` = 'maxilla' "
3254 "ORDER BY `Feature_`";
3255 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3256 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3258 r
= MsiViewExecute(hview
, 0);
3259 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3262 data_correct
= TRUE
;
3263 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3265 count
= MsiRecordGetFieldCount( hrec
);
3266 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3269 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3270 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3271 if( lstrcmp( buf
, join_res_fifth
[i
].one
))
3272 data_correct
= FALSE
;
3275 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3276 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3277 if( lstrcmp( buf
, join_res_fifth
[i
].two
))
3278 data_correct
= FALSE
;
3281 MsiCloseHandle(hrec
);
3283 ok( data_correct
, "data returned in the wrong order\n");
3285 ok( i
== 1, "Expected 1 rows, got %d\n", i
);
3286 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3288 MsiViewClose(hview
);
3289 MsiCloseHandle(hview
);
3291 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3292 "FROM `Component`, `FeatureComponents` "
3293 "WHERE `Component` = 'zygomatic' "
3294 "ORDER BY `Feature_`";
3295 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3296 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3298 r
= MsiViewExecute(hview
, 0);
3299 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3302 data_correct
= TRUE
;
3303 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3305 count
= MsiRecordGetFieldCount( hrec
);
3306 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3309 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3310 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3311 if( lstrcmp( buf
, join_res_sixth
[i
].one
))
3312 data_correct
= FALSE
;
3315 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3316 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3317 if( lstrcmp( buf
, join_res_sixth
[i
].two
))
3318 data_correct
= FALSE
;
3321 MsiCloseHandle(hrec
);
3323 ok( data_correct
, "data returned in the wrong order\n");
3325 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3326 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3328 MsiViewClose(hview
);
3329 MsiCloseHandle(hview
);
3331 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3332 "FROM `Component`, `FeatureComponents` "
3333 "WHERE `Component` = 'zygomatic' "
3334 "AND `Feature_` = 'nasalis' "
3335 "ORDER BY `Feature_`";
3336 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3337 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3339 r
= MsiViewExecute(hview
, 0);
3340 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3343 data_correct
= TRUE
;
3344 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3346 count
= MsiRecordGetFieldCount( hrec
);
3347 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3350 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3351 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3352 if( lstrcmp( buf
, join_res_seventh
[i
].one
))
3353 data_correct
= FALSE
;
3356 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3357 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3358 if( lstrcmp( buf
, join_res_seventh
[i
].two
))
3359 data_correct
= FALSE
;
3362 MsiCloseHandle(hrec
);
3365 ok( data_correct
, "data returned in the wrong order\n");
3366 ok( i
== 3, "Expected 3 rows, got %d\n", i
);
3367 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3369 MsiViewClose(hview
);
3370 MsiCloseHandle(hview
);
3372 query
= "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3373 "FROM `StdDlls`, `Binary` ";
3374 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3375 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3377 r
= MsiViewExecute(hview
, 0);
3378 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3381 data_correct
= TRUE
;
3382 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3384 count
= MsiRecordGetFieldCount( hrec
);
3385 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3388 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3389 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3390 if( lstrcmp( buf
, join_res_eighth
[i
].one
))
3391 data_correct
= FALSE
;
3394 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3395 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3396 if( lstrcmp( buf
, join_res_eighth
[i
].four
))
3397 data_correct
= FALSE
;
3400 MsiCloseHandle(hrec
);
3403 ok( data_correct
, "data returned in the wrong order\n");
3404 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3405 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3407 MsiViewClose(hview
);
3408 MsiCloseHandle(hview
);
3410 query
= "SELECT * FROM `StdDlls`, `Binary` ";
3411 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3412 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3414 r
= MsiViewExecute(hview
, 0);
3415 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3418 data_correct
= TRUE
;
3419 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3421 count
= MsiRecordGetFieldCount( hrec
);
3422 ok( count
== 4, "Expected 4 record fields, got %d\n", count
);
3425 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3426 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3427 if( lstrcmp( buf
, join_res_eighth
[i
].one
))
3428 data_correct
= FALSE
;
3431 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3432 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3433 if( lstrcmp( buf
, join_res_eighth
[i
].two
))
3434 data_correct
= FALSE
;
3437 r
= MsiRecordGetString( hrec
, 3, buf
, &size
);
3438 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3439 if( lstrcmp( buf
, join_res_eighth
[i
].three
))
3440 data_correct
= FALSE
;
3443 r
= MsiRecordGetString( hrec
, 4, buf
, &size
);
3444 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3445 if( lstrcmp( buf
, join_res_eighth
[i
].four
))
3446 data_correct
= FALSE
;
3449 MsiCloseHandle(hrec
);
3451 ok( data_correct
, "data returned in the wrong order\n");
3453 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3454 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3456 MsiViewClose(hview
);
3457 MsiCloseHandle(hview
);
3459 query
= "SELECT * FROM `One`, `Two`, `Three` ";
3460 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3461 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3463 r
= MsiViewExecute(hview
, 0);
3464 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3467 data_correct
= TRUE
;
3468 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3470 count
= MsiRecordGetFieldCount( hrec
);
3471 ok( count
== 6, "Expected 6 record fields, got %d\n", count
);
3473 r
= MsiRecordGetInteger( hrec
, 1 );
3474 if( r
!= join_res_ninth
[i
].one
)
3475 data_correct
= FALSE
;
3477 r
= MsiRecordGetInteger( hrec
, 2 );
3478 if( r
!= join_res_ninth
[i
].two
)
3479 data_correct
= FALSE
;
3481 r
= MsiRecordGetInteger( hrec
, 3 );
3482 if( r
!= join_res_ninth
[i
].three
)
3483 data_correct
= FALSE
;
3485 r
= MsiRecordGetInteger( hrec
, 4 );
3486 if( r
!= join_res_ninth
[i
].four
)
3487 data_correct
= FALSE
;
3489 r
= MsiRecordGetInteger( hrec
, 5 );
3490 if( r
!= join_res_ninth
[i
].five
)
3491 data_correct
= FALSE
;
3493 r
= MsiRecordGetInteger( hrec
, 6);
3494 if( r
!= join_res_ninth
[i
].six
)
3495 data_correct
= FALSE
;
3498 MsiCloseHandle(hrec
);
3500 ok( data_correct
, "data returned in the wrong order\n");
3502 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3503 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3505 MsiViewClose(hview
);
3506 MsiCloseHandle(hview
);
3508 query
= "SELECT * FROM `Four`, `Five`";
3509 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3510 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3512 r
= MsiViewExecute(hview
, 0);
3513 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3515 r
= MsiViewFetch(hview
, &hrec
);
3516 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3518 MsiViewClose(hview
);
3519 MsiCloseHandle(hview
);
3521 query
= "SELECT * FROM `Nonexistent`, `One`";
3522 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3523 ok( r
== ERROR_BAD_QUERY_SYNTAX
,
3524 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3526 MsiCloseHandle(hdb
);
3527 DeleteFile(msifile
);
3530 static void test_temporary_table(void)
3533 MSIHANDLE hdb
= 0, view
= 0, rec
;
3539 cond
= MsiDatabaseIsTablePersistent(0, NULL
);
3540 ok( cond
== MSICONDITION_ERROR
, "wrong return condition\n");
3543 ok( hdb
, "failed to create db\n");
3545 cond
= MsiDatabaseIsTablePersistent(hdb
, NULL
);
3546 ok( cond
== MSICONDITION_ERROR
, "wrong return condition\n");
3548 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Tables");
3549 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3551 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Columns");
3552 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3554 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Storages");
3555 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3557 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Streams");
3558 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3560 query
= "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
3561 r
= run_query(hdb
, 0, query
);
3562 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3564 cond
= MsiDatabaseIsTablePersistent(hdb
, "P");
3565 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3567 query
= "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
3568 r
= run_query(hdb
, 0, query
);
3569 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3571 cond
= MsiDatabaseIsTablePersistent(hdb
, "P2");
3572 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3574 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3575 r
= run_query(hdb
, 0, query
);
3576 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3578 cond
= MsiDatabaseIsTablePersistent(hdb
, "T");
3579 ok( cond
== MSICONDITION_FALSE
, "wrong return condition\n");
3581 query
= "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3582 r
= run_query(hdb
, 0, query
);
3583 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3585 query
= "SELECT * FROM `T2`";
3586 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3587 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
3588 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3590 cond
= MsiDatabaseIsTablePersistent(hdb
, "T2");
3591 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3593 query
= "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
3594 r
= run_query(hdb
, 0, query
);
3595 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3597 cond
= MsiDatabaseIsTablePersistent(hdb
, "T3");
3598 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3600 query
= "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3601 r
= run_query(hdb
, 0, query
);
3602 ok(r
== ERROR_FUNCTION_FAILED
, "failed to add table\n");
3604 cond
= MsiDatabaseIsTablePersistent(hdb
, "T4");
3605 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3607 query
= "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
3608 r
= run_query(hdb
, 0, query
);
3609 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to add table\n");
3611 query
= "select * from `T`";
3612 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3613 ok(r
== ERROR_SUCCESS
, "failed to query table\n");
3614 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
3615 ok(r
== ERROR_SUCCESS
, "failed to get column info\n");
3618 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
3619 ok(r
== ERROR_SUCCESS
, "failed to get string\n");
3620 ok( 0 == strcmp("G255", buf
), "wrong column type\n");
3623 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
3624 ok(r
== ERROR_SUCCESS
, "failed to get string\n");
3625 ok( 0 == strcmp("j2", buf
), "wrong column type\n");
3627 MsiCloseHandle( rec
);
3628 MsiViewClose( view
);
3629 MsiCloseHandle( view
);
3631 /* query the table data */
3633 r
= do_query(hdb
, "select * from `_Tables` where `Name` = 'T'", &rec
);
3634 ok( r
== ERROR_SUCCESS
, "temporary table exists in _Tables\n");
3635 MsiCloseHandle( rec
);
3637 /* query the column data */
3639 r
= do_query(hdb
, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec
);
3640 ok( r
== ERROR_NO_MORE_ITEMS
, "temporary table exists in _Columns\n");
3641 if (rec
) MsiCloseHandle( rec
);
3643 r
= do_query(hdb
, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec
);
3644 ok( r
== ERROR_NO_MORE_ITEMS
, "temporary table exists in _Columns\n");
3645 if (rec
) MsiCloseHandle( rec
);
3647 MsiCloseHandle( hdb
);
3649 DeleteFile(msifile
);
3652 static void test_alter(void)
3660 ok( hdb
, "failed to create db\n");
3662 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3663 r
= run_query(hdb
, 0, query
);
3664 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3666 cond
= MsiDatabaseIsTablePersistent(hdb
, "T");
3667 ok( cond
== MSICONDITION_FALSE
, "wrong return condition\n");
3669 query
= "ALTER TABLE `T` HOLD";
3670 r
= run_query(hdb
, 0, query
);
3671 ok(r
== ERROR_SUCCESS
, "failed to hold table %d\n", r
);
3673 query
= "ALTER TABLE `T` FREE";
3674 r
= run_query(hdb
, 0, query
);
3675 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
3677 query
= "ALTER TABLE `T` FREE";
3678 r
= run_query(hdb
, 0, query
);
3679 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
3681 query
= "ALTER TABLE `T` FREE";
3682 r
= run_query(hdb
, 0, query
);
3683 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to free table\n");
3685 query
= "ALTER TABLE `T` HOLD";
3686 r
= run_query(hdb
, 0, query
);
3687 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to hold table %d\n", r
);
3689 /* table T is removed */
3690 query
= "SELECT * FROM `T`";
3691 r
= run_query(hdb
, 0, query
);
3692 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3694 /* create the table again */
3695 query
= "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
3696 r
= run_query(hdb
, 0, query
);
3697 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3699 /* up the ref count */
3700 query
= "ALTER TABLE `U` HOLD";
3701 r
= run_query(hdb
, 0, query
);
3702 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
3704 /* add column, no data type */
3705 query
= "ALTER TABLE `U` ADD `C`";
3706 r
= run_query(hdb
, 0, query
);
3707 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3709 query
= "ALTER TABLE `U` ADD `C` INTEGER";
3710 r
= run_query(hdb
, 0, query
);
3711 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3713 /* add column C again */
3714 query
= "ALTER TABLE `U` ADD `C` INTEGER";
3715 r
= run_query(hdb
, 0, query
);
3716 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3718 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
3719 r
= run_query(hdb
, 0, query
);
3720 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3722 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
3723 r
= run_query(hdb
, 0, query
);
3724 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3726 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
3727 r
= run_query(hdb
, 0, query
);
3728 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3730 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
3731 r
= run_query(hdb
, 0, query
);
3732 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3734 query
= "SELECT * FROM `U` WHERE `D` = 8";
3735 r
= run_query(hdb
, 0, query
);
3736 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3738 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
3739 r
= run_query(hdb
, 0, query
);
3740 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3742 query
= "ALTER COLUMN `D` FREE";
3743 r
= run_query(hdb
, 0, query
);
3744 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3746 /* drop the ref count */
3747 query
= "ALTER TABLE `U` FREE";
3748 r
= run_query(hdb
, 0, query
);
3749 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3751 /* table is not empty */
3752 query
= "SELECT * FROM `U`";
3753 r
= run_query(hdb
, 0, query
);
3754 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3756 /* column D is removed */
3757 query
= "SELECT * FROM `U` WHERE `D` = 8";
3758 r
= run_query(hdb
, 0, query
);
3759 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3761 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
3762 r
= run_query(hdb
, 0, query
);
3763 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3765 /* add the column again */
3766 query
= "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
3767 r
= run_query(hdb
, 0, query
);
3768 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3770 /* up the ref count */
3771 query
= "ALTER TABLE `U` HOLD";
3772 r
= run_query(hdb
, 0, query
);
3773 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3775 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
3776 r
= run_query(hdb
, 0, query
);
3777 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3779 query
= "SELECT * FROM `U` WHERE `E` = 16";
3780 r
= run_query(hdb
, 0, query
);
3781 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3783 /* drop the ref count */
3784 query
= "ALTER TABLE `U` FREE";
3785 r
= run_query(hdb
, 0, query
);
3786 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3788 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
3789 r
= run_query(hdb
, 0, query
);
3790 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3792 query
= "SELECT * FROM `U` WHERE `E` = 20";
3793 r
= run_query(hdb
, 0, query
);
3794 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3796 /* drop the ref count */
3797 query
= "ALTER TABLE `U` FREE";
3798 r
= run_query(hdb
, 0, query
);
3799 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3801 /* table still exists */
3802 query
= "SELECT * FROM `U`";
3803 r
= run_query(hdb
, 0, query
);
3804 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3806 /* col E is removed */
3807 query
= "SELECT * FROM `U` WHERE `E` = 20";
3808 r
= run_query(hdb
, 0, query
);
3809 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3811 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
3812 r
= run_query(hdb
, 0, query
);
3813 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3815 /* drop the ref count once more */
3816 query
= "ALTER TABLE `U` FREE";
3817 r
= run_query(hdb
, 0, query
);
3818 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3820 /* table still exists */
3821 query
= "SELECT * FROM `U`";
3822 r
= run_query(hdb
, 0, query
);
3823 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3825 MsiCloseHandle( hdb
);
3826 DeleteFile(msifile
);
3829 static void test_integers(void)
3831 MSIHANDLE hdb
= 0, view
= 0, rec
= 0;
3836 /* just MsiOpenDatabase should not create a file */
3837 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
3838 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
3840 /* create a table */
3841 query
= "CREATE TABLE `integers` ( "
3842 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
3843 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
3844 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
3845 "PRIMARY KEY `one`)";
3846 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3847 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
3848 r
= MsiViewExecute(view
, 0);
3849 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
3850 r
= MsiViewClose(view
);
3851 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3852 r
= MsiCloseHandle(view
);
3853 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3855 query
= "SELECT * FROM `integers`";
3856 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3857 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3859 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
3860 count
= MsiRecordGetFieldCount(rec
);
3861 ok(count
== 8, "Expected 8, got %d\n", count
);
3862 ok(check_record(rec
, 1, "one"), "Expected one\n");
3863 ok(check_record(rec
, 2, "two"), "Expected two\n");
3864 ok(check_record(rec
, 3, "three"), "Expected three\n");
3865 ok(check_record(rec
, 4, "four"), "Expected four\n");
3866 ok(check_record(rec
, 5, "five"), "Expected five\n");
3867 ok(check_record(rec
, 6, "six"), "Expected six\n");
3868 ok(check_record(rec
, 7, "seven"), "Expected seven\n");
3869 ok(check_record(rec
, 8, "eight"), "Expected eight\n");
3870 MsiCloseHandle(rec
);
3872 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
3873 count
= MsiRecordGetFieldCount(rec
);
3874 ok(count
== 8, "Expected 8, got %d\n", count
);
3875 ok(check_record(rec
, 1, "I2"), "Expected I2\n");
3876 ok(check_record(rec
, 2, "I2"), "Expected I2\n");
3877 ok(check_record(rec
, 3, "I2"), "Expected I2\n");
3878 ok(check_record(rec
, 4, "I4"), "Expected I4\n");
3879 ok(check_record(rec
, 5, "i2"), "Expected i2\n");
3880 ok(check_record(rec
, 6, "i2"), "Expected i2\n");
3881 ok(check_record(rec
, 7, "i2"), "Expected i2\n");
3882 ok(check_record(rec
, 8, "i4"), "Expected i4\n");
3883 MsiCloseHandle(rec
);
3886 MsiCloseHandle(view
);
3888 /* insert values into it, NULL where NOT NULL is specified */
3889 query
= "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3890 "VALUES('', '', '', '', '', '', '', '')";
3891 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3892 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3893 r
= MsiViewExecute(view
, 0);
3894 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
3897 MsiCloseHandle(view
);
3899 query
= "SELECT * FROM `integers`";
3900 r
= do_query(hdb
, query
, &rec
);
3901 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3903 r
= MsiRecordGetFieldCount(rec
);
3904 ok(r
== -1, "record count wrong: %d\n", r
);
3906 MsiCloseHandle(rec
);
3908 /* insert legitimate values into it */
3909 query
= "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3910 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
3911 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3912 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3913 r
= MsiViewExecute(view
, 0);
3914 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3916 query
= "SELECT * FROM `integers`";
3917 r
= do_query(hdb
, query
, &rec
);
3918 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3920 r
= MsiRecordGetFieldCount(rec
);
3921 ok(r
== 8, "record count wrong: %d\n", r
);
3923 i
= MsiRecordGetInteger(rec
, 1);
3924 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
3925 i
= MsiRecordGetInteger(rec
, 3);
3926 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
3927 i
= MsiRecordGetInteger(rec
, 2);
3928 ok(i
== 2, "Expected 2, got %d\n", i
);
3929 i
= MsiRecordGetInteger(rec
, 4);
3930 ok(i
== 4, "Expected 4, got %d\n", i
);
3931 i
= MsiRecordGetInteger(rec
, 5);
3932 ok(i
== 5, "Expected 5, got %d\n", i
);
3933 i
= MsiRecordGetInteger(rec
, 6);
3934 ok(i
== 6, "Expected 6, got %d\n", i
);
3935 i
= MsiRecordGetInteger(rec
, 7);
3936 ok(i
== 7, "Expected 7, got %d\n", i
);
3937 i
= MsiRecordGetInteger(rec
, 8);
3938 ok(i
== 8, "Expected 8, got %d\n", i
);
3940 MsiCloseHandle(rec
);
3942 MsiCloseHandle(view
);
3944 r
= MsiDatabaseCommit(hdb
);
3945 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
3947 r
= MsiCloseHandle(hdb
);
3948 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3950 r
= DeleteFile(msifile
);
3951 ok(r
== TRUE
, "file didn't exist after commit\n");
3954 static void test_update(void)
3956 MSIHANDLE hdb
= 0, view
= 0, rec
= 0;
3957 CHAR result
[MAX_PATH
];
3962 /* just MsiOpenDatabase should not create a file */
3963 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
3964 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
3966 /* create the Control table */
3967 query
= "CREATE TABLE `Control` ( "
3968 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
3969 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
3970 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
3971 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
3972 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3973 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
3974 r
= MsiViewExecute(view
, 0);
3975 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
3976 r
= MsiViewClose(view
);
3977 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3978 r
= MsiCloseHandle(view
);
3979 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3982 query
= "INSERT INTO `Control` ( "
3983 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3984 "`Property`, `Text`, `Control_Next`, `Help` )"
3985 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3986 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3987 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3988 r
= MsiViewExecute(view
, 0);
3989 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3990 r
= MsiViewClose(view
);
3991 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3992 r
= MsiCloseHandle(view
);
3993 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3995 /* add a second control */
3996 query
= "INSERT INTO `Control` ( "
3997 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3998 "`Property`, `Text`, `Control_Next`, `Help` )"
3999 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
4000 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4001 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4002 r
= MsiViewExecute(view
, 0);
4003 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4004 r
= MsiViewClose(view
);
4005 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4006 r
= MsiCloseHandle(view
);
4007 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4009 /* add a third control */
4010 query
= "INSERT INTO `Control` ( "
4011 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4012 "`Property`, `Text`, `Control_Next`, `Help` )"
4013 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
4014 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4015 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4016 r
= MsiViewExecute(view
, 0);
4017 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4018 r
= MsiViewClose(view
);
4019 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4020 r
= MsiCloseHandle(view
);
4021 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4024 query
= "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4025 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4026 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4028 /* bad set column */
4029 query
= "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4030 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4031 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4033 /* bad where condition */
4034 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
4035 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4036 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4038 /* just the dialog_ specified */
4039 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4040 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4041 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4042 r
= MsiViewExecute(view
, 0);
4043 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4044 r
= MsiViewClose(view
);
4045 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4046 r
= MsiCloseHandle(view
);
4047 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4049 /* check the modified text */
4050 query
= "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
4051 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4052 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4053 r
= MsiViewExecute(view
, 0);
4054 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4056 r
= MsiViewFetch(view
, &rec
);
4057 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4060 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4061 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4062 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
4064 MsiCloseHandle(rec
);
4066 r
= MsiViewFetch(view
, &rec
);
4067 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4070 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4071 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4072 ok(!lstrlen(result
), "Expected an empty string, got %s\n", result
);
4074 MsiCloseHandle(rec
);
4076 r
= MsiViewFetch(view
, &rec
);
4077 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4079 r
= MsiViewClose(view
);
4080 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4081 r
= MsiCloseHandle(view
);
4082 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4084 /* dialog_ and control specified */
4085 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
4086 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4087 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4088 r
= MsiViewExecute(view
, 0);
4089 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4090 r
= MsiViewClose(view
);
4091 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4092 r
= MsiCloseHandle(view
);
4093 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4095 /* check the modified text */
4096 query
= "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
4097 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4098 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4099 r
= MsiViewExecute(view
, 0);
4100 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4102 r
= MsiViewFetch(view
, &rec
);
4103 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4106 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4107 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4108 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
4110 MsiCloseHandle(rec
);
4112 r
= MsiViewFetch(view
, &rec
);
4113 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4116 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4117 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4118 ok(!lstrlen(result
), "Expected an empty string, got %s\n", result
);
4120 MsiCloseHandle(rec
);
4122 r
= MsiViewFetch(view
, &rec
);
4123 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4125 r
= MsiViewClose(view
);
4126 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4127 r
= MsiCloseHandle(view
);
4128 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4130 /* no where condition */
4131 query
= "UPDATE `Control` SET `Text` = 'this is text'";
4132 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4133 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4134 r
= MsiViewExecute(view
, 0);
4135 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4136 r
= MsiViewClose(view
);
4137 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4138 r
= MsiCloseHandle(view
);
4139 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4141 /* check the modified text */
4142 query
= "SELECT `Text` FROM `Control`";
4143 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4144 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4145 r
= MsiViewExecute(view
, 0);
4146 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4148 r
= MsiViewFetch(view
, &rec
);
4149 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4152 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4153 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4154 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
4156 MsiCloseHandle(rec
);
4158 r
= MsiViewFetch(view
, &rec
);
4159 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4162 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4163 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4164 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
4166 MsiCloseHandle(rec
);
4168 r
= MsiViewFetch(view
, &rec
);
4169 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4172 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4173 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4174 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
4176 MsiCloseHandle(rec
);
4178 r
= MsiViewFetch(view
, &rec
);
4179 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4181 r
= MsiViewClose(view
);
4182 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4183 r
= MsiCloseHandle(view
);
4184 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4186 query
= "CREATE TABLE `Apple` ( `Banana` CHAR(72) NOT NULL, "
4187 "`Orange` CHAR(72), `Pear` INT PRIMARY KEY `Banana`)";
4188 r
= run_query(hdb
, 0, query
);
4189 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4191 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4192 "VALUES('one', 'two', 3)";
4193 r
= run_query(hdb
, 0, query
);
4194 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4196 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4197 "VALUES('three', 'four', 5)";
4198 r
= run_query(hdb
, 0, query
);
4199 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4201 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4202 "VALUES('six', 'two', 7)";
4203 r
= run_query(hdb
, 0, query
);
4204 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4206 rec
= MsiCreateRecord(2);
4207 MsiRecordSetInteger(rec
, 1, 8);
4208 MsiRecordSetString(rec
, 2, "two");
4210 query
= "UPDATE `Apple` SET `Pear` = ? WHERE `Orange` = ?";
4211 r
= run_query(hdb
, rec
, query
);
4212 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4214 MsiCloseHandle(rec
);
4216 query
= "SELECT `Pear` FROM `Apple` ORDER BY `Orange`";
4217 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4218 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4219 r
= MsiViewExecute(view
, 0);
4220 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4222 r
= MsiViewFetch(view
, &rec
);
4223 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4225 r
= MsiRecordGetInteger(rec
, 1);
4226 ok(r
== 8, "Expected 8, got %d\n", r
);
4228 MsiCloseHandle(rec
);
4230 r
= MsiViewFetch(view
, &rec
);
4231 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4233 r
= MsiRecordGetInteger(rec
, 1);
4234 ok(r
== 8, "Expected 8, got %d\n", r
);
4236 MsiCloseHandle(rec
);
4238 r
= MsiViewFetch(view
, &rec
);
4239 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4241 r
= MsiRecordGetInteger(rec
, 1);
4242 ok(r
== 5, "Expected 5, got %d\n", r
);
4244 MsiCloseHandle(rec
);
4246 r
= MsiViewFetch(view
, &rec
);
4247 ok(r
== ERROR_NO_MORE_ITEMS
, "Expectd ERROR_NO_MORE_ITEMS, got %d\n", r
);
4250 MsiCloseHandle(view
);
4252 r
= MsiDatabaseCommit(hdb
);
4253 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
4254 r
= MsiCloseHandle(hdb
);
4255 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4257 DeleteFile(msifile
);
4260 static void test_special_tables(void)
4266 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4267 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4269 query
= "CREATE TABLE `_Properties` ( "
4270 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4271 r
= run_query(hdb
, 0, query
);
4272 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
4274 query
= "CREATE TABLE `_Storages` ( "
4275 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4276 r
= run_query(hdb
, 0, query
);
4277 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Streams table\n");
4279 query
= "CREATE TABLE `_Streams` ( "
4280 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4281 r
= run_query(hdb
, 0, query
);
4282 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Streams table\n");
4284 query
= "CREATE TABLE `_Tables` ( "
4285 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4286 r
= run_query(hdb
, 0, query
);
4287 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Tables table\n");
4289 query
= "CREATE TABLE `_Columns` ( "
4290 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4291 r
= run_query(hdb
, 0, query
);
4292 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Columns table\n");
4294 r
= MsiCloseHandle(hdb
);
4295 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4298 static void test_tables_order(void)
4301 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4306 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4307 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4309 query
= "CREATE TABLE `foo` ( "
4310 "`baz` INT NOT NULL PRIMARY KEY `baz`)";
4311 r
= run_query(hdb
, 0, query
);
4312 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
4314 query
= "CREATE TABLE `bar` ( "
4315 "`foo` INT NOT NULL PRIMARY KEY `foo`)";
4316 r
= run_query(hdb
, 0, query
);
4317 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
4319 query
= "CREATE TABLE `baz` ( "
4320 "`bar` INT NOT NULL, "
4321 "`baz` INT NOT NULL, "
4322 "`foo` INT NOT NULL PRIMARY KEY `bar`)";
4323 r
= run_query(hdb
, 0, query
);
4324 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
4326 /* The names of the tables in the _Tables table must
4327 be in the same order as these names are created in
4328 the strings table. */
4329 query
= "SELECT * FROM `_Tables`";
4330 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4331 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4332 r
= MsiViewExecute(hview
, 0);
4333 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4335 r
= MsiViewFetch(hview
, &hrec
);
4336 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4337 sz
= sizeof(buffer
);
4338 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4339 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4340 ok(!lstrcmp(buffer
, "foo"), "Expected foo, got %s\n", buffer
);
4341 r
= MsiCloseHandle(hrec
);
4342 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4344 r
= MsiViewFetch(hview
, &hrec
);
4345 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4346 sz
= sizeof(buffer
);
4347 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4348 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4349 ok(!lstrcmp(buffer
, "baz"), "Expected baz, got %s\n", buffer
);
4350 r
= MsiCloseHandle(hrec
);
4351 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4353 r
= MsiViewFetch(hview
, &hrec
);
4354 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4355 sz
= sizeof(buffer
);
4356 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4357 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4358 ok(!lstrcmp(buffer
, "bar"), "Expected bar, got %s\n", buffer
);
4359 r
= MsiCloseHandle(hrec
);
4360 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4362 r
= MsiViewClose(hview
);
4363 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4364 r
= MsiCloseHandle(hview
);
4365 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4367 /* The names of the tables in the _Columns table must
4368 be in the same order as these names are created in
4369 the strings table. */
4370 query
= "SELECT * FROM `_Columns`";
4371 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4372 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4373 r
= MsiViewExecute(hview
, 0);
4374 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4376 r
= MsiViewFetch(hview
, &hrec
);
4377 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4378 sz
= sizeof(buffer
);
4379 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4380 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4381 ok(!lstrcmp(buffer
, "foo"), "Expected foo, got %s\n", buffer
);
4382 sz
= sizeof(buffer
);
4383 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4384 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4385 ok(!lstrcmp(buffer
, "baz"), "Expected baz, got %s\n", buffer
);
4386 r
= MsiCloseHandle(hrec
);
4387 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4389 r
= MsiViewFetch(hview
, &hrec
);
4390 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4391 sz
= sizeof(buffer
);
4392 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4393 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4394 ok(!lstrcmp(buffer
, "baz"), "Expected baz, got %s\n", buffer
);
4395 sz
= sizeof(buffer
);
4396 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4397 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4398 ok(!lstrcmp(buffer
, "bar"), "Expected bar, got %s\n", buffer
);
4399 r
= MsiCloseHandle(hrec
);
4400 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4402 r
= MsiViewFetch(hview
, &hrec
);
4403 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4404 sz
= sizeof(buffer
);
4405 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4406 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4407 ok(!lstrcmp(buffer
, "baz"), "Expected baz, got %s\n", buffer
);
4408 sz
= sizeof(buffer
);
4409 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4410 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4411 ok(!lstrcmp(buffer
, "baz"), "Expected baz, got %s\n", buffer
);
4412 r
= MsiCloseHandle(hrec
);
4413 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4415 r
= MsiViewFetch(hview
, &hrec
);
4416 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4417 sz
= sizeof(buffer
);
4418 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4419 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4420 ok(!lstrcmp(buffer
, "baz"), "Expected baz, got %s\n", buffer
);
4421 sz
= sizeof(buffer
);
4422 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4423 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4424 ok(!lstrcmp(buffer
, "foo"), "Expected foo, got %s\n", buffer
);
4425 r
= MsiCloseHandle(hrec
);
4426 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4428 r
= MsiViewFetch(hview
, &hrec
);
4429 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4430 sz
= sizeof(buffer
);
4431 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4432 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4433 ok(!lstrcmp(buffer
, "bar"), "Expected bar, got %s\n", buffer
);
4434 sz
= sizeof(buffer
);
4435 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4436 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4437 ok(!lstrcmp(buffer
, "foo"), "Expected foo, got %s\n", buffer
);
4438 r
= MsiCloseHandle(hrec
);
4439 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4441 r
= MsiViewClose(hview
);
4442 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4443 r
= MsiCloseHandle(hview
);
4444 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4446 r
= MsiCloseHandle(hdb
);
4447 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4449 DeleteFile(msifile
);
4452 static void test_select_markers(void)
4454 MSIHANDLE hdb
= 0, rec
, view
, res
;
4461 ok( hdb
, "failed to create db\n");
4463 r
= run_query(hdb
, 0,
4464 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
4465 ok(r
== S_OK
, "cannot create table: %d\n", r
);
4467 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4468 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
4469 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4471 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4472 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
4473 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4475 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4476 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
4477 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4479 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4480 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
4481 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4483 rec
= MsiCreateRecord(2);
4484 MsiRecordSetString(rec
, 1, "apple");
4485 MsiRecordSetString(rec
, 2, "two");
4487 query
= "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
4488 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4489 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4491 r
= MsiViewExecute(view
, rec
);
4492 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4494 r
= MsiViewFetch(view
, &res
);
4495 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4498 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4499 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4500 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4503 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4504 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4505 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4507 r
= MsiRecordGetInteger(res
, 3);
4508 ok(r
== 1, "Expected 1, got %d\n", r
);
4510 MsiCloseHandle(res
);
4512 r
= MsiViewFetch(view
, &res
);
4513 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4516 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4517 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4518 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4521 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4522 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4523 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4525 r
= MsiRecordGetInteger(res
, 3);
4526 ok(r
== 2, "Expected 2, got %d\n", r
);
4528 MsiCloseHandle(res
);
4530 r
= MsiViewFetch(view
, &res
);
4531 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4533 MsiCloseHandle(rec
);
4535 MsiCloseHandle(view
);
4537 rec
= MsiCreateRecord(2);
4538 MsiRecordSetString(rec
, 1, "one");
4539 MsiRecordSetInteger(rec
, 2, 1);
4541 query
= "SELECT * FROM `Table` WHERE `Two`<>? AND `Three`>? ORDER BY `Three`";
4542 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4543 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4544 r
= MsiViewExecute(view
, rec
);
4545 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4547 r
= MsiViewFetch(view
, &res
);
4548 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4551 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4552 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4553 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4556 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4557 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4558 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4560 r
= MsiRecordGetInteger(res
, 3);
4561 ok(r
== 2, "Expected 2, got %d\n", r
);
4563 MsiCloseHandle(res
);
4565 r
= MsiViewFetch(view
, &res
);
4566 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4569 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4570 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4571 ok(!lstrcmp(buf
, "banana"), "Expected banana, got %s\n", buf
);
4574 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4575 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4576 ok(!lstrcmp(buf
, "three"), "Expected three, got %s\n", buf
);
4578 r
= MsiRecordGetInteger(res
, 3);
4579 ok(r
== 3, "Expected 3, got %d\n", r
);
4581 MsiCloseHandle(res
);
4583 r
= MsiViewFetch(view
, &res
);
4584 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4586 MsiCloseHandle(rec
);
4588 MsiCloseHandle(view
);
4589 MsiCloseHandle(hdb
);
4590 DeleteFile(msifile
);
4593 static void test_viewmodify_update(void)
4595 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4599 DeleteFile(msifile
);
4601 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4602 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4604 query
= "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
4605 r
= run_query( hdb
, 0, query
);
4606 ok(r
== ERROR_SUCCESS
, "query failed\n");
4608 query
= "INSERT INTO `table` (`A`, `B`) VALUES (1, 2)";
4609 r
= run_query( hdb
, 0, query
);
4610 ok(r
== ERROR_SUCCESS
, "query failed\n");
4612 query
= "INSERT INTO `table` (`A`, `B`) VALUES (3, 4)";
4613 r
= run_query( hdb
, 0, query
);
4614 ok(r
== ERROR_SUCCESS
, "query failed\n");
4616 query
= "INSERT INTO `table` (`A`, `B`) VALUES (5, 6)";
4617 r
= run_query( hdb
, 0, query
);
4618 ok(r
== ERROR_SUCCESS
, "query failed\n");
4620 query
= "SELECT `B` FROM `table`";
4621 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4622 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4623 r
= MsiViewExecute(hview
, 0);
4624 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4625 r
= MsiViewFetch(hview
, &hrec
);
4626 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4628 r
= MsiRecordSetInteger(hrec
, 1, 0);
4629 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
4631 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
4632 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
4634 r
= MsiCloseHandle(hrec
);
4635 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4637 r
= MsiViewClose(hview
);
4638 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4639 r
= MsiCloseHandle(hview
);
4640 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4642 query
= "SELECT * FROM `table`";
4643 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4644 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4645 r
= MsiViewExecute(hview
, 0);
4646 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4647 r
= MsiViewFetch(hview
, &hrec
);
4648 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4650 r
= MsiRecordGetInteger(hrec
, 1);
4651 ok(r
== 1, "Expected 1, got %d\n", r
);
4652 r
= MsiRecordGetInteger(hrec
, 2);
4653 ok(r
== 0, "Expected 0, got %d\n", r
);
4655 r
= MsiCloseHandle(hrec
);
4656 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4658 r
= MsiViewFetch(hview
, &hrec
);
4659 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4661 r
= MsiRecordGetInteger(hrec
, 1);
4662 ok(r
== 3, "Expected 3, got %d\n", r
);
4663 r
= MsiRecordGetInteger(hrec
, 2);
4664 ok(r
== 4, "Expected 4, got %d\n", r
);
4666 r
= MsiCloseHandle(hrec
);
4667 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4669 r
= MsiViewFetch(hview
, &hrec
);
4670 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4672 r
= MsiRecordGetInteger(hrec
, 1);
4673 ok(r
== 5, "Expected 5, got %d\n", r
);
4674 r
= MsiRecordGetInteger(hrec
, 2);
4675 ok(r
== 6, "Expected 6, got %d\n", r
);
4677 r
= MsiCloseHandle(hrec
);
4678 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4680 r
= MsiViewFetch(hview
, &hrec
);
4681 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4683 r
= MsiViewClose(hview
);
4684 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4685 r
= MsiCloseHandle(hview
);
4686 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4688 /* loop through all elements */
4689 query
= "SELECT `B` FROM `table`";
4690 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4691 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4692 r
= MsiViewExecute(hview
, 0);
4693 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4697 r
= MsiViewFetch(hview
, &hrec
);
4698 if (r
!= ERROR_SUCCESS
)
4701 r
= MsiRecordSetInteger(hrec
, 1, 0);
4702 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
4704 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
4705 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
4707 r
= MsiCloseHandle(hrec
);
4708 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4711 r
= MsiViewClose(hview
);
4712 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4713 r
= MsiCloseHandle(hview
);
4714 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4716 query
= "SELECT * FROM `table`";
4717 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4718 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4719 r
= MsiViewExecute(hview
, 0);
4720 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4721 r
= MsiViewFetch(hview
, &hrec
);
4722 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4724 r
= MsiRecordGetInteger(hrec
, 1);
4725 ok(r
== 1, "Expected 1, got %d\n", r
);
4726 r
= MsiRecordGetInteger(hrec
, 2);
4727 ok(r
== 0, "Expected 0, got %d\n", r
);
4729 r
= MsiCloseHandle(hrec
);
4730 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4732 r
= MsiViewFetch(hview
, &hrec
);
4733 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4735 r
= MsiRecordGetInteger(hrec
, 1);
4736 ok(r
== 3, "Expected 3, got %d\n", r
);
4737 r
= MsiRecordGetInteger(hrec
, 2);
4738 ok(r
== 0, "Expected 0, got %d\n", r
);
4740 r
= MsiCloseHandle(hrec
);
4741 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4743 r
= MsiViewFetch(hview
, &hrec
);
4744 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4746 r
= MsiRecordGetInteger(hrec
, 1);
4747 ok(r
== 5, "Expected 5, got %d\n", r
);
4748 r
= MsiRecordGetInteger(hrec
, 2);
4749 ok(r
== 0, "Expected 0, got %d\n", r
);
4751 r
= MsiCloseHandle(hrec
);
4752 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4754 r
= MsiViewFetch(hview
, &hrec
);
4755 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4757 r
= MsiViewClose(hview
);
4758 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4759 r
= MsiCloseHandle(hview
);
4760 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4762 r
= MsiCloseHandle( hdb
);
4763 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
4766 static void test_viewmodify_assign(void)
4768 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4772 /* setup database */
4773 DeleteFile(msifile
);
4775 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4776 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4778 query
= "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
4779 r
= run_query( hdb
, 0, query
);
4780 ok(r
== ERROR_SUCCESS
, "query failed\n");
4782 /* assign to view, new primary key */
4783 query
= "SELECT * FROM `table`";
4784 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4785 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4786 r
= MsiViewExecute(hview
, 0);
4787 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4789 hrec
= MsiCreateRecord(2);
4790 ok(hrec
!= 0, "MsiCreateRecord failed\n");
4792 r
= MsiRecordSetInteger(hrec
, 1, 1);
4793 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
4794 r
= MsiRecordSetInteger(hrec
, 2, 2);
4795 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
4797 r
= MsiViewModify(hview
, MSIMODIFY_ASSIGN
, hrec
);
4798 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
4800 r
= MsiCloseHandle(hrec
);
4801 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4803 r
= MsiViewClose(hview
);
4804 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4805 r
= MsiCloseHandle(hview
);
4806 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4808 query
= "SELECT * FROM `table`";
4809 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4810 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4811 r
= MsiViewExecute(hview
, 0);
4812 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4813 r
= MsiViewFetch(hview
, &hrec
);
4814 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4816 r
= MsiRecordGetInteger(hrec
, 1);
4817 ok(r
== 1, "Expected 1, got %d\n", r
);
4818 r
= MsiRecordGetInteger(hrec
, 2);
4819 ok(r
== 2, "Expected 2, got %d\n", r
);
4821 r
= MsiCloseHandle(hrec
);
4822 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4824 r
= MsiViewFetch(hview
, &hrec
);
4825 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4827 r
= MsiViewClose(hview
);
4828 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4829 r
= MsiCloseHandle(hview
);
4830 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4832 /* assign to view, primary key matches */
4833 query
= "SELECT * FROM `table`";
4834 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4835 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4836 r
= MsiViewExecute(hview
, 0);
4837 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4839 hrec
= MsiCreateRecord(2);
4840 ok(hrec
!= 0, "MsiCreateRecord failed\n");
4842 r
= MsiRecordSetInteger(hrec
, 1, 1);
4843 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
4844 r
= MsiRecordSetInteger(hrec
, 2, 4);
4845 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
4847 r
= MsiViewModify(hview
, MSIMODIFY_ASSIGN
, hrec
);
4848 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
4850 r
= MsiCloseHandle(hrec
);
4851 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4853 r
= MsiViewClose(hview
);
4854 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4855 r
= MsiCloseHandle(hview
);
4856 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4858 query
= "SELECT * FROM `table`";
4859 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4860 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4861 r
= MsiViewExecute(hview
, 0);
4862 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4863 r
= MsiViewFetch(hview
, &hrec
);
4864 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4866 r
= MsiRecordGetInteger(hrec
, 1);
4867 ok(r
== 1, "Expected 1, got %d\n", r
);
4868 r
= MsiRecordGetInteger(hrec
, 2);
4869 ok(r
== 4, "Expected 4, got %d\n", r
);
4871 r
= MsiCloseHandle(hrec
);
4872 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4874 r
= MsiViewFetch(hview
, &hrec
);
4875 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4877 r
= MsiViewClose(hview
);
4878 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4879 r
= MsiCloseHandle(hview
);
4880 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4882 /* close database */
4883 r
= MsiCloseHandle( hdb
);
4884 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
4887 static const WCHAR data10
[] = { /* MOO */
4890 static const WCHAR data11
[] = { /* AAR */
4894 static const char data12
[] = /* _StringData */
4895 "MOOABAARCDonetwofourfive";
4896 static const WCHAR data13
[] = { /* _StringPool */
4898 0, 0, /* string 0 '' */
4899 0, 0, /* string 1 '' */
4900 0, 0, /* string 2 '' */
4901 0, 0, /* string 3 '' */
4902 0, 0, /* string 4 '' */
4903 3, 3, /* string 5 'MOO' */
4904 1, 1, /* string 6 'A' */
4905 1, 1, /* string 7 'B' */
4906 3, 3, /* string 8 'AAR' */
4907 1, 1, /* string 9 'C' */
4908 1, 1, /* string a 'D' */
4909 3, 1, /* string b 'one' */
4910 3, 1, /* string c 'two' */
4911 0, 0, /* string d '' */
4912 4, 1, /* string e 'four' */
4913 4, 1, /* string f 'five' */
4916 static void test_stringtable(void)
4918 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4919 IStorage
*stg
= NULL
;
4924 char buffer
[MAX_PATH
];
4925 WCHAR data
[MAX_PATH
];
4929 static const DWORD mode
= STGM_DIRECT
| STGM_READ
| STGM_SHARE_DENY_WRITE
;
4930 static const WCHAR stringdata
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0}; /* _StringData */
4931 static const WCHAR stringpool
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0}; /* _StringPool */
4932 static const WCHAR moo
[] = {0x4840, 0x3e16, 0x4818, 0}; /* MOO */
4933 static const WCHAR aar
[] = {0x4840, 0x3a8a, 0x481b, 0}; /* AAR */
4935 DeleteFile(msifile
);
4937 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4938 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4940 query
= "CREATE TABLE `MOO` (`A` INT, `B` CHAR(72) PRIMARY KEY `A`)";
4941 r
= run_query(hdb
, 0, query
);
4942 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4944 query
= "CREATE TABLE `AAR` (`C` INT, `D` CHAR(72) PRIMARY KEY `C`)";
4945 r
= run_query(hdb
, 0, query
);
4946 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4948 /* insert persistent row */
4949 query
= "INSERT INTO `MOO` (`A`, `B`) VALUES (1, 'one')";
4950 r
= run_query(hdb
, 0, query
);
4951 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4953 /* insert persistent row */
4954 query
= "INSERT INTO `AAR` (`C`, `D`) VALUES (2, 'two')";
4955 r
= run_query(hdb
, 0, query
);
4956 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4959 query
= "SELECT * FROM `MOO`";
4960 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4961 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4962 r
= MsiViewExecute(hview
, 0);
4963 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4965 hrec
= MsiCreateRecord(2);
4967 r
= MsiRecordSetInteger(hrec
, 1, 3);
4968 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4969 r
= MsiRecordSetString(hrec
, 2, "three");
4970 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4972 /* insert a nonpersistent row */
4973 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
4974 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4976 r
= MsiCloseHandle(hrec
);
4977 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4978 r
= MsiViewClose(hview
);
4979 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4980 r
= MsiCloseHandle(hview
);
4981 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4983 /* insert persistent row */
4984 query
= "INSERT INTO `MOO` (`A`, `B`) VALUES (4, 'four')";
4985 r
= run_query(hdb
, 0, query
);
4986 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4988 /* insert persistent row */
4989 query
= "INSERT INTO `AAR` (`C`, `D`) VALUES (5, 'five')";
4990 r
= run_query(hdb
, 0, query
);
4991 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4993 r
= MsiDatabaseCommit(hdb
);
4994 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4996 r
= MsiCloseHandle(hdb
);
4997 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4999 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
5000 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5002 query
= "SELECT * FROM `MOO`";
5003 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5004 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5006 r
= MsiViewExecute(hview
, 0);
5007 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5009 r
= MsiViewFetch(hview
, &hrec
);
5010 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5012 r
= MsiRecordGetFieldCount(hrec
);
5013 ok(r
== 2, "Expected 2, got %d\n", r
);
5015 r
= MsiRecordGetInteger(hrec
, 1);
5016 ok(r
== 1, "Expected 1, got %d\n", r
);
5018 sz
= sizeof(buffer
);
5019 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
5020 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5021 ok(!lstrcmp(buffer
, "one"), "Expected one, got %s\n", buffer
);
5023 r
= MsiCloseHandle(hrec
);
5024 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5026 r
= MsiViewFetch(hview
, &hrec
);
5029 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5032 r
= MsiViewClose(hview
);
5033 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5034 r
= MsiCloseHandle(hview
);
5035 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5036 r
= MsiCloseHandle(hrec
);
5037 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5039 query
= "SELECT * FROM `AAR`";
5040 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5041 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5043 r
= MsiViewExecute(hview
, 0);
5044 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5046 r
= MsiViewFetch(hview
, &hrec
);
5047 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5049 r
= MsiRecordGetFieldCount(hrec
);
5050 ok(r
== 2, "Expected 2, got %d\n", r
);
5052 r
= MsiRecordGetInteger(hrec
, 1);
5053 ok(r
== 2, "Expected 2, got %d\n", r
);
5055 sz
= sizeof(buffer
);
5056 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
5057 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5058 ok(!lstrcmp(buffer
, "two"), "Expected two, got %s\n", buffer
);
5060 r
= MsiCloseHandle(hrec
);
5061 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5063 r
= MsiViewFetch(hview
, &hrec
);
5064 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5066 r
= MsiRecordGetFieldCount(hrec
);
5067 ok(r
== 2, "Expected 2, got %d\n", r
);
5069 r
= MsiRecordGetInteger(hrec
, 1);
5070 ok(r
== 5, "Expected 5, got %d\n", r
);
5072 sz
= sizeof(buffer
);
5073 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
5074 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5075 ok(!lstrcmp(buffer
, "five"), "Expected five, got %s\n", buffer
);
5077 r
= MsiCloseHandle(hrec
);
5078 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5080 r
= MsiViewFetch(hview
, &hrec
);
5081 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5083 r
= MsiViewClose(hview
);
5084 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5085 r
= MsiCloseHandle(hview
);
5086 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5087 r
= MsiCloseHandle(hrec
);
5088 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5089 r
= MsiCloseHandle(hdb
);
5090 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5092 MultiByteToWideChar(CP_ACP
, 0, msifile
, -1, name
, 0x20);
5093 hr
= StgOpenStorage(name
, NULL
, mode
, NULL
, 0, &stg
);
5094 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5095 ok(stg
!= NULL
, "Expected non-NULL storage\n");
5097 hr
= IStorage_OpenStream(stg
, moo
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
5098 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5099 ok(stm
!= NULL
, "Expected non-NULL stream\n");
5101 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
5102 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5105 ok(read
== 4, "Expected 4, got %d\n", read
);
5106 ok(!memcmp(data
, data10
, read
), "Unexpected data\n");
5109 hr
= IStream_Release(stm
);
5110 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5112 hr
= IStorage_OpenStream(stg
, aar
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
5113 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5114 ok(stm
!= NULL
, "Expected non-NULL stream\n");
5116 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
5117 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5118 ok(read
== 8, "Expected 8, got %d\n", read
);
5121 ok(!memcmp(data
, data11
, read
), "Unexpected data\n");
5124 hr
= IStream_Release(stm
);
5125 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5127 hr
= IStorage_OpenStream(stg
, stringdata
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
5128 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5129 ok(stm
!= NULL
, "Expected non-NULL stream\n");
5131 hr
= IStream_Read(stm
, buffer
, MAX_PATH
, &read
);
5132 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5133 ok(read
== 24, "Expected 24, got %d\n", read
);
5134 ok(!memcmp(buffer
, data12
, read
), "Unexpected data\n");
5136 hr
= IStream_Release(stm
);
5137 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5139 hr
= IStorage_OpenStream(stg
, stringpool
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
5140 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5141 ok(stm
!= NULL
, "Expected non-NULL stream\n");
5143 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
5144 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5147 ok(read
== 64, "Expected 64, got %d\n", read
);
5148 ok(!memcmp(data
, data13
, read
), "Unexpected data\n");
5151 hr
= IStream_Release(stm
);
5152 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5154 hr
= IStorage_Release(stg
);
5155 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5157 DeleteFileA(msifile
);
5160 static void test_viewmodify_delete(void)
5162 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
5168 DeleteFile(msifile
);
5170 /* just MsiOpenDatabase should not create a file */
5171 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5172 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5174 query
= "CREATE TABLE `phone` ( "
5175 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
5176 "PRIMARY KEY `id`)";
5177 r
= run_query(hdb
, 0, query
);
5178 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5180 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
5181 "VALUES('1', 'Alan', '5030581')";
5182 r
= run_query(hdb
, 0, query
);
5183 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5185 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
5186 "VALUES('2', 'Barry', '928440')";
5187 r
= run_query(hdb
, 0, query
);
5188 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5190 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
5191 "VALUES('3', 'Cindy', '2937550')";
5192 r
= run_query(hdb
, 0, query
);
5193 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5195 query
= "SELECT * FROM `phone` WHERE `id` <= 2";
5196 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5197 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5198 r
= MsiViewExecute(hview
, 0);
5199 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5200 r
= MsiViewFetch(hview
, &hrec
);
5201 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5204 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
5205 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5207 r
= MsiCloseHandle(hrec
);
5208 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5209 r
= MsiViewFetch(hview
, &hrec
);
5210 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5213 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
5214 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5216 r
= MsiCloseHandle(hrec
);
5217 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5218 r
= MsiViewClose(hview
);
5219 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5220 r
= MsiCloseHandle(hview
);
5221 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5223 query
= "SELECT * FROM `phone`";
5224 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5225 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5226 r
= MsiViewExecute(hview
, 0);
5227 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5228 r
= MsiViewFetch(hview
, &hrec
);
5229 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5231 r
= MsiRecordGetInteger(hrec
, 1);
5232 ok(r
== 3, "Expected 3, got %d\n", r
);
5234 sz
= sizeof(buffer
);
5235 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
5236 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5237 ok(!lstrcmp(buffer
, "Cindy"), "Expected Cindy, got %s\n", buffer
);
5239 sz
= sizeof(buffer
);
5240 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
5241 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5242 ok(!lstrcmp(buffer
, "2937550"), "Expected 2937550, got %s\n", buffer
);
5244 r
= MsiCloseHandle(hrec
);
5245 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5247 r
= MsiViewFetch(hview
, &hrec
);
5248 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5250 r
= MsiViewClose(hview
);
5251 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5252 r
= MsiCloseHandle(hview
);
5253 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5254 r
= MsiCloseHandle(hdb
);
5255 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5258 static const WCHAR _Tables
[] = {0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0};
5259 static const WCHAR _StringData
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0};
5260 static const WCHAR _StringPool
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0};
5262 static const WCHAR data14
[] = { /* _StringPool */
5264 0, 0, /* string 0 '' */
5267 static const struct {
5271 } database_table_data
[] =
5274 {_StringData
, NULL
, 0},
5275 {_StringPool
, data14
, sizeof data14
},
5278 static void enum_stream_names(IStorage
*stg
)
5280 IEnumSTATSTG
*stgenum
= NULL
;
5285 BYTE data
[MAX_PATH
];
5286 BYTE check
[MAX_PATH
];
5289 memset(check
, 'a', MAX_PATH
);
5291 hr
= IStorage_EnumElements(stg
, 0, NULL
, 0, &stgenum
);
5292 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
5298 hr
= IEnumSTATSTG_Next(stgenum
, 1, &stat
, &count
);
5299 if(FAILED(hr
) || !count
)
5302 ok(!lstrcmpW(stat
.pwcsName
, database_table_data
[n
].name
),
5303 "Expected table %d name to match\n", n
);
5306 hr
= IStorage_OpenStream(stg
, stat
.pwcsName
, NULL
,
5307 STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
5308 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
5309 ok(stm
!= NULL
, "Expected non-NULL stream\n");
5312 memset(data
, 'a', MAX_PATH
);
5313 hr
= IStream_Read(stm
, data
, sz
, &count
);
5314 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
5316 ok(count
== database_table_data
[n
].size
,
5317 "Expected %d, got %d\n", database_table_data
[n
].size
, count
);
5319 if (!database_table_data
[n
].size
)
5320 ok(!memcmp(data
, check
, MAX_PATH
), "data should not be changed\n");
5322 ok(!memcmp(data
, database_table_data
[n
].data
, database_table_data
[n
].size
),
5323 "Expected table %d data to match\n", n
);
5325 IStream_Release(stm
);
5329 ok(n
== 3, "Expected 3, got %d\n", n
);
5331 IEnumSTATSTG_Release(stgenum
);
5334 static void test_defaultdatabase(void)
5339 IStorage
*stg
= NULL
;
5341 static const WCHAR msifileW
[] = {'w','i','n','e','t','e','s','t','.','m','s','i',0};
5343 DeleteFile(msifile
);
5345 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5346 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5348 r
= MsiDatabaseCommit(hdb
);
5349 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5351 MsiCloseHandle(hdb
);
5353 hr
= StgOpenStorage(msifileW
, NULL
, STGM_READ
| STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
5354 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
5355 ok(stg
!= NULL
, "Expected non-NULL stg\n");
5357 enum_stream_names(stg
);
5359 IStorage_Release(stg
);
5360 DeleteFileA(msifile
);
5363 static void test_order(void)
5365 MSIHANDLE hdb
, hview
, hrec
;
5366 CHAR buffer
[MAX_PATH
];
5372 ok(hdb
, "failed to create db\n");
5374 query
= "CREATE TABLE `Empty` ( `A` SHORT NOT NULL PRIMARY KEY `A`)";
5375 r
= run_query(hdb
, 0, query
);
5376 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5378 query
= "CREATE TABLE `Mesa` ( `A` SHORT NOT NULL, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
5379 r
= run_query(hdb
, 0, query
);
5380 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5382 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 1, 2, 9 )";
5383 r
= run_query(hdb
, 0, query
);
5384 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5386 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 3, 4, 7 )";
5387 r
= run_query(hdb
, 0, query
);
5388 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5390 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 5, 6, 8 )";
5391 r
= run_query(hdb
, 0, query
);
5392 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5394 query
= "CREATE TABLE `Sideboard` ( `D` SHORT NOT NULL, `E` SHORT, `F` SHORT PRIMARY KEY `D`)";
5395 r
= run_query(hdb
, 0, query
);
5396 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5398 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 10, 11, 18 )";
5399 r
= run_query(hdb
, 0, query
);
5400 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5402 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 12, 13, 16 )";
5403 r
= run_query(hdb
, 0, query
);
5404 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5406 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 14, 15, 17 )";
5407 r
= run_query(hdb
, 0, query
);
5408 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5410 query
= "SELECT `A`, `B` FROM `Mesa` ORDER BY `C`";
5411 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5412 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5413 r
= MsiViewExecute(hview
, 0);
5414 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5416 r
= MsiViewFetch(hview
, &hrec
);
5417 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5419 val
= MsiRecordGetInteger(hrec
, 1);
5420 ok(val
== 3, "Expected 3, got %d\n", val
);
5422 val
= MsiRecordGetInteger(hrec
, 2);
5423 ok(val
== 4, "Expected 3, got %d\n", val
);
5425 MsiCloseHandle(hrec
);
5427 r
= MsiViewFetch(hview
, &hrec
);
5428 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5430 val
= MsiRecordGetInteger(hrec
, 1);
5431 ok(val
== 5, "Expected 5, got %d\n", val
);
5433 val
= MsiRecordGetInteger(hrec
, 2);
5434 ok(val
== 6, "Expected 6, got %d\n", val
);
5436 MsiCloseHandle(hrec
);
5438 r
= MsiViewFetch(hview
, &hrec
);
5439 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5441 val
= MsiRecordGetInteger(hrec
, 1);
5442 ok(val
== 1, "Expected 1, got %d\n", val
);
5444 val
= MsiRecordGetInteger(hrec
, 2);
5445 ok(val
== 2, "Expected 2, got %d\n", val
);
5447 MsiCloseHandle(hrec
);
5449 r
= MsiViewFetch(hview
, &hrec
);
5450 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5452 MsiViewClose(hview
);
5453 MsiCloseHandle(hview
);
5455 query
= "SELECT `A`, `D` FROM `Mesa`, `Sideboard` ORDER BY `F`";
5456 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5457 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5458 r
= MsiViewExecute(hview
, 0);
5459 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5461 r
= MsiViewFetch(hview
, &hrec
);
5462 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5464 val
= MsiRecordGetInteger(hrec
, 1);
5465 ok(val
== 1, "Expected 1, got %d\n", val
);
5467 val
= MsiRecordGetInteger(hrec
, 2);
5468 ok(val
== 12, "Expected 12, got %d\n", val
);
5470 MsiCloseHandle(hrec
);
5472 r
= MsiViewFetch(hview
, &hrec
);
5473 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5475 val
= MsiRecordGetInteger(hrec
, 1);
5476 ok(val
== 3, "Expected 3, got %d\n", val
);
5478 val
= MsiRecordGetInteger(hrec
, 2);
5479 ok(val
== 12, "Expected 12, got %d\n", val
);
5481 MsiCloseHandle(hrec
);
5483 r
= MsiViewFetch(hview
, &hrec
);
5484 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5486 val
= MsiRecordGetInteger(hrec
, 1);
5487 ok(val
== 5, "Expected 5, got %d\n", val
);
5489 val
= MsiRecordGetInteger(hrec
, 2);
5490 ok(val
== 12, "Expected 12, got %d\n", val
);
5492 MsiCloseHandle(hrec
);
5494 r
= MsiViewFetch(hview
, &hrec
);
5495 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5497 val
= MsiRecordGetInteger(hrec
, 1);
5498 ok(val
== 1, "Expected 1, got %d\n", val
);
5500 val
= MsiRecordGetInteger(hrec
, 2);
5501 ok(val
== 14, "Expected 14, got %d\n", val
);
5503 MsiCloseHandle(hrec
);
5505 r
= MsiViewFetch(hview
, &hrec
);
5506 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5508 val
= MsiRecordGetInteger(hrec
, 1);
5509 ok(val
== 3, "Expected 3, got %d\n", val
);
5511 val
= MsiRecordGetInteger(hrec
, 2);
5512 ok(val
== 14, "Expected 14, got %d\n", val
);
5514 MsiCloseHandle(hrec
);
5516 r
= MsiViewFetch(hview
, &hrec
);
5517 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5519 val
= MsiRecordGetInteger(hrec
, 1);
5520 ok(val
== 5, "Expected 5, got %d\n", val
);
5522 val
= MsiRecordGetInteger(hrec
, 2);
5523 ok(val
== 14, "Expected 14, got %d\n", val
);
5525 MsiCloseHandle(hrec
);
5527 r
= MsiViewFetch(hview
, &hrec
);
5528 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5530 val
= MsiRecordGetInteger(hrec
, 1);
5531 ok(val
== 1, "Expected 1, got %d\n", val
);
5533 val
= MsiRecordGetInteger(hrec
, 2);
5534 ok(val
== 10, "Expected 10, got %d\n", val
);
5536 MsiCloseHandle(hrec
);
5538 r
= MsiViewFetch(hview
, &hrec
);
5539 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5541 val
= MsiRecordGetInteger(hrec
, 1);
5542 ok(val
== 3, "Expected 3, got %d\n", val
);
5544 val
= MsiRecordGetInteger(hrec
, 2);
5545 ok(val
== 10, "Expected 10, got %d\n", val
);
5547 MsiCloseHandle(hrec
);
5549 r
= MsiViewFetch(hview
, &hrec
);
5550 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5552 val
= MsiRecordGetInteger(hrec
, 1);
5553 ok(val
== 5, "Expected 5, got %d\n", val
);
5555 val
= MsiRecordGetInteger(hrec
, 2);
5556 ok(val
== 10, "Expected 10, got %d\n", val
);
5558 MsiCloseHandle(hrec
);
5560 r
= MsiViewFetch(hview
, &hrec
);
5561 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5563 MsiViewClose(hview
);
5564 MsiCloseHandle(hview
);
5566 query
= "SELECT * FROM `Empty` ORDER BY `A`";
5567 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5568 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5569 r
= MsiViewExecute(hview
, 0);
5570 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5572 r
= MsiViewFetch(hview
, &hrec
);
5573 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5575 MsiViewClose(hview
);
5576 MsiCloseHandle(hview
);
5578 query
= "CREATE TABLE `Buffet` ( `One` CHAR(72), `Two` SHORT PRIMARY KEY `One`)";
5579 r
= run_query(hdb
, 0, query
);
5580 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5582 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'uno', 2)";
5583 r
= run_query(hdb
, 0, query
);
5584 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5586 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'dos', 3)";
5587 r
= run_query(hdb
, 0, query
);
5588 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5590 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'tres', 1)";
5591 r
= run_query(hdb
, 0, query
);
5592 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5594 query
= "SELECT * FROM `Buffet` WHERE `One` = 'dos' ORDER BY `Two`";
5595 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5596 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5597 r
= MsiViewExecute(hview
, 0);
5598 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5600 r
= MsiViewFetch(hview
, &hrec
);
5601 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5603 sz
= sizeof(buffer
);
5604 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
5605 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5606 ok(!lstrcmp(buffer
, "dos"), "Expected \"dos\", got \"%s\"\n", buffer
);
5608 r
= MsiRecordGetInteger(hrec
, 2);
5609 ok(r
== 3, "Expected 3, got %d\n", r
);
5611 MsiCloseHandle(hrec
);
5613 r
= MsiViewFetch(hview
, &hrec
);
5614 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5616 MsiViewClose(hview
);
5617 MsiCloseHandle(hview
);
5618 MsiCloseHandle(hdb
);
5621 static void test_viewmodify_delete_temporary(void)
5623 MSIHANDLE hdb
, hview
, hrec
;
5627 DeleteFile(msifile
);
5629 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5630 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5632 query
= "CREATE TABLE `Table` ( `A` SHORT PRIMARY KEY `A` )";
5633 r
= run_query(hdb
, 0, query
);
5634 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5636 query
= "SELECT * FROM `Table`";
5637 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5638 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5639 r
= MsiViewExecute(hview
, 0);
5640 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5642 hrec
= MsiCreateRecord(1);
5643 MsiRecordSetInteger(hrec
, 1, 1);
5645 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, hrec
);
5646 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5648 MsiCloseHandle(hrec
);
5650 hrec
= MsiCreateRecord(1);
5651 MsiRecordSetInteger(hrec
, 1, 2);
5653 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
5654 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5656 MsiCloseHandle(hrec
);
5658 hrec
= MsiCreateRecord(1);
5659 MsiRecordSetInteger(hrec
, 1, 3);
5661 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, hrec
);
5662 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5664 MsiCloseHandle(hrec
);
5666 hrec
= MsiCreateRecord(1);
5667 MsiRecordSetInteger(hrec
, 1, 4);
5669 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
5670 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5672 MsiCloseHandle(hrec
);
5673 MsiViewClose(hview
);
5674 MsiCloseHandle(hview
);
5676 query
= "SELECT * FROM `Table` WHERE `A` = 2";
5677 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5678 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5679 r
= MsiViewExecute(hview
, 0);
5680 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5681 r
= MsiViewFetch(hview
, &hrec
);
5682 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5684 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
5685 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5687 MsiCloseHandle(hrec
);
5688 MsiViewClose(hview
);
5689 MsiCloseHandle(hview
);
5691 query
= "SELECT * FROM `Table` WHERE `A` = 3";
5692 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5693 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5694 r
= MsiViewExecute(hview
, 0);
5695 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5696 r
= MsiViewFetch(hview
, &hrec
);
5697 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5699 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
5700 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5702 MsiCloseHandle(hrec
);
5703 MsiViewClose(hview
);
5704 MsiCloseHandle(hview
);
5706 query
= "SELECT * FROM `Table` ORDER BY `A`";
5707 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5708 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5709 r
= MsiViewExecute(hview
, 0);
5710 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5712 r
= MsiViewFetch(hview
, &hrec
);
5713 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5715 r
= MsiRecordGetInteger(hrec
, 1);
5716 ok(r
== 1, "Expected 1, got %d\n", r
);
5718 MsiCloseHandle(hrec
);
5720 r
= MsiViewFetch(hview
, &hrec
);
5721 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5723 r
= MsiRecordGetInteger(hrec
, 1);
5724 ok(r
== 4, "Expected 4, got %d\n", r
);
5726 MsiCloseHandle(hrec
);
5728 r
= MsiViewFetch(hview
, &hrec
);
5729 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5731 MsiViewClose(hview
);
5732 MsiCloseHandle(hview
);
5733 MsiCloseHandle(hdb
);
5734 DeleteFileA(msifile
);
5737 static void test_deleterow(void)
5739 MSIHANDLE hdb
, hview
, hrec
;
5745 DeleteFile(msifile
);
5747 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5748 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5750 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5751 r
= run_query(hdb
, 0, query
);
5752 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5754 query
= "INSERT INTO `Table` (`A`) VALUES ('one')";
5755 r
= run_query(hdb
, 0, query
);
5756 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5758 query
= "INSERT INTO `Table` (`A`) VALUES ('two')";
5759 r
= run_query(hdb
, 0, query
);
5760 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5762 query
= "DELETE FROM `Table` WHERE `A` = 'one'";
5763 r
= run_query(hdb
, 0, query
);
5764 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5766 r
= MsiDatabaseCommit(hdb
);
5767 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5769 MsiCloseHandle(hdb
);
5771 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
5772 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5774 query
= "SELECT * FROM `Table`";
5775 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5776 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5777 r
= MsiViewExecute(hview
, 0);
5778 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5780 r
= MsiViewFetch(hview
, &hrec
);
5781 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5784 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5785 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5786 ok(!lstrcmpA(buf
, "two"), "Expected two, got %s\n", buf
);
5788 MsiCloseHandle(hrec
);
5790 r
= MsiViewFetch(hview
, &hrec
);
5791 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5793 MsiViewClose(hview
);
5794 MsiCloseHandle(hview
);
5795 MsiCloseHandle(hdb
);
5796 DeleteFileA(msifile
);
5799 static const CHAR import_dat
[] = "A\n"
5802 "This is a new 'string' ok\n";
5804 static void test_quotes(void)
5806 MSIHANDLE hdb
, hview
, hrec
;
5812 DeleteFile(msifile
);
5814 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5815 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5817 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5818 r
= run_query(hdb
, 0, query
);
5819 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5821 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a 'string' ok' )";
5822 r
= run_query(hdb
, 0, query
);
5823 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5824 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5826 query
= "INSERT INTO `Table` ( `A` ) VALUES ( \"This is a 'string' ok\" )";
5827 r
= run_query(hdb
, 0, query
);
5828 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5829 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5831 query
= "INSERT INTO `Table` ( `A` ) VALUES ( \"test\" )";
5832 r
= run_query(hdb
, 0, query
);
5833 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5834 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5836 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a ''string'' ok' )";
5837 r
= run_query(hdb
, 0, query
);
5838 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5840 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a '''string''' ok' )";
5841 r
= run_query(hdb
, 0, query
);
5842 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5844 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \'string\' ok' )";
5845 r
= run_query(hdb
, 0, query
);
5846 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5848 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \"string\" ok' )";
5849 r
= run_query(hdb
, 0, query
);
5850 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5852 query
= "SELECT * FROM `Table`";
5853 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5854 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5856 r
= MsiViewExecute(hview
, 0);
5857 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5859 r
= MsiViewFetch(hview
, &hrec
);
5860 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5863 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
5864 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5865 ok(!lstrcmp(buf
, "This is a \"string\" ok"),
5866 "Expected \"This is a \"string\" ok\", got %s\n", buf
);
5868 MsiCloseHandle(hrec
);
5870 r
= MsiViewFetch(hview
, &hrec
);
5871 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5873 MsiViewClose(hview
);
5874 MsiCloseHandle(hview
);
5876 write_file("import.idt", import_dat
, (sizeof(import_dat
) - 1) * sizeof(char));
5878 r
= MsiDatabaseImportA(hdb
, CURR_DIR
, "import.idt");
5879 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5881 DeleteFileA("import.idt");
5883 query
= "SELECT * FROM `Table`";
5884 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5885 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5887 r
= MsiViewExecute(hview
, 0);
5888 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5890 r
= MsiViewFetch(hview
, &hrec
);
5891 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5894 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
5895 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5896 ok(!lstrcmp(buf
, "This is a new 'string' ok"),
5897 "Expected \"This is a new 'string' ok\", got %s\n", buf
);
5899 MsiCloseHandle(hrec
);
5901 r
= MsiViewFetch(hview
, &hrec
);
5902 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5904 MsiViewClose(hview
);
5905 MsiCloseHandle(hview
);
5906 MsiCloseHandle(hdb
);
5907 DeleteFileA(msifile
);
5910 static void test_carriagereturn(void)
5912 MSIHANDLE hdb
, hview
, hrec
;
5918 DeleteFile(msifile
);
5920 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5921 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5923 query
= "CREATE TABLE `Table`\r ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5924 r
= run_query(hdb
, 0, query
);
5925 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5926 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5928 query
= "CREATE TABLE `Table` \r( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5929 r
= run_query(hdb
, 0, query
);
5930 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5931 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5933 query
= "CREATE\r TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5934 r
= run_query(hdb
, 0, query
);
5935 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5936 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5938 query
= "CREATE TABLE\r `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5939 r
= run_query(hdb
, 0, query
);
5940 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5941 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5943 query
= "CREATE TABLE `Table` (\r `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5944 r
= run_query(hdb
, 0, query
);
5945 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5946 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5948 query
= "CREATE TABLE `Table` ( `A`\r CHAR(72) NOT NULL PRIMARY KEY `A` )";
5949 r
= run_query(hdb
, 0, query
);
5950 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5951 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5953 query
= "CREATE TABLE `Table` ( `A` CHAR(72)\r NOT NULL PRIMARY KEY `A` )";
5954 r
= run_query(hdb
, 0, query
);
5955 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5956 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5958 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT\r NULL PRIMARY KEY `A` )";
5959 r
= run_query(hdb
, 0, query
);
5960 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5961 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5963 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT \rNULL PRIMARY KEY `A` )";
5964 r
= run_query(hdb
, 0, query
);
5965 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5966 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5968 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL\r PRIMARY KEY `A` )";
5969 r
= run_query(hdb
, 0, query
);
5970 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5971 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5973 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL \rPRIMARY KEY `A` )";
5974 r
= run_query(hdb
, 0, query
);
5975 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5976 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5978 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY\r KEY `A` )";
5979 r
= run_query(hdb
, 0, query
);
5980 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5981 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5983 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY \rKEY `A` )";
5984 r
= run_query(hdb
, 0, query
);
5985 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5986 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5988 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY\r `A` )";
5989 r
= run_query(hdb
, 0, query
);
5990 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5991 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5993 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A`\r )";
5994 r
= run_query(hdb
, 0, query
);
5995 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5996 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5998 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )\r";
5999 r
= run_query(hdb
, 0, query
);
6000 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6001 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6003 query
= "CREATE TABLE `\rOne` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6004 r
= run_query(hdb
, 0, query
);
6005 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6007 query
= "CREATE TABLE `Tw\ro` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6008 r
= run_query(hdb
, 0, query
);
6009 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6011 query
= "CREATE TABLE `Three\r` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6012 r
= run_query(hdb
, 0, query
);
6013 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6015 query
= "CREATE TABLE `Four` ( `A\r` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6016 r
= run_query(hdb
, 0, query
);
6017 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6018 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6020 query
= "CREATE TABLE `Four` ( `\rA` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6021 r
= run_query(hdb
, 0, query
);
6022 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6023 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6025 query
= "CREATE TABLE `Four` ( `A` CHAR(72\r) NOT NULL PRIMARY KEY `A` )";
6026 r
= run_query(hdb
, 0, query
);
6027 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6028 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6030 query
= "CREATE TABLE `Four` ( `A` CHAR(\r72) NOT NULL PRIMARY KEY `A` )";
6031 r
= run_query(hdb
, 0, query
);
6032 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6033 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6035 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `\rA` )";
6036 r
= run_query(hdb
, 0, query
);
6037 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6038 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6040 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
6041 r
= run_query(hdb
, 0, query
);
6042 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6043 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6045 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
6046 r
= run_query(hdb
, 0, query
);
6047 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6048 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6050 query
= "SELECT * FROM `_Tables`";
6051 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6052 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6053 r
= MsiViewExecute(hview
, 0);
6054 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6056 r
= MsiViewFetch(hview
, &hrec
);
6057 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6060 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6061 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6062 ok(!lstrcmpA(buf
, "\rOne"), "Expected \"\\rOne\", got \"%s\"\n", buf
);
6064 MsiCloseHandle(hrec
);
6066 r
= MsiViewFetch(hview
, &hrec
);
6067 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6070 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6071 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6072 ok(!lstrcmpA(buf
, "Tw\ro"), "Expected \"Tw\\ro\", got \"%s\"\n", buf
);
6074 MsiCloseHandle(hrec
);
6076 r
= MsiViewFetch(hview
, &hrec
);
6077 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6080 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6081 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6082 ok(!lstrcmpA(buf
, "Three\r"), "Expected \"Three\r\", got \"%s\"\n", buf
);
6084 MsiCloseHandle(hrec
);
6086 r
= MsiViewFetch(hview
, &hrec
);
6087 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6089 MsiViewClose(hview
);
6090 MsiCloseHandle(hview
);
6092 MsiCloseHandle(hdb
);
6093 DeleteFileA(msifile
);
6096 static void test_noquotes(void)
6098 MSIHANDLE hdb
, hview
, hrec
;
6104 DeleteFile(msifile
);
6106 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6107 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6109 query
= "CREATE TABLE Table ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6110 r
= run_query(hdb
, 0, query
);
6111 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6113 query
= "CREATE TABLE `Table` ( A CHAR(72) NOT NULL PRIMARY KEY `A` )";
6114 r
= run_query(hdb
, 0, query
);
6115 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6117 query
= "CREATE TABLE `Table2` ( `A` CHAR(72) NOT NULL PRIMARY KEY A )";
6118 r
= run_query(hdb
, 0, query
);
6119 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6121 query
= "CREATE TABLE `Table3` ( A CHAR(72) NOT NULL PRIMARY KEY A )";
6122 r
= run_query(hdb
, 0, query
);
6123 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6125 query
= "SELECT * FROM `_Tables`";
6126 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6127 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6128 r
= MsiViewExecute(hview
, 0);
6129 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6131 r
= MsiViewFetch(hview
, &hrec
);
6132 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6135 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6136 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6137 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
6139 MsiCloseHandle(hrec
);
6141 r
= MsiViewFetch(hview
, &hrec
);
6142 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6145 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6146 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6147 ok(!lstrcmpA(buf
, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf
);
6149 MsiCloseHandle(hrec
);
6151 r
= MsiViewFetch(hview
, &hrec
);
6152 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6155 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6156 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6157 ok(!lstrcmpA(buf
, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf
);
6159 MsiCloseHandle(hrec
);
6161 r
= MsiViewFetch(hview
, &hrec
);
6162 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6164 MsiViewClose(hview
);
6165 MsiCloseHandle(hview
);
6167 query
= "SELECT * FROM `_Columns`";
6168 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6169 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6170 r
= MsiViewExecute(hview
, 0);
6171 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6173 r
= MsiViewFetch(hview
, &hrec
);
6174 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6177 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6178 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6179 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
6181 r
= MsiRecordGetInteger(hrec
, 2);
6182 ok(r
== 1, "Expected 1, got %d\n", r
);
6185 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6186 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6187 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
6189 MsiCloseHandle(hrec
);
6191 r
= MsiViewFetch(hview
, &hrec
);
6192 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6195 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6196 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6197 ok(!lstrcmpA(buf
, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf
);
6199 r
= MsiRecordGetInteger(hrec
, 2);
6200 ok(r
== 1, "Expected 1, got %d\n", r
);
6203 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6204 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6205 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
6207 MsiCloseHandle(hrec
);
6209 r
= MsiViewFetch(hview
, &hrec
);
6210 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6213 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6214 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6215 ok(!lstrcmpA(buf
, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf
);
6217 r
= MsiRecordGetInteger(hrec
, 2);
6218 ok(r
== 1, "Expected 1, got %d\n", r
);
6221 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6222 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6223 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
6225 MsiCloseHandle(hrec
);
6227 r
= MsiViewFetch(hview
, &hrec
);
6228 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6230 MsiViewClose(hview
);
6231 MsiCloseHandle(hview
);
6233 query
= "INSERT INTO Table ( `A` ) VALUES ( 'hi' )";
6234 r
= run_query(hdb
, 0, query
);
6235 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6237 query
= "INSERT INTO `Table` ( A ) VALUES ( 'hi' )";
6238 r
= run_query(hdb
, 0, query
);
6239 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6241 query
= "INSERT INTO `Table` ( `A` ) VALUES ( hi )";
6242 r
= run_query(hdb
, 0, query
);
6243 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6245 query
= "SELECT * FROM Table WHERE `A` = 'hi'";
6246 r
= run_query(hdb
, 0, query
);
6247 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6249 query
= "SELECT * FROM `Table` WHERE `A` = hi";
6250 r
= run_query(hdb
, 0, query
);
6251 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6253 query
= "SELECT * FROM Table";
6254 r
= run_query(hdb
, 0, query
);
6255 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6257 query
= "SELECT * FROM Table2";
6258 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6259 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6260 r
= MsiViewExecute(hview
, 0);
6261 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6263 r
= MsiViewFetch(hview
, &hrec
);
6264 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6266 MsiViewClose(hview
);
6267 MsiCloseHandle(hview
);
6269 query
= "SELECT * FROM `Table` WHERE A = 'hi'";
6270 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6271 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6272 r
= MsiViewExecute(hview
, 0);
6273 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6275 r
= MsiViewFetch(hview
, &hrec
);
6276 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6279 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6280 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6281 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
6283 MsiCloseHandle(hrec
);
6285 r
= MsiViewFetch(hview
, &hrec
);
6286 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6288 MsiViewClose(hview
);
6289 MsiCloseHandle(hview
);
6290 MsiCloseHandle(hdb
);
6291 DeleteFileA(msifile
);
6294 static void read_file_data(LPCSTR filename
, LPSTR buffer
)
6299 file
= CreateFileA( filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
6300 ZeroMemory(buffer
, MAX_PATH
);
6301 ReadFile(file
, buffer
, MAX_PATH
, &read
, NULL
);
6305 static void test_forcecodepage(void)
6309 char buffer
[MAX_PATH
];
6312 DeleteFile(msifile
);
6314 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6315 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6317 query
= "SELECT * FROM `_ForceCodepage`";
6318 r
= run_query(hdb
, 0, query
);
6319 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6321 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6322 r
= run_query(hdb
, 0, query
);
6323 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6325 query
= "SELECT * FROM `_ForceCodepage`";
6326 r
= run_query(hdb
, 0, query
);
6327 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6329 r
= MsiDatabaseCommit(hdb
);
6330 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6332 query
= "SELECT * FROM `_ForceCodepage`";
6333 r
= run_query(hdb
, 0, query
);
6334 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6336 MsiCloseHandle(hdb
);
6338 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_DIRECT
, &hdb
);
6339 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6341 query
= "SELECT * FROM `_ForceCodepage`";
6342 r
= run_query(hdb
, 0, query
);
6343 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6345 r
= MsiDatabaseExport(hdb
, "_ForceCodepage", CURR_DIR
, "forcecodepage.idt");
6346 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6348 read_file_data("forcecodepage.idt", buffer
);
6349 ok(!lstrcmpA(buffer
, "\r\n\r\n0\t_ForceCodepage\r\n"),
6350 "Expected \"\r\n\r\n0\t_ForceCodepage\r\n\", got \"%s\"", buffer
);
6352 MsiCloseHandle(hdb
);
6353 DeleteFileA(msifile
);
6354 DeleteFileA("forcecodepage.idt");
6357 static void test_viewmodify_refresh(void)
6359 MSIHANDLE hdb
, hview
, hrec
;
6361 char buffer
[MAX_PATH
];
6365 DeleteFile(msifile
);
6367 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6368 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6370 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL, `B` INT PRIMARY KEY `A` )";
6371 r
= run_query(hdb
, 0, query
);
6372 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6374 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hi', 1 )";
6375 r
= run_query(hdb
, 0, query
);
6376 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6378 query
= "SELECT * FROM `Table`";
6379 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6380 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6381 r
= MsiViewExecute(hview
, 0);
6382 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6384 r
= MsiViewFetch(hview
, &hrec
);
6385 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6387 query
= "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hi'";
6388 r
= run_query(hdb
, 0, query
);
6389 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6391 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
6392 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6395 r
= MsiRecordGetStringA(hrec
, 1, buffer
, &size
);
6396 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6397 ok(!lstrcmpA(buffer
, "hi"), "Expected \"hi\", got \"%s\"\n", buffer
);
6398 ok(size
== 2, "Expected 2, got %d\n", size
);
6400 r
= MsiRecordGetInteger(hrec
, 2);
6401 ok(r
== 2, "Expected 2, got %d\n", r
);
6403 MsiCloseHandle(hrec
);
6404 MsiViewClose(hview
);
6405 MsiCloseHandle(hview
);
6407 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hello', 3 )";
6408 r
= run_query(hdb
, 0, query
);
6409 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6411 query
= "SELECT * FROM `Table` WHERE `B` = 3";
6412 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6413 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6414 r
= MsiViewExecute(hview
, 0);
6415 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6417 r
= MsiViewFetch(hview
, &hrec
);
6418 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6420 query
= "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hello'";
6421 r
= run_query(hdb
, 0, query
);
6422 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6424 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hithere', 3 )";
6425 r
= run_query(hdb
, 0, query
);
6426 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6428 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
6429 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6432 r
= MsiRecordGetStringA(hrec
, 1, buffer
, &size
);
6433 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6434 ok(!lstrcmpA(buffer
, "hello"), "Expected \"hello\", got \"%s\"\n", buffer
);
6435 ok(size
== 5, "Expected 5, got %d\n", size
);
6437 r
= MsiRecordGetInteger(hrec
, 2);
6438 ok(r
== 2, "Expected 2, got %d\n", r
);
6440 MsiCloseHandle(hrec
);
6441 MsiViewClose(hview
);
6442 MsiCloseHandle(hview
);
6443 MsiCloseHandle(hdb
);
6444 DeleteFileA(msifile
);
6447 static void test_where_viewmodify(void)
6449 MSIHANDLE hdb
, hview
, hrec
;
6453 DeleteFile(msifile
);
6455 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6456 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6458 query
= "CREATE TABLE `Table` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6459 r
= run_query(hdb
, 0, query
);
6460 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6462 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 1, 2 )";
6463 r
= run_query(hdb
, 0, query
);
6464 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6466 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 3, 4 )";
6467 r
= run_query(hdb
, 0, query
);
6468 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6470 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 5, 6 )";
6471 r
= run_query(hdb
, 0, query
);
6472 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6474 /* `B` = 3 doesn't match, but the view shouldn't be executed */
6475 query
= "SELECT * FROM `Table` WHERE `B` = 3";
6476 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6477 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6479 hrec
= MsiCreateRecord(2);
6480 MsiRecordSetInteger(hrec
, 1, 7);
6481 MsiRecordSetInteger(hrec
, 2, 8);
6483 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
6484 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6486 MsiCloseHandle(hrec
);
6487 MsiViewClose(hview
);
6488 MsiCloseHandle(hview
);
6490 query
= "SELECT * FROM `Table` WHERE `A` = 7";
6491 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6492 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6493 r
= MsiViewExecute(hview
, 0);
6494 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6496 r
= MsiViewFetch(hview
, &hrec
);
6497 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6499 r
= MsiRecordGetInteger(hrec
, 1);
6500 ok(r
== 7, "Expected 7, got %d\n", r
);
6502 r
= MsiRecordGetInteger(hrec
, 2);
6503 ok(r
== 8, "Expected 8, got %d\n", r
);
6505 MsiRecordSetInteger(hrec
, 2, 9);
6507 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
6508 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6510 MsiCloseHandle(hrec
);
6511 MsiViewClose(hview
);
6512 MsiCloseHandle(hview
);
6514 query
= "SELECT * FROM `Table` WHERE `A` = 7";
6515 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6516 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6517 r
= MsiViewExecute(hview
, 0);
6518 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6520 r
= MsiViewFetch(hview
, &hrec
);
6521 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6523 r
= MsiRecordGetInteger(hrec
, 1);
6524 ok(r
== 7, "Expected 7, got %d\n", r
);
6526 r
= MsiRecordGetInteger(hrec
, 2);
6527 ok(r
== 9, "Expected 9, got %d\n", r
);
6529 query
= "UPDATE `Table` SET `B` = 10 WHERE `A` = 7";
6530 r
= run_query(hdb
, 0, query
);
6531 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6533 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
6534 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6536 r
= MsiRecordGetInteger(hrec
, 1);
6537 ok(r
== 7, "Expected 7, got %d\n", r
);
6539 r
= MsiRecordGetInteger(hrec
, 2);
6540 ok(r
== 10, "Expected 10, got %d\n", r
);
6542 MsiCloseHandle(hrec
);
6543 MsiViewClose(hview
);
6544 MsiCloseHandle(hview
);
6545 MsiCloseHandle(hdb
);
6548 static BOOL
create_storage(LPCSTR name
)
6550 WCHAR nameW
[MAX_PATH
];
6557 MultiByteToWideChar(CP_ACP
, 0, name
, -1, nameW
, MAX_PATH
);
6558 hr
= StgCreateDocfile(nameW
, STGM_CREATE
| STGM_READWRITE
|
6559 STGM_DIRECT
| STGM_SHARE_EXCLUSIVE
, 0, &stg
);
6563 hr
= IStorage_CreateStream(stg
, nameW
, STGM_WRITE
| STGM_SHARE_EXCLUSIVE
,
6568 hr
= IStream_Write(stm
, "stgdata", 8, &count
);
6573 IStream_Release(stm
);
6574 IStorage_Release(stg
);
6579 static void test_storages_table(void)
6581 MSIHANDLE hdb
, hview
, hrec
;
6582 IStorage
*stg
, *inner
;
6584 char file
[MAX_PATH
];
6586 WCHAR name
[MAX_PATH
];
6593 ok(hdb
, "failed to create db\n");
6595 r
= MsiDatabaseCommit(hdb
);
6596 ok(r
== ERROR_SUCCESS
, "Failed to commit database\n");
6598 MsiCloseHandle(hdb
);
6600 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
6601 ok(r
== ERROR_SUCCESS
, "Failed to open database\n");
6603 /* check the column types */
6604 hrec
= get_column_info(hdb
, "SELECT * FROM `_Storages`", MSICOLINFO_TYPES
);
6605 ok(hrec
, "failed to get column info hrecord\n");
6606 ok(check_record(hrec
, 1, "s62"), "wrong hrecord type\n");
6607 ok(check_record(hrec
, 2, "V0"), "wrong hrecord type\n");
6609 MsiCloseHandle(hrec
);
6611 /* now try the names */
6612 hrec
= get_column_info(hdb
, "SELECT * FROM `_Storages`", MSICOLINFO_NAMES
);
6613 ok(hrec
, "failed to get column info hrecord\n");
6614 ok(check_record(hrec
, 1, "Name"), "wrong hrecord type\n");
6615 ok(check_record(hrec
, 2, "Data"), "wrong hrecord type\n");
6617 MsiCloseHandle(hrec
);
6619 create_storage("storage.bin");
6621 hrec
= MsiCreateRecord(2);
6622 MsiRecordSetString(hrec
, 1, "stgname");
6624 r
= MsiRecordSetStream(hrec
, 2, "storage.bin");
6625 ok(r
== ERROR_SUCCESS
, "Failed to add stream data to the hrecord: %d\n", r
);
6627 DeleteFileA("storage.bin");
6629 query
= "INSERT INTO `_Storages` (`Name`, `Data`) VALUES (?, ?)";
6630 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6631 ok(r
== ERROR_SUCCESS
, "Failed to open database hview: %d\n", r
);
6633 r
= MsiViewExecute(hview
, hrec
);
6634 ok(r
== ERROR_SUCCESS
, "Failed to execute hview: %d\n", r
);
6636 MsiCloseHandle(hrec
);
6637 MsiViewClose(hview
);
6638 MsiCloseHandle(hview
);
6640 query
= "SELECT `Name`, `Data` FROM `_Storages`";
6641 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6642 ok(r
== ERROR_SUCCESS
, "Failed to open database hview: %d\n", r
);
6644 r
= MsiViewExecute(hview
, 0);
6645 ok(r
== ERROR_SUCCESS
, "Failed to execute hview: %d\n", r
);
6647 r
= MsiViewFetch(hview
, &hrec
);
6648 ok(r
== ERROR_SUCCESS
, "Failed to fetch hrecord: %d\n", r
);
6651 r
= MsiRecordGetString(hrec
, 1, file
, &size
);
6652 ok(r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
6653 ok(!lstrcmp(file
, "stgname"), "Expected \"stgname\", got \"%s\"\n", file
);
6656 lstrcpyA(buf
, "apple");
6657 r
= MsiRecordReadStream(hrec
, 2, buf
, &size
);
6658 ok(r
== ERROR_INVALID_DATA
, "Expected ERROR_INVALID_DATA, got %d\n", r
);
6659 ok(!lstrcmp(buf
, "apple"), "Expected buf to be unchanged, got %s\n", buf
);
6660 ok(size
== 0, "Expected 0, got %d\n", size
);
6662 MsiCloseHandle(hrec
);
6664 r
= MsiViewFetch(hview
, &hrec
);
6665 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6667 MsiViewClose(hview
);
6668 MsiCloseHandle(hview
);
6670 MsiDatabaseCommit(hdb
);
6671 MsiCloseHandle(hdb
);
6673 MultiByteToWideChar(CP_ACP
, 0, msifile
, -1, name
, MAX_PATH
);
6674 hr
= StgOpenStorage(name
, NULL
, STGM_DIRECT
| STGM_READ
|
6675 STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
6676 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
6677 ok(stg
!= NULL
, "Expected non-NULL storage\n");
6679 MultiByteToWideChar(CP_ACP
, 0, "stgname", -1, name
, MAX_PATH
);
6680 hr
= IStorage_OpenStorage(stg
, name
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
,
6682 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
6683 ok(inner
!= NULL
, "Expected non-NULL storage\n");
6685 MultiByteToWideChar(CP_ACP
, 0, "storage.bin", -1, name
, MAX_PATH
);
6686 hr
= IStorage_OpenStream(inner
, name
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
6687 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
6688 ok(stm
!= NULL
, "Expected non-NULL stream\n");
6690 hr
= IStream_Read(stm
, buf
, MAX_PATH
, &size
);
6691 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
6692 ok(size
== 8, "Expected 8, got %d\n", size
);
6693 ok(!lstrcmpA(buf
, "stgdata"), "Expected \"stgdata\", got \"%s\"\n", buf
);
6695 IStream_Release(stm
);
6696 IStorage_Release(inner
);
6698 IStorage_Release(stg
);
6699 DeleteFileA(msifile
);
6702 static void test_dbtopackage(void)
6704 MSIHANDLE hdb
, hpkg
;
6710 /* create an empty database, transact mode */
6711 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6712 ok(r
== ERROR_SUCCESS
, "Failed to create database\n");
6714 set_summary_info(hdb
);
6716 r
= create_directory_table(hdb
);
6717 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6719 r
= create_custom_action_table(hdb
);
6720 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6722 r
= add_custom_action_entry(hdb
, "'SetProp', 51, 'MYPROP', 'grape'");
6723 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6725 sprintf(package
, "#%i", hdb
);
6726 r
= MsiOpenPackage(package
, &hpkg
);
6727 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6729 /* property is not set yet */
6731 lstrcpyA(buf
, "kiwi");
6732 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6733 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6734 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
6735 ok(size
== 0, "Expected 0, got %d\n", size
);
6737 /* run the custom action to set the property */
6738 r
= MsiDoAction(hpkg
, "SetProp");
6739 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6741 /* property is now set */
6743 lstrcpyA(buf
, "kiwi");
6744 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6745 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6746 ok(!lstrcmpA(buf
, "grape"), "Expected \"grape\", got \"%s\"\n", buf
);
6747 ok(size
== 5, "Expected 5, got %d\n", size
);
6749 MsiCloseHandle(hpkg
);
6751 /* reset the package */
6752 r
= MsiOpenPackage(package
, &hpkg
);
6753 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6755 /* property is not set anymore */
6757 lstrcpyA(buf
, "kiwi");
6758 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6759 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6762 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
6763 ok(size
== 0, "Expected 0, got %d\n", size
);
6766 MsiCloseHandle(hdb
);
6767 MsiCloseHandle(hpkg
);
6769 /* create an empty database, direct mode */
6770 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATEDIRECT
, &hdb
);
6771 ok(r
== ERROR_SUCCESS
, "Failed to create database\n");
6773 set_summary_info(hdb
);
6775 r
= create_directory_table(hdb
);
6776 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6778 r
= create_custom_action_table(hdb
);
6779 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6781 r
= add_custom_action_entry(hdb
, "'SetProp', 51, 'MYPROP', 'grape'");
6782 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6784 sprintf(package
, "#%i", hdb
);
6785 r
= MsiOpenPackage(package
, &hpkg
);
6786 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6788 /* property is not set yet */
6790 lstrcpyA(buf
, "kiwi");
6791 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6792 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6793 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
6794 ok(size
== 0, "Expected 0, got %d\n", size
);
6796 /* run the custom action to set the property */
6797 r
= MsiDoAction(hpkg
, "SetProp");
6798 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6800 /* property is now set */
6802 lstrcpyA(buf
, "kiwi");
6803 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6804 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6805 ok(!lstrcmpA(buf
, "grape"), "Expected \"grape\", got \"%s\"\n", buf
);
6806 ok(size
== 5, "Expected 5, got %d\n", size
);
6808 MsiCloseHandle(hpkg
);
6810 /* reset the package */
6811 r
= MsiOpenPackage(package
, &hpkg
);
6812 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6814 /* property is not set anymore */
6816 lstrcpyA(buf
, "kiwi");
6817 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6818 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6821 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
6822 ok(size
== 0, "Expected 0, got %d\n", size
);
6825 MsiCloseHandle(hdb
);
6826 MsiCloseHandle(hpkg
);
6827 DeleteFileA(msifile
);
6830 static void test_droptable(void)
6832 MSIHANDLE hdb
, hview
, hrec
;
6838 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6839 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6841 query
= "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
6842 r
= run_query(hdb
, 0, query
);
6843 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6845 query
= "SELECT * FROM `One`";
6846 r
= do_query(hdb
, query
, &hrec
);
6847 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6849 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
6850 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6851 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6852 r
= MsiViewExecute(hview
, 0);
6853 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6855 r
= MsiViewFetch(hview
, &hrec
);
6856 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6859 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6860 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6861 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6863 MsiCloseHandle(hrec
);
6864 MsiViewClose(hview
);
6865 MsiCloseHandle(hview
);
6867 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
6868 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6869 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6870 r
= MsiViewExecute(hview
, 0);
6871 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6873 r
= MsiViewFetch(hview
, &hrec
);
6874 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6877 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6878 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6879 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6881 r
= MsiRecordGetInteger(hrec
, 2);
6882 ok(r
== 1, "Expected 1, got %d\n", r
);
6885 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6886 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6887 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
6889 MsiCloseHandle(hrec
);
6891 r
= MsiViewFetch(hview
, &hrec
);
6892 ok(r
== ERROR_NO_MORE_ITEMS
,
6893 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6895 MsiViewClose(hview
);
6896 MsiCloseHandle(hview
);
6898 query
= "DROP `One`";
6899 r
= run_query(hdb
, 0, query
);
6900 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6901 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6903 query
= "DROP TABLE";
6904 r
= run_query(hdb
, 0, query
);
6905 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6906 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6908 query
= "DROP TABLE `One`";
6910 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6911 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6912 r
= MsiViewExecute(hview
, 0);
6913 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6915 r
= MsiViewFetch(hview
, &hrec
);
6916 ok(r
== ERROR_FUNCTION_FAILED
,
6917 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
6919 MsiViewClose(hview
);
6920 MsiCloseHandle(hview
);
6922 query
= "SELECT * FROM `IDontExist`";
6923 r
= do_query(hdb
, query
, &hrec
);
6924 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6925 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6927 query
= "SELECT * FROM `One`";
6928 r
= do_query(hdb
, query
, &hrec
);
6929 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6930 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6932 query
= "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
6933 r
= run_query(hdb
, 0, query
);
6934 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6936 query
= "DROP TABLE One";
6937 r
= run_query(hdb
, 0, query
);
6938 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6940 query
= "SELECT * FROM `One`";
6941 r
= do_query(hdb
, query
, &hrec
);
6942 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6943 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6945 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
6946 r
= do_query(hdb
, query
, &hrec
);
6947 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6949 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
6950 r
= do_query(hdb
, query
, &hrec
);
6951 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6953 query
= "CREATE TABLE `One` ( `B` INT, `C` INT PRIMARY KEY `B` )";
6954 r
= run_query(hdb
, 0, query
);
6955 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6957 query
= "SELECT * FROM `One`";
6958 r
= do_query(hdb
, query
, &hrec
);
6959 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6961 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
6962 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6963 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6964 r
= MsiViewExecute(hview
, 0);
6965 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6967 r
= MsiViewFetch(hview
, &hrec
);
6968 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6971 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6972 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6973 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6975 MsiCloseHandle(hrec
);
6976 MsiViewClose(hview
);
6977 MsiCloseHandle(hview
);
6979 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
6980 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6981 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6982 r
= MsiViewExecute(hview
, 0);
6983 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6985 r
= MsiViewFetch(hview
, &hrec
);
6986 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6989 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6990 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6991 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6993 r
= MsiRecordGetInteger(hrec
, 2);
6994 ok(r
== 1, "Expected 1, got %d\n", r
);
6997 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6998 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6999 ok(!lstrcmpA(buf
, "B"), "Expected \"B\", got \"%s\"\n", buf
);
7001 MsiCloseHandle(hrec
);
7003 r
= MsiViewFetch(hview
, &hrec
);
7004 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7007 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
7008 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7009 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
7011 r
= MsiRecordGetInteger(hrec
, 2);
7012 ok(r
== 2, "Expected 2, got %d\n", r
);
7015 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
7016 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7017 ok(!lstrcmpA(buf
, "C"), "Expected \"C\", got \"%s\"\n", buf
);
7019 MsiCloseHandle(hrec
);
7021 r
= MsiViewFetch(hview
, &hrec
);
7022 ok(r
== ERROR_NO_MORE_ITEMS
,
7023 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7025 MsiViewClose(hview
);
7026 MsiCloseHandle(hview
);
7028 query
= "DROP TABLE One";
7029 r
= run_query(hdb
, 0, query
);
7030 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7032 query
= "SELECT * FROM `One`";
7033 r
= do_query(hdb
, query
, &hrec
);
7034 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7035 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7037 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7038 r
= do_query(hdb
, query
, &hrec
);
7039 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7041 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7042 r
= do_query(hdb
, query
, &hrec
);
7043 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7045 MsiCloseHandle(hdb
);
7046 DeleteFileA(msifile
);
7049 static void test_dbmerge(void)
7051 MSIHANDLE hdb
, href
, hview
, hrec
;
7057 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
7058 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7060 r
= MsiOpenDatabase("refdb.msi", MSIDBOPEN_CREATE
, &href
);
7061 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7063 /* hDatabase is invalid */
7064 r
= MsiDatabaseMergeA(0, href
, "MergeErrors");
7065 ok(r
== ERROR_INVALID_HANDLE
,
7066 "Expected ERROR_INVALID_HANDLE, got %d\n", r
);
7068 /* hDatabaseMerge is invalid */
7069 r
= MsiDatabaseMergeA(hdb
, 0, "MergeErrors");
7070 ok(r
== ERROR_INVALID_HANDLE
,
7071 "Expected ERROR_INVALID_HANDLE, got %d\n", r
);
7073 /* szTableName is NULL */
7074 r
= MsiDatabaseMergeA(hdb
, href
, NULL
);
7075 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7077 /* szTableName is empty */
7078 r
= MsiDatabaseMergeA(hdb
, href
, "");
7079 ok(r
== ERROR_INVALID_TABLE
, "Expected ERROR_INVALID_TABLE, got %d\n", r
);
7081 /* both DBs empty, szTableName is valid */
7082 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7083 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7085 query
= "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7086 r
= run_query(hdb
, 0, query
);
7087 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7089 query
= "CREATE TABLE `One` ( `A` CHAR(72) PRIMARY KEY `A` )";
7090 r
= run_query(href
, 0, query
);
7091 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7093 /* column types don't match */
7094 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7095 ok(r
== ERROR_DATATYPE_MISMATCH
,
7096 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
7098 /* nothing in MergeErrors */
7099 query
= "SELECT * FROM `MergeErrors`";
7100 r
= do_query(hdb
, query
, &hrec
);
7101 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7102 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7104 query
= "DROP TABLE `One`";
7105 r
= run_query(hdb
, 0, query
);
7106 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7108 query
= "DROP TABLE `One`";
7109 r
= run_query(href
, 0, query
);
7110 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7112 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7113 r
= run_query(hdb
, 0, query
);
7114 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7116 query
= "CREATE TABLE `One` ( `A` INT, `C` INT PRIMARY KEY `A` )";
7117 r
= run_query(href
, 0, query
);
7118 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7120 /* column names don't match */
7121 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7122 ok(r
== ERROR_DATATYPE_MISMATCH
,
7123 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
7125 /* nothing in MergeErrors */
7126 query
= "SELECT * FROM `MergeErrors`";
7127 r
= do_query(hdb
, query
, &hrec
);
7128 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7129 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7131 query
= "DROP TABLE `One`";
7132 r
= run_query(hdb
, 0, query
);
7133 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7135 query
= "DROP TABLE `One`";
7136 r
= run_query(href
, 0, query
);
7137 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7139 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7140 r
= run_query(hdb
, 0, query
);
7141 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7143 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `B` )";
7144 r
= run_query(href
, 0, query
);
7145 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7147 /* primary keys don't match */
7148 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7149 ok(r
== ERROR_DATATYPE_MISMATCH
,
7150 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
7152 /* nothing in MergeErrors */
7153 query
= "SELECT * FROM `MergeErrors`";
7154 r
= do_query(hdb
, query
, &hrec
);
7155 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7156 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7158 query
= "DROP TABLE `One`";
7159 r
= run_query(hdb
, 0, query
);
7160 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7162 query
= "DROP TABLE `One`";
7163 r
= run_query(href
, 0, query
);
7164 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7166 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7167 r
= run_query(hdb
, 0, query
);
7168 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7170 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A`, `B` )";
7171 r
= run_query(href
, 0, query
);
7172 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7174 /* number of primary keys doesn't match */
7175 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7176 ok(r
== ERROR_DATATYPE_MISMATCH
,
7177 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
7179 /* nothing in MergeErrors */
7180 query
= "SELECT * FROM `MergeErrors`";
7181 r
= do_query(hdb
, query
, &hrec
);
7182 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7183 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7185 query
= "DROP TABLE `One`";
7186 r
= run_query(hdb
, 0, query
);
7187 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7189 query
= "DROP TABLE `One`";
7190 r
= run_query(href
, 0, query
);
7191 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7193 query
= "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
7194 r
= run_query(hdb
, 0, query
);
7195 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7197 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7198 r
= run_query(href
, 0, query
);
7199 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7201 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
7202 r
= run_query(href
, 0, query
);
7203 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7205 /* number of columns doesn't match */
7206 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7207 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7209 query
= "SELECT * FROM `One`";
7210 r
= do_query(hdb
, query
, &hrec
);
7211 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7213 r
= MsiRecordGetInteger(hrec
, 1);
7214 ok(r
== 1, "Expected 1, got %d\n", r
);
7216 r
= MsiRecordGetInteger(hrec
, 2);
7217 ok(r
== 2, "Expected 2, got %d\n", r
);
7219 r
= MsiRecordGetInteger(hrec
, 3);
7220 ok(r
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", r
);
7222 MsiCloseHandle(hrec
);
7224 /* nothing in MergeErrors */
7225 query
= "SELECT * FROM `MergeErrors`";
7226 r
= do_query(hdb
, query
, &hrec
);
7227 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7228 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7230 query
= "DROP TABLE `One`";
7231 r
= run_query(hdb
, 0, query
);
7232 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7234 query
= "DROP TABLE `One`";
7235 r
= run_query(href
, 0, query
);
7236 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7238 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7239 r
= run_query(hdb
, 0, query
);
7240 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7242 query
= "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
7243 r
= run_query(href
, 0, query
);
7244 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7246 query
= "INSERT INTO `One` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
7247 r
= run_query(href
, 0, query
);
7248 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7250 /* number of columns doesn't match */
7251 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7252 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7254 query
= "SELECT * FROM `One`";
7255 r
= do_query(hdb
, query
, &hrec
);
7256 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7258 r
= MsiRecordGetInteger(hrec
, 1);
7259 ok(r
== 1, "Expected 1, got %d\n", r
);
7261 r
= MsiRecordGetInteger(hrec
, 2);
7262 ok(r
== 2, "Expected 2, got %d\n", r
);
7264 r
= MsiRecordGetInteger(hrec
, 3);
7265 ok(r
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", r
);
7267 MsiCloseHandle(hrec
);
7269 /* nothing in MergeErrors */
7270 query
= "SELECT * FROM `MergeErrors`";
7271 r
= do_query(hdb
, query
, &hrec
);
7272 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7273 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7275 query
= "DROP TABLE `One`";
7276 r
= run_query(hdb
, 0, query
);
7277 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7279 query
= "DROP TABLE `One`";
7280 r
= run_query(href
, 0, query
);
7281 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7283 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7284 r
= run_query(hdb
, 0, query
);
7285 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7287 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 1 )";
7288 r
= run_query(hdb
, 0, query
);
7289 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7291 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 2 )";
7292 r
= run_query(hdb
, 0, query
);
7293 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7295 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7296 r
= run_query(href
, 0, query
);
7297 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7299 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
7300 r
= run_query(href
, 0, query
);
7301 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7303 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 3 )";
7304 r
= run_query(href
, 0, query
);
7305 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7307 /* primary keys match, rows do not */
7308 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7309 ok(r
== ERROR_FUNCTION_FAILED
,
7310 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
7312 /* nothing in MergeErrors */
7313 query
= "SELECT * FROM `MergeErrors`";
7314 r
= do_query(hdb
, query
, &hrec
);
7315 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7318 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
7319 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7320 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
7322 r
= MsiRecordGetInteger(hrec
, 2);
7323 ok(r
== 2, "Expected 2, got %d\n", r
);
7325 MsiCloseHandle(hrec
);
7327 r
= MsiDatabaseOpenViewA(hdb
, "SELECT * FROM `MergeErrors`", &hview
);
7328 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7330 r
= MsiViewGetColumnInfo(hview
, MSICOLINFO_NAMES
, &hrec
);
7331 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7334 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
7335 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
7338 r
= MsiRecordGetString(hrec
, 2, buf
, &size
);
7339 ok(!lstrcmpA(buf
, "NumRowMergeConflicts"),
7340 "Expected \"NumRowMergeConflicts\", got \"%s\"\n", buf
);
7342 MsiCloseHandle(hrec
);
7344 r
= MsiViewGetColumnInfo(hview
, MSICOLINFO_TYPES
, &hrec
);
7345 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7348 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
7349 ok(!lstrcmpA(buf
, "s255"), "Expected \"s255\", got \"%s\"\n", buf
);
7352 r
= MsiRecordGetString(hrec
, 2, buf
, &size
);
7353 ok(!lstrcmpA(buf
, "i2"), "Expected \"i2\", got \"%s\"\n", buf
);
7355 MsiCloseHandle(hrec
);
7356 MsiViewClose(hview
);
7357 MsiCloseHandle(hview
);
7359 query
= "DROP TABLE `MergeErrors`";
7360 r
= run_query(hdb
, 0, query
);
7361 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7363 query
= "DROP TABLE `One`";
7364 r
= run_query(hdb
, 0, query
);
7365 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7367 query
= "DROP TABLE `One`";
7368 r
= run_query(href
, 0, query
);
7369 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7371 query
= "CREATE TABLE `One` ( `A` INT, `B` CHAR(72) PRIMARY KEY `A` )";
7372 r
= run_query(href
, 0, query
);
7373 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7375 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
7376 r
= run_query(href
, 0, query
);
7377 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7379 /* table from merged database is not in target database */
7380 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7381 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7383 query
= "SELECT * FROM `One`";
7384 r
= do_query(hdb
, query
, &hrec
);
7385 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7387 r
= MsiRecordGetInteger(hrec
, 1);
7388 ok(r
== 1, "Expected 1, got %d\n", r
);
7391 r
= MsiRecordGetStringA(hrec
, 2, buf
, &size
);
7392 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7393 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
7395 MsiCloseHandle(hrec
);
7397 /* nothing in MergeErrors */
7398 query
= "SELECT * FROM `MergeErrors`";
7399 r
= do_query(hdb
, query
, &hrec
);
7400 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7401 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7403 query
= "DROP TABLE `One`";
7404 r
= run_query(hdb
, 0, query
);
7405 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7407 query
= "DROP TABLE `One`";
7408 r
= run_query(href
, 0, query
);
7409 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7411 query
= "CREATE TABLE `One` ( "
7412 "`A` CHAR(72), `B` INT PRIMARY KEY `A` )";
7413 r
= run_query(hdb
, 0, query
);
7414 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7416 query
= "CREATE TABLE `One` ( "
7417 "`A` CHAR(72), `B` INT PRIMARY KEY `A` )";
7418 r
= run_query(href
, 0, query
);
7419 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7421 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 'hi', 1 )";
7422 r
= run_query(href
, 0, query
);
7423 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7425 /* primary key is string */
7426 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7427 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7429 query
= "SELECT * FROM `One`";
7430 r
= do_query(hdb
, query
, &hrec
);
7431 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7434 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
7435 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7436 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
7438 r
= MsiRecordGetInteger(hrec
, 2);
7439 ok(r
== 1, "Expected 1, got %d\n", r
);
7441 MsiCloseHandle(hrec
);
7443 /* nothing in MergeErrors */
7444 query
= "SELECT * FROM `MergeErrors`";
7445 r
= do_query(hdb
, query
, &hrec
);
7446 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7447 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7449 create_file_data("codepage.idt", "\r\n\r\n850\t_ForceCodepage\r\n", 0);
7451 GetCurrentDirectoryA(MAX_PATH
, buf
);
7452 r
= MsiDatabaseImportA(hdb
, buf
, "codepage.idt");
7455 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7458 query
= "DROP TABLE `One`";
7459 r
= run_query(hdb
, 0, query
);
7460 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7462 query
= "DROP TABLE `One`";
7463 r
= run_query(href
, 0, query
);
7464 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7466 query
= "CREATE TABLE `One` ( "
7467 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
7468 r
= run_query(hdb
, 0, query
);
7469 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7471 query
= "CREATE TABLE `One` ( "
7472 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
7473 r
= run_query(href
, 0, query
);
7474 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7476 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
7477 r
= run_query(href
, 0, query
);
7478 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7480 /* code page does not match */
7481 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7482 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7484 query
= "SELECT * FROM `One`";
7485 r
= do_query(hdb
, query
, &hrec
);
7486 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7488 r
= MsiRecordGetInteger(hrec
, 1);
7489 ok(r
== 1, "Expected 1, got %d\n", r
);
7492 r
= MsiRecordGetStringA(hrec
, 2, buf
, &size
);
7493 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7494 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
7496 MsiCloseHandle(hrec
);
7498 /* nothing in MergeErrors */
7499 query
= "SELECT * FROM `MergeErrors`";
7500 r
= do_query(hdb
, query
, &hrec
);
7501 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7502 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7504 query
= "DROP TABLE `One`";
7505 r
= run_query(hdb
, 0, query
);
7506 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7508 query
= "DROP TABLE `One`";
7509 r
= run_query(href
, 0, query
);
7510 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7512 query
= "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
7513 r
= run_query(hdb
, 0, query
);
7514 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7516 query
= "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
7517 r
= run_query(href
, 0, query
);
7518 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7520 create_file("binary.dat");
7521 hrec
= MsiCreateRecord(1);
7522 MsiRecordSetStreamA(hrec
, 1, "binary.dat");
7524 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, ? )";
7525 r
= run_query(href
, hrec
, query
);
7526 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7528 MsiCloseHandle(hrec
);
7530 /* binary data to merge */
7531 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7532 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7534 query
= "SELECT * FROM `One`";
7535 r
= do_query(hdb
, query
, &hrec
);
7536 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7538 r
= MsiRecordGetInteger(hrec
, 1);
7539 ok(r
== 1, "Expected 1, got %d\n", r
);
7542 ZeroMemory(buf
, MAX_PATH
);
7543 r
= MsiRecordReadStream(hrec
, 2, buf
, &size
);
7544 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7545 ok(!lstrcmpA(buf
, "binary.dat\n"),
7546 "Expected \"binary.dat\\n\", got \"%s\"\n", buf
);
7548 MsiCloseHandle(hrec
);
7550 /* nothing in MergeErrors */
7551 query
= "SELECT * FROM `MergeErrors`";
7552 r
= do_query(hdb
, query
, &hrec
);
7553 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7554 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7556 query
= "DROP TABLE `One`";
7557 r
= run_query(hdb
, 0, query
);
7558 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7560 query
= "DROP TABLE `One`";
7561 r
= run_query(href
, 0, query
);
7562 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7564 query
= "CREATE TABLE `One` ( `A` INT, `B` CHAR(72) PRIMARY KEY `A` )";
7565 r
= run_query(hdb
, 0, query
);
7566 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7567 r
= run_query(href
, 0, query
);
7568 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7570 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'foo' )";
7571 r
= run_query(href
, 0, query
);
7572 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7574 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 'bar' )";
7575 r
= run_query(href
, 0, query
);
7576 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7578 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7579 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7581 query
= "SELECT * FROM `One`";
7582 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
7583 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7584 r
= MsiViewExecute(hview
, 0);
7585 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7587 r
= MsiViewFetch(hview
, &hrec
);
7588 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7590 r
= MsiRecordGetInteger(hrec
, 1);
7591 ok(r
== 1, "Expected 1, got %d\n", r
);
7594 r
= MsiRecordGetStringA(hrec
, 2, buf
, &size
);
7595 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7596 ok(!lstrcmpA(buf
, "foo"), "Expected \"foo\", got \"%s\"\n", buf
);
7598 MsiCloseHandle(hrec
);
7600 r
= MsiViewFetch(hview
, &hrec
);
7601 todo_wine
ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7603 r
= MsiRecordGetInteger(hrec
, 1);
7604 todo_wine
ok(r
== 2, "Expected 2, got %d\n", r
);
7607 r
= MsiRecordGetStringA(hrec
, 2, buf
, &size
);
7608 todo_wine
ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7609 todo_wine
ok(!lstrcmpA(buf
, "bar"), "Expected \"bar\", got \"%s\"\n", buf
);
7611 MsiCloseHandle(hrec
);
7613 r
= MsiViewFetch(hview
, &hrec
);
7614 ok(r
== ERROR_NO_MORE_ITEMS
,
7615 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7617 MsiViewClose(hview
);
7618 MsiCloseHandle(hview
);
7620 MsiCloseHandle(hdb
);
7621 MsiCloseHandle(href
);
7622 DeleteFileA(msifile
);
7623 DeleteFileA("refdb.msi");
7624 DeleteFileA("codepage.idt");
7625 DeleteFileA("binary.dat");
7628 UINT ordervals
[6][3] =
7630 { MSI_NULL_INTEGER
, 12, 13 },
7634 { 10, 11, MSI_NULL_INTEGER
},
7635 { 14, MSI_NULL_INTEGER
, 15 }
7638 static void test_insertorder(void)
7640 MSIHANDLE hdb
, view
, rec
;
7646 ok(hdb
, "failed to create db\n");
7648 query
= "CREATE TABLE `T` ( `A` SHORT, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
7649 r
= run_query(hdb
, 0, query
);
7650 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7652 query
= "INSERT INTO `T` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
7653 r
= run_query(hdb
, 0, query
);
7654 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7656 query
= "INSERT INTO `T` ( `B`, `C`, `A` ) VALUES ( 4, 5, 6 )";
7657 r
= run_query(hdb
, 0, query
);
7658 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7660 query
= "INSERT INTO `T` ( `C`, `A`, `B` ) VALUES ( 7, 8, 9 )";
7661 r
= run_query(hdb
, 0, query
);
7662 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7664 query
= "INSERT INTO `T` ( `A`, `B` ) VALUES ( 10, 11 )";
7665 r
= run_query(hdb
, 0, query
);
7666 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7668 query
= "INSERT INTO `T` ( `B`, `C` ) VALUES ( 12, 13 )";
7669 r
= run_query(hdb
, 0, query
);
7670 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7672 /* fails because the primary key already
7673 * has an MSI_NULL_INTEGER value set above
7675 query
= "INSERT INTO `T` ( `C` ) VALUES ( 14 )";
7676 r
= run_query(hdb
, 0, query
);
7677 ok(r
== ERROR_FUNCTION_FAILED
,
7678 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
7680 /* replicate the error where primary key is set twice */
7681 query
= "INSERT INTO `T` ( `A`, `C` ) VALUES ( 1, 14 )";
7682 r
= run_query(hdb
, 0, query
);
7683 ok(r
== ERROR_FUNCTION_FAILED
,
7684 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
7686 query
= "INSERT INTO `T` ( `A`, `C` ) VALUES ( 14, 15 )";
7687 r
= run_query(hdb
, 0, query
);
7688 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7690 query
= "INSERT INTO `T` VALUES ( 16 )";
7691 r
= run_query(hdb
, 0, query
);
7692 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7693 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7695 query
= "INSERT INTO `T` VALUES ( 17, 18 )";
7696 r
= run_query(hdb
, 0, query
);
7697 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7698 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7700 query
= "INSERT INTO `T` VALUES ( 19, 20, 21 )";
7701 r
= run_query(hdb
, 0, query
);
7702 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7703 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7705 query
= "SELECT * FROM `T`";
7706 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
7707 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7708 r
= MsiViewExecute(view
, 0);
7709 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7711 for (i
= 0; i
< 6; i
++)
7713 r
= MsiViewFetch(view
, &rec
);
7714 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7716 r
= MsiRecordGetInteger(rec
, 1);
7717 ok(r
== ordervals
[i
][0], "Expected %d, got %d\n", ordervals
[i
][0], r
);
7719 r
= MsiRecordGetInteger(rec
, 2);
7720 ok(r
== ordervals
[i
][1], "Expected %d, got %d\n", ordervals
[i
][1], r
);
7722 r
= MsiRecordGetInteger(rec
, 3);
7723 ok(r
== ordervals
[i
][2], "Expected %d, got %d\n", ordervals
[i
][2], r
);
7725 MsiCloseHandle(rec
);
7728 r
= MsiViewFetch(view
, &rec
);
7729 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7732 MsiCloseHandle(view
);
7734 query
= "DELETE FROM `T` WHERE `A` IS NULL";
7735 r
= run_query(hdb
, 0, query
);
7736 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7738 query
= "INSERT INTO `T` ( `B`, `C` ) VALUES ( 12, 13 ) TEMPORARY";
7739 r
= run_query(hdb
, 0, query
);
7740 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7742 query
= "SELECT * FROM `T`";
7743 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
7744 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7745 r
= MsiViewExecute(view
, 0);
7746 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7748 for (i
= 0; i
< 6; i
++)
7750 r
= MsiViewFetch(view
, &rec
);
7751 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7753 r
= MsiRecordGetInteger(rec
, 1);
7754 ok(r
== ordervals
[i
][0], "Expected %d, got %d\n", ordervals
[i
][0], r
);
7756 r
= MsiRecordGetInteger(rec
, 2);
7757 ok(r
== ordervals
[i
][1], "Expected %d, got %d\n", ordervals
[i
][1], r
);
7759 r
= MsiRecordGetInteger(rec
, 3);
7760 ok(r
== ordervals
[i
][2], "Expected %d, got %d\n", ordervals
[i
][2], r
);
7762 MsiCloseHandle(rec
);
7765 r
= MsiViewFetch(view
, &rec
);
7766 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7769 MsiCloseHandle(view
);
7770 MsiCloseHandle(hdb
);
7771 DeleteFileA(msifile
);
7774 static void test_columnorder(void)
7776 MSIHANDLE hdb
, view
, rec
;
7783 ok(hdb
, "failed to create db\n");
7785 /* Each column is a slot:
7786 * ---------------------
7787 * | B | C | A | E | D |
7788 * ---------------------
7790 * When a column is selected as a primary key,
7791 * the column occupying the nth primary key slot is swapped
7792 * with the current position of the primary key in question:
7794 * set primary key `D`
7795 * --------------------- ---------------------
7796 * | B | C | A | E | D | -> | D | C | A | E | B |
7797 * --------------------- ---------------------
7799 * set primary key `E`
7800 * --------------------- ---------------------
7801 * | D | C | A | E | B | -> | D | E | A | C | B |
7802 * --------------------- ---------------------
7805 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL, `C` SHORT NOT NULL, "
7806 "`A` CHAR(255), `E` INT, `D` CHAR(255) NOT NULL "
7807 "PRIMARY KEY `D`, `E`)";
7808 r
= run_query(hdb
, 0, query
);
7809 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7811 query
= "SELECT * FROM `T`";
7812 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
7813 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7815 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
7816 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7819 lstrcpyA(buf
, "kiwi");
7820 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
7821 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7822 ok(!lstrcmpA("s255", buf
), "Expected \"s255\", got \"%s\"\n", buf
);
7825 lstrcpyA(buf
, "kiwi");
7826 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
7827 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7828 ok(!lstrcmpA("I2", buf
), "Expected \"I2\", got \"%s\"\n", buf
);
7831 lstrcpyA(buf
, "kiwi");
7832 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
7833 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7834 ok(!lstrcmpA("S255", buf
), "Expected \"S255\", got \"%s\"\n", buf
);
7837 lstrcpyA(buf
, "kiwi");
7838 r
= MsiRecordGetString(rec
, 4, buf
, &sz
);
7839 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7840 ok(!lstrcmpA("i2", buf
), "Expected \"i2\", got \"%s\"\n", buf
);
7843 lstrcpyA(buf
, "kiwi");
7844 r
= MsiRecordGetString(rec
, 5, buf
, &sz
);
7845 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7846 ok(!lstrcmpA("i2", buf
), "Expected \"i2\", got \"%s\"\n", buf
);
7848 MsiCloseHandle(rec
);
7850 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
7851 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7854 lstrcpyA(buf
, "kiwi");
7855 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
7856 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7857 ok(!lstrcmpA("D", buf
), "Expected \"D\", got \"%s\"\n", buf
);
7860 lstrcpyA(buf
, "kiwi");
7861 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
7862 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7863 ok(!lstrcmpA("E", buf
), "Expected \"E\", got \"%s\"\n", buf
);
7866 lstrcpyA(buf
, "kiwi");
7867 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
7868 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7869 ok(!lstrcmpA("A", buf
), "Expected \"A\", got \"%s\"\n", buf
);
7872 lstrcpyA(buf
, "kiwi");
7873 r
= MsiRecordGetString(rec
, 4, buf
, &sz
);
7874 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7875 ok(!lstrcmpA("C", buf
), "Expected \"C\", got \"%s\"\n", buf
);
7878 lstrcpyA(buf
, "kiwi");
7879 r
= MsiRecordGetString(rec
, 5, buf
, &sz
);
7880 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7881 ok(!lstrcmpA("B", buf
), "Expected \"B\", got \"%s\"\n", buf
);
7883 MsiCloseHandle(rec
);
7885 MsiCloseHandle(view
);
7887 query
= "INSERT INTO `T` ( `B`, `C`, `A`, `E`, `D` ) "
7888 "VALUES ( 1, 2, 'a', 3, 'bc' )";
7889 r
= run_query(hdb
, 0, query
);
7890 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7892 query
= "SELECT * FROM `T`";
7893 r
= do_query(hdb
, query
, &rec
);
7896 lstrcpyA(buf
, "kiwi");
7897 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
7898 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7899 ok(!lstrcmpA("bc", buf
), "Expected \"bc\", got \"%s\"\n", buf
);
7901 r
= MsiRecordGetInteger(rec
, 2);
7902 ok(r
== 3, "Expected 3, got %d\n", r
);
7905 lstrcpyA(buf
, "kiwi");
7906 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
7907 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7908 ok(!lstrcmpA("a", buf
), "Expected \"a\", got \"%s\"\n", buf
);
7910 r
= MsiRecordGetInteger(rec
, 4);
7911 ok(r
== 2, "Expected 2, got %d\n", r
);
7913 r
= MsiRecordGetInteger(rec
, 5);
7914 ok(r
== 1, "Expected 1, got %d\n", r
);
7916 MsiCloseHandle(rec
);
7918 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'T'";
7919 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
7920 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7921 r
= MsiViewExecute(view
, 0);
7922 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7924 r
= MsiViewFetch(view
, &rec
);
7925 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7928 lstrcpyA(buf
, "kiwi");
7929 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
7930 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7931 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
7933 r
= MsiRecordGetInteger(rec
, 2);
7934 ok(r
== 1, "Expected 1, got %d\n", r
);
7937 lstrcpyA(buf
, "kiwi");
7938 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
7939 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7940 ok(!lstrcmpA("D", buf
), "Expected \"D\", got \"%s\"\n", buf
);
7942 MsiCloseHandle(rec
);
7944 r
= MsiViewFetch(view
, &rec
);
7945 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7948 lstrcpyA(buf
, "kiwi");
7949 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
7950 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7951 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
7953 r
= MsiRecordGetInteger(rec
, 2);
7954 ok(r
== 2, "Expected 2, got %d\n", r
);
7957 lstrcpyA(buf
, "kiwi");
7958 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
7959 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7960 ok(!lstrcmpA("E", buf
), "Expected \"E\", got \"%s\"\n", buf
);
7962 MsiCloseHandle(rec
);
7964 r
= MsiViewFetch(view
, &rec
);
7965 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7968 lstrcpyA(buf
, "kiwi");
7969 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
7970 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7971 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
7973 r
= MsiRecordGetInteger(rec
, 2);
7974 ok(r
== 3, "Expected 3, got %d\n", r
);
7977 lstrcpyA(buf
, "kiwi");
7978 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
7979 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7980 ok(!lstrcmpA("A", buf
), "Expected \"A\", got \"%s\"\n", buf
);
7982 MsiCloseHandle(rec
);
7984 r
= MsiViewFetch(view
, &rec
);
7985 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7988 lstrcpyA(buf
, "kiwi");
7989 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
7990 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7991 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
7993 r
= MsiRecordGetInteger(rec
, 2);
7994 ok(r
== 4, "Expected 4, got %d\n", r
);
7997 lstrcpyA(buf
, "kiwi");
7998 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
7999 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8000 ok(!lstrcmpA("C", buf
), "Expected \"C\", got \"%s\"\n", buf
);
8002 MsiCloseHandle(rec
);
8004 r
= MsiViewFetch(view
, &rec
);
8005 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8008 lstrcpyA(buf
, "kiwi");
8009 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8010 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8011 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8013 r
= MsiRecordGetInteger(rec
, 2);
8014 ok(r
== 5, "Expected 5, got %d\n", r
);
8017 lstrcpyA(buf
, "kiwi");
8018 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8019 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8020 ok(!lstrcmpA("B", buf
), "Expected \"B\", got \"%s\"\n", buf
);
8022 MsiCloseHandle(rec
);
8024 r
= MsiViewFetch(view
, &rec
);
8025 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
8028 MsiCloseHandle(view
);
8030 query
= "CREATE TABLE `Z` ( `B` SHORT NOT NULL, `C` SHORT NOT NULL, "
8031 "`A` CHAR(255), `E` INT, `D` CHAR(255) NOT NULL "
8032 "PRIMARY KEY `C`, `A`, `D`)";
8033 r
= run_query(hdb
, 0, query
);
8034 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8036 query
= "SELECT * FROM `Z`";
8037 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
8038 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8040 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
8041 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8044 lstrcpyA(buf
, "kiwi");
8045 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8046 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8047 ok(!lstrcmpA("i2", buf
), "Expected \"i2\", got \"%s\"\n", buf
);
8050 lstrcpyA(buf
, "kiwi");
8051 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
8052 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8053 ok(!lstrcmpA("S255", buf
), "Expected \"S255\", got \"%s\"\n", buf
);
8056 lstrcpyA(buf
, "kiwi");
8057 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8058 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8059 ok(!lstrcmpA("s255", buf
), "Expected \"s255\", got \"%s\"\n", buf
);
8062 lstrcpyA(buf
, "kiwi");
8063 r
= MsiRecordGetString(rec
, 4, buf
, &sz
);
8064 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8065 ok(!lstrcmpA("I2", buf
), "Expected \"I2\", got \"%s\"\n", buf
);
8068 lstrcpyA(buf
, "kiwi");
8069 r
= MsiRecordGetString(rec
, 5, buf
, &sz
);
8070 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8071 ok(!lstrcmpA("i2", buf
), "Expected \"i2\", got \"%s\"\n", buf
);
8073 MsiCloseHandle(rec
);
8075 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
8076 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8079 lstrcpyA(buf
, "kiwi");
8080 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8081 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8082 ok(!lstrcmpA("C", buf
), "Expected \"C\", got \"%s\"\n", buf
);
8085 lstrcpyA(buf
, "kiwi");
8086 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
8087 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8088 ok(!lstrcmpA("A", buf
), "Expected \"A\", got \"%s\"\n", buf
);
8091 lstrcpyA(buf
, "kiwi");
8092 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8093 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8094 ok(!lstrcmpA("D", buf
), "Expected \"D\", got \"%s\"\n", buf
);
8097 lstrcpyA(buf
, "kiwi");
8098 r
= MsiRecordGetString(rec
, 4, buf
, &sz
);
8099 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8100 ok(!lstrcmpA("E", buf
), "Expected \"E\", got \"%s\"\n", buf
);
8103 lstrcpyA(buf
, "kiwi");
8104 r
= MsiRecordGetString(rec
, 5, buf
, &sz
);
8105 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8106 ok(!lstrcmpA("B", buf
), "Expected \"B\", got \"%s\"\n", buf
);
8108 MsiCloseHandle(rec
);
8110 MsiCloseHandle(view
);
8112 query
= "INSERT INTO `Z` ( `B`, `C`, `A`, `E`, `D` ) "
8113 "VALUES ( 1, 2, 'a', 3, 'bc' )";
8114 r
= run_query(hdb
, 0, query
);
8115 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8117 query
= "SELECT * FROM `Z`";
8118 r
= do_query(hdb
, query
, &rec
);
8120 r
= MsiRecordGetInteger(rec
, 1);
8121 ok(r
== 2, "Expected 2, got %d\n", r
);
8124 lstrcpyA(buf
, "kiwi");
8125 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
8126 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8127 ok(!lstrcmpA("a", buf
), "Expected \"a\", got \"%s\"\n", buf
);
8130 lstrcpyA(buf
, "kiwi");
8131 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8132 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8133 ok(!lstrcmpA("bc", buf
), "Expected \"bc\", got \"%s\"\n", buf
);
8135 r
= MsiRecordGetInteger(rec
, 4);
8136 ok(r
== 3, "Expected 3, got %d\n", r
);
8138 r
= MsiRecordGetInteger(rec
, 5);
8139 ok(r
== 1, "Expected 1, got %d\n", r
);
8141 MsiCloseHandle(rec
);
8143 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'T'";
8144 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
8145 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8146 r
= MsiViewExecute(view
, 0);
8147 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8149 r
= MsiViewFetch(view
, &rec
);
8150 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8153 lstrcpyA(buf
, "kiwi");
8154 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8155 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8156 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8158 r
= MsiRecordGetInteger(rec
, 2);
8159 ok(r
== 1, "Expected 1, got %d\n", r
);
8162 lstrcpyA(buf
, "kiwi");
8163 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8164 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8165 ok(!lstrcmpA("D", buf
), "Expected \"D\", got \"%s\"\n", buf
);
8167 MsiCloseHandle(rec
);
8169 r
= MsiViewFetch(view
, &rec
);
8170 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8173 lstrcpyA(buf
, "kiwi");
8174 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8175 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8176 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8178 r
= MsiRecordGetInteger(rec
, 2);
8179 ok(r
== 2, "Expected 2, got %d\n", r
);
8182 lstrcpyA(buf
, "kiwi");
8183 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8184 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8185 ok(!lstrcmpA("E", buf
), "Expected \"E\", got \"%s\"\n", buf
);
8187 MsiCloseHandle(rec
);
8189 r
= MsiViewFetch(view
, &rec
);
8190 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8193 lstrcpyA(buf
, "kiwi");
8194 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8195 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8196 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8198 r
= MsiRecordGetInteger(rec
, 2);
8199 ok(r
== 3, "Expected 3, got %d\n", r
);
8202 lstrcpyA(buf
, "kiwi");
8203 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8204 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8205 ok(!lstrcmpA("A", buf
), "Expected \"A\", got \"%s\"\n", buf
);
8207 MsiCloseHandle(rec
);
8209 r
= MsiViewFetch(view
, &rec
);
8210 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8213 lstrcpyA(buf
, "kiwi");
8214 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8215 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8216 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8218 r
= MsiRecordGetInteger(rec
, 2);
8219 ok(r
== 4, "Expected 4, got %d\n", r
);
8222 lstrcpyA(buf
, "kiwi");
8223 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8224 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8225 ok(!lstrcmpA("C", buf
), "Expected \"C\", got \"%s\"\n", buf
);
8227 MsiCloseHandle(rec
);
8229 r
= MsiViewFetch(view
, &rec
);
8230 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8233 lstrcpyA(buf
, "kiwi");
8234 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8235 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8236 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8238 r
= MsiRecordGetInteger(rec
, 2);
8239 ok(r
== 5, "Expected 5, got %d\n", r
);
8242 lstrcpyA(buf
, "kiwi");
8243 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8244 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8245 ok(!lstrcmpA("B", buf
), "Expected \"B\", got \"%s\"\n", buf
);
8247 MsiCloseHandle(rec
);
8249 r
= MsiViewFetch(view
, &rec
);
8250 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
8253 MsiCloseHandle(view
);
8255 MsiCloseHandle(hdb
);
8256 DeleteFileA(msifile
);
8263 test_msidecomposedesc();
8264 test_msibadqueries();
8266 test_viewgetcolumninfo();
8274 test_binary_import();
8276 test_handle_limit();
8277 test_try_transform();
8279 test_temporary_table();
8283 test_special_tables();
8284 test_tables_order();
8285 test_select_markers();
8286 test_viewmodify_update();
8287 test_viewmodify_assign();
8289 test_viewmodify_delete();
8290 test_defaultdatabase();
8292 test_viewmodify_delete_temporary();
8295 test_carriagereturn();
8297 test_forcecodepage();
8298 test_viewmodify_refresh();
8299 test_where_viewmodify();
8300 test_storages_table();
8306 test_suminfo_import();