rpm  5.4.15
Data Structures | Macros | Typedefs | Functions | Variables
rpmodbc.c File Reference
#include "system.h"
#include <rpmiotypes.h>
#include <rpmio.h>
#include <rpmlog.h>
#include <rpmmacro.h>
#include <rpmurl.h>
#include <argv.h>
#include <rpmodbc.h>
#include "debug.h"
Include dependency graph for rpmodbc.c:

Go to the source code of this file.

Data Structures

struct  key_s
 

Macros

#define _RPMODBC_INTERNAL
 
#define DBG(_t, _l)   if ((_t) || _odbc_debug) fprintf _l
 
#define SPEW(_t, _rc, _odbc)
 
#define SQL_SUCCEEDED(rc)   (((rc)&(~1))==0)
 
#define SQL_NO_DATA   100
 
#define SQL_FETCH_NEXT   1
 
#define SQL_FETCH_FIRST   2
 
#define SQL_FETCH_LAST   3
 
#define SQL_FETCH_PRIOR   4
 
#define SQL_FETCH_ABSOLUTE   5
 
#define SQL_FETCH_RELATIVE   6
 
#define SQL_C_CHAR   1
 
#define SQL_C_SHORT   5
 
#define SQL_C_LONG   4
 
#define SQL_C_FLOAT   6
 
#define SQL_C_DOUBLE   8
 
#define SQL_C_DATE   9
 
#define SQL_C_TIME   10
 
#define SQL_C_TIMESTAMP   11
 
#define SQL_COLUMN_NAME   1
 
#define SQL_COLUMN_TABLE_NAME   15
 
#define SQL_COLUMN_LABEL   18
 
#define SQL_COMMIT   0
 
#define SQL_ROLLBACK   1
 
#define CHECK(_o, _t, _m, _rc)   (-1)
 
#define _ENTRY(_t, _v)   { _t, SQL_ATTR_##_v, #_v, }
 
#define _ENTRY(_t, _v)   { _t, SQL_##_v, #_v, }
 
#define _ENTRY(_t, _v)   { _t, SQL_ATTR_##_v, #_v, }
 
#define _ENTRY(_t, _v)   { _t, SQL_COLUMN_##_v, #_v, }
 

Typedefs

typedef struct key_s KEY
 

Functions

static void * hFree (ODBC_t odbc, HNDL_t H)
 
static void * hAlloc (ODBC_t odbc, int ht)
 
static int odbcDumpStmt (ODBC_t odbc, void *_fp)
 
int odbcGetStmtAttr (ODBC_t odbc, int _attr, void *_bp, int _nb, int *nsp)
 
int odbcSetStmtAttr (ODBC_t odbc, int _attr, void *_bp, int ns)
 
static int odbcDumpInfo (ODBC_t odbc, void *_fp)
 
int odbcGetInfo (ODBC_t odbc, int _type, void *_bp, int _nb, short *nsp)
 
static int odbcDumpEnvAttr (ODBC_t odbc, void *_fp)
 
int odbcGetEnvAttr (ODBC_t odbc, int _type, void *_bp, int _nb, int *nsp)
 
int odbcSetEnvAttr (ODBC_t odbc, int _type, void *_bp, int ns)
 
static int odbcDumpColAttrs (ODBC_t odbc, int colx, void *_fp)
 
int odbcColAttribute (ODBC_t odbc, unsigned short ColumnNumber, unsigned short FieldIdentifier, void *CharacterAttributePtr, short BufferLength, short *StringLengthPtr, long *NumericAttributePtr)
 
int odbcCloseCursor (ODBC_t odbc)
 
const char * odbcGetCursorName (ODBC_t odbc)
 
int odbcSetCursorName (ODBC_t odbc, const char *s, size_t ns)
 
int odbcEndTran (ODBC_t odbc, int _rollback)
 
int odbcCommit (ODBC_t odbc)
 
int odbcRollback (ODBC_t odbc)
 
int odbcConnect (ODBC_t odbc, const char *uri)
 
int odbcDisconnect (ODBC_t odbc)
 
int odbcListDataSources (ODBC_t odbc, void *_fp)
 
int odbcListDrivers (ODBC_t odbc, void *_fp)
 
int odbcNRows (ODBC_t odbc)
 
