aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test/connect/test1.pgc
blob: 3b478ba647202abf3197b3e9b4af831e869ea208 (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 connectdb as main;
	exec sql alter user connectuser ENCRYPTED PASSWORD 'connectpw';
	exec sql disconnect;  /* <-- "main" not specified */

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

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

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

	exec sql connect to tcp:postgresql://localhost/connectdb user connectuser identified by connectpw;
	exec sql disconnect;

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

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

	exec sql connect to unix:postgresql://localhost/connectdb user connectuser using "connectpw";
	exec sql disconnect;

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

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

	/* wrong port */
	exec sql connect to tcp:postgresql://localhost:20/connectdb user connectuser identified by connectpw;
	/* no disconnect necessary */

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

	return (0);
}