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;
707 /* just MsiOpenDatabase should not create a file */
708 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
709 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
711 query
= "CREATE TABLE `phone` ( "
712 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
714 r
= run_query( hdb
, 0, query
);
715 ok(r
== ERROR_SUCCESS
, "query failed\n");
717 /* check what the error function reports without doing anything */
719 /* passing NULL as the 3rd param make function to crash on older platforms */
720 r
= MsiViewGetError( 0, NULL
, &sz
);
721 ok(r
== MSIDBERROR_INVALIDARG
, "MsiViewGetError return\n");
724 query
= "SELECT * FROM `phone`";
725 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
726 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
728 /* see what happens with a good hview and bad args */
729 r
= MsiViewGetError( hview
, NULL
, NULL
);
730 ok(r
== MSIDBERROR_INVALIDARG
|| r
== MSIDBERROR_NOERROR
,
731 "MsiViewGetError returns %u (expected -3)\n", r
);
732 r
= MsiViewGetError( hview
, buffer
, NULL
);
733 ok(r
== MSIDBERROR_INVALIDARG
, "MsiViewGetError return\n");
735 /* see what happens with a zero length buffer */
738 r
= MsiViewGetError( hview
, buffer
, &sz
);
739 ok(r
== MSIDBERROR_MOREDATA
, "MsiViewGetError return\n");
740 ok(buffer
[0] == 'x', "buffer cleared\n");
741 ok(sz
== 0, "size not zero\n");
743 /* ok this one is strange */
745 r
= MsiViewGetError( hview
, NULL
, &sz
);
746 ok(r
== MSIDBERROR_NOERROR
, "MsiViewGetError return\n");
747 ok(sz
== 0, "size not zero\n");
749 /* see if it really has an error */
752 r
= MsiViewGetError( hview
, buffer
, &sz
);
753 ok(r
== MSIDBERROR_NOERROR
, "MsiViewGetError return\n");
754 ok(buffer
[0] == 0, "buffer not cleared\n");
755 ok(sz
== 0, "size not zero\n");
757 r
= MsiViewExecute(hview
, 0);
758 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
760 /* try some invalid records */
761 r
= MsiViewModify(hview
, MSIMODIFY_INSERT
, 0 );
762 ok(r
== ERROR_INVALID_HANDLE
, "MsiViewModify failed\n");
763 r
= MsiViewModify(hview
, -1, 0 );
764 ok(r
== ERROR_INVALID_HANDLE
, "MsiViewModify failed\n");
766 /* try an small record */
767 hrec
= MsiCreateRecord(1);
768 r
= MsiViewModify(hview
, -1, hrec
);
769 ok(r
== ERROR_INVALID_DATA
, "MsiViewModify failed\n");
771 r
= MsiCloseHandle(hrec
);
772 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
774 /* insert a valid record */
775 hrec
= MsiCreateRecord(3);
777 r
= MsiRecordSetInteger(hrec
, 2, 1);
778 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
779 r
= MsiRecordSetString(hrec
, 2, "bob");
780 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
781 r
= MsiRecordSetString(hrec
, 3, "7654321");
782 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
784 r
= MsiViewExecute(hview
, 0);
785 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
786 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
787 ok(r
== ERROR_SUCCESS
, "MsiViewModify failed\n");
789 /* insert the same thing again */
790 r
= MsiViewExecute(hview
, 0);
791 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
793 /* should fail ... */
795 r
= MsiViewModify(hview
, MSIMODIFY_INSERT_TEMPORARY
, hrec
);
796 ok(r
== ERROR_FUNCTION_FAILED
, "MsiViewModify failed\n");
799 r
= MsiCloseHandle(hrec
);
800 ok(r
== ERROR_SUCCESS
, "failed to close record\n");
802 r
= MsiViewClose(hview
);
803 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
804 r
= MsiCloseHandle(hview
);
805 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
807 r
= MsiCloseHandle( hdb
);
808 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase close failed\n");
811 static MSIHANDLE
create_db(void)
818 /* create an empty database */
819 res
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
820 ok( res
== ERROR_SUCCESS
, "Failed to create database\n" );
821 if( res
!= ERROR_SUCCESS
)
824 res
= MsiDatabaseCommit( hdb
);
825 ok( res
== ERROR_SUCCESS
, "Failed to commit database\n" );
830 static void test_getcolinfo(void)
832 MSIHANDLE hdb
, hview
= 0, rec
= 0;
837 /* create an empty db */
839 ok( hdb
, "failed to create db\n");
841 /* tables should be present */
842 r
= MsiDatabaseOpenView(hdb
, "select * from _Tables", &hview
);
843 ok( r
== ERROR_SUCCESS
, "failed to open query\n");
845 r
= MsiViewExecute(hview
, 0);
846 ok( r
== ERROR_SUCCESS
, "failed to execute query\n");
848 /* check that NAMES works */
850 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_NAMES
, &rec
);
851 ok( r
== ERROR_SUCCESS
, "failed to get names\n");
853 r
= MsiRecordGetString(rec
, 1, buffer
, &sz
);
854 ok( r
== ERROR_SUCCESS
, "failed to get string\n");
855 ok( !strcmp(buffer
,"Name"), "_Tables has wrong column name\n");
856 r
= MsiCloseHandle( rec
);
857 ok( r
== ERROR_SUCCESS
, "failed to close record handle\n");
859 /* check that TYPES works */
861 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_TYPES
, &rec
);
862 ok( r
== ERROR_SUCCESS
, "failed to get names\n");
864 r
= MsiRecordGetString(rec
, 1, buffer
, &sz
);
865 ok( r
== ERROR_SUCCESS
, "failed to get string\n");
866 ok( !strcmp(buffer
,"s64"), "_Tables has wrong column type\n");
867 r
= MsiCloseHandle( rec
);
868 ok( r
== ERROR_SUCCESS
, "failed to close record handle\n");
870 /* check that invalid values fail */
872 r
= MsiViewGetColumnInfo( hview
, 100, &rec
);
873 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error code\n");
874 ok( rec
== 0, "returned a record\n");
876 r
= MsiViewGetColumnInfo( hview
, MSICOLINFO_TYPES
, NULL
);
877 ok( r
== ERROR_INVALID_PARAMETER
, "wrong error code\n");
879 r
= MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES
, &rec
);
880 ok( r
== ERROR_INVALID_HANDLE
, "wrong error code\n");
882 r
= MsiViewClose(hview
);
883 ok( r
== ERROR_SUCCESS
, "failed to close view\n");
884 r
= MsiCloseHandle(hview
);
885 ok( r
== ERROR_SUCCESS
, "failed to close view handle\n");
886 r
= MsiCloseHandle(hdb
);
887 ok( r
== ERROR_SUCCESS
, "failed to close database\n");
890 static MSIHANDLE
get_column_info(MSIHANDLE hdb
, const char *query
, MSICOLINFO type
)
892 MSIHANDLE hview
= 0, rec
= 0;
895 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
896 if( r
!= ERROR_SUCCESS
)
899 r
= MsiViewExecute(hview
, 0);
900 if( r
== ERROR_SUCCESS
)
902 MsiViewGetColumnInfo( hview
, type
, &rec
);
905 MsiCloseHandle(hview
);
909 static UINT
get_columns_table_type(MSIHANDLE hdb
, const char *table
, UINT field
)
911 MSIHANDLE hview
= 0, rec
= 0;
915 sprintf(query
, "select * from `_Columns` where `Table` = '%s'", table
);
917 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
918 if( r
!= ERROR_SUCCESS
)
921 r
= MsiViewExecute(hview
, 0);
922 if( r
== ERROR_SUCCESS
)
926 r
= MsiViewFetch( hview
, &rec
);
927 if( r
!= ERROR_SUCCESS
)
929 r
= MsiRecordGetInteger( rec
, 2 );
931 type
= MsiRecordGetInteger( rec
, 4 );
932 MsiCloseHandle( rec
);
937 MsiCloseHandle(hview
);
941 static BOOL
check_record( MSIHANDLE rec
, UINT field
, LPCSTR val
)
948 r
= MsiRecordGetString( rec
, field
, buffer
, &sz
);
949 return (r
== ERROR_SUCCESS
) && !strcmp(val
, buffer
);
952 static void test_viewgetcolumninfo(void)
954 MSIHANDLE hdb
= 0, rec
;
958 ok( hdb
, "failed to create db\n");
960 r
= run_query( hdb
, 0,
961 "CREATE TABLE `Properties` "
962 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
963 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
965 /* check the column types */
966 rec
= get_column_info( hdb
, "select * from `Properties`", MSICOLINFO_TYPES
);
967 ok( rec
, "failed to get column info record\n" );
969 ok( check_record( rec
, 1, "S255"), "wrong record type\n");
970 ok( check_record( rec
, 2, "S1"), "wrong record type\n");
972 MsiCloseHandle( rec
);
974 /* check the type in _Columns */
975 ok( 0x3dff == get_columns_table_type(hdb
, "Properties", 1 ), "_columns table wrong\n");
976 ok( 0x1d01 == get_columns_table_type(hdb
, "Properties", 2 ), "_columns table wrong\n");
978 /* now try the names */
979 rec
= get_column_info( hdb
, "select * from `Properties`", MSICOLINFO_NAMES
);
980 ok( rec
, "failed to get column info record\n" );
982 ok( check_record( rec
, 1, "Property"), "wrong record type\n");
983 ok( check_record( rec
, 2, "Value"), "wrong record type\n");
985 MsiCloseHandle( rec
);
987 r
= run_query( hdb
, 0,
988 "CREATE TABLE `Binary` "
989 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
990 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
992 /* check the column types */
993 rec
= get_column_info( hdb
, "select * from `Binary`", MSICOLINFO_TYPES
);
994 ok( rec
, "failed to get column info record\n" );
996 ok( check_record( rec
, 1, "S255"), "wrong record type\n");
997 ok( check_record( rec
, 2, "V0"), "wrong record type\n");
999 MsiCloseHandle( rec
);
1001 /* check the type in _Columns */
1002 ok( 0x3dff == get_columns_table_type(hdb
, "Binary", 1 ), "_columns table wrong\n");
1003 ok( 0x1900 == get_columns_table_type(hdb
, "Binary", 2 ), "_columns table wrong\n");
1005 /* now try the names */
1006 rec
= get_column_info( hdb
, "select * from `Binary`", MSICOLINFO_NAMES
);
1007 ok( rec
, "failed to get column info record\n" );
1009 ok( check_record( rec
, 1, "Name"), "wrong record type\n");
1010 ok( check_record( rec
, 2, "Data"), "wrong record type\n");
1011 MsiCloseHandle( rec
);
1013 r
= run_query( hdb
, 0,
1014 "CREATE TABLE `UIText` "
1015 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
1016 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1018 ok( 0x2d48 == get_columns_table_type(hdb
, "UIText", 1 ), "_columns table wrong\n");
1019 ok( 0x1fff == get_columns_table_type(hdb
, "UIText", 2 ), "_columns table wrong\n");
1021 rec
= get_column_info( hdb
, "select * from `UIText`", MSICOLINFO_NAMES
);
1022 ok( rec
, "failed to get column info record\n" );
1023 ok( check_record( rec
, 1, "Key"), "wrong record type\n");
1024 ok( check_record( rec
, 2, "Text"), "wrong record type\n");
1025 MsiCloseHandle( rec
);
1027 rec
= get_column_info( hdb
, "select * from `UIText`", MSICOLINFO_TYPES
);
1028 ok( rec
, "failed to get column info record\n" );
1029 ok( check_record( rec
, 1, "s72"), "wrong record type\n");
1030 ok( check_record( rec
, 2, "L255"), "wrong record type\n");
1031 MsiCloseHandle( rec
);
1033 MsiCloseHandle( hdb
);
1036 static void test_msiexport(void)
1038 MSIHANDLE hdb
= 0, hview
= 0;
1041 char path
[MAX_PATH
];
1042 const char file
[] = "phone.txt";
1046 const char expected
[] =
1047 "id\tname\tnumber\r\n"
1050 "1\tAbe\t8675309\r\n";
1052 DeleteFile(msifile
);
1054 /* just MsiOpenDatabase should not create a file */
1055 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1056 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1058 /* create a table */
1059 query
= "CREATE TABLE `phone` ( "
1060 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
1061 "PRIMARY KEY `id`)";
1062 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1063 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1064 r
= MsiViewExecute(hview
, 0);
1065 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1066 r
= MsiViewClose(hview
);
1067 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1068 r
= MsiCloseHandle(hview
);
1069 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1071 /* insert a value into it */
1072 query
= "INSERT INTO `phone` ( `id`, `name`, `number` )"
1073 "VALUES('1', 'Abe', '8675309')";
1074 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
1075 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1076 r
= MsiViewExecute(hview
, 0);
1077 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1078 r
= MsiViewClose(hview
);
1079 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
1080 r
= MsiCloseHandle(hview
);
1081 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
1083 GetCurrentDirectory(MAX_PATH
, path
);
1085 r
= MsiDatabaseExport(hdb
, "phone", path
, file
);
1086 ok(r
== ERROR_SUCCESS
, "MsiDatabaseExport failed\n");
1088 MsiCloseHandle(hdb
);
1090 lstrcat(path
, "\\");
1091 lstrcat(path
, file
);
1093 /* check the data that was written */
1095 memset(buffer
, 0, sizeof buffer
);
1096 handle
= CreateFile(path
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
1097 if (handle
!= INVALID_HANDLE_VALUE
)
1099 ReadFile(handle
, buffer
, sizeof buffer
, &length
, NULL
);
1100 CloseHandle(handle
);
1104 ok(0, "failed to open file %s\n", path
);
1106 ok( length
== strlen(expected
), "length of data wrong\n");
1107 ok( !lstrcmp(buffer
, expected
), "data doesn't match\n");
1108 DeleteFile(msifile
);
1111 static void test_longstrings(void)
1113 const char insert_query
[] =
1114 "INSERT INTO `strings` ( `id`, `val` ) VALUES('1', 'Z')";
1116 MSIHANDLE hdb
= 0, hview
= 0, hrec
= 0;
1119 const DWORD STRING_LENGTH
= 0x10005;
1121 DeleteFile(msifile
);
1122 /* just MsiOpenDatabase should not create a file */
1123 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1124 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1126 /* create a table */
1128 "CREATE TABLE `strings` ( `id` INT, `val` CHAR(0) PRIMARY KEY `id`)");
1129 ok(r
== ERROR_SUCCESS
, "query failed\n");
1131 /* try a insert a very long string */
1132 str
= HeapAlloc(GetProcessHeap(), 0, STRING_LENGTH
+sizeof insert_query
);
1133 len
= strchr(insert_query
, 'Z') - insert_query
;
1134 strcpy(str
, insert_query
);
1135 memset(str
+len
, 'Z', STRING_LENGTH
);
1136 strcpy(str
+len
+STRING_LENGTH
, insert_query
+len
+1);
1137 r
= try_query( hdb
, str
);
1138 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1140 HeapFree(GetProcessHeap(), 0, str
);
1142 MsiDatabaseCommit(hdb
);
1143 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
1144 MsiCloseHandle(hdb
);
1146 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_READONLY
, &hdb
);
1147 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
1149 r
= MsiDatabaseOpenView(hdb
, "select * from `strings` where `id` = 1", &hview
);
1150 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
1152 r
= MsiViewExecute(hview
, 0);
1153 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
1155 r
= MsiViewFetch(hview
, &hrec
);
1156 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1158 MsiCloseHandle(hview
);
1160 r
= MsiRecordGetString(hrec
, 2, NULL
, &len
);
1161 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed\n");
1162 ok(len
== STRING_LENGTH
, "string length wrong\n");
1164 MsiCloseHandle(hrec
);
1165 MsiCloseHandle(hdb
);
1166 DeleteFile(msifile
);
1169 static void create_file(const CHAR
*name
)
1174 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
1175 ok(file
!= INVALID_HANDLE_VALUE
, "Failure to open file %s\n", name
);
1176 WriteFile(file
, name
, strlen(name
), &written
, NULL
);
1177 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
1181 static void test_streamtable(void)
1183 MSIHANDLE hdb
= 0, rec
, view
;
1184 char file
[MAX_PATH
];
1190 ok( hdb
, "failed to create db\n");
1192 r
= run_query( hdb
, 0,
1193 "CREATE TABLE `Properties` "
1194 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
1195 ok( r
== ERROR_SUCCESS
, "Failed to create table\n" );
1197 r
= run_query( hdb
, 0,
1198 "INSERT INTO `Properties` "
1199 "( `Value`, `Property` ) VALUES ( 'Prop', 'value' )" );
1200 ok( r
== ERROR_SUCCESS
, "Failed to add to table\n" );
1202 r
= MsiDatabaseCommit( hdb
);
1203 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
1205 MsiCloseHandle( hdb
);
1207 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb
);
1208 ok( r
== ERROR_SUCCESS
, "Failed to open database\n" );
1210 /* check the column types */
1211 rec
= get_column_info( hdb
, "select * from `_Streams`", MSICOLINFO_TYPES
);
1212 ok( rec
, "failed to get column info record\n" );
1214 ok( check_record( rec
, 1, "s62"), "wrong record type\n");
1215 ok( check_record( rec
, 2, "V0"), "wrong record type\n");
1217 MsiCloseHandle( rec
);
1219 /* now try the names */
1220 rec
= get_column_info( hdb
, "select * from `_Streams`", MSICOLINFO_NAMES
);
1221 ok( rec
, "failed to get column info record\n" );
1223 ok( check_record( rec
, 1, "Name"), "wrong record type\n");
1224 ok( check_record( rec
, 2, "Data"), "wrong record type\n");
1226 MsiCloseHandle( rec
);
1228 /* insert a file into the _Streams table */
1229 create_file( "test.txt" );
1231 rec
= MsiCreateRecord( 2 );
1232 MsiRecordSetString( rec
, 1, "data" );
1234 r
= MsiRecordSetStream( rec
, 2, "test.txt" );
1235 ok( r
== ERROR_SUCCESS
, "Failed to add stream data to the record: %d\n", r
);
1237 DeleteFile("test.txt");
1239 r
= MsiDatabaseOpenView( hdb
,
1240 "INSERT INTO `_Streams` ( `Name`, `Data` ) VALUES ( ?, ? )", &view
);
1241 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1243 r
= MsiViewExecute( view
, rec
);
1244 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1246 MsiCloseHandle( rec
);
1247 MsiCloseHandle( view
);
1249 r
= MsiDatabaseOpenView( hdb
,
1250 "SELECT `Name`, `Data` FROM `_Streams`", &view
);
1251 ok( r
== ERROR_SUCCESS
, "Failed to open database view: %d\n", r
);
1253 r
= MsiViewExecute( view
, 0 );
1254 ok( r
== ERROR_SUCCESS
, "Failed to execute view: %d\n", r
);
1256 r
= MsiViewFetch( view
, &rec
);
1257 ok( r
== ERROR_SUCCESS
, "Failed to fetch record: %d\n", r
);
1260 r
= MsiRecordGetString( rec
, 1, file
, &size
);
1261 ok( r
== ERROR_SUCCESS
, "Failed to get string: %d\n", r
);
1262 ok( !lstrcmp(file
, "data"), "Expected 'data', got %s\n", file
);
1265 memset(buf
, 0, MAX_PATH
);
1266 r
= MsiRecordReadStream( rec
, 2, buf
, &size
);
1267 ok( r
== ERROR_SUCCESS
, "Failed to get stream: %d\n", r
);
1268 ok( !lstrcmp(buf
, "test.txt\n"), "Expected 'test.txt\\n', got %s\n", buf
);
1270 MsiCloseHandle( rec
);
1272 r
= MsiViewFetch( view
, &rec
);
1273 ok( r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
1275 MsiCloseHandle( view
);
1276 MsiCloseHandle( hdb
);
1277 DeleteFile(msifile
);
1280 static void test_where(void)
1282 MSIHANDLE hdb
= 0, rec
, view
;
1290 ok( hdb
, "failed to create db\n");
1292 r
= run_query( hdb
, 0,
1293 "CREATE TABLE `Media` ("
1294 "`DiskId` SHORT NOT NULL, "
1295 "`LastSequence` LONG, "
1296 "`DiskPrompt` CHAR(64) LOCALIZABLE, "
1297 "`Cabinet` CHAR(255), "
1298 "`VolumeLabel` CHAR(32), "
1299 "`Source` CHAR(72) "
1300 "PRIMARY KEY `DiskId`)" );
1301 ok( r
== S_OK
, "cannot create Media table: %d\n", r
);
1303 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1304 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1305 "VALUES ( 1, 0, '', 'zero.cab', '', '' )" );
1306 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1308 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1309 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1310 "VALUES ( 2, 1, '', 'one.cab', '', '' )" );
1311 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1313 r
= run_query( hdb
, 0, "INSERT INTO `Media` "
1314 "( `DiskId`, `LastSequence`, `DiskPrompt`, `Cabinet`, `VolumeLabel`, `Source` ) "
1315 "VALUES ( 3, 2, '', 'two.cab', '', '' )" );
1316 ok( r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
1318 query
= "SELECT * FROM `Media`";
1319 r
= do_query(hdb
, query
, &rec
);
1320 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed: %d\n", r
);
1321 ok( check_record( rec
, 4, "zero.cab"), "wrong cabinet\n");
1322 MsiCloseHandle( rec
);
1324 query
= "SELECT * FROM `Media` WHERE `LastSequence` >= 1";
1325 r
= do_query(hdb
, query
, &rec
);
1326 ok(r
== ERROR_SUCCESS
, "MsiViewFetch failed: %d\n", r
);
1327 ok( check_record( rec
, 4, "one.cab"), "wrong cabinet\n");
1329 r
= MsiRecordGetInteger(rec
, 1);
1330 ok( 2 == r
, "field wrong\n");
1331 r
= MsiRecordGetInteger(rec
, 2);
1332 ok( 1 == r
, "field wrong\n");
1333 MsiCloseHandle( rec
);
1335 query
= "SELECT `DiskId` FROM `Media` WHERE `LastSequence` >= 1 AND DiskId >= 0";
1336 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1337 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
1339 r
= MsiViewExecute(view
, 0);
1340 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
1342 r
= MsiViewFetch(view
, &rec
);
1343 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1345 count
= MsiRecordGetFieldCount( rec
);
1346 ok( count
== 1, "Expected 1 record fields, got %d\n", count
);
1349 r
= MsiRecordGetString( rec
, 1, buf
, &size
);
1350 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
1351 ok( !lstrcmp( buf
, "2" ),
1352 "For (row %d, column 1) expected '%d', got %s\n", 0, 2, buf
);
1353 MsiCloseHandle( rec
);
1355 r
= MsiViewFetch(view
, &rec
);
1356 ok( r
== ERROR_SUCCESS
, "failed to fetch view: %d\n", r
);
1359 r
= MsiRecordGetString( rec
, 1, buf
, &size
);
1360 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
1361 ok( !lstrcmp( buf
, "3" ),
1362 "For (row %d, column 1) expected '%d', got %s\n", 1, 3, buf
);
1363 MsiCloseHandle( rec
);
1365 r
= MsiViewFetch(view
, &rec
);
1366 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
1369 MsiCloseHandle(view
);
1371 MsiCloseHandle( rec
);
1374 query
= "SELECT * FROM `Media` WHERE `DiskPrompt` IS NULL";
1375 r
= do_query(hdb
, query
, &rec
);
1376 ok( r
== ERROR_SUCCESS
, "query failed: %d\n", r
);
1377 MsiCloseHandle( rec
);
1379 MsiCloseHandle( hdb
);
1380 DeleteFile(msifile
);
1383 static CHAR CURR_DIR
[MAX_PATH
];
1385 static const CHAR test_data
[] = "FirstPrimaryColumn\tSecondPrimaryColumn\tShortInt\tShortIntNullable\tLongInt\tLongIntNullable\tString\tLocalizableString\tLocalizableStringNullable\n"
1386 "s255\ti2\ti2\tI2\ti4\tI4\tS255\tS0\ts0\n"
1387 "TestTable\tFirstPrimaryColumn\n"
1388 "stringage\t5\t2\t\t2147483640\t-2147483640\tanother string\tlocalizable\tduh\n";
1390 static const CHAR two_primary
[] = "PrimaryOne\tPrimaryTwo\n"
1392 "TwoPrimary\tPrimaryOne\tPrimaryTwo\n"
1396 static void write_file(const CHAR
*filename
, const char *data
, int data_size
)
1400 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
1401 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1403 WriteFile(hf
, data
, data_size
, &size
, NULL
);
1407 static UINT
add_table_to_db(MSIHANDLE hdb
, LPCSTR table_data
)
1411 write_file("temp_file", table_data
, (lstrlen(table_data
) - 1) * sizeof(char));
1412 r
= MsiDatabaseImportA(hdb
, CURR_DIR
, "temp_file");
1413 DeleteFileA("temp_file");
1418 static void test_msiimport(void)
1420 MSIHANDLE hdb
, view
, rec
;
1425 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
1427 r
= MsiOpenDatabaseA(msifile
, MSIDBOPEN_CREATE
, &hdb
);
1428 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1430 r
= add_table_to_db(hdb
, test_data
);
1431 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1433 r
= add_table_to_db(hdb
, two_primary
);
1434 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1436 query
= "SELECT * FROM `TestTable`";
1437 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1438 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1440 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
1441 count
= MsiRecordGetFieldCount(rec
);
1442 ok(count
== 9, "Expected 9, got %d\n", count
);
1443 ok(check_record(rec
, 1, "FirstPrimaryColumn"), "Expected FirstPrimaryColumn\n");
1444 ok(check_record(rec
, 2, "SecondPrimaryColumn"), "Expected SecondPrimaryColumn\n");
1445 ok(check_record(rec
, 3, "ShortInt"), "Expected ShortInt\n");
1446 ok(check_record(rec
, 4, "ShortIntNullable"), "Expected ShortIntNullalble\n");
1447 ok(check_record(rec
, 5, "LongInt"), "Expected LongInt\n");
1448 ok(check_record(rec
, 6, "LongIntNullable"), "Expected LongIntNullalble\n");
1449 ok(check_record(rec
, 7, "String"), "Expected String\n");
1450 ok(check_record(rec
, 8, "LocalizableString"), "Expected LocalizableString\n");
1451 ok(check_record(rec
, 9, "LocalizableStringNullable"), "Expected LocalizableStringNullable\n");
1452 MsiCloseHandle(rec
);
1454 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1455 count
= MsiRecordGetFieldCount(rec
);
1456 ok(count
== 9, "Expected 9, got %d\n", count
);
1457 ok(check_record(rec
, 1, "s255"), "Expected s255\n");
1458 ok(check_record(rec
, 2, "i2"), "Expected i2\n");
1459 ok(check_record(rec
, 3, "i2"), "Expected i2\n");
1460 ok(check_record(rec
, 4, "I2"), "Expected I2\n");
1461 ok(check_record(rec
, 5, "i4"), "Expected i4\n");
1462 ok(check_record(rec
, 6, "I4"), "Expected I4\n");
1463 ok(check_record(rec
, 7, "S255"), "Expected S255\n");
1464 ok(check_record(rec
, 8, "S0"), "Expected S0\n");
1465 ok(check_record(rec
, 9, "s0"), "Expected s0\n");
1466 MsiCloseHandle(rec
);
1468 query
= "SELECT * FROM `TestTable`";
1469 r
= do_query(hdb
, query
, &rec
);
1470 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1471 ok(check_record(rec
, 1, "stringage"), "Expected 'stringage'\n");
1472 ok(check_record(rec
, 7, "another string"), "Expected 'another string'\n");
1473 ok(check_record(rec
, 8, "localizable"), "Expected 'localizable'\n");
1474 ok(check_record(rec
, 9, "duh"), "Expected 'duh'\n");
1476 i
= MsiRecordGetInteger(rec
, 2);
1477 ok(i
== 5, "Expected 5, got %d\n", i
);
1479 i
= MsiRecordGetInteger(rec
, 3);
1480 ok(i
== 2, "Expected 2, got %d\n", i
);
1482 i
= MsiRecordGetInteger(rec
, 4);
1483 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
1485 i
= MsiRecordGetInteger(rec
, 5);
1486 ok(i
== 2147483640, "Expected 2147483640, got %d\n", i
);
1488 i
= MsiRecordGetInteger(rec
, 6);
1489 ok(i
== -2147483640, "Expected -2147483640, got %d\n", i
);
1491 MsiCloseHandle(rec
);
1492 MsiCloseHandle(view
);
1494 query
= "SELECT * FROM `TwoPrimary`";
1495 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
1496 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1498 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
1499 count
= MsiRecordGetFieldCount(rec
);
1500 ok(count
== 2, "Expected 2, got %d\n", count
);
1501 ok(check_record(rec
, 1, "PrimaryOne"), "Expected PrimaryOne\n");
1502 ok(check_record(rec
, 2, "PrimaryTwo"), "Expected PrimaryTwo\n");
1504 MsiCloseHandle(rec
);
1506 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
1507 count
= MsiRecordGetFieldCount(rec
);
1508 ok(count
== 2, "Expected 2, got %d\n", count
);
1509 ok(check_record(rec
, 1, "s255"), "Expected s255\n");
1510 ok(check_record(rec
, 2, "s255"), "Expected s255\n");
1511 MsiCloseHandle(rec
);
1513 r
= MsiViewExecute(view
, 0);
1514 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1516 r
= MsiViewFetch(view
, &rec
);
1517 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1519 ok(check_record(rec
, 1, "papaya"), "Expected 'papaya'\n");
1520 ok(check_record(rec
, 2, "leaf"), "Expected 'leaf'\n");
1522 MsiCloseHandle(rec
);
1524 r
= MsiViewFetch(view
, &rec
);
1525 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1527 ok(check_record(rec
, 1, "papaya"), "Expected 'papaya'\n");
1528 ok(check_record(rec
, 2, "flower"), "Expected 'flower'\n");
1530 MsiCloseHandle(rec
);
1532 r
= MsiViewFetch(view
, &rec
);
1533 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
1535 r
= MsiViewClose(view
);
1536 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1538 MsiCloseHandle(view
);
1539 MsiCloseHandle(hdb
);
1540 DeleteFileA(msifile
);
1543 static void test_markers(void)
1550 ok( hdb
, "failed to create db\n");
1552 rec
= MsiCreateRecord(3);
1553 MsiRecordSetString(rec
, 1, "Table");
1554 MsiRecordSetString(rec
, 2, "Apples");
1555 MsiRecordSetString(rec
, 3, "Oranges");
1557 /* try a legit create */
1558 query
= "CREATE TABLE `Table` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1559 r
= run_query(hdb
, 0, query
);
1560 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1561 MsiCloseHandle(rec
);
1563 /* try table name as marker */
1564 rec
= MsiCreateRecord(1);
1565 MsiRecordSetString(rec
, 1, "Fable");
1566 query
= "CREATE TABLE `?` ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1567 r
= run_query(hdb
, rec
, query
);
1568 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1570 /* verify that we just created a table called '?', not 'Fable' */
1571 r
= try_query(hdb
, "SELECT * from `Fable`");
1572 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1574 r
= try_query(hdb
, "SELECT * from `?`");
1575 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1577 /* try table name as marker without backticks */
1578 MsiRecordSetString(rec
, 1, "Mable");
1579 query
= "CREATE TABLE ? ( `One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1580 r
= run_query(hdb
, rec
, query
);
1581 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1583 /* try one column name as marker */
1584 MsiRecordSetString(rec
, 1, "One");
1585 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`)";
1586 r
= run_query(hdb
, rec
, query
);
1587 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1588 MsiCloseHandle(rec
);
1590 /* try column names as markers */
1591 rec
= MsiCreateRecord(2);
1592 MsiRecordSetString(rec
, 1, "One");
1593 MsiRecordSetString(rec
, 2, "Two");
1594 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `One`)";
1595 r
= run_query(hdb
, rec
, query
);
1596 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1597 MsiCloseHandle(rec
);
1599 /* try names with backticks */
1600 rec
= MsiCreateRecord(3);
1601 MsiRecordSetString(rec
, 1, "One");
1602 MsiRecordSetString(rec
, 2, "Two");
1603 MsiRecordSetString(rec
, 3, "One");
1604 query
= "CREATE TABLE `Mable` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1605 r
= run_query(hdb
, rec
, query
);
1606 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1608 /* try names with backticks, minus definitions */
1609 query
= "CREATE TABLE `Mable` ( `?`, `?` PRIMARY KEY `?`)";
1610 r
= run_query(hdb
, rec
, query
);
1611 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1613 /* try names without backticks */
1614 query
= "CREATE TABLE `Mable` ( ? SHORT NOT NULL, ? CHAR(255) PRIMARY KEY ?)";
1615 r
= run_query(hdb
, rec
, query
);
1616 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1617 MsiCloseHandle(rec
);
1619 /* try one long marker */
1620 rec
= MsiCreateRecord(1);
1621 MsiRecordSetString(rec
, 1, "`One` SHORT NOT NULL, `Two` CHAR(255) PRIMARY KEY `One`");
1622 query
= "CREATE TABLE `Mable` ( ? )";
1623 r
= run_query(hdb
, rec
, query
);
1624 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1625 MsiCloseHandle(rec
);
1627 /* try all names as markers */
1628 rec
= MsiCreateRecord(4);
1629 MsiRecordSetString(rec
, 1, "Mable");
1630 MsiRecordSetString(rec
, 2, "One");
1631 MsiRecordSetString(rec
, 3, "Two");
1632 MsiRecordSetString(rec
, 4, "One");
1633 query
= "CREATE TABLE `?` ( `?` SHORT NOT NULL, `?` CHAR(255) PRIMARY KEY `?`)";
1634 r
= run_query(hdb
, rec
, query
);
1635 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1636 MsiCloseHandle(rec
);
1638 /* try a legit insert */
1639 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( 5, 'hello' )";
1640 r
= run_query(hdb
, 0, query
);
1641 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1643 r
= try_query(hdb
, "SELECT * from `Table`");
1644 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1646 /* try values as markers */
1647 rec
= MsiCreateRecord(2);
1648 MsiRecordSetInteger(rec
, 1, 4);
1649 MsiRecordSetString(rec
, 2, "hi");
1650 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1651 r
= run_query(hdb
, rec
, query
);
1652 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1653 MsiCloseHandle(rec
);
1655 /* try column names and values as markers */
1656 rec
= MsiCreateRecord(4);
1657 MsiRecordSetString(rec
, 1, "One");
1658 MsiRecordSetString(rec
, 2, "Two");
1659 MsiRecordSetInteger(rec
, 3, 5);
1660 MsiRecordSetString(rec
, 4, "hi");
1661 query
= "INSERT INTO `Table` ( `?`, `?` ) VALUES ( ?, '?' )";
1662 r
= run_query(hdb
, rec
, query
);
1663 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1664 MsiCloseHandle(rec
);
1666 /* try column names as markers */
1667 rec
= MsiCreateRecord(2);
1668 MsiRecordSetString(rec
, 1, "One");
1669 MsiRecordSetString(rec
, 2, "Two");
1670 query
= "INSERT INTO `Table` ( `?`, `?` ) VALUES ( 3, 'yellow' )";
1671 r
= run_query(hdb
, rec
, query
);
1672 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1673 MsiCloseHandle(rec
);
1675 /* try table name as a marker */
1676 rec
= MsiCreateRecord(1);
1677 MsiRecordSetString(rec
, 1, "Table");
1678 query
= "INSERT INTO `?` ( `One`, `Two` ) VALUES ( 2, 'green' )";
1679 r
= run_query(hdb
, rec
, query
);
1680 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1681 MsiCloseHandle(rec
);
1683 /* try table name and values as markers */
1684 rec
= MsiCreateRecord(3);
1685 MsiRecordSetString(rec
, 1, "Table");
1686 MsiRecordSetInteger(rec
, 2, 10);
1687 MsiRecordSetString(rec
, 3, "haha");
1688 query
= "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
1689 r
= run_query(hdb
, rec
, query
);
1690 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
1691 MsiCloseHandle(rec
);
1693 /* try all markers */
1694 rec
= MsiCreateRecord(5);
1695 MsiRecordSetString(rec
, 1, "Table");
1696 MsiRecordSetString(rec
, 1, "One");
1697 MsiRecordSetString(rec
, 1, "Two");
1698 MsiRecordSetInteger(rec
, 2, 10);
1699 MsiRecordSetString(rec
, 3, "haha");
1700 query
= "INSERT INTO `?` ( `?`, `?` ) VALUES ( ?, '?' )";
1701 r
= run_query(hdb
, rec
, query
);
1702 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
1703 MsiCloseHandle(rec
);
1705 /* insert an integer as a string */
1706 rec
= MsiCreateRecord(2);
1707 MsiRecordSetString(rec
, 1, "11");
1708 MsiRecordSetString(rec
, 2, "hi");
1709 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, '?' )";
1710 r
= run_query(hdb
, rec
, query
);
1711 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1712 MsiCloseHandle(rec
);
1714 /* leave off the '' for the string */
1715 rec
= MsiCreateRecord(2);
1716 MsiRecordSetInteger(rec
, 1, 12);
1717 MsiRecordSetString(rec
, 2, "hi");
1718 query
= "INSERT INTO `Table` ( `One`, `Two` ) VALUES ( ?, ? )";
1719 r
= run_query(hdb
, rec
, query
);
1720 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
1721 MsiCloseHandle(rec
);
1723 MsiCloseHandle(hdb
);
1724 DeleteFileA(msifile
);
1727 #define MY_NVIEWS 4000 /* Largest installer I've seen uses < 2k */
1728 static void test_handle_limit(void)
1732 MSIHANDLE hviews
[MY_NVIEWS
];
1735 /* create an empty db */
1737 ok( hdb
, "failed to create db\n");
1739 memset(hviews
, 0, sizeof(hviews
));
1741 for (i
=0; i
<MY_NVIEWS
; i
++) {
1742 static char szQueryBuf
[256] = "SELECT * from `_Tables`";
1743 hviews
[i
] = 0xdeadbeeb;
1744 r
= MsiDatabaseOpenView(hdb
, szQueryBuf
, &hviews
[i
]);
1745 if( r
!= ERROR_SUCCESS
|| hviews
[i
] == 0xdeadbeeb ||
1746 hviews
[i
] == 0 || (i
&& (hviews
[i
] == hviews
[i
-1])))
1750 ok( i
== MY_NVIEWS
, "problem opening views\n");
1752 for (i
=0; i
<MY_NVIEWS
; i
++) {
1753 if (hviews
[i
] != 0 && hviews
[i
] != 0xdeadbeeb) {
1754 r
= MsiCloseHandle(hviews
[i
]);
1755 if (r
!= ERROR_SUCCESS
)
1760 ok( i
== MY_NVIEWS
, "problem closing views\n");
1762 r
= MsiCloseHandle(hdb
);
1763 ok( r
== ERROR_SUCCESS
, "failed to close database\n");
1766 static void generate_transform(void)
1768 MSIHANDLE hdb1
, hdb2
, hrec
;
1772 /* start with two identical databases */
1773 CopyFile(msifile2
, msifile
, FALSE
);
1775 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_TRANSACT
, &hdb1
);
1776 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
1778 r
= MsiDatabaseCommit( hdb1
);
1779 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
1781 r
= MsiOpenDatabase(msifile2
, MSIDBOPEN_READONLY
, &hdb2
);
1782 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
1784 /* the transform between two identical database should be empty */
1785 r
= MsiDatabaseGenerateTransform(hdb1
, hdb2
, NULL
, 0, 0);
1787 ok( r
== ERROR_NO_DATA
, "return code %d, should be ERROR_NO_DATA\n", r
);
1790 query
= "CREATE TABLE `AAR` ( `BAR` SHORT NOT NULL, `CAR` CHAR(255) PRIMARY KEY `CAR`)";
1791 r
= run_query(hdb1
, 0, query
);
1792 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
1794 query
= "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 1, 'vw' )";
1795 r
= run_query(hdb1
, 0, query
);
1796 ok(r
== ERROR_SUCCESS
, "failed to add row 1\n");
1798 query
= "INSERT INTO `AAR` ( `BAR`, `CAR` ) VALUES ( 2, 'bmw' )";
1799 r
= run_query(hdb1
, 0, query
);
1800 ok(r
== ERROR_SUCCESS
, "failed to add row 2\n");
1802 query
= "UPDATE `MOO` SET `OOO` = 'c' WHERE `NOO` = 1";
1803 r
= run_query(hdb1
, 0, query
);
1804 ok(r
== ERROR_SUCCESS
, "failed to modify row\n");
1806 query
= "DELETE FROM `MOO` WHERE `NOO` = 3";
1807 r
= run_query(hdb1
, 0, query
);
1808 ok(r
== ERROR_SUCCESS
, "failed to delete row\n");
1810 hrec
= MsiCreateRecord(2);
1811 r
= MsiRecordSetInteger(hrec
, 1, 1);
1812 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
1814 write_file("testdata.bin", "naengmyon", 9);
1815 r
= MsiRecordSetStream(hrec
, 2, "testdata.bin");
1816 ok(r
== ERROR_SUCCESS
, "failed to set stream\n");
1818 query
= "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
1819 r
= run_query(hdb1
, hrec
, query
);
1820 ok(r
== ERROR_SUCCESS
, "failed to add row with blob\n");
1822 MsiCloseHandle(hrec
);
1824 /* database needs to be committed */
1825 MsiDatabaseCommit(hdb1
);
1827 r
= MsiDatabaseGenerateTransform(hdb1
, hdb2
, mstfile
, 0, 0);
1828 ok( r
== ERROR_SUCCESS
, "return code %d, should be ERROR_SUCCESS\n", r
);
1830 MsiCloseHandle( hdb1
);
1831 MsiCloseHandle( hdb2
);
1833 DeleteFile("testdata.bin");
1836 /* data for generating a transform */
1838 /* tables transform names - encoded as they would be in an msi database file */
1839 static const WCHAR name1
[] = { 0x4840, 0x3a8a, 0x481b, 0 }; /* AAR */
1840 static const WCHAR name2
[] = { 0x4840, 0x3b3f, 0x43f2, 0x4438, 0x45b1, 0 }; /* _Columns */
1841 static const WCHAR name3
[] = { 0x4840, 0x3f7f, 0x4164, 0x422f, 0x4836, 0 }; /* _Tables */
1842 static const WCHAR name4
[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3b6a, 0x45e4, 0x4824, 0 }; /* _StringData */
1843 static const WCHAR name5
[] = { 0x4840, 0x3f3f, 0x4577, 0x446c, 0x3e6a, 0x44b2, 0x482f, 0 }; /* _StringPool */
1844 static const WCHAR name6
[] = { 0x4840, 0x3e16, 0x4818, 0}; /* MOO */
1845 static const WCHAR name7
[] = { 0x4840, 0x3c8b, 0x3a97, 0x409b, 0 }; /* BINARY */
1846 static const WCHAR name8
[] = { 0x3c8b, 0x3a97, 0x409b, 0x387e, 0 }; /* BINARY.1 */
1848 /* data in each table */
1849 static const WCHAR data1
[] = { /* AAR */
1850 0x0201, 0x0005, 0x8001, /* 0x0201 = add row (1), two shorts */
1851 0x0201, 0x0006, 0x8002,
1853 static const WCHAR data2
[] = { /* _Columns */
1854 0x0401, 0x0002, 0x0000, 0x0003, 0xbdff, /* 0x0401 = add row (1), 4 shorts */
1855 0x0401, 0x0002, 0x0000, 0x0004, 0x8502,
1857 static const WCHAR data3
[] = { /* _Tables */
1858 0x0101, 0x0002, /* 0x0101 = add row (1), 1 short */
1860 static const char data4
[] = /* _StringData */
1861 "cAARCARBARvwbmw"; /* all the strings squashed together */
1862 static const WCHAR data5
[] = { /* _StringPool */
1864 0, 0, /* string 0 '' */
1865 1, 1, /* string 1 'c' */
1866 3, 3, /* string 2 'AAR' */
1867 3, 1, /* string 3 'CAR' */
1868 3, 1, /* string 4 'BAR' */
1869 2, 1, /* string 5 'vw' */
1870 3, 1, /* string 6 'bmw' */
1872 /* update row, 0x0002 is a bitmask of present column data, keys are excluded */
1873 static const WCHAR data6
[] = { /* MOO */
1874 0x0002, 0x8001, 0x0001, /* update row */
1875 0x0000, 0x8003, /* delete row */
1878 static const WCHAR data7
[] = { /* BINARY */
1879 0x0201, 0x8001, 0x0001,
1882 static const char data8
[] = /* stream data for the BINARY table */
1885 static const struct {
1889 } table_transform_data
[] =
1891 { name1
, data1
, sizeof data1
},
1892 { name2
, data2
, sizeof data2
},
1893 { name3
, data3
, sizeof data3
},
1894 { name4
, data4
, sizeof data4
- 1 },
1895 { name5
, data5
, sizeof data5
},
1896 { name6
, data6
, sizeof data6
},
1897 { name7
, data7
, sizeof data7
},
1898 { name8
, data8
, sizeof data8
- 1 },
1901 #define NUM_TRANSFORM_TABLES (sizeof table_transform_data/sizeof table_transform_data[0])
1903 static void generate_transform_manual(void)
1905 IStorage
*stg
= NULL
;
1910 const DWORD mode
= STGM_CREATE
|STGM_READWRITE
|STGM_DIRECT
|STGM_SHARE_EXCLUSIVE
;
1912 const CLSID CLSID_MsiTransform
= { 0xc1082,0,0,{0xc0,0,0,0,0,0,0,0x46}};
1914 MultiByteToWideChar(CP_ACP
, 0, mstfile
, -1, name
, 0x20);
1916 r
= StgCreateDocfile(name
, mode
, 0, &stg
);
1917 ok(r
== S_OK
, "failed to create storage\n");
1921 r
= IStorage_SetClass( stg
, &CLSID_MsiTransform
);
1922 ok(r
== S_OK
, "failed to set storage type\n");
1924 for (i
=0; i
<NUM_TRANSFORM_TABLES
; i
++)
1926 r
= IStorage_CreateStream( stg
, table_transform_data
[i
].name
,
1927 STGM_WRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
1930 ok(0, "failed to create stream %08x\n", r
);
1934 r
= IStream_Write( stm
, table_transform_data
[i
].data
,
1935 table_transform_data
[i
].size
, &count
);
1936 if (FAILED(r
) || count
!= table_transform_data
[i
].size
)
1937 ok(0, "failed to write stream\n");
1938 IStream_Release(stm
);
1941 IStorage_Release(stg
);
1944 static void test_try_transform(void)
1946 MSIHANDLE hdb
, hrec
;
1952 DeleteFile(msifile
);
1953 DeleteFile(msifile2
);
1954 DeleteFile(mstfile
);
1956 /* create an empty database */
1957 r
= MsiOpenDatabase(msifile2
, MSIDBOPEN_CREATE
, &hdb
);
1958 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
1960 query
= "CREATE TABLE `MOO` ( `NOO` SHORT NOT NULL, `OOO` CHAR(255) PRIMARY KEY `NOO`)";
1961 r
= run_query(hdb
, 0, query
);
1962 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
1964 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 1, 'a' )";
1965 r
= run_query(hdb
, 0, query
);
1966 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
1968 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 2, 'b' )";
1969 r
= run_query(hdb
, 0, query
);
1970 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
1972 query
= "INSERT INTO `MOO` ( `NOO`, `OOO` ) VALUES ( 3, 'c' )";
1973 r
= run_query(hdb
, 0, query
);
1974 ok(r
== ERROR_SUCCESS
, "failed to add row\n");
1976 query
= "CREATE TABLE `BINARY` ( `ID` SHORT NOT NULL, `BLOB` OBJECT PRIMARY KEY `ID`)";
1977 r
= run_query(hdb
, 0, query
);
1978 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
1980 hrec
= MsiCreateRecord(2);
1981 r
= MsiRecordSetInteger(hrec
, 1, 2);
1982 ok(r
== ERROR_SUCCESS
, "failed to set integer\n");
1984 write_file("testdata.bin", "lamyon", 6);
1985 r
= MsiRecordSetStream(hrec
, 2, "testdata.bin");
1986 ok(r
== ERROR_SUCCESS
, "failed to set stream\n");
1988 query
= "INSERT INTO `BINARY` ( `ID`, `BLOB` ) VALUES ( ?, ? )";
1989 r
= run_query(hdb
, hrec
, query
);
1990 ok(r
== ERROR_SUCCESS
, "failed to add row with blob\n");
1992 MsiCloseHandle(hrec
);
1994 r
= MsiDatabaseCommit( hdb
);
1995 ok( r
== ERROR_SUCCESS
, "Failed to commit database\n" );
1997 MsiCloseHandle( hdb
);
1998 DeleteFileA("testdata.bin");
2001 * Both these generate an equivilent transform,
2002 * but the first doesn't work in Wine yet
2003 * because MsiDatabaseGenerateTransform is unimplemented.
2006 generate_transform();
2008 generate_transform_manual();
2010 r
= MsiOpenDatabase(msifile2
, MSIDBOPEN_DIRECT
, &hdb
);
2011 ok( r
== ERROR_SUCCESS
, "Failed to create database\n" );
2013 r
= MsiDatabaseApplyTransform( hdb
, mstfile
, 0 );
2014 ok( r
== ERROR_SUCCESS
, "return code %d, should be ERROR_SUCCESS\n", r
);
2016 MsiDatabaseCommit( hdb
);
2018 /* check new values */
2020 query
= "select `BAR`,`CAR` from `AAR` where `BAR` = 1 AND `CAR` = 'vw'";
2021 r
= do_query(hdb
, query
, &hrec
);
2022 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2023 MsiCloseHandle(hrec
);
2025 query
= "select `BAR`,`CAR` from `AAR` where `BAR` = 2 AND `CAR` = 'bmw'";
2027 r
= do_query(hdb
, query
, &hrec
);
2028 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2029 MsiCloseHandle(hrec
);
2031 /* check updated values */
2033 query
= "select `NOO`,`OOO` from `MOO` where `NOO` = 1 AND `OOO` = 'c'";
2034 r
= do_query(hdb
, query
, &hrec
);
2035 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2036 MsiCloseHandle(hrec
);
2038 /* check unchanged value */
2040 query
= "select `NOO`,`OOO` from `MOO` where `NOO` = 2 AND `OOO` = 'b'";
2041 r
= do_query(hdb
, query
, &hrec
);
2042 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2043 MsiCloseHandle(hrec
);
2045 /* check deleted value */
2047 query
= "select * from `MOO` where `NOO` = 3";
2048 r
= do_query(hdb
, query
, &hrec
);
2049 ok(r
== ERROR_NO_MORE_ITEMS
, "select query failed\n");
2050 if (hrec
) MsiCloseHandle(hrec
);
2052 /* check added stream */
2054 query
= "select `BLOB` from `BINARY` where `ID` = 1";
2055 r
= do_query(hdb
, query
, &hrec
);
2056 ok(r
== ERROR_SUCCESS
, "select query failed\n");
2058 /* check the contents of the stream */
2060 r
= MsiRecordReadStream( hrec
, 1, buffer
, &sz
);
2061 ok(r
== ERROR_SUCCESS
, "read stream failed\n");
2062 ok(!memcmp(buffer
, "naengmyon", 9), "stream data was wrong\n");
2063 ok(sz
== 9, "stream data was wrong size\n");
2064 if (hrec
) MsiCloseHandle(hrec
);
2066 MsiCloseHandle( hdb
);
2068 DeleteFile(msifile
);
2069 DeleteFile(msifile2
);
2070 DeleteFile(mstfile
);
2075 const CHAR one
[MAX_PATH
];
2076 const CHAR two
[MAX_PATH
];
2079 struct join_res_4col
2081 const CHAR one
[MAX_PATH
];
2082 const CHAR two
[MAX_PATH
];
2083 const CHAR three
[MAX_PATH
];
2084 const CHAR four
[MAX_PATH
];
2087 static const struct join_res join_res_first
[] =
2089 { "alveolar", "procerus" },
2090 { "septum", "procerus" },
2091 { "septum", "nasalis" },
2092 { "ramus", "nasalis" },
2093 { "malar", "mentalis" },
2096 static const struct join_res join_res_second
[] =
2098 { "nasal", "septum" },
2099 { "mandible", "ramus" },
2102 static const struct join_res join_res_third
[] =
2104 { "msvcp.dll", "abcdefgh" },
2105 { "msvcr.dll", "ijklmnop" },
2108 static const struct join_res join_res_fourth
[] =
2110 { "msvcp.dll.01234", "single.dll.31415" },
2113 static const struct join_res join_res_fifth
[] =
2115 { "malar", "procerus" },
2118 static const struct join_res join_res_sixth
[] =
2120 { "malar", "procerus" },
2121 { "malar", "procerus" },
2122 { "malar", "nasalis" },
2123 { "malar", "nasalis" },
2124 { "malar", "nasalis" },
2125 { "malar", "mentalis" },
2128 static const struct join_res join_res_seventh
[] =
2130 { "malar", "nasalis" },
2131 { "malar", "nasalis" },
2132 { "malar", "nasalis" },
2135 static const struct join_res_4col join_res_eighth
[] =
2137 { "msvcp.dll", "msvcp.dll.01234", "msvcp.dll.01234", "abcdefgh" },
2138 { "msvcr.dll", "msvcr.dll.56789", "msvcp.dll.01234", "abcdefgh" },
2139 { "msvcp.dll", "msvcp.dll.01234", "msvcr.dll.56789", "ijklmnop" },
2140 { "msvcr.dll", "msvcr.dll.56789", "msvcr.dll.56789", "ijklmnop" },
2141 { "msvcp.dll", "msvcp.dll.01234", "single.dll.31415", "msvcp.dll" },
2142 { "msvcr.dll", "msvcr.dll.56789", "single.dll.31415", "msvcp.dll" },
2145 static void test_join(void)
2147 MSIHANDLE hdb
, hview
, hrec
;
2155 ok( hdb
, "failed to create db\n");
2157 r
= create_component_table( hdb
);
2158 ok( r
== ERROR_SUCCESS
, "cannot create Component table: %d\n", r
);
2160 r
= add_component_entry( hdb
, "'zygomatic', 'malar', 'INSTALLDIR', 0, '', ''" );
2161 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2163 r
= add_component_entry( hdb
, "'maxilla', 'alveolar', 'INSTALLDIR', 0, '', ''" );
2164 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2166 r
= add_component_entry( hdb
, "'nasal', 'septum', 'INSTALLDIR', 0, '', ''" );
2167 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2169 r
= add_component_entry( hdb
, "'mandible', 'ramus', 'INSTALLDIR', 0, '', ''" );
2170 ok( r
== ERROR_SUCCESS
, "cannot add component: %d\n", r
);
2172 r
= create_feature_components_table( hdb
);
2173 ok( r
== ERROR_SUCCESS
, "cannot create FeatureComponents table: %d\n", r
);
2175 r
= add_feature_components_entry( hdb
, "'procerus', 'maxilla'" );
2176 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2178 r
= add_feature_components_entry( hdb
, "'procerus', 'nasal'" );
2179 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2181 r
= add_feature_components_entry( hdb
, "'nasalis', 'nasal'" );
2182 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2184 r
= add_feature_components_entry( hdb
, "'nasalis', 'mandible'" );
2185 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2187 r
= add_feature_components_entry( hdb
, "'nasalis', 'notacomponent'" );
2188 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2190 r
= add_feature_components_entry( hdb
, "'mentalis', 'zygomatic'" );
2191 ok( r
== ERROR_SUCCESS
, "cannot add feature components: %d\n", r
);
2193 r
= create_std_dlls_table( hdb
);
2194 ok( r
== ERROR_SUCCESS
, "cannot create StdDlls table: %d\n", r
);
2196 r
= add_std_dlls_entry( hdb
, "'msvcp.dll', 'msvcp.dll.01234'" );
2197 ok( r
== ERROR_SUCCESS
, "cannot add std dlls: %d\n", r
);
2199 r
= add_std_dlls_entry( hdb
, "'msvcr.dll', 'msvcr.dll.56789'" );
2200 ok( r
== ERROR_SUCCESS
, "cannot add std dlls: %d\n", r
);
2202 r
= create_binary_table( hdb
);
2203 ok( r
== ERROR_SUCCESS
, "cannot create Binary table: %d\n", r
);
2205 r
= add_binary_entry( hdb
, "'msvcp.dll.01234', 'abcdefgh'" );
2206 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
2208 r
= add_binary_entry( hdb
, "'msvcr.dll.56789', 'ijklmnop'" );
2209 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
2211 r
= add_binary_entry( hdb
, "'single.dll.31415', 'msvcp.dll'" );
2212 ok( r
== ERROR_SUCCESS
, "cannot add binary: %d\n", r
);
2214 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2215 "FROM `Component`, `FeatureComponents` "
2216 "WHERE `Component`.`Component` = `FeatureComponents`.`Component_` "
2217 "ORDER BY `Feature_`";
2218 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2219 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2221 r
= MsiViewExecute(hview
, 0);
2222 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2225 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2227 count
= MsiRecordGetFieldCount( hrec
);
2228 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2231 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2232 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2233 ok( !lstrcmp( buf
, join_res_first
[i
].one
),
2234 "For (row %d, column 1) expected '%s', got %s\n", i
, join_res_first
[i
].one
, buf
);
2237 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2238 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2239 ok( !lstrcmp( buf
, join_res_first
[i
].two
),
2240 "For (row %d, column 2) expected '%s', got %s\n", i
, join_res_first
[i
].two
, buf
);
2243 MsiCloseHandle(hrec
);
2246 ok( i
== 5, "Expected 5 rows, got %d\n", i
);
2247 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2249 MsiViewClose(hview
);
2250 MsiCloseHandle(hview
);
2252 /* try a join without a WHERE condition */
2253 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2254 "FROM `Component`, `FeatureComponents` ";
2255 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2256 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2258 r
= MsiViewExecute(hview
, 0);
2259 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2262 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2265 MsiCloseHandle(hrec
);
2267 ok( i
== 24, "Expected 24 rows, got %d\n", i
);
2269 MsiViewClose(hview
);
2270 MsiCloseHandle(hview
);
2272 query
= "SELECT DISTINCT Component, ComponentId FROM FeatureComponents, Component "
2273 "WHERE FeatureComponents.Component_=Component.Component "
2274 "AND (Feature_='nasalis') ORDER BY Feature_";
2275 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2276 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2278 r
= MsiViewExecute(hview
, 0);
2279 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2282 data_correct
= TRUE
;
2283 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2285 count
= MsiRecordGetFieldCount( hrec
);
2286 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2289 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2290 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2291 if( lstrcmp( buf
, join_res_second
[i
].one
))
2292 data_correct
= FALSE
;
2295 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2296 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2297 if( lstrcmp( buf
, join_res_second
[i
].two
))
2298 data_correct
= FALSE
;
2301 MsiCloseHandle(hrec
);
2304 ok( data_correct
, "data returned in the wrong order\n");
2306 ok( i
== 2, "Expected 2 rows, got %d\n", i
);
2307 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2309 MsiViewClose(hview
);
2310 MsiCloseHandle(hview
);
2312 query
= "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2313 "FROM `StdDlls`, `Binary` "
2314 "WHERE `StdDlls`.`Binary_` = `Binary`.`Name` "
2316 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2317 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2319 r
= MsiViewExecute(hview
, 0);
2320 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2323 data_correct
= TRUE
;
2324 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2326 count
= MsiRecordGetFieldCount( hrec
);
2327 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2330 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2331 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2332 if( lstrcmp( buf
, join_res_third
[i
].one
) )
2333 data_correct
= FALSE
;
2336 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2337 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2338 if( lstrcmp( buf
, join_res_third
[i
].two
) )
2339 data_correct
= FALSE
;
2342 MsiCloseHandle(hrec
);
2344 ok( data_correct
, "data returned in the wrong order\n");
2346 ok( i
== 2, "Expected 2 rows, got %d\n", i
);
2348 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2350 MsiViewClose(hview
);
2351 MsiCloseHandle(hview
);
2353 query
= "SELECT `StdDlls`.`Binary_`, `Binary`.`Name` "
2354 "FROM `StdDlls`, `Binary` "
2355 "WHERE `StdDlls`.`File` = `Binary`.`Data` "
2357 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2358 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2360 r
= MsiViewExecute(hview
, 0);
2361 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2364 data_correct
= TRUE
;
2365 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2367 count
= MsiRecordGetFieldCount( hrec
);
2368 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2371 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2372 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2373 if( lstrcmp( buf
, join_res_fourth
[i
].one
))
2374 data_correct
= FALSE
;
2377 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2378 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2379 if( lstrcmp( buf
, join_res_fourth
[i
].two
))
2380 data_correct
= FALSE
;
2383 MsiCloseHandle(hrec
);
2385 ok( data_correct
, "data returned in the wrong order\n");
2387 ok( i
== 1, "Expected 1 rows, got %d\n", i
);
2388 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2390 MsiViewClose(hview
);
2391 MsiCloseHandle(hview
);
2393 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2394 "FROM `Component`, `FeatureComponents` "
2395 "WHERE `Component`.`Component` = 'zygomatic' "
2396 "AND `FeatureComponents`.`Component_` = 'maxilla' "
2397 "ORDER BY `Feature_`";
2398 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2399 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2401 r
= MsiViewExecute(hview
, 0);
2402 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2405 data_correct
= TRUE
;
2406 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2408 count
= MsiRecordGetFieldCount( hrec
);
2409 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2412 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2413 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2414 if( lstrcmp( buf
, join_res_fifth
[i
].one
))
2415 data_correct
= FALSE
;
2418 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2419 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2420 if( lstrcmp( buf
, join_res_fifth
[i
].two
))
2421 data_correct
= FALSE
;
2424 MsiCloseHandle(hrec
);
2426 ok( data_correct
, "data returned in the wrong order\n");
2428 ok( i
== 1, "Expected 1 rows, got %d\n", i
);
2429 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2431 MsiViewClose(hview
);
2432 MsiCloseHandle(hview
);
2434 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2435 "FROM `Component`, `FeatureComponents` "
2436 "WHERE `Component` = 'zygomatic' "
2437 "ORDER BY `Feature_`";
2438 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2439 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2441 r
= MsiViewExecute(hview
, 0);
2444 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2448 data_correct
= TRUE
;
2449 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2451 count
= MsiRecordGetFieldCount( hrec
);
2452 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2455 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2456 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2457 if( lstrcmp( buf
, join_res_sixth
[i
].one
))
2458 data_correct
= FALSE
;
2461 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2462 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2463 if( lstrcmp( buf
, join_res_sixth
[i
].two
))
2464 data_correct
= FALSE
;
2467 MsiCloseHandle(hrec
);
2469 ok( data_correct
, "data returned in the wrong order\n");
2473 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
2475 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2477 MsiViewClose(hview
);
2478 MsiCloseHandle(hview
);
2480 query
= "SELECT `Component`.`ComponentId`, `FeatureComponents`.`Feature_` "
2481 "FROM `Component`, `FeatureComponents` "
2482 "WHERE `Component` = 'zygomatic' "
2483 "AND `Feature_` = 'nasalis' "
2484 "ORDER BY `Feature_`";
2485 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2486 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2488 r
= MsiViewExecute(hview
, 0);
2489 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2492 data_correct
= TRUE
;
2493 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2495 count
= MsiRecordGetFieldCount( hrec
);
2496 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2499 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2500 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2501 if( lstrcmp( buf
, join_res_seventh
[i
].one
))
2502 data_correct
= FALSE
;
2505 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2506 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2507 if( lstrcmp( buf
, join_res_seventh
[i
].two
))
2508 data_correct
= FALSE
;
2511 MsiCloseHandle(hrec
);
2514 ok( data_correct
, "data returned in the wrong order\n");
2515 ok( i
== 3, "Expected 3 rows, got %d\n", i
);
2516 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2518 MsiViewClose(hview
);
2519 MsiCloseHandle(hview
);
2521 query
= "SELECT `StdDlls`.`File`, `Binary`.`Data` "
2522 "FROM `StdDlls`, `Binary` ";
2523 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2524 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2526 r
= MsiViewExecute(hview
, 0);
2527 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2530 data_correct
= TRUE
;
2531 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2533 count
= MsiRecordGetFieldCount( hrec
);
2534 ok( count
== 2, "Expected 2 record fields, got %d\n", count
);
2537 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2538 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2539 if( lstrcmp( buf
, join_res_eighth
[i
].one
))
2540 data_correct
= FALSE
;
2543 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2544 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2545 if( lstrcmp( buf
, join_res_eighth
[i
].four
))
2546 data_correct
= FALSE
;
2549 MsiCloseHandle(hrec
);
2552 todo_wine
ok( data_correct
, "data returned in the wrong order\n");
2553 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
2554 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2556 MsiViewClose(hview
);
2557 MsiCloseHandle(hview
);
2559 query
= "SELECT * FROM `StdDlls`, `Binary` ";
2560 r
= MsiDatabaseOpenView(hdb
, query
, &hview
);
2561 ok( r
== ERROR_SUCCESS
, "failed to open view: %d\n", r
);
2563 r
= MsiViewExecute(hview
, 0);
2564 ok( r
== ERROR_SUCCESS
, "failed to execute view: %d\n", r
);
2567 data_correct
= TRUE
;
2568 while ((r
= MsiViewFetch(hview
, &hrec
)) == ERROR_SUCCESS
)
2570 count
= MsiRecordGetFieldCount( hrec
);
2571 ok( count
== 4, "Expected 4 record fields, got %d\n", count
);
2574 r
= MsiRecordGetString( hrec
, 1, buf
, &size
);
2575 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2576 if( lstrcmp( buf
, join_res_eighth
[i
].one
))
2577 data_correct
= FALSE
;
2580 r
= MsiRecordGetString( hrec
, 2, buf
, &size
);
2581 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2582 if( lstrcmp( buf
, join_res_eighth
[i
].two
))
2583 data_correct
= FALSE
;
2586 r
= MsiRecordGetString( hrec
, 3, buf
, &size
);
2587 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2588 if( lstrcmp( buf
, join_res_eighth
[i
].three
))
2589 data_correct
= FALSE
;
2592 r
= MsiRecordGetString( hrec
, 4, buf
, &size
);
2593 ok( r
== ERROR_SUCCESS
, "failed to get record string: %d\n", r
);
2594 if( lstrcmp( buf
, join_res_eighth
[i
].four
))
2595 data_correct
= FALSE
;
2598 MsiCloseHandle(hrec
);
2600 todo_wine
ok( data_correct
, "data returned in the wrong order\n");
2602 ok( i
== 6, "Expected 6 rows, got %d\n", i
);
2603 ok( r
== ERROR_NO_MORE_ITEMS
, "expected no more items: %d\n", r
);
2605 MsiViewClose(hview
);
2606 MsiCloseHandle(hview
);
2608 MsiCloseHandle(hdb
);
2609 DeleteFile(msifile
);
2612 static void test_temporary_table(void)
2615 MSIHANDLE hdb
= 0, view
= 0, rec
;
2621 cond
= MsiDatabaseIsTablePersistent(0, NULL
);
2622 ok( cond
== MSICONDITION_ERROR
, "wrong return condition\n");
2625 ok( hdb
, "failed to create db\n");
2627 cond
= MsiDatabaseIsTablePersistent(hdb
, NULL
);
2628 ok( cond
== MSICONDITION_ERROR
, "wrong return condition\n");
2631 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Tables");
2632 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
2634 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Columns");
2635 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
2638 cond
= MsiDatabaseIsTablePersistent(hdb
, "_Streams");
2639 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
2641 query
= "CREATE TABLE `P` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`)";
2642 r
= run_query(hdb
, 0, query
);
2643 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2645 cond
= MsiDatabaseIsTablePersistent(hdb
, "P");
2646 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
2648 query
= "CREATE TABLE `P2` ( `B` SHORT NOT NULL, `C` CHAR(255) PRIMARY KEY `C`) HOLD";
2649 r
= run_query(hdb
, 0, query
);
2650 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2652 cond
= MsiDatabaseIsTablePersistent(hdb
, "P2");
2653 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
2655 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
2656 r
= run_query(hdb
, 0, query
);
2657 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2659 cond
= MsiDatabaseIsTablePersistent(hdb
, "T");
2660 ok( cond
== MSICONDITION_FALSE
, "wrong return condition\n");
2662 query
= "CREATE TABLE `T2` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
2663 r
= run_query(hdb
, 0, query
);
2664 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2667 cond
= MsiDatabaseIsTablePersistent(hdb
, "T2");
2668 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
2671 query
= "CREATE TABLE `T3` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) PRIMARY KEY `C`)";
2672 r
= run_query(hdb
, 0, query
);
2673 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2675 cond
= MsiDatabaseIsTablePersistent(hdb
, "T3");
2676 ok( cond
== MSICONDITION_TRUE
, "wrong return condition\n");
2679 query
= "CREATE TABLE `T4` ( `B` SHORT NOT NULL, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`)";
2680 r
= run_query(hdb
, 0, query
);
2681 ok(r
== ERROR_FUNCTION_FAILED
, "failed to add table\n");
2683 cond
= MsiDatabaseIsTablePersistent(hdb
, "T4");
2684 ok( cond
== MSICONDITION_NONE
, "wrong return condition\n");
2687 query
= "CREATE TABLE `T5` ( `B` SHORT NOT NULL TEMP, `C` CHAR(255) TEMP PRIMARY KEY `C`) HOLD";
2688 r
= run_query(hdb
, 0, query
);
2689 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to add table\n");
2691 query
= "select * from `T`";
2692 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2693 ok(r
== ERROR_SUCCESS
, "failed to query table\n");
2694 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
2695 ok(r
== ERROR_SUCCESS
, "failed to get column info\n");
2698 r
= MsiRecordGetString(rec
, 1, buf
, &sz
);
2699 ok(r
== ERROR_SUCCESS
, "failed to get string\n");
2700 todo_wine
ok( 0 == strcmp("G255", buf
), "wrong column type\n");
2703 r
= MsiRecordGetString(rec
, 2, buf
, &sz
);
2704 ok(r
== ERROR_SUCCESS
, "failed to get string\n");
2705 todo_wine
ok( 0 == strcmp("j2", buf
), "wrong column type\n");
2707 MsiCloseHandle( rec
);
2708 MsiCloseHandle( view
);
2710 /* query the table data */
2712 r
= do_query(hdb
, "select * from `_Tables` where `Name` = 'T'", &rec
);
2713 ok( r
== ERROR_SUCCESS
, "temporary table exists in _Tables\n");
2714 MsiCloseHandle( rec
);
2716 /* query the column data */
2718 r
= do_query(hdb
, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'B'", &rec
);
2719 ok( r
== ERROR_NO_MORE_ITEMS
, "temporary table exists in _Columns\n");
2720 if (rec
) MsiCloseHandle( rec
);
2722 r
= do_query(hdb
, "select * from `_Columns` where `Table` = 'T' AND `Name` = 'C'", &rec
);
2723 ok( r
== ERROR_NO_MORE_ITEMS
, "temporary table exists in _Columns\n");
2724 if (rec
) MsiCloseHandle( rec
);
2726 MsiCloseHandle( hdb
);
2728 DeleteFile(msifile
);
2731 static void test_alter(void)
2739 ok( hdb
, "failed to create db\n");
2741 query
= "CREATE TABLE `T` ( `B` SHORT NOT NULL TEMPORARY, `C` CHAR(255) TEMPORARY PRIMARY KEY `C`) HOLD";
2742 r
= run_query(hdb
, 0, query
);
2743 ok(r
== ERROR_SUCCESS
, "failed to add table\n");
2745 cond
= MsiDatabaseIsTablePersistent(hdb
, "T");
2746 ok( cond
== MSICONDITION_FALSE
, "wrong return condition\n");
2748 query
= "ALTER TABLE `T` HOLD";
2749 r
= run_query(hdb
, 0, query
);
2750 ok(r
== ERROR_SUCCESS
, "failed to hold table %d\n", r
);
2752 query
= "ALTER TABLE `T` FREE";
2753 r
= run_query(hdb
, 0, query
);
2754 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
2756 query
= "ALTER TABLE `T` FREE";
2757 r
= run_query(hdb
, 0, query
);
2758 ok(r
== ERROR_SUCCESS
, "failed to free table\n");
2761 query
= "ALTER TABLE `T` FREE";
2762 r
= run_query(hdb
, 0, query
);
2763 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to free table\n");
2765 query
= "ALTER TABLE `T` HOLD";
2766 r
= run_query(hdb
, 0, query
);
2767 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "failed to hold table %d\n", r
);
2770 MsiCloseHandle( hdb
);
2772 DeleteFile(msifile
);
2775 static void test_integers(void)
2777 MSIHANDLE hdb
= 0, view
= 0, rec
= 0;
2782 /* just MsiOpenDatabase should not create a file */
2783 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
2784 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
2786 /* create a table */
2787 query
= "CREATE TABLE `integers` ( "
2788 "`one` SHORT, `two` INT, `three` INTEGER, `four` LONG, "
2789 "`five` SHORT NOT NULL, `six` INT NOT NULL, "
2790 "`seven` INTEGER NOT NULL, `eight` LONG NOT NULL "
2791 "PRIMARY KEY `one`)";
2792 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2793 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
2794 r
= MsiViewExecute(view
, 0);
2795 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
2796 r
= MsiViewClose(view
);
2797 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
2798 r
= MsiCloseHandle(view
);
2799 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
2801 query
= "SELECT * FROM `integers`";
2802 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2803 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2805 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_NAMES
, &rec
);
2806 count
= MsiRecordGetFieldCount(rec
);
2807 ok(count
== 8, "Expected 8, got %d\n", count
);
2808 ok(check_record(rec
, 1, "one"), "Expected one\n");
2809 ok(check_record(rec
, 2, "two"), "Expected two\n");
2810 ok(check_record(rec
, 3, "three"), "Expected three\n");
2811 ok(check_record(rec
, 4, "four"), "Expected four\n");
2812 ok(check_record(rec
, 5, "five"), "Expected five\n");
2813 ok(check_record(rec
, 6, "six"), "Expected six\n");
2814 ok(check_record(rec
, 7, "seven"), "Expected seven\n");
2815 ok(check_record(rec
, 8, "eight"), "Expected eight\n");
2816 MsiCloseHandle(rec
);
2818 r
= MsiViewGetColumnInfo(view
, MSICOLINFO_TYPES
, &rec
);
2819 count
= MsiRecordGetFieldCount(rec
);
2820 ok(count
== 8, "Expected 8, got %d\n", count
);
2821 ok(check_record(rec
, 1, "I2"), "Expected I2\n");
2822 ok(check_record(rec
, 2, "I2"), "Expected I2\n");
2823 ok(check_record(rec
, 3, "I2"), "Expected I2\n");
2824 ok(check_record(rec
, 4, "I4"), "Expected I4\n");
2825 ok(check_record(rec
, 5, "i2"), "Expected i2\n");
2826 ok(check_record(rec
, 6, "i2"), "Expected i2\n");
2827 ok(check_record(rec
, 7, "i2"), "Expected i2\n");
2828 ok(check_record(rec
, 8, "i4"), "Expected i4\n");
2829 MsiCloseHandle(rec
);
2832 MsiCloseHandle(view
);
2834 /* insert values into it, NULL where NOT NULL is specified */
2835 query
= "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
2836 "VALUES('', '', '', '', '', '', '', '')";
2837 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2838 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2839 r
= MsiViewExecute(view
, 0);
2840 ok(r
== ERROR_FUNCTION_FAILED
, "Expected ERROR_FUNCTION_FAILED, got %d\n", r
);
2843 MsiCloseHandle(view
);
2845 query
= "SELECT * FROM `integers`";
2846 r
= do_query(hdb
, query
, &rec
);
2847 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
2849 r
= MsiRecordGetFieldCount(rec
);
2850 ok(r
== -1, "record count wrong: %d\n", r
);
2852 MsiCloseHandle(rec
);
2854 /* insert legitimate values into it */
2855 query
= "INSERT INTO `integers` ( `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight` )"
2856 "VALUES('', '2', '', '4', '5', '6', '7', '8')";
2857 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2858 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2859 r
= MsiViewExecute(view
, 0);
2860 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2862 query
= "SELECT * FROM `integers`";
2863 r
= do_query(hdb
, query
, &rec
);
2864 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2866 r
= MsiRecordGetFieldCount(rec
);
2867 ok(r
== 8, "record count wrong: %d\n", r
);
2869 i
= MsiRecordGetInteger(rec
, 1);
2870 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
2871 i
= MsiRecordGetInteger(rec
, 3);
2872 ok(i
== MSI_NULL_INTEGER
, "Expected MSI_NULL_INTEGER, got %d\n", i
);
2873 i
= MsiRecordGetInteger(rec
, 2);
2874 ok(i
== 2, "Expected 2, got %d\n", i
);
2875 i
= MsiRecordGetInteger(rec
, 4);
2876 ok(i
== 4, "Expected 4, got %d\n", i
);
2877 i
= MsiRecordGetInteger(rec
, 5);
2878 ok(i
== 5, "Expected 5, got %d\n", i
);
2879 i
= MsiRecordGetInteger(rec
, 6);
2880 ok(i
== 6, "Expected 6, got %d\n", i
);
2881 i
= MsiRecordGetInteger(rec
, 7);
2882 ok(i
== 7, "Expected 7, got %d\n", i
);
2883 i
= MsiRecordGetInteger(rec
, 8);
2884 ok(i
== 8, "Expected 8, got %d\n", i
);
2886 MsiCloseHandle(rec
);
2888 MsiCloseHandle(view
);
2890 r
= MsiDatabaseCommit(hdb
);
2891 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
2893 r
= MsiCloseHandle(hdb
);
2894 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
2896 r
= DeleteFile(msifile
);
2897 ok(r
== TRUE
, "file didn't exist after commit\n");
2900 static void test_update(void)
2902 MSIHANDLE hdb
= 0, view
= 0, rec
= 0;
2903 CHAR result
[MAX_PATH
];
2908 /* just MsiOpenDatabase should not create a file */
2909 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
2910 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
2912 /* create the Control table */
2913 query
= "CREATE TABLE `Control` ( "
2914 "`Dialog_` CHAR(72) NOT NULL, `Control` CHAR(50) NOT NULL, `Type` SHORT NOT NULL, "
2915 "`X` SHORT NOT NULL, `Y` SHORT NOT NULL, `Width` SHORT NOT NULL, `Height` SHORT NOT NULL,"
2916 "`Attributes` LONG, `Property` CHAR(50), `Text` CHAR(0) LOCALIZABLE, "
2917 "`Control_Next` CHAR(50), `Help` CHAR(50) LOCALIZABLE PRIMARY KEY `Dialog_`, `Control`)";
2918 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2919 ok(r
== ERROR_SUCCESS
, "MsiDatabaseOpenView failed\n");
2920 r
= MsiViewExecute(view
, 0);
2921 ok(r
== ERROR_SUCCESS
, "MsiViewExecute failed\n");
2922 r
= MsiViewClose(view
);
2923 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
2924 r
= MsiCloseHandle(view
);
2925 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
2928 query
= "INSERT INTO `Control` ( "
2929 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
2930 "`Property`, `Text`, `Control_Next`, `Help` )"
2931 "VALUES('ErrorDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
2932 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2933 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2934 r
= MsiViewExecute(view
, 0);
2935 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2936 r
= MsiViewClose(view
);
2937 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
2938 r
= MsiCloseHandle(view
);
2939 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
2941 /* add a second control */
2942 query
= "INSERT INTO `Control` ( "
2943 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
2944 "`Property`, `Text`, `Control_Next`, `Help` )"
2945 "VALUES('ErrorDialog', 'Button', '1', '5', '5', '5', '5', '', '', '', '')";
2946 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2947 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2948 r
= MsiViewExecute(view
, 0);
2949 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2950 r
= MsiViewClose(view
);
2951 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
2952 r
= MsiCloseHandle(view
);
2953 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
2955 /* add a third control */
2956 query
= "INSERT INTO `Control` ( "
2957 "`Dialog_`, `Control`, `Type`, `X`, `Y`, `Width`, `Height`, "
2958 "`Property`, `Text`, `Control_Next`, `Help` )"
2959 "VALUES('AnotherDialog', 'ErrorText', '1', '5', '5', '5', '5', '', '', '', '')";
2960 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2961 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2962 r
= MsiViewExecute(view
, 0);
2963 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2964 r
= MsiViewClose(view
);
2965 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
2966 r
= MsiCloseHandle(view
);
2967 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
2970 query
= "UPDATE `NotATable` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
2971 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2972 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2974 /* bad set column */
2975 query
= "UPDATE `Control` SET `NotAColumn` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
2976 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2977 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2979 /* bad where condition */
2980 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `NotAColumn` = 'ErrorDialog'";
2981 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2982 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "Expected ERROR_BAD_QUERY_SYNTAX, got %d\n", r
);
2984 /* just the dialog_ specified */
2985 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog'";
2986 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2987 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2988 r
= MsiViewExecute(view
, 0);
2989 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2990 r
= MsiViewClose(view
);
2991 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
2992 r
= MsiCloseHandle(view
);
2993 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
2995 /* check the modified text */
2996 query
= "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
2997 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
2998 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
2999 r
= MsiViewExecute(view
, 0);
3000 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3002 r
= MsiViewFetch(view
, &rec
);
3003 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3006 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3007 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3008 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3010 MsiCloseHandle(rec
);
3012 r
= MsiViewFetch(view
, &rec
);
3013 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3016 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3017 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3018 ok(!lstrlen(result
), "Expected an empty string, got %s\n", result
);
3020 MsiCloseHandle(rec
);
3022 r
= MsiViewFetch(view
, &rec
);
3023 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3025 r
= MsiViewClose(view
);
3026 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3027 r
= MsiCloseHandle(view
);
3028 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3030 /* dialog_ and control specified */
3031 query
= "UPDATE `Control` SET `Text` = 'this is text' WHERE `Dialog_` = 'ErrorDialog' AND `Control` = 'ErrorText'";
3032 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3033 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3034 r
= MsiViewExecute(view
, 0);
3035 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3036 r
= MsiViewClose(view
);
3037 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3038 r
= MsiCloseHandle(view
);
3039 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3041 /* check the modified text */
3042 query
= "SELECT `Text` FROM `Control` WHERE `Control` = 'ErrorText'";
3043 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3044 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3045 r
= MsiViewExecute(view
, 0);
3046 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3048 r
= MsiViewFetch(view
, &rec
);
3049 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3052 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3053 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3054 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3056 MsiCloseHandle(rec
);
3058 r
= MsiViewFetch(view
, &rec
);
3059 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3062 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3063 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3064 ok(!lstrlen(result
), "Expected an empty string, got %s\n", result
);
3066 MsiCloseHandle(rec
);
3068 r
= MsiViewFetch(view
, &rec
);
3069 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3071 r
= MsiViewClose(view
);
3072 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3073 r
= MsiCloseHandle(view
);
3074 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3076 /* no where condition */
3077 query
= "UPDATE `Control` SET `Text` = 'this is text'";
3078 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3079 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3080 r
= MsiViewExecute(view
, 0);
3081 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3082 r
= MsiViewClose(view
);
3083 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3084 r
= MsiCloseHandle(view
);
3085 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3087 /* check the modified text */
3088 query
= "SELECT `Text` FROM `Control`";
3089 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3090 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3091 r
= MsiViewExecute(view
, 0);
3092 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3094 r
= MsiViewFetch(view
, &rec
);
3095 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3098 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3099 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3100 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3102 MsiCloseHandle(rec
);
3104 r
= MsiViewFetch(view
, &rec
);
3105 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3108 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3109 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3110 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3112 MsiCloseHandle(rec
);
3114 r
= MsiViewFetch(view
, &rec
);
3115 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3118 r
= MsiRecordGetString(rec
, 1, result
, &size
);
3119 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3120 ok(!lstrcmp(result
, "this is text"), "Expected `this is text`, got %s\n", result
);
3122 MsiCloseHandle(rec
);
3124 r
= MsiViewFetch(view
, &rec
);
3125 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3127 r
= MsiViewClose(view
);
3128 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3129 r
= MsiCloseHandle(view
);
3130 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3131 r
= MsiDatabaseCommit(hdb
);
3132 ok(r
== ERROR_SUCCESS
, "MsiDatabaseCommit failed\n");
3133 r
= MsiCloseHandle(hdb
);
3134 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3137 static void test_special_tables(void)
3143 r
= MsiOpenDatabase(msifile
, MSIDBOPEN_CREATE
, &hdb
);
3144 ok(r
== ERROR_SUCCESS
, "MsiOpenDatabase failed\n");
3146 query
= "CREATE TABLE `_Properties` ( "
3147 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3148 r
= run_query(hdb
, 0, query
);
3149 ok(r
== ERROR_SUCCESS
, "failed to create table\n");
3151 query
= "CREATE TABLE `_Streams` ( "
3152 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3153 r
= run_query(hdb
, 0, query
);
3154 todo_wine
ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Streams table\n");
3156 query
= "CREATE TABLE `_Tables` ( "
3157 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3158 r
= run_query(hdb
, 0, query
);
3159 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Tables table\n");
3161 query
= "CREATE TABLE `_Columns` ( "
3162 "`foo` INT NOT NULL, `bar` INT LOCALIZABLE PRIMARY KEY `foo`)";
3163 r
= run_query(hdb
, 0, query
);
3164 ok(r
== ERROR_BAD_QUERY_SYNTAX
, "created _Columns table\n");
3166 r
= MsiCloseHandle(hdb
);
3167 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3170 static void test_select_markers(void)
3172 MSIHANDLE hdb
= 0, rec
, view
, res
;
3179 ok( hdb
, "failed to create db\n");
3181 r
= run_query(hdb
, 0,
3182 "CREATE TABLE `Table` (`One` CHAR(72), `Two` CHAR(72), `Three` SHORT PRIMARY KEY `One`, `Two`, `Three`)");
3183 ok(r
== S_OK
, "cannot create table: %d\n", r
);
3185 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
3186 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'one', 1 )");
3187 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
3189 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
3190 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 1 )");
3191 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
3193 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
3194 "( `One`, `Two`, `Three` ) VALUES ( 'apple', 'two', 2 )");
3195 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
3197 r
= run_query(hdb
, 0, "INSERT INTO `Table` "
3198 "( `One`, `Two`, `Three` ) VALUES ( 'banana', 'three', 3 )");
3199 ok(r
== S_OK
, "cannot add file to the Media table: %d\n", r
);
3201 rec
= MsiCreateRecord(2);
3202 MsiRecordSetString(rec
, 1, "apple");
3203 MsiRecordSetString(rec
, 2, "two");
3205 query
= "SELECT * FROM `Table` WHERE `One`=? AND `Two`=? ORDER BY `Three`";
3206 r
= MsiDatabaseOpenView(hdb
, query
, &view
);
3207 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3209 r
= MsiViewExecute(view
, rec
);
3212 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3215 r
= MsiViewFetch(view
, &res
);
3218 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3222 r
= MsiRecordGetString(res
, 1, buf
, &size
);
3225 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3226 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
3230 r
= MsiRecordGetString(res
, 2, buf
, &size
);
3233 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3234 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
3237 r
= MsiRecordGetInteger(res
, 3);
3240 ok(r
== 1, "Expected 1, got %d\n", r
);
3243 MsiCloseHandle(res
);
3245 r
= MsiViewFetch(view
, &res
);
3248 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3252 r
= MsiRecordGetString(res
, 1, buf
, &size
);
3255 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3256 ok(!lstrcmp(buf
, "apple"), "Expected apple, got %s\n", buf
);
3260 r
= MsiRecordGetString(res
, 2, buf
, &size
);
3263 ok(r
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", r
);
3264 ok(!lstrcmp(buf
, "two"), "Expected two, got %s\n", buf
);
3267 r
= MsiRecordGetInteger(res
, 3);
3270 ok(r
== 2, "Expected 2, got %d\n", r
);
3273 MsiCloseHandle(res
);
3275 r
= MsiViewFetch(view
, &res
);
3276 ok(r
== ERROR_NO_MORE_ITEMS
, "Expected ERROR_NO_MORE_ITEMS, got %d\n", r
);
3278 r
= MsiViewClose(view
);
3279 ok(r
== ERROR_SUCCESS
, "MsiViewClose failed\n");
3280 r
= MsiCloseHandle(view
);
3281 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3282 r
= MsiCloseHandle(hdb
);
3283 ok(r
== ERROR_SUCCESS
, "MsiCloseHandle failed\n");
3290 test_msidecomposedesc();
3291 test_msibadqueries();
3293 test_viewgetcolumninfo();
3301 test_handle_limit();
3302 test_try_transform();
3304 test_temporary_table();
3308 test_special_tables();
3309 test_select_markers();