rpm 5.3.7

rpmio/rpmsql.h

Go to the documentation of this file.
00001 #ifndef rpmsql_h
00002 #define RPMSQL_H
00003 
00008 #include <rpmiotypes.h>
00009 #include <rpmio.h>
00010 #include <argv.h>
00011 
00012 typedef void * rpmvArg;
00013 
00014 typedef /*@abstract@*/ struct rpmvd_s * rpmvd;
00015 
00016 typedef /*@abstract@*/ struct rpmvc_s * rpmvc;
00017 typedef /*@abstract@*/ struct rpmvt_s * rpmvt;
00018 typedef /*@abstract@*/ /*@refcounted@*/ struct rpmsql_s * rpmsql;
00019 
00020 /*@unchecked@*/
00021 extern int _rpmsql_debug;
00022 
00023 /*@unchecked@*/
00024 extern int _rpmvt_debug;
00025 
00026 /*@unchecked@*/
00027 extern int _rpmvc_debug;
00028 
00029 /*@unchecked@*/
00030 extern rpmsql _rpmsqlI;
00031 
00032 /*@unchecked@*/
00033 extern volatile int _rpmsqlSeenInterrupt;
00034 
00035 #if defined(_RPMSQL_INTERNAL)
00036 
00037 #define F_ISSET(_sql, _FLAG) ((_sql)->flags & (RPMSQL_FLAGS_##_FLAG))
00038 #define SQLDBG(_l) if (_rpmsql_debug) fprintf _l
00039 
00043 enum rpmsqlFlags_e {
00044     RPMSQL_FLAGS_NONE           = 0,
00045     RPMSQL_FLAGS_INTERACTIVE    = (1 <<  0),    /*    -interactive */
00046     RPMSQL_FLAGS_BAIL           = (1 <<  1),    /*    -bail */
00047     RPMSQL_FLAGS_NOLOAD         = (1 <<  2),    /*    -[no]load */
00048 
00049     RPMSQL_FLAGS_ECHO           = (1 << 16),    /*    -echo */
00050     RPMSQL_FLAGS_SHOWHDR        = (1 << 17),    /*    -[no]header */
00051     RPMSQL_FLAGS_WRITABLE       = (1 << 18),    /* PRAGMA writable_schema */
00052 
00053     RPMSQL_FLAGS_PROMPT         = (1 << 24),    /* STDIN from tty */
00054 };
00055 
00059 enum rpmsqlModes_e {
00060     RPMSQL_MODE_LINE    = 0,    /* One column per line.  Blank line between records */
00061     RPMSQL_MODE_COLUMN  = 1,    /* One record per line in neat columns */
00062     RPMSQL_MODE_LIST    = 2,    /* One record per line with a separator */
00063     RPMSQL_MODE_SEMI    = 3,    /* Same as MODE_LIST but append ";" to each line */
00064     RPMSQL_MODE_HTML    = 4,    /* Generate an XHTML table */
00065     RPMSQL_MODE_INSERT  = 5,    /* Generate SQL "insert" statements */
00066     RPMSQL_MODE_TCL     = 6,    /* Generate ANSI-C or TCL quoted elements */
00067     RPMSQL_MODE_CSV     = 7,    /* Quote strings, numbers are plain */
00068     RPMSQL_MODE_EXPLAIN = 8,    /* Like MODE_COLUMN, but do not truncate data */
00069 };
00070 
00071 struct previous_mode {
00072     int valid;                  /* Is there legit data in here? */
00073     uint32_t mode;
00074     uint32_t flags;
00075     int colWidth[100];
00076 };
00077 
00078 struct rpmsql_s {
00079     struct rpmioItem_s _item;   
00080     uint32_t flags;             
00081     const char ** av;           
00083     void * I;                   /* The database (sqlite *) */
00084 /*@null@*/
00085     void * S;                   /* Current statement if any (sqlite3_stmt *) */
00086 
00087     const char * zInitFile;     /*    -init FILE */
00088 
00089     const char * zDbFilename;   /* Name of the database file */
00090     const char * zDestTable;    /* Name of destination table iff MODE_INSERT */
00091 
00092     uint32_t mode;              /* Operational mode. */
00093 
00094     int cnt;                    /* Number of records displayed so far */
00095 
00096     FD_t ifd;                   /* Read input here. */
00097     FD_t ofd;                   /* Write output here */
00098     FD_t lfd;                   /* Write log output here */
00099     FD_t tfd;                   /* Write I/O traces here */
00100     rpmiob iob;                 /* Output I/O buffer collector */
00101 
00102     int enableTimer;            /* Timer enabled? */
00103     struct rusage sBegin;       /* Saved resource info for start. */
00104 
00105         /* Holds the mode information just before .explain ON */
00106     struct previous_mode explainPrev;
00107     char separator[20];         /* Separator character for MODE_LIST */
00108     int colWidth[100];          /* Requested width of each column when in column mode */
00109     int actualWidth[100];       /* Actual width of each column */
00110     char nullvalue[20];         /* Text to print for NULL from the database */
00111     const char * outfile;       /* Filename for *out (NULL is stdout) */
00112 
00113     /* XXX INTERACTIVE cruft. */
00114     const char * zHome;         /* HOME */
00115     const char * zInitrc;       /* ~/.sqliterc */
00116     const char * zHistory;      /* ~/.sqlite_history */
00117     const char * zPrompt;       /* "sql> " */
00118     const char * zContinue;     /* "...> " */
00119 
00120     /* Sliding window input line buffer. */
00121     char * buf;
00122     size_t nbuf;
00123 /*@null@*/
00124     char * b;
00125     size_t nb;
00126 #if defined(__LCLINT__)
00127 /*@refs@*/
00128     int nrefs;                  
00129 #endif
00130 };
00131 #endif /* _RPMSQL_INTERNAL */
00132 
00133 #ifdef  _RPMVT_INTERNAL
00134 struct rpmvt_vtab_s {
00135     const void * pModule;
00136     int nRef;
00137     char * zErrMsg;
00138 };
00139 struct rpmvt_s {
00140     struct rpmvt_vtab_s _base;  /* for sqlite */
00141     void * db;                  /* SQL database handle. */
00142 
00143     int argc;
00144     const char ** argv;
00145 
00146     int nfields;
00147     const char ** fields;
00148 
00149     int ncols;                  /* No. of column items. */
00150     const char ** cols;         /* Column headers/types. */
00151 
00152     int ac;
00153     const char ** av;
00154 
00155     int debug;
00156 
00157     void * _ts;
00158     void * _gi;
00159     void * _h;
00160 
00161     rpmvd vd;           /* Data object. */
00162 };
00163 struct rpmVT_s {
00164     struct rpmioItem_s _item;   
00165     struct rpmvt_s vt;
00166 #if defined(__LCLINT__)
00167 /*@refs@*/
00168     int nrefs;                  
00169 #endif
00170 };
00171 struct rpmvd_s {
00172     const char * dbpath;
00173     const char * prefix;
00174     const char * split;
00175     const char * parse;
00176     const char * regex;
00177     int fx;                     
00178     int idx;
00179 };
00180 #endif  /* _RPMVT_INTERNAL */
00181 
00182 #ifdef  _RPMVC_INTERNAL
00183 struct rpmvc_cursor_s {
00184     const void * pVTab;
00185 };
00186 struct rpmvc_s {
00187     struct rpmvc_cursor_s _base;/* for sqlite */
00188     rpmvt vt;                   
00189     int ix;                     
00190     int nrows;                  
00191     int debug;
00192     rpmvd vd;                   
00193 };
00194 struct rpmVC_s {
00195     struct rpmioItem_s _item;   
00196     struct rpmvc_s vc;
00197 #if defined(__LCLINT__)
00198 /*@refs@*/
00199     int nrefs;                  
00200 #endif
00201 };
00202 #endif  /* _RPMVC_INTERNAL */
00203 
00204 #ifdef __cplusplus
00205 extern "C" {
00206 #endif
00207 
00216 int rpmsqlCmd(rpmsql sql, const char * msg, /*@null@*/ void * _db,
00217                 /*@returned@*/ int rc)
00218         /*@globals fileSystem @*/
00219         /*@modifies fileSystem @*/;
00220 
00226 /*@unused@*/ /*@null@*/
00227 rpmsql rpmsqlUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmsql sql)
00228         /*@modifies sql @*/;
00229 #define rpmsqlUnlink(_sql)      \
00230     ((rpmsql)rpmioUnlinkPoolItem((rpmioItem)(_sql), __FUNCTION__, __FILE__, __LINE__))
00231 
00237 /*@unused@*/ /*@newref@*/ /*@null@*/
00238 rpmsql rpmsqlLink (/*@null@*/ rpmsql sql)
00239         /*@modifies sql @*/;
00240 #define rpmsqlLink(_sql)        \
00241     ((rpmsql)rpmioLinkPoolItem((rpmioItem)(_sql), __FUNCTION__, __FILE__, __LINE__))
00242 
00248 /*@null@*/
00249 rpmsql rpmsqlFree(/*@killref@*/ /*@null@*/rpmsql sql)
00250         /*@globals fileSystem @*/
00251         /*@modifies sql, fileSystem @*/;
00252 #define rpmsqlFree(_sql)        \
00253     ((rpmsql)rpmioFreePoolItem((rpmioItem)(_sql), __FUNCTION__, __FILE__, __LINE__))
00254 
00261 /*@newref@*/ /*@null@*/
00262 rpmsql rpmsqlNew(/*@null@*/ char ** av, uint32_t flags)
00263         /*@globals fileSystem, internalState @*/
00264         /*@modifies fileSystem, internalState @*/;
00265 
00272 /*@null@*/
00273 const char ** rpmsqlArgv(/*@null@*/ rpmsql sql, /*@null@*/ int * argcp)
00274         /*@globals fileSystem, internalState @*/
00275         /*@modifies fileSystem, internalState @*/;
00276 
00291 rpmRC rpmsqlRun(rpmsql sql, /*@null@*/ const char * str,
00292                 /*@null@*/ const char ** resultp)
00293         /*@globals fileSystem, internalState @*/
00294         /*@modifies sql, *resultp, fileSystem, internalState @*/;
00295 
00296 #ifdef  _RPMSQL_INTERNAL
00297 typedef struct sqlite3_module * rpmsqlVM;
00298 typedef struct rpmsqlVMT_s * rpmsqlVMT;
00299 
00300 struct rpmsqlVMT_s {
00301     const char * zName;
00302     const rpmsqlVM module;
00303     void * data;
00304 };
00305 
00312 int _rpmsqlLoadVMT(void * _db, rpmsqlVMT _VMT)
00313         /*@*/;
00314 #endif  /* _RPMSQL_INTERNAL */
00315 
00316 #ifdef  _RPMVT_INTERNAL
00317 
00322 /*@unused@*/ /*@null@*/
00323 rpmvt rpmvtUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmvt vt)
00324         /*@modifies vt @*/;
00325 #define rpmvtUnlink(_vt)        \
00326     ((rpmvt)(rpmioUnlinkPoolItem(((rpmioItem)(_vt))-1, __FUNCTION__, __FILE__, __LINE__)+1))
00327 
00333 /*@unused@*/ /*@newref@*/ /*@null@*/
00334 rpmvt rpmvtLink (/*@null@*/ rpmvt vt)
00335         /*@modifies vt @*/;
00336 #define rpmvtLink(_vt)  \
00337     ((rpmvt)(rpmioLinkPoolItem(((rpmioItem)(_vt))-1, __FUNCTION__, __FILE__, __LINE__)+1))
00338 
00344 /*@null@*/
00345 rpmvt rpmvtFree(/*@killref@*/ /*@null@*/rpmvt vt)
00346         /*@globals fileSystem @*/
00347         /*@modifies vt, fileSystem @*/;
00348 #define rpmvtFree(_vt)  \
00349     ((rpmvt)rpmioFreePoolItem(((rpmioItem)(_vt))-1, __FUNCTION__, __FILE__, __LINE__))
00350 
00351 int rpmvtLoadArgv(rpmvt vt, rpmvt * vtp)
00352         /*@*/;
00353 rpmvt rpmvtNew(void * db, void * pModule, const char *const *argv, rpmvd vd)
00354         /*@*/;
00355 
00366 int rpmvtCreate(void * _db, void * pAux,
00367                 int argc, const char *const * argv,
00368                 rpmvt * vtp, char ** pzErr)
00369         /*@*/;
00370 
00381 int rpmvtConnect(void * _db, void * pAux,
00382                 int argc, const char *const * argv,
00383                 rpmvt * vtp, char ** pzErr)
00384         /*@*/;
00385 
00392 int rpmvtBestIndex(rpmvt vt, void * _pInfo)
00393         /*@*/;
00394 
00400 int rpmvtDisconnect(rpmvt vt)
00401         /*@*/;
00402 
00408 int rpmvtDestroy(rpmvt vt)
00409         /*@*/;
00410 
00419 int rpmvtUpdate(rpmvt vt, int argc, rpmvArg * _argv, int64_t * pRowid)
00420         /*@*/;
00421 
00427 int rpmvtBegin(rpmvt vt)
00428         /*@*/;
00429 
00435 int rpmvtSync(rpmvt vt)
00436         /*@*/;
00437 
00443 int rpmvtCommit(rpmvt vt)
00444         /*@*/;
00445 
00451 int rpmvtRollback(rpmvt vt)
00452         /*@*/;
00453 
00463 int rpmvtFindFunction(rpmvt vt, int nArg, const char * zName,
00464                 void (**pxFunc)(void *, int, rpmvArg *),
00465                 void ** ppArg)
00466         /*@*/;
00467 
00474 int rpmvtRename(rpmvt vt, const char * zNew)
00475         /*@*/;
00476 #endif  /* _RPMVT_INTERNAL */
00477 
00478 #ifdef  _RPMVC_INTERNAL
00479 
00484 /*@unused@*/ /*@null@*/
00485 rpmvc rpmvcUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmvc vc)
00486         /*@modifies vc @*/;
00487 #define rpmvcUnlink(_vc)        \
00488     ((rpmvc)(rpmioUnlinkPoolItem(((rpmioItem)(_vc))-1, __FUNCTION__, __FILE__, __LINE__)+1))
00489 
00495 /*@unused@*/ /*@newref@*/ /*@null@*/
00496 rpmvc rpmvcLink (/*@null@*/ rpmvc vc)
00497         /*@modifies vc @*/;
00498 #define rpmvcLink(_vc)  \
00499     ((rpmvc)(rpmioLinkPoolItem(((rpmioItem)(_vc))-1, __FUNCTION__, __FILE__, __LINE__)+1))
00500 
00506 /*@null@*/
00507 rpmvc rpmvcFree(/*@killref@*/ /*@null@*/rpmvc vc)
00508         /*@globals fileSystem @*/
00509         /*@modifies vc, fileSystem @*/;
00510 #define rpmvcFree(_vc)  \
00511     ((rpmvc)rpmioFreePoolItem(((rpmioItem)(_vc))-1, __FUNCTION__, __FILE__, __LINE__))
00512 
00513 rpmvc rpmvcNew(rpmvt vt, int nrows)
00514         /*@*/;
00515 
00522 int rpmvcOpen(rpmvt vt, rpmvc * vcp)
00523         /*@*/;
00524 
00530 int rpmvcClose(rpmvc vc)
00531         /*@*/;
00532 
00542 int rpmvcFilter(rpmvc vc, int idxNum, const char * idxStr,
00543                 int argc, rpmvArg * _argv)
00544         /*@*/;
00545 
00551 int rpmvcNext(rpmvc vc)
00552         /*@*/;
00553 
00559 int rpmvcEof(rpmvc vc)
00560         /*@*/;
00561 
00569 int rpmvcColumn(rpmvc vc, void * _pContext, int colx)
00570         /*@*/;
00571 
00578 int rpmvcRowid(rpmvc vc, int64_t * pRowid)
00579         /*@*/;
00580 
00581 #endif  /* _RPMVC_INTERNAL */
00582 
00583 #ifdef __cplusplus
00584 }
00585 #endif
00586 
00587 #endif /* RPMSQL_H */