+++ /dev/null
-#ident "$Header$"
-
-#include "mysql.h" // MySql header file
-#include "mysqld_error.h"
-#include "errmsg.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <time.h>
-#include <limits.h>
-
-#include "glite/jp/types.h"
-#include "glite/jp/context.h"
-
-#include "db.h"
-
-#define DEFAULTCS "jpps/@localhost:jpps1"
-#define GLITE_JP_LB_MYSQL_VERSION 40018
-
-static int my_err(glite_jp_context_t ctx, char *function)
-{
- glite_jp_error_t err;
-
- glite_jp_clear_error(ctx);
- memset(&err,0,sizeof err);
- err.source = function;
- err.code = EIO; /* XXX */
- err.desc = mysql_error((MYSQL *) ctx->dbhandle);
- return glite_jp_stack_error(ctx,&err);
-}
-
-struct _glite_jp_db_stmt_t {
- MYSQL_RES *result;
- glite_jp_context_t ctx;
-};
-
-int glite_jp_db_connect(glite_jp_context_t ctx,char *cs)
-{
- char *buf = NULL;
- char *host,*user,*pw,*db;
- char *slash,*at,*colon;
-
- glite_jp_error_t err;
-
- glite_jp_clear_error(ctx);
- memset(&err,0,sizeof err);
- err.source = __FUNCTION__;
-
- if (!cs) cs = DEFAULTCS;
-
- if (!(ctx->dbhandle = (void *) mysql_init(NULL))) {
- err.code = ENOMEM;
- return glite_jp_stack_error(ctx,&err);
- }
-
- mysql_options(ctx->dbhandle, MYSQL_READ_DEFAULT_FILE, "my");
-
- host = user = pw = db = NULL;
-
- buf = strdup(cs);
- slash = strchr(buf,'/');
- at = strrchr(buf,'@');
- colon = strrchr(buf,':');
-
- if (!slash || !at || !colon) {
- free(buf);
- err.code = EINVAL;
- err.desc = "Invalid DB connect string";
- return glite_jp_stack_error(ctx,&err);
- }
-
- *slash = *at = *colon = 0;
- host = at+1;
- user = buf;
- pw = slash+1;
- db = colon+1;
-
- if (!mysql_real_connect((MYSQL *) ctx->dbhandle,host,user,pw,db,0,NULL,CLIENT_FOUND_ROWS)) {
- free(buf);
- return my_err(ctx, __FUNCTION__);
- }
-
- free(buf);
- return 0;
-}
-
-void glite_jp_db_close(glite_jp_context_t ctx)
-{
- mysql_close((MYSQL *) ctx->dbhandle);
- ctx->dbhandle = NULL;
-}
-
-int glite_jp_db_execstmt(glite_jp_context_t ctx,char *txt,glite_jp_db_stmt_t *stmt)
-{
- int merr;
- int retry_nr = 0;
- int do_reconnect = 0;
-
- glite_jp_error_t err;
-
- glite_jp_clear_error(ctx);
- memset(&err,0,sizeof err);
- err.source = __FUNCTION__;
-
- if (stmt) {
- *stmt = NULL;
- }
-
- while (retry_nr == 0 || do_reconnect) {
- do_reconnect = 0;
- if (mysql_query((MYSQL *) ctx->dbhandle,txt)) {
- /* error occured */
- switch (merr = mysql_errno((MYSQL *) ctx->dbhandle)) {
- case 0:
- break;
- case ER_DUP_ENTRY:
- err.code = EEXIST;
- err.desc = mysql_error((MYSQL *) ctx->dbhandle);
- glite_jp_stack_error(ctx,&err);
- return -1;
- break;
- case CR_SERVER_LOST:
- if (retry_nr <= 0)
- do_reconnect = 1;
- break;
- default:
- my_err(ctx, __FUNCTION__);
- return -1;
- break;
- }
- }
- retry_nr++;
- }
-
- if (stmt) {
- *stmt = malloc(sizeof(**stmt));
- if (!*stmt) {
- err.code = ENOMEM;
- glite_jp_stack_error(ctx,&err);
- return -1;
- }
- memset(*stmt,0,sizeof(**stmt));
- (**stmt).ctx = ctx;
- (**stmt).result = mysql_store_result((MYSQL *) ctx->dbhandle);
- if (!(**stmt).result) {
- if (mysql_errno((MYSQL *) ctx->dbhandle)) {
- my_err(ctx, __FUNCTION__);
- return -1;
- }
- }
- } else {
- MYSQL_RES *r = mysql_store_result((MYSQL *) ctx->dbhandle);
- mysql_free_result(r);
- }
-
- return mysql_affected_rows((MYSQL *) ctx->dbhandle);
-}
-
-int glite_jp_db_fetchrow(glite_jp_db_stmt_t stmt,char **res)
-{
- MYSQL_ROW row;
- glite_jp_context_t ctx = stmt->ctx;
- int nr,i;
- unsigned long *len;
-
- glite_jp_clear_error(ctx);
-
- if (!stmt->result) return 0;
-
- if (!(row = mysql_fetch_row(stmt->result))) {
- if (mysql_errno((MYSQL *) ctx->dbhandle)) {
- my_err(ctx, __FUNCTION__);
- return -1;
- } else return 0;
- }
-
- nr = mysql_num_fields(stmt->result);
- len = mysql_fetch_lengths(stmt->result);
- for (i=0; i<nr; i++) res[i] = len[i] ? strdup(row[i]) : strdup("");
-
- return nr;
-}
-
-int glite_jp_db_querycolumns(glite_jp_db_stmt_t stmt,char **cols)
-{
- int i = 0;
- MYSQL_FIELD *f;
-
- while ((f = mysql_fetch_field(stmt->result))) cols[i++] = f->name;
- return i == 0;
-}
-
-void glite_jp_db_freestmt(glite_jp_db_stmt_t *stmt)
-{
- if (*stmt) {
- if ((**stmt).result) mysql_free_result((**stmt).result);
- free(*stmt);
- *stmt = NULL;
- }
-}
-
-
-char *glite_jp_db_timetodb(time_t t)
-{
- struct tm *tm = gmtime(&t);
- char tbuf[256];
-
- /* XXX: the very end of our days */
- if (!tm && t == (time_t) LONG_MAX) return strdup("9999-12-31 23:59:59");
-
- sprintf(tbuf,"'%4d-%02d-%02d %02d:%02d:%02d'",tm->tm_year+1900,tm->tm_mon+1,
- tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
-
- return strdup(tbuf);
-}
-
-time_t glite_jp_db_dbtotime(char *t)
-{
- struct tm tm;
-
- memset(&tm,0,sizeof(tm));
- setenv("TZ","UTC",1); tzset();
- sscanf(t,"%4d-%02d-%02d %02d:%02d:%02d",
- &tm.tm_year,&tm.tm_mon,&tm.tm_mday,
- &tm.tm_hour,&tm.tm_min,&tm.tm_sec);
- tm.tm_year -= 1900;
- tm.tm_mon--;
-
- return mktime(&tm);
-}
-
-int glite_jp_db_dbcheckversion(glite_jp_context_t ctx)
-{
- MYSQL *m = (MYSQL *) ctx->dbhandle;
- const char *ver_s = mysql_get_server_info(m);
- int major,minor,sub,version;
-
- glite_jp_error_t err;
-
- glite_jp_clear_error(ctx);
- memset(&err,0,sizeof err);
- err.source = __FUNCTION__;
-
- if (!ver_s || 3 != sscanf(ver_s,"%d.%d.%d",&major,&minor,&sub)) {
- err.code = EINVAL;
- err.desc = "problem checking MySQL version";
- return glite_jp_stack_error(ctx,&err);
- }
-
- version = 10000*major + 100*minor + sub;
-
- if (version < GLITE_JP_LB_MYSQL_VERSION) {
- char msg[300];
-
- snprintf(msg,sizeof msg,"Your MySQL version is %d. At least %d required.",version, GLITE_JP_LB_MYSQL_VERSION);
- err.code = EINVAL;
- err.desc = msg;
- return glite_jp_stack_error(ctx,&err);
- }
-
- return 0;
-}
#include "glite/jp/strmd5.h"
#include "glite/jp/known_attr.h"
#include "glite/jp/attr.h"
+#include "glite/jp/db.h"
#include "feed.h"
#include "tags.h"
#include "backend.h"
-#include "db.h"
#include "jpps_H.h" /* XXX: SOAP_TYPE___jpsrv__GetJob */
return glite_jp_stack_error(ctx,&err);
}
- if (glite_jp_db_execstmt(ctx, stmt, NULL) < 0) {
+ if (glite_jp_db_ExecSQL(ctx, stmt, NULL) < 0) {
if (ctx->error->code == EEXIST)
glite_jp_clear_error(ctx);
else {
return glite_jp_stack_error(ctx,&err);
}
- if (glite_jp_db_connect(ctx, config->db_cs)) {
+ if (glite_lbu_InitDBContext(((glite_lbu_DBContext *)&ctx->dbhandle)) != 0) {
+ err.code = EINVAL;
+ err.desc = "Cannot init backend's database";
+ return glite_jp_stack_error(ctx,&err);
+ }
+ if (glite_lbu_DBConnect(ctx->dbhandle, config->db_cs)) {
err.code = EIO;
err.desc = "Cannot access backend's database (during init)";
return glite_jp_stack_error(ctx,&err);
} else {
- glite_jp_db_close(ctx); /* slaves open their own connections */
+ /* slaves open their own connections */
+ glite_lbu_DBClose(ctx->dbhandle);
+ glite_lbu_FreeDBContext(ctx->dbhandle);
}
return 0;
memset(&err,0,sizeof err);
err.source = __FUNCTION__;
- if (glite_jp_db_connect(ctx, config->db_cs)) {
+ if (glite_lbu_InitDBContext(((glite_lbu_DBContext *)&ctx->dbhandle)) != 0) {
+ err.code = EINVAL;
+ err.desc = "Cannot init backend's database";
+ return glite_jp_stack_error(ctx,&err);
+ }
+ if (glite_lbu_DBConnect(ctx->dbhandle, config->db_cs)) {
err.code = EIO;
err.desc = "Cannot access backend's database";
return glite_jp_stack_error(ctx,&err);
goto error_out;
}
- dbtime = glite_jp_db_timetodb(reg_tv.tv_sec);
+ glite_lbu_TimeToDB(reg_tv.tv_sec, &dbtime);
if (!dbtime) {
err.code = ENOMEM;
goto error_out;
goto error_out;
}
- if (glite_jp_db_execstmt(ctx, stmt, NULL) < 0) {
+ if (glite_jp_db_ExecSQL(ctx, stmt, NULL) < 0) {
if (ctx->error->code == EEXIST) {
err.code = EEXIST;
err.desc = "Job already registered";
char *ju_path = NULL;
char *peername = NULL;
char *peerhash = NULL;
+ char *commit_before_inout_str;
char *stmt = NULL;
- glite_jp_db_stmt_t db_res;
+ glite_lbu_Statement db_res;
int db_retn;
char *db_row[2] = { NULL, NULL };
goto error_out;
}
- if ((db_retn = glite_jp_db_execstmt(ctx, stmt, &db_res)) <= 0) {
+ if ((db_retn = glite_jp_db_ExecSQL(ctx, stmt, &db_res)) <= 0) {
if (db_retn == 0) {
err.code = ENOENT;
err.desc = "No such job registered";
goto error_out;
}
- db_retn = glite_jp_db_fetchrow(db_res, db_row);
+ db_retn = glite_jp_db_FetchRow(ctx, db_res, sizeof(db_row)/sizeof(db_row[0]), NULL, db_row);
if (db_retn != 2) {
- glite_jp_db_freestmt(&db_res);
+ glite_jp_db_FreeStmt(&db_res);
err.code = EIO;
err.desc = "DB access failed";
goto error_out;
}
- glite_jp_db_freestmt(&db_res);
+ glite_jp_db_FreeStmt(&db_res);
/* XXX authorization done in soap_ops.c */
if (asprintf(&data_fname, "%s/data/%s/%d/%s/%s",
config->internal_path, db_row[0],
- regtime_trunc(glite_jp_db_dbtotime(db_row[1])),
+ regtime_trunc(glite_lbu_DBToTime(db_row[1])),
ju, data_basename) == -1) {
err.code = ENOMEM;
goto error_out;
}
if (asprintf(destination_out, "%s/data/%s/%d/%s/%s",
config->external_path, db_row[0],
- regtime_trunc(glite_jp_db_dbtotime(db_row[1])),
+ regtime_trunc(glite_lbu_DBToTime(db_row[1])),
ju, data_basename) == -1) {
err.code = ENOMEM;
goto error_out;
}
free(stmt); stmt = NULL;
+ glite_lbu_TimeToDB(*commit_before_inout, &commit_before_inout_str);
trio_asprintf(&stmt,"insert into files"
"(jobid,filename,int_path,ext_url,state,deadline,ul_userid) "
"values ('%|Ss','%|Ss','%|Ss','%|Ss','%|Ss', '%|Ss', '%|Ss')",
ju, data_basename, data_fname, *destination_out, "uploading",
- glite_jp_db_timetodb(*commit_before_inout), peerhash);
+ commit_before_inout_str, peerhash);
+ free(commit_before_inout_str);
if (!stmt) {
err.code = ENOMEM;
goto error_out;
}
- if (glite_jp_db_execstmt(ctx, stmt, NULL) < 0) {
+ if (glite_jp_db_ExecSQL(ctx, stmt, NULL) < 0) {
if (ctx->error->code == EEXIST) {
err.code = EEXIST;
err.desc = "File already stored or upload in progress";
char *peerhash = NULL;
char *stmt = NULL;
- glite_jp_db_stmt_t db_res;
+ glite_lbu_Statement db_res;
int db_retn;
char *db_row[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
int i;
goto error_out;
}
- if ((db_retn = glite_jp_db_execstmt(ctx, stmt, &db_res)) <= 0) {
+ if ((db_retn = glite_jp_db_ExecSQL(ctx, stmt, &db_res)) <= 0) {
if (db_retn == 0) {
err.code = ENOENT;
err.desc = "No such upload in progress";
goto error_out;
}
- db_retn = glite_jp_db_fetchrow(db_res, db_row);
+ db_retn = glite_jp_db_FetchRow(ctx, db_res, sizeof(db_row)/sizeof(db_row[0]), NULL, db_row);
if (db_retn != 7) {
- glite_jp_db_freestmt(&db_res);
+ glite_jp_db_FreeStmt(&db_res);
err.code = EIO;
err.desc = "DB access failed";
goto error_out;
}
- glite_jp_db_freestmt(&db_res);
+ glite_jp_db_FreeStmt(&db_res);
peername = glite_jp_peer_name(ctx);
if (peername == NULL) {
goto error_out;
}
- if (glite_jp_db_execstmt(ctx, stmt, NULL) < 0) {
+ if (glite_jp_db_ExecSQL(ctx, stmt, NULL) < 0) {
err.code = EIO;
err.desc = "DB access failed";
goto error_out;
)
{
char *stmt = NULL;
- glite_jp_db_stmt_t db_res;
+ glite_lbu_Statement db_res;
int db_retn;
char *db_row[2] = { NULL, NULL};
int i;
char *cp = NULL;
- char *classname = NULL;
glite_jp_error_t err;
assert(destination != NULL);
goto error_out;
}
- if ((db_retn = glite_jp_db_execstmt(ctx, stmt, &db_res)) <= 0) {
+ if ((db_retn = glite_jp_db_ExecSQL(ctx, stmt, &db_res)) <= 0) {
if (db_retn == 0) {
err.code = ENOENT;
err.desc = "Invalid destination string";
goto error_out;
}
- db_retn = glite_jp_db_fetchrow(db_res, db_row);
+ db_retn = glite_jp_db_FetchRow(ctx, db_res, sizeof(db_row)/sizeof(db_row[0]), NULL, db_row);
if (db_retn != 2) {
- glite_jp_db_freestmt(&db_res);
+ glite_jp_db_FreeStmt(&db_res);
err.code = EIO;
err.desc = "DB access failed";
goto error_out;
}
- glite_jp_db_freestmt(&db_res);
+ glite_jp_db_FreeStmt(&db_res);
*job = strdup(db_row[0]);
)
{
char *data_basename = NULL;
- char *data_fname = NULL;
char *ju = NULL;
char *ju_path = NULL;
char *stmt = NULL;
- glite_jp_db_stmt_t db_res;
+ glite_lbu_Statement db_res;
int db_retn;
char *db_row[3] = { NULL, NULL, NULL };
- long reg_time;
glite_jp_error_t err;
glite_jp_clear_error(ctx);
goto error_out;
}
- if ((db_retn = glite_jp_db_execstmt(ctx, stmt, &db_res)) <= 0) {
+ if ((db_retn = glite_jp_db_ExecSQL(ctx, stmt, &db_res)) <= 0) {
if (db_retn == 0) {
err.code = ENOENT;
err.desc = "No such job registered";
free(stmt); stmt = NULL;
- db_retn = glite_jp_db_fetchrow(db_res, db_row);
+ db_retn = glite_jp_db_FetchRow(ctx, db_res, sizeof(db_row)/sizeof(db_row[0]), NULL, db_row);
if (db_retn != 3) {
- glite_jp_db_freestmt(&db_res);
+ glite_jp_db_FreeStmt(&db_res);
err.code = EIO;
err.desc = "DB access failed";
goto error_out;
}
- glite_jp_db_freestmt(&db_res);
+ glite_jp_db_FreeStmt(&db_res);
if (glite_jpps_authz(ctx,SOAP_TYPE___jpsrv__GetJobFiles,job,db_row[2])) {
err.code = EPERM;
if (asprintf(url_out, "%s/data/%s/%d/%s/%s",
config->external_path, db_row[0],
- regtime_trunc(glite_jp_db_dbtotime(db_row[1])),
+ regtime_trunc(glite_lbu_DBToTime(db_row[1])),
ju, data_basename) == -1) {
err.code = ENOMEM;
goto error_out;
}
+// FIXME: relict?
+#if 0
trio_asprintf(&stmt,"select 'x' from files where jobid='%|Ss' "
"and ext_url = '%|Ss' "
"and state='committed' ",ju,*url_out);
- if ((db_retn = glite_jp_db_execstmt(ctx,stmt,&db_res)) <= 0) {
+ if ((db_retn = glite_jp_db_ExecSQL(ctx,stmt,&db_res)) <= 0) {
if (db_retn == 0) {
err.code = ENOENT;
err.desc = "not uploaded yet";
}
/* goto error_out; */
}
+#endif
error_out:
free(db_row[0]); free(db_row[1]);
char *ju_path = NULL;
char *stmt = NULL;
- glite_jp_db_stmt_t db_res;
+ glite_lbu_Statement db_res;
int db_retn;
char *db_row[2] = { NULL, NULL };
- long reg_time;
glite_jp_error_t err;
glite_jp_clear_error(ctx);
goto error_out;
}
- if ((db_retn = glite_jp_db_execstmt(ctx, stmt, &db_res)) <= 0) {
+ if ((db_retn = glite_jp_db_ExecSQL(ctx, stmt, &db_res)) <= 0) {
if (db_retn == 0) {
err.code = ENOENT;
err.desc = "No such job registered";
goto error_out;
}
- db_retn = glite_jp_db_fetchrow(db_res, db_row);
+ db_retn = glite_jp_db_FetchRow(ctx, db_res, sizeof(db_row)/sizeof(db_row[0]), NULL, db_row);
if (db_retn != 2) {
- glite_jp_db_freestmt(&db_res);
+ glite_jp_db_FreeStmt(&db_res);
err.code = EIO;
err.desc = "DB access failed";
goto error_out;
}
- glite_jp_db_freestmt(&db_res);
+ glite_jp_db_FreeStmt(&db_res);
/* XXX name length */
if (asprintf(&data_basename, "%s%s%s", class,
if (asprintf(fname_out, "%s/data/%s/%d/%s/%s",
config->internal_path, db_row[0],
- regtime_trunc(glite_jp_db_dbtotime(db_row[1])),
+ regtime_trunc(glite_lbu_DBToTime(db_row[1])),
ju, data_basename) == -1) {
err.code = ENOMEM;
goto error_out;
char *qry,*col[2];
int rows;
glite_jp_error_t err;
- glite_jp_db_stmt_t s = NULL;
+ glite_lbu_Statement s = NULL;
memset(&err,0,sizeof err);
err.source = __FUNCTION__;
"where j.owner = u.userid "
"and j.dg_jobid = '%|Ss'",job);
- if ((rows = glite_jp_db_execstmt(ctx,qry,&s)) <= 0) {
+ if ((rows = glite_jp_db_ExecSQL(ctx,qry,&s)) <= 0) {
if (rows == 0) {
err.code = ENOENT;
err.desc = "No records for this job";
goto cleanup;
}
- if (glite_jp_db_fetchrow(s,col) < 0) {
+ if (glite_jp_db_FetchRow(ctx,s,sizeof(col)/sizeof(col[0]), NULL, col) < 0) {
err.code = EIO;
err.desc = "DB call fail retrieving job files";
glite_jp_stack_error(ctx,&err);
}
*owner = col[0];
- tv_reg->tv_sec = glite_jp_db_dbtotime(col[1]);
+ tv_reg->tv_sec = glite_lbu_DBToTime(col[1]);
tv_reg->tv_usec = 0;
free(col[1]);
cleanup:
free(qry);
- if (s) glite_jp_db_freestmt(&s);
+ if (s) glite_jp_db_FreeStmt(&s);
return err.code;
}
void *tags_handle = NULL;
glite_jp_tagval_t* tags = NULL;
*/
- int i,j;
+ int i;
glite_jp_error_t err;
assert(job != NULL);
{
glite_jp_error_t err;
int i,ret;
- int quser = 0, muser = -1, mtime = -1;
+ int quser = 0;
char *where = NULL,*stmt = NULL,*aux = NULL, *cols = NULL;
char *qres[3] = { NULL, NULL, NULL };
int cmask = 0, owner_idx = -1, reg_idx = -1;
- glite_jp_db_stmt_t q = NULL;
+ glite_lbu_Statement q = NULL;
glite_jp_attrval_t metadata[3];
memset(&err,0,sizeof err);
}
else if (!strcmp(query[i].attr,GLITE_JP_ATTR_REGTIME)) {
time_t t = glite_jp_attr2time(query[i].value);
- char *t1 = glite_jp_db_timetodb(t),*t2 = NULL;
+ char *t1,*t2 = NULL;
+ glite_lbu_TimeToDB(t, &t1);
switch (query[i].op) {
case GLITE_JP_QUERYOP_EQUAL:
trio_asprintf(&qitem,"j.reg_time = %s",t1);
break;
case GLITE_JP_QUERYOP_WITHIN:
free(t2);
- trio_asprintf(&qitem,"j.reg_time >= %s and j.reg_time <= %s",
- t1,t2 = glite_jp_db_timetodb(glite_jp_attr2time(query[i].value2)+1));
+ glite_lbu_TimeToDB(glite_jp_attr2time(query[i].value2)+1, &t2);
+ trio_asprintf(&qitem,"j.reg_time >= %s and j.reg_time <= %s",t1,t2);
break;
default:
err.code = EINVAL;
where,
cmask & 1 ? "and u.userid = j.owner" : "");
- if ((ret = glite_jp_db_execstmt(ctx,stmt,&q)) < 0) {
+ if ((ret = glite_jp_db_ExecSQL(ctx,stmt,&q)) < 0) {
err.code = EIO;
err.desc = "DB call fail";
glite_jp_stack_error(ctx,&err);
goto cleanup;
}
- while ((ret = glite_jp_db_fetchrow(q,qres)) > 0) {
+ while ((ret = glite_jp_db_FetchRow(ctx,q,sizeof(qres)/sizeof(qres[0]), NULL, qres)) > 0) {
if (cmask & 1) {
/* XXX: owner always first */
metadata[owner_idx].value = qres[1];
}
if (cmask & 2) {
int qi = cmask == 2 ? 1 : 2;
- time_t t = glite_jp_db_dbtotime(qres[qi]);
+ time_t t = glite_lbu_DBToTime(qres[qi]);
metadata[reg_idx].value = glite_jp_time2attr(t);
metadata[reg_idx].origin = GLITE_JP_ATTR_ORIG_SYSTEM;
free(qres[qi]);
free(stmt);
free(qres[0]); free(qres[1]); free(qres[2]);
free(metadata[0].value); free(metadata[1].value);
- if (q) glite_jp_db_freestmt(&q);
+ if (q) glite_jp_db_FreeStmt(&q);
return err.code;
}
{
char *qry = NULL,*file = NULL,*dot;
char **out = NULL;
- glite_jp_db_stmt_t s = NULL;
+ glite_lbu_Statement s = NULL;
int rows,nout = 0;
glite_jp_error_t err;
trio_asprintf(&qry,"select filename from files f,jobs j "
"where j.dg_jobid = '%|Ss' and j.jobid = f.jobid and f.state = 'committed'",job);
- if ((rows = glite_jp_db_execstmt(ctx,qry,&s)) <= 0) {
+ if ((rows = glite_jp_db_ExecSQL(ctx,qry,&s)) <= 0) {
if (rows == 0) {
err.code = ENOENT;
err.desc = "No files for this job";
goto cleanup;
}
- while ((rows = glite_jp_db_fetchrow(s,&file))) {
- int l;
-
+ while ((rows = glite_jp_db_FetchRow(ctx,s,1,NULL,&file))) {
if (rows < 0) {
err.code = EIO;
err.desc = "DB call fail retrieving job files";
}
cleanup:
- if (s) glite_jp_db_freestmt(&s);
+ if (s) glite_jp_db_FreeStmt(&s);
free(qry);
free(file);
"values ('%|Ss','%|Ss')", feed,u);
free(u);
- if ((rows = glite_jp_db_execstmt(ctx,stmt,NULL)) < 0) {
+ if ((rows = glite_jp_db_ExecSQL(ctx,stmt,NULL)) < 0) {
err.source = __FUNCTION__;
err.code = EIO;
err.desc = "insert into fed_jobs";
free(u);
- if ((rows = glite_jp_db_execstmt(ctx,stmt,NULL)) < 0) {
+ if ((rows = glite_jp_db_ExecSQL(ctx,stmt,NULL)) < 0) {
err.source = __FUNCTION__;
err.code = EIO;
err.desc = "select from fed_jobs";
aux = NULL;
}
+ glite_lbu_TimeToDB(feed->expires, &e);
trio_asprintf(&stmt,"insert into feeds(feedid,destination,expires,cols,query) "
"values ('%|Ss','%|Ss',%s,'%|Ss','%|Ss')",
feed->id,feed->destination,
- e = glite_jp_db_timetodb(feed->expires),
+ e,
alist,qlist);
free(alist); free(qlist); free(e);
- if ((rows = glite_jp_db_execstmt(ctx,stmt,NULL)) < 0) {
+ if ((rows = glite_jp_db_ExecSQL(ctx,stmt,NULL)) < 0) {
err.source = __FUNCTION__;
err.code = EIO;
err.desc = "insert into fed_jobs";
)
{
char *stmt = NULL,*feed = NULL;
- char *expires = glite_jp_db_timetodb(time(NULL));
+ char *expires;
glite_jp_error_t err;
- glite_jp_db_stmt_t q = NULL;
+ glite_lbu_Statement q = NULL;
int rows;
+ glite_lbu_TimeToDB(time(NULL), &expires);
memset(&err,0,sizeof err);
trio_asprintf(&stmt,"select feedid from feeds where expires < %s",expires);
- if ((rows = glite_jp_db_execstmt(ctx, stmt, &q)) < 0) {
+ if ((rows = glite_jp_db_ExecSQL(ctx, stmt, &q)) < 0) {
err.code = EIO;
err.desc = "select from feeds";
glite_jp_stack_error(ctx,&err);
goto cleanup;
}
- while ((rows = glite_jp_db_fetchrow(q,&feed)) > 0) {
+ while ((rows = glite_jp_db_FetchRow(ctx,q,1,NULL,&feed)) > 0) {
free(stmt);
trio_asprintf(&stmt,"delete from fed_jobs where feedid = '%|Ss'",feed);
- if ((rows = glite_jp_db_execstmt(ctx, stmt, NULL)) < 0) {
+ if ((rows = glite_jp_db_ExecSQL(ctx, stmt, NULL)) < 0) {
err.code = EIO;
err.desc = "delete from fed_jobs";
glite_jp_stack_error(ctx,&err);
free(stmt);
trio_asprintf(&stmt,"delete from feeds where expires < %s",expires);
- if ((rows = glite_jp_db_execstmt(ctx, stmt, NULL)) < 0) {
+ if ((rows = glite_jp_db_ExecSQL(ctx, stmt, NULL)) < 0) {
err.code = EIO;
err.desc = "select from feeds";
glite_jp_stack_error(ctx,&err);
}
cleanup:
- glite_jp_db_freestmt(&q);
+ glite_jp_db_FreeStmt(&q);
free(feed);
free(stmt);
free(expires);
{
char *stmt,*res[5],*expires;
glite_jp_error_t err;
- glite_jp_db_stmt_t q = NULL;
+ glite_lbu_Statement q = NULL;
int rows;
stmt = expires = NULL;
memset(&res,0,sizeof res);
err.source = __FUNCTION__;
- expires = glite_jp_db_timetodb(time(NULL));
+ glite_lbu_TimeToDB(time(NULL), &expires);
trio_asprintf(&stmt,"select feedid,destination,expires,cols,query "
"from feeds "
"where expires > %s",expires);
free(expires); expires = NULL;
- if ((rows = glite_jp_db_execstmt(ctx, stmt, &q)) < 0) {
+ if ((rows = glite_jp_db_ExecSQL(ctx, stmt, &q)) < 0) {
err.code = EIO;
err.desc = "select from feeds";
glite_jp_stack_error(ctx,&err);
goto cleanup;
}
- while ((rows = glite_jp_db_fetchrow(q,res)) > 0) {
+ while ((rows = glite_jp_db_FetchRow(ctx,q,sizeof(res)/sizeof(res[0]),NULL, res)) > 0) {
struct jpfeed *f = calloc(1,sizeof *f);
int n;
char *p;
f->id = res[0]; res[0] = NULL;
f->destination = res[1]; res[1] = NULL;
- f->expires = glite_jp_db_dbtotime(res[2]); free(res[2]); res[2] = NULL;
+ f->expires = glite_lbu_DBToTime(res[2]); free(res[2]); res[2] = NULL;
n = 0;
for (p = strtok(res[3],"\n"); p; p = strtok(NULL,"\n")) {
}
cleanup:
- glite_jp_db_freestmt(&q);
+ glite_jp_db_FreeStmt(&q);
free(res[0]); free(res[1]); free(res[2]); free(res[3]); free(res[4]);
return err.code;
}