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 =
159 SELECT_get_dimensions,
160 SELECT_get_column_info,
165 UINT SELECT_CreateView( MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table )
167 MSISELECTVIEW *sv = NULL;
172 r = table->ops->get_dimensions( table, NULL, &count );
173 if( r != ERROR_SUCCESS )
175 ERR("can't get table dimensions\n");
179 sv = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
180 sizeof *sv + count*sizeof (UINT) );
182 return ERROR_FUNCTION_FAILED;
184 /* fill the structure */
185 sv->view.ops = &select_ops;
189 sv->max_cols = count;
190 *view = (MSIVIEW*) sv;
192 return ERROR_SUCCESS;
195 UINT SELECT_AddColumn( MSIVIEW *view, LPWSTR name )
197 MSISELECTVIEW *sv = (MSISELECTVIEW*)view;
201 TRACE("%p adding %s\n", sv, debugstr_w( name ) );
203 if( sv->view.ops != &select_ops )
204 return ERROR_FUNCTION_FAILED;
208 return ERROR_FUNCTION_FAILED;
209 if( !table->ops->get_dimensions )
210 return ERROR_FUNCTION_FAILED;
211 if( !table->ops->get_column_info )
212 return ERROR_FUNCTION_FAILED;
214 if( sv->num_cols >= sv->max_cols )
215 return ERROR_FUNCTION_FAILED;
217 r = VIEW_find_column( table, name, &n );
218 if( r != ERROR_SUCCESS )
221 sv->cols[sv->num_cols] = n;
222 TRACE("Translating column %s from %d -> %d\n",
223 debugstr_w( name ), sv->num_cols, n);
227 return ERROR_SUCCESS;