Remove the static variable from API, example updates.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 18 Mar 2010 18:38:35 +0000 (18:38 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 18 Mar 2010 18:38:35 +0000 (18:38 +0000)
org.glite.lbjp-common.db/Makefile
org.glite.lbjp-common.db/examples/db_expire.c
org.glite.lbjp-common.db/examples/db_test.c
org.glite.lbjp-common.db/interface/db-int.h
org.glite.lbjp-common.db/interface/db.h
org.glite.lbjp-common.db/src/db-mysql.c
org.glite.lbjp-common.db/src/db-pg.c
org.glite.lbjp-common.db/src/db.c

index e9f6699..aa39082 100644 (file)
@@ -169,7 +169,7 @@ install: all
        ${INSTALL} -m 644 ${top_srcdir}/interface/${HDRS} ${PREFIX}/include/${globalprefix}/${lbutilsprefix}
 
 clean:
-       rm -rvf *.o *.lo .libs lib* *.c *.h *.dox C/ CPP/
+       rm -rvf *.o *.lo *.loT .libs lib* *.c *.h *.dox C/ CPP/
        rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/
        rm -rvf db_expire db_test db_test_mysql db_test_psql
 
index b30e6ba..3761b48 100644 (file)
@@ -97,7 +97,7 @@ int main(int argn __attribute((unused)), char *argv[]) {
 
        // init
        dprintf(("connecting to %s...\n", cs));
-       if (glite_lbu_InitDBContext(&ctx, GLITE_LBU_DB_BACKEND_MYSQL) != 0) {
+       if (glite_lbu_InitDBContext(&ctx, GLITE_LBU_DB_BACKEND_MYSQL, NULL) != 0) {
                print_error(ctx);
                goto failctx;
        }
index 71ef73a..da9f799 100644 (file)
@@ -124,7 +124,7 @@ int main(int argn __attribute((unused)), char *argv[]) {
 
        // init
        dprintf(("connecting to %s...\n", cs));
-       if (glite_lbu_InitDBContext(&ctx, DB_TEST_BACKEND) != 0) goto failctx;
+       if (glite_lbu_InitDBContext(&ctx, DB_TEST_BACKEND, NULL) != 0) goto failctx;
        if (glite_lbu_DBConnect(ctx, cs) != 0) goto failctx;
        if ((caps = glite_lbu_DBQueryCaps(ctx)) == -1) goto failcon;
 #ifndef NO_PREPARED
index 413562a..37e314f 100644 (file)
@@ -30,6 +30,7 @@ struct glite_lbu_DBContext_s {
                char *desc;
        } err;
        int caps;
+       char *log_category;
 };
 typedef struct glite_lbu_DBContext_s glite_lbu_DBContext_t;
 
index 4de56ca..7172f4f 100644 (file)
@@ -417,8 +417,6 @@ long int glite_lbu_Lastid(glite_lbu_Statement stmt);
  * @} database group
  */
 
-static char *set_log_category;
-
 #ifdef __cplusplus
 }
 #endif
index 74891bb..3b525f6 100644 (file)
@@ -447,7 +447,7 @@ int glite_lbu_QueryIndicesMysql(glite_lbu_DBContext ctx_gen, const char *table,
        Key_name = Seq_in_index = Column_name = Sub_part = -1;
 
        asprintf(&sql, "show index from %s", table);
-       glite_common_log(set_log_category, LOG_PRIORITY_DEBUG, sql);
+       glite_common_log(ctx_gen->log_category, LOG_PRIORITY_DEBUG, sql);
        if (glite_lbu_ExecSQLMysql(ctx_gen,sql,&stmt)<0) {
                free(sql);
                return STATUS(ctx);
@@ -956,12 +956,12 @@ static int transaction_test(glite_lbu_DBContext ctx, int *caps) {
 
        (*caps) &= ~GLITE_LBU_DB_CAP_TRANSACTIONS;
 
-       glite_common_log(set_log_category, LOG_PRIORITY_DEBUG, "SHOW TABLES");
+       glite_common_log(ctx->log_category, LOG_PRIORITY_DEBUG, "SHOW TABLES");
        if ((retval = glite_lbu_ExecSQLMysql(ctx, "SHOW TABLES", &stmt)) <= 0 || glite_lbu_FetchRowMysql(stmt, 1, NULL, table) < 0) goto quit;
        glite_lbu_FreeStmtMysql(&stmt);
 
        trio_asprintf(&cmd, "SHOW CREATE TABLE %|Ss", table[0]);
-       glite_common_log(set_log_category, LOG_PRIORITY_DEBUG, cmd);
+       glite_common_log(ctx->log_category, LOG_PRIORITY_DEBUG, cmd);
        if (glite_lbu_ExecSQLMysql(ctx, cmd, &stmt) <= 0 || (retval = glite_lbu_FetchRowMysql(stmt, 2, NULL, res)) < 0 ) goto quit;
        if (retval != 2 || strcmp(res[0], table[0])) {
                ERR(ctx, EIO, "unexpected show create result");
index d8af7c8..c0acfc6 100644 (file)
@@ -246,7 +246,7 @@ int glite_lbu_DBConnectPsql(glite_lbu_DBContext ctx_gen, const char *cs) {
        else pgcs = pgcsbuf;
        free(buf);
 
-        glite_common_log(set_log_category, LOG_PRIORITY_DEBUG, 
+        glite_common_log(ctx_gen->log_category, LOG_PRIORITY_DEBUG, 
                "connection string = %s\n", pgcs);
        ctx->conn = psql_module.PQconnectdb(pgcs);
        free(pgcsbuf);
@@ -284,7 +284,7 @@ int glite_lbu_DBQueryCapsPsql(glite_lbu_DBContext ctx_gen) {
        int has_prepared = 0;
        char *res = NULL;
 
-       glite_common_log(set_log_category, LOG_PRIORITY_DEBUG, "SHOW server_version");
+       glite_common_log(ctx_gen->log_category, LOG_PRIORITY_DEBUG, "SHOW server_version");
        if (glite_lbu_ExecSQLPsql(ctx_gen, "SHOW server_version", &stmt) == -1) return -1;
        switch (glite_lbu_FetchRowPsql(stmt, 1, NULL, &res)) {
        case 1:
@@ -368,7 +368,7 @@ void glite_lbu_FreeStmtPsql(glite_lbu_Statement *stmt_gen) {
        if (stmt->res) psql_module.PQclear(stmt->res);
        if (stmt->name) {
                asprintf(&sql, "DEALLOCATE %s", stmt->name);
-               glite_common_log(set_log_category, LOG_PRIORITY_DEBUG, sql);
+               glite_common_log(ctx->generic.log_category, LOG_PRIORITY_DEBUG, sql);
                stmt->res = psql_module.PQexec(ctx->conn, sql);
                free(sql);
                psql_module.PQclear(stmt->res);
@@ -388,7 +388,7 @@ int glite_lbu_ExecSQLPsql(glite_lbu_DBContext ctx_gen, const char *cmd, glite_lb
        PGresult *res;
 
        //lprintf("command = %s\n", cmd);
-       glite_common_log(set_log_category, LOG_PRIORITY_DEBUG, "command = %s\n", cmd);
+       glite_common_log(ctx_gen->log_category, LOG_PRIORITY_DEBUG, "command = %s\n", cmd);
        if (stmt_out) *stmt_out = NULL;
        if ((res = psql_module.PQexec(ctx->conn, cmd)) == NULL) {
                ctx->generic.err.code = ENOMEM;
@@ -462,7 +462,7 @@ int glite_lbu_PrepareStmtPsql(glite_lbu_DBContext ctx_gen, const char *sql, glit
        asprintf(&stmt->name, "%s%d", prepared_names[i], ++ctx->prepared_counts[i]);
 
        asprintf(&sqlPrep, "PREPARE %s AS %s", stmt->name, stmt->sql);
-       glite_common_log(set_log_category, LOG_PRIORITY_DEBUG, sqlPrep);
+       glite_common_log(ctx_gen->log_category, LOG_PRIORITY_DEBUG, sqlPrep);
        res = psql_module.PQexec(ctx->conn, sqlPrep);
        if (psql_module.PQresultStatus(res) != PGRES_COMMAND_OK) {
                asprintf(&s, "error preparing command: %s", psql_module.PQerrorMessage(ctx->conn));
@@ -533,13 +533,13 @@ int glite_lbu_ExecPreparedStmtPsql_v(glite_lbu_Statement stmt_gen, int n, va_lis
 
                        s = va_arg(ap, char *);
                        binary_len = va_arg(ap, unsigned long);
-                       glite_common_log(set_log_category, LOG_PRIORITY_DEBUG, 
+                       glite_common_log(ctx->generic.log_category, LOG_PRIORITY_DEBUG, 
                                "blob, len = %lu, ptr = %p\n", binary_len, s);
                        if (s) {
                                tmp = malloc(2*binary_len + 1);
                                psql_module.PQescapeStringConn(ctx->conn, tmp, s, binary_len, NULL);
                                asprintf(&tmpdata[i], "'%s'", tmp);
-                               glite_common_log(set_log_category, LOG_PRIORITY_DEBUG, "escaped: '%s'\n", tmpdata[i]);
+                               glite_common_log(ctx->generic.log_category, LOG_PRIORITY_DEBUG, "escaped: '%s'\n", tmpdata[i]);
                                free(tmp);
                        } else
                                tmpdata[i] = strdup("NULL");
@@ -573,7 +573,7 @@ int glite_lbu_ExecPreparedStmtPsql_v(glite_lbu_Statement stmt_gen, int n, va_lis
                        break;
 
                default:
-                       glite_common_log(set_log_category, LOG_PRIORITY_DEBUG,
+                       glite_common_log(ctx->generic.log_category, LOG_PRIORITY_DEBUG,
                                "unknown type %d\n", type);
                        set_error(ctx, EINVAL, "unimplemented type");
                        goto quit;
@@ -592,7 +592,7 @@ int glite_lbu_ExecPreparedStmtPsql_v(glite_lbu_Statement stmt_gen, int n, va_lis
        }
        if (n) strcat(sql, ")");
 
-       glite_common_log(set_log_category, LOG_PRIORITY_DEBUG, sql);
+       glite_common_log(ctx->generic.log_category, LOG_PRIORITY_DEBUG, sql);
        stmt->res = psql_module.PQexec(ctx->conn, sql);
        status = psql_module.PQresultStatus(stmt->res);
        if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
index 429f727..f4a79f0 100644 (file)
@@ -98,7 +98,7 @@ int glite_lbu_DBSetError(glite_lbu_DBContext ctx, int code, const char *func, in
                va_end(ap);
        } else
                ctx->err.desc = NULL;
-       glite_common_log(set_log_category, LOG_PRIORITY_WARN, 
+       glite_common_log(ctx->log_category, LOG_PRIORITY_WARN, 
                "[db %d] %s:%d %s\n", getpid(), func, line, ctx->err.desc);
        return code;
 }
@@ -184,8 +184,10 @@ int glite_lbu_InitDBContext(glite_lbu_DBContext *ctx, int backend, char *log_cat
        if (!VALID(backend)) return EINVAL;
        if (backends[backend]->backend != backend) return ENOTSUP;
        ret = backends[backend]->initContext(ctx);
-       if (ctx && *ctx) (*ctx)->backend = backend;
-       set_log_category = log_category;
+       if (ctx && *ctx) {
+               (*ctx)->backend = backend;
+               (*ctx)->log_category = log_category;
+       }
        return ret;
 }
 
@@ -363,7 +365,7 @@ static int flush_bufferd_insert(glite_lbu_bufInsert bi)
        
        trio_asprintf(&stmt, "insert into %|Ss(%|Ss) values %s;",
                bi->table_name, bi->columns, vals);
-       glite_common_log(set_log_category, LOG_PRIORITY_DEBUG, stmt);
+       glite_common_log(bi->ctx->log_category, LOG_PRIORITY_DEBUG, stmt);
 
        if (glite_lbu_ExecSQL(bi->ctx,stmt,NULL) < 0) {
                 if (STATUS(bi->ctx) == EEXIST)