diff --git a/configure.ac b/configure.ac index 931543fdb..c1cb7d280 100644 --- a/configure.ac +++ b/configure.ac @@ -106,7 +106,13 @@ AC_ARG_WITH(postgresql, yes) DO_POSTGRESQL=yes ;; no) DO_POSTGRESQL=no ;; maybe) DO_POSTGRESQL=maybe ;; - *) AC_MSG_ERROR(Bad value ${withval} for --with-postgresql) ;; + *) + if test ! -x "${withval}" ; then + AC_MSG_ERROR([${withval} is not a executable file]) + fi + POSTGRE_CONFIG_HOME="${withval}" + DO_POSTGRESQL=yes + ;; esac], [DO_POSTGRESQL=no]) @@ -121,14 +127,64 @@ AC_ARG_WITH(mysql, [DO_MYSQL=yes]) # here Postgre -AC_MSG_CHECKING(whether to build/link POSTGRESQL) -if test "x$DO_POSTGRESQL" = "xyes"; then -DO_MYSQL=no -POSTGRE_INCLUDES="-I/usr/include/postgresql $POSTGRE_INCLUDES" -POSTGRE_LIBS="-L/usr/lib/postresql -lpq -lz -lpthread -lcrypt -lnsl -lm -lpthread -L/usr/lib $OPENSSL_LIBS $POSTGRE_LIBS " -CXXFLAGS="-DDO_POSTGRESQL $CXXFLAGS" -fi -AC_MSG_RESULT($DO_POSTGRESQL) +case "$DO_POSTGRESQL" in + yes|maybe) + + if test -z "$POSTGRE_CONFIG_HOME"; then + AC_PATH_PROG([POSTGRE_CONFIG_HOME], [pg_config], [no]) + fi + + if test "$POSTGRE_CONFIG_HOME" != "no" ; then + POSTGRE_VERSION="`$POSTGRE_CONFIG_HOME --version`" + POSTGRE_LIBS="-L`$POSTGRE_CONFIG_HOME --libdir` `$POSTGRE_CONFIG_HOME --libs` -lpq $OPENSSL_LIBS $POSTGRE_LIBS" + POSTGRE_INCLUDES="-I`$POSTGRE_CONFIG_HOME --includedir` $POSTGRE_INCLUDES" + else + POSTGRE_VERSION="unknown" + POSTGRE_LIBS="-L/usr/lib/postgresql/lib -lpq -lz -lpthread -lcrypt -lnsl -lm $OPENSSL_LIBS $POSTGRE_LIBS" + POSTGRE_INCLUDES="-I/usr/include/postgresql $POSTGRE_INCLUDES" + fi + + POSTGRESQL_OLD_LIBS="$LIBS" ; LIBS="$LIBS ${POSTGRE_LIBS}" + POSTGRESQL_OLD_CPPFLAGS="$CPPFLAGS" ; CPPFLAGS="$CPPFLAGS ${POSTGRE_INCLUDES}" + AC_CHECK_LIB([pq], [PQsetdbLogin], [HAVE_POSTGRESQL="yes"], []) + AC_CHECK_HEADER([libpq-fe.h], [], [HAVE_POSTGRESQL="yes"], []) + + AC_MSG_CHECKING(whether to build/link POSTGRESQL) + if test "${HAVE_POSTGRESQL}" != "yes" ; then + AC_MSG_RESULT([no]) + if test "${DO_POSTGRESQL}" = "yes" ; then + AC_MSG_ERROR([PostgreSQL not found or incompatible (requested)]) + else + AC_MSG_NOTICE([disabling PostgreSQL (optional)]) + POSTGRE_VERSION="" + POSTGRE_INCLUDES="" + POSTGRE_LIBS="" + fi + else + AC_MSG_RESULT([yes ($POSTGRE_VERSION)]) + fi + AC_MSG_CHECKING([PostgreSQL libs is a thread-safe]) + AC_RUN_IFELSE([ + AC_LANG_SOURCE( + [[ + #include + int main() { + return !PQisthreadsafe(); + } + ]]) + ], + [ + AC_MSG_RESULT([yes]) + ], + [ + AC_MSG_RESULT([no]) + AC_MSG_ERROR([postgre libs is not thread-safe, check your postgresql installation and /etc/ld.config*]) + ]) + CPPFLAGS="${POSTGRESQL_OLD_CPPFLAGS}" + LIBS="${POSTGRESQL_OLD_LIBS}" + CXXFLAGS="-DDO_POSTGRESQL $CXXFLAGS" + ;; +esac # here mysql AC_MSG_CHECKING(whether to build/link MYSQL) @@ -201,7 +257,6 @@ AC_CHECK_HEADERS([ arpa/inet.h fcntl.h limits.h locale.h malloc.h netdb.h netine AC_CHECK_HEADERS([pthread.h]) AC_CHECK_HEADERS([mysql.h mysql/mysql.h]) -AC_CHECK_HEADERS([libpq-fe.h]) AC_CHECK_HEADERS([zlib.h]) ## Check for typedefs, structures, and compiler characteristics. diff --git a/src/shared/Database/DatabasePostgre.cpp b/src/shared/Database/DatabasePostgre.cpp index 7eb258410..5f2b4d274 100644 --- a/src/shared/Database/DatabasePostgre.cpp +++ b/src/shared/Database/DatabasePostgre.cpp @@ -95,6 +95,7 @@ bool DatabasePostgre::Initialize(const char *infoString) sLog.outError( "Could not connect to Postgre database at %s: %s", host.c_str(), PQerrorMessage(mPGconn)); PQfinish(mPGconn); + mPGconn = NULL; return false; } else diff --git a/src/shared/Database/QueryResultPostgre.h b/src/shared/Database/QueryResultPostgre.h index 420b6858f..cfdd5117e 100644 --- a/src/shared/Database/QueryResultPostgre.h +++ b/src/shared/Database/QueryResultPostgre.h @@ -25,8 +25,50 @@ #include #include #else +// Define OID's from pg_type.h in postgresql server includes. +#define BOOLOID 16 +#define BYTEAOID 17 +#define CHAROID 18 +#define NAMEOID 19 +#define INT8OID 20 +#define INT2OID 21 +#define INT2VECTOROID 22 +#define INT4OID 23 +#define REGPROCOID 24 +#define TEXTOID 25 +#define OIDOID 26 +#define TIDOID 27 +#define XIDOID 28 +#define CIDOID 29 +#define OIDVECTOROID 30 +#define POINTOID 600 +#define LSEGOID 601 +#define PATHOID 602 +#define BOXOID 603 +#define POLYGONOID 604 +#define LINEOID 628 +#define FLOAT4OID 700 +#define FLOAT8OID 701 +#define ABSTIMEOID 702 +#define RELTIMEOID 703 +#define TINTERVALOID 704 +#define UNKNOWNOID 705 +#define CIRCLEOID 718 +#define CASHOID 790 +#define INETOID 869 +#define CIDROID 650 +#define BPCHAROID 1042 +#define VARCHAROID 1043 +#define DATEOID 1082 +#define TIMEOID 1083 +#define TIMESTAMPOID 1114 +#define TIMESTAMPTZOID 1184 +#define INTERVALOID 1186 +#define TIMETZOID 1266 +#define BITOID 1560 +#define VARBITOID 1562 +#define NUMERICOID 1700 #include -//#include #endif class QueryResultPostgre : public QueryResult diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index cfedee9d5..d50730999 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10771" + #define REVISION_NR "10772" #endif // __REVISION_NR_H__