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
)
147 /* open a select query */
148 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
149 if (r
!= ERROR_SUCCESS
)
151 r
= MsiViewExecute(hview
, 0);
152 if (r
!= ERROR_SUCCESS
)
154 ret
= MsiViewFetch(hview
, phrec
);
155 r
= MsiViewClose(hview
);
156 if (r
!= ERROR_SUCCESS
)
158 r
= MsiCloseHandle(hview
);
159 if (r
!= ERROR_SUCCESS
)
164 static UINT
run_query( MSIHANDLE hdb
, MSIHANDLE hrec
, const char *query
)
169 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
170 if( r
!= ERROR_SUCCESS
)
173 r
= MsiViewExecute(hview
, hrec
);
174 if( r
== ERROR_SUCCESS
)
175 r
= MsiViewClose(hview
);
176 MsiCloseHandle(hview
);
180 static UINT
create_component_table( MSIHANDLE hdb
)
182 return run_query( hdb
, 0,
183 "CREATE TABLE `Component` ( "
184 "`Component` CHAR(72) NOT NULL, "
185 "`ComponentId` CHAR(38), "
186 "`Directory_` CHAR(72) NOT NULL, "
187 "`Attributes` SHORT NOT NULL, "
188 "`Condition` CHAR(255), "
189 "`KeyPath` CHAR(72) "
190 "PRIMARY KEY `Component`)" );
193 static UINT
create_feature_components_table( MSIHANDLE hdb
)
195 return run_query( hdb
, 0,
196 "CREATE TABLE `FeatureComponents` ( "
197 "`Feature_` CHAR(38) NOT NULL, "
198 "`Component_` CHAR(72) NOT NULL "
199 "PRIMARY KEY `Feature_`, `Component_` )" );
202 static UINT
create_std_dlls_table( MSIHANDLE hdb
)
204 return run_query( hdb
, 0,
205 "CREATE TABLE `StdDlls` ( "
206 "`File` CHAR(255) NOT NULL, "
207 "`Binary_` CHAR(72) NOT NULL "
208 "PRIMARY KEY `File` )" );
211 static UINT
create_binary_table( MSIHANDLE hdb
)
213 return run_query( hdb
, 0,
214 "CREATE TABLE `Binary` ( "
215 "`Name` CHAR(72) NOT NULL, "
216 "`Data` CHAR(72) NOT NULL "
217 "PRIMARY KEY `Name` )" );
220 static UINT
add_component_entry( MSIHANDLE hdb
, const char *values
)
222 char insert
[] = "INSERT INTO `Component` "
223 "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `Condition`, `KeyPath`) "
228 sz
= strlen(values
) + sizeof insert
;
229 query
= HeapAlloc(GetProcessHeap(),0,sz
);
230 sprintf(query
,insert
,values
);
231 r
= run_query( hdb
, 0, query
);
232 HeapFree(GetProcessHeap(), 0, query
);
236 static UINT
add_feature_components_entry( MSIHANDLE hdb
, const char *values
)
238 char insert
[] = "INSERT INTO `FeatureComponents` "
239 "(`Feature_`, `Component_`) "
244 sz
= strlen(values
) + sizeof insert
;
245 query
= HeapAlloc(GetProcessHeap(),0,sz
);
246 sprintf(query
,insert
,values
);
247 r
= run_query( hdb
, 0, query
);
248 HeapFree(GetProcessHeap(), 0, query
);
252 static UINT
add_std_dlls_entry( MSIHANDLE hdb
, const char *values
)
254 char insert
[] = "INSERT INTO `StdDlls` "
255 "(`File`, `Binary_`) "
260 sz
= strlen(values
) + sizeof insert
;
261 query
= HeapAlloc(GetProcessHeap(),0,sz
);
262 sprintf(query
,insert
,values
);
263 r
= run_query( hdb
, 0, query
);
264 HeapFree(GetProcessHeap(), 0, query
);
268 static UINT
add_binary_entry( MSIHANDLE hdb
, const char *values
)
270 char insert
[] = "INSERT INTO `Binary` "
276 sz
= strlen(values
) + sizeof insert
;
277 query
= HeapAlloc(GetProcessHeap(),0,sz
);
278 sprintf(query
,insert
,values
);
279 r
= run_query( hdb
, 0, query
);
280 HeapFree(GetProcessHeap(), 0, query
);
284 static void test_msiinsert(void)
286 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
294 /* just MsiOpenDatabase should not create a file */
295 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
296 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
299 query
= "CREATE TABLE `phone` ( "
300 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
302 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
303 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
304 r
= MsiViewExecute(hview
, 0);
305 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
306 r
= MsiViewClose(hview
);
307 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
308 r
= MsiCloseHandle(hview
);
309 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
311 /* insert a value into it */
312 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
313 "VALUES('1', 'Abe', '8675309')";
314 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
315 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
316 r
= MsiViewExecute(hview
, 0);
317 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
318 r
= MsiViewClose(hview
);
319 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
320 r
= MsiCloseHandle(hview
);
321 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
323 query
= "SELECT * FROM `phone` WHERE `id` = 1";
324 r
= do_query(hdb
, query
, &hrec
);
325 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
327 /* check the record contains what we put in it */
328 r
= MsiRecordGetFieldCount(hrec
);
329 ok(r
== 3, "record count wrong\n");
332 r
= MsiRecordIsNull(hrec
, 0);
333 ok(r
== FALSE
, "field 0 not null\n");
336 r
= MsiRecordGetInteger(hrec
, 1);
337 ok(r
== 1, "field 1 contents wrong\n");
339 r
= MsiRecordGetString(hrec
, 2, buf
, &sz
);
340 ok(r
== ERROR_SUCCESS
, "field 2 content fetch failed\n");
341 ok(!strcmp(buf
,"Abe"), "field 2 content incorrect\n");
343 r
= MsiRecordGetString(hrec
, 3, buf
, &sz
);
344 ok(r
== ERROR_SUCCESS
, "field 3 content fetch failed\n");
345 ok(!strcmp(buf
,"8675309"), "field 3 content incorrect\n");
347 r
= MsiCloseHandle(hrec
);
348 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
350 /* open a select query */
352 query
= "SELECT * FROM `phone` WHERE `id` >= 10";
353 r
= do_query(hdb
, query
, &hrec
);
354 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
355 ok(hrec
== 0, "hrec should be null\n");
357 r
= MsiCloseHandle(hrec
);
358 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
360 query
= "SELECT * FROM `phone` WHERE `id` < 0";
361 r
= do_query(hdb
, query
, &hrec
);
362 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
364 query
= "SELECT * FROM `phone` WHERE `id` <= 0";
365 r
= do_query(hdb
, query
, &hrec
);
366 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
368 query
= "SELECT * FROM `phone` WHERE `id` <> 1";
369 r
= do_query(hdb
, query
, &hrec
);
370 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
372 query
= "SELECT * FROM `phone` WHERE `id` > 10";
373 r
= do_query(hdb
, query
, &hrec
);
374 ok(r
== ERROR_NO_MORE_ITEMS
, "MsiViewFetch failed\n");
376 /* now try a few bad INSERT xqueries */
377 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
379 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
380 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "MsiDatabaseOpenView failed\n");
382 /* construct a record to insert */
383 hrec
= MsiCreateRecord(4);
384 r
= MsiRecordSetInteger(hrec
, 1, 2);
385 ok(r
== ERROR_SUCCESS
, "MsiRecordSetInteger failed\n");
386 r
= MsiRecordSetString(hrec
, 2, "Adam");
387 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
388 r
= MsiRecordSetString(hrec
, 3, "96905305");
389 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
391 /* insert another value, using a record and wildcards */
392 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
394 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
395 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
397 if (r
== ERROR_SUCCESS
)
399 r
= MsiViewExecute(hview
, hrec
);
400 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
401 r
= MsiViewClose(hview
);
402 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
403 r
= MsiCloseHandle(hview
);
404 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
406 r
= MsiCloseHandle(hrec
);
407 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
409 r
= MsiViewFetch(0, NULL
);
410 ok(r
== ERROR_INVALID_PARAMETER
, "MsiViewFetch failed\n");
412 r
= MsiDatabaseCommit(hdb
);
413 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
415 r
= MsiCloseHandle(hdb
);
416 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
418 r
= DeleteFile(msifile
);
419 ok(r
== TRUE
, "file didn't exist after commit\n");
422 typedef UINT (WINAPI
*fnMsiDecomposeDescriptorA
)(LPCSTR
, LPCSTR
, LPSTR
, LPSTR
, DWORD
*);
423 static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA
;
425 static void test_msidecomposedesc(void)
427 char prod
[MAX_FEATURE_CHARS
+1], comp
[MAX_FEATURE_CHARS
+1], feature
[MAX_FEATURE_CHARS
+1];
433 hmod
= GetModuleHandle("msi.dll");
434 pMsiDecomposeDescriptorA
= (fnMsiDecomposeDescriptorA
)
435 GetProcAddress(hmod
, "MsiDecomposeDescriptorA");
436 if (!pMsiDecomposeDescriptorA
)
439 /* test a valid feature descriptor */
440 desc
= "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
442 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, comp
, &len
);
443 ok(r
== ERROR_SUCCESS
, "returned an error\n");
444 ok(len
== strlen(desc
), "length was wrong\n");
445 ok(strcmp(prod
,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
446 ok(strcmp(feature
,"FollowTheWhiteRabbit")==0, "feature wrong\n");
447 ok(strcmp(comp
,"{A7CD68DB-EF74-49C8-FBB2-A7C463B2AC24}")==0,"component wrong\n");
449 /* test an invalid feature descriptor with too many characters */
450 desc
= "']gAVn-}f(ZXfeAR6.ji"
451 "ThisWillFailIfTheresMoreThanAGuidsChars>"
452 "3w2x^IGfe?CxI5heAvk.";
454 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, comp
, &len
);
455 ok(r
== ERROR_INVALID_PARAMETER
, "returned wrong error\n");
458 * Test a valid feature descriptor with the
459 * maximum number of characters and some trailing characters.
461 desc
= "']gAVn-}f(ZXfeAR6.ji"
462 "ThisWillWorkIfTheresLTEThanAGuidsChars>"
463 "3w2x^IGfe?CxI5heAvk."
466 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, comp
, &len
);
467 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
468 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
471 r
= pMsiDecomposeDescriptorA(desc
, prod
, feature
, NULL
, &len
);
472 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
473 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
476 r
= pMsiDecomposeDescriptorA(desc
, prod
, NULL
, NULL
, &len
);
477 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
478 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
481 r
= pMsiDecomposeDescriptorA(desc
, NULL
, NULL
, NULL
, &len
);
482 ok(r
== ERROR_SUCCESS
, "returned wrong error\n");
483 ok(len
== (strlen(desc
) - strlen("extra")), "length wrong\n");
486 r
= pMsiDecomposeDescriptorA(NULL
, NULL
, NULL
, NULL
, &len
);
487 ok(r
== ERROR_INVALID_PARAMETER
, "returned wrong error\n");
488 ok(len
== 0, "length wrong\n");
491 static UINT
try_query_param( MSIHANDLE hdb
, LPCSTR szQuery
, MSIHANDLE hrec
)
496 res
= MsiDatabaseOpenView( hdb
, szQuery
, &htab
);
497 if(res
== ERROR_SUCCESS
)
501 r
= MsiViewExecute( htab
, hrec
);
502 if(r
!= ERROR_SUCCESS
)
505 r
= MsiViewClose( htab
);
506 if(r
!= ERROR_SUCCESS
)
509 r
= MsiCloseHandle( htab
);
510 if(r
!= ERROR_SUCCESS
)
516 static UINT
try_query( MSIHANDLE hdb
, LPCSTR szQuery
)
518 return try_query_param( hdb
, szQuery
, 0 );
521 static UINT
try_insert_query( MSIHANDLE hdb
, LPCSTR szQuery
)
526 hrec
= MsiCreateRecord( 1 );
527 MsiRecordSetString( hrec
, 1, "Hello");
529 r
= try_query_param( hdb
, szQuery
, hrec
);
531 MsiCloseHandle( hrec
);
535 static void test_msibadqueries(void)
542 /* just MsiOpenDatabase should not create a file */
543 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
544 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
546 r
= MsiDatabaseCommit( hdb
);
547 ok(r
== ERROR_SUCCESS
, "Failed to commit database\n");
549 r
= MsiCloseHandle( hdb
);
550 ok(r
== ERROR_SUCCESS
, "Failed to close database\n");
552 /* open it readonly */
553 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
554 ok(r
== ERROR_SUCCESS
, "Failed to open database r/o\n");
556 /* add a table to it */
557 r
= try_query( hdb
, "select * from _Tables");
558 ok(r
== ERROR_SUCCESS
, "query 1 failed\n");
560 r
= MsiCloseHandle( hdb
);
561 ok(r
== ERROR_SUCCESS
, "Failed to close database r/o\n");
563 /* open it read/write */
564 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
565 ok(r
== ERROR_SUCCESS
, "Failed to open database r/w\n");
567 /* a bunch of test queries that fail with the native MSI */
569 r
= try_query( hdb
, "CREATE TABLE");
570 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2a return code\n");
572 r
= try_query( hdb
, "CREATE TABLE `a`");
573 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2b return code\n");
575 r
= try_query( hdb
, "CREATE TABLE `a` ()");
576 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2c return code\n");
578 r
= try_query( hdb
, "CREATE TABLE `a` (`b`)");
579 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2d return code\n");
581 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) )");
582 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2e return code\n");
584 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
585 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2f return code\n");
587 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
588 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2g return code\n");
590 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
591 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2h return code\n");
593 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
594 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2i return code\n");
596 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
597 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2j return code\n");
599 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
600 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2k return code\n");
602 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
603 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2l return code\n");
605 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
606 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2m return code\n");
608 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
609 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2n return code\n");
611 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
612 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2o return code\n");
614 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
615 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2p return code\n");
617 r
= try_query( hdb
, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
618 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "invalid query 2p return code\n");
620 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
621 ok(r
== ERROR_SUCCESS
, "valid query 2z failed\n");
623 r
= try_query( hdb
, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
624 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created same table again\n");
626 r
= try_query( hdb
, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
627 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
628 ok(r
== ERROR_SUCCESS
, "query 4 failed\n");
630 r
= MsiDatabaseCommit( hdb
);
631 ok(r
== ERROR_SUCCESS
, "Failed to commit database after write\n");
633 r
= try_query( hdb
, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
634 "PRIMARY KEY `foo`)");
635 ok(r
== ERROR_SUCCESS
, "query 4 failed\n");
637 r
= try_insert_query( hdb
, "insert into a ( `b` ) VALUES ( ? )");
638 ok(r
== ERROR_SUCCESS
, "failed to insert record in db\n");
640 r
= MsiDatabaseCommit( hdb
);
641 ok(r
== ERROR_SUCCESS
, "Failed to commit database after write\n");
643 r
= try_query( hdb
, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
644 "PRIMARY KEY `ba`)");
645 ok(r
!= ERROR_SUCCESS
, "query 5 succeeded\n");
647 r
= try_query( hdb
,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
648 ok(r
!= ERROR_SUCCESS
, "query 6 succeeded\n");
650 r
= try_query( hdb
, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
652 ok(r
== ERROR_SUCCESS
, "query 7 failed\n");
654 r
= try_query( hdb
, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
655 ok(r
== ERROR_SUCCESS
, "query 8 failed\n");
657 r
= try_query( hdb
, "select * from c");
658 ok(r
== ERROR_SUCCESS
, "query failed\n");
660 r
= try_query( hdb
, "select * from c where b = 'x");
661 todo_wine
ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
663 r
= try_query( hdb
, "select * from 'c'");
664 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
666 r
= try_query( hdb
, "select * from ''");
667 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
669 r
= try_query( hdb
, "select * from c where b = x");
670 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
672 r
= try_query( hdb
, "select * from c where b = \"x\"");
673 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
675 r
= try_query( hdb
, "select * from c where b = 'x'");
676 ok(r
== ERROR_SUCCESS
, "query failed\n");
678 r
= try_query( hdb
, "select * from c where b = '\"x'");
679 ok(r
== ERROR_SUCCESS
, "query failed\n");
681 if (0) /* FIXME: this query causes trouble with other tests */
683 r
= try_query( hdb
, "select * from c where b = '\\\'x'");
684 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
687 r
= try_query( hdb
, "select * from 'c'");
688 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "query failed\n");
690 r
= MsiCloseHandle( hdb
);
691 ok(r
== ERROR_SUCCESS
, "Failed to close database transact\n");
693 r
= DeleteFile( msifile
);
694 ok(r
== TRUE
, "file didn't exist after commit\n");
697 static void test_viewmodify(void)
699 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
708 /* just MsiOpenDatabase should not create a file */
709 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
710 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
712 query
= "CREATE TABLE `phone` ( "
713 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
715 r
= run_query( hdb
, 0, query
);
716 ok(r
== ERROR_SUCCESS
, "query failed\n");
718 /* check what the error function reports without doing anything */
720 /* passing NULL as the 3rd param make function to crash on older platforms */
721 err
= MsiViewGetError( 0, NULL
, &sz
);
722 ok(err
== MSIDBERROR_INVALIDARG
, "MsiViewGetError return\n");
725 query
= "SELECT * FROM `phone`";
726 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
727 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
729 /* see what happens with a good hview and bad args */
730 err
= MsiViewGetError( hview
, NULL
, NULL
);
731 ok(err
== MSIDBERROR_INVALIDARG
|| err
== MSIDBERROR_NOERROR
,
732 "MsiViewGetError returns %u (expected -3)\n", err
);
733 err
= MsiViewGetError( hview
, buffer
, NULL
);
734 ok(err
== MSIDBERROR_INVALIDARG
, "MsiViewGetError return\n");
736 /* see what happens with a zero length buffer */
739 err
= MsiViewGetError( hview
, buffer
, &sz
);
740 ok(err
== MSIDBERROR_MOREDATA
, "MsiViewGetError return\n");
741 ok(buffer
[0] == 'x', "buffer cleared\n");
742 ok(sz
== 0, "size not zero\n");
744 /* ok this one is strange */
746 err
= MsiViewGetError( hview
, NULL
, &sz
);
747 ok(err
== MSIDBERROR_NOERROR
, "MsiViewGetError return\n");
748 ok(sz
== 0, "size not zero\n");
750 /* see if it really has an error */
753 err
= MsiViewGetError( hview
, buffer
, &sz
);
754 ok(err
== MSIDBERROR_NOERROR
, "MsiViewGetError return\n");
755 ok(buffer
[0] == 0, "buffer not cleared\n");
756 ok(sz
== 0, "size not zero\n");
758 r
= MsiViewExecute(hview
, 0);
759 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
761 /* try some invalid records */
762 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, 0 );
763 ok(r
== ERROR_INVALID_HANDLE
, "MsiViewModify failed\n");
764 r
= MsiViewModify(hview
, -1, 0 );
765 ok(r
== ERROR_INVALID_HANDLE
, "MsiViewModify failed\n");
767 /* try an small record */
768 hrec
= MsiCreateRecord(1);
769 r
= MsiViewModify(hview
, -1, hrec
);
770 ok(r
== ERROR_INVALID_DATA
, "MsiViewModify failed\n");
772 r
= MsiCloseHandle(hrec
);
773 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
775 /* insert a valid record */
776 hrec
= MsiCreateRecord(3);
778 r
= MsiRecordSetInteger(hrec
, 1, 1);
779 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
780 r
= MsiRecordSetString(hrec
, 2, "bob");
781 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
782 r
= MsiRecordSetString(hrec
, 3, "7654321");
783 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
785 r
= MsiViewExecute(hview
, 0);
786 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
787 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
788 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
790 /* insert the same thing again */
791 r
= MsiViewExecute(hview
, 0);
792 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
794 /* should fail ... */
795 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
796 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
798 r
= MsiCloseHandle(hrec
);
799 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
801 r
= MsiViewClose(hview
);
802 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
803 r
= MsiCloseHandle(hview
);
804 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
806 query
= "SELECT * FROM `phone`";
807 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
808 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
810 r
= MsiViewExecute(hview
, 0);
811 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
813 r
= MsiViewFetch(hview
, &hrec
);
814 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
816 r
= MsiRecordGetInteger(hrec
, 1);
817 ok(r
== 1, "Expected 1, got %d\n", r
);
820 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
821 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
822 ok(!lstrcmp(buffer
, "bob"), "Expected bob, got %s\n", buffer
);
825 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
826 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
827 ok(!lstrcmp(buffer
, "7654321"), "Expected 7654321, got %s\n", buffer
);
829 /* update the view, non-primary key */
830 r
= MsiRecordSetString(hrec
, 3, "3141592");
831 ok(r
== ERROR_SUCCESS
, "MsiRecordSetString failed\n");
833 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
834 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
837 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
838 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
840 /* update the view, primary key */
841 r
= MsiRecordSetInteger(hrec
, 1, 5);
842 ok(r
== ERROR_SUCCESS
, "MsiRecordSetInteger failed\n");
844 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
845 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
847 r
= MsiCloseHandle(hrec
);
848 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
850 r
= MsiViewClose(hview
);
851 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
852 r
= MsiCloseHandle(hview
);
853 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
855 query
= "SELECT * FROM `phone`";
856 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
857 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
859 r
= MsiViewExecute(hview
, 0);
860 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
862 r
= MsiViewFetch(hview
, &hrec
);
863 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
865 r
= MsiRecordGetInteger(hrec
, 1);
866 ok(r
== 1, "Expected 1, got %d\n", r
);
869 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
870 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
871 ok(!lstrcmp(buffer
, "bob"), "Expected bob, got %s\n", buffer
);
874 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
875 ok(r
== ERROR_SUCCESS
, "MsiRecordGetString failed\n");
876 ok(!lstrcmp(buffer
, "3141592"), "Expected 3141592, got %s\n", buffer
);
878 r
= MsiCloseHandle(hrec
);
879 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
881 /* use a record that doesn't come from a view fetch */
882 hrec
= MsiCreateRecord(3);
883 ok(hrec
!= 0, "MsiCreateRecord failed\n");
885 r
= MsiRecordSetInteger(hrec
, 1, 3);
886 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
887 r
= MsiRecordSetString(hrec
, 2, "jane");
888 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
889 r
= MsiRecordSetString(hrec
, 3, "112358");
890 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
892 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
893 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
895 r
= MsiCloseHandle(hrec
);
896 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
898 /* use a record that doesn't come from a view fetch, primary key matches */
899 hrec
= MsiCreateRecord(3);
900 ok(hrec
!= 0, "MsiCreateRecord failed\n");
902 r
= MsiRecordSetInteger(hrec
, 1, 1);
903 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
904 r
= MsiRecordSetString(hrec
, 2, "jane");
905 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
906 r
= MsiRecordSetString(hrec
, 3, "112358");
907 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
909 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
912 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
915 r
= MsiCloseHandle(hrec
);
916 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
918 hrec
= MsiCreateRecord(3);
920 r
= MsiRecordSetInteger(hrec
, 1, 2);
921 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
922 r
= MsiRecordSetString(hrec
, 2, "nick");
923 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
924 r
= MsiRecordSetString(hrec
, 3, "141421");
925 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
927 r
= MsiViewExecute(hview
, 0);
928 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
929 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
930 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
932 r
= MsiViewClose(hview
);
933 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
934 r
= MsiCloseHandle(hview
);
935 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
937 query
= "SELECT * FROM `phone` WHERE `id` = 1";
938 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
939 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
940 r
= MsiViewExecute(hview
, 0);
941 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
942 r
= MsiViewFetch(hview
, &hrec
);
943 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
945 /* change the id to match the second row */
946 r
= MsiRecordSetInteger(hrec
, 1, 2);
947 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
948 r
= MsiRecordSetString(hrec
, 2, "jerry");
949 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
951 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
952 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
954 r
= MsiCloseHandle(hrec
);
955 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
956 r
= MsiViewClose(hview
);
957 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
958 r
= MsiCloseHandle(hview
);
959 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
962 query
= "SELECT * FROM `phone` ORDER BY `id`";
963 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
964 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
965 r
= MsiViewExecute(hview
, 0);
966 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
967 r
= MsiViewFetch(hview
, &hrec
);
968 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
970 /* change the id to match the second row */
971 r
= MsiRecordSetInteger(hrec
, 1, 2);
972 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
973 r
= MsiRecordSetString(hrec
, 2, "jerry");
974 ok(r
== ERROR_SUCCESS
, "failed to set string\n");
976 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
977 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
979 r
= MsiCloseHandle(hrec
);
980 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
981 r
= MsiViewClose(hview
);
982 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
983 r
= MsiCloseHandle(hview
);
984 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
986 r
= MsiCloseHandle( hdb
);
987 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
990 static MSIHANDLE
create_db(void)
997 /* create an empty database */
998 res
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
999 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
1000 if( res
!= ERROR_SUCCESS
)
1003 res
= MsiDatabaseCommit( hdb
);
1004 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
1009 static void test_getcolinfo(void)
1011 MSIHANDLE hdb
, hview
= 0, rec
= 0;
1016 /* create an empty db */
1018 ok( hdb
, "failed to create db\n");
1020 /* tables should be present */
1021 r
= MsiDatabaseOpenView(hdb
, "select * from _Tables", &hview
);
1022 ok( r
== ERROR_SUCCESS
, "failed to open query\n");
1024 r
= MsiViewExecute(hview
, 0);
1025 ok( r
== ERROR_SUCCESS
, "failed to execute query\n");
1027 /* check that NAMES works */
1029 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_NAMES
, &rec
);
1030 ok( r
== ERROR_SUCCESS
, "failed to get names\n");
1032 r
= MsiRecordGetString(rec
, 1, buffer
, &sz
);
1033 ok( r
== ERROR_SUCCESS
, "failed to get string\n");
1034 ok( !strcmp(buffer
,"Name"), "_Tables has wrong column name\n");
1035 r
= MsiCloseHandle( rec
);
1036 ok( r
== ERROR_SUCCESS
, "failed to close record handle\n");
1038 /* check that TYPES works */
1040 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_TYPES
, &rec
);
1041 ok( r
== ERROR_SUCCESS
, "failed to get names\n");
1043 r
= MsiRecordGetString(rec
, 1, buffer
, &sz
);
1044 ok( r
== ERROR_SUCCESS
, "failed to get string\n");
1045 ok( !strcmp(buffer
,"s64"), "_Tables has wrong column type\n");
1046 r
= MsiCloseHandle( rec
);
1047 ok( r
== ERROR_SUCCESS
, "failed to close record handle\n");
1049 /* check that invalid values fail */
1051 r
= MsiViewGetColumnInfo( hview
, 100, &rec
);
1052 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error code\n");
1053 ok( rec
== 0, "returned a record\n");
1055 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_TYPES
, NULL
);
1056 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error code\n");
1058 r
= MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES
, &rec
);
1059 ok( r
== ERROR_INVALID_HANDLE
, "wrong error code\n");
1061 r
= MsiViewClose(hview
);
1062 ok( r
== ERROR_SUCCESS
, "failed to close view\n");
1063 r
= MsiCloseHandle(hview
);
1064 ok( r
== ERROR_SUCCESS
, "failed to close view handle\n");
1065 r
= MsiCloseHandle(hdb
);
1066 ok( r
== ERROR_SUCCESS
, "failed to close database\n");
1069 static MSIHANDLE
get_column_info(MSIHANDLE hdb
, const char *query
, MSICOLINFO type
)
1071 MSIHANDLE hview
= 0, rec
= 0;
1074 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1075 if( r
!= ERROR_SUCCESS
)
1078 r
= MsiViewExecute(hview
, 0);
1079 if( r
== ERROR_SUCCESS
)
1081 MsiViewGetColumnInfo( hview
, type
, &rec
);
1082 MsiViewClose(hview
);
1084 MsiCloseHandle(hview
);
1088 static UINT
get_columns_table_type(MSIHANDLE hdb
, const char *table
, UINT field
)
1090 MSIHANDLE hview
= 0, rec
= 0;
1094 sprintf(query
, "select * from `_Columns` where `Table` = '%s'", table
);
1096 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1097 if( r
!= ERROR_SUCCESS
)
1100 r
= MsiViewExecute(hview
, 0);
1101 if( r
== ERROR_SUCCESS
)
1105 r
= MsiViewFetch( hview
, &rec
);
1106 if( r
!= ERROR_SUCCESS
)
1108 r
= MsiRecordGetInteger( rec
, 2 );
1110 type
= MsiRecordGetInteger( rec
, 4 );
1111 MsiCloseHandle( rec
);
1114 MsiViewClose(hview
);
1116 MsiCloseHandle(hview
);
1120 static BOOL
check_record( MSIHANDLE rec
, UINT field
, LPCSTR val
)
1127 r
= MsiRecordGetString( rec
, field
, buffer
, &sz
);
1128 return (r
== ERROR_SUCCESS
) && !strcmp(val
, buffer
);
1131 static void test_viewgetcolumninfo(void)
1133 MSIHANDLE hdb
= 0, rec
;
1137 ok( hdb
, "failed to create db\n");
1139 r
= run_query( hdb
, 0,
1140 "CREATE TABLE `Properties` "
1141 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1142 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1144 /* check the column types */
1145 rec
= get_column_info( hdb
, "select * from `Properties`", MSICOLINFO_TYPES
);
1146 ok( rec
, "failed to get column info record\n" );
1148 ok( check_record( rec
, 1, "S255"), "wrong record type\n");
1149 ok( check_record( rec
, 2, "S1"), "wrong record type\n");
1151 MsiCloseHandle( rec
);
1153 /* check the type in _Columns */
1154 ok( 0x3dff == get_columns_table_type(hdb
, "Properties", 1 ), "_columns table wrong\n");
1155 ok( 0x1d01 == get_columns_table_type(hdb
, "Properties", 2 ), "_columns table wrong\n");
1157 /* now try the names */
1158 rec
= get_column_info( hdb
, "select * from `Properties`", MSICOLINFO_NAMES
);
1159 ok( rec
, "failed to get column info record\n" );
1161 ok( check_record( rec
, 1, "Property"), "wrong record type\n");
1162 ok( check_record( rec
, 2, "Value"), "wrong record type\n");
1164 MsiCloseHandle( rec
);
1166 r
= run_query( hdb
, 0,
1167 "CREATE TABLE `Binary` "
1168 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
1169 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1171 /* check the column types */
1172 rec
= get_column_info( hdb
, "select * from `Binary`", MSICOLINFO_TYPES
);
1173 ok( rec
, "failed to get column info record\n" );
1175 ok( check_record( rec
, 1, "S255"), "wrong record type\n");
1176 ok( check_record( rec
, 2, "V0"), "wrong record type\n");
1178 MsiCloseHandle( rec
);
1180 /* check the type in _Columns */
1181 ok( 0x3dff == get_columns_table_type(hdb
, "Binary", 1 ), "_columns table wrong\n");
1182 ok( 0x1900 == get_columns_table_type(hdb
, "Binary", 2 ), "_columns table wrong\n");
1184 /* now try the names */
1185 rec
= get_column_info( hdb
, "select * from `Binary`", MSICOLINFO_NAMES
);
1186 ok( rec
, "failed to get column info record\n" );
1188 ok( check_record( rec
, 1, "Name"), "wrong record type\n");
1189 ok( check_record( rec
, 2, "Data"), "wrong record type\n");
1190 MsiCloseHandle( rec
);
1192 r
= run_query( hdb
, 0,
1193 "CREATE TABLE `UIText` "
1194 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1195 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1197 ok( 0x2d48 == get_columns_table_type(hdb
, "UIText", 1 ), "_columns table wrong\n");
1198 ok( 0x1fff == get_columns_table_type(hdb
, "UIText", 2 ), "_columns table wrong\n");
1200 rec
= get_column_info( hdb
, "select * from `UIText`", MSICOLINFO_NAMES
);
1201 ok( rec
, "failed to get column info record\n" );
1202 ok( check_record( rec
, 1, "Key"), "wrong record type\n");
1203 ok( check_record( rec
, 2, "Text"), "wrong record type\n");
1204 MsiCloseHandle( rec
);
1206 rec
= get_column_info( hdb
, "select * from `UIText`", MSICOLINFO_TYPES
);
1207 ok( rec
, "failed to get column info record\n" );
1208 ok( check_record( rec
, 1, "s72"), "wrong record type\n");
1209 ok( check_record( rec
, 2, "L255"), "wrong record type\n");
1210 MsiCloseHandle( rec
);
1212 MsiCloseHandle( hdb
);
1215 static void test_msiexport(void)
1217 MSIHANDLE hdb
= 0, hview
= 0;
1220 char path
[MAX_PATH
];
1221 const char file
[] = "phone.txt";
1225 const char expected
[] =
1226 "id\tname\tnumber\r\n"
1229 "1\tAbe\t8675309\r\n";
1231 DeleteFile(msifile
);
1233 /* just MsiOpenDatabase should not create a file */
1234 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1235 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1237 /* create a table */
1238 query
= "CREATE TABLE `phone` ( "
1239 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1240 "PRIMARY KEY `id`)";
1241 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1242 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1243 r
= MsiViewExecute(hview
, 0);
1244 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1245 r
= MsiViewClose(hview
);
1246 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1247 r
= MsiCloseHandle(hview
);
1248 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1250 /* insert a value into it */
1251 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
1252 "VALUES('1', 'Abe', '8675309')";
1253 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1254 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1255 r
= MsiViewExecute(hview
, 0);
1256 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1257 r
= MsiViewClose(hview
);
1258 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1259 r
= MsiCloseHandle(hview
);
1260 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1262 GetCurrentDirectory(MAX_PATH
, path
);
1264 r
= MsiDatabaseExport(hdb
, "phone", path
, file
);
1265 ok(r
== ERROR_SUCCESS
, "MsiDatabaseExport failed\n");
1267 MsiCloseHandle(hdb
);
1269 lstrcat(path
, "\\");
1270 lstrcat(path
, file
);
1272 /* check the data that was written */
1274 memset(buffer
, 0, sizeof buffer
);
1275 handle
= CreateFile(path
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1276 if (handle
!= INVALID_HANDLE_VALUE
)
1278 ReadFile(handle
, buffer
, sizeof buffer
, &length
, NULL
);
1279 CloseHandle(handle
);
1283 ok(0, "failed to open file %s\n", path
);
1285 ok( length
== strlen(expected
), "length of data wrong\n");
1286 ok( !lstrcmp(buffer
, expected
), "data doesn't match\n");
1287 DeleteFile(msifile
);
1290 static void test_longstrings(void)
1292 const char insert_query
[] =
1293 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1295 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
1298 const DWORD STRING_LENGTH
= 0x10005;
1300 DeleteFile(msifile
);
1301 /* just MsiOpenDatabase should not create a file */
1302 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1303 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1305 /* create a table */
1307 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1308 ok(r
== ERROR_SUCCESS
, "query failed\n");
1310 /* try a insert a very long string */
1311 str
= HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH
+sizeof insert_query
);
1312 len
= strchr(insert_query
, 'Z') - insert_query
;
1313 strcpy(str
, insert_query
);
1314 memset(str
+len
, 'Z', STRING_LENGTH
);
1315 strcpy(str
+len
+STRING_LENGTH
, insert_query
+len
+1);
1316 r
= try_query( hdb
, str
);
1317 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1319 HeapFree(GetProcessHeap(), 0, str
);
1321 MsiDatabaseCommit(hdb
);
1322 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
1323 MsiCloseHandle(hdb
);
1325 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
1326 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1328 r
= MsiDatabaseOpenView(hdb
, "select * from `strings` where `id` = 1", &hview
);
1329 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1331 r
= MsiViewExecute(hview
, 0);
1332 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1334 r
= MsiViewFetch(hview
, &hrec
);
1335 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1337 MsiCloseHandle(hview
);
1339 r
= MsiRecordGetString(hrec
, 2, NULL
, &len
);
1340 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1341 ok(len
== STRING_LENGTH
, "string length wrong\n");
1343 MsiCloseHandle(hrec
);
1344 MsiCloseHandle(hdb
);
1345 DeleteFile(msifile
);
1348 static void create_file(const CHAR
*name
)
1353 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
1354 ok(file
!= INVALID_HANDLE_VALUE
, "Failure to open file %s\n", name
);
1355 WriteFile(file
, name
, strlen(name
), &written
, NULL
);
1356 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
1360 static void test_streamtable(void)
1362 MSIHANDLE hdb
= 0, rec
, view
;
1363 char file
[MAX_PATH
];
1369 ok( hdb
, "failed to create db\n");
1371 r
= run_query( hdb
, 0,
1372 "CREATE TABLE `Properties` "
1373 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1374 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1376 r
= run_query( hdb
, 0,
1377 "INSERT INTO `Properties` "
1378 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1379 ok( r
== ERROR_SUCCESS
, "Failed to add to table\n" );
1381 r
= MsiDatabaseCommit( hdb
);
1382 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
1384 MsiCloseHandle( hdb
);
1386 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
1387 ok( r
== ERROR_SUCCESS
, "Failed to open database\n" );
1389 /* check the column types */
1390 rec
= get_column_info( hdb
, "select * from `_Streams`", MSICOLINFO_TYPES
);
1391 ok( rec
, "failed to get column info record\n" );
1393 ok( check_record( rec
, 1, "s62"), "wrong record type\n");
1394 ok( check_record( rec
, 2, "V0"), "wrong record type\n");
1396 MsiCloseHandle( rec
);
1398 /* now try the names */
1399 rec
= get_column_info( hdb
, "select * from `_Streams`", MSICOLINFO_NAMES
);
1400 ok( rec
, "failed to get column info record\n" );
1402 ok( check_record( rec
, 1, "Name"), "wrong record type\n");
1403 ok( check_record( rec
, 2, "Data"), "wrong record type\n");
1405 MsiCloseHandle( rec
);
1407 /* insert a file into the _Streams table */
1408 create_file( "test.txt" );
1410 rec
= MsiCreateRecord( 2 );
1411 MsiRecordSetString( rec
, 1, "data" );
1413 r
= MsiRecordSetStream( rec
, 2, "test.txt" );
1414 ok( r
== ERROR_SUCCESS
, "Failed to add stream data to the record: %d\n", r
);
1416 DeleteFile("test.txt");
1418 r
= MsiDatabaseOpenView( hdb
,
1419 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view
);
1420 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1422 r
= MsiViewExecute( view
, rec
);
1423 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1425 MsiCloseHandle( rec
);
1426 MsiCloseHandle( view
);
1428 r
= MsiDatabaseOpenView( hdb
,
1429 "SELECT `Name`, `Data` FROM `_Streams`", &view
);
1430 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1432 r
= MsiViewExecute( view
, 0 );
1433 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1435 r
= MsiViewFetch( view
, &rec
);
1436 ok( r
== ERROR_SUCCESS
, "Failed to fetch record: %d\n", r
);
1439 r
= MsiRecordGetString( rec
, 1, file
, &size
);
1440 ok( r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
1441 ok( !lstrcmp(file
, "data"), "Expected 'data', got %s\n", file
);
1444 memset(buf
, 0, MAX_PATH
);
1445 r
= MsiRecordReadStream( rec
, 2, buf
, &size
);
1446 ok( r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
1447 ok( !lstrcmp(buf
, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf
);
1449 MsiCloseHandle( rec
);
1451 r
= MsiViewFetch( view
, &rec
);
1452 ok( r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
1454 MsiCloseHandle( view
);
1455 MsiCloseHandle( hdb
);
1456 DeleteFile(msifile
);
1459 static void test_where(void)
1461 MSIHANDLE hdb
= 0, rec
, view
;
1469 ok( hdb
, "failed to create db\n");
1471 r
= run_query( hdb
, 0,
1472 "CREATE TABLE `Media` ("
1473 "`DiskId` SHORT NOT NULL, "
1474 "`LastSequence` LONG, "
1475 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1476 "`Cabinet` CHAR(255), "
1477 "`VolumeLabel` CHAR(32), "
1478 "`Source` CHAR(72) "
1479 "PRIMARY KEY `DiskId`)" );
1480 ok( r
== S_OK
, "cannot create Media table: %d\n", r
);
1482 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1483 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1484 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1485 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1487 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1488 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1489 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1490 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1492 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1493 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1494 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1495 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1497 query
= "SELECT * FROM `Media`";
1498 r
= do_query(hdb
, query
, &rec
);
1499 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed: %d\n", r
);
1500 ok( check_record( rec
, 4, "zero.cab"), "wrong cabinet\n");
1501 MsiCloseHandle( rec
);
1503 query
= "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1504 r
= do_query(hdb
, query
, &rec
);
1505 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed: %d\n", r
);
1506 ok( check_record( rec
, 4, "one.cab"), "wrong cabinet\n");
1508 r
= MsiRecordGetInteger(rec
, 1);
1509 ok( 2 == r
, "field wrong\n");
1510 r
= MsiRecordGetInteger(rec
, 2);
1511 ok( 1 == r
, "field wrong\n");
1512 MsiCloseHandle( rec
);
1514 query
= "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1515 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1516 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
1518 r
= MsiViewExecute(view
, 0);
1519 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
1521 r
= MsiViewFetch(view
, &rec
);
1522 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1524 count
= MsiRecordGetFieldCount( rec
);
1525 ok( count
== 1, "Expected 1 record fields, got %d\n", count
);
1528 r
= MsiRecordGetString( rec
, 1, buf
, &size
);
1529 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
1530 ok( !lstrcmp( buf
, "2" ),
1531 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf
);
1532 MsiCloseHandle( rec
);
1534 r
= MsiViewFetch(view
, &rec
);
1535 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1538 r
= MsiRecordGetString( rec
, 1, buf
, &size
);
1539 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
1540 ok( !lstrcmp( buf
, "3" ),
1541 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf
);
1542 MsiCloseHandle( rec
);
1544 r
= MsiViewFetch(view
, &rec
);
1545 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
1548 MsiCloseHandle(view
);
1550 MsiCloseHandle( rec
);
1553 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1554 r
= do_query(hdb
, query
, &rec
);
1555 ok( r
== ERROR_SUCCESS
, "query failed: %d\n", r
);
1556 MsiCloseHandle( rec
);
1558 rec
= MsiCreateRecord(1);
1559 MsiRecordSetString(rec
, 1, "");
1561 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` = ?";
1562 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1563 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1564 r
= MsiViewExecute(view
, rec
);
1565 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1567 MsiCloseHandle(rec
);
1569 r
= MsiViewFetch(view
, &rec
);
1570 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1572 MsiCloseHandle(rec
);
1574 MsiCloseHandle(view
);
1576 MsiCloseHandle( hdb
);
1577 DeleteFile(msifile
);
1580 static CHAR CURR_DIR
[MAX_PATH
];
1582 static const CHAR test_data
[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1583 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1584 "TestTable\tFirstPrimaryColumn\n"
1585 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1587 static const CHAR two_primary
[] = "PrimaryOne\tPrimaryTwo\n"
1589 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1593 static const CHAR endlines1
[] = "A\tB\tC\tD\tE\tF\r\n"
1594 "s72\ts72\ts72\ts72\ts72\ts72\n"
1596 "a\tb\tc\td\te\tf\n"
1597 "g\th\ti\t\rj\tk\tl\r\n";
1599 static const CHAR endlines2
[] = "A\tB\tC\tD\tE\tF\r"
1600 "s72\ts72\ts72\ts72\ts72\ts72\n"
1602 "a\tb\tc\td\te\tf\n"
1603 "g\th\ti\tj\tk\tl\r\n";
1605 static void write_file(const CHAR
*filename
, const char *data
, int data_size
)
1609 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
1610 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1612 WriteFile(hf
, data
, data_size
, &size
, NULL
);
1616 static UINT
add_table_to_db(MSIHANDLE hdb
, LPCSTR table_data
)
1620 write_file("temp_file", table_data
, (lstrlen(table_data
) - 1) * sizeof(char));
1621 r
= MsiDatabaseImportA(hdb
, CURR_DIR
, "temp_file");
1622 DeleteFileA("temp_file");
1627 static void test_msiimport(void)
1629 MSIHANDLE hdb
, view
, rec
;
1634 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
1636 r
= MsiOpenDatabaseA(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1637 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1639 r
= add_table_to_db(hdb
, test_data
);
1640 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1642 r
= add_table_to_db(hdb
, two_primary
);
1643 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1645 r
= add_table_to_db(hdb
, endlines1
);
1646 if (r
== ERROR_FUNCTION_FAILED
)
1648 /* win9x doesn't handle this case */
1649 skip("endlines not handled correctly.\n");
1650 MsiCloseHandle(hdb
);
1651 DeleteFileA(msifile
);
1655 r
= add_table_to_db(hdb
, endlines2
);
1656 ok(r
== ERROR_FUNCTION_FAILED
,
1657 "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
1659 query
= "SELECT * FROM `TestTable`";
1660 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1661 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1663 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
1664 count
= MsiRecordGetFieldCount(rec
);
1665 ok(count
== 9, "Expected 9, got %d\n", count
);
1666 ok(check_record(rec
, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
1667 ok(check_record(rec
, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
1668 ok(check_record(rec
, 3, "ShortInt"), "Expected ShortInt\n");
1669 ok(check_record(rec
, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
1670 ok(check_record(rec
, 5, "LongInt"), "Expected LongInt\n");
1671 ok(check_record(rec
, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
1672 ok(check_record(rec
, 7, "String"), "Expected String\n");
1673 ok(check_record(rec
, 8, "LocalizableString"), "Expected LocalizableString\n");
1674 ok(check_record(rec
, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
1675 MsiCloseHandle(rec
);
1677 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1678 count
= MsiRecordGetFieldCount(rec
);
1679 ok(count
== 9, "Expected 9, got %d\n", count
);
1680 ok(check_record(rec
, 1, "s255"), "Expected s255\n");
1681 ok(check_record(rec
, 2, "i2"), "Expected i2\n");
1682 ok(check_record(rec
, 3, "i2"), "Expected i2\n");
1683 ok(check_record(rec
, 4, "I2"), "Expected I2\n");
1684 ok(check_record(rec
, 5, "i4"), "Expected i4\n");
1685 ok(check_record(rec
, 6, "I4"), "Expected I4\n");
1686 ok(check_record(rec
, 7, "S255"), "Expected S255\n");
1687 ok(check_record(rec
, 8, "S0"), "Expected S0\n");
1688 ok(check_record(rec
, 9, "s0"), "Expected s0\n");
1689 MsiCloseHandle(rec
);
1691 query
= "SELECT * FROM `TestTable`";
1692 r
= do_query(hdb
, query
, &rec
);
1693 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1694 ok(check_record(rec
, 1, "stringage"), "Expected 'stringage'\n");
1695 ok(check_record(rec
, 7, "another string"), "Expected 'another string'\n");
1696 ok(check_record(rec
, 8, "localizable"), "Expected 'localizable'\n");
1697 ok(check_record(rec
, 9, "duh"), "Expected 'duh'\n");
1699 i
= MsiRecordGetInteger(rec
, 2);
1700 ok(i
== 5, "Expected 5, got %d\n", i
);
1702 i
= MsiRecordGetInteger(rec
, 3);
1703 ok(i
== 2, "Expected 2, got %d\n", i
);
1705 i
= MsiRecordGetInteger(rec
, 4);
1706 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
1708 i
= MsiRecordGetInteger(rec
, 5);
1709 ok(i
== 2147483640, "Expected 2147483640, got %d\n", i
);
1711 i
= MsiRecordGetInteger(rec
, 6);
1712 ok(i
== -2147483640, "Expected -2147483640, got %d\n", i
);
1714 MsiCloseHandle(rec
);
1715 MsiCloseHandle(view
);
1717 query
= "SELECT * FROM `TwoPrimary`";
1718 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1719 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1721 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
1722 count
= MsiRecordGetFieldCount(rec
);
1723 ok(count
== 2, "Expected 2, got %d\n", count
);
1724 ok(check_record(rec
, 1, "PrimaryOne"), "Expected PrimaryOne\n");
1725 ok(check_record(rec
, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
1727 MsiCloseHandle(rec
);
1729 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1730 count
= MsiRecordGetFieldCount(rec
);
1731 ok(count
== 2, "Expected 2, got %d\n", count
);
1732 ok(check_record(rec
, 1, "s255"), "Expected s255\n");
1733 ok(check_record(rec
, 2, "s255"), "Expected s255\n");
1734 MsiCloseHandle(rec
);
1736 r
= MsiViewExecute(view
, 0);
1737 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1739 r
= MsiViewFetch(view
, &rec
);
1740 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1742 ok(check_record(rec
, 1, "papaya"), "Expected 'papaya'\n");
1743 ok(check_record(rec
, 2, "leaf"), "Expected 'leaf'\n");
1745 MsiCloseHandle(rec
);
1747 r
= MsiViewFetch(view
, &rec
);
1748 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1750 ok(check_record(rec
, 1, "papaya"), "Expected 'papaya'\n");
1751 ok(check_record(rec
, 2, "flower"), "Expected 'flower'\n");
1753 MsiCloseHandle(rec
);
1755 r
= MsiViewFetch(view
, &rec
);
1756 ok(r
== ERROR_NO_MORE_ITEMS
,
1757 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
1759 r
= MsiViewClose(view
);
1760 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1762 MsiCloseHandle(view
);
1764 query
= "SELECT * FROM `Table`";
1765 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1766 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1768 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
1769 count
= MsiRecordGetFieldCount(rec
);
1770 ok(count
== 6, "Expected 6, got %d\n", count
);
1771 ok(check_record(rec
, 1, "A"), "Expected A\n");
1772 ok(check_record(rec
, 2, "B"), "Expected B\n");
1773 ok(check_record(rec
, 3, "C"), "Expected C\n");
1774 ok(check_record(rec
, 4, "D"), "Expected D\n");
1775 ok(check_record(rec
, 5, "E"), "Expected E\n");
1776 ok(check_record(rec
, 6, "F"), "Expected F\n");
1777 MsiCloseHandle(rec
);
1779 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1780 count
= MsiRecordGetFieldCount(rec
);
1781 ok(count
== 6, "Expected 6, got %d\n", count
);
1782 ok(check_record(rec
, 1, "s72"), "Expected s72\n");
1783 ok(check_record(rec
, 2, "s72"), "Expected s72\n");
1784 ok(check_record(rec
, 3, "s72"), "Expected s72\n");
1785 ok(check_record(rec
, 4, "s72"), "Expected s72\n");
1786 ok(check_record(rec
, 5, "s72"), "Expected s72\n");
1787 ok(check_record(rec
, 6, "s72"), "Expected s72\n");
1788 MsiCloseHandle(rec
);
1791 MsiCloseHandle(view
);
1793 query
= "SELECT * FROM `Table`";
1794 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1795 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1797 r
= MsiViewExecute(view
, 0);
1798 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1800 r
= MsiViewFetch(view
, &rec
);
1801 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1802 ok(check_record(rec
, 1, "a"), "Expected 'a'\n");
1803 ok(check_record(rec
, 2, "b"), "Expected 'b'\n");
1804 ok(check_record(rec
, 3, "c"), "Expected 'c'\n");
1805 ok(check_record(rec
, 4, "d"), "Expected 'd'\n");
1806 ok(check_record(rec
, 5, "e"), "Expected 'e'\n");
1807 ok(check_record(rec
, 6, "f"), "Expected 'f'\n");
1809 MsiCloseHandle(rec
);
1811 r
= MsiViewFetch(view
, &rec
);
1812 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1813 ok(check_record(rec
, 1, "g"), "Expected 'g'\n");
1814 ok(check_record(rec
, 2, "h"), "Expected 'h'\n");
1815 ok(check_record(rec
, 3, "i"), "Expected 'i'\n");
1816 ok(check_record(rec
, 4, "j"), "Expected 'j'\n");
1817 ok(check_record(rec
, 5, "k"), "Expected 'k'\n");
1818 ok(check_record(rec
, 6, "l"), "Expected 'l'\n");
1820 MsiCloseHandle(rec
);
1822 r
= MsiViewFetch(view
, &rec
);
1823 ok(r
== ERROR_NO_MORE_ITEMS
,
1824 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
1827 MsiCloseHandle(view
);
1828 MsiCloseHandle(hdb
);
1829 DeleteFileA(msifile
);
1832 static void test_markers(void)
1839 ok( hdb
, "failed to create db\n");
1841 rec
= MsiCreateRecord(3);
1842 MsiRecordSetString(rec
, 1, "Table");
1843 MsiRecordSetString(rec
, 2, "Apples");
1844 MsiRecordSetString(rec
, 3, "Oranges");
1846 /* try a legit create */
1847 query
= "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1848 r
= run_query(hdb
, 0, query
);
1849 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1850 MsiCloseHandle(rec
);
1852 /* try table name as marker */
1853 rec
= MsiCreateRecord(1);
1854 MsiRecordSetString(rec
, 1, "Fable");
1855 query
= "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1856 r
= run_query(hdb
, rec
, query
);
1857 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1859 /* verify that we just created a table called '?', not 'Fable' */
1860 r
= try_query(hdb
, "SELECT * from `Fable`");
1861 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1863 r
= try_query(hdb
, "SELECT * from `?`");
1864 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1866 /* try table name as marker without backticks */
1867 MsiRecordSetString(rec
, 1, "Mable");
1868 query
= "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1869 r
= run_query(hdb
, rec
, query
);
1870 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1872 /* try one column name as marker */
1873 MsiRecordSetString(rec
, 1, "One");
1874 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1875 r
= run_query(hdb
, rec
, query
);
1876 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1877 MsiCloseHandle(rec
);
1879 /* try column names as markers */
1880 rec
= MsiCreateRecord(2);
1881 MsiRecordSetString(rec
, 1, "One");
1882 MsiRecordSetString(rec
, 2, "Two");
1883 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
1884 r
= run_query(hdb
, rec
, query
);
1885 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1886 MsiCloseHandle(rec
);
1888 /* try names with backticks */
1889 rec
= MsiCreateRecord(3);
1890 MsiRecordSetString(rec
, 1, "One");
1891 MsiRecordSetString(rec
, 2, "Two");
1892 MsiRecordSetString(rec
, 3, "One");
1893 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1894 r
= run_query(hdb
, rec
, query
);
1895 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1897 /* try names with backticks, minus definitions */
1898 query
= "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
1899 r
= run_query(hdb
, rec
, query
);
1900 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1902 /* try names without backticks */
1903 query
= "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
1904 r
= run_query(hdb
, rec
, query
);
1905 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1906 MsiCloseHandle(rec
);
1908 /* try one long marker */
1909 rec
= MsiCreateRecord(1);
1910 MsiRecordSetString(rec
, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
1911 query
= "CREATE TABLE `Mable` ( ? )";
1912 r
= run_query(hdb
, rec
, query
);
1913 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1914 MsiCloseHandle(rec
);
1916 /* try all names as markers */
1917 rec
= MsiCreateRecord(4);
1918 MsiRecordSetString(rec
, 1, "Mable");
1919 MsiRecordSetString(rec
, 2, "One");
1920 MsiRecordSetString(rec
, 3, "Two");
1921 MsiRecordSetString(rec
, 4, "One");
1922 query
= "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1923 r
= run_query(hdb
, rec
, query
);
1924 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1925 MsiCloseHandle(rec
);
1927 /* try a legit insert */
1928 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
1929 r
= run_query(hdb
, 0, query
);
1930 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1932 r
= try_query(hdb
, "SELECT * from `Table`");
1933 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1935 /* try values as markers */
1936 rec
= MsiCreateRecord(2);
1937 MsiRecordSetInteger(rec
, 1, 4);
1938 MsiRecordSetString(rec
, 2, "hi");
1939 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1940 r
= run_query(hdb
, rec
, query
);
1941 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1942 MsiCloseHandle(rec
);
1944 /* try column names and values as markers */
1945 rec
= MsiCreateRecord(4);
1946 MsiRecordSetString(rec
, 1, "One");
1947 MsiRecordSetString(rec
, 2, "Two");
1948 MsiRecordSetInteger(rec
, 3, 5);
1949 MsiRecordSetString(rec
, 4, "hi");
1950 query
= "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
1951 r
= run_query(hdb
, rec
, query
);
1952 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1953 MsiCloseHandle(rec
);
1955 /* try column names as markers */
1956 rec
= MsiCreateRecord(2);
1957 MsiRecordSetString(rec
, 1, "One");
1958 MsiRecordSetString(rec
, 2, "Two");
1959 query
= "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
1960 r
= run_query(hdb
, rec
, query
);
1961 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1962 MsiCloseHandle(rec
);
1964 /* try table name as a marker */
1965 rec
= MsiCreateRecord(1);
1966 MsiRecordSetString(rec
, 1, "Table");
1967 query
= "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
1968 r
= run_query(hdb
, rec
, query
);
1969 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1970 MsiCloseHandle(rec
);
1972 /* try table name and values as markers */
1973 rec
= MsiCreateRecord(3);
1974 MsiRecordSetString(rec
, 1, "Table");
1975 MsiRecordSetInteger(rec
, 2, 10);
1976 MsiRecordSetString(rec
, 3, "haha");
1977 query
= "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
1978 r
= run_query(hdb
, rec
, query
);
1979 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
1980 MsiCloseHandle(rec
);
1982 /* try all markers */
1983 rec
= MsiCreateRecord(5);
1984 MsiRecordSetString(rec
, 1, "Table");
1985 MsiRecordSetString(rec
, 1, "One");
1986 MsiRecordSetString(rec
, 1, "Two");
1987 MsiRecordSetInteger(rec
, 2, 10);
1988 MsiRecordSetString(rec
, 3, "haha");
1989 query
= "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
1990 r
= run_query(hdb
, rec
, query
);
1991 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1992 MsiCloseHandle(rec
);
1994 /* insert an integer as a string */
1995 rec
= MsiCreateRecord(2);
1996 MsiRecordSetString(rec
, 1, "11");
1997 MsiRecordSetString(rec
, 2, "hi");
1998 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1999 r
= run_query(hdb
, rec
, query
);
2000 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2001 MsiCloseHandle(rec
);
2003 /* leave off the '' for the string */
2004 rec
= MsiCreateRecord(2);
2005 MsiRecordSetInteger(rec
, 1, 12);
2006 MsiRecordSetString(rec
, 2, "hi");
2007 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
2008 r
= run_query(hdb
, rec
, query
);
2009 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2010 MsiCloseHandle(rec
);
2012 MsiCloseHandle(hdb
);
2013 DeleteFileA(msifile
);
2016 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
2017 static void test_handle_limit(void)
2021 MSIHANDLE hviews
[MY_NVIEWS
];
2024 /* create an empty db */
2026 ok( hdb
, "failed to create db\n");
2028 memset(hviews
, 0, sizeof(hviews
));
2030 for (i
=0; i
<MY_NVIEWS
; i
++) {
2031 static char szQueryBuf
[256] = "SELECT * from `_Tables`";
2032 hviews
[i
] = 0xdeadbeeb;
2033 r
= MsiDatabaseOpenView(hdb
, szQueryBuf
, &hviews
[i
]);
2034 if( r
!= ERROR_SUCCESS
|| hviews
[i
] == 0xdeadbeeb ||
2035 hviews
[i
] == 0 || (i
&& (hviews
[i
] == hviews
[i
-1])))
2039 ok( i
== MY_NVIEWS
, "problem opening views\n");
2041 for (i
=0; i
<MY_NVIEWS
; i
++) {
2042 if (hviews
[i
] != 0 && hviews
[i
] != 0xdeadbeeb) {
2043 r
= MsiCloseHandle(hviews
[i
]);
2044 if (r
!= ERROR_SUCCESS
)
2049 ok( i
== MY_NVIEWS
, "problem closing views\n");
2051 r
= MsiCloseHandle(hdb
);
2052 ok( r
== ERROR_SUCCESS
, "failed to close database\n");
2055 static void generate_transform(void)
2057 MSIHANDLE hdb1
, hdb2
, hrec
;
2061 /* start with two identical databases */
2062 CopyFile(msifile2
, msifile
, FALSE
);
2064 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb1
);
2065 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2067 r
= MsiDatabaseCommit( hdb1
);
2068 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
2070 r
= MsiOpenDatabase(msifile2
, MSIDBOPEN_READONLY
, &hdb2
);
2071 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2073 /* the transform between two identical database should be empty */
2074 r
= MsiDatabaseGenerateTransform(hdb1
, hdb2
, NULL
, 0, 0);
2076 ok( r
== ERROR_NO_DATA
, "return code %d, should be ERROR_NO_DATA\n", r
);
2079 query
= "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
2080 r
= run_query(hdb1
, 0, query
);
2081 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2083 query
= "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
2084 r
= run_query(hdb1
, 0, query
);
2085 ok(r
== ERROR_SUCCESS
, "failed to add row 1\n");
2087 query
= "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
2088 r
= run_query(hdb1
, 0, query
);
2089 ok(r
== ERROR_SUCCESS
, "failed to add row 2\n");
2091 query
= "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
2092 r
= run_query(hdb1
, 0, query
);
2093 ok(r
== ERROR_SUCCESS
, "failed to modify row\n");
2095 query
= "DELETE FROM `MOO` WHERE `NOO` = 3";
2096 r
= run_query(hdb1
, 0, query
);
2097 ok(r
== ERROR_SUCCESS
, "failed to delete row\n");
2099 hrec
= MsiCreateRecord(2);
2100 r
= MsiRecordSetInteger(hrec
, 1, 1);
2101 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
2103 write_file("testdata.bin", "naengmyon", 9);
2104 r
= MsiRecordSetStream(hrec
, 2, "testdata.bin");
2105 ok(r
== ERROR_SUCCESS
, "failed to set stream\n");
2107 query
= "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2108 r
= run_query(hdb1
, hrec
, query
);
2109 ok(r
== ERROR_SUCCESS
, "failed to add row with blob\n");
2111 MsiCloseHandle(hrec
);
2113 query
= "ALTER TABLE `MOO` ADD `COW` INTEGER";
2114 r
= run_query(hdb1
, 0, query
);
2115 ok(r
== ERROR_SUCCESS
, "failed to add column\n");
2117 query
= "ALTER TABLE `MOO` ADD `PIG` INTEGER";
2118 r
= run_query(hdb1
, 0, query
);
2119 ok(r
== ERROR_SUCCESS
, "failed to add column\n");
2121 query
= "UPDATE `MOO` SET `PIG` = 5 WHERE `NOO` = 1";
2122 r
= run_query(hdb1
, 0, query
);
2123 ok(r
== ERROR_SUCCESS
, "failed to modify row\n");
2125 query
= "CREATE TABLE `Property` ( `Property` CHAR(72) NOT NULL, "
2126 "`Value` CHAR(0) PRIMARY KEY `Property`)";
2127 r
= run_query(hdb1
, 0, query
);
2128 ok(r
== ERROR_SUCCESS
, "failed to add property table\n");
2130 query
= "INSERT INTO `Property` ( `Property`, `Value` ) VALUES ( 'prop', 'val' )";
2131 r
= run_query(hdb1
, 0, query
);
2132 ok(r
== ERROR_SUCCESS
, "failed to add property\n");
2134 /* database needs to be committed */
2135 MsiDatabaseCommit(hdb1
);
2137 r
= MsiDatabaseGenerateTransform(hdb1
, hdb2
, mstfile
, 0, 0);
2138 ok( r
== ERROR_SUCCESS
, "return code %d, should be ERROR_SUCCESS\n", r
);
2140 MsiCloseHandle( hdb1
);
2141 MsiCloseHandle( hdb2
);
2143 DeleteFile("testdata.bin");
2146 /* data for generating a transform */
2148 /* tables transform names - encoded as they would be in an msi database file */
2149 static const WCHAR name1
[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
2150 static const WCHAR name2
[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
2151 static const WCHAR name3
[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
2152 static const WCHAR name4
[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
2153 static const WCHAR name5
[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
2154 static const WCHAR name6
[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
2155 static const WCHAR name7
[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
2156 static const WCHAR name8
[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
2157 static const WCHAR name9
[] = { 0x4840, 0x4559, 0x44f2, 0x4568, 0x4737, 0 }; /* Property */
2159 /* data in each table */
2160 static const WCHAR data1
[] = { /* AAR */
2161 0x0201, 0x0008, 0x8001, /* 0x0201 = add row (1), two shorts */
2162 0x0201, 0x0009, 0x8002,
2164 static const WCHAR data2
[] = { /* _Columns */
2165 0x0401, 0x0001, 0x8003, 0x0002, 0x9502,
2166 0x0401, 0x0001, 0x8004, 0x0003, 0x9502,
2167 0x0401, 0x0005, 0x0000, 0x0006, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
2168 0x0401, 0x0005, 0x0000, 0x0007, 0x8502,
2169 0x0401, 0x000a, 0x0000, 0x000a, 0xad48,
2170 0x0401, 0x000a, 0x0000, 0x000b, 0x9d00,
2172 static const WCHAR data3
[] = { /* _Tables */
2173 0x0101, 0x0005, /* 0x0101 = add row (1), 1 short */
2176 static const char data4
[] = /* _StringData */
2177 "MOOCOWPIGcAARCARBARvwbmwPropertyValuepropval"; /* all the strings squashed together */
2178 static const WCHAR data5
[] = { /* _StringPool */
2180 0, 0, /* string 0 '' */
2181 3, 2, /* string 1 'MOO' */
2182 3, 1, /* string 2 'COW' */
2183 3, 1, /* string 3 'PIG' */
2184 1, 1, /* string 4 'c' */
2185 3, 3, /* string 5 'AAR' */
2186 3, 1, /* string 6 'CAR' */
2187 3, 1, /* string 7 'BAR' */
2188 2, 1, /* string 8 'vw' */
2189 3, 1, /* string 9 'bmw' */
2190 8, 4, /* string 10 'Property' */
2191 5, 1, /* string 11 'Value' */
2192 4, 1, /* string 12 'prop' */
2193 3, 1, /* string 13 'val' */
2195 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
2196 static const WCHAR data6
[] = { /* MOO */
2197 0x000a, 0x8001, 0x0004, 0x8005, /* update row */
2198 0x0000, 0x8003, /* delete row */
2201 static const WCHAR data7
[] = { /* BINARY */
2202 0x0201, 0x8001, 0x0001,
2205 static const char data8
[] = /* stream data for the BINARY table */
2208 static const WCHAR data9
[] = { /* Property */
2209 0x0201, 0x000c, 0x000d,
2212 static const struct {
2216 } table_transform_data
[] =
2218 { name1
, data1
, sizeof data1
},
2219 { name2
, data2
, sizeof data2
},
2220 { name3
, data3
, sizeof data3
},
2221 { name4
, data4
, sizeof data4
- 1 },
2222 { name5
, data5
, sizeof data5
},
2223 { name6
, data6
, sizeof data6
},
2224 { name7
, data7
, sizeof data7
},
2225 { name8
, data8
, sizeof data8
- 1 },
2226 { name9
, data9
, sizeof data9
},
2229 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
2231 static void generate_transform_manual(void)
2233 IStorage
*stg
= NULL
;
2238 const DWORD mode
= STGM_CREATE
|STGM_READWRITE
|STGM_DIRECT
|STGM_SHARE_EXCLUSIVE
;
2240 const CLSID CLSID_MsiTransform
= { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
2242 MultiByteToWideChar(CP_ACP
, 0, mstfile
, -1, name
, 0x20);
2244 r
= StgCreateDocfile(name
, mode
, 0, &stg
);
2245 ok(r
== S_OK
, "failed to create storage\n");
2249 r
= IStorage_SetClass( stg
, &CLSID_MsiTransform
);
2250 ok(r
== S_OK
, "failed to set storage type\n");
2252 for (i
=0; i
<NUM_TRANSFORM_TABLES
; i
++)
2254 r
= IStorage_CreateStream( stg
, table_transform_data
[i
].name
,
2255 STGM_WRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
2258 ok(0, "failed to create stream %08x\n", r
);
2262 r
= IStream_Write( stm
, table_transform_data
[i
].data
,
2263 table_transform_data
[i
].size
, &count
);
2264 if (FAILED(r
) || count
!= table_transform_data
[i
].size
)
2265 ok(0, "failed to write stream\n");
2266 IStream_Release(stm
);
2269 IStorage_Release(stg
);
2272 static UINT
set_summary_info(MSIHANDLE hdb
)
2277 /* build summmary info */
2278 res
= MsiGetSummaryInformation(hdb
, NULL
, 7, &suminfo
);
2279 ok( res
== ERROR_SUCCESS
, "Failed to open summaryinfo\n" );
2281 res
= MsiSummaryInfoSetProperty(suminfo
,2, VT_LPSTR
, 0,NULL
,
2282 "Installation Database");
2283 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2285 res
= MsiSummaryInfoSetProperty(suminfo
,3, VT_LPSTR
, 0,NULL
,
2286 "Installation Database");
2287 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2289 res
= MsiSummaryInfoSetProperty(suminfo
,4, VT_LPSTR
, 0,NULL
,
2291 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2293 res
= MsiSummaryInfoSetProperty(suminfo
,7, VT_LPSTR
, 0,NULL
,
2295 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2297 res
= MsiSummaryInfoSetProperty(suminfo
,9, VT_LPSTR
, 0,NULL
,
2298 "{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}");
2299 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2301 res
= MsiSummaryInfoSetProperty(suminfo
, 14, VT_I4
, 100, NULL
, NULL
);
2302 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2304 res
= MsiSummaryInfoSetProperty(suminfo
, 15, VT_I4
, 0, NULL
, NULL
);
2305 ok( res
== ERROR_SUCCESS
, "Failed to set summary info\n" );
2307 res
= MsiSummaryInfoPersist(suminfo
);
2308 ok( res
== ERROR_SUCCESS
, "Failed to make summary info persist\n" );
2310 res
= MsiCloseHandle( suminfo
);
2311 ok( res
== ERROR_SUCCESS
, "Failed to close suminfo\n" );
2316 static MSIHANDLE
create_package_db(LPCSTR filename
)
2321 DeleteFile(msifile
);
2323 /* create an empty database */
2324 res
= MsiOpenDatabase(filename
, MSIDBOPEN_CREATE
, &hdb
);
2325 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
2326 if( res
!= ERROR_SUCCESS
)
2329 res
= MsiDatabaseCommit( hdb
);
2330 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
2332 res
= set_summary_info(hdb
);
2334 res
= run_query( hdb
, 0,
2335 "CREATE TABLE `Directory` ( "
2336 "`Directory` CHAR(255) NOT NULL, "
2337 "`Directory_Parent` CHAR(255), "
2338 "`DefaultDir` CHAR(255) NOT NULL "
2339 "PRIMARY KEY `Directory`)" );
2340 ok( res
== ERROR_SUCCESS
, "Failed to create directory table\n" );
2345 static MSIHANDLE
package_from_db(MSIHANDLE hdb
)
2351 sprintf(szPackage
,"#%li",hdb
);
2352 res
= MsiOpenPackage(szPackage
,&hPackage
);
2353 if (res
!= ERROR_SUCCESS
)
2356 res
= MsiCloseHandle(hdb
);
2357 if (res
!= ERROR_SUCCESS
)
2363 static void test_try_transform(void)
2365 MSIHANDLE hdb
, hview
, hrec
, hpkg
;
2369 char buffer
[MAX_PATH
];
2371 DeleteFile(msifile
);
2372 DeleteFile(mstfile
);
2374 /* create the database */
2375 hdb
= create_package_db(msifile
);
2376 ok(hdb
, "Failed to create package db\n");
2378 query
= "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
2379 r
= run_query(hdb
, 0, query
);
2380 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2382 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
2383 r
= run_query(hdb
, 0, query
);
2384 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2386 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
2387 r
= run_query(hdb
, 0, query
);
2388 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2390 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
2391 r
= run_query(hdb
, 0, query
);
2392 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
2394 query
= "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
2395 r
= run_query(hdb
, 0, query
);
2396 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2398 hrec
= MsiCreateRecord(2);
2399 r
= MsiRecordSetInteger(hrec
, 1, 2);
2400 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
2402 write_file("testdata.bin", "lamyon", 6);
2403 r
= MsiRecordSetStream(hrec
, 2, "testdata.bin");
2404 ok(r
== ERROR_SUCCESS
, "failed to set stream\n");
2406 query
= "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
2407 r
= run_query(hdb
, hrec
, query
);
2408 ok(r
== ERROR_SUCCESS
, "failed to add row with blob\n");
2410 MsiCloseHandle(hrec
);
2412 r
= MsiDatabaseCommit( hdb
);
2413 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
2415 MsiCloseHandle( hdb
);
2416 DeleteFileA("testdata.bin");
2419 * Both these generate an equivalent transform,
2420 * but the first doesn't work in Wine yet
2421 * because MsiDatabaseGenerateTransform is unimplemented.
2424 generate_transform();
2426 generate_transform_manual();
2428 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_DIRECT
, &hdb
);
2429 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2431 r
= MsiDatabaseApplyTransform( hdb
, mstfile
, 0 );
2432 ok( r
== ERROR_SUCCESS
, "return code %d, should be ERROR_SUCCESS\n", r
);
2434 MsiDatabaseCommit( hdb
);
2436 /* check new values */
2438 query
= "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
2439 r
= do_query(hdb
, query
, &hrec
);
2440 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2441 MsiCloseHandle(hrec
);
2443 query
= "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
2445 r
= do_query(hdb
, query
, &hrec
);
2446 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2447 MsiCloseHandle(hrec
);
2449 /* check updated values */
2451 query
= "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
2452 r
= do_query(hdb
, query
, &hrec
);
2453 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2454 MsiCloseHandle(hrec
);
2456 /* check unchanged value */
2458 query
= "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
2459 r
= do_query(hdb
, query
, &hrec
);
2460 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2461 MsiCloseHandle(hrec
);
2463 /* check deleted value */
2465 query
= "select * from `MOO` where `NOO` = 3";
2466 r
= do_query(hdb
, query
, &hrec
);
2467 ok(r
== ERROR_NO_MORE_ITEMS
, "select query failed\n");
2468 if (hrec
) MsiCloseHandle(hrec
);
2470 /* check added stream */
2472 query
= "select `BLOB` from `BINARY` where `ID` = 1";
2473 r
= do_query(hdb
, query
, &hrec
);
2474 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2476 /* check the contents of the stream */
2478 r
= MsiRecordReadStream( hrec
, 1, buffer
, &sz
);
2479 ok(r
== ERROR_SUCCESS
, "read stream failed\n");
2480 ok(!memcmp(buffer
, "naengmyon", 9), "stream data was wrong\n");
2481 ok(sz
== 9, "stream data was wrong size\n");
2482 if (hrec
) MsiCloseHandle(hrec
);
2484 /* check the validity of the table with a deleted row */
2486 query
= "select * from `MOO`";
2487 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2488 ok(r
== ERROR_SUCCESS
, "open view failed\n");
2490 r
= MsiViewExecute(hview
, 0);
2491 ok(r
== ERROR_SUCCESS
, "view execute failed\n");
2493 r
= MsiViewFetch(hview
, &hrec
);
2494 ok(r
== ERROR_SUCCESS
, "view fetch failed\n");
2496 r
= MsiRecordGetInteger(hrec
, 1);
2497 ok(r
== 1, "Expected 1, got %d\n", r
);
2500 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
2501 ok(r
== ERROR_SUCCESS
, "record get string failed\n");
2502 ok(!lstrcmpA(buffer
, "c"), "Expected c, got %s\n", buffer
);
2504 r
= MsiRecordGetInteger(hrec
, 3);
2505 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
2507 r
= MsiRecordGetInteger(hrec
, 4);
2508 ok(r
== 5, "Expected 5, got %d\n", r
);
2510 MsiCloseHandle(hrec
);
2512 r
= MsiViewFetch(hview
, &hrec
);
2513 ok(r
== ERROR_SUCCESS
, "view fetch failed\n");
2515 r
= MsiRecordGetInteger(hrec
, 1);
2516 ok(r
== 2, "Expected 2, got %d\n", r
);
2519 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
2520 ok(r
== ERROR_SUCCESS
, "record get string failed\n");
2521 ok(!lstrcmpA(buffer
, "b"), "Expected b, got %s\n", buffer
);
2523 r
= MsiRecordGetInteger(hrec
, 3);
2524 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
2526 r
= MsiRecordGetInteger(hrec
, 4);
2527 ok(r
== 0x80000000, "Expected 0x80000000, got %d\n", r
);
2529 MsiCloseHandle(hrec
);
2531 r
= MsiViewFetch(hview
, &hrec
);
2532 ok(r
== ERROR_NO_MORE_ITEMS
, "view fetch succeeded\n");
2534 MsiCloseHandle(hrec
);
2535 MsiCloseHandle(hview
);
2537 /* check that the property was added */
2538 hpkg
= package_from_db(hdb
);
2539 ok(hpkg
!= 0, "Expected non-NULL hpkg\n");
2542 r
= MsiGetProperty(hpkg
, "prop", buffer
, &sz
);
2543 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2544 ok(!lstrcmp(buffer
, "val"), "Expected val, got %s\n", buffer
);
2546 MsiCloseHandle(hpkg
);
2547 MsiCloseHandle(hdb
);
2549 DeleteFile(msifile
);
2550 DeleteFile(mstfile
);
2555 const CHAR one
[MAX_PATH
];
2556 const CHAR two
[MAX_PATH
];
2559 struct join_res_4col
2561 const CHAR one
[MAX_PATH
];
2562 const CHAR two
[MAX_PATH
];
2563 const CHAR three
[MAX_PATH
];
2564 const CHAR four
[MAX_PATH
];
2567 struct join_res_uint
2577 static const struct join_res join_res_first
[] =
2579 { "alveolar", "procerus" },
2580 { "septum", "procerus" },
2581 { "septum", "nasalis" },
2582 { "ramus", "nasalis" },
2583 { "malar", "mentalis" },
2586 static const struct join_res join_res_second
[] =
2588 { "nasal", "septum" },
2589 { "mandible", "ramus" },
2592 static const struct join_res join_res_third
[] =
2594 { "msvcp.dll", "abcdefgh" },
2595 { "msvcr.dll", "ijklmnop" },
2598 static const struct join_res join_res_fourth
[] =
2600 { "msvcp.dll.01234", "single.dll.31415" },
2603 static const struct join_res join_res_fifth
[] =
2605 { "malar", "procerus" },
2608 static const struct join_res join_res_sixth
[] =
2610 { "malar", "procerus" },
2611 { "malar", "procerus" },
2612 { "malar", "nasalis" },
2613 { "malar", "nasalis" },
2614 { "malar", "nasalis" },
2615 { "malar", "mentalis" },
2618 static const struct join_res join_res_seventh
[] =
2620 { "malar", "nasalis" },
2621 { "malar", "nasalis" },
2622 { "malar", "nasalis" },
2625 static const struct join_res_4col join_res_eighth
[] =
2627 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
2628 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
2629 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
2630 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
2631 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
2632 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
2635 static const struct join_res_uint join_res_ninth
[] =
2637 { 1, 2, 3, 4, 7, 8 },
2638 { 1, 2, 5, 6, 7, 8 },
2639 { 1, 2, 3, 4, 9, 10 },
2640 { 1, 2, 5, 6, 9, 10 },
2641 { 1, 2, 3, 4, 11, 12 },
2642 { 1, 2, 5, 6, 11, 12 },
2645 static void test_join(void)
2647 MSIHANDLE hdb
, hview
, hrec
;
2655 ok( hdb
, "failed to create db\n");
2657 r
= create_component_table( hdb
);
2658 ok( r
== ERROR_SUCCESS
, "cannot create Component table: %d\n", r
);
2660 r
= add_component_entry( hdb
, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
2661 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2663 r
= add_component_entry( hdb
, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
2664 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2666 r
= add_component_entry( hdb
, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
2667 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2669 r
= add_component_entry( hdb
, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
2670 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2672 r
= create_feature_components_table( hdb
);
2673 ok( r
== ERROR_SUCCESS
, "cannot create FeatureComponents table: %d\n", r
);
2675 r
= add_feature_components_entry( hdb
, "'procerus', 'maxilla'" );
2676 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2678 r
= add_feature_components_entry( hdb
, "'procerus', 'nasal'" );
2679 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2681 r
= add_feature_components_entry( hdb
, "'nasalis', 'nasal'" );
2682 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2684 r
= add_feature_components_entry( hdb
, "'nasalis', 'mandible'" );
2685 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2687 r
= add_feature_components_entry( hdb
, "'nasalis', 'notacomponent'" );
2688 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2690 r
= add_feature_components_entry( hdb
, "'mentalis', 'zygomatic'" );
2691 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2693 r
= create_std_dlls_table( hdb
);
2694 ok( r
== ERROR_SUCCESS
, "cannot create StdDlls table: %d\n", r
);
2696 r
= add_std_dlls_entry( hdb
, "'msvcp.dll', 'msvcp.dll.01234'" );
2697 ok( r
== ERROR_SUCCESS
, "cannot add std dlls: %d\n", r
);
2699 r
= add_std_dlls_entry( hdb
, "'msvcr.dll', 'msvcr.dll.56789'" );
2700 ok( r
== ERROR_SUCCESS
, "cannot add std dlls: %d\n", r
);
2702 r
= create_binary_table( hdb
);
2703 ok( r
== ERROR_SUCCESS
, "cannot create Binary table: %d\n", r
);
2705 r
= add_binary_entry( hdb
, "'msvcp.dll.01234', 'abcdefgh'" );
2706 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
2708 r
= add_binary_entry( hdb
, "'msvcr.dll.56789', 'ijklmnop'" );
2709 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
2711 r
= add_binary_entry( hdb
, "'single.dll.31415', 'msvcp.dll'" );
2712 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
2714 query
= "CREATE TABLE `One` (`A` SHORT, `B` SHORT PRIMARY KEY `A`)";
2715 r
= run_query( hdb
, 0, query
);
2716 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2718 query
= "CREATE TABLE `Two` (`C` SHORT, `D` SHORT PRIMARY KEY `C`)";
2719 r
= run_query( hdb
, 0, query
);
2720 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2722 query
= "CREATE TABLE `Three` (`E` SHORT, `F` SHORT PRIMARY KEY `E`)";
2723 r
= run_query( hdb
, 0, query
);
2724 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2726 query
= "INSERT INTO `One` (`A`, `B`) VALUES (1, 2)";
2727 r
= run_query( hdb
, 0, query
);
2728 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2730 query
= "INSERT INTO `Two` (`C`, `D`) VALUES (3, 4)";
2731 r
= run_query( hdb
, 0, query
);
2732 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2734 query
= "INSERT INTO `Two` (`C`, `D`) VALUES (5, 6)";
2735 r
= run_query( hdb
, 0, query
);
2736 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2738 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (7, 8)";
2739 r
= run_query( hdb
, 0, query
);
2740 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2742 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (9, 10)";
2743 r
= run_query( hdb
, 0, query
);
2744 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2746 query
= "INSERT INTO `Three` (`E`, `F`) VALUES (11, 12)";
2747 r
= run_query( hdb
, 0, query
);
2748 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2750 query
= "CREATE TABLE `Four` (`G` SHORT, `H` SHORT PRIMARY KEY `G`)";
2751 r
= run_query( hdb
, 0, query
);
2752 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2754 query
= "CREATE TABLE `Five` (`I` SHORT, `J` SHORT PRIMARY KEY `I`)";
2755 r
= run_query( hdb
, 0, query
);
2756 ok(r
== ERROR_SUCCESS
, "cannot create table: %d\n", r
);
2758 query
= "INSERT INTO `Five` (`I`, `J`) VALUES (13, 14)";
2759 r
= run_query( hdb
, 0, query
);
2760 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2762 query
= "INSERT INTO `Five` (`I`, `J`) VALUES (15, 16)";
2763 r
= run_query( hdb
, 0, query
);
2764 ok(r
== ERROR_SUCCESS
, "cannot insert into table: %d\n", r
);
2766 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2767 "FROM `Component`, `FeatureComponents` "
2768 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
2769 "ORDER BY `Feature_`";
2770 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2771 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2773 r
= MsiViewExecute(hview
, 0);
2774 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2777 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2779 count
= MsiRecordGetFieldCount( hrec
);
2780 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2783 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2784 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2785 ok( !lstrcmp( buf
, join_res_first
[i
].one
),
2786 "For (row %d, column 1) expected '%s', got %s\n", i
, join_res_first
[i
].one
, buf
);
2789 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2790 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2791 ok( !lstrcmp( buf
, join_res_first
[i
].two
),
2792 "For (row %d, column 2) expected '%s', got %s\n", i
, join_res_first
[i
].two
, buf
);
2795 MsiCloseHandle(hrec
);
2798 ok( i
== 5, "Expected 5 rows, got %d\n", i
);
2799 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2801 MsiViewClose(hview
);
2802 MsiCloseHandle(hview
);
2804 /* try a join without a WHERE condition */
2805 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2806 "FROM `Component`, `FeatureComponents` ";
2807 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2808 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2810 r
= MsiViewExecute(hview
, 0);
2811 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2814 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2817 MsiCloseHandle(hrec
);
2819 ok( i
== 24, "Expected 24 rows, got %d\n", i
);
2821 MsiViewClose(hview
);
2822 MsiCloseHandle(hview
);
2824 query
= "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
2825 "WHERE FeatureComponents.Component_=Component.Component "
2826 "AND (Feature_='nasalis') ORDER BY Feature_";
2827 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2828 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2830 r
= MsiViewExecute(hview
, 0);
2831 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2834 data_correct
= TRUE
;
2835 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2837 count
= MsiRecordGetFieldCount( hrec
);
2838 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2841 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2842 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2843 if( lstrcmp( buf
, join_res_second
[i
].one
))
2844 data_correct
= FALSE
;
2847 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2848 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2849 if( lstrcmp( buf
, join_res_second
[i
].two
))
2850 data_correct
= FALSE
;
2853 MsiCloseHandle(hrec
);
2856 ok( data_correct
, "data returned in the wrong order\n");
2858 ok( i
== 2, "Expected 2 rows, got %d\n", i
);
2859 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2861 MsiViewClose(hview
);
2862 MsiCloseHandle(hview
);
2864 query
= "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2865 "FROM `StdDlls`, `Binary` "
2866 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
2868 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2869 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2871 r
= MsiViewExecute(hview
, 0);
2872 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2875 data_correct
= TRUE
;
2876 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2878 count
= MsiRecordGetFieldCount( hrec
);
2879 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2882 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2883 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2884 if( lstrcmp( buf
, join_res_third
[i
].one
) )
2885 data_correct
= FALSE
;
2888 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2889 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2890 if( lstrcmp( buf
, join_res_third
[i
].two
) )
2891 data_correct
= FALSE
;
2894 MsiCloseHandle(hrec
);
2896 ok( data_correct
, "data returned in the wrong order\n");
2898 ok( i
== 2, "Expected 2 rows, got %d\n", i
);
2900 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2902 MsiViewClose(hview
);
2903 MsiCloseHandle(hview
);
2905 query
= "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
2906 "FROM `StdDlls`, `Binary` "
2907 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
2909 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2910 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2912 r
= MsiViewExecute(hview
, 0);
2913 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2916 data_correct
= TRUE
;
2917 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2919 count
= MsiRecordGetFieldCount( hrec
);
2920 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2923 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2924 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2925 if( lstrcmp( buf
, join_res_fourth
[i
].one
))
2926 data_correct
= FALSE
;
2929 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2930 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2931 if( lstrcmp( buf
, join_res_fourth
[i
].two
))
2932 data_correct
= FALSE
;
2935 MsiCloseHandle(hrec
);
2937 ok( data_correct
, "data returned in the wrong order\n");
2939 ok( i
== 1, "Expected 1 rows, got %d\n", i
);
2940 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2942 MsiViewClose(hview
);
2943 MsiCloseHandle(hview
);
2945 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2946 "FROM `Component`, `FeatureComponents` "
2947 "WHERE `Component`.`Component` = 'zygomatic' "
2948 "AND `FeatureComponents`.`Component_` = 'maxilla' "
2949 "ORDER BY `Feature_`";
2950 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2951 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2953 r
= MsiViewExecute(hview
, 0);
2954 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2957 data_correct
= TRUE
;
2958 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2960 count
= MsiRecordGetFieldCount( hrec
);
2961 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2964 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2965 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2966 if( lstrcmp( buf
, join_res_fifth
[i
].one
))
2967 data_correct
= FALSE
;
2970 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2971 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2972 if( lstrcmp( buf
, join_res_fifth
[i
].two
))
2973 data_correct
= FALSE
;
2976 MsiCloseHandle(hrec
);
2978 ok( data_correct
, "data returned in the wrong order\n");
2980 ok( i
== 1, "Expected 1 rows, got %d\n", i
);
2981 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2983 MsiViewClose(hview
);
2984 MsiCloseHandle(hview
);
2986 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2987 "FROM `Component`, `FeatureComponents` "
2988 "WHERE `Component` = 'zygomatic' "
2989 "ORDER BY `Feature_`";
2990 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2991 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2993 r
= MsiViewExecute(hview
, 0);
2994 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2997 data_correct
= TRUE
;
2998 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3000 count
= MsiRecordGetFieldCount( hrec
);
3001 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3004 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3005 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3006 if( lstrcmp( buf
, join_res_sixth
[i
].one
))
3007 data_correct
= FALSE
;
3010 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3011 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3012 if( lstrcmp( buf
, join_res_sixth
[i
].two
))
3013 data_correct
= FALSE
;
3016 MsiCloseHandle(hrec
);
3018 ok( data_correct
, "data returned in the wrong order\n");
3020 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3021 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3023 MsiViewClose(hview
);
3024 MsiCloseHandle(hview
);
3026 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
3027 "FROM `Component`, `FeatureComponents` "
3028 "WHERE `Component` = 'zygomatic' "
3029 "AND `Feature_` = 'nasalis' "
3030 "ORDER BY `Feature_`";
3031 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3032 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3034 r
= MsiViewExecute(hview
, 0);
3035 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3038 data_correct
= TRUE
;
3039 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3041 count
= MsiRecordGetFieldCount( hrec
);
3042 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3045 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3046 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3047 if( lstrcmp( buf
, join_res_seventh
[i
].one
))
3048 data_correct
= FALSE
;
3051 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3052 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3053 if( lstrcmp( buf
, join_res_seventh
[i
].two
))
3054 data_correct
= FALSE
;
3057 MsiCloseHandle(hrec
);
3060 ok( data_correct
, "data returned in the wrong order\n");
3061 ok( i
== 3, "Expected 3 rows, got %d\n", i
);
3062 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3064 MsiViewClose(hview
);
3065 MsiCloseHandle(hview
);
3067 query
= "SELECT `StdDlls`.`File`, `Binary`.`Data` "
3068 "FROM `StdDlls`, `Binary` ";
3069 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3070 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3072 r
= MsiViewExecute(hview
, 0);
3073 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3076 data_correct
= TRUE
;
3077 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3079 count
= MsiRecordGetFieldCount( hrec
);
3080 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
3083 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3084 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3085 if( lstrcmp( buf
, join_res_eighth
[i
].one
))
3086 data_correct
= FALSE
;
3089 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3090 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3091 if( lstrcmp( buf
, join_res_eighth
[i
].four
))
3092 data_correct
= FALSE
;
3095 MsiCloseHandle(hrec
);
3098 ok( data_correct
, "data returned in the wrong order\n");
3099 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3100 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3102 MsiViewClose(hview
);
3103 MsiCloseHandle(hview
);
3105 query
= "SELECT * FROM `StdDlls`, `Binary` ";
3106 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3107 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3109 r
= MsiViewExecute(hview
, 0);
3110 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3113 data_correct
= TRUE
;
3114 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3116 count
= MsiRecordGetFieldCount( hrec
);
3117 ok( count
== 4, "Expected 4 record fields, got %d\n", count
);
3120 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
3121 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3122 if( lstrcmp( buf
, join_res_eighth
[i
].one
))
3123 data_correct
= FALSE
;
3126 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
3127 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3128 if( lstrcmp( buf
, join_res_eighth
[i
].two
))
3129 data_correct
= FALSE
;
3132 r
= MsiRecordGetString( hrec
, 3, buf
, &size
);
3133 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3134 if( lstrcmp( buf
, join_res_eighth
[i
].three
))
3135 data_correct
= FALSE
;
3138 r
= MsiRecordGetString( hrec
, 4, buf
, &size
);
3139 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
3140 if( lstrcmp( buf
, join_res_eighth
[i
].four
))
3141 data_correct
= FALSE
;
3144 MsiCloseHandle(hrec
);
3146 ok( data_correct
, "data returned in the wrong order\n");
3148 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3149 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3151 MsiViewClose(hview
);
3152 MsiCloseHandle(hview
);
3154 query
= "SELECT * FROM `One`, `Two`, `Three` ";
3155 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3156 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3158 r
= MsiViewExecute(hview
, 0);
3159 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3162 data_correct
= TRUE
;
3163 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
3165 count
= MsiRecordGetFieldCount( hrec
);
3166 ok( count
== 6, "Expected 6 record fields, got %d\n", count
);
3168 r
= MsiRecordGetInteger( hrec
, 1 );
3169 if( r
!= join_res_ninth
[i
].one
)
3170 data_correct
= FALSE
;
3172 r
= MsiRecordGetInteger( hrec
, 2 );
3173 if( r
!= join_res_ninth
[i
].two
)
3174 data_correct
= FALSE
;
3176 r
= MsiRecordGetInteger( hrec
, 3 );
3177 if( r
!= join_res_ninth
[i
].three
)
3178 data_correct
= FALSE
;
3180 r
= MsiRecordGetInteger( hrec
, 4 );
3181 if( r
!= join_res_ninth
[i
].four
)
3182 data_correct
= FALSE
;
3184 r
= MsiRecordGetInteger( hrec
, 5 );
3185 if( r
!= join_res_ninth
[i
].five
)
3186 data_correct
= FALSE
;
3188 r
= MsiRecordGetInteger( hrec
, 6);
3189 if( r
!= join_res_ninth
[i
].six
)
3190 data_correct
= FALSE
;
3193 MsiCloseHandle(hrec
);
3195 ok( data_correct
, "data returned in the wrong order\n");
3197 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
3198 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
3200 MsiViewClose(hview
);
3201 MsiCloseHandle(hview
);
3203 query
= "SELECT * FROM `Four`, `Five`";
3204 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3205 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
3207 r
= MsiViewExecute(hview
, 0);
3208 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
3210 r
= MsiViewFetch(hview
, &hrec
);
3211 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3213 MsiViewClose(hview
);
3214 MsiCloseHandle(hview
);
3216 query
= "SELECT * FROM `Nonexistent`, `One`";
3217 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
3218 ok( r
== ERROR_BAD_QUERY_SYNTAX
,
3219 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3221 MsiCloseHandle(hdb
);
3222 DeleteFile(msifile
);
3225 static void test_temporary_table(void)
3228 MSIHANDLE hdb
= 0, view
= 0, rec
;
3234 cond
= MsiDatabaseIsTablePersistent(0, NULL
);
3235 ok( cond
== MSICONDITION_ERROR
, "wrong return condition\n");
3238 ok( hdb
, "failed to create db\n");
3240 cond
= MsiDatabaseIsTablePersistent(hdb
, NULL
);
3241 ok( cond
== MSICONDITION_ERROR
, "wrong return condition\n");
3244 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Tables");
3245 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3247 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Columns");
3248 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3251 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Streams");
3252 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3254 query
= "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
3255 r
= run_query(hdb
, 0, query
);
3256 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3258 cond
= MsiDatabaseIsTablePersistent(hdb
, "P");
3259 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3261 query
= "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
3262 r
= run_query(hdb
, 0, query
);
3263 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3265 cond
= MsiDatabaseIsTablePersistent(hdb
, "P2");
3266 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3268 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3269 r
= run_query(hdb
, 0, query
);
3270 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3272 cond
= MsiDatabaseIsTablePersistent(hdb
, "T");
3273 ok( cond
== MSICONDITION_FALSE
, "wrong return condition\n");
3275 query
= "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3276 r
= run_query(hdb
, 0, query
);
3277 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3280 cond
= MsiDatabaseIsTablePersistent(hdb
, "T2");
3281 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3284 query
= "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
3285 r
= run_query(hdb
, 0, query
);
3286 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3288 cond
= MsiDatabaseIsTablePersistent(hdb
, "T3");
3289 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
3292 query
= "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
3293 r
= run_query(hdb
, 0, query
);
3294 ok(r
== ERROR_FUNCTION_FAILED
, "failed to add table\n");
3296 cond
= MsiDatabaseIsTablePersistent(hdb
, "T4");
3297 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
3300 query
= "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
3301 r
= run_query(hdb
, 0, query
);
3302 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to add table\n");
3304 query
= "select * from `T`";
3305 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3306 ok(r
== ERROR_SUCCESS
, "failed to query table\n");
3307 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
3308 ok(r
== ERROR_SUCCESS
, "failed to get column info\n");
3311 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
3312 ok(r
== ERROR_SUCCESS
, "failed to get string\n");
3313 todo_wine
ok( 0 == strcmp("G255", buf
), "wrong column type\n");
3316 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
3317 ok(r
== ERROR_SUCCESS
, "failed to get string\n");
3318 todo_wine
ok( 0 == strcmp("j2", buf
), "wrong column type\n");
3320 MsiCloseHandle( rec
);
3321 MsiCloseHandle( view
);
3323 /* query the table data */
3325 r
= do_query(hdb
, "select * from `_Tables` where `Name` = 'T'", &rec
);
3326 ok( r
== ERROR_SUCCESS
, "temporary table exists in _Tables\n");
3327 MsiCloseHandle( rec
);
3329 /* query the column data */
3331 r
= do_query(hdb
, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec
);
3332 ok( r
== ERROR_NO_MORE_ITEMS
, "temporary table exists in _Columns\n");
3333 if (rec
) MsiCloseHandle( rec
);
3335 r
= do_query(hdb
, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec
);
3336 ok( r
== ERROR_NO_MORE_ITEMS
, "temporary table exists in _Columns\n");
3337 if (rec
) MsiCloseHandle( rec
);
3339 MsiCloseHandle( hdb
);
3341 DeleteFile(msifile
);
3344 static void test_alter(void)
3352 ok( hdb
, "failed to create db\n");
3354 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
3355 r
= run_query(hdb
, 0, query
);
3356 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
3358 cond
= MsiDatabaseIsTablePersistent(hdb
, "T");
3359 ok( cond
== MSICONDITION_FALSE
, "wrong return condition\n");
3361 query
= "ALTER TABLE `T` HOLD";
3362 r
= run_query(hdb
, 0, query
);
3363 ok(r
== ERROR_SUCCESS
, "failed to hold table %d\n", r
);
3365 query
= "ALTER TABLE `T` FREE";
3366 r
= run_query(hdb
, 0, query
);
3367 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
3369 query
= "ALTER TABLE `T` FREE";
3370 r
= run_query(hdb
, 0, query
);
3371 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
3373 query
= "ALTER TABLE `T` FREE";
3374 r
= run_query(hdb
, 0, query
);
3375 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to free table\n");
3377 query
= "ALTER TABLE `T` HOLD";
3378 r
= run_query(hdb
, 0, query
);
3379 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to hold table %d\n", r
);
3381 /* table T is removed */
3382 query
= "SELECT * FROM `T`";
3383 r
= run_query(hdb
, 0, query
);
3384 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3386 /* create the table again */
3387 query
= "CREATE TABLE `U` ( `A` INTEGER, `B` INTEGER PRIMARY KEY `B`)";
3388 r
= run_query(hdb
, 0, query
);
3389 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3391 /* up the ref count */
3392 query
= "ALTER TABLE `U` HOLD";
3393 r
= run_query(hdb
, 0, query
);
3394 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
3396 /* add column, no data type */
3397 query
= "ALTER TABLE `U` ADD `C`";
3398 r
= run_query(hdb
, 0, query
);
3399 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3401 query
= "ALTER TABLE `U` ADD `C` INTEGER";
3402 r
= run_query(hdb
, 0, query
);
3403 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3405 /* add column C again */
3406 query
= "ALTER TABLE `U` ADD `C` INTEGER";
3407 r
= run_query(hdb
, 0, query
);
3408 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3410 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY";
3411 r
= run_query(hdb
, 0, query
);
3412 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3414 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 1, 2, 3, 4 )";
3415 r
= run_query(hdb
, 0, query
);
3416 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3418 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY HOLD";
3419 r
= run_query(hdb
, 0, query
);
3420 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3422 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 5, 6, 7, 8 )";
3423 r
= run_query(hdb
, 0, query
);
3424 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3426 query
= "SELECT * FROM `U` WHERE `D` = 8";
3427 r
= run_query(hdb
, 0, query
);
3428 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3430 query
= "ALTER TABLE `U` ADD `D` INTEGER TEMPORARY FREE";
3431 r
= run_query(hdb
, 0, query
);
3432 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3434 query
= "ALTER COLUMN `D` FREE";
3435 r
= run_query(hdb
, 0, query
);
3436 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3438 /* drop the ref count */
3439 query
= "ALTER TABLE `U` FREE";
3440 r
= run_query(hdb
, 0, query
);
3441 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3443 /* table is not empty */
3444 query
= "SELECT * FROM `U`";
3445 r
= run_query(hdb
, 0, query
);
3446 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3448 /* column D is removed */
3449 query
= "SELECT * FROM `U` WHERE `D` = 8";
3450 r
= run_query(hdb
, 0, query
);
3451 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3453 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `D` ) VALUES ( 9, 10, 11, 12 )";
3454 r
= run_query(hdb
, 0, query
);
3455 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3457 /* add the column again */
3458 query
= "ALTER TABLE `U` ADD `E` INTEGER TEMPORARY HOLD";
3459 r
= run_query(hdb
, 0, query
);
3460 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3462 /* up the ref count */
3463 query
= "ALTER TABLE `U` HOLD";
3464 r
= run_query(hdb
, 0, query
);
3465 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3467 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 13, 14, 15, 16 )";
3468 r
= run_query(hdb
, 0, query
);
3469 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3471 query
= "SELECT * FROM `U` WHERE `E` = 16";
3472 r
= run_query(hdb
, 0, query
);
3473 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3475 /* drop the ref count */
3476 query
= "ALTER TABLE `U` FREE";
3477 r
= run_query(hdb
, 0, query
);
3478 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3480 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 17, 18, 19, 20 )";
3481 r
= run_query(hdb
, 0, query
);
3482 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3484 query
= "SELECT * FROM `U` WHERE `E` = 20";
3485 r
= run_query(hdb
, 0, query
);
3486 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3488 /* drop the ref count */
3489 query
= "ALTER TABLE `U` FREE";
3490 r
= run_query(hdb
, 0, query
);
3491 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3493 /* table still exists */
3494 query
= "SELECT * FROM `U`";
3495 r
= run_query(hdb
, 0, query
);
3496 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3498 /* col E is removed */
3499 query
= "SELECT * FROM `U` WHERE `E` = 20";
3500 r
= run_query(hdb
, 0, query
);
3501 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3503 query
= "INSERT INTO `U` ( `A`, `B`, `C`, `E` ) VALUES ( 20, 21, 22, 23 )";
3504 r
= run_query(hdb
, 0, query
);
3505 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3507 /* drop the ref count once more */
3508 query
= "ALTER TABLE `U` FREE";
3509 r
= run_query(hdb
, 0, query
);
3510 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3512 /* table still exists */
3513 query
= "SELECT * FROM `U`";
3514 r
= run_query(hdb
, 0, query
);
3515 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3517 MsiCloseHandle( hdb
);
3518 DeleteFile(msifile
);
3521 static void test_integers(void)
3523 MSIHANDLE hdb
= 0, view
= 0, rec
= 0;
3528 /* just MsiOpenDatabase should not create a file */
3529 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
3530 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
3532 /* create a table */
3533 query
= "CREATE TABLE `integers` ( "
3534 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
3535 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
3536 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
3537 "PRIMARY KEY `one`)";
3538 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3539 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
3540 r
= MsiViewExecute(view
, 0);
3541 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
3542 r
= MsiViewClose(view
);
3543 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3544 r
= MsiCloseHandle(view
);
3545 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3547 query
= "SELECT * FROM `integers`";
3548 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3549 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3551 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
3552 count
= MsiRecordGetFieldCount(rec
);
3553 ok(count
== 8, "Expected 8, got %d\n", count
);
3554 ok(check_record(rec
, 1, "one"), "Expected one\n");
3555 ok(check_record(rec
, 2, "two"), "Expected two\n");
3556 ok(check_record(rec
, 3, "three"), "Expected three\n");
3557 ok(check_record(rec
, 4, "four"), "Expected four\n");
3558 ok(check_record(rec
, 5, "five"), "Expected five\n");
3559 ok(check_record(rec
, 6, "six"), "Expected six\n");
3560 ok(check_record(rec
, 7, "seven"), "Expected seven\n");
3561 ok(check_record(rec
, 8, "eight"), "Expected eight\n");
3562 MsiCloseHandle(rec
);
3564 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
3565 count
= MsiRecordGetFieldCount(rec
);
3566 ok(count
== 8, "Expected 8, got %d\n", count
);
3567 ok(check_record(rec
, 1, "I2"), "Expected I2\n");
3568 ok(check_record(rec
, 2, "I2"), "Expected I2\n");
3569 ok(check_record(rec
, 3, "I2"), "Expected I2\n");
3570 ok(check_record(rec
, 4, "I4"), "Expected I4\n");
3571 ok(check_record(rec
, 5, "i2"), "Expected i2\n");
3572 ok(check_record(rec
, 6, "i2"), "Expected i2\n");
3573 ok(check_record(rec
, 7, "i2"), "Expected i2\n");
3574 ok(check_record(rec
, 8, "i4"), "Expected i4\n");
3575 MsiCloseHandle(rec
);
3578 MsiCloseHandle(view
);
3580 /* insert values into it, NULL where NOT NULL is specified */
3581 query
= "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3582 "VALUES('', '', '', '', '', '', '', '')";
3583 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3584 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3585 r
= MsiViewExecute(view
, 0);
3586 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
3589 MsiCloseHandle(view
);
3591 query
= "SELECT * FROM `integers`";
3592 r
= do_query(hdb
, query
, &rec
);
3593 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3595 r
= MsiRecordGetFieldCount(rec
);
3596 ok(r
== -1, "record count wrong: %d\n", r
);
3598 MsiCloseHandle(rec
);
3600 /* insert legitimate values into it */
3601 query
= "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
3602 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
3603 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3604 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3605 r
= MsiViewExecute(view
, 0);
3606 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3608 query
= "SELECT * FROM `integers`";
3609 r
= do_query(hdb
, query
, &rec
);
3610 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3612 r
= MsiRecordGetFieldCount(rec
);
3613 ok(r
== 8, "record count wrong: %d\n", r
);
3615 i
= MsiRecordGetInteger(rec
, 1);
3616 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
3617 i
= MsiRecordGetInteger(rec
, 3);
3618 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
3619 i
= MsiRecordGetInteger(rec
, 2);
3620 ok(i
== 2, "Expected 2, got %d\n", i
);
3621 i
= MsiRecordGetInteger(rec
, 4);
3622 ok(i
== 4, "Expected 4, got %d\n", i
);
3623 i
= MsiRecordGetInteger(rec
, 5);
3624 ok(i
== 5, "Expected 5, got %d\n", i
);
3625 i
= MsiRecordGetInteger(rec
, 6);
3626 ok(i
== 6, "Expected 6, got %d\n", i
);
3627 i
= MsiRecordGetInteger(rec
, 7);
3628 ok(i
== 7, "Expected 7, got %d\n", i
);
3629 i
= MsiRecordGetInteger(rec
, 8);
3630 ok(i
== 8, "Expected 8, got %d\n", i
);
3632 MsiCloseHandle(rec
);
3634 MsiCloseHandle(view
);
3636 r
= MsiDatabaseCommit(hdb
);
3637 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
3639 r
= MsiCloseHandle(hdb
);
3640 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3642 r
= DeleteFile(msifile
);
3643 ok(r
== TRUE
, "file didn't exist after commit\n");
3646 static void test_update(void)
3648 MSIHANDLE hdb
= 0, view
= 0, rec
= 0;
3649 CHAR result
[MAX_PATH
];
3654 /* just MsiOpenDatabase should not create a file */
3655 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
3656 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
3658 /* create the Control table */
3659 query
= "CREATE TABLE `Control` ( "
3660 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
3661 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
3662 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
3663 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
3664 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3665 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
3666 r
= MsiViewExecute(view
, 0);
3667 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
3668 r
= MsiViewClose(view
);
3669 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3670 r
= MsiCloseHandle(view
);
3671 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3674 query
= "INSERT INTO `Control` ( "
3675 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3676 "`Property`, `Text`, `Control_Next`, `Help` )"
3677 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3678 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3679 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3680 r
= MsiViewExecute(view
, 0);
3681 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3682 r
= MsiViewClose(view
);
3683 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3684 r
= MsiCloseHandle(view
);
3685 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3687 /* add a second control */
3688 query
= "INSERT INTO `Control` ( "
3689 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3690 "`Property`, `Text`, `Control_Next`, `Help` )"
3691 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
3692 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3693 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3694 r
= MsiViewExecute(view
, 0);
3695 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3696 r
= MsiViewClose(view
);
3697 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3698 r
= MsiCloseHandle(view
);
3699 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3701 /* add a third control */
3702 query
= "INSERT INTO `Control` ( "
3703 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
3704 "`Property`, `Text`, `Control_Next`, `Help` )"
3705 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
3706 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3707 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3708 r
= MsiViewExecute(view
, 0);
3709 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3710 r
= MsiViewClose(view
);
3711 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3712 r
= MsiCloseHandle(view
);
3713 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3716 query
= "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3717 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3718 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3720 /* bad set column */
3721 query
= "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3722 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3723 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3725 /* bad where condition */
3726 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
3727 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3728 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
3730 /* just the dialog_ specified */
3731 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
3732 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3733 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3734 r
= MsiViewExecute(view
, 0);
3735 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3736 r
= MsiViewClose(view
);
3737 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3738 r
= MsiCloseHandle(view
);
3739 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3741 /* check the modified text */
3742 query
= "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3743 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3744 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3745 r
= MsiViewExecute(view
, 0);
3746 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3748 r
= MsiViewFetch(view
, &rec
);
3749 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3752 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3753 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3754 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3756 MsiCloseHandle(rec
);
3758 r
= MsiViewFetch(view
, &rec
);
3759 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3762 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3763 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3764 ok(!lstrlen(result
), "Expected an empty string, got %s\n", result
);
3766 MsiCloseHandle(rec
);
3768 r
= MsiViewFetch(view
, &rec
);
3769 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3771 r
= MsiViewClose(view
);
3772 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3773 r
= MsiCloseHandle(view
);
3774 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3776 /* dialog_ and control specified */
3777 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
3778 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3779 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3780 r
= MsiViewExecute(view
, 0);
3781 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3782 r
= MsiViewClose(view
);
3783 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3784 r
= MsiCloseHandle(view
);
3785 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3787 /* check the modified text */
3788 query
= "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3789 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3790 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3791 r
= MsiViewExecute(view
, 0);
3792 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3794 r
= MsiViewFetch(view
, &rec
);
3795 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3798 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3799 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3800 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3802 MsiCloseHandle(rec
);
3804 r
= MsiViewFetch(view
, &rec
);
3805 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3808 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3809 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3810 ok(!lstrlen(result
), "Expected an empty string, got %s\n", result
);
3812 MsiCloseHandle(rec
);
3814 r
= MsiViewFetch(view
, &rec
);
3815 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3817 r
= MsiViewClose(view
);
3818 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3819 r
= MsiCloseHandle(view
);
3820 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3822 /* no where condition */
3823 query
= "UPDATE `Control` SET `Text` = 'this is text'";
3824 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3825 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3826 r
= MsiViewExecute(view
, 0);
3827 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3828 r
= MsiViewClose(view
);
3829 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3830 r
= MsiCloseHandle(view
);
3831 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3833 /* check the modified text */
3834 query
= "SELECT `Text` FROM `Control`";
3835 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3836 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3837 r
= MsiViewExecute(view
, 0);
3838 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3840 r
= MsiViewFetch(view
, &rec
);
3841 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3844 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3845 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3846 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3848 MsiCloseHandle(rec
);
3850 r
= MsiViewFetch(view
, &rec
);
3851 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3854 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3855 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3856 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3858 MsiCloseHandle(rec
);
3860 r
= MsiViewFetch(view
, &rec
);
3861 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3864 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3865 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3866 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3868 MsiCloseHandle(rec
);
3870 r
= MsiViewFetch(view
, &rec
);
3871 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3873 r
= MsiViewClose(view
);
3874 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3875 r
= MsiCloseHandle(view
);
3876 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3878 query
= "CREATE TABLE `Apple` ( `Banana` CHAR(72) NOT NULL, "
3879 "`Orange` CHAR(72), `Pear` INT PRIMARY KEY `Banana`)";
3880 r
= run_query(hdb
, 0, query
);
3881 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3883 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
3884 "VALUES('one', 'two', 3)";
3885 r
= run_query(hdb
, 0, query
);
3886 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3888 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
3889 "VALUES('three', 'four', 5)";
3890 r
= run_query(hdb
, 0, query
);
3891 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3893 query
= "INSERT INTO `Apple` ( `Banana`, `Orange`, `Pear` )"
3894 "VALUES('six', 'two', 7)";
3895 r
= run_query(hdb
, 0, query
);
3896 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3898 rec
= MsiCreateRecord(2);
3899 MsiRecordSetInteger(rec
, 1, 8);
3900 MsiRecordSetString(rec
, 2, "two");
3902 query
= "UPDATE `Apple` SET `Pear` = ? WHERE `Orange` = ?";
3903 r
= run_query(hdb
, rec
, query
);
3904 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3906 MsiCloseHandle(rec
);
3908 query
= "SELECT `Pear` FROM `Apple` ORDER BY `Orange`";
3909 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3910 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3911 r
= MsiViewExecute(view
, 0);
3912 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3914 r
= MsiViewFetch(view
, &rec
);
3915 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3917 r
= MsiRecordGetInteger(rec
, 1);
3918 ok(r
== 8, "Expected 8, got %d\n", r
);
3920 MsiCloseHandle(rec
);
3922 r
= MsiViewFetch(view
, &rec
);
3923 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3925 r
= MsiRecordGetInteger(rec
, 1);
3926 ok(r
== 8, "Expected 8, got %d\n", r
);
3928 MsiCloseHandle(rec
);
3930 r
= MsiViewFetch(view
, &rec
);
3931 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3933 r
= MsiRecordGetInteger(rec
, 1);
3934 ok(r
== 5, "Expected 5, got %d\n", r
);
3936 MsiCloseHandle(rec
);
3938 r
= MsiViewFetch(view
, &rec
);
3939 ok(r
== ERROR_NO_MORE_ITEMS
, "Expectd ERROR_NO_MORE_ITEMS, got %d\n", r
);
3942 MsiCloseHandle(view
);
3944 r
= MsiDatabaseCommit(hdb
);
3945 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
3946 r
= MsiCloseHandle(hdb
);
3947 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3949 DeleteFile(msifile
);
3952 static void test_special_tables(void)
3958 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
3959 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
3961 query
= "CREATE TABLE `_Properties` ( "
3962 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3963 r
= run_query(hdb
, 0, query
);
3964 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
3966 query
= "CREATE TABLE `_Streams` ( "
3967 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3968 r
= run_query(hdb
, 0, query
);
3969 todo_wine
ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Streams table\n");
3971 query
= "CREATE TABLE `_Tables` ( "
3972 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3973 r
= run_query(hdb
, 0, query
);
3974 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Tables table\n");
3976 query
= "CREATE TABLE `_Columns` ( "
3977 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3978 r
= run_query(hdb
, 0, query
);
3979 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Columns table\n");
3981 r
= MsiCloseHandle(hdb
);
3982 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3985 static void test_select_markers(void)
3987 MSIHANDLE hdb
= 0, rec
, view
, res
;
3994 ok( hdb
, "failed to create db\n");
3996 r
= run_query(hdb
, 0,
3997 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
3998 ok(r
== S_OK
, "cannot create table: %d\n", r
);
4000 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4001 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
4002 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4004 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4005 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
4006 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4008 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4009 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
4010 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4012 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
4013 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
4014 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
4016 rec
= MsiCreateRecord(2);
4017 MsiRecordSetString(rec
, 1, "apple");
4018 MsiRecordSetString(rec
, 2, "two");
4020 query
= "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
4021 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4022 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4024 r
= MsiViewExecute(view
, rec
);
4025 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4027 r
= MsiViewFetch(view
, &res
);
4028 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4031 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4032 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4033 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4036 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4037 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4038 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4040 r
= MsiRecordGetInteger(res
, 3);
4041 ok(r
== 1, "Expected 1, got %d\n", r
);
4043 MsiCloseHandle(res
);
4045 r
= MsiViewFetch(view
, &res
);
4046 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4049 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4050 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4051 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4054 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4055 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4056 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4058 r
= MsiRecordGetInteger(res
, 3);
4059 ok(r
== 2, "Expected 2, got %d\n", r
);
4061 MsiCloseHandle(res
);
4063 r
= MsiViewFetch(view
, &res
);
4064 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4066 MsiCloseHandle(rec
);
4068 MsiCloseHandle(view
);
4070 rec
= MsiCreateRecord(2);
4071 MsiRecordSetString(rec
, 1, "one");
4072 MsiRecordSetInteger(rec
, 2, 1);
4074 query
= "SELECT * FROM `Table` WHERE `Two`<>? AND `Three`>? ORDER BY `Three`";
4075 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
4076 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4077 r
= MsiViewExecute(view
, rec
);
4078 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4080 r
= MsiViewFetch(view
, &res
);
4081 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4084 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4085 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4086 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
4089 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4090 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4091 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
4093 r
= MsiRecordGetInteger(res
, 3);
4094 ok(r
== 2, "Expected 2, got %d\n", r
);
4096 MsiCloseHandle(res
);
4098 r
= MsiViewFetch(view
, &res
);
4099 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4102 r
= MsiRecordGetString(res
, 1, buf
, &size
);
4103 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4104 ok(!lstrcmp(buf
, "banana"), "Expected banana, got %s\n", buf
);
4107 r
= MsiRecordGetString(res
, 2, buf
, &size
);
4108 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4109 ok(!lstrcmp(buf
, "three"), "Expected three, got %s\n", buf
);
4111 r
= MsiRecordGetInteger(res
, 3);
4112 ok(r
== 3, "Expected 3, got %d\n", r
);
4114 MsiCloseHandle(res
);
4116 r
= MsiViewFetch(view
, &res
);
4117 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4119 MsiCloseHandle(rec
);
4121 MsiCloseHandle(view
);
4122 MsiCloseHandle(hdb
);
4123 DeleteFile(msifile
);
4126 static void test_viewmodify_update(void)
4128 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4132 DeleteFile(msifile
);
4134 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4135 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
4137 query
= "CREATE TABLE `table` (`A` INT, `B` INT PRIMARY KEY `A`)";
4138 r
= run_query( hdb
, 0, query
);
4139 ok(r
== ERROR_SUCCESS
, "query failed\n");
4141 query
= "INSERT INTO `table` (`A`, `B`) VALUES (1, 2)";
4142 r
= run_query( hdb
, 0, query
);
4143 ok(r
== ERROR_SUCCESS
, "query failed\n");
4145 query
= "INSERT INTO `table` (`A`, `B`) VALUES (3, 4)";
4146 r
= run_query( hdb
, 0, query
);
4147 ok(r
== ERROR_SUCCESS
, "query failed\n");
4149 query
= "INSERT INTO `table` (`A`, `B`) VALUES (5, 6)";
4150 r
= run_query( hdb
, 0, query
);
4151 ok(r
== ERROR_SUCCESS
, "query failed\n");
4153 query
= "SELECT `B` FROM `table`";
4154 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4155 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4156 r
= MsiViewExecute(hview
, 0);
4157 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4158 r
= MsiViewFetch(hview
, &hrec
);
4159 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4161 r
= MsiRecordSetInteger(hrec
, 1, 0);
4162 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
4164 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
4165 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
4167 r
= MsiCloseHandle(hrec
);
4168 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4170 r
= MsiViewClose(hview
);
4171 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4172 r
= MsiCloseHandle(hview
);
4173 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4175 query
= "SELECT * FROM `table`";
4176 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4177 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4178 r
= MsiViewExecute(hview
, 0);
4179 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4180 r
= MsiViewFetch(hview
, &hrec
);
4181 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4183 r
= MsiRecordGetInteger(hrec
, 1);
4184 ok(r
== 1, "Expected 1, got %d\n", r
);
4185 r
= MsiRecordGetInteger(hrec
, 2);
4186 ok(r
== 0, "Expected 0, got %d\n", r
);
4188 r
= MsiCloseHandle(hrec
);
4189 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4191 r
= MsiViewFetch(hview
, &hrec
);
4192 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4194 r
= MsiRecordGetInteger(hrec
, 1);
4195 ok(r
== 3, "Expected 3, got %d\n", r
);
4196 r
= MsiRecordGetInteger(hrec
, 2);
4197 ok(r
== 4, "Expected 4, got %d\n", r
);
4199 r
= MsiCloseHandle(hrec
);
4200 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4202 r
= MsiViewFetch(hview
, &hrec
);
4203 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4205 r
= MsiRecordGetInteger(hrec
, 1);
4206 ok(r
== 5, "Expected 5, got %d\n", r
);
4207 r
= MsiRecordGetInteger(hrec
, 2);
4208 ok(r
== 6, "Expected 6, got %d\n", r
);
4210 r
= MsiCloseHandle(hrec
);
4211 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4213 r
= MsiViewFetch(hview
, &hrec
);
4214 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4216 r
= MsiViewClose(hview
);
4217 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4218 r
= MsiCloseHandle(hview
);
4219 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4221 /* loop through all elements */
4222 query
= "SELECT `B` FROM `table`";
4223 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4224 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4225 r
= MsiViewExecute(hview
, 0);
4226 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4230 r
= MsiViewFetch(hview
, &hrec
);
4231 if (r
!= ERROR_SUCCESS
)
4234 r
= MsiRecordSetInteger(hrec
, 1, 0);
4235 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
4237 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
4238 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed: %d\n", r
);
4240 r
= MsiCloseHandle(hrec
);
4241 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4244 r
= MsiViewClose(hview
);
4245 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4246 r
= MsiCloseHandle(hview
);
4247 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4249 query
= "SELECT * FROM `table`";
4250 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4251 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
4252 r
= MsiViewExecute(hview
, 0);
4253 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
4254 r
= MsiViewFetch(hview
, &hrec
);
4255 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4257 r
= MsiRecordGetInteger(hrec
, 1);
4258 ok(r
== 1, "Expected 1, got %d\n", r
);
4259 r
= MsiRecordGetInteger(hrec
, 2);
4260 ok(r
== 0, "Expected 0, got %d\n", r
);
4262 r
= MsiCloseHandle(hrec
);
4263 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4265 r
= MsiViewFetch(hview
, &hrec
);
4266 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4268 r
= MsiRecordGetInteger(hrec
, 1);
4269 ok(r
== 3, "Expected 3, got %d\n", r
);
4270 r
= MsiRecordGetInteger(hrec
, 2);
4271 ok(r
== 0, "Expected 0, got %d\n", r
);
4273 r
= MsiCloseHandle(hrec
);
4274 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4276 r
= MsiViewFetch(hview
, &hrec
);
4277 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
4279 r
= MsiRecordGetInteger(hrec
, 1);
4280 ok(r
== 5, "Expected 5, got %d\n", r
);
4281 r
= MsiRecordGetInteger(hrec
, 2);
4282 ok(r
== 0, "Expected 0, got %d\n", r
);
4284 r
= MsiCloseHandle(hrec
);
4285 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
4287 r
= MsiViewFetch(hview
, &hrec
);
4288 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4290 r
= MsiViewClose(hview
);
4291 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
4292 r
= MsiCloseHandle(hview
);
4293 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
4295 r
= MsiCloseHandle( hdb
);
4296 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
4299 static const WCHAR data10
[] = { /* MOO */
4302 static const WCHAR data11
[] = { /* AAR */
4306 static const char data12
[] = /* _StringData */
4307 "MOOABAARCDonetwofourfive";
4308 static const WCHAR data13
[] = { /* _StringPool */
4310 0, 0, /* string 0 '' */
4311 0, 0, /* string 1 '' */
4312 0, 0, /* string 2 '' */
4313 0, 0, /* string 3 '' */
4314 0, 0, /* string 4 '' */
4315 3, 3, /* string 5 'MOO' */
4316 1, 1, /* string 6 'A' */
4317 1, 1, /* string 7 'B' */
4318 3, 3, /* string 8 'AAR' */
4319 1, 1, /* string 9 'C' */
4320 1, 1, /* string a 'D' */
4321 3, 1, /* string b 'one' */
4322 3, 1, /* string c 'two' */
4323 0, 0, /* string d '' */
4324 4, 1, /* string e 'four' */
4325 4, 1, /* string f 'five' */
4328 static void test_stringtable(void)
4330 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4331 IStorage
*stg
= NULL
;
4336 char buffer
[MAX_PATH
];
4337 WCHAR data
[MAX_PATH
];
4341 static const DWORD mode
= STGM_DIRECT
| STGM_READ
| STGM_SHARE_DENY_WRITE
;
4342 static const WCHAR stringdata
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0}; /* _StringData */
4343 static const WCHAR stringpool
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0}; /* _StringPool */
4344 static const WCHAR moo
[] = {0x4840, 0x3e16, 0x4818, 0}; /* MOO */
4345 static const WCHAR aar
[] = {0x4840, 0x3a8a, 0x481b, 0}; /* AAR */
4347 DeleteFile(msifile
);
4349 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4350 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4352 query
= "CREATE TABLE `MOO` (`A` INT, `B` CHAR(72) PRIMARY KEY `A`)";
4353 r
= run_query(hdb
, 0, query
);
4354 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4356 query
= "CREATE TABLE `AAR` (`C` INT, `D` CHAR(72) PRIMARY KEY `C`)";
4357 r
= run_query(hdb
, 0, query
);
4358 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4360 /* insert persistent row */
4361 query
= "INSERT INTO `MOO` (`A`, `B`) VALUES (1, 'one')";
4362 r
= run_query(hdb
, 0, query
);
4363 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4365 /* insert persistent row */
4366 query
= "INSERT INTO `AAR` (`C`, `D`) VALUES (2, 'two')";
4367 r
= run_query(hdb
, 0, query
);
4368 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4371 query
= "SELECT * FROM `MOO`";
4372 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4373 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4374 r
= MsiViewExecute(hview
, 0);
4375 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4377 hrec
= MsiCreateRecord(2);
4379 r
= MsiRecordSetInteger(hrec
, 1, 3);
4380 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4381 r
= MsiRecordSetString(hrec
, 2, "three");
4382 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4384 /* insert a nonpersistent row */
4385 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
4386 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4388 r
= MsiCloseHandle(hrec
);
4389 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4390 r
= MsiViewClose(hview
);
4391 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4392 r
= MsiCloseHandle(hview
);
4393 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4395 /* insert persistent row */
4396 query
= "INSERT INTO `MOO` (`A`, `B`) VALUES (4, 'four')";
4397 r
= run_query(hdb
, 0, query
);
4398 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4400 /* insert persistent row */
4401 query
= "INSERT INTO `AAR` (`C`, `D`) VALUES (5, 'five')";
4402 r
= run_query(hdb
, 0, query
);
4403 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4405 r
= MsiDatabaseCommit(hdb
);
4406 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4408 r
= MsiCloseHandle(hdb
);
4409 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4411 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
4412 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4414 query
= "SELECT * FROM `MOO`";
4415 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4416 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4418 r
= MsiViewExecute(hview
, 0);
4419 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4421 r
= MsiViewFetch(hview
, &hrec
);
4422 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4424 r
= MsiRecordGetFieldCount(hrec
);
4425 ok(r
== 2, "Expected 2, got %d\n", r
);
4427 r
= MsiRecordGetInteger(hrec
, 1);
4428 ok(r
== 1, "Expected 1, got %d\n", r
);
4430 sz
= sizeof(buffer
);
4431 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4432 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4433 ok(!lstrcmp(buffer
, "one"), "Expected one, got %s\n", buffer
);
4435 r
= MsiCloseHandle(hrec
);
4436 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4438 r
= MsiViewFetch(hview
, &hrec
);
4441 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, 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
);
4448 r
= MsiCloseHandle(hrec
);
4449 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4451 query
= "SELECT * FROM `AAR`";
4452 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4453 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4455 r
= MsiViewExecute(hview
, 0);
4456 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4458 r
= MsiViewFetch(hview
, &hrec
);
4459 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4461 r
= MsiRecordGetFieldCount(hrec
);
4462 ok(r
== 2, "Expected 2, got %d\n", r
);
4464 r
= MsiRecordGetInteger(hrec
, 1);
4465 ok(r
== 2, "Expected 2, got %d\n", r
);
4467 sz
= sizeof(buffer
);
4468 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4469 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4470 ok(!lstrcmp(buffer
, "two"), "Expected two, got %s\n", buffer
);
4472 r
= MsiCloseHandle(hrec
);
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
== 5, "Expected 5, 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
, "five"), "Expected five, 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
);
4493 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4495 r
= MsiViewClose(hview
);
4496 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4497 r
= MsiCloseHandle(hview
);
4498 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4499 r
= MsiCloseHandle(hrec
);
4500 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4501 r
= MsiCloseHandle(hdb
);
4502 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4504 MultiByteToWideChar(CP_ACP
, 0, msifile
, -1, name
, 0x20);
4505 hr
= StgOpenStorage(name
, NULL
, mode
, NULL
, 0, &stg
);
4506 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4507 ok(stg
!= NULL
, "Expected non-NULL storage\n");
4509 hr
= IStorage_OpenStream(stg
, moo
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4510 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4511 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4513 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
4514 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4517 ok(read
== 4, "Expected 4, got %d\n", read
);
4518 ok(!memcmp(data
, data10
, read
), "Unexpected data\n");
4521 hr
= IStream_Release(stm
);
4522 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4524 hr
= IStorage_OpenStream(stg
, aar
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4525 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4526 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4528 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
4529 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4530 ok(read
== 8, "Expected 8, got %d\n", read
);
4533 ok(!memcmp(data
, data11
, read
), "Unexpected data\n");
4536 hr
= IStream_Release(stm
);
4537 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4539 hr
= IStorage_OpenStream(stg
, stringdata
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4540 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4541 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4543 hr
= IStream_Read(stm
, buffer
, MAX_PATH
, &read
);
4544 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4545 ok(read
== 24, "Expected 24, got %d\n", read
);
4546 ok(!memcmp(buffer
, data12
, read
), "Unexpected data\n");
4548 hr
= IStream_Release(stm
);
4549 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4551 hr
= IStorage_OpenStream(stg
, stringpool
, NULL
, STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4552 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4553 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4555 hr
= IStream_Read(stm
, data
, MAX_PATH
, &read
);
4556 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4559 ok(read
== 64, "Expected 64, got %d\n", read
);
4560 ok(!memcmp(data
, data13
, read
), "Unexpected data\n");
4563 hr
= IStream_Release(stm
);
4564 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4566 hr
= IStorage_Release(stg
);
4567 ok(hr
== S_OK
, "Expected S_OK, got %d\n", hr
);
4569 DeleteFileA(msifile
);
4572 static void test_viewmodify_delete(void)
4574 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
4580 DeleteFile(msifile
);
4582 /* just MsiOpenDatabase should not create a file */
4583 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4584 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4586 query
= "CREATE TABLE `phone` ( "
4587 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
4588 "PRIMARY KEY `id`)";
4589 r
= run_query(hdb
, 0, query
);
4590 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4592 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
4593 "VALUES('1', 'Alan', '5030581')";
4594 r
= run_query(hdb
, 0, query
);
4595 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4597 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
4598 "VALUES('2', 'Barry', '928440')";
4599 r
= run_query(hdb
, 0, query
);
4600 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4602 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
4603 "VALUES('3', 'Cindy', '2937550')";
4604 r
= run_query(hdb
, 0, query
);
4605 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4607 query
= "SELECT * FROM `phone` WHERE `id` <= 2";
4608 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4609 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4610 r
= MsiViewExecute(hview
, 0);
4611 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4612 r
= MsiViewFetch(hview
, &hrec
);
4613 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4616 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
4617 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4619 r
= MsiCloseHandle(hrec
);
4620 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4621 r
= MsiViewFetch(hview
, &hrec
);
4622 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4625 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
4626 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4628 r
= MsiCloseHandle(hrec
);
4629 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4630 r
= MsiViewClose(hview
);
4631 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4632 r
= MsiCloseHandle(hview
);
4633 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4635 query
= "SELECT * FROM `phone`";
4636 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4637 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4638 r
= MsiViewExecute(hview
, 0);
4639 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4640 r
= MsiViewFetch(hview
, &hrec
);
4641 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4643 r
= MsiRecordGetInteger(hrec
, 1);
4644 ok(r
== 3, "Expected 3, got %d\n", r
);
4646 sz
= sizeof(buffer
);
4647 r
= MsiRecordGetString(hrec
, 2, buffer
, &sz
);
4648 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4649 ok(!lstrcmp(buffer
, "Cindy"), "Expected Cindy, got %s\n", buffer
);
4651 sz
= sizeof(buffer
);
4652 r
= MsiRecordGetString(hrec
, 3, buffer
, &sz
);
4653 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4654 ok(!lstrcmp(buffer
, "2937550"), "Expected 2937550, got %s\n", buffer
);
4656 r
= MsiCloseHandle(hrec
);
4657 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4659 r
= MsiViewFetch(hview
, &hrec
);
4660 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4662 r
= MsiViewClose(hview
);
4663 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4664 r
= MsiCloseHandle(hview
);
4665 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4666 r
= MsiCloseHandle(hdb
);
4667 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4670 static const WCHAR _Tables
[] = {0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0};
4671 static const WCHAR _StringData
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0};
4672 static const WCHAR _StringPool
[] = {0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0};
4674 static const WCHAR data14
[] = { /* _StringPool */
4676 0, 0, /* string 0 '' */
4679 static const struct {
4683 } database_table_data
[] =
4686 {_StringData
, NULL
, 0},
4687 {_StringPool
, data14
, sizeof data14
},
4690 void enum_stream_names(IStorage
*stg
)
4692 IEnumSTATSTG
*stgenum
= NULL
;
4697 BYTE data
[MAX_PATH
];
4698 BYTE check
[MAX_PATH
];
4701 memset(check
, 'a', MAX_PATH
);
4703 hr
= IStorage_EnumElements(stg
, 0, NULL
, 0, &stgenum
);
4704 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
4710 hr
= IEnumSTATSTG_Next(stgenum
, 1, &stat
, &count
);
4711 if(FAILED(hr
) || !count
)
4714 ok(!lstrcmpW(stat
.pwcsName
, database_table_data
[n
].name
),
4715 "Expected table %d name to match\n", n
);
4718 hr
= IStorage_OpenStream(stg
, stat
.pwcsName
, NULL
,
4719 STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
4720 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
4721 ok(stm
!= NULL
, "Expected non-NULL stream\n");
4724 memset(data
, 'a', MAX_PATH
);
4725 hr
= IStream_Read(stm
, data
, sz
, &count
);
4726 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
4728 ok(count
== database_table_data
[n
].size
,
4729 "Expected %d, got %d\n", database_table_data
[n
].size
, count
);
4731 if (!database_table_data
[n
].size
)
4732 ok(!memcmp(data
, check
, MAX_PATH
), "data should not be changed\n");
4734 ok(!memcmp(data
, database_table_data
[n
].data
, database_table_data
[n
].size
),
4735 "Expected table %d data to match\n", n
);
4737 IStream_Release(stm
);
4741 ok(n
== 3, "Expected 3, got %d\n", n
);
4743 IEnumSTATSTG_Release(stgenum
);
4746 static void test_defaultdatabase(void)
4751 IStorage
*stg
= NULL
;
4753 static const WCHAR msifileW
[] = {'w','i','n','e','t','e','s','t','.','m','s','i',0};
4755 DeleteFile(msifile
);
4757 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
4758 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4760 r
= MsiDatabaseCommit(hdb
);
4761 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4763 MsiCloseHandle(hdb
);
4765 hr
= StgOpenStorage(msifileW
, NULL
, STGM_READ
| STGM_SHARE_DENY_WRITE
, NULL
, 0, &stg
);
4766 ok(hr
== S_OK
, "Expected S_OK, got %08x\n", hr
);
4767 ok(stg
!= NULL
, "Expected non-NULL stg\n");
4769 enum_stream_names(stg
);
4771 IStorage_Release(stg
);
4772 DeleteFileA(msifile
);
4775 static void test_order(void)
4777 MSIHANDLE hdb
, hview
, hrec
;
4778 CHAR buffer
[MAX_PATH
];
4784 ok(hdb
, "failed to create db\n");
4786 query
= "CREATE TABLE `Empty` ( `A` SHORT NOT NULL PRIMARY KEY `A`)";
4787 r
= run_query(hdb
, 0, query
);
4788 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4790 query
= "CREATE TABLE `Mesa` ( `A` SHORT NOT NULL, `B` SHORT, `C` SHORT PRIMARY KEY `A`)";
4791 r
= run_query(hdb
, 0, query
);
4792 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4794 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 1, 2, 9 )";
4795 r
= run_query(hdb
, 0, query
);
4796 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4798 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 3, 4, 7 )";
4799 r
= run_query(hdb
, 0, query
);
4800 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4802 query
= "INSERT INTO `Mesa` ( `A`, `B`, `C` ) VALUES ( 5, 6, 8 )";
4803 r
= run_query(hdb
, 0, query
);
4804 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4806 query
= "CREATE TABLE `Sideboard` ( `D` SHORT NOT NULL, `E` SHORT, `F` SHORT PRIMARY KEY `D`)";
4807 r
= run_query(hdb
, 0, query
);
4808 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4810 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 10, 11, 18 )";
4811 r
= run_query(hdb
, 0, query
);
4812 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4814 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 12, 13, 16 )";
4815 r
= run_query(hdb
, 0, query
);
4816 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4818 query
= "INSERT INTO `Sideboard` ( `D`, `E`, `F` ) VALUES ( 14, 15, 17 )";
4819 r
= run_query(hdb
, 0, query
);
4820 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4822 query
= "SELECT `A`, `B` FROM `Mesa` ORDER BY `C`";
4823 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4824 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4825 r
= MsiViewExecute(hview
, 0);
4826 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4828 r
= MsiViewFetch(hview
, &hrec
);
4829 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4831 val
= MsiRecordGetInteger(hrec
, 1);
4832 ok(val
== 3, "Expected 3, got %d\n", val
);
4834 val
= MsiRecordGetInteger(hrec
, 2);
4835 ok(val
== 4, "Expected 3, got %d\n", val
);
4837 MsiCloseHandle(hrec
);
4839 r
= MsiViewFetch(hview
, &hrec
);
4840 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4842 val
= MsiRecordGetInteger(hrec
, 1);
4843 ok(val
== 5, "Expected 5, got %d\n", val
);
4845 val
= MsiRecordGetInteger(hrec
, 2);
4846 ok(val
== 6, "Expected 6, got %d\n", val
);
4848 MsiCloseHandle(hrec
);
4850 r
= MsiViewFetch(hview
, &hrec
);
4851 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4853 val
= MsiRecordGetInteger(hrec
, 1);
4854 ok(val
== 1, "Expected 1, got %d\n", val
);
4856 val
= MsiRecordGetInteger(hrec
, 2);
4857 ok(val
== 2, "Expected 2, got %d\n", val
);
4859 MsiCloseHandle(hrec
);
4861 r
= MsiViewFetch(hview
, &hrec
);
4862 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4864 MsiViewClose(hview
);
4865 MsiCloseHandle(hview
);
4867 query
= "SELECT `A`, `D` FROM `Mesa`, `Sideboard` ORDER BY `F`";
4868 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4869 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4870 r
= MsiViewExecute(hview
, 0);
4871 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4873 r
= MsiViewFetch(hview
, &hrec
);
4874 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4876 val
= MsiRecordGetInteger(hrec
, 1);
4877 ok(val
== 1, "Expected 1, got %d\n", val
);
4879 val
= MsiRecordGetInteger(hrec
, 2);
4880 ok(val
== 12, "Expected 12, got %d\n", val
);
4882 MsiCloseHandle(hrec
);
4884 r
= MsiViewFetch(hview
, &hrec
);
4885 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4887 val
= MsiRecordGetInteger(hrec
, 1);
4888 ok(val
== 3, "Expected 3, got %d\n", val
);
4890 val
= MsiRecordGetInteger(hrec
, 2);
4891 ok(val
== 12, "Expected 12, got %d\n", val
);
4893 MsiCloseHandle(hrec
);
4895 r
= MsiViewFetch(hview
, &hrec
);
4896 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4898 val
= MsiRecordGetInteger(hrec
, 1);
4899 ok(val
== 5, "Expected 5, got %d\n", val
);
4901 val
= MsiRecordGetInteger(hrec
, 2);
4902 ok(val
== 12, "Expected 12, got %d\n", val
);
4904 MsiCloseHandle(hrec
);
4906 r
= MsiViewFetch(hview
, &hrec
);
4907 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4909 val
= MsiRecordGetInteger(hrec
, 1);
4910 ok(val
== 1, "Expected 1, got %d\n", val
);
4912 val
= MsiRecordGetInteger(hrec
, 2);
4913 ok(val
== 14, "Expected 14, got %d\n", val
);
4915 MsiCloseHandle(hrec
);
4917 r
= MsiViewFetch(hview
, &hrec
);
4918 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4920 val
= MsiRecordGetInteger(hrec
, 1);
4921 ok(val
== 3, "Expected 3, got %d\n", val
);
4923 val
= MsiRecordGetInteger(hrec
, 2);
4924 ok(val
== 14, "Expected 14, got %d\n", val
);
4926 MsiCloseHandle(hrec
);
4928 r
= MsiViewFetch(hview
, &hrec
);
4929 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4931 val
= MsiRecordGetInteger(hrec
, 1);
4932 ok(val
== 5, "Expected 5, got %d\n", val
);
4934 val
= MsiRecordGetInteger(hrec
, 2);
4935 ok(val
== 14, "Expected 14, got %d\n", val
);
4937 MsiCloseHandle(hrec
);
4939 r
= MsiViewFetch(hview
, &hrec
);
4940 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4942 val
= MsiRecordGetInteger(hrec
, 1);
4943 ok(val
== 1, "Expected 1, got %d\n", val
);
4945 val
= MsiRecordGetInteger(hrec
, 2);
4946 ok(val
== 10, "Expected 10, got %d\n", val
);
4948 MsiCloseHandle(hrec
);
4950 r
= MsiViewFetch(hview
, &hrec
);
4951 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4953 val
= MsiRecordGetInteger(hrec
, 1);
4954 ok(val
== 3, "Expected 3, got %d\n", val
);
4956 val
= MsiRecordGetInteger(hrec
, 2);
4957 ok(val
== 10, "Expected 10, got %d\n", val
);
4959 MsiCloseHandle(hrec
);
4961 r
= MsiViewFetch(hview
, &hrec
);
4962 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4964 val
= MsiRecordGetInteger(hrec
, 1);
4965 ok(val
== 5, "Expected 5, got %d\n", val
);
4967 val
= MsiRecordGetInteger(hrec
, 2);
4968 ok(val
== 10, "Expected 10, got %d\n", val
);
4970 MsiCloseHandle(hrec
);
4972 r
= MsiViewFetch(hview
, &hrec
);
4973 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4975 MsiViewClose(hview
);
4976 MsiCloseHandle(hview
);
4978 query
= "SELECT * FROM `Empty` ORDER BY `A`";
4979 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
4980 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4981 r
= MsiViewExecute(hview
, 0);
4982 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4984 r
= MsiViewFetch(hview
, &hrec
);
4985 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
4987 MsiViewClose(hview
);
4988 MsiCloseHandle(hview
);
4990 query
= "CREATE TABLE `Buffet` ( `One` CHAR(72), `Two` SHORT PRIMARY KEY `One`)";
4991 r
= run_query(hdb
, 0, query
);
4992 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4994 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'uno', 2)";
4995 r
= run_query(hdb
, 0, query
);
4996 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
4998 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'dos', 3)";
4999 r
= run_query(hdb
, 0, query
);
5000 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5002 query
= "INSERT INTO `Buffet` ( `One`, `Two` ) VALUES ( 'tres', 1)";
5003 r
= run_query(hdb
, 0, query
);
5004 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5006 query
= "SELECT * FROM `Buffet` WHERE `One` = 'dos' ORDER BY `Two`";
5007 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5008 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5009 r
= MsiViewExecute(hview
, 0);
5010 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5012 r
= MsiViewFetch(hview
, &hrec
);
5013 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5015 sz
= sizeof(buffer
);
5016 r
= MsiRecordGetString(hrec
, 1, buffer
, &sz
);
5017 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5018 ok(!lstrcmp(buffer
, "dos"), "Expected \"dos\", got \"%s\"\n", buffer
);
5020 r
= MsiRecordGetInteger(hrec
, 2);
5021 ok(r
== 3, "Expected 3, got %d\n", r
);
5023 MsiCloseHandle(hrec
);
5025 r
= MsiViewFetch(hview
, &hrec
);
5026 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5028 MsiViewClose(hview
);
5029 MsiCloseHandle(hview
);
5030 MsiCloseHandle(hdb
);
5033 static void test_viewmodify_delete_temporary(void)
5035 MSIHANDLE hdb
, hview
, hrec
;
5039 DeleteFile(msifile
);
5041 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5042 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5044 query
= "CREATE TABLE `Table` ( `A` SHORT PRIMARY KEY `A` )";
5045 r
= run_query(hdb
, 0, query
);
5046 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5048 query
= "SELECT * FROM `Table`";
5049 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5050 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5051 r
= MsiViewExecute(hview
, 0);
5052 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5054 hrec
= MsiCreateRecord(1);
5055 MsiRecordSetInteger(hrec
, 1, 1);
5057 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, hrec
);
5058 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5060 MsiCloseHandle(hrec
);
5062 hrec
= MsiCreateRecord(1);
5063 MsiRecordSetInteger(hrec
, 1, 2);
5065 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
5066 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5068 MsiCloseHandle(hrec
);
5070 hrec
= MsiCreateRecord(1);
5071 MsiRecordSetInteger(hrec
, 1, 3);
5073 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, hrec
);
5074 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5076 MsiCloseHandle(hrec
);
5078 hrec
= MsiCreateRecord(1);
5079 MsiRecordSetInteger(hrec
, 1, 4);
5081 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
5082 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5084 MsiCloseHandle(hrec
);
5085 MsiViewClose(hview
);
5086 MsiCloseHandle(hview
);
5088 query
= "SELECT * FROM `Table` WHERE `A` = 2";
5089 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5090 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5091 r
= MsiViewExecute(hview
, 0);
5092 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5093 r
= MsiViewFetch(hview
, &hrec
);
5094 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5096 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
5097 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5099 MsiCloseHandle(hrec
);
5100 MsiViewClose(hview
);
5101 MsiCloseHandle(hview
);
5103 query
= "SELECT * FROM `Table` WHERE `A` = 3";
5104 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5105 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5106 r
= MsiViewExecute(hview
, 0);
5107 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5108 r
= MsiViewFetch(hview
, &hrec
);
5109 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5111 r
= MsiViewModify(hview
, MSIMODIFY_DELETE
, hrec
);
5112 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5114 MsiCloseHandle(hrec
);
5115 MsiViewClose(hview
);
5116 MsiCloseHandle(hview
);
5118 query
= "SELECT * FROM `Table` ORDER BY `A`";
5119 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5120 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5121 r
= MsiViewExecute(hview
, 0);
5122 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5124 r
= MsiViewFetch(hview
, &hrec
);
5125 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5127 r
= MsiRecordGetInteger(hrec
, 1);
5128 ok(r
== 1, "Expected 1, got %d\n", r
);
5130 MsiCloseHandle(hrec
);
5132 r
= MsiViewFetch(hview
, &hrec
);
5133 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5135 r
= MsiRecordGetInteger(hrec
, 1);
5136 ok(r
== 4, "Expected 4, got %d\n", r
);
5138 MsiCloseHandle(hrec
);
5140 r
= MsiViewFetch(hview
, &hrec
);
5141 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5143 MsiViewClose(hview
);
5144 MsiCloseHandle(hview
);
5145 MsiCloseHandle(hdb
);
5146 DeleteFileA(msifile
);
5149 static void test_deleterow()
5151 MSIHANDLE hdb
, hview
, hrec
;
5157 DeleteFile(msifile
);
5159 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5160 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5162 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5163 r
= run_query(hdb
, 0, query
);
5164 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5166 query
= "INSERT INTO `Table` (`A`) VALUES ('one')";
5167 r
= run_query(hdb
, 0, query
);
5168 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5170 query
= "INSERT INTO `Table` (`A`) VALUES ('two')";
5171 r
= run_query(hdb
, 0, query
);
5172 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5174 query
= "DELETE FROM `Table` WHERE `A` = 'one'";
5175 r
= run_query(hdb
, 0, query
);
5176 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5178 r
= MsiDatabaseCommit(hdb
);
5179 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5181 MsiCloseHandle(hdb
);
5183 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
5184 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5186 query
= "SELECT * FROM `Table`";
5187 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5188 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5189 r
= MsiViewExecute(hview
, 0);
5190 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5192 r
= MsiViewFetch(hview
, &hrec
);
5193 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5196 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5197 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5198 ok(!lstrcmpA(buf
, "two"), "Expected two, got %s\n", buf
);
5200 MsiCloseHandle(hrec
);
5202 r
= MsiViewFetch(hview
, &hrec
);
5203 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5205 MsiViewClose(hview
);
5206 MsiCloseHandle(hview
);
5207 MsiCloseHandle(hdb
);
5208 DeleteFileA(msifile
);
5211 static const CHAR import_dat
[] = "A\n"
5214 "This is a new 'string' ok\n";
5216 static void test_quotes(void)
5218 MSIHANDLE hdb
, hview
, hrec
;
5224 DeleteFile(msifile
);
5226 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5227 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5229 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5230 r
= run_query(hdb
, 0, query
);
5231 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5233 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a 'string' ok' )";
5234 r
= run_query(hdb
, 0, query
);
5235 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5236 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5238 query
= "INSERT INTO `Table` ( `A` ) VALUES ( \"This is a 'string' ok\" )";
5239 r
= run_query(hdb
, 0, query
);
5240 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5241 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5243 query
= "INSERT INTO `Table` ( `A` ) VALUES ( \"test\" )";
5244 r
= run_query(hdb
, 0, query
);
5245 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5246 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5248 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a ''string'' ok' )";
5249 r
= run_query(hdb
, 0, query
);
5252 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5255 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a '''string''' ok' )";
5256 r
= run_query(hdb
, 0, query
);
5257 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5259 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \'string\' ok' )";
5260 r
= run_query(hdb
, 0, query
);
5261 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5263 query
= "INSERT INTO `Table` ( `A` ) VALUES ( 'This is a \"string\" ok' )";
5264 r
= run_query(hdb
, 0, query
);
5265 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5267 query
= "SELECT * FROM `Table`";
5268 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5269 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5271 r
= MsiViewExecute(hview
, 0);
5272 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5274 r
= MsiViewFetch(hview
, &hrec
);
5275 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5278 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
5279 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5282 ok(!lstrcmp(buf
, "This is a \"string\" ok"),
5283 "Expected \"This is a \"string\" ok\", got %s\n", buf
);
5286 MsiCloseHandle(hrec
);
5288 r
= MsiViewFetch(hview
, &hrec
);
5291 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5294 MsiCloseHandle(hview
);
5296 write_file("import.idt", import_dat
, (sizeof(import_dat
) - 1) * sizeof(char));
5298 r
= MsiDatabaseImportA(hdb
, CURR_DIR
, "import.idt");
5299 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5301 DeleteFileA("import.idt");
5303 query
= "SELECT * FROM `Table`";
5304 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5305 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5307 r
= MsiViewExecute(hview
, 0);
5308 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5310 r
= MsiViewFetch(hview
, &hrec
);
5311 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5314 r
= MsiRecordGetString(hrec
, 1, buf
, &size
);
5315 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5316 ok(!lstrcmp(buf
, "This is a new 'string' ok"),
5317 "Expected \"This is a new 'string' ok\", got %s\n", buf
);
5319 MsiCloseHandle(hrec
);
5321 r
= MsiViewFetch(hview
, &hrec
);
5322 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5324 MsiCloseHandle(hview
);
5326 MsiCloseHandle(hdb
);
5327 DeleteFileA(msifile
);
5330 static void test_carriagereturn(void)
5332 MSIHANDLE hdb
, hview
, hrec
;
5338 DeleteFile(msifile
);
5340 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5341 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5343 query
= "CREATE TABLE `Table`\r ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5344 r
= run_query(hdb
, 0, query
);
5347 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5348 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5351 query
= "CREATE TABLE `Table` \r( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5352 r
= run_query(hdb
, 0, query
);
5353 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5354 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5356 query
= "CREATE\r TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5357 r
= run_query(hdb
, 0, query
);
5358 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5359 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5361 query
= "CREATE TABLE\r `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5362 r
= run_query(hdb
, 0, query
);
5363 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5364 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5366 query
= "CREATE TABLE `Table` (\r `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5367 r
= run_query(hdb
, 0, query
);
5368 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5369 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5371 query
= "CREATE TABLE `Table` ( `A`\r CHAR(72) NOT NULL PRIMARY KEY `A` )";
5372 r
= run_query(hdb
, 0, query
);
5373 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5374 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5376 query
= "CREATE TABLE `Table` ( `A` CHAR(72)\r NOT NULL PRIMARY KEY `A` )";
5377 r
= run_query(hdb
, 0, query
);
5378 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5379 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5381 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT\r NULL PRIMARY KEY `A` )";
5382 r
= run_query(hdb
, 0, query
);
5383 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5384 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5386 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT \rNULL PRIMARY KEY `A` )";
5387 r
= run_query(hdb
, 0, query
);
5388 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5389 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5391 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL\r PRIMARY KEY `A` )";
5392 r
= run_query(hdb
, 0, query
);
5393 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5394 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5396 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL \rPRIMARY KEY `A` )";
5397 r
= run_query(hdb
, 0, query
);
5398 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5399 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5401 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY\r KEY `A` )";
5402 r
= run_query(hdb
, 0, query
);
5403 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5404 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5406 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY \rKEY `A` )";
5407 r
= run_query(hdb
, 0, query
);
5408 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5409 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5411 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY\r `A` )";
5412 r
= run_query(hdb
, 0, query
);
5413 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5414 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5416 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A`\r )";
5417 r
= run_query(hdb
, 0, query
);
5418 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5419 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5421 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )\r";
5422 r
= run_query(hdb
, 0, query
);
5423 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5424 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5426 query
= "CREATE TABLE `\rOne` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5427 r
= run_query(hdb
, 0, query
);
5428 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5430 query
= "CREATE TABLE `Tw\ro` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5431 r
= run_query(hdb
, 0, query
);
5432 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5434 query
= "CREATE TABLE `Three\r` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5435 r
= run_query(hdb
, 0, query
);
5436 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5438 query
= "CREATE TABLE `Four` ( `A\r` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5439 r
= run_query(hdb
, 0, query
);
5440 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5441 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5443 query
= "CREATE TABLE `Four` ( `\rA` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5444 r
= run_query(hdb
, 0, query
);
5445 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5446 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5448 query
= "CREATE TABLE `Four` ( `A` CHAR(72\r) NOT NULL PRIMARY KEY `A` )";
5449 r
= run_query(hdb
, 0, query
);
5452 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5453 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5456 query
= "CREATE TABLE `Four` ( `A` CHAR(\r72) NOT NULL PRIMARY KEY `A` )";
5457 r
= run_query(hdb
, 0, query
);
5458 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5459 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5461 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `\rA` )";
5462 r
= run_query(hdb
, 0, query
);
5463 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5464 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5466 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
5467 r
= run_query(hdb
, 0, query
);
5468 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5469 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5471 query
= "CREATE TABLE `Four` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A\r` )";
5472 r
= run_query(hdb
, 0, query
);
5473 ok(r
== ERROR_BAD_QUERY_SYNTAX
,
5474 "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5476 query
= "SELECT * FROM `_Tables`";
5477 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5478 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5479 r
= MsiViewExecute(hview
, 0);
5480 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5482 r
= MsiViewFetch(hview
, &hrec
);
5483 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5486 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5487 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5490 ok(!lstrcmpA(buf
, "\rOne"), "Expected \"\\rOne\", got \"%s\"\n", buf
);
5493 MsiCloseHandle(hrec
);
5495 r
= MsiViewFetch(hview
, &hrec
);
5496 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5499 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5500 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5503 ok(!lstrcmpA(buf
, "Tw\ro"), "Expected \"Tw\\ro\", got \"%s\"\n", buf
);
5506 MsiCloseHandle(hrec
);
5508 r
= MsiViewFetch(hview
, &hrec
);
5509 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5512 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5513 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5516 ok(!lstrcmpA(buf
, "Three\r"),
5517 "Expected \"Three\r\", got \"%s\"\n", buf
);
5520 MsiCloseHandle(hrec
);
5522 r
= MsiViewFetch(hview
, &hrec
);
5525 ok(r
== ERROR_NO_MORE_ITEMS
,
5526 "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5529 MsiViewClose(hview
);
5530 MsiCloseHandle(hview
);
5532 MsiCloseHandle(hdb
);
5533 DeleteFileA(msifile
);
5536 static void test_noquotes(void)
5538 MSIHANDLE hdb
, hview
, hrec
;
5544 DeleteFile(msifile
);
5546 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5547 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5549 query
= "CREATE TABLE Table ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5550 r
= run_query(hdb
, 0, query
);
5551 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5553 query
= "CREATE TABLE `Table` ( A CHAR(72) NOT NULL PRIMARY KEY `A` )";
5554 r
= run_query(hdb
, 0, query
);
5555 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5557 query
= "CREATE TABLE `Table2` ( `A` CHAR(72) NOT NULL PRIMARY KEY A )";
5558 r
= run_query(hdb
, 0, query
);
5559 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5561 query
= "CREATE TABLE `Table3` ( A CHAR(72) NOT NULL PRIMARY KEY A )";
5562 r
= run_query(hdb
, 0, query
);
5563 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5565 query
= "SELECT * FROM `_Tables`";
5566 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5567 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5568 r
= MsiViewExecute(hview
, 0);
5569 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5571 r
= MsiViewFetch(hview
, &hrec
);
5572 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5575 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5576 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5577 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
5579 MsiCloseHandle(hrec
);
5581 r
= MsiViewFetch(hview
, &hrec
);
5582 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5585 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5586 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5587 ok(!lstrcmpA(buf
, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf
);
5589 MsiCloseHandle(hrec
);
5591 r
= MsiViewFetch(hview
, &hrec
);
5592 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5595 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5596 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5597 ok(!lstrcmpA(buf
, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf
);
5599 MsiCloseHandle(hrec
);
5601 r
= MsiViewFetch(hview
, &hrec
);
5602 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5604 MsiViewClose(hview
);
5605 MsiCloseHandle(hview
);
5607 query
= "SELECT * FROM `_Columns`";
5608 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5609 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5610 r
= MsiViewExecute(hview
, 0);
5611 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5613 r
= MsiViewFetch(hview
, &hrec
);
5614 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5617 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5618 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5619 ok(!lstrcmpA(buf
, "Table"), "Expected \"Table\", got \"%s\"\n", buf
);
5621 r
= MsiRecordGetInteger(hrec
, 2);
5622 ok(r
== 1, "Expected 1, got %d\n", r
);
5625 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
5626 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5627 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
5629 MsiCloseHandle(hrec
);
5631 r
= MsiViewFetch(hview
, &hrec
);
5632 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5635 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5636 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5637 ok(!lstrcmpA(buf
, "Table2"), "Expected \"Table2\", got \"%s\"\n", buf
);
5639 r
= MsiRecordGetInteger(hrec
, 2);
5640 ok(r
== 1, "Expected 1, got %d\n", r
);
5643 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
5644 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5645 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
5647 MsiCloseHandle(hrec
);
5649 r
= MsiViewFetch(hview
, &hrec
);
5650 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5653 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5654 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5655 ok(!lstrcmpA(buf
, "Table3"), "Expected \"Table3\", got \"%s\"\n", buf
);
5657 r
= MsiRecordGetInteger(hrec
, 2);
5658 ok(r
== 1, "Expected 1, got %d\n", r
);
5661 r
= MsiRecordGetStringA(hrec
, 3, buf
, &size
);
5662 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5663 ok(!lstrcmpA(buf
, "A"), "Expected \"A\", got \"%s\"\n", buf
);
5665 MsiCloseHandle(hrec
);
5667 r
= MsiViewFetch(hview
, &hrec
);
5668 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5670 MsiViewClose(hview
);
5671 MsiCloseHandle(hview
);
5673 query
= "INSERT INTO Table ( `A` ) VALUES ( 'hi' )";
5674 r
= run_query(hdb
, 0, query
);
5675 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5677 query
= "INSERT INTO `Table` ( A ) VALUES ( 'hi' )";
5678 r
= run_query(hdb
, 0, query
);
5679 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5681 query
= "INSERT INTO `Table` ( `A` ) VALUES ( hi )";
5682 r
= run_query(hdb
, 0, query
);
5683 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5685 query
= "SELECT * FROM Table WHERE `A` = 'hi'";
5686 r
= run_query(hdb
, 0, query
);
5687 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5689 query
= "SELECT * FROM `Table` WHERE `A` = hi";
5690 r
= run_query(hdb
, 0, query
);
5691 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5693 query
= "SELECT * FROM Table";
5694 r
= run_query(hdb
, 0, query
);
5695 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5697 query
= "SELECT * FROM Table2";
5698 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5699 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5700 r
= MsiViewExecute(hview
, 0);
5701 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5703 r
= MsiViewFetch(hview
, &hrec
);
5704 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5706 MsiViewClose(hview
);
5707 MsiCloseHandle(hview
);
5709 query
= "SELECT * FROM `Table` WHERE A = 'hi'";
5710 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5711 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5712 r
= MsiViewExecute(hview
, 0);
5713 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5715 r
= MsiViewFetch(hview
, &hrec
);
5716 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5719 r
= MsiRecordGetStringA(hrec
, 1, buf
, &size
);
5720 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5721 ok(!lstrcmpA(buf
, "hi"), "Expected \"hi\", got \"%s\"\n", buf
);
5723 MsiCloseHandle(hrec
);
5725 r
= MsiViewFetch(hview
, &hrec
);
5726 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
5728 MsiViewClose(hview
);
5729 MsiCloseHandle(hview
);
5732 MsiCloseHandle(hdb
);
5733 DeleteFileA(msifile
);
5736 static void read_file_data(LPCSTR filename
, LPSTR buffer
)
5742 file
= OpenFile(filename
, &ofs
, OF_READ
);
5743 ZeroMemory(buffer
, MAX_PATH
);
5744 ReadFile((HANDLE
)file
, buffer
, MAX_PATH
, &read
, NULL
);
5745 CloseHandle((HANDLE
)file
);
5748 static void test_forcecodepage(void)
5752 char buffer
[MAX_PATH
];
5755 DeleteFile(msifile
);
5757 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5758 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5760 query
= "SELECT * FROM `_ForceCodepage`";
5761 r
= run_query(hdb
, 0, query
);
5762 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5764 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL PRIMARY KEY `A` )";
5765 r
= run_query(hdb
, 0, query
);
5766 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5768 query
= "SELECT * FROM `_ForceCodepage`";
5769 r
= run_query(hdb
, 0, query
);
5770 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5772 r
= MsiDatabaseCommit(hdb
);
5773 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5775 query
= "SELECT * FROM `_ForceCodepage`";
5776 r
= run_query(hdb
, 0, query
);
5777 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5779 MsiCloseHandle(hdb
);
5781 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_DIRECT
, &hdb
);
5782 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5784 query
= "SELECT * FROM `_ForceCodepage`";
5785 r
= run_query(hdb
, 0, query
);
5786 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
5788 r
= MsiDatabaseExport(hdb
, "_ForceCodepage", CURR_DIR
, "forcecodepage.idt");
5789 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5791 read_file_data("forcecodepage.idt", buffer
);
5792 ok(!lstrcmpA(buffer
, "\r\n\r\n0\t_ForceCodepage\r\n"),
5793 "Expected \"\r\n\r\n0\t_ForceCodepage\r\n\", got \"%s\"", buffer
);
5795 MsiCloseHandle(hdb
);
5796 DeleteFileA(msifile
);
5797 DeleteFileA("forcecodepage.idt");
5800 static void test_viewmodify_refresh(void)
5802 MSIHANDLE hdb
, hview
, hrec
;
5804 char buffer
[MAX_PATH
];
5808 DeleteFile(msifile
);
5810 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5811 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5813 query
= "CREATE TABLE `Table` ( `A` CHAR(72) NOT NULL, `B` INT PRIMARY KEY `A` )";
5814 r
= run_query(hdb
, 0, query
);
5815 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5817 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hi', 1 )";
5818 r
= run_query(hdb
, 0, query
);
5819 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5821 query
= "SELECT * FROM `Table`";
5822 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5823 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5824 r
= MsiViewExecute(hview
, 0);
5825 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5827 r
= MsiViewFetch(hview
, &hrec
);
5828 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5830 query
= "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hi'";
5831 r
= run_query(hdb
, 0, query
);
5832 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5834 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
5835 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5838 r
= MsiRecordGetStringA(hrec
, 1, buffer
, &size
);
5839 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5840 ok(!lstrcmpA(buffer
, "hi"), "Expected \"hi\", got \"%s\"\n", buffer
);
5841 ok(size
== 2, "Expected 2, got %d\n", size
);
5843 r
= MsiRecordGetInteger(hrec
, 2);
5844 ok(r
== 2, "Expected 2, got %d\n", r
);
5846 MsiCloseHandle(hrec
);
5847 MsiViewClose(hview
);
5848 MsiCloseHandle(hview
);
5850 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hello', 3 )";
5851 r
= run_query(hdb
, 0, query
);
5852 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5854 query
= "SELECT * FROM `Table` WHERE `B` = 3";
5855 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5856 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5857 r
= MsiViewExecute(hview
, 0);
5858 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5860 r
= MsiViewFetch(hview
, &hrec
);
5861 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5863 query
= "UPDATE `Table` SET `B` = 2 WHERE `A` = 'hello'";
5864 r
= run_query(hdb
, 0, query
);
5865 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5867 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 'hithere', 3 )";
5868 r
= run_query(hdb
, 0, query
);
5869 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5871 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
5872 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5875 r
= MsiRecordGetStringA(hrec
, 1, buffer
, &size
);
5876 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5877 ok(!lstrcmpA(buffer
, "hello"), "Expected \"hello\", got \"%s\"\n", buffer
);
5878 ok(size
== 5, "Expected 5, got %d\n", size
);
5880 r
= MsiRecordGetInteger(hrec
, 2);
5881 ok(r
== 2, "Expected 2, got %d\n", r
);
5883 MsiCloseHandle(hrec
);
5884 MsiViewClose(hview
);
5885 MsiCloseHandle(hview
);
5886 MsiCloseHandle(hdb
);
5887 DeleteFileA(msifile
);
5890 static void test_where_viewmodify(void)
5892 MSIHANDLE hdb
, hview
, hrec
;
5896 DeleteFile(msifile
);
5898 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
5899 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5901 query
= "CREATE TABLE `Table` ( `A` INT, `B` INT PRIMARY KEY `A` )";
5902 r
= run_query(hdb
, 0, query
);
5903 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5905 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 1, 2 )";
5906 r
= run_query(hdb
, 0, query
);
5907 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5909 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 3, 4 )";
5910 r
= run_query(hdb
, 0, query
);
5911 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5913 query
= "INSERT INTO `Table` ( `A`, `B` ) VALUES ( 5, 6 )";
5914 r
= run_query(hdb
, 0, query
);
5915 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5917 /* `B` = 3 doesn't match, but the view shouldn't be executed */
5918 query
= "SELECT * FROM `Table` WHERE `B` = 3";
5919 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5920 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5922 hrec
= MsiCreateRecord(2);
5923 MsiRecordSetInteger(hrec
, 1, 7);
5924 MsiRecordSetInteger(hrec
, 2, 8);
5926 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
5927 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5929 MsiCloseHandle(hrec
);
5930 MsiViewClose(hview
);
5931 MsiCloseHandle(hview
);
5933 query
= "SELECT * FROM `Table` WHERE `A` = 7";
5934 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5935 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5936 r
= MsiViewExecute(hview
, 0);
5937 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5939 r
= MsiViewFetch(hview
, &hrec
);
5940 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5942 r
= MsiRecordGetInteger(hrec
, 1);
5943 ok(r
== 7, "Expected 7, got %d\n", r
);
5945 r
= MsiRecordGetInteger(hrec
, 2);
5946 ok(r
== 8, "Expected 8, got %d\n", r
);
5948 MsiRecordSetInteger(hrec
, 2, 9);
5950 r
= MsiViewModify(hview
, MSIMODIFY_UPDATE
, hrec
);
5951 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5953 MsiCloseHandle(hrec
);
5954 MsiViewClose(hview
);
5955 MsiCloseHandle(hview
);
5957 query
= "SELECT * FROM `Table` WHERE `A` = 7";
5958 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
5959 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5960 r
= MsiViewExecute(hview
, 0);
5961 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5963 r
= MsiViewFetch(hview
, &hrec
);
5964 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5966 r
= MsiRecordGetInteger(hrec
, 1);
5967 ok(r
== 7, "Expected 7, got %d\n", r
);
5969 r
= MsiRecordGetInteger(hrec
, 2);
5970 ok(r
== 9, "Expected 9, got %d\n", r
);
5972 query
= "UPDATE `Table` SET `B` = 10 WHERE `A` = 7";
5973 r
= run_query(hdb
, 0, query
);
5974 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5976 r
= MsiViewModify(hview
, MSIMODIFY_REFRESH
, hrec
);
5977 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
5979 r
= MsiRecordGetInteger(hrec
, 1);
5980 ok(r
== 7, "Expected 7, got %d\n", r
);
5982 r
= MsiRecordGetInteger(hrec
, 2);
5983 ok(r
== 10, "Expected 10, got %d\n", r
);
5985 MsiCloseHandle(hrec
);
5986 MsiViewClose(hview
);
5987 MsiCloseHandle(hview
);
5988 MsiCloseHandle(hdb
);
5995 test_msidecomposedesc();
5996 test_msibadqueries();
5998 test_viewgetcolumninfo();
6006 test_handle_limit();
6007 test_try_transform();
6009 test_temporary_table();
6013 test_special_tables();
6014 test_select_markers();
6015 test_viewmodify_update();
6017 test_viewmodify_delete();
6018 test_defaultdatabase();
6020 test_viewmodify_delete_temporary();
6023 test_carriagereturn();
6025 test_forcecodepage();
6026 test_viewmodify_refresh();
6027 test_where_viewmodify();