Skip to content

Commit

Permalink
Fix pg driver int64 convertation. Issue #6
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgyKirichenko committed Feb 11, 2016
1 parent c56397e commit 9e3e626
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pg/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,18 @@ lua_pg_pushresult(struct lua_State *L, PGresult *r)
switch (PQftype(r, j)) {
case INT2OID:
case INT4OID:
case INT8OID:
case NUMERICOID: {
lua_pushlstring(L, s, len);
double v = lua_tonumber(L, -1);
lua_pop(L, 1);
lua_pushnumber(L, v);
break;
}
case INT8OID: {
long long v = strtoll(s, NULL, 0);
luaL_pushint64(L, v);
break;
}
case BOOLOID:
if (*s == 't' || *s == 'T')
lua_pushboolean(L, 1);
Expand Down
6 changes: 5 additions & 1 deletion test/pg.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local pg = require('pg')
local json = require('json')

require('tap').test('pg', function(t)
t:plan(16)
t:plan(17)
local host, port, user, pass, db = string.match(os.getenv('PG') or '',
"([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)")

Expand Down Expand Up @@ -59,5 +59,9 @@ require('tap').test('pg', function(t)
t:q('DROP TABLE IF EXISTS unknown_table', {})
local tuples, reason = c:execute('DROP TABLE unknown_table')
t:like(reason, 'unknown_table', 'error')
c:execute('CREATE TABLE int64test (id BIGINT)')
c:execute('INSERT INTO int64test VALUES(1234567890123456789)')
t:q('SELECT id FROM int64test', {{ id = 1234567890123456789LL}})
c:execute('drop table int64test')
t:ok(c:close(), "close")
end)

0 comments on commit 9e3e626

Please sign in to comment.