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 static UINT
add_component_entry( MSIHANDLE hdb
, const char *values
)
246 char insert
[] = "INSERT INTO `Component` "
247 "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `Condition`, `KeyPath`) "
252 sz
= strlen(values
) + sizeof insert
;
253 query
= HeapAlloc(GetProcessHeap(),0,sz
);
254 sprintf(query
,insert
,values
);
255 r
= run_query( hdb
, 0, query
);
256 HeapFree(GetProcessHeap(), 0, query
);
260 static UINT
add_custom_action_entry( MSIHANDLE hdb
, const char *values
)
262 char insert
[] = "INSERT INTO `CustomAction` "
263 "(`Action`, `Type`, `Source`, `Target`) "
268 sz
= strlen(values
) + sizeof insert
;
269 query
= HeapAlloc(GetProcessHeap(),0,sz
);
270 sprintf(query
,insert
,values
);
271 r
= run_query( hdb
, 0, query
);
272 HeapFree(GetProcessHeap(), 0, query
);
276 static UINT
add_feature_components_entry( MSIHANDLE hdb
, const char *values
)
278 char insert
[] = "INSERT INTO `FeatureComponents` "
279 "(`Feature_`, `Component_`) "
284 sz
= strlen(values
) + sizeof insert
;
285 query
= HeapAlloc(GetProcessHeap(),0,sz
);
286 sprintf(query
,insert
,values
);
287 r
= run_query( hdb
, 0, query
);
288 HeapFree(GetProcessHeap(), 0, query
);
292 static UINT
add_std_dlls_entry( MSIHANDLE hdb
, const char *values
)
294 char insert
[] = "INSERT INTO `StdDlls` "
295 "(`File`, `Binary_`) "
300 sz
= strlen(values
) + sizeof insert
;
301 query
= HeapAlloc(GetProcessHeap(),0,sz
);
302 sprintf(query
,insert
,values
);
303 r
= run_query( hdb
, 0, query
);
304 HeapFree(GetProcessHeap(), 0, query
);
308 static UINT
add_binary_entry( MSIHANDLE hdb
, const char *values
)
310 char insert
[] = "INSERT INTO `Binary` "
316 sz
= strlen(values
) + sizeof insert
;
317 query
= HeapAlloc(GetProcessHeap(),0,sz
);
318 sprintf(query
,insert
,values
);
319 r
= run_query( hdb
, 0, query
);
320 HeapFree(GetProcessHeap(), 0, query
);
324 static void test_msiinsert(void)
326 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
334 /* just MsiOpenDatabase should not create a file */
335 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
336 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
339 query
= "CREATE TABLE `phone` ( "
340 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
342 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
343 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
344 r
= MsiViewExecute(hview
, 0);
345 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
346 r
= MsiViewClose(hview
);
347 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
348 r
= MsiCloseHandle(hview
);
349 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
351 /* insert a value into it */
352 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
353 "VALUES('1', 'Abe', '8675309')";
354 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
355 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
356 r
= MsiViewExecute(hview
, 0);
357 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
358 r
= MsiViewClose(hview
);
359 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
360 r
= MsiCloseHandle(hview
);
361 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
363 query
= "SELECT * FROM `phone` WHERE `id` = 1";
364 r
= do_query(hdb
, query
, &hrec
);
365 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
367 /* check the record contains what we put in it */
368 r
= MsiRecordGetFieldCount(hrec
);
369 ok(r
== 3, "record count wrong\n");
372 r
= MsiRecordIsNull(hrec
, 0);
373 ok(r
== FALSE
, "field 0 not null\n");
376 r
= MsiRecordGetInteger(hrec
, 1);
377 ok(r
== 1, "field 1 contents wrong\n");
379 r
= MsiRecordGetString(hrec
, 2, buf
, &sz
);
380 ok(r
== ERROR_SUCCESS
, "field 2 content fetch failed\n");
381 ok(!strcmp(buf
,"Abe"), "field 2 content incorrect\n");
383 r
= MsiRecordGetString(hrec
, 3, buf
, &sz
);
384 ok(r
== ERROR_SUCCESS
, "field 3 content fetch failed\n");
385 ok(!strcmp(buf
,"8675309"), "field 3 content incorrect\n");
387 r
= MsiCloseHandle(hrec
);
388 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
390 /* open a select query */
392 query
= "SELECT * FROM `phone` WHERE `id` >= 10";
393 r
= do_query(hdb
, query
, &hrec
);
394 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
395 ok(hrec
== 0, "hrec should be null\n");
397 r
= MsiCloseHandle(hrec
);
398 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
400 query
= "SELECT * FROM `phone` WHERE `id` < 0";
401 r
= do_query(hdb
, query
, &hrec
);
402 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
404 query
= "SELECT * FROM `phone` WHERE `id` <= 0";
405 r
= do_query(hdb
, query
, &hrec
);
406 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
408 query
= "SELECT * FROM `phone` WHERE `id` <> 1";
409 r
= do_query(hdb
, query
, &hrec
);
410 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
412 query
= "SELECT * FROM `phone` WHERE `id` > 10";
413 r
= do_query(hdb
, query
, &hrec
);
414 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
416 /* now try a few bad INSERT xqueries */
417 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
419 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
420 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "MsiDatabaseOpenView failed\n");
422 /* construct a record to insert */
423 hrec
= MsiCreateRecord(4);
424 r
= MsiRecordSetInteger(hrec
, 1, 2);
425 ok(r
== ERROR_SUCCESS
, "MsiRecordSetInteger failed\n");
426 r
= MsiRecordSetString(hrec
, 2, "Adam");
427 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
428 r
= MsiRecordSetString(hrec
, 3, "96905305");
429 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
431 /* insert another value, using a record and wildcards */
432 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
434 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
435 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
437 if (r
== ERROR_SUCCESS
)
439 r
= MsiViewExecute(hview
, hrec
);
440 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
441 r
= MsiViewClose(hview
);
442 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
443 r
= MsiCloseHandle(hview
);
444 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
446 r
= MsiCloseHandle(hrec
);
447 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
449 r
= MsiViewFetch(0, NULL
);
450 ok(r
== ERROR_INVALID_PARAMETER
, "MsiViewFetch failed\n");
452 r
= MsiDatabaseCommit(hdb
);
453 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
455 r
= MsiCloseHandle(hdb
);
456 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
458 r
= DeleteFile(msifile
);
459 ok(r
== TRUE
, "file didn't exist after commit\n");
462 typedef UINT (WINAPI
*fnMsiDecomposeDescriptorA
)(LPCSTR
, LPCSTR
, LPSTR
, LPSTR
, DWORD
*);
463 static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA
;
465 static void test_msidecomposedesc(void)
467 char prod
[MAX_FEATURE_CHARS
+1], comp
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1];
473 hmod
= GetModuleHandle("msi.dll");
474 pMsiDecomposeDescriptorA
= (fnMsiDecomposeDescriptorA
)
475 GetProcAddress(hmod
, "MsiDecomposeDescriptorA");
476 if (!pMsiDecomposeDescriptorA
)
479 /* test a valid feature descriptor */
480 desc
= "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
482 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, comp
, &len
);
483 ok(r
== ERROR_SUCCESS
, "returned an error\n");
484 ok(len
== strlen(desc
), "length was wrong\n");
485 ok(strcmp(prod
,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
486 ok(strcmp(feature
,"FollowTheWhiteRabbit")==0, "feature wrong\n");
487 ok(strcmp(comp
,"{A7CD68DB-EF74-49C8-FBB2-A7C463B2AC24}")==0,"component wrong\n");
489 /* test an invalid feature descriptor with too many characters */
490 desc
= "']gAVn-}f(ZXfeAR6.ji"
491 "ThisWillFailIfTheresMoreThanAGuidsChars>"
492 "3w2x^IGfe?CxI5heAvk.";
494 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, comp
, &len
);
495 ok(r
== ERROR_INVALID_PARAMETER
, "returned wrong error\n");
498 * Test a valid feature descriptor with the
499 * maximum number of characters and some trailing characters.
501 desc
= "']gAVn-}f(ZXfeAR6.ji"
502 "ThisWillWorkIfTheresLTEThanAGuidsChars>"
503 "3w2x^IGfe?CxI5heAvk."
506 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, comp
, &len
);
507 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
508 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
511 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, NULL
, &len
);
512 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
513 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
516 r
= pMsiDecomposeDescriptorA(desc
, prod
, NULL
, NULL
, &len
);
517 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
518 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
521 r
= pMsiDecomposeDescriptorA(desc
, NULL
, NULL
, NULL
, &len
);
522 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
523 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
526 r
= pMsiDecomposeDescriptorA(NULL
, NULL
, NULL
, NULL
, &len
);
527 ok(r
== ERROR_INVALID_PARAMETER
, "returned wrong error\n");
528 ok(len
== 0, "length wrong\n");
531 static UINT
try_query_param( MSIHANDLE hdb
, LPCSTR szQuery
, MSIHANDLE hrec
)
536 res
= MsiDatabaseOpenView( hdb
, szQuery
, &htab
);
537 if(res
== ERROR_SUCCESS
)
541 r
= MsiViewExecute( htab
, hrec
);
542 if(r
!= ERROR_SUCCESS
)
545 r
= MsiViewClose( htab
);
546 if(r
!= ERROR_SUCCESS
)
549 r
= MsiCloseHandle( htab
);
550 if(r
!= ERROR_SUCCESS
)
556 static UINT
try_query( MSIHANDLE hdb
, LPCSTR szQuery
)
558 return try_query_param( hdb
, szQuery
, 0 );
561 static UINT
try_insert_query( MSIHANDLE hdb
, LPCSTR szQuery
)
566 hrec
= MsiCreateRecord( 1 );
567 MsiRecordSetString( hrec
, 1, "Hello");
569 r
= try_query_param( hdb
, szQuery
, hrec
);
571 MsiCloseHandle( hrec
);
575 static void test_msibadqueries(void)
582 /* just MsiOpenDatabase should not create a file */
583 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
584 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
586 r
= MsiDatabaseCommit( hdb
);
587 ok(r
== ERROR_SUCCESS
, "Failed to commit database\n");
589 r
= MsiCloseHandle( hdb
);
590 ok(r
== ERROR_SUCCESS
, "Failed to close database\n");
592 /* open it readonly */
593 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
594 ok(r
== ERROR_SUCCESS
, "Failed to open database r/o\n");
596 /* add a table to it */
597 r
= try_query( hdb
, "select * from _Tables");
598 ok(r
== ERROR_SUCCESS
, "query 1 failed\n");
600 r
= MsiCloseHandle( hdb
);
601 ok(r
== ERROR_SUCCESS
, "Failed to close database r/o\n");
603 /* open it read/write */
604 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
605 ok(r
== ERROR_SUCCESS
, "Failed to open database r/w\n");
607 /* a bunch of test queries that fail with the native MSI */
609 r
= try_query( hdb
, "CREATE TABLE");
610 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2a return code\n");
612 r
= try_query( hdb
, "CREATE TABLE `a`");
613 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2b return code\n");
615 r
= try_query( hdb
, "CREATE TABLE `a` ()");
616 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2c return code\n");
618 r
= try_query( hdb
, "CREATE TABLE `a` (`b`)");
619 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2d return code\n");
621 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) )");
622 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2e return code\n");
624 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
625 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2f return code\n");
627 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
628 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2g return code\n");
630 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
631 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2h return code\n");
633 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
634 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2i return code\n");
636 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
637 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2j return code\n");
639 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
640 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2k return code\n");
642 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
643 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2l return code\n");
645 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
646 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2m return code\n");
648 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
649 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2n return code\n");
651 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
652 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2o return code\n");
654 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
655 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2p return code\n");
657 r
= try_query( hdb
, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
658 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2p return code\n");
660 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
661 ok(r
== ERROR_SUCCESS
, "valid query 2z failed\n");
663 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
664 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created same table again\n");
666 r
= try_query( hdb
, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
667 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
668 ok(r
== ERROR_SUCCESS
, "query 4 failed\n");
670 r
= MsiDatabaseCommit( hdb
);
671 ok(r
== ERROR_SUCCESS
, "Failed to commit database after write\n");
673 r
= try_query( hdb
, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
674 "PRIMARY KEY `foo`)");
675 ok(r
== ERROR_SUCCESS
, "query 4 failed\n");
677 r
= try_insert_query( hdb
, "insert into a ( `b` ) VALUES ( ? )");
678 ok(r
== ERROR_SUCCESS
, "failed to insert record in db\n");
680 r
= MsiDatabaseCommit( hdb
);
681 ok(r
== ERROR_SUCCESS
, "Failed to commit database after write\n");
683 r
= try_query( hdb
, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
684 "PRIMARY KEY `ba`)");
685 ok(r
!= ERROR_SUCCESS
, "query 5 succeeded\n");
687 r
= try_query( hdb
,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
688 ok(r
!= ERROR_SUCCESS
, "query 6 succeeded\n");
690 r
= try_query( hdb
, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
692 ok(r
== ERROR_SUCCESS
, "query 7 failed\n");
694 r
= try_query( hdb
, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
695 ok(r
== ERROR_SUCCESS
, "query 8 failed\n");
697 r
= try_query( hdb
, "select * from c");
698 ok(r
== ERROR_SUCCESS
, "query failed\n");
700 r
= try_query( hdb
, "select * from c where b = 'x");
701 todo_wine
ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
703 r
= try_query( hdb
, "select * from 'c'");
704 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
706 r
= try_query( hdb
, "select * from ''");
707 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
709 r
= try_query( hdb
, "select * from c where b = x");
710 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
712 r
= try_query( hdb
, "select * from c where b = \"x\"");
713 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
715 r
= try_query( hdb
, "select * from c where b = 'x'");
716 ok(r
== ERROR_SUCCESS
, "query failed\n");
718 r
= try_query( hdb
, "select * from c where b = '\"x'");
719 ok(r
== ERROR_SUCCESS
, "query failed\n");
721 if (0) /* FIXME: this query causes trouble with other tests */
723 r
= try_query( hdb
, "select * from c where b = '\\\'x'");
724 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
727 r
= try_query( hdb
, "select * from 'c'");
728 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
730 r
= MsiCloseHandle( hdb
);
731 ok(r
== ERROR_SUCCESS
, "Failed to close database transact\n");
733 r
= DeleteFile( msifile
);
734 ok(r
== TRUE
, "file didn't exist after commit\n");
737 static void test_viewmodify(void)
739 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
748 /* just MsiOpenDatabase should not create a file */
749 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
750 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
752 query
= "CREATE TABLE `phone` ( "
753 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
755 r
= run_query( hdb
, 0, query
);
756 ok(r
== ERROR_SUCCESS
, "query failed\n");
758 /* check what the error function reports without doing anything */
760 /* passing NULL as the 3rd param make function to crash on older platforms */
761 err
= MsiViewGetError( 0, NULL
, &sz
);
762 ok(err
== MSIDBERROR_INVALIDARG
, "MsiViewGetError return\n");
765 query
= "SELECT * FROM `phone`";
766 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
767 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
769 /* see what happens with a good hview and bad args */
770 err
= MsiViewGetError( hview
, NULL
, NULL
);
771 ok(err
== MSIDBERROR_INVALIDARG
|| err
== MSIDBERROR_NOERROR
,
772 "MsiViewGetError returns %u (expected -3)\n", err
);
773 err
= MsiViewGetError( hview
, buffer
, NULL
);
774 ok(err
== MSIDBERROR_INVALIDARG
, "MsiViewGetError return\n");
776 /* see what happens with a zero length buffer */
779 err
= MsiViewGetError( hview
, buffer
, &sz
);
780 ok(err
== MSIDBERROR_MOREDATA
, "MsiViewGetError return\n");
781 ok(buffer
[0] == 'x', "buffer cleared\n");
782 ok(sz
== 0, "size not zero\n");
784 /* ok this one is strange */
786 err
= MsiViewGetError( hview
, NULL
, &sz
);
787 ok(err
== MSIDBERROR_NOERROR
, "MsiViewGetError return\n");
788 ok(sz
== 0, "size not zero\n");
790 /* see if it really has an error */
793 err
= MsiViewGetError( hview
, buffer
, &sz
);
794 ok(err
== MSIDBERROR_NOERROR
, "MsiViewGetError return\n");
795 ok(buffer
[0] == 0, "buffer not cleared\n");
796 ok(sz
== 0, "size not zero\n");
798 r
= MsiViewExecute(hview
, 0);
799 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
801 /* try some invalid records */
802 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, 0 );
803 ok(r
== ERROR_INVALID_HANDLE
, "MsiViewModify failed\n");
804 r
= MsiViewModify(hview
, -1, 0 );
805 ok(r
== ERROR_INVALID_HANDLE
, "MsiViewModify failed\n");
807 /* try an small record */
808 hrec
= MsiCreateRecord(1);
809 r
= MsiViewModify(hview
, -1, hrec
);
810 ok(r
== ERROR_INVALID_DATA
, "MsiViewModify failed\n");
812 r
= MsiCloseHandle(hrec
);
813 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
815 /* insert a valid record */
816 hrec
= MsiCreateRecord(3);
818 r
= MsiRecordSetInteger(hrec
, 1, 1);
819 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
820 r
= MsiRecordSetString(hrec
, 2, "bob");
821 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
822 r
= MsiRecordSetString(hrec
, 3, "7654321");
823 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
825 r
= MsiViewExecute(hview
, 0);
826 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
827 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
828 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
830 /* insert the same thing again */
831 r
= MsiViewExecute(hview
, 0);
832 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
834 /* should fail ... */
835 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
836 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
838 r
= MsiCloseHandle(hrec
);
839 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
841 r
= MsiViewClose(hview
);
842 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
843 r
= MsiCloseHandle(hview
);
844 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
846 query
= "SELECT * FROM `phone`";
847 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
848 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
850 r
= MsiViewExecute(hview
, 0);
851 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
853 r
= MsiViewFetch(hview
, &hrec
);
854 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
856 r
= MsiRecordGetInteger(hrec
, 1);
857 ok(r
== 1, "Expected 1, got %d\n", r
);
860 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
861 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
862 ok(!lstrcmp(buffer
, "bob"), "Expected bob, got %s\n", buffer
);
865 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
866 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
867 ok(!lstrcmp(buffer
, "7654321"), "Expected 7654321, got %s\n", buffer
);
869 /* update the view, non-primary key */
870 r
= MsiRecordSetString(hrec
, 3, "3141592");
871 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
873 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
874 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
877 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
878 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
880 /* update the view, primary key */
881 r
= MsiRecordSetInteger(hrec
, 1, 5);
882 ok(r
== ERROR_SUCCESS
, "MsiRecordSetInteger failed\n");
884 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
885 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
887 r
= MsiCloseHandle(hrec
);
888 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
890 r
= MsiViewClose(hview
);
891 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
892 r
= MsiCloseHandle(hview
);
893 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
895 query
= "SELECT * FROM `phone`";
896 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
897 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
899 r
= MsiViewExecute(hview
, 0);
900 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
902 r
= MsiViewFetch(hview
, &hrec
);
903 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
905 r
= MsiRecordGetInteger(hrec
, 1);
906 ok(r
== 1, "Expected 1, got %d\n", r
);
909 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
910 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
911 ok(!lstrcmp(buffer
, "bob"), "Expected bob, got %s\n", buffer
);
914 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
915 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
916 ok(!lstrcmp(buffer
, "3141592"), "Expected 3141592, got %s\n", buffer
);
918 r
= MsiCloseHandle(hrec
);
919 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
921 /* use a record that doesn't come from a view fetch */
922 hrec
= MsiCreateRecord(3);
923 ok(hrec
!= 0, "MsiCreateRecord failed\n");
925 r
= MsiRecordSetInteger(hrec
, 1, 3);
926 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
927 r
= MsiRecordSetString(hrec
, 2, "jane");
928 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
929 r
= MsiRecordSetString(hrec
, 3, "112358");
930 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
932 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
933 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
935 r
= MsiCloseHandle(hrec
);
936 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
938 /* use a record that doesn't come from a view fetch, primary key matches */
939 hrec
= MsiCreateRecord(3);
940 ok(hrec
!= 0, "MsiCreateRecord failed\n");
942 r
= MsiRecordSetInteger(hrec
, 1, 1);
943 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
944 r
= MsiRecordSetString(hrec
, 2, "jane");
945 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
946 r
= MsiRecordSetString(hrec
, 3, "112358");
947 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
949 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
952 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
955 r
= MsiCloseHandle(hrec
);
956 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
958 hrec
= MsiCreateRecord(3);
960 r
= MsiRecordSetInteger(hrec
, 1, 2);
961 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
962 r
= MsiRecordSetString(hrec
, 2, "nick");
963 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
964 r
= MsiRecordSetString(hrec
, 3, "141421");
965 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
967 r
= MsiViewExecute(hview
, 0);
968 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
969 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
970 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
972 r
= MsiViewClose(hview
);
973 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
974 r
= MsiCloseHandle(hview
);
975 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
977 query
= "SELECT * FROM `phone` WHERE `id` = 1";
978 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
979 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
980 r
= MsiViewExecute(hview
, 0);
981 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
982 r
= MsiViewFetch(hview
, &hrec
);
983 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
985 /* change the id to match the second row */
986 r
= MsiRecordSetInteger(hrec
, 1, 2);
987 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
988 r
= MsiRecordSetString(hrec
, 2, "jerry");
989 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
991 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
992 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
994 r
= MsiCloseHandle(hrec
);
995 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
996 r
= MsiViewClose(hview
);
997 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
998 r
= MsiCloseHandle(hview
);
999 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1001 /* broader search */
1002 query
= "SELECT * FROM `phone` ORDER BY `id`";
1003 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1004 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1005 r
= MsiViewExecute(hview
, 0);
1006 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1007 r
= MsiViewFetch(hview
, &hrec
);
1008 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1010 /* change the id to match the second row */
1011 r
= MsiRecordSetInteger(hrec
, 1, 2);
1012 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
1013 r
= MsiRecordSetString(hrec
, 2, "jerry");
1014 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
1016 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
1017 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
1019 r
= MsiCloseHandle(hrec
);
1020 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
1021 r
= MsiViewClose(hview
);
1022 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1023 r
= MsiCloseHandle(hview
);
1024 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1026 r
= MsiCloseHandle( hdb
);
1027 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
1030 static MSIHANDLE
create_db(void)
1035 DeleteFile(msifile
);
1037 /* create an empty database */
1038 res
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1039 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
1040 if( res
!= ERROR_SUCCESS
)
1043 res
= MsiDatabaseCommit( hdb
);
1044 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
1049 static void test_getcolinfo(void)
1051 MSIHANDLE hdb
, hview
= 0, rec
= 0;
1056 /* create an empty db */
1058 ok( hdb
, "failed to create db\n");
1060 /* tables should be present */
1061 r
= MsiDatabaseOpenView(hdb
, "select * from _Tables", &hview
);
1062 ok( r
== ERROR_SUCCESS
, "failed to open query\n");
1064 r
= MsiViewExecute(hview
, 0);
1065 ok( r
== ERROR_SUCCESS
, "failed to execute query\n");
1067 /* check that NAMES works */
1069 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_NAMES
, &rec
);
1070 ok( r
== ERROR_SUCCESS
, "failed to get names\n");
1072 r
= MsiRecordGetString(rec
, 1, buffer
, &sz
);
1073 ok( r
== ERROR_SUCCESS
, "failed to get string\n");
1074 ok( !strcmp(buffer
,"Name"), "_Tables has wrong column name\n");
1075 r
= MsiCloseHandle( rec
);
1076 ok( r
== ERROR_SUCCESS
, "failed to close record handle\n");
1078 /* check that TYPES works */
1080 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_TYPES
, &rec
);
1081 ok( r
== ERROR_SUCCESS
, "failed to get names\n");
1083 r
= MsiRecordGetString(rec
, 1, buffer
, &sz
);
1084 ok( r
== ERROR_SUCCESS
, "failed to get string\n");
1085 ok( !strcmp(buffer
,"s64"), "_Tables has wrong column type\n");
1086 r
= MsiCloseHandle( rec
);
1087 ok( r
== ERROR_SUCCESS
, "failed to close record handle\n");
1089 /* check that invalid values fail */
1091 r
= MsiViewGetColumnInfo( hview
, 100, &rec
);
1092 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error code\n");
1093 ok( rec
== 0, "returned a record\n");
1095 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_TYPES
, NULL
);
1096 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error code\n");
1098 r
= MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES
, &rec
);
1099 ok( r
== ERROR_INVALID_HANDLE
, "wrong error code\n");
1101 r
= MsiViewClose(hview
);
1102 ok( r
== ERROR_SUCCESS
, "failed to close view\n");
1103 r
= MsiCloseHandle(hview
);
1104 ok( r
== ERROR_SUCCESS
, "failed to close view handle\n");
1105 r
= MsiCloseHandle(hdb
);
1106 ok( r
== ERROR_SUCCESS
, "failed to close database\n");
1109 static MSIHANDLE
get_column_info(MSIHANDLE hdb
, const char *query
, MSICOLINFO type
)
1111 MSIHANDLE hview
= 0, rec
= 0;
1114 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1115 if( r
!= ERROR_SUCCESS
)
1118 r
= MsiViewExecute(hview
, 0);
1119 if( r
== ERROR_SUCCESS
)
1121 MsiViewGetColumnInfo( hview
, type
, &rec
);
1122 MsiViewClose(hview
);
1124 MsiCloseHandle(hview
);
1128 static UINT
get_columns_table_type(MSIHANDLE hdb
, const char *table
, UINT field
)
1130 MSIHANDLE hview
= 0, rec
= 0;
1134 sprintf(query
, "select * from `_Columns` where `Table` = '%s'", table
);
1136 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1137 if( r
!= ERROR_SUCCESS
)
1140 r
= MsiViewExecute(hview
, 0);
1141 if( r
== ERROR_SUCCESS
)
1145 r
= MsiViewFetch( hview
, &rec
);
1146 if( r
!= ERROR_SUCCESS
)
1148 r
= MsiRecordGetInteger( rec
, 2 );
1150 type
= MsiRecordGetInteger( rec
, 4 );
1151 MsiCloseHandle( rec
);
1154 MsiViewClose(hview
);
1156 MsiCloseHandle(hview
);
1160 static BOOL
check_record( MSIHANDLE rec
, UINT field
, LPCSTR val
)
1167 r
= MsiRecordGetString( rec
, field
, buffer
, &sz
);
1168 return (r
== ERROR_SUCCESS
) && !strcmp(val
, buffer
);
1171 static void test_viewgetcolumninfo(void)
1173 MSIHANDLE hdb
= 0, rec
;
1177 ok( hdb
, "failed to create db\n");
1179 r
= run_query( hdb
, 0,
1180 "CREATE TABLE `Properties` "
1181 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1182 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1184 /* check the column types */
1185 rec
= get_column_info( hdb
, "select * from `Properties`", MSICOLINFO_TYPES
);
1186 ok( rec
, "failed to get column info record\n" );
1188 ok( check_record( rec
, 1, "S255"), "wrong record type\n");
1189 ok( check_record( rec
, 2, "S1"), "wrong record type\n");
1191 MsiCloseHandle( rec
);
1193 /* check the type in _Columns */
1194 ok( 0x3dff == get_columns_table_type(hdb
, "Properties", 1 ), "_columns table wrong\n");
1195 ok( 0x1d01 == get_columns_table_type(hdb
, "Properties", 2 ), "_columns table wrong\n");
1197 /* now try the names */
1198 rec
= get_column_info( hdb
, "select * from `Properties`", MSICOLINFO_NAMES
);
1199 ok( rec
, "failed to get column info record\n" );
1201 ok( check_record( rec
, 1, "Property"), "wrong record type\n");
1202 ok( check_record( rec
, 2, "Value"), "wrong record type\n");
1204 MsiCloseHandle( rec
);
1206 r
= run_query( hdb
, 0,
1207 "CREATE TABLE `Binary` "
1208 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
1209 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1211 /* check the column types */
1212 rec
= get_column_info( hdb
, "select * from `Binary`", MSICOLINFO_TYPES
);
1213 ok( rec
, "failed to get column info record\n" );
1215 ok( check_record( rec
, 1, "S255"), "wrong record type\n");
1216 ok( check_record( rec
, 2, "V0"), "wrong record type\n");
1218 MsiCloseHandle( rec
);
1220 /* check the type in _Columns */
1221 ok( 0x3dff == get_columns_table_type(hdb
, "Binary", 1 ), "_columns table wrong\n");
1222 ok( 0x1900 == get_columns_table_type(hdb
, "Binary", 2 ), "_columns table wrong\n");
1224 /* now try the names */
1225 rec
= get_column_info( hdb
, "select * from `Binary`", MSICOLINFO_NAMES
);
1226 ok( rec
, "failed to get column info record\n" );
1228 ok( check_record( rec
, 1, "Name"), "wrong record type\n");
1229 ok( check_record( rec
, 2, "Data"), "wrong record type\n");
1230 MsiCloseHandle( rec
);
1232 r
= run_query( hdb
, 0,
1233 "CREATE TABLE `UIText` "
1234 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1235 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1237 ok( 0x2d48 == get_columns_table_type(hdb
, "UIText", 1 ), "_columns table wrong\n");
1238 ok( 0x1fff == get_columns_table_type(hdb
, "UIText", 2 ), "_columns table wrong\n");
1240 rec
= get_column_info( hdb
, "select * from `UIText`", MSICOLINFO_NAMES
);
1241 ok( rec
, "failed to get column info record\n" );
1242 ok( check_record( rec
, 1, "Key"), "wrong record type\n");
1243 ok( check_record( rec
, 2, "Text"), "wrong record type\n");
1244 MsiCloseHandle( rec
);
1246 rec
= get_column_info( hdb
, "select * from `UIText`", MSICOLINFO_TYPES
);
1247 ok( rec
, "failed to get column info record\n" );
1248 ok( check_record( rec
, 1, "s72"), "wrong record type\n");
1249 ok( check_record( rec
, 2, "L255"), "wrong record type\n");
1250 MsiCloseHandle( rec
);
1252 MsiCloseHandle( hdb
);
1255 static void test_msiexport(void)
1257 MSIHANDLE hdb
= 0, hview
= 0;
1260 char path
[MAX_PATH
];
1261 const char file
[] = "phone.txt";
1265 const char expected
[] =
1266 "id\tname\tnumber\r\n"
1269 "1\tAbe\t8675309\r\n";
1271 DeleteFile(msifile
);
1273 /* just MsiOpenDatabase should not create a file */
1274 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1275 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1277 /* create a table */
1278 query
= "CREATE TABLE `phone` ( "
1279 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1280 "PRIMARY KEY `id`)";
1281 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1282 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1283 r
= MsiViewExecute(hview
, 0);
1284 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1285 r
= MsiViewClose(hview
);
1286 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1287 r
= MsiCloseHandle(hview
);
1288 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1290 /* insert a value into it */
1291 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
1292 "VALUES('1', 'Abe', '8675309')";
1293 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1294 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1295 r
= MsiViewExecute(hview
, 0);
1296 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1297 r
= MsiViewClose(hview
);
1298 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1299 r
= MsiCloseHandle(hview
);
1300 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1302 GetCurrentDirectory(MAX_PATH
, path
);
1304 r
= MsiDatabaseExport(hdb
, "phone", path
, file
);
1305 ok(r
== ERROR_SUCCESS
, "MsiDatabaseExport failed\n");
1307 MsiCloseHandle(hdb
);
1309 lstrcat(path
, "\\");
1310 lstrcat(path
, file
);
1312 /* check the data that was written */
1314 memset(buffer
, 0, sizeof buffer
);
1315 handle
= CreateFile(path
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1316 if (handle
!= INVALID_HANDLE_VALUE
)
1318 ReadFile(handle
, buffer
, sizeof buffer
, &length
, NULL
);
1319 CloseHandle(handle
);
1323 ok(0, "failed to open file %s\n", path
);
1325 ok( length
== strlen(expected
), "length of data wrong\n");
1326 ok( !lstrcmp(buffer
, expected
), "data doesn't match\n");
1327 DeleteFile(msifile
);
1330 static void test_longstrings(void)
1332 const char insert_query
[] =
1333 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1335 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
1338 const DWORD STRING_LENGTH
= 0x10005;
1340 DeleteFile(msifile
);
1341 /* just MsiOpenDatabase should not create a file */
1342 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1343 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1345 /* create a table */
1347 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1348 ok(r
== ERROR_SUCCESS
, "query failed\n");
1350 /* try a insert a very long string */
1351 str
= HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH
+sizeof insert_query
);
1352 len
= strchr(insert_query
, 'Z') - insert_query
;
1353 strcpy(str
, insert_query
);
1354 memset(str
+len
, 'Z', STRING_LENGTH
);
1355 strcpy(str
+len
+STRING_LENGTH
, insert_query
+len
+1);
1356 r
= try_query( hdb
, str
);
1357 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1359 HeapFree(GetProcessHeap(), 0, str
);
1361 MsiDatabaseCommit(hdb
);
1362 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
1363 MsiCloseHandle(hdb
);
1365 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
1366 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1368 r
= MsiDatabaseOpenView(hdb
, "select * from `strings` where `id` = 1", &hview
);
1369 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1371 r
= MsiViewExecute(hview
, 0);
1372 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1374 r
= MsiViewFetch(hview
, &hrec
);
1375 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1377 MsiCloseHandle(hview
);
1379 r
= MsiRecordGetString(hrec
, 2, NULL
, &len
);
1380 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1381 ok(len
== STRING_LENGTH
, "string length wrong\n");
1383 MsiCloseHandle(hrec
);
1384 MsiCloseHandle(hdb
);
1385 DeleteFile(msifile
);
1388 static void create_file_data(LPCSTR name
, LPCSTR data
, DWORD size
)
1393 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
1394 if (file
== INVALID_HANDLE_VALUE
)
1397 WriteFile(file
, data
, strlen(data
), &written
, NULL
);
1398 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
1402 SetFilePointer(file
, size
, NULL
, FILE_BEGIN
);
1409 #define create_file(name) create_file_data(name, name, 0)
1411 static void test_streamtable(void)
1413 MSIHANDLE hdb
= 0, rec
, view
;
1414 char file
[MAX_PATH
];
1420 ok( hdb
, "failed to create db\n");
1422 r
= run_query( hdb
, 0,
1423 "CREATE TABLE `Properties` "
1424 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1425 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1427 r
= run_query( hdb
, 0,
1428 "INSERT INTO `Properties` "
1429 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1430 ok( r
== ERROR_SUCCESS
, "Failed to add to table\n" );
1432 r
= MsiDatabaseCommit( hdb
);
1433 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
1435 MsiCloseHandle( hdb
);
1437 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
1438 ok( r
== ERROR_SUCCESS
, "Failed to open database\n" );
1440 /* check the column types */
1441 rec
= get_column_info( hdb
, "select * from `_Streams`", MSICOLINFO_TYPES
);
1442 ok( rec
, "failed to get column info record\n" );
1444 ok( check_record( rec
, 1, "s62"), "wrong record type\n");
1445 ok( check_record( rec
, 2, "V0"), "wrong record type\n");
1447 MsiCloseHandle( rec
);
1449 /* now try the names */
1450 rec
= get_column_info( hdb
, "select * from `_Streams`", MSICOLINFO_NAMES
);
1451 ok( rec
, "failed to get column info record\n" );
1453 ok( check_record( rec
, 1, "Name"), "wrong record type\n");
1454 ok( check_record( rec
, 2, "Data"), "wrong record type\n");
1456 MsiCloseHandle( rec
);
1458 /* insert a file into the _Streams table */
1459 create_file( "test.txt" );
1461 rec
= MsiCreateRecord( 2 );
1462 MsiRecordSetString( rec
, 1, "data" );
1464 r
= MsiRecordSetStream( rec
, 2, "test.txt" );
1465 ok( r
== ERROR_SUCCESS
, "Failed to add stream data to the record: %d\n", r
);
1467 DeleteFile("test.txt");
1469 r
= MsiDatabaseOpenView( hdb
,
1470 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view
);
1471 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1473 r
= MsiViewExecute( view
, rec
);
1474 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1476 MsiCloseHandle( rec
);
1477 MsiCloseHandle( view
);
1479 r
= MsiDatabaseOpenView( hdb
,
1480 "SELECT `Name`, `Data` FROM `_Streams`", &view
);
1481 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1483 r
= MsiViewExecute( view
, 0 );
1484 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1486 r
= MsiViewFetch( view
, &rec
);
1487 ok( r
== ERROR_SUCCESS
, "Failed to fetch record: %d\n", r
);
1490 r
= MsiRecordGetString( rec
, 1, file
, &size
);
1491 ok( r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
1492 ok( !lstrcmp(file
, "data"), "Expected 'data', got %s\n", file
);
1495 memset(buf
, 0, MAX_PATH
);
1496 r
= MsiRecordReadStream( rec
, 2, buf
, &size
);
1497 ok( r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
1498 ok( !lstrcmp(buf
, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf
);
1500 MsiCloseHandle( rec
);
1502 r
= MsiViewFetch( view
, &rec
);
1503 ok( r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
1505 MsiCloseHandle( view
);
1506 MsiCloseHandle( hdb
);
1507 DeleteFile(msifile
);
1510 static void test_where(void)
1512 MSIHANDLE hdb
= 0, rec
, view
;
1520 ok( hdb
, "failed to create db\n");
1522 r
= run_query( hdb
, 0,
1523 "CREATE TABLE `Media` ("
1524 "`DiskId` SHORT NOT NULL, "
1525 "`LastSequence` LONG, "
1526 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1527 "`Cabinet` CHAR(255), "
1528 "`VolumeLabel` CHAR(32), "
1529 "`Source` CHAR(72) "
1530 "PRIMARY KEY `DiskId`)" );
1531 ok( r
== S_OK
, "cannot create Media table: %d\n", r
);
1533 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1534 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1535 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1536 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1538 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1539 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1540 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1541 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1543 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1544 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1545 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1546 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1548 query
= "SELECT * FROM `Media`";
1549 r
= do_query(hdb
, query
, &rec
);
1550 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed: %d\n", r
);
1551 ok( check_record( rec
, 4, "zero.cab"), "wrong cabinet\n");
1552 MsiCloseHandle( rec
);
1554 query
= "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1555 r
= do_query(hdb
, query
, &rec
);
1556 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed: %d\n", r
);
1557 ok( check_record( rec
, 4, "one.cab"), "wrong cabinet\n");
1559 r
= MsiRecordGetInteger(rec
, 1);
1560 ok( 2 == r
, "field wrong\n");
1561 r
= MsiRecordGetInteger(rec
, 2);
1562 ok( 1 == r
, "field wrong\n");
1563 MsiCloseHandle( rec
);
1565 query
= "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1566 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1567 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
1569 r
= MsiViewExecute(view
, 0);
1570 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
1572 r
= MsiViewFetch(view
, &rec
);
1573 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1575 count
= MsiRecordGetFieldCount( rec
);
1576 ok( count
== 1, "Expected 1 record fields, got %d\n", count
);
1579 r
= MsiRecordGetString( rec
, 1, buf
, &size
);
1580 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
1581 ok( !lstrcmp( buf
, "2" ),
1582 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf
);
1583 MsiCloseHandle( rec
);
1585 r
= MsiViewFetch(view
, &rec
);
1586 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1589 r
= MsiRecordGetString( rec
, 1, buf
, &size
);
1590 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
1591 ok( !lstrcmp( buf
, "3" ),
1592 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf
);
1593 MsiCloseHandle( rec
);
1595 r
= MsiViewFetch(view
, &rec
);
1596 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
1599 MsiCloseHandle(view
);
1601 MsiCloseHandle( rec
);
1604 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1605 r
= do_query(hdb
, query
, &rec
);
1606 ok( r
== ERROR_SUCCESS
, "query failed: %d\n", r
);
1607 MsiCloseHandle( rec
);
1609 rec
= MsiCreateRecord(1);
1610 MsiRecordSetString(rec
, 1, "");
1612 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` = ?";
1613 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1614 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1615 r
= MsiViewExecute(view
, rec
);
1616 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1618 MsiCloseHandle(rec
);
1620 r
= MsiViewFetch(view
, &rec
);
1621 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1623 MsiCloseHandle(rec
);
1625 MsiCloseHandle(view
);
1627 MsiCloseHandle( hdb
);
1628 DeleteFile(msifile
);
1631 static CHAR CURR_DIR
[MAX_PATH
];
1633 static const CHAR test_data
[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1634 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1635 "TestTable\tFirstPrimaryColumn\n"
1636 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1638 static const CHAR two_primary
[] = "PrimaryOne\tPrimaryTwo\n"
1640 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1644 static const CHAR endlines1
[] = "A\tB\tC\tD\tE\tF\r\n"
1645 "s72\ts72\ts72\ts72\ts72\ts72\n"
1647 "a\tb\tc\td\te\tf\n"
1648 "g\th\ti\t\rj\tk\tl\r\n";
1650 static const CHAR endlines2
[] = "A\tB\tC\tD\tE\tF\r"
1651 "s72\ts72\ts72\ts72\ts72\ts72\n"
1653 "a\tb\tc\td\te\tf\n"
1654 "g\th\ti\tj\tk\tl\r\n";
1656 static void write_file(const CHAR
*filename
, const char *data
, int data_size
)
1660 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
1661 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1663 WriteFile(hf
, data
, data_size
, &size
, NULL
);
1667 static UINT
add_table_to_db(MSIHANDLE hdb
, LPCSTR table_data
)
1671 write_file("temp_file", table_data
, (lstrlen(table_data
) - 1) * sizeof(char));
1672 r
= MsiDatabaseImportA(hdb
, CURR_DIR
, "temp_file");
1673 DeleteFileA("temp_file");
1678 static void test_msiimport(void)
1680 MSIHANDLE hdb
, view
, rec
;
1685 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
1687 r
= MsiOpenDatabaseA(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1688 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1690 r
= add_table_to_db(hdb
, test_data
);
1691 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1693 r
= add_table_to_db(hdb
, two_primary
);
1694 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1696 r
= add_table_to_db(hdb
, endlines1
);
1697 if (r
== ERROR_FUNCTION_FAILED
)
1699 /* win9x doesn't handle this case */
1700 skip("endlines not handled correctly.\n");
1701 MsiCloseHandle(hdb
);
1702 DeleteFileA(msifile
);
1706 r
= add_table_to_db(hdb
, endlines2
);
1707 ok(r
== ERROR_FUNCTION_FAILED
,
1708 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
1710 query
= "SELECT * FROM `TestTable`";
1711 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1712 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1714 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
1715 count
= MsiRecordGetFieldCount(rec
);
1716 ok(count
== 9, "Expected 9, got %d\n", count
);
1717 ok(check_record(rec
, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
1718 ok(check_record(rec
, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
1719 ok(check_record(rec
, 3, "ShortInt"), "Expected ShortInt\n");
1720 ok(check_record(rec
, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
1721 ok(check_record(rec
, 5, "LongInt"), "Expected LongInt\n");
1722 ok(check_record(rec
, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
1723 ok(check_record(rec
, 7, "String"), "Expected String\n");
1724 ok(check_record(rec
, 8, "LocalizableString"), "Expected LocalizableString\n");
1725 ok(check_record(rec
, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
1726 MsiCloseHandle(rec
);
1728 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1729 count
= MsiRecordGetFieldCount(rec
);
1730 ok(count
== 9, "Expected 9, got %d\n", count
);
1731 ok(check_record(rec
, 1, "s255"), "Expected s255\n");
1732 ok(check_record(rec
, 2, "i2"), "Expected i2\n");
1733 ok(check_record(rec
, 3, "i2"), "Expected i2\n");
1734 ok(check_record(rec
, 4, "I2"), "Expected I2\n");
1735 ok(check_record(rec
, 5, "i4"), "Expected i4\n");
1736 ok(check_record(rec
, 6, "I4"), "Expected I4\n");
1737 ok(check_record(rec
, 7, "S255"), "Expected S255\n");
1738 ok(check_record(rec
, 8, "S0"), "Expected S0\n");
1739 ok(check_record(rec
, 9, "s0"), "Expected s0\n");
1740 MsiCloseHandle(rec
);
1742 query
= "SELECT * FROM `TestTable`";
1743 r
= do_query(hdb
, query
, &rec
);
1744 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1745 ok(check_record(rec
, 1, "stringage"), "Expected 'stringage'\n");
1746 ok(check_record(rec
, 7, "another string"), "Expected 'another string'\n");
1747 ok(check_record(rec
, 8, "localizable"), "Expected 'localizable'\n");
1748 ok(check_record(rec
, 9, "duh"), "Expected 'duh'\n");
1750 i
= MsiRecordGetInteger(rec
, 2);
1751 ok(i
== 5, "Expected 5, got %d\n", i
);
1753 i
= MsiRecordGetInteger(rec
, 3);
1754 ok(i
== 2, "Expected 2, got %d\n", i
);
1756 i
= MsiRecordGetInteger(rec
, 4);
1757 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
1759 i
= MsiRecordGetInteger(rec
, 5);
1760 ok(i
== 2147483640, "Expected 2147483640, got %d\n", i
);
1762 i
= MsiRecordGetInteger(rec
, 6);
1763 ok(i
== -2147483640, "Expected -2147483640, got %d\n", i
);
1765 MsiCloseHandle(rec
);
1766 MsiCloseHandle(view
);
1768 query
= "SELECT * FROM `TwoPrimary`";
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
== 2, "Expected 2, got %d\n", count
);
1775 ok(check_record(rec
, 1, "PrimaryOne"), "Expected PrimaryOne\n");
1776 ok(check_record(rec
, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
1778 MsiCloseHandle(rec
);
1780 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1781 count
= MsiRecordGetFieldCount(rec
);
1782 ok(count
== 2, "Expected 2, got %d\n", count
);
1783 ok(check_record(rec
, 1, "s255"), "Expected s255\n");
1784 ok(check_record(rec
, 2, "s255"), "Expected s255\n");
1785 MsiCloseHandle(rec
);
1787 r
= MsiViewExecute(view
, 0);
1788 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1790 r
= MsiViewFetch(view
, &rec
);
1791 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1793 ok(check_record(rec
, 1, "papaya"), "Expected 'papaya'\n");
1794 ok(check_record(rec
, 2, "leaf"), "Expected 'leaf'\n");
1796 MsiCloseHandle(rec
);
1798 r
= MsiViewFetch(view
, &rec
);
1799 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1801 ok(check_record(rec
, 1, "papaya"), "Expected 'papaya'\n");
1802 ok(check_record(rec
, 2, "flower"), "Expected 'flower'\n");
1804 MsiCloseHandle(rec
);
1806 r
= MsiViewFetch(view
, &rec
);
1807 ok(r
== ERROR_NO_MORE_ITEMS
,
1808 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
1810 r
= MsiViewClose(view
);
1811 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1813 MsiCloseHandle(view
);
1815 query
= "SELECT * FROM `Table`";
1816 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1817 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1819 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
1820 count
= MsiRecordGetFieldCount(rec
);
1821 ok(count
== 6, "Expected 6, got %d\n", count
);
1822 ok(check_record(rec
, 1, "A"), "Expected A\n");
1823 ok(check_record(rec
, 2, "B"), "Expected B\n");
1824 ok(check_record(rec
, 3, "C"), "Expected C\n");
1825 ok(check_record(rec
, 4, "D"), "Expected D\n");
1826 ok(check_record(rec
, 5, "E"), "Expected E\n");
1827 ok(check_record(rec
, 6, "F"), "Expected F\n");
1828 MsiCloseHandle(rec
);
1830 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1831 count
= MsiRecordGetFieldCount(rec
);
1832 ok(count
== 6, "Expected 6, got %d\n", count
);
1833 ok(check_record(rec
, 1, "s72"), "Expected s72\n");
1834 ok(check_record(rec
, 2, "s72"), "Expected s72\n");
1835 ok(check_record(rec
, 3, "s72"), "Expected s72\n");
1836 ok(check_record(rec
, 4, "s72"), "Expected s72\n");
1837 ok(check_record(rec
, 5, "s72"), "Expected s72\n");
1838 ok(check_record(rec
, 6, "s72"), "Expected s72\n");
1839 MsiCloseHandle(rec
);
1842 MsiCloseHandle(view
);
1844 query
= "SELECT * FROM `Table`";
1845 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1846 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1848 r
= MsiViewExecute(view
, 0);
1849 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1851 r
= MsiViewFetch(view
, &rec
);
1852 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1853 ok(check_record(rec
, 1, "a"), "Expected 'a'\n");
1854 ok(check_record(rec
, 2, "b"), "Expected 'b'\n");
1855 ok(check_record(rec
, 3, "c"), "Expected 'c'\n");
1856 ok(check_record(rec
, 4, "d"), "Expected 'd'\n");
1857 ok(check_record(rec
, 5, "e"), "Expected 'e'\n");
1858 ok(check_record(rec
, 6, "f"), "Expected 'f'\n");
1860 MsiCloseHandle(rec
);
1862 r
= MsiViewFetch(view
, &rec
);
1863 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1864 ok(check_record(rec
, 1, "g"), "Expected 'g'\n");
1865 ok(check_record(rec
, 2, "h"), "Expected 'h'\n");
1866 ok(check_record(rec
, 3, "i"), "Expected 'i'\n");
1867 ok(check_record(rec
, 4, "j"), "Expected 'j'\n");
1868 ok(check_record(rec
, 5, "k"), "Expected 'k'\n");
1869 ok(check_record(rec
, 6, "l"), "Expected 'l'\n");
1871 MsiCloseHandle(rec
);
1873 r
= MsiViewFetch(view
, &rec
);
1874 ok(r
== ERROR_NO_MORE_ITEMS
,
1875 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
1878 MsiCloseHandle(view
);
1879 MsiCloseHandle(hdb
);
1880 DeleteFileA(msifile
);
1883 static void test_markers(void)
1890 ok( hdb
, "failed to create db\n");
1892 rec
= MsiCreateRecord(3);
1893 MsiRecordSetString(rec
, 1, "Table");
1894 MsiRecordSetString(rec
, 2, "Apples");
1895 MsiRecordSetString(rec
, 3, "Oranges");
1897 /* try a legit create */
1898 query
= "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1899 r
= run_query(hdb
, 0, query
);
1900 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1901 MsiCloseHandle(rec
);
1903 /* try table name as marker */
1904 rec
= MsiCreateRecord(1);
1905 MsiRecordSetString(rec
, 1, "Fable");
1906 query
= "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1907 r
= run_query(hdb
, rec
, query
);
1908 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1910 /* verify that we just created a table called '?', not 'Fable' */
1911 r
= try_query(hdb
, "SELECT * from `Fable`");
1912 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1914 r
= try_query(hdb
, "SELECT * from `?`");
1915 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1917 /* try table name as marker without backticks */
1918 MsiRecordSetString(rec
, 1, "Mable");
1919 query
= "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1920 r
= run_query(hdb
, rec
, query
);
1921 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1923 /* try one column name as marker */
1924 MsiRecordSetString(rec
, 1, "One");
1925 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1926 r
= run_query(hdb
, rec
, query
);
1927 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1928 MsiCloseHandle(rec
);
1930 /* try column names as markers */
1931 rec
= MsiCreateRecord(2);
1932 MsiRecordSetString(rec
, 1, "One");
1933 MsiRecordSetString(rec
, 2, "Two");
1934 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
1935 r
= run_query(hdb
, rec
, query
);
1936 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1937 MsiCloseHandle(rec
);
1939 /* try names with backticks */
1940 rec
= MsiCreateRecord(3);
1941 MsiRecordSetString(rec
, 1, "One");
1942 MsiRecordSetString(rec
, 2, "Two");
1943 MsiRecordSetString(rec
, 3, "One");
1944 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1945 r
= run_query(hdb
, rec
, query
);
1946 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1948 /* try names with backticks, minus definitions */
1949 query
= "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
1950 r
= run_query(hdb
, rec
, query
);
1951 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1953 /* try names without backticks */
1954 query
= "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
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 one long marker */
1960 rec
= MsiCreateRecord(1);
1961 MsiRecordSetString(rec
, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
1962 query
= "CREATE TABLE `Mable` ( ? )";
1963 r
= run_query(hdb
, rec
, query
);
1964 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1965 MsiCloseHandle(rec
);
1967 /* try all names as markers */
1968 rec
= MsiCreateRecord(4);
1969 MsiRecordSetString(rec
, 1, "Mable");
1970 MsiRecordSetString(rec
, 2, "One");
1971 MsiRecordSetString(rec
, 3, "Two");
1972 MsiRecordSetString(rec
, 4, "One");
1973 query
= "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1974 r
= run_query(hdb
, rec
, query
);
1975 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1976 MsiCloseHandle(rec
);
1978 /* try a legit insert */
1979 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
1980 r
= run_query(hdb
, 0, query
);
1981 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1983 r
= try_query(hdb
, "SELECT * from `Table`");
1984 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1986 /* try values as markers */
1987 rec
= MsiCreateRecord(2);
1988 MsiRecordSetInteger(rec
, 1, 4);
1989 MsiRecordSetString(rec
, 2, "hi");
1990 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1991 r
= run_query(hdb
, rec
, query
);
1992 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1993 MsiCloseHandle(rec
);
1995 /* try column names and values as markers */
1996 rec
= MsiCreateRecord(4);
1997 MsiRecordSetString(rec
, 1, "One");
1998 MsiRecordSetString(rec
, 2, "Two");
1999 MsiRecordSetInteger(rec
, 3, 5);
2000 MsiRecordSetString(rec
, 4, "hi");
2001 query
= "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
2002 r
= run_query(hdb
, rec
, query
);
2003 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2004 MsiCloseHandle(rec
);
2006 /* try column names as markers */
2007 rec
= MsiCreateRecord(2);
2008 MsiRecordSetString(rec
, 1, "One");
2009 MsiRecordSetString(rec
, 2, "Two");
2010 query
= "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
2011 r
= run_query(hdb
, rec
, query
);
2012 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2013 MsiCloseHandle(rec
);
2015 /* try table name as a marker */
2016 rec
= MsiCreateRecord(1);
2017 MsiRecordSetString(rec
, 1, "Table");
2018 query
= "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
2019 r
= run_query(hdb
, rec
, query
);
2020 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2021 MsiCloseHandle(rec
);
2023 /* try table name and values as markers */
2024 rec
= MsiCreateRecord(3);
2025 MsiRecordSetString(rec
, 1, "Table");
2026 MsiRecordSetInteger(rec
, 2, 10);
2027 MsiRecordSetString(rec
, 3, "haha");
2028 query
= "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
2029 r
= run_query(hdb
, rec
, query
);
2030 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
2031 MsiCloseHandle(rec
);
2033 /* try all markers */
2034 rec
= MsiCreateRecord(5);
2035 MsiRecordSetString(rec
, 1, "Table");
2036 MsiRecordSetString(rec
, 1, "One");
2037 MsiRecordSetString(rec
, 1, "Two");
2038 MsiRecordSetInteger(rec
, 2, 10);
2039 MsiRecordSetString(rec
, 3, "haha");
2040 query
= "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
2041 r
= run_query(hdb
, rec
, query
);
2042 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2043 MsiCloseHandle(rec
);
2045 /* insert an integer as a string */
2046 rec
= MsiCreateRecord(2);
2047 MsiRecordSetString(rec
, 1, "11");
2048 MsiRecordSetString(rec
, 2, "hi");
2049 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
2050 r
= run_query(hdb
, rec
, query
);
2051 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2052 MsiCloseHandle(rec
);
2054 /* leave off the '' for the string */
2055 rec
= MsiCreateRecord(2);
2056 MsiRecordSetInteger(rec
, 1, 12);
2057 MsiRecordSetString(rec
, 2, "hi");
2058 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
2059 r
= run_query(hdb
, rec
, query
);
2060 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2061 MsiCloseHandle(rec
);
2063 MsiCloseHandle(hdb
);
2064 DeleteFileA(msifile
);
2067 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
2068 static void test_handle_limit(void)
2072 MSIHANDLE hviews
[MY_NVIEWS
];
2075 /* create an empty db */
2077 ok( hdb
, "failed to create db\n");
2079 memset(hviews
, 0, sizeof(hviews
));
2081 for (i
=0; i
<MY_NVIEWS
; i
++) {
2082 static char szQueryBuf
[256] = "SELECT * from `_Tables`";
2083 hviews
[i
] = 0xdeadbeeb;
2084 r
= MsiDatabaseOpenView(hdb
, szQueryBuf
, &hviews
[i
]);
2085 if( r
!= ERROR_SUCCESS
|| hviews
[i
] == 0xdeadbeeb ||
2086 hviews
[i
] == 0 || (i
&& (hviews
[i
] == hviews
[i
-1])))
2090 ok( i
== MY_NVIEWS
, "problem opening views\n");
2092 for (i
=0; i
<MY_NVIEWS
; i
++) {
2093 if (hviews
[i
] != 0 && hviews
[i
] != 0xdeadbeeb) {
2094 r
= MsiCloseHandle(hviews
[i
]);
2095 if (r
!= ERROR_SUCCESS
)
2100 ok( i
== MY_NVIEWS
, "problem closing views\n");
2102 r
= MsiCloseHandle(hdb
);
2103 ok( r
== ERROR_SUCCESS
, "failed to close database\n");
2106 static void generate_transform(void)
2108 MSIHANDLE hdb1
, hdb2
, hrec
;
2112 /* start with two identical databases */
2113 CopyFile(msifile2
, msifile
, FALSE
);
2115 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb1
);
2116 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2118 r
= MsiDatabaseCommit( hdb1
);
2119 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
2121 r
= MsiOpenDatabase(msifile2
, MSIDBOPEN_READONLY
, &hdb2
);
2122 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2124 /* the transform between two identical database should be empty */
2125 r
= MsiDatabaseGenerateTransform(hdb1
, hdb2
, NULL
, 0, 0);
2127 ok( r
== ERROR_NO_DATA
, "return code %d, should be ERROR_NO_DATA\n", r
);
2130 query
= "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
2131 r
= run_query(hdb1
, 0, query
);
2132 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2134 query
= "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
2135 r
= run_query(hdb1
, 0, query
);
2136 ok(r
== ERROR_SUCCESS
, "failed to add row 1\n");
2138 query
= "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
2139 r
= run_query(hdb1
, 0, query
);
2140 ok(r
== ERROR_SUCCESS
, "failed to add row 2\n");
2142 query
= "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
2143 r
= run_query(hdb1
, 0, query
);
2144 ok(r
== ERROR_SUCCESS
, "failed to modify row\n");
2146 query
= "DELETE FROM `MOO` WHERE `NOO` = 3";
2147 r
= run_query(hdb1
, 0, query
);
2148 ok(r
== ERROR_SUCCESS
, "failed to delete row\n");
2150 hrec
= MsiCreateRecord(2);
2151 r
= MsiRecordSetInteger(hrec
, 1, 1);
2152 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
2154 write_file("testdata.bin", "naengmyon", 9);
2155 r
= MsiRecordSetStream(hrec
, 2, "testdata.bin");
2156 ok(r
== ERROR_SUCCESS
, "failed to set stream\n");
2158 query
= "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2159 r
= run_query(hdb1
, hrec
, query
);
2160 ok(r
== ERROR_SUCCESS
, "failed to add row with blob\n");
2162 MsiCloseHandle(hrec
);
2164 query
= "ALTER TABLE `MOO` ADD `COW` INTEGER";
2165 r
= run_query(hdb1
, 0, query
);
2166 ok(r
== ERROR_SUCCESS
, "failed to add column\n");
2168 query
= "ALTER TABLE `MOO` ADD `PIG` INTEGER";
2169 r
= run_query(hdb1
, 0, query
);
2170 ok(r
== ERROR_SUCCESS
, "failed to add column\n");
2172 query
= "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
2173 r
= run_query(hdb1
, 0, query
);
2174 ok(r
== ERROR_SUCCESS
, "failed to modify row\n");
2176 query
= "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
2177 "`Value` CHAR(0) PRIMARY KEY `Property`)";
2178 r
= run_query(hdb1
, 0, query
);
2179 ok(r
== ERROR_SUCCESS
, "failed to add property table\n");
2181 query
= "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2182 r
= run_query(hdb1
, 0, query
);
2183 ok(r
== ERROR_SUCCESS
, "failed to add property\n");
2185 /* database needs to be committed */
2186 MsiDatabaseCommit(hdb1
);
2188 r
= MsiDatabaseGenerateTransform(hdb1
, hdb2
, mstfile
, 0, 0);
2189 ok( r
== ERROR_SUCCESS
, "return code %d, should be ERROR_SUCCESS\n", r
);
2191 MsiCloseHandle( hdb1
);
2192 MsiCloseHandle( hdb2
);
2194 DeleteFile("testdata.bin");
2197 /* data for generating a transform */
2199 /* tables transform names - encoded as they would be in an msi database file */
2200 static const WCHAR name1
[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
2201 static const WCHAR name2
[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
2202 static const WCHAR name3
[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
2203 static const WCHAR name4
[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2204 static const WCHAR name5
[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2205 static const WCHAR name6
[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
2206 static const WCHAR name7
[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
2207 static const WCHAR name8
[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
2208 static const WCHAR name9
[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2210 /* data in each table */
2211 static const WCHAR data1
[] = { /* AAR */
2212 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
2213 0x0201, 0x0009, 0x8002,
2215 static const WCHAR data2
[] = { /* _Columns */
2216 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
2217 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
2218 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
2219 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
2220 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
2221 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
2223 static const WCHAR data3
[] = { /* _Tables */
2224 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
2227 static const char data4
[] = /* _StringData */
2228 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
2229 static const WCHAR data5
[] = { /* _StringPool */
2231 0, 0, /* string 0 '' */
2232 3, 2, /* string 1 'MOO' */
2233 3, 1, /* string 2 'COW' */
2234 3, 1, /* string 3 'PIG' */
2235 1, 1, /* string 4 'c' */
2236 3, 3, /* string 5 'AAR' */
2237 3, 1, /* string 6 'CAR' */
2238 3, 1, /* string 7 'BAR' */
2239 2, 1, /* string 8 'vw' */
2240 3, 1, /* string 9 'bmw' */
2241 8, 4, /* string 10 'Property' */
2242 5, 1, /* string 11 'Value' */
2243 4, 1, /* string 12 'prop' */
2244 3, 1, /* string 13 'val' */
2246 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
2247 static const WCHAR data6
[] = { /* MOO */
2248 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
2249 0x0000, 0x8003, /* delete row */
2252 static const WCHAR data7
[] = { /* BINARY */
2253 0x0201, 0x8001, 0x0001,
2256 static const char data8
[] = /* stream data for the BINARY table */
2259 static const WCHAR data9
[] = { /* Property */
2260 0x0201, 0x000c, 0x000d,
2263 static const struct {
2267 } table_transform_data
[] =
2269 { name1
, data1
, sizeof data1
},
2270 { name2
, data2
, sizeof data2
},
2271 { name3
, data3
, sizeof data3
},
2272 { name4
, data4
, sizeof data4
- 1 },
2273 { name5
, data5
, sizeof data5
},
2274 { name6
, data6
, sizeof data6
},
2275 { name7
, data7
, sizeof data7
},
2276 { name8
, data8
, sizeof data8
- 1 },
2277 { name9
, data9
, sizeof data9
},
2280 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2282 static void generate_transform_manual(void)
2284 IStorage
*stg
= NULL
;
2289 const DWORD mode
= STGM_CREATE
|STGM_READWRITE
|STGM_DIRECT
|STGM_SHARE_EXCLUSIVE
;
2291 const CLSID CLSID_MsiTransform
= { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2293 MultiByteToWideChar(CP_ACP
, 0, mstfile
, -1, name
, 0x20);
2295 r
= StgCreateDocfile(name
, mode
, 0, &stg
);
2296 ok(r
== S_OK
, "failed to create storage\n");
2300 r
= IStorage_SetClass( stg
, &CLSID_MsiTransform
);
2301 ok(r
== S_OK
, "failed to set storage type\n");
2303 for (i
=0; i
<NUM_TRANSFORM_TABLES
; i
++)
2305 r
= IStorage_CreateStream( stg
, table_transform_data
[i
].name
,
2306 STGM_WRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
2309 ok(0, "failed to create stream %08x\n", r
);
2313 r
= IStream_Write( stm
, table_transform_data
[i
].data
,
2314 table_transform_data
[i
].size
, &count
);
2315 if (FAILED(r
) || count
!= table_transform_data
[i
].size
)
2316 ok(0, "failed to write stream\n");
2317 IStream_Release(stm
);
2320 IStorage_Release(stg
);
2323 static UINT
set_summary_info(MSIHANDLE hdb
)
2328 /* build summary info */
2329 res
= MsiGetSummaryInformation(hdb
, NULL
, 7, &suminfo
);
2330 ok( res
== ERROR_SUCCESS
, "Failed to open summaryinfo\n" );
2332 res
= MsiSummaryInfoSetProperty(suminfo
,2, VT_LPSTR
, 0,NULL
,
2333 "Installation Database");
2334 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2336 res
= MsiSummaryInfoSetProperty(suminfo
,3, VT_LPSTR
, 0,NULL
,
2337 "Installation Database");
2338 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2340 res
= MsiSummaryInfoSetProperty(suminfo
,4, VT_LPSTR
, 0,NULL
,
2342 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2344 res
= MsiSummaryInfoSetProperty(suminfo
,7, VT_LPSTR
, 0,NULL
,
2346 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2348 res
= MsiSummaryInfoSetProperty(suminfo
,9, VT_LPSTR
, 0,NULL
,
2349 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2350 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2352 res
= MsiSummaryInfoSetProperty(suminfo
, 14, VT_I4
, 100, NULL
, NULL
);
2353 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2355 res
= MsiSummaryInfoSetProperty(suminfo
, 15, VT_I4
, 0, NULL
, NULL
);
2356 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2358 res
= MsiSummaryInfoPersist(suminfo
);
2359 ok( res
== ERROR_SUCCESS
, "Failed to make summary info persist\n" );
2361 res
= MsiCloseHandle( suminfo
);
2362 ok( res
== ERROR_SUCCESS
, "Failed to close suminfo\n" );
2367 static MSIHANDLE
create_package_db(LPCSTR filename
)
2372 DeleteFile(msifile
);
2374 /* create an empty database */
2375 res
= MsiOpenDatabase(filename
, MSIDBOPEN_CREATE
, &hdb
);
2376 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
2377 if( res
!= ERROR_SUCCESS
)
2380 res
= MsiDatabaseCommit( hdb
);
2381 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
2383 res
= set_summary_info(hdb
);
2385 res
= create_directory_table(hdb
);
2386 ok( res
== ERROR_SUCCESS
, "Failed to create directory table\n" );
2391 static MSIHANDLE
package_from_db(MSIHANDLE hdb
)
2397 sprintf(szPackage
,"#%li",hdb
);
2398 res
= MsiOpenPackage(szPackage
,&hPackage
);
2399 if (res
!= ERROR_SUCCESS
)
2402 res
= MsiCloseHandle(hdb
);
2403 if (res
!= ERROR_SUCCESS
)
2409 static void test_try_transform(void)
2411 MSIHANDLE hdb
, hview
, hrec
, hpkg
;
2415 char buffer
[MAX_PATH
];
2417 DeleteFile(msifile
);
2418 DeleteFile(mstfile
);
2420 /* create the database */
2421 hdb
= create_package_db(msifile
);
2422 ok(hdb
, "Failed to create package db\n");
2424 query
= "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
2425 r
= run_query(hdb
, 0, query
);
2426 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2428 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
2429 r
= run_query(hdb
, 0, query
);
2430 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2432 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
2433 r
= run_query(hdb
, 0, query
);
2434 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2436 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
2437 r
= run_query(hdb
, 0, query
);
2438 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2440 query
= "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
2441 r
= run_query(hdb
, 0, query
);
2442 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2444 hrec
= MsiCreateRecord(2);
2445 r
= MsiRecordSetInteger(hrec
, 1, 2);
2446 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
2448 write_file("testdata.bin", "lamyon", 6);
2449 r
= MsiRecordSetStream(hrec
, 2, "testdata.bin");
2450 ok(r
== ERROR_SUCCESS
, "failed to set stream\n");
2452 query
= "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2453 r
= run_query(hdb
, hrec
, query
);
2454 ok(r
== ERROR_SUCCESS
, "failed to add row with blob\n");
2456 MsiCloseHandle(hrec
);
2458 r
= MsiDatabaseCommit( hdb
);
2459 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
2461 MsiCloseHandle( hdb
);
2462 DeleteFileA("testdata.bin");
2465 * Both these generate an equivalent transform,
2466 * but the first doesn't work in Wine yet
2467 * because MsiDatabaseGenerateTransform is unimplemented.
2470 generate_transform();
2472 generate_transform_manual();
2474 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_DIRECT
, &hdb
);
2475 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2477 r
= MsiDatabaseApplyTransform( hdb
, mstfile
, 0 );
2478 ok( r
== ERROR_SUCCESS
, "return code %d, should be ERROR_SUCCESS\n", r
);
2480 MsiDatabaseCommit( hdb
);
2482 /* check new values */
2484 query
= "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
2485 r
= do_query(hdb
, query
, &hrec
);
2486 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2487 MsiCloseHandle(hrec
);
2489 query
= "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
2491 r
= do_query(hdb
, query
, &hrec
);
2492 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2493 MsiCloseHandle(hrec
);
2495 /* check updated values */
2497 query
= "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
2498 r
= do_query(hdb
, query
, &hrec
);
2499 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2500 MsiCloseHandle(hrec
);
2502 /* check unchanged value */
2504 query
= "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
2505 r
= do_query(hdb
, query
, &hrec
);
2506 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2507 MsiCloseHandle(hrec
);
2509 /* check deleted value */
2511 query
= "select * from `MOO` where `NOO` = 3";
2512 r
= do_query(hdb
, query
, &hrec
);
2513 ok(r
== ERROR_NO_MORE_ITEMS
, "select query failed\n");
2514 if (hrec
) MsiCloseHandle(hrec
);
2516 /* check added stream */
2518 query
= "select `BLOB` from `BINARY` where `ID` = 1";
2519 r
= do_query(hdb
, query
, &hrec
);
2520 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2522 /* check the contents of the stream */
2524 r
= MsiRecordReadStream( hrec
, 1, buffer
, &sz
);
2525 ok(r
== ERROR_SUCCESS
, "read stream failed\n");
2526 ok(!memcmp(buffer
, "naengmyon", 9), "stream data was wrong\n");
2527 ok(sz
== 9, "stream data was wrong size\n");
2528 if (hrec
) MsiCloseHandle(hrec
);
2530 /* check the validity of the table with a deleted row */
2532 query
= "select * from `MOO`";
2533 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2534 ok(r
== ERROR_SUCCESS
, "open view failed\n");
2536 r
= MsiViewExecute(hview
, 0);
2537 ok(r
== ERROR_SUCCESS
, "view execute failed\n");
2539 r
= MsiViewFetch(hview
, &hrec
);
2540 ok(r
== ERROR_SUCCESS
, "view fetch failed\n");
2542 r
= MsiRecordGetInteger(hrec
, 1);
2543 ok(r
== 1, "Expected 1, got %d\n", r
);
2546 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
2547 ok(r
== ERROR_SUCCESS
, "record get string failed\n");
2548 ok(!lstrcmpA(buffer
, "c"), "Expected c, got %s\n", buffer
);
2550 r
= MsiRecordGetInteger(hrec
, 3);
2551 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
2553 r
= MsiRecordGetInteger(hrec
, 4);
2554 ok(r
== 5, "Expected 5, got %d\n", r
);
2556 MsiCloseHandle(hrec
);
2558 r
= MsiViewFetch(hview
, &hrec
);
2559 ok(r
== ERROR_SUCCESS
, "view fetch failed\n");
2561 r
= MsiRecordGetInteger(hrec
, 1);
2562 ok(r
== 2, "Expected 2, got %d\n", r
);
2565 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
2566 ok(r
== ERROR_SUCCESS
, "record get string failed\n");
2567 ok(!lstrcmpA(buffer
, "b"), "Expected b, got %s\n", buffer
);
2569 r
= MsiRecordGetInteger(hrec
, 3);
2570 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
2572 r
= MsiRecordGetInteger(hrec
, 4);
2573 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
2575 MsiCloseHandle(hrec
);
2577 r
= MsiViewFetch(hview
, &hrec
);
2578 ok(r
== ERROR_NO_MORE_ITEMS
, "view fetch succeeded\n");
2580 MsiCloseHandle(hrec
);
2581 MsiCloseHandle(hview
);
2583 /* check that the property was added */
2584 hpkg
= package_from_db(hdb
);
2585 ok(hpkg
!= 0, "Expected non-NULL hpkg\n");
2588 r
= MsiGetProperty(hpkg
, "prop", buffer
, &sz
);
2589 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2590 ok(!lstrcmp(buffer
, "val"), "Expected val, got %s\n", buffer
);
2592 MsiCloseHandle(hpkg
);
2593 MsiCloseHandle(hdb
);
2595 DeleteFile(msifile
);
2596 DeleteFile(mstfile
);
2601 const CHAR one
[MAX_PATH
];
2602 const CHAR two
[MAX_PATH
];
2605 struct join_res_4col
2607 const CHAR one
[MAX_PATH
];
2608 const CHAR two
[MAX_PATH
];
2609 const CHAR three
[MAX_PATH
];
2610 const CHAR four
[MAX_PATH
];
2613 struct join_res_uint
2623 static const struct join_res join_res_first
[] =
2625 { "alveolar", "procerus" },
2626 { "septum", "procerus" },
2627 { "septum", "nasalis" },
2628 { "ramus", "nasalis" },
2629 { "malar", "mentalis" },
2632 static const struct join_res join_res_second
[] =
2634 { "nasal", "septum" },
2635 { "mandible", "ramus" },
2638 static const struct join_res join_res_third
[] =
2640 { "msvcp.dll", "abcdefgh" },
2641 { "msvcr.dll", "ijklmnop" },
2644 static const struct join_res join_res_fourth
[] =
2646 { "msvcp.dll.01234", "single.dll.31415" },
2649 static const struct join_res join_res_fifth
[] =
2651 { "malar", "procerus" },
2654 static const struct join_res join_res_sixth
[] =
2656 { "malar", "procerus" },
2657 { "malar", "procerus" },
2658 { "malar", "nasalis" },
2659 { "malar", "nasalis" },
2660 { "malar", "nasalis" },
2661 { "malar", "mentalis" },
2664 static const struct join_res join_res_seventh
[] =
2666 { "malar", "nasalis" },
2667 { "malar", "nasalis" },
2668 { "malar", "nasalis" },
2671 static const struct join_res_4col join_res_eighth
[] =
2673 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
2674 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
2675 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
2676 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
2677 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
2678 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
2681 static const struct join_res_uint join_res_ninth
[] =
2683 { 1, 2, 3, 4, 7, 8 },
2684 { 1, 2, 5, 6, 7, 8 },
2685 { 1, 2, 3, 4, 9, 10 },
2686 { 1, 2, 5, 6, 9, 10 },
2687 { 1, 2, 3, 4, 11, 12 },
2688 { 1, 2, 5, 6, 11, 12 },
2691 static void test_join(void)
2693 MSIHANDLE hdb
, hview
, hrec
;
2701 ok( hdb
, "failed to create db\n");
2703 r
= create_component_table( hdb
);
2704 ok( r
== ERROR_SUCCESS
, "cannot create Component table: %d\n", r
);
2706 r
= add_component_entry( hdb
, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
2707 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2709 r
= add_component_entry( hdb
, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
2710 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2712 r
= add_component_entry( hdb
, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
2713 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2715 r
= add_component_entry( hdb
, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
2716 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2718 r
= create_feature_components_table( hdb
);
2719 ok( r
== ERROR_SUCCESS
, "cannot create FeatureComponents table: %d\n", r
);
2721 r
= add_feature_components_entry( hdb
, "'procerus', 'maxilla'" );
2722 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2724 r
= add_feature_components_entry( hdb
, "'procerus', 'nasal'" );
2725 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2727 r
= add_feature_components_entry( hdb
, "'nasalis', 'nasal'" );
2728 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2730 r
= add_feature_components_entry( hdb
, "'nasalis', 'mandible'" );
2731 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2733 r
= add_feature_components_entry( hdb
, "'nasalis', 'notacomponent'" );
2734 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2736 r
= add_feature_components_entry( hdb
, "'mentalis', 'zygomatic'" );
2737 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2739 r
= create_std_dlls_table( hdb
);
2740 ok( r
== ERROR_SUCCESS
, "cannot create StdDlls table: %d\n", r
);
2742 r
= add_std_dlls_entry( hdb
, "'msvcp.dll', 'msvcp.dll.01234'" );
2743 ok( r
== ERROR_SUCCESS
, "cannot add std dlls: %d\n", r
);
2745 r
= add_std_dlls_entry( hdb
, "'msvcr.dll', 'msvcr.dll.56789'" );
2746 ok( r
== ERROR_SUCCESS
, "cannot add std dlls: %d\n", r
);
2748 r
= create_binary_table( hdb
);
2749 ok( r
== ERROR_SUCCESS
, "cannot create Binary table: %d\n", r
);
2751 r
= add_binary_entry( hdb
, "'msvcp.dll.01234', 'abcdefgh'" );
2752 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
2754 r
= add_binary_entry( hdb
, "'msvcr.dll.56789', 'ijklmnop'" );
2755 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
2757 r
= add_binary_entry( hdb
, "'single.dll.31415', 'msvcp.dll'" );
2758 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
2760 query
= "CREATE TABLE `One` (`A` SHORT, `B` SHORT PRIMARY KEY `A`)";
2761 r
= run_query( hdb
, 0, query
);
2762 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2764 query
= "CREATE TABLE `Two` (`C` SHORT, `D` SHORT PRIMARY KEY `C`)";
2765 r
= run_query( hdb
, 0, query
);
2766 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2768 query
= "CREATE TABLE `Three` (`E` SHORT, `F` SHORT PRIMARY KEY `E`)";
2769 r
= run_query( hdb
, 0, query
);
2770 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2772 query
= "INSERT INTO `One` (`A`, `B`) VALUES (1, 2)";
2773 r
= run_query( hdb
, 0, query
);
2774 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2776 query
= "INSERT INTO `Two` (`C`, `D`) VALUES (3, 4)";
2777 r
= run_query( hdb
, 0, query
);
2778 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2780 query
= "INSERT INTO `Two` (`C`, `D`) VALUES (5, 6)";
2781 r
= run_query( hdb
, 0, query
);
2782 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2784 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (7, 8)";
2785 r
= run_query( hdb
, 0, query
);
2786 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2788 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (9, 10)";
2789 r
= run_query( hdb
, 0, query
);
2790 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2792 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (11, 12)";
2793 r
= run_query( hdb
, 0, query
);
2794 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2796 query
= "CREATE TABLE `Four` (`G` SHORT, `H` SHORT PRIMARY KEY `G`)";
2797 r
= run_query( hdb
, 0, query
);
2798 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2800 query
= "CREATE TABLE `Five` (`I` SHORT, `J` SHORT PRIMARY KEY `I`)";
2801 r
= run_query( hdb
, 0, query
);
2802 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2804 query
= "INSERT INTO `Five` (`I`, `J`) VALUES (13, 14)";
2805 r
= run_query( hdb
, 0, query
);
2806 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2808 query
= "INSERT INTO `Five` (`I`, `J`) VALUES (15, 16)";
2809 r
= run_query( hdb
, 0, query
);
2810 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2812 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2813 "FROM `Component`, `FeatureComponents` "
2814 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
2815 "ORDER BY `Feature_`";
2816 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2817 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2819 r
= MsiViewExecute(hview
, 0);
2820 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2823 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2825 count
= MsiRecordGetFieldCount( hrec
);
2826 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2829 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2830 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2831 ok( !lstrcmp( buf
, join_res_first
[i
].one
),
2832 "For (row %d, column 1) expected '%s', got %s\n", i
, join_res_first
[i
].one
, buf
);
2835 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2836 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2837 ok( !lstrcmp( buf
, join_res_first
[i
].two
),
2838 "For (row %d, column 2) expected '%s', got %s\n", i
, join_res_first
[i
].two
, buf
);
2841 MsiCloseHandle(hrec
);
2844 ok( i
== 5, "Expected 5 rows, got %d\n", i
);
2845 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2847 MsiViewClose(hview
);
2848 MsiCloseHandle(hview
);
2850 /* try a join without a WHERE condition */
2851 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2852 "FROM `Component`, `FeatureComponents` ";
2853 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2854 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2856 r
= MsiViewExecute(hview
, 0);
2857 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2860 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2863 MsiCloseHandle(hrec
);
2865 ok( i
== 24, "Expected 24 rows, got %d\n", i
);
2867 MsiViewClose(hview
);
2868 MsiCloseHandle(hview
);
2870 query
= "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
2871 "WHERE FeatureComponents.Component_=Component.Component "
2872 "AND (Feature_='nasalis') ORDER BY Feature_";
2873 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2874 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2876 r
= MsiViewExecute(hview
, 0);
2877 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2880 data_correct
= TRUE
;
2881 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2883 count
= MsiRecordGetFieldCount( hrec
);
2884 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2887 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2888 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2889 if( lstrcmp( buf
, join_res_second
[i
].one
))
2890 data_correct
= FALSE
;
2893 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2894 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2895 if( lstrcmp( buf
, join_res_second
[i
].two
))
2896 data_correct
= FALSE
;
2899 MsiCloseHandle(hrec
);
2902 ok( data_correct
, "data returned in the wrong order\n");
2904 ok( i
== 2, "Expected 2 rows, got %d\n", i
);
2905 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2907 MsiViewClose(hview
);
2908 MsiCloseHandle(hview
);
2910 query
= "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2911 "FROM `StdDlls`, `Binary` "
2912 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
2914 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2915 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2917 r
= MsiViewExecute(hview
, 0);
2918 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2921 data_correct
= TRUE
;
2922 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2924 count
= MsiRecordGetFieldCount( hrec
);
2925 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2928 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2929 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2930 if( lstrcmp( buf
, join_res_third
[i
].one
) )
2931 data_correct
= FALSE
;
2934 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2935 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2936 if( lstrcmp( buf
, join_res_third
[i
].two
) )
2937 data_correct
= FALSE
;
2940 MsiCloseHandle(hrec
);
2942 ok( data_correct
, "data returned in the wrong order\n");
2944 ok( i
== 2, "Expected 2 rows, got %d\n", i
);
2946 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2948 MsiViewClose(hview
);
2949 MsiCloseHandle(hview
);
2951 query
= "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
2952 "FROM `StdDlls`, `Binary` "
2953 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
2955 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2956 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2958 r
= MsiViewExecute(hview
, 0);
2959 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2962 data_correct
= TRUE
;
2963 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2965 count
= MsiRecordGetFieldCount( hrec
);
2966 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2969 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2970 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2971 if( lstrcmp( buf
, join_res_fourth
[i
].one
))
2972 data_correct
= FALSE
;
2975 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2976 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2977 if( lstrcmp( buf
, join_res_fourth
[i
].two
))
2978 data_correct
= FALSE
;
2981 MsiCloseHandle(hrec
);
2983 ok( data_correct
, "data returned in the wrong order\n");
2985 ok( i
== 1, "Expected 1 rows, got %d\n", i
);
2986 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2988 MsiViewClose(hview
);
2989 MsiCloseHandle(hview
);
2991 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2992 "FROM `Component`, `FeatureComponents` "
2993 "WHERE `Component`.`Component` = 'zygomatic' "
2994 "AND `FeatureComponents`.`Component_` = 'maxilla' "
2995 "ORDER BY `Feature_`";
2996 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2997 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2999 r
= MsiViewExecute(hview
, 0);
3000 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3003 data_correct
= TRUE
;
3004 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3006 count
= MsiRecordGetFieldCount( hrec
);
3007 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3010 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3011 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3012 if( lstrcmp( buf
, join_res_fifth
[i
].one
))
3013 data_correct
= FALSE
;
3016 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3017 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3018 if( lstrcmp( buf
, join_res_fifth
[i
].two
))
3019 data_correct
= FALSE
;
3022 MsiCloseHandle(hrec
);
3024 ok( data_correct
, "data returned in the wrong order\n");
3026 ok( i
== 1, "Expected 1 rows, got %d\n", i
);
3027 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3029 MsiViewClose(hview
);
3030 MsiCloseHandle(hview
);
3032 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3033 "FROM `Component`, `FeatureComponents` "
3034 "WHERE `Component` = 'zygomatic' "
3035 "ORDER BY `Feature_`";
3036 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3037 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3039 r
= MsiViewExecute(hview
, 0);
3040 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3043 data_correct
= TRUE
;
3044 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3046 count
= MsiRecordGetFieldCount( hrec
);
3047 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3050 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3051 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3052 if( lstrcmp( buf
, join_res_sixth
[i
].one
))
3053 data_correct
= FALSE
;
3056 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3057 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3058 if( lstrcmp( buf
, join_res_sixth
[i
].two
))
3059 data_correct
= FALSE
;
3062 MsiCloseHandle(hrec
);
3064 ok( data_correct
, "data returned in the wrong order\n");
3066 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3067 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3069 MsiViewClose(hview
);
3070 MsiCloseHandle(hview
);
3072 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3073 "FROM `Component`, `FeatureComponents` "
3074 "WHERE `Component` = 'zygomatic' "
3075 "AND `Feature_` = 'nasalis' "
3076 "ORDER BY `Feature_`";
3077 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3078 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3080 r
= MsiViewExecute(hview
, 0);
3081 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3084 data_correct
= TRUE
;
3085 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3087 count
= MsiRecordGetFieldCount( hrec
);
3088 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3091 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3092 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3093 if( lstrcmp( buf
, join_res_seventh
[i
].one
))
3094 data_correct
= FALSE
;
3097 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3098 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3099 if( lstrcmp( buf
, join_res_seventh
[i
].two
))
3100 data_correct
= FALSE
;
3103 MsiCloseHandle(hrec
);
3106 ok( data_correct
, "data returned in the wrong order\n");
3107 ok( i
== 3, "Expected 3 rows, got %d\n", i
);
3108 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3110 MsiViewClose(hview
);
3111 MsiCloseHandle(hview
);
3113 query
= "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3114 "FROM `StdDlls`, `Binary` ";
3115 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3116 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3118 r
= MsiViewExecute(hview
, 0);
3119 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3122 data_correct
= TRUE
;
3123 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3125 count
= MsiRecordGetFieldCount( hrec
);
3126 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3129 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3130 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3131 if( lstrcmp( buf
, join_res_eighth
[i
].one
))
3132 data_correct
= FALSE
;
3135 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3136 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3137 if( lstrcmp( buf
, join_res_eighth
[i
].four
))
3138 data_correct
= FALSE
;
3141 MsiCloseHandle(hrec
);
3144 ok( data_correct
, "data returned in the wrong order\n");
3145 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3146 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3148 MsiViewClose(hview
);
3149 MsiCloseHandle(hview
);
3151 query
= "SELECT * FROM `StdDlls`, `Binary` ";
3152 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3153 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3155 r
= MsiViewExecute(hview
, 0);
3156 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3159 data_correct
= TRUE
;
3160 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3162 count
= MsiRecordGetFieldCount( hrec
);
3163 ok( count
== 4, "Expected 4 record fields, got %d\n", count
);
3166 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3167 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3168 if( lstrcmp( buf
, join_res_eighth
[i
].one
))
3169 data_correct
= FALSE
;
3172 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3173 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3174 if( lstrcmp( buf
, join_res_eighth
[i
].two
))
3175 data_correct
= FALSE
;
3178 r
= MsiRecordGetString( hrec
, 3, buf
, &size
);
3179 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3180 if( lstrcmp( buf
, join_res_eighth
[i
].three
))
3181 data_correct
= FALSE
;
3184 r
= MsiRecordGetString( hrec
, 4, buf
, &size
);
3185 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3186 if( lstrcmp( buf
, join_res_eighth
[i
].four
))
3187 data_correct
= FALSE
;
3190 MsiCloseHandle(hrec
);
3192 ok( data_correct
, "data returned in the wrong order\n");
3194 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3195 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3197 MsiViewClose(hview
);
3198 MsiCloseHandle(hview
);
3200 query
= "SELECT * FROM `One`, `Two`, `Three` ";
3201 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3202 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3204 r
= MsiViewExecute(hview
, 0);
3205 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3208 data_correct
= TRUE
;
3209 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3211 count
= MsiRecordGetFieldCount( hrec
);
3212 ok( count
== 6, "Expected 6 record fields, got %d\n", count
);
3214 r
= MsiRecordGetInteger( hrec
, 1 );
3215 if( r
!= join_res_ninth
[i
].one
)
3216 data_correct
= FALSE
;
3218 r
= MsiRecordGetInteger( hrec
, 2 );
3219 if( r
!= join_res_ninth
[i
].two
)
3220 data_correct
= FALSE
;
3222 r
= MsiRecordGetInteger( hrec
, 3 );
3223 if( r
!= join_res_ninth
[i
].three
)
3224 data_correct
= FALSE
;
3226 r
= MsiRecordGetInteger( hrec
, 4 );
3227 if( r
!= join_res_ninth
[i
].four
)
3228 data_correct
= FALSE
;
3230 r
= MsiRecordGetInteger( hrec
, 5 );
3231 if( r
!= join_res_ninth
[i
].five
)
3232 data_correct
= FALSE
;
3234 r
= MsiRecordGetInteger( hrec
, 6);
3235 if( r
!= join_res_ninth
[i
].six
)
3236 data_correct
= FALSE
;
3239 MsiCloseHandle(hrec
);
3241 ok( data_correct
, "data returned in the wrong order\n");
3243 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3244 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3246 MsiViewClose(hview
);
3247 MsiCloseHandle(hview
);
3249 query
= "SELECT * FROM `Four`, `Five`";
3250 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3251 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3253 r
= MsiViewExecute(hview
, 0);
3254 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3256 r
= MsiViewFetch(hview
, &hrec
);
3257 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3259 MsiViewClose(hview
);
3260 MsiCloseHandle(hview
);
3262 query
= "SELECT * FROM `Nonexistent`, `One`";
3263 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3264 ok( r
== ERROR_BAD_QUERY_SYNTAX
,
3265 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3267 MsiCloseHandle(hdb
);
3268 DeleteFile(msifile
);
3271 static void test_temporary_table(void)
3274 MSIHANDLE hdb
= 0, view
= 0, rec
;
3280 cond
= MsiDatabaseIsTablePersistent(0, NULL
);
3281 ok( cond
== MSICONDITION_ERROR
, "wrong return condition\n");
3284 ok( hdb
, "failed to create db\n");
3286 cond
= MsiDatabaseIsTablePersistent(hdb
, NULL
);
3287 ok( cond
== MSICONDITION_ERROR
, "wrong return condition\n");
3290 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Tables");
3291 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3293 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Columns");
3294 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3297 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Storages");
3298 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3300 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Streams");
3301 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3303 query
= "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
3304 r
= run_query(hdb
, 0, query
);
3305 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3307 cond
= MsiDatabaseIsTablePersistent(hdb
, "P");
3308 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3310 query
= "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
3311 r
= run_query(hdb
, 0, query
);
3312 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3314 cond
= MsiDatabaseIsTablePersistent(hdb
, "P2");
3315 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3317 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3318 r
= run_query(hdb
, 0, query
);
3319 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3321 cond
= MsiDatabaseIsTablePersistent(hdb
, "T");
3322 ok( cond
== MSICONDITION_FALSE
, "wrong return condition\n");
3324 query
= "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3325 r
= run_query(hdb
, 0, query
);
3326 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3329 cond
= MsiDatabaseIsTablePersistent(hdb
, "T2");
3330 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3333 query
= "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
3334 r
= run_query(hdb
, 0, query
);
3335 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3337 cond
= MsiDatabaseIsTablePersistent(hdb
, "T3");
3338 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3341 query
= "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3342 r
= run_query(hdb
, 0, query
);
3343 ok(r
== ERROR_FUNCTION_FAILED
, "failed to add table\n");
3345 cond
= MsiDatabaseIsTablePersistent(hdb
, "T4");
3346 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3349 query
= "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
3350 r
= run_query(hdb
, 0, query
);
3351 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to add table\n");
3353 query
= "select * from `T`";
3354 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3355 ok(r
== ERROR_SUCCESS
, "failed to query table\n");
3356 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
3357 ok(r
== ERROR_SUCCESS
, "failed to get column info\n");
3360 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
3361 ok(r
== ERROR_SUCCESS
, "failed to get string\n");
3362 todo_wine
ok( 0 == strcmp("G255", buf
), "wrong column type\n");
3365 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
3366 ok(r
== ERROR_SUCCESS
, "failed to get string\n");
3367 todo_wine
ok( 0 == strcmp("j2", buf
), "wrong column type\n");
3369 MsiCloseHandle( rec
);
3370 MsiCloseHandle( view
);
3372 /* query the table data */
3374 r
= do_query(hdb
, "select * from `_Tables` where `Name` = 'T'", &rec
);
3375 ok( r
== ERROR_SUCCESS
, "temporary table exists in _Tables\n");
3376 MsiCloseHandle( rec
);
3378 /* query the column data */
3380 r
= do_query(hdb
, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec
);
3381 ok( r
== ERROR_NO_MORE_ITEMS
, "temporary table exists in _Columns\n");
3382 if (rec
) MsiCloseHandle( rec
);
3384 r
= do_query(hdb
, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec
);
3385 ok( r
== ERROR_NO_MORE_ITEMS
, "temporary table exists in _Columns\n");
3386 if (rec
) MsiCloseHandle( rec
);
3388 MsiCloseHandle( hdb
);
3390 DeleteFile(msifile
);
3393 static void test_alter(void)
3401 ok( hdb
, "failed to create db\n");
3403 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3404 r
= run_query(hdb
, 0, query
);
3405 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3407 cond
= MsiDatabaseIsTablePersistent(hdb
, "T");
3408 ok( cond
== MSICONDITION_FALSE
, "wrong return condition\n");
3410 query
= "ALTER TABLE `T` HOLD";
3411 r
= run_query(hdb
, 0, query
);
3412 ok(r
== ERROR_SUCCESS
, "failed to hold table %d\n", r
);
3414 query
= "ALTER TABLE `T` FREE";
3415 r
= run_query(hdb
, 0, query
);
3416 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
3418 query
= "ALTER TABLE `T` FREE";
3419 r
= run_query(hdb
, 0, query
);
3420 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
3422 query
= "ALTER TABLE `T` FREE";
3423 r
= run_query(hdb
, 0, query
);
3424 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to free table\n");
3426 query
= "ALTER TABLE `T` HOLD";
3427 r
= run_query(hdb
, 0, query
);
3428 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to hold table %d\n", r
);
3430 /* table T is removed */
3431 query
= "SELECT * FROM `T`";
3432 r
= run_query(hdb
, 0, query
);
3433 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3435 /* create the table again */
3436 query
= "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
3437 r
= run_query(hdb
, 0, query
);
3438 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3440 /* up the ref count */
3441 query
= "ALTER TABLE `U` HOLD";
3442 r
= run_query(hdb
, 0, query
);
3443 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
3445 /* add column, no data type */
3446 query
= "ALTER TABLE `U` ADD `C`";
3447 r
= run_query(hdb
, 0, query
);
3448 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3450 query
= "ALTER TABLE `U` ADD `C` INTEGER";
3451 r
= run_query(hdb
, 0, query
);
3452 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3454 /* add column C again */
3455 query
= "ALTER TABLE `U` ADD `C` INTEGER";
3456 r
= run_query(hdb
, 0, query
);
3457 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3459 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
3460 r
= run_query(hdb
, 0, query
);
3461 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3463 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
3464 r
= run_query(hdb
, 0, query
);
3465 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3467 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
3468 r
= run_query(hdb
, 0, query
);
3469 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3471 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
3472 r
= run_query(hdb
, 0, query
);
3473 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3475 query
= "SELECT * FROM `U` WHERE `D` = 8";
3476 r
= run_query(hdb
, 0, query
);
3477 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3479 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
3480 r
= run_query(hdb
, 0, query
);
3481 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3483 query
= "ALTER COLUMN `D` FREE";
3484 r
= run_query(hdb
, 0, query
);
3485 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3487 /* drop the ref count */
3488 query
= "ALTER TABLE `U` FREE";
3489 r
= run_query(hdb
, 0, query
);
3490 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3492 /* table is not empty */
3493 query
= "SELECT * FROM `U`";
3494 r
= run_query(hdb
, 0, query
);
3495 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3497 /* column D is removed */
3498 query
= "SELECT * FROM `U` WHERE `D` = 8";
3499 r
= run_query(hdb
, 0, query
);
3500 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3502 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
3503 r
= run_query(hdb
, 0, query
);
3504 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3506 /* add the column again */
3507 query
= "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
3508 r
= run_query(hdb
, 0, query
);
3509 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3511 /* up the ref count */
3512 query
= "ALTER TABLE `U` HOLD";
3513 r
= run_query(hdb
, 0, query
);
3514 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3516 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
3517 r
= run_query(hdb
, 0, query
);
3518 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3520 query
= "SELECT * FROM `U` WHERE `E` = 16";
3521 r
= run_query(hdb
, 0, query
);
3522 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3524 /* drop the ref count */
3525 query
= "ALTER TABLE `U` FREE";
3526 r
= run_query(hdb
, 0, query
);
3527 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3529 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
3530 r
= run_query(hdb
, 0, query
);
3531 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3533 query
= "SELECT * FROM `U` WHERE `E` = 20";
3534 r
= run_query(hdb
, 0, query
);
3535 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3537 /* drop the ref count */
3538 query
= "ALTER TABLE `U` FREE";
3539 r
= run_query(hdb
, 0, query
);
3540 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3542 /* table still exists */
3543 query
= "SELECT * FROM `U`";
3544 r
= run_query(hdb
, 0, query
);
3545 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3547 /* col E is removed */
3548 query
= "SELECT * FROM `U` WHERE `E` = 20";
3549 r
= run_query(hdb
, 0, query
);
3550 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3552 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
3553 r
= run_query(hdb
, 0, query
);
3554 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3556 /* drop the ref count once more */
3557 query
= "ALTER TABLE `U` FREE";
3558 r
= run_query(hdb
, 0, query
);
3559 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3561 /* table still exists */
3562 query
= "SELECT * FROM `U`";
3563 r
= run_query(hdb
, 0, query
);
3564 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3566 MsiCloseHandle( hdb
);
3567 DeleteFile(msifile
);
3570 static void test_integers(void)
3572 MSIHANDLE hdb
= 0, view
= 0, rec
= 0;
3577 /* just MsiOpenDatabase should not create a file */
3578 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
3579 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
3581 /* create a table */
3582 query
= "CREATE TABLE `integers` ( "
3583 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
3584 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
3585 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
3586 "PRIMARY KEY `one`)";
3587 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3588 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
3589 r
= MsiViewExecute(view
, 0);
3590 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
3591 r
= MsiViewClose(view
);
3592 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3593 r
= MsiCloseHandle(view
);
3594 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3596 query
= "SELECT * FROM `integers`";
3597 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3598 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3600 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
3601 count
= MsiRecordGetFieldCount(rec
);
3602 ok(count
== 8, "Expected 8, got %d\n", count
);
3603 ok(check_record(rec
, 1, "one"), "Expected one\n");
3604 ok(check_record(rec
, 2, "two"), "Expected two\n");
3605 ok(check_record(rec
, 3, "three"), "Expected three\n");
3606 ok(check_record(rec
, 4, "four"), "Expected four\n");
3607 ok(check_record(rec
, 5, "five"), "Expected five\n");
3608 ok(check_record(rec
, 6, "six"), "Expected six\n");
3609 ok(check_record(rec
, 7, "seven"), "Expected seven\n");
3610 ok(check_record(rec
, 8, "eight"), "Expected eight\n");
3611 MsiCloseHandle(rec
);
3613 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
3614 count
= MsiRecordGetFieldCount(rec
);
3615 ok(count
== 8, "Expected 8, got %d\n", count
);
3616 ok(check_record(rec
, 1, "I2"), "Expected I2\n");
3617 ok(check_record(rec
, 2, "I2"), "Expected I2\n");
3618 ok(check_record(rec
, 3, "I2"), "Expected I2\n");
3619 ok(check_record(rec
, 4, "I4"), "Expected I4\n");
3620 ok(check_record(rec
, 5, "i2"), "Expected i2\n");
3621 ok(check_record(rec
, 6, "i2"), "Expected i2\n");
3622 ok(check_record(rec
, 7, "i2"), "Expected i2\n");
3623 ok(check_record(rec
, 8, "i4"), "Expected i4\n");
3624 MsiCloseHandle(rec
);
3627 MsiCloseHandle(view
);
3629 /* insert values into it, NULL where NOT NULL is specified */
3630 query
= "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3631 "VALUES('', '', '', '', '', '', '', '')";
3632 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3633 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3634 r
= MsiViewExecute(view
, 0);
3635 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
3638 MsiCloseHandle(view
);
3640 query
= "SELECT * FROM `integers`";
3641 r
= do_query(hdb
, query
, &rec
);
3642 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3644 r
= MsiRecordGetFieldCount(rec
);
3645 ok(r
== -1, "record count wrong: %d\n", r
);
3647 MsiCloseHandle(rec
);
3649 /* insert legitimate values into it */
3650 query
= "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3651 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
3652 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3653 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3654 r
= MsiViewExecute(view
, 0);
3655 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3657 query
= "SELECT * FROM `integers`";
3658 r
= do_query(hdb
, query
, &rec
);
3659 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3661 r
= MsiRecordGetFieldCount(rec
);
3662 ok(r
== 8, "record count wrong: %d\n", r
);
3664 i
= MsiRecordGetInteger(rec
, 1);
3665 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
3666 i
= MsiRecordGetInteger(rec
, 3);
3667 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
3668 i
= MsiRecordGetInteger(rec
, 2);
3669 ok(i
== 2, "Expected 2, got %d\n", i
);
3670 i
= MsiRecordGetInteger(rec
, 4);
3671 ok(i
== 4, "Expected 4, got %d\n", i
);
3672 i
= MsiRecordGetInteger(rec
, 5);
3673 ok(i
== 5, "Expected 5, got %d\n", i
);
3674 i
= MsiRecordGetInteger(rec
, 6);
3675 ok(i
== 6, "Expected 6, got %d\n", i
);
3676 i
= MsiRecordGetInteger(rec
, 7);
3677 ok(i
== 7, "Expected 7, got %d\n", i
);
3678 i
= MsiRecordGetInteger(rec
, 8);
3679 ok(i
== 8, "Expected 8, got %d\n", i
);
3681 MsiCloseHandle(rec
);
3683 MsiCloseHandle(view
);
3685 r
= MsiDatabaseCommit(hdb
);
3686 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
3688 r
= MsiCloseHandle(hdb
);
3689 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3691 r
= DeleteFile(msifile
);
3692 ok(r
== TRUE
, "file didn't exist after commit\n");
3695 static void test_update(void)
3697 MSIHANDLE hdb
= 0, view
= 0, rec
= 0;
3698 CHAR result
[MAX_PATH
];
3703 /* just MsiOpenDatabase should not create a file */
3704 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
3705 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
3707 /* create the Control table */
3708 query
= "CREATE TABLE `Control` ( "
3709 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
3710 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
3711 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
3712 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
3713 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3714 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
3715 r
= MsiViewExecute(view
, 0);
3716 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
3717 r
= MsiViewClose(view
);
3718 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3719 r
= MsiCloseHandle(view
);
3720 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3723 query
= "INSERT INTO `Control` ( "
3724 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3725 "`Property`, `Text`, `Control_Next`, `Help` )"
3726 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3727 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3728 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3729 r
= MsiViewExecute(view
, 0);
3730 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3731 r
= MsiViewClose(view
);
3732 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3733 r
= MsiCloseHandle(view
);
3734 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3736 /* add a second control */
3737 query
= "INSERT INTO `Control` ( "
3738 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3739 "`Property`, `Text`, `Control_Next`, `Help` )"
3740 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
3741 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3742 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3743 r
= MsiViewExecute(view
, 0);
3744 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3745 r
= MsiViewClose(view
);
3746 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3747 r
= MsiCloseHandle(view
);
3748 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3750 /* add a third control */
3751 query
= "INSERT INTO `Control` ( "
3752 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3753 "`Property`, `Text`, `Control_Next`, `Help` )"
3754 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3755 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3756 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3757 r
= MsiViewExecute(view
, 0);
3758 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3759 r
= MsiViewClose(view
);
3760 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3761 r
= MsiCloseHandle(view
);
3762 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3765 query
= "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3766 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3767 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3769 /* bad set column */
3770 query
= "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3771 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3772 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3774 /* bad where condition */
3775 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
3776 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3777 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3779 /* just the dialog_ specified */
3780 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3781 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3782 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3783 r
= MsiViewExecute(view
, 0);
3784 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3785 r
= MsiViewClose(view
);
3786 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3787 r
= MsiCloseHandle(view
);
3788 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3790 /* check the modified text */
3791 query
= "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3792 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3793 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3794 r
= MsiViewExecute(view
, 0);
3795 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3797 r
= MsiViewFetch(view
, &rec
);
3798 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3801 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3802 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3803 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3805 MsiCloseHandle(rec
);
3807 r
= MsiViewFetch(view
, &rec
);
3808 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3811 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3812 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3813 ok(!lstrlen(result
), "Expected an empty string, got %s\n", result
);
3815 MsiCloseHandle(rec
);
3817 r
= MsiViewFetch(view
, &rec
);
3818 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3820 r
= MsiViewClose(view
);
3821 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3822 r
= MsiCloseHandle(view
);
3823 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3825 /* dialog_ and control specified */
3826 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
3827 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3828 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3829 r
= MsiViewExecute(view
, 0);
3830 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3831 r
= MsiViewClose(view
);
3832 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3833 r
= MsiCloseHandle(view
);
3834 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3836 /* check the modified text */
3837 query
= "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3838 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3839 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3840 r
= MsiViewExecute(view
, 0);
3841 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3843 r
= MsiViewFetch(view
, &rec
);
3844 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3847 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3848 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3849 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3851 MsiCloseHandle(rec
);
3853 r
= MsiViewFetch(view
, &rec
);
3854 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3857 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3858 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3859 ok(!lstrlen(result
), "Expected an empty string, got %s\n", result
);
3861 MsiCloseHandle(rec
);
3863 r
= MsiViewFetch(view
, &rec
);
3864 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3866 r
= MsiViewClose(view
);
3867 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3868 r
= MsiCloseHandle(view
);
3869 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3871 /* no where condition */
3872 query
= "UPDATE `Control` SET `Text` = 'this is text'";
3873 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3874 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3875 r
= MsiViewExecute(view
, 0);
3876 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3877 r
= MsiViewClose(view
);
3878 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3879 r
= MsiCloseHandle(view
);
3880 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3882 /* check the modified text */
3883 query
= "SELECT `Text` FROM `Control`";
3884 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3885 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3886 r
= MsiViewExecute(view
, 0);
3887 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3889 r
= MsiViewFetch(view
, &rec
);
3890 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3893 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3894 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3895 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3897 MsiCloseHandle(rec
);
3899 r
= MsiViewFetch(view
, &rec
);
3900 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3903 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3904 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3905 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3907 MsiCloseHandle(rec
);
3909 r
= MsiViewFetch(view
, &rec
);
3910 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3913 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3914 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3915 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3917 MsiCloseHandle(rec
);
3919 r
= MsiViewFetch(view
, &rec
);
3920 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3922 r
= MsiViewClose(view
);
3923 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3924 r
= MsiCloseHandle(view
);
3925 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3927 query
= "CREATE TABLE `Apple` ( `Banana` CHAR(72) NOT NULL, "
3928 "`Orange` CHAR(72), `Pear` INT PRIMARY KEY `Banana`)";
3929 r
= run_query(hdb
, 0, query
);
3930 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3932 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
3933 "VALUES('one', 'two', 3)";
3934 r
= run_query(hdb
, 0, query
);
3935 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3937 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
3938 "VALUES('three', 'four', 5)";
3939 r
= run_query(hdb
, 0, query
);
3940 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3942 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
3943 "VALUES('six', 'two', 7)";
3944 r
= run_query(hdb
, 0, query
);
3945 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3947 rec
= MsiCreateRecord(2);
3948 MsiRecordSetInteger(rec
, 1, 8);
3949 MsiRecordSetString(rec
, 2, "two");
3951 query
= "UPDATE `Apple` SET `Pear` = ? WHERE `Orange` = ?";
3952 r
= run_query(hdb
, rec
, query
);
3953 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3955 MsiCloseHandle(rec
);
3957 query
= "SELECT `Pear` FROM `Apple` ORDER BY `Orange`";
3958 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3959 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3960 r
= MsiViewExecute(view
, 0);
3961 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3963 r
= MsiViewFetch(view
, &rec
);
3964 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3966 r
= MsiRecordGetInteger(rec
, 1);
3967 ok(r
== 8, "Expected 8, got %d\n", r
);
3969 MsiCloseHandle(rec
);
3971 r
= MsiViewFetch(view
, &rec
);
3972 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3974 r
= MsiRecordGetInteger(rec
, 1);
3975 ok(r
== 8, "Expected 8, got %d\n", r
);
3977 MsiCloseHandle(rec
);
3979 r
= MsiViewFetch(view
, &rec
);
3980 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3982 r
= MsiRecordGetInteger(rec
, 1);
3983 ok(r
== 5, "Expected 5, got %d\n", r
);
3985 MsiCloseHandle(rec
);
3987 r
= MsiViewFetch(view
, &rec
);
3988 ok(r
== ERROR_NO_MORE_ITEMS
, "Expectd ERROR_NO_MORE_ITEMS, got %d\n", r
);
3991 MsiCloseHandle(view
);
3993 r
= MsiDatabaseCommit(hdb
);
3994 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
3995 r
= MsiCloseHandle(hdb
);
3996 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3998 DeleteFile(msifile
);
4001 static void test_special_tables(void)
4007 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4008 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4010 query
= "CREATE TABLE `_Properties` ( "
4011 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4012 r
= run_query(hdb
, 0, query
);
4013 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
4015 query
= "CREATE TABLE `_Storages` ( "
4016 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4017 r
= run_query(hdb
, 0, query
);
4018 todo_wine
ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Streams table\n");
4020 query
= "CREATE TABLE `_Streams` ( "
4021 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4022 r
= run_query(hdb
, 0, query
);
4023 todo_wine
ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Streams table\n");
4025 query
= "CREATE TABLE `_Tables` ( "
4026 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4027 r
= run_query(hdb
, 0, query
);
4028 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Tables table\n");
4030 query
= "CREATE TABLE `_Columns` ( "
4031 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
4032 r
= run_query(hdb
, 0, query
);
4033 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Columns table\n");
4035 r
= MsiCloseHandle(hdb
);
4036 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4039 static void test_select_markers(void)
4041 MSIHANDLE hdb
= 0, rec
, view
, res
;
4048 ok( hdb
, "failed to create db\n");
4050 r
= run_query(hdb
, 0,
4051 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
4052 ok(r
== S_OK
, "cannot create table: %d\n", r
);
4054 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4055 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
4056 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4058 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4059 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
4060 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4062 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4063 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
4064 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4066 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4067 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
4068 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4070 rec
= MsiCreateRecord(2);
4071 MsiRecordSetString(rec
, 1, "apple");
4072 MsiRecordSetString(rec
, 2, "two");
4074 query
= "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
4075 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4076 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4078 r
= MsiViewExecute(view
, rec
);
4079 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4081 r
= MsiViewFetch(view
, &res
);
4082 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4085 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4086 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4087 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4090 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4091 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4092 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4094 r
= MsiRecordGetInteger(res
, 3);
4095 ok(r
== 1, "Expected 1, got %d\n", r
);
4097 MsiCloseHandle(res
);
4099 r
= MsiViewFetch(view
, &res
);
4100 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4103 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4104 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4105 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4108 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4109 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4110 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4112 r
= MsiRecordGetInteger(res
, 3);
4113 ok(r
== 2, "Expected 2, got %d\n", r
);
4115 MsiCloseHandle(res
);
4117 r
= MsiViewFetch(view
, &res
);
4118 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4120 MsiCloseHandle(rec
);
4122 MsiCloseHandle(view
);
4124 rec
= MsiCreateRecord(2);
4125 MsiRecordSetString(rec
, 1, "one");
4126 MsiRecordSetInteger(rec
, 2, 1);
4128 query
= "SELECT * FROM `Table` WHERE `Two`<>? AND `Three`>? ORDER BY `Three`";
4129 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4130 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4131 r
= MsiViewExecute(view
, rec
);
4132 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4134 r
= MsiViewFetch(view
, &res
);
4135 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4138 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4139 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4140 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4143 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4144 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4145 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4147 r
= MsiRecordGetInteger(res
, 3);
4148 ok(r
== 2, "Expected 2, got %d\n", r
);
4150 MsiCloseHandle(res
);
4152 r
= MsiViewFetch(view
, &res
);
4153 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4156 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4157 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4158 ok(!lstrcmp(buf
, "banana"), "Expected banana, got %s\n", buf
);
4161 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4162 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4163 ok(!lstrcmp(buf
, "three"), "Expected three, got %s\n", buf
);
4165 r
= MsiRecordGetInteger(res
, 3);
4166 ok(r
== 3, "Expected 3, got %d\n", r
);
4168 MsiCloseHandle(res
);
4170 r
= MsiViewFetch(view
, &res
);
4171 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4173 MsiCloseHandle(rec
);
4175 MsiCloseHandle(view
);
4176 MsiCloseHandle(hdb
);
4177 DeleteFile(msifile
);
4180 static void test_viewmodify_update(void)
4182 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4186 DeleteFile(msifile
);
4188 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4189 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4191 query
= "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
4192 r
= run_query( hdb
, 0, query
);
4193 ok(r
== ERROR_SUCCESS
, "query failed\n");
4195 query
= "INSERT INTO `table` (`A`, `B`) VALUES (1, 2)";
4196 r
= run_query( hdb
, 0, query
);
4197 ok(r
== ERROR_SUCCESS
, "query failed\n");
4199 query
= "INSERT INTO `table` (`A`, `B`) VALUES (3, 4)";
4200 r
= run_query( hdb
, 0, query
);
4201 ok(r
== ERROR_SUCCESS
, "query failed\n");
4203 query
= "INSERT INTO `table` (`A`, `B`) VALUES (5, 6)";
4204 r
= run_query( hdb
, 0, query
);
4205 ok(r
== ERROR_SUCCESS
, "query failed\n");
4207 query
= "SELECT `B` FROM `table`";
4208 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4209 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4210 r
= MsiViewExecute(hview
, 0);
4211 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4212 r
= MsiViewFetch(hview
, &hrec
);
4213 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4215 r
= MsiRecordSetInteger(hrec
, 1, 0);
4216 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
4218 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
4219 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
4221 r
= MsiCloseHandle(hrec
);
4222 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4224 r
= MsiViewClose(hview
);
4225 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4226 r
= MsiCloseHandle(hview
);
4227 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4229 query
= "SELECT * 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");
4234 r
= MsiViewFetch(hview
, &hrec
);
4235 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4237 r
= MsiRecordGetInteger(hrec
, 1);
4238 ok(r
== 1, "Expected 1, got %d\n", r
);
4239 r
= MsiRecordGetInteger(hrec
, 2);
4240 ok(r
== 0, "Expected 0, got %d\n", r
);
4242 r
= MsiCloseHandle(hrec
);
4243 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4245 r
= MsiViewFetch(hview
, &hrec
);
4246 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4248 r
= MsiRecordGetInteger(hrec
, 1);
4249 ok(r
== 3, "Expected 3, got %d\n", r
);
4250 r
= MsiRecordGetInteger(hrec
, 2);
4251 ok(r
== 4, "Expected 4, got %d\n", r
);
4253 r
= MsiCloseHandle(hrec
);
4254 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4256 r
= MsiViewFetch(hview
, &hrec
);
4257 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4259 r
= MsiRecordGetInteger(hrec
, 1);
4260 ok(r
== 5, "Expected 5, got %d\n", r
);
4261 r
= MsiRecordGetInteger(hrec
, 2);
4262 ok(r
== 6, "Expected 6, got %d\n", r
);
4264 r
= MsiCloseHandle(hrec
);
4265 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4267 r
= MsiViewFetch(hview
, &hrec
);
4268 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4270 r
= MsiViewClose(hview
);
4271 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4272 r
= MsiCloseHandle(hview
);
4273 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4275 /* loop through all elements */
4276 query
= "SELECT `B` FROM `table`";
4277 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4278 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4279 r
= MsiViewExecute(hview
, 0);
4280 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4284 r
= MsiViewFetch(hview
, &hrec
);
4285 if (r
!= ERROR_SUCCESS
)
4288 r
= MsiRecordSetInteger(hrec
, 1, 0);
4289 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
4291 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
4292 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
4294 r
= MsiCloseHandle(hrec
);
4295 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4298 r
= MsiViewClose(hview
);
4299 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4300 r
= MsiCloseHandle(hview
);
4301 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4303 query
= "SELECT * FROM `table`";
4304 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4305 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4306 r
= MsiViewExecute(hview
, 0);
4307 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4308 r
= MsiViewFetch(hview
, &hrec
);
4309 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4311 r
= MsiRecordGetInteger(hrec
, 1);
4312 ok(r
== 1, "Expected 1, got %d\n", r
);
4313 r
= MsiRecordGetInteger(hrec
, 2);
4314 ok(r
== 0, "Expected 0, got %d\n", r
);
4316 r
= MsiCloseHandle(hrec
);
4317 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4319 r
= MsiViewFetch(hview
, &hrec
);
4320 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4322 r
= MsiRecordGetInteger(hrec
, 1);
4323 ok(r
== 3, "Expected 3, got %d\n", r
);
4324 r
= MsiRecordGetInteger(hrec
, 2);
4325 ok(r
== 0, "Expected 0, got %d\n", r
);
4327 r
= MsiCloseHandle(hrec
);
4328 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4330 r
= MsiViewFetch(hview
, &hrec
);
4331 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4333 r
= MsiRecordGetInteger(hrec
, 1);
4334 ok(r
== 5, "Expected 5, got %d\n", r
);
4335 r
= MsiRecordGetInteger(hrec
, 2);
4336 ok(r
== 0, "Expected 0, got %d\n", r
);
4338 r
= MsiCloseHandle(hrec
);
4339 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4341 r
= MsiViewFetch(hview
, &hrec
);
4342 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4344 r
= MsiViewClose(hview
);
4345 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4346 r
= MsiCloseHandle(hview
);
4347 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4349 r
= MsiCloseHandle( hdb
);
4350 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
4353 static const WCHAR data10
[] = { /* MOO */
4356 static const WCHAR data11
[] = { /* AAR */
4360 static const char data12
[] = /* _StringData */
4361 "MOOABAARCDonetwofourfive";
4362 static const WCHAR data13
[] = { /* _StringPool */
4364 0, 0, /* string 0 '' */
4365 0, 0, /* string 1 '' */
4366 0, 0, /* string 2 '' */
4367 0, 0, /* string 3 '' */
4368 0, 0, /* string 4 '' */
4369 3, 3, /* string 5 'MOO' */
4370 1, 1, /* string 6 'A' */
4371 1, 1, /* string 7 'B' */
4372 3, 3, /* string 8 'AAR' */
4373 1, 1, /* string 9 'C' */
4374 1, 1, /* string a 'D' */
4375 3, 1, /* string b 'one' */
4376 3, 1, /* string c 'two' */
4377 0, 0, /* string d '' */
4378 4, 1, /* string e 'four' */
4379 4, 1, /* string f 'five' */
4382 static void test_stringtable(void)
4384 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4385 IStorage
*stg
= NULL
;
4390 char buffer
[MAX_PATH
];
4391 WCHAR data
[MAX_PATH
];
4395 static const DWORD mode
= STGM_DIRECT
| STGM_READ
| STGM_SHARE_DENY_WRITE
;
4396 static const WCHAR stringdata
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0}; /* _StringData */
4397 static const WCHAR stringpool
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0}; /* _StringPool */
4398 static const WCHAR moo
[] = {0x4840, 0x3e16, 0x4818, 0}; /* MOO */
4399 static const WCHAR aar
[] = {0x4840, 0x3a8a, 0x481b, 0}; /* AAR */
4401 DeleteFile(msifile
);
4403 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4404 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4406 query
= "CREATE TABLE `MOO` (`A` INT, `B` CHAR(72) PRIMARY KEY `A`)";
4407 r
= run_query(hdb
, 0, query
);
4408 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4410 query
= "CREATE TABLE `AAR` (`C` INT, `D` CHAR(72) PRIMARY KEY `C`)";
4411 r
= run_query(hdb
, 0, query
);
4412 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4414 /* insert persistent row */
4415 query
= "INSERT INTO `MOO` (`A`, `B`) VALUES (1, 'one')";
4416 r
= run_query(hdb
, 0, query
);
4417 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4419 /* insert persistent row */
4420 query
= "INSERT INTO `AAR` (`C`, `D`) VALUES (2, 'two')";
4421 r
= run_query(hdb
, 0, query
);
4422 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4425 query
= "SELECT * FROM `MOO`";
4426 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4427 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4428 r
= MsiViewExecute(hview
, 0);
4429 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4431 hrec
= MsiCreateRecord(2);
4433 r
= MsiRecordSetInteger(hrec
, 1, 3);
4434 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4435 r
= MsiRecordSetString(hrec
, 2, "three");
4436 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4438 /* insert a nonpersistent row */
4439 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
4440 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4442 r
= MsiCloseHandle(hrec
);
4443 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4444 r
= MsiViewClose(hview
);
4445 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4446 r
= MsiCloseHandle(hview
);
4447 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4449 /* insert persistent row */
4450 query
= "INSERT INTO `MOO` (`A`, `B`) VALUES (4, 'four')";
4451 r
= run_query(hdb
, 0, query
);
4452 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4454 /* insert persistent row */
4455 query
= "INSERT INTO `AAR` (`C`, `D`) VALUES (5, 'five')";
4456 r
= run_query(hdb
, 0, query
);
4457 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4459 r
= MsiDatabaseCommit(hdb
);
4460 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4462 r
= MsiCloseHandle(hdb
);
4463 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4465 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
4466 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4468 query
= "SELECT * FROM `MOO`";
4469 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4470 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4472 r
= MsiViewExecute(hview
, 0);
4473 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4475 r
= MsiViewFetch(hview
, &hrec
);
4476 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4478 r
= MsiRecordGetFieldCount(hrec
);
4479 ok(r
== 2, "Expected 2, got %d\n", r
);
4481 r
= MsiRecordGetInteger(hrec
, 1);
4482 ok(r
== 1, "Expected 1, got %d\n", r
);
4484 sz
= sizeof(buffer
);
4485 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4486 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4487 ok(!lstrcmp(buffer
, "one"), "Expected one, got %s\n", buffer
);
4489 r
= MsiCloseHandle(hrec
);
4490 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4492 r
= MsiViewFetch(hview
, &hrec
);
4495 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4498 r
= MsiViewClose(hview
);
4499 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4500 r
= MsiCloseHandle(hview
);
4501 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4502 r
= MsiCloseHandle(hrec
);
4503 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4505 query
= "SELECT * FROM `AAR`";
4506 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4507 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4509 r
= MsiViewExecute(hview
, 0);
4510 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4512 r
= MsiViewFetch(hview
, &hrec
);
4513 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4515 r
= MsiRecordGetFieldCount(hrec
);
4516 ok(r
== 2, "Expected 2, got %d\n", r
);
4518 r
= MsiRecordGetInteger(hrec
, 1);
4519 ok(r
== 2, "Expected 2, got %d\n", r
);
4521 sz
= sizeof(buffer
);
4522 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4523 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4524 ok(!lstrcmp(buffer
, "two"), "Expected two, got %s\n", buffer
);
4526 r
= MsiCloseHandle(hrec
);
4527 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4529 r
= MsiViewFetch(hview
, &hrec
);
4530 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4532 r
= MsiRecordGetFieldCount(hrec
);
4533 ok(r
== 2, "Expected 2, got %d\n", r
);
4535 r
= MsiRecordGetInteger(hrec
, 1);
4536 ok(r
== 5, "Expected 5, got %d\n", r
);
4538 sz
= sizeof(buffer
);
4539 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4540 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4541 ok(!lstrcmp(buffer
, "five"), "Expected five, got %s\n", buffer
);
4543 r
= MsiCloseHandle(hrec
);
4544 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4546 r
= MsiViewFetch(hview
, &hrec
);
4547 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4549 r
= MsiViewClose(hview
);
4550 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4551 r
= MsiCloseHandle(hview
);
4552 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4553 r
= MsiCloseHandle(hrec
);
4554 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4555 r
= MsiCloseHandle(hdb
);
4556 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4558 MultiByteToWideChar(CP_ACP
, 0, msifile
, -1, name
, 0x20);
4559 hr
= StgOpenStorage(name
, NULL
, mode
, NULL
, 0, &stg
);
4560 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4561 ok(stg
!= NULL
, "Expected non-NULL storage\n");
4563 hr
= IStorage_OpenStream(stg
, moo
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4564 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4565 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4567 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
4568 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4571 ok(read
== 4, "Expected 4, got %d\n", read
);
4572 ok(!memcmp(data
, data10
, read
), "Unexpected data\n");
4575 hr
= IStream_Release(stm
);
4576 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4578 hr
= IStorage_OpenStream(stg
, aar
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4579 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4580 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4582 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
4583 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4584 ok(read
== 8, "Expected 8, got %d\n", read
);
4587 ok(!memcmp(data
, data11
, read
), "Unexpected data\n");
4590 hr
= IStream_Release(stm
);
4591 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4593 hr
= IStorage_OpenStream(stg
, stringdata
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4594 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4595 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4597 hr
= IStream_Read(stm
, buffer
, MAX_PATH
, &read
);
4598 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4599 ok(read
== 24, "Expected 24, got %d\n", read
);
4600 ok(!memcmp(buffer
, data12
, read
), "Unexpected data\n");
4602 hr
= IStream_Release(stm
);
4603 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4605 hr
= IStorage_OpenStream(stg
, stringpool
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4606 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4607 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4609 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
4610 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4613 ok(read
== 64, "Expected 64, got %d\n", read
);
4614 ok(!memcmp(data
, data13
, read
), "Unexpected data\n");
4617 hr
= IStream_Release(stm
);
4618 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4620 hr
= IStorage_Release(stg
);
4621 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4623 DeleteFileA(msifile
);
4626 static void test_viewmodify_delete(void)
4628 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4634 DeleteFile(msifile
);
4636 /* just MsiOpenDatabase should not create a file */
4637 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4638 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4640 query
= "CREATE TABLE `phone` ( "
4641 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
4642 "PRIMARY KEY `id`)";
4643 r
= run_query(hdb
, 0, query
);
4644 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4646 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
4647 "VALUES('1', 'Alan', '5030581')";
4648 r
= run_query(hdb
, 0, query
);
4649 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4651 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
4652 "VALUES('2', 'Barry', '928440')";
4653 r
= run_query(hdb
, 0, query
);
4654 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4656 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
4657 "VALUES('3', 'Cindy', '2937550')";
4658 r
= run_query(hdb
, 0, query
);
4659 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4661 query
= "SELECT * FROM `phone` WHERE `id` <= 2";
4662 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4663 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4664 r
= MsiViewExecute(hview
, 0);
4665 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4666 r
= MsiViewFetch(hview
, &hrec
);
4667 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4670 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
4671 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4673 r
= MsiCloseHandle(hrec
);
4674 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4675 r
= MsiViewFetch(hview
, &hrec
);
4676 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4679 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
4680 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4682 r
= MsiCloseHandle(hrec
);
4683 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4684 r
= MsiViewClose(hview
);
4685 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4686 r
= MsiCloseHandle(hview
);
4687 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4689 query
= "SELECT * FROM `phone`";
4690 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4691 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4692 r
= MsiViewExecute(hview
, 0);
4693 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4694 r
= MsiViewFetch(hview
, &hrec
);
4695 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4697 r
= MsiRecordGetInteger(hrec
, 1);
4698 ok(r
== 3, "Expected 3, got %d\n", r
);
4700 sz
= sizeof(buffer
);
4701 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4702 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4703 ok(!lstrcmp(buffer
, "Cindy"), "Expected Cindy, got %s\n", buffer
);
4705 sz
= sizeof(buffer
);
4706 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4707 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4708 ok(!lstrcmp(buffer
, "2937550"), "Expected 2937550, got %s\n", buffer
);
4710 r
= MsiCloseHandle(hrec
);
4711 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4713 r
= MsiViewFetch(hview
, &hrec
);
4714 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4716 r
= MsiViewClose(hview
);
4717 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4718 r
= MsiCloseHandle(hview
);
4719 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4720 r
= MsiCloseHandle(hdb
);
4721 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4724 static const WCHAR _Tables
[] = {0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0};
4725 static const WCHAR _StringData
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0};
4726 static const WCHAR _StringPool
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0};
4728 static const WCHAR data14
[] = { /* _StringPool */
4730 0, 0, /* string 0 '' */
4733 static const struct {
4737 } database_table_data
[] =
4740 {_StringData
, NULL
, 0},
4741 {_StringPool
, data14
, sizeof data14
},
4744 void enum_stream_names(IStorage
*stg
)
4746 IEnumSTATSTG
*stgenum
= NULL
;
4751 BYTE data
[MAX_PATH
];
4752 BYTE check
[MAX_PATH
];
4755 memset(check
, 'a', MAX_PATH
);
4757 hr
= IStorage_EnumElements(stg
, 0, NULL
, 0, &stgenum
);
4758 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
4764 hr
= IEnumSTATSTG_Next(stgenum
, 1, &stat
, &count
);
4765 if(FAILED(hr
) || !count
)
4768 ok(!lstrcmpW(stat
.pwcsName
, database_table_data
[n
].name
),
4769 "Expected table %d name to match\n", n
);
4772 hr
= IStorage_OpenStream(stg
, stat
.pwcsName
, NULL
,
4773 STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4774 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
4775 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4778 memset(data
, 'a', MAX_PATH
);
4779 hr
= IStream_Read(stm
, data
, sz
, &count
);
4780 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
4782 ok(count
== database_table_data
[n
].size
,
4783 "Expected %d, got %d\n", database_table_data
[n
].size
, count
);
4785 if (!database_table_data
[n
].size
)
4786 ok(!memcmp(data
, check
, MAX_PATH
), "data should not be changed\n");
4788 ok(!memcmp(data
, database_table_data
[n
].data
, database_table_data
[n
].size
),
4789 "Expected table %d data to match\n", n
);
4791 IStream_Release(stm
);
4795 ok(n
== 3, "Expected 3, got %d\n", n
);
4797 IEnumSTATSTG_Release(stgenum
);
4800 static void test_defaultdatabase(void)
4805 IStorage
*stg
= NULL
;
4807 static const WCHAR msifileW
[] = {'w','i','n','e','t','e','s','t','.','m','s','i',0};
4809 DeleteFile(msifile
);
4811 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4812 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4814 r
= MsiDatabaseCommit(hdb
);
4815 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4817 MsiCloseHandle(hdb
);
4819 hr
= StgOpenStorage(msifileW
, NULL
, STGM_READ
| STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
4820 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
4821 ok(stg
!= NULL
, "Expected non-NULL stg\n");
4823 enum_stream_names(stg
);
4825 IStorage_Release(stg
);
4826 DeleteFileA(msifile
);
4829 static void test_order(void)
4831 MSIHANDLE hdb
, hview
, hrec
;
4832 CHAR buffer
[MAX_PATH
];
4838 ok(hdb
, "failed to create db\n");
4840 query
= "CREATE TABLE `Empty` ( `A` SHORT NOT NULL PRIMARY KEY `A`)";
4841 r
= run_query(hdb
, 0, query
);
4842 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4844 query
= "CREATE TABLE `Mesa` ( `A` SHORT NOT NULL, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
4845 r
= run_query(hdb
, 0, query
);
4846 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4848 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 1, 2, 9 )";
4849 r
= run_query(hdb
, 0, query
);
4850 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4852 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 3, 4, 7 )";
4853 r
= run_query(hdb
, 0, query
);
4854 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4856 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 5, 6, 8 )";
4857 r
= run_query(hdb
, 0, query
);
4858 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4860 query
= "CREATE TABLE `Sideboard` ( `D` SHORT NOT NULL, `E` SHORT, `F` SHORT PRIMARY KEY `D`)";
4861 r
= run_query(hdb
, 0, query
);
4862 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4864 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 10, 11, 18 )";
4865 r
= run_query(hdb
, 0, query
);
4866 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4868 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 12, 13, 16 )";
4869 r
= run_query(hdb
, 0, query
);
4870 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4872 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 14, 15, 17 )";
4873 r
= run_query(hdb
, 0, query
);
4874 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4876 query
= "SELECT `A`, `B` FROM `Mesa` ORDER BY `C`";
4877 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4878 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4879 r
= MsiViewExecute(hview
, 0);
4880 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4882 r
= MsiViewFetch(hview
, &hrec
);
4883 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4885 val
= MsiRecordGetInteger(hrec
, 1);
4886 ok(val
== 3, "Expected 3, got %d\n", val
);
4888 val
= MsiRecordGetInteger(hrec
, 2);
4889 ok(val
== 4, "Expected 3, got %d\n", val
);
4891 MsiCloseHandle(hrec
);
4893 r
= MsiViewFetch(hview
, &hrec
);
4894 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4896 val
= MsiRecordGetInteger(hrec
, 1);
4897 ok(val
== 5, "Expected 5, got %d\n", val
);
4899 val
= MsiRecordGetInteger(hrec
, 2);
4900 ok(val
== 6, "Expected 6, got %d\n", val
);
4902 MsiCloseHandle(hrec
);
4904 r
= MsiViewFetch(hview
, &hrec
);
4905 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4907 val
= MsiRecordGetInteger(hrec
, 1);
4908 ok(val
== 1, "Expected 1, got %d\n", val
);
4910 val
= MsiRecordGetInteger(hrec
, 2);
4911 ok(val
== 2, "Expected 2, got %d\n", val
);
4913 MsiCloseHandle(hrec
);
4915 r
= MsiViewFetch(hview
, &hrec
);
4916 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4918 MsiViewClose(hview
);
4919 MsiCloseHandle(hview
);
4921 query
= "SELECT `A`, `D` FROM `Mesa`, `Sideboard` ORDER BY `F`";
4922 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4923 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4924 r
= MsiViewExecute(hview
, 0);
4925 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4927 r
= MsiViewFetch(hview
, &hrec
);
4928 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4930 val
= MsiRecordGetInteger(hrec
, 1);
4931 ok(val
== 1, "Expected 1, got %d\n", val
);
4933 val
= MsiRecordGetInteger(hrec
, 2);
4934 ok(val
== 12, "Expected 12, got %d\n", val
);
4936 MsiCloseHandle(hrec
);
4938 r
= MsiViewFetch(hview
, &hrec
);
4939 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4941 val
= MsiRecordGetInteger(hrec
, 1);
4942 ok(val
== 3, "Expected 3, got %d\n", val
);
4944 val
= MsiRecordGetInteger(hrec
, 2);
4945 ok(val
== 12, "Expected 12, got %d\n", val
);
4947 MsiCloseHandle(hrec
);
4949 r
= MsiViewFetch(hview
, &hrec
);
4950 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4952 val
= MsiRecordGetInteger(hrec
, 1);
4953 ok(val
== 5, "Expected 5, got %d\n", val
);
4955 val
= MsiRecordGetInteger(hrec
, 2);
4956 ok(val
== 12, "Expected 12, got %d\n", val
);
4958 MsiCloseHandle(hrec
);
4960 r
= MsiViewFetch(hview
, &hrec
);
4961 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4963 val
= MsiRecordGetInteger(hrec
, 1);
4964 ok(val
== 1, "Expected 1, got %d\n", val
);
4966 val
= MsiRecordGetInteger(hrec
, 2);
4967 ok(val
== 14, "Expected 14, got %d\n", val
);
4969 MsiCloseHandle(hrec
);
4971 r
= MsiViewFetch(hview
, &hrec
);
4972 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4974 val
= MsiRecordGetInteger(hrec
, 1);
4975 ok(val
== 3, "Expected 3, got %d\n", val
);
4977 val
= MsiRecordGetInteger(hrec
, 2);
4978 ok(val
== 14, "Expected 14, got %d\n", val
);
4980 MsiCloseHandle(hrec
);
4982 r
= MsiViewFetch(hview
, &hrec
);
4983 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4985 val
= MsiRecordGetInteger(hrec
, 1);
4986 ok(val
== 5, "Expected 5, got %d\n", val
);
4988 val
= MsiRecordGetInteger(hrec
, 2);
4989 ok(val
== 14, "Expected 14, got %d\n", val
);
4991 MsiCloseHandle(hrec
);
4993 r
= MsiViewFetch(hview
, &hrec
);
4994 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4996 val
= MsiRecordGetInteger(hrec
, 1);
4997 ok(val
== 1, "Expected 1, got %d\n", val
);
4999 val
= MsiRecordGetInteger(hrec
, 2);
5000 ok(val
== 10, "Expected 10, got %d\n", val
);
5002 MsiCloseHandle(hrec
);
5004 r
= MsiViewFetch(hview
, &hrec
);
5005 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5007 val
= MsiRecordGetInteger(hrec
, 1);
5008 ok(val
== 3, "Expected 3, got %d\n", val
);
5010 val
= MsiRecordGetInteger(hrec
, 2);
5011 ok(val
== 10, "Expected 10, got %d\n", val
);
5013 MsiCloseHandle(hrec
);
5015 r
= MsiViewFetch(hview
, &hrec
);
5016 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5018 val
= MsiRecordGetInteger(hrec
, 1);
5019 ok(val
== 5, "Expected 5, got %d\n", val
);
5021 val
= MsiRecordGetInteger(hrec
, 2);
5022 ok(val
== 10, "Expected 10, got %d\n", val
);
5024 MsiCloseHandle(hrec
);
5026 r
= MsiViewFetch(hview
, &hrec
);
5027 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5029 MsiViewClose(hview
);
5030 MsiCloseHandle(hview
);
5032 query
= "SELECT * FROM `Empty` ORDER BY `A`";
5033 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5034 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5035 r
= MsiViewExecute(hview
, 0);
5036 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5038 r
= MsiViewFetch(hview
, &hrec
);
5039 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5041 MsiViewClose(hview
);
5042 MsiCloseHandle(hview
);
5044 query
= "CREATE TABLE `Buffet` ( `One` CHAR(72), `Two` SHORT PRIMARY KEY `One`)";
5045 r
= run_query(hdb
, 0, query
);
5046 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5048 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'uno', 2)";
5049 r
= run_query(hdb
, 0, query
);
5050 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5052 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'dos', 3)";
5053 r
= run_query(hdb
, 0, query
);
5054 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5056 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'tres', 1)";
5057 r
= run_query(hdb
, 0, query
);
5058 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5060 query
= "SELECT * FROM `Buffet` WHERE `One` = 'dos' ORDER BY `Two`";
5061 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5062 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5063 r
= MsiViewExecute(hview
, 0);
5064 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5066 r
= MsiViewFetch(hview
, &hrec
);
5067 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5069 sz
= sizeof(buffer
);
5070 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
5071 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5072 ok(!lstrcmp(buffer
, "dos"), "Expected \"dos\", got \"%s\"\n", buffer
);
5074 r
= MsiRecordGetInteger(hrec
, 2);
5075 ok(r
== 3, "Expected 3, got %d\n", r
);
5077 MsiCloseHandle(hrec
);
5079 r
= MsiViewFetch(hview
, &hrec
);
5080 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5082 MsiViewClose(hview
);
5083 MsiCloseHandle(hview
);
5084 MsiCloseHandle(hdb
);
5087 static void test_viewmodify_delete_temporary(void)
5089 MSIHANDLE hdb
, hview
, hrec
;
5093 DeleteFile(msifile
);
5095 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5096 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5098 query
= "CREATE TABLE `Table` ( `A` SHORT PRIMARY KEY `A` )";
5099 r
= run_query(hdb
, 0, query
);
5100 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5102 query
= "SELECT * FROM `Table`";
5103 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5104 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5105 r
= MsiViewExecute(hview
, 0);
5106 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5108 hrec
= MsiCreateRecord(1);
5109 MsiRecordSetInteger(hrec
, 1, 1);
5111 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, hrec
);
5112 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5114 MsiCloseHandle(hrec
);
5116 hrec
= MsiCreateRecord(1);
5117 MsiRecordSetInteger(hrec
, 1, 2);
5119 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
5120 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5122 MsiCloseHandle(hrec
);
5124 hrec
= MsiCreateRecord(1);
5125 MsiRecordSetInteger(hrec
, 1, 3);
5127 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, hrec
);
5128 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5130 MsiCloseHandle(hrec
);
5132 hrec
= MsiCreateRecord(1);
5133 MsiRecordSetInteger(hrec
, 1, 4);
5135 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
5136 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5138 MsiCloseHandle(hrec
);
5139 MsiViewClose(hview
);
5140 MsiCloseHandle(hview
);
5142 query
= "SELECT * FROM `Table` WHERE `A` = 2";
5143 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5144 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5145 r
= MsiViewExecute(hview
, 0);
5146 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5147 r
= MsiViewFetch(hview
, &hrec
);
5148 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5150 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
5151 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5153 MsiCloseHandle(hrec
);
5154 MsiViewClose(hview
);
5155 MsiCloseHandle(hview
);
5157 query
= "SELECT * FROM `Table` WHERE `A` = 3";
5158 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5159 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5160 r
= MsiViewExecute(hview
, 0);
5161 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5162 r
= MsiViewFetch(hview
, &hrec
);
5163 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5165 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
5166 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5168 MsiCloseHandle(hrec
);
5169 MsiViewClose(hview
);
5170 MsiCloseHandle(hview
);
5172 query
= "SELECT * FROM `Table` ORDER BY `A`";
5173 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5174 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5175 r
= MsiViewExecute(hview
, 0);
5176 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5178 r
= MsiViewFetch(hview
, &hrec
);
5179 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5181 r
= MsiRecordGetInteger(hrec
, 1);
5182 ok(r
== 1, "Expected 1, got %d\n", r
);
5184 MsiCloseHandle(hrec
);
5186 r
= MsiViewFetch(hview
, &hrec
);
5187 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5189 r
= MsiRecordGetInteger(hrec
, 1);
5190 ok(r
== 4, "Expected 4, got %d\n", r
);
5192 MsiCloseHandle(hrec
);
5194 r
= MsiViewFetch(hview
, &hrec
);
5195 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5197 MsiViewClose(hview
);
5198 MsiCloseHandle(hview
);
5199 MsiCloseHandle(hdb
);
5200 DeleteFileA(msifile
);
5203 static void test_deleterow()
5205 MSIHANDLE hdb
, hview
, hrec
;
5211 DeleteFile(msifile
);
5213 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5214 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5216 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5217 r
= run_query(hdb
, 0, query
);
5218 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5220 query
= "INSERT INTO `Table` (`A`) VALUES ('one')";
5221 r
= run_query(hdb
, 0, query
);
5222 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5224 query
= "INSERT INTO `Table` (`A`) VALUES ('two')";
5225 r
= run_query(hdb
, 0, query
);
5226 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5228 query
= "DELETE FROM `Table` WHERE `A` = 'one'";
5229 r
= run_query(hdb
, 0, query
);
5230 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5232 r
= MsiDatabaseCommit(hdb
);
5233 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5235 MsiCloseHandle(hdb
);
5237 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
5238 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5240 query
= "SELECT * FROM `Table`";
5241 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5242 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5243 r
= MsiViewExecute(hview
, 0);
5244 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5246 r
= MsiViewFetch(hview
, &hrec
);
5247 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5250 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5251 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5252 ok(!lstrcmpA(buf
, "two"), "Expected two, got %s\n", buf
);
5254 MsiCloseHandle(hrec
);
5256 r
= MsiViewFetch(hview
, &hrec
);
5257 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5259 MsiViewClose(hview
);
5260 MsiCloseHandle(hview
);
5261 MsiCloseHandle(hdb
);
5262 DeleteFileA(msifile
);
5265 static const CHAR import_dat
[] = "A\n"
5268 "This is a new 'string' ok\n";
5270 static void test_quotes(void)
5272 MSIHANDLE hdb
, hview
, hrec
;
5278 DeleteFile(msifile
);
5280 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5281 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5283 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5284 r
= run_query(hdb
, 0, query
);
5285 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5287 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a 'string' ok' )";
5288 r
= run_query(hdb
, 0, query
);
5289 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5290 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5292 query
= "INSERT INTO `Table` ( `A` ) VALUES ( \"This is a 'string' ok\" )";
5293 r
= run_query(hdb
, 0, query
);
5294 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5295 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5297 query
= "INSERT INTO `Table` ( `A` ) VALUES ( \"test\" )";
5298 r
= run_query(hdb
, 0, query
);
5299 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5300 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5302 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a ''string'' ok' )";
5303 r
= run_query(hdb
, 0, query
);
5306 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5309 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a '''string''' ok' )";
5310 r
= run_query(hdb
, 0, query
);
5311 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5313 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \'string\' ok' )";
5314 r
= run_query(hdb
, 0, query
);
5315 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5317 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \"string\" ok' )";
5318 r
= run_query(hdb
, 0, query
);
5319 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5321 query
= "SELECT * FROM `Table`";
5322 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5323 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5325 r
= MsiViewExecute(hview
, 0);
5326 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5328 r
= MsiViewFetch(hview
, &hrec
);
5329 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5332 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
5333 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5336 ok(!lstrcmp(buf
, "This is a \"string\" ok"),
5337 "Expected \"This is a \"string\" ok\", got %s\n", buf
);
5340 MsiCloseHandle(hrec
);
5342 r
= MsiViewFetch(hview
, &hrec
);
5345 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5348 MsiCloseHandle(hview
);
5350 write_file("import.idt", import_dat
, (sizeof(import_dat
) - 1) * sizeof(char));
5352 r
= MsiDatabaseImportA(hdb
, CURR_DIR
, "import.idt");
5353 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5355 DeleteFileA("import.idt");
5357 query
= "SELECT * FROM `Table`";
5358 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5359 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5361 r
= MsiViewExecute(hview
, 0);
5362 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5364 r
= MsiViewFetch(hview
, &hrec
);
5365 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5368 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
5369 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5370 ok(!lstrcmp(buf
, "This is a new 'string' ok"),
5371 "Expected \"This is a new 'string' ok\", got %s\n", buf
);
5373 MsiCloseHandle(hrec
);
5375 r
= MsiViewFetch(hview
, &hrec
);
5376 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5378 MsiCloseHandle(hview
);
5380 MsiCloseHandle(hdb
);
5381 DeleteFileA(msifile
);
5384 static void test_carriagereturn(void)
5386 MSIHANDLE hdb
, hview
, hrec
;
5392 DeleteFile(msifile
);
5394 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5395 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5397 query
= "CREATE TABLE `Table`\r ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5398 r
= run_query(hdb
, 0, query
);
5401 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5402 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5405 query
= "CREATE TABLE `Table` \r( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5406 r
= run_query(hdb
, 0, query
);
5407 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5408 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5410 query
= "CREATE\r TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5411 r
= run_query(hdb
, 0, query
);
5412 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5413 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5415 query
= "CREATE TABLE\r `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5416 r
= run_query(hdb
, 0, query
);
5417 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5418 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5420 query
= "CREATE TABLE `Table` (\r `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5421 r
= run_query(hdb
, 0, query
);
5422 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5423 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5425 query
= "CREATE TABLE `Table` ( `A`\r CHAR(72) NOT NULL PRIMARY KEY `A` )";
5426 r
= run_query(hdb
, 0, query
);
5427 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5428 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5430 query
= "CREATE TABLE `Table` ( `A` CHAR(72)\r NOT NULL PRIMARY KEY `A` )";
5431 r
= run_query(hdb
, 0, query
);
5432 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5433 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5435 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT\r NULL PRIMARY KEY `A` )";
5436 r
= run_query(hdb
, 0, query
);
5437 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5438 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5440 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT \rNULL PRIMARY KEY `A` )";
5441 r
= run_query(hdb
, 0, query
);
5442 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5443 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5445 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL\r 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 `Table` ( `A` CHAR(72) NOT NULL \rPRIMARY 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 `Table` ( `A` CHAR(72) NOT NULL PRIMARY\r KEY `A` )";
5456 r
= run_query(hdb
, 0, query
);
5457 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5458 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5460 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY \rKEY `A` )";
5461 r
= run_query(hdb
, 0, query
);
5462 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5463 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5465 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY\r `A` )";
5466 r
= run_query(hdb
, 0, query
);
5467 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5468 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5470 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A`\r )";
5471 r
= run_query(hdb
, 0, query
);
5472 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5473 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5475 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )\r";
5476 r
= run_query(hdb
, 0, query
);
5477 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5478 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5480 query
= "CREATE TABLE `\rOne` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5481 r
= run_query(hdb
, 0, query
);
5482 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5484 query
= "CREATE TABLE `Tw\ro` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5485 r
= run_query(hdb
, 0, query
);
5486 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5488 query
= "CREATE TABLE `Three\r` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5489 r
= run_query(hdb
, 0, query
);
5490 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5492 query
= "CREATE TABLE `Four` ( `A\r` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5493 r
= run_query(hdb
, 0, query
);
5494 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5495 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5497 query
= "CREATE TABLE `Four` ( `\rA` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5498 r
= run_query(hdb
, 0, query
);
5499 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5500 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5502 query
= "CREATE TABLE `Four` ( `A` CHAR(72\r) NOT NULL PRIMARY KEY `A` )";
5503 r
= run_query(hdb
, 0, query
);
5506 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5507 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5510 query
= "CREATE TABLE `Four` ( `A` CHAR(\r72) NOT NULL PRIMARY KEY `A` )";
5511 r
= run_query(hdb
, 0, query
);
5512 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5513 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5515 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `\rA` )";
5516 r
= run_query(hdb
, 0, query
);
5517 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5518 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5520 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
5521 r
= run_query(hdb
, 0, query
);
5522 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5523 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5525 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
5526 r
= run_query(hdb
, 0, query
);
5527 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5528 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5530 query
= "SELECT * FROM `_Tables`";
5531 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5532 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5533 r
= MsiViewExecute(hview
, 0);
5534 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5536 r
= MsiViewFetch(hview
, &hrec
);
5537 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5540 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5541 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5544 ok(!lstrcmpA(buf
, "\rOne"), "Expected \"\\rOne\", got \"%s\"\n", buf
);
5547 MsiCloseHandle(hrec
);
5549 r
= MsiViewFetch(hview
, &hrec
);
5550 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5553 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5554 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5557 ok(!lstrcmpA(buf
, "Tw\ro"), "Expected \"Tw\\ro\", got \"%s\"\n", buf
);
5560 MsiCloseHandle(hrec
);
5562 r
= MsiViewFetch(hview
, &hrec
);
5563 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5566 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5567 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5570 ok(!lstrcmpA(buf
, "Three\r"),
5571 "Expected \"Three\r\", got \"%s\"\n", buf
);
5574 MsiCloseHandle(hrec
);
5576 r
= MsiViewFetch(hview
, &hrec
);
5579 ok(r
== ERROR_NO_MORE_ITEMS
,
5580 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5583 MsiViewClose(hview
);
5584 MsiCloseHandle(hview
);
5586 MsiCloseHandle(hdb
);
5587 DeleteFileA(msifile
);
5590 static void test_noquotes(void)
5592 MSIHANDLE hdb
, hview
, hrec
;
5598 DeleteFile(msifile
);
5600 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5601 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5603 query
= "CREATE TABLE Table ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5604 r
= run_query(hdb
, 0, query
);
5605 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5607 query
= "CREATE TABLE `Table` ( A CHAR(72) NOT NULL PRIMARY KEY `A` )";
5608 r
= run_query(hdb
, 0, query
);
5609 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5611 query
= "CREATE TABLE `Table2` ( `A` CHAR(72) NOT NULL PRIMARY KEY A )";
5612 r
= run_query(hdb
, 0, query
);
5613 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5615 query
= "CREATE TABLE `Table3` ( A CHAR(72) NOT NULL PRIMARY KEY A )";
5616 r
= run_query(hdb
, 0, query
);
5617 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5619 query
= "SELECT * FROM `_Tables`";
5620 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5621 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5622 r
= MsiViewExecute(hview
, 0);
5623 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5625 r
= MsiViewFetch(hview
, &hrec
);
5626 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5629 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5630 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5631 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
5633 MsiCloseHandle(hrec
);
5635 r
= MsiViewFetch(hview
, &hrec
);
5636 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5639 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5640 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5641 ok(!lstrcmpA(buf
, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf
);
5643 MsiCloseHandle(hrec
);
5645 r
= MsiViewFetch(hview
, &hrec
);
5646 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5649 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5650 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5651 ok(!lstrcmpA(buf
, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf
);
5653 MsiCloseHandle(hrec
);
5655 r
= MsiViewFetch(hview
, &hrec
);
5656 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5658 MsiViewClose(hview
);
5659 MsiCloseHandle(hview
);
5661 query
= "SELECT * FROM `_Columns`";
5662 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5663 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5664 r
= MsiViewExecute(hview
, 0);
5665 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5667 r
= MsiViewFetch(hview
, &hrec
);
5668 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5671 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5672 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5673 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
5675 r
= MsiRecordGetInteger(hrec
, 2);
5676 ok(r
== 1, "Expected 1, got %d\n", r
);
5679 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
5680 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5681 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
5683 MsiCloseHandle(hrec
);
5685 r
= MsiViewFetch(hview
, &hrec
);
5686 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5689 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5690 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5691 ok(!lstrcmpA(buf
, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf
);
5693 r
= MsiRecordGetInteger(hrec
, 2);
5694 ok(r
== 1, "Expected 1, got %d\n", r
);
5697 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
5698 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5699 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
5701 MsiCloseHandle(hrec
);
5703 r
= MsiViewFetch(hview
, &hrec
);
5704 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5707 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5708 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5709 ok(!lstrcmpA(buf
, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf
);
5711 r
= MsiRecordGetInteger(hrec
, 2);
5712 ok(r
== 1, "Expected 1, got %d\n", r
);
5715 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
5716 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5717 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
5719 MsiCloseHandle(hrec
);
5721 r
= MsiViewFetch(hview
, &hrec
);
5722 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5724 MsiViewClose(hview
);
5725 MsiCloseHandle(hview
);
5727 query
= "INSERT INTO Table ( `A` ) VALUES ( 'hi' )";
5728 r
= run_query(hdb
, 0, query
);
5729 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5731 query
= "INSERT INTO `Table` ( A ) VALUES ( 'hi' )";
5732 r
= run_query(hdb
, 0, query
);
5733 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5735 query
= "INSERT INTO `Table` ( `A` ) VALUES ( hi )";
5736 r
= run_query(hdb
, 0, query
);
5737 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5739 query
= "SELECT * FROM Table WHERE `A` = 'hi'";
5740 r
= run_query(hdb
, 0, query
);
5741 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5743 query
= "SELECT * FROM `Table` WHERE `A` = hi";
5744 r
= run_query(hdb
, 0, query
);
5745 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5747 query
= "SELECT * FROM Table";
5748 r
= run_query(hdb
, 0, query
);
5749 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5751 query
= "SELECT * FROM Table2";
5752 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5753 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5754 r
= MsiViewExecute(hview
, 0);
5755 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5757 r
= MsiViewFetch(hview
, &hrec
);
5758 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5760 MsiViewClose(hview
);
5761 MsiCloseHandle(hview
);
5763 query
= "SELECT * FROM `Table` WHERE A = 'hi'";
5764 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5765 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5766 r
= MsiViewExecute(hview
, 0);
5767 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5769 r
= MsiViewFetch(hview
, &hrec
);
5770 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5773 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5774 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5775 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
5777 MsiCloseHandle(hrec
);
5779 r
= MsiViewFetch(hview
, &hrec
);
5780 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5782 MsiViewClose(hview
);
5783 MsiCloseHandle(hview
);
5786 MsiCloseHandle(hdb
);
5787 DeleteFileA(msifile
);
5790 static void read_file_data(LPCSTR filename
, LPSTR buffer
)
5796 file
= OpenFile(filename
, &ofs
, OF_READ
);
5797 ZeroMemory(buffer
, MAX_PATH
);
5798 ReadFile((HANDLE
)file
, buffer
, MAX_PATH
, &read
, NULL
);
5799 CloseHandle((HANDLE
)file
);
5802 static void test_forcecodepage(void)
5806 char buffer
[MAX_PATH
];
5809 DeleteFile(msifile
);
5811 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5812 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5814 query
= "SELECT * FROM `_ForceCodepage`";
5815 r
= run_query(hdb
, 0, query
);
5816 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5818 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5819 r
= run_query(hdb
, 0, query
);
5820 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5822 query
= "SELECT * FROM `_ForceCodepage`";
5823 r
= run_query(hdb
, 0, query
);
5824 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5826 r
= MsiDatabaseCommit(hdb
);
5827 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5829 query
= "SELECT * FROM `_ForceCodepage`";
5830 r
= run_query(hdb
, 0, query
);
5831 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5833 MsiCloseHandle(hdb
);
5835 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_DIRECT
, &hdb
);
5836 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5838 query
= "SELECT * FROM `_ForceCodepage`";
5839 r
= run_query(hdb
, 0, query
);
5840 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5842 r
= MsiDatabaseExport(hdb
, "_ForceCodepage", CURR_DIR
, "forcecodepage.idt");
5843 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5845 read_file_data("forcecodepage.idt", buffer
);
5846 ok(!lstrcmpA(buffer
, "\r\n\r\n0\t_ForceCodepage\r\n"),
5847 "Expected \"\r\n\r\n0\t_ForceCodepage\r\n\", got \"%s\"", buffer
);
5849 MsiCloseHandle(hdb
);
5850 DeleteFileA(msifile
);
5851 DeleteFileA("forcecodepage.idt");
5854 static void test_viewmodify_refresh(void)
5856 MSIHANDLE hdb
, hview
, hrec
;
5858 char buffer
[MAX_PATH
];
5862 DeleteFile(msifile
);
5864 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5865 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5867 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL, `B` INT PRIMARY KEY `A` )";
5868 r
= run_query(hdb
, 0, query
);
5869 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5871 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hi', 1 )";
5872 r
= run_query(hdb
, 0, query
);
5873 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5875 query
= "SELECT * FROM `Table`";
5876 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5877 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5878 r
= MsiViewExecute(hview
, 0);
5879 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5881 r
= MsiViewFetch(hview
, &hrec
);
5882 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5884 query
= "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hi'";
5885 r
= run_query(hdb
, 0, query
);
5886 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5888 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
5889 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5892 r
= MsiRecordGetStringA(hrec
, 1, buffer
, &size
);
5893 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5894 ok(!lstrcmpA(buffer
, "hi"), "Expected \"hi\", got \"%s\"\n", buffer
);
5895 ok(size
== 2, "Expected 2, got %d\n", size
);
5897 r
= MsiRecordGetInteger(hrec
, 2);
5898 ok(r
== 2, "Expected 2, got %d\n", r
);
5900 MsiCloseHandle(hrec
);
5901 MsiViewClose(hview
);
5902 MsiCloseHandle(hview
);
5904 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hello', 3 )";
5905 r
= run_query(hdb
, 0, query
);
5906 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5908 query
= "SELECT * FROM `Table` WHERE `B` = 3";
5909 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5910 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5911 r
= MsiViewExecute(hview
, 0);
5912 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5914 r
= MsiViewFetch(hview
, &hrec
);
5915 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5917 query
= "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hello'";
5918 r
= run_query(hdb
, 0, query
);
5919 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5921 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hithere', 3 )";
5922 r
= run_query(hdb
, 0, query
);
5923 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5925 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
5926 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5929 r
= MsiRecordGetStringA(hrec
, 1, buffer
, &size
);
5930 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5931 ok(!lstrcmpA(buffer
, "hello"), "Expected \"hello\", got \"%s\"\n", buffer
);
5932 ok(size
== 5, "Expected 5, got %d\n", size
);
5934 r
= MsiRecordGetInteger(hrec
, 2);
5935 ok(r
== 2, "Expected 2, got %d\n", r
);
5937 MsiCloseHandle(hrec
);
5938 MsiViewClose(hview
);
5939 MsiCloseHandle(hview
);
5940 MsiCloseHandle(hdb
);
5941 DeleteFileA(msifile
);
5944 static void test_where_viewmodify(void)
5946 MSIHANDLE hdb
, hview
, hrec
;
5950 DeleteFile(msifile
);
5952 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5953 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5955 query
= "CREATE TABLE `Table` ( `A` INT, `B` INT PRIMARY KEY `A` )";
5956 r
= run_query(hdb
, 0, query
);
5957 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5959 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 1, 2 )";
5960 r
= run_query(hdb
, 0, query
);
5961 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5963 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 3, 4 )";
5964 r
= run_query(hdb
, 0, query
);
5965 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5967 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 5, 6 )";
5968 r
= run_query(hdb
, 0, query
);
5969 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5971 /* `B` = 3 doesn't match, but the view shouldn't be executed */
5972 query
= "SELECT * FROM `Table` WHERE `B` = 3";
5973 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5974 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5976 hrec
= MsiCreateRecord(2);
5977 MsiRecordSetInteger(hrec
, 1, 7);
5978 MsiRecordSetInteger(hrec
, 2, 8);
5980 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
5981 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5983 MsiCloseHandle(hrec
);
5984 MsiViewClose(hview
);
5985 MsiCloseHandle(hview
);
5987 query
= "SELECT * FROM `Table` WHERE `A` = 7";
5988 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5989 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5990 r
= MsiViewExecute(hview
, 0);
5991 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5993 r
= MsiViewFetch(hview
, &hrec
);
5994 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5996 r
= MsiRecordGetInteger(hrec
, 1);
5997 ok(r
== 7, "Expected 7, got %d\n", r
);
5999 r
= MsiRecordGetInteger(hrec
, 2);
6000 ok(r
== 8, "Expected 8, got %d\n", r
);
6002 MsiRecordSetInteger(hrec
, 2, 9);
6004 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
6005 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6007 MsiCloseHandle(hrec
);
6008 MsiViewClose(hview
);
6009 MsiCloseHandle(hview
);
6011 query
= "SELECT * FROM `Table` WHERE `A` = 7";
6012 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6013 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6014 r
= MsiViewExecute(hview
, 0);
6015 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6017 r
= MsiViewFetch(hview
, &hrec
);
6018 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6020 r
= MsiRecordGetInteger(hrec
, 1);
6021 ok(r
== 7, "Expected 7, got %d\n", r
);
6023 r
= MsiRecordGetInteger(hrec
, 2);
6024 ok(r
== 9, "Expected 9, got %d\n", r
);
6026 query
= "UPDATE `Table` SET `B` = 10 WHERE `A` = 7";
6027 r
= run_query(hdb
, 0, query
);
6028 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6030 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
6031 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6033 r
= MsiRecordGetInteger(hrec
, 1);
6034 ok(r
== 7, "Expected 7, got %d\n", r
);
6036 r
= MsiRecordGetInteger(hrec
, 2);
6037 ok(r
== 10, "Expected 10, got %d\n", r
);
6039 MsiCloseHandle(hrec
);
6040 MsiViewClose(hview
);
6041 MsiCloseHandle(hview
);
6042 MsiCloseHandle(hdb
);
6045 static BOOL
create_storage(LPCSTR name
)
6047 WCHAR nameW
[MAX_PATH
];
6054 MultiByteToWideChar(CP_ACP
, 0, name
, -1, nameW
, MAX_PATH
);
6055 hr
= StgCreateDocfile(nameW
, STGM_CREATE
| STGM_READWRITE
|
6056 STGM_DIRECT
| STGM_SHARE_EXCLUSIVE
, 0, &stg
);
6060 hr
= IStorage_CreateStream(stg
, nameW
, STGM_WRITE
| STGM_SHARE_EXCLUSIVE
,
6065 hr
= IStream_Write(stm
, "stgdata", 8, &count
);
6070 IStream_Release(stm
);
6071 IStorage_Release(stg
);
6076 static void test_storages_table(void)
6078 MSIHANDLE hdb
, hview
, hrec
;
6079 IStorage
*stg
, *inner
;
6081 char file
[MAX_PATH
];
6083 WCHAR name
[MAX_PATH
];
6090 ok(hdb
, "failed to create db\n");
6092 r
= MsiDatabaseCommit(hdb
);
6093 ok(r
== ERROR_SUCCESS
, "Failed to commit database\n");
6095 MsiCloseHandle(hdb
);
6097 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
6098 ok(r
== ERROR_SUCCESS
, "Failed to open database\n");
6100 /* check the column types */
6101 hrec
= get_column_info(hdb
, "SELECT * FROM `_Storages`", MSICOLINFO_TYPES
);
6102 ok(hrec
, "failed to get column info hrecord\n");
6103 ok(check_record(hrec
, 1, "s62"), "wrong hrecord type\n");
6104 ok(check_record(hrec
, 2, "V0"), "wrong hrecord type\n");
6106 MsiCloseHandle(hrec
);
6108 /* now try the names */
6109 hrec
= get_column_info(hdb
, "SELECT * FROM `_Storages`", MSICOLINFO_NAMES
);
6110 ok(hrec
, "failed to get column info hrecord\n");
6111 ok(check_record(hrec
, 1, "Name"), "wrong hrecord type\n");
6112 ok(check_record(hrec
, 2, "Data"), "wrong hrecord type\n");
6114 MsiCloseHandle(hrec
);
6116 create_storage("storage.bin");
6118 hrec
= MsiCreateRecord(2);
6119 MsiRecordSetString(hrec
, 1, "stgname");
6121 r
= MsiRecordSetStream(hrec
, 2, "storage.bin");
6122 ok(r
== ERROR_SUCCESS
, "Failed to add stream data to the hrecord: %d\n", r
);
6124 DeleteFileA("storage.bin");
6126 query
= "INSERT INTO `_Storages` (`Name`, `Data`) VALUES (?, ?)";
6127 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6128 ok(r
== ERROR_SUCCESS
, "Failed to open database hview: %d\n", r
);
6130 r
= MsiViewExecute(hview
, hrec
);
6131 ok(r
== ERROR_SUCCESS
, "Failed to execute hview: %d\n", r
);
6133 MsiCloseHandle(hrec
);
6134 MsiViewClose(hview
);
6135 MsiCloseHandle(hview
);
6137 query
= "SELECT `Name`, `Data` FROM `_Storages`";
6138 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
6139 ok(r
== ERROR_SUCCESS
, "Failed to open database hview: %d\n", r
);
6141 r
= MsiViewExecute(hview
, 0);
6142 ok(r
== ERROR_SUCCESS
, "Failed to execute hview: %d\n", r
);
6144 r
= MsiViewFetch(hview
, &hrec
);
6145 ok(r
== ERROR_SUCCESS
, "Failed to fetch hrecord: %d\n", r
);
6148 r
= MsiRecordGetString(hrec
, 1, file
, &size
);
6149 ok(r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
6150 ok(!lstrcmp(file
, "stgname"), "Expected \"stgname\", got \"%s\"\n", file
);
6153 lstrcpyA(buf
, "apple");
6154 r
= MsiRecordReadStream(hrec
, 2, buf
, &size
);
6155 ok(!lstrcmp(buf
, "apple"), "Expected buf to be unchanged, got %s\n", buf
);
6158 ok(r
== ERROR_INVALID_DATA
, "Expected ERROR_INVALID_DATA, got %d\n", r
);
6159 ok(size
== 0, "Expected 0, got %d\n", size
);
6162 MsiCloseHandle(hrec
);
6164 r
= MsiViewFetch(hview
, &hrec
);
6165 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6167 MsiViewClose(hview
);
6168 MsiCloseHandle(hview
);
6170 MsiDatabaseCommit(hdb
);
6171 MsiCloseHandle(hdb
);
6173 MultiByteToWideChar(CP_ACP
, 0, msifile
, -1, name
, MAX_PATH
);
6174 hr
= StgOpenStorage(name
, NULL
, STGM_DIRECT
| STGM_READ
|
6175 STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
6176 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
6177 ok(stg
!= NULL
, "Expected non-NULL storage\n");
6179 MultiByteToWideChar(CP_ACP
, 0, "stgname", -1, name
, MAX_PATH
);
6180 hr
= IStorage_OpenStorage(stg
, name
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
,
6182 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
6183 ok(inner
!= NULL
, "Expected non-NULL storage\n");
6185 MultiByteToWideChar(CP_ACP
, 0, "storage.bin", -1, name
, MAX_PATH
);
6186 hr
= IStorage_OpenStream(inner
, name
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
6187 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
6188 ok(stm
!= NULL
, "Expected non-NULL stream\n");
6190 hr
= IStream_Read(stm
, buf
, MAX_PATH
, &size
);
6191 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
6192 ok(size
== 8, "Expected 8, got %d\n", size
);
6193 ok(!lstrcmpA(buf
, "stgdata"), "Expected \"stgdata\", got \"%s\"\n", buf
);
6195 IStream_Release(stm
);
6196 IStorage_Release(inner
);
6198 IStorage_Release(stg
);
6199 DeleteFileA(msifile
);
6202 static void test_dbtopackage(void)
6204 MSIHANDLE hdb
, hpkg
;
6210 /* create an empty database, transact mode */
6211 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6212 ok(r
== ERROR_SUCCESS
, "Failed to create database\n");
6214 set_summary_info(hdb
);
6216 r
= create_directory_table(hdb
);
6217 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6219 r
= create_custom_action_table(hdb
);
6220 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6222 r
= add_custom_action_entry(hdb
, "'SetProp', 51, 'MYPROP', 'grape'");
6223 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6225 sprintf(package
, "#%li", hdb
);
6226 r
= MsiOpenPackage(package
, &hpkg
);
6227 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6229 /* property is not set yet */
6231 lstrcpyA(buf
, "kiwi");
6232 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6233 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6234 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
6235 ok(size
== 0, "Expected 0, got %d\n", size
);
6237 /* run the custom action to set the property */
6238 r
= MsiDoAction(hpkg
, "SetProp");
6239 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6241 /* property is now set */
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
, "grape"), "Expected \"grape\", got \"%s\"\n", buf
);
6247 ok(size
== 5, "Expected 5, got %d\n", size
);
6249 MsiCloseHandle(hpkg
);
6251 /* reset the package */
6252 r
= MsiOpenPackage(package
, &hpkg
);
6253 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6255 /* property is not set anymore */
6257 lstrcpyA(buf
, "kiwi");
6258 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6259 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6262 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
6263 ok(size
== 0, "Expected 0, got %d\n", size
);
6266 MsiCloseHandle(hdb
);
6267 MsiCloseHandle(hpkg
);
6269 /* create an empty database, direct mode */
6270 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATEDIRECT
, &hdb
);
6271 ok(r
== ERROR_SUCCESS
, "Failed to create database\n");
6273 set_summary_info(hdb
);
6275 r
= create_directory_table(hdb
);
6276 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6278 r
= create_custom_action_table(hdb
);
6279 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6281 r
= add_custom_action_entry(hdb
, "'SetProp', 51, 'MYPROP', 'grape'");
6282 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6284 sprintf(package
, "#%li", hdb
);
6285 r
= MsiOpenPackage(package
, &hpkg
);
6286 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6288 /* property is not set yet */
6290 lstrcpyA(buf
, "kiwi");
6291 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6292 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6293 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
6294 ok(size
== 0, "Expected 0, got %d\n", size
);
6296 /* run the custom action to set the property */
6297 r
= MsiDoAction(hpkg
, "SetProp");
6298 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6300 /* property is now set */
6302 lstrcpyA(buf
, "kiwi");
6303 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6304 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6305 ok(!lstrcmpA(buf
, "grape"), "Expected \"grape\", got \"%s\"\n", buf
);
6306 ok(size
== 5, "Expected 5, got %d\n", size
);
6308 MsiCloseHandle(hpkg
);
6310 /* reset the package */
6311 r
= MsiOpenPackage(package
, &hpkg
);
6312 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6314 /* property is not set anymore */
6316 lstrcpyA(buf
, "kiwi");
6317 r
= MsiGetProperty(hpkg
, "MYPROP", buf
, &size
);
6318 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6321 ok(!lstrcmpA(buf
, ""), "Expected \"\", got \"%s\"\n", buf
);
6322 ok(size
== 0, "Expected 0, got %d\n", size
);
6325 MsiCloseHandle(hdb
);
6326 MsiCloseHandle(hpkg
);
6327 DeleteFileA(msifile
);
6330 static void test_droptable(void)
6332 MSIHANDLE hdb
, hview
, hrec
;
6338 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6339 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6341 query
= "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
6342 r
= run_query(hdb
, 0, query
);
6343 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6345 query
= "SELECT * FROM `One`";
6346 r
= do_query(hdb
, query
, &hrec
);
6347 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6349 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
6350 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6351 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6352 r
= MsiViewExecute(hview
, 0);
6353 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6355 r
= MsiViewFetch(hview
, &hrec
);
6356 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6359 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6360 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6361 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6363 MsiCloseHandle(hrec
);
6364 MsiViewClose(hview
);
6365 MsiCloseHandle(hview
);
6367 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
6368 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6369 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6370 r
= MsiViewExecute(hview
, 0);
6371 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6373 r
= MsiViewFetch(hview
, &hrec
);
6374 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6377 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6378 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6379 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6381 r
= MsiRecordGetInteger(hrec
, 2);
6382 ok(r
== 1, "Expected 1, got %d\n", r
);
6385 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6386 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6387 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
6389 MsiCloseHandle(hrec
);
6391 r
= MsiViewFetch(hview
, &hrec
);
6392 ok(r
== ERROR_NO_MORE_ITEMS
,
6393 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6395 MsiViewClose(hview
);
6396 MsiCloseHandle(hview
);
6398 query
= "DROP `One`";
6399 r
= run_query(hdb
, 0, query
);
6400 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6401 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6403 query
= "DROP TABLE";
6404 r
= run_query(hdb
, 0, query
);
6405 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6406 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6408 query
= "DROP TABLE `One`";
6410 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6411 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6412 r
= MsiViewExecute(hview
, 0);
6413 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6415 r
= MsiViewFetch(hview
, &hrec
);
6416 ok(r
== ERROR_FUNCTION_FAILED
,
6417 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
6419 MsiViewClose(hview
);
6420 MsiCloseHandle(hview
);
6422 query
= "SELECT * FROM `IDontExist`";
6423 r
= do_query(hdb
, query
, &hrec
);
6424 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6425 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6427 query
= "SELECT * FROM `One`";
6428 r
= do_query(hdb
, query
, &hrec
);
6429 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6430 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6432 query
= "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
6433 r
= run_query(hdb
, 0, query
);
6434 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6436 query
= "DROP TABLE One";
6437 r
= run_query(hdb
, 0, query
);
6438 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6440 query
= "SELECT * FROM `One`";
6441 r
= do_query(hdb
, query
, &hrec
);
6442 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6443 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6445 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
6446 r
= do_query(hdb
, query
, &hrec
);
6447 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6449 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
6450 r
= do_query(hdb
, query
, &hrec
);
6451 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6453 query
= "CREATE TABLE `One` ( `B` INT, `C` INT PRIMARY KEY `B` )";
6454 r
= run_query(hdb
, 0, query
);
6455 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6457 query
= "SELECT * FROM `One`";
6458 r
= do_query(hdb
, query
, &hrec
);
6459 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6461 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
6462 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6463 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6464 r
= MsiViewExecute(hview
, 0);
6465 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6467 r
= MsiViewFetch(hview
, &hrec
);
6468 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6471 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6472 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6473 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6475 MsiCloseHandle(hrec
);
6476 MsiViewClose(hview
);
6477 MsiCloseHandle(hview
);
6479 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
6480 r
= MsiDatabaseOpenViewA(hdb
, query
, &hview
);
6481 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6482 r
= MsiViewExecute(hview
, 0);
6483 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6485 r
= MsiViewFetch(hview
, &hrec
);
6486 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6489 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6490 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6491 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6493 r
= MsiRecordGetInteger(hrec
, 2);
6494 ok(r
== 1, "Expected 1, got %d\n", r
);
6497 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6498 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6499 ok(!lstrcmpA(buf
, "B"), "Expected \"B\", got \"%s\"\n", buf
);
6501 MsiCloseHandle(hrec
);
6503 r
= MsiViewFetch(hview
, &hrec
);
6504 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6507 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6508 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6509 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6511 r
= MsiRecordGetInteger(hrec
, 2);
6512 ok(r
== 2, "Expected 2, got %d\n", r
);
6515 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
6516 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6517 ok(!lstrcmpA(buf
, "C"), "Expected \"C\", got \"%s\"\n", buf
);
6519 MsiCloseHandle(hrec
);
6521 r
= MsiViewFetch(hview
, &hrec
);
6522 ok(r
== ERROR_NO_MORE_ITEMS
,
6523 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6525 MsiViewClose(hview
);
6526 MsiCloseHandle(hview
);
6528 query
= "DROP TABLE One";
6529 r
= run_query(hdb
, 0, query
);
6530 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6532 query
= "SELECT * FROM `One`";
6533 r
= do_query(hdb
, query
, &hrec
);
6534 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6535 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6537 query
= "SELECT * FROM `_Tables` WHERE `Name` = 'One'";
6538 r
= do_query(hdb
, query
, &hrec
);
6539 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6541 query
= "SELECT * FROM `_Columns` WHERE `Table` = 'One'";
6542 r
= do_query(hdb
, query
, &hrec
);
6543 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
6545 MsiCloseHandle(hdb
);
6546 DeleteFileA(msifile
);
6549 static void test_dbmerge(void)
6551 MSIHANDLE hdb
, href
, hview
, hrec
;
6557 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
6558 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6560 r
= MsiOpenDatabase("refdb.msi", MSIDBOPEN_CREATE
, &href
);
6561 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6563 /* hDatabase is invalid */
6564 r
= MsiDatabaseMergeA(0, href
, "MergeErrors");
6565 ok(r
== ERROR_INVALID_HANDLE
,
6566 "Expected ERROR_INVALID_HANDLE, got %d\n", r
);
6568 /* hDatabaseMerge is invalid */
6569 r
= MsiDatabaseMergeA(hdb
, 0, "MergeErrors");
6570 ok(r
== ERROR_INVALID_HANDLE
,
6571 "Expected ERROR_INVALID_HANDLE, got %d\n", r
);
6573 /* szTableName is NULL */
6574 r
= MsiDatabaseMergeA(hdb
, href
, NULL
);
6575 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6577 /* szTableName is empty */
6578 r
= MsiDatabaseMergeA(hdb
, href
, "");
6579 ok(r
== ERROR_INVALID_TABLE
, "Expected ERROR_INVALID_TABLE, got %d\n", r
);
6581 /* both DBs empty, szTableName is valid */
6582 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6583 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6585 query
= "CREATE TABLE `One` ( `A` INT PRIMARY KEY `A` )";
6586 r
= run_query(hdb
, 0, query
);
6587 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6589 query
= "CREATE TABLE `One` ( `A` CHAR(72) PRIMARY KEY `A` )";
6590 r
= run_query(href
, 0, query
);
6591 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6593 /* column types don't match */
6594 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6595 ok(r
== ERROR_DATATYPE_MISMATCH
,
6596 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
6598 /* nothing in MergeErrors */
6599 query
= "SELECT * FROM `MergeErrors`";
6600 r
= do_query(hdb
, query
, &hrec
);
6601 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6602 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6604 query
= "DROP TABLE `One`";
6605 r
= run_query(hdb
, 0, query
);
6606 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6608 query
= "DROP TABLE `One`";
6609 r
= run_query(href
, 0, query
);
6610 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6612 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6613 r
= run_query(hdb
, 0, query
);
6614 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6616 query
= "CREATE TABLE `One` ( `A` INT, `C` INT PRIMARY KEY `A` )";
6617 r
= run_query(href
, 0, query
);
6618 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6620 /* column names don't match */
6621 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6622 ok(r
== ERROR_DATATYPE_MISMATCH
,
6623 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
6625 /* nothing in MergeErrors */
6626 query
= "SELECT * FROM `MergeErrors`";
6627 r
= do_query(hdb
, query
, &hrec
);
6628 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6629 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6631 query
= "DROP TABLE `One`";
6632 r
= run_query(hdb
, 0, query
);
6633 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6635 query
= "DROP TABLE `One`";
6636 r
= run_query(href
, 0, query
);
6637 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6639 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6640 r
= run_query(hdb
, 0, query
);
6641 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6643 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `B` )";
6644 r
= run_query(href
, 0, query
);
6645 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6647 /* primary keys don't match */
6648 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6649 ok(r
== ERROR_DATATYPE_MISMATCH
,
6650 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
6652 /* nothing in MergeErrors */
6653 query
= "SELECT * FROM `MergeErrors`";
6654 r
= do_query(hdb
, query
, &hrec
);
6655 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6656 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6658 query
= "DROP TABLE `One`";
6659 r
= run_query(hdb
, 0, query
);
6660 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6662 query
= "DROP TABLE `One`";
6663 r
= run_query(href
, 0, query
);
6664 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6666 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6667 r
= run_query(hdb
, 0, query
);
6668 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6670 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A`, `B` )";
6671 r
= run_query(href
, 0, query
);
6672 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6674 /* number of primary keys doesn't match */
6675 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6676 ok(r
== ERROR_DATATYPE_MISMATCH
,
6677 "Expected ERROR_DATATYPE_MISMATCH, got %d\n", r
);
6679 /* nothing in MergeErrors */
6680 query
= "SELECT * FROM `MergeErrors`";
6681 r
= do_query(hdb
, query
, &hrec
);
6682 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6683 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6685 query
= "DROP TABLE `One`";
6686 r
= run_query(hdb
, 0, query
);
6687 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6689 query
= "DROP TABLE `One`";
6690 r
= run_query(href
, 0, query
);
6691 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6693 query
= "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
6694 r
= run_query(hdb
, 0, query
);
6695 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6697 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6698 r
= run_query(href
, 0, query
);
6699 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6701 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
6702 r
= run_query(href
, 0, query
);
6703 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6705 /* number of columns doesn't match */
6706 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6707 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6709 query
= "SELECT * FROM `One`";
6710 r
= do_query(hdb
, query
, &hrec
);
6711 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6713 r
= MsiRecordGetInteger(hrec
, 1);
6714 ok(r
== 1, "Expected 1, got %d\n", r
);
6716 r
= MsiRecordGetInteger(hrec
, 2);
6717 ok(r
== 2, "Expected 2, got %d\n", r
);
6719 r
= MsiRecordGetInteger(hrec
, 3);
6720 ok(r
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", r
);
6722 MsiCloseHandle(hrec
);
6724 /* nothing in MergeErrors */
6725 query
= "SELECT * FROM `MergeErrors`";
6726 r
= do_query(hdb
, query
, &hrec
);
6727 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6728 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6730 query
= "DROP TABLE `One`";
6731 r
= run_query(hdb
, 0, query
);
6732 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6734 query
= "DROP TABLE `One`";
6735 r
= run_query(href
, 0, query
);
6736 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6738 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6739 r
= run_query(hdb
, 0, query
);
6740 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6742 query
= "CREATE TABLE `One` ( `A` INT, `B` INT, `C` INT PRIMARY KEY `A` )";
6743 r
= run_query(href
, 0, query
);
6744 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6746 query
= "INSERT INTO `One` ( `A`, `B`, `C` ) VALUES ( 1, 2, 3 )";
6747 r
= run_query(href
, 0, query
);
6748 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6750 /* number of columns doesn't match */
6751 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6752 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6754 query
= "SELECT * FROM `One`";
6755 r
= do_query(hdb
, query
, &hrec
);
6756 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6758 r
= MsiRecordGetInteger(hrec
, 1);
6759 ok(r
== 1, "Expected 1, got %d\n", r
);
6761 r
= MsiRecordGetInteger(hrec
, 2);
6762 ok(r
== 2, "Expected 2, got %d\n", r
);
6764 r
= MsiRecordGetInteger(hrec
, 3);
6765 ok(r
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", r
);
6767 MsiCloseHandle(hrec
);
6769 /* nothing in MergeErrors */
6770 query
= "SELECT * FROM `MergeErrors`";
6771 r
= do_query(hdb
, query
, &hrec
);
6772 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6773 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6775 query
= "DROP TABLE `One`";
6776 r
= run_query(hdb
, 0, query
);
6777 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6779 query
= "DROP TABLE `One`";
6780 r
= run_query(href
, 0, query
);
6781 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6783 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6784 r
= run_query(hdb
, 0, query
);
6785 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6787 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 1 )";
6788 r
= run_query(hdb
, 0, query
);
6789 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6791 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 2 )";
6792 r
= run_query(hdb
, 0, query
);
6793 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6795 query
= "CREATE TABLE `One` ( `A` INT, `B` INT PRIMARY KEY `A` )";
6796 r
= run_query(href
, 0, query
);
6797 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6799 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 2 )";
6800 r
= run_query(href
, 0, query
);
6801 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6803 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 2, 3 )";
6804 r
= run_query(href
, 0, query
);
6805 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6807 /* primary keys match, rows do not */
6808 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6809 ok(r
== ERROR_FUNCTION_FAILED
,
6810 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
6812 /* nothing in MergeErrors */
6813 query
= "SELECT * FROM `MergeErrors`";
6814 r
= do_query(hdb
, query
, &hrec
);
6815 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6818 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
6819 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6820 ok(!lstrcmpA(buf
, "One"), "Expected \"One\", got \"%s\"\n", buf
);
6822 r
= MsiRecordGetInteger(hrec
, 2);
6823 ok(r
== 2, "Expected 2, got %d\n", r
);
6825 MsiCloseHandle(hrec
);
6827 r
= MsiDatabaseOpenViewA(hdb
, "SELECT * FROM `MergeErrors`", &hview
);
6828 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6830 r
= MsiViewGetColumnInfo(hview
, MSICOLINFO_NAMES
, &hrec
);
6831 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6834 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
6835 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
6838 r
= MsiRecordGetString(hrec
, 2, buf
, &size
);
6839 ok(!lstrcmpA(buf
, "NumRowMergeConflicts"),
6840 "Expected \"NumRowMergeConflicts\", got \"%s\"\n", buf
);
6842 MsiCloseHandle(hrec
);
6844 r
= MsiViewGetColumnInfo(hview
, MSICOLINFO_TYPES
, &hrec
);
6845 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6848 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
6849 ok(!lstrcmpA(buf
, "s255"), "Expected \"s255\", got \"%s\"\n", buf
);
6852 r
= MsiRecordGetString(hrec
, 2, buf
, &size
);
6853 ok(!lstrcmpA(buf
, "i2"), "Expected \"i2\", got \"%s\"\n", buf
);
6855 MsiCloseHandle(hrec
);
6856 MsiViewClose(hview
);
6857 MsiCloseHandle(hview
);
6859 query
= "DROP TABLE `MergeErrors`";
6860 r
= run_query(hdb
, 0, query
);
6861 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6863 create_file_data("codepage.idt", "\r\n\r\n850\t_ForceCodepage\r\n", 0);
6865 GetCurrentDirectoryA(MAX_PATH
, buf
);
6866 r
= MsiDatabaseImportA(hdb
, buf
, "codepage.idt");
6869 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6872 query
= "DROP TABLE `One`";
6873 r
= run_query(hdb
, 0, query
);
6874 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6876 query
= "DROP TABLE `One`";
6877 r
= run_query(href
, 0, query
);
6878 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6880 query
= "CREATE TABLE `One` ( "
6881 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
6882 r
= run_query(hdb
, 0, query
);
6883 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6885 query
= "CREATE TABLE `One` ( "
6886 "`A` INT, `B` CHAR(72) LOCALIZABLE PRIMARY KEY `A` )";
6887 r
= run_query(href
, 0, query
);
6888 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6890 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, 'hi' )";
6891 r
= run_query(href
, 0, query
);
6892 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6894 /* code page does not match */
6895 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6896 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6898 query
= "SELECT * FROM `One`";
6899 r
= do_query(hdb
, query
, &hrec
);
6900 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6902 r
= MsiRecordGetInteger(hrec
, 1);
6903 ok(r
== 1, "Expected 1, got %d\n", r
);
6906 r
= MsiRecordGetStringA(hrec
, 2, buf
, &size
);
6907 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6908 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
6910 MsiCloseHandle(hrec
);
6912 /* nothing in MergeErrors */
6913 query
= "SELECT * FROM `MergeErrors`";
6914 r
= do_query(hdb
, query
, &hrec
);
6915 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6916 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6918 query
= "DROP TABLE `One`";
6919 r
= run_query(hdb
, 0, query
);
6920 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6922 query
= "DROP TABLE `One`";
6923 r
= run_query(href
, 0, query
);
6924 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6926 query
= "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
6927 r
= run_query(hdb
, 0, query
);
6928 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6930 query
= "CREATE TABLE `One` ( `A` INT, `B` OBJECT PRIMARY KEY `A` )";
6931 r
= run_query(href
, 0, query
);
6932 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6934 create_file("binary.dat");
6935 hrec
= MsiCreateRecord(1);
6936 MsiRecordSetStreamA(hrec
, 1, "binary.dat");
6938 query
= "INSERT INTO `One` ( `A`, `B` ) VALUES ( 1, ? )";
6939 r
= run_query(href
, hrec
, query
);
6940 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6942 MsiCloseHandle(hrec
);
6944 /* binary data to merge */
6945 r
= MsiDatabaseMergeA(hdb
, href
, "MergeErrors");
6946 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6948 query
= "SELECT * FROM `One`";
6949 r
= do_query(hdb
, query
, &hrec
);
6950 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6952 r
= MsiRecordGetInteger(hrec
, 1);
6953 ok(r
== 1, "Expected 1, got %d\n", r
);
6956 ZeroMemory(buf
, MAX_PATH
);
6957 r
= MsiRecordReadStream(hrec
, 2, buf
, &size
);
6960 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
6961 ok(!lstrcmpA(buf
, "binary.dat\n"),
6962 "Expected \"binary.dat\\n\", got \"%s\"\n", buf
);
6965 MsiCloseHandle(hrec
);
6967 /* nothing in MergeErrors */
6968 query
= "SELECT * FROM `MergeErrors`";
6969 r
= do_query(hdb
, query
, &hrec
);
6970 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
6971 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
6973 MsiCloseHandle(hdb
);
6974 MsiCloseHandle(href
);
6975 DeleteFileA(msifile
);
6976 DeleteFileA("refdb.msi");
6977 DeleteFileA("codepage.idt");
6978 DeleteFileA("binary.dat");
6985 test_msidecomposedesc();
6986 test_msibadqueries();
6988 test_viewgetcolumninfo();
6996 test_handle_limit();
6997 test_try_transform();
6999 test_temporary_table();
7003 test_special_tables();
7004 test_select_markers();
7005 test_viewmodify_update();
7007 test_viewmodify_delete();
7008 test_defaultdatabase();
7010 test_viewmodify_delete_temporary();
7013 test_carriagereturn();
7015 test_forcecodepage();
7016 test_viewmodify_refresh();
7017 test_where_viewmodify();
7018 test_storages_table();