FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
child.c
Go to the documentation of this file.
1 /***************************************************************
2  Copyright (C) 2010-2011 Hewlett-Packard Development Company, L.P.
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 
17  ***************************************************************/
21 #include "buckets.h"
22 
23 extern int debug;
24 
37 FUNCTION int childInBucket(PGconn *pgConn, pbucketdef_t bucketDef, puploadtree_t puploadtree)
38 {
39  char *fcnName = "childInBucket";
40  char sql[1024];
41  int lft, rgt, upload_pk, rv;
42  PGresult *result;
43 
44  lft = puploadtree->lft;
45  rgt = puploadtree->rgt;
46  upload_pk = puploadtree->upload_fk;
47 
48  /* Are any children in this bucket?
49  First check bucket_container.
50  If none found, then look in bucket_file.
51  */
52  snprintf(sql, sizeof(sql),
53  "select uploadtree_pk from %s \
54  inner join bucket_container \
55  on uploadtree_fk=uploadtree_pk and bucket_fk=%d \
56  and agent_fk=%d and nomosagent_fk=%d \
57  where upload_fk=%d and %s.lft BETWEEN %d and %d limit 1",
58  bucketDef->uploadtree_tablename,
59  bucketDef->bucket_pk, bucketDef->bucket_agent_pk,
60  bucketDef->nomos_agent_pk, upload_pk,
61  bucketDef->uploadtree_tablename,
62  lft, rgt);
63 // if (debug) printf("===%s:%d:\n%s\n===\n", __FILE__, __LINE__, sql);
64  result = PQexec(pgConn, sql);
65  if (fo_checkPQresult(pgConn, result, sql, fcnName, __LINE__)) return -1;
66  rv = PQntuples(result);
67  PQclear(result);
68  if (rv) return 1;
69 
70  /* none found so look in bucket_file for any child in this bucket */
71  snprintf(sql, sizeof(sql),
72  "select uploadtree_pk from %s \
73  inner join bucket_file \
74  on %s.pfile_fk=bucket_file.pfile_fk and bucket_fk=%d \
75  and agent_fk=%d and nomosagent_fk=%d \
76  where upload_fk=%d and %s.lft BETWEEN %d and %d limit 1",
77  bucketDef->uploadtree_tablename,
78  bucketDef->uploadtree_tablename,
79  bucketDef->bucket_pk, bucketDef->bucket_agent_pk,
80  bucketDef->nomos_agent_pk, upload_pk,
81  bucketDef->uploadtree_tablename,
82  lft, rgt);
83 // if (debug) printf("===%s:%d:\n%s\n===\n", __FILE__, __LINE__, sql);
84  result = PQexec(pgConn, sql);
85  if (fo_checkPQresult(pgConn, result, sql, fcnName, __LINE__)) return -1;
86  rv = PQntuples(result);
87  PQclear(result);
88  if (rv) return 1;
89 
90  return 0;
91 }
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
Definition: libfossdb.c:181
int bucket_agent_pk
Definition: buckets.h:82
PGconn * pgConn
Database connection.
Definition: adj2nest.c:98
int debug
Definition: buckets.c:68
int nomos_agent_pk
Definition: buckets.h:81
const char * upload_pk
Definition: sqlstatements.h:93
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:37