2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2002 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_execute( struct tagMSIVIEW
*view
, MSIHANDLE record
)
70 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
72 TRACE("%p %ld\n", sv
, record
);
75 return ERROR_FUNCTION_FAILED
;
77 return sv
->table
->ops
->execute( sv
->table
, record
);
80 static UINT
SELECT_close( struct tagMSIVIEW
*view
)
82 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
87 return ERROR_FUNCTION_FAILED
;
89 return sv
->table
->ops
->close( sv
->table
);
92 static UINT
SELECT_get_dimensions( struct tagMSIVIEW
*view
, UINT
*rows
, UINT
*cols
)
94 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
96 TRACE("%p %p %p\n", sv
, rows
, cols
);
99 return ERROR_FUNCTION_FAILED
;
102 *cols
= sv
->num_cols
;
104 return sv
->table
->ops
->get_dimensions( sv
->table
, rows
, NULL
);
107 static UINT
SELECT_get_column_info( struct tagMSIVIEW
*view
,
108 UINT n
, LPWSTR
*name
, UINT
*type
)
110 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
112 TRACE("%p %d %p %p\n", sv
, n
, name
, type
);
115 return ERROR_FUNCTION_FAILED
;
117 if( (n
==0) || (n
>sv
->num_cols
) )
118 return ERROR_FUNCTION_FAILED
;
120 n
= sv
->cols
[ n
- 1 ];
122 return sv
->table
->ops
->get_column_info( sv
->table
, n
, name
, type
);
125 static UINT
SELECT_modify( struct tagMSIVIEW
*view
, MSIMODIFY eModifyMode
, MSIHANDLE hrec
)
127 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
129 TRACE("%p %d %ld\n", sv
, eModifyMode
, hrec
);
132 return ERROR_FUNCTION_FAILED
;
134 return sv
->table
->ops
->modify( sv
->table
, eModifyMode
, hrec
);
137 static UINT
SELECT_delete( struct tagMSIVIEW
*view
)
139 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
144 sv
->table
->ops
->delete( sv
->table
);
146 HeapFree( GetProcessHeap(), 0, sv
);
148 return ERROR_SUCCESS
;
152 MSIVIEWOPS select_ops
=
157 SELECT_get_dimensions
,
158 SELECT_get_column_info
,
163 UINT
SELECT_CreateView( MSIDATABASE
*db
, MSIVIEW
**view
, MSIVIEW
*table
)
165 MSISELECTVIEW
*sv
= NULL
;
170 r
= table
->ops
->get_dimensions( table
, NULL
, &count
);
171 if( r
!= ERROR_SUCCESS
)
173 ERR("can't get table dimensions\n");
177 sv
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
178 sizeof *sv
+ count
*sizeof (UINT
) );
180 return ERROR_FUNCTION_FAILED
;
182 /* fill the structure */
183 sv
->view
.ops
= &select_ops
;
187 sv
->max_cols
= count
;
188 *view
= (MSIVIEW
*) sv
;
190 return ERROR_SUCCESS
;
193 UINT
SELECT_AddColumn( MSIVIEW
*view
, LPWSTR name
)
195 MSISELECTVIEW
*sv
= (MSISELECTVIEW
*)view
;
199 TRACE("%p adding %s\n", sv
, debugstr_w( name
) );
201 if( sv
->view
.ops
!= &select_ops
)
202 return ERROR_FUNCTION_FAILED
;
206 return ERROR_FUNCTION_FAILED
;
207 if( !table
->ops
->get_dimensions
)
208 return ERROR_FUNCTION_FAILED
;
209 if( !table
->ops
->get_column_info
)
210 return ERROR_FUNCTION_FAILED
;
212 if( sv
->num_cols
>= sv
->max_cols
)
213 return ERROR_FUNCTION_FAILED
;
215 r
= VIEW_find_column( table
, name
, &n
);
216 if( r
!= ERROR_SUCCESS
)
219 sv
->cols
[sv
->num_cols
] = n
;
220 TRACE("Translating column %s from %d -> %d\n",
221 debugstr_w( name
), sv
->num_cols
, n
);
225 return ERROR_SUCCESS
;