Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / msi / create.c
blob2e13d5925526d19d0dcac384b5c7a98fcc05a849
1 /*
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "wine/debug.h"
27 #include "msi.h"
28 #include "msiquery.h"
29 #include "objbase.h"
30 #include "objidl.h"
31 #include "msipriv.h"
32 #include "winnls.h"
34 #include "query.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msidb);
39 /* below is the query interface to a table */
41 typedef struct tagMSICREATEVIEW
43 MSIVIEW view;
44 MSIDATABASE *db;
45 LPCWSTR name;
46 BOOL bIsTemp;
47 BOOL hold;
48 column_info *col_info;
49 } MSICREATEVIEW;
51 static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
53 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
55 TRACE("%p %d %d %p\n", cv, row, col, val );
57 return ERROR_FUNCTION_FAILED;
60 static UINT CREATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
62 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
63 MSITABLE *table;
64 BOOL persist = (cv->bIsTemp) ? MSICONDITION_FALSE : MSICONDITION_TRUE;
66 TRACE("%p Table %s (%s)\n", cv, debugstr_w(cv->name),
67 cv->bIsTemp?"temporary":"permanent");
69 if (cv->bIsTemp && !cv->hold)
70 return ERROR_SUCCESS;
72 return msi_create_table( cv->db, cv->name, cv->col_info, persist, &table);
75 static UINT CREATE_close( struct tagMSIVIEW *view )
77 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
79 TRACE("%p\n", cv);
81 return ERROR_SUCCESS;
84 static UINT CREATE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
86 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
88 TRACE("%p %p %p\n", cv, rows, cols );
90 return ERROR_FUNCTION_FAILED;
93 static UINT CREATE_get_column_info( struct tagMSIVIEW *view,
94 UINT n, LPWSTR *name, UINT *type, BOOL *temporary,
95 LPWSTR *table_name)
97 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
99 TRACE("%p %d %p %p %p %p\n", cv, n, name, type, temporary, table_name );
101 return ERROR_FUNCTION_FAILED;
104 static UINT CREATE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
105 MSIRECORD *rec, UINT row)
107 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
109 TRACE("%p %d %p\n", cv, eModifyMode, rec );
111 return ERROR_FUNCTION_FAILED;
114 static UINT CREATE_delete( struct tagMSIVIEW *view )
116 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
118 TRACE("%p\n", cv );
120 msiobj_release( &cv->db->hdr );
121 msi_free( cv );
123 return ERROR_SUCCESS;
126 static const MSIVIEWOPS create_ops =
128 CREATE_fetch_int,
129 NULL,
130 NULL,
131 NULL,
132 NULL,
133 NULL,
134 CREATE_execute,
135 CREATE_close,
136 CREATE_get_dimensions,
137 CREATE_get_column_info,
138 CREATE_modify,
139 CREATE_delete,
140 NULL,
141 NULL,
142 NULL,
143 NULL,
144 NULL,
145 NULL,
146 NULL,
149 static UINT check_columns( const column_info *col_info )
151 const column_info *c1, *c2;
153 /* check for two columns with the same name */
154 for( c1 = col_info; c1; c1 = c1->next )
155 for( c2 = c1->next; c2; c2 = c2->next )
156 if (!lstrcmpW(c1->column, c2->column))
157 return ERROR_BAD_QUERY_SYNTAX;
159 return ERROR_SUCCESS;
162 UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPCWSTR table,
163 column_info *col_info, BOOL hold )
165 MSICREATEVIEW *cv = NULL;
166 UINT r;
167 column_info *col;
168 BOOL temp = TRUE;
169 BOOL tempprim = FALSE;
171 TRACE("%p\n", cv );
173 r = check_columns( col_info );
174 if( r != ERROR_SUCCESS )
175 return r;
177 cv = msi_alloc_zero( sizeof *cv );
178 if( !cv )
179 return ERROR_FUNCTION_FAILED;
181 for( col = col_info; col; col = col->next )
183 if (!col->table)
184 col->table = table;
186 if( !col->temporary )
187 temp = FALSE;
188 else if ( col->type & MSITYPE_KEY )
189 tempprim = TRUE;
192 if ( !temp && tempprim )
194 msi_free( cv );
195 return ERROR_FUNCTION_FAILED;
198 /* fill the structure */
199 cv->view.ops = &create_ops;
200 msiobj_addref( &db->hdr );
201 cv->db = db;
202 cv->name = table;
203 cv->col_info = col_info;
204 cv->bIsTemp = temp;
205 cv->hold = hold;
206 *view = (MSIVIEW*) cv;
208 return ERROR_SUCCESS;