39 char *fcnName =
"getContainerBuckets";
41 int *bucket_pk_list = 0;
42 int numBucketDefs = 0;
49 if (
debug) printf(
"%s: for uploadtree_pk %d\n",fcnName,uploadtree_pk);
55 for (pbucketDefArray = bucketDefArray; pbucketDefArray->
bucket_pk; pbucketDefArray++)
59 bucket_pk_list = calloc(numBucketDefs+1,
sizeof(
int));
60 if (bucket_pk_list == 0)
62 printf(
"FATAL: %s(%d) out of memory allocating int array of %d ints\n",
63 fcnName, __LINE__, numBucketDefs+1);
69 snprintf(sql,
sizeof(sql),
70 "SELECT lft,rgt,upload_fk FROM uploadtree WHERE uploadtree_pk ='%d'",
72 result = PQexec(
pgConn, sql);
78 numLics = PQntuples(result);
81 if (
debug) printf(
"%s(%d): uploadtree_pk %d %s returned no recs.\n",__FILE__, __LINE__,uploadtree_pk, sql);
83 return bucket_pk_list;
85 lft = atoi(PQgetvalue(result, 0, 0));
86 rgt = atoi(PQgetvalue(result, 0, 1));
87 upload_pk = atoi(PQgetvalue(result, 0, 2));
93 snprintf(sql,
sizeof(sql),
94 "SELECT distinct(bucket_fk) as bucket_pk\
95 from bucket_file, bucket_def,\
96 (SELECT distinct(pfile_fk) as PF from uploadtree \
98 and ((ufile_mode & (1<<28))=0)\
99 and uploadtree.lft BETWEEN %d and %d) as SS\
100 where PF=pfile_fk and agent_fk=%d\
101 and bucket_file.nomosagent_fk=%d\
102 and bucket_pk=bucket_fk\
103 and bucketpool_fk=%d",
106 if (
debug) printf(
"%s(%d): Find buckets in container for uploadtree_pk %d\n%s\n",__FILE__, __LINE__,uploadtree_pk, sql);
107 result = PQexec(
pgConn, sql);
110 free(bucket_pk_list);
113 numLics = PQntuples(result);
117 return bucket_pk_list;
122 for (bucketNumb=0; bucketNumb < numLics; bucketNumb++)
124 bucket_pk_list[bucketNumb] = atoi(PQgetvalue(result, bucketNumb, 0));
130 printf(
"getContainerBuckets returning: ");
131 for (bucketNumb=0; bucketNumb < numLics; bucketNumb++)
133 printf(
"%d " ,bucket_pk_list[bucketNumb]);
138 return bucket_pk_list;
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.
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.