2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 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 tagMSIINSERTVIEW
51 static UINT
INSERT_fetch_int( struct tagMSIVIEW
*view
, UINT row
, UINT col
, UINT
*val
)
53 MSIINSERTVIEW
*iv
= (MSIINSERTVIEW
*)view
;
55 TRACE("%p %d %d %p\n", iv
, row
, col
, val
);
57 return ERROR_FUNCTION_FAILED
;
60 static UINT
INSERT_execute( struct tagMSIVIEW
*view
, MSIHANDLE record
)
63 MSIINSERTVIEW
*iv
= (MSIINSERTVIEW
*)view
;
65 UINT r
, nField
, row
, table_val
, column_val
;
66 static const WCHAR szTables
[] = { '_','T','a','b','l','e','s',0 };
67 static const WCHAR szColumns
[] = { '_','C','o','l','u','m','n','s',0 };
70 TRACE("%p Table %s (%s)\n", iv
, debugstr_w(iv
->name
),
71 iv
->bIsTemp
?"temporary":"permanent");
73 /* only add tables that don't exist already */
74 if( TABLE_Exists(iv
->db
, iv
->name
) )
75 return ERROR_BAD_QUERY_SYNTAX
;
77 /* add the name to the _Tables table */
78 table_val
= msi_addstringW( iv
->db
->strings
, 0, iv
->name
, -1, 1 );
79 TRACE("New string %s -> %d\n", debugstr_w( iv
->name
), table_val
);
81 return ERROR_FUNCTION_FAILED
;
83 r
= TABLE_CreateView( iv
->db
, szTables
, &tv
);
84 TRACE("CreateView returned %x\n", r
);
88 r
= tv
->ops
->execute( tv
, 0 );
89 TRACE("tv execute returned %x\n", r
);
94 r
= tv
->ops
->insert_row( tv
, &row
);
95 TRACE("insert_row returned %x\n", r
);
99 r
= tv
->ops
->set_int( tv
, row
, 1, table_val
);
102 tv
->ops
->delete( tv
);
105 /* add each column to the _Columns table */
106 r
= TABLE_CreateView( iv
->db
, szColumns
, &tv
);
110 r
= tv
->ops
->execute( tv
, 0 );
111 TRACE("tv execute returned %x\n", r
);
116 * need to set the table, column number, col name and type
117 * for each column we enter in the table
120 for( col
= iv
->col_info
; col
; col
= col
->next
)
123 r
= tv
->ops
->insert_row( tv
, &row
);
127 column_val
= msi_addstringW( iv
->db
->strings
, 0, col
->colname
, -1, 1 );
128 TRACE("New string %s -> %d\n", debugstr_w( col
->colname
), column_val
);
132 r
= tv
->ops
->set_int( tv
, row
, 1, table_val
);
136 r
= tv
->ops
->set_int( tv
, row
, 2, 0x8000|nField
);
140 r
= tv
->ops
->set_int( tv
, row
, 3, column_val
);
144 r
= tv
->ops
->set_int( tv
, row
, 4, 0x8000|col
->type
);
152 /* FIXME: remove values from the string table on error */
154 tv
->ops
->delete( tv
);
157 return ERROR_FUNCTION_FAILED
;
161 static UINT
INSERT_close( struct tagMSIVIEW
*view
)
163 MSIINSERTVIEW
*iv
= (MSIINSERTVIEW
*)view
;
167 return ERROR_SUCCESS
;
170 static UINT
INSERT_get_dimensions( struct tagMSIVIEW
*view
, UINT
*rows
, UINT
*cols
)
172 MSIINSERTVIEW
*iv
= (MSIINSERTVIEW
*)view
;
174 TRACE("%p %p %p\n", iv
, rows
, cols
);
176 return ERROR_FUNCTION_FAILED
;
179 static UINT
INSERT_get_column_info( struct tagMSIVIEW
*view
,
180 UINT n
, LPWSTR
*name
, UINT
*type
)
182 MSIINSERTVIEW
*iv
= (MSIINSERTVIEW
*)view
;
184 TRACE("%p %d %p %p\n", iv
, n
, name
, type
);
186 return ERROR_FUNCTION_FAILED
;
189 static UINT
INSERT_modify( struct tagMSIVIEW
*view
, MSIMODIFY eModifyMode
, MSIHANDLE hrec
)
191 MSIINSERTVIEW
*iv
= (MSIINSERTVIEW
*)view
;
193 TRACE("%p %d %ld\n", iv
, eModifyMode
, hrec
);
195 return ERROR_FUNCTION_FAILED
;
198 static UINT
INSERT_delete( struct tagMSIVIEW
*view
)
200 MSIINSERTVIEW
*iv
= (MSIINSERTVIEW
*)view
;
204 delete_string_list( iv
->cols
);
205 delete_value_list( iv
->vals
);
206 HeapFree( GetProcessHeap(), 0, iv
->name
);
207 HeapFree( GetProcessHeap(), 0, iv
);
209 return ERROR_SUCCESS
;
213 MSIVIEWOPS insert_ops
=
220 INSERT_get_dimensions
,
221 INSERT_get_column_info
,
226 UINT
INSERT_CreateView( MSIDATABASE
*db
, MSIVIEW
**view
, LPWSTR table
,
227 string_list
*columns
, value_list
*values
, BOOL temp
)
229 MSIINSERTVIEW
*iv
= NULL
;
233 iv
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof *iv
);
235 return ERROR_FUNCTION_FAILED
;
237 /* fill the structure */
238 iv
->view
.ops
= &insert_ops
;
240 iv
->name
= table
; /* FIXME: strdupW it? */
244 *view
= (MSIVIEW
*) iv
;
246 return ERROR_SUCCESS
;