Testsuite: MySQL portability
[exim.git] / test / scripts / 2610-MySQL / 2610
1 # mysql lookups
2 # The mysql-devel (or equivalent) package will be need for Exim to build, and
3 # the mysql-server (or mariadb-server or equivalent) package for this test to run.
4 #
5 # first, populate a DB to test against
6 sudo rm -fr DIR/mysql
7 perl
8 system 'mysql_install_db --no-defaults --datadir=DIR/mysql --user=CALLER';
9 ****
10 sudo rm test-stdout test-stderr
11 #
12 # start a db server
13 background
14 DIR/bin.sys/mysqld --datadir=DIR/mysql --log-error=DIR/mysql/log --bind-address=* --port=PORT_N --socket=DIR/mysql/sock --pid-file=DIR/mysql/pidfile
15 ****
16 #
17 # wait for db startup, insert some data
18 perl
19 system 'mysqladmin --protocol=TCP -P PORT_N --connect_timeout=1 --wait=5 -u root create test';
20 my $fh;
21 open($fh, '-|', 'mysql --protocol=TCP -P PORT_N -u root -D test -e "select 1 from mysql.user where User = \'root\' and Host = \'HOSTIPV4\'"');
22 my $line = <$fh>;
23 if (length($line) == 0) {
24   system 'mysql --protocol=TCP -P PORT_N -u root -D test -e "create user \'root\'@\'HOSTIPV4\'"';
25 }
26 open($fh, '-|', 'mysql --protocol=TCP -P PORT_N -u root -D test -e "select 1 from mysql.user where User = \'CALLER\' and Host = \'HOSTIPV4\'"');
27 $line = <$fh>;
28 if (length($line) == 0) {
29   system 'mysql --protocol=TCP -P PORT_N -u root -D test -e "create user \'CALLER\'@\'HOSTIPV4\'"';
30 }
31 system 'mysql --protocol=TCP -P PORT_N -u root -D test \
32  -e "CREATE TABLE them ( name text, id text ); \
33      INSERT INTO them VALUES ( \'Philip Hazel\', \'ph10\' ); \
34      INSERT INTO them VALUES ( \'Aristotle\',    \'aaaa\' ); \
35      INSERT INTO them VALUES ( \'\', \'nothing\' ); \
36      INSERT INTO them VALUES ( \'\"stquot\', \'quote2\' ); \
37      INSERT INTO them VALUES ( CONCAT(\'before\', CHAR(13), CHAR(10), \'after\'), \'newline\' ); \
38      INSERT INTO them VALUES ( CONCAT(\'x\', CHAR(9), \'x\'), \'tab\' ); \
39      INSERT INTO them VALUES ( CONCAT(CHAR(39), \'stquot\'), \'quote1\' ); \
40      GRANT ALL ON *.* TO \'root\'@\'HOSTIPV4\'; \
41      GRANT ALL ON *.* TO \'CALLER\'@\'HOSTIPV4\'; \
42  "';
43 ****
44 sudo rm test-stderr-server
45 #
46 #
47 exim -d-all+lookup -be
48 ${lookup mysql {select name from them where id='ph10';}}
49 ${lookup mysql {select name from them where id='ph10';}}
50 ${lookup mysql {select name from them where id='xxxx';}}
51 ${lookup mysql {select name from them where id='nothing';}}
52 ${lookup mysql {select id,name from them where id='nothing';}}
53 ${lookup mysql {delete from them where id='nonexist';}}
54 ${lookup mysql {select * from them where id='quote';}}
55 ${lookup mysql {select * from them where id='filter';}}
56 ${lookup mysql {select * from them where id='quote2';}}
57 ${lookup mysql {select * from them where id='nlonly';}}
58 ${lookup mysql {servers=x:127.0.0.1::PORT_N; select name from them where id='ph10';}}
59 ${lookup mysql {servers=127.0.0.1::PORT_N:x; select name from them where id='ph10';}}
60 ${lookup mysql {servers=127.0.0.1::PORT_N/test/root/:x; select name from them where id='ph10';}}
61 ${lookup mysql {servers=HOSTIPV4::PORT_N/test/root/:127.0.0.1::PORT_N; select name from them where id='ph10';}}
62 ${lookup mysql {servers=localhost(DIR/mysql/sock)/test/root/; select name from them where id='ph10';}}
63 x
64 ${lookup mysql {SELECT name FROM them WHERE id IN ('ph10', 'aaaa');}}
65 ${lookup mysql {SELECT *    FROM them WHERE id IN ('ph10', 'aaaa');}}
66 ${lookup mysql {delete from them where id='aaaa'}}
67 ****
68 exim -d -bh 10.0.0.0
69 mail from:<a@b>
70 rcpt to:<c@d>
71 quit
72 ****
73 exim -odi -d ph10
74 Test message
75 .
76 ****
77 #
78 perl
79 system 'mysqladmin --protocol=TCP -P PORT_N -u root shutdown';
80 ****
81 killdaemon
82 #sudo rm -fr DIR/mysql