test example construct complex query ((x OR y) AND (z))
authorMiloš Mulač <mulac@civ.zcu.cz>
Fri, 14 Oct 2005 15:57:51 +0000 (15:57 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Fri, 14 Oct 2005 15:57:51 +0000 (15:57 +0000)
- correct construction of sql complex queries

org.glite.jp.index/examples/jpis-test.c
org.glite.jp.index/src/db_ops.c
org.glite.jp.index/src/soap_ops.c

index c0c8e45..3c92f12 100644 (file)
@@ -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));
 
index 3c63f2e..65b61a6 100644 (file)
@@ -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;
index e36e4f4..b94c0ce 100644 (file)
@@ -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);