PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
connect-test1.c
Go to the documentation of this file.
1 /* Processed by ecpg (regression mode) */
2 /* These include files are added by the preprocessor */
3 #include <ecpglib.h>
4 #include <ecpgerrno.h>
5 #include <sqlca.h>
6 /* End of automatic include section */
7 #define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8 
9 #line 1 "test1.pgc"
10 /*
11  * this file tests all sorts of connecting to one single database.
12  */
13 
14 #include <stdlib.h>
15 #include <string.h>
16 #include <stdlib.h>
17 #include <stdio.h>
18 
19 /* do not include regression.h */
20 
21 int
22 main(void)
23 {
24 /* exec sql begin declare section */
25 
26 
27 
28 #line 16 "test1.pgc"
29  char db [ 200 ] ;
30 
31 #line 17 "test1.pgc"
32  char pw [ 200 ] ;
33 /* exec sql end declare section */
34 #line 18 "test1.pgc"
35 
36 
37  ECPGdebug(1, stderr);
38 
39  { ECPGconnect(__LINE__, 0, "ecpg2_regression" , NULL, NULL , "main", 0); }
40 #line 22 "test1.pgc"
41 
42  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "alter user regress_ecpg_user1 encrypted password 'connectpw'", ECPGt_EOIT, ECPGt_EORT);}
43 #line 23 "test1.pgc"
44 
45  { ECPGdisconnect(__LINE__, "CURRENT");}
46 #line 24 "test1.pgc"
47  /* <-- "main" not specified */
48 
49  { ECPGconnect(__LINE__, 0, "ecpg2_regression@localhost" , NULL, NULL , "main", 0); }
50 #line 26 "test1.pgc"
51 
52  { ECPGdisconnect(__LINE__, "main");}
53 #line 27 "test1.pgc"
54 
55 
56  { ECPGconnect(__LINE__, 0, "@localhost" , "regress_ecpg_user2" , NULL , "main", 0); }
57 #line 29 "test1.pgc"
58 
59  { ECPGdisconnect(__LINE__, "main");}
60 #line 30 "test1.pgc"
61 
62 
63  /* exec sql connect to :@TEMP_PORT@ as main user regress_ecpg_user2;
64  exec sql disconnect main; */
65 
66  { ECPGconnect(__LINE__, 0, "tcp:postgresql://localhost/ecpg2_regression" , "regress_ecpg_user1" , "connectpw" , NULL, 0); }
67 #line 35 "test1.pgc"
68 
69  { ECPGdisconnect(__LINE__, "CURRENT");}
70 #line 36 "test1.pgc"
71 
72 
73  { ECPGconnect(__LINE__, 0, "tcp:postgresql://localhost/" , "regress_ecpg_user2" , NULL , NULL, 0); }
74 #line 38 "test1.pgc"
75 
76  { ECPGdisconnect(__LINE__, "CURRENT");}
77 #line 39 "test1.pgc"
78 
79 
80  strcpy(pw, "connectpw");
81  strcpy(db, "tcp:postgresql://localhost/ecpg2_regression");
82  { ECPGconnect(__LINE__, 0, db , "regress_ecpg_user1" , pw , NULL, 0); }
83 #line 43 "test1.pgc"
84 
85  { ECPGdisconnect(__LINE__, "CURRENT");}
86 #line 44 "test1.pgc"
87 
88 
89  { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/ecpg2_regression" , "regress_ecpg_user1" , "connectpw" , NULL, 0); }
90 #line 46 "test1.pgc"
91 
92  { ECPGdisconnect(__LINE__, "CURRENT");}
93 #line 47 "test1.pgc"
94 
95 
96  { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/ecpg2_regression?connect_timeout=14" , "regress_ecpg_user1" , NULL , NULL, 0); }
97 #line 49 "test1.pgc"
98 
99  { ECPGdisconnect(__LINE__, "CURRENT");}
100 #line 50 "test1.pgc"
101 
102 
103  /* wrong db */
104  { ECPGconnect(__LINE__, 0, "tcp:postgresql://localhost/nonexistant" , "regress_ecpg_user1" , "connectpw" , NULL, 0); }
105 #line 53 "test1.pgc"
106 
107  { ECPGdisconnect(__LINE__, "CURRENT");}
108 #line 54 "test1.pgc"
109 
110 
111  /* wrong port */
112  { ECPGconnect(__LINE__, 0, "tcp:postgresql://localhost:20/ecpg2_regression" , "regress_ecpg_user1" , "connectpw" , NULL, 0); }
113 #line 57 "test1.pgc"
114 
115  /* no disconnect necessary */
116 
117  /* wrong password */
118  { ECPGconnect(__LINE__, 0, "unix:postgresql://localhost/ecpg2_regression" , "regress_ecpg_user1" , "wrongpw" , NULL, 0); }
119 #line 61 "test1.pgc"
120 
121  /* no disconnect necessary */
122 
123  return 0;
124 }
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:669
bool ECPGdo(const int lineno, const int compat, const int force_indicator, const char *connection_name, const bool questionmarks, const int st, const char *query,...)
Definition: execute.c:2030
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:271
int main(void)
Definition: connect-test1.c:22
#define ECPGdebug(X, Y)
Definition: connect-test1.c:7