Exemple #1
0
/*
Do a query on AVUs for users and show the results
 */
int queryUser(char *attribute, char *op, char *value) {
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[BIG_STR];
   char v2[BIG_STR];
   int status;
   char *columnNames[]={"user", "zone"};

   printCount=0;
   memset (&genQueryInp, 0, sizeof (genQueryInp_t));

   i1a[0]=COL_USER_NAME;
   i1b[0]=0;  /* (unused) */
   i1a[1]=COL_USER_ZONE;
   i1b[1]=0;  /* (unused) */
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 2;

   i2a[0]=COL_META_USER_ATTR_NAME;
   sprintf(v1,"='%s'",attribute);
   condVal[0]=v1;

   i2a[1]=COL_META_USER_ATTR_VALUE;
   sprintf(v2, "%s '%s'", op, value);
   condVal[1]=v2;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=2;

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);

   printGenQueryResults(Conn, status, genQueryOut, columnNames);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Exemple #2
0
/* perform the list data-types command */
int
doListDataTypes(rcComm_t *Conn) {
   
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int select_inx[3];
   int select_value[3]={0,0,0};
   int condition_inx[3];
   char *condition_value[10];
   char value1[MAX_NAME_LEN+10]="='data_type'";
   int i, status;
   int printCount;

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));
   printCount=0;

   printf("Defined data-types:\n");

   i=0;
   select_inx[i++]=COL_TOKEN_NAME;
   
   genQueryInp.selectInp.inx = select_inx;
   genQueryInp.selectInp.value = select_value;
   genQueryInp.selectInp.len = i;

   genQueryInp.sqlCondInp.inx = condition_inx;
   genQueryInp.sqlCondInp.value = condition_value;
   condition_inx[0]=COL_TOKEN_NAMESPACE;
   condition_value[0]=value1;
   genQueryInp.sqlCondInp.len=1;

   genQueryInp.maxRows=50;
   genQueryInp.continueInx=0;
   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      printf("None exist.\n");
      return(0);
   }

   printCount+= printGenQueryResults(Conn, status, genQueryOut, 0, 
				     0);
   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      printCount+= printGenQueryResults(Conn, status, genQueryOut, 
					0, 0);
   }

   return (1);
}
Exemple #3
0
/*
Via a general query, show a resource
*/
int
showResc( char *name, int longOption ) {
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut;
    int i1a[20];
    int i1b[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    int i2a[20];
    char *condVal[10];
    char v1[BIG_STR];
    int i, status;
    int printCount;
    char *columnNames[] = {"resource name", "id", "zone", "type", "class",
                           "location",  "vault", "free space", "free space time", "status",
                           "info", "comment", "create time", "modify time", "children",
                           "context", "parent", "object count"
                          };

    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    printCount = 0;

    i = 0;
    i1a[i++] = COL_R_RESC_NAME;
    if ( longOption ) {
        i1a[i++] = COL_R_RESC_ID;
        i1a[i++] = COL_R_ZONE_NAME;
        i1a[i++] = COL_R_TYPE_NAME;
        i1a[i++] = COL_R_CLASS_NAME;
        i1a[i++] = COL_R_LOC;
        i1a[i++] = COL_R_VAULT_PATH;
        i1a[i++] = COL_R_FREE_SPACE;
        i1a[i++] = COL_R_FREE_SPACE_TIME;
        i1a[i++] = COL_R_RESC_STATUS;
        i1a[i++] = COL_R_RESC_INFO;
        i1a[i++] = COL_R_RESC_COMMENT;
        i1a[i++] = COL_R_CREATE_TIME;
        i1a[i++] = COL_R_MODIFY_TIME;
        i1a[i++] = COL_R_RESC_CHILDREN;
        i1a[i++] = COL_R_RESC_CONTEXT;
        i1a[i++] = COL_R_RESC_PARENT;
        i1a[i++] = COL_R_RESC_OBJCOUNT;

    }
    else {
        columnNames[0] = "";
    }

    genQueryInp.selectInp.inx = i1a;
    genQueryInp.selectInp.value = i1b;
    genQueryInp.selectInp.len = i;

    genQueryInp.sqlCondInp.inx = i2a;
    genQueryInp.sqlCondInp.value = condVal;
    if ( name != NULL && *name != '\0' ) {
        // =-=-=-=-=-=-=-
        // JMC - backport 4629
        if ( strncmp( name, BUNDLE_RESC, sizeof( BUNDLE_RESC ) ) == 0 ) {
            printf( "%s is a pseudo resource for system use only.\n",
                    BUNDLE_RESC );
            return 0;
        }
        // =-=-=-=-=-=-=-
        i2a[0] = COL_R_RESC_NAME;
        snprintf( v1, BIG_STR, "='%s'", name );
        condVal[0] = v1;
        genQueryInp.sqlCondInp.len = 1;
    }
    else {
        // =-=-=-=-=-=-=-
        // JMC - backport 4629
        i2a[0] = COL_R_RESC_NAME;
        sprintf( v1, "!='%s'", BUNDLE_RESC ); /* all but bundleResc */
        condVal[0] = v1;
        genQueryInp.sqlCondInp.len = 1;
        // =-=-=-=-=-=-=-
    }

    if ( zoneArgument[0] != '\0' ) {
        addKeyVal( &genQueryInp.condInput, ZONE_KW, zoneArgument );
    }

    genQueryInp.maxRows = 50;
    genQueryInp.continueInx = 0;
    status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
    if ( status == CAT_NO_ROWS_FOUND ) {
        i1a[0] = COL_R_RESC_INFO;
        genQueryInp.selectInp.len = 1;
        status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
        if ( status == 0 ) {
            printf( "None\n" );
            return 0;
        }
        if ( status == CAT_NO_ROWS_FOUND ) {
            if ( name != NULL && name[0] != '\0' ) {
                printf( "Resource %s does not exist.\n", name );
            }
            else {
                printf( "Resource does not exist.\n" );
            }
            return 0;
        }
    }

    printCount += printGenQueryResults( Conn, status, genQueryOut, columnNames,
                                        longOption );
    while ( status == 0 && genQueryOut->continueInx > 0 ) {
        genQueryInp.continueInx = genQueryOut->continueInx;
        status = rcGenQuery( Conn, &genQueryInp, &genQueryOut );
        if ( genQueryOut->rowCnt > 0 && longOption ) {
            printf( "----\n" );
        }
        printCount += printGenQueryResults( Conn, status, genQueryOut,
                                            columnNames, longOption );
    }

    return 1;
}
Exemple #4
0
/* perform the ls command */
int
doLs(rcComm_t *Conn, char *objPath, int longOption) {
   
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[30];
   int i1b[30]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
   int i2a[30];
   char *condVal[10];
   char v1[MAX_NAME_LEN+10];
   char v2[MAX_NAME_LEN+10];
   int i, status;
   int printCount;

   char *columnNames[]={
   "data_name",
   "data_id", "coll_id", "data_repl_num", "data_version",
   "data_type_name", "data_size", "resc_group_name", "resc_name",
   "data_path ", "data_owner_name", "data_owner_zone", 
   "data_repl_status", "data_status",
   "data_checksum ", "data_expiry_ts (expire time)",
   "data_map_id", "r_comment", "create_ts","modify_ts"};

   char logicalEndName[MAX_NAME_LEN];
   char logicalParentDirName[MAX_NAME_LEN];

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));
   printCount=0;

   printf("doing ls of %s\n", objPath);

   status = splitPathByKey(objPath,
			   logicalParentDirName, logicalEndName, '/');

   i=0;
   i1a[i++]=COL_DATA_NAME;
   if (longOption) {   
      i1a[i++]=COL_D_DATA_ID;
      i1a[i++]=COL_D_COLL_ID;
      i1a[i++]=COL_DATA_REPL_NUM;
      i1a[i++]=COL_DATA_VERSION;
      i1a[i++]=COL_DATA_TYPE_NAME;
      i1a[i++]=COL_DATA_SIZE;
      i1a[i++]=COL_D_RESC_GROUP_NAME;
      i1a[i++]=COL_D_RESC_NAME;
      i1a[i++]=COL_D_DATA_PATH;
      i1a[i++]=COL_D_OWNER_NAME;
      i1a[i++]=COL_D_OWNER_ZONE;
      i1a[i++]=COL_D_REPL_STATUS;
      i1a[i++]=COL_D_DATA_STATUS;
      i1a[i++]=COL_D_DATA_CHECKSUM;
      i1a[i++]=COL_D_EXPIRY;
      i1a[i++]=COL_D_MAP_ID;
      i1a[i++]=COL_D_COMMENTS;
      i1a[i++]=COL_D_CREATE_TIME;
      i1a[i++]=COL_D_MODIFY_TIME;
   }
   else {
      columnNames[1]="data_expiry_ts (expire time)";
      i1a[i++]=COL_D_EXPIRY;
   }
   
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = i;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   i2a[0]=COL_COLL_NAME;
   snprintf(v1,sizeof(v1),"='%s'",logicalParentDirName);
   condVal[0]=v1;
   i2a[1]=COL_DATA_NAME;
   snprintf(v2,sizeof(v1),"='%s'",logicalEndName);
   condVal[1]=v2;
   genQueryInp.sqlCondInp.len=2;

   genQueryInp.maxRows=50;
   genQueryInp.continueInx=0;
   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_R_RESC_INFO;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 printf("DataObject %s does not exist.\n", objPath);
	 return(0);
      }
   }

   printCount+= printGenQueryResults(Conn, status, genQueryOut, columnNames, 
				     longOption);
   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt > 0 && longOption) {
	 printf("----\n");
      }
      printCount+= printGenQueryResults(Conn, status, genQueryOut, 
					columnNames, longOption);
   }

   return (1);
}
Exemple #5
0
/*
 Via a general query and show the AVUs for a dataobject.
 */