int odbcNCols (ODBC_t odbc)
 
int odbcCancel (ODBC_t odbc)
 
int odbcFetch (ODBC_t odbc)
 
int odbcFetchScroll (ODBC_t odbc, short FetchOrientation, long FetchOffset)
 
int odbcGetData (ODBC_t odbc, unsigned short Col_or_Param_Num, short TargetType, void *TargetValuePtr, long BufferLength, long *StrLen_or_IndPtr)
 
int odbcPrint (ODBC_t odbc, void *_fp)
 
int odbcTables (ODBC_t odbc, const char *tblname)
 
int odbcColumns (ODBC_t odbc, const char *tblname, const char *colname)
 
int odbcStatistics (ODBC_t odbc, const char *tblname)
 
int odbcExecDirect (ODBC_t odbc, const char *s, size_t ns)
 
int odbcPrepare (ODBC_t odbc, const char *s, size_t ns)
 
int odbcBindCol (ODBC_t odbc, unsigned short ColumnNumber, short TargetType, void *TargetValuePtr, long BufferLength, long *StrLen_or_Ind)
 
int odbcBindParameter (ODBC_t odbc, _PARAM_t param)
 
int odbcExecute (ODBC_t odbc)
 
static void odbcFini (void *_odbc)
 
static ODBC_t odbcGetPool (rpmioPool pool)
 
ODBC_t odbcNew (const char *fn, int flags)
 Create and load a odbc wrapper. More...
 

Variables

int _odbc_debug = 0
 
static KEY SQL_ATTRS []
 
static size_t nSQL_ATTRS = sizeof(SQL_ATTRS) / sizeof(SQL_ATTRS[0])
 
static KEY SQL_INFOS []
 
static size_t nSQL_INFOS = sizeof(SQL_INFOS) / sizeof(SQL_INFOS[0])
 
static KEY SQL_EATTRS []
 
static size_t nSQL_EATTRS = sizeof(SQL_EATTRS) / sizeof(SQL_EATTRS[0])
 
static KEY SQL_CATTRS []
 
static size_t nSQL_CATTRS = sizeof(SQL_CATTRS) / sizeof(SQL_CATTRS[0])
 
rpmioPool _odbcPool = NULL
 
static char * _odbc_uri = "mysql://luser:jasnl@localhost/test"
 

Macro Definition Documentation

#define _ENTRY (   _t,
  _v 
)    { _t, SQL_ATTR_##_v, #_v, }

Definition at line 590 of file rpmodbc.c.

#define _ENTRY (   _t,
  _v 
)    { _t, SQL_##_v, #_v, }

Definition at line 590 of file rpmodbc.c.

#define _ENTRY (   _t,
  _v 
)    { _t, SQL_ATTR_##_v, #_v, }

Definition at line 590 of file rpmodbc.c.

#define _ENTRY (   _t,
  _v 
)    { _t, SQL_COLUMN_##_v, #_v, }

Definition at line 590 of file rpmodbc.c.

#define _RPMODBC_INTERNAL

Definition at line 18 of file rpmodbc.c.

#define CHECK (   _o,
  _t,
  _m,
  _rc 
)    (-1)
#define DBG (   _t,
  _l 
)    if ((_t) || _odbc_debug) fprintf _l

Definition at line 26 of file rpmodbc.c.

Referenced by odbcConnect(), odbcExecDirect(), odbcPrepare(), and odbcPrint().

#define SPEW (   _t,
  _rc,
  _odbc 
)
#define SQL_C_CHAR   1

Definition at line 45 of file rpmodbc.c.

Referenced by odbcPrint().

#define SQL_C_DATE   9

Definition at line 50 of file rpmodbc.c.

#define SQL_C_DOUBLE   8

Definition at line 49 of file rpmodbc.c.

#define SQL_C_FLOAT   6

Definition at line 48 of file rpmodbc.c.

#define SQL_C_LONG   4

Definition at line 47 of file rpmodbc.c.

#define SQL_C_SHORT   5

Definition at line 46 of file rpmodbc.c.

#define SQL_C_TIME   10

Definition at line 51 of file rpmodbc.c.

#define SQL_C_TIMESTAMP   11

Definition at line 52 of file rpmodbc.c.

#define SQL_COLUMN_LABEL   18

