abies Thu Sep 4 10:18:40 2003 EDT Modified files: /php-src/ext/interbase interbase.c php_interbase.h Log: Fix inter-op with IB < 6 Fixes for 64-bit archs
Index: php-src/ext/interbase/interbase.c diff -u php-src/ext/interbase/interbase.c:1.172 php-src/ext/interbase/interbase.c:1.173 --- php-src/ext/interbase/interbase.c:1.172 Thu Sep 4 07:09:46 2003 +++ php-src/ext/interbase/interbase.c Thu Sep 4 10:18:39 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: interbase.c,v 1.172 2003/09/04 11:09:46 abies Exp $ */ +/* $Id: interbase.c,v 1.173 2003/09/04 14:18:39 abies Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -39,7 +39,7 @@ #endif #ifndef SQL_DIALECT_CURRENT -#define SQL_DIALECT_CURRENT SQL_DIALECT_V5 +#define SQL_DIALECT_CURRENT 1 /* == SQL_DIALECT_V5 */ #endif #ifdef ZEND_DEBUG_ @@ -53,11 +53,17 @@ #define SAFE_STRING(s) ((s)?(s):"") #ifdef PHP_WIN32 -#define LL_MASK "I64" -#define LL_LIT(lit) lit ## I64 +# ifndef ISC_UINT64 +# define ISC_UINT64 unsigned __int64 +# endif +# define LL_MASK "I64" +# define LL_LIT(lit) lit ## I64 #else -#define LL_MASK "ll" -#define LL_LIT(lit) lit ## ll +# ifndef ISC_UINT64 +# define ISC_UINT64 unsigned long long int +# endif +# define LL_MASK "ll" +# define LL_LIT(lit) lit ## ll #endif #define QUERY_RESULT 1 @@ -111,7 +117,6 @@ PHP_FE(ibase_commit, NULL) PHP_FE(ibase_rollback, NULL) PHP_FE(ibase_commit_ret, NULL) - PHP_FE(ibase_rollback_ret, NULL) PHP_FE(ibase_blob_info, NULL) PHP_FE(ibase_blob_create, NULL) @@ -129,6 +134,8 @@ PHP_FE(ibase_add_user, NULL) PHP_FE(ibase_modify_user, NULL) PHP_FE(ibase_delete_user, NULL) + + PHP_FE(ibase_rollback_ret, NULL) #endif PHP_FE(ibase_wait_event, NULL) PHP_FE(ibase_set_event_handler, NULL) @@ -253,7 +260,7 @@ } ISC_TEB; typedef struct { - ISC_USHORT vary_length; + unsigned short vary_length; char vary_string[1]; } IBVARY; @@ -293,6 +300,7 @@ union { short sval; float fval; + ISC_LONG lval; ISC_QUAD qval; #ifdef ISC_TIMESTAMP ISC_TIMESTAMP tsval; @@ -312,7 +320,7 @@ ISC_UINT64 res; if (sscanf(id, BLOB_ID_MASK, &res)) { qd->gds_quad_high = (ISC_LONG) (res >> 0x20); - qd->gds_quad_low = (ISC_ULONG) (res & 0xFFFFFFFF); + qd->gds_quad_low = (unsigned ISC_LONG) (res & 0xFFFFFFFF); return 1; } return 0; @@ -466,9 +474,6 @@ IBDEBUG("Dropping statement handle (free_result dtor)..."); isc_dsql_free_statement(IB_STATUS, &ib_result->stmt, DSQL_drop); } - if (ib_result->out_array) { - efree(ib_result->out_array); - } efree(ib_result); } } @@ -708,7 +713,7 @@ php_info_print_table_start(); php_info_print_table_row(2, "Interbase Support", "enabled"); - php_info_print_table_row(2, "Revision", "$Revision: 1.172 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.173 $"); #ifdef COMPILE_DL_INTERBASE php_info_print_table_row(2, "Dynamic Module", "Yes"); #endif @@ -1356,8 +1361,22 @@ break; case SQL_LONG: convert_to_long(b_var); +#if (SIZEOF_LONG > 4) + /* ISC_LONG is always 32-bit */ + if (Z_LVAL_P(b_var) > INT_MAX || Z_LVAL_P(b_var) < INT_MIN) { + _php_ibase_module_error("Parameter %d exceeds field width" TSRMLS_CC, i+1); + rv = FAILURE; + } +#endif + buf[i].val.lval = (ISC_LONG) Z_LVAL_P(b_var); + var->sqldata = (void *) &buf[i].val.lval; + break; +#if defined(SQL_INT64) && (SIZEOF_LONG == 8) + case SQL_INT64: + convert_to_long(b_var); var->sqldata = (void *) &Z_LVAL_P(b_var); break; +#endif case SQL_FLOAT: convert_to_double(b_var); buf[i].val.fval = (float) Z_DVAL_P(b_var); @@ -1602,7 +1621,7 @@ /* allocate sqlda and output buffers */ if (ib_query->out_sqlda) { /* output variables in select, select for update */ IBDEBUG("Query wants XSQLDA for output"); - IB_RESULT = emalloc(sizeof(ibase_result)); + IB_RESULT = emalloc(sizeof(ibase_result) + sizeof(ibase_array) * (ib_query->out_sqlda->sqld-1)); IB_RESULT->link = ib_query->link; IB_RESULT->trans = ib_query->trans; IB_RESULT->stmt = ib_query->stmt; @@ -1615,10 +1634,7 @@ _php_ibase_alloc_xsqlda(out_sqlda); if (ib_query->out_array) { - IB_RESULT->out_array = safe_emalloc(sizeof(ibase_array), out_sqlda->sqld, 0); - memcpy(IB_RESULT->out_array, ib_query->out_array, sizeof(ibase_array) * out_sqlda->sqld); - } else { - IB_RESULT->out_array = NULL; + memcpy(&IB_RESULT->out_array, ib_query->out_array, sizeof(ibase_array) * out_sqlda->sqld); } } @@ -1949,9 +1965,11 @@ case COMMIT: result = isc_commit_transaction(IB_STATUS, &trans->handle); break; +#ifdef SQL_DIALECT_V6 case (ROLLBACK | RETAIN): result = isc_rollback_retaining(IB_STATUS, &trans->handle); break; +#endif case (COMMIT | RETAIN): result = isc_commit_retaining(IB_STATUS, &trans->handle); break; @@ -1996,10 +2014,14 @@ /* {{{ proto bool ibase_rollback_ret( resource link_identifier ) Rollback transaction and retain the transaction context */ +#ifdef SQL_DIALECT_V6 + PHP_FUNCTION(ibase_rollback_ret) { _php_ibase_trans_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, ROLLBACK | RETAIN); } + +#endif /* }}} */ /* {{{ proto mixed ibase_query([resource link_identifier, [ resource link_identifier, ]] string query [, mixed bind_arg [, mixed bind_arg [, ...]]]) @@ -2295,8 +2317,32 @@ case SQL_SHORT: n = *(short *) data; goto _sql_long; +#ifdef SQL_INT64 + case SQL_INT64: +#if (SIZEOF_LONG >= 8) + n = *(long *) data; + goto _sql_long; +#else + if (scale == 0) { + l = sprintf(string_data, "%.0" LL_MASK "d", *(ISC_INT64 *) data); + ZVAL_STRINGL(val,string_data,l,1); + } else { + ISC_INT64 n = *(ISC_INT64 *) data, f = scales[-scale]; + + if (n >= 0) { + l = sprintf(string_data, "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -scale, n % f); + } else if (n < -f) { + l = sprintf(string_data, "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -scale, -n % f); + } else { + l = sprintf(string_data, "-0.%0*" LL_MASK "d", -scale, -n % f); + } + ZVAL_STRINGL(val,string_data,l,1); + } + break; +#endif +#endif case SQL_LONG: - n = *(long *) data; + n = *(ISC_LONG *) data; _sql_long: if (scale == 0) { ZVAL_LONG(val,n); @@ -2319,24 +2365,6 @@ case SQL_DOUBLE: ZVAL_DOUBLE(val, *(double *) data); break; -#ifdef SQL_INT64 - case SQL_INT64: - if (scale == 0) { - l = sprintf(string_data, "%.0" LL_MASK "d", *(ISC_INT64 *) data); - } else { - ISC_INT64 n = *(ISC_INT64 *) data, f = scales[-scale]; - - if (n >= 0) { - l = sprintf(string_data, "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -scale, n % f); - } else if (n < -f) { - l = sprintf(string_data, "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -scale, -n % f); - } else { - l = sprintf(string_data, "-0.%0*" LL_MASK "d", -scale, -n % f); - } - } - ZVAL_STRINGL(val,string_data,l,1); - break; -#endif default: /* == any date/time type */ { struct tm t; Index: php-src/ext/interbase/php_interbase.h diff -u php-src/ext/interbase/php_interbase.h:1.59 php-src/ext/interbase/php_interbase.h:1.60 --- php-src/ext/interbase/php_interbase.h:1.59 Thu Sep 4 07:09:46 2003 +++ php-src/ext/interbase/php_interbase.h Thu Sep 4 10:18:39 2003 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_interbase.h,v 1.59 2003/09/04 11:09:46 abies Exp $ */ +/* $Id: php_interbase.h,v 1.60 2003/09/04 14:18:39 abies Exp $ */ #ifndef PHP_INTERBASE_H #define PHP_INTERBASE_H @@ -64,7 +64,6 @@ PHP_FUNCTION(ibase_commit); PHP_FUNCTION(ibase_rollback); PHP_FUNCTION(ibase_commit_ret); -PHP_FUNCTION(ibase_rollback_ret); PHP_FUNCTION(ibase_blob_create); PHP_FUNCTION(ibase_blob_add); @@ -79,6 +78,8 @@ PHP_FUNCTION(ibase_add_user); PHP_FUNCTION(ibase_modify_user); PHP_FUNCTION(ibase_delete_user); + +PHP_FUNCTION(ibase_rollback_ret); #endif PHP_FUNCTION(ibase_errmsg); PHP_FUNCTION(ibase_errcode); @@ -120,7 +121,7 @@ isc_tr_handle handle; unsigned short link_cnt; unsigned long affected_rows; - ibase_db_link *db_link[1]; + ibase_db_link *db_link[1]; /* last member */ } ibase_trans; typedef struct tr_list { @@ -147,7 +148,7 @@ unsigned short type; unsigned char has_more_rows, statement_type; XSQLDA *out_sqlda; - ibase_array *out_array; + ibase_array out_array[1]; /* last member */ } ibase_result; typedef struct {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php