Lookups: fix pgsql multiple-row, single-column return
[users/heiko/exim.git] / test / scripts / 2620-Postgresql / 2620
1 # pgsql lookups
2 #
3 # first, populate a DB to test against
4 sudo rm -fr DIR/pgsql
5 perl
6 system 'initdb -D DIR/pgsql/data';
7 ****
8 background
9 /usr/bin/postgres -D DIR/pgsql/data -p PORT_N -k DIR/pgsql
10 ****
11 perl
12 system 'createdb -h localhost -p PORT_N test';
13 system 'psql -h localhost -p PORT_N -d test \
14  -c "CREATE TABLE them ( name text, id text );" \
15  -c "INSERT INTO them VALUES ( \'Philip Hazel\', \'ph10\' );" \
16  -c "INSERT INTO them VALUES ( \'Aristotle\',    \'aaaa\' );" \
17  -c "INSERT INTO them VALUES ( \'\', \'nothing\' );" \
18  -c "INSERT INTO them VALUES ( \'\"stquot\', \'quote2\' );" \
19  -c "INSERT INTO them VALUES ( \'before\' || CHR(13) || CHR(10) || \'after\', \'newline\' );" \
20  -c "INSERT INTO them VALUES ( \'x\' || CHR(9) || \'x\', \'tab\' );" \
21  -c "INSERT INTO them VALUES ( CHR(39) || \'stquot\', \'quote1\' );" \
22  ';
23 ****
24 #
25 # now, the tests
26 exim -d-all+lookup -be
27 ${lookup pgsql {select name from them where id='ph10';}}
28 ${lookup pgsql {select name from them where id='ph10';}}
29 ${lookup pgsql {select name from them where id='xxxx';}}
30 ${lookup pgsql {select name from them where id='nothing';}}
31 ${lookup pgsql {select id,name from them where id='nothing';}}
32 ${lookup pgsql {delete from them where id='nonexist';}}
33 ${lookup pgsql {select * from them where id='quote2';}}
34 ${lookup pgsql {select * from them where id='newline';}}
35 ${lookup pgsql {select * from them where id='tab';}}
36 ${lookup pgsql {select * from them where name='${quote_pgsql:'stquot}';}}
37 ${lookup pgsql {servers=x:localhost; select name from them where id='ph10';}}
38 ${lookup pgsql {servers=localhost::PORT_N:x; select name from them where id='ph10';}}
39 ${lookup pgsql {servers=localhost::PORT_N/test/CALLER/:x; select name from them where id='ph10';}}
40 ${lookup pgsql {servers=(DIR/pgsql/.s.PGSQL.PORT_N)/test/CALLER/:x; select name from them where id='ph10';}}
41 x
42 ${lookup pgsql {SELECT name FROM them WHERE id IN ('ph10', 'aaaa');}}
43 ${lookup pgsql {SELECT *    FROM them WHERE id IN ('ph10', 'aaaa');}}
44 ****
45 exim -d -bh 10.0.0.0
46 mail from:<a@b>
47 rcpt to:<c@d>
48 rcpt to:<c@d>
49 quit
50 ****
51 exim -odi -d CALLER
52 Test message
53 .
54 ****
55 exim -DSERVERS=\(DIR/pgsql/.s.PGSQL.PORT_N\)/test/CALLER/ -d-all+lookup -be
56 ${lookup pgsql {select name from them where id='ph10';}}
57 ****
58 #
59 perl
60 system 'pg_ctl stop -D DIR/pgsql/data -m immediate';
61 ****
62 killdaemon
63 sudo rm -fr DIR/pgsql