Definition at line 56 of file rpmodbc.c.

Referenced by odbcPrint().

#define SQL_COLUMN_NAME   1

Definition at line 54 of file rpmodbc.c.

#define SQL_COLUMN_TABLE_NAME   15

Definition at line 55 of file rpmodbc.c.

#define SQL_COMMIT   0

Definition at line 58 of file rpmodbc.c.

Referenced by odbcCommit(), and odbcEndTran().

#define SQL_FETCH_ABSOLUTE   5

Definition at line 42 of file rpmodbc.c.

#define SQL_FETCH_FIRST   2

Definition at line 39 of file rpmodbc.c.

Referenced by odbcListDataSources(), and odbcListDrivers().

#define SQL_FETCH_LAST   3

Definition at line 40 of file rpmodbc.c.

#define SQL_FETCH_NEXT   1

Definition at line 38 of file rpmodbc.c.

Referenced by odbcListDataSources(), and odbcListDrivers().

#define SQL_FETCH_PRIOR   4

Definition at line 41 of file rpmodbc.c.

#define SQL_FETCH_RELATIVE   6

Definition at line 43 of file rpmodbc.c.

#define SQL_NO_DATA   100
#define SQL_ROLLBACK   1

Definition at line 59 of file rpmodbc.c.

Referenced by odbcEndTran(), and odbcRollback().

#define SQL_SUCCEEDED (   rc)    (((rc)&(~1))==0)

Definition at line 36 of file rpmodbc.c.

Referenced by odbcListDataSources(), odbcListDrivers(), and odbcPrint().

Typedef Documentation

typedef struct key_s KEY

Function Documentation

static void* hAlloc ( ODBC_t  odbc,
int  ht 
)
static

Definition at line 128 of file rpmodbc.c.

References CHECK, and xmalloc.

Referenced by odbcColumns(), odbcConnect(), odbcExecDirect(), odbcNew(), odbcPrepare(), odbcStatistics(), and odbcTables().

static void* hFree ( ODBC_t  odbc,
HNDL_t  H 
)
static

Definition at line 113 of file rpmodbc.c.

References _free(), and CHECK.

Referenced by odbcCancel(), odbcDisconnect(), odbcFini(), odbcPrepare(), and odbcPrint().

int odbcBindCol ( ODBC_t  odbc,
unsigned short  ColumnNumber,
short  TargetType,
void *  TargetValuePtr,
long  BufferLength,
long *  StrLen_or_Ind 
)

Definition at line 1159 of file rpmodbc.c.

References CHECK, and SPEW.

int odbcBindParameter ( ODBC_t  odbc,
_PARAM_t  param 
)

Definition at line 1176 of file rpmodbc.c.

References CHECK, and SPEW.

int odbcCancel ( ODBC_t  odbc)

Definition at line 927 of file rpmodbc.c.

References CHECK, hFree(), SPEW, and SQL_NO_DATA.

int odbcCloseCursor ( ODBC_t  odbc)

Definition at line 687 of file rpmodbc.c.

References CHECK, SPEW, and SQL_NO_DATA.

int odbcColAttribute ( ODBC_t  odbc,
unsigned short  ColumnNumber,
unsigned short  FieldIdentifier,
void *  CharacterAttributePtr,
short  BufferLength,
short *  StringLengthPtr,
long *  NumericAttributePtr 
)

Definition at line 660 of file rpmodbc.c.

References CHECK, and SPEW.

Referenced by odbcDumpColAttrs(), and odbcPrint().

int odbcColumns ( ODBC_t  odbc,
const char *  tblname,
const char *  colname 
)

Definition at line 1074 of file rpmodbc.c.

References CHECK, hAlloc(), and SPEW.

int odbcCommit ( ODBC_t  odbc)

Definition at line 752 of file rpmodbc.c.

References odbcEndTran(), and SQL_COMMIT.

int odbcConnect ( ODBC_t  odbc,
const char *  uri 
)
int odbcDisconnect ( ODBC_t  odbc)

Definition at line 814 of file rpmodbc.c.

References CHECK, hFree(), and SPEW.

static int odbcDumpColAttrs ( ODBC_t  odbc,
int  colx,
void *  _fp 
)
static

Definition at line 620 of file rpmodbc.c.

