ReactOS  0.4.14-dev-315-gbb6fece
distinct.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 distinct.c:

Go to the source code of this file.

Classes

struct  tagDISTINCTSET
 
struct  tagMSIDISTINCTVIEW
 

Typedefs

typedef struct tagDISTINCTSET DISTINCTSET
 
typedef struct tagMSIDISTINCTVIEW MSIDISTINCTVIEW
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msidb)
 
static DISTINCTSET ** distinct_insert (DISTINCTSET **x, UINT val, UINT row)
 
static void distinct_free (DISTINCTSET *x)
 
static UINT DISTINCT_fetch_int (struct tagMSIVIEW *view, UINT row, UINT col, UINT *val)
 
static UINT DISTINCT_execute (struct tagMSIVIEW *view, MSIRECORD *record)
 
static UINT DISTINCT_close (struct tagMSIVIEW *view)
 
static UINT DISTINCT_get_dimensions (struct tagMSIVIEW *view, UINT *rows, UINT *cols)
 
static UINT DISTINCT_get_column_info (struct tagMSIVIEW *view, UINT n, LPCWSTR *name, UINT *type, BOOL *temporary, LPCWSTR *table_name)
 
static UINT DISTINCT_modify (struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIRECORD *rec, UINT row)
 
static UINT DISTINCT_delete (struct tagMSIVIEW *view)
 
static UINT DISTINCT_find_matching_rows (struct tagMSIVIEW *view, UINT col, UINT val, UINT *row, MSIITERHANDLE *handle)
 
UINT DISTINCT_CreateView (MSIDATABASE *db, MSIVIEW **view, MSIVIEW *table)
 

Variables

static const MSIVIEWOPS distinct_ops
 

Typedef Documentation

◆ DISTINCTSET

◆ MSIDISTINCTVIEW

Function Documentation

◆ DISTINCT_close()

static UINT DISTINCT_close ( struct tagMSIVIEW view)
static

Definition at line 172 of file distinct.c.

173 {
175 
176  TRACE("%p\n", dv );
177 
178  if( !dv->table )
179  return ERROR_FUNCTION_FAILED;
180 
181  msi_free( dv->translation );
182  dv->translation = NULL;
183  dv->row_count = 0;
184 
185  return dv->table->ops->close( dv->table );
186 }
#define ERROR_FUNCTION_FAILED
Definition: winerror.h:985
smooth NULL
Definition: ftsmooth.c:416
MSIVIEW * table
Definition: distinct.c:51
#define TRACE(s)
Definition: solgame.cpp:4
const MSIVIEWOPS * ops
Definition: msipriv.h:348
UINT(* close)(struct tagMSIVIEW *view)
Definition: msipriv.h:273
static BOOL msi_free(void *mem)
Definition: msipriv.h:1227
UINT * translation
Definition: distinct.c:53

◆ DISTINCT_CreateView()

UINT DISTINCT_CreateView ( MSIDATABASE db,
MSIVIEW **  view,
MSIVIEW table 
)

Definition at line 294 of file distinct.c.

295 {
296  MSIDISTINCTVIEW *dv = NULL;
297  UINT count = 0, r;
298 
299  TRACE("%p\n", dv );
300 
301  r = table->ops->get_dimensions( table, NULL, &count );
302  if( r != ERROR_SUCCESS )
303  {
304  ERR("can't get table dimensions\n");
305  return r;
306  }
307 
308  dv = msi_alloc_zero( sizeof *dv );
309  if( !dv )
310  return ERROR_FUNCTION_FAILED;
311 
312  /* fill the structure */
313  dv->view.ops = &distinct_ops;
314  msiobj_addref( &db->hdr );
315  dv->db = db;
316  dv->table = table;
317  dv->translation = NULL;
318  dv->row_count = 0;
319  *view = (MSIVIEW*) dv;
320 
321  return ERROR_SUCCESS;
322 }
void msiobj_addref(MSIOBJECTHDR *info)
Definition: handle.c:218
static const MSIVIEWOPS distinct_ops
Definition: distinct.c:271
#define ERROR_SUCCESS
Definition: deptool.c:10
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum GLsizei GLenum GLenum const GLvoid * table
Definition: glext.h:5644
static void * msi_alloc_zero(size_t len) __WINE_ALLOC_SIZE(1)
Definition: msipriv.h:1210
#define ERROR_FUNCTION_FAILED
Definition: winerror.h:985
smooth NULL
Definition: ftsmooth.c:416
MSIVIEW * table
Definition: distinct.c:51
#define TRACE(s)
Definition: solgame.cpp:4
const MSIVIEWOPS * ops
Definition: msipriv.h:348
#define ERR(fmt,...)
Definition: debug.h:109
unsigned int UINT
Definition: ndis.h:50
MSIDATABASE * db
Definition: distinct.c:50
MSIOBJECTHDR hdr
Definition: msipriv.h:97
UINT * translation
Definition: distinct.c:53

