summaryrefslogtreecommitdiff
path: root/src/interfaces/ecpg/test/connect/test1.pgc.in
blob: b2141d1c2344cee37af71c03ccd70abbc4cded50 (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
/*
 * 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 connectdb@localhost:@TEMP_PORT@ as main;
	exec sql disconnect main;

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

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

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

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

	exec sql connect to unix:postgresql://localhost:@TEMP_PORT@/connectdb user connectuser;
	exec sql disconnect;

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

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

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

	return (0);
}