References b, i, ns, nSQL_CATTRS, odbcColAttribute(), and key_s::v.

Referenced by odbcPrint().

static int odbcDumpEnvAttr ( ODBC_t  odbc,
void *  _fp 
)
static

Definition at line 541 of file rpmodbc.c.

References i, ns, nSQL_EATTRS, odbcGetEnvAttr(), and key_s::v.

Referenced by odbcNew().

static int odbcDumpInfo ( ODBC_t  odbc,
void *  _fp 
)
static

Definition at line 464 of file rpmodbc.c.

References i, ns, nSQL_INFOS, odbcGetInfo(), and key_s::v.

Referenced by odbcConnect().

static int odbcDumpStmt ( ODBC_t  odbc,
void *  _fp 
)
static

Definition at line 209 of file rpmodbc.c.

References i, ns, nSQL_ATTRS, odbcGetStmtAttr(), and key_s::v.

Referenced by odbcPrint().

int odbcEndTran ( ODBC_t  odbc,
int  _rollback 
)

Definition at line 738 of file rpmodbc.c.

References CHECK, SPEW, SQL_COMMIT, and SQL_ROLLBACK.

Referenced by odbcCommit(), and odbcRollback().

int odbcExecDirect ( ODBC_t  odbc,
const char *  s,
size_t  ns 
)

Definition at line 1114 of file rpmodbc.c.

References CHECK, DBG, hAlloc(), and SPEW.

int odbcExecute ( ODBC_t  odbc)

Definition at line 1196 of file rpmodbc.c.

References CHECK, and SPEW.

int odbcFetch ( ODBC_t  odbc)

Definition at line 941 of file rpmodbc.c.

References CHECK, SPEW, and SQL_NO_DATA.

Referenced by odbcPrint().

int odbcFetchScroll ( ODBC_t  odbc,
short  FetchOrientation,
long  FetchOffset 
)

Definition at line 954 of file rpmodbc.c.

References CHECK, SPEW, and SQL_NO_DATA.

static void odbcFini ( void *  _odbc)
static

Definition at line 1209 of file rpmodbc.c.

References _free(), hFree(), and urlFree().

Referenced by odbcGetPool().

const char* odbcGetCursorName ( ODBC_t  odbc)

Definition at line 700 of file rpmodbc.c.

References b, CHECK, ns, SPEW, SQL_NO_DATA, and xstrdup().

int odbcGetData ( ODBC_t  odbc,
unsigned short  Col_or_Param_Num,
short  TargetType,
void *  TargetValuePtr,
long  BufferLength,
long *  StrLen_or_IndPtr 
)

Definition at line 967 of file rpmodbc.c.

References CHECK, and SPEW.

Referenced by odbcPrint().

int odbcGetEnvAttr ( ODBC_t  odbc,
int  _type,
void *  _bp,
int  _nb,
int *  nsp 
)

Definition at line 569 of file rpmodbc.c.

References CHECK.

Referenced by odbcDumpEnvAttr().

int odbcGetInfo ( ODBC_t  odbc,
int  _type,
void *  _bp,
int  _nb,
short *  nsp 
)

Definition at line 513 of file rpmodbc.c.

References CHECK.

Referenced by odbcDumpInfo().

static ODBC_t odbcGetPool ( rpmioPool  pool)
static

Definition at line 1228 of file rpmodbc.c.

References _odbc_debug, _odbcPool, odbcFini(), rpmioGetPool(), and rpmioNewPool().

Referenced by odbcNew().

int odbcGetStmtAttr ( ODBC_t  odbc,
int  _attr,
void *  _bp,
int  _nb,
int *  nsp 
)

Definition at line 258 of file rpmodbc.c.

References CHECK.

Referenced by odbcDumpStmt().

int odbcListDataSources ( ODBC_t  odbc,
void *  _fp 
)

Definition at line 831 of file rpmodbc.c.

References CHECK, SPEW, SQL_FETCH_FIRST, SQL_FETCH_NEXT, and SQL_SUCCEEDED.

int odbcListDrivers ( ODBC_t  odbc,
void *  _fp 
)

Definition at line 864 of file rpmodbc.c.

References CHECK, SPEW, SQL_FETCH_FIRST, SQL_FETCH_NEXT, and SQL_SUCCEEDED.

