blob: f632ef63d91243ef7e2d6cad4e28784a02e175b2 [file] [log] [blame]
Mike McCormack14ec5262004-03-16 19:18:22 +00001/*
2 * Implementation of the Microsoft Installer (msi.dll)
3 *
Mike McCormack068b4ec2004-03-19 01:16:36 +00004 * Copyright 2002-2004 Mike McCormack for CodeWeavers
Mike McCormack14ec5262004-03-16 19:18:22 +00005 *
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.
10 *
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.
15 *
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
Jonathan Ernst360a3f92006-05-18 14:49:52 +020018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Mike McCormack14ec5262004-03-16 19:18:22 +000019 */
20
21#include <stdarg.h>
22
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"
33
34#include "query.h"
35
Mike McCormack50684c12005-11-02 14:24:21 +000036WINE_DEFAULT_DEBUG_CHANNEL(msidb);
Mike McCormack14ec5262004-03-16 19:18:22 +000037
38
39/* below is the query interface to a table */
40
41typedef struct tagMSICREATEVIEW
42{
43 MSIVIEW view;
44 MSIDATABASE *db;
45 LPWSTR name;
46 BOOL bIsTemp;
Mike McCormackd1a55eb2005-05-29 20:17:16 +000047 column_info *col_info;
Mike McCormack14ec5262004-03-16 19:18:22 +000048} MSICREATEVIEW;
49
50static UINT CREATE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
51{
52 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
53
54 TRACE("%p %d %d %p\n", cv, row, col, val );
55
56 return ERROR_FUNCTION_FAILED;
57}
58
Alexandre Julliarda7a6f5f2004-07-09 22:25:34 +000059static UINT CREATE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
Mike McCormack14ec5262004-03-16 19:18:22 +000060{
61 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
Rob Shearmanba0507a2007-04-23 08:21:32 +010062 MSITABLE *table;
Mike McCormack14ec5262004-03-16 19:18:22 +000063
Mike McCormack068b4ec2004-03-19 01:16:36 +000064 TRACE("%p Table %s (%s)\n", cv, debugstr_w(cv->name),
Mike McCormack14ec5262004-03-16 19:18:22 +000065 cv->bIsTemp?"temporary":"permanent");
66
Rob Shearmanba0507a2007-04-23 08:21:32 +010067 return msi_create_table( cv->db, cv->name, cv->col_info, !cv->bIsTemp, &table);
Mike McCormack14ec5262004-03-16 19:18:22 +000068}
69
70static UINT CREATE_close( struct tagMSIVIEW *view )
71{
72 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
73
Mike McCormack068b4ec2004-03-19 01:16:36 +000074 TRACE("%p\n", cv);
Mike McCormack14ec5262004-03-16 19:18:22 +000075
76 return ERROR_SUCCESS;
Mike McCormack14ec5262004-03-16 19:18:22 +000077}
78
79static UINT CREATE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols )
80{
81 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
82
83 TRACE("%p %p %p\n", cv, rows, cols );
84
85 return ERROR_FUNCTION_FAILED;
86}
87
88static UINT CREATE_get_column_info( struct tagMSIVIEW *view,
89 UINT n, LPWSTR *name, UINT *type )
90{
91 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
92
93 TRACE("%p %d %p %p\n", cv, n, name, type );
94
95 return ERROR_FUNCTION_FAILED;
96}
97
Mike McCormackef1d3672005-02-08 13:44:25 +000098static UINT CREATE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
99 MSIRECORD *rec)
Mike McCormack14ec5262004-03-16 19:18:22 +0000100{
101 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
102
Mike McCormackef1d3672005-02-08 13:44:25 +0000103 TRACE("%p %d %p\n", cv, eModifyMode, rec );
Mike McCormack14ec5262004-03-16 19:18:22 +0000104
105 return ERROR_FUNCTION_FAILED;
106}
107
108static UINT CREATE_delete( struct tagMSIVIEW *view )
109{
110 MSICREATEVIEW *cv = (MSICREATEVIEW*)view;
Mike McCormack14ec5262004-03-16 19:18:22 +0000111
112 TRACE("%p\n", cv );
113
Aric Stewartbc6ce2b2004-08-25 17:31:39 +0000114 msiobj_release( &cv->db->hdr );
Mike McCormack8dc28d52005-09-20 11:57:19 +0000115 msi_free( cv );
Mike McCormack14ec5262004-03-16 19:18:22 +0000116
117 return ERROR_SUCCESS;
118}
119
Alexandre Julliard9a59ee72006-06-10 12:02:39 +0200120static const MSIVIEWOPS create_ops =
Mike McCormack14ec5262004-03-16 19:18:22 +0000121{
122 CREATE_fetch_int,
Mike McCormack068b4ec2004-03-19 01:16:36 +0000123 NULL,
124 NULL,
Mike McCormack24e9a342004-07-06 18:56:12 +0000125 NULL,
James Hawkins9309f4d2007-06-18 13:49:31 -0700126 NULL,
Mike McCormack14ec5262004-03-16 19:18:22 +0000127 CREATE_execute,
128 CREATE_close,
129 CREATE_get_dimensions,
130 CREATE_get_column_info,
131 CREATE_modify,
James Hawkins3b1ab762007-07-18 18:21:00 -0700132 CREATE_delete,
133 NULL,
134 NULL,
James Hawkins0fd733b2007-07-20 14:01:13 -0700135 NULL,
Mike McCormack14ec5262004-03-16 19:18:22 +0000136};
137
Mike McCormack29245012006-08-31 17:04:40 +0900138static UINT check_columns( column_info *col_info )
139{
140 column_info *c1, *c2;
141
142 /* check for two columns with the same name */
143 for( c1 = col_info; c1; c1 = c1->next )
144 for( c2 = c1->next; c2; c2 = c2->next )
145 if (!lstrcmpW(c1->column, c2->column))
146 return ERROR_BAD_QUERY_SYNTAX;
147
148 return ERROR_SUCCESS;
149}
150
Mike McCormack14ec5262004-03-16 19:18:22 +0000151UINT CREATE_CreateView( MSIDATABASE *db, MSIVIEW **view, LPWSTR table,
Rob Shearman697d8202007-04-23 08:26:44 +0100152 column_info *col_info, BOOL hold )
Mike McCormack14ec5262004-03-16 19:18:22 +0000153{
154 MSICREATEVIEW *cv = NULL;
Mike McCormack29245012006-08-31 17:04:40 +0900155 UINT r;
Rob Shearman697d8202007-04-23 08:26:44 +0100156 const column_info *col;
157 BOOL temp = TRUE;
Mike McCormack14ec5262004-03-16 19:18:22 +0000158
159 TRACE("%p\n", cv );
160
Mike McCormack29245012006-08-31 17:04:40 +0900161 r = check_columns( col_info );
162 if( r != ERROR_SUCCESS )
163 return r;
164
Mike McCormack8dc28d52005-09-20 11:57:19 +0000165 cv = msi_alloc_zero( sizeof *cv );
Mike McCormack14ec5262004-03-16 19:18:22 +0000166 if( !cv )
167 return ERROR_FUNCTION_FAILED;
Mike McCormack29245012006-08-31 17:04:40 +0900168
Rob Shearman697d8202007-04-23 08:26:44 +0100169 for( col = col_info; col; col = col->next )
170 if( !col->temporary )
171 {
172 temp = FALSE;
173 break;
174 }
175
Mike McCormack14ec5262004-03-16 19:18:22 +0000176 /* fill the structure */
177 cv->view.ops = &create_ops;
Alexandre Julliarda7a6f5f2004-07-09 22:25:34 +0000178 msiobj_addref( &db->hdr );
Mike McCormack14ec5262004-03-16 19:18:22 +0000179 cv->db = db;
Mike McCormack00930072005-05-23 12:08:17 +0000180 cv->name = table;
Mike McCormack14ec5262004-03-16 19:18:22 +0000181 cv->col_info = col_info;
182 cv->bIsTemp = temp;
183 *view = (MSIVIEW*) cv;
184
185 return ERROR_SUCCESS;
186}