diff options
author | Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz> | 2013-08-23 09:57:47 +0000 |
---|---|---|
committer | Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz> | 2013-08-23 11:11:00 +0000 |
commit | fc821cda70e3bd2677ad68a62b0b2b0698c189d4 (patch) | |
tree | 8def109b05f843c170a275d2d9fcb7509ccc1507 | |
parent | 99c7f2f78c786cfc71010d3fb60c1b44d5f1371c (diff) | |
download | lem-postgres-fc821cda70e3bd2677ad68a62b0b2b0698c189d4.tar.gz lem-postgres-fc821cda70e3bd2677ad68a62b0b2b0698c189d4.tar.xz lem-postgres-fc821cda70e3bd2677ad68a62b0b2b0698c189d4.zip |
test: add tests of nil/NULL support
Signed-off-by: Asbjørn Sloth Tønnesen <asbjorn@asbjorn.biz>
-rwxr-xr-x | test.lua | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -2,6 +2,7 @@ -- -- This file is part of lem-postgres. -- Copyright 2011 Emil Renner Berthing +-- Copyright 2013 Asbjørn Sloth Tønnesen -- -- lem-postgres is free software: you can redistribute it and/or -- modify it under the terms of the GNU General Public License as @@ -17,6 +18,9 @@ -- along with lem-postgres. If not, see <http://www.gnu.org/licenses/>. -- +package.path = '?.lua;'..package.path +package.cpath = '?.so;'..package.cpath + print("Entering " .. arg[0]) local prettyprint @@ -64,13 +68,14 @@ dbname=mydb ]])) assert(db:exec( -'CREATE TABLE mytable (id integer PRIMARY KEY, name TEXT)')) - -assert(db:exec("COPY mytable FROM STDIN (delimiter ',')")) -assert(db:put('1,alpha\n')) -assert(db:put('2,beta\n')) -assert(db:put('3,gamma\n')) -assert(db:put('4,delta\n')) +'CREATE TABLE mytable (id serial PRIMARY KEY, name TEXT, foo integer)')) + +assert(db:exec("COPY mytable (name, foo) FROM STDIN (delimiter ',')")) +assert(db:put('alpha,1\n')) +assert(db:put('beta,2\n')) +assert(db:put('gamma,4\n')) +assert(db:put('delta,8\n')) +assert(db:put('epsilon,\\N\n')) assert(db:done()) local res = assert(db:exec('SELECT * FROM mytable WHERE id = $1', '1')) @@ -86,7 +91,11 @@ assert(db:prepare('mystmt', 'SELECT * FROM mytable WHERE id = $1')) local res = assert(db:run('mystmt', '3')) prettyprint(res) -assert(db:exec("COPY mytable TO STDIN (format csv)")) +assert(db:prepare('insert', 'INSERT INTO mytable (name, foo) VALUES ($1, $2)')) +assert(db:run('insert', 'zeta', 32)) +assert(db:run('insert', 'eta', nil)) + +assert(db:exec("COPY mytable TO STDIN (format csv, null '\\N')")) print("\nDumping CSV:") while true do |