-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
sql_utils.h
55 lines (47 loc) · 1.02 KB
/
sql_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* sql_utils.h
*
* Created on: 18-Aug-2011
* Author: jkk
*/
#ifndef SQL_UTILS_H_
#define SQL_UTILS_H_
#include <libpq-fe.h>
/**
* @brief
*
*/
typedef struct
{
char *name;
char *user;
char *pass;
char *host;
char *port;
} database_settings;
/**
* @brief Establish a connection to a PostgreSQL database
*
* @param db All parameters needed for connection to the DB
* @return PGconn*
*/
PGconn *make_connection(database_settings *db);
/**
* @brief Run a .sql file containing a SQL query
*
* @param conn The PostgreSQL connection
* @param file_path The path of the file to open
* @return int
*/
int run_sql_file(PGconn *conn, char *file_path);
/**
* @brief Run a SQL query into a PostgreSQL database
*
* @param conn The PostgreSQL connection
* @param sql_text The SQL query as a string
* @param ...
* @return int
*/
int run_sql(PGconn *conn, char *sql_text, ...);
int add_foreign_key(PGconn *conn, char *table, char *column, char *ref_table, char *ref_column);
#endif /* SQL_UTILS_H_ */