Skip to content

Commit 8487ddb

Browse files
authored
pdo_firebird: Cleanup code (GH-15510)
Since we're requiring fbclient >= 3.0 anyway, we: * Remove unneeded `#if FB_API_VER >= 25`, `#if FB_API_VER >= 30`, `#ifdef SQL_BOOLEAN` * Simplify support for new types for query input parameters. Support force_null for them. * fbclient 3.0+ does not have a limit on the length of a SQL query of 64 KB. The new limit is 10 MB, no one in their right mind would transmit a query of such length.
1 parent 3ed884f commit 8487ddb

File tree

2 files changed

+7
-73
lines changed

2 files changed

+7
-73
lines changed

ext/pdo_firebird/firebird_driver.c

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -463,53 +463,6 @@ static int php_firebird_preprocess(const zend_string* sql, char* sql_out, HashTa
463463

464464
#if FB_API_VER >= 40
465465
/* set coercing a data type */
466-
static void set_coercing_input_data_types(XSQLDA* sqlda)
467-
{
468-
/* Data types introduced in Firebird 4.0 are difficult to process using the Firebird Legacy API. */
469-
/* These data types include DECFLOAT(16), DECFLOAT(34), INT128 (NUMERIC/DECIMAL(38, x)), */
470-
/* TIMESTAMP WITH TIME ZONE, and TIME WITH TIME ZONE. */
471-
/* This function allows you to ensure minimal performance */
472-
/* of queries if they contain parameters of the above types. */
473-
unsigned int i;
474-
short dtype;
475-
short nullable;
476-
XSQLVAR* var;
477-
for (i=0, var = sqlda->sqlvar; i < sqlda->sqld; i++, var++) {
478-
dtype = (var->sqltype & ~1); /* drop flag bit */
479-
nullable = (var->sqltype & 1);
480-
switch(dtype) {
481-
case SQL_INT128:
482-
var->sqltype = SQL_VARYING + nullable;
483-
var->sqllen = 46;
484-
var->sqlscale = 0;
485-
break;
486-
487-
case SQL_DEC16:
488-
var->sqltype = SQL_VARYING + nullable;
489-
var->sqllen = 24;
490-
break;
491-
492-
case SQL_DEC34:
493-
var->sqltype = SQL_VARYING + nullable;
494-
var->sqllen = 43;
495-
break;
496-
497-
case SQL_TIMESTAMP_TZ:
498-
var->sqltype = SQL_VARYING + nullable;
499-
var->sqllen = 58;
500-
break;
501-
502-
case SQL_TIME_TZ:
503-
var->sqltype = SQL_VARYING + nullable;
504-
var->sqllen = 46;
505-
break;
506-
507-
default:
508-
break;
509-
}
510-
}
511-
}
512-
513466
static void set_coercing_output_data_types(XSQLDA* sqlda)
514467
{
515468
/* Data types introduced in Firebird 4.0 are difficult to process using the Firebird Legacy API. */
@@ -602,14 +555,12 @@ void php_firebird_set_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *state,
602555
einfo->errmsg_length = read_len;
603556
einfo->errmsg = pestrndup(buf, read_len, dbh->is_persistent);
604557

605-
#if FB_API_VER >= 25
606558
char sqlstate[sizeof(pdo_error_type)];
607559
fb_sqlstate(sqlstate, H->isc_status);
608560
if (sqlstate != NULL && strlen(sqlstate) < sizeof(pdo_error_type)) {
609561
strcpy(*error_code, sqlstate);
610562
goto end;
611563
}
612-
#endif
613564
} else if (msg && msg_len) {
614565
einfo->errmsg_length = msg_len;
615566
einfo->errmsg = pestrndup(msg, einfo->errmsg_length, dbh->is_persistent);
@@ -730,11 +681,6 @@ static bool firebird_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, /* {{{ */
730681
if (isc_dsql_describe_bind(H->isc_status, &s, PDO_FB_SQLDA_VERSION, S->in_sqlda)) {
731682
break;
732683
}
733-
734-
#if FB_API_VER >= 40
735-
/* set coercing a data type */
736-
set_coercing_input_data_types(S->in_sqlda);
737-
#endif
738684
}
739685

740686
stmt->driver_data = S;
@@ -1043,12 +989,6 @@ static int php_firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const zend_string *sq
1043989
pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data;
1044990
char *new_sql;
1045991

1046-
/* Firebird allows SQL statements up to 64k, so bail if it doesn't fit */
1047-
if (ZSTR_LEN(sql) > 65536) {
1048-
php_firebird_error_with_info(dbh, "01004", strlen("01004"), NULL, 0);
1049-
return 0;
1050-
}
1051-
1052992
/* allocate the statement */
1053993
if (isc_dsql_allocate_statement(H->isc_status, &H->db, s)) {
1054994
php_firebird_error(dbh);
@@ -1333,7 +1273,6 @@ static int pdo_firebird_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val)
13331273
}
13341274
/* }}} */
13351275

