Skip to content

Refactor: [pdo_firebird] unified function naming #12750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 46 additions & 46 deletions ext/pdo_firebird/firebird_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 != '"'))
{
Expand All @@ -293,21 +293,21 @@ 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;
char pname[254], ident[253], ident2[253];
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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -662,21 +662,21 @@ 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;
}

/* 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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -828,23 +828,23 @@ 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;
}
/* }}} */

/* 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;
char *new_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;
}

Expand All @@ -860,23 +860,23 @@ 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;
}

/* 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 = 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;
}
Expand All @@ -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;
Expand All @@ -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 */
Expand Down Expand Up @@ -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 */
Expand All @@ -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;

Expand All @@ -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: {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 */
Expand Down
Loading