Navigation Menu

Skip to content

Commit

Permalink
- Hardcode the few OIDs that are used internally and rearrange some h…
Browse files Browse the repository at this point in the history
…eader

files, so the server development files are no longer used.
- Conditionally compile the setSingleRowMode() function, since it only
exists for PostgreSQL 9.2+.
  • Loading branch information
mbalmer committed Feb 13, 2015
1 parent c44e65d commit 9f76ea0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 0 additions & 2 deletions GNUmakefile
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions luapgsql.c
Expand Up @@ -27,11 +27,12 @@

/* PostgreSQL extension module (using Lua) */

#include <postgres_fe.h>
#include <string.h>
#include <stdlib.h>

#include <libpq-fe.h>
#include <libpq/libpq-fs.h>
#include <pg_config.h>
#include <catalog/pg_type.h>

#include <lua.h>
#include <lauxlib.h>
Expand Down Expand Up @@ -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)
{
Expand All @@ -816,6 +818,7 @@ conn_setSingleRowMode(lua_State *L)
lua_pushinteger(L, PQsetSingleRowMode(*d));
return 1;
}
#endif

/*
* Asynchronous Notification Functions
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 },
Expand Down
7 changes: 6 additions & 1 deletion 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
Expand Down Expand Up @@ -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

This comment has been minimized.

Copy link
@daurnimator

daurnimator Feb 13, 2015

Contributor

alignment seems off?

This comment has been minimized.

Copy link
@mbalmer

mbalmer via email Feb 13, 2015

Author Collaborator

This comment has been minimized.

Copy link
@daurnimator

daurnimator Feb 13, 2015

Contributor

the 1700 isn't horizontally aligned with the 25 above it.

This comment has been minimized.

Copy link
@mbalmer

mbalmer via email Feb 13, 2015

Author Collaborator

This comment has been minimized.

Copy link
@daurnimator

daurnimator Feb 13, 2015

Contributor

ah; I'm just reviewing in the github online viewer.
I try not to use tabs except at the start of lines.

This comment has been minimized.

Copy link
@mbalmer

mbalmer via email Feb 13, 2015

Author Collaborator

typedef struct largeObject {
PGconn *conn;
int fd;
Expand Down

0 comments on commit 9f76ea0

Please sign in to comment.