int
showDataObj(char *name, char *attrName, int wild) 
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[BIG_STR];
   char v2[BIG_STR];
   char v3[BIG_STR];
   char fullName[MAX_NAME_LEN];
   char myDirName[MAX_NAME_LEN];
   char myFileName[MAX_NAME_LEN];
   int status;
   /* "id" only used in testMode, in longMode id is reset to be 'time set' :*/
   char *columnNames[]={"attribute", "value", "units", "id"};

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));

   printf("AVUs defined for dataObj %s:\n",name);
   printCount=0;
   i1a[0]=COL_META_DATA_ATTR_NAME;
   i1b[0]=0;
   i1a[1]=COL_META_DATA_ATTR_VALUE;
   i1b[1]=0;
   i1a[2]=COL_META_DATA_ATTR_UNITS;
   i1b[2]=0;
   if (testMode) {
      i1a[3]=COL_META_DATA_ATTR_ID;
      i1b[3]=0;
   }
   if (longMode) {
      i1a[3]=COL_META_DATA_MODIFY_TIME;
      i1b[3]=0;
      columnNames[3]="time set";
   }
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 3;
   if (testMode) {
      genQueryInp.selectInp.len = 4;
   }
   if (longMode) {
      genQueryInp.selectInp.len = 4;
   }

   i2a[0]=COL_COLL_NAME;
   sprintf(v1,"='%s'",cwd);
   condVal[0]=v1;

   i2a[1]=COL_DATA_NAME;
   sprintf(v2,"='%s'",name);
   condVal[1]=v2;

   strncpy(fullName, cwd, MAX_NAME_LEN);
   rstrcat(fullName, "/", MAX_NAME_LEN);
   rstrcat(fullName, name, MAX_NAME_LEN);
   if (strstr(name, "/") != NULL) {
      /* reset v1 and v2 for when full path or relative path entered */
      if (*name=='/') {
	 strncpy(fullName, name, MAX_NAME_LEN);
      }
      status = splitPathByKey(fullName, 
			      myDirName, myFileName, '/');
      sprintf(v1,"='%s'",myDirName);
      sprintf(v2,"='%s'",myFileName);
   }

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=2;

   if (attrName != NULL && *attrName!='\0') {
      i2a[2]=COL_META_DATA_ATTR_NAME;
      if (wild) {
	 sprintf(v3,"like '%s'",attrName);
      }
      else {
	 sprintf(v3,"= '%s'",attrName);
      }
      condVal[2]=v3;
      genQueryInp.sqlCondInp.len++;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_D_DATA_PATH;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 printf("Dataobject %s does not exist.\n", fullName);
	 return(0);
      }
      printGenQueryResults(Conn, status, genQueryOut, columnNames);
   }
   else {
      printGenQueryResults(Conn, status, genQueryOut, columnNames);
   }

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Exemple #6
0
/*
Do a query on AVUs for collections and show the results
 */
