2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002-2005 Mike McCormack for CodeWeavers
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
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
30 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msidb
);
42 typedef struct tagMSICOLUMNINFO
59 typedef struct tagMSITRANSFORM
{
64 #define MAX_STREAM_NAME 0x1f
66 static UINT
table_get_column_info( MSIDATABASE
*db
, LPCWSTR name
,
67 MSICOLUMNINFO
**pcols
, UINT
*pcount
);
68 static UINT
get_tablecolumns( MSIDATABASE
*db
,
69 LPCWSTR szTableName
, MSICOLUMNINFO
*colinfo
, UINT
*sz
);
70 static void msi_free_colinfo( MSICOLUMNINFO
*colinfo
, UINT count
);
72 static inline UINT
bytes_per_column( const MSICOLUMNINFO
*col
)
74 if( col
->type
& MSITYPE_STRING
)
76 if( (col
->type
& 0xff) > 4 )
77 ERR("Invalid column size!\n");
78 return col
->type
& 0xff;
81 static int utf2mime(int x
)
83 if( (x
>='0') && (x
<='9') )
85 if( (x
>='A') && (x
<='Z') )
87 if( (x
>='a') && (x
<='z') )
96 static LPWSTR
encode_streamname(BOOL bTable
, LPCWSTR in
)
98 DWORD count
= MAX_STREAM_NAME
;
103 count
= lstrlenW( in
)+2;
104 out
= msi_alloc( count
*sizeof(WCHAR
) );
120 if( ( ch
< 0x80 ) && ( utf2mime(ch
) >= 0 ) )
122 ch
= utf2mime(ch
) + 0x4800;
124 if( next
&& (next
<0x80) )
126 next
= utf2mime(next
);
137 ERR("Failed to encode stream name (%s)\n",debugstr_w(in
));
142 static int mime2utf(int x
)
149 return x
- 10 - 26 + 'a';
150 if( x
== (10+26+26) )
155 static BOOL
decode_streamname(LPWSTR in
, LPWSTR out
)
160 while ( (ch
= *in
++) )
162 if( (ch
>= 0x3800 ) && (ch
< 0x4840 ) )
165 ch
= mime2utf(ch
-0x4800);
169 *out
++ = mime2utf(ch
&0x3f);
171 ch
= mime2utf((ch
>>6)&0x3f);
181 void enum_stream_names( IStorage
*stg
)
183 IEnumSTATSTG
*stgenum
= NULL
;
189 r
= IStorage_EnumElements( stg
, 0, NULL
, 0, &stgenum
);
197 r
= IEnumSTATSTG_Next( stgenum
, 1, &stat
, &count
);
198 if( FAILED( r
) || !count
)
200 decode_streamname( stat
.pwcsName
, name
);
201 TRACE("stream %2ld -> %s %s\n", n
,
202 debugstr_w(stat
.pwcsName
), debugstr_w(name
) );
206 IEnumSTATSTG_Release( stgenum
);
209 static UINT
read_stream_data( IStorage
*stg
, LPCWSTR stname
,
210 USHORT
**pdata
, UINT
*psz
)
213 UINT ret
= ERROR_FUNCTION_FAILED
;
220 encname
= encode_streamname(TRUE
, stname
);
222 TRACE("%s -> %s\n",debugstr_w(stname
),debugstr_w(encname
));
224 r
= IStorage_OpenStream(stg
, encname
, NULL
,
225 STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
229 WARN("open stream failed r = %08lx - empty table?\n",r
);
233 r
= IStream_Stat(stm
, &stat
, STATFLAG_NONAME
);
236 WARN("open stream failed r = %08lx!\n",r
);
240 if( stat
.cbSize
.QuadPart
>> 32 )
246 sz
= stat
.cbSize
.QuadPart
;
247 data
= msi_alloc( sz
);
250 WARN("couldn't allocate memory r=%08lx!\n",r
);
251 ret
= ERROR_NOT_ENOUGH_MEMORY
;
255 r
= IStream_Read(stm
, data
, sz
, &count
);
256 if( FAILED( r
) || ( count
!= sz
) )
259 WARN("read stream failed r = %08lx!\n",r
);
268 IStream_Release( stm
);
273 UINT
db_get_raw_stream( MSIDATABASE
*db
, LPCWSTR stname
, IStream
**stm
)
278 encname
= encode_streamname(FALSE
, stname
);
280 TRACE("%s -> %s\n",debugstr_w(stname
),debugstr_w(encname
));
282 r
= IStorage_OpenStream(db
->storage
, encname
, NULL
,
283 STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, stm
);
286 MSITRANSFORM
*transform
;
288 LIST_FOR_EACH_ENTRY( transform
, &db
->transforms
, MSITRANSFORM
, entry
)
290 TRACE("looking for %s in transform storage\n", debugstr_w(stname
) );
291 r
= IStorage_OpenStream( transform
->stg
, encname
, NULL
,
292 STGM_READ
| STGM_SHARE_EXCLUSIVE
, 0, stm
);
300 return SUCCEEDED(r
) ? ERROR_SUCCESS
: ERROR_FUNCTION_FAILED
;
303 UINT
read_raw_stream_data( MSIDATABASE
*db
, LPCWSTR stname
,
304 USHORT
**pdata
, UINT
*psz
)
307 UINT ret
= ERROR_FUNCTION_FAILED
;
313 r
= db_get_raw_stream( db
, stname
, &stm
);
314 if( r
!= ERROR_SUCCESS
)
316 r
= IStream_Stat(stm
, &stat
, STATFLAG_NONAME
);
319 WARN("open stream failed r = %08lx!\n",r
);
323 if( stat
.cbSize
.QuadPart
>> 32 )
329 sz
= stat
.cbSize
.QuadPart
;
330 data
= msi_alloc( sz
);
333 WARN("couldn't allocate memory r=%08lx!\n",r
);
334 ret
= ERROR_NOT_ENOUGH_MEMORY
;
338 r
= IStream_Read(stm
, data
, sz
, &count
);
339 if( FAILED( r
) || ( count
!= sz
) )
342 WARN("read stream failed r = %08lx!\n",r
);
351 IStream_Release( stm
);
356 static UINT
write_stream_data( IStorage
*stg
, LPCWSTR stname
,
357 LPVOID data
, UINT sz
)
360 UINT ret
= ERROR_FUNCTION_FAILED
;
367 encname
= encode_streamname(TRUE
, stname
);
368 r
= IStorage_OpenStream( stg
, encname
, NULL
,
369 STGM_WRITE
| STGM_SHARE_EXCLUSIVE
, 0, &stm
);
372 r
= IStorage_CreateStream( stg
, encname
,
373 STGM_WRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
378 WARN("open stream failed r = %08lx\n",r
);
383 r
= IStream_SetSize( stm
, size
);
386 WARN("Failed to SetSize\n");
391 r
= IStream_Seek( stm
, pos
, STREAM_SEEK_SET
, NULL
);
394 WARN("Failed to Seek\n");
398 r
= IStream_Write(stm
, data
, sz
, &count
);
399 if( FAILED( r
) || ( count
!= sz
) )
401 WARN("Failed to Write\n");
408 IStream_Release( stm
);
413 static void free_table( MSITABLE
*table
)
416 for( i
=0; i
<table
->row_count
; i
++ )
417 msi_free( table
->data
[i
] );
418 msi_free( table
->data
);
422 static UINT
msi_table_get_row_size( const MSICOLUMNINFO
*cols
, UINT count
)
424 const MSICOLUMNINFO
*last_col
= &cols
[count
-1];
427 return last_col
->offset
+ bytes_per_column( last_col
);
430 /* add this table to the list of cached tables in the database */
431 static MSITABLE
*read_table_from_storage( IStorage
*stg
, LPCWSTR name
,
432 const MSICOLUMNINFO
*cols
, UINT num_cols
)
435 USHORT
*rawdata
= NULL
;
436 UINT rawsize
= 0, i
, j
, row_size
= 0;
438 TRACE("%s\n",debugstr_w(name
));
440 /* nonexistent tables should be interpreted as empty tables */
441 t
= msi_alloc( sizeof (MSITABLE
) + lstrlenW(name
)*sizeof (WCHAR
) );
445 row_size
= msi_table_get_row_size( cols
, num_cols
);
449 lstrcpyW( t
->name
, name
);
451 /* if we can't read the table, just assume that it's empty */
452 read_stream_data( stg
, name
, &rawdata
, &rawsize
);
456 TRACE("Read %d bytes\n", rawsize
);
458 if( rawsize
% row_size
)
460 WARN("Table size is invalid %d/%d\n", rawsize
, row_size
);
464 t
->row_count
= rawsize
/ row_size
;
465 t
->data
= msi_alloc_zero( t
->row_count
* sizeof (USHORT
*) );
469 /* transpose all the data */
470 TRACE("Transposing data from %d columns\n", t
->row_count
);
471 for( i
=0; i
<t
->row_count
; i
++ )
473 t
->data
[i
] = msi_alloc( row_size
);
477 for( j
=0; j
<num_cols
; j
++ )
479 UINT ofs
= cols
[j
].offset
/2;
480 UINT n
= bytes_per_column( &cols
[j
] );
485 t
->data
[i
][ofs
] = rawdata
[ofs
*t
->row_count
+ i
];
488 t
->data
[i
][ofs
] = rawdata
[ofs
*t
->row_count
+ i
*2 ];
489 t
->data
[i
][ofs
+1] = rawdata
[ofs
*t
->row_count
+ i
*2 + 1];
492 ERR("oops - unknown column width %d\n", n
);
506 void free_cached_tables( MSIDATABASE
*db
)
508 while( !list_empty( &db
->tables
) )
510 MSITABLE
*t
= LIST_ENTRY( list_head( &db
->tables
), MSITABLE
, entry
);
512 list_remove( &t
->entry
);
517 static MSITABLE
*find_cached_table( MSIDATABASE
*db
, LPCWSTR name
)
521 LIST_FOR_EACH_ENTRY( t
, &db
->tables
, MSITABLE
, entry
)
522 if( !lstrcmpW( name
, t
->name
) )
528 static UINT
table_get_column_info( MSIDATABASE
*db
, LPCWSTR name
, MSICOLUMNINFO
**pcols
, UINT
*pcount
)
530 UINT r
, column_count
= 0;
531 MSICOLUMNINFO
*columns
;
533 /* get the number of columns in this table */
535 r
= get_tablecolumns( db
, name
, NULL
, &column_count
);
536 if( r
!= ERROR_SUCCESS
)
539 /* if there's no columns, there's no table */
540 if( column_count
== 0 )
541 return ERROR_INVALID_PARAMETER
;
543 TRACE("Table %s found\n", debugstr_w(name
) );
545 columns
= msi_alloc( column_count
*sizeof (MSICOLUMNINFO
) );
547 return ERROR_FUNCTION_FAILED
;
549 r
= get_tablecolumns( db
, name
, columns
, &column_count
);
550 if( r
!= ERROR_SUCCESS
)
553 return ERROR_FUNCTION_FAILED
;
557 *pcount
= column_count
;
562 static MSITABLE
*get_table( MSIDATABASE
*db
, LPCWSTR name
,
563 const MSICOLUMNINFO
*cols
, UINT num_cols
)
567 /* first, see if the table is cached */
568 table
= find_cached_table( db
, name
);
572 table
= read_table_from_storage( db
->storage
, name
, cols
, num_cols
);
574 list_add_head( &db
->tables
, &table
->entry
);
579 static UINT
save_table( MSIDATABASE
*db
, MSITABLE
*t
)
581 USHORT
*rawdata
= NULL
, *p
;
582 UINT rawsize
, r
, i
, j
, row_size
, num_cols
= 0;
583 MSICOLUMNINFO
*cols
= NULL
;
585 TRACE("Saving %s\n", debugstr_w( t
->name
) );
587 r
= table_get_column_info( db
, t
->name
, &cols
, &num_cols
);
588 if( r
!= ERROR_SUCCESS
)
591 row_size
= msi_table_get_row_size( cols
, num_cols
);
593 rawsize
= t
->row_count
* row_size
;
594 rawdata
= msi_alloc_zero( rawsize
);
597 r
= ERROR_NOT_ENOUGH_MEMORY
;
602 for( i
=0; i
<num_cols
; i
++ )
604 for( j
=0; j
<t
->row_count
; j
++ )
606 UINT offset
= cols
[i
].offset
;
608 *p
++ = t
->data
[j
][offset
/2];
609 if( 4 == bytes_per_column( &cols
[i
] ) )
610 *p
++ = t
->data
[j
][offset
/2+1];
614 TRACE("writing %d bytes\n", rawsize
);
615 r
= write_stream_data( db
->storage
, t
->name
, rawdata
, rawsize
);
618 msi_free_colinfo( cols
, num_cols
);
625 HRESULT
init_string_table( IStorage
*stg
)
628 static const WCHAR szStringData
[] = {
629 '_','S','t','r','i','n','g','D','a','t','a',0 };
630 static const WCHAR szStringPool
[] = {
631 '_','S','t','r','i','n','g','P','o','o','l',0 };
632 USHORT zero
[2] = { 0, 0 };
637 encname
= encode_streamname(TRUE
, szStringPool
);
639 /* create the StringPool stream... add the zero string to it*/
640 r
= IStorage_CreateStream( stg
, encname
,
641 STGM_WRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
649 r
= IStream_Write(stm
, zero
, sizeof zero
, &count
);
650 IStream_Release( stm
);
652 if( FAILED( r
) || ( count
!= sizeof zero
) )
658 /* create the StringData stream... make it zero length */
659 encname
= encode_streamname(TRUE
, szStringData
);
660 r
= IStorage_CreateStream( stg
, encname
,
661 STGM_WRITE
| STGM_SHARE_EXCLUSIVE
, 0, 0, &stm
);
668 IStream_Release( stm
);
673 string_table
*load_string_table( IStorage
*stg
)
675 string_table
*st
= NULL
;
678 UINT r
, datasize
= 0, poolsize
= 0, codepage
;
679 DWORD i
, count
, offset
, len
, n
;
680 static const WCHAR szStringData
[] = {
681 '_','S','t','r','i','n','g','D','a','t','a',0 };
682 static const WCHAR szStringPool
[] = {
683 '_','S','t','r','i','n','g','P','o','o','l',0 };
685 r
= read_stream_data( stg
, szStringPool
, &pool
, &poolsize
);
686 if( r
!= ERROR_SUCCESS
)
688 r
= read_stream_data( stg
, szStringData
, (USHORT
**)&data
, &datasize
);
689 if( r
!= ERROR_SUCCESS
)
694 codepage
= pool
[0] | ( pool
[1] << 16 );
697 st
= msi_init_stringtable( count
, codepage
);
701 for( i
=1; i
<count
; i
++ )
706 * If a string is over 64k, the previous string entry is made null
707 * and its the high word of the length is inserted in the null string's
708 * reference count field.
710 if( pool
[i
*2-2] == 0 )
711 len
+= pool
[i
*2-1] * 0x10000;
713 if( (offset
+ len
) > datasize
)
715 ERR("string table corrupt?\n");
719 /* don't add the high word of a string's length as a string */
720 if ( len
|| !pool
[i
*2+1] )
722 r
= msi_addstring( st
, n
, data
+offset
, len
, pool
[i
*2+1] );
724 ERR("Failed to add string %ld\n", n
);
731 if ( datasize
!= offset
)
732 ERR("string table load failed! (%08x != %08lx)\n", datasize
, offset
);
734 TRACE("Loaded %ld strings\n", count
);
743 static UINT
save_string_table( MSIDATABASE
*db
)
745 UINT i
, count
, datasize
, poolsize
, sz
, used
, r
, codepage
;
746 UINT ret
= ERROR_FUNCTION_FAILED
;
747 static const WCHAR szStringData
[] = {
748 '_','S','t','r','i','n','g','D','a','t','a',0 };
749 static const WCHAR szStringPool
[] = {
750 '_','S','t','r','i','n','g','P','o','o','l',0 };
756 /* construct the new table in memory first */
757 datasize
= msi_string_totalsize( db
->strings
, &count
);
758 poolsize
= count
*2*sizeof(USHORT
);
760 pool
= msi_alloc( poolsize
);
763 WARN("Failed to alloc pool %d bytes\n", poolsize
);
766 data
= msi_alloc( datasize
);
769 WARN("Failed to alloc data %d bytes\n", poolsize
);
774 codepage
= msi_string_get_codepage( db
->strings
);
775 pool
[0]=codepage
&0xffff;
776 pool
[1]=(codepage
>>16);
777 for( i
=1; i
<count
; i
++ )
779 sz
= datasize
- used
;
780 r
= msi_id2stringA( db
->strings
, i
, data
+used
, &sz
);
781 if( r
!= ERROR_SUCCESS
)
783 ERR("failed to fetch string\n");
786 if( sz
&& (sz
< (datasize
- used
) ) )
788 TRACE("adding %u bytes %s\n", sz
, debugstr_a(data
+used
) );
790 pool
[ i
*2 + 1 ] = msi_id_refcount( db
->strings
, i
);
792 if( used
> datasize
)
794 ERR("oops overran %d >= %d\n", used
, datasize
);
799 if( used
!= datasize
)
801 ERR("oops used %d != datasize %d\n", used
, datasize
);
805 /* write the streams */
806 r
= write_stream_data( db
->storage
, szStringData
, data
, datasize
);
807 TRACE("Wrote StringData r=%08x\n", r
);
810 r
= write_stream_data( db
->storage
, szStringPool
, pool
, poolsize
);
811 TRACE("Wrote StringPool r=%08x\n", r
);
824 /* information for default tables */
825 static const WCHAR szTables
[] = { '_','T','a','b','l','e','s',0 };
826 static const WCHAR szTable
[] = { 'T','a','b','l','e',0 };
827 static const WCHAR szName
[] = { 'N','a','m','e',0 };
828 static const WCHAR szColumns
[] = { '_','C','o','l','u','m','n','s',0 };
829 static const WCHAR szColumn
[] = { 'C','o','l','u','m','n',0 };
830 static const WCHAR szNumber
[] = { 'N','u','m','b','e','r',0 };
831 static const WCHAR szType
[] = { 'T','y','p','e',0 };
833 static const MSICOLUMNINFO _Columns_cols
[4] = {
834 { szColumns
, 1, szTable
, MSITYPE_VALID
| MSITYPE_STRING
| 64, 0 },
835 { szColumns
, 2, szNumber
, MSITYPE_VALID
| 2, 2 },
836 { szColumns
, 3, szName
, MSITYPE_VALID
| MSITYPE_STRING
| 64, 4 },
837 { szColumns
, 4, szType
, MSITYPE_VALID
| 2, 6 },
839 static const MSICOLUMNINFO _Tables_cols
[1] = {
840 { szTables
, 1, szName
, MSITYPE_VALID
| MSITYPE_STRING
| 64, 0 },
843 static UINT
get_defaulttablecolumns( LPCWSTR name
, MSICOLUMNINFO
*colinfo
, UINT
*sz
)
845 const MSICOLUMNINFO
*p
;
848 TRACE("%s\n", debugstr_w(name
));
850 if (!lstrcmpW( name
, szTables
))
855 else if (!lstrcmpW( name
, szColumns
))
861 return ERROR_FUNCTION_FAILED
;
863 /* duplicate the string data so we can free it in msi_free_colinfo */
866 if (colinfo
&& (i
< *sz
) )
868 memcpy( &colinfo
[i
], &p
[i
], sizeof(MSICOLUMNINFO
) );
869 colinfo
[i
].tablename
= strdupW( p
[i
].tablename
);
870 colinfo
[i
].colname
= strdupW( p
[i
].colname
);
872 if( colinfo
&& (i
>= *sz
) )
876 return ERROR_SUCCESS
;
879 static void msi_free_colinfo( MSICOLUMNINFO
*colinfo
, UINT count
)
883 for( i
=0; i
<count
; i
++ )
885 msi_free( (LPWSTR
) colinfo
[i
].tablename
);
886 msi_free( (LPWSTR
) colinfo
[i
].colname
);
890 LPWSTR
MSI_makestring( MSIDATABASE
*db
, UINT stringid
)
895 r
= msi_id2stringW( db
->strings
, stringid
, NULL
, &sz
);
896 if( r
!= ERROR_SUCCESS
)
898 str
= msi_alloc( sz
*sizeof (WCHAR
) );
901 r
= msi_id2stringW( db
->strings
, stringid
, str
, &sz
);
902 if( r
== ERROR_SUCCESS
)
908 static UINT
get_tablecolumns( MSIDATABASE
*db
,
909 LPCWSTR szTableName
, MSICOLUMNINFO
*colinfo
, UINT
*sz
)
911 UINT r
, i
, n
=0, table_id
, count
, maxcount
= *sz
;
912 MSITABLE
*table
= NULL
;
914 /* first check if there is a default table with that name */
915 r
= get_defaulttablecolumns( szTableName
, colinfo
, sz
);
916 if( ( r
== ERROR_SUCCESS
) && *sz
)
919 table
= get_table( db
, szColumns
, _Columns_cols
, 4 );
922 ERR("couldn't load _Columns table\n");
923 return ERROR_FUNCTION_FAILED
;
926 /* convert table and column names to IDs from the string table */
927 r
= msi_string2idW( db
->strings
, szTableName
, &table_id
);
928 if( r
!= ERROR_SUCCESS
)
930 WARN("Couldn't find id for %s\n", debugstr_w(szTableName
));
934 TRACE("Table id is %d\n", table_id
);
936 count
= table
->row_count
;
937 for( i
=0; i
<count
; i
++ )
939 if( table
->data
[ i
][ 0 ] != table_id
)
943 UINT id
= table
->data
[ i
] [ 2 ];
944 colinfo
[n
].tablename
= MSI_makestring( db
, table_id
);
945 colinfo
[n
].number
= table
->data
[ i
][ 1 ] - (1<<15);
946 colinfo
[n
].colname
= MSI_makestring( db
, id
);
947 colinfo
[n
].type
= table
->data
[ i
] [ 3 ] ^ 0x8000;
948 /* this assumes that columns are in order in the table */
950 colinfo
[n
].offset
= colinfo
[n
-1].offset
951 + bytes_per_column( &colinfo
[n
-1] );
953 colinfo
[n
].offset
= 0;
954 TRACE("table %s column %d is [%s] (%d) with type %08x "
955 "offset %d at row %d\n", debugstr_w(szTableName
),
956 colinfo
[n
].number
, debugstr_w(colinfo
[n
].colname
),
957 id
, colinfo
[n
].type
, colinfo
[n
].offset
, i
);
958 if( n
!= (colinfo
[n
].number
-1) )
960 ERR("oops. data in the _Columns table isn't in the right "
961 "order for table %s\n", debugstr_w(szTableName
));
962 return ERROR_FUNCTION_FAILED
;
966 if( colinfo
&& ( n
>= maxcount
) )
971 return ERROR_SUCCESS
;
974 /* try to find the table name in the _Tables table */
975 BOOL
TABLE_Exists( MSIDATABASE
*db
, LPWSTR name
)
977 UINT r
, table_id
= 0, i
, count
;
978 MSITABLE
*table
= NULL
;
980 if( !lstrcmpW( name
, szTables
) )
982 if( !lstrcmpW( name
, szColumns
) )
985 r
= msi_string2idW( db
->strings
, name
, &table_id
);
986 if( r
!= ERROR_SUCCESS
)
988 TRACE("Couldn't find id for %s\n", debugstr_w(name
));
992 table
= get_table( db
, szTables
, _Tables_cols
, 1 );
995 TRACE("table %s not available\n", debugstr_w(szTables
));
999 /* count = table->size/2; */
1000 count
= table
->row_count
;
1001 for( i
=0; i
<count
; i
++ )
1002 if( table
->data
[ i
][ 0 ] == table_id
)
1008 TRACE("Searched %d tables, but %d was not found\n", count
, table_id
);
1013 /* below is the query interface to a table */
1015 typedef struct tagMSITABLEVIEW
1020 MSICOLUMNINFO
*columns
;
1026 static UINT
TABLE_fetch_int( struct tagMSIVIEW
*view
, UINT row
, UINT col
, UINT
*val
)
1028 MSITABLEVIEW
*tv
= (MSITABLEVIEW
*)view
;
1029 UINT offset
, num_rows
, n
;
1032 return ERROR_INVALID_PARAMETER
;
1034 if( (col
==0) || (col
>tv
->num_cols
) )
1035 return ERROR_INVALID_PARAMETER
;
1037 /* how many rows are there ? */
1038 num_rows
= tv
->table
->row_count
;
1039 if( row
>= num_rows
)
1040 return ERROR_NO_MORE_ITEMS
;
1042 if( tv
->columns
[col
-1].offset
>= tv
->row_size
)
1044 ERR("Stuffed up %d >= %d\n", tv
->columns
[col
-1].offset
, tv
->row_size
);
1045 ERR("%p %p\n", tv
, tv
->columns
);
1046 return ERROR_FUNCTION_FAILED
;
1049 offset
= row
+ (tv
->columns
[col
-1].offset
/2) * num_rows
;
1050 n
= bytes_per_column( &tv
->columns
[col
-1] );
1054 offset
= tv
->columns
[col
-1].offset
/2;
1055 *val
= tv
->table
->data
[row
][offset
] +
1056 (tv
->table
->data
[row
][offset
+ 1] << 16);
1059 offset
= tv
->columns
[col
-1].offset
/2;
1060 *val
= tv
->table
->data
[row
][offset
];
1063 ERR("oops! what is %d bytes per column?\n", n
);
1064 return ERROR_FUNCTION_FAILED
;
1067 /* TRACE("Data [%d][%d] = %d\n", row, col, *val ); */
1069 return ERROR_SUCCESS
;
1073 * We need a special case for streams, as we need to reference column with
1074 * the name of the stream in the same table, and the table name
1075 * which may not be available at higher levels of the query
1077 static UINT
TABLE_fetch_stream( struct tagMSIVIEW
*view
, UINT row
, UINT col
, IStream
**stm
)
1079 MSITABLEVIEW
*tv
= (MSITABLEVIEW
*)view
;
1080 UINT ival
= 0, refcol
= 0, r
;
1084 static const WCHAR szDot
[] = { '.', 0 };
1086 if( !view
->ops
->fetch_int
)
1087 return ERROR_INVALID_PARAMETER
;
1090 * The column marked with the type stream data seems to have a single number
1091 * which references the column containing the name of the stream data
1093 * Fetch the column to reference first.
1095 r
= view
->ops
->fetch_int( view
, row
, col
, &ival
);
1096 if( r
!= ERROR_SUCCESS
)
1099 /* now get the column with the name of the stream */
1100 r
= view
->ops
->fetch_int( view
, row
, ival
, &refcol
);
1101 if( r
!= ERROR_SUCCESS
)
1104 /* lookup the string value from the string table */
1105 sval
= MSI_makestring( tv
->db
, refcol
);
1107 return ERROR_INVALID_PARAMETER
;
1109 len
= lstrlenW( tv
->name
) + 2 + lstrlenW( sval
);
1110 full_name
= msi_alloc( len
*sizeof(WCHAR
) );
1111 lstrcpyW( full_name
, tv
->name
);
1112 lstrcatW( full_name
, szDot
);
1113 lstrcatW( full_name
, sval
);
1115 r
= db_get_raw_stream( tv
->db
, full_name
, stm
);
1117 ERR("fetching stream %s, error = %d\n",debugstr_w(full_name
), r
);
1118 msi_free( full_name
);
1124 static UINT
TABLE_set_int( struct tagMSIVIEW
*view
, UINT row
, UINT col
, UINT val
)
1126 MSITABLEVIEW
*tv
= (MSITABLEVIEW
*)view
;
1130 return ERROR_INVALID_PARAMETER
;
1132 if( (col
==0) || (col
>tv
->num_cols
) )
1133 return ERROR_INVALID_PARAMETER
;
1135 if( tv
->columns
[col
-1].offset
>= tv
->row_size
)
1137 ERR("Stuffed up %d >= %d\n", tv
->columns
[col
-1].offset
, tv
->row_size
);
1138 ERR("%p %p\n", tv
, tv
->columns
);
1139 return ERROR_FUNCTION_FAILED
;
1142 n
= bytes_per_column( &tv
->columns
[col
-1] );
1146 offset
= tv
->columns
[col
-1].offset
/2;
1147 tv
->table
->data
[row
][offset
] = val
& 0xffff;
1148 tv
->table
->data
[row
][offset
+ 1] = (val
>>16)&0xffff;
1151 offset
= tv
->columns
[col
-1].offset
/2;
1152 tv
->table
->data
[row
][offset
] = val
;
1155 ERR("oops! what is %d bytes per column?\n", n
);
1156 return ERROR_FUNCTION_FAILED
;
1158 return ERROR_SUCCESS
;
1161 static UINT
table_create_new_row( struct tagMSIVIEW
*view
, UINT
*num
)
1163 MSITABLEVIEW
*tv
= (MSITABLEVIEW
*)view
;
1167 TRACE("%p\n", view
);
1170 return ERROR_INVALID_PARAMETER
;
1172 row
= msi_alloc_zero( tv
->row_size
);
1174 return ERROR_NOT_ENOUGH_MEMORY
;
1176 sz
= (tv
->table
->row_count
+ 1) * sizeof (UINT
*);
1177 if( tv
->table
->data
)
1178 p
= msi_realloc( tv
->table
->data
, sz
);
1180 p
= msi_alloc( sz
);
1184 return ERROR_NOT_ENOUGH_MEMORY
;
1187 tv
->table
->data
= p
;
1188 tv
->table
->data
[tv
->table
->row_count
] = row
;
1189 *num
= tv
->table
->row_count
;
1190 tv
->table
->row_count
++;
1192 return ERROR_SUCCESS
;
1195 static UINT
TABLE_execute( struct tagMSIVIEW
*view
, MSIRECORD
*record
)
1197 MSITABLEVIEW
*tv
= (MSITABLEVIEW
*)view
;
1199 TRACE("%p %p\n", tv
, record
);
1201 TRACE("There are %d columns\n", tv
->num_cols
);
1202 tv
->table
= get_table( tv
->db
, tv
->name
, tv
->columns
, tv
->num_cols
);
1204 return ERROR_FUNCTION_FAILED
;
1206 return ERROR_SUCCESS
;
1209 static UINT
TABLE_close( struct tagMSIVIEW
*view
)
1211 MSITABLEVIEW
*tv
= (MSITABLEVIEW
*)view
;
1213 TRACE("%p\n", view
);
1216 return ERROR_FUNCTION_FAILED
;
1220 return ERROR_SUCCESS
;
1223 static UINT
TABLE_get_dimensions( struct tagMSIVIEW
*view
, UINT
*rows
, UINT
*cols
)
1225 MSITABLEVIEW
*tv
= (MSITABLEVIEW
*)view
;
1227 TRACE("%p %p %p\n", view
, rows
, cols
);
1230 *cols
= tv
->num_cols
;
1234 return ERROR_INVALID_PARAMETER
;
1235 *rows
= tv
->table
->row_count
;
1238 return ERROR_SUCCESS
;
1241 static UINT
TABLE_get_column_info( struct tagMSIVIEW
*view
,
1242 UINT n
, LPWSTR
*name
, UINT
*type
)
1244 MSITABLEVIEW
*tv
= (MSITABLEVIEW
*)view
;
1246 TRACE("%p %d %p %p\n", tv
, n
, name
, type
);
1248 if( ( n
== 0 ) || ( n
> tv
->num_cols
) )
1249 return ERROR_INVALID_PARAMETER
;
1253 *name
= strdupW( tv
->columns
[n
-1].colname
);
1255 return ERROR_FUNCTION_FAILED
;
1258 *type
= tv
->columns
[n
-1].type
;
1260 return ERROR_SUCCESS
;
1263 static UINT
msi_table_find_row( MSITABLEVIEW
*tv
, MSIRECORD
*rec
, UINT
*row
);
1265 static UINT
table_validate_new( MSITABLEVIEW
*tv
, MSIRECORD
*rec
)
1269 r
= msi_table_find_row( tv
, rec
, &row
);
1270 if (r
!= ERROR_SUCCESS
)
1271 return ERROR_SUCCESS
;
1272 return ERROR_INVALID_DATA
;
1275 static UINT
msi_table_modify_row( MSITABLEVIEW
*tv
, MSIRECORD
*rec
,
1276 UINT row
, UINT mask
)
1278 UINT i
, val
, r
= ERROR_SUCCESS
;
1280 TRACE("%p %p %u %08x\n", tv
, rec
, row
, mask
);
1282 for( i
= 0; i
< tv
->num_cols
; i
++ )
1284 /* set keys or values specified in the mask */
1285 if( (~tv
->columns
[i
].type
& MSITYPE_KEY
) && (~mask
& (1<<i
)) )
1288 if( (tv
->columns
[i
].type
& MSITYPE_STRING
) &&
1289 ! MSITYPE_IS_BINARY(tv
->columns
[i
].type
) )
1291 const WCHAR
*str
= MSI_RecordGetString( rec
, i
+1 );
1292 val
= msi_addstringW( tv
->db
->strings
, 0, str
, -1, 1 );
1296 val
= MSI_RecordGetInteger( rec
, i
+1 );
1297 if ( 2 == bytes_per_column( &tv
->columns
[i
] ) )
1300 r
= TABLE_set_int( &tv
->view
, row
, i
+1, val
);
1308 static UINT
TABLE_insert_row( struct tagMSIVIEW
*view
, MSIRECORD
*rec
)
1310 MSITABLEVIEW
*tv
= (MSITABLEVIEW
*)view
;
1313 TRACE("%p %p\n", tv
, rec
);
1315 r
= table_create_new_row( view
, &row
);
1316 TRACE("insert_row returned %08x\n", r
);
1317 if( r
!= ERROR_SUCCESS
)
1320 return msi_table_modify_row( tv
, rec
, row
, ~0 );
1323 static UINT
TABLE_modify( struct tagMSIVIEW
*view
, MSIMODIFY eModifyMode
,
1326 MSITABLEVIEW
*tv
= (MSITABLEVIEW
*)view
;
1329 TRACE("%p %d %p\n", view
, eModifyMode
, rec
);
1333 r
= TABLE_execute( view
, NULL
);
1338 switch (eModifyMode
)
1340 case MSIMODIFY_VALIDATE_NEW
:
1341 r
= table_validate_new( tv
, rec
);
1344 case MSIMODIFY_INSERT_TEMPORARY
:
1345 r
= table_validate_new( tv
, rec
);
1346 if (r
!= ERROR_SUCCESS
)
1348 r
= TABLE_insert_row( view
, rec
);
1351 case MSIMODIFY_REFRESH
:
1352 case MSIMODIFY_INSERT
:
1353 case MSIMODIFY_UPDATE
:
1354 case MSIMODIFY_ASSIGN
:
1355 case MSIMODIFY_REPLACE
:
1356 case MSIMODIFY_MERGE
:
1357 case MSIMODIFY_DELETE
:
1358 case MSIMODIFY_VALIDATE
:
1359 case MSIMODIFY_VALIDATE_FIELD
:
1360 case MSIMODIFY_VALIDATE_DELETE
:
1361 FIXME("%p %d %p - mode not implemented\n", view
, eModifyMode
, rec
);
1362 r
= ERROR_CALL_NOT_IMPLEMENTED
;
1366 r
= ERROR_INVALID_DATA
;
1372 static UINT
TABLE_delete( struct tagMSIVIEW
*view
)
1374 MSITABLEVIEW
*tv
= (MSITABLEVIEW
*)view
;
1376 TRACE("%p\n", view
);
1382 msi_free_colinfo( tv
->columns
, tv
->num_cols
);
1383 msi_free( tv
->columns
);
1389 return ERROR_SUCCESS
;
1393 MSIVIEWOPS table_ops
=
1401 TABLE_get_dimensions
,
1402 TABLE_get_column_info
,
1407 UINT
TABLE_CreateView( MSIDATABASE
*db
, LPCWSTR name
, MSIVIEW
**view
)
1410 UINT r
, sz
, column_count
;
1411 MSICOLUMNINFO
*columns
;
1413 TRACE("%p %s %p\n", db
, debugstr_w(name
), view
);
1415 /* get the number of columns in this table */
1417 r
= get_tablecolumns( db
, name
, NULL
, &column_count
);
1418 if( r
!= ERROR_SUCCESS
)
1421 /* if there's no columns, there's no table */
1422 if( column_count
== 0 )
1423 return ERROR_INVALID_PARAMETER
;
1425 TRACE("Table found\n");
1427 sz
= sizeof *tv
+ lstrlenW(name
)*sizeof name
[0] ;
1428 tv
= msi_alloc_zero( sz
);
1430 return ERROR_FUNCTION_FAILED
;
1432 columns
= msi_alloc( column_count
*sizeof (MSICOLUMNINFO
));
1436 return ERROR_FUNCTION_FAILED
;
1439 r
= get_tablecolumns( db
, name
, columns
, &column_count
);
1440 if( r
!= ERROR_SUCCESS
)
1442 msi_free( columns
);
1444 return ERROR_FUNCTION_FAILED
;
1447 TRACE("Table has %d columns\n", column_count
);
1449 /* fill the structure */
1450 tv
->view
.ops
= &table_ops
;
1452 tv
->columns
= columns
;
1453 tv
->num_cols
= column_count
;
1455 tv
->row_size
= msi_table_get_row_size( columns
, column_count
);
1457 TRACE("%s one row is %d bytes\n", debugstr_w(name
), tv
->row_size
);
1459 *view
= (MSIVIEW
*) tv
;
1460 lstrcpyW( tv
->name
, name
);
1462 return ERROR_SUCCESS
;
1465 UINT
MSI_CommitTables( MSIDATABASE
*db
)
1468 MSITABLE
*table
= NULL
;
1472 r
= save_string_table( db
);
1473 if( r
!= ERROR_SUCCESS
)
1475 WARN("failed to save string table r=%08x\n",r
);
1479 LIST_FOR_EACH_ENTRY( table
, &db
->tables
, MSITABLE
, entry
)
1481 r
= save_table( db
, table
);
1482 if( r
!= ERROR_SUCCESS
)
1484 WARN("failed to save table %s (r=%08x)\n",
1485 debugstr_w(table
->name
), r
);
1490 /* force everything to reload next time */
1491 free_cached_tables( db
);
1493 return ERROR_SUCCESS
;
1496 static MSIRECORD
*msi_get_transform_record( MSITABLEVIEW
*tv
, string_table
*st
, USHORT
*rawdata
)
1498 UINT i
, val
, ofs
= 0;
1499 USHORT mask
= *rawdata
++;
1500 MSICOLUMNINFO
*columns
= tv
->columns
;
1502 const int debug_transform
= 0;
1504 rec
= MSI_CreateRecord( tv
->num_cols
);
1508 if( debug_transform
) MESSAGE("row -> ");
1509 for( i
=0; i
<tv
->num_cols
; i
++ )
1511 UINT n
= bytes_per_column( &columns
[i
] );
1513 if ( (mask
&1) && (i
>=(mask
>>8)) )
1515 /* all keys must be present */
1516 if ( (~mask
&1) && (~columns
[i
].type
& MSITYPE_KEY
) && ((1<<i
) & ~mask
) )
1523 if( (columns
[i
].type
& MSITYPE_STRING
) &&
1524 ! MSITYPE_IS_BINARY(tv
->columns
[i
].type
) )
1526 LPCWSTR sval
= msi_string_lookup_id( st
, val
);
1527 MSI_RecordSetStringW( rec
, i
+1, sval
);
1528 if( debug_transform
) MESSAGE("[%s]", debugstr_w(sval
));
1533 MSI_RecordSetInteger( rec
, i
+1, val
);
1534 if( debug_transform
) MESSAGE("[0x%04x]", val
);
1538 val
= rawdata
[ofs
] + (rawdata
[ofs
+ 1]<<16);
1539 /* val ^= 0x80000000; */
1540 MSI_RecordSetInteger( rec
, i
+1, val
);
1541 if( debug_transform
) MESSAGE("[0x%08x]", val
);
1544 ERR("oops - unknown column width %d\n", n
);
1549 if( debug_transform
) MESSAGE("\n");
1553 static void dump_record( MSIRECORD
*rec
)
1558 n
= MSI_RecordGetFieldCount( rec
);
1559 for( i
=1; i
<=n
; i
++ )
1561 LPCWSTR sval
= MSI_RecordGetString( rec
, i
);
1563 if( MSI_RecordIsNull( rec
, i
) )
1565 else if( (sval
= MSI_RecordGetString( rec
, i
)) )
1566 MESSAGE("[%s]", debugstr_w(sval
));
1568 MESSAGE("[0x%08x]", MSI_RecordGetInteger( rec
, i
) );
1573 static void dump_table( string_table
*st
, USHORT
*rawdata
, UINT rawsize
)
1578 for( i
=0; i
<(rawsize
/2); i
++ )
1580 sval
= msi_string_lookup_id( st
, rawdata
[i
] );
1581 if( !sval
) sval
= (WCHAR
[]) {0};
1582 MESSAGE(" %04x %s\n", rawdata
[i
], debugstr_w(sval
) );
1586 static UINT
* msi_record_to_row( MSITABLEVIEW
*tv
, MSIRECORD
*rec
)
1591 data
= msi_alloc( tv
->num_cols
*sizeof (UINT
) );
1592 for( i
=0; i
<tv
->num_cols
; i
++ )
1596 if ( ~tv
->columns
[i
].type
& MSITYPE_KEY
)
1599 /* turn the transform column value into a row value */
1600 if ( ( tv
->columns
[i
].type
& MSITYPE_STRING
) &&
1601 ! MSITYPE_IS_BINARY(tv
->columns
[i
].type
) )
1603 str
= MSI_RecordGetString( rec
, i
+1 );
1604 r
= msi_string2idW( tv
->db
->strings
, str
, &data
[i
] );
1606 /* if there's no matching string in the string table,
1607 these keys can't match any record, so fail now. */
1608 if( ERROR_SUCCESS
!= r
)
1615 data
[i
] = MSI_RecordGetInteger( rec
, i
+1 );
1620 static UINT
msi_row_matches( MSITABLEVIEW
*tv
, UINT row
, UINT
*data
)
1622 UINT i
, r
, x
, ret
= ERROR_FUNCTION_FAILED
;
1624 for( i
=0; i
<tv
->num_cols
; i
++ )
1626 if ( ~tv
->columns
[i
].type
& MSITYPE_KEY
)
1629 /* turn the transform column value into a row value */
1630 r
= TABLE_fetch_int( &tv
->view
, row
, i
+1, &x
);
1631 if ( r
!= ERROR_SUCCESS
)
1633 ERR("TABLE_fetch_int shouldn't fail here\n");
1637 /* if this key matches, move to the next column */
1640 ret
= ERROR_FUNCTION_FAILED
;
1644 ret
= ERROR_SUCCESS
;
1650 static UINT
msi_table_find_row( MSITABLEVIEW
*tv
, MSIRECORD
*rec
, UINT
*row
)
1652 UINT i
, r
= ERROR_FUNCTION_FAILED
, *data
;
1654 data
= msi_record_to_row( tv
, rec
);
1657 for( i
=0; i
<tv
->table
->row_count
; i
++ )
1659 r
= msi_row_matches( tv
, i
, data
);
1660 if( r
== ERROR_SUCCESS
)
1670 static UINT
msi_delete_row( MSITABLEVIEW
*tv
, UINT row
)
1673 for( i
=1; i
<=tv
->num_cols
; i
++ )
1674 tv
->view
.ops
->set_int( &tv
->view
, row
, i
, 0 );
1675 return ERROR_SUCCESS
;
1678 static UINT
msi_table_load_transform( MSIDATABASE
*db
, IStorage
*stg
,
1679 string_table
*st
, LPCWSTR name
)
1682 USHORT
*rawdata
= NULL
;
1683 MSITABLEVIEW
*tv
= NULL
;
1684 UINT r
, n
, sz
, i
, mask
;
1685 MSIRECORD
*rec
= NULL
;
1686 const int debug_transform
= 0;
1688 TRACE("%p %p %p %s\n", db
, stg
, st
, debugstr_w(name
) );
1690 /* create a table view */
1691 r
= TABLE_CreateView( db
, name
, (MSIVIEW
**) &tv
);
1692 if( r
!= ERROR_SUCCESS
)
1695 r
= tv
->view
.ops
->execute( &tv
->view
, NULL
);
1696 if( r
!= ERROR_SUCCESS
)
1699 /* read the transform data */
1700 r
= ERROR_FUNCTION_FAILED
;
1701 read_stream_data( stg
, name
, &rawdata
, &rawsize
);
1702 if( !rawdata
|| (rawsize
< 2) )
1704 ERR("odd sized transform for table %s\n", debugstr_w(name
));
1708 TRACE("name = %s columns = %u row_size = %u raw size = %u\n",
1709 debugstr_w(name
), tv
->num_cols
, tv
->row_size
, rawsize
);
1711 /* interpret the data */
1713 for( n
=0; n
< (rawsize
/2); )
1720 * if the low bit is set, columns are continuous and
1721 * the number of columns is specified in the high byte
1723 sz
= 2 + tv
->row_size
;
1728 * If the low bit is not set, rowdata[n] is a bitmask.
1729 * Excepting for key fields, which are always present,
1730 * each bit indicates that a field is present in the transform record.
1732 * rawdata[n] == 0 is a special case ... only the keys will be present
1733 * and it means that this row should be deleted.
1736 for( i
=0; i
<tv
->num_cols
; i
++ )
1738 if( (tv
->columns
[i
].type
& MSITYPE_KEY
) || ((1<<i
)&mask
))
1739 sz
+= bytes_per_column( &tv
->columns
[i
] );
1743 /* check we didn't run of the end of the table */
1744 if ( (n
+sz
) > rawsize
)
1747 dump_table( st
, rawdata
, rawsize
);
1751 rec
= msi_get_transform_record( tv
, st
, &rawdata
[n
] );
1756 r
= msi_table_find_row( tv
, rec
, &row
);
1760 if( debug_transform
) MESSAGE("insert [%d]: ", row
);
1761 TABLE_insert_row( &tv
->view
, rec
);
1763 else if( mask
& 0xff )
1765 if( debug_transform
) MESSAGE("modify [%d]: ", row
);
1766 msi_table_modify_row( tv
, rec
, row
, mask
);
1770 if( debug_transform
) MESSAGE("delete [%d]: ", row
);
1771 msi_delete_row( tv
, row
);
1773 if( debug_transform
) dump_record( rec
);
1774 msiobj_release( &rec
->hdr
);
1782 /* no need to free the table, it's associated with the database */
1783 msi_free( rawdata
);
1785 tv
->view
.ops
->delete( &tv
->view
);
1787 return ERROR_SUCCESS
;
1791 * msi_table_apply_transform
1793 * Enumerate the table transforms in a transform storage and apply each one.
1795 UINT
msi_table_apply_transform( MSIDATABASE
*db
, IStorage
*stg
)
1797 IEnumSTATSTG
*stgenum
= NULL
;
1802 string_table
*strings
;
1803 UINT ret
= ERROR_FUNCTION_FAILED
;
1805 TRACE("%p %p\n", db
, stg
);
1807 strings
= load_string_table( stg
);
1811 r
= IStorage_EnumElements( stg
, 0, NULL
, 0, &stgenum
);
1816 ret
= ERROR_SUCCESS
;
1818 while( r
== ERROR_SUCCESS
)
1821 r
= IEnumSTATSTG_Next( stgenum
, 1, &stat
, &count
);
1822 if( FAILED( r
) || !count
)
1824 decode_streamname( stat
.pwcsName
, name
);
1825 if( ( name
[0] == 0x4840 ) && ( name
[1] != '_' ) )
1826 ret
= msi_table_load_transform( db
, stg
, strings
, name
+1 );
1828 TRACE("transform contains stream %s\n", debugstr_w(name
));
1832 if ( ret
== ERROR_SUCCESS
)
1836 t
= msi_alloc( sizeof *t
);
1838 IStorage_AddRef( stg
);
1839 list_add_tail( &db
->transforms
, &t
->entry
);
1844 IEnumSTATSTG_Release( stgenum
);
1846 msi_destroy_stringtable( strings
);
1851 void msi_free_transforms( MSIDATABASE
*db
)
1853 while( !list_empty( &db
->transforms
) )
1855 MSITRANSFORM
*t
= LIST_ENTRY( list_head( &db
->transforms
),
1856 MSITRANSFORM
, entry
);
1857 list_remove( &t
->entry
);
1858 IStorage_Release( t
->stg
);