51 char *fcnName =
"getContainerBuckets";
53 int *bucket_pk_list = 0;
54 int numBucketDefs = 0;
61 if (
debug) printf(
"%s: for uploadtree_pk %d\n",fcnName,uploadtree_pk);
67 for (pbucketDefArray = bucketDefArray; pbucketDefArray->
bucket_pk; pbucketDefArray++)
71 bucket_pk_list = calloc(numBucketDefs+1,
sizeof(
int));
72 if (bucket_pk_list == 0)
74 printf(
"FATAL: %s(%d) out of memory allocating int array of %d ints\n",
75 fcnName, __LINE__, numBucketDefs+1);
81 snprintf(sql,
sizeof(sql),
82 "SELECT lft,rgt,upload_fk FROM uploadtree WHERE uploadtree_pk ='%d'",
84 result = PQexec(pgConn, sql);
90 numLics = PQntuples(result);
93 if (
debug) printf(
"%s(%d): uploadtree_pk %d %s returned no recs.\n",__FILE__, __LINE__,uploadtree_pk, sql);
95 return bucket_pk_list;
97 lft = atoi(PQgetvalue(result, 0, 0));
98 rgt = atoi(PQgetvalue(result, 0, 1));
99 upload_pk = atoi(PQgetvalue(result, 0, 2));
105 snprintf(sql,
sizeof(sql),
106 "SELECT distinct(bucket_fk) as bucket_pk\ 107 from bucket_file, bucket_def,\ 108 (SELECT distinct(pfile_fk) as PF from uploadtree \ 110 and ((ufile_mode & (1<<28))=0)\ 111 and uploadtree.lft BETWEEN %d and %d) as SS\ 112 where PF=pfile_fk and agent_fk=%d\ 113 and bucket_file.nomosagent_fk=%d\ 114 and bucket_pk=bucket_fk\ 115 and bucketpool_fk=%d",
118 if (
debug) printf(
"%s(%d): Find buckets in container for uploadtree_pk %d\n%s\n",__FILE__, __LINE__,uploadtree_pk, sql);
119 result = PQexec(pgConn, sql);
122 free(bucket_pk_list);
125 numLics = PQntuples(result);
129 return bucket_pk_list;
134 for (bucketNumb=0; bucketNumb < numLics; bucketNumb++)
136 bucket_pk_list[bucketNumb] = atoi(PQgetvalue(result, bucketNumb, 0));
142 printf(
"getContainerBuckets returning: ");
143 for (bucketNumb=0; bucketNumb < numLics; bucketNumb++)
145 printf(
"%d " ,bucket_pk_list[bucketNumb]);
150 return bucket_pk_list;
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
PGconn * pgConn
Database connection.
FUNCTION int * getContainerBuckets(PGconn *pgConn, pbucketdef_t bucketDefArray, int uploadtree_pk)
Given a container uploadtree_pk and bucketdef, determine what buckets the container is in...