summaryrefslogtreecommitdiff
path: root/ext/pdo_firebird/firebird_driver.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pdo_firebird/firebird_driver.c')
-rw-r--r--ext/pdo_firebird/firebird_driver.c136
1 files changed, 68 insertions, 68 deletions
diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c
index 31432e2707..76e3eef367 100644
--- a/ext/pdo_firebird/firebird_driver.c
+++ b/ext/pdo_firebird/firebird_driver.c
@@ -38,11 +38,11 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t*, const char*, zend_long, XSQLD
void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, char const *file, zend_long line) /* {{{ */
{
#if 0
- pdo_firebird_db_handle *H = stmt ? ((pdo_firebird_stmt *)stmt->driver_data)->H
+ pdo_firebird_db_handle *H = stmt ? ((pdo_firebird_stmt *)stmt->driver_data)->H
: (pdo_firebird_db_handle *)dbh->driver_data;
#endif
pdo_error_type *const error_code = stmt ? &stmt->error_code : &dbh->error_code;
-
+
#if 0
switch (isc_sqlcode(H->isc_status)) {
@@ -68,7 +68,7 @@ void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, char const *file, zend_lo
*error_code = PDO_ERR_ALREADY_EXISTS;
break;
-
+
*error_code = PDO_ERR_NOT_IMPLEMENTED;
break;
case -313:
@@ -76,11 +76,11 @@ void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, char const *file, zend_lo
*error_code = PDO_ERR_MISMATCH;
break;
case -303:
- case -314:
+ case -314:
case -413:
*error_code = PDO_ERR_TRUNCATED;
break;
-
+
*error_code = PDO_ERR_DISCONNECTED;
break;
}
@@ -96,7 +96,7 @@ void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, char const *file, zend_lo
static int firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */
{
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
-
+
if (dbh->in_txn) {
if (dbh->auto_commit) {
if (isc_commit_transaction(H->isc_status, &H->tr)) {
@@ -108,7 +108,7 @@ static int firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */
}
}
}
-
+
if (isc_detach_database(H->isc_status, &H->db)) {
RECORD_ERROR(dbh);
}
@@ -122,7 +122,7 @@ static int firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */
if (H->timestamp_format) {
efree(H->timestamp_format);
}
-
+
pefree(H, dbh->is_persistent);
return 0;
@@ -148,12 +148,12 @@ static int firebird_handle_preparer(pdo_dbh_t *dbh, const char *sql, zend_long s
ALLOC_HASHTABLE(np);
zend_hash_init(np, 8, NULL, NULL, 0);
-
+
/* allocate and prepare statement */
if (!firebird_alloc_prepare_stmt(dbh, sql, sql_len, &num_sqlda, &s, np)) {
break;
}
-
+
/* allocate a statement handle struct of the right size (struct out_sqlda is inlined) */
S = ecalloc(1, sizeof(*S)-sizeof(XSQLDA) + XSQLDA_LENGTH(num_sqlda.sqld));
S->H = H;
@@ -168,49 +168,49 @@ static int firebird_handle_preparer(pdo_dbh_t *dbh, const char *sql, zend_long s
result)) {
break;
}
- S->statement_type = result[3];
-
+ S->statement_type = result[3];
+
/* fill the output sqlda with information about the prepared query */
if (isc_dsql_describe(H->isc_status, &s, PDO_FB_SQLDA_VERSION, &S->out_sqlda)) {
RECORD_ERROR(dbh);
break;
}
-
+
/* allocate the input descriptors */
if (isc_dsql_describe_bind(H->isc_status, &s, PDO_FB_SQLDA_VERSION, &num_sqlda)) {
break;
}
-
+
if (num_sqlda.sqld) {
S->in_sqlda = ecalloc(1,XSQLDA_LENGTH(num_sqlda.sqld));
S->in_sqlda->version = PDO_FB_SQLDA_VERSION;
S->in_sqlda->sqln = num_sqlda.sqld;
-
+
if (isc_dsql_describe_bind(H->isc_status, &s, PDO_FB_SQLDA_VERSION, S->in_sqlda)) {
break;
}
}
-
+
stmt->driver_data = S;
stmt->methods = &firebird_stmt_methods;
stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL;
-
+
return 1;
} while (0);
RECORD_ERROR(dbh);
-
+
zend_hash_destroy(np);
FREE_HASHTABLE(np);
-
+
if (S) {
if (S->in_sqlda) {
efree(S->in_sqlda);
}
efree(S);
}
-
+
return 0;
}
/* }}} */
@@ -224,12 +224,12 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long
char result[64];
int ret = 0;
XSQLDA in_sqlda, out_sqlda;
-
+
/* TODO no placeholders in exec() for now */
in_sqlda.version = out_sqlda.version = PDO_FB_SQLDA_VERSION;
in_sqlda.sqld = out_sqlda.sqld = 0;
out_sqlda.sqln = 1;
-
+
/* allocate and prepare statement */
if (!firebird_alloc_prepare_stmt(dbh, sql, sql_len, &out_sqlda, &stmt, 0)) {
return -1;
@@ -240,7 +240,7 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long
RECORD_ERROR(dbh);
return -1;
}
-
+
/* find out how many rows were affected */
if (isc_dsql_sql_info(H->isc_status, &stmt, sizeof(info_count), const_cast(info_count),
sizeof(result), result)) {
@@ -259,7 +259,7 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const char *sql, zend_long
i += len+3;
}
}
-
+
/* commit if we're in auto_commit mode */
if (dbh->auto_commit && isc_commit_retaining(H->isc_status, &H->tr)) {
RECORD_ERROR(dbh);
@@ -276,35 +276,35 @@ static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unqu
int qcount = 0;
char const *co, *l, *r;
char *c;
-
+
if (!unquotedlen) {
*quotedlen = 2;
*quoted = emalloc(*quotedlen+1);
strcpy(*quoted, "''");
return 1;
}
-
+
/* Firebird only requires single quotes to be doubled if string lengths are used */
/* count the number of ' characters */
for (co = unquoted; (co = strchr(co,'\'')); qcount++, co++);
-
+
*quotedlen = unquotedlen + qcount + 2;
- *quoted = c = emalloc(*quotedlen+1);
+ *quoted = c = emalloc(*quotedlen+1);
*c++ = '\'';
-
+
/* foreach (chunk that ends in a quote) */
- for (l = unquoted; (r = strchr(l,'\'')); l = r+1) {
+ for (l = unquoted; (r = strchr(l,'\'')); l = r+1) {
strncpy(c, l, r-l+1);
- c += (r-l+1);
+ c += (r-l+1);
/* add the second quote */
*c++ = '\'';
}
-
+
/* copy the remainder */
strncpy(c, l, *quotedlen-(c-*quoted)-1);
- (*quoted)[*quotedlen-1] = '\'';
+ (*quoted)[*quotedlen-1] = '\'';
(*quoted)[*quotedlen] = '\0';
-
+
return 1;
}
/* }}} */
@@ -314,7 +314,7 @@ static int firebird_handle_begin(pdo_dbh_t *dbh) /* {{{ */
{
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
char tpb[8] = { isc_tpb_version3 }, *ptpb = tpb+1;
-#if abies_0
+#if abies_0
if (dbh->transaction_flags & PDO_TRANS_ISOLATION_LEVEL) {
if (dbh->transaction_flags & PDO_TRANS_READ_UNCOMMITTED) {
/* this is a poor fit, but it's all we have */
@@ -333,7 +333,7 @@ static int firebird_handle_begin(pdo_dbh_t *dbh) /* {{{ */
dbh->transaction_flags &= ~(PDO_TRANS_ISOLATION_LEVEL^PDO_TRANS_SERIALIZABLE);
}
}
-
+
if (dbh->transaction_flags & PDO_TRANS_ACCESS_MODE) {
if (dbh->transaction_flags & PDO_TRANS_READONLY) {
*ptpb++ = isc_tpb_read;
@@ -395,13 +395,13 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, zend_lon
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
char *c, *new_sql, in_quote, in_param, pname[64], *ppname;
zend_long l, pindex = -1;
-
+
/* Firebird allows SQL statements up to 64k, so bail if it doesn't fit */
if (sql_len > 65536) {
strcpy(dbh->error_code, "01004");
return 0;
}
-
+
/* start a new transaction implicitly if auto_commit is enabled and no transaction is open */
if (dbh->auto_commit && !dbh->in_txn) {
/* dbh->transaction_flags = PDO_TRANS_READ_UNCOMMITTED; */
@@ -411,17 +411,17 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, zend_lon
}
dbh->in_txn = 1;
}
-
+
/* allocate the statement */
if (isc_dsql_allocate_statement(H->isc_status, &H->db, s)) {
RECORD_ERROR(dbh);
return 0;
}
-
- /* in order to support named params, which Firebird itself doesn't,
+
+ /* in order to support named params, which Firebird itself doesn't,
we need to replace :foo by ?, and store the name we just replaced */
new_sql = c = emalloc(sql_len+1);
-
+
for (l = in_quote = in_param = 0; l <= sql_len; ++l) {
if ( !(in_quote ^= (sql[l] == '\''))) {
if (!in_param) {
@@ -437,9 +437,9 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, zend_lon
}
} else {
if ((in_param &= ((sql[l] >= 'A' && sql[l] <= 'Z') || (sql[l] >= 'a' && sql[l] <= 'z')
- || (sql[l] >= '0' && sql[l] <= '9') || sql[l] == '_' || sql[l] == '-'))) {
+ || (sql[l] >= '0' && sql[l] <= '9') || sql[l] == '_' || sql[l] == '-'))) {
+
-
*ppname++ = sql[l];
continue;
} else {
@@ -461,12 +461,12 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, zend_lon
efree(new_sql);
return 0;
}
-
+
efree(new_sql);
return 1;
}
/* }}} */
-
+
/* called by PDO to set a driver-specific dbh attribute */
static int firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */
{
@@ -476,8 +476,8 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v
case PDO_ATTR_AUTOCOMMIT:
convert_to_boolean(val);
-
- /* ignore if the new value equals the old one */
+
+ /* ignore if the new value equals the old one */
if (dbh->auto_commit ^ (Z_TYPE_P(val) == IS_TRUE? 1 : 0)) {
if (dbh->in_txn) {
if (Z_TYPE_P(val) == IS_TRUE) {
@@ -507,7 +507,7 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v
if (H->date_format) {
efree(H->date_format);
}
- spprintf(&H->date_format, 0, "%s", Z_STRVAL_P(val));
+ spprintf(&H->date_format, 0, "%s", Z_STRVAL_P(val));
return 1;
case PDO_FB_ATTR_TIME_FORMAT:
@@ -515,7 +515,7 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v
if (H->time_format) {
efree(H->time_format);
}
- spprintf(&H->time_format, 0, "%s", Z_STRVAL_P(val));
+ spprintf(&H->time_format, 0, "%s", Z_STRVAL_P(val));
return 1;
case PDO_FB_ATTR_TIMESTAMP_FORMAT:
@@ -523,7 +523,7 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v
if (H->timestamp_format) {
efree(H->timestamp_format);
}
- spprintf(&H->timestamp_format, 0, "%s", Z_STRVAL_P(val));
+ spprintf(&H->timestamp_format, 0, "%s", Z_STRVAL_P(val));
return 1;
}
return 0;
@@ -549,7 +549,7 @@ static int firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v
switch (attr) {
char tmp[512];
-
+
case PDO_ATTR_AUTOCOMMIT:
ZVAL_LONG(val,dbh->auto_commit);
return 1;
@@ -574,33 +574,33 @@ static int firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v
if (info_func) {
info_func(tmp);
ZVAL_STRING(val, tmp);
- }
+ }
#else
ZVAL_NULL(val);
#endif
}
return 1;
-
+
case PDO_ATTR_SERVER_VERSION:
case PDO_ATTR_SERVER_INFO:
*tmp = 0;
-
+
if (!isc_version(&H->db, firebird_info_cb, (void*)tmp)) {
ZVAL_STRING(val, tmp);
return 1;
}
-
+
case PDO_ATTR_FETCH_TABLE_NAMES:
ZVAL_BOOL(val, H->fetch_table_names);
return 1;
}
return 0;
-}
+}
/* }}} */
-
+
/* called by PDO to retrieve driver-specific information about an error that has occurred */
static int pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
-{
+{
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
const ISC_STATUS *s = H->isc_status;
char buf[400];
@@ -652,14 +652,14 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /*
pdo_firebird_db_handle *H = dbh->driver_data = pecalloc(1,sizeof(*H),dbh->is_persistent);
php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, 3);
-
+
do {
- static char const dpb_flags[] = {
+ static char const dpb_flags[] = {
isc_dpb_user_name, isc_dpb_password, isc_dpb_lc_ctype, isc_dpb_sql_role_name };
char const *dpb_values[] = { dbh->username, dbh->password, vars[1].optval, vars[2].optval };
char dpb_buffer[256] = { isc_dpb_version1 }, *dpb;
-
- dpb = dpb_buffer + 1;
+
+ dpb = dpb_buffer + 1;
/* loop through all the provided arguments and set dpb fields accordingly */
for (i = 0; i < sizeof(dpb_flags); ++i) {
@@ -670,20 +670,20 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options) /*
buf_len -= dpb_len;
}
}
-
+
/* fire it up baby! */
if (isc_attach_database(H->isc_status, 0, vars[0].optval, &H->db,(short)(dpb-dpb_buffer), dpb_buffer)) {
break;
}
-
+
dbh->methods = &firebird_methods;
dbh->native_case = PDO_CASE_UPPER;
dbh->alloc_own_columns = 1;
-
+
ret = 1;
-
+
} while (0);
-
+
for (i = 0; i < sizeof(vars)/sizeof(vars[0]); ++i) {
if (vars[i].freeme) {
efree(vars[i].optval);