1
0
mirror of https://github.com/haiwen/ccnet-server.git synced 2025-09-06 07:10:24 +00:00

Conditional compile MySQL and PostgreSQL support.

This commit is contained in:
Jiaqiang Xu
2016-08-20 17:50:06 +08:00
parent 48c3f5edef
commit 51bde41209
5 changed files with 59 additions and 6 deletions

View File

@@ -253,17 +253,19 @@ if test "xyes" = "x$mysql"; then
tmp_LDFLAGS=$LDFLAGS
CPPFLAGS="`$MYSQLCONFIG --include` $CPPFLAGS"
LDFLAGS="`$MYSQLCONFIG --libs` $LDFLAGS"
AC_CHECK_HEADERS([mysql.h])
AC_CHECK_HEADERS([mysql.h], [], [mysql="no"])
if test "xyes" = "x$mysql"; then
echo "found mysql client library"
MYSQL_CFLAGS=`$MYSQLCONFIG --include`
MYSQL_LIBS=`$MYSQLCONFIG --libs`
AC_SUBST(MYSQL_CFLAGS)
AC_SUBST(MYSQL_LIBS)
AC_DEFINE([HAVE_MYSQL], 1, [Define to 1 to enable mysql])
fi
CPPFLAGS=$tmp_CPPFLAGS
LDFLAGS=$tmp_LDFLAGS
fi
AM_CONDITIONAL([WITH_MYSQL], test "xyes" = "x$mysql")
postgresql="yes"
check_postgres_config()
@@ -305,10 +307,12 @@ if test "xyes" = "x$postgresql"; then
PGSQL_LIBS="-L`$PGCONFIG --libdir` -lpq"
AC_SUBST(PGSQL_CFLAGS)
AC_SUBST(PGSQL_LIBS)
AC_DEFINE([HAVE_POSTGRESQL], 1, [Define to 1 to enable postgresql])
fi
CPPFLAGS=$tmp_CPPFLAGS
LDFLAGS=$tmp_LDFLAGS
fi
AM_CONDITIONAL([WITH_POSTGRESQL], test "xyes" = "x$postgresql")
if test "${compile_ldap}" = "yes"; then
if test "$bwin32" != true; then

View File

@@ -21,6 +21,8 @@ struct CcnetDBTrans {
DBConnection *conn;
};
#ifdef HAVE_MYSQL
CcnetDB *
ccnet_db_new_mysql (const char *host,
int port,
@@ -48,6 +50,10 @@ ccnet_db_new_mysql (const char *host,
return db;
}
#endif
#ifdef HAVE_POSTGRESQL
CcnetDB *
ccnet_db_new_pgsql (const char *host,
const char *user,
@@ -72,6 +78,8 @@ ccnet_db_new_pgsql (const char *host,
return db;
}
#endif
CcnetDB *
ccnet_db_new_sqlite (const char *db_path)
{

View File

@@ -6,7 +6,19 @@ noinst_LTLIBRARIES = libdbwrapper.la
noinst_HEADERS = db-wrapper.h mysql-db-ops.h sqlite-db-ops.h pgsql-db-ops.h
libdbwrapper_la_SOURCES = db-wrapper.c mysql-db-ops.c sqlite-db-ops.c pgsql-db-ops.c
if WITH_MYSQL
MYSQL_DB_SRC = mysql-db-ops.c
else
MYSQL_DB_SRC =
endif
if WITH_POSTGRESQL
PGSQL_DB_SRC = pgsql-db-ops.c
else
PGSQL_DB_SRC =
endif
libdbwrapper_la_SOURCES = db-wrapper.c sqlite-db-ops.c $(MYSQL_DB_SRC) $(PGSQL_DB_SRC)
libdbwrapper_la_LDFLAGS = -Wl,-z -Wl,defs
libdbwrapper_la_LIBADD = @SSL_LIBS@ @GLIB2_LIBS@ @MYSQL_LIBS@ -lsqlite3 @PGSQL_LIBS@

View File

@@ -1,9 +1,15 @@
#include "common.h"
#include "db-wrapper.h"
#include "mysql-db-ops.h"
#include "sqlite-db-ops.h"
#ifdef HAVE_MYSQL
#include "mysql-db-ops.h"
#endif
#ifdef HAVE_POSTGRESQL
#include "pgsql-db-ops.h"
#endif
typedef struct DBOperations {
void (*db_conn_pool_free) (DBConnPool *);
@@ -40,6 +46,8 @@ init_conn_pool_common (DBConnPool *pool, int max_connections)
pool->max_connections = max_connections;
}
#ifdef HAVE_MYSQL
DBConnPool *
db_conn_pool_new_mysql (const char *host,
const char *user,
@@ -81,6 +89,10 @@ db_conn_pool_new_mysql (const char *host,
return pool;
}
#endif
#ifdef HAVE_POSTGRESQL
DBConnPool *
db_conn_pool_new_pgsql (const char *host,
const char *user,
@@ -118,6 +130,8 @@ db_conn_pool_new_pgsql (const char *host,
return pool;
}
#endif
DBConnPool *
db_conn_pool_new_sqlite (const char *db_path, int max_connections)
{

View File

@@ -122,6 +122,8 @@ static int init_sqlite_database (CcnetSession *session)
return 0;
}
#ifdef HAVE_MYSQL
#define MYSQL_DEFAULT_PORT 3306
static int init_mysql_database (CcnetSession *session)
@@ -188,6 +190,10 @@ static int init_mysql_database (CcnetSession *session)
return 0;
}
#endif
#ifdef HAVE_POSTGRESQL
static int init_pgsql_database (CcnetSession *session)
{
char *host, *user, *passwd, *db, *unix_socket;
@@ -226,6 +232,8 @@ static int init_pgsql_database (CcnetSession *session)
return 0;
}
#endif
static int
load_database_config (CcnetSession *session)
{
@@ -236,13 +244,20 @@ load_database_config (CcnetSession *session)
if (!engine || strncasecmp (engine, DB_SQLITE, sizeof(DB_SQLITE)) == 0) {
ccnet_debug ("Use database sqlite\n");
ret = init_sqlite_database (session);
} else if (strncasecmp (engine, DB_MYSQL, sizeof(DB_MYSQL)) == 0) {
}
#ifdef HAVE_MYSQL
else if (strncasecmp (engine, DB_MYSQL, sizeof(DB_MYSQL)) == 0) {
ccnet_debug ("Use database Mysql\n");
ret = init_mysql_database (session);
} else if (strncasecmp (engine, DB_PGSQL, sizeof(DB_PGSQL)) == 0) {
}
#endif
#ifdef HAVE_POSTGRESQL
else if (strncasecmp (engine, DB_PGSQL, sizeof(DB_PGSQL)) == 0) {
ccnet_debug ("Use database PostgreSQL\n");
ret = init_pgsql_database (session);
} else {
}
#endif
else {
ccnet_warning ("Unknown database type: %s.\n", engine);
ret = -1;
}