rpm  5.4.10
rpmsql.h
Go to the documentation of this file.
1 #ifndef rpmsql_h
2 #define RPMSQL_H
3 
8 #include <rpmiotypes.h>
9 #include <rpmio.h>
10 #include <argv.h>
11 
12 typedef void * rpmvArg;
13 
14 typedef /*@abstract@*/ struct rpmvd_s * rpmvd;
15 
16 typedef /*@abstract@*/ struct rpmvc_s * rpmvc;
17 typedef /*@abstract@*/ struct rpmvt_s * rpmvt;
18 typedef /*@abstract@*/ /*@refcounted@*/ struct rpmsql_s * rpmsql;
19 
20 /*@unchecked@*/
21 extern int _rpmsql_debug;
22 
23 /*@unchecked@*/
24 extern int _rpmvt_debug;
25 
26 /*@unchecked@*/
27 extern int _rpmvc_debug;
28 
29 /*@unchecked@*/
30 extern rpmsql _rpmsqlI;
31 
32 /*@unchecked@*/
33 extern volatile int _rpmsqlSeenInterrupt;
34 
35 #if defined(_RPMSQL_INTERNAL)
36 
37 #define F_ISSET(_sql, _FLAG) ((_sql)->flags & (RPMSQL_FLAGS_##_FLAG))
38 #define SQLDBG(_l) if (_rpmsql_debug) fprintf _l
39 
43 enum rpmsqlFlags_e {
44  RPMSQL_FLAGS_NONE = 0,
45  RPMSQL_FLAGS_INTERACTIVE = (1 << 0), /* -interactive */
46  RPMSQL_FLAGS_BAIL = (1 << 1), /* -bail */
47  RPMSQL_FLAGS_NOLOAD = (1 << 2), /* -[no]load */
48  RPMSQL_FLAGS_CREATE = (1 << 3), /* -[no]create */
49 
50  RPMSQL_FLAGS_ECHO = (1 << 16), /* -echo */
51  RPMSQL_FLAGS_SHOWHDR = (1 << 17), /* -[no]header */
52  RPMSQL_FLAGS_WRITABLE = (1 << 18), /* PRAGMA writable_schema */
53 
54  RPMSQL_FLAGS_PROMPT = (1 << 24), /* STDIN from tty */
55 };
56 
60 enum rpmsqlModes_e {
61  RPMSQL_MODE_LINE = 0, /* One column per line. Blank line between records */
62  RPMSQL_MODE_COLUMN = 1, /* One record per line in neat columns */
63  RPMSQL_MODE_LIST = 2, /* One record per line with a separator */
64  RPMSQL_MODE_SEMI = 3, /* Same as MODE_LIST but append ";" to each line */
65  RPMSQL_MODE_HTML = 4, /* Generate an XHTML table */
66  RPMSQL_MODE_INSERT = 5, /* Generate SQL "insert" statements */
67  RPMSQL_MODE_TCL = 6, /* Generate ANSI-C or TCL quoted elements */
68  RPMSQL_MODE_CSV = 7, /* Quote strings, numbers are plain */
69  RPMSQL_MODE_EXPLAIN = 8, /* Like MODE_COLUMN, but do not truncate data */
70 };
71 
72 struct previous_mode {
73  int valid; /* Is there legit data in here? */
74  uint32_t mode;
75  uint32_t flags;
76  int colWidth[100];
77 };
78 
79 struct rpmsql_s {
80  struct rpmioItem_s _item;
81  uint32_t flags;
82  const char ** av;
84  void * I; /* The database (sqlite *) */
85 /*@null@*/
86  void * S; /* Current statement if any (sqlite3_stmt *) */
87 
88  const char * zInitFile; /* -init FILE */
89 
90  const char * zDbFilename; /* Name of the database file */
91  const char * zDestTable; /* Name of destination table iff MODE_INSERT */
92 
93  uint32_t mode; /* Operational mode. */
94 
95  int cnt; /* Number of records displayed so far */
96 
97  FD_t ifd; /* Read input here. */
98  FD_t ofd; /* Write output here */
99  FD_t lfd; /* Write log output here */
100  FD_t tfd; /* Write I/O traces here */
101  rpmiob iob; /* Output I/O buffer collector */
102 
103  int enableTimer; /* Timer enabled? */
104  struct rusage sBegin; /* Saved resource info for start. */
105 
106  /* Holds the mode information just before .explain ON */
107  struct previous_mode explainPrev;
108  char separator[20]; /* Separator character for MODE_LIST */
109  int colWidth[100]; /* Requested width of each column when in column mode */
110  int actualWidth[100]; /* Actual width of each column */
111  char nullvalue[20]; /* Text to print for NULL from the database */
112  const char * outfile; /* Filename for *out (NULL is stdout) */
113 
114  /* XXX INTERACTIVE cruft. */
115  const char * zHome; /* HOME */
116  const char * zInitrc; /* ~/.sqliterc */
117  const char * zHistory; /* ~/.sqlite_history */
118  const char * zPrompt; /* "sql> " */
119  const char * zContinue; /* "...> " */
120 
121  /* Sliding window input line buffer. */
122  char * buf;
123  size_t nbuf;
124 /*@null@*/
125  char * b;
126  size_t nb;
127 
128 #if defined(__LCLINT__)
129 /*@refs@*/
130  int nrefs;
131 #endif
132 };
133 #endif /* _RPMSQL_INTERNAL */
134 
135 #ifdef _RPMVT_INTERNAL
136 struct rpmvt_vtab_s {
137  const void * pModule;
138  int nRef;
139  char * zErrMsg;
140 };
141 struct rpmvt_s {
142  struct rpmvt_vtab_s _base; /* for sqlite */
143  void * db; /* SQL database handle. */
144 
145  int argc;
146  const char ** argv;
147 
148  int nfields;
149  const char ** fields;
150 
151  int ncols; /* No. of column items. */
152  const char ** cols; /* Column headers/types. */
153 
154  int ac;
155  const char ** av;
156 
157  int debug;
158 
159  void * _ts;
160  void * _gi;
161  void * _h;
162 
163  rpmvd vd; /* Data object. */
164 };
165 struct rpmVT_s {
166  struct rpmioItem_s _item;
167  struct rpmvt_s vt;
168 #if defined(__LCLINT__)
169 /*@refs@*/
170  int nrefs;
171 #endif
172 };
173 struct rpmvd_s {
174  const char * dbpath;
175  const char * prefix;
176  const char * split;
177  const char * parse;
178  const char * regex;
179  int fx;
180  int idx;
181 };
182 #endif /* _RPMVT_INTERNAL */
183 
184 #ifdef _RPMVC_INTERNAL
185 struct rpmvc_cursor_s {
186  const void * pVTab;
187 };
188 struct rpmvc_s {
189  struct rpmvc_cursor_s _base;/* for sqlite */
190  rpmvt vt;
191  int ix;
192  int nrows;
193  int debug;
194  rpmvd vd;
195 };
196 struct rpmVC_s {
197  struct rpmioItem_s _item;
198  struct rpmvc_s vc;
199 #if defined(__LCLINT__)
200 /*@refs@*/
201  int nrefs;
202 #endif
203 };
204 #endif /* _RPMVC_INTERNAL */
205 
206 #ifdef __cplusplus
207 extern "C" {
208 #endif
209 
218 int rpmsqlCmd(rpmsql sql, const char * msg, /*@null@*/ void * _db,
219  /*@returned@*/ int rc)
220  /*@globals fileSystem @*/
221  /*@modifies fileSystem @*/;
222 
228 /*@unused@*/ /*@null@*/
229 rpmsql rpmsqlUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmsql sql)
230  /*@modifies sql @*/;
231 #define rpmsqlUnlink(_sql) \
232  ((rpmsql)rpmioUnlinkPoolItem((rpmioItem)(_sql), __FUNCTION__, __FILE__, __LINE__))
233 
239 /*@unused@*/ /*@newref@*/ /*@null@*/
240 rpmsql rpmsqlLink (/*@null@*/ rpmsql sql)
241  /*@modifies sql @*/;
242 #define rpmsqlLink(_sql) \
243  ((rpmsql)rpmioLinkPoolItem((rpmioItem)(_sql), __FUNCTION__, __FILE__, __LINE__))
244 
250 /*@null@*/
251 rpmsql rpmsqlFree(/*@killref@*/ /*@null@*/rpmsql sql)
252  /*@globals fileSystem @*/
253  /*@modifies sql, fileSystem @*/;
254 #define rpmsqlFree(_sql) \
255  ((rpmsql)rpmioFreePoolItem((rpmioItem)(_sql), __FUNCTION__, __FILE__, __LINE__))
256 
263 /*@newref@*/ /*@null@*/
264 rpmsql rpmsqlNew(/*@null@*/ char ** av, uint32_t flags)
265  /*@globals fileSystem, internalState @*/
266  /*@modifies fileSystem, internalState @*/;
267 
274 /*@null@*/
275 const char ** rpmsqlArgv(/*@null@*/ rpmsql sql, /*@null@*/ int * argcp)
276  /*@globals fileSystem, internalState @*/
277  /*@modifies fileSystem, internalState @*/;
278 
293 rpmRC rpmsqlRun(rpmsql sql, /*@null@*/ const char * str,
294  /*@null@*/ const char ** resultp)
295  /*@globals fileSystem, internalState @*/
296  /*@modifies sql, *resultp, fileSystem, internalState @*/;
297 
298 #ifdef _RPMSQL_INTERNAL
299 typedef struct rpmsqlCF_s * rpmsqlCF;
300 struct rpmsqlCF_s {
301  const char * zName;
302  int8_t nArg;
303  uint8_t argType; /* 0: none. 1: db 2: (-1) */
304  uint8_t eTextRep; /* SQLITE_UTF8 or SQLITE_UTF16 */
305  uint8_t needCollSeq;
306  void (*xFunc)(); /* (sqlite3_context *, int, sqlite3_value **); */
307  void (*xStep)(); /* (sqlite3_context *, int, sqlite3_value **); */
308  void (*xFinal)(); /* (sqlite3_context *); */
309 };
310 
316 int _rpmsqlLoadCFT(rpmsql sql, /*@null@*/ void * _CF)
317  /*@*/;
318 
319 typedef struct sqlite3_module * rpmsqlVM;
320 typedef struct rpmsqlVMT_s * rpmsqlVMT;
321 
322 struct rpmsqlVMT_s {
323  const char * zName;
324  const rpmsqlVM module;
325  void * data;
326 };
327 
334 int _rpmsqlLoadVMT(void * _db, rpmsqlVMT _VMT)
335  /*@*/;
336 #endif /* _RPMSQL_INTERNAL */
337 
338 #ifdef _RPMVT_INTERNAL
339 
344 /*@unused@*/ /*@null@*/
345 rpmvt rpmvtUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmvt vt)
346  /*@modifies vt @*/;
347 #define rpmvtUnlink(_vt) \
348  ((rpmvt)(rpmioUnlinkPoolItem(((rpmioItem)(_vt))-1, __FUNCTION__, __FILE__, __LINE__)+1))
349 
355 /*@unused@*/ /*@newref@*/ /*@null@*/
356 rpmvt rpmvtLink (/*@null@*/ rpmvt vt)
357  /*@modifies vt @*/;
358 #define rpmvtLink(_vt) \
359  ((rpmvt)(rpmioLinkPoolItem(((rpmioItem)(_vt))-1, __FUNCTION__, __FILE__, __LINE__)+1))
360 
366 /*@null@*/
367 rpmvt rpmvtFree(/*@killref@*/ /*@null@*/rpmvt vt)
368  /*@globals fileSystem @*/
369  /*@modifies vt, fileSystem @*/;
370 #define rpmvtFree(_vt) \
371  ((rpmvt)rpmioFreePoolItem(((rpmioItem)(_vt))-1, __FUNCTION__, __FILE__, __LINE__))
372 
373 int rpmvtLoadArgv(rpmvt vt, rpmvt * vtp)
374  /*@*/;
375 rpmvt rpmvtNew(void * db, void * pModule, const char *const *argv, rpmvd vd)
376  /*@*/;
377 
388 int rpmvtCreate(void * _db, void * pAux,
389  int argc, const char *const * argv,
390  rpmvt * vtp, char ** pzErr)
391  /*@*/;
392 
403 int rpmvtConnect(void * _db, void * pAux,
404  int argc, const char *const * argv,
405  rpmvt * vtp, char ** pzErr)
406  /*@*/;
407 
414 int rpmvtBestIndex(rpmvt vt, void * _pInfo)
415  /*@*/;
416 
422 int rpmvtDisconnect(rpmvt vt)
423  /*@*/;
424 
430 int rpmvtDestroy(rpmvt vt)
431  /*@*/;
432 
441 int rpmvtUpdate(rpmvt vt, int argc, rpmvArg * _argv, int64_t * pRowid)
442  /*@*/;
443 
449 int rpmvtBegin(rpmvt vt)
450  /*@*/;
451 
457 int rpmvtSync(rpmvt vt)
458  /*@*/;
459 
465 int rpmvtCommit(rpmvt vt)
466  /*@*/;
467 
473 int rpmvtRollback(rpmvt vt)
474  /*@*/;
475 
485 int rpmvtFindFunction(rpmvt vt, int nArg, const char * zName,
486  void (**pxFunc)(void *, int, rpmvArg *),
487  void ** ppArg)
488  /*@*/;
489 
496 int rpmvtRename(rpmvt vt, const char * zNew)
497  /*@*/;
498 #endif /* _RPMVT_INTERNAL */
499 
500 #ifdef _RPMVC_INTERNAL
501 
506 /*@unused@*/ /*@null@*/
507 rpmvc rpmvcUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmvc vc)
508  /*@modifies vc @*/;
509 #define rpmvcUnlink(_vc) \
510  ((rpmvc)(rpmioUnlinkPoolItem(((rpmioItem)(_vc))-1, __FUNCTION__, __FILE__, __LINE__)+1))
511 
517 /*@unused@*/ /*@newref@*/ /*@null@*/
518 rpmvc rpmvcLink (/*@null@*/ rpmvc vc)
519  /*@modifies vc @*/;
520 #define rpmvcLink(_vc) \
521  ((rpmvc)(rpmioLinkPoolItem(((rpmioItem)(_vc))-1, __FUNCTION__, __FILE__, __LINE__)+1))
522 
528 /*@null@*/
529 rpmvc rpmvcFree(/*@killref@*/ /*@null@*/rpmvc vc)
530  /*@globals fileSystem @*/
531  /*@modifies vc, fileSystem @*/;
532 #define rpmvcFree(_vc) \
533  ((rpmvc)rpmioFreePoolItem(((rpmioItem)(_vc))-1, __FUNCTION__, __FILE__, __LINE__))
534 
535 rpmvc rpmvcNew(rpmvt vt, int nrows)
536  /*@*/;
537 
544 int rpmvcOpen(rpmvt vt, rpmvc * vcp)
545  /*@*/;
546 
552 int rpmvcClose(rpmvc vc)
553  /*@*/;
554 
564 int rpmvcFilter(rpmvc vc, int idxNum, const char * idxStr,
565  int argc, rpmvArg * _argv)
566  /*@*/;
567 
573 int rpmvcNext(rpmvc vc)
574  /*@*/;
575 
581 int rpmvcEof(rpmvc vc)
582  /*@*/;
583 
591 int rpmvcColumn(rpmvc vc, void * _pContext, int colx)
592  /*@*/;
593 
600 int rpmvcRowid(rpmvc vc, int64_t * pRowid)
601  /*@*/;
602 
603 #endif /* _RPMVC_INTERNAL */
604 
605 #ifdef __cplusplus
606 }
607 #endif
608 
609 #endif /* RPMSQL_H */
volatile int _rpmsqlSeenInterrupt
Definition: rpmsql.c:55
#define rpmsqlUnlink(_sql)
Definition: rpmsql.h:231
struct rpmsql_s * rpmsql
Definition: rpmsql.h:18
#define rpmsqlLink(_sql)
Definition: rpmsql.h:242
int rpmsqlCmd(rpmsql sql, const char *msg, void *_db, int rc)
Check sqlite3 return code, displaying error messages.
struct rpmvd_s * rpmvd
Definition: rpmsql.h:14
struct rpmvt_s * rpmvt
Definition: rpmsql.h:17
int _rpmvc_debug
Definition: rpmsql.c:49
rpmvt rpmvtNew(void *db, void *pModule, const char *const *argv, rpmvd vd)
Definition: rpmsql.c:108
int _rpmvt_debug
Definition: rpmsql.c:46
The FD_t File Handle data structure.
rpmsql _rpmsqlI
Definition: rpmsql.c:52
#define rpmsqlFree(_sql)
Definition: rpmsql.h:254
rpmRC rpmsqlRun(rpmsql sql, const char *str, const char **resultp)
Execute sql from STRING | FILE | STDIN | INTERACTIVE.
Definition: rpmsql.c:5397
enum rpmRC_e rpmRC
RPM return codes.
static const char * prefix[]
Tables for prefixing and suffixing patterns, according to the -w, -x, and -F options.
Definition: rpmgrep.c:183
rpmvc rpmvcNew(rpmvt vt, int nrows)
Definition: rpmsql.c:615
rpmsql rpmsqlNew(char **av, uint32_t flags)
Create and load a sql interpreter.
Definition: rpmsql.c:5295
struct rpmiob_s * rpmiob
Definition: rpmiotypes.h:57
int _rpmsql_debug
Definition: rpmsql.c:43
const char ** rpmsqlArgv(rpmsql sql, int *argcp)
Return arguments from a sql interpreter.
Definition: rpmsql.c:5225
void * rpmvArg
Definition: rpmsql.h:12
struct rpmvc_s * rpmvc
Definition: rpmsql.h:16