Referenced by yyparse().

◆ DISTINCT_delete()

static UINT DISTINCT_delete ( struct tagMSIVIEW view)
static

Definition at line 234 of file distinct.c.

235 {
237 
238  TRACE("%p\n", dv );
239 
240  if( dv->table )
241  dv->table->ops->delete( dv->table );
242 
243  msi_free( dv->translation );
244  msiobj_release( &dv->db->hdr );
245  msi_free( dv );
246 
247  return ERROR_SUCCESS;
248 }
#define ERROR_SUCCESS
Definition: deptool.c:10
MSIVIEW * table
Definition: distinct.c:51
#define TRACE(s)
Definition: solgame.cpp:4
const MSIVIEWOPS * ops
Definition: msipriv.h:348
int msiobj_release(MSIOBJECTHDR *info)
Definition: handle.c:242
UINT(* delete)(struct tagMSIVIEW *)
Definition: msipriv.h:299
MSIDATABASE * db
Definition: distinct.c:50
static BOOL msi_free(void *mem)
Definition: msipriv.h:1227
MSIOBJECTHDR hdr
Definition: msipriv.h:97
UINT * translation
Definition: distinct.c:53

◆ DISTINCT_execute()

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

Definition at line 110 of file distinct.c.

111 {
113  UINT r, i, j, r_count, c_count;
114  DISTINCTSET *rowset = NULL;
115 
116  TRACE("%p %p\n", dv, record);
117 
118  if( !dv->table )
119  return ERROR_FUNCTION_FAILED;
120 
121  r = dv->table->ops->execute( dv->table, record );
122  if( r != ERROR_SUCCESS )
123  return r;
124 
125  r = dv->table->ops->get_dimensions( dv->table, &r_count, &c_count );
126  if( r != ERROR_SUCCESS )
127  return r;
128 
129  dv->translation = msi_alloc( r_count*sizeof(UINT) );
130  if( !dv->translation )
131  return ERROR_FUNCTION_FAILED;
132 
133  /* build it */
134  for( i=0; i<r_count; i++ )
135  {
136  DISTINCTSET **x = &rowset;
137 
138  for( j=1; j<=c_count; j++ )
139  {
140  UINT val = 0;
141  r = dv->table->ops->fetch_int( dv->table, i, j, &val );
142  if( r != ERROR_SUCCESS )
143  {
144  ERR("Failed to fetch int at %d %d\n", i, j );
145  distinct_free( rowset );
146  return r;
147  }
148  x = distinct_insert( x, val, i );
149  if( !*x )
150  {
151  ERR("Failed to insert at %d %d\n", i, j );
152  distinct_free( rowset );
153  return ERROR_FUNCTION_FAILED;
154  }
155  if( j != c_count )
156  x = &(*x)->nextcol;
157  }
158 
159  /* check if it was distinct and if so, include it */
160  if( (*x)->row == i )
161  {
162  TRACE("Row %d -> %d\n", dv->row_count, i);
163  dv->translation[dv->row_count++] = i;
164  }
165  }
166 
167  distinct_free( rowset );
168 
169  return ERROR_SUCCESS;
170 }
#define ERROR_SUCCESS
Definition: deptool.c:10
UINT(* get_dimensions)(struct tagMSIVIEW *view, UINT *rows, UINT *cols)
Definition: msipriv.h:281
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
UINT(* execute)(struct tagMSIVIEW *view, MSIRECORD *record)
Definition: msipriv.h:268
static void distinct_free(DISTINCTSET *x)
Definition: distinct.c:82
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
#define ERROR_FUNCTION_FAILED
Definition: winerror.h:985
smooth NULL
Definition: ftsmooth.c:416
static DISTINCTSET ** distinct_insert(DISTINCTSET **x, UINT val, UINT row)
Definition: distinct.c:56
GLuint GLfloat * val
Definition: glext.h:7180
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 GLint GLint j
Definition: glfuncs.h:250
MSIVIEW * table
Definition: distinct.c:51
#define TRACE(s)
Definition: solgame.cpp:4
const MSIVIEWOPS * ops
Definition: msipriv.h:348
#define ERR(fmt,...)
Definition: debug.h:109
unsigned int UINT
Definition: ndis.h:50
UINT(* fetch_int)(struct tagMSIVIEW *view, UINT row, UINT col, UINT *val)
Definition: msipriv.h:232
static void * msi_alloc(size_t len) __WINE_ALLOC_SIZE(1)
Definition: msipriv.h:1204
UINT * translation
Definition: distinct.c:53

