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.

◆ 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.

◆ 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 108 of file misc.c.

109 {
110  struct sqlca_t *sqlca;
111 
112  pthread_once(&sqlca_key_once, ecpg_sqlca_key_init);
113 
115  if (sqlca == NULL)
116  {
117  sqlca = malloc(sizeof(struct sqlca_t));
118  if (sqlca == NULL)
119  return NULL;
122  }
123  return sqlca;
124 }
#define malloc(a)
Definition: header.h:50
static pthread_key_t sqlca_key
Definition: misc.c:58
void ecpg_init_sqlca(struct sqlca_t *sqlca)
Definition: misc.c:67
static void ecpg_sqlca_key_init(void)
Definition: misc.c:102
static pthread_once_t sqlca_key_once
Definition: misc.c:59
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24
#define sqlca
Definition: sqlca.h:59
Definition: sqlca.h:20

◆ main()

int main ( void  )

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

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:673
bool ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
Definition: connect.c:255
@ ECPGst_normal
Definition: ecpgtype.h:97
@ ECPGt_EOIT
Definition: ecpgtype.h:62
@ ECPGt_EORT
Definition: ecpgtype.h:63
void sqlprint(void)
Definition: error.c:334
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:2277
#define printf(...)
Definition: port.h:244
#define sqlca
#define ECPGdebug(X, Y)
Definition: sql-copystdout.c:7

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