PostgreSQL Source Code  git master
sql-copystdout.c File Reference
#include <ecpglib.h>
#include <ecpgerrno.h>
#include <sqlca.h>
#include <stdio.h>
Include dependency graph for sql-copystdout.c:

Go to the source code of this file.

Data Structures

struct  sqlca_t
 

Macros

#define ECPGdebug(X, Y)   ECPGdebug((X)+100,(Y))
 
#define POSTGRES_SQLCA_H
 
#define PGDLLIMPORT
 
#define SQLERRMC_LEN   150
 
#define sqlca   (*ECPGget_sqlca())
 

Functions

struct sqlca_tECPGget_sqlca (void)
 
int main ()
 

Macro Definition Documentation

◆ ECPGdebug

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

Definition at line 7 of file sql-copystdout.c.

Referenced by main().

◆ PGDLLIMPORT

#define PGDLLIMPORT

Definition at line 21 of file sql-copystdout.c.

◆ POSTGRES_SQLCA_H

#define POSTGRES_SQLCA_H

Definition at line 15 of file sql-copystdout.c.

◆ sqlca

#define sqlca   (*ECPGget_sqlca())

Definition at line 72 of file sql-copystdout.c.

Referenced by main().

◆ SQLERRMC_LEN

#define SQLERRMC_LEN   150

Definition at line 25 of file sql-copystdout.c.

Function Documentation

◆ ECPGget_sqlca()

struct sqlca_t* ECPGget_sqlca ( void  )

Definition at line 141 of file misc.c.

142 {
143 #ifdef ENABLE_THREAD_SAFETY
144  struct sqlca_t *sqlca;
145 
146  pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
147 
148  sqlca = pthread_getspecific(sqlca_key);
149  if (sqlca == NULL)
150  {
151  sqlca = malloc(sizeof(struct sqlca_t));
152  if (sqlca == NULL)
153  return NULL;
154  ecpg_init_sqlca(sqlca);
155  pthread_setspecific(sqlca_key, sqlca);
156  }
157  return sqlca;
158 #else
159  return &sqlca;
160 #endif
161 }
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:98
#define malloc(a)
Definition: header.h:50
Definition: sqlca.h:19
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29
static struct sqlca_t sqlca
Definition: misc.c:62
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24

◆ main()

int main ( void  )

Definition at line 99 of file sql-copystdout.c.

References ECPGconnect(), ECPGdebug, ECPGdisconnect(), ECPGdo(), ECPGst_normal, ECPGt_EOIT, ECPGt_EORT, printf, sqlca, and sqlprint().

100 {
101  ECPGdebug (1, stderr);
102 
103  { ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
104 #line 13 "copystdout.pgc"
105 
106 if (sqlca.sqlcode < 0) sqlprint();}
107 #line 13 "copystdout.pgc"
108 
109  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table foo ( a int , b varchar )", ECPGt_EOIT, ECPGt_EORT);
110 #line 14 "copystdout.pgc"
111 
112 if (sqlca.sqlcode < 0) sqlprint();}
113 #line 14 "copystdout.pgc"
114 
115  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into foo values ( 5 , 'abc' )", ECPGt_EOIT, ECPGt_EORT);
116 #line 15 "copystdout.pgc"
117 
118 if (sqlca.sqlcode < 0) sqlprint();}
119 #line 15 "copystdout.pgc"
120 
121  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into foo values ( 6 , 'def' )", ECPGt_EOIT, ECPGt_EORT);
122 #line 16 "copystdout.pgc"
123 
124 if (sqlca.sqlcode < 0) sqlprint();}
125 #line 16 "copystdout.pgc"
126 
127  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into foo values ( 7 , 'ghi' )", ECPGt_EOIT, ECPGt_EORT);
128 #line 17 "copystdout.pgc"
129 
130 if (sqlca.sqlcode < 0) sqlprint();}
131 #line 17 "copystdout.pgc"
132 
133 
134  { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "copy foo to stdout with delimiter ','", ECPGt_EOIT, ECPGt_EORT);
135 #line 19 "copystdout.pgc"
136 
137 if (sqlca.sqlcode < 0) sqlprint();}
138 #line 19 "copystdout.pgc"
139 
140  printf ("copy to STDOUT : sqlca.sqlcode = %ld\n", sqlca.sqlcode);
141 
142  { ECPGdisconnect(__LINE__, "CURRENT");
143 #line 22 "copystdout.pgc"
144 
145 if (sqlca.sqlcode < 0) sqlprint();}
146 #line 22 "copystdout.pgc"
147 
148 
149  return 0;
150 }
bool ECPGdisconnect(int lineno, const char *connection_name)
Definition: connect.c:684
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:2287
#define printf(...)
Definition: port.h:198
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
#define sqlca
void sqlprint(void)
Definition: error.c:336
#define ECPGdebug(X, Y)
Definition: sql-copystdout.c:7