rpm  5.4.14
rpmsql.h
Go to the documentation of this file.
1 #ifndef rpmsql_h
2 #define RPMSQL_H
3 
8 #include <stdio.h>
9 
10 #include <rpmiotypes.h>
11 #include <rpmio.h>
12 #include <argv.h>
13 
14 typedef void * rpmvArg;
15 
16 typedef /*@abstract@*/ struct rpmvd_s * rpmvd;
17 
18 typedef /*@abstract@*/ struct rpmvc_s * rpmvc;
19 typedef /*@abstract@*/ struct rpmvt_s * rpmvt;
20 typedef /*@abstract@*/ /*@refcounted@*/ struct rpmsql_s * rpmsql;
21 
22 /*@unchecked@*/
23 extern int _rpmsql_debug;
24 
25 /*@unchecked@*/
26 extern int _rpmvt_debug;
27 
28 /*@unchecked@*/
29 extern int _rpmvc_debug;
30 
31 /*@unchecked@*/
32 extern rpmsql _rpmsqlI;
33 
34 /*@unchecked@*/
35 extern volatile int _rpmsqlSeenInterrupt;
36 
37 #if defined(_RPMSQL_INTERNAL)
38 
39 #define F_ISSET(_sql, _FLAG) ((_sql)->flags & (RPMSQL_FLAGS_##_FLAG))
40 #define SQLDBG(_l) if (_rpmsql_debug) fprintf _l
41 
45 enum rpmsqlFlags_e {
46  RPMSQL_FLAGS_NONE = 0,
47  RPMSQL_FLAGS_INTERACTIVE = (1 << 0), /* -interactive */
48  RPMSQL_FLAGS_BAIL = (1 << 1), /* -bail */
49  RPMSQL_FLAGS_NOLOAD = (1 << 2), /* -[no]load */
50  RPMSQL_FLAGS_CREATE = (1 << 3), /* -[no]create */
51 
52  RPMSQL_FLAGS_ECHO = (1 << 16), /* -echo */
53  RPMSQL_FLAGS_SHOWHDR = (1 << 17), /* -[no]header */
54  RPMSQL_FLAGS_WRITABLE = (1 << 18), /* PRAGMA writable_schema */
55 
56  RPMSQL_FLAGS_PROMPT = (1 << 24), /* STDIN from tty */
57 };
58 
62 enum rpmsqlModes_e {
63  RPMSQL_MODE_LINE = 0, /* One column per line. Blank line between records */
64  RPMSQL_MODE_COLUMN = 1, /* One record per line in neat columns */
65  RPMSQL_MODE_LIST = 2, /* One record per line with a separator */
66  RPMSQL_MODE_SEMI = 3, /* Same as MODE_LIST but append ";" to each line */
67  RPMSQL_MODE_HTML = 4, /* Generate an XHTML table */
68  RPMSQL_MODE_INSERT = 5, /* Generate SQL "insert" statements */
69  RPMSQL_MODE_TCL = 6, /* Generate ANSI-C or TCL quoted elements */
70  RPMSQL_MODE_CSV = 7, /* Quote strings, numbers are plain */
71  RPMSQL_MODE_EXPLAIN = 8, /* Like MODE_COLUMN, but do not truncate data */
72 };
73 
74 struct previous_mode {
75  int valid; /* Is there legit data in here? */
76  uint32_t mode;
77  uint32_t flags;
78  int colWidth[100];
79 };
80 
81 struct rpmsql_s {
82  struct rpmioItem_s _item;
83  uint32_t flags;
84  const char ** av;
86  void * I; /* The database (sqlite *) */
87 /*@null@*/
88  void * S; /* Current statement if any (sqlite3_stmt *) */
89 
90  const char * zInitFile; /* -init FILE */
91 
92  const char * zDbFilename; /* Name of the database file */
93  const char * zDestTable; /* Name of destination table iff MODE_INSERT */
94 
95  uint32_t mode; /* Operational mode. */
96 
97  int cnt; /* Number of records displayed so far */
98 
99  FD_t ifd; /* Read input here. */
100  FD_t ofd; /* Write output here */
101  FD_t lfd; /* Write log output here */
102  FD_t tfd; /* Write I/O traces here */
103  rpmiob iob; /* Output I/O buffer collector */
104 
105  int enableTimer; /* Timer enabled? */
106  struct rusage sBegin; /* Saved resource info for start. */
107 
108  /* Holds the mode information just before .explain ON */
109  struct previous_mode explainPrev;
110  char separator[20]; /* Separator character for MODE_LIST */
111  int colWidth[100]; /* Requested width of each column when in column mode */
112  int actualWidth[100]; /* Actual width of each column */
113  char nullvalue[20]; /* Text to print for NULL from the database */
114  const char * outfile; /* Filename for *out (NULL is stdout) */
115 
116  /* XXX INTERACTIVE cruft. */
117  const char * zHome; /* HOME */
118  const char * zInitrc; /* ~/.sqliterc */
119  const char * zHistory; /* ~/.sqlite_history */
120  const char * zPrompt; /* "sql> " */
121  const char * zContinue; /* "...> " */
122 
123  /* Sliding window input line buffer. */
124  char * buf;
125  size_t nbuf;
126 /*@null@*/
127  char * b;
128  size_t nb;
129 
130 #if defined(__LCLINT__)
131 /*@refs@*/
132  int nrefs;
133 #endif
134 };
135 #endif /* _RPMSQL_INTERNAL */
136 
137 #ifdef _RPMVT_INTERNAL
138 struct rpmvt_vtab_s {
139  const void * pModule;
140  int nRef;
141  char * zErrMsg;
142 };
143 struct rpmvt_s {
144  struct rpmvt_vtab_s _base; /* for sqlite */
145  void * db; /* SQL database handle. */
146 
147  int argc;
148  const char ** argv;
149 
150  int nfields;
151  const char ** fields;
152 
153  int ncols; /* No. of column items. */
154  const char ** cols; /* Column headers/types. */
155 
156  int ac;
157  const char ** av;
158 
159  int debug;
160 
161  void * _ts;
162  void * _gi;
163  void * _h;
164 
165  rpmvd vd; /* Data object. */
166 };
167 struct rpmVT_s {
168  struct rpmioItem_s _item;
169  struct rpmvt_s vt;
170 #if defined(__LCLINT__)
171 /*@refs@*/
172  int nrefs;
173 #endif
174 };
175 struct rpmvd_s {
176  const char * dbpath;
177  const char * prefix;
178  const char * split;
179  const char * parse;
180  const char * regex;
181  int fx;
182  int idx;
183 };
184 #endif /* _RPMVT_INTERNAL */
185 
186 #ifdef _RPMVC_INTERNAL
187 struct rpmvc_cursor_s {
188  const void * pVTab;
189 };
190 struct rpmvc_s {
191  struct rpmvc_cursor_s _base;/* for sqlite */
192  rpmvt vt;
193  int ix;
194  int nrows;
195  int debug;
196  rpmvd vd;
197 };
198 struct rpmVC_s {
199  struct rpmioItem_s _item;
200  struct rpmvc_s vc;
201 #if defined(__LCLINT__)
202 /*@refs@*/
203  int nrefs;
204 #endif
205 };
206 #endif /* _RPMVC_INTERNAL */
207 
208 #ifdef __cplusplus
209 extern "C" {
210 #endif
211 
220 int rpmsqlCmd(rpmsql sql, const char * msg, /*@null@*/ void * _db,
221  /*@returned@*/ int rc)
222  /*@globals fileSystem @*/
223  /*@modifies fileSystem @*/;
224 
230 /*@unused@*/ /*@null@*/
231 rpmsql rpmsqlUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmsql sql)
232  /*@modifies sql @*/;
233 #define rpmsqlUnlink(_sql) \
234  ((rpmsql)rpmioUnlinkPoolItem((rpmioItem)(_sql), __FUNCTION__, __FILE__, __LINE__))
235 
241 /*@unused@*/ /*@newref@*/ /*@null@*/
242 rpmsql rpmsqlLink (/*@null@*/ rpmsql sql)
243  /*@modifies sql @*/;
244 #define rpmsqlLink(_sql) \
245  ((rpmsql)rpmioLinkPoolItem((rpmioItem)(_sql), __FUNCTION__, __FILE__, __LINE__))
246 
252 /*@null@*/
253 rpmsql rpmsqlFree(/*@killref@*/ /*@null@*/rpmsql sql)
254  /*@globals fileSystem @*/
255  /*@modifies sql, fileSystem @*/;
256 #define rpmsqlFree(_sql) \
257  ((rpmsql)rpmioFreePoolItem((rpmioItem)(_sql), __FUNCTION__, __FILE__, __LINE__))
258 
265 /*@newref@*/ /*@null@*/
266 rpmsql rpmsqlNew(/*@null@*/ char ** av, uint32_t flags)
267  /*@globals fileSystem, internalState @*/
268  /*@modifies fileSystem, internalState @*/;
269 
276 /*@null@*/
277 const char ** rpmsqlArgv(/*@null@*/ rpmsql sql, /*@null@*/ int * argcp)
278  /*@globals fileSystem, internalState @*/
279  /*@modifies fileSystem, internalState @*/;
280 
295 rpmRC rpmsqlRun(rpmsql sql, /*@null@*/ const char * str,
296  /*@null@*/ const char ** resultp)
297  /*@globals fileSystem, internalState @*/
298  /*@modifies sql, *resultp, fileSystem, internalState @*/;
299 
300 #ifdef _RPMSQL_INTERNAL
301 typedef struct rpmsqlCF_s * rpmsqlCF;
302 struct rpmsqlCF_s {
303  const char * zName;
304  int8_t nArg;
305  uint8_t argType; /* 0: none. 1: db 2: (-1) */
306  uint8_t eTextRep; /* SQLITE_UTF8 or SQLITE_UTF16 */
307  uint8_t needCollSeq;
308  void (*xFunc)(); /* (sqlite3_context *, int, sqlite3_value **); */
309  void (*xStep)(); /* (sqlite3_context *, int, sqlite3_value **); */
310  void (*xFinal)(); /* (sqlite3_context *); */
311 };
312 
318 int _rpmsqlLoadCFT(rpmsql sql, /*@null@*/ void * _CF)
319  /*@*/;
320 
321 typedef struct sqlite3_module * rpmsqlVM;
322 typedef struct rpmsqlVMT_s * rpmsqlVMT;
323 
324 struct rpmsqlVMT_s {
325  const char * zName;
326  const rpmsqlVM module;
327  void * data;
328 };
329 
336 int _rpmsqlLoadVMT(void * _db, rpmsqlVMT _VMT)
337  /*@*/;
338 #endif /* _RPMSQL_INTERNAL */
339 
340 #ifdef _RPMVT_INTERNAL
341 
346 /*@unused@*/ /*@null@*/
347 rpmvt rpmvtUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmvt vt)
348  /*@modifies vt @*/;
349 #define rpmvtUnlink(_vt) \
350  ((rpmvt)(rpmioUnlinkPoolItem(((rpmioItem)(_vt))-1, __FUNCTION__, __FILE__, __LINE__)+1))
351 
357 /*@unused@*/ /*@newref@*/ /*@null@*/
358 rpmvt rpmvtLink (/*@null@*/ rpmvt vt)
359  /*@modifies vt @*/;
360 #define rpmvtLink(_vt) \
361  ((rpmvt)(rpmioLinkPoolItem(((rpmioItem)(_vt))-1, __FUNCTION__, __FILE__, __LINE__)+1))
362 
368 /*@null@*/
369 rpmvt rpmvtFree(/*@killref@*/ /*@null@*/rpmvt vt)
370  /*@globals fileSystem @*/
371  /*@modifies vt, fileSystem @*/;
372 #define rpmvtFree(_vt) \
373  ((rpmvt)rpmioFreePoolItem(((rpmioItem)(_vt))-1, __FUNCTION__, __FILE__, __LINE__))
374 
375 int rpmvtLoadArgv(rpmvt vt, rpmvt * vtp)
376  /*@*/;
377 rpmvt rpmvtNew(void * db, void * pModule, const char *const *argv, rpmvd vd)
378  /*@*/;
379 
390 int rpmvtCreate(void * _db, void * pAux,
391  int argc, const char *const * argv,
392  rpmvt * vtp, char ** pzErr)
393  /*@*/;
394 
405 int rpmvtConnect(void * _db, void * pAux,
406  int argc, const char *const * argv,
407  rpmvt * vtp, char ** pzErr)
408  /*@*/;
409 
416 int rpmvtBestIndex(rpmvt vt, void * _pInfo)
417  /*@*/;
418 
424 int rpmvtDisconnect(rpmvt vt)
425  /*@*/;
426 
432 int rpmvtDestroy(rpmvt vt)
433  /*@*/;
434 
443 int rpmvtUpdate(rpmvt vt, int argc, rpmvArg * _argv, int64_t * pRowid)
444  /*@*/;
445 
451 int rpmvtBegin(rpmvt vt)
452  /*@*/;
453 
459 int rpmvtSync(rpmvt vt)
460  /*@*/;
461 
467 int rpmvtCommit(rpmvt vt)
468  /*@*/;
469 
475 int rpmvtRollback(rpmvt vt)
476  /*@*/;
477 
487 int rpmvtFindFunction(rpmvt vt, int nArg, const char * zName,
488  void (**pxFunc)(void *, int, rpmvArg *),
489  void ** ppArg)
490  /*@*/;
491 
498 int rpmvtRename(rpmvt vt, const char * zNew)
499  /*@*/;
500 #endif /* _RPMVT_INTERNAL */
501 
502 #ifdef _RPMVC_INTERNAL
503 
508 /*@unused@*/ /*@null@*/
509 rpmvc rpmvcUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmvc vc)
510  /*@modifies vc @*/;
511 #define rpmvcUnlink(_vc) \
512  ((rpmvc)(rpmioUnlinkPoolItem(((rpmioItem)(_vc))-1, __FUNCTION__, __FILE__, __LINE__)+1))
513 
519 /*@unused@*/ /*@newref@*/ /*@null@*/
520 rpmvc rpmvcLink (/*@null@*/ rpmvc vc)
521  /*@modifies vc @*/;
522 #define rpmvcLink(_vc) \
523  ((rpmvc)(rpmioLinkPoolItem(((rpmioItem)(_vc))-1, __FUNCTION__, __FILE__, __LINE__)+1))
524 
530 /*@null@*/
531 rpmvc rpmvcFree(/*@killref@*/ /*@null@*/rpmvc vc)
532  /*@globals fileSystem @*/
533  /*@modifies vc, fileSystem @*/;
534 #define rpmvcFree(_vc) \
535  ((rpmvc)rpmioFreePoolItem(((rpmioItem)(_vc))-1, __FUNCTION__, __FILE__, __LINE__))
536 
537 rpmvc rpmvcNew(rpmvt vt, int nrows)
538  /*@*/;
539 
546 int rpmvcOpen(rpmvt vt, rpmvc * vcp)
547  /*@*/;
548 
554 int rpmvcClose(rpmvc vc)
555  /*@*/;
556 
566 int rpmvcFilter(rpmvc vc, int idxNum, const char * idxStr,
567  int argc, rpmvArg * _argv)
568  /*@*/;
569 
575 int rpmvcNext(rpmvc vc)
576  /*@*/;
577 
583 int rpmvcEof(rpmvc vc)
584  /*@*/;
585 
593 int rpmvcColumn(rpmvc vc, void * _pContext, int colx)
594  /*@*/;
595 
602 int rpmvcRowid(rpmvc vc, int64_t * pRowid)
603  /*@*/;
604 
605 #endif /* _RPMVC_INTERNAL */
606 
607 #ifdef __cplusplus
608 }
609 #endif
610 
611 #endif /* RPMSQL_H */
#define rpmsqlUnlink(_sql)
Definition: rpmsql.h:233
int _rpmvt_debug
Definition: rpmsql.c:46
struct rpmsql_s * rpmsql
Definition: rpmsql.h:20
#define rpmsqlLink(_sql)
Definition: rpmsql.h:244
static char *size_t nb
fgets(3) analogue that reads \ continuations.
Definition: macro.c:409
int rc
Definition: poptALL.c:670
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:16
int ac
Definition: rpmgrep.c:1431
argv
Definition: rpmmtree.c:3679
repo _ts
Definition: rpmrepo.c:164
static PyObject *char * mode
Definition: rpmfd-py.c:115
struct rpmiob_s * rpmiob
Definition: rpmiotypes.h:60
rpmsql rpmsqlNew(char **av, uint32_t flags)
Create and load a sql interpreter.
Definition: rpmsql.c:5300
enum rpmRC_e rpmRC
RPM return codes.
Definition: signature.c:616
int ix
Definition: rpmps-py.c:174
struct rpmvt_s * rpmvt
Definition: rpmsql.h:19
rpmvt rpmvtNew(void *db, void *pModule, const char *const *argv, rpmvd vd)
Definition: rpmsql.c:108
volatile int _rpmsqlSeenInterrupt
Definition: rpmsql.c:55
int _rpmvc_debug
Definition: rpmsql.c:49
The FD_t File Handle data structure.
rpmsql _rpmsqlI
Definition: rpmsql.c:52
#define rpmsqlFree(_sql)
Definition: rpmsql.h:256
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:617
int flags
Definition: fnmatch.c:282
const char * msg
Definition: rpmts-py.c:976
rpmRC rpmsqlRun(rpmsql sql, const char *str, const char **resultp)
Execute sql from STRING | FILE | STDIN | INTERACTIVE.
Definition: rpmsql.c:5404
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
Definition: spec.c:737
char * buf
Parse (and execute) macro undefinition.
Definition: macro.c:703
char * b
Definition: macro.c:746
int _rpmsql_debug
Definition: rpmsql.c:43
void * rpmvArg
Definition: rpmsql.h:14
const char ** av
Definition: rpmts-py.c:788
struct rpmvc_s * rpmvc
Definition: rpmsql.h:18
const char ** rpmsqlArgv(rpmsql sql, int *argcp)
Return arguments from a sql interpreter.
Definition: rpmsql.c:5230