2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2006 Mike McCormack
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(msidb
);
37 typedef struct tagMSIALTERVIEW
46 static UINT
ALTER_fetch_int( struct tagMSIVIEW
*view
, UINT row
, UINT col
, UINT
*val
)
48 MSIALTERVIEW
*av
= (MSIALTERVIEW
*)view
;
50 TRACE("%p %d %d %p\n", av
, row
, col
, val
);
52 return ERROR_FUNCTION_FAILED
;
55 static UINT
ALTER_fetch_stream( struct tagMSIVIEW
*view
, UINT row
, UINT col
, IStream
**stm
)
57 MSIALTERVIEW
*av
= (MSIALTERVIEW
*)view
;
59 TRACE("%p %d %d %p\n", av
, row
, col
, stm
);
61 return ERROR_FUNCTION_FAILED
;
64 static UINT
ITERATE_columns(MSIRECORD
*row
, LPVOID param
)
70 static BOOL
check_column_exists(MSIDATABASE
*db
, MSIVIEW
*columns
, LPCWSTR table
, LPCWSTR column
)
76 static const WCHAR query
[] = {
77 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
78 '`','_','C','o','l','u','m','n','s','`',' ','W','H','E','R','E',' ',
79 '`','T','a','b','l','e','`','=','\'','%','s','\'',' ','A','N','D',' ',
80 '`','N','a','m','e','`','=','\'','%','s','\'',0
83 r
= MSI_OpenQuery(db
, &view
, query
, table
, column
);
84 if (r
!= ERROR_SUCCESS
)
87 r
= MSI_ViewExecute(view
, NULL
);
88 if (r
!= ERROR_SUCCESS
)
91 r
= MSI_ViewFetch(view
, &rec
);
92 if (r
== ERROR_SUCCESS
)
93 msiobj_release(&rec
->hdr
);
96 msiobj_release(&view
->hdr
);
97 return (r
== ERROR_SUCCESS
);
100 static UINT
alter_add_column(MSIALTERVIEW
*av
)
106 static const WCHAR szColumns
[] = {'_','C','o','l','u','m','n','s',0};
107 static const WCHAR query
[] = {
108 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
109 '`','_','C','o','l','u','m','n','s','`',' ','W','H','E','R','E',' ',
110 '`','T','a','b','l','e','`','=','\'','%','s','\'',' ','O','R','D','E','R',' ',
111 'B','Y',' ','`','N','u','m','b','e','r','`',0
114 r
= TABLE_CreateView(av
->db
, szColumns
, &columns
);
115 if (r
!= ERROR_SUCCESS
)
118 if (check_column_exists(av
->db
, columns
, av
->colinfo
->table
, av
->colinfo
->column
))
119 return ERROR_BAD_QUERY_SYNTAX
;
121 r
= MSI_OpenQuery(av
->db
, &view
, query
, av
->colinfo
->table
, av
->colinfo
->column
);
122 if (r
== ERROR_SUCCESS
)
124 r
= MSI_IterateRecords(view
, NULL
, ITERATE_columns
, &colnum
);
125 msiobj_release(&view
->hdr
);
128 r
= columns
->ops
->add_column(columns
, av
->colinfo
->table
,
129 colnum
, av
->colinfo
->column
,
130 av
->colinfo
->type
, (av
->hold
== 1));
132 msiobj_release(&columns
->hdr
);
136 static UINT
ALTER_execute( struct tagMSIVIEW
*view
, MSIRECORD
*record
)
138 MSIALTERVIEW
*av
= (MSIALTERVIEW
*)view
;
140 TRACE("%p %p\n", av
, record
);
143 av
->table
->ops
->add_ref(av
->table
);
144 else if (av
->hold
== -1)
145 av
->table
->ops
->release(av
->table
);
148 return alter_add_column(av
);
150 return ERROR_SUCCESS
;
153 static UINT
ALTER_close( struct tagMSIVIEW
*view
)
155 MSIALTERVIEW
*av
= (MSIALTERVIEW
*)view
;
159 return ERROR_SUCCESS
;
162 static UINT
ALTER_get_dimensions( struct tagMSIVIEW
*view
, UINT
*rows
, UINT
*cols
)
164 MSIALTERVIEW
*av
= (MSIALTERVIEW
*)view
;
166 TRACE("%p %p %p\n", av
, rows
, cols
);
168 return ERROR_FUNCTION_FAILED
;
171 static UINT
ALTER_get_column_info( struct tagMSIVIEW
*view
,
172 UINT n
, LPWSTR
*name
, UINT
*type
)
174 MSIALTERVIEW
*av
= (MSIALTERVIEW
*)view
;
176 TRACE("%p %d %p %p\n", av
, n
, name
, type
);
178 return ERROR_FUNCTION_FAILED
;
181 static UINT
ALTER_modify( struct tagMSIVIEW
*view
, MSIMODIFY eModifyMode
,
184 MSIALTERVIEW
*av
= (MSIALTERVIEW
*)view
;
186 TRACE("%p %d %p\n", av
, eModifyMode
, rec
);
188 return ERROR_FUNCTION_FAILED
;
191 static UINT
ALTER_delete( struct tagMSIVIEW
*view
)
193 MSIALTERVIEW
*av
= (MSIALTERVIEW
*)view
;
197 av
->table
->ops
->delete( av
->table
);
199 return ERROR_SUCCESS
;
202 static UINT
ALTER_find_matching_rows( struct tagMSIVIEW
*view
, UINT col
,
203 UINT val
, UINT
*row
, MSIITERHANDLE
*handle
)
205 TRACE("%p, %d, %u, %p\n", view
, col
, val
, *handle
);
207 return ERROR_FUNCTION_FAILED
;
210 static const MSIVIEWOPS alter_ops
=
219 ALTER_get_dimensions
,
220 ALTER_get_column_info
,
223 ALTER_find_matching_rows
,
230 UINT
ALTER_CreateView( MSIDATABASE
*db
, MSIVIEW
**view
, LPCWSTR name
, column_info
*colinfo
, int hold
)
235 TRACE("%p %p %s %d\n", view
, colinfo
, debugstr_w(name
), hold
);
237 av
= msi_alloc_zero( sizeof *av
);
239 return ERROR_FUNCTION_FAILED
;
241 r
= TABLE_CreateView( db
, name
, &av
->table
);
242 if (r
!= ERROR_SUCCESS
|| !av
->table
)
246 colinfo
->table
= name
;
248 /* fill the structure */
249 av
->view
.ops
= &alter_ops
;
252 av
->colinfo
= colinfo
;
256 return ERROR_SUCCESS
;