FOSSology  4.4.0
Open Source License Compliance by Open Source Software
child.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2010-2011 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
10 #include "buckets.h"
11 
12 extern int debug;
13 
26 FUNCTION int childInBucket(PGconn *pgConn, pbucketdef_t bucketDef, puploadtree_t puploadtree)
27 {
28  char *fcnName = "childInBucket";
29  char sql[1024];
30  int lft, rgt, upload_pk, rv;
31  PGresult *result;
32 
33  lft = puploadtree->lft;
34  rgt = puploadtree->rgt;
35  upload_pk = puploadtree->upload_fk;
36 
37  /* Are any children in this bucket?
38  First check bucket_container.
39  If none found, then look in bucket_file.
40  */
41  snprintf(sql, sizeof(sql),
42  "select uploadtree_pk from %s \
43  inner join bucket_container \
44  on uploadtree_fk=uploadtree_pk and bucket_fk=%d \
45  and agent_fk=%d and nomosagent_fk=%d \
46  where upload_fk=%d and %s.lft BETWEEN %d and %d limit 1",
47  bucketDef->uploadtree_tablename,
48  bucketDef->bucket_pk, bucketDef->bucket_agent_pk,
49  bucketDef->nomos_agent_pk, upload_pk,
50  bucketDef->uploadtree_tablename,
51  lft, rgt);
52 // if (debug) printf("===%s:%d:\n%s\n===\n", __FILE__, __LINE__, sql);
53  result = PQexec(pgConn, sql);
54  if (fo_checkPQresult(pgConn, result, sql, fcnName, __LINE__)) return -1;
55  rv = PQntuples(result);
56  PQclear(result);
57  if (rv) return 1;
58 
59  /* none found so look in bucket_file for any child in this bucket */
60  snprintf(sql, sizeof(sql),
61  "select uploadtree_pk from %s \
62  inner join bucket_file \
63  on %s.pfile_fk=bucket_file.pfile_fk and bucket_fk=%d \
64  and agent_fk=%d and nomosagent_fk=%d \
65  where upload_fk=%d and %s.lft BETWEEN %d and %d limit 1",
66  bucketDef->uploadtree_tablename,
67  bucketDef->uploadtree_tablename,
68  bucketDef->bucket_pk, bucketDef->bucket_agent_pk,
69  bucketDef->nomos_agent_pk, upload_pk,
70  bucketDef->uploadtree_tablename,
71  lft, rgt);
72 // if (debug) printf("===%s:%d:\n%s\n===\n", __FILE__, __LINE__, sql);
73  result = PQexec(pgConn, sql);
74  if (fo_checkPQresult(pgConn, result, sql, fcnName, __LINE__)) return -1;
75  rv = PQntuples(result);
76  PQclear(result);
77  if (rv) return 1;
78 
79  return 0;
80 }
PGconn * pgConn
Database connection.
Definition: adj2nest.c:86
FUNCTION int childInBucket(PGconn *pgConn, pbucketdef_t bucketDef, puploadtree_t puploadtree)
Given a container uploadtree_pk and bucketdef, determine if any child is in this bucket.
Definition: child.c:26
int debug
Definition: buckets.c:57
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
Definition: libfossdb.c:170
const char * upload_pk
Definition: sqlstatements.h:82
int nomos_agent_pk
Definition: buckets.h:70
int bucket_agent_pk
Definition: buckets.h:71