int queryCollection(char *cmdToken[]) {
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[20];
   int i1b[20];
   int i2a[20];
   char *condVal[20];
   char v1[BIG_STR];
   char v2[BIG_STR];
   char v3[BIG_STR];
   int status;
   char *columnNames[]={"collection"};
   int cmdIx;
   int condIx;
   char vstr[20] [BIG_STR];

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));

   printCount=0;
   i1a[0]=COL_COLL_NAME;
   i1b[0]=0;  /* (unused) */
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 1;

   i2a[0]=COL_META_COLL_ATTR_NAME;
   sprintf(v1,"='%s'", cmdToken[2]);
   condVal[0]=v1;

   i2a[1]=COL_META_COLL_ATTR_VALUE;
   sprintf(v2, "%s '%s'", cmdToken[3], cmdToken[4]);
   condVal[1]=v2;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=2;

   if (strcmp(cmdToken[5], "or")==0) {
      sprintf(v3, "|| %s '%s'", cmdToken[6], cmdToken[7]);
      rstrcat(v2, v3, BIG_STR);
   }

   cmdIx = 5;
   condIx = 2;
   while (strcmp(cmdToken[cmdIx], "and")==0) {
      i2a[condIx]=COL_META_COLL_ATTR_NAME;
      cmdIx++;
      sprintf(vstr[condIx],"='%s'", cmdToken[cmdIx]);
      condVal[condIx]=vstr[condIx];
      condIx++;

      i2a[condIx]=COL_META_COLL_ATTR_VALUE;
      sprintf(vstr[condIx], "%s '%s'", cmdToken[cmdIx+1], cmdToken[cmdIx+2]);
      cmdIx+=3;
      condVal[condIx]=vstr[condIx];
      condIx++;
      genQueryInp.sqlCondInp.len+=2;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);

   printGenQueryResults(Conn, status, genQueryOut, columnNames);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Exemple #7