◆ DISTINCT_fetch_int()

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

Definition at line 93 of file distinct.c.

94 {
96 
97  TRACE("%p %d %d %p\n", dv, row, col, val );
98 
99  if( !dv->table )
100  return ERROR_FUNCTION_FAILED;
101 
102  if( row >= dv->row_count )
104 
105  row = dv->translation[ row ];
106 
107  return dv->table->ops->fetch_int( dv->table, row, col, val );
108 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define ERROR_FUNCTION_FAILED
Definition: winerror.h:985
GLuint GLfloat * val
Definition: glext.h:7180
MSIVIEW * table
Definition: distinct.c:51
#define TRACE(s)
Definition: solgame.cpp:4
const MSIVIEWOPS * ops
Definition: msipriv.h:348
UINT(* fetch_int)(struct tagMSIVIEW *view, UINT row, UINT col, UINT *val)
Definition: msipriv.h:232
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
UINT * translation
Definition: distinct.c:53

◆ DISTINCT_find_matching_rows()

static UINT DISTINCT_find_matching_rows ( struct tagMSIVIEW view,
UINT  col,
UINT  val,
UINT row,
MSIITERHANDLE handle 
)
static

Definition at line 250 of file distinct.c.

252 {
254  UINT r;
255 
256  TRACE("%p, %d, %u, %p\n", view, col, val, *handle);
257 
258  if( !dv->table )
259  return ERROR_FUNCTION_FAILED;
260 
261  r = dv->table->ops->find_matching_rows( dv->table, col, val, row, handle );
262 
263  if( *row > dv->row_count )
264  return ERROR_NO_MORE_ITEMS;
265 
266  *row = dv->translation[ *row ];
267 
268  return r;
269 }
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:95
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
UINT(* find_matching_rows)(struct tagMSIVIEW *view, UINT col, UINT val, UINT *row, MSIITERHANDLE *handle)
Definition: msipriv.h:312
#define ERROR_FUNCTION_FAILED
Definition: winerror.h:985
GLuint GLfloat * val
Definition: glext.h:7180
MSIVIEW * table
Definition: distinct.c:51
#define TRACE(s)
Definition: solgame.cpp:4
const MSIVIEWOPS * ops
Definition: msipriv.h:348
unsigned int UINT
Definition: ndis.h:50
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
UINT * translation
Definition: distinct.c:53

◆ distinct_free()

static void distinct_free ( DISTINCTSET x)
static

Definition at line 82 of file distinct.c.

83 {
84  while( x )
85  {
86  DISTINCTSET *next = x->nextrow;
87  distinct_free( x->nextcol );
88  msi_free( x );
89  x = next;
90  }
91 }
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
static void distinct_free(DISTINCTSET *x)
Definition: distinct.c:82
static unsigned __int64 next
Definition: rand_nt.c:6
static BOOL msi_free(void *mem)
Definition: msipriv.h:1227

Referenced by DISTINCT_execute().

◆ DISTINCT_get_column_info()

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

Definition at line 207 of file distinct.c.

209 {
211 
212  TRACE("%p %d %p %p %p %p\n", dv, n, name, type, temporary, table_name );
213 
214  if( !dv->table )
215  return ERROR_FUNCTION_FAILED;
216 
217  return dv->table->ops->get_column_info( dv->table, n, name,
218  type, temporary, table_name );
219 }
GLdouble n
Definition: glext.h:7729
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define ERROR_FUNCTION_FAILED
Definition: winerror.h:985
MSIVIEW * table
Definition: distinct.c:51
#define TRACE(s)
Definition: solgame.cpp:4
const MSIVIEWOPS * ops
Definition: msipriv.h:348
UINT(* get_column_info)(struct tagMSIVIEW *view, UINT n, LPCWSTR *name, UINT *type, BOOL *temporary, LPCWSTR *table_name)
Definition: msipriv.h:288
Definition: name.c:36

◆ DISTINCT_get_dimensions()

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

Definition at line 188 of file distinct.c.

189 {
191 
192  TRACE("%p %p %p\n", dv, rows, cols );
193 
194  if( !dv->table )
195  return ERROR_FUNCTION_FAILED;
196 
197  if( rows )
198  {
199  if( !dv->translation )
200  return ERROR_FUNCTION_FAILED;
201  *rows = dv->row_count;
202  }
203 
204  return dv->table->ops->get_dimensions( dv->table, NULL, cols );
205 }
UINT(* get_dimensions)(struct tagMSIVIEW *view, UINT *rows, UINT *cols)
Definition: msipriv.h:281
#define ERROR_FUNCTION_FAILED
Definition: winerror.h:985
smooth NULL
Definition: ftsmooth.c:416
MSIVIEW * table
Definition: distinct.c:51
#define TRACE(s)
Definition: solgame.cpp:4
const MSIVIEWOPS * ops
Definition: msipriv.h:348
UINT * translation
Definition: distinct.c:53

◆ distinct_insert()

static DISTINCTSET** distinct_insert ( DISTINCTSET **  x,
UINT  val,
UINT  row 
)
static

Definition at line 56 of file distinct.c.

57 {
58  /* horrible O(n) find */
59  while( *x )
60  {
61  if( (*x)->val == val )
62  {
63  (*x)->count++;
64  return x;
65  }
66  x = &(*x)->nextrow;
67  }
68 
69  /* nothing found, so add one */
70  *x = msi_alloc( sizeof (DISTINCTSET) );
71  if( *x )
72  {
73  (*x)->val = val;
74  (*x)->count = 1;
75  (*x)->row = row;
76  (*x)->nextrow = NULL;
77  (*x)->nextcol = NULL;
78  }
79  return x;
80 }
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
smooth NULL
Definition: ftsmooth.c:416
GLuint GLfloat * val
Definition: glext.h:7180
static void * msi_alloc(size_t len) __WINE_ALLOC_SIZE(1)
Definition: msipriv.h:1204
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

Referenced by DISTINCT_execute().

◆ DISTINCT_modify()

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

Definition at line 221 of file distinct.c.

223 {
225 
226  TRACE("%p %d %p\n", dv, eModifyMode, rec );
227 
228  if( !dv->table )
229  return ERROR_FUNCTION_FAILED;
230 
231  return dv->table->ops->modify( dv->table, eModifyMode, rec, row );
232 }
#define ERROR_FUNCTION_FAILED
Definition: winerror.h:985
MSIVIEW * table
Definition: distinct.c:51
#define TRACE(s)
Definition: solgame.cpp:4
const MSIVIEWOPS * ops
Definition: msipriv.h:348
UINT(* modify)(struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIRECORD *record, UINT row)
Definition: msipriv.h:294
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

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msidb  )

