RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 18-Mar-2012 16:47:06 Branch: rpm-5_4 Handle: 2012031815470600 Modified files: (Branch: rpm-5_4) rpm/rpmio rpmodbc.c rpmodbc.h todbc.c Log: - odbc: use a uri to carry around connect info. Summary: Revision Changes Path 1.1.2.4 +41 -13 rpm/rpmio/rpmodbc.c 1.1.2.4 +2 -4 rpm/rpmio/rpmodbc.h 1.1.2.3 +15 -9 rpm/rpmio/todbc.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/rpmio/rpmodbc.c ============================================================================ $ cvs diff -u -r1.1.2.3 -r1.1.2.4 rpmodbc.c --- rpm/rpmio/rpmodbc.c 18 Mar 2012 14:02:14 -0000 1.1.2.3 +++ rpm/rpmio/rpmodbc.c 18 Mar 2012 15:47:06 -0000 1.1.2.4 @@ -11,6 +11,7 @@ #include <rpmiotypes.h> #include <rpmio.h> /* for *Pool methods */ #include <rpmlog.h> +#include <rpmmacro.h> #include <rpmurl.h> #define _RPMODBC_INTERNAL @@ -29,15 +30,30 @@ /*==============================================================*/ -int odbcConnect(ODBC_t odbc, - const char * db, const char * u, const char * pw) +int odbcConnect(ODBC_t odbc, const char * uri) { + const char * db = NULL; + urlinfo u = NULL; int rc = -1; -fprintf(stderr, "--> %s(%p,%s,%s,%s)\n", __FUNCTION__, odbc, db, u, pw); - odbc->db = xstrdup(db); - odbc->u = xstrdup(u); - odbc->pw = xstrdup(pw); +fprintf(stderr, "--> %s(%p,%s)\n", __FUNCTION__, odbc, uri); + + if (uri) { + const char * dbpath = NULL; + int ut = urlPath(uri, &dbpath); +assert(ut == URL_IS_MYSQL || ut == URL_IS_POSTGRES); + rc = urlSplit(uri, &u); + db = rpmExpand(u->scheme, "_", basename((char *)dbpath), NULL); + } else { + u = odbc->u; + db = xstrdup(odbc->db); + } +assert(u); +assert(db); + +fprintf(stderr, "\tdb: %s\n", db); +fprintf(stderr, "\t u: %s\n", u->user); +fprintf(stderr, "\tpw: %s\n", u->password); #if defined(WITH_UNIXODBC) assert(odbc->env); @@ -46,13 +62,15 @@ assert(odbc->dbc); } + /* XXX FIXME: odbc->u->user and odbc->u->password */ rc = SQLConnect(odbc->dbc, (SQLCHAR *) db, SQL_NTS, - (SQLCHAR *) u, SQL_NTS, - (SQLCHAR *) pw, SQL_NTS); + (SQLCHAR *) u->user, SQL_NTS, + (SQLCHAR *) u->password, SQL_NTS); #endif SPEW(0, rc, odbc); + db = _free(db); return rc; } @@ -293,10 +311,8 @@ } #endif - odbc->pw = _free(odbc->pw); - odbc->u = _free(odbc->u); odbc->db = _free(odbc->db); - + odbc->u = urlFree(odbc->u, __FUNCTION__); odbc->fn = _free(odbc->fn); } @@ -319,14 +335,26 @@ return odbc; } +static char * _odbc_uri = "mysql://luser:jasnl@localhost/test"; + ODBC_t odbcNew(const char * fn, int flags) { ODBC_t odbc = odbcGetPool(_odbcPool); - if (fn) - odbc->fn = xstrdup(fn); + if (fn == NULL) + fn = _odbc_uri; + odbc->fn = xstrdup(fn); odbc->flags = flags; + { const char * dbpath = NULL; + int ut = urlPath(fn, &dbpath); + urlinfo u = NULL; + int xx = urlSplit(fn, &u); +assert(ut == URL_IS_MYSQL || ut == URL_IS_POSTGRES); + odbc->db = rpmExpand(u->scheme, "_", basename((char *)dbpath), NULL); + odbc->u = urlLink(u, __FUNCTION__); + } + #if defined(WITH_UNIXODBC) SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &odbc->env); assert(odbc->env); @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmodbc.h ============================================================================ $ cvs diff -u -r1.1.2.3 -r1.1.2.4 rpmodbc.h --- rpm/rpmio/rpmodbc.h 18 Mar 2012 14:02:14 -0000 1.1.2.3 +++ rpm/rpmio/rpmodbc.h 18 Mar 2012 15:47:06 -0000 1.1.2.4 @@ -22,9 +22,8 @@ const char * fn; int flags; + void * u; const char * db; - const char * u; - const char * pw; void * env; void * dbc; @@ -92,8 +91,7 @@ /*@globals fileSystem, internalState @*/ /*@modifies fileSystem, internalState @*/; -int odbcConnect(ODBC_t odbc, - const char * db, const char * u, const char * pw) +int odbcConnect(ODBC_t odbc, /*@null@*/ const char * uri) /*@*/; int odbcDisconnect(ODBC_t odbc) @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/todbc.c ============================================================================ $ cvs diff -u -r1.1.2.2 -r1.1.2.3 todbc.c --- rpm/rpmio/todbc.c 18 Mar 2012 14:02:14 -0000 1.1.2.2 +++ rpm/rpmio/todbc.c 18 Mar 2012 15:47:06 -0000 1.1.2.3 @@ -19,10 +19,6 @@ static char * _odbc_uri = "mysql://luser:jasnl@localhost/test"; static int _odbc_flags = 0; -static char * _odbc_db = "mysql_test"; -static char * _odbc_u = "luser"; -static char * _odbc_pw = "jasnl"; - /*==============================================================*/ static int odbcOpen(ODBC_t odbc) @@ -90,8 +86,15 @@ /*==============================================================*/ -static struct poptOption rpmsvnOptionsTable[] = { - { "debug", 'd', POPT_ARG_VAL, &_rpmmg_debug, -1, NULL, NULL }, +static struct poptOption odbcOptionsTable[] = { + { NULL, 'f', POPT_ARG_INT, &_odbc_flags, -1, + NULL, NULL }, + + { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioAllPoptTable, 0, + N_("Common options for all rpmio executables:"), + NULL }, + + POPT_AUTOALIAS POPT_AUTOHELP POPT_TABLEEND }; @@ -99,8 +102,11 @@ int main(int argc, char *argv[]) { - poptContext con = rpmioInit(argc, argv, rpmsvnOptionsTable); - ODBC_t odbc = odbcNew(_odbc_uri, _odbc_flags); + poptContext con = rpmioInit(argc, argv, odbcOptionsTable); + char ** av = (char **) poptGetArgs(con); + int ac = argvCount((ARGV_t)av); + const char * _uri = (ac > 1 ? av[1] : _odbc_uri); + ODBC_t odbc = odbcNew(_uri, _odbc_flags); FILE * _odbc_fp = stderr; int rc = 0; int xx; @@ -108,7 +114,7 @@ rc = odbcListDrivers(odbc, _odbc_fp); rc = odbcListDataSources(odbc, _odbc_fp); - rc = odbcConnect(odbc, _odbc_db, _odbc_u, _odbc_pw); + rc = odbcConnect(odbc, _uri); xx = odbcColumns(odbc); odbc->ncols = odbcNCols(odbc); @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org