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-db.msi";
35 static const char *msifile2
= "winetst2-db.msi";
36 static const char *mstfile
= "winetst-db.mst";
37 static const WCHAR msifileW
[] = {'w','i','n','e','t','e','s','t','-','d','b','.','m','s','i',0};
39 static void test_msidatabase(void)
41 MSIHANDLE hdb
= 0, hdb2
= 0;
46 res
= MsiOpenDatabase( msifile
, msifile2
, &hdb
);
47 ok( res
== ERROR_OPEN_FAILED
, "expected failure\n");
49 res
= MsiOpenDatabase( msifile
, (LPSTR
) 0xff, &hdb
);
50 ok( res
== ERROR_INVALID_PARAMETER
, "expected failure\n");
52 res
= MsiCloseHandle( hdb
);
53 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
55 /* create an empty database */
56 res
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
57 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
59 res
= MsiDatabaseCommit( hdb
);
60 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
62 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile
), "database should exist\n");
64 res
= MsiCloseHandle( hdb
);
65 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
66 res
= MsiOpenDatabase( msifile
, msifile2
, &hdb2
);
67 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
69 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile2
), "database should exist\n");
71 res
= MsiDatabaseCommit( hdb2
);
72 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
74 res
= MsiCloseHandle( hdb2
);
75 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
77 res
= MsiOpenDatabase( msifile
, msifile2
, &hdb2
);
78 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
80 res
= MsiCloseHandle( hdb2
);
81 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
83 ok( INVALID_FILE_ATTRIBUTES
== GetFileAttributes( msifile2
), "uncommitted database should not exist\n");
85 res
= MsiOpenDatabase( msifile
, msifile2
, &hdb2
);
86 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
88 res
= MsiDatabaseCommit( hdb2
);
89 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
91 res
= MsiCloseHandle( hdb2
);
92 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
94 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile2
), "committed database should exist\n");
96 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_READONLY
, &hdb
);
97 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
99 res
= MsiCloseHandle( hdb
);
100 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
102 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_DIRECT
, &hdb
);
103 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
105 res
= MsiCloseHandle( hdb
);
106 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
108 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
109 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
111 res
= MsiCloseHandle( hdb
);
112 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
113 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile
), "database should exist\n");
115 /* MSIDBOPEN_CREATE deletes the database if MsiCommitDatabase isn't called */
116 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_CREATE
, &hdb
);
117 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
119 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile
), "database should exist\n");
121 res
= MsiCloseHandle( hdb
);
122 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
124 ok( INVALID_FILE_ATTRIBUTES
== GetFileAttributes( msifile
), "database should exist\n");
126 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_CREATE
, &hdb
);
127 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
129 res
= MsiDatabaseCommit( hdb
);
130 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
132 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile
), "database should exist\n");
134 res
= MsiCloseHandle( hdb
);
135 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
137 res
= DeleteFile( msifile2
);
138 ok( res
== TRUE
, "Failed to delete database\n" );
140 res
= DeleteFile( msifile
);
141 ok( res
== TRUE
, "Failed to delete database\n" );
144 static UINT
do_query(MSIHANDLE hdb
, const char *query
, MSIHANDLE
*phrec
)
152 /* open a select query */
153 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
154 if (r
!= ERROR_SUCCESS
)
156 r
= MsiViewExecute(hview
, 0);
157 if (r
!= ERROR_SUCCESS
)
159 ret
= MsiViewFetch(hview
, phrec
);
160 r
= MsiViewClose(hview
);
161 if (r
!= ERROR_SUCCESS
)
163 r
= MsiCloseHandle(hview
);
164 if (r
!= ERROR_SUCCESS
)
169 static UINT
run_query( MSIHANDLE hdb
, MSIHANDLE hrec
, const char *query
)
174 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
175 if( r
!= ERROR_SUCCESS
)
178 r
= MsiViewExecute(hview
, hrec
);
179 if( r
== ERROR_SUCCESS
)
180 r
= MsiViewClose(hview
);
181 MsiCloseHandle(hview
);
185 static UINT
create_component_table( MSIHANDLE hdb
)
187 return run_query( hdb
, 0,
188 "CREATE TABLE `Component` ( "
189 "`Component` CHAR(72) NOT NULL, "
190 "`ComponentId` CHAR(38), "
191 "`Directory_` CHAR(72) NOT NULL, "
192 "`Attributes` SHORT NOT NULL, "
193 "`Condition` CHAR(255), "
194 "`KeyPath` CHAR(72) "
195 "PRIMARY KEY `Component`)" );
198 static UINT
create_custom_action_table( MSIHANDLE hdb
)
200 return run_query( hdb
, 0,
201 "CREATE TABLE `CustomAction` ( "
202 "`Action` CHAR(72) NOT NULL, "
203 "`Type` SHORT NOT NULL, "
204 "`Source` CHAR(72), "
205 "`Target` CHAR(255) "
206 "PRIMARY KEY `Action`)" );
209 static UINT
create_directory_table( MSIHANDLE hdb
)
211 return run_query( hdb
, 0,
212 "CREATE TABLE `Directory` ( "
213 "`Directory` CHAR(255) NOT NULL, "
214 "`Directory_Parent` CHAR(255), "
215 "`DefaultDir` CHAR(255) NOT NULL "
216 "PRIMARY KEY `Directory`)" );
219 static UINT
create_feature_components_table( MSIHANDLE hdb
)
221 return run_query( hdb
, 0,
222 "CREATE TABLE `FeatureComponents` ( "
223 "`Feature_` CHAR(38) NOT NULL, "
224 "`Component_` CHAR(72) NOT NULL "
225 "PRIMARY KEY `Feature_`, `Component_` )" );
228 static UINT
create_std_dlls_table( MSIHANDLE hdb
)
230 return run_query( hdb
, 0,
231 "CREATE TABLE `StdDlls` ( "
232 "`File` CHAR(255) NOT NULL, "
233 "`Binary_` CHAR(72) NOT NULL "
234 "PRIMARY KEY `File` )" );
237 static UINT
create_binary_table( MSIHANDLE hdb
)
239 return run_query( hdb
, 0,
240 "CREATE TABLE `Binary` ( "
241 "`Name` CHAR(72) NOT NULL, "
242 "`Data` CHAR(72) NOT NULL "
243 "PRIMARY KEY `Name` )" );
246 #define make_add_entry(type, qtext) \
247 static UINT add##_##type##_##entry( MSIHANDLE hdb, const char *values ) \
249 char insert[] = qtext; \
252 sz = strlen(values) + sizeof insert; \
253 query = HeapAlloc(GetProcessHeap(),0,sz); \
254 sprintf(query,insert,values); \
255 r = run_query( hdb, 0, query ); \
256 HeapFree(GetProcessHeap(), 0, query); \
260 make_add_entry(component
,
261 "INSERT INTO `Component` "
262 "(`Component`, `ComponentId`, `Directory_`, "
263 "`Attributes`, `Condition`, `KeyPath`) VALUES( %s )")
265 make_add_entry(custom_action
,
266 "INSERT INTO `CustomAction` "
267 "(`Action`, `Type`, `Source`, `Target`) VALUES( %s )")
269 make_add_entry(feature_components
,
270 "INSERT INTO `FeatureComponents` "
271 "(`Feature_`, `Component_`) VALUES( %s )")
273 make_add_entry(std_dlls
,
274 "INSERT INTO `StdDlls` (`File`, `Binary_`) VALUES( %s )")
276 make_add_entry(binary
,
277 "INSERT INTO `Binary` (`Name`, `Data`) VALUES( %s )")
279 static void test_msiinsert(void)
281 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
289 /* just MsiOpenDatabase should not create a file */
290 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
291 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
294 query
= "CREATE TABLE `phone` ( "
295 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
297 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
298 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
299 r
= MsiViewExecute(hview
, 0);
300 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
301 r
= MsiViewClose(hview
);
302 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
303 r
= MsiCloseHandle(hview
);
304 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
306 /* insert a value into it */
307 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
308 "VALUES('1', 'Abe', '8675309')";
309 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
310 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
311 r
= MsiViewExecute(hview
, 0);
312 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
313 r
= MsiViewClose(hview
);
314 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
315 r
= MsiCloseHandle(hview
);
316 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
318 query
= "SELECT * FROM `phone` WHERE `id` = 1";
319 r
= do_query(hdb
, query
, &hrec
);
320 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
322 /* check the record contains what we put in it */
323 r
= MsiRecordGetFieldCount(hrec
);
324 ok(r
== 3, "record count wrong\n");
326 r
= MsiRecordIsNull(hrec
, 0);
327 ok(r
== FALSE
, "field 0 not null\n");
329 r
= MsiRecordGetInteger(hrec
, 1);
330 ok(r
== 1, "field 1 contents wrong\n");
332 r
= MsiRecordGetString(hrec
, 2, buf
, &sz
);
333 ok(r
== ERROR_SUCCESS
, "field 2 content fetch failed\n");
334 ok(!strcmp(buf
,"Abe"), "field 2 content incorrect\n");
336 r
= MsiRecordGetString(hrec
, 3, buf
, &sz
);
337 ok(r
== ERROR_SUCCESS
, "field 3 content fetch failed\n");
338 ok(!strcmp(buf
,"8675309"), "field 3 content incorrect\n");
340 r
= MsiCloseHandle(hrec
);
341 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
343 /* open a select query */
345 query
= "SELECT * FROM `phone` WHERE `id` >= 10";
346 r
= do_query(hdb
, query
, &hrec
);
347 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
348 ok(hrec
== 0, "hrec should be null\n");
350 r
= MsiCloseHandle(hrec
);
351 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
353 query
= "SELECT * FROM `phone` WHERE `id` < 0";
354 r
= do_query(hdb
, query
, &hrec
);
355 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
357 query
= "SELECT * FROM `phone` WHERE `id` <= 0";
358 r
= do_query(hdb
, query
, &hrec
);
359 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
361 query
= "SELECT * FROM `phone` WHERE `id` <> 1";
362 r
= do_query(hdb
, query
, &hrec
);
363 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
365 query
= "SELECT * FROM `phone` WHERE `id` > 10";
366 r
= do_query(hdb
, query
, &hrec
);
367 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
369 /* now try a few bad INSERT xqueries */
370 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
372 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
373 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "MsiDatabaseOpenView failed\n");
375 /* construct a record to insert */
376 hrec
= MsiCreateRecord(4);
377 r
= MsiRecordSetInteger(hrec
, 1, 2);
378 ok(r
== ERROR_SUCCESS
, "MsiRecordSetInteger failed\n");
379 r
= MsiRecordSetString(hrec
, 2, "Adam");
380 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
381 r
= MsiRecordSetString(hrec
, 3, "96905305");
382 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
384 /* insert another value, using a record and wildcards */
385 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
387 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
388 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
390 if (r
== ERROR_SUCCESS
)
392 r
= MsiViewExecute(hview
, hrec
);
393 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
394 r
= MsiViewClose(hview
);
395 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
396 r
= MsiCloseHandle(hview
);
397 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
399 r
= MsiCloseHandle(hrec
);
400 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
402 r
= MsiViewFetch(0, NULL
);
403 ok(r
== ERROR_INVALID_PARAMETER
, "MsiViewFetch failed\n");
405 r
= MsiDatabaseCommit(hdb
);
406 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
408 r
= MsiCloseHandle(hdb
);
409 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
411 r
= DeleteFile(msifile
);
412 ok(r
== TRUE
, "file didn't exist after commit\n");
415 typedef UINT (WINAPI
*fnMsiDecomposeDescriptorA
)(LPCSTR
, LPCSTR
, LPSTR
, LPSTR
, DWORD
*);
416 static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA
;
418 static void test_msidecomposedesc(void)
420 char prod
[MAX_FEATURE_CHARS
+1], comp
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1];
426 hmod
= GetModuleHandle("msi.dll");
427 pMsiDecomposeDescriptorA
= (fnMsiDecomposeDescriptorA
)
428 GetProcAddress(hmod
, "MsiDecomposeDescriptorA");
429 if (!pMsiDecomposeDescriptorA
)
432 /* test a valid feature descriptor */
433 desc
= "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
435 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, comp
, &len
);
436 ok(r
== ERROR_SUCCESS
, "returned an error\n");
437 ok(len
== strlen(desc
), "length was wrong\n");
438 ok(strcmp(prod
,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
439 ok(strcmp(feature
,"FollowTheWhiteRabbit")==0, "feature wrong\n");
440 ok(strcmp(comp
,"{A7CD68DB-EF74-49C8-FBB2-A7C463B2AC24}")==0,"component wrong\n");
442 /* test an invalid feature descriptor with too many characters */
443 desc
= "']gAVn-}f(ZXfeAR6.ji"
444 "ThisWillFailIfTheresMoreThanAGuidsChars>"
445 "3w2x^IGfe?CxI5heAvk.";
447 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, comp
, &len
);
448 ok(r
== ERROR_INVALID_PARAMETER
, "returned wrong error\n");
451 * Test a valid feature descriptor with the
452 * maximum number of characters and some trailing characters.
454 desc
= "']gAVn-}f(ZXfeAR6.ji"
455 "ThisWillWorkIfTheresLTEThanAGuidsChars>"
456 "3w2x^IGfe?CxI5heAvk."
459 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, comp
, &len
);
460 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
461 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
464 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, NULL
, &len
);
465 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
466 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
469 r
= pMsiDecomposeDescriptorA(desc
, prod
, NULL
, NULL
, &len
);
470 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
471 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
474 r
= pMsiDecomposeDescriptorA(desc
, NULL
, NULL
, NULL
, &len
);
475 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
476 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
479 r
= pMsiDecomposeDescriptorA(NULL
, NULL
, NULL
, NULL
, &len
);
480 ok(r
== ERROR_INVALID_PARAMETER
, "returned wrong error\n");
481 ok(len
== 0, "length wrong\n");
483 r
= pMsiDecomposeDescriptorA(desc
, NULL
, NULL
, NULL
, NULL
);
484 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
487 static UINT
try_query_param( MSIHANDLE hdb
, LPCSTR szQuery
, MSIHANDLE hrec
)
492 res
= MsiDatabaseOpenView( hdb
, szQuery
, &htab
);
493 if(res
== ERROR_SUCCESS
)
497 r
= MsiViewExecute( htab
, hrec
);
498 if(r
!= ERROR_SUCCESS
)
501 r
= MsiViewClose( htab
);
502 if(r
!= ERROR_SUCCESS
)
505 r
= MsiCloseHandle( htab
);
506 if(r
!= ERROR_SUCCESS
)
512 static UINT
try_query( MSIHANDLE hdb
, LPCSTR szQuery
)
514 return try_query_param( hdb
, szQuery
, 0 );
517 static UINT
try_insert_query( MSIHANDLE hdb
, LPCSTR szQuery
)
522 hrec
= MsiCreateRecord( 1 );
523 MsiRecordSetString( hrec
, 1, "Hello");
525 r
= try_query_param( hdb
, szQuery
, hrec
);
527 MsiCloseHandle( hrec
);
531 static void test_msibadqueries(void)
538 /* just MsiOpenDatabase should not create a file */
539 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
540 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
542 r
= MsiDatabaseCommit( hdb
);
543 ok(r
== ERROR_SUCCESS
, "Failed to commit database\n");
545 r
= MsiCloseHandle( hdb
);
546 ok(r
== ERROR_SUCCESS
, "Failed to close database\n");
548 /* open it readonly */
549 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
550 ok(r
== ERROR_SUCCESS
, "Failed to open database r/o\n");
552 /* add a table to it */
553 r
= try_query( hdb
, "select * from _Tables");
554 ok(r
== ERROR_SUCCESS
, "query 1 failed\n");
556 r
= MsiCloseHandle( hdb
);
557 ok(r
== ERROR_SUCCESS
, "Failed to close database r/o\n");
559 /* open it read/write */
560 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
561 ok(r
== ERROR_SUCCESS
, "Failed to open database r/w\n");
563 /* a bunch of test queries that fail with the native MSI */
565 r
= try_query( hdb
, "CREATE TABLE");
566 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2a return code\n");
568 r
= try_query( hdb
, "CREATE TABLE `a`");
569 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2b return code\n");
571 r
= try_query( hdb
, "CREATE TABLE `a` ()");
572 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2c return code\n");
574 r
= try_query( hdb
, "CREATE TABLE `a` (`b`)");
575 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2d return code\n");
577 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) )");
578 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2e return code\n");
580 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
581 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2f return code\n");
583 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
584 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2g return code\n");
586 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
587 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2h return code\n");
589 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
590 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2i return code\n");
592 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
593 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2j return code\n");
595 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
596 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2k return code\n");
598 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
599 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2l return code\n");
601 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
602 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2m return code\n");
604 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
605 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2n return code\n");
607 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
608 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2o return code\n");
610 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
611 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2p return code\n");
613 r
= try_query( hdb
, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
614 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2p return code\n");
616 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
617 ok(r
== ERROR_SUCCESS
, "valid query 2z failed\n");
619 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
620 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created same table again\n");
622 r
= try_query( hdb
, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
623 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
624 ok(r
== ERROR_SUCCESS
, "query 4 failed\n");
626 r
= MsiDatabaseCommit( hdb
);
627 ok(r
== ERROR_SUCCESS
, "Failed to commit database after write\n");
629 r
= try_query( hdb
, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
630 "PRIMARY KEY `foo`)");
631 ok(r
== ERROR_SUCCESS
, "query 4 failed\n");
633 r
= try_insert_query( hdb
, "insert into a ( `b` ) VALUES ( ? )");
634 ok(r
== ERROR_SUCCESS
, "failed to insert record in db\n");
636 r
= MsiDatabaseCommit( hdb
);
637 ok(r
== ERROR_SUCCESS
, "Failed to commit database after write\n");
639 r
= try_query( hdb
, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
640 "PRIMARY KEY `ba`)");
641 ok(r
!= ERROR_SUCCESS
, "query 5 succeeded\n");
643 r
= try_query( hdb
,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
644 ok(r
!= ERROR_SUCCESS
, "query 6 succeeded\n");
646 r
= try_query( hdb
, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
648 ok(r
== ERROR_SUCCESS
, "query 7 failed\n");
650 r
= try_query( hdb
, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
651 ok(r
== ERROR_SUCCESS
, "query 8 failed\n");
653 r
= try_query( hdb
, "select * from c");
654 ok(r
== ERROR_SUCCESS
, "query failed\n");
656 r
= try_query( hdb
, "select * from c where b = 'x");
657 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
659 r
= try_query( hdb
, "select * from c where b = 'x'");
660 ok(r
== ERROR_SUCCESS
, "query failed\n");
662 r
= try_query( hdb
, "select * from 'c'");
663 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
665 r
= try_query( hdb
, "select * from ''");
666 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
668 r
= try_query( hdb
, "select * from c where b = x");
669 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
671 r
= try_query( hdb
, "select * from c where b = \"x\"");
672 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
674 r
= try_query( hdb
, "select * from c where b = 'x'");
675 ok(r
== ERROR_SUCCESS
, "query failed\n");
677 r
= try_query( hdb
, "select * from c where b = '\"x'");
678 ok(r
== ERROR_SUCCESS
, "query failed\n");
680 if (0) /* FIXME: this query causes trouble with other tests */
682 r
= try_query( hdb
, "select * from c where b = '\\\'x'");
683 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
686 r
= try_query( hdb
, "select * from 'c'");
687 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
689 r
= try_query( hdb
, "CREATE TABLE `\5a` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
690 ok( r
== ERROR_SUCCESS
, "query failed: %u\n", r
);
692 r
= try_query( hdb
, "SELECT * FROM \5a" );
693 ok( r
== ERROR_SUCCESS
, "query failed: %u\n", r
);
695 r
= try_query( hdb
, "CREATE TABLE `a\5` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
696 ok( r
== ERROR_SUCCESS
, "query failed: %u\n", r
);
698 r
= try_query( hdb
, "SELECT * FROM a\5" );
699 ok( r
== ERROR_SUCCESS
, "query failed: %u\n", r
);
701 r
= try_query( hdb
, "CREATE TABLE `-a` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
702 ok( r
== ERROR_SUCCESS
, "query failed: %u\n", r
);
704 r
= try_query( hdb
, "SELECT * FROM -a" );
705 todo_wine
ok( r
== ERROR_SUCCESS
, "query failed: %u\n", r
);
707 r
= try_query( hdb
, "CREATE TABLE `a-` (`b` CHAR NOT NULL PRIMARY KEY `b`)" );
708 ok( r
== ERROR_SUCCESS
, "query failed: %u\n", r
);
710 r
= try_query( hdb
, "SELECT * FROM a-" );
711 ok( r
== ERROR_SUCCESS
, "query failed: %u\n", r
);
713 r
= MsiCloseHandle( hdb
);
714 ok(r
== ERROR_SUCCESS
, "Failed to close database transact\n");
716 r
= DeleteFile( msifile
);
717 ok(r
== TRUE
, "file didn't exist after commit\n");
720 static void test_viewmodify(void)
722 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
731 /* just MsiOpenDatabase should not create a file */
732 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
733 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
735 query
= "CREATE TABLE `phone` ( "
736 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
738 r
= run_query( hdb
, 0, query
);
739 ok(r
== ERROR_SUCCESS
, "query failed\n");
741 /* check what the error function reports without doing anything */
743 /* passing NULL as the 3rd param make function to crash on older platforms */
744 err
= MsiViewGetError( 0, NULL
, &sz
);
745 ok(err
== MSIDBERROR_INVALIDARG
, "MsiViewGetError return\n");
748 query
= "SELECT * FROM `phone`";
749 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
750 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
752 /* see what happens with a good hview and bad args */
753 err
= MsiViewGetError( hview
, NULL
, NULL
);
754 ok(err
== MSIDBERROR_INVALIDARG
|| err
== MSIDBERROR_NOERROR
,
755 "MsiViewGetError returns %u (expected -3)\n", err
);
756 err
= MsiViewGetError( hview
, buffer
, NULL
);
757 ok(err
== MSIDBERROR_INVALIDARG
, "MsiViewGetError return\n");
759 /* see what happens with a zero length buffer */
762 err
= MsiViewGetError( hview
, buffer
, &sz
);
763 ok(err
== MSIDBERROR_MOREDATA
, "MsiViewGetError return\n");
764 ok(buffer
[0] == 'x', "buffer cleared\n");
765 ok(sz
== 0, "size not zero\n");
767 /* ok this one is strange */
769 err
= MsiViewGetError( hview
, NULL
, &sz
);
770 ok(err
== MSIDBERROR_NOERROR
, "MsiViewGetError return\n");
771 ok(sz
== 0, "size not zero\n");
773 /* see if it really has an error */
776 err
= MsiViewGetError( hview
, buffer
, &sz
);
777 ok(err
== MSIDBERROR_NOERROR
, "MsiViewGetError return\n");
778 ok(buffer
[0] == 0, "buffer not cleared\n");
779 ok(sz
== 0, "size not zero\n");
781 r
= MsiViewExecute(hview
, 0);
782 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
784 /* try some invalid records */
785 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, 0 );
786 ok(r
== ERROR_INVALID_HANDLE
, "MsiViewModify failed\n");
787 r
= MsiViewModify(hview
, -1, 0 );
788 ok(r
== ERROR_INVALID_HANDLE
, "MsiViewModify failed\n");
790 /* try an small record */
791 hrec
= MsiCreateRecord(1);
792 r
= MsiViewModify(hview
, -1, hrec
);
793 ok(r
== ERROR_INVALID_DATA
, "MsiViewModify failed\n");
795 r
= MsiCloseHandle(hrec
);
796 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
798 /* insert a valid record */
799 hrec
= MsiCreateRecord(3);
801 r
= MsiRecordSetInteger(hrec
, 1, 1);
802 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
803 r
= MsiRecordSetString(hrec
, 2, "bob");
804 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
805 r
= MsiRecordSetString(hrec
, 3, "7654321");
806 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
808 r
= MsiViewExecute(hview
, 0);
809 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
810 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
811 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
813 /* insert the same thing again */
814 r
= MsiViewExecute(hview
, 0);
815 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
817 /* should fail ... */
818 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
819 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
821 r
= MsiCloseHandle(hrec
);
822 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
824 r
= MsiViewClose(hview
);
825 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
826 r
= MsiCloseHandle(hview
);
827 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
829 query
= "SELECT * FROM `phone`";
830 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
831 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
833 r
= MsiViewExecute(hview
, 0);
834 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
836 r
= MsiViewFetch(hview
, &hrec
);
837 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
839 r
= MsiRecordGetInteger(hrec
, 1);
840 ok(r
== 1, "Expected 1, got %d\n", r
);
843 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
844 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
845 ok(!lstrcmp(buffer
, "bob"), "Expected bob, got %s\n", buffer
);
848 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
849 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
850 ok(!lstrcmp(buffer
, "7654321"), "Expected 7654321, got %s\n", buffer
);
852 /* update the view, non-primary key */
853 r
= MsiRecordSetString(hrec
, 3, "3141592");
854 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
856 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
857 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
860 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
861 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
863 /* update the view, primary key */
864 r
= MsiRecordSetInteger(hrec
, 1, 5);
865 ok(r
== ERROR_SUCCESS
, "MsiRecordSetInteger failed\n");
867 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
868 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
870 r
= MsiCloseHandle(hrec
);
871 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
873 r
= MsiViewClose(hview
);
874 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
875 r
= MsiCloseHandle(hview
);
876 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
878 query
= "SELECT * FROM `phone`";
879 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
880 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
882 r
= MsiViewExecute(hview
, 0);
883 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
885 r
= MsiViewFetch(hview
, &hrec
);
886 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
888 r
= MsiRecordGetInteger(hrec
, 1);
889 ok(r
== 1, "Expected 1, got %d\n", r
);
892 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
893 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
894 ok(!lstrcmp(buffer
, "bob"), "Expected bob, got %s\n", buffer
);
897 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
898 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
899 ok(!lstrcmp(buffer
, "3141592"), "Expected 3141592, got %s\n", buffer
);
901 r
= MsiCloseHandle(hrec
);
902 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
904 /* use a record that doesn't come from a view fetch */
905 hrec
= MsiCreateRecord(3);
906 ok(hrec
!= 0, "MsiCreateRecord failed\n");
908 r
= MsiRecordSetInteger(hrec
, 1, 3);
909 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
910 r
= MsiRecordSetString(hrec
, 2, "jane");
911 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
912 r
= MsiRecordSetString(hrec
, 3, "112358");
913 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
915 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
916 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
918 r
= MsiCloseHandle(hrec
);
919 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
921 /* use a record that doesn't come from a view fetch, primary key matches */
922 hrec
= MsiCreateRecord(3);
923 ok(hrec
!= 0, "MsiCreateRecord failed\n");
925 r
= MsiRecordSetInteger(hrec
, 1, 1);
926 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
927 r
= MsiRecordSetString(hrec
, 2, "jane");
928 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
929 r
= MsiRecordSetString(hrec
, 3, "112358");
930 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
932 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
933 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
935 r
= MsiCloseHandle(hrec
);
936 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
938 hrec
= MsiCreateRecord(3);
940 r
= MsiRecordSetInteger(hrec
, 1, 2);
941 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
942 r
= MsiRecordSetString(hrec
, 2, "nick");
943 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
944 r
= MsiRecordSetString(hrec
, 3, "141421");
945 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
947 r
= MsiViewExecute(hview
, 0);
948 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
949 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
950 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
952 r
= MsiCloseHandle(hrec
);
953 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
954 r
= MsiViewClose(hview
);
955 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
956 r
= MsiCloseHandle(hview
);
957 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
959 query
= "SELECT * FROM `phone` WHERE `id` = 1";
960 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
961 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
962 r
= MsiViewExecute(hview
, 0);
963 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
964 r
= MsiViewFetch(hview
, &hrec
);
965 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
967 /* change the id to match the second row */
968 r
= MsiRecordSetInteger(hrec
, 1, 2);
969 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
970 r
= MsiRecordSetString(hrec
, 2, "jerry");
971 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
973 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
974 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
976 r
= MsiCloseHandle(hrec
);
977 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
978 r
= MsiViewClose(hview
);
979 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
980 r
= MsiCloseHandle(hview
);
981 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
984 query
= "SELECT * FROM `phone` ORDER BY `id`";
985 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
986 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
987 r
= MsiViewExecute(hview
, 0);
988 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
989 r
= MsiViewFetch(hview
, &hrec
);
990 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
992 /* change the id to match the second row */
993 r
= MsiRecordSetInteger(hrec
, 1, 2);
994 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
995 r
= MsiRecordSetString(hrec
, 2, "jerry");
996 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
998 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
999 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
1001 r
= MsiCloseHandle(hrec
);
1002 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
1003 r
= MsiViewClose(hview
);
1004 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1005 r
= MsiCloseHandle(hview
);
1006 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1008 r
= MsiCloseHandle( hdb
);
1009 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
1012 static MSIHANDLE
create_db(void)
1017 DeleteFile(msifile
);
1019 /* create an empty database */
1020 res
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1021 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
1022 if( res
!= ERROR_SUCCESS
)
1025 res
= MsiDatabaseCommit( hdb
);
1026 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
1031 static void test_getcolinfo(void)
1033 MSIHANDLE hdb
, hview
= 0, rec
= 0;
1038 /* create an empty db */
1040 ok( hdb
, "failed to create db\n");
1042 /* tables should be present */
1043 r
= MsiDatabaseOpenView(hdb
, "select * from _Tables", &hview
);
1044 ok( r
== ERROR_SUCCESS
, "failed to open query\n");
1046 r
= MsiViewExecute(hview
, 0);
1047 ok( r
== ERROR_SUCCESS
, "failed to execute query\n");
1049 /* check that NAMES works */
1051 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_NAMES
, &rec
);
1052 ok( r
== ERROR_SUCCESS
, "failed to get names\n");
1054 r
= MsiRecordGetString(rec
, 1, buffer
, &sz
);
1055 ok( r
== ERROR_SUCCESS
, "failed to get string\n");
1056 ok( !strcmp(buffer
,"Name"), "_Tables has wrong column name\n");
1057 r
= MsiCloseHandle( rec
);
1058 ok( r
== ERROR_SUCCESS
, "failed to close record handle\n");
1060 /* check that TYPES works */
1062 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_TYPES
, &rec
);
1063 ok( r
== ERROR_SUCCESS
, "failed to get names\n");
1065 r
= MsiRecordGetString(rec
, 1, buffer
, &sz
);
1066 ok( r
== ERROR_SUCCESS
, "failed to get string\n");
1067 ok( !strcmp(buffer
,"s64"), "_Tables has wrong column type\n");
1068 r
= MsiCloseHandle( rec
);
1069 ok( r
== ERROR_SUCCESS
, "failed to close record handle\n");
1071 /* check that invalid values fail */
1073 r
= MsiViewGetColumnInfo( hview
, 100, &rec
);
1074 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error code\n");
1075 ok( rec
== 0, "returned a record\n");
1077 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_TYPES
, NULL
);
1078 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error code\n");
1080 r
= MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES
, &rec
);
1081 ok( r
== ERROR_INVALID_HANDLE
, "wrong error code\n");
1083 r
= MsiViewClose(hview
);
1084 ok( r
== ERROR_SUCCESS
, "failed to close view\n");
1085 r
= MsiCloseHandle(hview
);
1086 ok( r
== ERROR_SUCCESS
, "failed to close view handle\n");
1087 r
= MsiCloseHandle(hdb
);
1088 ok( r
== ERROR_SUCCESS
, "failed to close database\n");
1091 static MSIHANDLE
get_column_info(MSIHANDLE hdb
, const char *query
, MSICOLINFO type
)
1093 MSIHANDLE hview
= 0, rec
= 0;
1096 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1097 if( r
!= ERROR_SUCCESS
)
1100 r
= MsiViewExecute(hview
, 0);
1101 if( r
== ERROR_SUCCESS
)
1103 MsiViewGetColumnInfo( hview
, type
, &rec
);
1105 MsiViewClose(hview
);
1106 MsiCloseHandle(hview
);
1110 static UINT
get_columns_table_type(MSIHANDLE hdb
, const char *table
, UINT field
)
1112 MSIHANDLE hview
= 0, rec
= 0;
1116 sprintf(query
, "select * from `_Columns` where `Table` = '%s'", table
);
1118 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1119 if( r
!= ERROR_SUCCESS
)
1122 r
= MsiViewExecute(hview
, 0);
1123 if( r
== ERROR_SUCCESS
)
1127 r
= MsiViewFetch( hview
, &rec
);
1128 if( r
!= ERROR_SUCCESS
)
1130 r
= MsiRecordGetInteger( rec
, 2 );
1132 type
= MsiRecordGetInteger( rec
, 4 );
1133 MsiCloseHandle( rec
);
1136 MsiViewClose(hview
);
1137 MsiCloseHandle(hview
);
1141 static BOOL
check_record( MSIHANDLE rec
, UINT field
, LPCSTR val
)
1148 r
= MsiRecordGetString( rec
, field
, buffer
, &sz
);
1149 return (r
== ERROR_SUCCESS
) && !strcmp(val
, buffer
);
1152 static void test_viewgetcolumninfo(void)
1154 MSIHANDLE hdb
= 0, rec
;
1158 ok( hdb
, "failed to create db\n");
1160 r
= run_query( hdb
, 0,
1161 "CREATE TABLE `Properties` "
1162 "( `Property` CHAR(255), "
1163 " `Value` CHAR(1), "
1165 " `Integervalue` INTEGER, "
1166 " `Shortvalue` SHORT, "
1167 " `Longvalue` LONG, "
1168 " `Longcharvalue` LONGCHAR "
1169 " PRIMARY KEY `Property`)" );
1170 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1172 /* check the column types */
1173 rec
= get_column_info( hdb
, "select * from `Properties`", MSICOLINFO_TYPES
);
1174 ok( rec
, "failed to get column info record\n" );
1176 ok( check_record( rec
, 1, "S255"), "wrong record type\n");
1177 ok( check_record( rec
, 2, "S1"), "wrong record type\n");
1178 ok( check_record( rec
, 3, "I2"), "wrong record type\n");
1179 ok( check_record( rec
, 4, "I2"), "wrong record type\n");
1180 ok( check_record( rec
, 5, "I2"), "wrong record type\n");
1181 ok( check_record( rec
, 6, "I4"), "wrong record type\n");
1182 ok( check_record( rec
, 7, "S0"), "wrong record type\n");
1184 MsiCloseHandle( rec
);
1186 /* check the type in _Columns */
1187 ok( 0x3dff == get_columns_table_type(hdb
, "Properties", 1 ), "_columns table wrong\n");
1188 ok( 0x1d01 == get_columns_table_type(hdb
, "Properties", 2 ), "_columns table wrong\n");
1189 ok( 0x1502 == get_columns_table_type(hdb
, "Properties", 3 ), "_columns table wrong\n");
1190 ok( 0x1502 == get_columns_table_type(hdb
, "Properties", 4 ), "_columns table wrong\n");
1191 ok( 0x1502 == get_columns_table_type(hdb
, "Properties", 5 ), "_columns table wrong\n");
1192 ok( 0x1104 == get_columns_table_type(hdb
, "Properties", 6 ), "_columns table wrong\n");
1193 ok( 0x1d00 == get_columns_table_type(hdb
, "Properties", 7 ), "_columns table wrong\n");
1195 /* now try the names */
1196 rec
= get_column_info( hdb
, "select * from `Properties`", MSICOLINFO_NAMES
);
1197 ok( rec
, "failed to get column info record\n" );
1199 ok( check_record( rec
, 1, "Property"), "wrong record type\n");
1200 ok( check_record( rec
, 2, "Value"), "wrong record type\n");
1201 ok( check_record( rec
, 3, "Intvalue"), "wrong record type\n");
1202 ok( check_record( rec
, 4, "Integervalue"), "wrong record type\n");
1203 ok( check_record( rec
, 5, "Shortvalue"), "wrong record type\n");
1204 ok( check_record( rec
, 6, "Longvalue"), "wrong record type\n");
1205 ok( check_record( rec
, 7, "Longcharvalue"), "wrong record type\n");
1207 MsiCloseHandle( rec
);
1209 r
= run_query( hdb
, 0,
1210 "CREATE TABLE `Binary` "
1211 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
1212 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1214 /* check the column types */
1215 rec
= get_column_info( hdb
, "select * from `Binary`", MSICOLINFO_TYPES
);
1216 ok( rec
, "failed to get column info record\n" );
1218 ok( check_record( rec
, 1, "S255"), "wrong record type\n");
1219 ok( check_record( rec
, 2, "V0"), "wrong record type\n");
1221 MsiCloseHandle( rec
);
1223 /* check the type in _Columns */
1224 ok( 0x3dff == get_columns_table_type(hdb
, "Binary", 1 ), "_columns table wrong\n");
1225 ok( 0x1900 == get_columns_table_type(hdb
, "Binary", 2 ), "_columns table wrong\n");
1227 /* now try the names */
1228 rec
= get_column_info( hdb
, "select * from `Binary`", MSICOLINFO_NAMES
);
1229 ok( rec
, "failed to get column info record\n" );
1231 ok( check_record( rec
, 1, "Name"), "wrong record type\n");
1232 ok( check_record( rec
, 2, "Data"), "wrong record type\n");
1233 MsiCloseHandle( rec
);
1235 r
= run_query( hdb
, 0,
1236 "CREATE TABLE `UIText` "
1237 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1238 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1240 ok( 0x2d48 == get_columns_table_type(hdb
, "UIText", 1 ), "_columns table wrong\n");
1241 ok( 0x1fff == get_columns_table_type(hdb
, "UIText", 2 ), "_columns table wrong\n");
1243 rec
= get_column_info( hdb
, "select * from `UIText`", MSICOLINFO_NAMES
);
1244 ok( rec
, "failed to get column info record\n" );
1245 ok( check_record( rec
, 1, "Key"), "wrong record type\n");
1246 ok( check_record( rec
, 2, "Text"), "wrong record type\n");
1247 MsiCloseHandle( rec
);
1249 rec
= get_column_info( hdb
, "select * from `UIText`", MSICOLINFO_TYPES
);
1250 ok( rec
, "failed to get column info record\n" );
1251 ok( check_record( rec
, 1, "s72"), "wrong record type\n");
1252 ok( check_record( rec
, 2, "L255"), "wrong record type\n");
1253 MsiCloseHandle( rec
);
1255 MsiCloseHandle( hdb
);
1258 static void test_msiexport(void)
1260 MSIHANDLE hdb
= 0, hview
= 0;
1263 char path
[MAX_PATH
];
1264 const char file
[] = "phone.txt";
1268 const char expected
[] =
1269 "id\tname\tnumber\r\n"
1272 "1\tAbe\t8675309\r\n";
1274 DeleteFile(msifile
);
1276 /* just MsiOpenDatabase should not create a file */
1277 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1278 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1280 /* create a table */
1281 query
= "CREATE TABLE `phone` ( "
1282 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1283 "PRIMARY KEY `id`)";
1284 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1285 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1286 r
= MsiViewExecute(hview
, 0);
1287 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1288 r
= MsiViewClose(hview
);
1289 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1290 r
= MsiCloseHandle(hview
);
1291 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1293 /* insert a value into it */
1294 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
1295 "VALUES('1', 'Abe', '8675309')";
1296 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1297 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1298 r
= MsiViewExecute(hview
, 0);
1299 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1300 r
= MsiViewClose(hview
);
1301 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1302 r
= MsiCloseHandle(hview
);
1303 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1305 GetCurrentDirectory(MAX_PATH
, path
);
1307 r
= MsiDatabaseExport(hdb
, "phone", path
, file
);
1308 ok(r
== ERROR_SUCCESS
, "MsiDatabaseExport failed\n");
1310 MsiCloseHandle(hdb
);
1312 lstrcat(path
, "\\");
1313 lstrcat(path
, file
);
1315 /* check the data that was written */
1317 memset(buffer
, 0, sizeof buffer
);
1318 handle
= CreateFile(path
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1319 if (handle
!= INVALID_HANDLE_VALUE
)
1321 ReadFile(handle
, buffer
, sizeof buffer
, &length
, NULL
);
1322 CloseHandle(handle
);
1326 ok(0, "failed to open file %s\n", path
);
1328 ok( length
== strlen(expected
), "length of data wrong\n");
1329 ok( !lstrcmp(buffer
, expected
), "data doesn't match\n");
1330 DeleteFile(msifile
);
1333 static void test_longstrings(void)
1335 const char insert_query
[] =
1336 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1338 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
1341 const DWORD STRING_LENGTH
= 0x10005;
1343 DeleteFile(msifile
);
1344 /* just MsiOpenDatabase should not create a file */
1345 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1346 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1348 /* create a table */
1350 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1351 ok(r
== ERROR_SUCCESS
, "query failed\n");
1353 /* try a insert a very long string */
1354 str
= HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH
+sizeof insert_query
);
1355 len
= strchr(insert_query
, 'Z') - insert_query
;
1356 strcpy(str
, insert_query
);
1357 memset(str
+len
, 'Z', STRING_LENGTH
);
1358 strcpy(str
+len
+STRING_LENGTH
, insert_query
+len
+1);
1359 r
= try_query( hdb
, str
);
1360 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1362 HeapFree(GetProcessHeap(), 0, str
);
1364 MsiDatabaseCommit(hdb
);
1365 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
1366 MsiCloseHandle(hdb
);
1368 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
1369 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1371 r
= MsiDatabaseOpenView(hdb
, "select * from `strings` where `id` = 1", &hview
);
1372 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1374 r
= MsiViewExecute(hview
, 0);
1375 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1377 r
= MsiViewFetch(hview
, &hrec
);
1378 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1380 MsiViewClose(hview
);
1381 MsiCloseHandle(hview
);
1383 r
= MsiRecordGetString(hrec
, 2, NULL
, &len
);
1384 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1385 ok(len
== STRING_LENGTH
, "string length wrong\n");
1387 MsiCloseHandle(hrec
);
1388 MsiCloseHandle(hdb
);
1389 DeleteFile(msifile
);
1392 static void create_file_data(LPCSTR name
, LPCSTR data
, DWORD size
)
1397 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
1398 if (file
== INVALID_HANDLE_VALUE
)
1401 WriteFile(file
, data
, strlen(data
), &written
, NULL
);
1402 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
1406 SetFilePointer(file
, size
, NULL
, FILE_BEGIN
);
1413 #define create_file(name) create_file_data(name, name, 0)
1415 static void test_streamtable(void)
1417 MSIHANDLE hdb
= 0, rec
, view
, hsi
;
1418 char file
[MAX_PATH
];
1424 ok( hdb
, "failed to create db\n");
1426 r
= run_query( hdb
, 0,
1427 "CREATE TABLE `Properties` "
1428 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1429 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1431 r
= run_query( hdb
, 0,
1432 "INSERT INTO `Properties` "
1433 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1434 ok( r
== ERROR_SUCCESS
, "Failed to add to table\n" );
1436 r
= MsiDatabaseCommit( hdb
);
1437 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
1439 MsiCloseHandle( hdb
);
1441 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
1442 ok( r
== ERROR_SUCCESS
, "Failed to open database\n" );
1444 /* check the column types */
1445 rec
= get_column_info( hdb
, "select * from `_Streams`", MSICOLINFO_TYPES
);
1446 ok( rec
, "failed to get column info record\n" );
1448 ok( check_record( rec
, 1, "s62"), "wrong record type\n");
1449 ok( check_record( rec
, 2, "V0"), "wrong record type\n");
1451 MsiCloseHandle( rec
);
1453 /* now try the names */
1454 rec
= get_column_info( hdb
, "select * from `_Streams`", MSICOLINFO_NAMES
);
1455 ok( rec
, "failed to get column info record\n" );
1457 ok( check_record( rec
, 1, "Name"), "wrong record type\n");
1458 ok( check_record( rec
, 2, "Data"), "wrong record type\n");
1460 MsiCloseHandle( rec
);
1462 r
= MsiDatabaseOpenView( hdb
,
1463 "SELECT * FROM `_Streams` WHERE `Name` = '\5SummaryInformation'", &view
);
1464 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %u\n", r
);
1466 r
= MsiViewExecute( view
, 0 );
1467 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %u\n", r
);
1469 r
= MsiViewFetch( view
, &rec
);
1470 ok( r
== ERROR_NO_MORE_ITEMS
, "Unexpected result: %u\n", r
);
1472 MsiCloseHandle( rec
);
1473 MsiViewClose( view
);
1474 MsiCloseHandle( view
);
1476 /* create a summary information stream */
1477 r
= MsiGetSummaryInformationA( hdb
, NULL
, 1, &hsi
);
1478 ok( r
== ERROR_SUCCESS
, "Failed to get summary information handle: %u\n", r
);
1480 r
= MsiSummaryInfoSetPropertyA( hsi
, PID_SECURITY
, VT_I4
, 2, NULL
, NULL
);
1481 ok( r
== ERROR_SUCCESS
, "Failed to set property: %u\n", r
);
1483 r
= MsiSummaryInfoPersist( hsi
);
1484 ok( r
== ERROR_SUCCESS
, "Failed to save summary information: %u\n", r
);
1486 MsiCloseHandle( hsi
);
1488 r
= MsiDatabaseOpenView( hdb
,
1489 "SELECT * FROM `_Streams` WHERE `Name` = '\5SummaryInformation'", &view
);
1490 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %u\n", r
);
1492 r
= MsiViewExecute( view
, 0 );
1493 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %u\n", r
);
1495 r
= MsiViewFetch( view
, &rec
);
1496 ok( r
== ERROR_SUCCESS
, "Unexpected result: %u\n", r
);
1498 MsiCloseHandle( rec
);
1499 MsiViewClose( view
);
1500 MsiCloseHandle( view
);
1502 /* insert a file into the _Streams table */
1503 create_file( "test.txt" );
1505 rec
= MsiCreateRecord( 2 );
1506 MsiRecordSetString( rec
, 1, "data" );
1508 r
= MsiRecordSetStream( rec
, 2, "test.txt" );
1509 ok( r
== ERROR_SUCCESS
, "Failed to add stream data to the record: %d\n", r
);
1511 DeleteFile("test.txt");
1513 r
= MsiDatabaseOpenView( hdb
,
1514 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view
);
1515 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1517 r
= MsiViewExecute( view
, rec
);
1518 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1520 MsiCloseHandle( rec
);
1521 MsiViewClose( view
);
1522 MsiCloseHandle( view
);
1524 /* insert another one */
1525 create_file( "test1.txt" );
1527 rec
= MsiCreateRecord( 2 );
1528 MsiRecordSetString( rec
, 1, "data1" );
1530 r
= MsiRecordSetStream( rec
, 2, "test1.txt" );
1531 ok( r
== ERROR_SUCCESS
, "Failed to add stream data to the record: %d\n", r
);
1533 DeleteFile("test1.txt");
1535 r
= MsiDatabaseOpenView( hdb
,
1536 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view
);
1537 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1539 r
= MsiViewExecute( view
, rec
);
1540 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1542 MsiCloseHandle( rec
);
1543 MsiViewClose( view
);
1544 MsiCloseHandle( view
);
1546 r
= MsiDatabaseOpenView( hdb
,
1547 "SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = 'data'", &view
);
1548 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1550 r
= MsiViewExecute( view
, 0 );
1551 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1553 r
= MsiViewFetch( view
, &rec
);
1554 ok( r
== ERROR_SUCCESS
, "Failed to fetch record: %d\n", r
);
1557 r
= MsiRecordGetString( rec
, 1, file
, &size
);
1558 ok( r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
1559 ok( !lstrcmp(file
, "data"), "Expected 'data', got %s\n", file
);
1562 memset(buf
, 0, MAX_PATH
);
1563 r
= MsiRecordReadStream( rec
, 2, buf
, &size
);
1564 ok( r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
1565 ok( !lstrcmp(buf
, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf
);
1567 MsiCloseHandle( rec
);
1568 MsiViewClose( view
);
1569 MsiCloseHandle( view
);
1571 r
= MsiDatabaseOpenView( hdb
,
1572 "SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = 'data1'", &view
);
1573 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1575 r
= MsiViewExecute( view
, 0 );
1576 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1578 r
= MsiViewFetch( view
, &rec
);
1579 ok( r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1582 r
= MsiRecordGetString( rec
, 1, file
, &size
);
1583 ok( r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
1584 ok( !lstrcmp(file
, "data1"), "Expected 'data1', got %s\n", file
);
1587 memset(buf
, 0, MAX_PATH
);
1588 r
= MsiRecordReadStream( rec
, 2, buf
, &size
);
1589 ok( r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
1590 ok( !lstrcmp(buf
, "test1.txt\n"), "Expected 'test1.txt\\n', got %s\n", buf
);
1592 MsiCloseHandle( rec
);
1593 MsiViewClose( view
);
1594 MsiCloseHandle( view
);
1596 /* perform an update */
1597 create_file( "test2.txt" );
1598 rec
= MsiCreateRecord( 1 );
1600 r
= MsiRecordSetStream( rec
, 1, "test2.txt" );
1601 ok( r
== ERROR_SUCCESS
, "Failed to add stream data to the record: %d\n", r
);
1603 DeleteFile("test2.txt");
1605 r
= MsiDatabaseOpenView( hdb
,
1606 "UPDATE `_Streams` SET `Data` = ? WHERE `Name` = 'data1'", &view
);
1607 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1609 r
= MsiViewExecute( view
, rec
);
1610 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1612 MsiCloseHandle( rec
);
1613 MsiViewClose( view
);
1614 MsiCloseHandle( view
);
1616 r
= MsiDatabaseOpenView( hdb
,
1617 "SELECT `Name`, `Data` FROM `_Streams` WHERE `Name` = 'data1'", &view
);
1618 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1620 r
= MsiViewExecute( view
, 0 );
1621 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1623 r
= MsiViewFetch( view
, &rec
);
1624 ok( r
== ERROR_SUCCESS
, "Failed to fetch record: %d\n", r
);
1627 r
= MsiRecordGetString( rec
, 1, file
, &size
);
1628 ok( r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
1629 ok( !lstrcmp(file
, "data1"), "Expected 'data1', got %s\n", file
);
1632 memset(buf
, 0, MAX_PATH
);
1633 r
= MsiRecordReadStream( rec
, 2, buf
, &size
);
1634 ok( r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
1635 todo_wine
ok( !lstrcmp(buf
, "test2.txt\n"), "Expected 'test2.txt\\n', got %s\n", buf
);
1637 MsiCloseHandle( rec
);
1638 MsiViewClose( view
);
1639 MsiCloseHandle( view
);
1640 MsiCloseHandle( hdb
);
1641 DeleteFile(msifile
);
1644 static void test_binary(void)
1646 MSIHANDLE hdb
= 0, rec
;
1647 char file
[MAX_PATH
];
1653 /* insert a file into the Binary table */
1654 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1655 ok( r
== ERROR_SUCCESS
, "Failed to open database\n" );
1657 query
= "CREATE TABLE `Binary` ( `Name` CHAR(72) NOT NULL, `ID` INT NOT NULL, `Data` OBJECT PRIMARY KEY `Name`, `ID`)";
1658 r
= run_query( hdb
, 0, query
);
1659 ok( r
== ERROR_SUCCESS
, "Cannot create Binary table: %d\n", r
);
1661 create_file( "test.txt" );
1662 rec
= MsiCreateRecord( 1 );
1663 r
= MsiRecordSetStream( rec
, 1, "test.txt" );
1664 ok( r
== ERROR_SUCCESS
, "Failed to add stream data to the record: %d\n", r
);
1665 DeleteFile( "test.txt" );
1667 query
= "INSERT INTO `Binary` ( `Name`, `ID`, `Data` ) VALUES ( 'filename1', 1, ? )";
1668 r
= run_query( hdb
, rec
, query
);
1669 ok( r
== ERROR_SUCCESS
, "Insert into Binary table failed: %d\n", r
);
1671 r
= MsiCloseHandle( rec
);
1672 ok( r
== ERROR_SUCCESS
, "Failed to close record handle\n" );
1674 r
= MsiDatabaseCommit( hdb
);
1675 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
1677 r
= MsiCloseHandle( hdb
);
1678 ok( r
== ERROR_SUCCESS
, "Failed to close database\n" );
1680 /* read file from the Stream table */
1681 r
= MsiOpenDatabase( msifile
, MSIDBOPEN_READONLY
, &hdb
);
1682 ok( r
== ERROR_SUCCESS
, "Failed to open database\n" );
1684 query
= "SELECT * FROM `_Streams`";
1685 r
= do_query( hdb
, query
, &rec
);
1686 ok( r
== ERROR_SUCCESS
, "SELECT query failed: %d\n", r
);
1689 r
= MsiRecordGetString( rec
, 1, file
, &size
);
1690 ok( r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
1691 ok( !lstrcmp(file
, "Binary.filename1.1"), "Expected 'Binary.filename1.1', got %s\n", file
);
1694 memset( buf
, 0, MAX_PATH
);
1695 r
= MsiRecordReadStream( rec
, 2, buf
, &size
);
1696 ok( r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
1697 ok( !lstrcmp(buf
, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf
);
1699 r
= MsiCloseHandle( rec
);
1700 ok( r
== ERROR_SUCCESS
, "Failed to close record handle\n" );
1702 /* read file from the Binary table */
1703 query
= "SELECT * FROM `Binary`";
1704 r
= do_query( hdb
, query
, &rec
);
1705 ok( r
== ERROR_SUCCESS
, "SELECT query failed: %d\n", r
);
1708 r
= MsiRecordGetString( rec
, 1, file
, &size
);
1709 ok( r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
1710 ok( !lstrcmp(file
, "filename1"), "Expected 'filename1', got %s\n", file
);
1713 memset( buf
, 0, MAX_PATH
);
1714 r
= MsiRecordReadStream( rec
, 3, buf
, &size
);
1715 ok( r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
1716 ok( !lstrcmp(buf
, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf
);
1718 r
= MsiCloseHandle( rec
);
1719 ok( r
== ERROR_SUCCESS
, "Failed to close record handle\n" );
1721 r
= MsiCloseHandle( hdb
);
1722 ok( r
== ERROR_SUCCESS
, "Failed to close database\n" );
1724 DeleteFile( msifile
);
1727 static void test_where_not_in_selected(void)
1729 MSIHANDLE hdb
= 0, rec
, view
;
1734 ok( hdb
, "failed to create db\n");
1736 r
= run_query(hdb
, 0,
1737 "CREATE TABLE `IESTable` ("
1738 "`Action` CHAR(64), "
1739 "`Condition` CHAR(64), "
1740 "`Sequence` LONG PRIMARY KEY `Sequence`)");
1741 ok( r
== S_OK
, "Cannot create IESTable table: %d\n", r
);
1743 r
= run_query(hdb
, 0,
1744 "CREATE TABLE `CATable` ("
1745 "`Action` CHAR(64), "
1746 "`Type` LONG PRIMARY KEY `Type`)");
1747 ok( r
== S_OK
, "Cannot create CATable table: %d\n", r
);
1749 r
= run_query(hdb
, 0, "INSERT INTO `IESTable` "
1750 "( `Action`, `Condition`, `Sequence`) "
1751 "VALUES ( 'clean', 'cond4', 4)");
1752 ok( r
== S_OK
, "cannot add entry to IESTable table:%d\n", r
);
1754 r
= run_query(hdb
, 0, "INSERT INTO `IESTable` "
1755 "( `Action`, `Condition`, `Sequence`) "
1756 "VALUES ( 'depends', 'cond1', 1)");
1757 ok( r
== S_OK
, "cannot add entry to IESTable table:%d\n", r
);
1759 r
= run_query(hdb
, 0, "INSERT INTO `IESTable` "
1760 "( `Action`, `Condition`, `Sequence`) "
1761 "VALUES ( 'build', 'cond2', 2)");
1762 ok( r
== S_OK
, "cannot add entry to IESTable table:%d\n", r
);
1764 r
= run_query(hdb
, 0, "INSERT INTO `IESTable` "
1765 "( `Action`, `Condition`, `Sequence`) "
1766 "VALUES ( 'build2', 'cond6', 6)");
1767 ok( r
== S_OK
, "cannot add entry to IESTable table:%d\n", r
);
1769 r
= run_query(hdb
, 0, "INSERT INTO `IESTable` "
1770 "( `Action`, `Condition`, `Sequence`) "
1771 "VALUES ( 'build', 'cond3', 3)");
1772 ok(r
== S_OK
, "cannot add entry to IESTable table:%d\n", r
);
1774 r
= run_query(hdb
, 0, "INSERT INTO `CATable` "
1775 "( `Action`, `Type` ) "
1776 "VALUES ( 'build', 32)");
1777 ok(r
== S_OK
, "cannot add entry to CATable table:%d\n", r
);
1779 r
= run_query(hdb
, 0, "INSERT INTO `CATable` "
1780 "( `Action`, `Type` ) "
1781 "VALUES ( 'depends', 64)");
1782 ok(r
== S_OK
, "cannot add entry to CATable table:%d\n", r
);
1784 r
= run_query(hdb
, 0, "INSERT INTO `CATable` "
1785 "( `Action`, `Type` ) "
1786 "VALUES ( 'clean', 63)");
1787 ok(r
== S_OK
, "cannot add entry to CATable table:%d\n", r
);
1789 r
= run_query(hdb
, 0, "INSERT INTO `CATable` "
1790 "( `Action`, `Type` ) "
1791 "VALUES ( 'build2', 34)");
1792 ok(r
== S_OK
, "cannot add entry to CATable table:%d\n", r
);
1793 query
= "Select IESTable.Condition from CATable, IESTable where "
1794 "CATable.Action = IESTable.Action and CATable.Type = 32";
1795 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1796 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
1798 r
= MsiViewExecute(view
, 0);
1799 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
1801 r
= MsiViewFetch(view
, &rec
);
1802 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1804 ok( check_record( rec
, 1, "cond2"), "wrong condition\n");
1806 MsiCloseHandle( rec
);
1807 r
= MsiViewFetch(view
, &rec
);
1808 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1810 ok( check_record( rec
, 1, "cond3"), "wrong condition\n");
1812 MsiCloseHandle( rec
);
1814 MsiCloseHandle(view
);
1816 MsiCloseHandle( hdb
);
1817 DeleteFile(msifile
);
1822 static void test_where(void)
1824 MSIHANDLE hdb
= 0, rec
, view
;
1832 ok( hdb
, "failed to create db\n");
1834 r
= run_query( hdb
, 0,
1835 "CREATE TABLE `Media` ("
1836 "`DiskId` SHORT NOT NULL, "
1837 "`LastSequence` LONG, "
1838 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1839 "`Cabinet` CHAR(255), "
1840 "`VolumeLabel` CHAR(32), "
1841 "`Source` CHAR(72) "
1842 "PRIMARY KEY `DiskId`)" );
1843 ok( r
== S_OK
, "cannot create Media table: %d\n", r
);
1845 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1846 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1847 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1848 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1850 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1851 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1852 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1853 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1855 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1856 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1857 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1858 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1860 query
= "SELECT * FROM `Media`";
1861 r
= do_query(hdb
, query
, &rec
);
1862 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed: %d\n", r
);
1863 ok( check_record( rec
, 4, "zero.cab"), "wrong cabinet\n");
1864 MsiCloseHandle( rec
);
1866 query
= "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1867 r
= do_query(hdb
, query
, &rec
);
1868 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed: %d\n", r
);
1869 ok( check_record( rec
, 4, "one.cab"), "wrong cabinet\n");
1871 r
= MsiRecordGetInteger(rec
, 1);
1872 ok( 2 == r
, "field wrong\n");
1873 r
= MsiRecordGetInteger(rec
, 2);
1874 ok( 1 == r
, "field wrong\n");
1875 MsiCloseHandle( rec
);
1877 query
= "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1878 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1879 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
1881 r
= MsiViewExecute(view
, 0);
1882 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
1884 r
= MsiViewFetch(view
, &rec
);
1885 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1887 count
= MsiRecordGetFieldCount( rec
);
1888 ok( count
== 1, "Expected 1 record fields, got %d\n", count
);
1891 r
= MsiRecordGetString( rec
, 1, buf
, &size
);
1892 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
1893 ok( !lstrcmp( buf
, "2" ),
1894 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf
);
1895 MsiCloseHandle( rec
);
1897 r
= MsiViewFetch(view
, &rec
);
1898 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1901 r
= MsiRecordGetString( rec
, 1, buf
, &size
);
1902 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
1903 ok( !lstrcmp( buf
, "3" ),
1904 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf
);
1905 MsiCloseHandle( rec
);
1907 r
= MsiViewFetch(view
, &rec
);
1908 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
1911 MsiCloseHandle(view
);
1913 MsiCloseHandle( rec
);
1916 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1917 r
= do_query(hdb
, query
, &rec
);
1918 ok( r
== ERROR_SUCCESS
, "query failed: %d\n", r
);
1919 MsiCloseHandle( rec
);
1922 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` < 'Cabinet'";
1923 r
= do_query(hdb
, query
, &rec
);
1924 ok( r
== ERROR_BAD_QUERY_SYNTAX
, "query failed: %d\n", r
);
1925 MsiCloseHandle( rec
);
1928 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` > 'Cabinet'";
1929 r
= do_query(hdb
, query
, &rec
);
1930 ok( r
== ERROR_BAD_QUERY_SYNTAX
, "query failed: %d\n", r
);
1931 MsiCloseHandle( rec
);
1934 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` <> 'Cabinet'";
1935 r
= do_query(hdb
, query
, &rec
);
1936 ok( r
== ERROR_SUCCESS
, "query failed: %d\n", r
);
1937 MsiCloseHandle( rec
);
1940 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` = 'Cabinet'";
1941 r
= do_query(hdb
, query
, &rec
);
1942 ok( r
== ERROR_NO_MORE_ITEMS
, "query failed: %d\n", r
);
1943 MsiCloseHandle( rec
);
1945 rec
= MsiCreateRecord(1);
1946 MsiRecordSetString(rec
, 1, "");
1948 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` = ?";
1949 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1950 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1951 r
= MsiViewExecute(view
, rec
);
1952 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1954 MsiCloseHandle(rec
);
1956 r
= MsiViewFetch(view
, &rec
);
1957 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1959 MsiCloseHandle(rec
);
1961 MsiCloseHandle(view
);
1963 MsiCloseHandle( hdb
);
1964 DeleteFile(msifile
);
1967 static CHAR CURR_DIR
[MAX_PATH
];
1969 static const CHAR test_data
[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1970 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1971 "TestTable\tFirstPrimaryColumn\n"
1972 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1974 static const CHAR two_primary
[] = "PrimaryOne\tPrimaryTwo\n"
1976 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1980 static const CHAR endlines1
[] = "A\tB\tC\tD\tE\tF\r\n"
1981 "s72\ts72\ts72\ts72\ts72\ts72\n"
1983 "a\tb\tc\td\te\tf\n"
1984 "g\th\ti\t\rj\tk\tl\r\n";
1986 static const CHAR endlines2
[] = "A\tB\tC\tD\tE\tF\r"
1987 "s72\ts72\ts72\ts72\ts72\ts72\n"
1989 "a\tb\tc\td\te\tf\n"
1990 "g\th\ti\tj\tk\tl\r\n";
1992 static const CHAR suminfo
[] = "PropertyId\tValue\n"
1994 "_SummaryInformation\tPropertyId\n"
1996 "2\tInstaller Database\n"
1997 "3\tInstaller description\n"
2000 "6\tInstaller comments\n"
2002 "9\t{12345678-1234-1234-1234-123456789012}\n"
2003 "12\t2009/04/12 15:46:11\n"
2004 "13\t2009/04/12 15:46:11\n"
2010 static void write_file(const CHAR
*filename
, const char *data
, int data_size
)
2014 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
2015 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2017 WriteFile(hf
, data
, data_size
, &size
, NULL
);
2021 static UINT
add_table_to_db(MSIHANDLE hdb
, LPCSTR table_data
)
2025 write_file("temp_file", table_data
, (lstrlen(table_data
) - 1) * sizeof(char));
2026 r
= MsiDatabaseImportA(hdb
, CURR_DIR
, "temp_file");
2027 DeleteFileA("temp_file");
2032 static void test_suminfo_import(void)
2034 MSIHANDLE hdb
, hsi
, view
= 0;
2036 UINT r
, count
, size
, type
;
2041 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
2043 r
= MsiOpenDatabaseA(msifile
, MSIDBOPEN_CREATE
, &hdb
);
2044 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2046 r
= add_table_to_db(hdb
, suminfo
);
2047 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2049 /* _SummaryInformation is not imported as a regular table... */
2051 query
= "SELECT * FROM `_SummaryInformation`";
2052 r
= MsiDatabaseOpenViewA(hdb
, query
, &view
);
2053 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %u\n", r
);
2054 MsiCloseHandle(view
);
2056 /* ...its data is added to the special summary information stream */
2058 r
= MsiGetSummaryInformationA(hdb
, NULL
, 0, &hsi
);
2059 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2061 r
= MsiSummaryInfoGetPropertyCount(hsi
, &count
);
2062 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2063 ok(count
== 14, "Expected 14, got %u\n", count
);
2065 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_CODEPAGE
, &type
, &int_value
, NULL
, NULL
, NULL
);
2066 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2067 ok(type
== VT_I2
, "Expected VT_I2, got %u\n", type
);
2068 ok(int_value
== 1252, "Expected 1252, got %d\n", int_value
);
2070 size
= sizeof(str_value
);
2071 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_TITLE
, &type
, NULL
, NULL
, str_value
, &size
);
2072 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2073 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
2074 ok(size
== 18, "Expected 18, got %u\n", size
);
2075 ok(!strcmp(str_value
, "Installer Database"),
2076 "Expected \"Installer Database\", got %s\n", str_value
);
2078 size
= sizeof(str_value
);
2079 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_SUBJECT
, &type
, NULL
, NULL
, str_value
, &size
);
2080 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2081 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
2082 ok(!strcmp(str_value
, "Installer description"),
2083 "Expected \"Installer description\", got %s\n", str_value
);
2085 size
= sizeof(str_value
);
2086 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_AUTHOR
, &type
, NULL
, NULL
, str_value
, &size
);
2087 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2088 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
2089 ok(!strcmp(str_value
, "WineHQ"),
2090 "Expected \"WineHQ\", got %s\n", str_value
);
2092 size
= sizeof(str_value
);
2093 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_KEYWORDS
, &type
, NULL
, NULL
, str_value
, &size
);
2094 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2095 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
2096 ok(!strcmp(str_value
, "Installer"),
2097 "Expected \"Installer\", got %s\n", str_value
);
2099 size
= sizeof(str_value
);
2100 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_COMMENTS
, &type
, NULL
, NULL
, str_value
, &size
);
2101 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2102 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
2103 ok(!strcmp(str_value
, "Installer comments"),
2104 "Expected \"Installer comments\", got %s\n", str_value
);
2106 size
= sizeof(str_value
);
2107 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_TEMPLATE
, &type
, NULL
, NULL
, str_value
, &size
);
2108 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2109 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
2110 ok(!strcmp(str_value
, "Intel;1033"),
2111 "Expected \"Intel;1033\", got %s\n", str_value
);
2113 size
= sizeof(str_value
);
2114 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_REVNUMBER
, &type
, NULL
, NULL
, str_value
, &size
);
2115 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2116 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
2117 ok(!strcmp(str_value
, "{12345678-1234-1234-1234-123456789012}"),
2118 "Expected \"{12345678-1234-1234-1234-123456789012}\", got %s\n", str_value
);
2120 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_CREATE_DTM
, &type
, NULL
, &ft_value
, NULL
, NULL
);
2121 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2122 ok(type
== VT_FILETIME
, "Expected VT_FILETIME, got %u\n", type
);
2124 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_LASTSAVE_DTM
, &type
, NULL
, &ft_value
, NULL
, NULL
);
2125 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2126 ok(type
== VT_FILETIME
, "Expected VT_FILETIME, got %u\n", type
);
2128 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_PAGECOUNT
, &type
, &int_value
, NULL
, NULL
, NULL
);
2129 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2130 ok(type
== VT_I4
, "Expected VT_I4, got %u\n", type
);
2131 ok(int_value
== 200, "Expected 200, got %d\n", int_value
);
2133 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_WORDCOUNT
, &type
, &int_value
, NULL
, NULL
, NULL
);
2134 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2135 ok(type
== VT_I4
, "Expected VT_I4, got %u\n", type
);
2136 ok(int_value
== 2, "Expected 2, got %d\n", int_value
);
2138 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_SECURITY
, &type
, &int_value
, NULL
, NULL
, NULL
);
2139 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2140 ok(type
== VT_I4
, "Expected VT_I4, got %u\n", type
);
2141 ok(int_value
== 2, "Expected 2, got %d\n", int_value
);
2143 size
= sizeof(str_value
);
2144 r
= MsiSummaryInfoGetPropertyA(hsi
, PID_APPNAME
, &type
, NULL
, NULL
, str_value
, &size
);
2145 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
2146 ok(type
== VT_LPSTR
, "Expected VT_LPSTR, got %u\n", type
);
2147 ok(!strcmp(str_value
, "Vim"), "Expected \"Vim\", got %s\n", str_value
);
2149 MsiCloseHandle(hsi
);
2150 MsiCloseHandle(hdb
);
2151 DeleteFileA(msifile
);
2154 static void test_msiimport(void)
2156 MSIHANDLE hdb
, view
, rec
;
2161 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
2163 r
= MsiOpenDatabaseA(msifile
, MSIDBOPEN_CREATE
, &hdb
);
2164 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2166 r
= add_table_to_db(hdb
, test_data
);
2167 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2169 r
= add_table_to_db(hdb
, two_primary
);
2170 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2172 r
= add_table_to_db(hdb
, endlines1
);
2173 if (r
== ERROR_FUNCTION_FAILED
)
2175 /* win9x doesn't handle this case */
2176 skip("endlines not handled correctly.\n");
2177 MsiCloseHandle(hdb
);
2178 DeleteFileA(msifile
);
2182 r
= add_table_to_db(hdb
, endlines2
);
2183 ok(r
== ERROR_FUNCTION_FAILED
,
2184 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
2186 query
= "SELECT * FROM `TestTable`";
2187 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2188 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2190 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
2191 count
= MsiRecordGetFieldCount(rec
);
2192 ok(count
== 9, "Expected 9, got %d\n", count
);
2193 ok(check_record(rec
, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
2194 ok(check_record(rec
, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
2195 ok(check_record(rec
, 3, "ShortInt"), "Expected ShortInt\n");
2196 ok(check_record(rec
, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
2197 ok(check_record(rec
, 5, "LongInt"), "Expected LongInt\n");
2198 ok(check_record(rec
, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
2199 ok(check_record(rec
, 7, "String"), "Expected String\n");
2200 ok(check_record(rec
, 8, "LocalizableString"), "Expected LocalizableString\n");
2201 ok(check_record(rec
, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
2202 MsiCloseHandle(rec
);
2204 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
2205 count
= MsiRecordGetFieldCount(rec
);
2206 ok(count
== 9, "Expected 9, got %d\n", count
);
2207 ok(check_record(rec
, 1, "s255"), "Expected s255\n");
2208 ok(check_record(rec
, 2, "i2"), "Expected i2\n");
2209 ok(check_record(rec
, 3, "i2"), "Expected i2\n");
2210 ok(check_record(rec
, 4, "I2"), "Expected I2\n");
2211 ok(check_record(rec
, 5, "i4"), "Expected i4\n");
2212 ok(check_record(rec
, 6, "I4"), "Expected I4\n");
2213 ok(check_record(rec
, 7, "S255"), "Expected S255\n");
2214 ok(check_record(rec
, 8, "S0"), "Expected S0\n");
2215 ok(check_record(rec
, 9, "s0"), "Expected s0\n");
2216 MsiCloseHandle(rec
);
2218 query
= "SELECT * FROM `TestTable`";
2219 r
= do_query(hdb
, query
, &rec
);
2220 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2221 ok(check_record(rec
, 1, "stringage"), "Expected 'stringage'\n");
2222 ok(check_record(rec
, 7, "another string"), "Expected 'another string'\n");
2223 ok(check_record(rec
, 8, "localizable"), "Expected 'localizable'\n");
2224 ok(check_record(rec
, 9, "duh"), "Expected 'duh'\n");
2226 i
= MsiRecordGetInteger(rec
, 2);
2227 ok(i
== 5, "Expected 5, got %d\n", i
);
2229 i
= MsiRecordGetInteger(rec
, 3);
2230 ok(i
== 2, "Expected 2, got %d\n", i
);
2232 i
= MsiRecordGetInteger(rec
, 4);
2233 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
2235 i
= MsiRecordGetInteger(rec
, 5);
2236 ok(i
== 2147483640, "Expected 2147483640, got %d\n", i
);
2238 i
= MsiRecordGetInteger(rec
, 6);
2239 ok(i
== -2147483640, "Expected -2147483640, got %d\n", i
);
2241 MsiCloseHandle(rec
);
2243 MsiCloseHandle(view
);
2245 query
= "SELECT * FROM `TwoPrimary`";
2246 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2247 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2249 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
2250 count
= MsiRecordGetFieldCount(rec
);
2251 ok(count
== 2, "Expected 2, got %d\n", count
);
2252 ok(check_record(rec
, 1, "PrimaryOne"), "Expected PrimaryOne\n");
2253 ok(check_record(rec
, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
2255 MsiCloseHandle(rec
);
2257 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
2258 count
= MsiRecordGetFieldCount(rec
);
2259 ok(count
== 2, "Expected 2, got %d\n", count
);
2260 ok(check_record(rec
, 1, "s255"), "Expected s255\n");
2261 ok(check_record(rec
, 2, "s255"), "Expected s255\n");
2262 MsiCloseHandle(rec
);
2264 r
= MsiViewExecute(view
, 0);
2265 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2267 r
= MsiViewFetch(view
, &rec
);
2268 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2270 ok(check_record(rec
, 1, "papaya"), "Expected 'papaya'\n");
2271 ok(check_record(rec
, 2, "leaf"), "Expected 'leaf'\n");
2273 MsiCloseHandle(rec
);
2275 r
= MsiViewFetch(view
, &rec
);
2276 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2278 ok(check_record(rec
, 1, "papaya"), "Expected 'papaya'\n");
2279 ok(check_record(rec
, 2, "flower"), "Expected 'flower'\n");
2281 MsiCloseHandle(rec
);
2283 r
= MsiViewFetch(view
, &rec
);
2284 ok(r
== ERROR_NO_MORE_ITEMS
,
2285 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
2287 r
= MsiViewClose(view
);
2288 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2290 MsiCloseHandle(view
);
2292 query
= "SELECT * FROM `Table`";
2293 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2294 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2296 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
2297 count
= MsiRecordGetFieldCount(rec
);
2298 ok(count
== 6, "Expected 6, got %d\n", count
);
2299 ok(check_record(rec
, 1, "A"), "Expected A\n");
2300 ok(check_record(rec
, 2, "B"), "Expected B\n");
2301 ok(check_record(rec
, 3, "C"), "Expected C\n");
2302 ok(check_record(rec
, 4, "D"), "Expected D\n");
2303 ok(check_record(rec
, 5, "E"), "Expected E\n");
2304 ok(check_record(rec
, 6, "F"), "Expected F\n");
2305 MsiCloseHandle(rec
);
2307 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
2308 count
= MsiRecordGetFieldCount(rec
);
2309 ok(count
== 6, "Expected 6, got %d\n", count
);
2310 ok(check_record(rec
, 1, "s72"), "Expected s72\n");
2311 ok(check_record(rec
, 2, "s72"), "Expected s72\n");
2312 ok(check_record(rec
, 3, "s72"), "Expected s72\n");
2313 ok(check_record(rec
, 4, "s72"), "Expected s72\n");
2314 ok(check_record(rec
, 5, "s72"), "Expected s72\n");
2315 ok(check_record(rec
, 6, "s72"), "Expected s72\n");
2316 MsiCloseHandle(rec
);
2319 MsiCloseHandle(view
);
2321 query
= "SELECT * FROM `Table`";
2322 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2323 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2325 r
= MsiViewExecute(view
, 0);
2326 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2328 r
= MsiViewFetch(view
, &rec
);
2329 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2330 ok(check_record(rec
, 1, "a"), "Expected 'a'\n");
2331 ok(check_record(rec
, 2, "b"), "Expected 'b'\n");
2332 ok(check_record(rec
, 3, "c"), "Expected 'c'\n");
2333 ok(check_record(rec
, 4, "d"), "Expected 'd'\n");
2334 ok(check_record(rec
, 5, "e"), "Expected 'e'\n");
2335 ok(check_record(rec
, 6, "f"), "Expected 'f'\n");
2337 MsiCloseHandle(rec
);
2339 r
= MsiViewFetch(view
, &rec
);
2340 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2341 ok(check_record(rec
, 1, "g"), "Expected 'g'\n");
2342 ok(check_record(rec
, 2, "h"), "Expected 'h'\n");
2343 ok(check_record(rec
, 3, "i"), "Expected 'i'\n");
2344 ok(check_record(rec
, 4, "j"), "Expected 'j'\n");
2345 ok(check_record(rec
, 5, "k"), "Expected 'k'\n");
2346 ok(check_record(rec
, 6, "l"), "Expected 'l'\n");
2348 MsiCloseHandle(rec
);
2350 r
= MsiViewFetch(view
, &rec
);
2351 ok(r
== ERROR_NO_MORE_ITEMS
,
2352 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
2355 MsiCloseHandle(view
);
2356 MsiCloseHandle(hdb
);
2357 DeleteFileA(msifile
);
2360 static const CHAR bin_import_dat
[] = "Name\tData\r\n"
2363 "filename1\tfilename1.ibd\r\n";
2365 static void test_binary_import(void)
2367 MSIHANDLE hdb
= 0, rec
;
2368 char file
[MAX_PATH
];
2370 char path
[MAX_PATH
];
2375 /* create files to import */
2376 write_file("bin_import.idt", bin_import_dat
,
2377 (sizeof(bin_import_dat
) - 1) * sizeof(char));
2378 CreateDirectory("bin_import", NULL
);
2379 create_file_data("bin_import/filename1.ibd", "just some words", 15);
2381 /* import files into database */
2382 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
2383 ok( r
== ERROR_SUCCESS
, "Failed to open database\n");
2385 GetCurrentDirectory(MAX_PATH
, path
);
2386 r
= MsiDatabaseImport(hdb
, path
, "bin_import.idt");
2387 ok(r
== ERROR_SUCCESS
, "Failed to import Binary table\n");
2389 /* read file from the Binary table */
2390 query
= "SELECT * FROM `Binary`";
2391 r
= do_query(hdb
, query
, &rec
);
2392 ok(r
== ERROR_SUCCESS
, "SELECT query failed: %d\n", r
);
2395 r
= MsiRecordGetString(rec
, 1, file
, &size
);
2396 ok(r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
2397 ok(!lstrcmp(file
, "filename1"), "Expected 'filename1', got %s\n", file
);
2400 memset(buf
, 0, MAX_PATH
);
2401 r
= MsiRecordReadStream(rec
, 2, buf
, &size
);
2402 ok(r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
2403 ok(!lstrcmp(buf
, "just some words"),
2404 "Expected 'just some words', got %s\n", buf
);
2406 r
= MsiCloseHandle(rec
);
2407 ok(r
== ERROR_SUCCESS
, "Failed to close record handle\n");
2409 r
= MsiCloseHandle(hdb
);
2410 ok(r
== ERROR_SUCCESS
, "Failed to close database\n");
2412 DeleteFile("bin_import/filename1.ibd");
2413 RemoveDirectory("bin_import");
2414 DeleteFile("bin_import.idt");
2417 static void test_markers(void)
2424 ok( hdb
, "failed to create db\n");
2426 rec
= MsiCreateRecord(3);
2427 MsiRecordSetString(rec
, 1, "Table");
2428 MsiRecordSetString(rec
, 2, "Apples");
2429 MsiRecordSetString(rec
, 3, "Oranges");
2431 /* try a legit create */
2432 query
= "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2433 r
= run_query(hdb
, 0, query
);
2434 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2435 MsiCloseHandle(rec
);
2437 /* try table name as marker */
2438 rec
= MsiCreateRecord(1);
2439 MsiRecordSetString(rec
, 1, "Fable");
2440 query
= "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2441 r
= run_query(hdb
, rec
, query
);
2442 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2444 /* verify that we just created a table called '?', not 'Fable' */
2445 r
= try_query(hdb
, "SELECT * from `Fable`");
2446 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2448 r
= try_query(hdb
, "SELECT * from `?`");
2449 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2451 /* try table name as marker without backticks */
2452 MsiRecordSetString(rec
, 1, "Mable");
2453 query
= "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2454 r
= run_query(hdb
, rec
, query
);
2455 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2457 /* try one column name as marker */
2458 MsiRecordSetString(rec
, 1, "One");
2459 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
2460 r
= run_query(hdb
, rec
, query
);
2461 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2462 MsiCloseHandle(rec
);
2464 /* try column names as markers */
2465 rec
= MsiCreateRecord(2);
2466 MsiRecordSetString(rec
, 1, "One");
2467 MsiRecordSetString(rec
, 2, "Two");
2468 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
2469 r
= run_query(hdb
, rec
, query
);
2470 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2471 MsiCloseHandle(rec
);
2473 /* try names with backticks */
2474 rec
= MsiCreateRecord(3);
2475 MsiRecordSetString(rec
, 1, "One");
2476 MsiRecordSetString(rec
, 2, "Two");
2477 MsiRecordSetString(rec
, 3, "One");
2478 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
2479 r
= run_query(hdb
, rec
, query
);
2480 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2482 /* try names with backticks, minus definitions */
2483 query
= "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
2484 r
= run_query(hdb
, rec
, query
);
2485 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2487 /* try names without backticks */
2488 query
= "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
2489 r
= run_query(hdb
, rec
, query
);
2490 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2491 MsiCloseHandle(rec
);
2493 /* try one long marker */
2494 rec
= MsiCreateRecord(1);
2495 MsiRecordSetString(rec
, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
2496 query
= "CREATE TABLE `Mable` ( ? )";
2497 r
= run_query(hdb
, rec
, query
);
2498 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2499 MsiCloseHandle(rec
);
2501 /* try all names as markers */
2502 rec
= MsiCreateRecord(4);
2503 MsiRecordSetString(rec
, 1, "Mable");
2504 MsiRecordSetString(rec
, 2, "One");
2505 MsiRecordSetString(rec
, 3, "Two");
2506 MsiRecordSetString(rec
, 4, "One");
2507 query
= "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
2508 r
= run_query(hdb
, rec
, query
);
2509 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2510 MsiCloseHandle(rec
);
2512 /* try a legit insert */
2513 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
2514 r
= run_query(hdb
, 0, query
);
2515 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2517 r
= try_query(hdb
, "SELECT * from `Table`");
2518 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2520 /* try values as markers */
2521 rec
= MsiCreateRecord(2);
2522 MsiRecordSetInteger(rec
, 1, 4);
2523 MsiRecordSetString(rec
, 2, "hi");
2524 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2525 r
= run_query(hdb
, rec
, query
);
2526 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2527 MsiCloseHandle(rec
);
2529 /* try column names and values as markers */
2530 rec
= MsiCreateRecord(4);
2531 MsiRecordSetString(rec
, 1, "One");
2532 MsiRecordSetString(rec
, 2, "Two");
2533 MsiRecordSetInteger(rec
, 3, 5);
2534 MsiRecordSetString(rec
, 4, "hi");
2535 query
= "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
2536 r
= run_query(hdb
, rec
, query
);
2537 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2538 MsiCloseHandle(rec
);
2540 /* try column names as markers */
2541 rec
= MsiCreateRecord(2);
2542 MsiRecordSetString(rec
, 1, "One");
2543 MsiRecordSetString(rec
, 2, "Two");
2544 query
= "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
2545 r
= run_query(hdb
, rec
, query
);
2546 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2547 MsiCloseHandle(rec
);
2549 /* try table name as a marker */
2550 rec
= MsiCreateRecord(1);
2551 MsiRecordSetString(rec
, 1, "Table");
2552 query
= "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
2553 r
= run_query(hdb
, rec
, query
);
2554 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2555 MsiCloseHandle(rec
);
2557 /* try table name and values as markers */
2558 rec
= MsiCreateRecord(3);
2559 MsiRecordSetString(rec
, 1, "Table");
2560 MsiRecordSetInteger(rec
, 2, 10);
2561 MsiRecordSetString(rec
, 3, "haha");
2562 query
= "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
2563 r
= run_query(hdb
, rec
, query
);
2564 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
2565 MsiCloseHandle(rec
);
2567 /* try all markers */
2568 rec
= MsiCreateRecord(5);
2569 MsiRecordSetString(rec
, 1, "Table");
2570 MsiRecordSetString(rec
, 1, "One");
2571 MsiRecordSetString(rec
, 1, "Two");
2572 MsiRecordSetInteger(rec
, 2, 10);
2573 MsiRecordSetString(rec
, 3, "haha");
2574 query
= "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
2575 r
= run_query(hdb
, rec
, query
);
2576 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2577 MsiCloseHandle(rec
);
2579 /* insert an integer as a string */
2580 rec
= MsiCreateRecord(2);
2581 MsiRecordSetString(rec
, 1, "11");
2582 MsiRecordSetString(rec
, 2, "hi");
2583 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2584 r
= run_query(hdb
, rec
, query
);
2585 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2586 MsiCloseHandle(rec
);
2588 /* leave off the '' for the string */
2589 rec
= MsiCreateRecord(2);
2590 MsiRecordSetInteger(rec
, 1, 12);
2591 MsiRecordSetString(rec
, 2, "hi");
2592 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
2593 r
= run_query(hdb
, rec
, query
);
2594 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2595 MsiCloseHandle(rec
);
2597 MsiCloseHandle(hdb
);
2598 DeleteFileA(msifile
);
2601 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
2602 static void test_handle_limit(void)
2606 MSIHANDLE hviews
[MY_NVIEWS
];
2609 /* create an empty db */
2611 ok( hdb
, "failed to create db\n");
2613 memset(hviews
, 0, sizeof(hviews
));
2615 for (i
=0; i
<MY_NVIEWS
; i
++) {
2616 static char szQueryBuf
[256] = "SELECT * from `_Tables`";
2617 hviews
[i
] = 0xdeadbeeb;
2618 r
= MsiDatabaseOpenView(hdb
, szQueryBuf
, &hviews
[i
]);
2619 if( r
!= ERROR_SUCCESS
|| hviews
[i
] == 0xdeadbeeb ||
2620 hviews
[i
] == 0 || (i
&& (hviews
[i
] == hviews
[i
-1])))
2624 ok( i
== MY_NVIEWS
, "problem opening views\n");
2626 for (i
=0; i
<MY_NVIEWS
; i
++) {
2627 if (hviews
[i
] != 0 && hviews
[i
] != 0xdeadbeeb) {
2628 MsiViewClose(hviews
[i
]);
2629 r
= MsiCloseHandle(hviews
[i
]);
2630 if (r
!= ERROR_SUCCESS
)
2635 ok( i
== MY_NVIEWS
, "problem closing views\n");
2637 r
= MsiCloseHandle(hdb
);
2638 ok( r
== ERROR_SUCCESS
, "failed to close database\n");
2641 static void generate_transform(void)
2643 MSIHANDLE hdb1
, hdb2
, hrec
;
2647 /* start with two identical databases */
2648 CopyFile(msifile2
, msifile
, FALSE
);
2650 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb1
);
2651 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2653 r
= MsiDatabaseCommit( hdb1
);
2654 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
2656 r
= MsiOpenDatabase(msifile2
, MSIDBOPEN_READONLY
, &hdb2
);
2657 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2659 /* the transform between two identical database should be empty */
2660 r
= MsiDatabaseGenerateTransform(hdb1
, hdb2
, NULL
, 0, 0);
2662 ok( r
== ERROR_NO_DATA
, "return code %d, should be ERROR_NO_DATA\n", r
);
2665 query
= "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
2666 r
= run_query(hdb1
, 0, query
);
2667 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2669 query
= "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
2670 r
= run_query(hdb1
, 0, query
);
2671 ok(r
== ERROR_SUCCESS
, "failed to add row 1\n");
2673 query
= "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
2674 r
= run_query(hdb1
, 0, query
);
2675 ok(r
== ERROR_SUCCESS
, "failed to add row 2\n");
2677 query
= "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
2678 r
= run_query(hdb1
, 0, query
);
2679 ok(r
== ERROR_SUCCESS
, "failed to modify row\n");
2681 query
= "DELETE FROM `MOO` WHERE `NOO` = 3";
2682 r
= run_query(hdb1
, 0, query
);
2683 ok(r
== ERROR_SUCCESS
, "failed to delete row\n");
2685 hrec
= MsiCreateRecord(2);
2686 r
= MsiRecordSetInteger(hrec
, 1, 1);
2687 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
2689 write_file("testdata.bin", "naengmyon", 9);
2690 r
= MsiRecordSetStream(hrec
, 2, "testdata.bin");
2691 ok(r
== ERROR_SUCCESS
, "failed to set stream\n");
2693 query
= "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2694 r
= run_query(hdb1
, hrec
, query
);
2695 ok(r
== ERROR_SUCCESS
, "failed to add row with blob\n");
2697 MsiCloseHandle(hrec
);
2699 query
= "ALTER TABLE `MOO` ADD `COW` INTEGER";
2700 r
= run_query(hdb1
, 0, query
);
2701 ok(r
== ERROR_SUCCESS
, "failed to add column\n");
2703 query
= "ALTER TABLE `MOO` ADD `PIG` INTEGER";
2704 r
= run_query(hdb1
, 0, query
);
2705 ok(r
== ERROR_SUCCESS
, "failed to add column\n");
2707 query
= "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
2708 r
= run_query(hdb1
, 0, query
);
2709 ok(r
== ERROR_SUCCESS
, "failed to modify row\n");
2711 query
= "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
2712 "`Value` CHAR(0) PRIMARY KEY `Property`)";
2713 r
= run_query(hdb1
, 0, query
);
2714 ok(r
== ERROR_SUCCESS
, "failed to add property table\n");
2716 query
= "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2717 r
= run_query(hdb1
, 0, query
);
2718 ok(r
== ERROR_SUCCESS
, "failed to add property\n");
2720 /* database needs to be committed */
2721 MsiDatabaseCommit(hdb1
);
2723 r
= MsiDatabaseGenerateTransform(hdb1
, hdb2
, mstfile
, 0, 0);
2724 ok( r
== ERROR_SUCCESS
, "return code %d, should be ERROR_SUCCESS\n", r
);
2726 MsiCloseHandle( hdb1
);
2727 MsiCloseHandle( hdb2
);
2729 DeleteFile("testdata.bin");
2732 /* data for generating a transform */
2734 /* tables transform names - encoded as they would be in an msi database file */
2735 static const WCHAR name1
[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
2736 static const WCHAR name2
[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
2737 static const WCHAR name3
[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
2738 static const WCHAR name4
[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2739 static const WCHAR name5
[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2740 static const WCHAR name6
[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
2741 static const WCHAR name7
[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
2742 static const WCHAR name8
[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
2743 static const WCHAR name9
[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2745 /* data in each table */
2746 static const WCHAR data1
[] = { /* AAR */
2747 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
2748 0x0201, 0x0009, 0x8002,
2750 static const WCHAR data2
[] = { /* _Columns */
2751 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
2752 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
2753 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
2754 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
2755 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
2756 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
2758 static const WCHAR data3
[] = { /* _Tables */
2759 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
2762 static const char data4
[] = /* _StringData */
2763 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
2764 static const WCHAR data5
[] = { /* _StringPool */
2766 0, 0, /* string 0 '' */
2767 3, 2, /* string 1 'MOO' */
2768 3, 1, /* string 2 'COW' */
2769 3, 1, /* string 3 'PIG' */
2770 1, 1, /* string 4 'c' */
2771 3, 3, /* string 5 'AAR' */
2772 3, 1, /* string 6 'CAR' */
2773 3, 1, /* string 7 'BAR' */
2774 2, 1, /* string 8 'vw' */
2775 3, 1, /* string 9 'bmw' */
2776 8, 4, /* string 10 'Property' */
2777 5, 1, /* string 11 'Value' */
2778 4, 1, /* string 12 'prop' */
2779 3, 1, /* string 13 'val' */
2781 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
2782 static const WCHAR data6
[] = { /* MOO */
2783 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
2784 0x0000, 0x8003, /* delete row */
2787 static const WCHAR data7
[] = { /* BINARY */
2788 0x0201, 0x8001, 0x0001,
2791 static const char data8
[] = /* stream data for the BINARY table */
2794 static const WCHAR data9
[] = { /* Property */
2795 0x0201, 0x000c, 0x000d,
2798 static const struct {
2802 } table_transform_data
[] =
2804 { name1
, data1
, sizeof data1
},
2805 { name2
, data2
, sizeof data2
},
2806 { name3
, data3
, sizeof data3
},
2807 { name4
, data4
, sizeof data4
- 1 },
2808 { name5
, data5
, sizeof data5
},
2809 { name6
, data6
, sizeof data6
},
2810 { name7
, data7
, sizeof data7
},
2811 { name8
, data8
, sizeof data8
- 1 },
2812 { name9
, data9
, sizeof data9
},
2815 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2817 static void generate_transform_manual(void)
2819 IStorage
*stg
= NULL
;
2824 const DWORD mode
= STGM_CREATE
|STGM_READWRITE
|STGM_DIRECT
|STGM_SHARE_EXCLUSIVE
;
2826 const CLSID CLSID_MsiTransform
= { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2828 MultiByteToWideChar(CP_ACP
, 0, mstfile
, -1, name
, 0x20);
2830 r
= StgCreateDocfile(name
, mode
, 0, &stg
);
2831 ok(r
== S_OK
, "failed to create storage\n");
2835 r
= IStorage_SetClass( stg
, &CLSID_MsiTransform
);
2836 ok(r
== S_OK
, "failed to set storage type\n");
2838 for (i
=0; i
<NUM_TRANSFORM_TABLES
; i
++)
2840 r
= IStorage_CreateStream( stg
, table_transform_data
[i
].name
,
2841 STGM_WRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
2844 ok(0, "failed to create stream %08x\n", r
);
2848 r
= IStream_Write( stm
, table_transform_data
[i
].data
,
2849 table_transform_data
[i
].size
, &count
);
2850 if (FAILED(r
) || count
!= table_transform_data
[i
].size
)
2851 ok(0, "failed to write stream\n");
2852 IStream_Release(stm
);
2855 IStorage_Release(stg
);
2858 static UINT
set_summary_info(MSIHANDLE hdb
)
2863 /* build summary info */
2864 res
= MsiGetSummaryInformation(hdb
, NULL
, 7, &suminfo
);
2865 ok( res
== ERROR_SUCCESS
, "Failed to open summaryinfo\n" );
2867 res
= MsiSummaryInfoSetProperty(suminfo
,2, VT_LPSTR
, 0,NULL
,
2868 "Installation Database");
2869 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2871 res
= MsiSummaryInfoSetProperty(suminfo
,3, VT_LPSTR
, 0,NULL
,
2872 "Installation Database");
2873 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2875 res
= MsiSummaryInfoSetProperty(suminfo
,4, VT_LPSTR
, 0,NULL
,
2877 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2879 res
= MsiSummaryInfoSetProperty(suminfo
,7, VT_LPSTR
, 0,NULL
,
2881 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2883 res
= MsiSummaryInfoSetProperty(suminfo
,9, VT_LPSTR
, 0,NULL
,
2884 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2885 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2887 res
= MsiSummaryInfoSetProperty(suminfo
, 14, VT_I4
, 100, NULL
, NULL
);
2888 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2890 res
= MsiSummaryInfoSetProperty(suminfo
, 15, VT_I4
, 0, NULL
, NULL
);
2891 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2893 res
= MsiSummaryInfoPersist(suminfo
);
2894 ok( res
== ERROR_SUCCESS
, "Failed to make summary info persist\n" );
2896 res
= MsiCloseHandle( suminfo
);
2897 ok( res
== ERROR_SUCCESS
, "Failed to close suminfo\n" );
2902 static MSIHANDLE
create_package_db(LPCSTR filename
)
2907 DeleteFile(msifile
);
2909 /* create an empty database */
2910 res
= MsiOpenDatabase(filename
, MSIDBOPEN_CREATE
, &hdb
);
2911 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
2912 if( res
!= ERROR_SUCCESS
)
2915 res
= MsiDatabaseCommit( hdb
);
2916 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
2918 res
= set_summary_info(hdb
);
2920 res
= create_directory_table(hdb
);
2921 ok( res
== ERROR_SUCCESS
, "Failed to create directory table\n" );
2926 static UINT
package_from_db(MSIHANDLE hdb
, MSIHANDLE
*handle
)
2932 sprintf(szPackage
, "#%u", hdb
);
2933 res
= MsiOpenPackage(szPackage
, &hPackage
);
2934 if (res
!= ERROR_SUCCESS
)
2937 res
= MsiCloseHandle(hdb
);
2938 if (res
!= ERROR_SUCCESS
)
2940 MsiCloseHandle(hPackage
);
2945 return ERROR_SUCCESS
;
2948 static void test_try_transform(void)
2950 MSIHANDLE hdb
, hview
, hrec
, hpkg
= 0;
2954 char buffer
[MAX_PATH
];
2956 DeleteFile(msifile
);
2957 DeleteFile(mstfile
);
2959 /* create the database */
2960 hdb
= create_package_db(msifile
);
2961 ok(hdb
, "Failed to create package db\n");
2963 query
= "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
2964 r
= run_query(hdb
, 0, query
);
2965 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2967 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
2968 r
= run_query(hdb
, 0, query
);
2969 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2971 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
2972 r
= run_query(hdb
, 0, query
);
2973 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2975 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
2976 r
= run_query(hdb
, 0, query
);
2977 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2979 query
= "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
2980 r
= run_query(hdb
, 0, query
);
2981 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2983 hrec
= MsiCreateRecord(2);
2984 r
= MsiRecordSetInteger(hrec
, 1, 2);
2985 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
2987 write_file("testdata.bin", "lamyon", 6);
2988 r
= MsiRecordSetStream(hrec
, 2, "testdata.bin");
2989 ok(r
== ERROR_SUCCESS
, "failed to set stream\n");
2991 query
= "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2992 r
= run_query(hdb
, hrec
, query
);
2993 ok(r
== ERROR_SUCCESS
, "failed to add row with blob\n");
2995 MsiCloseHandle(hrec
);
2997 r
= MsiDatabaseCommit( hdb
);
2998 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
3000 MsiCloseHandle( hdb
);
3001 DeleteFileA("testdata.bin");
3004 * Both these generate an equivalent transform,
3005 * but the first doesn't work in Wine yet
3006 * because MsiDatabaseGenerateTransform is unimplemented.
3009 generate_transform();
3011 generate_transform_manual();
3013 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_DIRECT
, &hdb
);
3014 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
3016 r
= MsiDatabaseApplyTransform( hdb
, mstfile
, 0 );
3017 ok( r
== ERROR_SUCCESS
, "return code %d, should be ERROR_SUCCESS\n", r
);
3019 MsiDatabaseCommit( hdb
);
3021 /* check new values */
3023 query
= "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
3024 r
= do_query(hdb
, query
, &hrec
);
3025 ok(r
== ERROR_SUCCESS
, "select query failed\n");
3026 MsiCloseHandle(hrec
);
3028 query
= "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
3030 r
= do_query(hdb
, query
, &hrec
);
3031 ok(r
== ERROR_SUCCESS
, "select query failed\n");
3032 MsiCloseHandle(hrec
);
3034 /* check updated values */
3036 query
= "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
3037 r
= do_query(hdb
, query
, &hrec
);
3038 ok(r
== ERROR_SUCCESS
, "select query failed\n");
3039 MsiCloseHandle(hrec
);
3041 /* check unchanged value */
3043 query
= "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
3044 r
= do_query(hdb
, query
, &hrec
);
3045 ok(r
== ERROR_SUCCESS
, "select query failed\n");
3046 MsiCloseHandle(hrec
);
3048 /* check deleted value */
3050 query
= "select * from `MOO` where `NOO` = 3";
3051 r
= do_query(hdb
, query
, &hrec
);
3052 ok(r
== ERROR_NO_MORE_ITEMS
, "select query failed\n");
3053 if (hrec
) MsiCloseHandle(hrec
);
3055 /* check added stream */
3057 query
= "select `BLOB` from `BINARY` where `ID` = 1";
3058 r
= do_query(hdb
, query
, &hrec
);
3059 ok(r
== ERROR_SUCCESS
, "select query failed\n");
3061 /* check the contents of the stream */
3063 r
= MsiRecordReadStream( hrec
, 1, buffer
, &sz
);
3064 ok(r
== ERROR_SUCCESS
, "read stream failed\n");
3065 ok(!memcmp(buffer
, "naengmyon", 9), "stream data was wrong\n");
3066 ok(sz
== 9, "stream data was wrong size\n");
3067 if (hrec
) MsiCloseHandle(hrec
);
3069 /* check the validity of the table with a deleted row */
3071 query
= "select * from `MOO`";
3072 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3073 ok(r
== ERROR_SUCCESS
, "open view failed\n");
3075 r
= MsiViewExecute(hview
, 0);
3076 ok(r
== ERROR_SUCCESS
, "view execute failed\n");
3078 r
= MsiViewFetch(hview
, &hrec
);
3079 ok(r
== ERROR_SUCCESS
, "view fetch failed\n");
3081 r
= MsiRecordGetInteger(hrec
, 1);
3082 ok(r
== 1, "Expected 1, got %d\n", r
);
3085 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
3086 ok(r
== ERROR_SUCCESS
, "record get string failed\n");
3087 ok(!lstrcmpA(buffer
, "c"), "Expected c, got %s\n", buffer
);
3089 r
= MsiRecordGetInteger(hrec
, 3);
3090 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
3092 r
= MsiRecordGetInteger(hrec
, 4);
3093 ok(r
== 5, "Expected 5, got %d\n", r
);
3095 MsiCloseHandle(hrec
);
3097 r
= MsiViewFetch(hview
, &hrec
);
3098 ok(r
== ERROR_SUCCESS
, "view fetch failed\n");
3100 r
= MsiRecordGetInteger(hrec
, 1);
3101 ok(r
== 2, "Expected 2, got %d\n", r
);
3104 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
3105 ok(r
== ERROR_SUCCESS
, "record get string failed\n");
3106 ok(!lstrcmpA(buffer
, "b"), "Expected b, got %s\n", buffer
);
3108 r
= MsiRecordGetInteger(hrec
, 3);
3109 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
3111 r
= MsiRecordGetInteger(hrec
, 4);
3112 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
3114 MsiCloseHandle(hrec
);
3116 r
= MsiViewFetch(hview
, &hrec
);
3117 ok(r
== ERROR_NO_MORE_ITEMS
, "view fetch succeeded\n");
3119 MsiCloseHandle(hrec
);
3120 MsiViewClose(hview
);
3121 MsiCloseHandle(hview
);
3123 /* check that the property was added */
3124 r
= package_from_db(hdb
, &hpkg
);
3125 if (r
== ERROR_INSTALL_PACKAGE_REJECTED
)
3127 skip("Not enough rights to perform tests\n");
3130 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %u\n", r
);
3133 r
= MsiGetProperty(hpkg
, "prop", buffer
, &sz
);
3134 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3135 ok(!lstrcmp(buffer
, "val"), "Expected val, got %s\n", buffer
);
3137 MsiCloseHandle(hpkg
);
3140 MsiCloseHandle(hdb
);
3141 DeleteFile(msifile
);
3142 DeleteFile(mstfile
);
3147 const CHAR one
[MAX_PATH
];
3148 const CHAR two
[MAX_PATH
];
3151 struct join_res_4col
3153 const CHAR one
[MAX_PATH
];
3154 const CHAR two
[MAX_PATH
];
3155 const CHAR three
[MAX_PATH
];
3156 const CHAR four
[MAX_PATH
];
3159 struct join_res_uint
3169 static const struct join_res join_res_first
[] =
3171 { "alveolar", "procerus" },
3172 { "septum", "procerus" },
3173 { "septum", "nasalis" },
3174 { "ramus", "nasalis" },
3175 { "malar", "mentalis" },
3178 static const struct join_res join_res_second
[] =
3180 { "nasal", "septum" },
3181 { "mandible", "ramus" },
3184 static const struct join_res join_res_third
[] =
3186 { "msvcp.dll", "abcdefgh" },
3187 { "msvcr.dll", "ijklmnop" },
3190 static const struct join_res join_res_fourth
[] =
3192 { "msvcp.dll.01234", "single.dll.31415" },
3195 static const struct join_res join_res_fifth
[] =
3197 { "malar", "procerus" },
3200 static const struct join_res join_res_sixth
[] =
3202 { "malar", "procerus" },
3203 { "malar", "procerus" },
3204 { "malar", "nasalis" },
3205 { "malar", "nasalis" },
3206 { "malar", "nasalis" },
3207 { "malar", "mentalis" },
3210 static const struct join_res join_res_seventh
[] =
3212 { "malar", "nasalis" },
3213 { "malar", "nasalis" },
3214 { "malar", "nasalis" },
3217 static const struct join_res_4col join_res_eighth
[] =
3219 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
3220 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
3221 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
3222 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
3223 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
3224 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
3227 static const struct join_res_uint join_res_ninth
[] =
3229 { 1, 2, 3, 4, 7, 8 },
3230 { 1, 2, 5, 6, 7, 8 },
3231 { 1, 2, 3, 4, 9, 10 },
3232 { 1, 2, 5, 6, 9, 10 },
3233 { 1, 2, 3, 4, 11, 12 },
3234 { 1, 2, 5, 6, 11, 12 },
3237 static void test_join(void)
3239 MSIHANDLE hdb
, hview
, hrec
;
3247 ok( hdb
, "failed to create db\n");
3249 r
= create_component_table( hdb
);
3250 ok( r
== ERROR_SUCCESS
, "cannot create Component table: %d\n", r
);
3252 r
= add_component_entry( hdb
, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
3253 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
3255 r
= add_component_entry( hdb
, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
3256 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
3258 r
= add_component_entry( hdb
, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
3259 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
3261 r
= add_component_entry( hdb
, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
3262 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
3264 r
= create_feature_components_table( hdb
);
3265 ok( r
== ERROR_SUCCESS
, "cannot create FeatureComponents table: %d\n", r
);
3267 r
= add_feature_components_entry( hdb
, "'procerus', 'maxilla'" );
3268 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
3270 r
= add_feature_components_entry( hdb
, "'procerus', 'nasal'" );
3271 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
3273 r
= add_feature_components_entry( hdb
, "'nasalis', 'nasal'" );
3274 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
3276 r
= add_feature_components_entry( hdb
, "'nasalis', 'mandible'" );
3277 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
3279 r
= add_feature_components_entry( hdb
, "'nasalis', 'notacomponent'" );
3280 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
3282 r
= add_feature_components_entry( hdb
, "'mentalis', 'zygomatic'" );
3283 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
3285 r
= create_std_dlls_table( hdb
);
3286 ok( r
== ERROR_SUCCESS
, "cannot create StdDlls table: %d\n", r
);
3288 r
= add_std_dlls_entry( hdb
, "'msvcp.dll', 'msvcp.dll.01234'" );
3289 ok( r
== ERROR_SUCCESS
, "cannot add std dlls: %d\n", r
);
3291 r
= add_std_dlls_entry( hdb
, "'msvcr.dll', 'msvcr.dll.56789'" );
3292 ok( r
== ERROR_SUCCESS
, "cannot add std dlls: %d\n", r
);
3294 r
= create_binary_table( hdb
);
3295 ok( r
== ERROR_SUCCESS
, "cannot create Binary table: %d\n", r
);
3297 r
= add_binary_entry( hdb
, "'msvcp.dll.01234', 'abcdefgh'" );
3298 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
3300 r
= add_binary_entry( hdb
, "'msvcr.dll.56789', 'ijklmnop'" );
3301 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
3303 r
= add_binary_entry( hdb
, "'single.dll.31415', 'msvcp.dll'" );
3304 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
3306 query
= "CREATE TABLE `One` (`A` SHORT, `B` SHORT PRIMARY KEY `A`)";
3307 r
= run_query( hdb
, 0, query
);
3308 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
3310 query
= "CREATE TABLE `Two` (`C` SHORT, `D` SHORT PRIMARY KEY `C`)";
3311 r
= run_query( hdb
, 0, query
);
3312 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
3314 query
= "CREATE TABLE `Three` (`E` SHORT, `F` SHORT PRIMARY KEY `E`)";
3315 r
= run_query( hdb
, 0, query
);
3316 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
3318 query
= "INSERT INTO `One` (`A`, `B`) VALUES (1, 2)";
3319 r
= run_query( hdb
, 0, query
);
3320 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3322 query
= "INSERT INTO `Two` (`C`, `D`) VALUES (3, 4)";
3323 r
= run_query( hdb
, 0, query
);
3324 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3326 query
= "INSERT INTO `Two` (`C`, `D`) VALUES (5, 6)";
3327 r
= run_query( hdb
, 0, query
);
3328 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3330 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (7, 8)";
3331 r
= run_query( hdb
, 0, query
);
3332 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3334 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (9, 10)";
3335 r
= run_query( hdb
, 0, query
);
3336 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3338 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (11, 12)";
3339 r
= run_query( hdb
, 0, query
);
3340 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3342 query
= "CREATE TABLE `Four` (`G` SHORT, `H` SHORT PRIMARY KEY `G`)";
3343 r
= run_query( hdb
, 0, query
);
3344 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
3346 query
= "CREATE TABLE `Five` (`I` SHORT, `J` SHORT PRIMARY KEY `I`)";
3347 r
= run_query( hdb
, 0, query
);
3348 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
3350 query
= "INSERT INTO `Five` (`I`, `J`) VALUES (13, 14)";
3351 r
= run_query( hdb
, 0, query
);
3352 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3354 query
= "INSERT INTO `Five` (`I`, `J`) VALUES (15, 16)";
3355 r
= run_query( hdb
, 0, query
);
3356 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
3358 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3359 "FROM `Component`, `FeatureComponents` "
3360 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
3361 "ORDER BY `Feature_`";
3362 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3363 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3365 r
= MsiViewExecute(hview
, 0);
3366 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3369 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3371 count
= MsiRecordGetFieldCount( hrec
);
3372 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3375 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3376 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3377 ok( !lstrcmp( buf
, join_res_first
[i
].one
),
3378 "For (row %d, column 1) expected '%s', got %s\n", i
, join_res_first
[i
].one
, buf
);
3381 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3382 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3383 ok( !lstrcmp( buf
, join_res_first
[i
].two
),
3384 "For (row %d, column 2) expected '%s', got %s\n", i
, join_res_first
[i
].two
, buf
);
3387 MsiCloseHandle(hrec
);
3390 ok( i
== 5, "Expected 5 rows, got %d\n", i
);
3391 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3393 MsiViewClose(hview
);
3394 MsiCloseHandle(hview
);
3396 /* try a join without a WHERE condition */
3397 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3398 "FROM `Component`, `FeatureComponents` ";
3399 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3400 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3402 r
= MsiViewExecute(hview
, 0);
3403 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3406 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3409 MsiCloseHandle(hrec
);
3411 ok( i
== 24, "Expected 24 rows, got %d\n", i
);
3413 MsiViewClose(hview
);
3414 MsiCloseHandle(hview
);
3416 query
= "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
3417 "WHERE FeatureComponents.Component_=Component.Component "
3418 "AND (Feature_='nasalis') ORDER BY Feature_";
3419 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3420 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3422 r
= MsiViewExecute(hview
, 0);
3423 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3426 data_correct
= TRUE
;
3427 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3429 count
= MsiRecordGetFieldCount( hrec
);
3430 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3433 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3434 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3435 if( lstrcmp( buf
, join_res_second
[i
].one
))
3436 data_correct
= FALSE
;
3439 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3440 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3441 if( lstrcmp( buf
, join_res_second
[i
].two
))
3442 data_correct
= FALSE
;
3445 MsiCloseHandle(hrec
);
3448 ok( data_correct
, "data returned in the wrong order\n");
3450 ok( i
== 2, "Expected 2 rows, got %d\n", i
);
3451 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3453 MsiViewClose(hview
);
3454 MsiCloseHandle(hview
);
3456 query
= "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3457 "FROM `StdDlls`, `Binary` "
3458 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
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
== 2, "Expected 2 record fields, got %d\n", count
);
3474 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3475 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3476 if( lstrcmp( buf
, join_res_third
[i
].one
) )
3477 data_correct
= FALSE
;
3480 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3481 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3482 if( lstrcmp( buf
, join_res_third
[i
].two
) )
3483 data_correct
= FALSE
;
3486 MsiCloseHandle(hrec
);
3488 ok( data_correct
, "data returned in the wrong order\n");
3490 ok( i
== 2, "Expected 2 rows, got %d\n", i
);
3492 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3494 MsiViewClose(hview
);
3495 MsiCloseHandle(hview
);
3497 query
= "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
3498 "FROM `StdDlls`, `Binary` "
3499 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
3501 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3502 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3504 r
= MsiViewExecute(hview
, 0);
3505 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3508 data_correct
= TRUE
;
3509 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3511 count
= MsiRecordGetFieldCount( hrec
);
3512 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3515 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3516 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3517 if( lstrcmp( buf
, join_res_fourth
[i
].one
))
3518 data_correct
= FALSE
;
3521 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3522 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3523 if( lstrcmp( buf
, join_res_fourth
[i
].two
))
3524 data_correct
= FALSE
;
3527 MsiCloseHandle(hrec
);
3529 ok( data_correct
, "data returned in the wrong order\n");
3531 ok( i
== 1, "Expected 1 rows, got %d\n", i
);
3532 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3534 MsiViewClose(hview
);
3535 MsiCloseHandle(hview
);
3537 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3538 "FROM `Component`, `FeatureComponents` "
3539 "WHERE `Component`.`Component` = 'zygomatic' "
3540 "AND `FeatureComponents`.`Component_` = 'maxilla' "
3541 "ORDER BY `Feature_`";
3542 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3543 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3545 r
= MsiViewExecute(hview
, 0);
3546 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3549 data_correct
= TRUE
;
3550 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3552 count
= MsiRecordGetFieldCount( hrec
);
3553 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3556 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3557 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3558 if( lstrcmp( buf
, join_res_fifth
[i
].one
))
3559 data_correct
= FALSE
;
3562 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3563 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3564 if( lstrcmp( buf
, join_res_fifth
[i
].two
))
3565 data_correct
= FALSE
;
3568 MsiCloseHandle(hrec
);
3570 ok( data_correct
, "data returned in the wrong order\n");
3572 ok( i
== 1, "Expected 1 rows, got %d\n", i
);
3573 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3575 MsiViewClose(hview
);
3576 MsiCloseHandle(hview
);
3578 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3579 "FROM `Component`, `FeatureComponents` "
3580 "WHERE `Component` = 'zygomatic' "
3581 "ORDER BY `Feature_`";
3582 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3583 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3585 r
= MsiViewExecute(hview
, 0);
3586 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3589 data_correct
= TRUE
;
3590 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3592 count
= MsiRecordGetFieldCount( hrec
);
3593 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3596 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3597 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3598 if( lstrcmp( buf
, join_res_sixth
[i
].one
))
3599 data_correct
= FALSE
;
3602 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3603 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3604 if( lstrcmp( buf
, join_res_sixth
[i
].two
))
3605 data_correct
= FALSE
;
3608 MsiCloseHandle(hrec
);
3610 ok( data_correct
, "data returned in the wrong order\n");
3612 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3613 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3615 MsiViewClose(hview
);
3616 MsiCloseHandle(hview
);
3618 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3619 "FROM `Component`, `FeatureComponents` "
3620 "WHERE `Component` = 'zygomatic' "
3621 "AND `Feature_` = 'nasalis' "
3622 "ORDER BY `Feature_`";
3623 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3624 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3626 r
= MsiViewExecute(hview
, 0);
3627 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3630 data_correct
= TRUE
;
3631 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3633 count
= MsiRecordGetFieldCount( hrec
);
3634 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3637 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3638 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3639 if( lstrcmp( buf
, join_res_seventh
[i
].one
))
3640 data_correct
= FALSE
;
3643 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3644 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3645 if( lstrcmp( buf
, join_res_seventh
[i
].two
))
3646 data_correct
= FALSE
;
3649 MsiCloseHandle(hrec
);
3652 ok( data_correct
, "data returned in the wrong order\n");
3653 ok( i
== 3, "Expected 3 rows, got %d\n", i
);
3654 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3656 MsiViewClose(hview
);
3657 MsiCloseHandle(hview
);
3659 query
= "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3660 "FROM `StdDlls`, `Binary` ";
3661 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3662 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3664 r
= MsiViewExecute(hview
, 0);
3665 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3668 data_correct
= TRUE
;
3669 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3671 count
= MsiRecordGetFieldCount( hrec
);
3672 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3675 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3676 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3677 if( lstrcmp( buf
, join_res_eighth
[i
].one
))
3678 data_correct
= FALSE
;
3681 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3682 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3683 if( lstrcmp( buf
, join_res_eighth
[i
].four
))
3684 data_correct
= FALSE
;
3687 MsiCloseHandle(hrec
);
3690 ok( data_correct
, "data returned in the wrong order\n");
3691 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3692 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3694 MsiViewClose(hview
);
3695 MsiCloseHandle(hview
);
3697 query
= "SELECT * FROM `StdDlls`, `Binary` ";
3698 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3699 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3701 r
= MsiViewExecute(hview
, 0);
3702 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3705 data_correct
= TRUE
;
3706 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3708 count
= MsiRecordGetFieldCount( hrec
);
3709 ok( count
== 4, "Expected 4 record fields, got %d\n", count
);
3712 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3713 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3714 if( lstrcmp( buf
, join_res_eighth
[i
].one
))
3715 data_correct
= FALSE
;
3718 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3719 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3720 if( lstrcmp( buf
, join_res_eighth
[i
].two
))
3721 data_correct
= FALSE
;
3724 r
= MsiRecordGetString( hrec
, 3, buf
, &size
);
3725 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3726 if( lstrcmp( buf
, join_res_eighth
[i
].three
))
3727 data_correct
= FALSE
;
3730 r
= MsiRecordGetString( hrec
, 4, buf
, &size
);
3731 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3732 if( lstrcmp( buf
, join_res_eighth
[i
].four
))
3733 data_correct
= FALSE
;
3736 MsiCloseHandle(hrec
);
3738 ok( data_correct
, "data returned in the wrong order\n");
3740 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3741 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3743 MsiViewClose(hview
);
3744 MsiCloseHandle(hview
);
3746 query
= "SELECT * FROM `One`, `Two`, `Three` ";
3747 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3748 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3750 r
= MsiViewExecute(hview
, 0);
3751 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3754 data_correct
= TRUE
;
3755 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3757 count
= MsiRecordGetFieldCount( hrec
);
3758 ok( count
== 6, "Expected 6 record fields, got %d\n", count
);
3760 r
= MsiRecordGetInteger( hrec
, 1 );
3761 if( r
!= join_res_ninth
[i
].one
)
3762 data_correct
= FALSE
;
3764 r
= MsiRecordGetInteger( hrec
, 2 );
3765 if( r
!= join_res_ninth
[i
].two
)
3766 data_correct
= FALSE
;
3768 r
= MsiRecordGetInteger( hrec
, 3 );
3769 if( r
!= join_res_ninth
[i
].three
)
3770 data_correct
= FALSE
;
3772 r
= MsiRecordGetInteger( hrec
, 4 );
3773 if( r
!= join_res_ninth
[i
].four
)
3774 data_correct
= FALSE
;
3776 r
= MsiRecordGetInteger( hrec
, 5 );
3777 if( r
!= join_res_ninth
[i
].five
)
3778 data_correct
= FALSE
;
3780 r
= MsiRecordGetInteger( hrec
, 6);
3781 if( r
!= join_res_ninth
[i
].six
)
3782 data_correct
= FALSE
;
3785 MsiCloseHandle(hrec
);
3787 ok( data_correct
, "data returned in the wrong order\n");
3789 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3790 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3792 MsiViewClose(hview
);
3793 MsiCloseHandle(hview
);
3795 query
= "SELECT * FROM `Four`, `Five`";
3796 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3797 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3799 r
= MsiViewExecute(hview
, 0);
3800 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3802 r
= MsiViewFetch(hview
, &hrec
);
3803 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3805 MsiViewClose(hview
);
3806 MsiCloseHandle(hview
);
3808 query
= "SELECT * FROM `Nonexistent`, `One`";
3809 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3810 ok( r
== ERROR_BAD_QUERY_SYNTAX
,
3811 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3813 /* try updating a row in a join table */
3814 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3815 "FROM `Component`, `FeatureComponents` "
3816 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
3817 "ORDER BY `Feature_`";
3818 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3819 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3821 r
= MsiViewExecute(hview
, 0);
3822 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3824 r
= MsiViewFetch(hview
, &hrec
);
3825 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
3827 r
= MsiRecordSetString( hrec
, 1, "epicranius" );
3828 ok( r
== ERROR_SUCCESS
, "failed to set string: %d\n", r
);
3830 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
3831 ok( r
== ERROR_SUCCESS
, "failed to update row: %d\n", r
);
3833 /* try another valid operation for joins */
3834 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
3835 todo_wine
ok( r
== ERROR_SUCCESS
, "failed to refresh row: %d\n", r
);
3837 /* try an invalid operation for joins */
3838 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
3839 ok( r
== ERROR_FUNCTION_FAILED
, "unexpected result: %d\n", r
);
3841 r
= MsiRecordSetString( hrec
, 2, "epicranius" );
3842 ok( r
== ERROR_SUCCESS
, "failed to set string: %d\n", r
);
3844 /* primary key cannot be updated */
3845 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
3846 todo_wine
ok( r
== ERROR_FUNCTION_FAILED
, "failed to update row: %d\n", r
);
3848 MsiCloseHandle(hrec
);
3849 MsiViewClose(hview
);
3850 MsiCloseHandle(hview
);
3852 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3853 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
3855 r
= MsiViewExecute(hview
, 0);
3856 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
3858 r
= MsiViewFetch(hview
, &hrec
);
3859 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
3862 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3863 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3864 ok( !lstrcmp( buf
, "epicranius" ), "expected 'epicranius', got %s\n", buf
);
3866 MsiCloseHandle(hrec
);
3867 MsiViewClose(hview
);
3868 MsiCloseHandle(hview
);
3870 MsiCloseHandle(hdb
);
3871 DeleteFile(msifile
);
3874 static void test_temporary_table(void)
3877 MSIHANDLE hdb
= 0, view
= 0, rec
;
3883 cond
= MsiDatabaseIsTablePersistent(0, NULL
);
3884 ok( cond
== MSICONDITION_ERROR
, "wrong return condition\n");
3887 ok( hdb
, "failed to create db\n");
3889 cond
= MsiDatabaseIsTablePersistent(hdb
, NULL
);
3890 ok( cond
== MSICONDITION_ERROR
, "wrong return condition\n");
3892 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Tables");
3893 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3895 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Columns");
3896 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3898 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Storages");
3899 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3901 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Streams");
3902 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3904 query
= "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
3905 r
= run_query(hdb
, 0, query
);
3906 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3908 cond
= MsiDatabaseIsTablePersistent(hdb
, "P");
3909 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3911 query
= "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
3912 r
= run_query(hdb
, 0, query
);
3913 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3915 cond
= MsiDatabaseIsTablePersistent(hdb
, "P2");
3916 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3918 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3919 r
= run_query(hdb
, 0, query
);
3920 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3922 cond
= MsiDatabaseIsTablePersistent(hdb
, "T");
3923 ok( cond
== MSICONDITION_FALSE
, "wrong return condition\n");
3925 query
= "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3926 r
= run_query(hdb
, 0, query
);
3927 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3929 query
= "SELECT * FROM `T2`";
3930 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3931 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
3932 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3934 cond
= MsiDatabaseIsTablePersistent(hdb
, "T2");
3935 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3937 query
= "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
3938 r
= run_query(hdb
, 0, query
);
3939 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3941 cond
= MsiDatabaseIsTablePersistent(hdb
, "T3");
3942 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3944 query
= "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3945 r
= run_query(hdb
, 0, query
);
3946 ok(r
== ERROR_FUNCTION_FAILED
, "failed to add table\n");
3948 cond
= MsiDatabaseIsTablePersistent(hdb
, "T4");
3949 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3951 query
= "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
3952 r
= run_query(hdb
, 0, query
);
3953 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to add table\n");
3955 query
= "select * from `T`";
3956 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3957 ok(r
== ERROR_SUCCESS
, "failed to query table\n");
3958 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
3959 ok(r
== ERROR_SUCCESS
, "failed to get column info\n");
3962 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
3963 ok(r
== ERROR_SUCCESS
, "failed to get string\n");
3964 ok( 0 == strcmp("G255", buf
), "wrong column type\n");
3967 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
3968 ok(r
== ERROR_SUCCESS
, "failed to get string\n");
3969 ok( 0 == strcmp("j2", buf
), "wrong column type\n");
3971 MsiCloseHandle( rec
);
3972 MsiViewClose( view
);
3973 MsiCloseHandle( view
);
3975 /* query the table data */
3977 r
= do_query(hdb
, "select * from `_Tables` where `Name` = 'T'", &rec
);
3978 ok( r
== ERROR_SUCCESS
, "temporary table exists in _Tables\n");
3979 MsiCloseHandle( rec
);
3981 /* query the column data */
3983 r
= do_query(hdb
, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec
);
3984 ok( r
== ERROR_NO_MORE_ITEMS
, "temporary table exists in _Columns\n");
3985 if (rec
) MsiCloseHandle( rec
);
3987 r
= do_query(hdb
, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec
);
3988 ok( r
== ERROR_NO_MORE_ITEMS
, "temporary table exists in _Columns\n");
3989 if (rec
) MsiCloseHandle( rec
);
3991 MsiCloseHandle( hdb
);
3993 DeleteFile(msifile
);
3996 static void test_alter(void)
4004 ok( hdb
, "failed to create db\n");
4006 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
4007 r
= run_query(hdb
, 0, query
);
4008 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
4010 cond
= MsiDatabaseIsTablePersistent(hdb
, "T");
4011 ok( cond
== MSICONDITION_FALSE
, "wrong return condition\n");
4013 query
= "ALTER TABLE `T` HOLD";
4014 r
= run_query(hdb
, 0, query
);
4015 ok(r
== ERROR_SUCCESS
, "failed to hold table %d\n", r
);
4017 query
= "ALTER TABLE `T` FREE";
4018 r
= run_query(hdb
, 0, query
);
4019 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
4021 query
= "ALTER TABLE `T` FREE";
4022 r
= run_query(hdb
, 0, query
);
4023 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
4025 query
= "ALTER TABLE `T` FREE";
4026 r
= run_query(hdb
, 0, query
);
4027 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to free table\n");
4029 query
= "ALTER TABLE `T` HOLD";
4030 r
= run_query(hdb
, 0, query
);
4031 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to hold table %d\n", r
);
4033 /* table T is removed */
4034 query
= "SELECT * FROM `T`";
4035 r
= run_query(hdb
, 0, query
);
4036 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4038 /* create the table again */
4039 query
= "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
4040 r
= run_query(hdb
, 0, query
);
4041 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4043 /* up the ref count */
4044 query
= "ALTER TABLE `U` HOLD";
4045 r
= run_query(hdb
, 0, query
);
4046 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
4048 /* add column, no data type */
4049 query
= "ALTER TABLE `U` ADD `C`";
4050 r
= run_query(hdb
, 0, query
);
4051 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4053 query
= "ALTER TABLE `U` ADD `C` INTEGER";
4054 r
= run_query(hdb
, 0, query
);
4055 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4057 /* add column C again */
4058 query
= "ALTER TABLE `U` ADD `C` INTEGER";
4059 r
= run_query(hdb
, 0, query
);
4060 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4062 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
4063 r
= run_query(hdb
, 0, query
);
4064 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4066 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
4067 r
= run_query(hdb
, 0, query
);
4068 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4070 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
4071 r
= run_query(hdb
, 0, query
);
4072 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4074 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
4075 r
= run_query(hdb
, 0, query
);
4076 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4078 query
= "SELECT * FROM `U` WHERE `D` = 8";
4079 r
= run_query(hdb
, 0, query
);
4080 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4082 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
4083 r
= run_query(hdb
, 0, query
);
4084 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4086 query
= "ALTER COLUMN `D` FREE";
4087 r
= run_query(hdb
, 0, query
);
4088 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4090 /* drop the ref count */
4091 query
= "ALTER TABLE `U` FREE";
4092 r
= run_query(hdb
, 0, query
);
4093 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4095 /* table is not empty */
4096 query
= "SELECT * FROM `U`";
4097 r
= run_query(hdb
, 0, query
);
4098 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4100 /* column D is removed */
4101 query
= "SELECT * FROM `U` WHERE `D` = 8";
4102 r
= run_query(hdb
, 0, query
);
4103 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4105 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
4106 r
= run_query(hdb
, 0, query
);
4107 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4109 /* add the column again */
4110 query
= "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
4111 r
= run_query(hdb
, 0, query
);
4112 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4114 /* up the ref count */
4115 query
= "ALTER TABLE `U` HOLD";
4116 r
= run_query(hdb
, 0, query
);
4117 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4119 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
4120 r
= run_query(hdb
, 0, query
);
4121 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4123 query
= "SELECT * FROM `U` WHERE `E` = 16";
4124 r
= run_query(hdb
, 0, query
);
4125 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4127 /* drop the ref count */
4128 query
= "ALTER TABLE `U` FREE";
4129 r
= run_query(hdb
, 0, query
);
4130 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4132 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
4133 r
= run_query(hdb
, 0, query
);
4134 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4136 query
= "SELECT * FROM `U` WHERE `E` = 20";
4137 r
= run_query(hdb
, 0, query
);
4138 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4140 /* drop the ref count */
4141 query
= "ALTER TABLE `U` FREE";
4142 r
= run_query(hdb
, 0, query
);
4143 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4145 /* table still exists */
4146 query
= "SELECT * FROM `U`";
4147 r
= run_query(hdb
, 0, query
);
4148 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4150 /* col E is removed */
4151 query
= "SELECT * FROM `U` WHERE `E` = 20";
4152 r
= run_query(hdb
, 0, query
);
4153 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4155 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
4156 r
= run_query(hdb
, 0, query
);
4157 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4159 /* drop the ref count once more */
4160 query
= "ALTER TABLE `U` FREE";
4161 r
= run_query(hdb
, 0, query
);
4162 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4164 /* table still exists */
4165 query
= "SELECT * FROM `U`";
4166 r
= run_query(hdb
, 0, query
);
4167 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4169 MsiCloseHandle( hdb
);
4170 DeleteFile(msifile
);
4173 static void test_integers(void)
4175 MSIHANDLE hdb
= 0, view
= 0, rec
= 0;
4180 /* just MsiOpenDatabase should not create a file */
4181 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4182 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4184 /* create a table */
4185 query
= "CREATE TABLE `integers` ( "
4186 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
4187 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
4188 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
4189 "PRIMARY KEY `one`)";
4190 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4191 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4192 r
= MsiViewExecute(view
, 0);
4193 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4194 r
= MsiViewClose(view
);
4195 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4196 r
= MsiCloseHandle(view
);
4197 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4199 query
= "SELECT * FROM `integers`";
4200 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4201 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4203 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
4204 count
= MsiRecordGetFieldCount(rec
);
4205 ok(count
== 8, "Expected 8, got %d\n", count
);
4206 ok(check_record(rec
, 1, "one"), "Expected one\n");
4207 ok(check_record(rec
, 2, "two"), "Expected two\n");
4208 ok(check_record(rec
, 3, "three"), "Expected three\n");
4209 ok(check_record(rec
, 4, "four"), "Expected four\n");
4210 ok(check_record(rec
, 5, "five"), "Expected five\n");
4211 ok(check_record(rec
, 6, "six"), "Expected six\n");
4212 ok(check_record(rec
, 7, "seven"), "Expected seven\n");
4213 ok(check_record(rec
, 8, "eight"), "Expected eight\n");
4214 MsiCloseHandle(rec
);
4216 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
4217 count
= MsiRecordGetFieldCount(rec
);
4218 ok(count
== 8, "Expected 8, got %d\n", count
);
4219 ok(check_record(rec
, 1, "I2"), "Expected I2\n");
4220 ok(check_record(rec
, 2, "I2"), "Expected I2\n");
4221 ok(check_record(rec
, 3, "I2"), "Expected I2\n");
4222 ok(check_record(rec
, 4, "I4"), "Expected I4\n");
4223 ok(check_record(rec
, 5, "i2"), "Expected i2\n");
4224 ok(check_record(rec
, 6, "i2"), "Expected i2\n");
4225 ok(check_record(rec
, 7, "i2"), "Expected i2\n");
4226 ok(check_record(rec
, 8, "i4"), "Expected i4\n");
4227 MsiCloseHandle(rec
);
4230 MsiCloseHandle(view
);
4232 /* insert values into it, NULL where NOT NULL is specified */
4233 query
= "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
4234 "VALUES('', '', '', '', '', '', '', '')";
4235 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4236 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4237 r
= MsiViewExecute(view
, 0);
4238 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
4241 MsiCloseHandle(view
);
4243 query
= "SELECT * FROM `integers`";
4244 r
= do_query(hdb
, query
, &rec
);
4245 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4247 r
= MsiRecordGetFieldCount(rec
);
4248 ok(r
== -1, "record count wrong: %d\n", r
);
4250 MsiCloseHandle(rec
);
4252 /* insert legitimate values into it */
4253 query
= "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
4254 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
4255 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4256 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4257 r
= MsiViewExecute(view
, 0);
4258 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4260 query
= "SELECT * FROM `integers`";
4261 r
= do_query(hdb
, query
, &rec
);
4262 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4264 r
= MsiRecordGetFieldCount(rec
);
4265 ok(r
== 8, "record count wrong: %d\n", r
);
4267 i
= MsiRecordGetInteger(rec
, 1);
4268 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
4269 i
= MsiRecordGetInteger(rec
, 3);
4270 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
4271 i
= MsiRecordGetInteger(rec
, 2);
4272 ok(i
== 2, "Expected 2, got %d\n", i
);
4273 i
= MsiRecordGetInteger(rec
, 4);
4274 ok(i
== 4, "Expected 4, got %d\n", i
);
4275 i
= MsiRecordGetInteger(rec
, 5);
4276 ok(i
== 5, "Expected 5, got %d\n", i
);
4277 i
= MsiRecordGetInteger(rec
, 6);
4278 ok(i
== 6, "Expected 6, got %d\n", i
);
4279 i
= MsiRecordGetInteger(rec
, 7);
4280 ok(i
== 7, "Expected 7, got %d\n", i
);
4281 i
= MsiRecordGetInteger(rec
, 8);
4282 ok(i
== 8, "Expected 8, got %d\n", i
);
4284 MsiCloseHandle(rec
);
4286 MsiCloseHandle(view
);
4288 r
= MsiDatabaseCommit(hdb
);
4289 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
4291 r
= MsiCloseHandle(hdb
);
4292 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4294 r
= DeleteFile(msifile
);
4295 ok(r
== TRUE
, "file didn't exist after commit\n");
4298 static void test_update(void)
4300 MSIHANDLE hdb
= 0, view
= 0, rec
= 0;
4301 CHAR result
[MAX_PATH
];
4306 /* just MsiOpenDatabase should not create a file */
4307 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4308 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4310 /* create the Control table */
4311 query
= "CREATE TABLE `Control` ( "
4312 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
4313 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
4314 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
4315 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
4316 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4317 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4318 r
= MsiViewExecute(view
, 0);
4319 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4320 r
= MsiViewClose(view
);
4321 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4322 r
= MsiCloseHandle(view
);
4323 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4326 query
= "INSERT INTO `Control` ( "
4327 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4328 "`Property`, `Text`, `Control_Next`, `Help` )"
4329 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
4330 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4331 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4332 r
= MsiViewExecute(view
, 0);
4333 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4334 r
= MsiViewClose(view
);
4335 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4336 r
= MsiCloseHandle(view
);
4337 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4339 /* add a second control */
4340 query
= "INSERT INTO `Control` ( "
4341 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4342 "`Property`, `Text`, `Control_Next`, `Help` )"
4343 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
4344 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4345 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4346 r
= MsiViewExecute(view
, 0);
4347 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4348 r
= MsiViewClose(view
);
4349 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4350 r
= MsiCloseHandle(view
);
4351 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4353 /* add a third control */
4354 query
= "INSERT INTO `Control` ( "
4355 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
4356 "`Property`, `Text`, `Control_Next`, `Help` )"
4357 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
4358 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4359 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4360 r
= MsiViewExecute(view
, 0);
4361 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4362 r
= MsiViewClose(view
);
4363 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4364 r
= MsiCloseHandle(view
);
4365 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4368 query
= "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4369 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4370 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4372 /* bad set column */
4373 query
= "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4374 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4375 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4377 /* bad where condition */
4378 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
4379 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4380 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
4382 /* just the dialog_ specified */
4383 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
4384 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4385 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4386 r
= MsiViewExecute(view
, 0);
4387 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4388 r
= MsiViewClose(view
);
4389 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4390 r
= MsiCloseHandle(view
);
4391 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4393 /* check the modified text */
4394 query
= "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
4395 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4396 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4397 r
= MsiViewExecute(view
, 0);
4398 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4400 r
= MsiViewFetch(view
, &rec
);
4401 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4404 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4405 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4406 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
4408 MsiCloseHandle(rec
);
4410 r
= MsiViewFetch(view
, &rec
);
4411 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4414 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4415 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4416 ok(!lstrlen(result
), "Expected an empty string, got %s\n", result
);
4418 MsiCloseHandle(rec
);
4420 r
= MsiViewFetch(view
, &rec
);
4421 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4423 r
= MsiViewClose(view
);
4424 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4425 r
= MsiCloseHandle(view
);
4426 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4428 /* dialog_ and control specified */
4429 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
4430 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4431 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4432 r
= MsiViewExecute(view
, 0);
4433 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4434 r
= MsiViewClose(view
);
4435 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4436 r
= MsiCloseHandle(view
);
4437 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4439 /* check the modified text */
4440 query
= "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
4441 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4442 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4443 r
= MsiViewExecute(view
, 0);
4444 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4446 r
= MsiViewFetch(view
, &rec
);
4447 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4450 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4451 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4452 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
4454 MsiCloseHandle(rec
);
4456 r
= MsiViewFetch(view
, &rec
);
4457 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4460 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4461 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4462 ok(!lstrlen(result
), "Expected an empty string, got %s\n", result
);
4464 MsiCloseHandle(rec
);
4466 r
= MsiViewFetch(view
, &rec
);
4467 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4469 r
= MsiViewClose(view
);
4470 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4471 r
= MsiCloseHandle(view
);
4472 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4474 /* no where condition */
4475 query
= "UPDATE `Control` SET `Text` = 'this is text'";
4476 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4477 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4478 r
= MsiViewExecute(view
, 0);
4479 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4480 r
= MsiViewClose(view
);
4481 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4482 r
= MsiCloseHandle(view
);
4483 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4485 /* check the modified text */
4486 query
= "SELECT `Text` FROM `Control`";
4487 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4488 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4489 r
= MsiViewExecute(view
, 0);
4490 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4492 r
= MsiViewFetch(view
, &rec
);
4493 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4496 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4497 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4498 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
4500 MsiCloseHandle(rec
);
4502 r
= MsiViewFetch(view
, &rec
);
4503 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4506 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4507 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4508 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
4510 MsiCloseHandle(rec
);
4512 r
= MsiViewFetch(view
, &rec
);
4513 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4516 r
= MsiRecordGetString(rec
, 1, result
, &size
);
4517 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4518 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
4520 MsiCloseHandle(rec
);
4522 r
= MsiViewFetch(view
, &rec
);
4523 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4525 r
= MsiViewClose(view
);
4526 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4527 r
= MsiCloseHandle(view
);
4528 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4530 query
= "CREATE TABLE `Apple` ( `Banana` CHAR(72) NOT NULL, "
4531 "`Orange` CHAR(72), `Pear` INT PRIMARY KEY `Banana`)";
4532 r
= run_query(hdb
, 0, query
);
4533 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4535 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4536 "VALUES('one', 'two', 3)";
4537 r
= run_query(hdb
, 0, query
);
4538 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4540 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4541 "VALUES('three', 'four', 5)";
4542 r
= run_query(hdb
, 0, query
);
4543 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4545 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
4546 "VALUES('six', 'two', 7)";
4547 r
= run_query(hdb
, 0, query
);
4548 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4550 rec
= MsiCreateRecord(2);
4551 MsiRecordSetInteger(rec
, 1, 8);
4552 MsiRecordSetString(rec
, 2, "two");
4554 query
= "UPDATE `Apple` SET `Pear` = ? WHERE `Orange` = ?";
4555 r
= run_query(hdb
, rec
, query
);
4556 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4558 MsiCloseHandle(rec
);
4560 query
= "SELECT `Pear` FROM `Apple` ORDER BY `Orange`";
4561 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4562 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4563 r
= MsiViewExecute(view
, 0);
4564 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4566 r
= MsiViewFetch(view
, &rec
);
4567 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4569 r
= MsiRecordGetInteger(rec
, 1);
4570 ok(r
== 8, "Expected 8, got %d\n", r
);
4572 MsiCloseHandle(rec
);
4574 r
= MsiViewFetch(view
, &rec
);
4575 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4577 r
= MsiRecordGetInteger(rec
, 1);
4578 ok(r
== 8, "Expected 8, got %d\n", r
);
4580 MsiCloseHandle(rec
);
4582 r
= MsiViewFetch(view
, &rec
);
4583 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4585 r
= MsiRecordGetInteger(rec
, 1);
4586 ok(r
== 5, "Expected 5, got %d\n", r
);
4588 MsiCloseHandle(rec
);
4590 r
= MsiViewFetch(view
, &rec
);
4591 ok(r
== ERROR_NO_MORE_ITEMS
, "Expectd ERROR_NO_MORE_ITEMS, got %d\n", r
);
4594 MsiCloseHandle(view
);
4596 r
= MsiDatabaseCommit(hdb
);
4597 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
4598 r
= MsiCloseHandle(hdb
);
4599 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4601 DeleteFile(msifile
);
4604 static void test_special_tables(void)
4610 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4611 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4613 query
= "CREATE TABLE `_Properties` ( "
4614 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4615 r
= run_query(hdb
, 0, query
);
4616 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
4618 query
= "CREATE TABLE `_Storages` ( "
4619 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4620 r
= run_query(hdb
, 0, query
);
4621 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Streams table\n");
4623 query
= "CREATE TABLE `_Streams` ( "
4624 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4625 r
= run_query(hdb
, 0, query
);
4626 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Streams table\n");
4628 query
= "CREATE TABLE `_Tables` ( "
4629 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4630 r
= run_query(hdb
, 0, query
);
4631 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Tables table\n");
4633 query
= "CREATE TABLE `_Columns` ( "
4634 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4635 r
= run_query(hdb
, 0, query
);
4636 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Columns table\n");
4638 r
= MsiCloseHandle(hdb
);
4639 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4642 static void test_tables_order(void)
4645 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4650 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4651 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4653 query
= "CREATE TABLE `foo` ( "
4654 "`baz` INT NOT NULL PRIMARY KEY `baz`)";
4655 r
= run_query(hdb
, 0, query
);
4656 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
4658 query
= "CREATE TABLE `bar` ( "
4659 "`foo` INT NOT NULL PRIMARY KEY `foo`)";
4660 r
= run_query(hdb
, 0, query
);
4661 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
4663 query
= "CREATE TABLE `baz` ( "
4664 "`bar` INT NOT NULL, "
4665 "`baz` INT NOT NULL, "
4666 "`foo` INT NOT NULL PRIMARY KEY `bar`)";
4667 r
= run_query(hdb
, 0, query
);
4668 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
4670 /* The names of the tables in the _Tables table must
4671 be in the same order as these names are created in
4672 the strings table. */
4673 query
= "SELECT * FROM `_Tables`";
4674 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4675 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4676 r
= MsiViewExecute(hview
, 0);
4677 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4679 r
= MsiViewFetch(hview
, &hrec
);
4680 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4681 sz
= sizeof(buffer
);
4682 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4683 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4684 ok(!lstrcmp(buffer
, "foo"), "Expected foo, got %s\n", buffer
);
4685 r
= MsiCloseHandle(hrec
);
4686 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4688 r
= MsiViewFetch(hview
, &hrec
);
4689 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4690 sz
= sizeof(buffer
);
4691 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4692 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4693 ok(!lstrcmp(buffer
, "baz"), "Expected baz, got %s\n", buffer
);
4694 r
= MsiCloseHandle(hrec
);
4695 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4697 r
= MsiViewFetch(hview
, &hrec
);
4698 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4699 sz
= sizeof(buffer
);
4700 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4701 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4702 ok(!lstrcmp(buffer
, "bar"), "Expected bar, got %s\n", buffer
);
4703 r
= MsiCloseHandle(hrec
);
4704 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4706 r
= MsiViewClose(hview
);
4707 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4708 r
= MsiCloseHandle(hview
);
4709 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4711 /* The names of the tables in the _Columns table must
4712 be in the same order as these names are created in
4713 the strings table. */
4714 query
= "SELECT * FROM `_Columns`";
4715 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4716 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4717 r
= MsiViewExecute(hview
, 0);
4718 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4720 r
= MsiViewFetch(hview
, &hrec
);
4721 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4722 sz
= sizeof(buffer
);
4723 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4724 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4725 ok(!lstrcmp(buffer
, "foo"), "Expected foo, got %s\n", buffer
);
4726 sz
= sizeof(buffer
);
4727 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4728 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4729 ok(!lstrcmp(buffer
, "baz"), "Expected baz, got %s\n", buffer
);
4730 r
= MsiCloseHandle(hrec
);
4731 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4733 r
= MsiViewFetch(hview
, &hrec
);
4734 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4735 sz
= sizeof(buffer
);
4736 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4737 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4738 ok(!lstrcmp(buffer
, "baz"), "Expected baz, got %s\n", buffer
);
4739 sz
= sizeof(buffer
);
4740 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4741 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4742 ok(!lstrcmp(buffer
, "bar"), "Expected bar, got %s\n", buffer
);
4743 r
= MsiCloseHandle(hrec
);
4744 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4746 r
= MsiViewFetch(hview
, &hrec
);
4747 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4748 sz
= sizeof(buffer
);
4749 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4750 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4751 ok(!lstrcmp(buffer
, "baz"), "Expected baz, got %s\n", buffer
);
4752 sz
= sizeof(buffer
);
4753 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4754 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4755 ok(!lstrcmp(buffer
, "baz"), "Expected baz, got %s\n", buffer
);
4756 r
= MsiCloseHandle(hrec
);
4757 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4759 r
= MsiViewFetch(hview
, &hrec
);
4760 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4761 sz
= sizeof(buffer
);
4762 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4763 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4764 ok(!lstrcmp(buffer
, "baz"), "Expected baz, got %s\n", buffer
);
4765 sz
= sizeof(buffer
);
4766 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4767 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4768 ok(!lstrcmp(buffer
, "foo"), "Expected foo, got %s\n", buffer
);
4769 r
= MsiCloseHandle(hrec
);
4770 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4772 r
= MsiViewFetch(hview
, &hrec
);
4773 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4774 sz
= sizeof(buffer
);
4775 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4776 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4777 ok(!lstrcmp(buffer
, "bar"), "Expected bar, got %s\n", buffer
);
4778 sz
= sizeof(buffer
);
4779 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4780 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4781 ok(!lstrcmp(buffer
, "foo"), "Expected foo, got %s\n", buffer
);
4782 r
= MsiCloseHandle(hrec
);
4783 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4785 r
= MsiViewClose(hview
);
4786 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4787 r
= MsiCloseHandle(hview
);
4788 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4790 r
= MsiCloseHandle(hdb
);
4791 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4793 DeleteFile(msifile
);
4796 static void test_rows_order(void)
4799 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4804 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4805 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4807 query
= "CREATE TABLE `foo` ( "
4808 "`bar` LONGCHAR NOT NULL PRIMARY KEY `bar`)";
4809 r
= run_query(hdb
, 0, query
);
4810 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
4812 r
= run_query(hdb
, 0, "INSERT INTO `foo` "
4813 "( `bar` ) VALUES ( 'A' )");
4814 ok(r
== ERROR_SUCCESS
, "cannot add value to table\n");
4816 r
= run_query(hdb
, 0, "INSERT INTO `foo` "
4817 "( `bar` ) VALUES ( 'B' )");
4818 ok(r
== ERROR_SUCCESS
, "cannot add value to table\n");
4820 r
= run_query(hdb
, 0, "INSERT INTO `foo` "
4821 "( `bar` ) VALUES ( 'C' )");
4822 ok(r
== ERROR_SUCCESS
, "cannot add value to table\n");
4824 r
= run_query(hdb
, 0, "INSERT INTO `foo` "
4825 "( `bar` ) VALUES ( 'D' )");
4826 ok(r
== ERROR_SUCCESS
, "cannot add value to table\n");
4828 r
= run_query(hdb
, 0, "INSERT INTO `foo` "
4829 "( `bar` ) VALUES ( 'E' )");
4830 ok(r
== ERROR_SUCCESS
, "cannot add value to table\n");
4832 r
= run_query(hdb
, 0, "INSERT INTO `foo` "
4833 "( `bar` ) VALUES ( 'F' )");
4834 ok(r
== ERROR_SUCCESS
, "cannot add value to table\n");
4836 query
= "CREATE TABLE `bar` ( "
4837 "`foo` LONGCHAR NOT NULL, "
4838 "`baz` LONGCHAR NOT NULL "
4839 "PRIMARY KEY `foo` )";
4840 r
= run_query(hdb
, 0, query
);
4841 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
4843 r
= run_query(hdb
, 0, "INSERT INTO `bar` "
4844 "( `foo`, `baz` ) VALUES ( 'C', 'E' )");
4845 ok(r
== ERROR_SUCCESS
, "cannot add value to table\n");
4847 r
= run_query(hdb
, 0, "INSERT INTO `bar` "
4848 "( `foo`, `baz` ) VALUES ( 'F', 'A' )");
4849 ok(r
== ERROR_SUCCESS
, "cannot add value to table\n");
4851 r
= run_query(hdb
, 0, "INSERT INTO `bar` "
4852 "( `foo`, `baz` ) VALUES ( 'A', 'B' )");
4853 ok(r
== ERROR_SUCCESS
, "cannot add value to table\n");
4855 r
= run_query(hdb
, 0, "INSERT INTO `bar` "
4856 "( `foo`, `baz` ) VALUES ( 'D', 'E' )");
4857 ok(r
== ERROR_SUCCESS
, "cannot add value to table\n");
4859 /* The rows of the table must be ordered by the column values of
4860 each row. For strings, the column value is the string id
4861 in the string table. */
4863 query
= "SELECT * FROM `bar`";
4864 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4865 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4866 r
= MsiViewExecute(hview
, 0);
4867 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4869 r
= MsiViewFetch(hview
, &hrec
);
4870 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4871 sz
= sizeof(buffer
);
4872 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4873 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4874 ok(!lstrcmp(buffer
, "A"), "Expected A, got %s\n", buffer
);
4875 sz
= sizeof(buffer
);
4876 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4877 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4878 ok(!lstrcmp(buffer
, "B"), "Expected B, got %s\n", buffer
);
4879 r
= MsiCloseHandle(hrec
);
4880 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4882 r
= MsiViewFetch(hview
, &hrec
);
4883 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4884 sz
= sizeof(buffer
);
4885 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4886 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4887 ok(!lstrcmp(buffer
, "C"), "Expected E, got %s\n", buffer
);
4888 sz
= sizeof(buffer
);
4889 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4890 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4891 ok(!lstrcmp(buffer
, "E"), "Expected E, got %s\n", buffer
);
4892 r
= MsiCloseHandle(hrec
);
4893 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4895 r
= MsiViewFetch(hview
, &hrec
);
4896 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4897 sz
= sizeof(buffer
);
4898 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4899 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4900 ok(!lstrcmp(buffer
, "D"), "Expected D, got %s\n", buffer
);
4901 sz
= sizeof(buffer
);
4902 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4903 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4904 ok(!lstrcmp(buffer
, "E"), "Expected E, got %s\n", buffer
);
4905 r
= MsiCloseHandle(hrec
);
4906 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4908 r
= MsiViewFetch(hview
, &hrec
);
4909 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4910 sz
= sizeof(buffer
);
4911 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
4912 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4913 ok(!lstrcmp(buffer
, "F"), "Expected F, got %s\n", buffer
);
4914 sz
= sizeof(buffer
);
4915 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4916 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4917 ok(!lstrcmp(buffer
, "A"), "Expected A, got %s\n", buffer
);
4918 r
= MsiCloseHandle(hrec
);
4919 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4921 r
= MsiViewClose(hview
);
4922 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4923 r
= MsiCloseHandle(hview
);
4924 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4926 r
= MsiCloseHandle(hdb
);
4927 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4929 DeleteFile(msifile
);
4932 static void test_select_markers(void)
4934 MSIHANDLE hdb
= 0, rec
, view
, res
;
4941 ok( hdb
, "failed to create db\n");
4943 r
= run_query(hdb
, 0,
4944 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
4945 ok(r
== S_OK
, "cannot create table: %d\n", r
);
4947 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4948 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
4949 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4951 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4952 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
4953 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4955 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4956 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
4957 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4959 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4960 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
4961 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4963 rec
= MsiCreateRecord(2);
4964 MsiRecordSetString(rec
, 1, "apple");
4965 MsiRecordSetString(rec
, 2, "two");
4967 query
= "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
4968 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4969 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4971 r
= MsiViewExecute(view
, rec
);
4972 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4974 r
= MsiViewFetch(view
, &res
);
4975 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4978 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4979 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4980 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4983 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4984 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4985 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4987 r
= MsiRecordGetInteger(res
, 3);
4988 ok(r
== 1, "Expected 1, got %d\n", r
);
4990 MsiCloseHandle(res
);
4992 r
= MsiViewFetch(view
, &res
);
4993 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4996 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4997 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4998 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
5001 r
= MsiRecordGetString(res
, 2, buf
, &size
);
5002 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5003 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
5005 r
= MsiRecordGetInteger(res
, 3);
5006 ok(r
== 2, "Expected 2, got %d\n", r
);
5008 MsiCloseHandle(res
);
5010 r
= MsiViewFetch(view
, &res
);
5011 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5013 MsiCloseHandle(rec
);
5015 MsiCloseHandle(view
);
5017 rec
= MsiCreateRecord(2);
5018 MsiRecordSetString(rec
, 1, "one");
5019 MsiRecordSetInteger(rec
, 2, 1);
5021 query
= "SELECT * FROM `Table` WHERE `Two`<>? AND `Three`>? ORDER BY `Three`";
5022 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
5023 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5024 r
= MsiViewExecute(view
, rec
);
5025 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5027 r
= MsiViewFetch(view
, &res
);
5028 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5031 r
= MsiRecordGetString(res
, 1, buf
, &size
);
5032 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5033 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
5036 r
= MsiRecordGetString(res
, 2, buf
, &size
);
5037 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5038 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
5040 r
= MsiRecordGetInteger(res
, 3);
5041 ok(r
== 2, "Expected 2, got %d\n", r
);
5043 MsiCloseHandle(res
);
5045 r
= MsiViewFetch(view
, &res
);
5046 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5049 r
= MsiRecordGetString(res
, 1, buf
, &size
);
5050 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5051 ok(!lstrcmp(buf
, "banana"), "Expected banana, got %s\n", buf
);
5054 r
= MsiRecordGetString(res
, 2, buf
, &size
);
5055 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5056 ok(!lstrcmp(buf
, "three"), "Expected three, got %s\n", buf
);
5058 r
= MsiRecordGetInteger(res
, 3);
5059 ok(r
== 3, "Expected 3, got %d\n", r
);
5061 MsiCloseHandle(res
);
5063 r
= MsiViewFetch(view
, &res
);
5064 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5066 MsiCloseHandle(rec
);
5068 MsiCloseHandle(view
);
5069 MsiCloseHandle(hdb
);
5070 DeleteFile(msifile
);
5073 static void test_viewmodify_update(void)
5075 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
5079 DeleteFile(msifile
);
5081 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5082 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
5084 query
= "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
5085 r
= run_query( hdb
, 0, query
);
5086 ok(r
== ERROR_SUCCESS
, "query failed\n");
5088 query
= "INSERT INTO `table` (`A`, `B`) VALUES (1, 2)";
5089 r
= run_query( hdb
, 0, query
);
5090 ok(r
== ERROR_SUCCESS
, "query failed\n");
5092 query
= "INSERT INTO `table` (`A`, `B`) VALUES (3, 4)";
5093 r
= run_query( hdb
, 0, query
);
5094 ok(r
== ERROR_SUCCESS
, "query failed\n");
5096 query
= "INSERT INTO `table` (`A`, `B`) VALUES (5, 6)";
5097 r
= run_query( hdb
, 0, query
);
5098 ok(r
== ERROR_SUCCESS
, "query failed\n");
5100 query
= "SELECT `B` FROM `table`";
5101 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5102 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
5103 r
= MsiViewExecute(hview
, 0);
5104 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
5105 r
= MsiViewFetch(hview
, &hrec
);
5106 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
5108 r
= MsiRecordSetInteger(hrec
, 1, 0);
5109 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
5111 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
5112 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
5114 r
= MsiCloseHandle(hrec
);
5115 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
5117 r
= MsiViewClose(hview
);
5118 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
5119 r
= MsiCloseHandle(hview
);
5120 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
5122 query
= "SELECT * FROM `table`";
5123 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5124 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
5125 r
= MsiViewExecute(hview
, 0);
5126 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
5127 r
= MsiViewFetch(hview
, &hrec
);
5128 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
5130 r
= MsiRecordGetInteger(hrec
, 1);
5131 ok(r
== 1, "Expected 1, got %d\n", r
);
5132 r
= MsiRecordGetInteger(hrec
, 2);
5133 ok(r
== 0, "Expected 0, got %d\n", r
);
5135 r
= MsiCloseHandle(hrec
);
5136 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
5138 r
= MsiViewFetch(hview
, &hrec
);
5139 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
5141 r
= MsiRecordGetInteger(hrec
, 1);
5142 ok(r
== 3, "Expected 3, got %d\n", r
);
5143 r
= MsiRecordGetInteger(hrec
, 2);
5144 ok(r
== 4, "Expected 4, got %d\n", r
);
5146 r
= MsiCloseHandle(hrec
);
5147 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
5149 r
= MsiViewFetch(hview
, &hrec
);
5150 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
5152 r
= MsiRecordGetInteger(hrec
, 1);
5153 ok(r
== 5, "Expected 5, got %d\n", r
);
5154 r
= MsiRecordGetInteger(hrec
, 2);
5155 ok(r
== 6, "Expected 6, got %d\n", r
);
5157 r
= MsiCloseHandle(hrec
);
5158 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
5160 r
= MsiViewFetch(hview
, &hrec
);
5161 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5163 r
= MsiViewClose(hview
);
5164 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
5165 r
= MsiCloseHandle(hview
);
5166 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
5168 /* loop through all elements */
5169 query
= "SELECT `B` FROM `table`";
5170 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5171 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
5172 r
= MsiViewExecute(hview
, 0);
5173 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
5177 r
= MsiViewFetch(hview
, &hrec
);
5178 if (r
!= ERROR_SUCCESS
)
5181 r
= MsiRecordSetInteger(hrec
, 1, 0);
5182 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
5184 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
5185 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
5187 r
= MsiCloseHandle(hrec
);
5188 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
5191 r
= MsiViewClose(hview
);
5192 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
5193 r
= MsiCloseHandle(hview
);
5194 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
5196 query
= "SELECT * FROM `table`";
5197 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5198 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
5199 r
= MsiViewExecute(hview
, 0);
5200 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
5201 r
= MsiViewFetch(hview
, &hrec
);
5202 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
5204 r
= MsiRecordGetInteger(hrec
, 1);
5205 ok(r
== 1, "Expected 1, got %d\n", r
);
5206 r
= MsiRecordGetInteger(hrec
, 2);
5207 ok(r
== 0, "Expected 0, got %d\n", r
);
5209 r
= MsiCloseHandle(hrec
);
5210 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
5212 r
= MsiViewFetch(hview
, &hrec
);
5213 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
5215 r
= MsiRecordGetInteger(hrec
, 1);
5216 ok(r
== 3, "Expected 3, got %d\n", r
);
5217 r
= MsiRecordGetInteger(hrec
, 2);
5218 ok(r
== 0, "Expected 0, got %d\n", r
);
5220 r
= MsiCloseHandle(hrec
);
5221 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
5223 r
= MsiViewFetch(hview
, &hrec
);
5224 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
5226 r
= MsiRecordGetInteger(hrec
, 1);
5227 ok(r
== 5, "Expected 5, got %d\n", r
);
5228 r
= MsiRecordGetInteger(hrec
, 2);
5229 ok(r
== 0, "Expected 0, got %d\n", r
);
5231 r
= MsiCloseHandle(hrec
);
5232 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
5234 r
= MsiViewFetch(hview
, &hrec
);
5235 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5237 r
= MsiViewClose(hview
);
5238 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
5239 r
= MsiCloseHandle(hview
);
5240 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
5242 r
= MsiCloseHandle( hdb
);
5243 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
5246 static void test_viewmodify_assign(void)
5248 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
5252 /* setup database */
5253 DeleteFile(msifile
);
5255 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5256 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
5258 query
= "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
5259 r
= run_query( hdb
, 0, query
);
5260 ok(r
== ERROR_SUCCESS
, "query failed\n");
5262 /* assign to view, new primary key */
5263 query
= "SELECT * FROM `table`";
5264 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5265 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
5266 r
= MsiViewExecute(hview
, 0);
5267 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
5269 hrec
= MsiCreateRecord(2);
5270 ok(hrec
!= 0, "MsiCreateRecord failed\n");
5272 r
= MsiRecordSetInteger(hrec
, 1, 1);
5273 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
5274 r
= MsiRecordSetInteger(hrec
, 2, 2);
5275 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
5277 r
= MsiViewModify(hview
, MSIMODIFY_ASSIGN
, hrec
);
5278 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
5280 r
= MsiCloseHandle(hrec
);
5281 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
5283 r
= MsiViewClose(hview
);
5284 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
5285 r
= MsiCloseHandle(hview
);
5286 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
5288 query
= "SELECT * FROM `table`";
5289 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5290 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
5291 r
= MsiViewExecute(hview
, 0);
5292 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
5293 r
= MsiViewFetch(hview
, &hrec
);
5294 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
5296 r
= MsiRecordGetInteger(hrec
, 1);
5297 ok(r
== 1, "Expected 1, got %d\n", r
);
5298 r
= MsiRecordGetInteger(hrec
, 2);
5299 ok(r
== 2, "Expected 2, got %d\n", r
);
5301 r
= MsiCloseHandle(hrec
);
5302 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
5304 r
= MsiViewFetch(hview
, &hrec
);
5305 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5307 r
= MsiViewClose(hview
);
5308 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
5309 r
= MsiCloseHandle(hview
);
5310 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
5312 /* assign to view, primary key matches */
5313 query
= "SELECT * FROM `table`";
5314 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5315 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
5316 r
= MsiViewExecute(hview
, 0);
5317 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
5319 hrec
= MsiCreateRecord(2);
5320 ok(hrec
!= 0, "MsiCreateRecord failed\n");
5322 r
= MsiRecordSetInteger(hrec
, 1, 1);
5323 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
5324 r
= MsiRecordSetInteger(hrec
, 2, 4);
5325 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
5327 r
= MsiViewModify(hview
, MSIMODIFY_ASSIGN
, hrec
);
5328 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
5330 r
= MsiCloseHandle(hrec
);
5331 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
5333 r
= MsiViewClose(hview
);
5334 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
5335 r
= MsiCloseHandle(hview
);
5336 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
5338 query
= "SELECT * FROM `table`";
5339 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5340 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
5341 r
= MsiViewExecute(hview
, 0);
5342 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
5343 r
= MsiViewFetch(hview
, &hrec
);
5344 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
5346 r
= MsiRecordGetInteger(hrec
, 1);
5347 ok(r
== 1, "Expected 1, got %d\n", r
);
5348 r
= MsiRecordGetInteger(hrec
, 2);
5349 ok(r
== 4, "Expected 4, got %d\n", r
);
5351 r
= MsiCloseHandle(hrec
);
5352 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
5354 r
= MsiViewFetch(hview
, &hrec
);
5355 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5357 r
= MsiViewClose(hview
);
5358 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
5359 r
= MsiCloseHandle(hview
);
5360 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
5362 /* close database */
5363 r
= MsiCloseHandle( hdb
);
5364 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
5367 static const WCHAR data10
[] = { /* MOO */
5370 static const WCHAR data11
[] = { /* AAR */
5374 static const char data12
[] = /* _StringData */
5375 "MOOABAARCDonetwofourfive";
5376 static const WCHAR data13
[] = { /* _StringPool */
5378 0, 0, /* string 0 '' */
5379 0, 0, /* string 1 '' */
5380 0, 0, /* string 2 '' */
5381 0, 0, /* string 3 '' */
5382 0, 0, /* string 4 '' */
5383 3, 3, /* string 5 'MOO' */
5384 1, 1, /* string 6 'A' */
5385 1, 1, /* string 7 'B' */
5386 3, 3, /* string 8 'AAR' */
5387 1, 1, /* string 9 'C' */
5388 1, 1, /* string a 'D' */
5389 3, 1, /* string b 'one' */
5390 3, 1, /* string c 'two' */
5391 0, 0, /* string d '' */
5392 4, 1, /* string e 'four' */
5393 4, 1, /* string f 'five' */
5396 static void test_stringtable(void)
5398 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
5399 IStorage
*stg
= NULL
;
5404 char buffer
[MAX_PATH
];
5405 WCHAR data
[MAX_PATH
];
5409 static const DWORD mode
= STGM_DIRECT
| STGM_READ
| STGM_SHARE_DENY_WRITE
;
5410 static const WCHAR stringdata
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0}; /* _StringData */
5411 static const WCHAR stringpool
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0}; /* _StringPool */
5412 static const WCHAR moo
[] = {0x4840, 0x3e16, 0x4818, 0}; /* MOO */
5413 static const WCHAR aar
[] = {0x4840, 0x3a8a, 0x481b, 0}; /* AAR */
5415 DeleteFile(msifile
);
5417 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5418 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5420 query
= "CREATE TABLE `MOO` (`A` INT, `B` CHAR(72) PRIMARY KEY `A`)";
5421 r
= run_query(hdb
, 0, query
);
5422 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5424 query
= "CREATE TABLE `AAR` (`C` INT, `D` CHAR(72) PRIMARY KEY `C`)";
5425 r
= run_query(hdb
, 0, query
);
5426 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5428 /* insert persistent row */
5429 query
= "INSERT INTO `MOO` (`A`, `B`) VALUES (1, 'one')";
5430 r
= run_query(hdb
, 0, query
);
5431 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5433 /* insert persistent row */
5434 query
= "INSERT INTO `AAR` (`C`, `D`) VALUES (2, 'two')";
5435 r
= run_query(hdb
, 0, query
);
5436 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5439 query
= "SELECT * FROM `MOO`";
5440 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5441 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5442 r
= MsiViewExecute(hview
, 0);
5443 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5445 hrec
= MsiCreateRecord(2);
5447 r
= MsiRecordSetInteger(hrec
, 1, 3);
5448 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5449 r
= MsiRecordSetString(hrec
, 2, "three");
5450 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5452 /* insert a nonpersistent row */
5453 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
5454 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5456 r
= MsiCloseHandle(hrec
);
5457 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5458 r
= MsiViewClose(hview
);
5459 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5460 r
= MsiCloseHandle(hview
);
5461 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5463 /* insert persistent row */
5464 query
= "INSERT INTO `MOO` (`A`, `B`) VALUES (4, 'four')";
5465 r
= run_query(hdb
, 0, query
);
5466 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5468 /* insert persistent row */
5469 query
= "INSERT INTO `AAR` (`C`, `D`) VALUES (5, 'five')";
5470 r
= run_query(hdb
, 0, query
);
5471 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5473 r
= MsiDatabaseCommit(hdb
);
5474 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5476 r
= MsiCloseHandle(hdb
);
5477 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5479 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
5480 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5482 query
= "SELECT * FROM `MOO`";
5483 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5484 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5486 r
= MsiViewExecute(hview
, 0);
5487 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5489 r
= MsiViewFetch(hview
, &hrec
);
5490 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5492 r
= MsiRecordGetFieldCount(hrec
);
5493 ok(r
== 2, "Expected 2, got %d\n", r
);
5495 r
= MsiRecordGetInteger(hrec
, 1);
5496 ok(r
== 1, "Expected 1, got %d\n", r
);
5498 sz
= sizeof(buffer
);
5499 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
5500 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5501 ok(!lstrcmp(buffer
, "one"), "Expected one, got %s\n", buffer
);
5503 r
= MsiCloseHandle(hrec
);
5504 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5506 r
= MsiViewFetch(hview
, &hrec
);
5509 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5512 r
= MsiViewClose(hview
);
5513 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5514 r
= MsiCloseHandle(hview
);
5515 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5516 r
= MsiCloseHandle(hrec
);
5517 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5519 query
= "SELECT * FROM `AAR`";
5520 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5521 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5523 r
= MsiViewExecute(hview
, 0);
5524 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5526 r
= MsiViewFetch(hview
, &hrec
);
5527 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5529 r
= MsiRecordGetFieldCount(hrec
);
5530 ok(r
== 2, "Expected 2, got %d\n", r
);
5532 r
= MsiRecordGetInteger(hrec
, 1);
5533 ok(r
== 2, "Expected 2, got %d\n", r
);
5535 sz
= sizeof(buffer
);
5536 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
5537 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5538 ok(!lstrcmp(buffer
, "two"), "Expected two, got %s\n", buffer
);
5540 r
= MsiCloseHandle(hrec
);
5541 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5543 r
= MsiViewFetch(hview
, &hrec
);
5544 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5546 r
= MsiRecordGetFieldCount(hrec
);
5547 ok(r
== 2, "Expected 2, got %d\n", r
);
5549 r
= MsiRecordGetInteger(hrec
, 1);
5550 ok(r
== 5, "Expected 5, got %d\n", r
);
5552 sz
= sizeof(buffer
);
5553 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
5554 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5555 ok(!lstrcmp(buffer
, "five"), "Expected five, got %s\n", buffer
);
5557 r
= MsiCloseHandle(hrec
);
5558 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5560 r
= MsiViewFetch(hview
, &hrec
);
5561 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5563 r
= MsiViewClose(hview
);
5564 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5565 r
= MsiCloseHandle(hview
);
5566 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5567 r
= MsiCloseHandle(hrec
);
5568 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5569 r
= MsiCloseHandle(hdb
);
5570 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5572 MultiByteToWideChar(CP_ACP
, 0, msifile
, -1, name
, 0x20);
5573 hr
= StgOpenStorage(name
, NULL
, mode
, NULL
, 0, &stg
);
5574 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5575 ok(stg
!= NULL
, "Expected non-NULL storage\n");
5577 hr
= IStorage_OpenStream(stg
, moo
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
5578 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5579 ok(stm
!= NULL
, "Expected non-NULL stream\n");
5581 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
5582 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5585 ok(read
== 4, "Expected 4, got %d\n", read
);
5586 ok(!memcmp(data
, data10
, read
), "Unexpected data\n");
5589 hr
= IStream_Release(stm
);
5590 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5592 hr
= IStorage_OpenStream(stg
, aar
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
5593 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5594 ok(stm
!= NULL
, "Expected non-NULL stream\n");
5596 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
5597 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5598 ok(read
== 8, "Expected 8, got %d\n", read
);
5601 ok(!memcmp(data
, data11
, read
), "Unexpected data\n");
5604 hr
= IStream_Release(stm
);
5605 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5607 hr
= IStorage_OpenStream(stg
, stringdata
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
5608 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5609 ok(stm
!= NULL
, "Expected non-NULL stream\n");
5611 hr
= IStream_Read(stm
, buffer
, MAX_PATH
, &read
);
5612 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5613 ok(read
== 24, "Expected 24, got %d\n", read
);
5614 ok(!memcmp(buffer
, data12
, read
), "Unexpected data\n");
5616 hr
= IStream_Release(stm
);
5617 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5619 hr
= IStorage_OpenStream(stg
, stringpool
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
5620 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5621 ok(stm
!= NULL
, "Expected non-NULL stream\n");
5623 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
5624 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5627 ok(read
== 64, "Expected 64, got %d\n", read
);
5628 ok(!memcmp(data
, data13
, read
), "Unexpected data\n");
5631 hr
= IStream_Release(stm
);
5632 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5634 hr
= IStorage_Release(stg
);
5635 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
5637 DeleteFileA(msifile
);
5640 static void test_viewmodify_delete(void)
5642 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
5648 DeleteFile(msifile
);
5650 /* just MsiOpenDatabase should not create a file */
5651 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5652 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5654 query
= "CREATE TABLE `phone` ( "
5655 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
5656 "PRIMARY KEY `id`)";
5657 r
= run_query(hdb
, 0, query
);
5658 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5660 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
5661 "VALUES('1', 'Alan', '5030581')";
5662 r
= run_query(hdb
, 0, query
);
5663 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5665 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
5666 "VALUES('2', 'Barry', '928440')";
5667 r
= run_query(hdb
, 0, query
);
5668 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5670 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
5671 "VALUES('3', 'Cindy', '2937550')";
5672 r
= run_query(hdb
, 0, query
);
5673 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5675 query
= "SELECT * FROM `phone` WHERE `id` <= 2";
5676 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5677 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5678 r
= MsiViewExecute(hview
, 0);
5679 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5680 r
= MsiViewFetch(hview
, &hrec
);
5681 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 r
= MsiCloseHandle(hrec
);
5688 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5689 r
= MsiViewFetch(hview
, &hrec
);
5690 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5693 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
5694 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5696 r
= MsiCloseHandle(hrec
);
5697 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5698 r
= MsiViewClose(hview
);
5699 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5700 r
= MsiCloseHandle(hview
);
5701 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5703 query
= "SELECT * FROM `phone`";
5704 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5705 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5706 r
= MsiViewExecute(hview
, 0);
5707 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5708 r
= MsiViewFetch(hview
, &hrec
);
5709 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5711 r
= MsiRecordGetInteger(hrec
, 1);
5712 ok(r
== 3, "Expected 3, got %d\n", r
);
5714 sz
= sizeof(buffer
);
5715 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
5716 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5717 ok(!lstrcmp(buffer
, "Cindy"), "Expected Cindy, got %s\n", buffer
);
5719 sz
= sizeof(buffer
);
5720 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
5721 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5722 ok(!lstrcmp(buffer
, "2937550"), "Expected 2937550, got %s\n", buffer
);
5724 r
= MsiCloseHandle(hrec
);
5725 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5727 r
= MsiViewFetch(hview
, &hrec
);
5728 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5730 r
= MsiViewClose(hview
);
5731 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5732 r
= MsiCloseHandle(hview
);
5733 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5734 r
= MsiCloseHandle(hdb
);
5735 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5738 static const WCHAR _Tables
[] = {0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0};
5739 static const WCHAR _StringData
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0};
5740 static const WCHAR _StringPool
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0};
5742 static const WCHAR data14
[] = { /* _StringPool */
5744 0, 0, /* string 0 '' */
5747 static const struct {
5751 } database_table_data
[] =
5754 {_StringData
, NULL
, 0},
5755 {_StringPool
, data14
, sizeof data14
},
5758 static void enum_stream_names(IStorage
*stg
)
5760 IEnumSTATSTG
*stgenum
= NULL
;
5765 BYTE data
[MAX_PATH
];
5766 BYTE check
[MAX_PATH
];
5769 memset(check
, 'a', MAX_PATH
);
5771 hr
= IStorage_EnumElements(stg
, 0, NULL
, 0, &stgenum
);
5772 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
5778 hr
= IEnumSTATSTG_Next(stgenum
, 1, &stat
, &count
);
5779 if(FAILED(hr
) || !count
)
5782 ok(!lstrcmpW(stat
.pwcsName
, database_table_data
[n
].name
),
5783 "Expected table %d name to match\n", n
);
5786 hr
= IStorage_OpenStream(stg
, stat
.pwcsName
, NULL
,
5787 STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
5788 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
5789 ok(stm
!= NULL
, "Expected non-NULL stream\n");
5791 CoTaskMemFree(stat
.pwcsName
);
5794 memset(data
, 'a', MAX_PATH
);
5795 hr
= IStream_Read(stm
, data
, sz
, &count
);
5796 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
5798 ok(count
== database_table_data
[n
].size
,
5799 "Expected %d, got %d\n", database_table_data
[n
].size
, count
);
5801 if (!database_table_data
[n
].size
)
5802 ok(!memcmp(data
, check
, MAX_PATH
), "data should not be changed\n");
5804 ok(!memcmp(data
, database_table_data
[n
].data
, database_table_data
[n
].size
),
5805 "Expected table %d data to match\n", n
);
5807 IStream_Release(stm
);
5811 ok(n
== 3, "Expected 3, got %d\n", n
);
5813 IEnumSTATSTG_Release(stgenum
);
5816 static void test_defaultdatabase(void)
5821 IStorage
*stg
= NULL
;
5823 DeleteFile(msifile
);
5825 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5826 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5828 r
= MsiDatabaseCommit(hdb
);
5829 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5831 MsiCloseHandle(hdb
);
5833 hr
= StgOpenStorage(msifileW
, NULL
, STGM_READ
| STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
5834 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
5835 ok(stg
!= NULL
, "Expected non-NULL stg\n");
5837 enum_stream_names(stg
);
5839 IStorage_Release(stg
);
5840 DeleteFileA(msifile
);
5843 static void test_order(void)
5845 MSIHANDLE hdb
, hview
, hrec
;
5846 CHAR buffer
[MAX_PATH
];
5852 ok(hdb
, "failed to create db\n");
5854 query
= "CREATE TABLE `Empty` ( `A` SHORT NOT NULL PRIMARY KEY `A`)";
5855 r
= run_query(hdb
, 0, query
);
5856 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5858 query
= "CREATE TABLE `Mesa` ( `A` SHORT NOT NULL, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
5859 r
= run_query(hdb
, 0, query
);
5860 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5862 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 1, 2, 9 )";
5863 r
= run_query(hdb
, 0, query
);
5864 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5866 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 3, 4, 7 )";
5867 r
= run_query(hdb
, 0, query
);
5868 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5870 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 5, 6, 8 )";
5871 r
= run_query(hdb
, 0, query
);
5872 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5874 query
= "CREATE TABLE `Sideboard` ( `D` SHORT NOT NULL, `E` SHORT, `F` SHORT PRIMARY KEY `D`)";
5875 r
= run_query(hdb
, 0, query
);
5876 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5878 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 10, 11, 18 )";
5879 r
= run_query(hdb
, 0, query
);
5880 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5882 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 12, 13, 16 )";
5883 r
= run_query(hdb
, 0, query
);
5884 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5886 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 14, 15, 17 )";
5887 r
= run_query(hdb
, 0, query
);
5888 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5890 query
= "SELECT `A`, `B` FROM `Mesa` ORDER BY `C`";
5891 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5892 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5893 r
= MsiViewExecute(hview
, 0);
5894 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5896 r
= MsiViewFetch(hview
, &hrec
);
5897 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5899 val
= MsiRecordGetInteger(hrec
, 1);
5900 ok(val
== 3, "Expected 3, got %d\n", val
);
5902 val
= MsiRecordGetInteger(hrec
, 2);
5903 ok(val
== 4, "Expected 3, got %d\n", val
);
5905 MsiCloseHandle(hrec
);
5907 r
= MsiViewFetch(hview
, &hrec
);
5908 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5910 val
= MsiRecordGetInteger(hrec
, 1);
5911 ok(val
== 5, "Expected 5, got %d\n", val
);
5913 val
= MsiRecordGetInteger(hrec
, 2);
5914 ok(val
== 6, "Expected 6, got %d\n", val
);
5916 MsiCloseHandle(hrec
);
5918 r
= MsiViewFetch(hview
, &hrec
);
5919 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5921 val
= MsiRecordGetInteger(hrec
, 1);
5922 ok(val
== 1, "Expected 1, got %d\n", val
);
5924 val
= MsiRecordGetInteger(hrec
, 2);
5925 ok(val
== 2, "Expected 2, got %d\n", val
);
5927 MsiCloseHandle(hrec
);
5929 r
= MsiViewFetch(hview
, &hrec
);
5930 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5932 MsiViewClose(hview
);
5933 MsiCloseHandle(hview
);
5935 query
= "SELECT `A`, `D` FROM `Mesa`, `Sideboard` ORDER BY `F`";
5936 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5937 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5938 r
= MsiViewExecute(hview
, 0);
5939 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5941 r
= MsiViewFetch(hview
, &hrec
);
5942 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5944 val
= MsiRecordGetInteger(hrec
, 1);
5945 ok(val
== 1, "Expected 1, got %d\n", val
);
5947 val
= MsiRecordGetInteger(hrec
, 2);
5948 ok(val
== 12, "Expected 12, got %d\n", val
);
5950 MsiCloseHandle(hrec
);
5952 r
= MsiViewFetch(hview
, &hrec
);
5953 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5955 val
= MsiRecordGetInteger(hrec
, 1);
5956 ok(val
== 3, "Expected 3, got %d\n", val
);
5958 val
= MsiRecordGetInteger(hrec
, 2);
5959 ok(val
== 12, "Expected 12, got %d\n", val
);
5961 MsiCloseHandle(hrec
);
5963 r
= MsiViewFetch(hview
, &hrec
);
5964 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5966 val
= MsiRecordGetInteger(hrec
, 1);
5967 ok(val
== 5, "Expected 5, got %d\n", val
);
5969 val
= MsiRecordGetInteger(hrec
, 2);
5970 ok(val
== 12, "Expected 12, got %d\n", val
);
5972 MsiCloseHandle(hrec
);
5974 r
= MsiViewFetch(hview
, &hrec
);
5975 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5977 val
= MsiRecordGetInteger(hrec
, 1);
5978 ok(val
== 1, "Expected 1, got %d\n", val
);
5980 val
= MsiRecordGetInteger(hrec
, 2);
5981 ok(val
== 14, "Expected 14, got %d\n", val
);
5983 MsiCloseHandle(hrec
);
5985 r
= MsiViewFetch(hview
, &hrec
);
5986 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5988 val
= MsiRecordGetInteger(hrec
, 1);
5989 ok(val
== 3, "Expected 3, got %d\n", val
);
5991 val
= MsiRecordGetInteger(hrec
, 2);
5992 ok(val
== 14, "Expected 14, got %d\n", val
);
5994 MsiCloseHandle(hrec
);
5996 r
= MsiViewFetch(hview
, &hrec
);
5997 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5999 val
= MsiRecordGetInteger(hrec
, 1);
6000 ok(val
== 5, "Expected 5, got %d\n", val
);
6002 val
= MsiRecordGetInteger(hrec
, 2);
6003 ok(val
== 14, "Expected 14, got %d\n", val
);
6005 MsiCloseHandle(hrec
);
6007 r
= MsiViewFetch(hview
, &hrec
);
6008 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6010 val
= MsiRecordGetInteger(hrec
, 1);
6011 ok(val
== 1, "Expected 1, got %d\n", val
);
6013 val
= MsiRecordGetInteger(hrec
, 2);
6014 ok(val
== 10, "Expected 10, got %d\n", val
);
6016 MsiCloseHandle(hrec
);
6018 r
= MsiViewFetch(hview
, &hrec
);
6019 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6021 val
= MsiRecordGetInteger(hrec
, 1);
6022 ok(val
== 3, "Expected 3, got %d\n", val
);
6024 val
= MsiRecordGetInteger(hrec
, 2);
6025 ok(val
== 10, "Expected 10, got %d\n", val
);
6027 MsiCloseHandle(hrec
);
6029 r
= MsiViewFetch(hview
, &hrec
);
6030 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6032 val
= MsiRecordGetInteger(hrec
, 1);
6033 ok(val
== 5, "Expected 5, got %d\n", val
);
6035 val
= MsiRecordGetInteger(hrec
, 2);
6036 ok(val
== 10, "Expected 10, got %d\n", val
);
6038 MsiCloseHandle(hrec
);
6040 r
= MsiViewFetch(hview
, &hrec
);
6041 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6043 MsiViewClose(hview
);
6044 MsiCloseHandle(hview
);
6046 query
= "SELECT * FROM `Empty` ORDER BY `A`";
6047 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6048 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6049 r
= MsiViewExecute(hview
, 0);
6050 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6052 r
= MsiViewFetch(hview
, &hrec
);
6053 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6055 MsiViewClose(hview
);
6056 MsiCloseHandle(hview
);
6058 query
= "CREATE TABLE `Buffet` ( `One` CHAR(72), `Two` SHORT PRIMARY KEY `One`)";
6059 r
= run_query(hdb
, 0, query
);
6060 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6062 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'uno', 2)";
6063 r
= run_query(hdb
, 0, query
);
6064 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6066 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'dos', 3)";
6067 r
= run_query(hdb
, 0, query
);
6068 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6070 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'tres', 1)";
6071 r
= run_query(hdb
, 0, query
);
6072 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6074 query
= "SELECT * FROM `Buffet` WHERE `One` = 'dos' ORDER BY `Two`";
6075 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6076 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6077 r
= MsiViewExecute(hview
, 0);
6078 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6080 r
= MsiViewFetch(hview
, &hrec
);
6081 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6083 sz
= sizeof(buffer
);
6084 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
6085 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6086 ok(!lstrcmp(buffer
, "dos"), "Expected \"dos\", got \"%s\"\n", buffer
);
6088 r
= MsiRecordGetInteger(hrec
, 2);
6089 ok(r
== 3, "Expected 3, got %d\n", r
);
6091 MsiCloseHandle(hrec
);
6093 r
= MsiViewFetch(hview
, &hrec
);
6094 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6096 MsiViewClose(hview
);
6097 MsiCloseHandle(hview
);
6098 MsiCloseHandle(hdb
);
6101 static void test_viewmodify_delete_temporary(void)
6103 MSIHANDLE hdb
, hview
, hrec
;
6107 DeleteFile(msifile
);
6109 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6110 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6112 query
= "CREATE TABLE `Table` ( `A` SHORT PRIMARY KEY `A` )";
6113 r
= run_query(hdb
, 0, query
);
6114 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6116 query
= "SELECT * FROM `Table`";
6117 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6118 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6119 r
= MsiViewExecute(hview
, 0);
6120 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6122 hrec
= MsiCreateRecord(1);
6123 MsiRecordSetInteger(hrec
, 1, 1);
6125 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, hrec
);
6126 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6128 MsiCloseHandle(hrec
);
6130 hrec
= MsiCreateRecord(1);
6131 MsiRecordSetInteger(hrec
, 1, 2);
6133 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
6134 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6136 MsiCloseHandle(hrec
);
6138 hrec
= MsiCreateRecord(1);
6139 MsiRecordSetInteger(hrec
, 1, 3);
6141 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, hrec
);
6142 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6144 MsiCloseHandle(hrec
);
6146 hrec
= MsiCreateRecord(1);
6147 MsiRecordSetInteger(hrec
, 1, 4);
6149 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
6150 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6152 MsiCloseHandle(hrec
);
6153 MsiViewClose(hview
);
6154 MsiCloseHandle(hview
);
6156 query
= "SELECT * FROM `Table` WHERE `A` = 2";
6157 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6158 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6159 r
= MsiViewExecute(hview
, 0);
6160 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6161 r
= MsiViewFetch(hview
, &hrec
);
6162 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6164 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
6165 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6167 MsiCloseHandle(hrec
);
6168 MsiViewClose(hview
);
6169 MsiCloseHandle(hview
);
6171 query
= "SELECT * FROM `Table` WHERE `A` = 3";
6172 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6173 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6174 r
= MsiViewExecute(hview
, 0);
6175 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6176 r
= MsiViewFetch(hview
, &hrec
);
6177 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6179 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
6180 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6182 MsiCloseHandle(hrec
);
6183 MsiViewClose(hview
);
6184 MsiCloseHandle(hview
);
6186 query
= "SELECT * FROM `Table` ORDER BY `A`";
6187 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6188 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6189 r
= MsiViewExecute(hview
, 0);
6190 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6192 r
= MsiViewFetch(hview
, &hrec
);
6193 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6195 r
= MsiRecordGetInteger(hrec
, 1);
6196 ok(r
== 1, "Expected 1, got %d\n", r
);
6198 MsiCloseHandle(hrec
);
6200 r
= MsiViewFetch(hview
, &hrec
);
6201 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6203 r
= MsiRecordGetInteger(hrec
, 1);
6204 ok(r
== 4, "Expected 4, got %d\n", r
);
6206 MsiCloseHandle(hrec
);
6208 r
= MsiViewFetch(hview
, &hrec
);
6209 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6211 MsiViewClose(hview
);
6212 MsiCloseHandle(hview
);
6213 MsiCloseHandle(hdb
);
6214 DeleteFileA(msifile
);
6217 static void test_deleterow(void)
6219 MSIHANDLE hdb
, hview
, hrec
;
6225 DeleteFile(msifile
);
6227 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6228 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6230 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6231 r
= run_query(hdb
, 0, query
);
6232 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6234 query
= "INSERT INTO `Table` (`A`) VALUES ('one')";
6235 r
= run_query(hdb
, 0, query
);
6236 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6238 query
= "INSERT INTO `Table` (`A`) VALUES ('two')";
6239 r
= run_query(hdb
, 0, query
);
6240 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6242 query
= "DELETE FROM `Table` WHERE `A` = 'one'";
6243 r
= run_query(hdb
, 0, query
);
6244 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6246 r
= MsiDatabaseCommit(hdb
);
6247 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6249 MsiCloseHandle(hdb
);
6251 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
6252 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6254 query
= "SELECT * FROM `Table`";
6255 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6256 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6257 r
= MsiViewExecute(hview
, 0);
6258 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6260 r
= MsiViewFetch(hview
, &hrec
);
6261 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6264 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6265 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6266 ok(!lstrcmpA(buf
, "two"), "Expected two, got %s\n", buf
);
6268 MsiCloseHandle(hrec
);
6270 r
= MsiViewFetch(hview
, &hrec
);
6271 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6273 MsiViewClose(hview
);
6274 MsiCloseHandle(hview
);
6275 MsiCloseHandle(hdb
);
6276 DeleteFileA(msifile
);
6279 static const CHAR import_dat
[] = "A\n"
6282 "This is a new 'string' ok\n";
6284 static void test_quotes(void)
6286 MSIHANDLE hdb
, hview
, hrec
;
6292 DeleteFile(msifile
);
6294 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6295 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6297 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6298 r
= run_query(hdb
, 0, query
);
6299 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6301 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a 'string' ok' )";
6302 r
= run_query(hdb
, 0, query
);
6303 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6304 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6306 query
= "INSERT INTO `Table` ( `A` ) VALUES ( \"This is a 'string' ok\" )";
6307 r
= run_query(hdb
, 0, query
);
6308 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6309 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6311 query
= "INSERT INTO `Table` ( `A` ) VALUES ( \"test\" )";
6312 r
= run_query(hdb
, 0, query
);
6313 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6314 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6316 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a ''string'' ok' )";
6317 r
= run_query(hdb
, 0, query
);
6318 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6320 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a '''string''' ok' )";
6321 r
= run_query(hdb
, 0, query
);
6322 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6324 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \'string\' ok' )";
6325 r
= run_query(hdb
, 0, query
);
6326 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6328 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \"string\" ok' )";
6329 r
= run_query(hdb
, 0, query
);
6330 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6332 query
= "SELECT * FROM `Table`";
6333 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6334 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6336 r
= MsiViewExecute(hview
, 0);
6337 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6339 r
= MsiViewFetch(hview
, &hrec
);
6340 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6343 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
6344 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6345 ok(!lstrcmp(buf
, "This is a \"string\" ok"),
6346 "Expected \"This is a \"string\" ok\", got %s\n", buf
);
6348 MsiCloseHandle(hrec
);
6350 r
= MsiViewFetch(hview
, &hrec
);
6351 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6353 MsiViewClose(hview
);
6354 MsiCloseHandle(hview
);
6356 write_file("import.idt", import_dat
, (sizeof(import_dat
) - 1) * sizeof(char));
6358 r
= MsiDatabaseImportA(hdb
, CURR_DIR
, "import.idt");
6359 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6361 DeleteFileA("import.idt");
6363 query
= "SELECT * FROM `Table`";
6364 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6365 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6367 r
= MsiViewExecute(hview
, 0);
6368 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6370 r
= MsiViewFetch(hview
, &hrec
);
6371 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6374 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
6375 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6376 ok(!lstrcmp(buf
, "This is a new 'string' ok"),
6377 "Expected \"This is a new 'string' ok\", got %s\n", buf
);
6379 MsiCloseHandle(hrec
);
6381 r
= MsiViewFetch(hview
, &hrec
);
6382 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6384 MsiViewClose(hview
);
6385 MsiCloseHandle(hview
);
6386 MsiCloseHandle(hdb
);
6387 DeleteFileA(msifile
);
6390 static void test_carriagereturn(void)
6392 MSIHANDLE hdb
, hview
, hrec
;
6398 DeleteFile(msifile
);
6400 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6401 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6403 query
= "CREATE TABLE `Table`\r ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6404 r
= run_query(hdb
, 0, query
);
6405 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6406 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6408 query
= "CREATE TABLE `Table` \r( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6409 r
= run_query(hdb
, 0, query
);
6410 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6411 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6413 query
= "CREATE\r TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6414 r
= run_query(hdb
, 0, query
);
6415 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6416 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6418 query
= "CREATE TABLE\r `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6419 r
= run_query(hdb
, 0, query
);
6420 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6421 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6423 query
= "CREATE TABLE `Table` (\r `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6424 r
= run_query(hdb
, 0, query
);
6425 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6426 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6428 query
= "CREATE TABLE `Table` ( `A`\r CHAR(72) NOT NULL PRIMARY KEY `A` )";
6429 r
= run_query(hdb
, 0, query
);
6430 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6431 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6433 query
= "CREATE TABLE `Table` ( `A` CHAR(72)\r NOT NULL PRIMARY KEY `A` )";
6434 r
= run_query(hdb
, 0, query
);
6435 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6436 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6438 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT\r NULL PRIMARY KEY `A` )";
6439 r
= run_query(hdb
, 0, query
);
6440 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6441 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6443 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT \rNULL PRIMARY KEY `A` )";
6444 r
= run_query(hdb
, 0, query
);
6445 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6446 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6448 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL\r PRIMARY KEY `A` )";
6449 r
= run_query(hdb
, 0, query
);
6450 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6451 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6453 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL \rPRIMARY KEY `A` )";
6454 r
= run_query(hdb
, 0, query
);
6455 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6456 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6458 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY\r KEY `A` )";
6459 r
= run_query(hdb
, 0, query
);
6460 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6461 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6463 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY \rKEY `A` )";
6464 r
= run_query(hdb
, 0, query
);
6465 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6466 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6468 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY\r `A` )";
6469 r
= run_query(hdb
, 0, query
);
6470 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6471 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6473 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A`\r )";
6474 r
= run_query(hdb
, 0, query
);
6475 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6476 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6478 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )\r";
6479 r
= run_query(hdb
, 0, query
);
6480 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6481 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6483 query
= "CREATE TABLE `\rOne` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6484 r
= run_query(hdb
, 0, query
);
6485 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6487 query
= "CREATE TABLE `Tw\ro` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6488 r
= run_query(hdb
, 0, query
);
6489 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6491 query
= "CREATE TABLE `Three\r` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6492 r
= run_query(hdb
, 0, query
);
6493 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6495 query
= "CREATE TABLE `Four` ( `A\r` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6496 r
= run_query(hdb
, 0, query
);
6497 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6498 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6500 query
= "CREATE TABLE `Four` ( `\rA` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6501 r
= run_query(hdb
, 0, query
);
6502 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6503 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6505 query
= "CREATE TABLE `Four` ( `A` CHAR(72\r) NOT NULL PRIMARY KEY `A` )";
6506 r
= run_query(hdb
, 0, query
);
6507 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6508 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6510 query
= "CREATE TABLE `Four` ( `A` CHAR(\r72) NOT NULL PRIMARY KEY `A` )";
6511 r
= run_query(hdb
, 0, query
);
6512 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6513 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6515 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `\rA` )";
6516 r
= run_query(hdb
, 0, query
);
6517 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6518 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6520 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
6521 r
= run_query(hdb
, 0, query
);
6522 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6523 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6525 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
6526 r
= run_query(hdb
, 0, query
);
6527 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6528 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6530 query
= "SELECT * FROM `_Tables`";
6531 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6532 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6533 r
= MsiViewExecute(hview
, 0);
6534 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6536 r
= MsiViewFetch(hview
, &hrec
);
6537 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6540 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6541 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6542 ok(!lstrcmpA(buf
, "\rOne"), "Expected \"\\rOne\", got \"%s\"\n", buf
);
6544 MsiCloseHandle(hrec
);
6546 r
= MsiViewFetch(hview
, &hrec
);
6547 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6550 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6551 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6552 ok(!lstrcmpA(buf
, "Tw\ro"), "Expected \"Tw\\ro\", got \"%s\"\n", buf
);
6554 MsiCloseHandle(hrec
);
6556 r
= MsiViewFetch(hview
, &hrec
);
6557 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6560 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6561 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6562 ok(!lstrcmpA(buf
, "Three\r"), "Expected \"Three\r\", got \"%s\"\n", buf
);
6564 MsiCloseHandle(hrec
);
6566 r
= MsiViewFetch(hview
, &hrec
);
6567 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6569 MsiViewClose(hview
);
6570 MsiCloseHandle(hview
);
6572 MsiCloseHandle(hdb
);
6573 DeleteFileA(msifile
);
6576 static void test_noquotes(void)
6578 MSIHANDLE hdb
, hview
, hrec
;
6584 DeleteFile(msifile
);
6586 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6587 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6589 query
= "CREATE TABLE Table ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6590 r
= run_query(hdb
, 0, query
);
6591 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6593 query
= "CREATE TABLE `Table` ( A CHAR(72) NOT NULL PRIMARY KEY `A` )";
6594 r
= run_query(hdb
, 0, query
);
6595 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6597 query
= "CREATE TABLE `Table2` ( `A` CHAR(72) NOT NULL PRIMARY KEY A )";
6598 r
= run_query(hdb
, 0, query
);
6599 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6601 query
= "CREATE TABLE `Table3` ( A CHAR(72) NOT NULL PRIMARY KEY A )";
6602 r
= run_query(hdb
, 0, query
);
6603 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6605 query
= "SELECT * FROM `_Tables`";
6606 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6607 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6608 r
= MsiViewExecute(hview
, 0);
6609 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6611 r
= MsiViewFetch(hview
, &hrec
);
6612 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6615 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6616 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6617 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
6619 MsiCloseHandle(hrec
);
6621 r
= MsiViewFetch(hview
, &hrec
);
6622 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6625 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6626 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6627 ok(!lstrcmpA(buf
, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf
);
6629 MsiCloseHandle(hrec
);
6631 r
= MsiViewFetch(hview
, &hrec
);
6632 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6635 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6636 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6637 ok(!lstrcmpA(buf
, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf
);
6639 MsiCloseHandle(hrec
);
6641 r
= MsiViewFetch(hview
, &hrec
);
6642 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6644 MsiViewClose(hview
);
6645 MsiCloseHandle(hview
);
6647 query
= "SELECT * FROM `_Columns`";
6648 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6649 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6650 r
= MsiViewExecute(hview
, 0);
6651 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6653 r
= MsiViewFetch(hview
, &hrec
);
6654 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6657 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6658 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6659 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
6661 r
= MsiRecordGetInteger(hrec
, 2);
6662 ok(r
== 1, "Expected 1, got %d\n", r
);
6665 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6666 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6667 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
6669 MsiCloseHandle(hrec
);
6671 r
= MsiViewFetch(hview
, &hrec
);
6672 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6675 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6676 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6677 ok(!lstrcmpA(buf
, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf
);
6679 r
= MsiRecordGetInteger(hrec
, 2);
6680 ok(r
== 1, "Expected 1, got %d\n", r
);
6683 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6684 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6685 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
6687 MsiCloseHandle(hrec
);
6689 r
= MsiViewFetch(hview
, &hrec
);
6690 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6693 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6694 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6695 ok(!lstrcmpA(buf
, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf
);
6697 r
= MsiRecordGetInteger(hrec
, 2);
6698 ok(r
== 1, "Expected 1, got %d\n", r
);
6701 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6702 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6703 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
6705 MsiCloseHandle(hrec
);
6707 r
= MsiViewFetch(hview
, &hrec
);
6708 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6710 MsiViewClose(hview
);
6711 MsiCloseHandle(hview
);
6713 query
= "INSERT INTO Table ( `A` ) VALUES ( 'hi' )";
6714 r
= run_query(hdb
, 0, query
);
6715 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6717 query
= "INSERT INTO `Table` ( A ) VALUES ( 'hi' )";
6718 r
= run_query(hdb
, 0, query
);
6719 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6721 query
= "INSERT INTO `Table` ( `A` ) VALUES ( hi )";
6722 r
= run_query(hdb
, 0, query
);
6723 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6725 query
= "SELECT * FROM Table WHERE `A` = 'hi'";
6726 r
= run_query(hdb
, 0, query
);
6727 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6729 query
= "SELECT * FROM `Table` WHERE `A` = hi";
6730 r
= run_query(hdb
, 0, query
);
6731 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6733 query
= "SELECT * FROM Table";
6734 r
= run_query(hdb
, 0, query
);
6735 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6737 query
= "SELECT * FROM Table2";
6738 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6739 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6740 r
= MsiViewExecute(hview
, 0);
6741 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6743 r
= MsiViewFetch(hview
, &hrec
);
6744 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6746 MsiViewClose(hview
);
6747 MsiCloseHandle(hview
);
6749 query
= "SELECT * FROM `Table` WHERE A = 'hi'";
6750 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6751 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6752 r
= MsiViewExecute(hview
, 0);
6753 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6755 r
= MsiViewFetch(hview
, &hrec
);
6756 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6759 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6760 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6761 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
6763 MsiCloseHandle(hrec
);
6765 r
= MsiViewFetch(hview
, &hrec
);
6766 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6768 MsiViewClose(hview
);
6769 MsiCloseHandle(hview
);
6770 MsiCloseHandle(hdb
);
6771 DeleteFileA(msifile
);
6774 static void read_file_data(LPCSTR filename
, LPSTR buffer
)
6779 file
= CreateFileA( filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, NULL
);
6780 ZeroMemory(buffer
, MAX_PATH
);
6781 ReadFile(file
, buffer
, MAX_PATH
, &read
, NULL
);
6785 static void test_forcecodepage(void)
6789 char buffer
[MAX_PATH
];
6792 DeleteFile(msifile
);
6794 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6795 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6797 query
= "SELECT * FROM `_ForceCodepage`";
6798 r
= run_query(hdb
, 0, query
);
6799 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6801 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
6802 r
= run_query(hdb
, 0, query
);
6803 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6805 query
= "SELECT * FROM `_ForceCodepage`";
6806 r
= run_query(hdb
, 0, query
);
6807 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6809 r
= MsiDatabaseCommit(hdb
);
6810 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6812 query
= "SELECT * FROM `_ForceCodepage`";
6813 r
= run_query(hdb
, 0, query
);
6814 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6816 MsiCloseHandle(hdb
);
6818 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_DIRECT
, &hdb
);
6819 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6821 query
= "SELECT * FROM `_ForceCodepage`";
6822 r
= run_query(hdb
, 0, query
);
6823 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6825 r
= MsiDatabaseExport(hdb
, "_ForceCodepage", CURR_DIR
, "forcecodepage.idt");
6826 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6828 read_file_data("forcecodepage.idt", buffer
);
6829 ok(!lstrcmpA(buffer
, "\r\n\r\n0\t_ForceCodepage\r\n"),
6830 "Expected \"\r\n\r\n0\t_ForceCodepage\r\n\", got \"%s\"", buffer
);
6832 MsiCloseHandle(hdb
);
6833 DeleteFileA(msifile
);
6834 DeleteFileA("forcecodepage.idt");
6837 static void test_viewmodify_refresh(void)
6839 MSIHANDLE hdb
, hview
, hrec
;
6841 char buffer
[MAX_PATH
];
6845 DeleteFile(msifile
);
6847 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6848 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6850 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL, `B` INT PRIMARY KEY `A` )";
6851 r
= run_query(hdb
, 0, query
);
6852 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6854 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hi', 1 )";
6855 r
= run_query(hdb
, 0, query
);
6856 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6858 query
= "SELECT * FROM `Table`";
6859 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6860 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6861 r
= MsiViewExecute(hview
, 0);
6862 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6864 r
= MsiViewFetch(hview
, &hrec
);
6865 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6867 query
= "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hi'";
6868 r
= run_query(hdb
, 0, query
);
6869 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6871 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
6872 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6875 r
= MsiRecordGetStringA(hrec
, 1, buffer
, &size
);
6876 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6877 ok(!lstrcmpA(buffer
, "hi"), "Expected \"hi\", got \"%s\"\n", buffer
);
6878 ok(size
== 2, "Expected 2, got %d\n", size
);
6880 r
= MsiRecordGetInteger(hrec
, 2);
6881 ok(r
== 2, "Expected 2, got %d\n", r
);
6883 MsiCloseHandle(hrec
);
6884 MsiViewClose(hview
);
6885 MsiCloseHandle(hview
);
6887 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hello', 3 )";
6888 r
= run_query(hdb
, 0, query
);
6889 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6891 query
= "SELECT * FROM `Table` WHERE `B` = 3";
6892 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6893 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6894 r
= MsiViewExecute(hview
, 0);
6895 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6897 r
= MsiViewFetch(hview
, &hrec
);
6898 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6900 query
= "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hello'";
6901 r
= run_query(hdb
, 0, query
);
6902 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6904 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hithere', 3 )";
6905 r
= run_query(hdb
, 0, query
);
6906 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6908 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
6909 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6912 r
= MsiRecordGetStringA(hrec
, 1, buffer
, &size
);
6913 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6914 ok(!lstrcmpA(buffer
, "hello"), "Expected \"hello\", got \"%s\"\n", buffer
);
6915 ok(size
== 5, "Expected 5, got %d\n", size
);
6917 r
= MsiRecordGetInteger(hrec
, 2);
6918 ok(r
== 2, "Expected 2, got %d\n", r
);
6920 MsiCloseHandle(hrec
);
6921 MsiViewClose(hview
);
6922 MsiCloseHandle(hview
);
6923 MsiCloseHandle(hdb
);
6924 DeleteFileA(msifile
);
6927 static void test_where_viewmodify(void)
6929 MSIHANDLE hdb
, hview
, hrec
;
6933 DeleteFile(msifile
);
6935 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6936 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6938 query
= "CREATE TABLE `Table` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6939 r
= run_query(hdb
, 0, query
);
6940 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6942 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 1, 2 )";
6943 r
= run_query(hdb
, 0, query
);
6944 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6946 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 3, 4 )";
6947 r
= run_query(hdb
, 0, query
);
6948 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6950 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 5, 6 )";
6951 r
= run_query(hdb
, 0, query
);
6952 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6954 /* `B` = 3 doesn't match, but the view shouldn't be executed */
6955 query
= "SELECT * FROM `Table` WHERE `B` = 3";
6956 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6957 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6959 hrec
= MsiCreateRecord(2);
6960 MsiRecordSetInteger(hrec
, 1, 7);
6961 MsiRecordSetInteger(hrec
, 2, 8);
6963 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
6964 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6966 MsiCloseHandle(hrec
);
6967 MsiViewClose(hview
);
6968 MsiCloseHandle(hview
);
6970 query
= "SELECT * FROM `Table` WHERE `A` = 7";
6971 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6972 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6973 r
= MsiViewExecute(hview
, 0);
6974 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6976 r
= MsiViewFetch(hview
, &hrec
);
6977 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6979 r
= MsiRecordGetInteger(hrec
, 1);
6980 ok(r
== 7, "Expected 7, got %d\n", r
);
6982 r
= MsiRecordGetInteger(hrec
, 2);
6983 ok(r
== 8, "Expected 8, got %d\n", r
);
6985 MsiRecordSetInteger(hrec
, 2, 9);
6987 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
6988 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6990 MsiCloseHandle(hrec
);
6991 MsiViewClose(hview
);
6992 MsiCloseHandle(hview
);
6994 query
= "SELECT * FROM `Table` WHERE `A` = 7";
6995 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6996 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6997 r
= MsiViewExecute(hview
, 0);
6998 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7000 r
= MsiViewFetch(hview
, &hrec
);
7001 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7003 r
= MsiRecordGetInteger(hrec
, 1);
7004 ok(r
== 7, "Expected 7, got %d\n", r
);
7006 r
= MsiRecordGetInteger(hrec
, 2);
7007 ok(r
== 9, "Expected 9, got %d\n", r
);
7009 query
= "UPDATE `Table` SET `B` = 10 WHERE `A` = 7";
7010 r
= run_query(hdb
, 0, query
);
7011 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7013 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
7014 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7016 r
= MsiRecordGetInteger(hrec
, 1);
7017 ok(r
== 7, "Expected 7, got %d\n", r
);
7019 r
= MsiRecordGetInteger(hrec
, 2);
7020 ok(r
== 10, "Expected 10, got %d\n", r
);
7022 MsiCloseHandle(hrec
);
7023 MsiViewClose(hview
);
7024 MsiCloseHandle(hview
);
7025 MsiCloseHandle(hdb
);
7028 static BOOL
create_storage(LPCSTR name
)
7030 WCHAR nameW
[MAX_PATH
];
7037 MultiByteToWideChar(CP_ACP
, 0, name
, -1, nameW
, MAX_PATH
);
7038 hr
= StgCreateDocfile(nameW
, STGM_CREATE
| STGM_READWRITE
|
7039 STGM_DIRECT
| STGM_SHARE_EXCLUSIVE
, 0, &stg
);
7043 hr
= IStorage_CreateStream(stg
, nameW
, STGM_WRITE
| STGM_SHARE_EXCLUSIVE
,
7048 hr
= IStream_Write(stm
, "stgdata", 8, &count
);
7053 IStream_Release(stm
);
7054 IStorage_Release(stg
);
7059 static void test_storages_table(void)
7061 MSIHANDLE hdb
, hview
, hrec
;
7062 IStorage
*stg
, *inner
;
7064 char file
[MAX_PATH
];
7066 WCHAR name
[MAX_PATH
];
7073 ok(hdb
, "failed to create db\n");
7075 r
= MsiDatabaseCommit(hdb
);
7076 ok(r
== ERROR_SUCCESS
, "Failed to commit database\n");
7078 MsiCloseHandle(hdb
);
7080 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
7081 ok(r
== ERROR_SUCCESS
, "Failed to open database\n");
7083 /* check the column types */
7084 hrec
= get_column_info(hdb
, "SELECT * FROM `_Storages`", MSICOLINFO_TYPES
);
7085 ok(hrec
, "failed to get column info hrecord\n");
7086 ok(check_record(hrec
, 1, "s62"), "wrong hrecord type\n");
7087 ok(check_record(hrec
, 2, "V0"), "wrong hrecord type\n");
7089 MsiCloseHandle(hrec
);
7091 /* now try the names */
7092 hrec
= get_column_info(hdb
, "SELECT * FROM `_Storages`", MSICOLINFO_NAMES
);
7093 ok(hrec
, "failed to get column info hrecord\n");
7094 ok(check_record(hrec
, 1, "Name"), "wrong hrecord type\n");
7095 ok(check_record(hrec
, 2, "Data"), "wrong hrecord type\n");
7097 MsiCloseHandle(hrec
);
7099 create_storage("storage.bin");
7101 hrec
= MsiCreateRecord(2);
7102 MsiRecordSetString(hrec
, 1, "stgname");
7104 r
= MsiRecordSetStream(hrec
, 2, "storage.bin");
7105 ok(r
== ERROR_SUCCESS
, "Failed to add stream data to the hrecord: %d\n", r
);
7107 DeleteFileA("storage.bin");
7109 query
= "INSERT INTO `_Storages` (`Name`, `Data`) VALUES (?, ?)";
7110 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
7111 ok(r
== ERROR_SUCCESS
, "Failed to open database hview: %d\n", r
);
7113 r
= MsiViewExecute(hview
, hrec
);
7114 ok(r
== ERROR_SUCCESS
, "Failed to execute hview: %d\n", r
);
7116 MsiCloseHandle(hrec
);
7117 MsiViewClose(hview
);
7118 MsiCloseHandle(hview
);
7120 query
= "SELECT `Name`, `Data` FROM `_Storages`";
7121 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
7122 ok(r
== ERROR_SUCCESS
, "Failed to open database hview: %d\n", r
);
7124 r
= MsiViewExecute(hview
, 0);
7125 ok(r
== ERROR_SUCCESS
, "Failed to execute hview: %d\n", r
);
7127 r
= MsiViewFetch(hview
, &hrec
);
7128 ok(r
== ERROR_SUCCESS
, "Failed to fetch hrecord: %d\n", r
);
7131 r
= MsiRecordGetString(hrec
, 1, file
, &size
);
7132 ok(r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
7133 ok(!lstrcmp(file
, "stgname"), "Expected \"stgname\", got \"%s\"\n", file
);
7136 lstrcpyA(buf
, "apple");
7137 r
= MsiRecordReadStream(hrec
, 2, buf
, &size
);
7138 ok(r
== ERROR_INVALID_DATA
, "Expected ERROR_INVALID_DATA, got %d\n", r
);
7139 ok(!lstrcmp(buf
, "apple"), "Expected buf to be unchanged, got %s\n", buf
);
7140 ok(size
== 0, "Expected 0, got %d\n", size
);
7142 MsiCloseHandle(hrec
);
7144 r
= MsiViewFetch(hview
, &hrec
);
7145 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7147 MsiViewClose(hview
);
7148 MsiCloseHandle(hview
);
7150 MsiDatabaseCommit(hdb
);
7151 MsiCloseHandle(hdb
);
7153 MultiByteToWideChar(CP_ACP
, 0, msifile
, -1, name
, MAX_PATH
);
7154 hr
= StgOpenStorage(name
, NULL
, STGM_DIRECT
| STGM_READ
|
7155 STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
7156 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
7157 ok(stg
!= NULL
, "Expected non-NULL storage\n");
7159 MultiByteToWideChar(CP_ACP
, 0, "stgname", -1, name
, MAX_PATH
);
7160 hr
= IStorage_OpenStorage(stg
, name
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
,
7162 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
7163 ok(inner
!= NULL
, "Expected non-NULL storage\n");
7165 MultiByteToWideChar(CP_ACP
, 0, "storage.bin", -1, name
, MAX_PATH
);
7166 hr
= IStorage_OpenStream(inner
, name
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
7167 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
7168 ok(stm
!= NULL
, "Expected non-NULL stream\n");
7170 hr
= IStream_Read(stm
, buf
, MAX_PATH
, &size
);
7171 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
7172 ok(size
== 8, "Expected 8, got %d\n", size
);
7173 ok(!lstrcmpA(buf
, "stgdata"), "Expected \"stgdata\", got \"%s\"\n", buf
);
7175 IStream_Release(stm
);
7176 IStorage_Release(inner
);
7178 IStorage_Release(stg
);
7179 DeleteFileA(msifile
);
7182 static void test_dbtopackage(void)
7184 MSIHANDLE hdb
, hpkg
;
7185 CHAR package
[12], buf
[MAX_PATH
];
7189 /* create an empty database, transact mode */
7190 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
7191 ok(r
== ERROR_SUCCESS
, "Failed to create database\n");
7193 set_summary_info(hdb
);
7195 r
= create_directory_table(hdb
);
7196 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7198 r
= create_custom_action_table(hdb
);
7199 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7201 r
= add_custom_action_entry(hdb
, "'SetProp', 51, 'MYPROP', 'grape'");
7202 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7204 sprintf(package
, "#%u", hdb
);
7205 r
= MsiOpenPackage(package
, &hpkg
);
7206 if (r
== ERROR_INSTALL_PACKAGE_REJECTED
)
7208 skip("Not enough rights to perform tests\n");
7211 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7213 /* property is not set yet */
7215 lstrcpyA(buf
, "kiwi");
7216 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
7217 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7218 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
7219 ok(size
== 0, "Expected 0, got %d\n", size
);
7221 /* run the custom action to set the property */
7222 r
= MsiDoAction(hpkg
, "SetProp");
7223 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7225 /* property is now set */
7227 lstrcpyA(buf
, "kiwi");
7228 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
7229 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7230 ok(!lstrcmpA(buf
, "grape"), "Expected \"grape\", got \"%s\"\n", buf
);
7231 ok(size
== 5, "Expected 5, got %d\n", size
);
7233 MsiCloseHandle(hpkg
);
7235 /* reset the package */
7236 r
= MsiOpenPackage(package
, &hpkg
);
7237 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7239 /* property is not set anymore */
7241 lstrcpyA(buf
, "kiwi");
7242 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
7243 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7246 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
7247 ok(size
== 0, "Expected 0, got %d\n", size
);
7250 MsiCloseHandle(hdb
);
7251 MsiCloseHandle(hpkg
);
7253 /* create an empty database, direct mode */
7254 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATEDIRECT
, &hdb
);
7255 ok(r
== ERROR_SUCCESS
, "Failed to create database\n");
7257 set_summary_info(hdb
);
7259 r
= create_directory_table(hdb
);
7260 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7262 r
= create_custom_action_table(hdb
);
7263 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7265 r
= add_custom_action_entry(hdb
, "'SetProp', 51, 'MYPROP', 'grape'");
7266 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7268 sprintf(package
, "#%u", hdb
);
7269 r
= MsiOpenPackage(package
, &hpkg
);
7270 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7272 /* property is not set yet */
7274 lstrcpyA(buf
, "kiwi");
7275 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
7276 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7277 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
7278 ok(size
== 0, "Expected 0, got %d\n", size
);
7280 /* run the custom action to set the property */
7281 r
= MsiDoAction(hpkg
, "SetProp");
7282 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7284 /* property is now set */
7286 lstrcpyA(buf
, "kiwi");
7287 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
7288 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7289 ok(!lstrcmpA(buf
, "grape"), "Expected \"grape\", got \"%s\"\n", buf
);
7290 ok(size
== 5, "Expected 5, got %d\n", size
);
7292 MsiCloseHandle(hpkg
);
7294 /* reset the package */
7295 r
= MsiOpenPackage(package
, &hpkg
);
7296 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7298 /* property is not set anymore */
7300 lstrcpyA(buf
, "kiwi");
7301 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
7302 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7305 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
7306 ok(size
== 0, "Expected 0, got %d\n", size
);
7309 MsiCloseHandle(hpkg
);
7312 MsiCloseHandle(hdb
);
7313 DeleteFileA(msifile
);
7316 static void test_droptable(void)
7318 MSIHANDLE hdb
, hview
, hrec
;
7324 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
7325 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7327 query
= "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7328 r
= run_query(hdb
, 0, query
);
7329 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7331 query
= "SELECT * FROM `One`";
7332 r
= do_query(hdb
, query
, &hrec
);
7333 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7335 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7336 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
7337 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7338 r
= MsiViewExecute(hview
, 0);
7339 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7341 r
= MsiViewFetch(hview
, &hrec
);
7342 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7345 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
7346 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7347 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
7349 MsiCloseHandle(hrec
);
7350 MsiViewClose(hview
);
7351 MsiCloseHandle(hview
);
7353 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7354 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
7355 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7356 r
= MsiViewExecute(hview
, 0);
7357 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7359 r
= MsiViewFetch(hview
, &hrec
);
7360 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7363 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
7364 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7365 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
7367 r
= MsiRecordGetInteger(hrec
, 2);
7368 ok(r
== 1, "Expected 1, got %d\n", r
);
7371 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
7372 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7373 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
7375 MsiCloseHandle(hrec
);
7377 r
= MsiViewFetch(hview
, &hrec
);
7378 ok(r
== ERROR_NO_MORE_ITEMS
,
7379 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7381 MsiViewClose(hview
);
7382 MsiCloseHandle(hview
);
7384 query
= "DROP `One`";
7385 r
= run_query(hdb
, 0, query
);
7386 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7387 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7389 query
= "DROP TABLE";
7390 r
= run_query(hdb
, 0, query
);
7391 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7392 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7394 query
= "DROP TABLE `One`";
7396 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
7397 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7398 r
= MsiViewExecute(hview
, 0);
7399 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7401 r
= MsiViewFetch(hview
, &hrec
);
7402 ok(r
== ERROR_FUNCTION_FAILED
,
7403 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
7405 MsiViewClose(hview
);
7406 MsiCloseHandle(hview
);
7408 query
= "SELECT * FROM `IDontExist`";
7409 r
= do_query(hdb
, query
, &hrec
);
7410 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7411 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7413 query
= "SELECT * FROM `One`";
7414 r
= do_query(hdb
, query
, &hrec
);
7415 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7416 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7418 query
= "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7419 r
= run_query(hdb
, 0, query
);
7420 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7422 query
= "DROP TABLE One";
7423 r
= run_query(hdb
, 0, query
);
7424 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7426 query
= "SELECT * FROM `One`";
7427 r
= do_query(hdb
, query
, &hrec
);
7428 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7429 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7431 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7432 r
= do_query(hdb
, query
, &hrec
);
7433 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7435 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7436 r
= do_query(hdb
, query
, &hrec
);
7437 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7439 query
= "CREATE TABLE `One` ( `B` INT, `C` INT PRIMARY KEY `B` )";
7440 r
= run_query(hdb
, 0, query
);
7441 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7443 query
= "SELECT * FROM `One`";
7444 r
= do_query(hdb
, query
, &hrec
);
7445 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7447 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7448 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
7449 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7450 r
= MsiViewExecute(hview
, 0);
7451 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7453 r
= MsiViewFetch(hview
, &hrec
);
7454 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7457 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
7458 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7459 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
7461 MsiCloseHandle(hrec
);
7462 MsiViewClose(hview
);
7463 MsiCloseHandle(hview
);
7465 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7466 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
7467 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7468 r
= MsiViewExecute(hview
, 0);
7469 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7471 r
= MsiViewFetch(hview
, &hrec
);
7472 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7475 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
7476 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7477 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
7479 r
= MsiRecordGetInteger(hrec
, 2);
7480 ok(r
== 1, "Expected 1, got %d\n", r
);
7483 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
7484 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7485 ok(!lstrcmpA(buf
, "B"), "Expected \"B\", got \"%s\"\n", buf
);
7487 MsiCloseHandle(hrec
);
7489 r
= MsiViewFetch(hview
, &hrec
);
7490 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7493 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
7494 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7495 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
7497 r
= MsiRecordGetInteger(hrec
, 2);
7498 ok(r
== 2, "Expected 2, got %d\n", r
);
7501 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
7502 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7503 ok(!lstrcmpA(buf
, "C"), "Expected \"C\", got \"%s\"\n", buf
);
7505 MsiCloseHandle(hrec
);
7507 r
= MsiViewFetch(hview
, &hrec
);
7508 ok(r
== ERROR_NO_MORE_ITEMS
,
7509 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7511 MsiViewClose(hview
);
7512 MsiCloseHandle(hview
);
7514 query
= "DROP TABLE One";
7515 r
= run_query(hdb
, 0, query
);
7516 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7518 query
= "SELECT * FROM `One`";
7519 r
= do_query(hdb
, query
, &hrec
);
7520 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7521 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7523 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
7524 r
= do_query(hdb
, query
, &hrec
);
7525 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7527 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
7528 r
= do_query(hdb
, query
, &hrec
);
7529 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
7531 MsiCloseHandle(hdb
);
7532 DeleteFileA(msifile
);
7535 static void test_dbmerge(void)
7537 MSIHANDLE hdb
, href
, hview
, hrec
;
7543 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
7544 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7546 r
= MsiOpenDatabase("refdb.msi", MSIDBOPEN_CREATE
, &href
);
7547 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7549 /* hDatabase is invalid */
7550 r
= MsiDatabaseMergeA(0, href
, "MergeErrors");
7551 ok(r
== ERROR_INVALID_HANDLE
,
7552 "Expected ERROR_INVALID_HANDLE, got %d\n", r
);
7554 /* hDatabaseMerge is invalid */
7555 r
= MsiDatabaseMergeA(hdb
, 0, "MergeErrors");
7556 ok(r
== ERROR_INVALID_HANDLE
,
7557 "Expected ERROR_INVALID_HANDLE, got %d\n", r
);
7559 /* szTableName is NULL */
7560 r
= MsiDatabaseMergeA(hdb
, href
, NULL
);
7561 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7563 /* szTableName is empty */
7564 r
= MsiDatabaseMergeA(hdb
, href
, "");
7565 ok(r
== ERROR_INVALID_TABLE
, "Expected ERROR_INVALID_TABLE, got %d\n", r
);
7567 /* both DBs empty, szTableName is valid */
7568 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7569 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7571 query
= "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
7572 r
= run_query(hdb
, 0, query
);
7573 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7575 query
= "CREATE TABLE `One` ( `A` CHAR(72) PRIMARY KEY `A` )";
7576 r
= run_query(href
, 0, query
);
7577 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7579 /* column types don't match */
7580 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7581 ok(r
== ERROR_DATATYPE_MISMATCH
,
7582 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
7584 /* nothing in MergeErrors */
7585 query
= "SELECT * FROM `MergeErrors`";
7586 r
= do_query(hdb
, query
, &hrec
);
7587 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7588 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7590 query
= "DROP TABLE `One`";
7591 r
= run_query(hdb
, 0, query
);
7592 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7594 query
= "DROP TABLE `One`";
7595 r
= run_query(href
, 0, query
);
7596 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7598 query
= "CREATE TABLE `One` ( "
7601 "`C` CHAR(64) LOCALIZABLE, "
7603 "`E` CHAR(72) NOT NULL, "
7604 "`F` CHAR(56) NOT NULL, "
7605 "`G` CHAR(64) NOT NULL LOCALIZABLE, "
7606 "`H` LONGCHAR NOT NULL "
7607 "PRIMARY KEY `A` )";
7608 r
= run_query(hdb
, 0, query
);
7609 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7611 query
= "CREATE TABLE `One` ( "
7616 "`E` CHAR(64) NOT NULL, "
7617 "`F` CHAR(64) NOT NULL, "
7618 "`G` CHAR(64) NOT NULL, "
7619 "`H` CHAR(64) NOT NULL "
7620 "PRIMARY KEY `A` )";
7621 r
= run_query(href
, 0, query
);
7622 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7624 /* column sting types don't match exactly */
7625 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7626 ok(r
== ERROR_SUCCESS
,
7627 "Expected ERROR_SUCCESS, got %d\n", r
);
7629 /* nothing in MergeErrors */
7630 query
= "SELECT * FROM `MergeErrors`";
7631 r
= do_query(hdb
, query
, &hrec
);
7632 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7633 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7635 query
= "DROP TABLE `One`";
7636 r
= run_query(hdb
, 0, query
);
7637 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7639 query
= "DROP TABLE `One`";
7640 r
= run_query(href
, 0, query
);
7641 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7643 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7644 r
= run_query(hdb
, 0, query
);
7645 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7647 query
= "CREATE TABLE `One` ( `A` INT, `C` INT PRIMARY KEY `A` )";
7648 r
= run_query(href
, 0, query
);
7649 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7651 /* column names don't match */
7652 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7653 ok(r
== ERROR_DATATYPE_MISMATCH
,
7654 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
7656 /* nothing in MergeErrors */
7657 query
= "SELECT * FROM `MergeErrors`";
7658 r
= do_query(hdb
, query
, &hrec
);
7659 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7660 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7662 query
= "DROP TABLE `One`";
7663 r
= run_query(hdb
, 0, query
);
7664 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7666 query
= "DROP TABLE `One`";
7667 r
= run_query(href
, 0, query
);
7668 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7670 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7671 r
= run_query(hdb
, 0, query
);
7672 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7674 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `B` )";
7675 r
= run_query(href
, 0, query
);
7676 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7678 /* primary keys don't match */
7679 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7680 ok(r
== ERROR_DATATYPE_MISMATCH
,
7681 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
7683 /* nothing in MergeErrors */
7684 query
= "SELECT * FROM `MergeErrors`";
7685 r
= do_query(hdb
, query
, &hrec
);
7686 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7687 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7689 query
= "DROP TABLE `One`";
7690 r
= run_query(hdb
, 0, query
);
7691 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7693 query
= "DROP TABLE `One`";
7694 r
= run_query(href
, 0, query
);
7695 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7697 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7698 r
= run_query(hdb
, 0, query
);
7699 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7701 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A`, `B` )";
7702 r
= run_query(href
, 0, query
);
7703 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7705 /* number of primary keys doesn't match */
7706 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7707 ok(r
== ERROR_DATATYPE_MISMATCH
,
7708 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
7710 /* nothing in MergeErrors */
7711 query
= "SELECT * FROM `MergeErrors`";
7712 r
= do_query(hdb
, query
, &hrec
);
7713 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7714 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7716 query
= "DROP TABLE `One`";
7717 r
= run_query(hdb
, 0, query
);
7718 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7720 query
= "DROP TABLE `One`";
7721 r
= run_query(href
, 0, query
);
7722 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7724 query
= "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
7725 r
= run_query(hdb
, 0, query
);
7726 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7728 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7729 r
= run_query(href
, 0, query
);
7730 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7732 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
7733 r
= run_query(href
, 0, query
);
7734 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7736 /* number of columns doesn't match */
7737 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7738 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7740 query
= "SELECT * FROM `One`";
7741 r
= do_query(hdb
, query
, &hrec
);
7742 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7744 r
= MsiRecordGetInteger(hrec
, 1);
7745 ok(r
== 1, "Expected 1, got %d\n", r
);
7747 r
= MsiRecordGetInteger(hrec
, 2);
7748 ok(r
== 2, "Expected 2, got %d\n", r
);
7750 r
= MsiRecordGetInteger(hrec
, 3);
7751 ok(r
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", r
);
7753 MsiCloseHandle(hrec
);
7755 /* nothing in MergeErrors */
7756 query
= "SELECT * FROM `MergeErrors`";
7757 r
= do_query(hdb
, query
, &hrec
);
7758 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7759 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7761 query
= "DROP TABLE `One`";
7762 r
= run_query(hdb
, 0, query
);
7763 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7765 query
= "DROP TABLE `One`";
7766 r
= run_query(href
, 0, query
);
7767 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7769 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7770 r
= run_query(hdb
, 0, query
);
7771 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7773 query
= "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
7774 r
= run_query(href
, 0, query
);
7775 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7777 query
= "INSERT INTO `One` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
7778 r
= run_query(href
, 0, query
);
7779 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7781 /* number of columns doesn't match */
7782 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7783 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7785 query
= "SELECT * FROM `One`";
7786 r
= do_query(hdb
, query
, &hrec
);
7787 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7789 r
= MsiRecordGetInteger(hrec
, 1);
7790 ok(r
== 1, "Expected 1, got %d\n", r
);
7792 r
= MsiRecordGetInteger(hrec
, 2);
7793 ok(r
== 2, "Expected 2, got %d\n", r
);
7795 r
= MsiRecordGetInteger(hrec
, 3);
7796 ok(r
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", r
);
7798 MsiCloseHandle(hrec
);
7800 /* nothing in MergeErrors */
7801 query
= "SELECT * FROM `MergeErrors`";
7802 r
= do_query(hdb
, query
, &hrec
);
7803 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7804 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7806 query
= "DROP TABLE `One`";
7807 r
= run_query(hdb
, 0, query
);
7808 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7810 query
= "DROP TABLE `One`";
7811 r
= run_query(href
, 0, query
);
7812 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7814 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7815 r
= run_query(hdb
, 0, query
);
7816 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7818 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 1 )";
7819 r
= run_query(hdb
, 0, query
);
7820 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7822 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 2 )";
7823 r
= run_query(hdb
, 0, query
);
7824 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7826 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
7827 r
= run_query(href
, 0, query
);
7828 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7830 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
7831 r
= run_query(href
, 0, query
);
7832 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7834 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 3 )";
7835 r
= run_query(href
, 0, query
);
7836 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7838 /* primary keys match, rows do not */
7839 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7840 ok(r
== ERROR_FUNCTION_FAILED
,
7841 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
7843 /* nothing in MergeErrors */
7844 query
= "SELECT * FROM `MergeErrors`";
7845 r
= do_query(hdb
, query
, &hrec
);
7846 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7849 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
7850 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7851 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
7853 r
= MsiRecordGetInteger(hrec
, 2);
7854 ok(r
== 2, "Expected 2, got %d\n", r
);
7856 MsiCloseHandle(hrec
);
7858 r
= MsiDatabaseOpenViewA(hdb
, "SELECT * FROM `MergeErrors`", &hview
);
7859 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7861 r
= MsiViewGetColumnInfo(hview
, MSICOLINFO_NAMES
, &hrec
);
7862 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7865 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
7866 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
7869 r
= MsiRecordGetString(hrec
, 2, buf
, &size
);
7870 ok(!lstrcmpA(buf
, "NumRowMergeConflicts"),
7871 "Expected \"NumRowMergeConflicts\", got \"%s\"\n", buf
);
7873 MsiCloseHandle(hrec
);
7875 r
= MsiViewGetColumnInfo(hview
, MSICOLINFO_TYPES
, &hrec
);
7876 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7879 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
7880 ok(!lstrcmpA(buf
, "s255"), "Expected \"s255\", got \"%s\"\n", buf
);
7883 r
= MsiRecordGetString(hrec
, 2, buf
, &size
);
7884 ok(!lstrcmpA(buf
, "i2"), "Expected \"i2\", got \"%s\"\n", buf
);
7886 MsiCloseHandle(hrec
);
7887 MsiViewClose(hview
);
7888 MsiCloseHandle(hview
);
7890 query
= "DROP TABLE `MergeErrors`";
7891 r
= run_query(hdb
, 0, query
);
7892 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7894 query
= "DROP TABLE `One`";
7895 r
= run_query(hdb
, 0, query
);
7896 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7898 query
= "DROP TABLE `One`";
7899 r
= run_query(href
, 0, query
);
7900 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7902 query
= "CREATE TABLE `One` ( `A` INT, `B` CHAR(72) PRIMARY KEY `A` )";
7903 r
= run_query(href
, 0, query
);
7904 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7906 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
7907 r
= run_query(href
, 0, query
);
7908 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7910 /* table from merged database is not in target database */
7911 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7912 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7914 query
= "SELECT * FROM `One`";
7915 r
= do_query(hdb
, query
, &hrec
);
7916 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7918 r
= MsiRecordGetInteger(hrec
, 1);
7919 ok(r
== 1, "Expected 1, got %d\n", r
);
7922 r
= MsiRecordGetStringA(hrec
, 2, buf
, &size
);
7923 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7924 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
7926 MsiCloseHandle(hrec
);
7928 /* nothing in MergeErrors */
7929 query
= "SELECT * FROM `MergeErrors`";
7930 r
= do_query(hdb
, query
, &hrec
);
7931 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7932 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7934 query
= "DROP TABLE `One`";
7935 r
= run_query(hdb
, 0, query
);
7936 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7938 query
= "DROP TABLE `One`";
7939 r
= run_query(href
, 0, query
);
7940 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7942 query
= "CREATE TABLE `One` ( "
7943 "`A` CHAR(72), `B` INT PRIMARY KEY `A` )";
7944 r
= run_query(hdb
, 0, query
);
7945 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7947 query
= "CREATE TABLE `One` ( "
7948 "`A` CHAR(72), `B` INT PRIMARY KEY `A` )";
7949 r
= run_query(href
, 0, query
);
7950 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7952 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 'hi', 1 )";
7953 r
= run_query(href
, 0, query
);
7954 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7956 /* primary key is string */
7957 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
7958 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7960 query
= "SELECT * FROM `One`";
7961 r
= do_query(hdb
, query
, &hrec
);
7962 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7965 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
7966 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7967 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
7969 r
= MsiRecordGetInteger(hrec
, 2);
7970 ok(r
== 1, "Expected 1, got %d\n", r
);
7972 MsiCloseHandle(hrec
);
7974 /* nothing in MergeErrors */
7975 query
= "SELECT * FROM `MergeErrors`";
7976 r
= do_query(hdb
, query
, &hrec
);
7977 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
7978 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
7980 create_file_data("codepage.idt", "\r\n\r\n850\t_ForceCodepage\r\n", 0);
7982 GetCurrentDirectoryA(MAX_PATH
, buf
);
7983 r
= MsiDatabaseImportA(hdb
, buf
, "codepage.idt");
7986 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7989 query
= "DROP TABLE `One`";
7990 r
= run_query(hdb
, 0, query
);
7991 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7993 query
= "DROP TABLE `One`";
7994 r
= run_query(href
, 0, query
);
7995 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
7997 query
= "CREATE TABLE `One` ( "
7998 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
7999 r
= run_query(hdb
, 0, query
);
8000 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8002 query
= "CREATE TABLE `One` ( "
8003 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
8004 r
= run_query(href
, 0, query
);
8005 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8007 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
8008 r
= run_query(href
, 0, query
);
8009 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8011 /* code page does not match */
8012 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
8013 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8015 query
= "SELECT * FROM `One`";
8016 r
= do_query(hdb
, query
, &hrec
);
8017 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8019 r
= MsiRecordGetInteger(hrec
, 1);
8020 ok(r
== 1, "Expected 1, got %d\n", r
);
8023 r
= MsiRecordGetStringA(hrec
, 2, buf
, &size
);
8024 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8025 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
8027 MsiCloseHandle(hrec
);
8029 /* nothing in MergeErrors */
8030 query
= "SELECT * FROM `MergeErrors`";
8031 r
= do_query(hdb
, query
, &hrec
);
8032 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
8033 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
8035 query
= "DROP TABLE `One`";
8036 r
= run_query(hdb
, 0, query
);
8037 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8039 query
= "DROP TABLE `One`";
8040 r
= run_query(href
, 0, query
);
8041 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8043 query
= "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
8044 r
= run_query(hdb
, 0, query
);
8045 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8047 query
= "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
8048 r
= run_query(href
, 0, query
);
8049 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8051 create_file("binary.dat");
8052 hrec
= MsiCreateRecord(1);
8053 MsiRecordSetStreamA(hrec
, 1, "binary.dat");
8055 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, ? )";
8056 r
= run_query(href
, hrec
, query
);
8057 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8059 MsiCloseHandle(hrec
);
8061 /* binary data to merge */
8062 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
8063 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8065 query
= "SELECT * FROM `One`";
8066 r
= do_query(hdb
, query
, &hrec
);
8067 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8069 r
= MsiRecordGetInteger(hrec
, 1);
8070 ok(r
== 1, "Expected 1, got %d\n", r
);
8073 ZeroMemory(buf
, MAX_PATH
);
8074 r
= MsiRecordReadStream(hrec
, 2, buf
, &size
);
8075 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8076 ok(!lstrcmpA(buf
, "binary.dat\n"),
8077 "Expected \"binary.dat\\n\", got \"%s\"\n", buf
);
8079 MsiCloseHandle(hrec
);
8081 /* nothing in MergeErrors */
8082 query
= "SELECT * FROM `MergeErrors`";
8083 r
= do_query(hdb
, query
, &hrec
);
8084 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
8085 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
8087 query
= "DROP TABLE `One`";
8088 r
= run_query(hdb
, 0, query
);
8089 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8091 query
= "DROP TABLE `One`";
8092 r
= run_query(href
, 0, query
);
8093 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8095 query
= "CREATE TABLE `One` ( `A` INT, `B` CHAR(72) PRIMARY KEY `A` )";
8096 r
= run_query(hdb
, 0, query
);
8097 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8098 r
= run_query(href
, 0, query
);
8099 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8101 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'foo' )";
8102 r
= run_query(href
, 0, query
);
8103 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8105 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 'bar' )";
8106 r
= run_query(href
, 0, query
);
8107 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8109 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
8110 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8112 query
= "SELECT * FROM `One`";
8113 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
8114 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8115 r
= MsiViewExecute(hview
, 0);
8116 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8118 r
= MsiViewFetch(hview
, &hrec
);
8119 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8121 r
= MsiRecordGetInteger(hrec
, 1);
8122 ok(r
== 1, "Expected 1, got %d\n", r
);
8125 r
= MsiRecordGetStringA(hrec
, 2, buf
, &size
);
8126 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8127 ok(!lstrcmpA(buf
, "foo"), "Expected \"foo\", got \"%s\"\n", buf
);
8129 MsiCloseHandle(hrec
);
8131 r
= MsiViewFetch(hview
, &hrec
);
8132 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8134 r
= MsiRecordGetInteger(hrec
, 1);
8135 ok(r
== 2, "Expected 2, got %d\n", r
);
8138 r
= MsiRecordGetStringA(hrec
, 2, buf
, &size
);
8139 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8140 ok(!lstrcmpA(buf
, "bar"), "Expected \"bar\", got \"%s\"\n", buf
);
8142 MsiCloseHandle(hrec
);
8144 r
= MsiViewFetch(hview
, &hrec
);
8145 ok(r
== ERROR_NO_MORE_ITEMS
,
8146 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
8148 MsiViewClose(hview
);
8149 MsiCloseHandle(hview
);
8151 MsiCloseHandle(hdb
);
8152 MsiCloseHandle(href
);
8153 DeleteFileA(msifile
);
8154 DeleteFileA("refdb.msi");
8155 DeleteFileA("codepage.idt");
8156 DeleteFileA("binary.dat");
8159 static void test_select_with_tablenames(void)
8161 MSIHANDLE hdb
, view
, rec
;
8173 ok(hdb
, "failed to create db\n");
8175 /* Build a pair of tables with the same column names, but unique data */
8176 query
= "CREATE TABLE `T1` ( `A` SHORT, `B` SHORT PRIMARY KEY `A`)";
8177 r
= run_query(hdb
, 0, query
);
8178 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8180 query
= "INSERT INTO `T1` ( `A`, `B` ) VALUES ( 1, 2 )";
8181 r
= run_query(hdb
, 0, query
);
8182 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8184 query
= "INSERT INTO `T1` ( `A`, `B` ) VALUES ( 4, 5 )";
8185 r
= run_query(hdb
, 0, query
);
8186 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8188 query
= "CREATE TABLE `T2` ( `A` SHORT, `B` SHORT PRIMARY KEY `A`)";
8189 r
= run_query(hdb
, 0, query
);
8190 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8192 query
= "INSERT INTO `T2` ( `A`, `B` ) VALUES ( 11, 12 )";
8193 r
= run_query(hdb
, 0, query
);
8194 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8196 query
= "INSERT INTO `T2` ( `A`, `B` ) VALUES ( 14, 15 )";
8197 r
= run_query(hdb
, 0, query
);
8198 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8201 /* Test that selection based on prefixing the column with the table
8202 * actually selects the right data */
8204 query
= "SELECT T1.A, T2.B FROM T1,T2";
8205 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
8206 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8207 r
= MsiViewExecute(view
, 0);
8208 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8210 for (i
= 0; i
< 4; i
++)
8212 r
= MsiViewFetch(view
, &rec
);
8213 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8215 r
= MsiRecordGetInteger(rec
, 1);
8216 ok(r
== vals
[i
][0], "Expected %d, got %d\n", vals
[i
][0], r
);
8218 r
= MsiRecordGetInteger(rec
, 2);
8219 ok(r
== vals
[i
][1], "Expected %d, got %d\n", vals
[i
][1], r
);
8221 MsiCloseHandle(rec
);
8224 r
= MsiViewFetch(view
, &rec
);
8225 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
8228 MsiCloseHandle(view
);
8229 MsiCloseHandle(hdb
);
8230 DeleteFileA(msifile
);
8233 UINT ordervals
[6][3] =
8235 { MSI_NULL_INTEGER
, 12, 13 },
8239 { 10, 11, MSI_NULL_INTEGER
},
8240 { 14, MSI_NULL_INTEGER
, 15 }
8243 static void test_insertorder(void)
8245 MSIHANDLE hdb
, view
, rec
;
8251 ok(hdb
, "failed to create db\n");
8253 query
= "CREATE TABLE `T` ( `A` SHORT, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
8254 r
= run_query(hdb
, 0, query
);
8255 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8257 query
= "INSERT INTO `T` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
8258 r
= run_query(hdb
, 0, query
);
8259 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8261 query
= "INSERT INTO `T` ( `B`, `C`, `A` ) VALUES ( 4, 5, 6 )";
8262 r
= run_query(hdb
, 0, query
);
8263 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8265 query
= "INSERT INTO `T` ( `C`, `A`, `B` ) VALUES ( 7, 8, 9 )";
8266 r
= run_query(hdb
, 0, query
);
8267 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8269 query
= "INSERT INTO `T` ( `A`, `B` ) VALUES ( 10, 11 )";
8270 r
= run_query(hdb
, 0, query
);
8271 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8273 query
= "INSERT INTO `T` ( `B`, `C` ) VALUES ( 12, 13 )";
8274 r
= run_query(hdb
, 0, query
);
8275 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8277 /* fails because the primary key already
8278 * has an MSI_NULL_INTEGER value set above
8280 query
= "INSERT INTO `T` ( `C` ) VALUES ( 14 )";
8281 r
= run_query(hdb
, 0, query
);
8282 ok(r
== ERROR_FUNCTION_FAILED
,
8283 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
8285 /* replicate the error where primary key is set twice */
8286 query
= "INSERT INTO `T` ( `A`, `C` ) VALUES ( 1, 14 )";
8287 r
= run_query(hdb
, 0, query
);
8288 ok(r
== ERROR_FUNCTION_FAILED
,
8289 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
8291 query
= "INSERT INTO `T` ( `A`, `C` ) VALUES ( 14, 15 )";
8292 r
= run_query(hdb
, 0, query
);
8293 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8295 query
= "INSERT INTO `T` VALUES ( 16 )";
8296 r
= run_query(hdb
, 0, query
);
8297 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
8298 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
8300 query
= "INSERT INTO `T` VALUES ( 17, 18 )";
8301 r
= run_query(hdb
, 0, query
);
8302 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
8303 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
8305 query
= "INSERT INTO `T` VALUES ( 19, 20, 21 )";
8306 r
= run_query(hdb
, 0, query
);
8307 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
8308 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
8310 query
= "SELECT * FROM `T`";
8311 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
8312 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8313 r
= MsiViewExecute(view
, 0);
8314 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8316 for (i
= 0; i
< 6; i
++)
8318 r
= MsiViewFetch(view
, &rec
);
8319 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8321 r
= MsiRecordGetInteger(rec
, 1);
8322 ok(r
== ordervals
[i
][0], "Expected %d, got %d\n", ordervals
[i
][0], r
);
8324 r
= MsiRecordGetInteger(rec
, 2);
8325 ok(r
== ordervals
[i
][1], "Expected %d, got %d\n", ordervals
[i
][1], r
);
8327 r
= MsiRecordGetInteger(rec
, 3);
8328 ok(r
== ordervals
[i
][2], "Expected %d, got %d\n", ordervals
[i
][2], r
);
8330 MsiCloseHandle(rec
);
8333 r
= MsiViewFetch(view
, &rec
);
8334 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
8337 MsiCloseHandle(view
);
8339 query
= "DELETE FROM `T` WHERE `A` IS NULL";
8340 r
= run_query(hdb
, 0, query
);
8341 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8343 query
= "INSERT INTO `T` ( `B`, `C` ) VALUES ( 12, 13 ) TEMPORARY";
8344 r
= run_query(hdb
, 0, query
);
8345 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8347 query
= "SELECT * FROM `T`";
8348 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
8349 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8350 r
= MsiViewExecute(view
, 0);
8351 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8353 for (i
= 0; i
< 6; i
++)
8355 r
= MsiViewFetch(view
, &rec
);
8356 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8358 r
= MsiRecordGetInteger(rec
, 1);
8359 ok(r
== ordervals
[i
][0], "Expected %d, got %d\n", ordervals
[i
][0], r
);
8361 r
= MsiRecordGetInteger(rec
, 2);
8362 ok(r
== ordervals
[i
][1], "Expected %d, got %d\n", ordervals
[i
][1], r
);
8364 r
= MsiRecordGetInteger(rec
, 3);
8365 ok(r
== ordervals
[i
][2], "Expected %d, got %d\n", ordervals
[i
][2], r
);
8367 MsiCloseHandle(rec
);
8370 r
= MsiViewFetch(view
, &rec
);
8371 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
8374 MsiCloseHandle(view
);
8375 MsiCloseHandle(hdb
);
8376 DeleteFileA(msifile
);
8379 static void test_columnorder(void)
8381 MSIHANDLE hdb
, view
, rec
;
8388 ok(hdb
, "failed to create db\n");
8390 /* Each column is a slot:
8391 * ---------------------
8392 * | B | C | A | E | D |
8393 * ---------------------
8395 * When a column is selected as a primary key,
8396 * the column occupying the nth primary key slot is swapped
8397 * with the current position of the primary key in question:
8399 * set primary key `D`
8400 * --------------------- ---------------------
8401 * | B | C | A | E | D | -> | D | C | A | E | B |
8402 * --------------------- ---------------------
8404 * set primary key `E`
8405 * --------------------- ---------------------
8406 * | D | C | A | E | B | -> | D | E | A | C | B |
8407 * --------------------- ---------------------
8410 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL, `C` SHORT NOT NULL, "
8411 "`A` CHAR(255), `E` INT, `D` CHAR(255) NOT NULL "
8412 "PRIMARY KEY `D`, `E`)";
8413 r
= run_query(hdb
, 0, query
);
8414 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8416 query
= "SELECT * FROM `T`";
8417 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
8418 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8420 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
8421 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8424 lstrcpyA(buf
, "kiwi");
8425 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8426 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8427 ok(!lstrcmpA("s255", buf
), "Expected \"s255\", got \"%s\"\n", buf
);
8430 lstrcpyA(buf
, "kiwi");
8431 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
8432 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8433 ok(!lstrcmpA("I2", buf
), "Expected \"I2\", got \"%s\"\n", buf
);
8436 lstrcpyA(buf
, "kiwi");
8437 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8438 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8439 ok(!lstrcmpA("S255", buf
), "Expected \"S255\", got \"%s\"\n", buf
);
8442 lstrcpyA(buf
, "kiwi");
8443 r
= MsiRecordGetString(rec
, 4, buf
, &sz
);
8444 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8445 ok(!lstrcmpA("i2", buf
), "Expected \"i2\", got \"%s\"\n", buf
);
8448 lstrcpyA(buf
, "kiwi");
8449 r
= MsiRecordGetString(rec
, 5, buf
, &sz
);
8450 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8451 ok(!lstrcmpA("i2", buf
), "Expected \"i2\", got \"%s\"\n", buf
);
8453 MsiCloseHandle(rec
);
8455 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
8456 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8459 lstrcpyA(buf
, "kiwi");
8460 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8461 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8462 ok(!lstrcmpA("D", buf
), "Expected \"D\", got \"%s\"\n", buf
);
8465 lstrcpyA(buf
, "kiwi");
8466 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
8467 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8468 ok(!lstrcmpA("E", buf
), "Expected \"E\", got \"%s\"\n", buf
);
8471 lstrcpyA(buf
, "kiwi");
8472 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8473 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8474 ok(!lstrcmpA("A", buf
), "Expected \"A\", got \"%s\"\n", buf
);
8477 lstrcpyA(buf
, "kiwi");
8478 r
= MsiRecordGetString(rec
, 4, buf
, &sz
);
8479 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8480 ok(!lstrcmpA("C", buf
), "Expected \"C\", got \"%s\"\n", buf
);
8483 lstrcpyA(buf
, "kiwi");
8484 r
= MsiRecordGetString(rec
, 5, buf
, &sz
);
8485 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8486 ok(!lstrcmpA("B", buf
), "Expected \"B\", got \"%s\"\n", buf
);
8488 MsiCloseHandle(rec
);
8490 MsiCloseHandle(view
);
8492 query
= "INSERT INTO `T` ( `B`, `C`, `A`, `E`, `D` ) "
8493 "VALUES ( 1, 2, 'a', 3, 'bc' )";
8494 r
= run_query(hdb
, 0, query
);
8495 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8497 query
= "SELECT * FROM `T`";
8498 r
= do_query(hdb
, query
, &rec
);
8501 lstrcpyA(buf
, "kiwi");
8502 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8503 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8504 ok(!lstrcmpA("bc", buf
), "Expected \"bc\", got \"%s\"\n", buf
);
8506 r
= MsiRecordGetInteger(rec
, 2);
8507 ok(r
== 3, "Expected 3, got %d\n", r
);
8510 lstrcpyA(buf
, "kiwi");
8511 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8512 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8513 ok(!lstrcmpA("a", buf
), "Expected \"a\", got \"%s\"\n", buf
);
8515 r
= MsiRecordGetInteger(rec
, 4);
8516 ok(r
== 2, "Expected 2, got %d\n", r
);
8518 r
= MsiRecordGetInteger(rec
, 5);
8519 ok(r
== 1, "Expected 1, got %d\n", r
);
8521 MsiCloseHandle(rec
);
8523 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'T'";
8524 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
8525 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8526 r
= MsiViewExecute(view
, 0);
8527 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8529 r
= MsiViewFetch(view
, &rec
);
8530 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8533 lstrcpyA(buf
, "kiwi");
8534 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8535 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8536 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8538 r
= MsiRecordGetInteger(rec
, 2);
8539 ok(r
== 1, "Expected 1, got %d\n", r
);
8542 lstrcpyA(buf
, "kiwi");
8543 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8544 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8545 ok(!lstrcmpA("D", buf
), "Expected \"D\", got \"%s\"\n", buf
);
8547 MsiCloseHandle(rec
);
8549 r
= MsiViewFetch(view
, &rec
);
8550 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8553 lstrcpyA(buf
, "kiwi");
8554 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8555 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8556 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8558 r
= MsiRecordGetInteger(rec
, 2);
8559 ok(r
== 2, "Expected 2, got %d\n", r
);
8562 lstrcpyA(buf
, "kiwi");
8563 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8564 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8565 ok(!lstrcmpA("E", buf
), "Expected \"E\", got \"%s\"\n", buf
);
8567 MsiCloseHandle(rec
);
8569 r
= MsiViewFetch(view
, &rec
);
8570 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8573 lstrcpyA(buf
, "kiwi");
8574 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8575 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8576 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8578 r
= MsiRecordGetInteger(rec
, 2);
8579 ok(r
== 3, "Expected 3, got %d\n", r
);
8582 lstrcpyA(buf
, "kiwi");
8583 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8584 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8585 ok(!lstrcmpA("A", buf
), "Expected \"A\", got \"%s\"\n", buf
);
8587 MsiCloseHandle(rec
);
8589 r
= MsiViewFetch(view
, &rec
);
8590 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8593 lstrcpyA(buf
, "kiwi");
8594 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8595 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8596 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8598 r
= MsiRecordGetInteger(rec
, 2);
8599 ok(r
== 4, "Expected 4, got %d\n", r
);
8602 lstrcpyA(buf
, "kiwi");
8603 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8604 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8605 ok(!lstrcmpA("C", buf
), "Expected \"C\", got \"%s\"\n", buf
);
8607 MsiCloseHandle(rec
);
8609 r
= MsiViewFetch(view
, &rec
);
8610 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8613 lstrcpyA(buf
, "kiwi");
8614 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8615 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8616 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8618 r
= MsiRecordGetInteger(rec
, 2);
8619 ok(r
== 5, "Expected 5, got %d\n", r
);
8622 lstrcpyA(buf
, "kiwi");
8623 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8624 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8625 ok(!lstrcmpA("B", buf
), "Expected \"B\", got \"%s\"\n", buf
);
8627 MsiCloseHandle(rec
);
8629 r
= MsiViewFetch(view
, &rec
);
8630 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
8633 MsiCloseHandle(view
);
8635 query
= "CREATE TABLE `Z` ( `B` SHORT NOT NULL, `C` SHORT NOT NULL, "
8636 "`A` CHAR(255), `E` INT, `D` CHAR(255) NOT NULL "
8637 "PRIMARY KEY `C`, `A`, `D`)";
8638 r
= run_query(hdb
, 0, query
);
8639 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8641 query
= "SELECT * FROM `Z`";
8642 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
8643 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8645 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
8646 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8649 lstrcpyA(buf
, "kiwi");
8650 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8651 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8652 ok(!lstrcmpA("i2", buf
), "Expected \"i2\", got \"%s\"\n", buf
);
8655 lstrcpyA(buf
, "kiwi");
8656 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
8657 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8658 ok(!lstrcmpA("S255", buf
), "Expected \"S255\", got \"%s\"\n", buf
);
8661 lstrcpyA(buf
, "kiwi");
8662 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8663 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8664 ok(!lstrcmpA("s255", buf
), "Expected \"s255\", got \"%s\"\n", buf
);
8667 lstrcpyA(buf
, "kiwi");
8668 r
= MsiRecordGetString(rec
, 4, buf
, &sz
);
8669 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8670 ok(!lstrcmpA("I2", buf
), "Expected \"I2\", got \"%s\"\n", buf
);
8673 lstrcpyA(buf
, "kiwi");
8674 r
= MsiRecordGetString(rec
, 5, buf
, &sz
);
8675 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8676 ok(!lstrcmpA("i2", buf
), "Expected \"i2\", got \"%s\"\n", buf
);
8678 MsiCloseHandle(rec
);
8680 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
8681 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8684 lstrcpyA(buf
, "kiwi");
8685 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8686 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8687 ok(!lstrcmpA("C", buf
), "Expected \"C\", got \"%s\"\n", buf
);
8690 lstrcpyA(buf
, "kiwi");
8691 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
8692 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8693 ok(!lstrcmpA("A", buf
), "Expected \"A\", got \"%s\"\n", buf
);
8696 lstrcpyA(buf
, "kiwi");
8697 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8698 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8699 ok(!lstrcmpA("D", buf
), "Expected \"D\", got \"%s\"\n", buf
);
8702 lstrcpyA(buf
, "kiwi");
8703 r
= MsiRecordGetString(rec
, 4, buf
, &sz
);
8704 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8705 ok(!lstrcmpA("E", buf
), "Expected \"E\", got \"%s\"\n", buf
);
8708 lstrcpyA(buf
, "kiwi");
8709 r
= MsiRecordGetString(rec
, 5, buf
, &sz
);
8710 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8711 ok(!lstrcmpA("B", buf
), "Expected \"B\", got \"%s\"\n", buf
);
8713 MsiCloseHandle(rec
);
8715 MsiCloseHandle(view
);
8717 query
= "INSERT INTO `Z` ( `B`, `C`, `A`, `E`, `D` ) "
8718 "VALUES ( 1, 2, 'a', 3, 'bc' )";
8719 r
= run_query(hdb
, 0, query
);
8720 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8722 query
= "SELECT * FROM `Z`";
8723 r
= do_query(hdb
, query
, &rec
);
8725 r
= MsiRecordGetInteger(rec
, 1);
8726 ok(r
== 2, "Expected 2, got %d\n", r
);
8729 lstrcpyA(buf
, "kiwi");
8730 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
8731 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8732 ok(!lstrcmpA("a", buf
), "Expected \"a\", got \"%s\"\n", buf
);
8735 lstrcpyA(buf
, "kiwi");
8736 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8737 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8738 ok(!lstrcmpA("bc", buf
), "Expected \"bc\", got \"%s\"\n", buf
);
8740 r
= MsiRecordGetInteger(rec
, 4);
8741 ok(r
== 3, "Expected 3, got %d\n", r
);
8743 r
= MsiRecordGetInteger(rec
, 5);
8744 ok(r
== 1, "Expected 1, got %d\n", r
);
8746 MsiCloseHandle(rec
);
8748 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'T'";
8749 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
8750 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8751 r
= MsiViewExecute(view
, 0);
8752 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8754 r
= MsiViewFetch(view
, &rec
);
8755 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8758 lstrcpyA(buf
, "kiwi");
8759 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8760 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8761 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8763 r
= MsiRecordGetInteger(rec
, 2);
8764 ok(r
== 1, "Expected 1, got %d\n", r
);
8767 lstrcpyA(buf
, "kiwi");
8768 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8769 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8770 ok(!lstrcmpA("D", buf
), "Expected \"D\", got \"%s\"\n", buf
);
8772 MsiCloseHandle(rec
);
8774 r
= MsiViewFetch(view
, &rec
);
8775 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8778 lstrcpyA(buf
, "kiwi");
8779 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8780 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8781 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8783 r
= MsiRecordGetInteger(rec
, 2);
8784 ok(r
== 2, "Expected 2, got %d\n", r
);
8787 lstrcpyA(buf
, "kiwi");
8788 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8789 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8790 ok(!lstrcmpA("E", buf
), "Expected \"E\", got \"%s\"\n", buf
);
8792 MsiCloseHandle(rec
);
8794 r
= MsiViewFetch(view
, &rec
);
8795 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8798 lstrcpyA(buf
, "kiwi");
8799 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8800 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8801 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8803 r
= MsiRecordGetInteger(rec
, 2);
8804 ok(r
== 3, "Expected 3, got %d\n", r
);
8807 lstrcpyA(buf
, "kiwi");
8808 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8809 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8810 ok(!lstrcmpA("A", buf
), "Expected \"A\", got \"%s\"\n", buf
);
8812 MsiCloseHandle(rec
);
8814 r
= MsiViewFetch(view
, &rec
);
8815 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8818 lstrcpyA(buf
, "kiwi");
8819 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8820 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8821 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8823 r
= MsiRecordGetInteger(rec
, 2);
8824 ok(r
== 4, "Expected 4, got %d\n", r
);
8827 lstrcpyA(buf
, "kiwi");
8828 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8829 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8830 ok(!lstrcmpA("C", buf
), "Expected \"C\", got \"%s\"\n", buf
);
8832 MsiCloseHandle(rec
);
8834 r
= MsiViewFetch(view
, &rec
);
8835 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8838 lstrcpyA(buf
, "kiwi");
8839 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
8840 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8841 ok(!lstrcmpA("T", buf
), "Expected \"T\", got \"%s\"\n", buf
);
8843 r
= MsiRecordGetInteger(rec
, 2);
8844 ok(r
== 5, "Expected 5, got %d\n", r
);
8847 lstrcpyA(buf
, "kiwi");
8848 r
= MsiRecordGetString(rec
, 3, buf
, &sz
);
8849 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
8850 ok(!lstrcmpA("B", buf
), "Expected \"B\", got \"%s\"\n", buf
);
8852 MsiCloseHandle(rec
);
8854 r
= MsiViewFetch(view
, &rec
);
8855 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
8858 MsiCloseHandle(view
);
8860 MsiCloseHandle(hdb
);
8861 DeleteFileA(msifile
);
8864 static void test_createtable(void)
8866 MSIHANDLE hdb
, htab
= 0, hrec
= 0;
8873 ok(hdb
, "failed to create db\n");
8875 query
= "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL PRIMARY KEY `foo`)";
8876 res
= MsiDatabaseOpenView( hdb
, query
, &htab
);
8877 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8878 if(res
== ERROR_SUCCESS
)
8880 res
= MsiViewExecute( htab
, hrec
);
8881 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8883 res
= MsiViewGetColumnInfo( htab
, MSICOLINFO_NAMES
, &hrec
);
8884 todo_wine
ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8886 size
= sizeof(buffer
);
8887 res
= MsiRecordGetString(hrec
, 1, buffer
, &size
);
8888 todo_wine
ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8889 MsiCloseHandle( hrec
);
8891 res
= MsiViewClose( htab
);
8892 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8894 res
= MsiCloseHandle( htab
);
8895 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8898 query
= "CREATE TABLE `a` (`b` INT PRIMARY KEY `b`)";
8899 res
= MsiDatabaseOpenView( hdb
, query
, &htab
);
8900 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8901 if(res
== ERROR_SUCCESS
)
8903 res
= MsiViewExecute( htab
, 0 );
8904 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8906 res
= MsiViewClose( htab
);
8907 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8909 res
= MsiCloseHandle( htab
);
8910 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8912 query
= "SELECT * FROM `a`";
8913 res
= MsiDatabaseOpenView( hdb
, query
, &htab
);
8914 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8916 res
= MsiViewGetColumnInfo( htab
, MSICOLINFO_NAMES
, &hrec
);
8917 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8920 size
= sizeof(buffer
);
8921 res
= MsiRecordGetString(hrec
, 1, buffer
, &size
);
8922 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8923 ok(!strcmp(buffer
,"b"), "b != %s\n", buffer
);
8924 MsiCloseHandle( hrec
);
8926 res
= MsiViewClose( htab
);
8927 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8929 res
= MsiCloseHandle( htab
);
8930 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8932 res
= MsiDatabaseCommit(hdb
);
8933 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8935 res
= MsiCloseHandle(hdb
);
8936 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8938 res
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
8939 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8941 query
= "SELECT * FROM `a`";
8942 res
= MsiDatabaseOpenView( hdb
, query
, &htab
);
8943 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8945 res
= MsiViewGetColumnInfo( htab
, MSICOLINFO_NAMES
, &hrec
);
8946 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8949 size
= sizeof(buffer
);
8950 res
= MsiRecordGetString(hrec
, 1, buffer
, &size
);
8951 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8952 todo_wine
ok(!strcmp(buffer
,"b"), "b != %s\n", buffer
);
8954 res
= MsiCloseHandle( hrec
);
8955 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8957 res
= MsiViewClose( htab
);
8958 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8960 res
= MsiCloseHandle( htab
);
8961 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8964 res
= MsiDatabaseCommit(hdb
);
8965 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8967 res
= MsiCloseHandle(hdb
);
8968 ok(res
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", res
);
8970 DeleteFileA(msifile
);
8978 test_msidecomposedesc();
8979 test_msibadqueries();
8981 test_viewgetcolumninfo();
8987 test_where_not_in_selected();
8990 test_binary_import();
8992 test_handle_limit();
8993 test_try_transform();
8995 test_temporary_table();
8999 test_special_tables();
9000 test_tables_order();
9002 test_select_markers();
9003 test_viewmodify_update();
9004 test_viewmodify_assign();
9006 test_viewmodify_delete();
9007 test_defaultdatabase();
9009 test_viewmodify_delete_temporary();
9012 test_carriagereturn();
9014 test_forcecodepage();
9015 test_viewmodify_refresh();
9016 test_where_viewmodify();
9017 test_storages_table();
9021 test_select_with_tablenames();
9024 test_suminfo_import();