Variable Documentation

◆ distinct_ops

const MSIVIEWOPS distinct_ops
static
Initial value:
=
{
}
static UINT DISTINCT_get_dimensions(struct tagMSIVIEW *view, UINT *rows, UINT *cols)
Definition: distinct.c:188
static UINT DISTINCT_fetch_int(struct tagMSIVIEW *view, UINT row, UINT col, UINT *val)
Definition: distinct.c:93
static UINT DISTINCT_close(struct tagMSIVIEW *view)
Definition: distinct.c:172
smooth NULL
Definition: ftsmooth.c:416
static UINT DISTINCT_find_matching_rows(struct tagMSIVIEW *view, UINT col, UINT val, UINT *row, MSIITERHANDLE *handle)
Definition: distinct.c:250
static UINT DISTINCT_modify(struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIRECORD *rec, UINT row)
Definition: distinct.c:221
static UINT DISTINCT_get_column_info(struct tagMSIVIEW *view, UINT n, LPCWSTR *name, UINT *type, BOOL *temporary, LPCWSTR *table_name)
Definition: distinct.c:207
static UINT DISTINCT_execute(struct tagMSIVIEW *view, MSIRECORD *record)
Definition: distinct.c:110
static UINT DISTINCT_delete(struct tagMSIVIEW *view)
Definition: distinct.c:234

Definition at line 271 of file distinct.c.

Referenced by DISTINCT_CreateView().