Debian Codegraph @

src/interfaces/ecpg/test/connect/test1.pgc

raw
1 /*
2 * this file tests all sorts of connecting to one single database.
3 */
4
5 #include <stdlib.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9
10 /* do not include regression.h */
11
12 int
13 main(void)
14 {
15 exec sql begin declare section;
16 char db[200];
17 char pw[200];
18 exec sql end declare section;
19
20 ECPGdebug(1, stderr);
21
22 exec sql connect to ecpg2_regression as main;
23 exec sql alter user regress_ecpg_user1 ENCRYPTED PASSWORD 'connectpw';
24 exec sql disconnect; /* <-- "main" not specified */
25
26 exec sql connect to ecpg2_regression@localhost as main;
27 exec sql disconnect main;
28
29 exec sql connect to @localhost as main user regress_ecpg_user2;
30 exec sql disconnect main;
31
32 /* exec sql connect to :@TEMP_PORT@ as main user regress_ecpg_user2;
33 exec sql disconnect main; */
34
35 exec sql connect to tcp:postgresql://localhost/ecpg2_regression user regress_ecpg_user1 identified by connectpw;
36 exec sql disconnect;
37
38 exec sql connect to tcp:postgresql://localhost/ user regress_ecpg_user2;
39 exec sql disconnect;
40
41 strcpy(pw, "connectpw");
42 strcpy(db, "tcp:postgresql://localhost/ecpg2_regression");
43 exec sql connect to :db user regress_ecpg_user1 using :pw;
44 exec sql disconnect;
45
46 exec sql connect to unix:postgresql://localhost/ecpg2_regression user regress_ecpg_user1 using "connectpw";
47 exec sql disconnect;
48
49 exec sql connect to unix:postgresql://localhost/ecpg2_regression?connect_timeout=180 user regress_ecpg_user1;
50 exec sql disconnect;
51
52 /* wrong db */
53 exec sql connect to tcp:postgresql://localhost/nonexistent user regress_ecpg_user1 identified by connectpw;
54 exec sql disconnect;
55
56 /* wrong port */
57 exec sql connect to tcp:postgresql://127.0.0.1:20/ecpg2_regression user regress_ecpg_user1 identified by connectpw;
58 /* no disconnect necessary */
59
60 /* wrong password */
61 exec sql connect to unix:postgresql://localhost/ecpg2_regression user regress_ecpg_user1 identified by "wrongpw";
62 /* no disconnect necessary */
63
64 return 0;
65 }