1336-
#if FB_API_VER >= 30
13371276
/* called by PDO to check liveness */
13381277
static zend_result pdo_firebird_check_liveness(pdo_dbh_t *dbh) /* {{{ */
13391278
{
@@ -1343,7 +1282,6 @@ static zend_result pdo_firebird_check_liveness(pdo_dbh_t *dbh) /* {{{ */
13431282
return fb_ping(H->isc_status, &H->db) ? FAILURE : SUCCESS;
13441283
}
13451284
/* }}} */
1346-
#endif
13471285

13481286
/* called by PDO to retrieve driver-specific information about an error that has occurred */
13491287
static void pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */
@@ -1383,11 +1321,7 @@ static const struct pdo_dbh_methods firebird_methods = { /* {{{ */
13831321
NULL, /* last_id not supported */
13841322
pdo_firebird_fetch_error_func,
13851323
pdo_firebird_get_attribute,
1386-
#if FB_API_VER >= 30
13871324
pdo_firebird_check_liveness,
1388-
#else
1389-
NULL,
1390-
#endif
13911325
NULL, /* get driver methods */
13921326
NULL, /* request shutdown */
13931327
pdo_firebird_in_manually_transaction,

ext/pdo_firebird/firebird_statement.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,9 @@ static int pdo_firebird_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno,
349349
#endif
350350
param_type = PDO_PARAM_INT;
351351
break;
352-
#ifdef SQL_BOOLEAN
353352
case SQL_BOOLEAN:
354353
param_type = PDO_PARAM_BOOL;
355354
break;
356-
#endif
357355
default:
358356
param_type = PDO_PARAM_STR;
359357
break;
@@ -542,11 +540,9 @@ static int pdo_firebird_stmt_get_col(
542540
/* TODO: Why is this not returned as the native type? */
543541
ZVAL_STR(result, zend_strpprintf_unchecked(0, "%.16H", php_get_double_from_sqldata(var->sqldata)));
544542
break;
545-
#ifdef SQL_BOOLEAN
546543
case SQL_BOOLEAN:
547544
ZVAL_BOOL(result, *(FB_BOOLEAN*)var->sqldata);
548545
break;
549-
#endif
550546
case SQL_TYPE_DATE:
551547
isc_decode_sql_date((ISC_DATE*)var->sqldata, &t);
552548
fmt = S->H->date_format ? S->H->date_format : PDO_FB_DEF_DATE_FMT;
@@ -744,7 +740,6 @@ static int pdo_firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param
744740
}
745741
}
746742

747-
#ifdef SQL_BOOLEAN
748743
/* keep native BOOLEAN type */
749744
if ((var->sqltype & ~1) == SQL_BOOLEAN) {
750745
switch (Z_TYPE_P(parameter)) {
@@ -797,8 +792,6 @@ static int pdo_firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param
797792
}
798793
break;
799794
}
800-
#endif
801-
802795

803796
/* check if a NULL should be inserted */
804797
switch (Z_TYPE_P(parameter)) {
@@ -829,6 +822,13 @@ static int pdo_firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param
829822
case SQL_TIMESTAMP:
830823
case SQL_TYPE_DATE:
831824
case SQL_TYPE_TIME:
825+
#if FB_API_VER >= 40
826+
case SQL_INT128:
827+
case SQL_DEC16:
828+
case SQL_DEC34:
829+
case SQL_TIMESTAMP_TZ:
830+
case SQL_TIME_TZ:
831+
#endif
832832
force_null = (Z_STRLEN_P(parameter) == 0);
833833
}
834834
if (!force_null) {

0 commit comments

Comments
 (0)