2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002-2004 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
26 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
39 /* below is the query interface to a table */
41 typedef struct tagMSISELECTVIEW
51 static UINT
SELECT_fetch_int( struct tagMSIVIEW
*view
, UINT row
, UINT col
, UINT
*val
)
53 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
55 TRACE("%p %d %d %p\n", sv
, row
, col
, val
);
58 return ERROR_FUNCTION_FAILED
;
60 if( (col
==0) || (col
>sv
->num_cols
) )
61 return ERROR_FUNCTION_FAILED
;
63 col
= sv
->cols
[ col
- 1 ];
65 return sv
->table
->ops
->fetch_int( sv
->table
, row
, col
, val
);
68 static UINT
SELECT_fetch_stream( struct tagMSIVIEW
*view
, UINT row
, UINT col
, IStream
**stm
)
70 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
72 TRACE("%p %d %d %p\n", sv
, row
, col
, stm
);
75 return ERROR_FUNCTION_FAILED
;
77 if( (col
==0) || (col
>sv
->num_cols
) )
78 return ERROR_FUNCTION_FAILED
;
80 col
= sv
->cols
[ col
- 1 ];
82 return sv
->table
->ops
->fetch_stream( sv
->table
, row
, col
, stm
);
85 static UINT
SELECT_set_int( struct tagMSIVIEW
*view
, UINT row
, UINT col
, UINT val
)
87 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
89 TRACE("%p %d %d %04x\n", sv
, row
, col
, val
);
92 return ERROR_FUNCTION_FAILED
;
94 if( (col
==0) || (col
>sv
->num_cols
) )
95 return ERROR_FUNCTION_FAILED
;
97 col
= sv
->cols
[ col
- 1 ];
99 return sv
->table
->ops
->set_int( sv
->table
, row
, col
, val
);
102 static UINT
SELECT_insert_row( struct tagMSIVIEW
*view
, MSIRECORD
*record
)
104 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
106 TRACE("%p %p\n", sv
, record
);
109 return ERROR_FUNCTION_FAILED
;
111 return sv
->table
->ops
->insert_row( sv
->table
, record
);
114 static UINT
SELECT_execute( struct tagMSIVIEW
*view
, MSIRECORD
*record
)
116 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
118 TRACE("%p %p\n", sv
, record
);
121 return ERROR_FUNCTION_FAILED
;
123 return sv
->table
->ops
->execute( sv
->table
, record
);
126 static UINT
SELECT_close( struct tagMSIVIEW
*view
)
128 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
133 return ERROR_FUNCTION_FAILED
;
135 return sv
->table
->ops
->close( sv
->table
);
138 static UINT
SELECT_get_dimensions( struct tagMSIVIEW
*view
, UINT
*rows
, UINT
*cols
)
140 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
142 TRACE("%p %p %p\n", sv
, rows
, cols
);
145 return ERROR_FUNCTION_FAILED
;
148 *cols
= sv
->num_cols
;
150 return sv
->table
->ops
->get_dimensions( sv
->table
, rows
, NULL
);
153 static UINT
SELECT_get_column_info( struct tagMSIVIEW
*view
,
154 UINT n
, LPWSTR
*name
, UINT
*type
)
156 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
158 TRACE("%p %d %p %p\n", sv
, n
, name
, type
);
161 return ERROR_FUNCTION_FAILED
;
163 if( (n
==0) || (n
>sv
->num_cols
) )
164 return ERROR_FUNCTION_FAILED
;
166 n
= sv
->cols
[ n
- 1 ];
168 return sv
->table
->ops
->get_column_info( sv
->table
, n
, name
, type
);
171 static UINT
SELECT_modify( struct tagMSIVIEW
*view
, MSIMODIFY eModifyMode
,
174 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
176 TRACE("%p %d %p\n", sv
, eModifyMode
, rec
);
179 return ERROR_FUNCTION_FAILED
;
181 return sv
->table
->ops
->modify( sv
->table
, eModifyMode
, rec
);
184 static UINT
SELECT_delete( struct tagMSIVIEW
*view
)
186 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
191 sv
->table
->ops
->delete( sv
->table
);
196 return ERROR_SUCCESS
;
200 MSIVIEWOPS select_ops
=
208 SELECT_get_dimensions
,
209 SELECT_get_column_info
,
214 static UINT
SELECT_AddColumn( MSISELECTVIEW
*sv
, LPCWSTR name
)
219 TRACE("%p adding %s\n", sv
, debugstr_w( name
) );
221 if( sv
->view
.ops
!= &select_ops
)
222 return ERROR_FUNCTION_FAILED
;
226 return ERROR_FUNCTION_FAILED
;
227 if( !table
->ops
->get_dimensions
)
228 return ERROR_FUNCTION_FAILED
;
229 if( !table
->ops
->get_column_info
)
230 return ERROR_FUNCTION_FAILED
;
232 if( sv
->num_cols
>= sv
->max_cols
)
233 return ERROR_FUNCTION_FAILED
;
235 r
= VIEW_find_column( table
, name
, &n
);
236 if( r
!= ERROR_SUCCESS
)
239 sv
->cols
[sv
->num_cols
] = n
;
240 TRACE("Translating column %s from %d -> %d\n",
241 debugstr_w( name
), sv
->num_cols
, n
);
245 return ERROR_SUCCESS
;
248 UINT
SELECT_CreateView( MSIDATABASE
*db
, MSIVIEW
**view
, MSIVIEW
*table
,
249 column_info
*columns
)
251 MSISELECTVIEW
*sv
= NULL
;
256 r
= table
->ops
->get_dimensions( table
, NULL
, &count
);
257 if( r
!= ERROR_SUCCESS
)
259 ERR("can't get table dimensions\n");
263 sv
= msi_alloc_zero( sizeof *sv
+ count
*sizeof (UINT
) );
265 return ERROR_FUNCTION_FAILED
;
267 /* fill the structure */
268 sv
->view
.ops
= &select_ops
;
272 sv
->max_cols
= count
;
276 r
= SELECT_AddColumn( sv
, columns
->column
);
279 columns
= columns
->next
;
282 if( r
== ERROR_SUCCESS
)