G:/ScriptBasic/source/extensions/psql/interface.c File Reference

#include <postgresql/libpq-fe.h>
#include "../../basext.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  _Wrapper
struct  _ModuleGlobal

Defines

#define PTS_MODULE   "pgsqlinterf.c"
#define DEBUGMSG(x)
#define assert(x)
#define NDEBUG   1
#define InvalidOid   0
#define PGSQL_ERROR_CON_EXPECTED   0x00081001
#define PGSQL_ERROR_RES_EXPECTED   0x00081002
#define PGSQL_ERROR_HAN_EXPECTED   0x00081003
#define PGSQL_ERROR_CONNGET_KEY   0x00081004
#define PGSQL_ERROR_LVAL_EXPECTED   0x00081005
#define PGSQL_ERROR_EST_EXPECTED   0x00081006
#define copystr(dst, src)
#define copystrz(dst, src)
#define copystry(dst, src)
#define copylong(dst, src)
#define streq(var, strz)   (STRLEN(var)==strlen(strz) && 0==memcmp(STRINGVALUE(var),strz,STRLEN(var)))
#define strbegins(var, strz)   (STRLEN(var)>=strlen(strz) && 0==memcmp(STRINGVALUE(var),strz,strlen(strz)))

Typedefs

typedef enum _TY TY
typedef _Wrapper Wrapper
typedef _WrapperpWrapper
typedef _ModuleGlobal ModuleGlobal
typedef _ModuleGlobalpModuleGlobal

Enumerations

enum  _TY { CON = 1, RES = 2 }

Functions

static void stderrNoticeProcessor (void *arg, const char *message)
static void silentNoticeProcessor (void *arg, const char *message)
 besSUB_ERRMSG (void)
besEND besVERSION_NEGOTIATE (void)
static besEND Wrapperalloc_Wrapper (pSupportTable pSt, ModuleGlobal *mg)
static void delete_Wrapper (pSupportTable pSt, ModuleGlobal *mg, Wrapper *w)
 besFUNCTION (PGopen)
else if (TYPE(Argument)==VTYPE_STRING)
 LONGVALUE (besRETURNVALUE)
besEND besFUNCTION (PGclose)
 besFUNCTION (PGconnget)
 besALLOC_RETURN_STRING (strlen(s))
 memcpy (STRINGVALUE(besRETURNVALUE), s, STRLEN(besRETURNVALUE))
besEND besFUNCTION (PGok)
 for (p=cio;p!=cioend-3;p++)
 PQconninfoFree (cio)
besEND besFUNCTION (PGnotified)
 if (!(no=PQnotifies(w->u.con)))
 besLEFTVALUE (Argument2, Lval)
 while (len< NAMEDATALEN &&no->relname![len]='\0')
 if (!(query=besALLOC(sumlen)))
 DEBUGMSG (fprintf(stderr,"qry=(%s)\n", query);)
 if (est==PGRES_COMMAND_OK||est==PGRES_TUPLES_OK)
 besALLOC_RETURN_STRING (strlen(s)+2+strlen(dst))
 memcpy (STRINGVALUE(besRETURNVALUE), s, strlen(s))
 memcpy (STRINGVALUE(besRETURNVALUE)+strlen(s),": ", 2)
 memcpy (STRINGVALUE(besRETURNVALUE)+strlen(s)+2, dst, strlen(dst))
 if (res)
 besDEREFERENCE (Argument)
 besDEREFERENCE (Argument2)
 if (besARGNR, 2)
 besCONVERT2STRING (Argument2)
 if (strbegins(Argument2,"PGRES_EMPTY_QUERY"))
besEND besFUNCTION (PGoid)
 if (besARGNR, 1)
 if (InvalidOid==(oid=PQftype(w->u.res, idx)))
