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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/test.h"
28 static const char *msifile = "winetest.msi";
30 static void test_msidatabase(void)
37 /* create an empty database */
38 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
39 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
41 res = MsiDatabaseCommit( hdb );
42 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
44 res = MsiCloseHandle( hdb );
45 ok( res == ERROR_SUCCESS , "Failed to close database\n" );
47 res = DeleteFile( msifile );
48 ok( res == TRUE, "Falled to delete database\n" );
51 static void test_msiinsert(void)
53 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
61 /* just MsiOpenDatabase should not create a file */
62 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
63 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
66 query = "CREATE TABLE `phone` ( "
67 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
69 r = MsiDatabaseOpenView(hdb, query, &hview);
70 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
71 r = MsiViewExecute(hview, 0);
72 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
73 r = MsiViewClose(hview);
74 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
75 r = MsiCloseHandle(hview);
76 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
78 /* insert a value into it */
79 query = "INSERT INTO `phone` ( `id`, `name`, `number` )"
80 "VALUES('1', 'Abe', '8675309')";
81 r = MsiDatabaseOpenView(hdb, query, &hview);
82 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
83 r = MsiViewExecute(hview, 0);
84 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
85 r = MsiViewClose(hview);
86 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
87 r = MsiCloseHandle(hview);
88 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
90 query = "SELECT * FROM `phone`";
91 r = MsiDatabaseOpenView(hdb, query, &hview);
92 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
93 r = MsiViewExecute(hview, 0);
94 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
95 r = MsiViewFetch(hview, &hrec);
96 ok(r == ERROR_SUCCESS, "MsiViewFetch failed\n");
98 /* check the record contains what we put in it */
99 r = MsiRecordGetFieldCount(hrec);
100 ok(r == 3, "record count wrong\n");
102 r = MsiRecordGetInteger(hrec, 1);
103 ok(r == 1, "field 1 contents wrong\n");
105 r = MsiRecordGetString(hrec, 2, buf, &sz);
106 ok(r == ERROR_SUCCESS, "field 2 content fetch failed\n");
107 ok(!strcmp(buf,"Abe"), "field 2 content incorrect\n");
109 r = MsiRecordGetString(hrec, 3, buf, &sz);
110 ok(r == ERROR_SUCCESS, "field 3 content fetch failed\n");
111 ok(!strcmp(buf,"8675309"), "field 3 content incorrect\n");
113 r = MsiViewClose(hview);
114 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
115 r = MsiCloseHandle(hview);
116 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
117 r = MsiCloseHandle(hrec);
118 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
120 r = MsiDatabaseCommit(hdb);
121 ok(r == ERROR_SUCCESS, "MsiDatabaseCommit failed\n");
123 r = MsiCloseHandle(hdb);
124 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
126 r = DeleteFile(msifile);
127 ok(r == TRUE, "file didn't exist after commit\n");
130 typedef UINT (WINAPI *fnMsiDecomposeDescriptorA)(LPCSTR, LPCSTR, LPSTR, LPSTR, DWORD *);
131 static fnMsiDecomposeDescriptorA pMsiDecomposeDescriptorA;
133 static void test_msidecomposedesc(void)
135 char prod[MAX_FEATURE_CHARS+1], comp[MAX_FEATURE_CHARS+1], feature[MAX_FEATURE_CHARS+1];
141 hmod = GetModuleHandle("msi.dll");
144 pMsiDecomposeDescriptorA = (fnMsiDecomposeDescriptorA)
145 GetProcAddress(hmod, "MsiDecomposeDescriptorA");
146 if (!pMsiDecomposeDescriptorA)
149 /* test a valid feature descriptor */
150 desc = "']gAVn-}f(ZXfeAR6.jiFollowTheWhiteRabbit>3w2x^IGfe?CxI5heAvk.";
152 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
153 ok(r == ERROR_SUCCESS, "returned an error\n");
154 ok(len == strlen(desc), "length was wrong\n");
155 ok(strcmp(prod,"{90110409-6000-11D3-8CFE-0150048383C9}")==0, "product wrong\n");
156 ok(strcmp(feature,"FollowTheWhiteRabbit")==0, "feature wrong\n");
157 ok(strcmp(comp,"{A7CD68DB-EF74-49C8-FBB2-A7C463B2AC24}")==0,"component wrong\n");
159 /* test an invalid feature descriptor with too many characters */
160 desc = "']gAVn-}f(ZXfeAR6.ji"
161 "ThisWillFailIfTheresMoreThanAGuidsChars>"
162 "3w2x^IGfe?CxI5heAvk.";
164 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
165 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
168 * Test a valid feature descriptor with the
169 * maximum number of characters and some trailing characters.
171 desc = "']gAVn-}f(ZXfeAR6.ji"
172 "ThisWillWorkIfTheresLTEThanAGuidsChars>"
173 "3w2x^IGfe?CxI5heAvk."
176 r = pMsiDecomposeDescriptorA(desc, prod, feature, comp, &len);
177 ok(r == ERROR_SUCCESS, "returned wrong error\n");
178 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
181 r = pMsiDecomposeDescriptorA(desc, prod, feature, NULL, &len);
182 ok(r == ERROR_SUCCESS, "returned wrong error\n");
183 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
186 r = pMsiDecomposeDescriptorA(desc, prod, NULL, NULL, &len);
187 ok(r == ERROR_SUCCESS, "returned wrong error\n");
188 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
191 r = pMsiDecomposeDescriptorA(desc, NULL, NULL, NULL, &len);
192 ok(r == ERROR_SUCCESS, "returned wrong error\n");
193 ok(len == (strlen(desc) - strlen("extra")), "length wrong\n");
196 r = pMsiDecomposeDescriptorA(NULL, NULL, NULL, NULL, &len);
197 ok(r == ERROR_INVALID_PARAMETER, "returned wrong error\n");
198 ok(len == 0, "length wrong\n");
201 static UINT try_query_param( MSIHANDLE hdb, LPCSTR szQuery, MSIHANDLE hrec )
206 res = MsiDatabaseOpenView( hdb, szQuery, &htab );
207 if(res == ERROR_SUCCESS )
211 r = MsiViewExecute( htab, hrec );
212 if(r != ERROR_SUCCESS )
215 r = MsiViewClose( htab );
216 if(r != ERROR_SUCCESS )
219 r = MsiCloseHandle( htab );
220 if(r != ERROR_SUCCESS )
226 static UINT try_query( MSIHANDLE hdb, LPCSTR szQuery )
228 return try_query_param( hdb, szQuery, 0 );
231 static UINT try_insert_query( MSIHANDLE hdb, LPCSTR szQuery )
236 hrec = MsiCreateRecord( 1 );
237 MsiRecordSetString( hrec, 1, "Hello");
239 r = try_query_param( hdb, szQuery, hrec );
241 MsiCloseHandle( hrec );
245 static void test_msibadqueries(void)
252 /* just MsiOpenDatabase should not create a file */
253 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
254 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
256 r = MsiDatabaseCommit( hdb );
257 ok(r == ERROR_SUCCESS , "Failed to commit database\n");
259 r = MsiCloseHandle( hdb );
260 ok(r == ERROR_SUCCESS , "Failed to close database\n");
262 /* open it readonly */
263 r = MsiOpenDatabase(msifile, MSIDBOPEN_READONLY, &hdb );
264 ok(r == ERROR_SUCCESS , "Failed to open database r/o\n");
266 /* add a table to it */
267 r = try_query( hdb, "select * from _Tables");
268 ok(r == ERROR_SUCCESS , "query 1 failed\n");
270 r = MsiCloseHandle( hdb );
271 ok(r == ERROR_SUCCESS , "Failed to close database r/o\n");
273 /* open it read/write */
274 r = MsiOpenDatabase(msifile, MSIDBOPEN_TRANSACT, &hdb );
275 ok(r == ERROR_SUCCESS , "Failed to open database r/w\n");
277 /* a bunch of test queries that fail with the native MSI */
279 r = try_query( hdb, "CREATE TABLE");
280 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2a return code\n");
282 r = try_query( hdb, "CREATE TABLE `a`");
283 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2b return code\n");
285 r = try_query( hdb, "CREATE TABLE `a` ()");
286 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2c return code\n");
288 r = try_query( hdb, "CREATE TABLE `a` (`b`)");
289 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2d return code\n");
291 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) )");
292 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2e return code\n");
294 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL)");
295 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2f return code\n");
297 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY)");
298 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2g return code\n");
300 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
301 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2h return code\n");
303 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY)");
304 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2i return code\n");
306 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY 'b')");
307 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2j return code\n");
309 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
310 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2k return code\n");
312 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b')");
313 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2l return code\n");
315 r = try_query( hdb, "CREATE TABLE `a` (`b` CHA(72) NOT NULL PRIMARY KEY `b`)");
316 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2m return code\n");
318 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(-1) NOT NULL PRIMARY KEY `b`)");
319 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2n return code\n");
321 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(720) NOT NULL PRIMARY KEY `b`)");
322 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2o return code\n");
324 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL KEY `b`)");
325 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
327 r = try_query( hdb, "CREATE TABLE `a` (`` CHAR(72) NOT NULL PRIMARY KEY `b`)");
328 ok(r == ERROR_BAD_QUERY_SYNTAX , "invalid query 2p return code\n");
330 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
331 ok(r == ERROR_SUCCESS , "valid query 2z failed\n");
333 r = try_query( hdb, "CREATE TABLE `a` (`b` CHAR(72) NOT NULL PRIMARY KEY `b`)");
334 ok(r == ERROR_BAD_QUERY_SYNTAX , "created same table again\n");
336 r = try_query( hdb, "CREATE TABLE `aa` (`b` CHAR(72) NOT NULL, `c` "
337 "CHAR(72), `d` CHAR(255) NOT NULL LOCALIZABLE PRIMARY KEY `b`)");
338 ok(r == ERROR_SUCCESS , "query 4 failed\n");
340 r = MsiDatabaseCommit( hdb );
341 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
343 r = try_query( hdb, "CREATE TABLE `blah` (`foo` CHAR(72) NOT NULL "
344 "PRIMARY KEY `foo`)");
345 ok(r == ERROR_SUCCESS , "query 4 failed\n");
347 r = try_insert_query( hdb, "insert into a ( `b` ) VALUES ( ? )");
348 ok(r == ERROR_SUCCESS , "failed to insert record in db\n");
350 r = MsiDatabaseCommit( hdb );
351 ok(r == ERROR_SUCCESS , "Failed to commit database after write\n");
353 r = try_query( hdb, "CREATE TABLE `boo` (`foo` CHAR(72) NOT NULL "
354 "PRIMARY KEY `ba`)");
355 ok(r != ERROR_SUCCESS , "query 5 succeeded\n");
357 r = try_query( hdb,"CREATE TABLE `bee` (`foo` CHAR(72) NOT NULL )");
358 ok(r != ERROR_SUCCESS , "query 6 succeeded\n");
360 r = try_query( hdb, "CREATE TABLE `temp` (`t` CHAR(72) NOT NULL "
362 ok(r == ERROR_SUCCESS , "query 7 failed\n");
364 r = try_query( hdb, "CREATE TABLE `c` (`b` CHAR NOT NULL PRIMARY KEY `b`)");
365 ok(r == ERROR_SUCCESS , "query 8 failed\n");
367 r = MsiCloseHandle( hdb );
368 ok(r == ERROR_SUCCESS , "Failed to close database transact\n");
370 r = DeleteFile( msifile );
371 ok(r == TRUE, "file didn't exist after commit\n");
374 static UINT run_query( MSIHANDLE hdb, const char *query )
379 r = MsiDatabaseOpenView(hdb, query, &hview);
380 if( r != ERROR_SUCCESS )
383 r = MsiViewExecute(hview, 0);
384 if( r == ERROR_SUCCESS )
385 r = MsiViewClose(hview);
386 MsiCloseHandle(hview);
390 static void test_viewmodify(void)
392 MSIHANDLE hdb = 0, hview = 0, hrec = 0;
400 /* just MsiOpenDatabase should not create a file */
401 r = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb);
402 ok(r == ERROR_SUCCESS, "MsiOpenDatabase failed\n");
404 query = "CREATE TABLE `phone` ( "
405 "`id` INT, `name` CHAR(32), `number` CHAR(32) "
407 r = run_query( hdb, query );
408 ok(r == ERROR_SUCCESS, "query failed\n");
410 /* check what the error function reports without doing anything */
412 /* passing NULL as the 3rd param make function to crash on older platforms */
413 r = MsiViewGetError( 0, NULL, &sz );
414 ok(r == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
417 query = "SELECT * FROM `phone`";
418 r = MsiDatabaseOpenView(hdb, query, &hview);
419 ok(r == ERROR_SUCCESS, "MsiDatabaseOpenView failed\n");
421 /* see what happens with a good hview and bad args */
422 r = MsiViewGetError( hview, NULL, NULL );
423 ok(r == MSIDBERROR_INVALIDARG || r == MSIDBERROR_NOERROR,
424 "MsiViewGetError returns %u (expected -3)\n", r);
425 r = MsiViewGetError( hview, buffer, NULL );
426 ok(r == MSIDBERROR_INVALIDARG, "MsiViewGetError return\n");
428 /* see what happens with a zero length buffer */
431 r = MsiViewGetError( hview, buffer, &sz );
432 ok(r == MSIDBERROR_MOREDATA, "MsiViewGetError return\n");
433 ok(buffer[0] == 'x', "buffer cleared\n");
434 ok(sz == 0, "size not zero\n");
436 /* ok this one is strange */
438 r = MsiViewGetError( hview, NULL, &sz );
439 ok(r == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
440 ok(sz == 0, "size not zero\n");
442 /* see if it really has an error */
445 r = MsiViewGetError( hview, buffer, &sz );
446 ok(r == MSIDBERROR_NOERROR, "MsiViewGetError return\n");
447 ok(buffer[0] == 0, "buffer not cleared\n");
448 ok(sz == 0, "size not zero\n");
450 r = MsiViewExecute(hview, 0);
451 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
453 /* try some invalid records */
454 r = MsiViewModify(hview, MSIMODIFY_INSERT, 0 );
455 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
456 r = MsiViewModify(hview, -1, 0 );
457 ok(r == ERROR_INVALID_HANDLE, "MsiViewModify failed\n");
459 /* try an small record */
460 hrec = MsiCreateRecord(1);
461 r = MsiViewModify(hview, -1, hrec );
462 ok(r == ERROR_INVALID_DATA, "MsiViewModify failed\n");
464 r = MsiCloseHandle(hrec);
465 ok(r == ERROR_SUCCESS, "failed to close record\n");
467 /* insert a valid record */
468 hrec = MsiCreateRecord(3);
470 r = MsiRecordSetInteger(hrec, 2, 1);
471 ok(r == ERROR_SUCCESS, "failed to set integer\n");
472 r = MsiRecordSetString(hrec, 2, "bob");
473 ok(r == ERROR_SUCCESS, "failed to set integer\n");
474 r = MsiRecordSetString(hrec, 3, "7654321");
475 ok(r == ERROR_SUCCESS, "failed to set integer\n");
477 r = MsiViewExecute(hview, 0);
478 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
479 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
480 ok(r == ERROR_SUCCESS, "MsiViewModify failed\n");
482 /* insert the same thing again */
483 r = MsiViewExecute(hview, 0);
484 ok(r == ERROR_SUCCESS, "MsiViewExecute failed\n");
486 /* should fail ... */
488 r = MsiViewModify(hview, MSIMODIFY_INSERT_TEMPORARY, hrec );
489 ok(r == ERROR_FUNCTION_FAILED, "MsiViewModify failed\n");
492 r = MsiCloseHandle(hrec);
493 ok(r == ERROR_SUCCESS, "failed to close record\n");
495 r = MsiViewClose(hview);
496 ok(r == ERROR_SUCCESS, "MsiViewClose failed\n");
497 r = MsiCloseHandle(hview);
498 ok(r == ERROR_SUCCESS, "MsiCloseHandle failed\n");
500 r = MsiCloseHandle( hdb );
501 ok(r == ERROR_SUCCESS, "MsiOpenDatabase close failed\n");
504 static MSIHANDLE create_db(void)
511 /* create an empty database */
512 res = MsiOpenDatabase(msifile, MSIDBOPEN_CREATE, &hdb );
513 ok( res == ERROR_SUCCESS , "Failed to create database\n" );
514 if( res != ERROR_SUCCESS )
517 res = MsiDatabaseCommit( hdb );
518 ok( res == ERROR_SUCCESS , "Failed to commit database\n" );
523 static void test_getcolinfo(void)
525 MSIHANDLE hdb, hview = 0, rec = 0;
530 /* create an empty db */
532 ok( hdb, "failed to create db\n");
534 /* tables should be present */
535 r = MsiDatabaseOpenView(hdb, "select * from _Tables", &hview);
536 ok( r == ERROR_SUCCESS, "failed to open query\n");
538 r = MsiViewExecute(hview, 0);
539 ok( r == ERROR_SUCCESS, "failed to execute query\n");
541 /* check that NAMES works */
543 r = MsiViewGetColumnInfo( hview, MSICOLINFO_NAMES, &rec );
544 ok( r == ERROR_SUCCESS, "failed to get names\n");
546 r = MsiRecordGetString(rec, 1, buffer, &sz );
547 ok( r == ERROR_SUCCESS, "failed to get string\n");
548 ok( !strcmp(buffer,"Name"), "_Tables has wrong column name\n");
549 r = MsiCloseHandle( rec );
550 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
552 /* check that TYPES works */
554 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, &rec );
555 ok( r == ERROR_SUCCESS, "failed to get names\n");
557 r = MsiRecordGetString(rec, 1, buffer, &sz );
558 ok( r == ERROR_SUCCESS, "failed to get string\n");
559 ok( !strcmp(buffer,"s64"), "_Tables has wrong column type\n");
560 r = MsiCloseHandle( rec );
561 ok( r == ERROR_SUCCESS, "failed to close record handle\n");
563 /* check that invalid values fail */
565 r = MsiViewGetColumnInfo( hview, 100, &rec );
566 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
567 ok( rec == 0, "returned a record\n");
569 r = MsiViewGetColumnInfo( hview, MSICOLINFO_TYPES, NULL );
570 ok( r == ERROR_INVALID_PARAMETER, "wrong error code\n");
572 r = MsiViewGetColumnInfo( 0, MSICOLINFO_TYPES, &rec );
573 ok( r == ERROR_INVALID_HANDLE, "wrong error code\n");
575 r = MsiViewClose(hview);
576 ok( r == ERROR_SUCCESS, "failed to close view\n");
577 r = MsiCloseHandle(hview);
578 ok( r == ERROR_SUCCESS, "failed to close view handle\n");
579 r = MsiCloseHandle(hdb);
580 ok( r == ERROR_SUCCESS, "failed to close database\n");
583 static MSIHANDLE get_column_info(MSIHANDLE hdb, const char *query, MSICOLINFO type)
585 MSIHANDLE hview = 0, rec = 0;
588 r = MsiDatabaseOpenView(hdb, query, &hview);
589 if( r != ERROR_SUCCESS )
592 r = MsiViewExecute(hview, 0);
593 if( r == ERROR_SUCCESS )
595 MsiViewGetColumnInfo( hview, type, &rec );
598 MsiCloseHandle(hview);
602 static UINT get_columns_table_type(MSIHANDLE hdb, const char *table, UINT field)
604 MSIHANDLE hview = 0, rec = 0;
608 sprintf(query, "select * from `_Columns` where `Table` = '%s'", table );
610 r = MsiDatabaseOpenView(hdb, query, &hview);
611 if( r != ERROR_SUCCESS )
614 r = MsiViewExecute(hview, 0);
615 if( r == ERROR_SUCCESS )
619 r = MsiViewFetch( hview, &rec );
620 if( r != ERROR_SUCCESS)
622 r = MsiRecordGetInteger( rec, 2 );
624 type = MsiRecordGetInteger( rec, 4 );
625 MsiCloseHandle( rec );
630 MsiCloseHandle(hview);
634 static BOOL check_record( MSIHANDLE rec, UINT field, LPSTR val )
641 r = MsiRecordGetString( rec, field, buffer, &sz );
642 return (r == ERROR_SUCCESS ) && !strcmp(val, buffer);
645 static void test_viewgetcolumninfo(void)
647 MSIHANDLE hdb = 0, rec;
651 ok( hdb, "failed to create db\n");
654 "CREATE TABLE `Properties` "
655 "( `Property` CHAR(255), `Value` CHAR(1) PRIMARY KEY `Property`)" );
656 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
658 /* check the column types */
659 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_TYPES );
660 ok( rec, "failed to get column info record\n" );
662 ok( check_record( rec, 1, "S255"), "wrong record type\n");
663 ok( check_record( rec, 2, "S1"), "wrong record type\n");
665 MsiCloseHandle( rec );
667 /* check the type in _Columns */
668 ok( 0x3dff == get_columns_table_type(hdb, "Properties", 1 ), "_columns table wrong\n");
669 ok( 0x1d01 == get_columns_table_type(hdb, "Properties", 2 ), "_columns table wrong\n");
671 /* now try the names */
672 rec = get_column_info( hdb, "select * from `Properties`", MSICOLINFO_NAMES );
673 ok( rec, "failed to get column info record\n" );
675 ok( check_record( rec, 1, "Property"), "wrong record type\n");
676 ok( check_record( rec, 2, "Value"), "wrong record type\n");
678 MsiCloseHandle( rec );
681 "CREATE TABLE `Binary` "
682 "( `Name` CHAR(255), `Data` OBJECT PRIMARY KEY `Name`)" );
683 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
685 /* check the column types */
686 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_TYPES );
687 ok( rec, "failed to get column info record\n" );
689 ok( check_record( rec, 1, "S255"), "wrong record type\n");
690 ok( check_record( rec, 2, "V0"), "wrong record type\n");
692 MsiCloseHandle( rec );
694 /* check the type in _Columns */
695 ok( 0x3dff == get_columns_table_type(hdb, "Binary", 1 ), "_columns table wrong\n");
696 ok( 0x1900 == get_columns_table_type(hdb, "Binary", 2 ), "_columns table wrong\n");
698 /* now try the names */
699 rec = get_column_info( hdb, "select * from `Binary`", MSICOLINFO_NAMES );
700 ok( rec, "failed to get column info record\n" );
702 ok( check_record( rec, 1, "Name"), "wrong record type\n");
703 ok( check_record( rec, 2, "Data"), "wrong record type\n");
704 MsiCloseHandle( rec );
707 "CREATE TABLE `UIText` "
708 "( `Key` CHAR(72) NOT NULL, `Text` CHAR(255) LOCALIZABLE PRIMARY KEY `Key`)" );
709 ok( r == ERROR_SUCCESS , "Failed to create table\n" );
711 ok( 0x2d48 == get_columns_table_type(hdb, "UIText", 1 ), "_columns table wrong\n");
712 ok( 0x1fff == get_columns_table_type(hdb, "UIText", 2 ), "_columns table wrong\n");
714 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_NAMES );
715 ok( rec, "failed to get column info record\n" );
716 ok( check_record( rec, 1, "Key"), "wrong record type\n");
717 ok( check_record( rec, 2, "Text"), "wrong record type\n");
718 MsiCloseHandle( rec );
720 rec = get_column_info( hdb, "select * from `UIText`", MSICOLINFO_TYPES );
721 ok( rec, "failed to get column info record\n" );
722 ok( check_record( rec, 1, "s72"), "wrong record type\n");
723 ok( check_record( rec, 2, "L255"), "wrong record type\n");
724 MsiCloseHandle( rec );
726 MsiCloseHandle( hdb );
733 test_msidecomposedesc();
734 test_msibadqueries();
736 test_viewgetcolumninfo();