0
/*
Via a general query, show the AVUs for a user
*/
int
showUser(char *name, char *attrName, int wild)
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[BIG_STR];
   char v2[BIG_STR];
   char v3[BIG_STR];
   int status;
   char *columnNames[]={"attribute", "value", "units"};

   char userName[NAME_LEN];
   char userZone[NAME_LEN];

   status = parseUserName(name, userName, userZone);
   if (status) {
      printf("Invalid username format\n");
      return(0);
   }
   if (userZone[0]=='\0') {
      strncpy(userZone, myEnv.rodsZone, NAME_LEN);
   }

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));

   printf("AVUs defined for user %s#%s:\n",userName, userZone);
   printCount=0;
   i1a[0]=COL_META_USER_ATTR_NAME;
   i1b[0]=0; /* currently unused */
   i1a[1]=COL_META_USER_ATTR_VALUE;
   i1b[1]=0;
   i1a[2]=COL_META_USER_ATTR_UNITS;
   i1b[2]=0;
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 3;

   i2a[0]=COL_USER_NAME;
   sprintf(v1,"='%s'",userName);
   condVal[0]=v1;

   i2a[1]=COL_USER_ZONE;
   sprintf(v2,"='%s'",userZone);
   condVal[1]=v2;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=2;

   if (attrName != NULL && *attrName!='\0') {
      i2a[2]=COL_META_USER_ATTR_NAME;
      if (wild) {
	 sprintf(v3,"like '%s'",attrName);
      }
      else {
	 sprintf(v3,"= '%s'",attrName);
      }
      condVal[2]=v3;
      genQueryInp.sqlCondInp.len++;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_USER_COMMENT;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 printf("User %s does not exist.\n", name);
	 return(0);
      }
   }

   printGenQueryResults(Conn, status, genQueryOut, columnNames);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Exemple #8
