From 9f76ea0a7096ddd3f27db1b0263e8207473320fe Mon Sep 17 00:00:00 2001 From: Marc Balmer Date: Fri, 13 Feb 2015 10:49:11 +0100 Subject: [PATCH] - Hardcode the few OIDs that are used internally and rearrange some header files, so the server development files are no longer used. - Conditionally compile the setSingleRowMode() function, since it only exists for PostgreSQL 9.2+. --- GNUmakefile | 2 -- Makefile | 2 +- luapgsql.c | 11 ++++++++--- luapgsql.h | 7 ++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 9b81dec..a14d308 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -2,11 +2,9 @@ SRCS= luapgsql.c LIB= pgsql LUAVER= $(shell lua -v 2>&1 | cut -c 5-7) -PGVER= $(shell psql -V | cut -c 19-21) CFLAGS+= -O3 -Wall -fPIC -I/usr/include -I/usr/include/lua${LUAVER} \ -I/usr/include/postgresql \ - -I/usr/include/postgresql/${PGVER}/server \ -D_GNU_SOURCE LDADD+= -L/usr/lib -lpq -lbsd diff --git a/Makefile b/Makefile index 12b23c7..79195a3 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ LOCALBASE= /usr/local .endif NOLINT= 1 -CFLAGS+= -I${LOCALBASE}/include -I${LOCALBASE}/include/postgresql/server +CFLAGS+= -I${LOCALBASE}/include LDADD+= -L${LOCALBASE}/lib -lpq LIBDIR= ${LOCALBASE}/lib/lua/5.2 diff --git a/luapgsql.c b/luapgsql.c index 7e16c47..a42eba6 100644 --- a/luapgsql.c +++ b/luapgsql.c @@ -27,11 +27,12 @@ /* PostgreSQL extension module (using Lua) */ -#include +#include +#include + #include #include #include -#include #include #include @@ -807,6 +808,7 @@ conn_cancel(lua_State *L) return res == 1 ? 1 : 2; } +#if PG_VERSION_NUMBER >= 90200 static int conn_setSingleRowMode(lua_State *L) { @@ -816,6 +818,7 @@ conn_setSingleRowMode(lua_State *L) lua_pushinteger(L, PQsetSingleRowMode(*d)); return 1; } +#endif /* * Asynchronous Notification Functions @@ -1522,7 +1525,7 @@ pgsql_set_info(lua_State *L) lua_pushliteral(L, "PostgreSQL binding for Lua"); lua_settable(L, -3); lua_pushliteral(L, "_VERSION"); - lua_pushliteral(L, "pgsql 1.4.0"); + lua_pushliteral(L, "pgsql 1.4.1"); lua_settable(L, -3); } @@ -1592,8 +1595,10 @@ luaopen_pgsql(lua_State *L) { "getResult", conn_getResult }, { "cancel", conn_cancel }, +#if PG_VERSION_NUMBER >= 90200 /* Retrieving query results row-by-row */ { "setSingleRowMode", conn_setSingleRowMode }, +#endif /* Asynchronous Notifications Functions */ { "notifies", conn_notifies }, diff --git a/luapgsql.h b/luapgsql.h index f50d886..aca1fd5 100644 --- a/luapgsql.h +++ b/luapgsql.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 - 2014, Micro Systems Marc Balmer, CH-5073 Gipf-Oberfrick + * Copyright (c) 2009 - 2015, Micro Systems Marc Balmer, CH-5073 Gipf-Oberfrick * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,6 +35,11 @@ #define NOTIFY_METATABLE "pgsql asychronous notification methods" #define LO_METATABLE "pgsql large object methods" +/* OIDs from server/pg_type.h */ +#define BOOLOID 16 +#define TEXTOID 25 +#define NUMERICOID 1700 + typedef struct largeObject { PGconn *conn; int fd;