FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
database.hpp
1 /*
2  * Copyright (C) 2014, Siemens AG
3  * Author: Daniele Fognini
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2
7  * as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * See the GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef DATABASE_HPP
20 #define DATABASE_HPP
21 
22 #include <string>
23 #include <vector>
24 
27 #include "cleanEntries.hpp"
28 
29 #define MAX_TABLE_CREATION_RETRIES 5
30 
36 {
37 public:
38  DatabaseEntry();
39 
40  long agent_fk;
41  long pfile_fk;
42  std::string content;
43  std::string hash;
54  std::string type;
57 };
58 
64 {
65 public:
68  CopyrightDatabaseHandler(CopyrightDatabaseHandler&& other) : fo::AgentDatabaseHandler(std::move(other)) {}; // = default
69  CopyrightDatabaseHandler spawn() const;
70 
71  bool createTables() const;
72  bool insertInDatabase(DatabaseEntry& entry) const;
73  bool insertNoResultInDatabase(long agentId, long pFileId) const;
74  std::vector<unsigned long> queryFileIdsForUpload(int agentId, int uploadId, bool ignoreFilesWithMimeType);
75 
76 private:
82  typedef struct
83  {
84  const char* name;
85  const char* type;
86  const char* creationFlags;
87  } ColumnDef;
88 
89  static const ColumnDef columns[];
90  static const ColumnDef columnsDecision[];
91 
92  bool createTableAgentFindings() const;
93  bool createTableClearing() const;
94  std::string getColumnListString(const ColumnDef in[], size_t size) const;
95  std::string getColumnCreationString(const ColumnDef in[], size_t size) const;
96 };
97 
98 #endif // DATABASE_HPP
DB wrapper for agents.
Holds the column related data for table creation.
Definition: database.hpp:82
DB wrapper for agents.
int copy_endbyte
Definition: database.hpp:56
Manages database related requests for agent.
Definition: database.hpp:63
Database handler for agents.
std::string type
Type of statement found.
Definition: database.hpp:54
DatabaseEntry()
Default constructor for DatabaseEntry.
Definition: database.cc:37
std::string hash
Definition: database.hpp:43
std::string content
Definition: database.hpp:42
int copy_startbyte
Definition: database.hpp:55
PGresult * queryFileIdsForUpload(fo_dbManager *dbManager, int uploadId, bool ignoreFilesWithMimeType)
Get all file IDs (pfile_fk) for a given upload.
Definition: libfossagent.c:73
DB utility functions for agents.
Maps agent data to database schema.
Definition: database.hpp:35