0
/*
Via a general query, show the AVUs for a resource group
*/
int
showRescGroup(char *name, char *attrName, int wild) 
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[BIG_STR];
   char v2[BIG_STR];
   int  status;
   char *columnNames[]={"attribute", "value", "units"};

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));

   printf("AVUs defined for resource group %s:\n",name);
   printCount=0;
   i1a[0]=COL_META_RESC_GROUP_ATTR_NAME;
   i1b[0]=0; /* currently unused */
   i1a[1]=COL_META_RESC_GROUP_ATTR_VALUE;
   i1b[1]=0;
   i1a[2]=COL_META_RESC_GROUP_ATTR_UNITS;
   i1b[2]=0;
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 3;

   i2a[0]=COL_RESC_GROUP_NAME;
   sprintf(v1,"='%s'",name);
   condVal[0]=v1;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=1;

   if (attrName != NULL && *attrName!='\0') {
      i2a[1]=COL_META_RESC_GROUP_ATTR_NAME;
      if (wild) {
	 sprintf(v2,"like '%s'",attrName);
      }
      else {
	 sprintf(v2,"= '%s'",attrName);
      }
      condVal[1]=v2;
      genQueryInp.sqlCondInp.len++;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   /*
   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }
   */
   
   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      /* When no AVU found, test the existence of the resource group itself */
      i1a[0]=COL_RESC_GROUP_NAME;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 printf("Resource group %s does not exist.\n", name);
	 return(0);
      }
   }

   printGenQueryResults(Conn, status, genQueryOut, columnNames);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}
Exemple #9
0
/*
Via a general query, show the AVUs for a collection
*/
int
showColl(char *name, char *attrName, int wild) 
{
   genQueryInp_t genQueryInp;
   genQueryOut_t *genQueryOut;
   int i1a[10];
   int i1b[10];
   int i2a[10];
   char *condVal[10];
   char v1[BIG_STR];
   char v2[BIG_STR];
   char fullName[MAX_NAME_LEN];
   int  status;
   char *columnNames[]={"attribute", "value", "units"};

   memset (&genQueryInp, 0, sizeof (genQueryInp_t));

   printf("AVUs defined for collection %s:\n",name);
   printCount=0;
   i1a[0]=COL_META_COLL_ATTR_NAME;
   i1b[0]=0; /* currently unused */
   i1a[1]=COL_META_COLL_ATTR_VALUE;
   i1b[1]=0;
   i1a[2]=COL_META_COLL_ATTR_UNITS;
   i1b[2]=0;
   genQueryInp.selectInp.inx = i1a;
   genQueryInp.selectInp.value = i1b;
   genQueryInp.selectInp.len = 3;

   strncpy(fullName, cwd, MAX_NAME_LEN);
   if (strlen(name)>0) {
      if (*name=='/') {
	 strncpy(fullName, name, MAX_NAME_LEN);
      }
      else {
	 rstrcat(fullName, "/", MAX_NAME_LEN);
	 rstrcat(fullName, name, MAX_NAME_LEN);
      }
   }
   i2a[0]=COL_COLL_NAME;
   sprintf(v1,"='%s'",fullName);
   condVal[0]=v1;

   genQueryInp.sqlCondInp.inx = i2a;
   genQueryInp.sqlCondInp.value = condVal;
   genQueryInp.sqlCondInp.len=1;

   if (attrName != NULL && *attrName!='\0') {
      i2a[1]=COL_META_COLL_ATTR_NAME;
      if (wild) {
	 sprintf(v2,"like '%s'",attrName);
      }
      else {
	 sprintf(v2,"= '%s'",attrName);
      }
      condVal[1]=v2;
      genQueryInp.sqlCondInp.len++;
   }

   genQueryInp.maxRows=10;
   genQueryInp.continueInx=0;
   genQueryInp.condInput.len=0;

   if (zoneArgument[0]!='\0') {
      addKeyVal (&genQueryInp.condInput, ZONE_KW, zoneArgument);
   }

   status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
   if (status == CAT_NO_ROWS_FOUND) {
      i1a[0]=COL_COLL_COMMENTS;
      genQueryInp.selectInp.len = 1;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (status==0) {
	 printf("None\n");
	 return(0);
      }
      if (status == CAT_NO_ROWS_FOUND) {
	 printf("Collection %s does not exist.\n", fullName);
	 return(0);
      }
   }

   printGenQueryResults(Conn, status, genQueryOut, columnNames);

   while (status==0 && genQueryOut->continueInx > 0) {
      genQueryInp.continueInx=genQueryOut->continueInx;
      status = rcGenQuery(Conn, &genQueryInp, &genQueryOut);
      if (genQueryOut->rowCnt>0) printf("----\n");
      printGenQueryResults(Conn, status, genQueryOut, 
					columnNames);
   }

   return (0);
}