00001
00002
00003
00004
00005
00006
00007 #include "rodsClient.h"
00008 #include "readServerConfig.h"
00009
00010 #include "icatHighLevelRoutines.h"
00011
00012 int sTest(int i1, int i2);
00013 int sTest2(int i1, int i2, int i3);
00014 int findCycles(int startTable);
00015
00016 #define BIG_STR 200
00017 int doLs()
00018 {
00019 genQueryInp_t genQueryInp;
00020 genQueryOut_t genQueryOut;
00021 int i1a[10];
00022 int i1b[10];
00023 int i2a[10];
00024 int status = 0;
00025 char *condVal[2];
00026 char v1[BIG_STR];
00027 int i;
00028 char cwd[]="/";
00029
00030 i1a[0]=COL_DATA_NAME;
00031 i1a[1]=COL_COLL_NAME;
00032 i1b[0]=0;
00033 genQueryInp.selectInp.inx = i1a;
00034 genQueryInp.selectInp.value = i1b;
00035 genQueryInp.selectInp.len = 2;
00036
00037 i2a[0]=COL_COLL_PARENT_NAME;
00038 genQueryInp.sqlCondInp.inx = i2a;
00039 sprintf(v1,"='%s'",cwd);
00040 condVal[0]=v1;
00041 genQueryInp.sqlCondInp.value = condVal;
00042 genQueryInp.sqlCondInp.len=1;
00043
00044 genQueryInp.maxRows=10;
00045 genQueryInp.continueInx=0;
00046 i = chlGenQuery(genQueryInp, &genQueryOut);
00047 printf("chlGenQuery status=%d\n",i);
00048 printf("genQueryOut.rowCnt=%d\n", genQueryOut.rowCnt);
00049 printf("genQueryOut.attriCnt=%d\n", genQueryOut.attriCnt);
00050 if (genQueryOut.rowCnt > 0) {
00051 int i, j;
00052 for (i=0;i<genQueryOut.attriCnt;i++) {
00053 printf("genQueryOut.SqlResult[%d].attriInx=%d\n",i,
00054 genQueryOut.sqlResult[i].attriInx);
00055 printf("genQueryOut.SqlResult[%d].len=%d\n",i,
00056 genQueryOut.sqlResult[i].len);
00057 for (j=0;j<genQueryOut.rowCnt;j++) {
00058 char *tResult;
00059 tResult = genQueryOut.sqlResult[i].value;
00060 tResult += j*genQueryOut.sqlResult[i].len;
00061 printf("genQueryOut.SqlResult[%d].value=%s\n",i, tResult);
00062 }
00063 }
00064 }
00065 return(status);
00066 }
00067
00068
00069 int doLs2()
00070 {
00071 genQueryInp_t genQueryInp;
00072 genQueryOut_t genQueryOut;
00073 int i1a[10];
00074 int i1b[10];
00075 int i2a[10];
00076 char *condVal[2];
00077 char v1[BIG_STR];
00078 int i;
00079 char cwd[]="/tempZone/home/rods";
00080
00081 memset ((char*)&genQueryInp, 0, sizeof (genQueryInp));
00082
00083 i1a[0]=COL_DATA_NAME;
00084 i1b[0]=0;
00085 genQueryInp.selectInp.inx = i1a;
00086 genQueryInp.selectInp.value = i1b;
00087 genQueryInp.selectInp.len = 1;
00088
00089 i2a[0]=COL_COLL_NAME;
00090 genQueryInp.sqlCondInp.inx = i2a;
00091 sprintf(v1,"='%s'",cwd);
00092 condVal[0]=v1;
00093
00094 genQueryInp.sqlCondInp.value = condVal;
00095 genQueryInp.sqlCondInp.len=1;
00096
00097 genQueryInp.maxRows=10;
00098 genQueryInp.continueInx=0;
00099 i = chlGenQuery(genQueryInp, &genQueryOut);
00100 printf("chlGenQuery status=%d\n",i);
00101 printf("genQueryOut.rowCnt=%d\n", genQueryOut.rowCnt);
00102 printf("genQueryOut.attriCnt=%d\n", genQueryOut.attriCnt);
00103 if (genQueryOut.rowCnt > 0) {
00104 int i, j;
00105 for (i=0;i<genQueryOut.attriCnt;i++) {
00106 printf("genQueryOut.SqlResult[%d].attriInx=%d\n",i,
00107 genQueryOut.sqlResult[i].attriInx);
00108 printf("genQueryOut.SqlResult[%d].len=%d\n",i,
00109 genQueryOut.sqlResult[i].len);
00110 for (j=0;j<genQueryOut.rowCnt;j++) {
00111 char *tResult;
00112 tResult = genQueryOut.sqlResult[i].value;
00113 tResult += j*genQueryOut.sqlResult[i].len;
00114 printf("genQueryOut.SqlResult[%d].value=%s\n",i, tResult);
00115 }
00116 }
00117 }
00118 return(i);
00119 }
00120
00121
00122
00123 int doLs3a()
00124
00125 {
00126 genQueryInp_t genQueryInp;
00127 genQueryOut_t genQueryOut;
00128 int i1a[10];
00129 int i1b[10];
00130 int i2a[10];
00131 char *condVal[2];
00132 char v1[BIG_STR];
00133 int i;
00134 char cwd[]="/newZone/home/rods";
00135
00136 memset ((char*)&genQueryInp, 0, sizeof (genQueryInp));
00137
00138 i1a[0]=COL_DATA_NAME;
00139 i1b[0]=0;
00140 genQueryInp.selectInp.inx = i1a;
00141 genQueryInp.selectInp.value = i1b;
00142 genQueryInp.selectInp.len = 1;
00143
00144 i2a[0]=COL_COLL_NAME;
00145 genQueryInp.sqlCondInp.inx = i2a;
00146 sprintf(v1,"='%s'",cwd);
00147 condVal[0]=v1;
00148
00149 genQueryInp.sqlCondInp.value = condVal;
00150 genQueryInp.sqlCondInp.len=1;
00151
00152 genQueryInp.maxRows=10;
00153 genQueryInp.continueInx=0;
00154 i = chlGenQuery(genQueryInp, &genQueryOut);
00155 printf("chlGenQuery status=%d, genQueryOut.rowCnt=%d\n", i,
00156 genQueryOut.rowCnt);
00157 if (genQueryOut.continueInx>0) {
00158 int status2;
00159 genQueryInp.maxRows=-1;
00160 genQueryInp.continueInx = genQueryOut.continueInx;
00161 status2 = chlGenQuery(genQueryInp, &genQueryOut);
00162 printf("chlGenQuery second call to close out status=%d\n",status2);
00163 }
00164 return(i);
00165 }
00166
00167
00168 int doLs3(char *repCount) {
00169 int iRepCount, i, status;
00170 rodsLogSqlReq(0);
00171 iRepCount = atoi(repCount);
00172 for (i=0;i<iRepCount;i++) {
00173 status = doLs3a();
00174 if (status) break;
00175 }
00176 return(status);
00177 }
00178
00179
00180 int
00181 doTest2() {
00182 genQueryInp_t genQueryInp;
00183 genQueryOut_t genQueryOut;
00184 int status;
00185
00186 rodsLogSqlReq(1);
00187
00188 memset ((char*)&genQueryInp, 0, sizeof (genQueryInp));
00189
00190 addInxIval (&genQueryInp.selectInp, COL_R_RESC_ID, 1);
00191 addInxIval (&genQueryInp.selectInp, COL_R_RESC_NAME, 1);
00192 addInxIval (&genQueryInp.selectInp, COL_R_ZONE_NAME, 1);
00193 addInxIval (&genQueryInp.selectInp, COL_R_TYPE_NAME, 1);
00194 addInxIval (&genQueryInp.selectInp, COL_R_CLASS_NAME, 1);
00195 addInxIval (&genQueryInp.selectInp, COL_R_LOC, 1);
00196 addInxIval (&genQueryInp.selectInp, COL_R_VAULT_PATH, 1);
00197 addInxIval (&genQueryInp.selectInp, COL_R_FREE_SPACE, 1);
00198 addInxIval (&genQueryInp.selectInp, COL_R_RESC_INFO, 1);
00199 addInxIval (&genQueryInp.selectInp, COL_R_RESC_COMMENT, 1);
00200 addInxIval (&genQueryInp.selectInp, COL_R_CREATE_TIME, 1);
00201 addInxIval (&genQueryInp.selectInp, COL_R_MODIFY_TIME, 1);
00202
00203 status = chlGenQuery(genQueryInp, &genQueryOut);
00204 printf("chlGenQuery status=%d\n",status);
00205 return(status);
00206 }
00207
00208 int
00209 printGenQOut( genQueryOut_t *genQueryOut) {
00210 int i;
00211 printf("genQueryOut->rowCnt=%d\n", genQueryOut->rowCnt);
00212 printf("genQueryOut->attriCnt=%d\n", genQueryOut->attriCnt);
00213 printf("genQueryOut->totalRowCount=%d\n", genQueryOut->totalRowCount);
00214 for (i=0;i<genQueryOut->attriCnt;i++) {
00215 int j;
00216 printf("genQueryOut->SqlResult[%d].attriInx=%d\n",i,
00217 genQueryOut->sqlResult[i].attriInx);
00218 printf("genQueryOut->SqlResult[%d].len=%d\n",i,
00219 genQueryOut->sqlResult[i].len);
00220 for (j=0;j<genQueryOut->rowCnt;j++) {
00221 char *tResult;
00222 tResult = genQueryOut->sqlResult[i].value;
00223 tResult += j*genQueryOut->sqlResult[i].len;
00224 printf("genQueryOut->SqlResult[%d].value=%s\n",i, tResult);
00225 }
00226 printf("genQueryOut->continueInx=%d\n",genQueryOut->continueInx);
00227 }
00228 return(0);
00229 }
00230
00231
00232 int
00233 doTest3() {
00234 genQueryInp_t genQueryInp;
00235 genQueryOut_t genQueryOut;
00236 char condStr[MAX_NAME_LEN];
00237 int status;
00238
00239 printf("dotest3\n");
00240 rodsLogSqlReq(1);
00241
00242 memset (&genQueryInp, 0, sizeof (genQueryInp));
00243
00244 addInxIval (&genQueryInp.selectInp, COL_R_RESC_ID, 1);
00245 addInxIval (&genQueryInp.selectInp, COL_R_RESC_NAME, 1);
00246 addInxIval (&genQueryInp.selectInp, COL_R_ZONE_NAME, 1);
00247
00248
00249
00250
00251
00252 snprintf (condStr, MAX_NAME_LEN, "like '%s' || like 's'", "e");
00253 addInxVal (&genQueryInp.sqlCondInp, COL_R_RESC_NAME, condStr);
00254
00255 genQueryInp.maxRows=2;
00256
00257 status = chlGenQuery(genQueryInp, &genQueryOut);
00258 printf("chlGenQuery status=%d\n",status);
00259 if (status == 0) {
00260 printGenQOut(&genQueryOut);
00261 }
00262 return(status);
00263 }
00264
00265 int
00266 doTest4() {
00267 genQueryInp_t genQueryInp;
00268 genQueryOut_t genQueryOut;
00269 char condStr[MAX_NAME_LEN];
00270 int status;
00271
00272 printf("dotest4\n");
00273 rodsLogSqlReq(1);
00274
00275 memset (&genQueryInp, 0, sizeof (genQueryInp));
00276
00277 addInxIval (&genQueryInp.selectInp, COL_RESC_GROUP_RESC_ID, 1);
00278 addInxIval (&genQueryInp.selectInp, COL_R_RESC_NAME, 1);
00279
00280
00281 snprintf (condStr, MAX_NAME_LEN, "like 'abc'");
00282 addInxVal (&genQueryInp.sqlCondInp, COL_RESC_GROUP_NAME, condStr);
00283
00284 genQueryInp.maxRows=2;
00285
00286 status = chlGenQuery(genQueryInp, &genQueryOut);
00287 printf("chlGenQuery status=%d\n",status);
00288 if (status == 0) {
00289 printGenQOut(&genQueryOut);
00290 }
00291 return(status);
00292 }
00293
00294 int
00295 doTest5() {
00296 genQueryInp_t genQueryInp;
00297 genQueryOut_t genQueryOut;
00298 char condStr[MAX_NAME_LEN];
00299 int status;
00300
00301 printf("dotest5\n");
00302 rodsLogSqlReq(1);
00303
00304 memset (&genQueryInp, 0, sizeof (genQueryInp));
00305
00306 addInxIval (&genQueryInp.selectInp, COL_RULE_EXEC_ID, 1);
00307 addInxIval (&genQueryInp.selectInp, COL_RULE_EXEC_NAME, 1);
00308 addInxIval (&genQueryInp.selectInp, COL_RULE_EXEC_REI_FILE_PATH, 1);
00309 addInxIval (&genQueryInp.selectInp, COL_RULE_EXEC_USER_NAME, 1);
00310 addInxIval (&genQueryInp.selectInp, COL_RULE_EXEC_ADDRESS, 1);
00311 addInxIval (&genQueryInp.selectInp, COL_RULE_EXEC_TIME, 1);
00312 addInxIval (&genQueryInp.selectInp, COL_RULE_EXEC_FREQUENCY, 1);
00313 addInxIval (&genQueryInp.selectInp, COL_RULE_EXEC_PRIORITY, 1);
00314 addInxIval (&genQueryInp.selectInp, COL_RULE_EXEC_ESTIMATED_EXE_TIME, 1);
00315 addInxIval (&genQueryInp.selectInp, COL_RULE_EXEC_NOTIFICATION_ADDR, 1);
00316
00317
00318 snprintf (condStr, MAX_NAME_LEN, "= 'Wayne'");
00319 addInxVal (&genQueryInp.sqlCondInp, COL_RULE_EXEC_USER_NAME, condStr);
00320
00321 genQueryInp.maxRows=2;
00322
00323 status = chlGenQuery(genQueryInp, &genQueryOut);
00324 printf("chlGenQuery status=%d\n",status);
00325 if (status == 0) {
00326 printGenQOut(&genQueryOut);
00327 }
00328 return(status);
00329 }
00330
00331 int
00332 doTest6(char *testString) {
00333 genQueryInp_t genQueryInp;
00334 genQueryOut_t genQueryOut;
00335 char condStr1[MAX_NAME_LEN];
00336 char condStr2[MAX_NAME_LEN];
00337 int status;
00338
00339 printf("dotest6\n");
00340 rodsLogSqlReq(1);
00341
00342 memset (&genQueryInp, 0, sizeof (genQueryInp));
00343
00344 addInxIval (&genQueryInp.selectInp, COL_TOKEN_NAME, 1);
00345
00346 snprintf (condStr1, MAX_NAME_LEN, "= 'data_type'");
00347 addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_NAMESPACE, condStr1);
00348
00349
00350
00351 snprintf (condStr2, MAX_NAME_LEN, "like '%s%s%s'", "%",
00352 testString,"%");
00353 addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_VALUE2, condStr2);
00354
00355 genQueryInp.maxRows=1;
00356
00357 status = chlGenQuery(genQueryInp, &genQueryOut);
00358 printf("chlGenQuery status=%d\n",status);
00359 if (status == 0) {
00360 printGenQOut(&genQueryOut);
00361 }
00362 return(status);
00363 }
00364
00365 int
00366 doTest7(char *testString, char *testString2, char *testString3,
00367 char *minTotalRows) {
00368 genQueryInp_t genQueryInp;
00369 genQueryOut_t genQueryOut;
00370 char condStr1[MAX_NAME_LEN];
00371 char condStr2[MAX_NAME_LEN];
00372 int status, status2;
00373
00374 printf("dotest7\n");
00375 rodsLogSqlReq(1);
00376
00377 memset (&genQueryInp, 0, sizeof (genQueryInp));
00378
00379 addInxIval (&genQueryInp.selectInp, COL_TOKEN_NAME, 1);
00380
00381 snprintf (condStr1, MAX_NAME_LEN, "= 'data_type'");
00382 addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_NAMESPACE, condStr1);
00383
00384 snprintf (condStr2, MAX_NAME_LEN, "like '%s%s%s'", "%",
00385 testString,"%");
00386 addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_VALUE2, condStr2);
00387
00388 genQueryInp.options=RETURN_TOTAL_ROW_COUNT;
00389 genQueryInp.maxRows=5;
00390 if (testString3 != NULL && *testString3!='\0') {
00391 genQueryInp.maxRows = atoi(testString3);
00392 }
00393
00394 if (testString2 != NULL && *testString2!='\0') {
00395 genQueryInp.rowOffset = atoi(testString2);
00396 }
00397
00398 status = chlGenQuery(genQueryInp, &genQueryOut);
00399 printf("chlGenQuery status=%d\n",status);
00400
00401 printf("genQueryOut->totalRowCount=%d\n", genQueryOut.totalRowCount);
00402
00403 if (status == 0) {
00404 printGenQOut(&genQueryOut);
00405 }
00406
00407 if (minTotalRows != NULL && *minTotalRows!='\0') {
00408 int minTotalRowsInt;
00409 minTotalRowsInt = atoi(minTotalRows);
00410 if (genQueryOut.totalRowCount < minTotalRowsInt) {
00411 rodsLog (LOG_ERROR, "doTest7 chlGenQuery totalRowCount(%d) is less than minimum expected (%d)\n",
00412 genQueryOut.totalRowCount, minTotalRowsInt);
00413 return(-1);
00414 }
00415 }
00416
00417 if (genQueryOut.continueInx>0) {
00418 genQueryInp.continueInx = genQueryOut.continueInx;
00419 printf("Second call to chlGenQuery\n");
00420 status2 = chlGenQuery(genQueryInp, &genQueryOut);
00421 printf("chlGenQuery status=%d\n",status2);
00422 if (status2 == 0) {
00423 printGenQOut(&genQueryOut);
00424 }
00425 }
00426 return(status);
00427 }
00428
00429 int
00430 doTest8(char *testString, char *testString2, char *testString3) {
00431 genQueryInp_t genQueryInp;
00432 genQueryOut_t genQueryOut;
00433
00434 char condStr2[MAX_NAME_LEN];
00435 int status, status2;
00436
00437 printf("dotest8\n");
00438 rodsLogSqlReq(1);
00439
00440 memset (&genQueryInp, 0, sizeof (genQueryInp));
00441
00442 #if 0
00443
00444 addInxIval (&genQueryInp.selectInp, COL_TOKEN_NAME, 1);
00445
00446 snprintf (condStr1, MAX_NAME_LEN, "= 'data_type'");
00447 addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_NAMESPACE, condStr1);
00448
00449 snprintf (condStr2, MAX_NAME_LEN, "begin_of '%s'", testString);
00450 addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_VALUE2, condStr2);
00451 #endif
00452
00453 #if 1
00454
00455
00456
00457 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
00458
00459 snprintf (condStr2, MAX_NAME_LEN, "begin_of '%s'", testString);
00460 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr2);
00461 #endif
00462
00463 genQueryInp.options=RETURN_TOTAL_ROW_COUNT;
00464 genQueryInp.maxRows=5;
00465 if (testString3 != NULL && *testString3!='\0') {
00466 genQueryInp.maxRows = atoi(testString3);
00467 }
00468
00469 if (testString2 != NULL && *testString2!='\0') {
00470 genQueryInp.rowOffset = atoi(testString2);
00471 }
00472
00473 status = chlGenQuery(genQueryInp, &genQueryOut);
00474 printf("chlGenQuery status=%d\n",status);
00475
00476 printf("genQueryOut->totalRowCount=%d\n", genQueryOut.totalRowCount);
00477
00478 if (status == 0) {
00479 printGenQOut(&genQueryOut);
00480 }
00481
00482 if (genQueryOut.continueInx>0) {
00483 genQueryInp.continueInx = genQueryOut.continueInx;
00484 printf("Second call to chlGenQuery\n");
00485 status2 = chlGenQuery(genQueryInp, &genQueryOut);
00486 printf("chlGenQuery status=%d\n",status2);
00487 if (status2 == 0) {
00488 printGenQOut(&genQueryOut);
00489 }
00490 }
00491 return(status);
00492 }
00493
00494 int
00495 doTest9(char *testString, char *testString2) {
00496 genQueryInp_t genQueryInp;
00497 genQueryOut_t genQueryOut;
00498 char condStr1[MAX_NAME_LEN];
00499 int status, status2;
00500 int type;
00501
00502 printf("dotest9\n");
00503 rodsLogSqlReq(1);
00504
00505 memset (&genQueryInp, 0, sizeof (genQueryInp));
00506
00507 type=0;
00508 if (testString2 != NULL) {
00509 if (strcmp(testString2,"min")==0) type=1;
00510 if (strcmp(testString2,"max")==0) type=2;
00511 if (strcmp(testString2,"sum")==0) type=3;
00512 if (strcmp(testString2,"avg")==0) type=4;
00513 if (strcmp(testString2,"count")==0) type=5;
00514 }
00515
00516 if (type==0)
00517 addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, 0);
00518 if (type==1)
00519 addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, SELECT_MIN);
00520 if (type==2)
00521 addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, SELECT_MAX);
00522 if (type==3)
00523 addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, SELECT_SUM);
00524 if (type==4)
00525 addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, SELECT_AVG);
00526 if (type==5)
00527 addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, SELECT_COUNT);
00528
00529 snprintf (condStr1, MAX_NAME_LEN, "= '%s'", testString);
00530
00531 addInxVal (&genQueryInp.sqlCondInp, COL_R_RESC_NAME, condStr1);
00532
00533 genQueryInp.maxRows=5;
00534
00535 status = chlGenQuery(genQueryInp, &genQueryOut);
00536 printf("chlGenQuery status=%d\n",status);
00537
00538 printf("genQueryOut->totalRowCount=%d\n", genQueryOut.totalRowCount);
00539
00540 if (status == 0) {
00541 printGenQOut(&genQueryOut);
00542 }
00543
00544 if (genQueryOut.continueInx>0) {
00545 genQueryInp.continueInx = genQueryOut.continueInx;
00546 printf("Second call to chlGenQuery\n");
00547 status2 = chlGenQuery(genQueryInp, &genQueryOut);
00548 printf("chlGenQuery status=%d\n",status2);
00549 if (status2 == 0) {
00550 printGenQOut(&genQueryOut);
00551 }
00552 }
00553 return(status);
00554 }
00555
00556 int
00557 doTest10(char *userName, char *rodsZone, char *accessPerm, char *collection) {
00558 genQueryInp_t genQueryInp;
00559 genQueryOut_t genQueryOut;
00560 char condStr[MAX_NAME_LEN];
00561 int status;
00562 char accStr[LONG_NAME_LEN];
00563
00564 printf("dotest10\n");
00565 rodsLogSqlReq(1);
00566
00567 memset (&genQueryInp, 0, sizeof (genQueryInp));
00568
00569 snprintf (accStr, LONG_NAME_LEN, "%s", userName);
00570 addKeyVal (&genQueryInp.condInput, USER_NAME_CLIENT_KW, accStr);
00571
00572 snprintf (accStr, LONG_NAME_LEN, "%s", rodsZone);
00573 addKeyVal (&genQueryInp.condInput, RODS_ZONE_CLIENT_KW, accStr);
00574
00575 snprintf (accStr, LONG_NAME_LEN, "%s", accessPerm);
00576 addKeyVal (&genQueryInp.condInput, ACCESS_PERMISSION_KW, accStr);
00577
00578 snprintf (condStr, MAX_NAME_LEN, "='%s'", collection);
00579 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr);
00580
00581 addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
00582
00583 genQueryInp.maxRows = 10;
00584
00585
00586
00587 status = chlGenQuery(genQueryInp, &genQueryOut);
00588 printf("chlGenQuery status=%d\n",status);
00589
00590 printf("genQueryOut->totalRowCount=%d\n", genQueryOut.totalRowCount);
00591
00592 if (status == 0) {
00593 printGenQOut(&genQueryOut);
00594 }
00595
00596 return(0);
00597 }
00598
00599 int
00600 doTest11(char *userName, char *rodsZone, char *accessPerm, char *collection,
00601 char *dataObj) {
00602 genQueryInp_t genQueryInp;
00603 genQueryOut_t genQueryOut;
00604 char condStr[MAX_NAME_LEN];
00605 int status;
00606 char accStr[LONG_NAME_LEN];
00607
00608 printf("dotest11\n");
00609 rodsLogSqlReq(1);
00610
00611 memset (&genQueryInp, 0, sizeof (genQueryInp));
00612
00613 snprintf (accStr, LONG_NAME_LEN, "%s", userName);
00614 addKeyVal (&genQueryInp.condInput, USER_NAME_CLIENT_KW, accStr);
00615
00616 snprintf (accStr, LONG_NAME_LEN, "%s", rodsZone);
00617 addKeyVal (&genQueryInp.condInput, RODS_ZONE_CLIENT_KW, accStr);
00618
00619 snprintf (accStr, LONG_NAME_LEN, "%s", accessPerm);
00620 addKeyVal (&genQueryInp.condInput, ACCESS_PERMISSION_KW, accStr);
00621
00622 snprintf (condStr, MAX_NAME_LEN, "='%s'", collection);
00623 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr);
00624
00625 snprintf (condStr, MAX_NAME_LEN, "='%s'", dataObj);
00626 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, condStr);
00627
00628 addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1);
00629
00630 genQueryInp.maxRows = 10;
00631
00632 status = chlGenQuery(genQueryInp, &genQueryOut);
00633 printf("chlGenQuery status=%d\n",status);
00634
00635 printf("genQueryOut->totalRowCount=%d\n", genQueryOut.totalRowCount);
00636
00637 if (status == 0) {
00638 printGenQOut(&genQueryOut);
00639 }
00640
00641 return(0);
00642 }
00643
00644 int
00645 doTest12(char *userName, char *rodsZone, char *accessPerm, char *collection) {
00646 genQueryInp_t genQueryInp;
00647 genQueryOut_t genQueryOut;
00648 char condStr[MAX_NAME_LEN];
00649 char condStr2[MAX_NAME_LEN];
00650 int status;
00651 char accStr[LONG_NAME_LEN];
00652 int doAccessControlToQuery=0;
00653
00654 printf("dotest12\n");
00655 rodsLogSqlReq(1);
00656
00657 memset (&genQueryInp, 0, sizeof (genQueryInp));
00658
00659 if (doAccessControlToQuery) {
00660 snprintf (accStr, LONG_NAME_LEN, "%s", userName);
00661 addKeyVal (&genQueryInp.condInput, USER_NAME_CLIENT_KW, accStr);
00662
00663 snprintf (accStr, LONG_NAME_LEN, "%s", rodsZone);
00664 addKeyVal (&genQueryInp.condInput, RODS_ZONE_CLIENT_KW, accStr);
00665
00666 snprintf (accStr, LONG_NAME_LEN, "%s", accessPerm);
00667 addKeyVal (&genQueryInp.condInput, ACCESS_PERMISSION_KW, accStr);
00668 }
00669
00670 snprintf (condStr, MAX_NAME_LEN, "='%s'", collection);
00671 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr);
00672
00673 addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
00674
00675 snprintf (condStr2, LONG_NAME_LEN, "='%s'", userName);
00676 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_USER_NAME, condStr2);
00677
00678 snprintf (condStr2, LONG_NAME_LEN, "='%s'", rodsZone);
00679 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_USER_ZONE, condStr2);
00680
00681 addInxIval (&genQueryInp.selectInp, COL_COLL_ACCESS_NAME, ORDER_BY);
00682
00683 #if 0
00684 addInxIval (&genQueryInp.selectInp, COL_COLL_ACCESS_USER_ID, 1);
00685 #endif
00686
00687 genQueryInp.maxRows = 10;
00688
00689
00690
00691 status = chlGenQuery(genQueryInp, &genQueryOut);
00692 printf("chlGenQuery status=%d\n",status);
00693
00694 printf("genQueryOut->totalRowCount=%d\n", genQueryOut.totalRowCount);
00695
00696 if (status == 0) {
00697 printGenQOut(&genQueryOut);
00698 }
00699
00700 return(0);
00701 }
00702
00703 int
00704 doTest13(char *userName, char *rodsZone, char *accessPerm, char *collection,
00705 char *fileName) {
00706 genQueryInp_t genQueryInp;
00707 genQueryOut_t genQueryOut;
00708 char condStr[MAX_NAME_LEN];
00709 char condStr2[MAX_NAME_LEN];
00710 int status;
00711 char accStr[LONG_NAME_LEN];
00712 int doAccessControlToQuery=0;
00713
00714 printf("dotest13\n");
00715 rodsLogSqlReq(1);
00716
00717 memset (&genQueryInp, 0, sizeof (genQueryInp));
00718
00719 if (doAccessControlToQuery) {
00720 snprintf (accStr, LONG_NAME_LEN, "%s", userName);
00721 addKeyVal (&genQueryInp.condInput, USER_NAME_CLIENT_KW, accStr);
00722
00723 snprintf (accStr, LONG_NAME_LEN, "%s", rodsZone);
00724 addKeyVal (&genQueryInp.condInput, RODS_ZONE_CLIENT_KW, accStr);
00725
00726 snprintf (accStr, LONG_NAME_LEN, "%s", accessPerm);
00727 addKeyVal (&genQueryInp.condInput, ACCESS_PERMISSION_KW, accStr);
00728 }
00729
00730 snprintf (condStr, MAX_NAME_LEN, "='%s'", collection);
00731 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr);
00732
00733 snprintf (condStr, MAX_NAME_LEN, "='%s'", fileName);
00734 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_NAME, condStr);
00735
00736 addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1);
00737
00738 snprintf (condStr2, LONG_NAME_LEN, "='%s'", userName);
00739 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_USER_NAME, condStr2);
00740
00741 snprintf (condStr2, LONG_NAME_LEN, "='%s'", rodsZone);
00742 addInxVal (&genQueryInp.sqlCondInp, COL_DATA_USER_ZONE, condStr2);
00743
00744 addInxIval (&genQueryInp.selectInp, COL_DATA_ACCESS_NAME, ORDER_BY);
00745
00746 #if 0
00747 addInxIval (&genQueryInp.selectInp, COL_DATA_ACCESS_USER_ID, 1);
00748 #endif
00749
00750 genQueryInp.maxRows = 10;
00751
00752
00753
00754 status = chlGenQuery(genQueryInp, &genQueryOut);
00755 printf("chlGenQuery status=%d\n",status);
00756
00757 printf("genQueryOut->totalRowCount=%d\n", genQueryOut.totalRowCount);
00758
00759 if (status == 0) {
00760 printGenQOut(&genQueryOut);
00761 }
00762
00763 return(0);
00764 }
00765
00766
00767 int
00768 doTest15(char *testString, char *testString2, char *testString3) {
00769 genQueryInp_t genQueryInp;
00770 genQueryOut_t genQueryOut;
00771 char condStr1[MAX_NAME_LEN];
00772 char condStr2[MAX_NAME_LEN];
00773 int status;
00774
00775 printf("dotest15\n");
00776 rodsLogSqlReq(1);
00777
00778 memset (&genQueryInp, 0, sizeof (genQueryInp));
00779
00780 addInxIval (&genQueryInp.selectInp, COL_TOKEN_NAME, 1);
00781
00782 snprintf (condStr1, MAX_NAME_LEN, "= 'data_type'");
00783 addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_NAMESPACE, condStr1);
00784
00785 snprintf (condStr2, MAX_NAME_LEN, "like '%s%s%s'", "%",
00786 testString,"%");
00787 addInxVal (&genQueryInp.sqlCondInp, COL_TOKEN_VALUE2, condStr2);
00788
00789 genQueryInp.options=AUTO_CLOSE;
00790 genQueryInp.maxRows=1;
00791 if (testString3 != NULL && *testString3!='\0') {
00792 genQueryInp.maxRows = atoi(testString3);
00793 }
00794
00795 if (testString2 != NULL && *testString2!='\0') {
00796 genQueryInp.rowOffset = atoi(testString2);
00797 }
00798
00799 status = chlGenQuery(genQueryInp, &genQueryOut);
00800 printf("chlGenQuery status=%d\n",status);
00801
00802 if (status == 0) {
00803 printGenQOut(&genQueryOut);
00804 }
00805 return(status);
00806 }
00807
00808
00809 int
00810 main(int argc, char **argv) {
00811 int i1, i2, i3, i;
00812 genQueryInp_t genQueryInp;
00813 int i1a[10];
00814 int i2a[10];
00815 int done;
00816 int mode;
00817 char *condVal[2];
00818 char v1[20];
00819 rodsServerConfig_t serverConfig;
00820
00821
00822 rodsLogLevel(LOG_ERROR);
00823
00824
00825 rodsLogSqlReq(1);
00826
00827 i1=7;
00828 i2=5;
00829
00830 done=0;
00831 mode = 0;
00832 if (argc >= 2) {
00833 if (strcmp(argv[1],"gen")==0) mode=1;
00834 if (strcmp(argv[1],"ls")==0) mode=2;
00835 if (strcmp(argv[1],"gen2")==0) mode=3;
00836 if (strcmp(argv[1],"gen3")==0) mode=4;
00837 if (strcmp(argv[1],"gen4")==0) mode=5;
00838 if (strcmp(argv[1],"gen5")==0) mode=6;
00839 if (strcmp(argv[1],"gen6")==0) mode=7;
00840 if (strcmp(argv[1],"gen7")==0) mode=8;
00841 if (strcmp(argv[1],"gen8")==0) mode=9;
00842 if (strcmp(argv[1],"gen9")==0) mode=10;
00843 if (strcmp(argv[1],"gen10")==0) mode=11;
00844 if (strcmp(argv[1],"gen11")==0) mode=12;
00845 if (strcmp(argv[1],"gen12")==0) mode=13;
00846 if (strcmp(argv[1],"gen13")==0) mode=14;
00847 if (strcmp(argv[1],"lsr")==0) mode=15;
00848 if (strcmp(argv[1],"gen15")==0) mode=16;
00849 }
00850
00851 if (argc ==3 && mode==0) {
00852 i1 = atoi(argv[1]);
00853 i2 = atoi(argv[2]);
00854 sTest(i1, i2);
00855 done++;
00856 }
00857
00858 if (argc == 4 && mode==0) {
00859 i1 = atoi(argv[1]);
00860 i2 = atoi(argv[2]);
00861 i3 = atoi(argv[3]);
00862 sTest2(i1, i2, i3);
00863 done++;
00864 }
00865
00866 if (argc==2 && mode==0 ) {
00867 int j;
00868 j = atoi(argv[1]);
00869 if (j >= 0) {
00870 printf("finding cycles starting with table %d\n",j);
00871 i = findCycles(j);
00872 printf("status = %d\n", i);
00873 }
00874 else {
00875 printf("finding cycles for all tables\n");
00876 printf("last test should be -816000 if last table finished\n");
00877 i=0;
00878 for (j=0;i==0;j++) {
00879 i = findCycles(j);
00880 printf("starting with table %d status = %d\n", j, i);
00881 }
00882 if (j > 70 && i == CAT_INVALID_ARGUMENT) {
00883 printf(
00884 "Success: Searched all tables (0 to %d) and no cycles found\n",
00885 j-1);
00886 exit(0);
00887 } else {
00888 exit(5);
00889 }
00890 }
00891 done++;
00892 }
00893
00894 memset((char*)&genQueryInp, 0, sizeof(genQueryInp));
00895
00896 genQueryInp.maxRows = 10;
00897 genQueryInp.continueInx = 0;
00898
00899
00900
00901
00902
00903
00904
00905
00906 i1a[0]=COL_COLL_NAME;
00907
00908 genQueryInp.selectInp.inx = i1a;
00909 genQueryInp.selectInp.len = 1;
00910
00911 i2a[0]=COL_D_DATA_PATH;
00912 genQueryInp.sqlCondInp.inx = i2a;
00913 strcpy(v1, "='b'");
00914 condVal[0]=v1;
00915 genQueryInp.sqlCondInp.value = condVal;
00916 genQueryInp.sqlCondInp.len=1;
00917
00918 if (mode==1) {
00919 if (argc == 3) {
00920 i1a[0]=atoi(argv[2]);
00921 }
00922 }
00923 if (done==0) {
00924 int status;
00925 genQueryOut_t result;
00926 rodsEnv myEnv;
00927
00928 memset((char *)&result, 0, sizeof(result));
00929 memset((char *)&myEnv, 0, sizeof(myEnv));
00930 status = getRodsEnv (&myEnv);
00931 if (status < 0) {
00932 rodsLog (LOG_ERROR, "main: getRodsEnv error. status = %d",
00933 status);
00934 exit (1);
00935 }
00936
00937
00938
00939
00940 chlGenQueryAccessControlSetup(myEnv.rodsUserName,
00941 myEnv.rodsZone,
00942 LOCAL_PRIV_USER_AUTH, 1);
00943
00944 if (strstr(myEnv.rodsDebug, "CAT") != NULL) {
00945 chlDebug(myEnv.rodsDebug);
00946 }
00947
00948 memset(&serverConfig, 0, sizeof(serverConfig));
00949 status = readServerConfig(&serverConfig);
00950 if (status) {
00951 printf("Error %d from readServerConfig\n", status);
00952 }
00953
00954 if ((status = chlOpen( &serverConfig)) != 0) {
00955
00956 rodsLog (LOG_SYS_FATAL,
00957 "chlopen Error. Status = %d",
00958 status);
00959 return (status);
00960 }
00961 if (mode==2) {
00962
00963 doLs2();
00964 exit(0);
00965 }
00966 if (mode==3) {
00967 doTest2();
00968 exit(0);
00969 }
00970 if (mode==4) {
00971 doTest3();
00972 exit(0);
00973 }
00974 if (mode==5) {
00975 doTest4();
00976 exit(0);
00977 }
00978 if (mode==6) {
00979 doTest5();
00980 exit(0);
00981 }
00982 if (mode==7) {
00983 doTest6(argv[2]);
00984 exit(0);
00985 }
00986
00987 if (mode==8) {
00988 status = doTest7(argv[2], argv[3], argv[4], argv[5]);
00989 if (status <0) exit(1);
00990 exit(0);
00991 }
00992
00993 if (mode==9) {
00994 status = doTest8(argv[2], argv[3], argv[4]);
00995 if (status <0) exit(2);
00996 exit(0);
00997 }
00998
00999 if (mode==10) {
01000 status = doTest9(argv[2], argv[3]);
01001 if (status <0) exit(2);
01002 exit(0);
01003 }
01004
01005 if (mode==11) {
01006 status = doTest10(argv[2], argv[3], argv[4], argv[5]);
01007 if (status <0) exit(2);
01008 exit(0);
01009 }
01010
01011 if (mode==12) {
01012 status = doTest11(argv[2], argv[3], argv[4], argv[5], argv[6]);
01013 if (status <0) exit(2);
01014 exit(0);
01015 }
01016 if (mode==13) {
01017 status = doTest12(argv[2], argv[3], argv[4], argv[5]);
01018 if (status <0) exit(2);
01019 exit(0);
01020 }
01021 if (mode==14) {
01022 status = doTest13(argv[2], argv[3], argv[4], argv[5], argv[6]);
01023 if (status <0) exit(2);
01024 exit(0);
01025 }
01026 if (mode==15) {
01027 status = doLs3(argv[2]);
01028 if (status <0) exit(2);
01029 exit(0);
01030 }
01031 if (mode==16) {
01032 status = doTest15(argv[2], argv[3], argv[4]);
01033 if (status <0) exit(2);
01034 exit(0);
01035 }
01036
01037 genQueryInp.maxRows=2;
01038 i = chlGenQuery(genQueryInp, &result);
01039 printf("chlGenQuery status=%d\n",i);
01040 printf("result.rowCnt=%d\n", result.rowCnt);
01041 if (result.rowCnt > 0) {
01042 int i;
01043 for (i=0;i<result.rowCnt;i++) {
01044 printf("result.SqlResult[%d].value=%s\n",i,
01045 result.sqlResult[i].value);
01046 }
01047 }
01048 }
01049 exit(0);
01050 }