ReactOS 0.4.15-dev-7953-g1f49173
insert.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "wine/debug.h"
#include "msi.h"
#include "msiquery.h"
#include "objbase.h"
#include "objidl.h"
#include "msipriv.h"
#include "winnls.h"
#include "query.h"
Include dependency graph for insert.c:

Go to the source code of this file.

Classes

struct  tagMSIINSERTVIEW
 

Typedefs

typedef struct tagMSIINSERTVIEW MSIINSERTVIEW
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msidb)
 
static UINT INSERT_fetch_int (struct tagMSIVIEW *view, UINT row, UINT col, UINT *val)
 
MSIRECORDmsi_query_merge_record (UINT fields, const column_info *vl, MSIRECORD *rec)
 
static BOOL msi_columns_in_order (MSIINSERTVIEW *iv, UINT col_count)
 
static UINT msi_arrange_record (MSIINSERTVIEW *iv, MSIRECORD **values)
 
static BOOL row_has_null_primary_keys (MSIINSERTVIEW *iv, MSIRECORD *row)
 
static UINT INSERT_execute (struct tagMSIVIEW *view, MSIRECORD *record)
 
static UINT INSERT_close (struct tagMSIVIEW *view)
 
static UINT INSERT_get_dimensions (struct tagMSIVIEW *view, UINT *rows, UINT *cols)
 
static UINT INSERT_get_column_info (struct tagMSIVIEW *view, UINT n, LPCWSTR *name, UINT *type, BOOL *temporary, LPCWSTR *table_name)
 
static UINT INSERT_modify (struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIRECORD *rec, UINT row)
 
static UINT INSERT_delete (struct tagMSIVIEW *view)
 
static UINT count_column_info (const column_info *ci)
 
UINT INSERT_CreateView (MSIDATABASE *db, MSIVIEW **view, LPCWSTR table, column_info *columns, column_info *values, BOOL temp)
 

Variables

static const MSIVIEWOPS insert_ops
 

Typedef Documentation

◆ MSIINSERTVIEW

Function Documentation

◆ count_column_info()

static UINT count_column_info ( const column_info ci)
static

Definition at line 343 of file insert.c.

344{
345 UINT n = 0;
346 for ( ; ci; ci = ci->next )
347 n++;
348 return n;
349}
GLdouble n
Definition: glext.h:7729
unsigned int UINT
Definition: ndis.h:50
struct _column_info * next
Definition: msipriv.h:226

Referenced by INSERT_CreateView().

◆ INSERT_close()

static UINT INSERT_close ( struct tagMSIVIEW view)
static

Definition at line 252 of file insert.c.

253{
255 MSIVIEW *sv;
256
257 TRACE("%p\n", iv);
258
259 sv = iv->sv;
260 if( !sv )
262
263 return sv->ops->close( sv );
264}
#define TRACE(s)
Definition: solgame.cpp:4
MSIVIEW * sv
Definition: insert.c:47
UINT(* close)(struct tagMSIVIEW *view)
Definition: msipriv.h:298
const MSIVIEWOPS * ops
Definition: msipriv.h:355
#define ERROR_FUNCTION_FAILED
Definition: winerror.h:985

◆ INSERT_CreateView()

UINT INSERT_CreateView ( MSIDATABASE db,
MSIVIEW **  view,
LPCWSTR  table,
column_info columns,
column_info values,
BOOL  temp 
)

Definition at line 351 of file insert.c.

