From f32226db9285839a3dc69af2bf18ff8c04bf2067 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Milo=C5=A1=20Mula=C4=8D?= Date: Fri, 14 Oct 2005 15:57:51 +0000 Subject: [PATCH] test example construct complex query ((x OR y) AND (z)) - correct construction of sql complex queries --- org.glite.jp.index/examples/jpis-test.c | 51 +++++++++++++++++++++++++++------ org.glite.jp.index/src/db_ops.c | 2 +- org.glite.jp.index/src/soap_ops.c | 11 +++---- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/org.glite.jp.index/examples/jpis-test.c b/org.glite.jp.index/examples/jpis-test.c index c0c8e45..3c92f12 100644 --- a/org.glite.jp.index/examples/jpis-test.c +++ b/org.glite.jp.index/examples/jpis-test.c @@ -92,7 +92,7 @@ int main(int argc,char *argv[]) rec->attributes = soap_malloc(soap, rec->__sizeattributes * sizeof(*(rec->attributes))); rec->attributes[0] = soap_malloc(soap, sizeof(*(rec->attributes[0]))); - rec->attributes[0]->name = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/JP/System:owner"); + rec->attributes[0]->name = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/LB/Attributes:user"); rec->attributes[0]->value = soap_malloc(soap, sizeof(*(rec->attributes[0]->value))); rec->attributes[0]->value->string = soap_strdup(soap, "CertSubj"); rec->attributes[0]->value->blob = NULL; @@ -118,7 +118,7 @@ int main(int argc,char *argv[]) } /*---------------------------------------------------------------------------*/ - // this call is issued by user + // this query call issued by user { struct _jpelem__QueryJobs in; struct jptype__indexQuery *cond; @@ -127,35 +127,68 @@ int main(int argc,char *argv[]) int i, j; - in.__sizeconditions = 1; + in.__sizeconditions = 2; in.conditions = soap_malloc(soap, in.__sizeconditions * sizeof(*(in.conditions))); + // query status cond = soap_malloc(soap, sizeof(*cond)); memset(cond, 0, sizeof(*cond)); cond->attr = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus"); cond->origin = NULL; - cond->__sizerecord = 1; - cond->record = soap_malloc(soap, sizeof(*(cond->record))); + cond->__sizerecord = 2; + cond->record = soap_malloc(soap, cond->__sizerecord * sizeof(*(cond->record))); + // equal to Done rec = soap_malloc(soap, sizeof(*rec)); memset(rec, 0, sizeof(*rec)); rec->op = jptype__queryOp__EQUAL; rec->value = soap_malloc(soap, sizeof(*(rec->value))); rec->value->string = soap_strdup(soap, "Done"); rec->value->blob = NULL; - - *(cond->record) = rec; - *(in.conditions) = cond; + cond->record[0] = rec; + + // OR equal to Ready + rec = soap_malloc(soap, sizeof(*rec)); + memset(rec, 0, sizeof(*rec)); + rec->op = jptype__queryOp__EQUAL; + rec->value = soap_malloc(soap, sizeof(*(rec->value))); + rec->value->string = soap_strdup(soap, "Ready"); + rec->value->blob = NULL; + cond->record[1] = rec; + + in.conditions[0] = cond; + + // AND + // owner + cond = soap_malloc(soap, sizeof(*cond)); + memset(cond, 0, sizeof(*cond)); + cond->attr = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/LB/Attributes:user"); + cond->origin = NULL; + cond->__sizerecord = 1; + cond->record = soap_malloc(soap, cond->__sizerecord * sizeof(*(cond->record))); + + // not equal to CertSubj + rec = soap_malloc(soap, sizeof(*rec)); + memset(rec, 0, sizeof(*rec)); + rec->op = jptype__queryOp__UNEQUAL; + rec->value = soap_malloc(soap, sizeof(*(rec->value))); + rec->value->string = soap_strdup(soap, "God"); + rec->value->blob = NULL; + cond->record[0] = rec; + + in.conditions[1] = cond; + - in.__sizeattributes = 3; + in.__sizeattributes = 4; in.attributes = soap_malloc(soap, in.__sizeattributes * sizeof(*(in.attributes))); in.attributes[0] = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/JP/System:owner"); in.attributes[1] = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/JP/System:jobId"); in.attributes[2] = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/LB/Attributes:finalStatus"); + in.attributes[3] = soap_strdup(soap, "http://egee.cesnet.cz/en/Schema/LB/Attributes:user"); memset(&out, 0, sizeof(out)); diff --git a/org.glite.jp.index/src/db_ops.c b/org.glite.jp.index/src/db_ops.c index 3c63f2e..65b61a6 100644 --- a/org.glite.jp.index/src/db_ops.c +++ b/org.glite.jp.index/src/db_ops.c @@ -585,7 +585,7 @@ int glite_jpis_insertAttrVal(glite_jpis_context_t ctx, const char *jobid, glite_ free(table); free(value); free(full_value); - lprintf("%s: sql=%s\n", __FUNCTION__, sql); + lprintf("%s(%s): sql=%s\n", __FUNCTION__, av->name, sql); if (glite_jp_db_execstmt(ctx->jpctx, sql, NULL) != 1) { free(sql); return ctx->jpctx->error->code; diff --git a/org.glite.jp.index/src/soap_ops.c b/org.glite.jp.index/src/soap_ops.c index e36e4f4..b94c0ce 100644 --- a/org.glite.jp.index/src/soap_ops.c +++ b/org.glite.jp.index/src/soap_ops.c @@ -233,7 +233,8 @@ static int get_jobids(struct soap *soap, glite_jpis_context_t ctx, struct _jpele glite_jp_db_stmt_t stmt; glite_jp_attrval_t attr; - + + qwhere = strdup(""); for (i=0; i < in->__sizeconditions; i++) { attr_md5 = str2md5(in->conditions[i]->attr); trio_asprintf(&qa,"%s jobs.jobid = attr_%|Ss.jobid AND (", @@ -268,13 +269,12 @@ static int get_jobids(struct soap *soap, glite_jpis_context_t ctx, struct _jpele free(qop); free(qa); qa = qb; qb = NULL; } - free(attr_md5); } - trio_asprintf(&qb,"%s)",qa); - free(qa); qa = qb; qb = NULL; + trio_asprintf(&qb,"%s %s)", qwhere, qa); + free(qa); qwhere = qb; qb = NULL; qa = NULL; + free(attr_md5); } - qwhere = qa; qa = strdup(""); for (i=0; (attr_tables && attr_tables[i]); i++) { @@ -283,6 +283,7 @@ static int get_jobids(struct soap *soap, glite_jpis_context_t ctx, struct _jpele } trio_asprintf(&query, "SELECT dg_jobid,ps FROM jobs%s WHERE %s;", qa, qwhere); + printf("Incomming QUERY:\n %s\n", query); free(qwhere); free(qa); -- 1.8.2.3