besEND besFUNCTION (PGcolmod)
besEND besFUNCTION (PGcolsize)
besEND besFUNCTION (PGgetvalue)
 besCONVERT2LONG (Argument2)
 if (!(v=PQgetvalue(w->u.res, LONGVALUE(Argument2), idx))||PQgetisnull(w->u.res, LONGVALUE(Argument2), idx)>0)
besEND besFUNCTION (PGgetlength)
 if (0 >(len=PQgetlength(w->u.res, LONGVALUE(Argument2), idx)))
besEND besFUNCTION (PGgetisnull)
 if (0 >(len=PQgetisnull(w->u.res, LONGVALUE(Argument2), idx)))
besEND besFUNCTION (PGbinaryTuples)
 besALLOC_RETURN_STRING (tmp)
besEND besFUNCTION (PGcmdTuples)

Variables

return NULL
 return
 besALLOC_RETURN_LONG
 besRETURNVALUE = NULL
 len = 0
dst = '\0'
 est = !res ? PGRES_FATAL_ERROR : PQresultStatus(res)
 s = PQresStatus(est)
 dst = res ? PQresultErrorMessage(res) : "PQexec() returned NULL"
Wrapperw
PGconn * con = NULL
PGresult * res
VARIABLE Argument = besARGUMENT(1)
VARIABLE Argument2 = besARGUMENT(2)
void pEo
w ty = RES
wres = res
 besALLOC_RETURN_LONG
VARIABLE Argument = besARGUMENT(1)
void pEo
void ppModuleInternal
Wrapperw
int idx = -1
char * s = NULL
VARIABLE Argument = besARGUMENT(1)
VARIABLE Argument2 = besARGUMENT(2)
void pEo
else idx = LONGVALUE(Argument2)
else idx = LONGVALUE(Argument2)
else idx = LONGVALUE(Argument2)
else idx = LONGVALUE(Argument3)
else idx = LONGVALUE(Argument3)
else idx = LONGVALUE(Argument3)
 tmp = strlen(s)
 tmp = strlen(s)
 besRETURNVALUE = besCONVERT2LONG(besRETURNVALUE)


Define Documentation

#define assert  ) 
 

Definition at line 39 of file interface.c.

Referenced by allocset(), besVERSION_NEGOTIATE(), bothcases(), delete_Wrapper(), doemit(), dofwd(), doinsert(), dupl(), findmust(), firstch(), mccase(), mcinvert(), mcsub(), nonnewline(), othercase(), p_bracket(), p_ere_exp(), p_simp_re(), regerror(), regexec(), and repeat().

#define copylong dst,
src   ) 
 

Value:

(\
  ((dst)=besNEWLONG) && \
  (LONGVALUE(dst)=src, 1) \
)

Definition at line 90 of file interface.c.

#define copystr dst,
src   ) 
 

Value:

(\
  ((dst)=besNEWSTRING(STRLEN(src))) && \
  (memcpy(STRINGVALUE(dst),STRINGVALUE(src),STRLEN(src)), 1) \
)

Definition at line 77 of file interface.c.

#define copystry dst,
src   ) 
 

Value:

(src ? (tmplen=strlen(src), \
  ((dst)=besNEWSTRING(tmplen)) && \
  (memcpy(STRINGVALUE(dst),src,tmplen), 1) \
) : ((dst)=NULL, 1) )
like copystrz, but converts NULL -> undef

Definition at line 86 of file interface.c.

#define copystrz dst,
src   ) 
 

Value:

(tmplen=strlen(src), \
  ((dst)=besNEWSTRING(tmplen)) && \
  (memcpy(STRINGVALUE(dst),src,tmplen), 1) \
)

Definition at line 81 of file interface.c.

#define DEBUGMSG  ) 
 

Definition at line 38 of file interface.c.

Referenced by alloc_Wrapper(), besFUNCTION(), besVERSION_NEGOTIATE(), and delete_Wrapper().

#define InvalidOid   0
 

Definition at line 44 of file interface.c.

#define NDEBUG   1
 

Definition at line 40 of file interface.c.

