FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
libfossdbmanager.h
1 /*
2 Author: Daniele Fognini
3 Copyright (C) 2014-2015, Siemens AG
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 version 2 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. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 #ifndef LIBFOSSDBMANAGER_H
20 #define LIBFOSSDBMANAGER_H
21 
22 #include <libpq-fe.h>
23 #include <stdarg.h>
24 #include <glib.h>
25 
27 typedef struct fo_dbmanager fo_dbManager;
28 
30 fo_dbManager* fo_dbManager_new_withConf(PGconn* dbConnection, const char* dbConf);
31 PGconn* fo_dbManager_getWrappedConnection(fo_dbManager* dbManager);
32 fo_dbManager* fo_dbManager_fork(fo_dbManager* dbManager);
34 void fo_dbManager_finish(fo_dbManager* dbManager);
35 int fo_dbManager_setLogFile(fo_dbManager* dbManager, const char* logFileName);
36 void fo_dbManager_ignoreWarnings(fo_dbManager* dbManager, int ignoreWarns);
37 char* fo_dbManager_StringEscape(fo_dbManager* dbManager, const char* string);
38 int fo_dbManager_begin(fo_dbManager* dbManager);
39 int fo_dbManager_commit(fo_dbManager* dbManager);
40 int fo_dbManager_rollback(fo_dbManager* dbManager);
41 PGresult* fo_dbManager_Exec_printf(fo_dbManager* dbManager, const char* sqlQueryStringFormat, ...);
42 
77 #define fo_dbManager_PrepareStamement(dbManager, name, query, ...) \
78 fo_dbManager_PrepareStamement_str(dbManager, \
79  name, \
80  query, \
81  #__VA_ARGS__\
82 )
83 
84 fo_dbManager_PreparedStatement* fo_dbManager_PrepareStamement_str(fo_dbManager* dbManager, const char* name, const char* query, const char* paramtypes);
85 
86 PGresult* fo_dbManager_ExecPrepared(fo_dbManager_PreparedStatement* preparedStatement, ...);
87 PGresult* fo_dbManager_ExecPreparedv(fo_dbManager_PreparedStatement* preparedStatement, va_list args);
88 
89 int fo_dbManager_tableExists(fo_dbManager* dbManager, const char* tableName);
90 int fo_dbManager_exists(fo_dbManager* dbManager, const char* type, const char* name);
91 
92 // visible for testing
93 int fo_dbManager_parseParamStr(const char* paramtypes, GArray** params);
94 char* fo_dbManager_printStatement(fo_dbManager_PreparedStatement* preparedStatement);
95 
96 #endif /* LIBFOSSDBMANAGER_H */
fo_dbManager_PreparedStatement * fo_dbManager_PrepareStamement_str(fo_dbManager *dbManager, const char *name, const char *query, const char *paramtypes)
Create a prepared statement.
Definition: standalone.c:30
PGresult * fo_dbManager_ExecPrepared(fo_dbManager_PreparedStatement *preparedStatement,...)
Execute a prepared statement.
Definition: standalone.c:31
int ignoreWarns
Set to ignore warnings from logging.
char * dbConf
DB conf file location.
fo_dbManager * fo_dbManager_new(PGconn *dbConnection)
Create and initialize new fo_dbManager object.
Definition: standalone.c:28
PGconn * dbConnection
Postgres database connection object.
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28
void fo_dbManager_free(fo_dbManager *dbManager)
Un-allocate the memory from a DB manager.
Definition: standalone.c:29