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
26 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msidb
);
39 /* below is the query interface to a table */
41 typedef struct tagMSICREATEVIEW
48 column_info
*col_info
;
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 BOOL persist
= (cv
->bIsTemp
) ? MSICONDITION_FALSE
: MSICONDITION_TRUE
;
65 TRACE("%p Table %s (%s)\n", cv
, debugstr_w(cv
->name
),
66 cv
->bIsTemp
?"temporary":"permanent");
68 if (cv
->bIsTemp
&& !cv
->hold
)
71 return msi_create_table( cv
->db
, cv
->name
, cv
->col_info
, persist
, cv
->hold
);
74 static UINT
CREATE_close( struct tagMSIVIEW
*view
)
76 MSICREATEVIEW
*cv
= (MSICREATEVIEW
*)view
;
83 static UINT
CREATE_get_dimensions( struct tagMSIVIEW
*view
, UINT
*rows
, UINT
*cols
)
85 MSICREATEVIEW
*cv
= (MSICREATEVIEW
*)view
;
87 TRACE("%p %p %p\n", cv
, rows
, cols
);
89 return ERROR_FUNCTION_FAILED
;
92 static UINT
CREATE_get_column_info( struct tagMSIVIEW
*view
, UINT n
, LPCWSTR
*name
,
93 UINT
*type
, BOOL
*temporary
, LPCWSTR
*table_name
)
95 MSICREATEVIEW
*cv
= (MSICREATEVIEW
*)view
;
97 TRACE("%p %d %p %p %p %p\n", cv
, n
, name
, type
, temporary
, table_name
);
99 return ERROR_FUNCTION_FAILED
;
102 static UINT
CREATE_modify( struct tagMSIVIEW
*view
, MSIMODIFY eModifyMode
,
103 MSIRECORD
*rec
, UINT row
)
105 MSICREATEVIEW
*cv
= (MSICREATEVIEW
*)view
;
107 TRACE("%p %d %p\n", cv
, eModifyMode
, rec
);
109 return ERROR_FUNCTION_FAILED
;
112 static UINT
CREATE_delete( struct tagMSIVIEW
*view
)
114 MSICREATEVIEW
*cv
= (MSICREATEVIEW
*)view
;
118 msiobj_release( &cv
->db
->hdr
);
121 return ERROR_SUCCESS
;
124 static const MSIVIEWOPS create_ops
=
136 CREATE_get_dimensions
,
137 CREATE_get_column_info
,
147 static UINT
check_columns( const column_info
*col_info
)
149 const column_info
*c1
, *c2
;
151 /* check for two columns with the same name */
152 for( c1
= col_info
; c1
; c1
= c1
->next
)
153 for( c2
= c1
->next
; c2
; c2
= c2
->next
)
154 if (!wcscmp( c1
->column
, c2
->column
))
155 return ERROR_BAD_QUERY_SYNTAX
;
157 return ERROR_SUCCESS
;
160 UINT
CREATE_CreateView( MSIDATABASE
*db
, MSIVIEW
**view
, LPCWSTR table
,
161 column_info
*col_info
, BOOL hold
)
163 MSICREATEVIEW
*cv
= NULL
;
167 BOOL tempprim
= FALSE
;
171 r
= check_columns( col_info
);
172 if( r
!= ERROR_SUCCESS
)
175 cv
= msi_alloc_zero( sizeof *cv
);
177 return ERROR_FUNCTION_FAILED
;
179 for( col
= col_info
; col
; col
= col
->next
)
184 if( !(col
->type
& MSITYPE_TEMPORARY
) )
186 else if ( col
->type
& MSITYPE_KEY
)
190 if ( !temp
&& tempprim
)
193 return ERROR_FUNCTION_FAILED
;
196 /* fill the structure */
197 cv
->view
.ops
= &create_ops
;
198 msiobj_addref( &db
->hdr
);
201 cv
->col_info
= col_info
;
204 *view
= (MSIVIEW
*) cv
;
206 return ERROR_SUCCESS
;