353{
354 MSIINSERTVIEW *iv = NULL;
355 UINT r;
356 MSIVIEW *tv = NULL, *sv = NULL;
357
358 TRACE("%p\n", iv );
359
360 /* there should be one value for each column */
361 if ( count_column_info( columns ) != count_column_info(values) )
363
364 r = TABLE_CreateView( db, table, &tv );
365 if( r != ERROR_SUCCESS )
366 return r;
367
368 r = SELECT_CreateView( db, &sv, tv, columns );
369 if( r != ERROR_SUCCESS )
370 {
371 if( tv )
372 tv->ops->delete( tv );
373 return r;
374 }
375
376 iv = msi_alloc_zero( sizeof *iv );
377 if( !iv )
379
380 /* fill the structure */
381 iv->view.ops = &insert_ops;
382 msiobj_addref( &db->hdr );
383 iv->table = tv;
384 iv->db = db;
385 iv->vals = values;
386 iv->bIsTemp = temp;
387 iv->sv = sv;
388 *view = (MSIVIEW*) iv;
389
390 return ERROR_SUCCESS;
391}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
void msiobj_addref(MSIOBJECTHDR *info)
Definition: handle.c:217
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:5666
static UINT count_column_info(const column_info *ci)
Definition: insert.c:343
static const MSIVIEWOPS insert_ops
Definition: insert.c:320
static void * msi_alloc_zero(size_t len) __WINE_ALLOC_SIZE(1)
Definition: msipriv.h:1148
UINT TABLE_CreateView(MSIDATABASE *db, LPCWSTR name, MSIVIEW **view) DECLSPEC_HIDDEN
Definition: table.c:2189
UINT SELECT_CreateView(MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table, const column_info *columns) DECLSPEC_HIDDEN
Definition: select.c:423
static calc_node_t temp
Definition: rpn_ieee.c:38
MSIOBJECTHDR hdr
Definition: msipriv.h:108
MSIDATABASE * db
Definition: insert.c:45
MSIVIEW view
Definition: insert.c:43
MSIVIEW * table
Definition: insert.c:44
BOOL bIsTemp
Definition: insert.c:46
column_info * vals
Definition: insert.c:48
UINT(* delete)(struct tagMSIVIEW *)
Definition: msipriv.h:324
#define ERROR_BAD_QUERY_SYNTAX
Definition: winerror.h:973

◆ INSERT_delete()

static UINT INSERT_delete ( struct tagMSIVIEW view)
static

Definition at line 304 of file insert.c.

305{
307 MSIVIEW *sv;
308
309 TRACE("%p\n", iv );
310
311 sv = iv->sv;
312 if( sv )
313 sv->ops->delete( sv );
314 msiobj_release( &iv->db->hdr );
315 msi_free( iv );
316
317 return ERROR_SUCCESS;
318}
int msiobj_release(MSIOBJECTHDR *info)
Definition: handle.c:241
static void msi_free(void *mem)
Definition: msipriv.h:1159

◆ INSERT_execute()

static UINT INSERT_execute ( struct tagMSIVIEW view,
MSIRECORD record 
)
static

Definition at line 204 of file insert.c.

205{
207 UINT r, row = -1, col_count = 0;
208 MSIVIEW *sv;
210
211 TRACE("%p %p\n", iv, record );
212
213 sv = iv->sv;
214 if( !sv )
216
217 r = sv->ops->execute( sv, 0 );
218 TRACE("sv execute returned %x\n", r);
219 if( r )
220 return r;
221
222 r = sv->ops->get_dimensions( sv, NULL, &col_count );
223 if( r )
224 goto err;
225
226 /*
227 * Merge the wildcard values into the list of values provided
228 * in the query, and create a record containing both.
229 */
230 values = msi_query_merge_record( col_count, iv->vals, record );
231 if( !values )
232 goto err;
233
234 r = msi_arrange_record( iv, &values );
235 if( r != ERROR_SUCCESS )
236 goto err;
237
238 /* rows with NULL primary keys are inserted at the beginning of the table */
240 row = 0;
241
242 r = iv->table->ops->insert_row( iv->table, values, row, iv->bIsTemp );
243
244err:
245 if( values )
246 msiobj_release( &values->hdr );
247
248 return r;
249}
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:78
static BOOL row_has_null_primary_keys(MSIINSERTVIEW *iv, MSIRECORD *row)
Definition: insert.c:179
static UINT msi_arrange_record(MSIINSERTVIEW *iv, MSIRECORD **values)
Definition: insert.c:127
MSIRECORD * msi_query_merge_record(UINT fields, const column_info *vl, MSIRECORD *rec)
Definition: insert.c:66
#define err(...)
UINT(* insert_row)(struct tagMSIVIEW *view, MSIRECORD *record, UINT row, BOOL temporary)
Definition: msipriv.h:283
UINT(* get_dimensions)(struct tagMSIVIEW *view, UINT *rows, UINT *cols)
Definition: msipriv.h:306
UINT(* execute)(struct tagMSIVIEW *view, MSIRECORD *record)
Definition: msipriv.h:293

◆ INSERT_fetch_int()

static UINT INSERT_fetch_int ( struct tagMSIVIEW view,
UINT  row,
UINT  col,
UINT val 
)
static

Definition at line 51 of file insert.c.

52{
54
55 TRACE("%p %d %d %p\n", iv, row, col, val );
56
58}
GLuint GLfloat * val
Definition: glext.h:7180

◆ INSERT_get_column_info()

