1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-09-12 21:35:30 +00:00

Conditional compile MySQL and PostgreSQL support.

This commit is contained in:
Jiaqiang Xu
2016-08-20 17:32:22 +08:00
parent f8b9c37a08
commit 5a50db9c48
5 changed files with 59 additions and 6 deletions

View File

@@ -5,7 +5,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

@@ -21,6 +21,8 @@ struct SeafDBTrans {
DBConnection *conn;
};
#ifdef HAVE_MYSQL
SeafDB *
seaf_db_new_mysql (const char *host,
int port,
@@ -48,6 +50,10 @@ seaf_db_new_mysql (const char *host,
return db;
}
#endif
#ifdef HAVE_POSTGRESQL
SeafDB *
seaf_db_new_pgsql (const char *host,
const char *user,
@@ -72,6 +78,8 @@ seaf_db_new_pgsql (const char *host,
return db;
}
#endif
SeafDB *
seaf_db_new_sqlite (const char *db_path, int max_connections)
{

View File

@@ -52,6 +52,8 @@ sqlite_db_start (SeafileSession *session)
return 0;
}
#ifdef HAVE_MYSQL
#define MYSQL_DEFAULT_PORT 3306
static int
@@ -125,6 +127,10 @@ mysql_db_start (SeafileSession *session)
return 0;
}
#endif
#ifdef HAVE_POSTGRESQL
static int
pgsql_db_start (SeafileSession *session)
{
@@ -174,6 +180,8 @@ pgsql_db_start (SeafileSession *session)
return 0;
}
#endif
int
load_database_config (SeafileSession *session)
{
@@ -185,11 +193,18 @@ load_database_config (SeafileSession *session)
/* Default to use sqlite if not set. */
if (!type || strcasecmp (type, "sqlite") == 0) {
ret = sqlite_db_start (session);
} else if (strcasecmp (type, "mysql") == 0) {
}
#ifdef HAVE_MYSQL
else if (strcasecmp (type, "mysql") == 0) {
ret = mysql_db_start (session);
} else if (strcasecmp (type, "pgsql") == 0) {
}
#endif
#ifdef HAVE_POSTGRESQL
else if (strcasecmp (type, "pgsql") == 0) {
ret = pgsql_db_start (session);
} else {
}
#endif
else {
seaf_warning ("Unsupported db type %s.\n", type);
ret = -1;
}

View File

@@ -268,17 +268,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()
@@ -320,10 +322,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_fuse}" = "yes"; then
PKG_CHECK_MODULES(FUSE, [fuse >= $FUSE_REQUIRED])