2 * Copyright (C) 2005 Mike McCormack for CodeWeavers
4 * A test program for MSI database files.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/test.h"
33 static const char *msifile
= "winetest.msi";
34 static const char *msifile2
= "winetst2.msi";
35 static const char *mstfile
= "winetst.mst";
37 static void test_msidatabase(void)
39 MSIHANDLE hdb
= 0, hdb2
= 0;
44 res
= MsiOpenDatabase( msifile
, msifile2
, &hdb
);
45 ok( res
== ERROR_OPEN_FAILED
, "expected failure\n");
47 res
= MsiOpenDatabase( msifile
, (LPSTR
) 0xff, &hdb
);
48 ok( res
== ERROR_INVALID_PARAMETER
, "expected failure\n");
50 res
= MsiCloseHandle( hdb
);
51 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
53 /* create an empty database */
54 res
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
55 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
57 res
= MsiDatabaseCommit( hdb
);
58 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
60 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile
), "database should exist\n");
62 res
= MsiCloseHandle( hdb
);
63 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
64 res
= MsiOpenDatabase( msifile
, msifile2
, &hdb2
);
65 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
67 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile2
), "database should exist\n");
69 res
= MsiDatabaseCommit( hdb2
);
70 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
72 res
= MsiCloseHandle( hdb2
);
73 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
75 res
= MsiOpenDatabase( msifile
, msifile2
, &hdb2
);
76 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
78 res
= MsiCloseHandle( hdb2
);
79 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
81 ok( INVALID_FILE_ATTRIBUTES
== GetFileAttributes( msifile2
), "uncommitted database should not exist\n");
83 res
= MsiOpenDatabase( msifile
, msifile2
, &hdb2
);
84 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
86 res
= MsiDatabaseCommit( hdb2
);
87 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
89 res
= MsiCloseHandle( hdb2
);
90 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
92 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile2
), "committed database should exist\n");
94 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_READONLY
, &hdb
);
95 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
97 res
= MsiCloseHandle( hdb
);
98 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
100 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_DIRECT
, &hdb
);
101 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
103 res
= MsiCloseHandle( hdb
);
104 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
106 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
107 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
109 res
= MsiCloseHandle( hdb
);
110 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
111 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile
), "database should exist\n");
113 /* MSIDBOPEN_CREATE deletes the database if MsiCommitDatabase isn't called */
114 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_CREATE
, &hdb
);
115 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
117 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile
), "database should exist\n");
119 res
= MsiCloseHandle( hdb
);
120 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
122 ok( INVALID_FILE_ATTRIBUTES
== GetFileAttributes( msifile
), "database should exist\n");
124 res
= MsiOpenDatabase( msifile
, MSIDBOPEN_CREATE
, &hdb
);
125 ok( res
== ERROR_SUCCESS
, "Failed to open database\n" );
127 res
= MsiDatabaseCommit( hdb
);
128 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
130 ok( INVALID_FILE_ATTRIBUTES
!= GetFileAttributes( msifile
), "database should exist\n");
132 res
= MsiCloseHandle( hdb
);
133 ok( res
== ERROR_SUCCESS
, "Failed to close database\n" );
135 res
= DeleteFile( msifile2
);
136 ok( res
== TRUE
, "Failed to delete database\n" );
138 res
= DeleteFile( msifile
);
139 ok( res
== TRUE
, "Failed to delete database\n" );
142 static UINT
do_query(MSIHANDLE hdb
, const char *query
, MSIHANDLE
*phrec
)
150 /* open a select query */
151 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
152 if (r
!= ERROR_SUCCESS
)
154 r
= MsiViewExecute(hview
, 0);
155 if (r
!= ERROR_SUCCESS
)
157 ret
= MsiViewFetch(hview
, phrec
);
158 r
= MsiViewClose(hview
);
159 if (r
!= ERROR_SUCCESS
)
161 r
= MsiCloseHandle(hview
);
162 if (r
!= ERROR_SUCCESS
)
167 static UINT
run_query( MSIHANDLE hdb
, MSIHANDLE hrec
, const char *query
)
172 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
173 if( r
!= ERROR_SUCCESS
)
176 r
= MsiViewExecute(hview
, hrec
);
177 if( r
== ERROR_SUCCESS
)
178 r
= MsiViewClose(hview
);
179 MsiCloseHandle(hview
);
183 static UINT
create_component_table( MSIHANDLE hdb
)
185 return run_query( hdb
, 0,
186 "CREATE TABLE `Component` ( "
187 "`Component` CHAR(72) NOT NULL, "
188 "`ComponentId` CHAR(38), "
189 "`Directory_` CHAR(72) NOT NULL, "
190 "`Attributes` SHORT NOT NULL, "
191 "`Condition` CHAR(255), "
192 "`KeyPath` CHAR(72) "
193 "PRIMARY KEY `Component`)" );
196 static UINT
create_custom_action_table( MSIHANDLE hdb
)
198 return run_query( hdb
, 0,
199 "CREATE TABLE `CustomAction` ( "
200 "`Action` CHAR(72) NOT NULL, "
201 "`Type` SHORT NOT NULL, "
202 "`Source` CHAR(72), "
203 "`Target` CHAR(255) "
204 "PRIMARY KEY `Action`)" );
207 static UINT
create_directory_table( MSIHANDLE hdb
)
209 return run_query( hdb
, 0,
210 "CREATE TABLE `Directory` ( "
211 "`Directory` CHAR(255) NOT NULL, "
212 "`Directory_Parent` CHAR(255), "
213 "`DefaultDir` CHAR(255) NOT NULL "
214 "PRIMARY KEY `Directory`)" );
217 static UINT
create_feature_components_table( MSIHANDLE hdb
)
219 return run_query( hdb
, 0,
220 "CREATE TABLE `FeatureComponents` ( "
221 "`Feature_` CHAR(38) NOT NULL, "
222 "`Component_` CHAR(72) NOT NULL "
223 "PRIMARY KEY `Feature_`, `Component_` )" );
226 static UINT
create_std_dlls_table( MSIHANDLE hdb
)
228 return run_query( hdb
, 0,
229 "CREATE TABLE `StdDlls` ( "
230 "`File` CHAR(255) NOT NULL, "
231 "`Binary_` CHAR(72) NOT NULL "
232 "PRIMARY KEY `File` )" );
235 static UINT
create_binary_table( MSIHANDLE hdb
)
237 return run_query( hdb
, 0,
238 "CREATE TABLE `Binary` ( "
239 "`Name` CHAR(72) NOT NULL, "
240 "`Data` CHAR(72) NOT NULL "
241 "PRIMARY KEY `Name` )" );
244 #define make_add_entry(type, qtext) \
245 static UINT add##_##type##_##entry( MSIHANDLE hdb, const char *values ) \
247 char insert[] = qtext; \
250 sz = strlen(values) + sizeof insert; \
251 query = HeapAlloc(GetProcessHeap(),0,sz); \
252 sprintf(query,insert,values); \
253 r = run_query( hdb, 0, query ); \
254 HeapFree(GetProcessHeap(), 0, query); \
258 make_add_entry(component
,
259 "INSERT INTO `Component` "
260 "(`Component`, `ComponentId`, `Directory_`, "
261 "`Attributes`, `Condition`, `KeyPath`) VALUES( %s )")
263 make_add_entry(custom_action
,
264 "INSERT INTO `CustomAction` "
265 "(`Action`, `Type`, `Source`, `Target`) VALUES( %s )")
267 make_add_entry(feature_components
,
268 "INSERT INTO `FeatureComponents` "
269 "(`Feature_`, `Component_`) VALUES( %s )")
271 make_add_entry(std_dlls
,
272 "INSERT INTO `StdDlls` (`File`, `Binary_`) VALUES( %s )")
274 make_add_entry(binary
,
275 "INSERT INTO `Binary` (`Name`, `Data`) VALUES( %s )")
277 static void test_msiinsert(void)
279 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
287 /* just MsiOpenDatabase should not create a file */
288 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
289 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
292 query
= "CREATE TABLE `phone` ( "
293 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
295 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
296 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
297 r
= MsiViewExecute(hview
, 0);
298 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
299 r
= MsiViewClose(hview
);
300 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
301 r
= MsiCloseHandle(hview
);
302 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
304 /* insert a value into it */
305 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
306 "VALUES('1', 'Abe', '8675309')";
307 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
308 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
309 r
= MsiViewExecute(hview
, 0);
310 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
311 r
= MsiViewClose(hview
);
312 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
313 r
= MsiCloseHandle(hview
);
314 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
316 query
= "SELECT * FROM `phone` WHERE `id` = 1";
317 r
= do_query(hdb
, query
, &hrec
);
318 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
320 /* check the record contains what we put in it */
321 r
= MsiRecordGetFieldCount(hrec
);
322 ok(r
== 3, "record count wrong\n");
325 r
= MsiRecordIsNull(hrec
, 0);
326 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");
484 static UINT
try_query_param( MSIHANDLE hdb
, LPCSTR szQuery
, MSIHANDLE hrec
)
489 res
= MsiDatabaseOpenView( hdb
, szQuery
, &htab
);
490 if(res
== ERROR_SUCCESS
)
494 r
= MsiViewExecute( htab
, hrec
);
495 if(r
!= ERROR_SUCCESS
)
498 r
= MsiViewClose( htab
);
499 if(r
!= ERROR_SUCCESS
)
502 r
= MsiCloseHandle( htab
);
503 if(r
!= ERROR_SUCCESS
)
509 static UINT
try_query( MSIHANDLE hdb
, LPCSTR szQuery
)
511 return try_query_param( hdb
, szQuery
, 0 );
514 static UINT
try_insert_query( MSIHANDLE hdb
, LPCSTR szQuery
)
519 hrec
= MsiCreateRecord( 1 );
520 MsiRecordSetString( hrec
, 1, "Hello");
522 r
= try_query_param( hdb
, szQuery
, hrec
);
524 MsiCloseHandle( hrec
);
528 static void test_msibadqueries(void)
535 /* just MsiOpenDatabase should not create a file */
536 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
537 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
539 r
= MsiDatabaseCommit( hdb
);
540 ok(r
== ERROR_SUCCESS
, "Failed to commit database\n");
542 r
= MsiCloseHandle( hdb
);
543 ok(r
== ERROR_SUCCESS
, "Failed to close database\n");
545 /* open it readonly */
546 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
547 ok(r
== ERROR_SUCCESS
, "Failed to open database r/o\n");
549 /* add a table to it */
550 r
= try_query( hdb
, "select * from _Tables");
551 ok(r
== ERROR_SUCCESS
, "query 1 failed\n");
553 r
= MsiCloseHandle( hdb
);
554 ok(r
== ERROR_SUCCESS
, "Failed to close database r/o\n");
556 /* open it read/write */
557 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
558 ok(r
== ERROR_SUCCESS
, "Failed to open database r/w\n");
560 /* a bunch of test queries that fail with the native MSI */
562 r
= try_query( hdb
, "CREATE TABLE");
563 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2a return code\n");
565 r
= try_query( hdb
, "CREATE TABLE `a`");
566 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2b return code\n");
568 r
= try_query( hdb
, "CREATE TABLE `a` ()");
569 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2c return code\n");
571 r
= try_query( hdb
, "CREATE TABLE `a` (`b`)");
572 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2d return code\n");
574 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) )");
575 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2e return code\n");
577 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
578 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2f return code\n");
580 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
581 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2g return code\n");
583 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
584 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2h 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 2i return code\n");
589 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
590 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2j 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 2k 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 2l return code\n");
598 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
599 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2m return code\n");
601 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
602 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2n return code\n");
604 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
605 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2o return code\n");
607 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
608 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2p return code\n");
610 r
= try_query( hdb
, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
611 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2p return code\n");
613 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
614 ok(r
== ERROR_SUCCESS
, "valid query 2z failed\n");
616 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
617 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created same table again\n");
619 r
= try_query( hdb
, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
620 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
621 ok(r
== ERROR_SUCCESS
, "query 4 failed\n");
623 r
= MsiDatabaseCommit( hdb
);
624 ok(r
== ERROR_SUCCESS
, "Failed to commit database after write\n");
626 r
= try_query( hdb
, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
627 "PRIMARY KEY `foo`)");
628 ok(r
== ERROR_SUCCESS
, "query 4 failed\n");
630 r
= try_insert_query( hdb
, "insert into a ( `b` ) VALUES ( ? )");
631 ok(r
== ERROR_SUCCESS
, "failed to insert record in db\n");
633 r
= MsiDatabaseCommit( hdb
);
634 ok(r
== ERROR_SUCCESS
, "Failed to commit database after write\n");
636 r
= try_query( hdb
, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
637 "PRIMARY KEY `ba`)");
638 ok(r
!= ERROR_SUCCESS
, "query 5 succeeded\n");
640 r
= try_query( hdb
,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
641 ok(r
!= ERROR_SUCCESS
, "query 6 succeeded\n");
643 r
= try_query( hdb
, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
645 ok(r
== ERROR_SUCCESS
, "query 7 failed\n");
647 r
= try_query( hdb
, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
648 ok(r
== ERROR_SUCCESS
, "query 8 failed\n");
650 r
= try_query( hdb
, "select * from c");
651 ok(r
== ERROR_SUCCESS
, "query failed\n");
653 r
= try_query( hdb
, "select * from c where b = 'x");
654 todo_wine
ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
656 r
= try_query( hdb
, "select * from 'c'");
657 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
659 r
= try_query( hdb
, "select * from ''");
660 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
662 r
= try_query( hdb
, "select * from c where b = x");
663 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
665 r
= try_query( hdb
, "select * from c where b = \"x\"");
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_SUCCESS
, "query failed\n");
671 r
= try_query( hdb
, "select * from c where b = '\"x'");
672 ok(r
== ERROR_SUCCESS
, "query failed\n");
674 if (0) /* FIXME: this query causes trouble with other tests */
676 r
= try_query( hdb
, "select * from c where b = '\\\'x'");
677 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
680 r
= try_query( hdb
, "select * from 'c'");
681 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
683 r
= MsiCloseHandle( hdb
);
684 ok(r
== ERROR_SUCCESS
, "Failed to close database transact\n");
686 r
= DeleteFile( msifile
);
687 ok(r
== TRUE
, "file didn't exist after commit\n");
690 static void test_viewmodify(void)
692 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
701 /* just MsiOpenDatabase should not create a file */
702 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
703 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
705 query
= "CREATE TABLE `phone` ( "
706 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
708 r
= run_query( hdb
, 0, query
);
709 ok(r
== ERROR_SUCCESS
, "query failed\n");
711 /* check what the error function reports without doing anything */
713 /* passing NULL as the 3rd param make function to crash on older platforms */
714 err
= MsiViewGetError( 0, NULL
, &sz
);
715 ok(err
== MSIDBERROR_INVALIDARG
, "MsiViewGetError return\n");
718 query
= "SELECT * FROM `phone`";
719 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
720 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
722 /* see what happens with a good hview and bad args */
723 err
= MsiViewGetError( hview
, NULL
, NULL
);
724 ok(err
== MSIDBERROR_INVALIDARG
|| err
== MSIDBERROR_NOERROR
,
725 "MsiViewGetError returns %u (expected -3)\n", err
);
726 err
= MsiViewGetError( hview
, buffer
, NULL
);
727 ok(err
== MSIDBERROR_INVALIDARG
, "MsiViewGetError return\n");
729 /* see what happens with a zero length buffer */
732 err
= MsiViewGetError( hview
, buffer
, &sz
);
733 ok(err
== MSIDBERROR_MOREDATA
, "MsiViewGetError return\n");
734 ok(buffer
[0] == 'x', "buffer cleared\n");
735 ok(sz
== 0, "size not zero\n");
737 /* ok this one is strange */
739 err
= MsiViewGetError( hview
, NULL
, &sz
);
740 ok(err
== MSIDBERROR_NOERROR
, "MsiViewGetError return\n");
741 ok(sz
== 0, "size not zero\n");
743 /* see if it really has an error */
746 err
= MsiViewGetError( hview
, buffer
, &sz
);
747 ok(err
== MSIDBERROR_NOERROR
, "MsiViewGetError return\n");
748 ok(buffer
[0] == 0, "buffer not cleared\n");
749 ok(sz
== 0, "size not zero\n");
751 r
= MsiViewExecute(hview
, 0);
752 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
754 /* try some invalid records */
755 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, 0 );
756 ok(r
== ERROR_INVALID_HANDLE
, "MsiViewModify failed\n");
757 r
= MsiViewModify(hview
, -1, 0 );
758 ok(r
== ERROR_INVALID_HANDLE
, "MsiViewModify failed\n");
760 /* try an small record */
761 hrec
= MsiCreateRecord(1);
762 r
= MsiViewModify(hview
, -1, hrec
);
763 ok(r
== ERROR_INVALID_DATA
, "MsiViewModify failed\n");
765 r
= MsiCloseHandle(hrec
);
766 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
768 /* insert a valid record */
769 hrec
= MsiCreateRecord(3);
771 r
= MsiRecordSetInteger(hrec
, 1, 1);
772 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
773 r
= MsiRecordSetString(hrec
, 2, "bob");
774 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
775 r
= MsiRecordSetString(hrec
, 3, "7654321");
776 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
778 r
= MsiViewExecute(hview
, 0);
779 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
780 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
781 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
783 /* insert the same thing again */
784 r
= MsiViewExecute(hview
, 0);
785 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
787 /* should fail ... */
788 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
789 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
791 r
= MsiCloseHandle(hrec
);
792 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
794 r
= MsiViewClose(hview
);
795 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
796 r
= MsiCloseHandle(hview
);
797 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
799 query
= "SELECT * FROM `phone`";
800 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
801 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
803 r
= MsiViewExecute(hview
, 0);
804 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
806 r
= MsiViewFetch(hview
, &hrec
);
807 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
809 r
= MsiRecordGetInteger(hrec
, 1);
810 ok(r
== 1, "Expected 1, got %d\n", r
);
813 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
814 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
815 ok(!lstrcmp(buffer
, "bob"), "Expected bob, got %s\n", buffer
);
818 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
819 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
820 ok(!lstrcmp(buffer
, "7654321"), "Expected 7654321, got %s\n", buffer
);
822 /* update the view, non-primary key */
823 r
= MsiRecordSetString(hrec
, 3, "3141592");
824 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
826 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
827 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
830 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
831 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
833 /* update the view, primary key */
834 r
= MsiRecordSetInteger(hrec
, 1, 5);
835 ok(r
== ERROR_SUCCESS
, "MsiRecordSetInteger failed\n");
837 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
838 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
840 r
= MsiCloseHandle(hrec
);
841 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
843 r
= MsiViewClose(hview
);
844 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
845 r
= MsiCloseHandle(hview
);
846 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
848 query
= "SELECT * FROM `phone`";
849 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
850 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
852 r
= MsiViewExecute(hview
, 0);
853 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
855 r
= MsiViewFetch(hview
, &hrec
);
856 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
858 r
= MsiRecordGetInteger(hrec
, 1);
859 ok(r
== 1, "Expected 1, got %d\n", r
);
862 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
863 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
864 ok(!lstrcmp(buffer
, "bob"), "Expected bob, got %s\n", buffer
);
867 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
868 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
869 ok(!lstrcmp(buffer
, "3141592"), "Expected 3141592, got %s\n", buffer
);
871 r
= MsiCloseHandle(hrec
);
872 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
874 /* use a record that doesn't come from a view fetch */
875 hrec
= MsiCreateRecord(3);
876 ok(hrec
!= 0, "MsiCreateRecord failed\n");
878 r
= MsiRecordSetInteger(hrec
, 1, 3);
879 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
880 r
= MsiRecordSetString(hrec
, 2, "jane");
881 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
882 r
= MsiRecordSetString(hrec
, 3, "112358");
883 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
885 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
886 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
888 r
= MsiCloseHandle(hrec
);
889 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
891 /* use a record that doesn't come from a view fetch, primary key matches */
892 hrec
= MsiCreateRecord(3);
893 ok(hrec
!= 0, "MsiCreateRecord failed\n");
895 r
= MsiRecordSetInteger(hrec
, 1, 1);
896 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
897 r
= MsiRecordSetString(hrec
, 2, "jane");
898 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
899 r
= MsiRecordSetString(hrec
, 3, "112358");
900 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
902 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
905 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
908 r
= MsiCloseHandle(hrec
);
909 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
911 hrec
= MsiCreateRecord(3);
913 r
= MsiRecordSetInteger(hrec
, 1, 2);
914 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
915 r
= MsiRecordSetString(hrec
, 2, "nick");
916 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
917 r
= MsiRecordSetString(hrec
, 3, "141421");
918 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
920 r
= MsiViewExecute(hview
, 0);
921 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
922 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
923 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
925 r
= MsiViewClose(hview
);
926 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
927 r
= MsiCloseHandle(hview
);
928 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
930 query
= "SELECT * FROM `phone` WHERE `id` = 1";
931 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
932 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
933 r
= MsiViewExecute(hview
, 0);
934 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
935 r
= MsiViewFetch(hview
, &hrec
);
936 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
938 /* change the id to match the second row */
939 r
= MsiRecordSetInteger(hrec
, 1, 2);
940 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
941 r
= MsiRecordSetString(hrec
, 2, "jerry");
942 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
944 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
945 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
947 r
= MsiCloseHandle(hrec
);
948 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
949 r
= MsiViewClose(hview
);
950 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
951 r
= MsiCloseHandle(hview
);
952 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
955 query
= "SELECT * FROM `phone` ORDER BY `id`";
956 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
957 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
958 r
= MsiViewExecute(hview
, 0);
959 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
960 r
= MsiViewFetch(hview
, &hrec
);
961 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
963 /* change the id to match the second row */
964 r
= MsiRecordSetInteger(hrec
, 1, 2);
965 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
966 r
= MsiRecordSetString(hrec
, 2, "jerry");
967 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
969 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
970 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
972 r
= MsiCloseHandle(hrec
);
973 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
974 r
= MsiViewClose(hview
);
975 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
976 r
= MsiCloseHandle(hview
);
977 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
979 r
= MsiCloseHandle( hdb
);
980 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
983 static MSIHANDLE
create_db(void)
990 /* create an empty database */
991 res
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
992 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
993 if( res
!= ERROR_SUCCESS
)
996 res
= MsiDatabaseCommit( hdb
);
997 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
1002 static void test_getcolinfo(void)
1004 MSIHANDLE hdb
, hview
= 0, rec
= 0;
1009 /* create an empty db */
1011 ok( hdb
, "failed to create db\n");
1013 /* tables should be present */
1014 r
= MsiDatabaseOpenView(hdb
, "select * from _Tables", &hview
);
1015 ok( r
== ERROR_SUCCESS
, "failed to open query\n");
1017 r
= MsiViewExecute(hview
, 0);
1018 ok( r
== ERROR_SUCCESS
, "failed to execute query\n");
1020 /* check that NAMES works */
1022 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_NAMES
, &rec
);
1023 ok( r
== ERROR_SUCCESS
, "failed to get names\n");
1025 r
= MsiRecordGetString(rec
, 1, buffer
, &sz
);
1026 ok( r
== ERROR_SUCCESS
, "failed to get string\n");
1027 ok( !strcmp(buffer
,"Name"), "_Tables has wrong column name\n");
1028 r
= MsiCloseHandle( rec
);
1029 ok( r
== ERROR_SUCCESS
, "failed to close record handle\n");
1031 /* check that TYPES works */
1033 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_TYPES
, &rec
);
1034 ok( r
== ERROR_SUCCESS
, "failed to get names\n");
1036 r
= MsiRecordGetString(rec
, 1, buffer
, &sz
);
1037 ok( r
== ERROR_SUCCESS
, "failed to get string\n");
1038 ok( !strcmp(buffer
,"s64"), "_Tables has wrong column type\n");
1039 r
= MsiCloseHandle( rec
);
1040 ok( r
== ERROR_SUCCESS
, "failed to close record handle\n");
1042 /* check that invalid values fail */
1044 r
= MsiViewGetColumnInfo( hview
, 100, &rec
);
1045 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error code\n");
1046 ok( rec
== 0, "returned a record\n");
1048 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_TYPES
, NULL
);
1049 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error code\n");
1051 r
= MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES
, &rec
);
1052 ok( r
== ERROR_INVALID_HANDLE
, "wrong error code\n");
1054 r
= MsiViewClose(hview
);
1055 ok( r
== ERROR_SUCCESS
, "failed to close view\n");
1056 r
= MsiCloseHandle(hview
);
1057 ok( r
== ERROR_SUCCESS
, "failed to close view handle\n");
1058 r
= MsiCloseHandle(hdb
);
1059 ok( r
== ERROR_SUCCESS
, "failed to close database\n");
1062 static MSIHANDLE
get_column_info(MSIHANDLE hdb
, const char *query
, MSICOLINFO type
)
1064 MSIHANDLE hview
= 0, rec
= 0;
1067 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1068 if( r
!= ERROR_SUCCESS
)
1071 r
= MsiViewExecute(hview
, 0);
1072 if( r
== ERROR_SUCCESS
)
1074 MsiViewGetColumnInfo( hview
, type
, &rec
);
1075 MsiViewClose(hview
);
1077 MsiCloseHandle(hview
);
1081 static UINT
get_columns_table_type(MSIHANDLE hdb
, const char *table
, UINT field
)
1083 MSIHANDLE hview
= 0, rec
= 0;
1087 sprintf(query
, "select * from `_Columns` where `Table` = '%s'", table
);
1089 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1090 if( r
!= ERROR_SUCCESS
)
1093 r
= MsiViewExecute(hview
, 0);
1094 if( r
== ERROR_SUCCESS
)
1098 r
= MsiViewFetch( hview
, &rec
);
1099 if( r
!= ERROR_SUCCESS
)
1101 r
= MsiRecordGetInteger( rec
, 2 );
1103 type
= MsiRecordGetInteger( rec
, 4 );
1104 MsiCloseHandle( rec
);
1107 MsiViewClose(hview
);
1109 MsiCloseHandle(hview
);
1113 static BOOL
check_record( MSIHANDLE rec
, UINT field
, LPCSTR val
)
1120 r
= MsiRecordGetString( rec
, field
, buffer
, &sz
);
1121 return (r
== ERROR_SUCCESS
) && !strcmp(val
, buffer
);
1124 static void test_viewgetcolumninfo(void)
1126 MSIHANDLE hdb
= 0, rec
;
1130 ok( hdb
, "failed to create db\n");
1132 r
= run_query( hdb
, 0,
1133 "CREATE TABLE `Properties` "
1134 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1135 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1137 /* check the column types */
1138 rec
= get_column_info( hdb
, "select * from `Properties`", MSICOLINFO_TYPES
);
1139 ok( rec
, "failed to get column info record\n" );
1141 ok( check_record( rec
, 1, "S255"), "wrong record type\n");
1142 ok( check_record( rec
, 2, "S1"), "wrong record type\n");
1144 MsiCloseHandle( rec
);
1146 /* check the type in _Columns */
1147 ok( 0x3dff == get_columns_table_type(hdb
, "Properties", 1 ), "_columns table wrong\n");
1148 ok( 0x1d01 == get_columns_table_type(hdb
, "Properties", 2 ), "_columns table wrong\n");
1150 /* now try the names */
1151 rec
= get_column_info( hdb
, "select * from `Properties`", MSICOLINFO_NAMES
);
1152 ok( rec
, "failed to get column info record\n" );
1154 ok( check_record( rec
, 1, "Property"), "wrong record type\n");
1155 ok( check_record( rec
, 2, "Value"), "wrong record type\n");
1157 MsiCloseHandle( rec
);
1159 r
= run_query( hdb
, 0,
1160 "CREATE TABLE `Binary` "
1161 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
1162 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1164 /* check the column types */
1165 rec
= get_column_info( hdb
, "select * from `Binary`", MSICOLINFO_TYPES
);
1166 ok( rec
, "failed to get column info record\n" );
1168 ok( check_record( rec
, 1, "S255"), "wrong record type\n");
1169 ok( check_record( rec
, 2, "V0"), "wrong record type\n");
1171 MsiCloseHandle( rec
);
1173 /* check the type in _Columns */
1174 ok( 0x3dff == get_columns_table_type(hdb
, "Binary", 1 ), "_columns table wrong\n");
1175 ok( 0x1900 == get_columns_table_type(hdb
, "Binary", 2 ), "_columns table wrong\n");
1177 /* now try the names */
1178 rec
= get_column_info( hdb
, "select * from `Binary`", MSICOLINFO_NAMES
);
1179 ok( rec
, "failed to get column info record\n" );
1181 ok( check_record( rec
, 1, "Name"), "wrong record type\n");
1182 ok( check_record( rec
, 2, "Data"), "wrong record type\n");
1183 MsiCloseHandle( rec
);
1185 r
= run_query( hdb
, 0,
1186 "CREATE TABLE `UIText` "
1187 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1188 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1190 ok( 0x2d48 == get_columns_table_type(hdb
, "UIText", 1 ), "_columns table wrong\n");
1191 ok( 0x1fff == get_columns_table_type(hdb
, "UIText", 2 ), "_columns table wrong\n");
1193 rec
= get_column_info( hdb
, "select * from `UIText`", MSICOLINFO_NAMES
);
1194 ok( rec
, "failed to get column info record\n" );
1195 ok( check_record( rec
, 1, "Key"), "wrong record type\n");
1196 ok( check_record( rec
, 2, "Text"), "wrong record type\n");
1197 MsiCloseHandle( rec
);
1199 rec
= get_column_info( hdb
, "select * from `UIText`", MSICOLINFO_TYPES
);
1200 ok( rec
, "failed to get column info record\n" );
1201 ok( check_record( rec
, 1, "s72"), "wrong record type\n");
1202 ok( check_record( rec
, 2, "L255"), "wrong record type\n");
1203 MsiCloseHandle( rec
);
1205 MsiCloseHandle( hdb
);
1208 static void test_msiexport(void)
1210 MSIHANDLE hdb
= 0, hview
= 0;
1213 char path
[MAX_PATH
];
1214 const char file
[] = "phone.txt";
1218 const char expected
[] =
1219 "id\tname\tnumber\r\n"
1222 "1\tAbe\t8675309\r\n";
1224 DeleteFile(msifile
);
1226 /* just MsiOpenDatabase should not create a file */
1227 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1228 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1230 /* create a table */
1231 query
= "CREATE TABLE `phone` ( "
1232 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1233 "PRIMARY KEY `id`)";
1234 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1235 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1236 r
= MsiViewExecute(hview
, 0);
1237 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1238 r
= MsiViewClose(hview
);
1239 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1240 r
= MsiCloseHandle(hview
);
1241 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1243 /* insert a value into it */
1244 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
1245 "VALUES('1', 'Abe', '8675309')";
1246 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1247 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1248 r
= MsiViewExecute(hview
, 0);
1249 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1250 r
= MsiViewClose(hview
);
1251 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1252 r
= MsiCloseHandle(hview
);
1253 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1255 GetCurrentDirectory(MAX_PATH
, path
);
1257 r
= MsiDatabaseExport(hdb
, "phone", path
, file
);
1258 ok(r
== ERROR_SUCCESS
, "MsiDatabaseExport failed\n");
1260 MsiCloseHandle(hdb
);
1262 lstrcat(path
, "\\");
1263 lstrcat(path
, file
);
1265 /* check the data that was written */
1267 memset(buffer
, 0, sizeof buffer
);
1268 handle
= CreateFile(path
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1269 if (handle
!= INVALID_HANDLE_VALUE
)
1271 ReadFile(handle
, buffer
, sizeof buffer
, &length
, NULL
);
1272 CloseHandle(handle
);
1276 ok(0, "failed to open file %s\n", path
);
1278 ok( length
== strlen(expected
), "length of data wrong\n");
1279 ok( !lstrcmp(buffer
, expected
), "data doesn't match\n");
1280 DeleteFile(msifile
);
1283 static void test_longstrings(void)
1285 const char insert_query
[] =
1286 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1288 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
1291 const DWORD STRING_LENGTH
= 0x10005;
1293 DeleteFile(msifile
);
1294 /* just MsiOpenDatabase should not create a file */
1295 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1296 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1298 /* create a table */
1300 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1301 ok(r
== ERROR_SUCCESS
, "query failed\n");
1303 /* try a insert a very long string */
1304 str
= HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH
+sizeof insert_query
);
1305 len
= strchr(insert_query
, 'Z') - insert_query
;
1306 strcpy(str
, insert_query
);
1307 memset(str
+len
, 'Z', STRING_LENGTH
);
1308 strcpy(str
+len
+STRING_LENGTH
, insert_query
+len
+1);
1309 r
= try_query( hdb
, str
);
1310 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1312 HeapFree(GetProcessHeap(), 0, str
);
1314 MsiDatabaseCommit(hdb
);
1315 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
1316 MsiCloseHandle(hdb
);
1318 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
1319 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1321 r
= MsiDatabaseOpenView(hdb
, "select * from `strings` where `id` = 1", &hview
);
1322 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1324 r
= MsiViewExecute(hview
, 0);
1325 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1327 r
= MsiViewFetch(hview
, &hrec
);
1328 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1330 MsiCloseHandle(hview
);
1332 r
= MsiRecordGetString(hrec
, 2, NULL
, &len
);
1333 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1334 ok(len
== STRING_LENGTH
, "string length wrong\n");
1336 MsiCloseHandle(hrec
);
1337 MsiCloseHandle(hdb
);
1338 DeleteFile(msifile
);
1341 static void create_file_data(LPCSTR name
, LPCSTR data
, DWORD size
)
1346 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
1347 if (file
== INVALID_HANDLE_VALUE
)
1350 WriteFile(file
, data
, strlen(data
), &written
, NULL
);
1351 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
1355 SetFilePointer(file
, size
, NULL
, FILE_BEGIN
);
1362 #define create_file(name) create_file_data(name, name, 0)
1364 static void test_streamtable(void)
1366 MSIHANDLE hdb
= 0, rec
, view
;
1367 char file
[MAX_PATH
];
1373 ok( hdb
, "failed to create db\n");
1375 r
= run_query( hdb
, 0,
1376 "CREATE TABLE `Properties` "
1377 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1378 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1380 r
= run_query( hdb
, 0,
1381 "INSERT INTO `Properties` "
1382 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1383 ok( r
== ERROR_SUCCESS
, "Failed to add to table\n" );
1385 r
= MsiDatabaseCommit( hdb
);
1386 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
1388 MsiCloseHandle( hdb
);
1390 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
1391 ok( r
== ERROR_SUCCESS
, "Failed to open database\n" );
1393 /* check the column types */
1394 rec
= get_column_info( hdb
, "select * from `_Streams`", MSICOLINFO_TYPES
);
1395 ok( rec
, "failed to get column info record\n" );
1397 ok( check_record( rec
, 1, "s62"), "wrong record type\n");
1398 ok( check_record( rec
, 2, "V0"), "wrong record type\n");
1400 MsiCloseHandle( rec
);
1402 /* now try the names */
1403 rec
= get_column_info( hdb
, "select * from `_Streams`", MSICOLINFO_NAMES
);
1404 ok( rec
, "failed to get column info record\n" );
1406 ok( check_record( rec
, 1, "Name"), "wrong record type\n");
1407 ok( check_record( rec
, 2, "Data"), "wrong record type\n");
1409 MsiCloseHandle( rec
);
1411 /* insert a file into the _Streams table */
1412 create_file( "test.txt" );
1414 rec
= MsiCreateRecord( 2 );
1415 MsiRecordSetString( rec
, 1, "data" );
1417 r
= MsiRecordSetStream( rec
, 2, "test.txt" );
1418 ok( r
== ERROR_SUCCESS
, "Failed to add stream data to the record: %d\n", r
);
1420 DeleteFile("test.txt");
1422 r
= MsiDatabaseOpenView( hdb
,
1423 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view
);
1424 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1426 r
= MsiViewExecute( view
, rec
);
1427 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1429 MsiCloseHandle( rec
);
1430 MsiCloseHandle( view
);
1432 r
= MsiDatabaseOpenView( hdb
,
1433 "SELECT `Name`, `Data` FROM `_Streams`", &view
);
1434 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1436 r
= MsiViewExecute( view
, 0 );
1437 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1439 r
= MsiViewFetch( view
, &rec
);
1440 ok( r
== ERROR_SUCCESS
, "Failed to fetch record: %d\n", r
);
1443 r
= MsiRecordGetString( rec
, 1, file
, &size
);
1444 ok( r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
1445 ok( !lstrcmp(file
, "data"), "Expected 'data', got %s\n", file
);
1448 memset(buf
, 0, MAX_PATH
);
1449 r
= MsiRecordReadStream( rec
, 2, buf
, &size
);
1450 ok( r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
1451 ok( !lstrcmp(buf
, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf
);
1453 MsiCloseHandle( rec
);
1455 r
= MsiViewFetch( view
, &rec
);
1456 ok( r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
1458 MsiCloseHandle( view
);
1459 MsiCloseHandle( hdb
);
1460 DeleteFile(msifile
);
1463 static void test_where(void)
1465 MSIHANDLE hdb
= 0, rec
, view
;
1473 ok( hdb
, "failed to create db\n");
1475 r
= run_query( hdb
, 0,
1476 "CREATE TABLE `Media` ("
1477 "`DiskId` SHORT NOT NULL, "
1478 "`LastSequence` LONG, "
1479 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1480 "`Cabinet` CHAR(255), "
1481 "`VolumeLabel` CHAR(32), "
1482 "`Source` CHAR(72) "
1483 "PRIMARY KEY `DiskId`)" );
1484 ok( r
== S_OK
, "cannot create Media table: %d\n", r
);
1486 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1487 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1488 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1489 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1491 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1492 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1493 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1494 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1496 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1497 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1498 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1499 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1501 query
= "SELECT * FROM `Media`";
1502 r
= do_query(hdb
, query
, &rec
);
1503 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed: %d\n", r
);
1504 ok( check_record( rec
, 4, "zero.cab"), "wrong cabinet\n");
1505 MsiCloseHandle( rec
);
1507 query
= "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1508 r
= do_query(hdb
, query
, &rec
);
1509 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed: %d\n", r
);
1510 ok( check_record( rec
, 4, "one.cab"), "wrong cabinet\n");
1512 r
= MsiRecordGetInteger(rec
, 1);
1513 ok( 2 == r
, "field wrong\n");
1514 r
= MsiRecordGetInteger(rec
, 2);
1515 ok( 1 == r
, "field wrong\n");
1516 MsiCloseHandle( rec
);
1518 query
= "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1519 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1520 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
1522 r
= MsiViewExecute(view
, 0);
1523 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
1525 r
= MsiViewFetch(view
, &rec
);
1526 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1528 count
= MsiRecordGetFieldCount( rec
);
1529 ok( count
== 1, "Expected 1 record fields, got %d\n", count
);
1532 r
= MsiRecordGetString( rec
, 1, buf
, &size
);
1533 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
1534 ok( !lstrcmp( buf
, "2" ),
1535 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf
);
1536 MsiCloseHandle( rec
);
1538 r
= MsiViewFetch(view
, &rec
);
1539 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1542 r
= MsiRecordGetString( rec
, 1, buf
, &size
);
1543 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
1544 ok( !lstrcmp( buf
, "3" ),
1545 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf
);
1546 MsiCloseHandle( rec
);
1548 r
= MsiViewFetch(view
, &rec
);
1549 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
1552 MsiCloseHandle(view
);
1554 MsiCloseHandle( rec
);
1557 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1558 r
= do_query(hdb
, query
, &rec
);
1559 ok( r
== ERROR_SUCCESS
, "query failed: %d\n", r
);
1560 MsiCloseHandle( rec
);
1562 rec
= MsiCreateRecord(1);
1563 MsiRecordSetString(rec
, 1, "");
1565 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` = ?";
1566 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1567 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1568 r
= MsiViewExecute(view
, rec
);
1569 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1571 MsiCloseHandle(rec
);
1573 r
= MsiViewFetch(view
, &rec
);
1574 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1576 MsiCloseHandle(rec
);
1578 MsiCloseHandle(view
);
1580 MsiCloseHandle( hdb
);
1581 DeleteFile(msifile
);
1584 static CHAR CURR_DIR
[MAX_PATH
];
1586 static const CHAR test_data
[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1587 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1588 "TestTable\tFirstPrimaryColumn\n"
1589 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1591 static const CHAR two_primary
[] = "PrimaryOne\tPrimaryTwo\n"
1593 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1597 static const CHAR endlines1
[] = "A\tB\tC\tD\tE\tF\r\n"
1598 "s72\ts72\ts72\ts72\ts72\ts72\n"
1600 "a\tb\tc\td\te\tf\n"
1601 "g\th\ti\t\rj\tk\tl\r\n";
1603 static const CHAR endlines2
[] = "A\tB\tC\tD\tE\tF\r"
1604 "s72\ts72\ts72\ts72\ts72\ts72\n"
1606 "a\tb\tc\td\te\tf\n"
1607 "g\th\ti\tj\tk\tl\r\n";
1609 static void write_file(const CHAR
*filename
, const char *data
, int data_size
)
1613 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
1614 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1616 WriteFile(hf
, data
, data_size
, &size
, NULL
);
1620 static UINT
add_table_to_db(MSIHANDLE hdb
, LPCSTR table_data
)
1624 write_file("temp_file", table_data
, (lstrlen(table_data
) - 1) * sizeof(char));
1625 r
= MsiDatabaseImportA(hdb
, CURR_DIR
, "temp_file");
1626 DeleteFileA("temp_file");
1631 static void test_msiimport(void)
1633 MSIHANDLE hdb
, view
, rec
;
1638 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
1640 r
= MsiOpenDatabaseA(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1641 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1643 r
= add_table_to_db(hdb
, test_data
);
1644 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1646 r
= add_table_to_db(hdb
, two_primary
);
1647 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1649 r
= add_table_to_db(hdb
, endlines1
);
1650 if (r
== ERROR_FUNCTION_FAILED
)
1652 /* win9x doesn't handle this case */
1653 skip("endlines not handled correctly.\n");
1654 MsiCloseHandle(hdb
);
1655 DeleteFileA(msifile
);
1659 r
= add_table_to_db(hdb
, endlines2
);
1660 ok(r
== ERROR_FUNCTION_FAILED
,
1661 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
1663 query
= "SELECT * FROM `TestTable`";
1664 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1665 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1667 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
1668 count
= MsiRecordGetFieldCount(rec
);
1669 ok(count
== 9, "Expected 9, got %d\n", count
);
1670 ok(check_record(rec
, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
1671 ok(check_record(rec
, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
1672 ok(check_record(rec
, 3, "ShortInt"), "Expected ShortInt\n");
1673 ok(check_record(rec
, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
1674 ok(check_record(rec
, 5, "LongInt"), "Expected LongInt\n");
1675 ok(check_record(rec
, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
1676 ok(check_record(rec
, 7, "String"), "Expected String\n");
1677 ok(check_record(rec
, 8, "LocalizableString"), "Expected LocalizableString\n");
1678 ok(check_record(rec
, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
1679 MsiCloseHandle(rec
);
1681 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1682 count
= MsiRecordGetFieldCount(rec
);
1683 ok(count
== 9, "Expected 9, got %d\n", count
);
1684 ok(check_record(rec
, 1, "s255"), "Expected s255\n");
1685 ok(check_record(rec
, 2, "i2"), "Expected i2\n");
1686 ok(check_record(rec
, 3, "i2"), "Expected i2\n");
1687 ok(check_record(rec
, 4, "I2"), "Expected I2\n");
1688 ok(check_record(rec
, 5, "i4"), "Expected i4\n");
1689 ok(check_record(rec
, 6, "I4"), "Expected I4\n");
1690 ok(check_record(rec
, 7, "S255"), "Expected S255\n");
1691 ok(check_record(rec
, 8, "S0"), "Expected S0\n");
1692 ok(check_record(rec
, 9, "s0"), "Expected s0\n");
1693 MsiCloseHandle(rec
);
1695 query
= "SELECT * FROM `TestTable`";
1696 r
= do_query(hdb
, query
, &rec
);
1697 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1698 ok(check_record(rec
, 1, "stringage"), "Expected 'stringage'\n");
1699 ok(check_record(rec
, 7, "another string"), "Expected 'another string'\n");
1700 ok(check_record(rec
, 8, "localizable"), "Expected 'localizable'\n");
1701 ok(check_record(rec
, 9, "duh"), "Expected 'duh'\n");
1703 i
= MsiRecordGetInteger(rec
, 2);
1704 ok(i
== 5, "Expected 5, got %d\n", i
);
1706 i
= MsiRecordGetInteger(rec
, 3);
1707 ok(i
== 2, "Expected 2, got %d\n", i
);
1709 i
= MsiRecordGetInteger(rec
, 4);
1710 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
1712 i
= MsiRecordGetInteger(rec
, 5);
1713 ok(i
== 2147483640, "Expected 2147483640, got %d\n", i
);
1715 i
= MsiRecordGetInteger(rec
, 6);
1716 ok(i
== -2147483640, "Expected -2147483640, got %d\n", i
);
1718 MsiCloseHandle(rec
);
1719 MsiCloseHandle(view
);
1721 query
= "SELECT * FROM `TwoPrimary`";
1722 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1723 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1725 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
1726 count
= MsiRecordGetFieldCount(rec
);
1727 ok(count
== 2, "Expected 2, got %d\n", count
);
1728 ok(check_record(rec
, 1, "PrimaryOne"), "Expected PrimaryOne\n");
1729 ok(check_record(rec
, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
1731 MsiCloseHandle(rec
);
1733 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1734 count
= MsiRecordGetFieldCount(rec
);
1735 ok(count
== 2, "Expected 2, got %d\n", count
);
1736 ok(check_record(rec
, 1, "s255"), "Expected s255\n");
1737 ok(check_record(rec
, 2, "s255"), "Expected s255\n");
1738 MsiCloseHandle(rec
);
1740 r
= MsiViewExecute(view
, 0);
1741 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1743 r
= MsiViewFetch(view
, &rec
);
1744 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1746 ok(check_record(rec
, 1, "papaya"), "Expected 'papaya'\n");
1747 ok(check_record(rec
, 2, "leaf"), "Expected 'leaf'\n");
1749 MsiCloseHandle(rec
);
1751 r
= MsiViewFetch(view
, &rec
);
1752 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1754 ok(check_record(rec
, 1, "papaya"), "Expected 'papaya'\n");
1755 ok(check_record(rec
, 2, "flower"), "Expected 'flower'\n");
1757 MsiCloseHandle(rec
);
1759 r
= MsiViewFetch(view
, &rec
);
1760 ok(r
== ERROR_NO_MORE_ITEMS
,
1761 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
1763 r
= MsiViewClose(view
);
1764 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1766 MsiCloseHandle(view
);
1768 query
= "SELECT * FROM `Table`";
1769 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1770 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1772 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
1773 count
= MsiRecordGetFieldCount(rec
);
1774 ok(count
== 6, "Expected 6, got %d\n", count
);
1775 ok(check_record(rec
, 1, "A"), "Expected A\n");
1776 ok(check_record(rec
, 2, "B"), "Expected B\n");
1777 ok(check_record(rec
, 3, "C"), "Expected C\n");
1778 ok(check_record(rec
, 4, "D"), "Expected D\n");
1779 ok(check_record(rec
, 5, "E"), "Expected E\n");
1780 ok(check_record(rec
, 6, "F"), "Expected F\n");
1781 MsiCloseHandle(rec
);
1783 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1784 count
= MsiRecordGetFieldCount(rec
);
1785 ok(count
== 6, "Expected 6, got %d\n", count
);
1786 ok(check_record(rec
, 1, "s72"), "Expected s72\n");
1787 ok(check_record(rec
, 2, "s72"), "Expected s72\n");
1788 ok(check_record(rec
, 3, "s72"), "Expected s72\n");
1789 ok(check_record(rec
, 4, "s72"), "Expected s72\n");
1790 ok(check_record(rec
, 5, "s72"), "Expected s72\n");
1791 ok(check_record(rec
, 6, "s72"), "Expected s72\n");
1792 MsiCloseHandle(rec
);
1795 MsiCloseHandle(view
);
1797 query
= "SELECT * FROM `Table`";
1798 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1799 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1801 r
= MsiViewExecute(view
, 0);
1802 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1804 r
= MsiViewFetch(view
, &rec
);
1805 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1806 ok(check_record(rec
, 1, "a"), "Expected 'a'\n");
1807 ok(check_record(rec
, 2, "b"), "Expected 'b'\n");
1808 ok(check_record(rec
, 3, "c"), "Expected 'c'\n");
1809 ok(check_record(rec
, 4, "d"), "Expected 'd'\n");
1810 ok(check_record(rec
, 5, "e"), "Expected 'e'\n");
1811 ok(check_record(rec
, 6, "f"), "Expected 'f'\n");
1813 MsiCloseHandle(rec
);
1815 r
= MsiViewFetch(view
, &rec
);
1816 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1817 ok(check_record(rec
, 1, "g"), "Expected 'g'\n");
1818 ok(check_record(rec
, 2, "h"), "Expected 'h'\n");
1819 ok(check_record(rec
, 3, "i"), "Expected 'i'\n");
1820 ok(check_record(rec
, 4, "j"), "Expected 'j'\n");
1821 ok(check_record(rec
, 5, "k"), "Expected 'k'\n");
1822 ok(check_record(rec
, 6, "l"), "Expected 'l'\n");
1824 MsiCloseHandle(rec
);
1826 r
= MsiViewFetch(view
, &rec
);
1827 ok(r
== ERROR_NO_MORE_ITEMS
,
1828 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
1831 MsiCloseHandle(view
);
1832 MsiCloseHandle(hdb
);
1833 DeleteFileA(msifile
);
1836 static void test_markers(void)
1843 ok( hdb
, "failed to create db\n");
1845 rec
= MsiCreateRecord(3);
1846 MsiRecordSetString(rec
, 1, "Table");
1847 MsiRecordSetString(rec
, 2, "Apples");
1848 MsiRecordSetString(rec
, 3, "Oranges");
1850 /* try a legit create */
1851 query
= "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1852 r
= run_query(hdb
, 0, query
);
1853 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1854 MsiCloseHandle(rec
);
1856 /* try table name as marker */
1857 rec
= MsiCreateRecord(1);
1858 MsiRecordSetString(rec
, 1, "Fable");
1859 query
= "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1860 r
= run_query(hdb
, rec
, query
);
1861 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1863 /* verify that we just created a table called '?', not 'Fable' */
1864 r
= try_query(hdb
, "SELECT * from `Fable`");
1865 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1867 r
= try_query(hdb
, "SELECT * from `?`");
1868 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1870 /* try table name as marker without backticks */
1871 MsiRecordSetString(rec
, 1, "Mable");
1872 query
= "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1873 r
= run_query(hdb
, rec
, query
);
1874 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1876 /* try one column name as marker */
1877 MsiRecordSetString(rec
, 1, "One");
1878 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1879 r
= run_query(hdb
, rec
, query
);
1880 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1881 MsiCloseHandle(rec
);
1883 /* try column names as markers */
1884 rec
= MsiCreateRecord(2);
1885 MsiRecordSetString(rec
, 1, "One");
1886 MsiRecordSetString(rec
, 2, "Two");
1887 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
1888 r
= run_query(hdb
, rec
, query
);
1889 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1890 MsiCloseHandle(rec
);
1892 /* try names with backticks */
1893 rec
= MsiCreateRecord(3);
1894 MsiRecordSetString(rec
, 1, "One");
1895 MsiRecordSetString(rec
, 2, "Two");
1896 MsiRecordSetString(rec
, 3, "One");
1897 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1898 r
= run_query(hdb
, rec
, query
);
1899 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1901 /* try names with backticks, minus definitions */
1902 query
= "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
1903 r
= run_query(hdb
, rec
, query
);
1904 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1906 /* try names without backticks */
1907 query
= "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
1908 r
= run_query(hdb
, rec
, query
);
1909 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1910 MsiCloseHandle(rec
);
1912 /* try one long marker */
1913 rec
= MsiCreateRecord(1);
1914 MsiRecordSetString(rec
, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
1915 query
= "CREATE TABLE `Mable` ( ? )";
1916 r
= run_query(hdb
, rec
, query
);
1917 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1918 MsiCloseHandle(rec
);
1920 /* try all names as markers */
1921 rec
= MsiCreateRecord(4);
1922 MsiRecordSetString(rec
, 1, "Mable");
1923 MsiRecordSetString(rec
, 2, "One");
1924 MsiRecordSetString(rec
, 3, "Two");
1925 MsiRecordSetString(rec
, 4, "One");
1926 query
= "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1927 r
= run_query(hdb
, rec
, query
);
1928 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1929 MsiCloseHandle(rec
);
1931 /* try a legit insert */
1932 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
1933 r
= run_query(hdb
, 0, query
);
1934 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1936 r
= try_query(hdb
, "SELECT * from `Table`");
1937 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1939 /* try values as markers */
1940 rec
= MsiCreateRecord(2);
1941 MsiRecordSetInteger(rec
, 1, 4);
1942 MsiRecordSetString(rec
, 2, "hi");
1943 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1944 r
= run_query(hdb
, rec
, query
);
1945 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1946 MsiCloseHandle(rec
);
1948 /* try column names and values as markers */
1949 rec
= MsiCreateRecord(4);
1950 MsiRecordSetString(rec
, 1, "One");
1951 MsiRecordSetString(rec
, 2, "Two");
1952 MsiRecordSetInteger(rec
, 3, 5);
1953 MsiRecordSetString(rec
, 4, "hi");
1954 query
= "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
1955 r
= run_query(hdb
, rec
, query
);
1956 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1957 MsiCloseHandle(rec
);
1959 /* try column names as markers */
1960 rec
= MsiCreateRecord(2);
1961 MsiRecordSetString(rec
, 1, "One");
1962 MsiRecordSetString(rec
, 2, "Two");
1963 query
= "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
1964 r
= run_query(hdb
, rec
, query
);
1965 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1966 MsiCloseHandle(rec
);
1968 /* try table name as a marker */
1969 rec
= MsiCreateRecord(1);
1970 MsiRecordSetString(rec
, 1, "Table");
1971 query
= "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
1972 r
= run_query(hdb
, rec
, query
);
1973 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1974 MsiCloseHandle(rec
);
1976 /* try table name and values as markers */
1977 rec
= MsiCreateRecord(3);
1978 MsiRecordSetString(rec
, 1, "Table");
1979 MsiRecordSetInteger(rec
, 2, 10);
1980 MsiRecordSetString(rec
, 3, "haha");
1981 query
= "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
1982 r
= run_query(hdb
, rec
, query
);
1983 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
1984 MsiCloseHandle(rec
);
1986 /* try all markers */
1987 rec
= MsiCreateRecord(5);
1988 MsiRecordSetString(rec
, 1, "Table");
1989 MsiRecordSetString(rec
, 1, "One");
1990 MsiRecordSetString(rec
, 1, "Two");
1991 MsiRecordSetInteger(rec
, 2, 10);
1992 MsiRecordSetString(rec
, 3, "haha");
1993 query
= "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
1994 r
= run_query(hdb
, rec
, query
);
1995 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1996 MsiCloseHandle(rec
);
1998 /* insert an integer as a string */
1999 rec
= MsiCreateRecord(2);
2000 MsiRecordSetString(rec
, 1, "11");
2001 MsiRecordSetString(rec
, 2, "hi");
2002 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2003 r
= run_query(hdb
, rec
, query
);
2004 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2005 MsiCloseHandle(rec
);
2007 /* leave off the '' for the string */
2008 rec
= MsiCreateRecord(2);
2009 MsiRecordSetInteger(rec
, 1, 12);
2010 MsiRecordSetString(rec
, 2, "hi");
2011 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
2012 r
= run_query(hdb
, rec
, query
);
2013 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2014 MsiCloseHandle(rec
);
2016 MsiCloseHandle(hdb
);
2017 DeleteFileA(msifile
);
2020 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
2021 static void test_handle_limit(void)
2025 MSIHANDLE hviews
[MY_NVIEWS
];
2028 /* create an empty db */
2030 ok( hdb
, "failed to create db\n");
2032 memset(hviews
, 0, sizeof(hviews
));
2034 for (i
=0; i
<MY_NVIEWS
; i
++) {
2035 static char szQueryBuf
[256] = "SELECT * from `_Tables`";
2036 hviews
[i
] = 0xdeadbeeb;
2037 r
= MsiDatabaseOpenView(hdb
, szQueryBuf
, &hviews
[i
]);
2038 if( r
!= ERROR_SUCCESS
|| hviews
[i
] == 0xdeadbeeb ||
2039 hviews
[i
] == 0 || (i
&& (hviews
[i
] == hviews
[i
-1])))
2043 ok( i
== MY_NVIEWS
, "problem opening views\n");
2045 for (i
=0; i
<MY_NVIEWS
; i
++) {
2046 if (hviews
[i
] != 0 && hviews
[i
] != 0xdeadbeeb) {
2047 r
= MsiCloseHandle(hviews
[i
]);
2048 if (r
!= ERROR_SUCCESS
)
2053 ok( i
== MY_NVIEWS
, "problem closing views\n");
2055 r
= MsiCloseHandle(hdb
);
2056 ok( r
== ERROR_SUCCESS
, "failed to close database\n");
2059 static void generate_transform(void)
2061 MSIHANDLE hdb1
, hdb2
, hrec
;
2065 /* start with two identical databases */
2066 CopyFile(msifile2
, msifile
, FALSE
);
2068 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb1
);
2069 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2071 r
= MsiDatabaseCommit( hdb1
);
2072 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
2074 r
= MsiOpenDatabase(msifile2
, MSIDBOPEN_READONLY
, &hdb2
);
2075 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2077 /* the transform between two identical database should be empty */
2078 r
= MsiDatabaseGenerateTransform(hdb1
, hdb2
, NULL
, 0, 0);
2080 ok( r
== ERROR_NO_DATA
, "return code %d, should be ERROR_NO_DATA\n", r
);
2083 query
= "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
2084 r
= run_query(hdb1
, 0, query
);
2085 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2087 query
= "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
2088 r
= run_query(hdb1
, 0, query
);
2089 ok(r
== ERROR_SUCCESS
, "failed to add row 1\n");
2091 query
= "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
2092 r
= run_query(hdb1
, 0, query
);
2093 ok(r
== ERROR_SUCCESS
, "failed to add row 2\n");
2095 query
= "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
2096 r
= run_query(hdb1
, 0, query
);
2097 ok(r
== ERROR_SUCCESS
, "failed to modify row\n");
2099 query
= "DELETE FROM `MOO` WHERE `NOO` = 3";
2100 r
= run_query(hdb1
, 0, query
);
2101 ok(r
== ERROR_SUCCESS
, "failed to delete row\n");
2103 hrec
= MsiCreateRecord(2);
2104 r
= MsiRecordSetInteger(hrec
, 1, 1);
2105 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
2107 write_file("testdata.bin", "naengmyon", 9);
2108 r
= MsiRecordSetStream(hrec
, 2, "testdata.bin");
2109 ok(r
== ERROR_SUCCESS
, "failed to set stream\n");
2111 query
= "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2112 r
= run_query(hdb1
, hrec
, query
);
2113 ok(r
== ERROR_SUCCESS
, "failed to add row with blob\n");
2115 MsiCloseHandle(hrec
);
2117 query
= "ALTER TABLE `MOO` ADD `COW` INTEGER";
2118 r
= run_query(hdb1
, 0, query
);
2119 ok(r
== ERROR_SUCCESS
, "failed to add column\n");
2121 query
= "ALTER TABLE `MOO` ADD `PIG` INTEGER";
2122 r
= run_query(hdb1
, 0, query
);
2123 ok(r
== ERROR_SUCCESS
, "failed to add column\n");
2125 query
= "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
2126 r
= run_query(hdb1
, 0, query
);
2127 ok(r
== ERROR_SUCCESS
, "failed to modify row\n");
2129 query
= "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
2130 "`Value` CHAR(0) PRIMARY KEY `Property`)";
2131 r
= run_query(hdb1
, 0, query
);
2132 ok(r
== ERROR_SUCCESS
, "failed to add property table\n");
2134 query
= "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2135 r
= run_query(hdb1
, 0, query
);
2136 ok(r
== ERROR_SUCCESS
, "failed to add property\n");
2138 /* database needs to be committed */
2139 MsiDatabaseCommit(hdb1
);
2141 r
= MsiDatabaseGenerateTransform(hdb1
, hdb2
, mstfile
, 0, 0);
2142 ok( r
== ERROR_SUCCESS
, "return code %d, should be ERROR_SUCCESS\n", r
);
2144 MsiCloseHandle( hdb1
);
2145 MsiCloseHandle( hdb2
);
2147 DeleteFile("testdata.bin");
2150 /* data for generating a transform */
2152 /* tables transform names - encoded as they would be in an msi database file */
2153 static const WCHAR name1
[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
2154 static const WCHAR name2
[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
2155 static const WCHAR name3
[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
2156 static const WCHAR name4
[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2157 static const WCHAR name5
[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2158 static const WCHAR name6
[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
2159 static const WCHAR name7
[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
2160 static const WCHAR name8
[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
2161 static const WCHAR name9
[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2163 /* data in each table */
2164 static const WCHAR data1
[] = { /* AAR */
2165 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
2166 0x0201, 0x0009, 0x8002,
2168 static const WCHAR data2
[] = { /* _Columns */
2169 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
2170 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
2171 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
2172 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
2173 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
2174 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
2176 static const WCHAR data3
[] = { /* _Tables */
2177 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
2180 static const char data4
[] = /* _StringData */
2181 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
2182 static const WCHAR data5
[] = { /* _StringPool */
2184 0, 0, /* string 0 '' */
2185 3, 2, /* string 1 'MOO' */
2186 3, 1, /* string 2 'COW' */
2187 3, 1, /* string 3 'PIG' */
2188 1, 1, /* string 4 'c' */
2189 3, 3, /* string 5 'AAR' */
2190 3, 1, /* string 6 'CAR' */
2191 3, 1, /* string 7 'BAR' */
2192 2, 1, /* string 8 'vw' */
2193 3, 1, /* string 9 'bmw' */
2194 8, 4, /* string 10 'Property' */
2195 5, 1, /* string 11 'Value' */
2196 4, 1, /* string 12 'prop' */
2197 3, 1, /* string 13 'val' */
2199 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
2200 static const WCHAR data6
[] = { /* MOO */
2201 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
2202 0x0000, 0x8003, /* delete row */
2205 static const WCHAR data7
[] = { /* BINARY */
2206 0x0201, 0x8001, 0x0001,
2209 static const char data8
[] = /* stream data for the BINARY table */
2212 static const WCHAR data9
[] = { /* Property */
2213 0x0201, 0x000c, 0x000d,
2216 static const struct {
2220 } table_transform_data
[] =
2222 { name1
, data1
, sizeof data1
},
2223 { name2
, data2
, sizeof data2
},
2224 { name3
, data3
, sizeof data3
},
2225 { name4
, data4
, sizeof data4
- 1 },
2226 { name5
, data5
, sizeof data5
},
2227 { name6
, data6
, sizeof data6
},
2228 { name7
, data7
, sizeof data7
},
2229 { name8
, data8
, sizeof data8
- 1 },
2230 { name9
, data9
, sizeof data9
},
2233 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2235 static void generate_transform_manual(void)
2237 IStorage
*stg
= NULL
;
2242 const DWORD mode
= STGM_CREATE
|STGM_READWRITE
|STGM_DIRECT
|STGM_SHARE_EXCLUSIVE
;
2244 const CLSID CLSID_MsiTransform
= { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2246 MultiByteToWideChar(CP_ACP
, 0, mstfile
, -1, name
, 0x20);
2248 r
= StgCreateDocfile(name
, mode
, 0, &stg
);
2249 ok(r
== S_OK
, "failed to create storage\n");
2253 r
= IStorage_SetClass( stg
, &CLSID_MsiTransform
);
2254 ok(r
== S_OK
, "failed to set storage type\n");
2256 for (i
=0; i
<NUM_TRANSFORM_TABLES
; i
++)
2258 r
= IStorage_CreateStream( stg
, table_transform_data
[i
].name
,
2259 STGM_WRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
2262 ok(0, "failed to create stream %08x\n", r
);
2266 r
= IStream_Write( stm
, table_transform_data
[i
].data
,
2267 table_transform_data
[i
].size
, &count
);
2268 if (FAILED(r
) || count
!= table_transform_data
[i
].size
)
2269 ok(0, "failed to write stream\n");
2270 IStream_Release(stm
);
2273 IStorage_Release(stg
);
2276 static UINT
set_summary_info(MSIHANDLE hdb
)
2281 /* build summary info */
2282 res
= MsiGetSummaryInformation(hdb
, NULL
, 7, &suminfo
);
2283 ok( res
== ERROR_SUCCESS
, "Failed to open summaryinfo\n" );
2285 res
= MsiSummaryInfoSetProperty(suminfo
,2, VT_LPSTR
, 0,NULL
,
2286 "Installation Database");
2287 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2289 res
= MsiSummaryInfoSetProperty(suminfo
,3, VT_LPSTR
, 0,NULL
,
2290 "Installation Database");
2291 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2293 res
= MsiSummaryInfoSetProperty(suminfo
,4, VT_LPSTR
, 0,NULL
,
2295 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2297 res
= MsiSummaryInfoSetProperty(suminfo
,7, VT_LPSTR
, 0,NULL
,
2299 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2301 res
= MsiSummaryInfoSetProperty(suminfo
,9, VT_LPSTR
, 0,NULL
,
2302 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2303 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2305 res
= MsiSummaryInfoSetProperty(suminfo
, 14, VT_I4
, 100, NULL
, NULL
);
2306 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2308 res
= MsiSummaryInfoSetProperty(suminfo
, 15, VT_I4
, 0, NULL
, NULL
);
2309 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2311 res
= MsiSummaryInfoPersist(suminfo
);
2312 ok( res
== ERROR_SUCCESS
, "Failed to make summary info persist\n" );
2314 res
= MsiCloseHandle( suminfo
);
2315 ok( res
== ERROR_SUCCESS
, "Failed to close suminfo\n" );
2320 static MSIHANDLE
create_package_db(LPCSTR filename
)
2325 DeleteFile(msifile
);
2327 /* create an empty database */
2328 res
= MsiOpenDatabase(filename
, MSIDBOPEN_CREATE
, &hdb
);
2329 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
2330 if( res
!= ERROR_SUCCESS
)
2333 res
= MsiDatabaseCommit( hdb
);
2334 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
2336 res
= set_summary_info(hdb
);
2338 res
= create_directory_table(hdb
);
2339 ok( res
== ERROR_SUCCESS
, "Failed to create directory table\n" );
2344 static MSIHANDLE
package_from_db(MSIHANDLE hdb
)
2350 sprintf(szPackage
,"#%li",hdb
);
2351 res
= MsiOpenPackage(szPackage
,&hPackage
);
2352 if (res
!= ERROR_SUCCESS
)
2355 res
= MsiCloseHandle(hdb
);
2356 if (res
!= ERROR_SUCCESS
)
2362 static void test_try_transform(void)
2364 MSIHANDLE hdb
, hview
, hrec
, hpkg
;
2368 char buffer
[MAX_PATH
];
2370 DeleteFile(msifile
);
2371 DeleteFile(mstfile
);
2373 /* create the database */
2374 hdb
= create_package_db(msifile
);
2375 ok(hdb
, "Failed to create package db\n");
2377 query
= "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
2378 r
= run_query(hdb
, 0, query
);
2379 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2381 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
2382 r
= run_query(hdb
, 0, query
);
2383 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2385 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
2386 r
= run_query(hdb
, 0, query
);
2387 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2389 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
2390 r
= run_query(hdb
, 0, query
);
2391 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2393 query
= "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
2394 r
= run_query(hdb
, 0, query
);
2395 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2397 hrec
= MsiCreateRecord(2);
2398 r
= MsiRecordSetInteger(hrec
, 1, 2);
2399 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
2401 write_file("testdata.bin", "lamyon", 6);
2402 r
= MsiRecordSetStream(hrec
, 2, "testdata.bin");
2403 ok(r
== ERROR_SUCCESS
, "failed to set stream\n");
2405 query
= "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2406 r
= run_query(hdb
, hrec
, query
);
2407 ok(r
== ERROR_SUCCESS
, "failed to add row with blob\n");
2409 MsiCloseHandle(hrec
);
2411 r
= MsiDatabaseCommit( hdb
);
2412 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
2414 MsiCloseHandle( hdb
);
2415 DeleteFileA("testdata.bin");
2418 * Both these generate an equivalent transform,
2419 * but the first doesn't work in Wine yet
2420 * because MsiDatabaseGenerateTransform is unimplemented.
2423 generate_transform();
2425 generate_transform_manual();
2427 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_DIRECT
, &hdb
);
2428 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2430 r
= MsiDatabaseApplyTransform( hdb
, mstfile
, 0 );
2431 ok( r
== ERROR_SUCCESS
, "return code %d, should be ERROR_SUCCESS\n", r
);
2433 MsiDatabaseCommit( hdb
);
2435 /* check new values */
2437 query
= "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
2438 r
= do_query(hdb
, query
, &hrec
);
2439 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2440 MsiCloseHandle(hrec
);
2442 query
= "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
2444 r
= do_query(hdb
, query
, &hrec
);
2445 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2446 MsiCloseHandle(hrec
);
2448 /* check updated values */
2450 query
= "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
2451 r
= do_query(hdb
, query
, &hrec
);
2452 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2453 MsiCloseHandle(hrec
);
2455 /* check unchanged value */
2457 query
= "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
2458 r
= do_query(hdb
, query
, &hrec
);
2459 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2460 MsiCloseHandle(hrec
);
2462 /* check deleted value */
2464 query
= "select * from `MOO` where `NOO` = 3";
2465 r
= do_query(hdb
, query
, &hrec
);
2466 ok(r
== ERROR_NO_MORE_ITEMS
, "select query failed\n");
2467 if (hrec
) MsiCloseHandle(hrec
);
2469 /* check added stream */
2471 query
= "select `BLOB` from `BINARY` where `ID` = 1";
2472 r
= do_query(hdb
, query
, &hrec
);
2473 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2475 /* check the contents of the stream */
2477 r
= MsiRecordReadStream( hrec
, 1, buffer
, &sz
);
2478 ok(r
== ERROR_SUCCESS
, "read stream failed\n");
2479 ok(!memcmp(buffer
, "naengmyon", 9), "stream data was wrong\n");
2480 ok(sz
== 9, "stream data was wrong size\n");
2481 if (hrec
) MsiCloseHandle(hrec
);
2483 /* check the validity of the table with a deleted row */
2485 query
= "select * from `MOO`";
2486 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2487 ok(r
== ERROR_SUCCESS
, "open view failed\n");
2489 r
= MsiViewExecute(hview
, 0);
2490 ok(r
== ERROR_SUCCESS
, "view execute failed\n");
2492 r
= MsiViewFetch(hview
, &hrec
);
2493 ok(r
== ERROR_SUCCESS
, "view fetch failed\n");
2495 r
= MsiRecordGetInteger(hrec
, 1);
2496 ok(r
== 1, "Expected 1, got %d\n", r
);
2499 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
2500 ok(r
== ERROR_SUCCESS
, "record get string failed\n");
2501 ok(!lstrcmpA(buffer
, "c"), "Expected c, got %s\n", buffer
);
2503 r
= MsiRecordGetInteger(hrec
, 3);
2504 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
2506 r
= MsiRecordGetInteger(hrec
, 4);
2507 ok(r
== 5, "Expected 5, got %d\n", r
);
2509 MsiCloseHandle(hrec
);
2511 r
= MsiViewFetch(hview
, &hrec
);
2512 ok(r
== ERROR_SUCCESS
, "view fetch failed\n");
2514 r
= MsiRecordGetInteger(hrec
, 1);
2515 ok(r
== 2, "Expected 2, got %d\n", r
);
2518 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
2519 ok(r
== ERROR_SUCCESS
, "record get string failed\n");
2520 ok(!lstrcmpA(buffer
, "b"), "Expected b, got %s\n", buffer
);
2522 r
= MsiRecordGetInteger(hrec
, 3);
2523 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
2525 r
= MsiRecordGetInteger(hrec
, 4);
2526 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
2528 MsiCloseHandle(hrec
);
2530 r
= MsiViewFetch(hview
, &hrec
);
2531 ok(r
== ERROR_NO_MORE_ITEMS
, "view fetch succeeded\n");
2533 MsiCloseHandle(hrec
);
2534 MsiCloseHandle(hview
);
2536 /* check that the property was added */
2537 hpkg
= package_from_db(hdb
);
2538 ok(hpkg
!= 0, "Expected non-NULL hpkg\n");
2541 r
= MsiGetProperty(hpkg
, "prop", buffer
, &sz
);
2542 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2543 ok(!lstrcmp(buffer
, "val"), "Expected val, got %s\n", buffer
);
2545 MsiCloseHandle(hpkg
);
2546 MsiCloseHandle(hdb
);
2548 DeleteFile(msifile
);
2549 DeleteFile(mstfile
);
2554 const CHAR one
[MAX_PATH
];
2555 const CHAR two
[MAX_PATH
];
2558 struct join_res_4col
2560 const CHAR one
[MAX_PATH
];
2561 const CHAR two
[MAX_PATH
];
2562 const CHAR three
[MAX_PATH
];
2563 const CHAR four
[MAX_PATH
];
2566 struct join_res_uint
2576 static const struct join_res join_res_first
[] =
2578 { "alveolar", "procerus" },
2579 { "septum", "procerus" },
2580 { "septum", "nasalis" },
2581 { "ramus", "nasalis" },
2582 { "malar", "mentalis" },
2585 static const struct join_res join_res_second
[] =
2587 { "nasal", "septum" },
2588 { "mandible", "ramus" },
2591 static const struct join_res join_res_third
[] =
2593 { "msvcp.dll", "abcdefgh" },
2594 { "msvcr.dll", "ijklmnop" },
2597 static const struct join_res join_res_fourth
[] =
2599 { "msvcp.dll.01234", "single.dll.31415" },
2602 static const struct join_res join_res_fifth
[] =
2604 { "malar", "procerus" },
2607 static const struct join_res join_res_sixth
[] =
2609 { "malar", "procerus" },
2610 { "malar", "procerus" },
2611 { "malar", "nasalis" },
2612 { "malar", "nasalis" },
2613 { "malar", "nasalis" },
2614 { "malar", "mentalis" },
2617 static const struct join_res join_res_seventh
[] =
2619 { "malar", "nasalis" },
2620 { "malar", "nasalis" },
2621 { "malar", "nasalis" },
2624 static const struct join_res_4col join_res_eighth
[] =
2626 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
2627 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
2628 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
2629 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
2630 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
2631 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
2634 static const struct join_res_uint join_res_ninth
[] =
2636 { 1, 2, 3, 4, 7, 8 },
2637 { 1, 2, 5, 6, 7, 8 },
2638 { 1, 2, 3, 4, 9, 10 },
2639 { 1, 2, 5, 6, 9, 10 },
2640 { 1, 2, 3, 4, 11, 12 },
2641 { 1, 2, 5, 6, 11, 12 },
2644 static void test_join(void)
2646 MSIHANDLE hdb
, hview
, hrec
;
2654 ok( hdb
, "failed to create db\n");
2656 r
= create_component_table( hdb
);
2657 ok( r
== ERROR_SUCCESS
, "cannot create Component table: %d\n", r
);
2659 r
= add_component_entry( hdb
, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
2660 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2662 r
= add_component_entry( hdb
, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
2663 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2665 r
= add_component_entry( hdb
, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
2666 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2668 r
= add_component_entry( hdb
, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
2669 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2671 r
= create_feature_components_table( hdb
);
2672 ok( r
== ERROR_SUCCESS
, "cannot create FeatureComponents table: %d\n", r
);
2674 r
= add_feature_components_entry( hdb
, "'procerus', 'maxilla'" );
2675 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2677 r
= add_feature_components_entry( hdb
, "'procerus', 'nasal'" );
2678 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2680 r
= add_feature_components_entry( hdb
, "'nasalis', 'nasal'" );
2681 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2683 r
= add_feature_components_entry( hdb
, "'nasalis', 'mandible'" );
2684 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2686 r
= add_feature_components_entry( hdb
, "'nasalis', 'notacomponent'" );
2687 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2689 r
= add_feature_components_entry( hdb
, "'mentalis', 'zygomatic'" );
2690 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2692 r
= create_std_dlls_table( hdb
);
2693 ok( r
== ERROR_SUCCESS
, "cannot create StdDlls table: %d\n", r
);
2695 r
= add_std_dlls_entry( hdb
, "'msvcp.dll', 'msvcp.dll.01234'" );
2696 ok( r
== ERROR_SUCCESS
, "cannot add std dlls: %d\n", r
);
2698 r
= add_std_dlls_entry( hdb
, "'msvcr.dll', 'msvcr.dll.56789'" );
2699 ok( r
== ERROR_SUCCESS
, "cannot add std dlls: %d\n", r
);
2701 r
= create_binary_table( hdb
);
2702 ok( r
== ERROR_SUCCESS
, "cannot create Binary table: %d\n", r
);
2704 r
= add_binary_entry( hdb
, "'msvcp.dll.01234', 'abcdefgh'" );
2705 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
2707 r
= add_binary_entry( hdb
, "'msvcr.dll.56789', 'ijklmnop'" );
2708 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
2710 r
= add_binary_entry( hdb
, "'single.dll.31415', 'msvcp.dll'" );
2711 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
2713 query
= "CREATE TABLE `One` (`A` SHORT, `B` SHORT PRIMARY KEY `A`)";
2714 r
= run_query( hdb
, 0, query
);
2715 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2717 query
= "CREATE TABLE `Two` (`C` SHORT, `D` SHORT PRIMARY KEY `C`)";
2718 r
= run_query( hdb
, 0, query
);
2719 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2721 query
= "CREATE TABLE `Three` (`E` SHORT, `F` SHORT PRIMARY KEY `E`)";
2722 r
= run_query( hdb
, 0, query
);
2723 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2725 query
= "INSERT INTO `One` (`A`, `B`) VALUES (1, 2)";
2726 r
= run_query( hdb
, 0, query
);
2727 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2729 query
= "INSERT INTO `Two` (`C`, `D`) VALUES (3, 4)";
2730 r
= run_query( hdb
, 0, query
);
2731 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2733 query
= "INSERT INTO `Two` (`C`, `D`) VALUES (5, 6)";
2734 r
= run_query( hdb
, 0, query
);
2735 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2737 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (7, 8)";
2738 r
= run_query( hdb
, 0, query
);
2739 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2741 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (9, 10)";
2742 r
= run_query( hdb
, 0, query
);
2743 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2745 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (11, 12)";
2746 r
= run_query( hdb
, 0, query
);
2747 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2749 query
= "CREATE TABLE `Four` (`G` SHORT, `H` SHORT PRIMARY KEY `G`)";
2750 r
= run_query( hdb
, 0, query
);
2751 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2753 query
= "CREATE TABLE `Five` (`I` SHORT, `J` SHORT PRIMARY KEY `I`)";
2754 r
= run_query( hdb
, 0, query
);
2755 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2757 query
= "INSERT INTO `Five` (`I`, `J`) VALUES (13, 14)";
2758 r
= run_query( hdb
, 0, query
);
2759 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2761 query
= "INSERT INTO `Five` (`I`, `J`) VALUES (15, 16)";
2762 r
= run_query( hdb
, 0, query
);
2763 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2765 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2766 "FROM `Component`, `FeatureComponents` "
2767 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
2768 "ORDER BY `Feature_`";
2769 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2770 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2772 r
= MsiViewExecute(hview
, 0);
2773 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2776 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2778 count
= MsiRecordGetFieldCount( hrec
);
2779 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2782 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2783 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2784 ok( !lstrcmp( buf
, join_res_first
[i
].one
),
2785 "For (row %d, column 1) expected '%s', got %s\n", i
, join_res_first
[i
].one
, buf
);
2788 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2789 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2790 ok( !lstrcmp( buf
, join_res_first
[i
].two
),
2791 "For (row %d, column 2) expected '%s', got %s\n", i
, join_res_first
[i
].two
, buf
);
2794 MsiCloseHandle(hrec
);
2797 ok( i
== 5, "Expected 5 rows, got %d\n", i
);
2798 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2800 MsiViewClose(hview
);
2801 MsiCloseHandle(hview
);
2803 /* try a join without a WHERE condition */
2804 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2805 "FROM `Component`, `FeatureComponents` ";
2806 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2807 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2809 r
= MsiViewExecute(hview
, 0);
2810 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2813 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2816 MsiCloseHandle(hrec
);
2818 ok( i
== 24, "Expected 24 rows, got %d\n", i
);
2820 MsiViewClose(hview
);
2821 MsiCloseHandle(hview
);
2823 query
= "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
2824 "WHERE FeatureComponents.Component_=Component.Component "
2825 "AND (Feature_='nasalis') ORDER BY Feature_";
2826 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2827 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2829 r
= MsiViewExecute(hview
, 0);
2830 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2833 data_correct
= TRUE
;
2834 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2836 count
= MsiRecordGetFieldCount( hrec
);
2837 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2840 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2841 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2842 if( lstrcmp( buf
, join_res_second
[i
].one
))
2843 data_correct
= FALSE
;
2846 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2847 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2848 if( lstrcmp( buf
, join_res_second
[i
].two
))
2849 data_correct
= FALSE
;
2852 MsiCloseHandle(hrec
);
2855 ok( data_correct
, "data returned in the wrong order\n");
2857 ok( i
== 2, "Expected 2 rows, got %d\n", i
);
2858 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2860 MsiViewClose(hview
);
2861 MsiCloseHandle(hview
);
2863 query
= "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2864 "FROM `StdDlls`, `Binary` "
2865 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
2867 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2868 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2870 r
= MsiViewExecute(hview
, 0);
2871 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2874 data_correct
= TRUE
;
2875 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2877 count
= MsiRecordGetFieldCount( hrec
);
2878 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2881 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2882 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2883 if( lstrcmp( buf
, join_res_third
[i
].one
) )
2884 data_correct
= FALSE
;
2887 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2888 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2889 if( lstrcmp( buf
, join_res_third
[i
].two
) )
2890 data_correct
= FALSE
;
2893 MsiCloseHandle(hrec
);
2895 ok( data_correct
, "data returned in the wrong order\n");
2897 ok( i
== 2, "Expected 2 rows, got %d\n", i
);
2899 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2901 MsiViewClose(hview
);
2902 MsiCloseHandle(hview
);
2904 query
= "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
2905 "FROM `StdDlls`, `Binary` "
2906 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
2908 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2909 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2911 r
= MsiViewExecute(hview
, 0);
2912 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2915 data_correct
= TRUE
;
2916 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2918 count
= MsiRecordGetFieldCount( hrec
);
2919 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2922 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2923 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2924 if( lstrcmp( buf
, join_res_fourth
[i
].one
))
2925 data_correct
= FALSE
;
2928 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2929 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2930 if( lstrcmp( buf
, join_res_fourth
[i
].two
))
2931 data_correct
= FALSE
;
2934 MsiCloseHandle(hrec
);
2936 ok( data_correct
, "data returned in the wrong order\n");
2938 ok( i
== 1, "Expected 1 rows, got %d\n", i
);
2939 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2941 MsiViewClose(hview
);
2942 MsiCloseHandle(hview
);
2944 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2945 "FROM `Component`, `FeatureComponents` "
2946 "WHERE `Component`.`Component` = 'zygomatic' "
2947 "AND `FeatureComponents`.`Component_` = 'maxilla' "
2948 "ORDER BY `Feature_`";
2949 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2950 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2952 r
= MsiViewExecute(hview
, 0);
2953 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2956 data_correct
= TRUE
;
2957 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2959 count
= MsiRecordGetFieldCount( hrec
);
2960 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2963 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2964 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2965 if( lstrcmp( buf
, join_res_fifth
[i
].one
))
2966 data_correct
= FALSE
;
2969 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2970 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2971 if( lstrcmp( buf
, join_res_fifth
[i
].two
))
2972 data_correct
= FALSE
;
2975 MsiCloseHandle(hrec
);
2977 ok( data_correct
, "data returned in the wrong order\n");
2979 ok( i
== 1, "Expected 1 rows, got %d\n", i
);
2980 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2982 MsiViewClose(hview
);
2983 MsiCloseHandle(hview
);
2985 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2986 "FROM `Component`, `FeatureComponents` "
2987 "WHERE `Component` = 'zygomatic' "
2988 "ORDER BY `Feature_`";
2989 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2990 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2992 r
= MsiViewExecute(hview
, 0);
2993 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2996 data_correct
= TRUE
;
2997 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2999 count
= MsiRecordGetFieldCount( hrec
);
3000 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3003 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3004 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3005 if( lstrcmp( buf
, join_res_sixth
[i
].one
))
3006 data_correct
= FALSE
;
3009 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3010 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3011 if( lstrcmp( buf
, join_res_sixth
[i
].two
))
3012 data_correct
= FALSE
;
3015 MsiCloseHandle(hrec
);
3017 ok( data_correct
, "data returned in the wrong order\n");
3019 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3020 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3022 MsiViewClose(hview
);
3023 MsiCloseHandle(hview
);
3025 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3026 "FROM `Component`, `FeatureComponents` "
3027 "WHERE `Component` = 'zygomatic' "
3028 "AND `Feature_` = 'nasalis' "
3029 "ORDER BY `Feature_`";
3030 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3031 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3033 r
= MsiViewExecute(hview
, 0);
3034 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3037 data_correct
= TRUE
;
3038 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3040 count
= MsiRecordGetFieldCount( hrec
);
3041 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3044 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3045 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3046 if( lstrcmp( buf
, join_res_seventh
[i
].one
))
3047 data_correct
= FALSE
;
3050 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3051 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3052 if( lstrcmp( buf
, join_res_seventh
[i
].two
))
3053 data_correct
= FALSE
;
3056 MsiCloseHandle(hrec
);
3059 ok( data_correct
, "data returned in the wrong order\n");
3060 ok( i
== 3, "Expected 3 rows, got %d\n", i
);
3061 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3063 MsiViewClose(hview
);
3064 MsiCloseHandle(hview
);
3066 query
= "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3067 "FROM `StdDlls`, `Binary` ";
3068 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3069 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3071 r
= MsiViewExecute(hview
, 0);
3072 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3075 data_correct
= TRUE
;
3076 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3078 count
= MsiRecordGetFieldCount( hrec
);
3079 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3082 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3083 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3084 if( lstrcmp( buf
, join_res_eighth
[i
].one
))
3085 data_correct
= FALSE
;
3088 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3089 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3090 if( lstrcmp( buf
, join_res_eighth
[i
].four
))
3091 data_correct
= FALSE
;
3094 MsiCloseHandle(hrec
);
3097 ok( data_correct
, "data returned in the wrong order\n");
3098 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3099 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3101 MsiViewClose(hview
);
3102 MsiCloseHandle(hview
);
3104 query
= "SELECT * FROM `StdDlls`, `Binary` ";
3105 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3106 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3108 r
= MsiViewExecute(hview
, 0);
3109 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3112 data_correct
= TRUE
;
3113 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3115 count
= MsiRecordGetFieldCount( hrec
);
3116 ok( count
== 4, "Expected 4 record fields, got %d\n", count
);
3119 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3120 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3121 if( lstrcmp( buf
, join_res_eighth
[i
].one
))
3122 data_correct
= FALSE
;
3125 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3126 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3127 if( lstrcmp( buf
, join_res_eighth
[i
].two
))
3128 data_correct
= FALSE
;
3131 r
= MsiRecordGetString( hrec
, 3, buf
, &size
);
3132 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3133 if( lstrcmp( buf
, join_res_eighth
[i
].three
))
3134 data_correct
= FALSE
;
3137 r
= MsiRecordGetString( hrec
, 4, buf
, &size
);
3138 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3139 if( lstrcmp( buf
, join_res_eighth
[i
].four
))
3140 data_correct
= FALSE
;
3143 MsiCloseHandle(hrec
);
3145 ok( data_correct
, "data returned in the wrong order\n");
3147 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3148 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3150 MsiViewClose(hview
);
3151 MsiCloseHandle(hview
);
3153 query
= "SELECT * FROM `One`, `Two`, `Three` ";
3154 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3155 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3157 r
= MsiViewExecute(hview
, 0);
3158 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3161 data_correct
= TRUE
;
3162 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3164 count
= MsiRecordGetFieldCount( hrec
);
3165 ok( count
== 6, "Expected 6 record fields, got %d\n", count
);
3167 r
= MsiRecordGetInteger( hrec
, 1 );
3168 if( r
!= join_res_ninth
[i
].one
)
3169 data_correct
= FALSE
;
3171 r
= MsiRecordGetInteger( hrec
, 2 );
3172 if( r
!= join_res_ninth
[i
].two
)
3173 data_correct
= FALSE
;
3175 r
= MsiRecordGetInteger( hrec
, 3 );
3176 if( r
!= join_res_ninth
[i
].three
)
3177 data_correct
= FALSE
;
3179 r
= MsiRecordGetInteger( hrec
, 4 );
3180 if( r
!= join_res_ninth
[i
].four
)
3181 data_correct
= FALSE
;
3183 r
= MsiRecordGetInteger( hrec
, 5 );
3184 if( r
!= join_res_ninth
[i
].five
)
3185 data_correct
= FALSE
;
3187 r
= MsiRecordGetInteger( hrec
, 6);
3188 if( r
!= join_res_ninth
[i
].six
)
3189 data_correct
= FALSE
;
3192 MsiCloseHandle(hrec
);
3194 ok( data_correct
, "data returned in the wrong order\n");
3196 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3197 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3199 MsiViewClose(hview
);
3200 MsiCloseHandle(hview
);
3202 query
= "SELECT * FROM `Four`, `Five`";
3203 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3204 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3206 r
= MsiViewExecute(hview
, 0);
3207 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3209 r
= MsiViewFetch(hview
, &hrec
);
3210 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3212 MsiViewClose(hview
);
3213 MsiCloseHandle(hview
);
3215 query
= "SELECT * FROM `Nonexistent`, `One`";
3216 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3217 ok( r
== ERROR_BAD_QUERY_SYNTAX
,
3218 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3220 MsiCloseHandle(hdb
);
3221 DeleteFile(msifile
);
3224 static void test_temporary_table(void)
3227 MSIHANDLE hdb
= 0, view
= 0, rec
;
3233 cond
= MsiDatabaseIsTablePersistent(0, NULL
);
3234 ok( cond
== MSICONDITION_ERROR
, "wrong return condition\n");
3237 ok( hdb
, "failed to create db\n");
3239 cond
= MsiDatabaseIsTablePersistent(hdb
, NULL
);
3240 ok( cond
== MSICONDITION_ERROR
, "wrong return condition\n");
3243 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Tables");
3244 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3246 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Columns");
3247 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3250 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Storages");
3251 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3253 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Streams");
3254 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3256 query
= "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
3257 r
= run_query(hdb
, 0, query
);
3258 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3260 cond
= MsiDatabaseIsTablePersistent(hdb
, "P");
3261 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3263 query
= "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
3264 r
= run_query(hdb
, 0, query
);
3265 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3267 cond
= MsiDatabaseIsTablePersistent(hdb
, "P2");
3268 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3270 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3271 r
= run_query(hdb
, 0, query
);
3272 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3274 cond
= MsiDatabaseIsTablePersistent(hdb
, "T");
3275 ok( cond
== MSICONDITION_FALSE
, "wrong return condition\n");
3277 query
= "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3278 r
= run_query(hdb
, 0, query
);
3279 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3282 cond
= MsiDatabaseIsTablePersistent(hdb
, "T2");
3283 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3286 query
= "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
3287 r
= run_query(hdb
, 0, query
);
3288 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3290 cond
= MsiDatabaseIsTablePersistent(hdb
, "T3");
3291 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3294 query
= "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3295 r
= run_query(hdb
, 0, query
);
3296 ok(r
== ERROR_FUNCTION_FAILED
, "failed to add table\n");
3298 cond
= MsiDatabaseIsTablePersistent(hdb
, "T4");
3299 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3302 query
= "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
3303 r
= run_query(hdb
, 0, query
);
3304 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to add table\n");
3306 query
= "select * from `T`";
3307 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3308 ok(r
== ERROR_SUCCESS
, "failed to query table\n");
3309 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
3310 ok(r
== ERROR_SUCCESS
, "failed to get column info\n");
3313 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
3314 ok(r
== ERROR_SUCCESS
, "failed to get string\n");
3315 todo_wine
ok( 0 == strcmp("G255", buf
), "wrong column type\n");
3318 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
3319 ok(r
== ERROR_SUCCESS
, "failed to get string\n");
3320 todo_wine
ok( 0 == strcmp("j2", buf
), "wrong column type\n");
3322 MsiCloseHandle( rec
);
3323 MsiCloseHandle( view
);
3325 /* query the table data */
3327 r
= do_query(hdb
, "select * from `_Tables` where `Name` = 'T'", &rec
);
3328 ok( r
== ERROR_SUCCESS
, "temporary table exists in _Tables\n");
3329 MsiCloseHandle( rec
);
3331 /* query the column data */
3333 r
= do_query(hdb
, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec
);
3334 ok( r
== ERROR_NO_MORE_ITEMS
, "temporary table exists in _Columns\n");
3335 if (rec
) MsiCloseHandle( rec
);
3337 r
= do_query(hdb
, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec
);
3338 ok( r
== ERROR_NO_MORE_ITEMS
, "temporary table exists in _Columns\n");
3339 if (rec
) MsiCloseHandle( rec
);
3341 MsiCloseHandle( hdb
);
3343 DeleteFile(msifile
);
3346 static void test_alter(void)
3354 ok( hdb
, "failed to create db\n");
3356 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3357 r
= run_query(hdb
, 0, query
);
3358 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3360 cond
= MsiDatabaseIsTablePersistent(hdb
, "T");
3361 ok( cond
== MSICONDITION_FALSE
, "wrong return condition\n");
3363 query
= "ALTER TABLE `T` HOLD";
3364 r
= run_query(hdb
, 0, query
);
3365 ok(r
== ERROR_SUCCESS
, "failed to hold table %d\n", r
);
3367 query
= "ALTER TABLE `T` FREE";
3368 r
= run_query(hdb
, 0, query
);
3369 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
3371 query
= "ALTER TABLE `T` FREE";
3372 r
= run_query(hdb
, 0, query
);
3373 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
3375 query
= "ALTER TABLE `T` FREE";
3376 r
= run_query(hdb
, 0, query
);
3377 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to free table\n");
3379 query
= "ALTER TABLE `T` HOLD";
3380 r
= run_query(hdb
, 0, query
);
3381 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to hold table %d\n", r
);
3383 /* table T is removed */
3384 query
= "SELECT * FROM `T`";
3385 r
= run_query(hdb
, 0, query
);
3386 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3388 /* create the table again */
3389 query
= "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
3390 r
= run_query(hdb
, 0, query
);
3391 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3393 /* up the ref count */
3394 query
= "ALTER TABLE `U` HOLD";
3395 r
= run_query(hdb
, 0, query
);
3396 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
3398 /* add column, no data type */
3399 query
= "ALTER TABLE `U` ADD `C`";
3400 r
= run_query(hdb
, 0, query
);
3401 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3403 query
= "ALTER TABLE `U` ADD `C` INTEGER";
3404 r
= run_query(hdb
, 0, query
);
3405 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3407 /* add column C again */
3408 query
= "ALTER TABLE `U` ADD `C` INTEGER";
3409 r
= run_query(hdb
, 0, query
);
3410 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3412 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
3413 r
= run_query(hdb
, 0, query
);
3414 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3416 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
3417 r
= run_query(hdb
, 0, query
);
3418 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3420 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
3421 r
= run_query(hdb
, 0, query
);
3422 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3424 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
3425 r
= run_query(hdb
, 0, query
);
3426 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3428 query
= "SELECT * FROM `U` WHERE `D` = 8";
3429 r
= run_query(hdb
, 0, query
);
3430 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3432 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
3433 r
= run_query(hdb
, 0, query
);
3434 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3436 query
= "ALTER COLUMN `D` FREE";
3437 r
= run_query(hdb
, 0, query
);
3438 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3440 /* drop the ref count */
3441 query
= "ALTER TABLE `U` FREE";
3442 r
= run_query(hdb
, 0, query
);
3443 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3445 /* table is not empty */
3446 query
= "SELECT * FROM `U`";
3447 r
= run_query(hdb
, 0, query
);
3448 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3450 /* column D is removed */
3451 query
= "SELECT * FROM `U` WHERE `D` = 8";
3452 r
= run_query(hdb
, 0, query
);
3453 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3455 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
3456 r
= run_query(hdb
, 0, query
);
3457 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3459 /* add the column again */
3460 query
= "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
3461 r
= run_query(hdb
, 0, query
);
3462 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3464 /* up the ref count */
3465 query
= "ALTER TABLE `U` HOLD";
3466 r
= run_query(hdb
, 0, query
);
3467 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3469 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
3470 r
= run_query(hdb
, 0, query
);
3471 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3473 query
= "SELECT * FROM `U` WHERE `E` = 16";
3474 r
= run_query(hdb
, 0, query
);
3475 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3477 /* drop the ref count */
3478 query
= "ALTER TABLE `U` FREE";
3479 r
= run_query(hdb
, 0, query
);
3480 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3482 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
3483 r
= run_query(hdb
, 0, query
);
3484 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3486 query
= "SELECT * FROM `U` WHERE `E` = 20";
3487 r
= run_query(hdb
, 0, query
);
3488 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3490 /* drop the ref count */
3491 query
= "ALTER TABLE `U` FREE";
3492 r
= run_query(hdb
, 0, query
);
3493 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3495 /* table still exists */
3496 query
= "SELECT * FROM `U`";
3497 r
= run_query(hdb
, 0, query
);
3498 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3500 /* col E is removed */
3501 query
= "SELECT * FROM `U` WHERE `E` = 20";
3502 r
= run_query(hdb
, 0, query
);
3503 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3505 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
3506 r
= run_query(hdb
, 0, query
);
3507 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3509 /* drop the ref count once more */
3510 query
= "ALTER TABLE `U` FREE";
3511 r
= run_query(hdb
, 0, query
);
3512 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3514 /* table still exists */
3515 query
= "SELECT * FROM `U`";
3516 r
= run_query(hdb
, 0, query
);
3517 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3519 MsiCloseHandle( hdb
);
3520 DeleteFile(msifile
);
3523 static void test_integers(void)
3525 MSIHANDLE hdb
= 0, view
= 0, rec
= 0;
3530 /* just MsiOpenDatabase should not create a file */
3531 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
3532 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
3534 /* create a table */
3535 query
= "CREATE TABLE `integers` ( "
3536 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
3537 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
3538 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
3539 "PRIMARY KEY `one`)";
3540 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3541 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
3542 r
= MsiViewExecute(view
, 0);
3543 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
3544 r
= MsiViewClose(view
);
3545 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3546 r
= MsiCloseHandle(view
);
3547 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3549 query
= "SELECT * FROM `integers`";
3550 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3551 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3553 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
3554 count
= MsiRecordGetFieldCount(rec
);
3555 ok(count
== 8, "Expected 8, got %d\n", count
);
3556 ok(check_record(rec
, 1, "one"), "Expected one\n");
3557 ok(check_record(rec
, 2, "two"), "Expected two\n");
3558 ok(check_record(rec
, 3, "three"), "Expected three\n");
3559 ok(check_record(rec
, 4, "four"), "Expected four\n");
3560 ok(check_record(rec
, 5, "five"), "Expected five\n");
3561 ok(check_record(rec
, 6, "six"), "Expected six\n");
3562 ok(check_record(rec
, 7, "seven"), "Expected seven\n");
3563 ok(check_record(rec
, 8, "eight"), "Expected eight\n");
3564 MsiCloseHandle(rec
);
3566 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
3567 count
= MsiRecordGetFieldCount(rec
);
3568 ok(count
== 8, "Expected 8, got %d\n", count
);
3569 ok(check_record(rec
, 1, "I2"), "Expected I2\n");
3570 ok(check_record(rec
, 2, "I2"), "Expected I2\n");
3571 ok(check_record(rec
, 3, "I2"), "Expected I2\n");
3572 ok(check_record(rec
, 4, "I4"), "Expected I4\n");
3573 ok(check_record(rec
, 5, "i2"), "Expected i2\n");
3574 ok(check_record(rec
, 6, "i2"), "Expected i2\n");
3575 ok(check_record(rec
, 7, "i2"), "Expected i2\n");
3576 ok(check_record(rec
, 8, "i4"), "Expected i4\n");
3577 MsiCloseHandle(rec
);
3580 MsiCloseHandle(view
);
3582 /* insert values into it, NULL where NOT NULL is specified */
3583 query
= "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3584 "VALUES('', '', '', '', '', '', '', '')";
3585 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3586 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3587 r
= MsiViewExecute(view
, 0);
3588 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
3591 MsiCloseHandle(view
);
3593 query
= "SELECT * FROM `integers`";
3594 r
= do_query(hdb
, query
, &rec
);
3595 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3597 r
= MsiRecordGetFieldCount(rec
);
3598 ok(r
== -1, "record count wrong: %d\n", r
);
3600 MsiCloseHandle(rec
);
3602 /* insert legitimate values into it */
3603 query
= "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3604 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
3605 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3606 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3607 r
= MsiViewExecute(view
, 0);
3608 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3610 query
= "SELECT * FROM `integers`";
3611 r
= do_query(hdb
, query
, &rec
);
3612 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3614 r
= MsiRecordGetFieldCount(rec
);
3615 ok(r
== 8, "record count wrong: %d\n", r
);
3617 i
= MsiRecordGetInteger(rec
, 1);
3618 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
3619 i
= MsiRecordGetInteger(rec
, 3);
3620 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
3621 i
= MsiRecordGetInteger(rec
, 2);
3622 ok(i
== 2, "Expected 2, got %d\n", i
);
3623 i
= MsiRecordGetInteger(rec
, 4);
3624 ok(i
== 4, "Expected 4, got %d\n", i
);
3625 i
= MsiRecordGetInteger(rec
, 5);
3626 ok(i
== 5, "Expected 5, got %d\n", i
);
3627 i
= MsiRecordGetInteger(rec
, 6);
3628 ok(i
== 6, "Expected 6, got %d\n", i
);
3629 i
= MsiRecordGetInteger(rec
, 7);
3630 ok(i
== 7, "Expected 7, got %d\n", i
);
3631 i
= MsiRecordGetInteger(rec
, 8);
3632 ok(i
== 8, "Expected 8, got %d\n", i
);
3634 MsiCloseHandle(rec
);
3636 MsiCloseHandle(view
);
3638 r
= MsiDatabaseCommit(hdb
);
3639 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
3641 r
= MsiCloseHandle(hdb
);
3642 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3644 r
= DeleteFile(msifile
);
3645 ok(r
== TRUE
, "file didn't exist after commit\n");
3648 static void test_update(void)
3650 MSIHANDLE hdb
= 0, view
= 0, rec
= 0;
3651 CHAR result
[MAX_PATH
];
3656 /* just MsiOpenDatabase should not create a file */
3657 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
3658 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
3660 /* create the Control table */
3661 query
= "CREATE TABLE `Control` ( "
3662 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
3663 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
3664 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
3665 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
3666 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3667 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
3668 r
= MsiViewExecute(view
, 0);
3669 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
3670 r
= MsiViewClose(view
);
3671 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3672 r
= MsiCloseHandle(view
);
3673 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3676 query
= "INSERT INTO `Control` ( "
3677 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3678 "`Property`, `Text`, `Control_Next`, `Help` )"
3679 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3680 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3681 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3682 r
= MsiViewExecute(view
, 0);
3683 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3684 r
= MsiViewClose(view
);
3685 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3686 r
= MsiCloseHandle(view
);
3687 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3689 /* add a second control */
3690 query
= "INSERT INTO `Control` ( "
3691 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3692 "`Property`, `Text`, `Control_Next`, `Help` )"
3693 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
3694 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3695 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3696 r
= MsiViewExecute(view
, 0);
3697 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3698 r
= MsiViewClose(view
);
3699 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3700 r
= MsiCloseHandle(view
);
3701 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3703 /* add a third control */
3704 query
= "INSERT INTO `Control` ( "
3705 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3706 "`Property`, `Text`, `Control_Next`, `Help` )"
3707 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3708 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3709 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3710 r
= MsiViewExecute(view
, 0);
3711 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3712 r
= MsiViewClose(view
);
3713 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3714 r
= MsiCloseHandle(view
);
3715 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3718 query
= "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3719 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3720 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3722 /* bad set column */
3723 query
= "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3724 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3725 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3727 /* bad where condition */
3728 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
3729 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3730 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3732 /* just the dialog_ specified */
3733 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3734 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3735 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3736 r
= MsiViewExecute(view
, 0);
3737 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3738 r
= MsiViewClose(view
);
3739 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3740 r
= MsiCloseHandle(view
);
3741 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3743 /* check the modified text */
3744 query
= "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3745 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3746 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3747 r
= MsiViewExecute(view
, 0);
3748 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3750 r
= MsiViewFetch(view
, &rec
);
3751 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3754 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3755 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3756 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3758 MsiCloseHandle(rec
);
3760 r
= MsiViewFetch(view
, &rec
);
3761 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3764 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3765 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3766 ok(!lstrlen(result
), "Expected an empty string, got %s\n", result
);
3768 MsiCloseHandle(rec
);
3770 r
= MsiViewFetch(view
, &rec
);
3771 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3773 r
= MsiViewClose(view
);
3774 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3775 r
= MsiCloseHandle(view
);
3776 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3778 /* dialog_ and control specified */
3779 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
3780 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3781 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3782 r
= MsiViewExecute(view
, 0);
3783 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3784 r
= MsiViewClose(view
);
3785 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3786 r
= MsiCloseHandle(view
);
3787 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3789 /* check the modified text */
3790 query
= "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3791 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3792 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3793 r
= MsiViewExecute(view
, 0);
3794 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3796 r
= MsiViewFetch(view
, &rec
);
3797 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3800 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3801 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3802 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3804 MsiCloseHandle(rec
);
3806 r
= MsiViewFetch(view
, &rec
);
3807 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3810 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3811 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3812 ok(!lstrlen(result
), "Expected an empty string, got %s\n", result
);
3814 MsiCloseHandle(rec
);
3816 r
= MsiViewFetch(view
, &rec
);
3817 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3819 r
= MsiViewClose(view
);
3820 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3821 r
= MsiCloseHandle(view
);
3822 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3824 /* no where condition */
3825 query
= "UPDATE `Control` SET `Text` = 'this is text'";
3826 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3827 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3828 r
= MsiViewExecute(view
, 0);
3829 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3830 r
= MsiViewClose(view
);
3831 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3832 r
= MsiCloseHandle(view
);
3833 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3835 /* check the modified text */
3836 query
= "SELECT `Text` FROM `Control`";
3837 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3838 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3839 r
= MsiViewExecute(view
, 0);
3840 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3842 r
= MsiViewFetch(view
, &rec
);
3843 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3846 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3847 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3848 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3850 MsiCloseHandle(rec
);
3852 r
= MsiViewFetch(view
, &rec
);
3853 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3856 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3857 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3858 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3860 MsiCloseHandle(rec
);
3862 r
= MsiViewFetch(view
, &rec
);
3863 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3866 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3867 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3868 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3870 MsiCloseHandle(rec
);
3872 r
= MsiViewFetch(view
, &rec
);
3873 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3875 r
= MsiViewClose(view
);
3876 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3877 r
= MsiCloseHandle(view
);
3878 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3880 query
= "CREATE TABLE `Apple` ( `Banana` CHAR(72) NOT NULL, "
3881 "`Orange` CHAR(72), `Pear` INT PRIMARY KEY `Banana`)";
3882 r
= run_query(hdb
, 0, query
);
3883 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3885 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
3886 "VALUES('one', 'two', 3)";
3887 r
= run_query(hdb
, 0, query
);
3888 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3890 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
3891 "VALUES('three', 'four', 5)";
3892 r
= run_query(hdb
, 0, query
);
3893 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3895 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
3896 "VALUES('six', 'two', 7)";
3897 r
= run_query(hdb
, 0, query
);
3898 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3900 rec
= MsiCreateRecord(2);
3901 MsiRecordSetInteger(rec
, 1, 8);
3902 MsiRecordSetString(rec
, 2, "two");
3904 query
= "UPDATE `Apple` SET `Pear` = ? WHERE `Orange` = ?";
3905 r
= run_query(hdb
, rec
, query
);
3906 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3908 MsiCloseHandle(rec
);
3910 query
= "SELECT `Pear` FROM `Apple` ORDER BY `Orange`";
3911 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3912 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3913 r
= MsiViewExecute(view
, 0);
3914 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3916 r
= MsiViewFetch(view
, &rec
);
3917 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3919 r
= MsiRecordGetInteger(rec
, 1);
3920 ok(r
== 8, "Expected 8, got %d\n", r
);
3922 MsiCloseHandle(rec
);
3924 r
= MsiViewFetch(view
, &rec
);
3925 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3927 r
= MsiRecordGetInteger(rec
, 1);
3928 ok(r
== 8, "Expected 8, got %d\n", r
);
3930 MsiCloseHandle(rec
);
3932 r
= MsiViewFetch(view
, &rec
);
3933 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3935 r
= MsiRecordGetInteger(rec
, 1);
3936 ok(r
== 5, "Expected 5, got %d\n", r
);
3938 MsiCloseHandle(rec
);
3940 r
= MsiViewFetch(view
, &rec
);
3941 ok(r
== ERROR_NO_MORE_ITEMS
, "Expectd ERROR_NO_MORE_ITEMS, got %d\n", r
);
3944 MsiCloseHandle(view
);
3946 r
= MsiDatabaseCommit(hdb
);
3947 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
3948 r
= MsiCloseHandle(hdb
);
3949 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3951 DeleteFile(msifile
);
3954 static void test_special_tables(void)
3960 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
3961 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
3963 query
= "CREATE TABLE `_Properties` ( "
3964 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3965 r
= run_query(hdb
, 0, query
);
3966 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
3968 query
= "CREATE TABLE `_Storages` ( "
3969 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3970 r
= run_query(hdb
, 0, query
);
3971 todo_wine
ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Streams table\n");
3973 query
= "CREATE TABLE `_Streams` ( "
3974 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3975 r
= run_query(hdb
, 0, query
);
3976 todo_wine
ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Streams table\n");
3978 query
= "CREATE TABLE `_Tables` ( "
3979 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3980 r
= run_query(hdb
, 0, query
);
3981 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Tables table\n");
3983 query
= "CREATE TABLE `_Columns` ( "
3984 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3985 r
= run_query(hdb
, 0, query
);
3986 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Columns table\n");
3988 r
= MsiCloseHandle(hdb
);
3989 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3992 static void test_select_markers(void)
3994 MSIHANDLE hdb
= 0, rec
, view
, res
;
4001 ok( hdb
, "failed to create db\n");
4003 r
= run_query(hdb
, 0,
4004 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
4005 ok(r
== S_OK
, "cannot create table: %d\n", r
);
4007 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4008 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
4009 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4011 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4012 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
4013 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4015 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4016 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
4017 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4019 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4020 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
4021 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4023 rec
= MsiCreateRecord(2);
4024 MsiRecordSetString(rec
, 1, "apple");
4025 MsiRecordSetString(rec
, 2, "two");
4027 query
= "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
4028 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4029 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4031 r
= MsiViewExecute(view
, rec
);
4032 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4034 r
= MsiViewFetch(view
, &res
);
4035 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4038 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4039 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4040 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4043 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4044 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4045 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4047 r
= MsiRecordGetInteger(res
, 3);
4048 ok(r
== 1, "Expected 1, got %d\n", r
);
4050 MsiCloseHandle(res
);
4052 r
= MsiViewFetch(view
, &res
);
4053 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4056 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4057 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4058 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4061 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4062 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4063 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4065 r
= MsiRecordGetInteger(res
, 3);
4066 ok(r
== 2, "Expected 2, got %d\n", r
);
4068 MsiCloseHandle(res
);
4070 r
= MsiViewFetch(view
, &res
);
4071 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4073 MsiCloseHandle(rec
);
4075 MsiCloseHandle(view
);
4077 rec
= MsiCreateRecord(2);
4078 MsiRecordSetString(rec
, 1, "one");
4079 MsiRecordSetInteger(rec
, 2, 1);
4081 query
= "SELECT * FROM `Table` WHERE `Two`<>? AND `Three`>? ORDER BY `Three`";
4082 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4083 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4084 r
= MsiViewExecute(view
, rec
);
4085 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4087 r
= MsiViewFetch(view
, &res
);
4088 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4091 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4092 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4093 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4096 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4097 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4098 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4100 r
= MsiRecordGetInteger(res
, 3);
4101 ok(r
== 2, "Expected 2, got %d\n", r
);
4103 MsiCloseHandle(res
);
4105 r
= MsiViewFetch(view
, &res
);
4106 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4109 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4110 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4111 ok(!lstrcmp(buf
, "banana"), "Expected banana, got %s\n", buf
);
4114 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4115 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4116 ok(!lstrcmp(buf
, "three"), "Expected three, got %s\n", buf
);
4118 r
= MsiRecordGetInteger(res
, 3);
4119 ok(r
== 3, "Expected 3, got %d\n", r
);
4121 MsiCloseHandle(res
);
4123 r
= MsiViewFetch(view
, &res
);
4124 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4126 MsiCloseHandle(rec
);
4128 MsiCloseHandle(view
);
4129 MsiCloseHandle(hdb
);
4130 DeleteFile(msifile
);
4133 static void test_viewmodify_update(void)
4135 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4139 DeleteFile(msifile
);
4141 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4142 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4144 query
= "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
4145 r
= run_query( hdb
, 0, query
);
4146 ok(r
== ERROR_SUCCESS
, "query failed\n");
4148 query
= "INSERT INTO `table` (`A`, `B`) VALUES (1, 2)";
4149 r
= run_query( hdb
, 0, query
);
4150 ok(r
== ERROR_SUCCESS
, "query failed\n");
4152 query
= "INSERT INTO `table` (`A`, `B`) VALUES (3, 4)";
4153 r
= run_query( hdb
, 0, query
);
4154 ok(r
== ERROR_SUCCESS
, "query failed\n");
4156 query
= "INSERT INTO `table` (`A`, `B`) VALUES (5, 6)";
4157 r
= run_query( hdb
, 0, query
);
4158 ok(r
== ERROR_SUCCESS
, "query failed\n");
4160 query
= "SELECT `B` FROM `table`";
4161 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4162 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4163 r
= MsiViewExecute(hview
, 0);
4164 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4165 r
= MsiViewFetch(hview
, &hrec
);
4166 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4168 r
= MsiRecordSetInteger(hrec
, 1, 0);
4169 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
4171 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
4172 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
4174 r
= MsiCloseHandle(hrec
);
4175 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4177 r
= MsiViewClose(hview
);
4178 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4179 r
= MsiCloseHandle(hview
);
4180 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4182 query
= "SELECT * FROM `table`";
4183 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4184 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4185 r
= MsiViewExecute(hview
, 0);
4186 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4187 r
= MsiViewFetch(hview
, &hrec
);
4188 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4190 r
= MsiRecordGetInteger(hrec
, 1);
4191 ok(r
== 1, "Expected 1, got %d\n", r
);
4192 r
= MsiRecordGetInteger(hrec
, 2);
4193 ok(r
== 0, "Expected 0, got %d\n", r
);
4195 r
= MsiCloseHandle(hrec
);
4196 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4198 r
= MsiViewFetch(hview
, &hrec
);
4199 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4201 r
= MsiRecordGetInteger(hrec
, 1);
4202 ok(r
== 3, "Expected 3, got %d\n", r
);
4203 r
= MsiRecordGetInteger(hrec
, 2);
4204 ok(r
== 4, "Expected 4, got %d\n", r
);
4206 r
= MsiCloseHandle(hrec
);
4207 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4209 r
= MsiViewFetch(hview
, &hrec
);
4210 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4212 r
= MsiRecordGetInteger(hrec
, 1);
4213 ok(r
== 5, "Expected 5, got %d\n", r
);
4214 r
= MsiRecordGetInteger(hrec
, 2);
4215 ok(r
== 6, "Expected 6, got %d\n", r
);
4217 r
= MsiCloseHandle(hrec
);
4218 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4220 r
= MsiViewFetch(hview
, &hrec
);
4221 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4223 r
= MsiViewClose(hview
);
4224 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4225 r
= MsiCloseHandle(hview
);
4226 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4228 /* loop through all elements */
4229 query
= "SELECT `B` FROM `table`";
4230 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4231 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4232 r
= MsiViewExecute(hview
, 0);
4233 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4237 r
= MsiViewFetch(hview
, &hrec
);
4238 if (r
!= ERROR_SUCCESS
)
4241 r
= MsiRecordSetInteger(hrec
, 1, 0);
4242 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
4244 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
4245 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
4247 r
= MsiCloseHandle(hrec
);
4248 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4251 r
= MsiViewClose(hview
);
4252 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4253 r
= MsiCloseHandle(hview
);
4254 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4256 query
= "SELECT * FROM `table`";
4257 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4258 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4259 r
= MsiViewExecute(hview
, 0);
4260 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4261 r
= MsiViewFetch(hview
, &hrec
);
4262 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4264 r
= MsiRecordGetInteger(hrec
, 1);
4265 ok(r
== 1, "Expected 1, got %d\n", r
);
4266 r
= MsiRecordGetInteger(hrec
, 2);
4267 ok(r
== 0, "Expected 0, got %d\n", r
);
4269 r
= MsiCloseHandle(hrec
);
4270 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4272 r
= MsiViewFetch(hview
, &hrec
);
4273 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4275 r
= MsiRecordGetInteger(hrec
, 1);
4276 ok(r
== 3, "Expected 3, got %d\n", r
);
4277 r
= MsiRecordGetInteger(hrec
, 2);
4278 ok(r
== 0, "Expected 0, got %d\n", r
);
4280 r
= MsiCloseHandle(hrec
);
4281 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4283 r
= MsiViewFetch(hview
, &hrec
);
4284 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4286 r
= MsiRecordGetInteger(hrec
, 1);
4287 ok(r
== 5, "Expected 5, got %d\n", r
);
4288 r
= MsiRecordGetInteger(hrec
, 2);
4289 ok(r
== 0, "Expected 0, got %d\n", r
);
4291 r
= MsiCloseHandle(hrec
);
4292 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4294 r
= MsiViewFetch(hview
, &hrec
);
4295 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4297 r
= MsiViewClose(hview
);
4298 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4299 r
= MsiCloseHandle(hview
);
4300 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4302 r
= MsiCloseHandle( hdb
);
4303 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
4306 static const WCHAR data10
[] = { /* MOO */
4309 static const WCHAR data11
[] = { /* AAR */
4313 static const char data12
[] = /* _StringData */
4314 "MOOABAARCDonetwofourfive";
4315 static const WCHAR data13
[] = { /* _StringPool */
4317 0, 0, /* string 0 '' */
4318 0, 0, /* string 1 '' */
4319 0, 0, /* string 2 '' */
4320 0, 0, /* string 3 '' */
4321 0, 0, /* string 4 '' */
4322 3, 3, /* string 5 'MOO' */
4323 1, 1, /* string 6 'A' */
4324 1, 1, /* string 7 'B' */
4325 3, 3, /* string 8 'AAR' */
4326 1, 1, /* string 9 'C' */
4327 1, 1, /* string a 'D' */
4328 3, 1, /* string b 'one' */
4329 3, 1, /* string c 'two' */
4330 0, 0, /* string d '' */
4331 4, 1, /* string e 'four' */
4332 4, 1, /* string f 'five' */
4335 static void test_stringtable(void)
4337 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4338 IStorage
*stg
= NULL
;
4343 char buffer
[MAX_PATH
];
4344 WCHAR data
[MAX_PATH
];
4348 static const DWORD mode
= STGM_DIRECT
| STGM_READ
| STGM_SHARE_DENY_WRITE
;
4349 static const WCHAR stringdata
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0}; /* _StringData */
4350 static const WCHAR stringpool
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0}; /* _StringPool */
4351 static const WCHAR moo
[] = {0x4840, 0x3e16, 0x4818, 0}; /* MOO */
4352 static const WCHAR aar
[] = {0x4840, 0x3a8a, 0x481b, 0}; /* AAR */
4354 DeleteFile(msifile
);
4356 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4357 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4359 query
= "CREATE TABLE `MOO` (`A` INT, `B` CHAR(72) PRIMARY KEY `A`)";
4360 r
= run_query(hdb
, 0, query
);
4361 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4363 query
= "CREATE TABLE `AAR` (`C` INT, `D` CHAR(72) PRIMARY KEY `C`)";
4364 r
= run_query(hdb
, 0, query
);
4365 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4367 /* insert persistent row */
4368 query
= "INSERT INTO `MOO` (`A`, `B`) VALUES (1, 'one')";
4369 r
= run_query(hdb
, 0, query
);
4370 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4372 /* insert persistent row */
4373 query
= "INSERT INTO `AAR` (`C`, `D`) VALUES (2, 'two')";
4374 r
= run_query(hdb
, 0, query
);
4375 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4378 query
= "SELECT * FROM `MOO`";
4379 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4380 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4381 r
= MsiViewExecute(hview
, 0);
4382 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4384 hrec
= MsiCreateRecord(2);
4386 r
= MsiRecordSetInteger(hrec
, 1, 3);
4387 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4388 r
= MsiRecordSetString(hrec
, 2, "three");
4389 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4391 /* insert a nonpersistent row */
4392 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
4393 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4395 r
= MsiCloseHandle(hrec
);
4396 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4397 r
= MsiViewClose(hview
);
4398 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4399 r
= MsiCloseHandle(hview
);
4400 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4402 /* insert persistent row */
4403 query
= "INSERT INTO `MOO` (`A`, `B`) VALUES (4, 'four')";
4404 r
= run_query(hdb
, 0, query
);
4405 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4407 /* insert persistent row */
4408 query
= "INSERT INTO `AAR` (`C`, `D`) VALUES (5, 'five')";
4409 r
= run_query(hdb
, 0, query
);
4410 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4412 r
= MsiDatabaseCommit(hdb
);
4413 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4415 r
= MsiCloseHandle(hdb
);
4416 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4418 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
4419 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4421 query
= "SELECT * FROM `MOO`";
4422 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4423 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4425 r
= MsiViewExecute(hview
, 0);
4426 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4428 r
= MsiViewFetch(hview
, &hrec
);
4429 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4431 r
= MsiRecordGetFieldCount(hrec
);
4432 ok(r
== 2, "Expected 2, got %d\n", r
);
4434 r
= MsiRecordGetInteger(hrec
, 1);
4435 ok(r
== 1, "Expected 1, got %d\n", r
);
4437 sz
= sizeof(buffer
);
4438 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4439 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4440 ok(!lstrcmp(buffer
, "one"), "Expected one, got %s\n", buffer
);
4442 r
= MsiCloseHandle(hrec
);
4443 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4445 r
= MsiViewFetch(hview
, &hrec
);
4448 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4451 r
= MsiViewClose(hview
);
4452 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4453 r
= MsiCloseHandle(hview
);
4454 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4455 r
= MsiCloseHandle(hrec
);
4456 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4458 query
= "SELECT * FROM `AAR`";
4459 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4460 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4462 r
= MsiViewExecute(hview
, 0);
4463 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4465 r
= MsiViewFetch(hview
, &hrec
);
4466 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4468 r
= MsiRecordGetFieldCount(hrec
);
4469 ok(r
== 2, "Expected 2, got %d\n", r
);
4471 r
= MsiRecordGetInteger(hrec
, 1);
4472 ok(r
== 2, "Expected 2, got %d\n", r
);
4474 sz
= sizeof(buffer
);
4475 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4476 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4477 ok(!lstrcmp(buffer
, "two"), "Expected two, got %s\n", buffer
);
4479 r
= MsiCloseHandle(hrec
);
4480 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4482 r
= MsiViewFetch(hview
, &hrec
);
4483 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4485 r
= MsiRecordGetFieldCount(hrec
);
4486 ok(r
== 2, "Expected 2, got %d\n", r
);
4488 r
= MsiRecordGetInteger(hrec
, 1);
4489 ok(r
== 5, "Expected 5, got %d\n", r
);
4491 sz
= sizeof(buffer
);
4492 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4493 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4494 ok(!lstrcmp(buffer
, "five"), "Expected five, got %s\n", buffer
);
4496 r
= MsiCloseHandle(hrec
);
4497 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4499 r
= MsiViewFetch(hview
, &hrec
);
4500 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4502 r
= MsiViewClose(hview
);
4503 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4504 r
= MsiCloseHandle(hview
);
4505 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4506 r
= MsiCloseHandle(hrec
);
4507 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4508 r
= MsiCloseHandle(hdb
);
4509 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4511 MultiByteToWideChar(CP_ACP
, 0, msifile
, -1, name
, 0x20);
4512 hr
= StgOpenStorage(name
, NULL
, mode
, NULL
, 0, &stg
);
4513 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4514 ok(stg
!= NULL
, "Expected non-NULL storage\n");
4516 hr
= IStorage_OpenStream(stg
, moo
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4517 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4518 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4520 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
4521 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4524 ok(read
== 4, "Expected 4, got %d\n", read
);
4525 ok(!memcmp(data
, data10
, read
), "Unexpected data\n");
4528 hr
= IStream_Release(stm
);
4529 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4531 hr
= IStorage_OpenStream(stg
, aar
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4532 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4533 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4535 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
4536 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4537 ok(read
== 8, "Expected 8, got %d\n", read
);
4540 ok(!memcmp(data
, data11
, read
), "Unexpected data\n");
4543 hr
= IStream_Release(stm
);
4544 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4546 hr
= IStorage_OpenStream(stg
, stringdata
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4547 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4548 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4550 hr
= IStream_Read(stm
, buffer
, MAX_PATH
, &read
);
4551 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4552 ok(read
== 24, "Expected 24, got %d\n", read
);
4553 ok(!memcmp(buffer
, data12
, read
), "Unexpected data\n");
4555 hr
= IStream_Release(stm
);
4556 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4558 hr
= IStorage_OpenStream(stg
, stringpool
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4559 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4560 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4562 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
4563 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4566 ok(read
== 64, "Expected 64, got %d\n", read
);
4567 ok(!memcmp(data
, data13
, read
), "Unexpected data\n");
4570 hr
= IStream_Release(stm
);
4571 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4573 hr
= IStorage_Release(stg
);
4574 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4576 DeleteFileA(msifile
);
4579 static void test_viewmodify_delete(void)
4581 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4587 DeleteFile(msifile
);
4589 /* just MsiOpenDatabase should not create a file */
4590 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4591 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4593 query
= "CREATE TABLE `phone` ( "
4594 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
4595 "PRIMARY KEY `id`)";
4596 r
= run_query(hdb
, 0, query
);
4597 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4599 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
4600 "VALUES('1', 'Alan', '5030581')";
4601 r
= run_query(hdb
, 0, query
);
4602 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4604 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
4605 "VALUES('2', 'Barry', '928440')";
4606 r
= run_query(hdb
, 0, query
);
4607 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4609 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
4610 "VALUES('3', 'Cindy', '2937550')";
4611 r
= run_query(hdb
, 0, query
);
4612 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4614 query
= "SELECT * FROM `phone` WHERE `id` <= 2";
4615 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4616 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4617 r
= MsiViewExecute(hview
, 0);
4618 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4619 r
= MsiViewFetch(hview
, &hrec
);
4620 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4623 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
4624 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4626 r
= MsiCloseHandle(hrec
);
4627 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4628 r
= MsiViewFetch(hview
, &hrec
);
4629 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4632 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
4633 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4635 r
= MsiCloseHandle(hrec
);
4636 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4637 r
= MsiViewClose(hview
);
4638 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4639 r
= MsiCloseHandle(hview
);
4640 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4642 query
= "SELECT * FROM `phone`";
4643 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4644 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4645 r
= MsiViewExecute(hview
, 0);
4646 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4647 r
= MsiViewFetch(hview
, &hrec
);
4648 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4650 r
= MsiRecordGetInteger(hrec
, 1);
4651 ok(r
== 3, "Expected 3, got %d\n", r
);
4653 sz
= sizeof(buffer
);
4654 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4655 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4656 ok(!lstrcmp(buffer
, "Cindy"), "Expected Cindy, got %s\n", buffer
);
4658 sz
= sizeof(buffer
);
4659 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4660 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4661 ok(!lstrcmp(buffer
, "2937550"), "Expected 2937550, got %s\n", buffer
);
4663 r
= MsiCloseHandle(hrec
);
4664 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4666 r
= MsiViewFetch(hview
, &hrec
);
4667 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4669 r
= MsiViewClose(hview
);
4670 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4671 r
= MsiCloseHandle(hview
);
4672 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4673 r
= MsiCloseHandle(hdb
);
4674 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4677 static const WCHAR _Tables
[] = {0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0};
4678 static const WCHAR _StringData
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0};
4679 static const WCHAR _StringPool
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0};
4681 static const WCHAR data14
[] = { /* _StringPool */
4683 0, 0, /* string 0 '' */
4686 static const struct {
4690 } database_table_data
[] =
4693 {_StringData
, NULL
, 0},
4694 {_StringPool
, data14
, sizeof data14
},
4697 void enum_stream_names(IStorage
*stg
)
4699 IEnumSTATSTG
*stgenum
= NULL
;
4704 BYTE data
[MAX_PATH
];
4705 BYTE check
[MAX_PATH
];
4708 memset(check
, 'a', MAX_PATH
);
4710 hr
= IStorage_EnumElements(stg
, 0, NULL
, 0, &stgenum
);
4711 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
4717 hr
= IEnumSTATSTG_Next(stgenum
, 1, &stat
, &count
);
4718 if(FAILED(hr
) || !count
)
4721 ok(!lstrcmpW(stat
.pwcsName
, database_table_data
[n
].name
),
4722 "Expected table %d name to match\n", n
);
4725 hr
= IStorage_OpenStream(stg
, stat
.pwcsName
, NULL
,
4726 STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4727 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
4728 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4731 memset(data
, 'a', MAX_PATH
);
4732 hr
= IStream_Read(stm
, data
, sz
, &count
);
4733 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
4735 ok(count
== database_table_data
[n
].size
,
4736 "Expected %d, got %d\n", database_table_data
[n
].size
, count
);
4738 if (!database_table_data
[n
].size
)
4739 ok(!memcmp(data
, check
, MAX_PATH
), "data should not be changed\n");
4741 ok(!memcmp(data
, database_table_data
[n
].data
, database_table_data
[n
].size
),
4742 "Expected table %d data to match\n", n
);
4744 IStream_Release(stm
);
4748 ok(n
== 3, "Expected 3, got %d\n", n
);
4750 IEnumSTATSTG_Release(stgenum
);
4753 static void test_defaultdatabase(void)
4758 IStorage
*stg
= NULL
;
4760 static const WCHAR msifileW
[] = {'w','i','n','e','t','e','s','t','.','m','s','i',0};
4762 DeleteFile(msifile
);
4764 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4765 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4767 r
= MsiDatabaseCommit(hdb
);
4768 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4770 MsiCloseHandle(hdb
);
4772 hr
= StgOpenStorage(msifileW
, NULL
, STGM_READ
| STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
4773 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
4774 ok(stg
!= NULL
, "Expected non-NULL stg\n");
4776 enum_stream_names(stg
);
4778 IStorage_Release(stg
);
4779 DeleteFileA(msifile
);
4782 static void test_order(void)
4784 MSIHANDLE hdb
, hview
, hrec
;
4785 CHAR buffer
[MAX_PATH
];
4791 ok(hdb
, "failed to create db\n");
4793 query
= "CREATE TABLE `Empty` ( `A` SHORT NOT NULL PRIMARY KEY `A`)";
4794 r
= run_query(hdb
, 0, query
);
4795 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4797 query
= "CREATE TABLE `Mesa` ( `A` SHORT NOT NULL, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
4798 r
= run_query(hdb
, 0, query
);
4799 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4801 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 1, 2, 9 )";
4802 r
= run_query(hdb
, 0, query
);
4803 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4805 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 3, 4, 7 )";
4806 r
= run_query(hdb
, 0, query
);
4807 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4809 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 5, 6, 8 )";
4810 r
= run_query(hdb
, 0, query
);
4811 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4813 query
= "CREATE TABLE `Sideboard` ( `D` SHORT NOT NULL, `E` SHORT, `F` SHORT PRIMARY KEY `D`)";
4814 r
= run_query(hdb
, 0, query
);
4815 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4817 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 10, 11, 18 )";
4818 r
= run_query(hdb
, 0, query
);
4819 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4821 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 12, 13, 16 )";
4822 r
= run_query(hdb
, 0, query
);
4823 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4825 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 14, 15, 17 )";
4826 r
= run_query(hdb
, 0, query
);
4827 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4829 query
= "SELECT `A`, `B` FROM `Mesa` ORDER BY `C`";
4830 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4831 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4832 r
= MsiViewExecute(hview
, 0);
4833 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4835 r
= MsiViewFetch(hview
, &hrec
);
4836 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4838 val
= MsiRecordGetInteger(hrec
, 1);
4839 ok(val
== 3, "Expected 3, got %d\n", val
);
4841 val
= MsiRecordGetInteger(hrec
, 2);
4842 ok(val
== 4, "Expected 3, got %d\n", val
);
4844 MsiCloseHandle(hrec
);
4846 r
= MsiViewFetch(hview
, &hrec
);
4847 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4849 val
= MsiRecordGetInteger(hrec
, 1);
4850 ok(val
== 5, "Expected 5, got %d\n", val
);
4852 val
= MsiRecordGetInteger(hrec
, 2);
4853 ok(val
== 6, "Expected 6, got %d\n", val
);
4855 MsiCloseHandle(hrec
);
4857 r
= MsiViewFetch(hview
, &hrec
);
4858 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4860 val
= MsiRecordGetInteger(hrec
, 1);
4861 ok(val
== 1, "Expected 1, got %d\n", val
);
4863 val
= MsiRecordGetInteger(hrec
, 2);
4864 ok(val
== 2, "Expected 2, got %d\n", val
);
4866 MsiCloseHandle(hrec
);
4868 r
= MsiViewFetch(hview
, &hrec
);
4869 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4871 MsiViewClose(hview
);
4872 MsiCloseHandle(hview
);
4874 query
= "SELECT `A`, `D` FROM `Mesa`, `Sideboard` ORDER BY `F`";
4875 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4876 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4877 r
= MsiViewExecute(hview
, 0);
4878 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4880 r
= MsiViewFetch(hview
, &hrec
);
4881 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4883 val
= MsiRecordGetInteger(hrec
, 1);
4884 ok(val
== 1, "Expected 1, got %d\n", val
);
4886 val
= MsiRecordGetInteger(hrec
, 2);
4887 ok(val
== 12, "Expected 12, got %d\n", val
);
4889 MsiCloseHandle(hrec
);
4891 r
= MsiViewFetch(hview
, &hrec
);
4892 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4894 val
= MsiRecordGetInteger(hrec
, 1);
4895 ok(val
== 3, "Expected 3, got %d\n", val
);
4897 val
= MsiRecordGetInteger(hrec
, 2);
4898 ok(val
== 12, "Expected 12, got %d\n", val
);
4900 MsiCloseHandle(hrec
);
4902 r
= MsiViewFetch(hview
, &hrec
);
4903 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4905 val
= MsiRecordGetInteger(hrec
, 1);
4906 ok(val
== 5, "Expected 5, got %d\n", val
);
4908 val
= MsiRecordGetInteger(hrec
, 2);
4909 ok(val
== 12, "Expected 12, got %d\n", val
);
4911 MsiCloseHandle(hrec
);
4913 r
= MsiViewFetch(hview
, &hrec
);
4914 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4916 val
= MsiRecordGetInteger(hrec
, 1);
4917 ok(val
== 1, "Expected 1, got %d\n", val
);
4919 val
= MsiRecordGetInteger(hrec
, 2);
4920 ok(val
== 14, "Expected 14, got %d\n", val
);
4922 MsiCloseHandle(hrec
);
4924 r
= MsiViewFetch(hview
, &hrec
);
4925 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4927 val
= MsiRecordGetInteger(hrec
, 1);
4928 ok(val
== 3, "Expected 3, got %d\n", val
);
4930 val
= MsiRecordGetInteger(hrec
, 2);
4931 ok(val
== 14, "Expected 14, got %d\n", val
);
4933 MsiCloseHandle(hrec
);
4935 r
= MsiViewFetch(hview
, &hrec
);
4936 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4938 val
= MsiRecordGetInteger(hrec
, 1);
4939 ok(val
== 5, "Expected 5, got %d\n", val
);
4941 val
= MsiRecordGetInteger(hrec
, 2);
4942 ok(val
== 14, "Expected 14, got %d\n", val
);
4944 MsiCloseHandle(hrec
);
4946 r
= MsiViewFetch(hview
, &hrec
);
4947 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4949 val
= MsiRecordGetInteger(hrec
, 1);
4950 ok(val
== 1, "Expected 1, got %d\n", val
);
4952 val
= MsiRecordGetInteger(hrec
, 2);
4953 ok(val
== 10, "Expected 10, got %d\n", val
);
4955 MsiCloseHandle(hrec
);
4957 r
= MsiViewFetch(hview
, &hrec
);
4958 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4960 val
= MsiRecordGetInteger(hrec
, 1);
4961 ok(val
== 3, "Expected 3, got %d\n", val
);
4963 val
= MsiRecordGetInteger(hrec
, 2);
4964 ok(val
== 10, "Expected 10, got %d\n", val
);
4966 MsiCloseHandle(hrec
);
4968 r
= MsiViewFetch(hview
, &hrec
);
4969 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4971 val
= MsiRecordGetInteger(hrec
, 1);
4972 ok(val
== 5, "Expected 5, got %d\n", val
);
4974 val
= MsiRecordGetInteger(hrec
, 2);
4975 ok(val
== 10, "Expected 10, got %d\n", val
);
4977 MsiCloseHandle(hrec
);
4979 r
= MsiViewFetch(hview
, &hrec
);
4980 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4982 MsiViewClose(hview
);
4983 MsiCloseHandle(hview
);
4985 query
= "SELECT * FROM `Empty` ORDER BY `A`";
4986 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4987 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4988 r
= MsiViewExecute(hview
, 0);
4989 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4991 r
= MsiViewFetch(hview
, &hrec
);
4992 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4994 MsiViewClose(hview
);
4995 MsiCloseHandle(hview
);
4997 query
= "CREATE TABLE `Buffet` ( `One` CHAR(72), `Two` SHORT PRIMARY KEY `One`)";
4998 r
= run_query(hdb
, 0, query
);
4999 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5001 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'uno', 2)";
5002 r
= run_query(hdb
, 0, query
);
5003 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5005 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'dos', 3)";
5006 r
= run_query(hdb
, 0, query
);
5007 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5009 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'tres', 1)";
5010 r
= run_query(hdb
, 0, query
);
5011 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5013 query
= "SELECT * FROM `Buffet` WHERE `One` = 'dos' ORDER BY `Two`";
5014 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5015 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5016 r
= MsiViewExecute(hview
, 0);
5017 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5019 r
= MsiViewFetch(hview
, &hrec
);
5020 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5022 sz
= sizeof(buffer
);
5023 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
5024 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5025 ok(!lstrcmp(buffer
, "dos"), "Expected \"dos\", got \"%s\"\n", buffer
);
5027 r
= MsiRecordGetInteger(hrec
, 2);
5028 ok(r
== 3, "Expected 3, got %d\n", r
);
5030 MsiCloseHandle(hrec
);
5032 r
= MsiViewFetch(hview
, &hrec
);
5033 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5035 MsiViewClose(hview
);
5036 MsiCloseHandle(hview
);
5037 MsiCloseHandle(hdb
);
5040 static void test_viewmodify_delete_temporary(void)
5042 MSIHANDLE hdb
, hview
, hrec
;
5046 DeleteFile(msifile
);
5048 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5049 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5051 query
= "CREATE TABLE `Table` ( `A` SHORT PRIMARY KEY `A` )";
5052 r
= run_query(hdb
, 0, query
);
5053 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5055 query
= "SELECT * FROM `Table`";
5056 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5057 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5058 r
= MsiViewExecute(hview
, 0);
5059 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5061 hrec
= MsiCreateRecord(1);
5062 MsiRecordSetInteger(hrec
, 1, 1);
5064 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, hrec
);
5065 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5067 MsiCloseHandle(hrec
);
5069 hrec
= MsiCreateRecord(1);
5070 MsiRecordSetInteger(hrec
, 1, 2);
5072 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
5073 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5075 MsiCloseHandle(hrec
);
5077 hrec
= MsiCreateRecord(1);
5078 MsiRecordSetInteger(hrec
, 1, 3);
5080 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, hrec
);
5081 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5083 MsiCloseHandle(hrec
);
5085 hrec
= MsiCreateRecord(1);
5086 MsiRecordSetInteger(hrec
, 1, 4);
5088 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
5089 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5091 MsiCloseHandle(hrec
);
5092 MsiViewClose(hview
);
5093 MsiCloseHandle(hview
);
5095 query
= "SELECT * FROM `Table` WHERE `A` = 2";
5096 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5097 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5098 r
= MsiViewExecute(hview
, 0);
5099 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5100 r
= MsiViewFetch(hview
, &hrec
);
5101 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5103 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
5104 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5106 MsiCloseHandle(hrec
);
5107 MsiViewClose(hview
);
5108 MsiCloseHandle(hview
);
5110 query
= "SELECT * FROM `Table` WHERE `A` = 3";
5111 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5112 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5113 r
= MsiViewExecute(hview
, 0);
5114 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5115 r
= MsiViewFetch(hview
, &hrec
);
5116 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5118 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
5119 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5121 MsiCloseHandle(hrec
);
5122 MsiViewClose(hview
);
5123 MsiCloseHandle(hview
);
5125 query
= "SELECT * FROM `Table` ORDER BY `A`";
5126 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5127 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5128 r
= MsiViewExecute(hview
, 0);
5129 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5131 r
= MsiViewFetch(hview
, &hrec
);
5132 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5134 r
= MsiRecordGetInteger(hrec
, 1);
5135 ok(r
== 1, "Expected 1, got %d\n", r
);
5137 MsiCloseHandle(hrec
);
5139 r
= MsiViewFetch(hview
, &hrec
);
5140 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5142 r
= MsiRecordGetInteger(hrec
, 1);
5143 ok(r
== 4, "Expected 4, got %d\n", r
);
5145 MsiCloseHandle(hrec
);
5147 r
= MsiViewFetch(hview
, &hrec
);
5148 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5150 MsiViewClose(hview
);
5151 MsiCloseHandle(hview
);
5152 MsiCloseHandle(hdb
);
5153 DeleteFileA(msifile
);
5156 static void test_deleterow()
5158 MSIHANDLE hdb
, hview
, hrec
;
5164 DeleteFile(msifile
);
5166 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5167 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5169 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5170 r
= run_query(hdb
, 0, query
);
5171 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5173 query
= "INSERT INTO `Table` (`A`) VALUES ('one')";
5174 r
= run_query(hdb
, 0, query
);
5175 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5177 query
= "INSERT INTO `Table` (`A`) VALUES ('two')";
5178 r
= run_query(hdb
, 0, query
);
5179 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5181 query
= "DELETE FROM `Table` WHERE `A` = 'one'";
5182 r
= run_query(hdb
, 0, query
);
5183 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5185 r
= MsiDatabaseCommit(hdb
);
5186 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5188 MsiCloseHandle(hdb
);
5190 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
5191 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5193 query
= "SELECT * FROM `Table`";
5194 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5195 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5196 r
= MsiViewExecute(hview
, 0);
5197 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5199 r
= MsiViewFetch(hview
, &hrec
);
5200 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5203 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5204 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5205 ok(!lstrcmpA(buf
, "two"), "Expected two, got %s\n", buf
);
5207 MsiCloseHandle(hrec
);
5209 r
= MsiViewFetch(hview
, &hrec
);
5210 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5212 MsiViewClose(hview
);
5213 MsiCloseHandle(hview
);
5214 MsiCloseHandle(hdb
);
5215 DeleteFileA(msifile
);
5218 static const CHAR import_dat
[] = "A\n"
5221 "This is a new 'string' ok\n";
5223 static void test_quotes(void)
5225 MSIHANDLE hdb
, hview
, hrec
;
5231 DeleteFile(msifile
);
5233 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5234 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5236 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5237 r
= run_query(hdb
, 0, query
);
5238 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5240 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a 'string' ok' )";
5241 r
= run_query(hdb
, 0, query
);
5242 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5243 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5245 query
= "INSERT INTO `Table` ( `A` ) VALUES ( \"This is a 'string' ok\" )";
5246 r
= run_query(hdb
, 0, query
);
5247 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5248 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5250 query
= "INSERT INTO `Table` ( `A` ) VALUES ( \"test\" )";
5251 r
= run_query(hdb
, 0, query
);
5252 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5253 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5255 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a ''string'' ok' )";
5256 r
= run_query(hdb
, 0, query
);
5259 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5262 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a '''string''' ok' )";
5263 r
= run_query(hdb
, 0, query
);
5264 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5266 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \'string\' ok' )";
5267 r
= run_query(hdb
, 0, query
);
5268 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5270 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \"string\" ok' )";
5271 r
= run_query(hdb
, 0, query
);
5272 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5274 query
= "SELECT * FROM `Table`";
5275 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5276 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5278 r
= MsiViewExecute(hview
, 0);
5279 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5281 r
= MsiViewFetch(hview
, &hrec
);
5282 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5285 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
5286 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5289 ok(!lstrcmp(buf
, "This is a \"string\" ok"),
5290 "Expected \"This is a \"string\" ok\", got %s\n", buf
);
5293 MsiCloseHandle(hrec
);
5295 r
= MsiViewFetch(hview
, &hrec
);
5298 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5301 MsiCloseHandle(hview
);
5303 write_file("import.idt", import_dat
, (sizeof(import_dat
) - 1) * sizeof(char));
5305 r
= MsiDatabaseImportA(hdb
, CURR_DIR
, "import.idt");
5306 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5308 DeleteFileA("import.idt");
5310 query
= "SELECT * FROM `Table`";
5311 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5312 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5314 r
= MsiViewExecute(hview
, 0);
5315 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5317 r
= MsiViewFetch(hview
, &hrec
);
5318 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5321 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
5322 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5323 ok(!lstrcmp(buf
, "This is a new 'string' ok"),
5324 "Expected \"This is a new 'string' ok\", got %s\n", buf
);
5326 MsiCloseHandle(hrec
);
5328 r
= MsiViewFetch(hview
, &hrec
);
5329 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5331 MsiCloseHandle(hview
);
5333 MsiCloseHandle(hdb
);
5334 DeleteFileA(msifile
);
5337 static void test_carriagereturn(void)
5339 MSIHANDLE hdb
, hview
, hrec
;
5345 DeleteFile(msifile
);
5347 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5348 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5350 query
= "CREATE TABLE `Table`\r ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5351 r
= run_query(hdb
, 0, query
);
5354 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5355 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5358 query
= "CREATE TABLE `Table` \r( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5359 r
= run_query(hdb
, 0, query
);
5360 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5361 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5363 query
= "CREATE\r TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5364 r
= run_query(hdb
, 0, query
);
5365 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5366 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5368 query
= "CREATE TABLE\r `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5369 r
= run_query(hdb
, 0, query
);
5370 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5371 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5373 query
= "CREATE TABLE `Table` (\r `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5374 r
= run_query(hdb
, 0, query
);
5375 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5376 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5378 query
= "CREATE TABLE `Table` ( `A`\r CHAR(72) NOT NULL PRIMARY KEY `A` )";
5379 r
= run_query(hdb
, 0, query
);
5380 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5381 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5383 query
= "CREATE TABLE `Table` ( `A` CHAR(72)\r NOT NULL PRIMARY KEY `A` )";
5384 r
= run_query(hdb
, 0, query
);
5385 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5386 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5388 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT\r NULL PRIMARY KEY `A` )";
5389 r
= run_query(hdb
, 0, query
);
5390 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5391 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5393 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT \rNULL PRIMARY KEY `A` )";
5394 r
= run_query(hdb
, 0, query
);
5395 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5396 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5398 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL\r PRIMARY KEY `A` )";
5399 r
= run_query(hdb
, 0, query
);
5400 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5401 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5403 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL \rPRIMARY KEY `A` )";
5404 r
= run_query(hdb
, 0, query
);
5405 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5406 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5408 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY\r KEY `A` )";
5409 r
= run_query(hdb
, 0, query
);
5410 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5411 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5413 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY \rKEY `A` )";
5414 r
= run_query(hdb
, 0, query
);
5415 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5416 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5418 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY\r `A` )";
5419 r
= run_query(hdb
, 0, query
);
5420 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5421 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5423 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A`\r )";
5424 r
= run_query(hdb
, 0, query
);
5425 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5426 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5428 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )\r";
5429 r
= run_query(hdb
, 0, query
);
5430 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5431 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5433 query
= "CREATE TABLE `\rOne` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5434 r
= run_query(hdb
, 0, query
);
5435 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5437 query
= "CREATE TABLE `Tw\ro` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5438 r
= run_query(hdb
, 0, query
);
5439 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5441 query
= "CREATE TABLE `Three\r` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5442 r
= run_query(hdb
, 0, query
);
5443 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5445 query
= "CREATE TABLE `Four` ( `A\r` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5446 r
= run_query(hdb
, 0, query
);
5447 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5448 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5450 query
= "CREATE TABLE `Four` ( `\rA` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5451 r
= run_query(hdb
, 0, query
);
5452 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5453 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5455 query
= "CREATE TABLE `Four` ( `A` CHAR(72\r) NOT NULL PRIMARY KEY `A` )";
5456 r
= run_query(hdb
, 0, query
);
5459 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5460 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5463 query
= "CREATE TABLE `Four` ( `A` CHAR(\r72) NOT NULL PRIMARY KEY `A` )";
5464 r
= run_query(hdb
, 0, query
);
5465 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5466 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5468 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `\rA` )";
5469 r
= run_query(hdb
, 0, query
);
5470 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5471 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5473 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
5474 r
= run_query(hdb
, 0, query
);
5475 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5476 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5478 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
5479 r
= run_query(hdb
, 0, query
);
5480 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5481 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5483 query
= "SELECT * FROM `_Tables`";
5484 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5485 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
);
5493 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5494 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5497 ok(!lstrcmpA(buf
, "\rOne"), "Expected \"\\rOne\", got \"%s\"\n", buf
);
5500 MsiCloseHandle(hrec
);
5502 r
= MsiViewFetch(hview
, &hrec
);
5503 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5506 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5507 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5510 ok(!lstrcmpA(buf
, "Tw\ro"), "Expected \"Tw\\ro\", got \"%s\"\n", buf
);
5513 MsiCloseHandle(hrec
);
5515 r
= MsiViewFetch(hview
, &hrec
);
5516 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5519 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5520 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5523 ok(!lstrcmpA(buf
, "Three\r"),
5524 "Expected \"Three\r\", got \"%s\"\n", buf
);
5527 MsiCloseHandle(hrec
);
5529 r
= MsiViewFetch(hview
, &hrec
);
5532 ok(r
== ERROR_NO_MORE_ITEMS
,
5533 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5536 MsiViewClose(hview
);
5537 MsiCloseHandle(hview
);
5539 MsiCloseHandle(hdb
);
5540 DeleteFileA(msifile
);
5543 static void test_noquotes(void)
5545 MSIHANDLE hdb
, hview
, hrec
;
5551 DeleteFile(msifile
);
5553 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5554 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5556 query
= "CREATE TABLE Table ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5557 r
= run_query(hdb
, 0, query
);
5558 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5560 query
= "CREATE TABLE `Table` ( A CHAR(72) NOT NULL PRIMARY KEY `A` )";
5561 r
= run_query(hdb
, 0, query
);
5562 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5564 query
= "CREATE TABLE `Table2` ( `A` CHAR(72) NOT NULL PRIMARY KEY A )";
5565 r
= run_query(hdb
, 0, query
);
5566 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5568 query
= "CREATE TABLE `Table3` ( A CHAR(72) NOT NULL PRIMARY KEY A )";
5569 r
= run_query(hdb
, 0, query
);
5570 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5572 query
= "SELECT * FROM `_Tables`";
5573 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5574 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5575 r
= MsiViewExecute(hview
, 0);
5576 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5578 r
= MsiViewFetch(hview
, &hrec
);
5579 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5582 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5583 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5584 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
5586 MsiCloseHandle(hrec
);
5588 r
= MsiViewFetch(hview
, &hrec
);
5589 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5592 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5593 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5594 ok(!lstrcmpA(buf
, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf
);
5596 MsiCloseHandle(hrec
);
5598 r
= MsiViewFetch(hview
, &hrec
);
5599 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5602 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5603 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5604 ok(!lstrcmpA(buf
, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf
);
5606 MsiCloseHandle(hrec
);
5608 r
= MsiViewFetch(hview
, &hrec
);
5609 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5611 MsiViewClose(hview
);
5612 MsiCloseHandle(hview
);
5614 query
= "SELECT * FROM `_Columns`";
5615 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5616 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5617 r
= MsiViewExecute(hview
, 0);
5618 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5620 r
= MsiViewFetch(hview
, &hrec
);
5621 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5624 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5625 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5626 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
5628 r
= MsiRecordGetInteger(hrec
, 2);
5629 ok(r
== 1, "Expected 1, got %d\n", r
);
5632 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
5633 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5634 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
5636 MsiCloseHandle(hrec
);
5638 r
= MsiViewFetch(hview
, &hrec
);
5639 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5642 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5643 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5644 ok(!lstrcmpA(buf
, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf
);
5646 r
= MsiRecordGetInteger(hrec
, 2);
5647 ok(r
== 1, "Expected 1, got %d\n", r
);
5650 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
5651 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5652 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
5654 MsiCloseHandle(hrec
);
5656 r
= MsiViewFetch(hview
, &hrec
);
5657 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5660 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5661 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5662 ok(!lstrcmpA(buf
, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf
);
5664 r
= MsiRecordGetInteger(hrec
, 2);
5665 ok(r
== 1, "Expected 1, got %d\n", r
);
5668 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
5669 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5670 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
5672 MsiCloseHandle(hrec
);
5674 r
= MsiViewFetch(hview
, &hrec
);
5675 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5677 MsiViewClose(hview
);
5678 MsiCloseHandle(hview
);
5680 query
= "INSERT INTO Table ( `A` ) VALUES ( 'hi' )";
5681 r
= run_query(hdb
, 0, query
);
5682 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5684 query
= "INSERT INTO `Table` ( A ) VALUES ( 'hi' )";
5685 r
= run_query(hdb
, 0, query
);
5686 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5688 query
= "INSERT INTO `Table` ( `A` ) VALUES ( hi )";
5689 r
= run_query(hdb
, 0, query
);
5690 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5692 query
= "SELECT * FROM Table WHERE `A` = 'hi'";
5693 r
= run_query(hdb
, 0, query
);
5694 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5696 query
= "SELECT * FROM `Table` WHERE `A` = hi";
5697 r
= run_query(hdb
, 0, query
);
5698 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5700 query
= "SELECT * FROM Table";
5701 r
= run_query(hdb
, 0, query
);
5702 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5704 query
= "SELECT * FROM Table2";
5705 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5706 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5707 r
= MsiViewExecute(hview
, 0);
5708 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5710 r
= MsiViewFetch(hview
, &hrec
);
5711 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5713 MsiViewClose(hview
);
5714 MsiCloseHandle(hview
);
5716 query
= "SELECT * FROM `Table` WHERE A = 'hi'";
5717 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5718 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5719 r
= MsiViewExecute(hview
, 0);
5720 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5722 r
= MsiViewFetch(hview
, &hrec
);
5723 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5726 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5727 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5728 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
5730 MsiCloseHandle(hrec
);
5732 r
= MsiViewFetch(hview
, &hrec
);
5733 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5735 MsiViewClose(hview
);
5736 MsiCloseHandle(hview
);
5739 MsiCloseHandle(hdb
);
5740 DeleteFileA(msifile
);
5743 static void read_file_data(LPCSTR filename
, LPSTR buffer
)
5749 file
= OpenFile(filename
, &ofs
, OF_READ
);
5750 ZeroMemory(buffer
, MAX_PATH
);
5751 ReadFile((HANDLE
)file
, buffer
, MAX_PATH
, &read
, NULL
);
5752 CloseHandle((HANDLE
)file
);
5755 static void test_forcecodepage(void)
5759 char buffer
[MAX_PATH
];
5762 DeleteFile(msifile
);
5764 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5765 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5767 query
= "SELECT * FROM `_ForceCodepage`";
5768 r
= run_query(hdb
, 0, query
);
5769 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5771 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5772 r
= run_query(hdb
, 0, query
);
5773 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5775 query
= "SELECT * FROM `_ForceCodepage`";
5776 r
= run_query(hdb
, 0, query
);
5777 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5779 r
= MsiDatabaseCommit(hdb
);
5780 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5782 query
= "SELECT * FROM `_ForceCodepage`";
5783 r
= run_query(hdb
, 0, query
);
5784 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5786 MsiCloseHandle(hdb
);
5788 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_DIRECT
, &hdb
);
5789 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5791 query
= "SELECT * FROM `_ForceCodepage`";
5792 r
= run_query(hdb
, 0, query
);
5793 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5795 r
= MsiDatabaseExport(hdb
, "_ForceCodepage", CURR_DIR
, "forcecodepage.idt");
5796 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5798 read_file_data("forcecodepage.idt", buffer
);
5799 ok(!lstrcmpA(buffer
, "\r\n\r\n0\t_ForceCodepage\r\n"),
5800 "Expected \"\r\n\r\n0\t_ForceCodepage\r\n\", got \"%s\"", buffer
);
5802 MsiCloseHandle(hdb
);
5803 DeleteFileA(msifile
);
5804 DeleteFileA("forcecodepage.idt");
5807 static void test_viewmodify_refresh(void)
5809 MSIHANDLE hdb
, hview
, hrec
;
5811 char buffer
[MAX_PATH
];
5815 DeleteFile(msifile
);
5817 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5818 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5820 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL, `B` INT PRIMARY KEY `A` )";
5821 r
= run_query(hdb
, 0, query
);
5822 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5824 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hi', 1 )";
5825 r
= run_query(hdb
, 0, query
);
5826 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5828 query
= "SELECT * FROM `Table`";
5829 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5830 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5831 r
= MsiViewExecute(hview
, 0);
5832 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5834 r
= MsiViewFetch(hview
, &hrec
);
5835 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5837 query
= "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hi'";
5838 r
= run_query(hdb
, 0, query
);
5839 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5841 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
5842 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5845 r
= MsiRecordGetStringA(hrec
, 1, buffer
, &size
);
5846 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5847 ok(!lstrcmpA(buffer
, "hi"), "Expected \"hi\", got \"%s\"\n", buffer
);
5848 ok(size
== 2, "Expected 2, got %d\n", size
);
5850 r
= MsiRecordGetInteger(hrec
, 2);
5851 ok(r
== 2, "Expected 2, got %d\n", r
);
5853 MsiCloseHandle(hrec
);
5854 MsiViewClose(hview
);
5855 MsiCloseHandle(hview
);
5857 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hello', 3 )";
5858 r
= run_query(hdb
, 0, query
);
5859 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5861 query
= "SELECT * FROM `Table` WHERE `B` = 3";
5862 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5863 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5864 r
= MsiViewExecute(hview
, 0);
5865 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5867 r
= MsiViewFetch(hview
, &hrec
);
5868 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5870 query
= "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hello'";
5871 r
= run_query(hdb
, 0, query
);
5872 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5874 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hithere', 3 )";
5875 r
= run_query(hdb
, 0, query
);
5876 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5878 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
5879 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5882 r
= MsiRecordGetStringA(hrec
, 1, buffer
, &size
);
5883 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5884 ok(!lstrcmpA(buffer
, "hello"), "Expected \"hello\", got \"%s\"\n", buffer
);
5885 ok(size
== 5, "Expected 5, got %d\n", size
);
5887 r
= MsiRecordGetInteger(hrec
, 2);
5888 ok(r
== 2, "Expected 2, got %d\n", r
);
5890 MsiCloseHandle(hrec
);
5891 MsiViewClose(hview
);
5892 MsiCloseHandle(hview
);
5893 MsiCloseHandle(hdb
);
5894 DeleteFileA(msifile
);
5897 static void test_where_viewmodify(void)
5899 MSIHANDLE hdb
, hview
, hrec
;
5903 DeleteFile(msifile
);
5905 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5906 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5908 query
= "CREATE TABLE `Table` ( `A` INT, `B` INT PRIMARY KEY `A` )";
5909 r
= run_query(hdb
, 0, query
);
5910 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5912 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 1, 2 )";
5913 r
= run_query(hdb
, 0, query
);
5914 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5916 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 3, 4 )";
5917 r
= run_query(hdb
, 0, query
);
5918 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5920 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 5, 6 )";
5921 r
= run_query(hdb
, 0, query
);
5922 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5924 /* `B` = 3 doesn't match, but the view shouldn't be executed */
5925 query
= "SELECT * FROM `Table` WHERE `B` = 3";
5926 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5927 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5929 hrec
= MsiCreateRecord(2);
5930 MsiRecordSetInteger(hrec
, 1, 7);
5931 MsiRecordSetInteger(hrec
, 2, 8);
5933 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
5934 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5936 MsiCloseHandle(hrec
);
5937 MsiViewClose(hview
);
5938 MsiCloseHandle(hview
);
5940 query
= "SELECT * FROM `Table` WHERE `A` = 7";
5941 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5942 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5943 r
= MsiViewExecute(hview
, 0);
5944 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5946 r
= MsiViewFetch(hview
, &hrec
);
5947 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5949 r
= MsiRecordGetInteger(hrec
, 1);
5950 ok(r
== 7, "Expected 7, got %d\n", r
);
5952 r
= MsiRecordGetInteger(hrec
, 2);
5953 ok(r
== 8, "Expected 8, got %d\n", r
);
5955 MsiRecordSetInteger(hrec
, 2, 9);
5957 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
5958 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5960 MsiCloseHandle(hrec
);
5961 MsiViewClose(hview
);
5962 MsiCloseHandle(hview
);
5964 query
= "SELECT * FROM `Table` WHERE `A` = 7";
5965 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5966 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5967 r
= MsiViewExecute(hview
, 0);
5968 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5970 r
= MsiViewFetch(hview
, &hrec
);
5971 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5973 r
= MsiRecordGetInteger(hrec
, 1);
5974 ok(r
== 7, "Expected 7, got %d\n", r
);
5976 r
= MsiRecordGetInteger(hrec
, 2);
5977 ok(r
== 9, "Expected 9, got %d\n", r
);
5979 query
= "UPDATE `Table` SET `B` = 10 WHERE `A` = 7";
5980 r
= run_query(hdb
, 0, query
);
5981 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5983 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
5984 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5986 r
= MsiRecordGetInteger(hrec
, 1);
5987 ok(r
== 7, "Expected 7, got %d\n", r
);
5989 r
= MsiRecordGetInteger(hrec
, 2);
5990 ok(r
== 10, "Expected 10, got %d\n", r
);
5992 MsiCloseHandle(hrec
);
5993 MsiViewClose(hview
);
5994 MsiCloseHandle(hview
);
5995 MsiCloseHandle(hdb
);
5998 static BOOL
create_storage(LPCSTR name
)
6000 WCHAR nameW
[MAX_PATH
];
6007 MultiByteToWideChar(CP_ACP
, 0, name
, -1, nameW
, MAX_PATH
);
6008 hr
= StgCreateDocfile(nameW
, STGM_CREATE
| STGM_READWRITE
|
6009 STGM_DIRECT
| STGM_SHARE_EXCLUSIVE
, 0, &stg
);
6013 hr
= IStorage_CreateStream(stg
, nameW
, STGM_WRITE
| STGM_SHARE_EXCLUSIVE
,
6018 hr
= IStream_Write(stm
, "stgdata", 8, &count
);
6023 IStream_Release(stm
);
6024 IStorage_Release(stg
);
6029 static void test_storages_table(void)
6031 MSIHANDLE hdb
, hview
, hrec
;
6032 IStorage
*stg
, *inner
;
6034 char file
[MAX_PATH
];
6036 WCHAR name
[MAX_PATH
];
6043 ok(hdb
, "failed to create db\n");
6045 r
= MsiDatabaseCommit(hdb
);
6046 ok(r
== ERROR_SUCCESS
, "Failed to commit database\n");
6048 MsiCloseHandle(hdb
);
6050 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
6051 ok(r
== ERROR_SUCCESS
, "Failed to open database\n");
6053 /* check the column types */
6054 hrec
= get_column_info(hdb
, "SELECT * FROM `_Storages`", MSICOLINFO_TYPES
);
6055 ok(hrec
, "failed to get column info hrecord\n");
6056 ok(check_record(hrec
, 1, "s62"), "wrong hrecord type\n");
6057 ok(check_record(hrec
, 2, "V0"), "wrong hrecord type\n");
6059 MsiCloseHandle(hrec
);
6061 /* now try the names */
6062 hrec
= get_column_info(hdb
, "SELECT * FROM `_Storages`", MSICOLINFO_NAMES
);
6063 ok(hrec
, "failed to get column info hrecord\n");
6064 ok(check_record(hrec
, 1, "Name"), "wrong hrecord type\n");
6065 ok(check_record(hrec
, 2, "Data"), "wrong hrecord type\n");
6067 MsiCloseHandle(hrec
);
6069 create_storage("storage.bin");
6071 hrec
= MsiCreateRecord(2);
6072 MsiRecordSetString(hrec
, 1, "stgname");
6074 r
= MsiRecordSetStream(hrec
, 2, "storage.bin");
6075 ok(r
== ERROR_SUCCESS
, "Failed to add stream data to the hrecord: %d\n", r
);
6077 DeleteFileA("storage.bin");
6079 query
= "INSERT INTO `_Storages` (`Name`, `Data`) VALUES (?, ?)";
6080 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6081 ok(r
== ERROR_SUCCESS
, "Failed to open database hview: %d\n", r
);
6083 r
= MsiViewExecute(hview
, hrec
);
6084 ok(r
== ERROR_SUCCESS
, "Failed to execute hview: %d\n", r
);
6086 MsiCloseHandle(hrec
);
6087 MsiViewClose(hview
);
6088 MsiCloseHandle(hview
);
6090 query
= "SELECT `Name`, `Data` FROM `_Storages`";
6091 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6092 ok(r
== ERROR_SUCCESS
, "Failed to open database hview: %d\n", r
);
6094 r
= MsiViewExecute(hview
, 0);
6095 ok(r
== ERROR_SUCCESS
, "Failed to execute hview: %d\n", r
);
6097 r
= MsiViewFetch(hview
, &hrec
);
6098 ok(r
== ERROR_SUCCESS
, "Failed to fetch hrecord: %d\n", r
);
6101 r
= MsiRecordGetString(hrec
, 1, file
, &size
);
6102 ok(r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
6103 ok(!lstrcmp(file
, "stgname"), "Expected \"stgname\", got \"%s\"\n", file
);
6106 lstrcpyA(buf
, "apple");
6107 r
= MsiRecordReadStream(hrec
, 2, buf
, &size
);
6108 ok(!lstrcmp(buf
, "apple"), "Expected buf to be unchanged, got %s\n", buf
);
6111 ok(r
== ERROR_INVALID_DATA
, "Expected ERROR_INVALID_DATA, got %d\n", r
);
6112 ok(size
== 0, "Expected 0, got %d\n", size
);
6115 MsiCloseHandle(hrec
);
6117 r
= MsiViewFetch(hview
, &hrec
);
6118 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6120 MsiViewClose(hview
);
6121 MsiCloseHandle(hview
);
6123 MsiDatabaseCommit(hdb
);
6124 MsiCloseHandle(hdb
);
6126 MultiByteToWideChar(CP_ACP
, 0, msifile
, -1, name
, MAX_PATH
);
6127 hr
= StgOpenStorage(name
, NULL
, STGM_DIRECT
| STGM_READ
|
6128 STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
6129 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
6130 ok(stg
!= NULL
, "Expected non-NULL storage\n");
6132 MultiByteToWideChar(CP_ACP
, 0, "stgname", -1, name
, MAX_PATH
);
6133 hr
= IStorage_OpenStorage(stg
, name
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
,
6135 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
6136 ok(inner
!= NULL
, "Expected non-NULL storage\n");
6138 MultiByteToWideChar(CP_ACP
, 0, "storage.bin", -1, name
, MAX_PATH
);
6139 hr
= IStorage_OpenStream(inner
, name
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
6140 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
6141 ok(stm
!= NULL
, "Expected non-NULL stream\n");
6143 hr
= IStream_Read(stm
, buf
, MAX_PATH
, &size
);
6144 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
6145 ok(size
== 8, "Expected 8, got %d\n", size
);
6146 ok(!lstrcmpA(buf
, "stgdata"), "Expected \"stgdata\", got \"%s\"\n", buf
);
6148 IStream_Release(stm
);
6149 IStorage_Release(inner
);
6151 IStorage_Release(stg
);
6152 DeleteFileA(msifile
);
6155 static void test_dbtopackage(void)
6157 MSIHANDLE hdb
, hpkg
;
6163 /* create an empty database, transact mode */
6164 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6165 ok(r
== ERROR_SUCCESS
, "Failed to create database\n");
6167 set_summary_info(hdb
);
6169 r
= create_directory_table(hdb
);
6170 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6172 r
= create_custom_action_table(hdb
);
6173 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6175 r
= add_custom_action_entry(hdb
, "'SetProp', 51, 'MYPROP', 'grape'");
6176 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6178 sprintf(package
, "#%li", hdb
);
6179 r
= MsiOpenPackage(package
, &hpkg
);
6180 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6182 /* property is not set yet */
6184 lstrcpyA(buf
, "kiwi");
6185 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6186 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6187 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
6188 ok(size
== 0, "Expected 0, got %d\n", size
);
6190 /* run the custom action to set the property */
6191 r
= MsiDoAction(hpkg
, "SetProp");
6192 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6194 /* property is now set */
6196 lstrcpyA(buf
, "kiwi");
6197 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6198 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6199 ok(!lstrcmpA(buf
, "grape"), "Expected \"grape\", got \"%s\"\n", buf
);
6200 ok(size
== 5, "Expected 5, got %d\n", size
);
6202 MsiCloseHandle(hpkg
);
6204 /* reset the package */
6205 r
= MsiOpenPackage(package
, &hpkg
);
6206 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6208 /* property is not set anymore */
6210 lstrcpyA(buf
, "kiwi");
6211 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6212 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6215 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
6216 ok(size
== 0, "Expected 0, got %d\n", size
);
6219 MsiCloseHandle(hdb
);
6220 MsiCloseHandle(hpkg
);
6222 /* create an empty database, direct mode */
6223 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATEDIRECT
, &hdb
);
6224 ok(r
== ERROR_SUCCESS
, "Failed to create database\n");
6226 set_summary_info(hdb
);
6228 r
= create_directory_table(hdb
);
6229 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6231 r
= create_custom_action_table(hdb
);
6232 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6234 r
= add_custom_action_entry(hdb
, "'SetProp', 51, 'MYPROP', 'grape'");
6235 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6237 sprintf(package
, "#%li", hdb
);
6238 r
= MsiOpenPackage(package
, &hpkg
);
6239 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6241 /* property is not set yet */
6243 lstrcpyA(buf
, "kiwi");
6244 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6245 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6246 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
6247 ok(size
== 0, "Expected 0, got %d\n", size
);
6249 /* run the custom action to set the property */
6250 r
= MsiDoAction(hpkg
, "SetProp");
6251 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6253 /* property is now set */
6255 lstrcpyA(buf
, "kiwi");
6256 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6257 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6258 ok(!lstrcmpA(buf
, "grape"), "Expected \"grape\", got \"%s\"\n", buf
);
6259 ok(size
== 5, "Expected 5, got %d\n", size
);
6261 MsiCloseHandle(hpkg
);
6263 /* reset the package */
6264 r
= MsiOpenPackage(package
, &hpkg
);
6265 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6267 /* property is not set anymore */
6269 lstrcpyA(buf
, "kiwi");
6270 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6271 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6274 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
6275 ok(size
== 0, "Expected 0, got %d\n", size
);
6278 MsiCloseHandle(hdb
);
6279 MsiCloseHandle(hpkg
);
6280 DeleteFileA(msifile
);
6283 static void test_droptable(void)
6285 MSIHANDLE hdb
, hview
, hrec
;
6291 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6292 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6294 query
= "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
6295 r
= run_query(hdb
, 0, query
);
6296 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6298 query
= "SELECT * FROM `One`";
6299 r
= do_query(hdb
, query
, &hrec
);
6300 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6302 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
6303 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6304 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6305 r
= MsiViewExecute(hview
, 0);
6306 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6308 r
= MsiViewFetch(hview
, &hrec
);
6309 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6312 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6313 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6314 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6316 MsiCloseHandle(hrec
);
6317 MsiViewClose(hview
);
6318 MsiCloseHandle(hview
);
6320 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
6321 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6322 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6323 r
= MsiViewExecute(hview
, 0);
6324 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6326 r
= MsiViewFetch(hview
, &hrec
);
6327 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6330 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6331 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6332 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6334 r
= MsiRecordGetInteger(hrec
, 2);
6335 ok(r
== 1, "Expected 1, got %d\n", r
);
6338 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6339 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6340 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
6342 MsiCloseHandle(hrec
);
6344 r
= MsiViewFetch(hview
, &hrec
);
6345 ok(r
== ERROR_NO_MORE_ITEMS
,
6346 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6348 MsiViewClose(hview
);
6349 MsiCloseHandle(hview
);
6351 query
= "DROP `One`";
6352 r
= run_query(hdb
, 0, query
);
6353 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6354 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6356 query
= "DROP TABLE";
6357 r
= run_query(hdb
, 0, query
);
6358 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6359 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6361 query
= "DROP TABLE `One`";
6363 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6364 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6365 r
= MsiViewExecute(hview
, 0);
6366 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6368 r
= MsiViewFetch(hview
, &hrec
);
6369 ok(r
== ERROR_FUNCTION_FAILED
,
6370 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
6372 MsiViewClose(hview
);
6373 MsiCloseHandle(hview
);
6375 query
= "SELECT * FROM `IDontExist`";
6376 r
= do_query(hdb
, query
, &hrec
);
6377 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6378 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6380 query
= "SELECT * FROM `One`";
6381 r
= do_query(hdb
, query
, &hrec
);
6382 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6383 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6385 query
= "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
6386 r
= run_query(hdb
, 0, query
);
6387 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6389 query
= "DROP TABLE One";
6390 r
= run_query(hdb
, 0, query
);
6391 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6393 query
= "SELECT * FROM `One`";
6394 r
= do_query(hdb
, query
, &hrec
);
6395 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6396 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6398 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
6399 r
= do_query(hdb
, query
, &hrec
);
6400 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6402 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
6403 r
= do_query(hdb
, query
, &hrec
);
6404 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6406 query
= "CREATE TABLE `One` ( `B` INT, `C` INT PRIMARY KEY `B` )";
6407 r
= run_query(hdb
, 0, query
);
6408 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6410 query
= "SELECT * FROM `One`";
6411 r
= do_query(hdb
, query
, &hrec
);
6412 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6414 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
6415 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6416 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6417 r
= MsiViewExecute(hview
, 0);
6418 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6420 r
= MsiViewFetch(hview
, &hrec
);
6421 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6424 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6425 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6426 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6428 MsiCloseHandle(hrec
);
6429 MsiViewClose(hview
);
6430 MsiCloseHandle(hview
);
6432 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
6433 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6434 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6435 r
= MsiViewExecute(hview
, 0);
6436 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6438 r
= MsiViewFetch(hview
, &hrec
);
6439 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6442 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6443 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6444 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6446 r
= MsiRecordGetInteger(hrec
, 2);
6447 ok(r
== 1, "Expected 1, got %d\n", r
);
6450 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6451 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6452 ok(!lstrcmpA(buf
, "B"), "Expected \"B\", got \"%s\"\n", buf
);
6454 MsiCloseHandle(hrec
);
6456 r
= MsiViewFetch(hview
, &hrec
);
6457 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6460 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6461 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6462 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6464 r
= MsiRecordGetInteger(hrec
, 2);
6465 ok(r
== 2, "Expected 2, got %d\n", r
);
6468 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6469 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6470 ok(!lstrcmpA(buf
, "C"), "Expected \"C\", got \"%s\"\n", buf
);
6472 MsiCloseHandle(hrec
);
6474 r
= MsiViewFetch(hview
, &hrec
);
6475 ok(r
== ERROR_NO_MORE_ITEMS
,
6476 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6478 MsiViewClose(hview
);
6479 MsiCloseHandle(hview
);
6481 query
= "DROP TABLE One";
6482 r
= run_query(hdb
, 0, query
);
6483 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6485 query
= "SELECT * FROM `One`";
6486 r
= do_query(hdb
, query
, &hrec
);
6487 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6488 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6490 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
6491 r
= do_query(hdb
, query
, &hrec
);
6492 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6494 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
6495 r
= do_query(hdb
, query
, &hrec
);
6496 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6498 MsiCloseHandle(hdb
);
6499 DeleteFileA(msifile
);
6502 static void test_dbmerge(void)
6504 MSIHANDLE hdb
, href
, hview
, hrec
;
6510 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6511 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6513 r
= MsiOpenDatabase("refdb.msi", MSIDBOPEN_CREATE
, &href
);
6514 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6516 /* hDatabase is invalid */
6517 r
= MsiDatabaseMergeA(0, href
, "MergeErrors");
6518 ok(r
== ERROR_INVALID_HANDLE
,
6519 "Expected ERROR_INVALID_HANDLE, got %d\n", r
);
6521 /* hDatabaseMerge is invalid */
6522 r
= MsiDatabaseMergeA(hdb
, 0, "MergeErrors");
6523 ok(r
== ERROR_INVALID_HANDLE
,
6524 "Expected ERROR_INVALID_HANDLE, got %d\n", r
);
6526 /* szTableName is NULL */
6527 r
= MsiDatabaseMergeA(hdb
, href
, NULL
);
6528 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6530 /* szTableName is empty */
6531 r
= MsiDatabaseMergeA(hdb
, href
, "");
6532 ok(r
== ERROR_INVALID_TABLE
, "Expected ERROR_INVALID_TABLE, got %d\n", r
);
6534 /* both DBs empty, szTableName is valid */
6535 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6536 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6538 query
= "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
6539 r
= run_query(hdb
, 0, query
);
6540 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6542 query
= "CREATE TABLE `One` ( `A` CHAR(72) PRIMARY KEY `A` )";
6543 r
= run_query(href
, 0, query
);
6544 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6546 /* column types don't match */
6547 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6548 ok(r
== ERROR_DATATYPE_MISMATCH
,
6549 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
6551 /* nothing in MergeErrors */
6552 query
= "SELECT * FROM `MergeErrors`";
6553 r
= do_query(hdb
, query
, &hrec
);
6554 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6555 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6557 query
= "DROP TABLE `One`";
6558 r
= run_query(hdb
, 0, query
);
6559 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6561 query
= "DROP TABLE `One`";
6562 r
= run_query(href
, 0, query
);
6563 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6565 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6566 r
= run_query(hdb
, 0, query
);
6567 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6569 query
= "CREATE TABLE `One` ( `A` INT, `C` INT PRIMARY KEY `A` )";
6570 r
= run_query(href
, 0, query
);
6571 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6573 /* column names don't match */
6574 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6575 ok(r
== ERROR_DATATYPE_MISMATCH
,
6576 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
6578 /* nothing in MergeErrors */
6579 query
= "SELECT * FROM `MergeErrors`";
6580 r
= do_query(hdb
, query
, &hrec
);
6581 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6582 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6584 query
= "DROP TABLE `One`";
6585 r
= run_query(hdb
, 0, query
);
6586 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6588 query
= "DROP TABLE `One`";
6589 r
= run_query(href
, 0, query
);
6590 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6592 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6593 r
= run_query(hdb
, 0, query
);
6594 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6596 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `B` )";
6597 r
= run_query(href
, 0, query
);
6598 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6600 /* primary keys don't match */
6601 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6602 ok(r
== ERROR_DATATYPE_MISMATCH
,
6603 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
6605 /* nothing in MergeErrors */
6606 query
= "SELECT * FROM `MergeErrors`";
6607 r
= do_query(hdb
, query
, &hrec
);
6608 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6609 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6611 query
= "DROP TABLE `One`";
6612 r
= run_query(hdb
, 0, query
);
6613 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6615 query
= "DROP TABLE `One`";
6616 r
= run_query(href
, 0, query
);
6617 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6619 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6620 r
= run_query(hdb
, 0, query
);
6621 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6623 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A`, `B` )";
6624 r
= run_query(href
, 0, query
);
6625 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6627 /* number of primary keys doesn't match */
6628 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6629 ok(r
== ERROR_DATATYPE_MISMATCH
,
6630 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
6632 /* nothing in MergeErrors */
6633 query
= "SELECT * FROM `MergeErrors`";
6634 r
= do_query(hdb
, query
, &hrec
);
6635 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6636 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6638 query
= "DROP TABLE `One`";
6639 r
= run_query(hdb
, 0, query
);
6640 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6642 query
= "DROP TABLE `One`";
6643 r
= run_query(href
, 0, query
);
6644 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6646 query
= "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
6647 r
= run_query(hdb
, 0, query
);
6648 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6650 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6651 r
= run_query(href
, 0, query
);
6652 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6654 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
6655 r
= run_query(href
, 0, query
);
6656 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6658 /* number of columns doesn't match */
6659 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6660 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6662 query
= "SELECT * FROM `One`";
6663 r
= do_query(hdb
, query
, &hrec
);
6664 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6666 r
= MsiRecordGetInteger(hrec
, 1);
6667 ok(r
== 1, "Expected 1, got %d\n", r
);
6669 r
= MsiRecordGetInteger(hrec
, 2);
6670 ok(r
== 2, "Expected 2, got %d\n", r
);
6672 r
= MsiRecordGetInteger(hrec
, 3);
6673 ok(r
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", r
);
6675 MsiCloseHandle(hrec
);
6677 /* nothing in MergeErrors */
6678 query
= "SELECT * FROM `MergeErrors`";
6679 r
= do_query(hdb
, query
, &hrec
);
6680 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6681 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6683 query
= "DROP TABLE `One`";
6684 r
= run_query(hdb
, 0, query
);
6685 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6687 query
= "DROP TABLE `One`";
6688 r
= run_query(href
, 0, query
);
6689 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6691 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6692 r
= run_query(hdb
, 0, query
);
6693 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6695 query
= "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
6696 r
= run_query(href
, 0, query
);
6697 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6699 query
= "INSERT INTO `One` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
6700 r
= run_query(href
, 0, query
);
6701 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6703 /* number of columns doesn't match */
6704 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6705 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6707 query
= "SELECT * FROM `One`";
6708 r
= do_query(hdb
, query
, &hrec
);
6709 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6711 r
= MsiRecordGetInteger(hrec
, 1);
6712 ok(r
== 1, "Expected 1, got %d\n", r
);
6714 r
= MsiRecordGetInteger(hrec
, 2);
6715 ok(r
== 2, "Expected 2, got %d\n", r
);
6717 r
= MsiRecordGetInteger(hrec
, 3);
6718 ok(r
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", r
);
6720 MsiCloseHandle(hrec
);
6722 /* nothing in MergeErrors */
6723 query
= "SELECT * FROM `MergeErrors`";
6724 r
= do_query(hdb
, query
, &hrec
);
6725 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6726 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6728 query
= "DROP TABLE `One`";
6729 r
= run_query(hdb
, 0, query
);
6730 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6732 query
= "DROP TABLE `One`";
6733 r
= run_query(href
, 0, query
);
6734 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6736 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6737 r
= run_query(hdb
, 0, query
);
6738 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6740 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 1 )";
6741 r
= run_query(hdb
, 0, query
);
6742 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6744 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 2 )";
6745 r
= run_query(hdb
, 0, query
);
6746 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6748 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6749 r
= run_query(href
, 0, query
);
6750 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6752 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
6753 r
= run_query(href
, 0, query
);
6754 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6756 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 3 )";
6757 r
= run_query(href
, 0, query
);
6758 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6760 /* primary keys match, rows do not */
6761 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6762 ok(r
== ERROR_FUNCTION_FAILED
,
6763 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
6765 /* nothing in MergeErrors */
6766 query
= "SELECT * FROM `MergeErrors`";
6767 r
= do_query(hdb
, query
, &hrec
);
6768 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6771 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6772 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6773 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6775 r
= MsiRecordGetInteger(hrec
, 2);
6776 ok(r
== 2, "Expected 2, got %d\n", r
);
6778 MsiCloseHandle(hrec
);
6780 r
= MsiDatabaseOpenViewA(hdb
, "SELECT * FROM `MergeErrors`", &hview
);
6781 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6783 r
= MsiViewGetColumnInfo(hview
, MSICOLINFO_NAMES
, &hrec
);
6784 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6787 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
6788 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
6791 r
= MsiRecordGetString(hrec
, 2, buf
, &size
);
6792 ok(!lstrcmpA(buf
, "NumRowMergeConflicts"),
6793 "Expected \"NumRowMergeConflicts\", got \"%s\"\n", buf
);
6795 MsiCloseHandle(hrec
);
6797 r
= MsiViewGetColumnInfo(hview
, MSICOLINFO_TYPES
, &hrec
);
6798 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6801 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
6802 ok(!lstrcmpA(buf
, "s255"), "Expected \"s255\", got \"%s\"\n", buf
);
6805 r
= MsiRecordGetString(hrec
, 2, buf
, &size
);
6806 ok(!lstrcmpA(buf
, "i2"), "Expected \"i2\", got \"%s\"\n", buf
);
6808 MsiCloseHandle(hrec
);
6809 MsiViewClose(hview
);
6810 MsiCloseHandle(hview
);
6812 query
= "DROP TABLE `MergeErrors`";
6813 r
= run_query(hdb
, 0, query
);
6814 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6816 create_file_data("codepage.idt", "\r\n\r\n850\t_ForceCodepage\r\n", 0);
6818 GetCurrentDirectoryA(MAX_PATH
, buf
);
6819 r
= MsiDatabaseImportA(hdb
, buf
, "codepage.idt");
6822 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6825 query
= "DROP TABLE `One`";
6826 r
= run_query(hdb
, 0, query
);
6827 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6829 query
= "DROP TABLE `One`";
6830 r
= run_query(href
, 0, query
);
6831 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6833 query
= "CREATE TABLE `One` ( "
6834 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
6835 r
= run_query(hdb
, 0, query
);
6836 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6838 query
= "CREATE TABLE `One` ( "
6839 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
6840 r
= run_query(href
, 0, query
);
6841 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6843 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
6844 r
= run_query(href
, 0, query
);
6845 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6847 /* code page does not match */
6848 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6849 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6851 query
= "SELECT * FROM `One`";
6852 r
= do_query(hdb
, query
, &hrec
);
6853 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6855 r
= MsiRecordGetInteger(hrec
, 1);
6856 ok(r
== 1, "Expected 1, got %d\n", r
);
6859 r
= MsiRecordGetStringA(hrec
, 2, buf
, &size
);
6860 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6861 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
6863 MsiCloseHandle(hrec
);
6865 /* nothing in MergeErrors */
6866 query
= "SELECT * FROM `MergeErrors`";
6867 r
= do_query(hdb
, query
, &hrec
);
6868 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6869 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6871 query
= "DROP TABLE `One`";
6872 r
= run_query(hdb
, 0, query
);
6873 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6875 query
= "DROP TABLE `One`";
6876 r
= run_query(href
, 0, query
);
6877 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6879 query
= "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
6880 r
= run_query(hdb
, 0, query
);
6881 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6883 query
= "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
6884 r
= run_query(href
, 0, query
);
6885 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6887 create_file("binary.dat");
6888 hrec
= MsiCreateRecord(1);
6889 MsiRecordSetStreamA(hrec
, 1, "binary.dat");
6891 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, ? )";
6892 r
= run_query(href
, hrec
, query
);
6893 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6895 MsiCloseHandle(hrec
);
6897 /* binary data to merge */
6898 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6899 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6901 query
= "SELECT * FROM `One`";
6902 r
= do_query(hdb
, query
, &hrec
);
6903 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6905 r
= MsiRecordGetInteger(hrec
, 1);
6906 ok(r
== 1, "Expected 1, got %d\n", r
);
6909 ZeroMemory(buf
, MAX_PATH
);
6910 r
= MsiRecordReadStream(hrec
, 2, buf
, &size
);
6913 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6914 ok(!lstrcmpA(buf
, "binary.dat\n"),
6915 "Expected \"binary.dat\\n\", got \"%s\"\n", buf
);
6918 MsiCloseHandle(hrec
);
6920 /* nothing in MergeErrors */
6921 query
= "SELECT * FROM `MergeErrors`";
6922 r
= do_query(hdb
, query
, &hrec
);
6923 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6924 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6926 MsiCloseHandle(hdb
);
6927 MsiCloseHandle(href
);
6928 DeleteFileA(msifile
);
6929 DeleteFileA("refdb.msi");
6930 DeleteFileA("codepage.idt");
6931 DeleteFileA("binary.dat");
6938 test_msidecomposedesc();
6939 test_msibadqueries();
6941 test_viewgetcolumninfo();
6949 test_handle_limit();
6950 test_try_transform();
6952 test_temporary_table();
6956 test_special_tables();
6957 test_select_markers();
6958 test_viewmodify_update();
6960 test_viewmodify_delete();
6961 test_defaultdatabase();
6963 test_viewmodify_delete_temporary();
6966 test_carriagereturn();
6968 test_forcecodepage();
6969 test_viewmodify_refresh();
6970 test_where_viewmodify();
6971 test_storages_table();