static UINT INSERT_get_column_info ( struct tagMSIVIEW view,
UINT  n,
LPCWSTR name,
UINT type,
BOOL temporary,
LPCWSTR table_name 
)
static

Definition at line 280 of file insert.c.

282{
284 MSIVIEW *sv;
285
286 TRACE("%p %d %p %p %p %p\n", iv, n, name, type, temporary, table_name );
287
288 sv = iv->sv;
289 if( !sv )
291
292 return sv->ops->get_column_info( sv, n, name, type, temporary, table_name );
293}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
Definition: name.c:39
UINT(* get_column_info)(struct tagMSIVIEW *view, UINT n, LPCWSTR *name, UINT *type, BOOL *temporary, LPCWSTR *table_name)
Definition: msipriv.h:313

◆ INSERT_get_dimensions()

static UINT INSERT_get_dimensions ( struct tagMSIVIEW view,
UINT rows,
UINT cols 
)
static

Definition at line 266 of file insert.c.

267{
269 MSIVIEW *sv;
270
271 TRACE("%p %p %p\n", iv, rows, cols );
272
273 sv = iv->sv;
274 if( !sv )
276
277 return sv->ops->get_dimensions( sv, rows, cols );
278}

◆ INSERT_modify()

static UINT INSERT_modify ( struct tagMSIVIEW view,
MSIMODIFY  eModifyMode,
MSIRECORD rec,
UINT  row 
)
static

Definition at line 295 of file insert.c.

296{
298
299 TRACE("%p %d %p\n", iv, eModifyMode, rec );
300
302}

◆ msi_arrange_record()

static UINT msi_arrange_record ( MSIINSERTVIEW iv,
MSIRECORD **  values 
)
static

Definition at line 127 of file insert.c.

128{
129 MSIRECORD *padded;
130 UINT col_count, val_count;
131 UINT r, i, colidx;
132 LPCWSTR a, b;
133
134 r = iv->table->ops->get_dimensions(iv->table, NULL, &col_count);
135 if (r != ERROR_SUCCESS)
136 return r;
137
138 val_count = MSI_RecordGetFieldCount(*values);
139
140 /* check to see if the columns are arranged already
141 * to avoid unnecessary copying
142 */
143 if (col_count == val_count && msi_columns_in_order(iv, col_count))
144 return ERROR_SUCCESS;
145
146 padded = MSI_CreateRecord(col_count);
147 if (!padded)
148 return ERROR_OUTOFMEMORY;
149
150 for (colidx = 1; colidx <= val_count; colidx++)
151 {
152 r = iv->sv->ops->get_column_info(iv->sv, colidx, &a, NULL, NULL, NULL);
153 if (r != ERROR_SUCCESS)
154 goto err;
155
156 for (i = 1; i <= col_count; i++)
157 {
158 r = iv->table->ops->get_column_info(iv->table, i, &b, NULL,
159 NULL, NULL);
160 if (r != ERROR_SUCCESS)
161 goto err;
162
163 if (!wcscmp( a, b ))
164 {
165 MSI_RecordCopyField(*values, colidx, padded, i);
166 break;
167 }
168 }
169 }
170 msiobj_release(&(*values)->hdr);
171 *values = padded;
172 return ERROR_SUCCESS;
173
174err:
175 msiobj_release(&padded->hdr);
176 return r;
177}
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static BOOL msi_columns_in_order(MSIINSERTVIEW *iv, UINT col_count)
Definition: insert.c:109
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
UINT MSI_RecordGetFieldCount(const MSIRECORD *rec) DECLSPEC_HIDDEN
Definition: record.c:108
MSIRECORD * MSI_CreateRecord(UINT) DECLSPEC_HIDDEN
Definition: record.c:76
UINT MSI_RecordCopyField(MSIRECORD *, UINT, MSIRECORD *, UINT) DECLSPEC_HIDDEN
Definition: record.c:166
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
MSIOBJECTHDR hdr
Definition: msipriv.h:151
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by INSERT_execute().

◆ msi_columns_in_order()

static BOOL msi_columns_in_order ( MSIINSERTVIEW iv,
UINT  col_count 
)
static

Definition at line 109 of file insert.c.

110{
111 LPCWSTR a, b;
112 UINT i;
113
114 for (i = 1; i <= col_count; i++)
115 {
116 iv->sv->ops->get_column_info(iv->sv, i, &a, NULL, NULL, NULL);
117 iv->table->ops->get_column_info(iv->table, i, &b, NULL, NULL, NULL);
118
119 if (wcscmp( a, b )) return FALSE;
120 }
121 return TRUE;
122}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117

