RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: [email protected] Module: rpm Date: 07-Apr-2010 15:37:56 Branch: HEAD Handle: 2010040713375401 Modified files: rpm CHANGES rpm/rpmio librpmio.vers rpmsql.c rpmsql.h rpm/tools dbsql.c Log: - sqlite: haul out the construction scaffholding trash. Summary: Revision Changes Path 1.3307 +1 -0 rpm/CHANGES 2.168 +0 -6 rpm/rpmio/librpmio.vers 2.8 +21 -6 rpm/rpmio/rpmsql.c 2.8 +8 -57 rpm/rpmio/rpmsql.h 2.10 +6 -23 rpm/tools/dbsql.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.3306 -r1.3307 CHANGES --- rpm/CHANGES 7 Apr 2010 12:06:53 -0000 1.3306 +++ rpm/CHANGES 7 Apr 2010 13:37:54 -0000 1.3307 @@ -1,5 +1,6 @@ 5.2b1 -> 5.3a1 + - jbj: sqlite: haul out the construction scaffholding trash. - jbj: sqlite: return the output as the macro expansion value. - jbj: dbsql: incremental step toward the desired rpmsql object API. - jbj: rpmsql: add rc checking for sqlite3_foo() calls (a la rpmrepo.c). @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/librpmio.vers ============================================================================ $ cvs diff -u -r2.167 -r2.168 librpmio.vers --- rpm/rpmio/librpmio.vers 5 Apr 2010 21:27:56 -0000 2.167 +++ rpm/rpmio/librpmio.vers 7 Apr 2010 13:37:55 -0000 2.168 @@ -536,18 +536,12 @@ _sql; _rpmsqlI; _rpmsql_debug; - _rpmsqlOpenDB; _rpmsqlOptions; _rpmsqlSeenInterrupt; _rpmsqlShellStatic; - _rpmsqlShellCallback; - _rpmsqlShellExec; rpmsqlArgv; - rpmsqlInput; - rpmsqlMetaCommand; rpmsqlNew; rpmsqlRun; - rpmsqlRunFile; _rpmsquirrel_debug; rpmsquirrelNew; rpmsquirrelRun; @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmsql.c ============================================================================ $ cvs diff -u -r2.7 -r2.8 rpmsql.c --- rpm/rpmio/rpmsql.c 7 Apr 2010 12:06:54 -0000 2.7 +++ rpm/rpmio/rpmsql.c 7 Apr 2010 13:37:55 -0000 2.8 @@ -318,7 +318,7 @@ ** Make sure the database is open. If it is not, then open it. If ** the database fails to open, print an error message and exit. */ -int _rpmsqlOpenDB(rpmsql sql) +static int _rpmsqlOpenDB(rpmsql sql) { int rc = -1; /* assume failure */ #if defined(WITH_SQLITE) @@ -581,7 +581,7 @@ ** This is the callback routine that the shell ** invokes for each row of a query result. */ -int _rpmsqlShellCallback(void *pArg, int nArg, char **azArg, char **azCol, +static int _rpmsqlShellCallback(void *pArg, int nArg, char **azArg, char **azCol, int *aiType) { rpmsql sql = (rpmsql) pArg; @@ -987,7 +987,7 @@ ** function except it takes a slightly different callback ** and callback data argument. */ -int _rpmsqlShellExec(rpmsql sql, const char *zSql, +static int _rpmsqlShellExec(rpmsql sql, const char *zSql, int (*xCallback) (void *, int, char **, char **, int *), char **pzErrMsg ) @@ -1349,7 +1349,15 @@ "explain", }; -int rpmsqlMetaCommand(rpmsql sql, char *zLine) +/* forward ref @*/ +static int rpmsqlInput(rpmsql sql, void * _in); + +/** + * Process .foo SQLITE3 meta command. + * + * @return 0 on success, 1 on error, 2 to exit + */ +static int rpmsqlMetaCommand(rpmsql sql, char *zLine) { sqlite3 * db = (sqlite3 *)sql->I; int i = 1; @@ -2232,7 +2240,7 @@ ** ** Return the number of errors. */ -int rpmsqlInput(rpmsql sql, void * _in) +static int rpmsqlInput(rpmsql sql, void * _in) { FILE * in = (FILE *) _in; FILE * out = sql->out; @@ -2680,10 +2688,14 @@ #if defined(WITH_SQLITE) if (str != NULL) { - FILE * fp = NULL; const char * s = str; + FILE * fp = NULL; + + /* Ignore leading whitespace. */ while (*s && xisspace((int)*s)) s++; + + /* Perform the SQL operation(s). */ if (*s == '\0') { /* INTERACTIVE */ uint32_t _flags = sql->flags; FILE * _out = sql->out; @@ -2724,12 +2736,15 @@ } if (fp && fileno(fp) > STDERR_FILENO) (void) fclose(fp); + + /* Return the SQL output. */ if (sql->iob) { (void) rpmiobRTrim(sql->iob); SQLDBG((stderr, "==========\n%s\n==========\n", rpmiobStr(sql->iob))); if (resultp) *resultp = rpmiobStr(sql->iob); /* XXX strdup? */ } + } #endif /* WITH_SQLITE */ @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmsql.h ============================================================================ $ cvs diff -u -r2.7 -r2.8 rpmsql.h --- rpm/rpmio/rpmsql.h 7 Apr 2010 03:20:07 -0000 2.7 +++ rpm/rpmio/rpmsql.h 7 Apr 2010 13:37:55 -0000 2.8 @@ -167,22 +167,15 @@ /*...@globals fileSystem, internalState @*/ /*...@modifies fileSystem, internalState @*/; -#ifdef NOTYET /** - * Execute sql from a file. - * @param sql sql interpreter (NULL uses global interpreter) - * @param fn sql file to run (NULL returns RPMRC_FAIL) - * @param *resultp sql exec result - * @return RPMRC_OK on success - */ -rpmRC rpmsqlRunFile(rpmsql sql, /*...@null@*/ const char * fn, - /*...@null@*/ const char ** resultp) - /*...@globals fileSystem, internalState @*/ - /*...@modifies sql, fileSystem, internalState @*/; -#endif - -/** - * Execute sql string. + * Execute sql from STRING | FILE | STDIN | INTERACTIVE. + * + * The str argument is used to determine how it should be run: + * A leading '/' indicates a FILE, containing SQL commands. + * A "-" or "stdin" argument used STD for SQL commands. + * An empty "" string assumes INTERACTIVE, like STDIN but with prompts. + * Otherwise, the STRING argument is treated as a sql command. + * * @param sql sql interpreter (NULL uses global interpreter) * @param str sql string to execute (NULL returns RPMRC_FAIL) * @param *resultp sql interpreter result @@ -193,48 +186,6 @@ /*...@globals fileSystem, internalState @*/ /*...@modifies sql, *resultp, fileSystem, internalState @*/; -/** - * Process SQL input from a file. - * @param sql sql interpreter (NULL uses global interpreter) - * @param in file handle - * @return no. of errors. - */ -int rpmsqlInput(/*...@null@*/ rpmsql sql, void * _in) - /*...@*/; - -/** - * Process .foo SQLITE3 meat command. - * - * @return 0 on success, 1 on error, 2 to exit - */ -int rpmsqlMetaCommand(rpmsql sql, char * zLine) - /*...@*/; - -int _rpmsqlOpenDB(rpmsql sql) - /*...@*/; - -/* - ** This is the callback routine that the shell - ** invokes for each row of a query result. - */ -int _rpmsqlShellCallback(void *pArg, int nArg, char **azArg, char **azCol, - int *aiType) - /*...@*/; - -/* - ** Execute a statement or set of statements. Print - ** any result rows/columns depending on the current mode - ** set via the supplied callback. - ** - ** This is very similar to SQLite's built-in sqlite3_exec() - ** function except it takes a slightly different callback - ** and callback data argument. - */ -int _rpmsqlShellExec(rpmsql sql, const char * zSql, - int (*xCallback) (void *, int, char **, char **, int *), - char ** pzErrMsg) - /*...@*/; - #ifdef __cplusplus } #endif @@ . patch -p0 <<'@@ .' Index: rpm/tools/dbsql.c ============================================================================ $ cvs diff -u -r2.9 -r2.10 dbsql.c --- rpm/tools/dbsql.c 6 Apr 2010 20:12:25 -0000 2.9 +++ rpm/tools/dbsql.c 7 Apr 2010 13:37:55 -0000 2.10 @@ -152,27 +152,10 @@ memcpy(sql->separator, ",", 2); if (zFirstCmd) { - /* Run just the command that follows the database name - */ - if (zFirstCmd[0] == '.') { - ec = rpmsqlMetaCommand(sql, zFirstCmd); - goto exit; - } else { - _rpmsqlOpenDB(sql); - ec = _rpmsqlShellExec(sql, zFirstCmd, _rpmsqlShellCallback, &zErrMsg); - if (zErrMsg != 0) { - fprintf(stderr, "Error: %s\n", zErrMsg); - if (ec == 0) ec = 1; - goto exit; - } else if (ec != 0) { - fprintf(stderr, "Error: unable to process SQL \"%s\"\n", - zFirstCmd); - goto exit; - } - } + /* Run just the command that follows the database name */ + ec = (int) rpmsqlRun(NULL, zFirstCmd, NULL); /* FILE | STRING */ } else { - /* Run commands received from standard input - */ + /* Run commands received from standard input */ if (F_ISSET(sql, INTERACTIVE)) { extern char *db_full_version(int *, int *, int *, int *, int *); @@ -184,13 +167,13 @@ if (sql->zHistory) read_history(sql->zHistory); #endif - ec = rpmsqlInput(sql, NULL); + ec = (int) rpmsqlRun(NULL, "", NULL); /* INTERACTIVE */ if (sql->zHistory) { stifle_history(100); write_history(sql->zHistory); } } else { - ec = (int) rpmsqlRun(NULL, "", NULL); + ec = (int) rpmsqlRun(NULL, "-", NULL); /* STDIN */ } } @@ -199,7 +182,7 @@ zFirstCmd = _free(zFirstCmd); sql = rpmsqlFree(sql); - rpmioClean(); /* XXX 0x8000000 global newref */ + rpmioClean(); return ec; } @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository [email protected]
