diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c index 00398a7116127..bb9eb29ee9166 100644 --- a/ext/pdo_firebird/firebird_driver.c +++ b/ext/pdo_firebird/firebird_driver.c @@ -31,7 +31,7 @@ #include "php_pdo_firebird.h" #include "php_pdo_firebird_int.h" -static int firebird_alloc_prepare_stmt(pdo_dbh_t*, const zend_string*, XSQLDA*, isc_stmt_handle*, +static int php_firebird_alloc_prepare_stmt(pdo_dbh_t*, const zend_string*, XSQLDA*, isc_stmt_handle*, HashTable*); const char CHR_LETTER = 1; @@ -173,7 +173,7 @@ static const char classes_array[] = { /* 127 */ 0 }; -static inline char classes(char idx) +static inline char php_firebird_classes(char idx) { unsigned char uidx = (unsigned char) idx; if (uidx > 127) return 0; @@ -191,7 +191,7 @@ typedef enum { ttOther } FbTokenType; -static FbTokenType getToken(const char** begin, const char* end) +static FbTokenType php_firebird_get_token(const char** begin, const char* end) { FbTokenType ret = ttNone; const char* p = *begin; @@ -259,27 +259,27 @@ static FbTokenType getToken(const char** begin, const char* end) break; default: - if (classes(c) & CHR_DIGIT) + if (php_firebird_classes(c) & CHR_DIGIT) { - while (p < end && (classes(*p) & CHR_DIGIT)) + while (p < end && (php_firebird_classes(*p) & CHR_DIGIT)) p++; ret = ttOther; } - else if (classes(c) & CHR_IDENT) + else if (php_firebird_classes(c) & CHR_IDENT) { - while (p < end && (classes(*p) & CHR_IDENT)) + while (p < end && (php_firebird_classes(*p) & CHR_IDENT)) p++; ret = ttIdent; } - else if (classes(c) & CHR_WHITE) + else if (php_firebird_classes(c) & CHR_WHITE) { - while (p < end && (classes(*p) & CHR_WHITE)) + while (p < end && (php_firebird_classes(*p) & CHR_WHITE)) p++; ret = ttWhite; } else { - while (p < end && !(classes(*p) & (CHR_DIGIT | CHR_IDENT | CHR_WHITE)) && + while (p < end && !(php_firebird_classes(*p) & (CHR_DIGIT | CHR_IDENT | CHR_WHITE)) && (*p != '/') && (*p != '-') && (*p != ':') && (*p != '?') && (*p != '\'') && (*p != '"')) { @@ -293,7 +293,7 @@ static FbTokenType getToken(const char** begin, const char* end) return ret; } -int preprocess(const zend_string* sql, char* sql_out, HashTable* named_params) +static int php_firebird_preprocess(const zend_string* sql, char* sql_out, HashTable* named_params) { bool passAsIs = 1, execBlock = 0; zend_long pindex = -1; @@ -301,13 +301,13 @@ int preprocess(const zend_string* sql, char* sql_out, HashTable* named_params) unsigned int l; const char* p = ZSTR_VAL(sql), * end = ZSTR_VAL(sql) + ZSTR_LEN(sql); const char* start = p; - FbTokenType tok = getToken(&p, end); + FbTokenType tok = php_firebird_get_token(&p, end); const char* i = start; while (p < end && (tok == ttComment || tok == ttWhite)) { i = p; - tok = getToken(&p, end); + tok = php_firebird_get_token(&p, end); } if (p >= end || tok != ttIdent) @@ -331,11 +331,11 @@ int preprocess(const zend_string* sql, char* sql_out, HashTable* named_params) /* For EXECUTE PROCEDURE and EXECUTE BLOCK statements, named parameters must be processed. */ /* However, in EXECUTE BLOCK this is done in a special way. */ const char* i2 = p; - tok = getToken(&p, end); + tok = php_firebird_get_token(&p, end); while (p < end && (tok == ttComment || tok == ttWhite)) { i2 = p; - tok = getToken(&p, end); + tok = php_firebird_get_token(&p, end); } if (p >= end || tok != ttIdent) { @@ -374,11 +374,11 @@ int preprocess(const zend_string* sql, char* sql_out, HashTable* named_params) while (p < end) { start = p; - tok = getToken(&p, end); + tok = php_firebird_get_token(&p, end); switch (tok) { case ttParamMark: - tok = getToken(&p, end); + tok = php_firebird_get_token(&p, end); if (tok == ttIdent /*|| tok == ttString*/) { ++pindex; @@ -460,7 +460,7 @@ int preprocess(const zend_string* sql, char* sql_out, HashTable* named_params) } /* map driver specific error message to PDO error */ -void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *state, const size_t state_len, +void php_firebird_set_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *state, const size_t state_len, const char *msg, const size_t msg_len) /* {{{ */ { pdo_error_type *const error_code = stmt ? &stmt->error_code : &dbh->error_code; @@ -529,17 +529,17 @@ static void firebird_handle_closer(pdo_dbh_t *dbh) /* {{{ */ if (dbh->in_txn) { if (dbh->auto_commit) { if (isc_commit_transaction(H->isc_status, &H->tr)) { - firebird_error(dbh); + php_firebird_error(dbh); } } else { if (isc_rollback_transaction(H->isc_status, &H->tr)) { - firebird_error(dbh); + php_firebird_error(dbh); } } } if (isc_detach_database(H->isc_status, &H->db)) { - firebird_error(dbh); + php_firebird_error(dbh); } if (H->date_format) { @@ -582,7 +582,7 @@ static bool firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */ zend_hash_init(np, 8, NULL, NULL, 0); /* allocate and prepare statement */ - if (!firebird_alloc_prepare_stmt(dbh, sql, &num_sqlda, &s, np)) { + if (!php_firebird_alloc_prepare_stmt(dbh, sql, &num_sqlda, &s, np)) { break; } @@ -603,7 +603,7 @@ static bool firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */ /* 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)) { - firebird_error(dbh); + php_firebird_error(dbh); break; } @@ -630,7 +630,7 @@ static bool firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */ } while (0); - firebird_error(dbh); + php_firebird_error(dbh); zend_hash_destroy(np); FREE_HASHTABLE(np); @@ -662,13 +662,13 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const zend_string *sql) /* out_sqlda.sqln = 1; /* allocate and prepare statement */ - if (!firebird_alloc_prepare_stmt(dbh, sql, &out_sqlda, &stmt, 0)) { + if (!php_firebird_alloc_prepare_stmt(dbh, sql, &out_sqlda, &stmt, 0)) { return -1; } /* execute the statement */ if (isc_dsql_execute2(H->isc_status, &H->tr, &stmt, PDO_FB_SQLDA_VERSION, &in_sqlda, &out_sqlda)) { - firebird_error(dbh); + php_firebird_error(dbh); ret = -1; goto free_statement; } @@ -676,7 +676,7 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const zend_string *sql) /* /* 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)) { - firebird_error(dbh); + php_firebird_error(dbh); ret = -1; goto free_statement; } @@ -704,13 +704,13 @@ static zend_long firebird_handle_doer(pdo_dbh_t *dbh, const zend_string *sql) /* /* commit if we're in auto_commit mode */ if (dbh->auto_commit && isc_commit_retaining(H->isc_status, &H->tr)) { - firebird_error(dbh); + php_firebird_error(dbh); } free_statement: if (isc_dsql_free_statement(H->isc_status, &stmt, DSQL_drop)) { - firebird_error(dbh); + php_firebird_error(dbh); } return ret; @@ -802,7 +802,7 @@ static bool firebird_handle_begin(pdo_dbh_t *dbh) /* {{{ */ } #endif if (isc_start_transaction(H->isc_status, &H->tr, 1, &H->db, (unsigned short)(ptpb-tpb), tpb)) { - firebird_error(dbh); + php_firebird_error(dbh); return false; } return true; @@ -815,7 +815,7 @@ static bool firebird_handle_commit(pdo_dbh_t *dbh) /* {{{ */ pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; if (isc_commit_transaction(H->isc_status, &H->tr)) { - firebird_error(dbh); + php_firebird_error(dbh); return false; } return true; @@ -828,7 +828,7 @@ static bool firebird_handle_rollback(pdo_dbh_t *dbh) /* {{{ */ pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; if (isc_rollback_transaction(H->isc_status, &H->tr)) { - firebird_error(dbh); + php_firebird_error(dbh); return false; } return true; @@ -836,7 +836,7 @@ static bool firebird_handle_rollback(pdo_dbh_t *dbh) /* {{{ */ /* }}} */ /* used by prepare and exec to allocate a statement handle and prepare the SQL */ -static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const zend_string *sql, +static int php_firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const zend_string *sql, XSQLDA *out_sqlda, isc_stmt_handle *s, HashTable *named_params) { pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; @@ -844,7 +844,7 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const zend_string *sql, /* Firebird allows SQL statements up to 64k, so bail if it doesn't fit */ if (ZSTR_LEN(sql) > 65536) { - strcpy(dbh->error_code, "01004"); + php_firebird_error_with_info(dbh, "01004", strlen("01004"), NULL, 0); return 0; } @@ -860,7 +860,7 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const zend_string *sql, /* allocate the statement */ if (isc_dsql_allocate_statement(H->isc_status, &H->db, s)) { - firebird_error(dbh); + php_firebird_error(dbh); return 0; } @@ -868,15 +868,15 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const zend_string *sql, we need to replace :foo by ?, and store the name we just replaced */ new_sql = emalloc(ZSTR_LEN(sql)+1); new_sql[0] = '\0'; - if (!preprocess(sql, new_sql, named_params)) { - strcpy(dbh->error_code, "07000"); + if (!php_firebird_preprocess(sql, new_sql, named_params)) { + php_firebird_error_with_info(dbh, "07000", strlen("07000"), NULL, 0); efree(new_sql); return 0; } /* prepare the statement */ if (isc_dsql_prepare(H->isc_status, &H->tr, s, 0, new_sql, H->sql_dialect, out_sqlda)) { - firebird_error(dbh); + php_firebird_error(dbh); efree(new_sql); return 0; } @@ -886,7 +886,7 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const zend_string *sql, } /* called by PDO to set a driver-specific dbh attribute */ -static bool firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */ +static bool pdo_firebird_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */ { pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; bool bval; @@ -905,7 +905,7 @@ static bool firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval * /* turning on auto_commit with an open transaction is illegal, because we won't know what to do with it */ const char *msg = "Cannot enable auto-commit while a transaction is already open"; - firebird_error_with_info(dbh, "HY000", strlen("HY000"), msg, strlen(msg)); + php_firebird_error_with_info(dbh, "HY000", strlen("HY000"), msg, strlen(msg)); return false; } else { /* close the transaction */ @@ -976,7 +976,7 @@ static bool firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval * #define INFO_BUF_LEN 512 /* callback to used to report database server info */ -static void firebird_info_cb(void *arg, char const *s) /* {{{ */ +static void php_firebird_info_cb(void *arg, char const *s) /* {{{ */ { if (arg) { if (*(char*)arg) { /* second call */ @@ -988,7 +988,7 @@ static void firebird_info_cb(void *arg, char const *s) /* {{{ */ /* }}} */ /* called by PDO to get a driver-specific dbh attribute */ -static int firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */ +static int pdo_firebird_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */ { pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; @@ -1000,7 +1000,7 @@ static int firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v return 1; case PDO_ATTR_CONNECTION_STATUS: - ZVAL_BOOL(val, !isc_version(&H->db, firebird_info_cb, NULL)); + ZVAL_BOOL(val, !isc_version(&H->db, php_firebird_info_cb, NULL)); return 1; case PDO_ATTR_CLIENT_VERSION: { @@ -1030,7 +1030,7 @@ static int firebird_handle_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v case PDO_ATTR_SERVER_INFO: *tmp = 0; - if (!isc_version(&H->db, firebird_info_cb, (void*)tmp)) { + if (!isc_version(&H->db, php_firebird_info_cb, (void*)tmp)) { ZVAL_STRING(val, tmp); return 1; } @@ -1066,10 +1066,10 @@ static const struct pdo_dbh_methods firebird_methods = { /* {{{ */ firebird_handle_begin, firebird_handle_commit, firebird_handle_rollback, - firebird_handle_set_attribute, + pdo_firebird_set_attribute, NULL, /* last_id not supported */ pdo_firebird_fetch_error_func, - firebird_handle_get_attribute, + pdo_firebird_get_attribute, NULL, /* check_liveness */ NULL, /* get driver methods */ NULL, /* request shutdown */ diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c index 686ab0c3d1793..bc973171b2f61 100644 --- a/ext/pdo_firebird/firebird_statement.c +++ b/ext/pdo_firebird/firebird_statement.c @@ -34,38 +34,38 @@ return ret; \ } while (0); -static zend_always_inline ISC_INT64 get_isc_int64_from_sqldata(const ISC_SCHAR *sqldata) +static zend_always_inline ISC_INT64 php_get_isc_int64_from_sqldata(const ISC_SCHAR *sqldata) { READ_AND_RETURN_USING_MEMCPY(ISC_INT64, sqldata); } -static zend_always_inline ISC_LONG get_isc_long_from_sqldata(const ISC_SCHAR *sqldata) +static zend_always_inline ISC_LONG php_get_isc_long_from_sqldata(const ISC_SCHAR *sqldata) { READ_AND_RETURN_USING_MEMCPY(ISC_LONG, sqldata); } -static zend_always_inline double get_double_from_sqldata(const ISC_SCHAR *sqldata) +static zend_always_inline double php_get_double_from_sqldata(const ISC_SCHAR *sqldata) { READ_AND_RETURN_USING_MEMCPY(double, sqldata); } -static zend_always_inline float get_float_from_sqldata(const ISC_SCHAR *sqldata) +static zend_always_inline float php_get_float_from_sqldata(const ISC_SCHAR *sqldata) { READ_AND_RETURN_USING_MEMCPY(float, sqldata); } -static zend_always_inline ISC_TIMESTAMP get_isc_timestamp_from_sqldata(const ISC_SCHAR *sqldata) +static zend_always_inline ISC_TIMESTAMP php_get_isc_timestamp_from_sqldata(const ISC_SCHAR *sqldata) { READ_AND_RETURN_USING_MEMCPY(ISC_TIMESTAMP, sqldata); } -static zend_always_inline ISC_QUAD get_isc_quad_from_sqldata(const ISC_SCHAR *sqldata) +static zend_always_inline ISC_QUAD php_get_isc_quad_from_sqldata(const ISC_SCHAR *sqldata) { READ_AND_RETURN_USING_MEMCPY(ISC_QUAD, sqldata); } /* free the allocated space for passing field values to the db and back */ -static void free_sqlda(XSQLDA const *sqlda) /* {{{ */ +static void php_firebird_free_sqlda(XSQLDA const *sqlda) /* {{{ */ { int i; @@ -80,14 +80,14 @@ static void free_sqlda(XSQLDA const *sqlda) /* {{{ */ /* }}} */ /* called by PDO to clean up a statement handle */ -static int firebird_stmt_dtor(pdo_stmt_t *stmt) /* {{{ */ +static int pdo_firebird_stmt_dtor(pdo_stmt_t *stmt) /* {{{ */ { pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data; int result = 1; /* release the statement */ if (isc_dsql_free_statement(S->H->isc_status, &S->stmt, DSQL_drop)) { - firebird_error_stmt(stmt); + php_firebird_error_stmt(stmt); result = 0; } @@ -96,11 +96,11 @@ static int firebird_stmt_dtor(pdo_stmt_t *stmt) /* {{{ */ /* clean up the input descriptor */ if (S->in_sqlda) { - free_sqlda(S->in_sqlda); + php_firebird_free_sqlda(S->in_sqlda); efree(S->in_sqlda); } - free_sqlda(&S->out_sqlda); + php_firebird_free_sqlda(&S->out_sqlda); efree(S); return result; @@ -108,7 +108,7 @@ static int firebird_stmt_dtor(pdo_stmt_t *stmt) /* {{{ */ /* }}} */ /* called by PDO to execute a prepared query */ -static int firebird_stmt_execute(pdo_stmt_t *stmt) /* {{{ */ +static int pdo_firebird_stmt_execute(pdo_stmt_t *stmt) /* {{{ */ { pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data; pdo_firebird_db_handle *H = S->H; @@ -193,14 +193,14 @@ static int firebird_stmt_execute(pdo_stmt_t *stmt) /* {{{ */ } while (0); error: - firebird_error_stmt(stmt); + php_firebird_error_stmt(stmt); return 0; } /* }}} */ /* called by PDO to fetch the next row from a statement */ -static int firebird_stmt_fetch(pdo_stmt_t *stmt, /* {{{ */ +static int pdo_firebird_stmt_fetch(pdo_stmt_t *stmt, /* {{{ */ enum pdo_fetch_orientation ori, zend_long offset) { pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data; @@ -208,7 +208,7 @@ static int firebird_stmt_fetch(pdo_stmt_t *stmt, /* {{{ */ if (!stmt->executed) { const char *msg = "Cannot fetch from a closed cursor"; - firebird_error_stmt_with_info(stmt, "HY000", strlen("HY000"), msg, strlen(msg)); + php_firebird_error_stmt_with_info(stmt, "HY000", strlen("HY000"), msg, strlen(msg)); } else if (!S->exhausted) { if (S->statement_type == isc_info_sql_stmt_exec_procedure) { stmt->row_count = 1; @@ -217,7 +217,7 @@ static int firebird_stmt_fetch(pdo_stmt_t *stmt, /* {{{ */ } if (isc_dsql_fetch(H->isc_status, &S->stmt, PDO_FB_SQLDA_VERSION, &S->out_sqlda)) { if (H->isc_status[0] && H->isc_status[1]) { - firebird_error_stmt(stmt); + php_firebird_error_stmt(stmt); } S->exhausted = 1; return 0; @@ -230,7 +230,7 @@ static int firebird_stmt_fetch(pdo_stmt_t *stmt, /* {{{ */ /* }}} */ /* called by PDO to retrieve information about the fields being returned */ -static int firebird_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */ +static int pdo_firebird_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */ { pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data; struct pdo_column_data *col = &stmt->columns[colno]; @@ -260,7 +260,7 @@ static int firebird_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */ } /* }}} */ -static int firebird_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_value) +static int pdo_firebird_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_value) { pdo_firebird_stmt *S = (pdo_firebird_stmt *) stmt->driver_data; XSQLVAR *var = &S->out_sqlda.sqlvar[colno]; @@ -294,7 +294,7 @@ static int firebird_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zval } /* fetch a blob into a fetch buffer */ -static int firebird_fetch_blob(pdo_stmt_t *stmt, int colno, zval *result, ISC_QUAD *blob_id) +static int php_firebird_fetch_blob(pdo_stmt_t *stmt, int colno, zval *result, ISC_QUAD *blob_id) { pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data; pdo_firebird_db_handle *H = S->H; @@ -306,13 +306,13 @@ static int firebird_fetch_blob(pdo_stmt_t *stmt, int colno, zval *result, ISC_QU size_t len = 0; if (isc_open_blob(H->isc_status, &H->db, &H->tr, &blobh, blob_id)) { - firebird_error_stmt(stmt); + php_firebird_error_stmt(stmt); return 0; } if (isc_blob_info(H->isc_status, &blobh, 1, const_cast(&bl_item), sizeof(bl_info), bl_info)) { - firebird_error_stmt(stmt); + php_firebird_error_stmt(stmt); goto fetch_blob_end; } @@ -324,7 +324,7 @@ static int firebird_fetch_blob(pdo_stmt_t *stmt, int colno, zval *result, ISC_QU if (item == isc_info_end || item == isc_info_truncated || item == isc_info_error || i >= sizeof(bl_info)) { const char *msg = "Couldn't determine BLOB size"; - firebird_error_stmt_with_info(stmt, "HY000", strlen("HY000"), msg, strlen(msg)); + php_firebird_error_stmt_with_info(stmt, "HY000", strlen("HY000"), msg, strlen(msg)); goto fetch_blob_end; } @@ -366,7 +366,7 @@ static int firebird_fetch_blob(pdo_stmt_t *stmt, int colno, zval *result, ISC_QU if (H->isc_status[0] == 1 && (stat != 0 && stat != isc_segstr_eof && stat != isc_segment)) { const char *msg = "Error reading from BLOB"; - firebird_error_stmt_with_info(stmt, "HY000", strlen("HY000"), msg, strlen(msg)); + php_firebird_error_stmt_with_info(stmt, "HY000", strlen("HY000"), msg, strlen(msg)); goto fetch_blob_end; } } @@ -374,14 +374,14 @@ static int firebird_fetch_blob(pdo_stmt_t *stmt, int colno, zval *result, ISC_QU fetch_blob_end: if (isc_close_blob(H->isc_status, &blobh)) { - firebird_error_stmt(stmt); + php_firebird_error_stmt(stmt); return 0; } return retval; } /* }}} */ -static int firebird_stmt_get_col( +static int pdo_firebird_stmt_get_col( pdo_stmt_t *stmt, int colno, zval *result, enum pdo_param_type *type) { pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data; @@ -416,10 +416,10 @@ static int firebird_stmt_get_col( n = *(short*)var->sqldata; break; case SQL_LONG: - n = get_isc_long_from_sqldata(var->sqldata); + n = php_get_isc_long_from_sqldata(var->sqldata); break; case SQL_INT64: - n = get_isc_int64_from_sqldata(var->sqldata); + n = php_get_isc_int64_from_sqldata(var->sqldata); break; case SQL_DOUBLE: break; @@ -427,7 +427,7 @@ static int firebird_stmt_get_col( } if ((var->sqltype & ~1) == SQL_DOUBLE) { - str = zend_strpprintf(0, "%.*F", -var->sqlscale, get_double_from_sqldata(var->sqldata)); + str = zend_strpprintf(0, "%.*F", -var->sqlscale, php_get_double_from_sqldata(var->sqldata)); } else if (n >= 0) { str = zend_strpprintf(0, "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -var->sqlscale, n % f); @@ -453,22 +453,22 @@ static int firebird_stmt_get_col( ZVAL_LONG(result, *(short*)var->sqldata); break; case SQL_LONG: - ZVAL_LONG(result, get_isc_long_from_sqldata(var->sqldata)); + ZVAL_LONG(result, php_get_isc_long_from_sqldata(var->sqldata)); break; case SQL_INT64: #if SIZEOF_ZEND_LONG >= 8 - ZVAL_LONG(result, get_isc_int64_from_sqldata(var->sqldata)); + ZVAL_LONG(result, php_get_isc_int64_from_sqldata(var->sqldata)); #else - ZVAL_STR(result, zend_strpprintf(0, "%" LL_MASK "d", get_isc_int64_from_sqldata(var->sqldata))); + ZVAL_STR(result, zend_strpprintf(0, "%" LL_MASK "d", php_get_isc_int64_from_sqldata(var->sqldata))); #endif break; case SQL_FLOAT: /* TODO: Why is this not returned as the native type? */ - ZVAL_STR(result, zend_strpprintf(0, "%F", get_float_from_sqldata(var->sqldata))); + ZVAL_STR(result, zend_strpprintf(0, "%F", php_get_float_from_sqldata(var->sqldata))); break; case SQL_DOUBLE: /* TODO: Why is this not returned as the native type? */ - ZVAL_STR(result, zend_strpprintf(0, "%F", get_double_from_sqldata(var->sqldata))); + ZVAL_STR(result, zend_strpprintf(0, "%F", php_get_double_from_sqldata(var->sqldata))); break; #ifdef SQL_BOOLEAN case SQL_BOOLEAN: @@ -485,7 +485,7 @@ static int firebird_stmt_get_col( } else if (0) { case SQL_TIMESTAMP: { - ISC_TIMESTAMP timestamp = get_isc_timestamp_from_sqldata(var->sqldata); + ISC_TIMESTAMP timestamp = php_get_isc_timestamp_from_sqldata(var->sqldata); isc_decode_timestamp(×tamp, &t); } fmt = S->H->timestamp_format ? S->H->timestamp_format : PDO_FB_DEF_TIMESTAMP_FMT; @@ -496,8 +496,8 @@ static int firebird_stmt_get_col( ZVAL_STRINGL(result, buf, len); break; case SQL_BLOB: { - ISC_QUAD quad = get_isc_quad_from_sqldata(var->sqldata); - return firebird_fetch_blob(stmt, colno, result, &quad); + ISC_QUAD quad = php_get_isc_quad_from_sqldata(var->sqldata); + return php_firebird_fetch_blob(stmt, colno, result, &quad); } } } @@ -505,7 +505,7 @@ static int firebird_stmt_get_col( return 1; } -static int firebird_bind_blob(pdo_stmt_t *stmt, ISC_QUAD *blob_id, zval *param) +static int php_firebird_bind_blob(pdo_stmt_t *stmt, ISC_QUAD *blob_id, zval *param) { pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data; pdo_firebird_db_handle *H = S->H; @@ -516,7 +516,7 @@ static int firebird_bind_blob(pdo_stmt_t *stmt, ISC_QUAD *blob_id, zval *param) int result = 1; if (isc_create_blob(H->isc_status, &H->db, &H->tr, &h, blob_id)) { - firebird_error_stmt(stmt); + php_firebird_error_stmt(stmt); return 0; } @@ -529,7 +529,7 @@ static int firebird_bind_blob(pdo_stmt_t *stmt, ISC_QUAD *blob_id, zval *param) for (rem_cnt = Z_STRLEN(data); rem_cnt > 0; rem_cnt -= chunk_size) { chunk_size = rem_cnt > USHRT_MAX ? USHRT_MAX : (unsigned short)rem_cnt; if (isc_put_segment(H->isc_status, &h, chunk_size, &Z_STRVAL(data)[put_cnt])) { - firebird_error_stmt(stmt); + php_firebird_error_stmt(stmt); result = 0; break; } @@ -541,13 +541,13 @@ static int firebird_bind_blob(pdo_stmt_t *stmt, ISC_QUAD *blob_id, zval *param) } if (isc_close_blob(H->isc_status, &h)) { - firebird_error_stmt(stmt); + php_firebird_error_stmt(stmt); return 0; } return result; } -static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, /* {{{ */ +static int pdo_firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, /* {{{ */ enum pdo_param_event event_type) { pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data; @@ -560,7 +560,7 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat if (!sqlda || param->paramno >= sqlda->sqld) { const char *msg = "Invalid parameter index"; - firebird_error_stmt_with_info(stmt, "HY093", strlen("HY093"), msg, strlen(msg)); + php_firebird_error_stmt_with_info(stmt, "HY093", strlen("HY093"), msg, strlen(msg)); return 0; } if (param->is_param && param->paramno == -1) { @@ -586,7 +586,7 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat } if (i >= sqlda->sqld) { const char *msg = "Invalid parameter name"; - firebird_error_stmt_with_info(stmt, "HY093", strlen("HY093"), msg, strlen(msg)); + php_firebird_error_stmt_with_info(stmt, "HY093", strlen("HY093"), msg, strlen(msg)); return 0; } } @@ -638,7 +638,7 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat case SQL_ARRAY: { const char *msg = "Cannot bind to array field"; - firebird_error_stmt_with_info(stmt, "HY000", strlen("HY000"), msg, strlen(msg)); + php_firebird_error_stmt_with_info(stmt, "HY000", strlen("HY000"), msg, strlen(msg)); } return 0; @@ -647,14 +647,14 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat /* Check if field allow NULL values */ if (~var->sqltype & 1) { const char *msg = "Parameter requires non-null value"; - firebird_error_stmt_with_info(stmt, "HY105", strlen("HY105"), msg, strlen(msg)); + php_firebird_error_stmt_with_info(stmt, "HY105", strlen("HY105"), msg, strlen(msg)); return 0; } *var->sqlind = -1; return 1; } - ISC_QUAD quad = get_isc_quad_from_sqldata(var->sqldata); - if (firebird_bind_blob(stmt, &quad, parameter) != 0) { + ISC_QUAD quad = php_get_isc_quad_from_sqldata(var->sqldata); + if (php_firebird_bind_blob(stmt, &quad, parameter) != 0) { memcpy(var->sqldata, &quad, sizeof(quad)); return 1; } @@ -696,7 +696,7 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat *(FB_BOOLEAN*)var->sqldata = FB_FALSE; } else { const char *msg = "Cannot convert string to boolean"; - firebird_error_stmt_with_info(stmt, "HY105", strlen("HY105"), msg, strlen(msg)); + php_firebird_error_stmt_with_info(stmt, "HY105", strlen("HY105"), msg, strlen(msg)); return 0; } @@ -709,7 +709,7 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat default: { const char *msg = "Binding arrays/objects is not supported"; - firebird_error_stmt_with_info(stmt, "HY105", strlen("HY105"), msg, strlen(msg)); + php_firebird_error_stmt_with_info(stmt, "HY105", strlen("HY105"), msg, strlen(msg)); } return 0; } @@ -761,7 +761,7 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat /* complain if this field doesn't allow NULL values */ if (~var->sqltype & 1) { const char *msg = "Parameter requires non-null value"; - firebird_error_stmt_with_info(stmt, "HY105", strlen("HY105"), msg, strlen(msg)); + php_firebird_error_stmt_with_info(stmt, "HY105", strlen("HY105"), msg, strlen(msg)); return 0; } *var->sqlind = -1; @@ -769,7 +769,7 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat default: { const char *msg = "Binding arrays/objects is not supported"; - firebird_error_stmt_with_info(stmt, "HY105", strlen("HY105"), msg, strlen(msg)); + php_firebird_error_stmt_with_info(stmt, "HY105", strlen("HY105"), msg, strlen(msg)); } return 0; } @@ -789,7 +789,7 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat } zval_ptr_dtor(parameter); ZVAL_NULL(parameter); - return firebird_stmt_get_col(stmt, param->paramno, parameter, NULL); + return pdo_firebird_stmt_get_col(stmt, param->paramno, parameter, NULL); default: ; } @@ -797,7 +797,7 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat } /* }}} */ -static int firebird_stmt_set_attribute(pdo_stmt_t *stmt, zend_long attr, zval *val) /* {{{ */ +static int pdo_firebird_stmt_set_attribute(pdo_stmt_t *stmt, zend_long attr, zval *val) /* {{{ */ { pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data; @@ -810,7 +810,7 @@ static int firebird_stmt_set_attribute(pdo_stmt_t *stmt, zend_long attr, zval *v } if (isc_dsql_set_cursor_name(S->H->isc_status, &S->stmt, Z_STRVAL_P(val),0)) { - firebird_error_stmt(stmt); + php_firebird_error_stmt(stmt); return 0; } strlcpy(S->name, Z_STRVAL_P(val), sizeof(S->name)); @@ -820,7 +820,7 @@ static int firebird_stmt_set_attribute(pdo_stmt_t *stmt, zend_long attr, zval *v } /* }}} */ -static int firebird_stmt_get_attribute(pdo_stmt_t *stmt, zend_long attr, zval *val) /* {{{ */ +static int pdo_firebird_stmt_get_attribute(pdo_stmt_t *stmt, zend_long attr, zval *val) /* {{{ */ { pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data; @@ -839,13 +839,13 @@ static int firebird_stmt_get_attribute(pdo_stmt_t *stmt, zend_long attr, zval *v } /* }}} */ -static int firebird_stmt_cursor_closer(pdo_stmt_t *stmt) /* {{{ */ +static int pdo_firebird_stmt_cursor_closer(pdo_stmt_t *stmt) /* {{{ */ { pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data; /* close the statement handle */ if ((*S->name || S->cursor_open) && isc_dsql_free_statement(S->H->isc_status, &S->stmt, DSQL_close)) { - firebird_error_stmt(stmt); + php_firebird_error_stmt(stmt); return 0; } *S->name = 0; @@ -856,16 +856,16 @@ static int firebird_stmt_cursor_closer(pdo_stmt_t *stmt) /* {{{ */ const struct pdo_stmt_methods firebird_stmt_methods = { /* {{{ */ - firebird_stmt_dtor, - firebird_stmt_execute, - firebird_stmt_fetch, - firebird_stmt_describe, - firebird_stmt_get_col, - firebird_stmt_param_hook, - firebird_stmt_set_attribute, - firebird_stmt_get_attribute, - firebird_stmt_get_column_meta, + pdo_firebird_stmt_dtor, + pdo_firebird_stmt_execute, + pdo_firebird_stmt_fetch, + pdo_firebird_stmt_describe, + pdo_firebird_stmt_get_col, + pdo_firebird_stmt_param_hook, + pdo_firebird_stmt_set_attribute, + pdo_firebird_stmt_get_attribute, + pdo_firebird_stmt_get_column_meta, NULL, /* next_rowset_func */ - firebird_stmt_cursor_closer + pdo_firebird_stmt_cursor_closer }; /* }}} */ diff --git a/ext/pdo_firebird/php_pdo_firebird_int.h b/ext/pdo_firebird/php_pdo_firebird_int.h index 39e954ffc2acd..c7a0087ed6d9f 100644 --- a/ext/pdo_firebird/php_pdo_firebird_int.h +++ b/ext/pdo_firebird/php_pdo_firebird_int.h @@ -129,12 +129,12 @@ extern const pdo_driver_t pdo_firebird_driver; extern const struct pdo_stmt_methods firebird_stmt_methods; -extern void _firebird_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *state, const size_t state_len, +extern void php_firebird_set_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *state, const size_t state_len, const char *msg, const size_t msg_len); -#define firebird_error(d) _firebird_error(d, NULL, NULL, 0, NULL, 0) -#define firebird_error_stmt(s) _firebird_error(s->dbh, s, NULL, 0, NULL, 0) -#define firebird_error_with_info(d,e,el,m,ml) _firebird_error(d, NULL, e, el, m, ml) -#define firebird_error_stmt_with_info(s,e,el,m,ml) _firebird_error(s->dbh, s, e, el, m, ml) +#define php_firebird_error(d) php_firebird_set_error(d, NULL, NULL, 0, NULL, 0) +#define php_firebird_error_stmt(s) php_firebird_set_error(s->dbh, s, NULL, 0, NULL, 0) +#define php_firebird_error_with_info(d,e,el,m,ml) php_firebird_set_error(d, NULL, e, el, m, ml) +#define php_firebird_error_stmt_with_info(s,e,el,m,ml) php_firebird_set_error(s->dbh, s, e, el, m, ml) enum { PDO_FB_ATTR_DATE_FORMAT = PDO_ATTR_DRIVER_SPECIFIC,