#define PGSQL_ERROR_CON_EXPECTED   0x00081001
 

Definition at line 70 of file interface.c.

Referenced by besFUNCTION().

#define PGSQL_ERROR_CONNGET_KEY   0x00081004
 

Definition at line 73 of file interface.c.

Referenced by besFUNCTION().

#define PGSQL_ERROR_EST_EXPECTED   0x00081006
 

Definition at line 75 of file interface.c.

#define PGSQL_ERROR_HAN_EXPECTED   0x00081003
 

Definition at line 72 of file interface.c.

#define PGSQL_ERROR_LVAL_EXPECTED   0x00081005
 

Definition at line 74 of file interface.c.

#define PGSQL_ERROR_RES_EXPECTED   0x00081002
 

Definition at line 71 of file interface.c.

#define PTS_MODULE   "pgsqlinterf.c"
 

Definition at line 24 of file interface.c.

Referenced by alloc_Wrapper(), besVERSION_NEGOTIATE(), and delete_Wrapper().

#define strbegins var,
strz   )     (STRLEN(var)>=strlen(strz) && 0==memcmp(STRINGVALUE(var),strz,strlen(strz)))
 

Definition at line 96 of file interface.c.

#define streq var,
strz   )     (STRLEN(var)==strlen(strz) && 0==memcmp(STRINGVALUE(var),strz,STRLEN(var)))
 

Definition at line 94 of file interface.c.


Typedef Documentation

typedef struct _ModuleGlobal ModuleGlobal
 

typedef struct _ModuleGlobal * pModuleGlobal
 

typedef struct _Wrapper * pWrapper
 

typedef enum _TY TY
 

typedef struct _Wrapper Wrapper
 


Enumeration Type Documentation

enum _TY
 

Enumerator:
CON 
RES 

Definition at line 47 of file interface.c.


Function Documentation

static besEND Wrapper* alloc_Wrapper pSupportTable  pSt,
ModuleGlobal mg
[static]
 

May return NULL

Definition at line 205 of file interface.c.

References besLockMutex(), besUnlockMutex(), DEBUGMSG, _ModuleGlobal::first, _ModuleGlobal::ha, _Wrapper::next, NULL, _Wrapper::prev, PTS_MODULE, and w.

Referenced by if().

besALLOC_RETURN_STRING tmp   ) 
 

besALLOC_RETURN_STRING strlen(s)+2+strlen(dst  ) 
 

besALLOC_RETURN_STRING strlen(s  ) 
 

besCONVERT2LONG Argument2   ) 
 

besCONVERT2STRING Argument2   ) 
 

Referenced by basext_GetArgsF(), besFUNCTION(), CHECK_OPTION(), and if().

besDEREFERENCE Argument2   ) 
 

besDEREFERENCE Argument   ) 
 

besEND besFUNCTION PGcmdTuples   ) 
 

Definition at line 981 of file interface.c.

besEND besFUNCTION PGbinaryTuples   ) 
 

Definition at line 945 of file interface.c.

besEND besFUNCTION PGgetisnull   ) 
 

Definition at line 913 of file interface.c.

References besCONVERT2STRING(), besCONVERT2ZCHAR(), and besFREE().

besEND besFUNCTION PGgetlength   ) 
 

Definition at line 881 of file interface.c.

References besCONVERT2STRING(), besCONVERT2ZCHAR(), and besFREE().

besEND besFUNCTION PGgetvalue   ) 
 

Definition at line 845 of file interface.c.

References besCONVERT2STRING(), besCONVERT2ZCHAR(), and besFREE().

besEND besFUNCTION PGcolsize   ) 
 

Definition at line 814 of file interface.c.

References besCONVERT2STRING(), besCONVERT2ZCHAR(), besFREE(), DEBUGMSG, if(), and w.

besEND besFUNCTION PGcolmod   ) 
 

Definition at line 785 of file interface.c.