int odbcNCols ( ODBC_t  odbc)

Definition at line 912 of file rpmodbc.c.

References CHECK, columns, and SPEW.

Referenced by odbcPrint().

ODBC_t odbcNew ( const char *  fn,
int  flags 
)

Create and load a odbc wrapper.

Parameters
fnodbc file
flagsodbc flags
Returns
new odbc wrapper

Definition at line 1246 of file rpmodbc.c.

References _odbc_debug, _odbc_uri, flags, hAlloc(), odbcDumpEnvAttr(), odbcGetPool(), odbcLink(), odbcSetEnvAttr(), rpmExpand(), urlinfo_s::scheme, URL_IS_MYSQL, URL_IS_POSTGRES, URL_IS_SQLSERVER, urlLink(), urlPath(), urlSplit(), and xstrdup().

int odbcNRows ( ODBC_t  odbc)

Definition at line 897 of file rpmodbc.c.

References CHECK, and SPEW.

int odbcPrepare ( ODBC_t  odbc,
const char *  s,
size_t  ns 
)

Definition at line 1135 of file rpmodbc.c.

References CHECK, DBG, hAlloc(), hFree(), and SPEW.

int odbcPrint ( ODBC_t  odbc,
void *  _fp 
)
int odbcRollback ( ODBC_t  odbc)

Definition at line 757 of file rpmodbc.c.

References odbcEndTran(), and SQL_ROLLBACK.

int odbcSetCursorName ( ODBC_t  odbc,
const char *  s,
size_t  ns 
)

Definition at line 721 of file rpmodbc.c.

References CHECK, SPEW, and SQL_NO_DATA.

int odbcSetEnvAttr ( ODBC_t  odbc,
int  _type,
void *  _bp,
int  ns 
)

Definition at line 579 of file rpmodbc.c.

References CHECK.

Referenced by odbcNew().

int odbcSetStmtAttr ( ODBC_t  odbc,
int  _attr,
void *  _bp,
int  ns 
)

Definition at line 269 of file rpmodbc.c.

References CHECK.

int odbcStatistics ( ODBC_t  odbc,
const char *  tblname 
)

Definition at line 1094 of file rpmodbc.c.

References CHECK, hAlloc(), and SPEW.

int odbcTables ( ODBC_t  odbc,
const char *  tblname 
)

Definition at line 1054 of file rpmodbc.c.

References CHECK, hAlloc(), and SPEW.

Variable Documentation

int _odbc_debug = 0

Definition at line 24 of file rpmodbc.c.

Referenced by odbcGetPool(), odbcNew(), and odbcPrint().

char* _odbc_uri = "mysql://luser:jasnl@localhost/test"
static

Definition at line 1244 of file rpmodbc.c.

Referenced by odbcNew().

rpmioPool _odbcPool = NULL

Definition at line 1226 of file rpmodbc.c.

Referenced by odbcGetPool(), and rpmioClean().

size_t nSQL_ATTRS = sizeof(SQL_ATTRS) / sizeof(SQL_ATTRS[0])
static

Definition at line 207 of file rpmodbc.c.

Referenced by odbcDumpStmt().

size_t nSQL_CATTRS = sizeof(SQL_CATTRS) / sizeof(SQL_CATTRS[0])
static

Definition at line 618 of file rpmodbc.c.

Referenced by odbcDumpColAttrs().

size_t nSQL_EATTRS = sizeof(SQL_EATTRS) / sizeof(SQL_EATTRS[0])
static

Definition at line 539 of file rpmodbc.c.

Referenced by odbcDumpEnvAttr().

size_t nSQL_INFOS = sizeof(SQL_INFOS) / sizeof(SQL_INFOS[0])
static

Definition at line 462 of file rpmodbc.c.

Referenced by odbcDumpInfo().

KEY SQL_ATTRS[]
static

Definition at line 162 of file rpmodbc.c.

KEY SQL_CATTRS[]
static
Initial value:
= {
{ 0, 0, "UNKNOWN" },
}

Definition at line 591 of file rpmodbc.c.

KEY SQL_EATTRS[]
static
Initial value:
= {
}

Definition at line 525 of file rpmodbc.c.

KEY SQL_INFOS[]
static

Definition at line 281 of file rpmodbc.c.