PostgreSQL Source Code git master
Loading...
Searching...
No Matches
connect-test6.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Include dependency graph for connect-test6.c:

Go to the source code of this file.

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 

Functions

int main (void)
 

Macro Definition Documentation

◆ ECPGdebug

#define ECPGdebug (   X,
  Y 
)    ECPGdebug((X)+100,(Y))

Definition at line 7 of file connect-test6.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 32 of file connect-test6.c.

33{
34/* exec sql begin declare section */
35
36
37
38
39
40#line 17 "test6.pgc"
41 int val1output = 2 ;
42
43#line 18 "test6.pgc"
44 int val1 = 1 ;
45
46#line 19 "test6.pgc"
47 char val2 [ 6 ] = "data1" ;
48
49#line 20 "test6.pgc"
50 char * stmt1 = "SELECT * from test1 where a = $1 and b = $2" ;
51/* exec sql end declare section */
52#line 21 "test6.pgc"
53
54
55 ECPGdebug(1, stderr);
56
57 /* Connect to the database */
58 { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , "myconn", 0); }
59#line 26 "test6.pgc"
60
61
62 /* Test 1: Try to get descriptor on a disconnected connection */
63 printf("Test 1: Try to get descriptor on a disconnected connection\n");
64 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table test1 ( a int , b text )", ECPGt_EOIT, ECPGt_EORT);}
65#line 30 "test6.pgc"
66
67 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into test1 ( a , b ) values ( 1 , 'data1' )", ECPGt_EOIT, ECPGt_EORT);}
68#line 31 "test6.pgc"
69
70
71 ECPGallocate_desc(__LINE__, "indesc");
72#line 33 "test6.pgc"
73
74 ECPGallocate_desc(__LINE__, "outdesc");
75#line 34 "test6.pgc"
76
77
78 { ECPGprepare(__LINE__, NULL, 0, "foo2", stmt1);}
79#line 36 "test6.pgc"
80
81
82 { ECPGset_desc(__LINE__, "indesc", 1,ECPGd_data,
83 ECPGt_int,&(val1),(long)1,(long)1,sizeof(int), ECPGd_EODT);
84}
85#line 38 "test6.pgc"
86
87 { ECPGset_desc(__LINE__, "indesc", 2,ECPGd_data,
88 ECPGt_char,(val2),(long)6,(long)1,(6)*sizeof(char), ECPGd_EODT);
89}
90#line 39 "test6.pgc"
91
92
93 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_execute, "foo2",
94 ECPGt_descriptor, "indesc", 1L, 1L, 1L,
96 ECPGt_descriptor, "outdesc", 1L, 1L, 1L,
98#line 41 "test6.pgc"
99
100
101 { ECPGtrans(__LINE__, NULL, "rollback");}
102#line 43 "test6.pgc"
103
104 { ECPGdisconnect(__LINE__, "CURRENT");}
105#line 44 "test6.pgc"
106
107 { ECPGget_desc(__LINE__, "outdesc", 1,ECPGd_data,
108 ECPGt_int,&(val1output),(long)1,(long)1,sizeof(int), ECPGd_EODT);
109}
110#line 45 "test6.pgc"
111
112 printf("sqlca.sqlcode = %ld\n", sqlca.sqlcode);
113
114 /* Test 2: Try to deallocate all on a non-existent connection */
115 printf("Test 2: deallocate all with non-existent connection\n");
116 { ECPGdeallocate_all(__LINE__, 0, "nonexistent");}
117#line 50 "test6.pgc"
118
119 printf("sqlca.sqlcode = %ld\n", sqlca.sqlcode);
120
121 /* Test 3: deallocate on disconnected connection */
122 printf("Test 3: deallocate all on disconnected connection\n");
124#line 55 "test6.pgc"
125
126 printf("sqlca.sqlcode = %ld\n", sqlca.sqlcode);
127
128 /* Test 4: Use prepared statement from non-existent connection */
129 printf("Test 4: Use prepared statement from non-existent connection\n");
130 { ECPGprepare(__LINE__, "nonexistent", 0, "stmt1", "SELECT 1");}
131#line 60 "test6.pgc"
132
133 /* declare cur1 cursor for $1 */
134#line 61 "test6.pgc"
135
136 { ECPGdo(__LINE__, 0, 1, "nonexistent", 0, ECPGst_normal, "declare cur1 cursor for $1",
137 ECPGt_char_variable,(ECPGprepared_statement("nonexistent", "stmt1", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
139#line 62 "test6.pgc"
140
141 printf("sqlca.sqlcode = %ld\n", sqlca.sqlcode);
142
143 printf("All tests completed !\n");
144
145 return 0;
146}
#define ECPGdebug(X, Y)
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition connect.c:693
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition connect.c:260
bool ECPGget_desc(int lineno, const char *desc_name, int index,...)
Definition descriptor.c:234
bool ECPGallocate_desc(int line, const char *name)
Definition descriptor.c:808
bool ECPGset_desc(int lineno, const char *desc_name, int index,...)
Definition descriptor.c:621
@ ECPGst_normal
Definition ecpgtype.h:97
@ ECPGst_execute
Definition ecpgtype.h:98
@ ECPGt_EOIT
Definition ecpgtype.h:62
@ ECPGt_char_variable
Definition ecpgtype.h:60
@ ECPGt_int
Definition ecpgtype.h:44
@ ECPGt_NO_INDICATOR
Definition ecpgtype.h:64
@ ECPGt_EORT
Definition ecpgtype.h:63
@ ECPGt_descriptor
Definition ecpgtype.h:59
@ ECPGt_char
Definition ecpgtype.h:43
@ ECPGd_EODT
Definition ecpgtype.h:88
@ ECPGd_data
Definition ecpgtype.h:74
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:2292
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
Definition misc.c:160
bool ECPGdeallocate_all(int lineno, int compat, const char *connection_name)
Definition prepare.c:382
char * ECPGprepared_statement(const char *connection_name, const char *name, int lineno)
Definition prepare.c:403
bool ECPGprepare(int lineno, const char *connection_name, const bool questionmarks, const char *name, const char *variable)
Definition prepare.c:249
#define printf(...)
Definition port.h:266
static int fb(int x)
#define sqlca
Definition sqlca.h:59

References ECPGallocate_desc(), ECPGconnect(), ECPGd_data, ECPGd_EODT, ECPGdeallocate_all(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGget_desc(), ECPGprepare(), ECPGprepared_statement(), ECPGset_desc(), ECPGst_execute, ECPGst_normal, ECPGt_char, ECPGt_char_variable, ECPGt_descriptor, ECPGt_EOIT, ECPGt_EORT, ECPGt_int, ECPGt_NO_INDICATOR, ECPGtrans(), fb(), printf, and sqlca.