FOSSology  4.4.0
Open Source License Compliance by Open Source Software
libfossdb.c File Reference

Common libpq database functions. More...

#include "libfossdb.h"
#include <string.h>
Include dependency graph for libfossdb.c:

Go to the source code of this file.

Macros

#define ERRBUFSIZE   11264
 

Functions

PGconn * fo_dbconnect (char *DBConfFile, char **ErrorBuf)
 Connect to a database. The default is Db.conf. More...
 
int fo_checkPQresult (PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
 Check the result status of a postgres SELECT. More...
 
int fo_checkPQcommand (PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
 Check the result status of a postgres commands (not select) If an error occured, write the error to stdout. More...
 
int fo_tableExists (PGconn *pgConn, const char *tableName)
 Check if table exists. Note, this assumes the database name is 'fossology'. More...
 

Detailed Description

Common libpq database functions.

Definition in file libfossdb.c.

Function Documentation

◆ fo_checkPQcommand()

int fo_checkPQcommand ( PGconn *  pgConn,
PGresult *  result,
char *  sql,
char *  FileID,
int  LineNumb 
)

Check the result status of a postgres commands (not select) If an error occured, write the error to stdout.

Parameters
pgConnDatabase connection object
resultPostgres result object
sqlthe sql query
FileIDis a file identifier string to write into the error message. Typically the caller will use FILE, but any identifier string is ok.
LineNumbthe line number of the caller (LINE)
Returns
0 on OK, -1 on failure. On failure, result will be freed.

Definition at line 204 of file libfossdb.c.

◆ fo_checkPQresult()

int fo_checkPQresult ( PGconn *  pgConn,
PGresult *  result,
char *  sql,
char *  FileID,
int  LineNumb 
)

Check the result status of a postgres SELECT.

If an error occured, write the error to stdout

Parameters
pgConnDatabase connection object
resultPostgres result object
sqlthe sql query
FileIDis a file identifier string to write into the error message. Typically the caller will use FILE, but any identifier string is ok.
LineNumbthe line number of the caller (LINE)
Returns
0 on OK, -1 on failure. On failure, result will be freed.

Definition at line 170 of file libfossdb.c.

◆ fo_dbconnect()

PGconn* fo_dbconnect ( char *  DBConfFile,
char **  ErrorBuf 
)

Connect to a database. The default is Db.conf.

Parameters
DBConfFileFile path of the Db.conf file to use. If NULL, use the default Db.conf
ErrorBufAddress of pointer to error buffer. fo_dbconnect will allocate this if needed. The caller should free it.
Returns
PGconn*, or NULL on failure to process the config file. If NULL, ErrorBuff will contain the error message. If NULL is returned and ErrorBuf is NULL, then there was insufficient memory to allocate ErrorBuf.

Definition at line 29 of file libfossdb.c.

◆ fo_tableExists()

int fo_tableExists ( PGconn *  pgConn,
const char *  tableName 
)

Check if table exists. Note, this assumes the database name is 'fossology'.

Parameters
pgConndatabase connection
tableNameThe table in question
Returns
1 if table exists, 0 on error (which is logged) or if table does not exist.

Definition at line 232 of file libfossdb.c.