References besCONVERT2STRING(), besCONVERT2ZCHAR(), besFREE(), and w.

besEND besFUNCTION PGoid   ) 
 

Definition at line 635 of file interface.c.

besEND besFUNCTION PGnotified   ) 
 

Definition at line 409 of file interface.c.

References besRETURNVALUE, and NULL.

besEND besFUNCTION PGok   ) 
 

Definition at line 340 of file interface.c.

References COMMAND_ERROR_MEMORY_LOW, and PQconninfoFree().

besFUNCTION PGconnget   ) 
 

Definition at line 305 of file interface.c.

References besALLOC_RETURN_LONG, besRETURNVALUE, LONGVALUE(), PGSQL_ERROR_CONNGET_KEY, STRINGVALUE(), STRLEN(), and w.

besEND besFUNCTION PGclose   ) 
 

Definition at line 281 of file interface.c.

besFUNCTION PGopen   ) 
 

Definition at line 240 of file interface.c.

References besMODULEPOINTER, CON, PGSQL_ERROR_CON_EXPECTED, and w.

besLEFTVALUE Argument2  ,
Lval 
 

besSUB_ERRMSG void   ) 
 

Definition at line 110 of file interface.c.

besEND besVERSION_NEGOTIATE void   ) 
 

Definition at line 126 of file interface.c.

References assert, CON, DEBUGMSG, PTS_MODULE, q, and RES.

DEBUGMSG fprintf(stderr,"qry=(%s)\n", query);   ) 
 

Definition at line 537 of file interface.c.

static void delete_Wrapper pSupportTable  pSt,
ModuleGlobal mg,
Wrapper w
[static]
 

Also calls PGfinish() or PGclear()

Definition at line 221 of file interface.c.

References assert, besFREE(), besLockMutex(), besUnlockMutex(), CON, DEBUGMSG, _ModuleGlobal::first, _ModuleGlobal::ha, NULL, PTS_MODULE, RES, and w.

for p  = cio; p!=cioend-3; p++  ) 
 

Definition at line 385 of file interface.c.

if ,
(len=PQgetisnull(w->u.res, LONGVALUE(Argument2), idx)) 
 

Definition at line 937 of file interface.c.

if ,
(len=PQgetlength(w->u.res, LONGVALUE(Argument2), idx)) 
 

Definition at line 905 of file interface.c.

if (v=PQgetvalue(w->u.res, LONGVALUE(Argument2), idx))||PQgetisnull(w->u.res, LONGVALUE(Argument2), idx),
 

Definition at line 870 of file interface.c.

if InvalidOid  = =(oid=PQftype(w->u.residx))  ) 
 

Definition at line 777 of file interface.c.

if besARGNR  ,
 

Definition at line 661 of file interface.c.

if strbegins(Argument2,"PGRES_EMPTY_QUERY")   ) 
 

Definition at line 616 of file interface.c.

if besARGNR  ,
 

Definition at line 605 of file interface.c.

References besMODULEPOINTER, CON, and w.

if res   ) 
 

Definition at line 559 of file interface.c.

else if est  = =PGRES_COMMAND_OK || est==PGRES_TUPLES_OK  ) 
 

Definition at line 544 of file interface.c.

References alloc_Wrapper(), besALLOC_RETURN_LONG, besMODULEPOINTER, besRETURNVALUE, LONGVALUE(), pSt, RES, and w.

if (query=besALLOC(sumlen))  ) 
 

Definition at line 514 of file interface.c.

if (no=PQnotifies(w->u.con))  ) 
 

Definition at line 433 of file interface.c.

References besALLOC_RETURN_LONG, besRETURNVALUE, LONGVALUE(), and NULL.

else if TYPE(Argument = =VTYPE_STRING  ) 
 

Definition at line 252 of file interface.c.

LONGVALUE besRETURNVALUE   ) 
 

