irods::error get_query_array( rsComm_t* _comm, json_t*& _queries ) { if( !_comm ) { return ERROR( SYS_INVALID_INPUT_PARAM, "comm is null" ); } _queries = json_array(); if ( !_queries ) { return ERROR( SYS_MALLOC_ERR, "allocation of json object failed" ); } specificQueryInp_t spec_inp; memset( &spec_inp, 0, sizeof( specificQueryInp_t ) ); spec_inp.maxRows = MAX_SQL_ROWS; spec_inp.continueInx = 0; spec_inp.sql = "ls"; genQueryOut_t* gen_out = 0; int status = rsSpecificQuery( _comm, &spec_inp, &gen_out ); if( status < 0 ) { return ERROR( status, "rsSpecificQuery for 'ls' failed" ); } // first attribute is the alias of the specific query int len = gen_out->sqlResult[ 0 ].len; char* values = gen_out->sqlResult[ 0 ].value; for( int i = 0 ; i < gen_out->rowCnt ; ++i ) { char* alias = &values[ len * i ]; if( !alias ) { rodsLog( LOG_ERROR, "get_query_array - alias at %d is null", i ); continue; } json_array_append( _queries, json_string( alias ) ); } // for i freeGenQueryOut( &gen_out ); return SUCCESS(); } // get_query_array
/* Try a specific-query for the a particular Data-object in collection query first, for performance improvements, before going back to a general-query. This is called from rsQueryDataObjInCollReCur below. See the svn commit log (r5682) for the specific query definition. */ int trySpecificQueryDataObjInCollReCur( rsComm_t *rsComm, char *collection, genQueryOut_t **genQueryOut ) { int status = 0; char collNamePercent[MAX_NAME_LEN + 2]; specificQueryInp_t specificQueryInp; rstrcpy( collNamePercent, collection, MAX_NAME_LEN ); rstrcat( collNamePercent, "/%", MAX_NAME_LEN ); memset( &specificQueryInp, 0, sizeof( specificQueryInp_t ) ); specificQueryInp.maxRows = MAX_SQL_ROWS; specificQueryInp.continueInx = 0; specificQueryInp.sql = "DataObjInCollReCur"; specificQueryInp.args[0] = collection; specificQueryInp.args[1] = collNamePercent; status = rsSpecificQuery( rsComm, &specificQueryInp, genQueryOut ); if ( status == 0 ) { /* Set the attriInx values so the server-side code can locate the fields (avoid a UNMATCHED_KEY_OR_INDEX error) the way general-query is handled. The specific-query can't set these because the columns being returned are not known (unlike for general-query). So this code assumes the DataObjInCollReCur is defined correctly and is returning the following columns. The result->attriCnt == 6 test is a sanity check. */ genQueryOut_t *result; result = *genQueryOut; if ( result->attriCnt == 7 ) { result->sqlResult[0].attriInx = COL_D_DATA_ID; result->sqlResult[1].attriInx = COL_COLL_NAME; result->sqlResult[2].attriInx = COL_DATA_NAME; result->sqlResult[3].attriInx = COL_DATA_REPL_NUM; result->sqlResult[4].attriInx = COL_D_RESC_NAME; result->sqlResult[5].attriInx = COL_D_DATA_PATH; result->sqlResult[6].attriInx = COL_D_RESC_HIER; } } return status; }