aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test/connect/test1.pgc
blob: 101b806d5bab8853b8c357cc82d92acb99134fbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
 * this file tests all sorts of connecting to one single database.
 */

#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

/* do not include regression.h */

int
main(void)
{
exec sql begin declare section;
	char db[200];
	char pw[200];
exec sql end declare section;

	ECPGdebug(1, stderr);

	exec sql connect to ecpg2_regression as main;
	exec sql alter user regress_ecpg_user1 ENCRYPTED PASSWORD 'connectpw';
	exec sql disconnect;  /* <-- "main" not specified */

	exec sql connect to ecpg2_regression@localhost as main;
	exec sql disconnect main;

	exec sql connect to @localhost as main user regress_ecpg_user2;
	exec sql disconnect main;

	/* exec sql connect to :@TEMP_PORT@ as main user regress_ecpg_user2;
	exec sql disconnect main; */

	exec sql connect to tcp:postgresql://localhost/ecpg2_regression user regress_ecpg_user1 identified by connectpw;
	exec sql disconnect;

	exec sql connect to tcp:postgresql://localhost/ user regress_ecpg_user2;
	exec sql disconnect;

	strcpy(pw, "connectpw");
	strcpy(db, "tcp:postgresql://localhost/ecpg2_regression");
	exec sql connect to :db user regress_ecpg_user1 using :pw;
	exec sql disconnect;

	exec sql connect to unix:postgresql://localhost/ecpg2_regression user regress_ecpg_user1 using "connectpw";
	exec sql disconnect;

	exec sql connect to unix:postgresql://localhost/ecpg2_regression?connect_timeout=14 user regress_ecpg_user1;
	exec sql disconnect;

	/* wrong db */
	exec sql connect to tcp:postgresql://localhost/nonexistant user regress_ecpg_user1 identified by connectpw;
	exec sql disconnect;

	/* wrong port */
	exec sql connect to tcp:postgresql://127.0.0.1:20/ecpg2_regression user regress_ecpg_user1 identified by connectpw;
	/* no disconnect necessary */

	/* wrong password */
	exec sql connect to unix:postgresql://localhost/ecpg2_regression user regress_ecpg_user1 identified by "wrongpw";
	/* no disconnect necessary */

	return 0;
}