memcpy STRINGVALUE(besRETURNVALUE)+strlen(s)+  2,
dst  ,
strlen(dst
 

memcpy STRINGVALUE(besRETURNVALUE)+strlen(s ,
": "  ,
 

memcpy STRINGVALUE(besRETURNVALUE ,
s  ,
strlen(s
 

memcpy STRINGVALUE(besRETURNVALUE ,
s  ,
STRLEN(besRETURNVALUE
 

PQconninfoFree cio   ) 
 

Referenced by besFUNCTION().

static void silentNoticeProcessor void *  arg,
const char *  message
[static]
 

Definition at line 104 of file interface.c.

static void stderrNoticeProcessor void *  arg,
const char *  message
[static]
 

Definition at line 99 of file interface.c.

while len< NAMEDATALEN &&no->relname!  [len] = '\0'  ) 
 

Definition at line 440 of file interface.c.


Variable Documentation

VARIABLE Argument = besARGUMENT(1)
 

Definition at line 761 of file interface.c.

VARIABLE Argument = besARGUMENT(1)
 

Definition at line 657 of file interface.c.

VARIABLE Argument = besARGUMENT(1)
 

Definition at line 600 of file interface.c.

VARIABLE Argument2 = besARGUMENT(2)
 

Definition at line 762 of file interface.c.

VARIABLE Argument2 = besARGUMENT(2)
 

Definition at line 601 of file interface.c.

besALLOC_RETURN_LONG
 

Definition at line 632 of file interface.c.

besALLOC_RETURN_LONG
 

Definition at line 276 of file interface.c.

besRETURNVALUE = besCONVERT2LONG(besRETURNVALUE)
 

Definition at line 999 of file interface.c.

besRETURNVALUE = NULL
 

Definition at line 406 of file interface.c.

PGconn* con = NULL
 

Definition at line 598 of file interface.c.

dst = res ? PQresultErrorMessage(res) : "PQexec() returned NULL"
 

Definition at line 554 of file interface.c.

* dst = '\0'
 

Definition at line 536 of file interface.c.

est = !res ? PGRES_FATAL_ERROR : PQresultStatus(res)
 

Definition at line 543 of file interface.c.

else idx = LONGVALUE(Argument3)
 

Definition at line 935 of file interface.c.

else idx = LONGVALUE(Argument3)
 

Definition at line 903 of file interface.c.

else idx = LONGVALUE(Argument3)
 

Definition at line 867 of file interface.c.

else idx = LONGVALUE(Argument2)
 

Definition at line 836 of file interface.c.

else idx = LONGVALUE(Argument2)
 

Definition at line 805 of file interface.c.

else idx = LONGVALUE(Argument2)
 

Definition at line 776 of file interface.c.

int idx = -1
 

Definition at line 759 of file interface.c.

len = 0
 

Definition at line 440 of file interface.c.

return NULL
 

Definition at line 121 of file interface.c.

void pEo
 

Definition at line 763 of file interface.c.

void pEo
 

Definition at line 658 of file interface.c.

void pEo
 

Definition at line 602 of file interface.c.

Referenced by comm_GetCommand(), if(), and while().

void ppModuleInternal
 

Definition at line 659 of file interface.c.

w u res = res
 

Definition at line 631 of file interface.c.

PGresult* res
 

Definition at line 599 of file interface.c.

return
 

Definition at line 201 of file interface.c.

char* s = NULL
 

Definition at line 760 of file interface.c.

s = PQresStatus(est)
 

Definition at line 553 of file interface.c.

tmp = strlen(s)
 

Definition at line 996 of file interface.c.

tmp = strlen(s)
 

Definition at line 976 of file interface.c.

w ty = RES
 

Definition at line 631 of file interface.c.

Wrapper* w
 

Definition at line 757 of file interface.c.

Wrapper* w
 

Definition at line 596 of file interface.c.


Generated on Sun Mar 12 23:56:36 2006 for ScriptBasic by  doxygen 1.4.6-NO