Referenced by msi_arrange_record().

◆ msi_query_merge_record()

MSIRECORD * msi_query_merge_record ( UINT  fields,
const column_info vl,
MSIRECORD rec 
)

Definition at line 66 of file insert.c.

67{
68 MSIRECORD *merged;
69 DWORD wildcard_count = 1, i;
70
71 merged = MSI_CreateRecord( fields );
72 for( i=1; i <= fields; i++ )
73 {
74 if( !vl )
75 {
76 TRACE("Not enough elements in the list to insert\n");
77 goto err;
78 }
79 switch( vl->val->type )
80 {
81 case EXPR_SVAL:
82 TRACE( "field %lu -> %s\n", i, debugstr_w(vl->val->u.sval) );
83 MSI_RecordSetStringW( merged, i, vl->val->u.sval );
84 break;
85 case EXPR_IVAL:
86 MSI_RecordSetInteger( merged, i, vl->val->u.ival );
87 break;
88 case EXPR_WILDCARD:
89 if( !rec )
90 goto err;
91 MSI_RecordCopyField( rec, wildcard_count, merged, i );
92 wildcard_count++;
93 break;
94 default:
95 ERR("Unknown expression type %d\n", vl->val->type);
96 }
97 vl = vl->next;
98 }
99
100 return merged;
101err:
102 msiobj_release( &merged->hdr );
103 return NULL;
104}
#define ERR(fmt,...)
Definition: debug.h:110
unsigned long DWORD
Definition: ntddk_ex.h:95
#define debugstr_w
Definition: kernel32.h:32
const char * fields[10]
Definition: parser.c:313
UINT MSI_RecordSetInteger(MSIRECORD *, UINT, int) DECLSPEC_HIDDEN
Definition: record.c:280
UINT MSI_RecordSetStringW(MSIRECORD *, UINT, LPCWSTR) DECLSPEC_HIDDEN
Definition: record.c:597
#define EXPR_WILDCARD
Definition: query.h:54
#define EXPR_IVAL
Definition: query.h:50
#define EXPR_SVAL
Definition: query.h:51
struct expr * val
Definition: msipriv.h:225

Referenced by INSERT_execute(), and UPDATE_execute().

◆ row_has_null_primary_keys()

static BOOL row_has_null_primary_keys ( MSIINSERTVIEW iv,
MSIRECORD row 
)
static

Definition at line 179 of file insert.c.

180{
181 UINT r, i, col_count, type;
182
183 r = iv->table->ops->get_dimensions( iv->table, NULL, &col_count );
184 if (r != ERROR_SUCCESS)
185 return FALSE;
186
187 for (i = 1; i <= col_count; i++)
188 {
189 r = iv->table->ops->get_column_info(iv->table, i, NULL, &type,
190 NULL, NULL);
191 if (r != ERROR_SUCCESS)
192 return FALSE;
193
194 if (!(type & MSITYPE_KEY))
195 continue;
196
197 if (MSI_RecordIsNull(row, i))
198 return TRUE;
199 }
200
201 return FALSE;
202}
#define MSITYPE_KEY
Definition: msipriv.h:52
BOOL MSI_RecordIsNull(MSIRECORD *, UINT) DECLSPEC_HIDDEN
Definition: record.c:321

Referenced by INSERT_execute().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msidb  )

Variable Documentation

◆ insert_ops

const MSIVIEWOPS insert_ops
static
Initial value:
=
{
}
static UINT INSERT_fetch_int(struct tagMSIVIEW *view, UINT row, UINT col, UINT *val)
Definition: insert.c:51
static UINT INSERT_close(struct tagMSIVIEW *view)
Definition: insert.c:252
static UINT INSERT_modify(struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIRECORD *rec, UINT row)
Definition: insert.c:295
static UINT INSERT_get_column_info(struct tagMSIVIEW *view, UINT n, LPCWSTR *name, UINT *type, BOOL *temporary, LPCWSTR *table_name)
Definition: insert.c:280
static UINT INSERT_delete(struct tagMSIVIEW *view)
Definition: insert.c:304
static UINT INSERT_get_dimensions(struct tagMSIVIEW *view, UINT *rows, UINT *cols)
Definition: insert.c:266
static UINT INSERT_execute(struct tagMSIVIEW *view, MSIRECORD *record)
Definition: insert.c:204

Definition at line 320 of file insert.c.

Referenced by INSERT_CreateView().