PostgreSQL Source Code: src/interfaces/ecpg/ecpglib/misc.c Source File (original) (raw)
1
2
3#define POSTGRES_ECPG_INTERNAL
5
6#include <limits.h>
8
14#include "pg_config_paths.h"
20
21#ifndef LONG_LONG_MIN
22#ifdef LLONG_MIN
23#define LONG_LONG_MIN LLONG_MIN
24#else
25#define LONG_LONG_MIN LONGLONG_MIN
26#endif
27#endif
28
30
32{
33 {
34 'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '
35 },
37 0,
38 {
39 0,
40 {
41 0
42 }
43 },
44 {
45 'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '
46 },
47 {
48 0, 0, 0, 0, 0, 0
49 },
50 {
51 0, 0, 0, 0, 0, 0, 0, 0
52 },
53 {
54 '0', '0', '0', '0', '0'
55 }
56};
57
60
65
66void
71
72bool
74{
76
78 {
81 return false;
82 }
83
85 if (con == NULL)
86 {
89 return false;
90 }
91
92 return true;
93}
94
95static void
100
101static void
106
109{
111
113
116 {
122 }
124}
125
126bool
128{
130
132 return false;
133
134
136 {
138 return false;
139 }
140
141 return true;
142}
143
146{
148
150 if (con == NULL)
151 {
152
154 }
155
157}
158
159bool
161{
164
166 return false;
167
168 ecpg_log("ECPGtrans on line %d: action \"%s\"; connection \"%s\"\n", lineno, transaction, con ? con->name : "null");
169
170
172 {
173
174
175
176
177
178
179
186 {
189 return false;
191 }
192
195 return false;
197 }
198
199 return true;
200}
201
202
203void
205{
206
208
209
211
212 if (n > 100)
213 {
216 }
217 else
219
221
222
224
225
227
229}
230
231void
233{
237 char *fmt;
239
240
241
242
243
244
246 return;
247
248
250
251
252
253
254
258 return;
259
262 else
264
266
268
269
271 {
275
276
278 {
281 }
282
284 }
285
287
289}
290
291void
293{
294 switch (type)
295 {
299 *((char *) ptr) = '\0';
300 break;
303 *((short int *) ptr) = SHRT_MIN;
304 break;
307 *((int *) ptr) = INT_MIN;
308 break;
313 break;
317 break;
319 memset(ptr, 0xff, sizeof(float));
320 break;
322 memset(ptr, 0xff, sizeof(double));
323 break;
327 break;
330 break;
334 break;
338 break;
341 break;
344 break;
345 default:
346 break;
347 }
348}
349
350static bool
351_check(const unsigned char *ptr, int length)
352{
353 for (length--; length >= 0; length--)
354 if (ptr[length] != 0xff)
355 return false;
356
357 return true;
358}
359
360bool
362{
363 switch (type)
364 {
368 if (*((const char *) ptr) == '\0')
369 return true;
370 break;
373 if (*((const short int *) ptr) == SHRT_MIN)
374 return true;
375 break;
378 if (*((const int *) ptr) == INT_MIN)
379 return true;
380 break;
384 if (*((const long *) ptr) == LONG_MIN)
385 return true;
386 break;
390 return true;
391 break;
393 return _check(ptr, sizeof(float));
394 break;
396 return _check(ptr, sizeof(double));
397 break;
400 return true;
401 break;
404 return true;
405 break;
408 return true;
409 break;
412 return true;
413 break;
416 break;
419 break;
420 default:
421 break;
422 }
423
424 return false;
425}
426
427#ifdef WIN32
428
429int
431{
432 mp->initstate = 0;
433 return 0;
434}
435
436int
438{
439
440 if (mp->initstate != 1)
441 {
443
445 Sleep(0);
449 }
451 return 0;
452}
453
454int
456{
457 if (mp->initstate != 1)
460 return 0;
461}
462
464
465void
467{
469 {
472 {
473 fn();
474 *once = true;
475 }
477 }
478}
479#endif
480
481#ifdef ENABLE_NLS
482
483char *
485{
486
487
488
489
490
491
492
495
497 {
498
499#ifdef WIN32
501#else
503#endif
504
506
508 {
509 const char *ldir;
510
511
512
513
514
520 }
521
523
524#ifdef WIN32
526#else
528#endif
529 }
530
532}
533#endif
534
536
537void
539{
541
543
545 {
548 return;
549 }
550
552
554 {
555 if (ptr->number == number)
556 {
557
559 return;
560 }
561 }
562
563
565 if (!ptr)
566 {
568
570 {
573 return;
574 }
575
578 snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc), "out of memory on line %d", lineno);
580
582 }
583 else
584 {
589 }
590}
591
592void *
#define PG_TEXTDOMAIN(domain)
struct connection * ecpg_get_connection(const char *connection_name)
#define fprintf(file, fmt, msg)
#define ECPG_OUT_OF_MEMORY
bool ecpg_check_PQresult(PGresult *results, int lineno, PGconn *connection, enum COMPAT_MODE compat)
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
#define ECPG_SQLSTATE_ECPG_INTERNAL_ERROR
#define ECPG_SQLSTATE_CONNECTION_DOES_NOT_EXIST
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
@ ECPGt_unsigned_long_long
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
PGresult * PQexec(PGconn *conn, const char *query)
void ECPGset_var(int number, void *pointer, int lineno)
PGTransactionStatusType ECPGtransactionStatus(const char *connection_name)
static pthread_key_t sqlca_key
struct sqlca_t * ECPGget_sqlca(void)
static void ecpg_sqlca_key_destructor(void *arg)
void ECPGset_noind_null(enum ECPGttype type, void *ptr)
static struct sqlca_t sqlca_init
static pthread_mutex_t debug_init_mutex
bool ECPGtrans(int lineno, const char *connection_name, const char *transaction)
static bool _check(const unsigned char *ptr, int length)
static pthread_mutex_t debug_mutex
bool ECPGis_noind_null(enum ECPGttype type, const void *ptr)
void ecpg_log(const char *format,...)
bool ecpg_init(const struct connection *con, const char *connection_name, const int lineno)
static FILE * debugstream
bool ECPGstatus(int lineno, const char *connection_name)
void ecpg_init_sqlca(struct sqlca_t *sqlca)
static volatile int simple_debug
void * ECPGget_var(int number)
bool ecpg_internal_regression_mode
static void ecpg_sqlca_key_init(void)
static pthread_once_t sqlca_key_once
void ECPGfree_auto_mem(void)
int pthread_mutex_unlock(pthread_mutex_t *mp)
int pthread_mutex_lock(pthread_mutex_t *mp)
void pthread_setspecific(pthread_key_t key, void *val)
void * pthread_getspecific(pthread_key_t key)
int pthread_mutex_init(pthread_mutex_t *mp, void *attr)
#define PTHREAD_MUTEX_INITIALIZER
char arr[FLEXIBLE_ARRAY_MEMBER]
static void * fn(void *arg)