1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
|
/*
Copyright (c) 2011 Marius Popa <mapopa@gmail.com>
Copyright (c) 2010 pilcrow <mjp@pilcrow.madison.wi.us>
Copyright (c) 1999-2008 Edwin Pratomo
Portions Copyright (c) 2001-2005 Daniel Ritz
You may distribute under the terms of either the GNU General Public
License or the Artistic License, as specified in the Perl README file.
*/
#include <DBIXS.h> /* installed by the DBI module */
/* make it compile with DBI < 1.20 */
#ifndef SQL_TYPE_DATE
# define SQL_TYPE_DATE 91
#endif
#ifndef SQL_TYPE_TIME
# define SQL_TYPE_TIME 92
#endif
#ifndef SQL_BLOB
# define SQL_BLOB 30
#endif
#ifndef SQL_ARRAY
# define SQL_ARRAY 50
#endif
static const int DBI_SQL_CHAR = SQL_CHAR;
static const int DBI_SQL_NUMERIC = SQL_NUMERIC;
static const int DBI_SQL_DECIMAL = SQL_DECIMAL;
static const int DBI_SQL_INTEGER = SQL_INTEGER;
static const int DBI_SQL_SMALLINT = SQL_SMALLINT;
static const int DBI_SQL_FLOAT = SQL_FLOAT;
static const int DBI_SQL_REAL = SQL_REAL;
static const int DBI_SQL_DOUBLE = SQL_DOUBLE;
static const int DBI_SQL_DATE = SQL_DATE;
static const int DBI_SQL_TIME = SQL_TIME;
static const int DBI_SQL_TIMESTAMP = SQL_TIMESTAMP;
static const int DBI_SQL_VARCHAR = SQL_VARCHAR;
static const int DBI_SQL_TYPE_TIME = SQL_TYPE_TIME;
static const int DBI_SQL_TYPE_DATE = SQL_TYPE_DATE;
static const int DBI_SQL_ARRAY = SQL_ARRAY;
static const int DBI_SQL_BLOB = SQL_BLOB;
/* conflicts */
#undef SQL_CHAR
#undef SQL_NUMERIC
#undef SQL_DECIMAL
#undef SQL_INTEGER
#undef SQL_SMALLINT
#undef SQL_FLOAT
#undef SQL_REAL
#undef SQL_DOUBLE
#undef SQL_DATE
#undef SQL_TIME
#undef SQL_TIMESTAMP
#undef SQL_VARCHAR
#undef SQL_TYPE_TIME
#undef SQL_TYPE_DATE
#undef SQL_ARRAY
#undef SQL_BLOB
#undef SQL_BOOLEAN
#include <ibase.h>
#include <time.h>
/* defines */
/* Firebird API 20 */
#if !defined(FB_API_VER) || FB_API_VER < 20
typedef void (*ISC_EVENT_CALLBACK)();
#endif
#ifndef SQLDA_CURRENT_VERSION
# define SQLDA_OK_VERSION SQLDA_VERSION1
#else
# define SQLDA_OK_VERSION SQLDA_CURRENT_VERSION
#endif
#define IB_ALLOC_FAIL 2
#define IB_FETCH_ERROR 1
#ifndef ISC_STATUS_LENGTH
# define ISC_STATUS_LENGTH 20
#endif
#ifndef SvPV_nolen
# define SvPV_nolen(sv) SvPV(sv, na)
#endif
#define FREE_SETNULL(ptr) \
do { \
if (ptr) \
{ \
Safefree(ptr); \
ptr = NULL; \
} \
} while (0)
#define DPB_FILL_BYTE(dpb, code, byte) \
do { \
*dpb++ = code; \
*dpb++ = 1; \
*dpb++ = byte; \
} while (0)
#define DPB_FILL_INTEGER(dpb, code, integer) \
do { \
ISC_LONG tmp = integer; \
*dpb++ = code; \
*dpb++ = sizeof(tmp); \
tmp = isc_vax_integer((char *) &tmp, sizeof(tmp)); \
Copy(&tmp, dpb, 1, ISC_LONG); \
dpb += sizeof(tmp); \
} while (0)
#define DPB_FILL_STRING(dpb, code, string) \
DPB_FILL_STRING_LEN(dpb, code, string, strlen(string) )
#define DPB_FILL_STRING_LEN(dpb, code, string, len) \
do { \
if ( len > 255 ) \
croak("DPB string too long (%d)", len); \
*dpb++ = code; \
*dpb++ = len; \
strncpy(dpb, string, (size_t) len); \
dpb += len; \
} while (0)
#define DPB_PREP_INTEGER(buflen) \
do { \
buflen += sizeof(ISC_LONG) + 2; \
} while (0)
#define DPB_PREP_STRING(buflen, string) \
DPB_PREP_STRING_LEN(buflen, strlen(string))
#define DPB_PREP_STRING_LEN(buflen, len) \
do { \
buflen += len + 2; \
} while (0)
# define TIMESTAMP_FPSECS(value) \
(long)(((ISC_TIMESTAMP *)value)->timestamp_time % ISC_TIME_SECONDS_PRECISION)
# define TIMESTAMP_ADD_FPSECS(value, inc) \
((ISC_TIMESTAMP *)value)->timestamp_time += (inc % ISC_TIME_SECONDS_PRECISION)
# define TIME_FPSECS(value) \
(long)((*(ISC_TIME *)value) % ISC_TIME_SECONDS_PRECISION)
# define TIME_ADD_FPSECS(value, inc) \
(*(ISC_TIME *)value) += (inc % ISC_TIME_SECONDS_PRECISION)
#ifndef NO_TRACE_MSGS
# define DBI_TRACE(level, args) \
do { \
if (DBIS->debug >= level) \
PerlIO_printf args ; \
} while (0)
# define DBI_TRACE_imp_xxh(imp_xxh, level, args) \
do { \
if (DBIc_TRACE_LEVEL(imp_xxh) >= level) \
PerlIO_printf args; \
} while (0)
#else
# define DBI_TRACE(level, args) do {} while (0)
# define DBI_TRACE_imp_xxh(imp_xxh, level, args) do {} while (0)
#endif
#define BLOB_SEGMENT (256)
#define DEFAULT_SQL_DIALECT (3)
#define INPUT_XSQLDA (1)
#define OUTPUT_XSQLDA (0)
#define PLAN_BUFFER_LEN 2048
#define SUCCESS (0)
#define FAILURE (-1)
/*
* Hardcoded limit on the length of a Blob that can be fetched into a scalar.
* If you want to fetch Blobs that are bigger, write your own Perl
*/
#define MAX_SAFE_BLOB_LENGTH (1000000)
#define MAX_EVENTS 15
typedef enum { ACTIVE, INACTIVE } IB_EVENT_STATE;
/****************/
/* data types */
/****************/
/* structs for event */
typedef struct
{
imp_dbh_t *dbh; /* pointer to parent dbh */
ISC_LONG id; /* event id assigned by IB */
#if defined(INCLUDE_TYPES_PUB_H)
ISC_UCHAR *event_buffer;
ISC_UCHAR *result_buffer;
#else
char ISC_FAR *event_buffer;
char ISC_FAR *result_buffer;
#endif
char ISC_FAR * ISC_FAR *names; /* names of events of interest */
unsigned short num; /* number of events of interest */
short epb_length; /* length of event parameter buffer */
SV *perl_cb; /* perl callback for this event */
IB_EVENT_STATE state;
char exec_cb;
} IB_EVENT;
/* Define driver handle data structure */
struct imp_drh_st
{
dbih_drc_t com; /* MUST be first element in structure */
};
/* Define dbh implementor data structure */
struct imp_dbh_st
{
dbih_dbc_t com; /* MUST be first element in structure */
isc_db_handle db;
isc_tr_handle tr;
char ISC_FAR *tpb_buffer; /* transaction parameter buffer */
unsigned short tpb_length; /* length of tpb_buffer */
unsigned short sqldialect; /* default sql dialect */
char soft_commit; /* use soft commit ? */
char *ib_charset;
bool ib_enable_utf8;
unsigned int sth_ddl; /* number of open DDL statments */
imp_sth_t *first_sth; /* pointer to first statement */
imp_sth_t *last_sth; /* pointer to last statement */
#if defined(USE_THREADS) || defined(USE_ITHREADS) || defined(MULTIPLICITY)
void *context; /* perl context for threads / multiplicity */
#endif
/* per dbh default strftime() formats */
char *dateformat;
char *timestampformat;
char *timeformat;
};
/* Define sth implementor data structure */
struct imp_sth_st
{
dbih_stc_t com; /* MUST be first element in structure */
isc_stmt_handle stmt;
XSQLDA *out_sqlda; /* for storing select-list items */
XSQLDA *in_sqlda; /* for storing placeholder values */
char *cursor_name;
long type; /* statement type */
char count_item;
int affected; /* number of affected rows */
char *dateformat;
char *timestampformat;
char *timeformat;
imp_sth_t *prev_sth; /* pointer to prev statement */
imp_sth_t *next_sth; /* pointer to next statement */
};
/* newer header file defines the struct already */
typedef struct dbd_vary
{
short vary_length;
char vary_string [1];
} DBD_VARY;
/* These defines avoid name clashes for multiple statically linked DBD's */
#define dbd_init ib_init
#define dbd_discon_all ib_discon_all
#define dbd_db_login ib_db_login
#define dbd_db_login6 ib_db_login6
#define dbd_db_do ib_db_do
#define dbd_db_commit ib_db_commit
#define dbd_db_rollback ib_db_rollback
#define dbd_db_disconnect ib_db_disconnect
#define dbd_db_destroy ib_db_destroy
#define dbd_db_STORE_attrib ib_db_STORE_attrib
#define dbd_db_FETCH_attrib ib_db_FETCH_attrib
#define dbd_st_prepare ib_st_prepare
#define dbd_st_rows ib_st_rows
#define dbd_st_execute ib_st_execute
#define dbd_st_fetch ib_st_fetch
#define dbd_st_finish ib_st_finish
#define dbd_st_destroy ib_st_destroy
#define dbd_st_blob_read ib_st_blob_read
#define dbd_st_STORE_attrib ib_st_STORE_attrib
#define dbd_st_FETCH_attrib ib_st_FETCH_attrib
#define dbd_bind_ph ib_bind_ph
void do_error _((SV *h, int rc, char *what));
void dbd_init _((dbistate_t *dbistate));
void dbd_preparse _((SV *sth, imp_sth_t *imp_sth, char *statement));
int dbd_describe _((SV *sth, imp_sth_t *imp_sth));
int dbd_db_ping (SV *dbh);
char* ib_error_decode(const ISC_STATUS *status);
int ib_error_check(SV *h, ISC_STATUS *status);
int ib_start_transaction (SV *h, imp_dbh_t *imp_dbh);
int ib_commit_transaction (SV *h, imp_dbh_t *imp_dbh);
int ib_rollback_transaction(SV *h, imp_dbh_t *imp_dbh);
long ib_rows(SV *xxh, isc_stmt_handle *h_stmt, char count_type);
void ib_cleanup_st_prepare (imp_sth_t *imp_sth);
SV* dbd_db_quote(SV* dbh, SV* str, SV* type);
/* end */
|