[PHP-DEV] CVS update: php3/functions From: andrew (php-dev <email protected>)
Date: 03/20/99

Date: Saturday March 20, 1999 @ 10:03
Author: andrew

Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv19249/functions

Modified Files:
        interbase.c php3_interbase.h
Log Message:
Added charset parameter to ibase_connect, ibase_pconnect

Initial arrays support added. Now read-only, not tested on
        multidimensional arrays.
        
Constant argument ibase_fetch() "TEXT" changed to constant IBASE_TEXT,
        added IBASE_TIMESTAMP for fetching DATE as timestamp.
        
Constant arguments ibase_trans() changed:

       "READ" IBASE_READ
       "COMMITED" IBASE_COMMITED
       "CONSISTENCY" IBASE_CONSISTENCY
       "NOWAIT" IBASE_NOWAIT
Index: php3/functions/interbase.c
diff -c php3/functions/interbase.c:1.13 php3/functions/interbase.c:1.14
*** php3/functions/interbase.c:1.13 Tue Mar 9 01:23:14 1999
--- php3/functions/interbase.c Sat Mar 20 10:03:32 1999
***************
*** 28,34 ****
     +----------------------------------------------------------------------+
   */
  
! /* $Id: interbase.c,v 1.13 1999/03/09 06:23:14 andrew Exp $ */
  
  /* TODO: Arrays, roles?
  A lot... */
--- 28,34 ----
     +----------------------------------------------------------------------+
   */
  
! /* $Id: interbase.c,v 1.14 1999/03/20 15:03:32 andrew Exp $ */
  
  /* TODO: Arrays, roles?
  A lot... */
***************
*** 46,83 ****
  #include "fsock.h"
  #include "head.h"
  
! /* {{{ extension definition structures */ /*fold00*/
  function_entry ibase_functions[] = {
! {"ibase_connect", php3_ibase_connect, NULL},
! {"ibase_pconnect", php3_ibase_pconnect, NULL},
! {"ibase_close", php3_ibase_close, NULL},
! {"ibase_query", php3_ibase_query, NULL},
! {"ibase_fetch_row", php3_ibase_fetch_row, NULL},
! {"ibase_fetch_object", php3_ibase_fetch_object,NULL},
! {"ibase_free_result", php3_ibase_free_result, NULL},
! {"ibase_prepare", php3_ibase_prepare, NULL},
! {"ibase_execute", php3_ibase_execute, NULL},
! {"ibase_free_query", php3_ibase_free_query, NULL},
! {"ibase_timefmt", php3_ibase_timefmt, NULL},
!
! {"ibase_num_fields", php3_ibase_num_fields, NULL},
! {"ibase_field_info", php3_ibase_field_info, NULL},
!
! {"ibase_trans", php3_ibase_trans, NULL},
! {"ibase_commit", php3_ibase_commit, NULL},
! {"ibase_rollback", php3_ibase_rollback, NULL},
!
! {"ibase_blob_info", php3_ibase_blob_info, NULL},
! {"ibase_blob_create", php3_ibase_blob_create, NULL},
! {"ibase_blob_add", php3_ibase_blob_add, NULL},
! {"ibase_blob_cancel", php3_ibase_blob_cancel, NULL},
! {"ibase_blob_close", php3_ibase_blob_close, NULL},
! {"ibase_blob_open", php3_ibase_blob_open, NULL},
! {"ibase_blob_get", php3_ibase_blob_get, NULL},
! {"ibase_blob_echo", php3_ibase_blob_echo, NULL},
! {"ibase_blob_import", php3_ibase_blob_import, NULL},
!
! {"ibase_errmsg", php3_ibase_errmsg, NULL},
          {NULL, NULL, NULL}
  };
  
--- 46,84 ----
  #include "fsock.h"
  #include "head.h"
  
! /* {{{ extension definition structures */
  function_entry ibase_functions[] = {
! PHP_FE(ibase_connect, NULL)
! PHP_FE(ibase_pconnect, NULL)
! PHP_FE(ibase_close, NULL)
! PHP_FE(ibase_query, NULL)
! PHP_FE(ibase_fetch_row, NULL)
! PHP_FE(ibase_fetch_object, NULL)
! PHP_FE(ibase_free_result, NULL)
! PHP_FE(ibase_prepare, NULL)
! PHP_FE(ibase_execute, NULL)
! PHP_FE(ibase_free_query, NULL)
! PHP_FE(ibase_timefmt, NULL)
!
! PHP_FE(ibase_num_fields, NULL)
! PHP_FE(ibase_field_info, NULL)
!
! PHP_FE(ibase_trans, NULL)
! PHP_FE(ibase_commit, NULL)
! PHP_FE(ibase_rollback, NULL)
!
! PHP_FE(ibase_blob_info, NULL)
! PHP_FE(ibase_blob_create, NULL)
! PHP_FE(ibase_blob_add, NULL)
! PHP_FE(ibase_blob_cancel, NULL)
! PHP_FE(ibase_blob_close, NULL)
! PHP_FE(ibase_blob_open, NULL)
! PHP_FE(ibase_blob_get, NULL)
! PHP_FE(ibase_blob_echo, NULL)
! PHP_FE(ibase_blob_import, NULL)
!
! PHP_FE(ibase_errmsg, NULL)
!
          {NULL, NULL, NULL}
  };
  
***************
*** 86,102 ****
          "InterBase",
          ibase_functions,
          php3_minit_ibase,
! NULL,
          php3_rinit_ibase,
          php3_rfinish_ibase,
! NULL /*php3_info_ibase*/,
          STANDARD_MODULE_PROPERTIES
  };
  /* }}} */
  
  
! /* {{{ internal macros and structs */ /*fold00*/
  
  /* db_handle and transaction handle keep in one variable
    link = db_handle * IBASE_TRANS_ON_LINK + trans_handle
  */
--- 87,105 ----
          "InterBase",
          ibase_functions,
          php3_minit_ibase,
! php3_mfinish_ibase,
          php3_rinit_ibase,
          php3_rfinish_ibase,
! php3_info_ibase,
          STANDARD_MODULE_PROPERTIES
  };
  /* }}} */
  
  
! /* {{{ internal macros and structures */
  
+ #define IB_STATUS (IBASE_GLOBAL(php3_ibase_module).status)
+
  /* db_handle and transaction handle keep in one variable
    link = db_handle * IBASE_TRANS_ON_LINK + trans_handle
  */
***************
*** 109,115 ****
          link_id /= IBASE_TRANS_ON_LINK; \
          ib_link = (ibase_db_link *) php3_list_find(link_id, &type); \
          if (type!=IBASE_GLOBAL(php3_ibase_module).le_link && type!=IBASE_GLOBAL(php3_ibase_module).le_plink) { \
! _php3_module_error("%d is not link or transaction index",link_id); \
                  RETURN_FALSE; \
          }}
  
--- 112,118 ----
          link_id /= IBASE_TRANS_ON_LINK; \
          ib_link = (ibase_db_link *) php3_list_find(link_id, &type); \
          if (type!=IBASE_GLOBAL(php3_ibase_module).le_link && type!=IBASE_GLOBAL(php3_ibase_module).le_plink) { \
! _php3_ibase_module_error("%d is not link or transaction index",link_id); \
                  RETURN_FALSE; \
          }}
  
***************
*** 119,125 ****
          int type; \
          ib_query = (ibase_query *) php3_list_find(query_id, &type); \
          if (type!=IBASE_GLOBAL(php3_ibase_module).le_query) { \
! _php3_module_error("%d is not query index",query_id); \
                  RETURN_FALSE; \
          }}
  
--- 122,128 ----
          int type; \
          ib_query = (ibase_query *) php3_list_find(query_id, &type); \
          if (type!=IBASE_GLOBAL(php3_ibase_module).le_query) { \
! _php3_ibase_module_error("%d is not query index",query_id); \
                  RETURN_FALSE; \
          }}
  
***************
*** 128,134 ****
          int type; \
          ib_result = (ibase_result *) php3_list_find(result_id, &type); \
          if (type!=IBASE_GLOBAL(php3_ibase_module).le_result) { \
! _php3_module_error("%d is not result index",result_id); \
                  RETURN_FALSE; \
          }}
  
--- 131,137 ----
          int type; \
          ib_result = (ibase_result *) php3_list_find(result_id, &type); \
          if (type!=IBASE_GLOBAL(php3_ibase_module).le_result) { \
! _php3_ibase_module_error("%d is not result index",result_id); \
                  RETURN_FALSE; \
          }}
  
***************
*** 151,166 ****
  
  
  /* get blob identifier from argument
   */
! #define GET_BLOB_ID_ARG(blob_arg, ib_blob) \
  {\
! if(blob_arg->type != IS_STRING\
! || blob_arg->value.str.len != sizeof(ibase_blob_handle)\
! || ((ibase_blob_handle *)(blob_arg->value.str.val))->bl_handle != 0){\
! _php3_module_error("invalid blob id");\
                  RETURN_FALSE;\
          }\
- ib_blob = (ibase_blob_handle *)blob_arg->value.str.val;\
  }
  
  
--- 154,173 ----
  
  
  /* get blob identifier from argument
+ on empty unset argumnet ib_blob set to NULL
   */
! #define GET_BLOB_ID_ARG(blob_arg, ib_blob)\
  {\
! if(blob_arg->type == IS_STRING && blob_arg->value.str.len == 0){\
! ib_blob = NULL;\
! }else if(blob_arg->type != IS_STRING\
! || blob_arg->value.str.len != sizeof(ibase_blob_handle)\
! || ((ibase_blob_handle *)(blob_arg->value.str.val))->bl_handle != 0){\
! _php3_ibase_module_error("invalid blob id");\
                  RETURN_FALSE;\
+ }else{\
+ ib_blob = (ibase_blob_handle *)blob_arg->value.str.val;\
          }\
  }
  
  
***************
*** 173,179 ****
          convert_to_long(blob_arg); \
          blob_ptr = (ibase_blob_handle *) php3_list_find(blob_arg->value.lval, &type); \
          if (type!=IBASE_GLOBAL(php3_ibase_module).le_blob) { \
! _php3_module_error("%d is not blob handle",blob_arg->value.lval); \
                  RETURN_FALSE; \
          } \
  }
--- 180,186 ----
          convert_to_long(blob_arg); \
          blob_ptr = (ibase_blob_handle *) php3_list_find(blob_arg->value.lval, &type); \
          if (type!=IBASE_GLOBAL(php3_ibase_module).le_blob) { \
! _php3_ibase_module_error("%d is not blob handle",blob_arg->value.lval); \
                  RETURN_FALSE; \
          } \
  }
***************
*** 189,195 ****
  /* }}} */
  
  
! /* {{{ thread safety stuff */ /*fold00*/
  #if defined(THREAD_SAFE)
  typedef ibase_global_struct{
          ibase_module php3_ibase_module;
--- 196,202 ----
  /* }}} */
  
  
! /* {{{ thread safety stuff */
  #if defined(THREAD_SAFE)
  typedef ibase_global_struct{
          ibase_module php3_ibase_module;
***************
*** 210,221 ****
  
  /* error handling ---------------------------- */
  
! /* {{{ proto string ibase_errmsg() */ /*fold00*/
  /* Return error message */
  void php3_ibase_errmsg(INTERNAL_FUNCTION_PARAMETERS)
  {
          char *errmsg = IBASE_GLOBAL(php3_ibase_module).errmsg;
          IBASE_TLS_VARS;
          if(errmsg[0]){
                  RETURN_STRING(errmsg,1);
          }
--- 217,229 ----
  
  /* error handling ---------------------------- */
  
! /* {{{ proto string ibase_errmsg() */
  /* Return error message */
  void php3_ibase_errmsg(INTERNAL_FUNCTION_PARAMETERS)
  {
          char *errmsg = IBASE_GLOBAL(php3_ibase_module).errmsg;
          IBASE_TLS_VARS;
+
          if(errmsg[0]){
                  RETURN_STRING(errmsg,1);
          }
***************
*** 224,237 ****
  /* }}} */
  
  
! /* {{{ _php3_ibase_error() */ /*fold00*/
  /* print interbase error and save it for ibase_errmsg() */
! static void _php3_ibase_error(ISC_STATUS *status)
  {
          char *s, *errmsg = IBASE_GLOBAL(php3_ibase_module).errmsg;
  
          s = errmsg;
! while((s - errmsg) < MAX_ERRMSG - (IBASE_MSGSIZE + 2) && isc_interprete(s, &status)){
                  strcat(errmsg, " ");
                  s = errmsg + strlen(errmsg);
          }
--- 232,246 ----
  /* }}} */
  
  
! /* {{{ _php3_ibase_error() */
  /* print interbase error and save it for ibase_errmsg() */
! static void _php3_ibase_error(void)
  {
          char *s, *errmsg = IBASE_GLOBAL(php3_ibase_module).errmsg;
+ ISC_STATUS *statusp = IB_STATUS;
  
          s = errmsg;
! while((s - errmsg) < MAX_ERRMSG - (IBASE_MSGSIZE + 2) && isc_interprete(s, &statusp)){
                  strcat(errmsg, " ");
                  s = errmsg + strlen(errmsg);
          }
***************
*** 240,248 ****
  /* }}} */
  
  
! /* {{{ _php3_module_error() */ /*fold00*/
  /* print php interbase module error and save it for ibase_errmsg() */
! static void _php3_module_error(char *msg, ...)
  {
          char *errmsg = IBASE_GLOBAL(php3_ibase_module).errmsg;
          va_list ap;
--- 249,257 ----
  /* }}} */
  
  
! /* {{{ _php3_ibase_module_error() */
  /* print php interbase module error and save it for ibase_errmsg() */
! static void _php3_ibase_module_error(char *msg, ...)
  {
          char *errmsg = IBASE_GLOBAL(php3_ibase_module).errmsg;
          va_list ap;
***************
*** 261,267 ****
  /* destructors ---------------------- */
  
  
! /* {{{ _php3_ibase_free_xsqlda() */ /*fold00*/
  /* not actual destructor ... */
  static void _php3_ibase_free_xsqlda(XSQLDA *sqlda)
  {
--- 270,276 ----
  /* destructors ---------------------- */
  
  
! /* {{{ _php3_ibase_free_xsqlda() */
  /* not actual destructor ... */
  static void _php3_ibase_free_xsqlda(XSQLDA *sqlda)
  {
***************
*** 281,366 ****
  /* }}} */
  
  
! /* {{{ _php3_ibase_commit_link() */ /*fold00*/
  static void _php3_ibase_commit_link(ibase_db_link *link)
  {
- ISC_STATUS status[20];
          int i;
  
! if(link->trans[0] != NULL){ /* commit default */
! if(isc_commit_transaction(status, &link->trans[0])){
! _php3_ibase_error(status);
                  }
! link->trans[0] = NULL;
          }
          for(i = 1; i < IBASE_TRANS_ON_LINK; i++){
                  if(link->trans[i] != NULL){
! if(isc_rollback_transaction(status, &link->trans[i])){
! _php3_ibase_error(status);
                          }
! link->trans[i] = NULL;
                  }
          }
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_close_link() */ /*fold00*/
  static void _php3_ibase_close_link(ibase_db_link *link)
  {
- ISC_STATUS status[20];
- IBASE_TLS_VARS;
-
          _php3_ibase_commit_link(link);
! isc_detach_database(status, &link->link);
          IBASE_GLOBAL(php3_ibase_module).num_links--;
          efree(link);
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_close_plink() */ /*fold00*/
  static void _php3_ibase_close_plink(ibase_db_link *link)
  {
- ISC_STATUS status[20];
- IBASE_TLS_VARS;
-
          _php3_ibase_commit_link(link);
! isc_detach_database(status, &link->link);
! php3_ibase_module.num_persistent--;
! php3_ibase_module.num_links--;
          free(link);
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_free_result() */ /*fold00*/
  static void _php3_ibase_free_result(ibase_result *ib_result)
  {
- ISC_STATUS status[20];
-
          if (ib_result){
                  _php3_ibase_free_xsqlda(ib_result->out_sqlda);
                  if(ib_result->drop_stmt && ib_result->stmt){
! if(isc_dsql_free_statement(status, &ib_result->stmt, DSQL_drop)){
! _php3_ibase_error(status);
                          }
                  }else{
! if(isc_dsql_free_statement(status, &ib_result->stmt, DSQL_close)){
! _php3_ibase_error(status);
                          }
                  }
                  efree(ib_result);
          }
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_free_query() */ /*fold00*/
  static void _php3_ibase_free_query(ibase_query *ib_query)
  {
! ISC_STATUS status[20];
!
          if(ib_query){
                  if (ib_query->in_sqlda) {
                          efree(ib_query->in_sqlda);
--- 290,368 ----
  /* }}} */
  
  
! /* {{{ _php3_ibase_commit_link() */
  static void _php3_ibase_commit_link(ibase_db_link *link)
  {
          int i;
  
! if(link->trans[0] != NULL){ /* commit default */
! if(isc_commit_transaction(IB_STATUS, &link->trans[0])){
! _php3_ibase_error();
                  }
! link->trans[0] = NULL;
          }
          for(i = 1; i < IBASE_TRANS_ON_LINK; i++){
                  if(link->trans[i] != NULL){
! if(isc_rollback_transaction(IB_STATUS, &link->trans[i])){
! _php3_ibase_error();
                          }
! link->trans[i] = NULL;
                  }
          }
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_close_link() */
  static void _php3_ibase_close_link(ibase_db_link *link)
  {
          _php3_ibase_commit_link(link);
! isc_detach_database(IB_STATUS, &link->link);
          IBASE_GLOBAL(php3_ibase_module).num_links--;
          efree(link);
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_close_plink() */
  static void _php3_ibase_close_plink(ibase_db_link *link)
  {
          _php3_ibase_commit_link(link);
! isc_detach_database(IB_STATUS, &link->link);
! IBASE_GLOBAL(php3_ibase_module).num_persistent--;
! IBASE_GLOBAL(php3_ibase_module).num_links--;
          free(link);
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_free_result() */
  static void _php3_ibase_free_result(ibase_result *ib_result)
  {
          if (ib_result){
                  _php3_ibase_free_xsqlda(ib_result->out_sqlda);
                  if(ib_result->drop_stmt && ib_result->stmt){
! if(isc_dsql_free_statement(IB_STATUS, &ib_result->stmt, DSQL_drop)){
! _php3_ibase_error();
                          }
                  }else{
! if(isc_dsql_free_statement(IB_STATUS, &ib_result->stmt, DSQL_close)){
! _php3_ibase_error();
                          }
                  }
+ if(ib_result->out_array){
+ efree(ib_result->out_array);
+ }
                  efree(ib_result);
          }
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_free_query() */
  static void _php3_ibase_free_query(ibase_query *ib_query)
  {
!
          if(ib_query){
                  if (ib_query->in_sqlda) {
                          efree(ib_query->in_sqlda);
***************
*** 369,393 ****
                          efree(ib_query->out_sqlda);
                  }
                  if(ib_query->stmt){
! if(isc_dsql_free_statement(status, &ib_query->stmt, DSQL_drop)){
! _php3_ibase_error(status);
                          }
                  }
                  efree(ib_query);
          }
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_free_blob() */ /*fold00*/
  static void _php3_ibase_free_blob(ibase_blob_handle *ib_blob)
  {
- ISC_STATUS status[20];
- IBASE_TLS_VARS;
          
          if(ib_blob->bl_handle != NULL){ /* blob open*/
! if(isc_cancel_blob(status, &ib_blob->bl_handle)){
! _php3_ibase_error(status);
                  }
          }
          efree(ib_blob);
--- 371,399 ----
                          efree(ib_query->out_sqlda);
                  }
                  if(ib_query->stmt){
! if(isc_dsql_free_statement(IB_STATUS, &ib_query->stmt, DSQL_drop)){
! _php3_ibase_error();
                          }
                  }
+ if(ib_query->in_array){
+ efree(ib_query->in_array);
+ }
+ if(ib_query->out_array){
+ efree(ib_query->out_array);
+ }
                  efree(ib_query);
          }
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_free_blob() */
  static void _php3_ibase_free_blob(ibase_blob_handle *ib_blob)
  {
          
          if(ib_blob->bl_handle != NULL){ /* blob open*/
! if(isc_cancel_blob(IB_STATUS, &ib_blob->bl_handle)){
! _php3_ibase_error();
                  }
          }
          efree(ib_blob);
***************
*** 395,401 ****
  /* }}} */
  
  
! /* {{{ startup, shutdown and info functions */ /*fold00*/
  int php3_minit_ibase(INIT_FUNC_ARGS)
  {
          IBASE_TLS_VARS;
--- 401,407 ----
  /* }}} */
  
  
! /* {{{ startup, shutdown and info functions */
  int php3_minit_ibase(INIT_FUNC_ARGS)
  {
          IBASE_TLS_VARS;
***************
*** 426,431 ****
--- 432,446 ----
          IBASE_GLOBAL(php3_ibase_module).le_blob = register_list_destructors(_php3_ibase_free_blob, NULL);
          IBASE_GLOBAL(php3_ibase_module).le_link = register_list_destructors(_php3_ibase_close_link, NULL);
          IBASE_GLOBAL(php3_ibase_module).le_plink = register_list_destructors(_php3_ibase_commit_link, _php3_ibase_close_plink);
+
+ REGISTER_LONG_CONSTANT("IBASE_DEFAULT", PHP3_IBASE_DEFAULT, CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("IBASE_TEXT", PHP3_IBASE_TEXT, CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("IBASE_TIMESTAMP", PHP3_IBASE_TIMESTAMP, CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("IBASE_READ", PHP3_IBASE_READ, CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("IBASE_COMMITED", PHP3_IBASE_COMMITED, CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("IBASE_CONSISTENCY", PHP3_IBASE_CONSISTENCY, CONST_PERSISTENT);
+ REGISTER_LONG_CONSTANT("IBASE_NOWAIT", PHP3_IBASE_NOWAIT, CONST_PERSISTENT);
+
          return SUCCESS;
  }
  
***************
*** 440,451 ****
          return SUCCESS;
  }
  
- /* TODO IF NEEDED
  
  int php3_mfinish_ibase(void)
  {
  }
! */
  
  int php3_rfinish_ibase(void)
  {
--- 455,466 ----
          return SUCCESS;
  }
  
  
  int php3_mfinish_ibase(void)
  {
+ return SUCCESS;
  }
!
  
  int php3_rfinish_ibase(void)
  {
***************
*** 457,475 ****
  }
  
  
! void php3_info_ibase(void) /*fold00*/
  {
! php3_printf("");
  }
  /* }}} */
  
  
! /* {{{ _php_ibase_attach_db() */ /*fold00*/
  static int _php_ibase_attach_db(char *server, char *uname, char *passwd, char *charset, int buffers, char *role, isc_db_handle *db)
  {
          char dpb_buffer[256], *dpb, *p;
          int dpb_length, len;
- ISC_STATUS status[20];
  
          dpb = dpb_buffer;
  
--- 472,489 ----
  }
  
  
! void php3_info_ibase(void)
  {
! php3_printf("$Revision: 1.14 $");
  }
  /* }}} */
  
  
! /* {{{ _php_ibase_attach_db() */
  static int _php_ibase_attach_db(char *server, char *uname, char *passwd, char *charset, int buffers, char *role, isc_db_handle *db)
  {
          char dpb_buffer[256], *dpb, *p;
          int dpb_length, len;
  
          dpb = dpb_buffer;
  
***************
*** 517,541 ****
  
          dpb_length = dpb - dpb_buffer;
  
! if(isc_attach_database(status, strlen(server), server, db, dpb_length, dpb_buffer)){
! _php3_ibase_error(status);
! return 1;
          }
! return 0;
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_connect() */ /*fold00*/
  static void _php3_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
  {
! pval *server, *uname, *passwd;
!
! char *ib_server, *ib_uname, *ib_passwd;
! int i, ib_server_len, ib_uname_len, ib_passwd_len;
          isc_db_handle db_handle = NULL;
          char *hashed_details;
! int hashed_details_length;
          ibase_db_link *ib_link;
          IBASE_TLS_VARS;
          
--- 531,554 ----
  
          dpb_length = dpb - dpb_buffer;
  
! if(isc_attach_database(IB_STATUS, strlen(server), server, db, dpb_length, dpb_buffer)){
! _php3_ibase_error();
! return FAILURE;
          }
! return SUCCESS;
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_connect() */
  static void _php3_ibase_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
  {
! pval **args;
! char *ib_server, *ib_uname, *ib_passwd, *ib_charset = NULL;
! int i, ib_uname_len, ib_passwd_len;
          isc_db_handle db_handle = NULL;
          char *hashed_details;
! int hashed_details_length = 0;
          ibase_db_link *ib_link;
          IBASE_TLS_VARS;
          
***************
*** 545,605 ****
          ib_passwd = IBASE_GLOBAL(php3_ibase_module).default_password;
          ib_uname_len = ib_uname ? strlen(ib_uname) : 0;
          ib_passwd_len = ib_passwd ? strlen(ib_passwd) : 0;
!
! switch(ARG_COUNT(ht)) {
! case 1:
! {
! if (getParameters(ht, 1, &server) == FAILURE) {
! RETURN_FALSE;
! }
! convert_to_string(server);
! ib_server = server->value.str.val;
! ib_server_len = server->value.str.len;
! hashed_details_length = server->value.str.len+ib_uname_len+ib_passwd_len+5+3;
! hashed_details = (char *) emalloc(hashed_details_length+1);
! sprintf(hashed_details, "ibase_%s_%s_%s", ib_server, ib_uname, ib_passwd);
! }
! break;
! case 2:
! {
! if (getParameters(ht, 2, &server, &uname) == FAILURE) {
! RETURN_FALSE;
! }
! convert_to_string(server);
! convert_to_string(uname);
! ib_server = server->value.str.val;
! ib_uname = uname->value.str.val;
! ib_server_len = server->value.str.len;
! ib_uname_len = uname->value.str.len;
! hashed_details_length = server->value.str.len+uname->value.str.len+ib_passwd_len+5+3;
! hashed_details = (char *) emalloc(hashed_details_length+1);
! sprintf(hashed_details, "ibase_%s_%s_%s", ib_server, ib_uname, ib_passwd);
! }
! break;
! case 3:
! {
! if (getParameters(ht, 3, &server, &uname, &passwd) == FAILURE) {
! RETURN_FALSE;
! }
! convert_to_string(server);
! convert_to_string(uname);
! convert_to_string(passwd);
! ib_server = server->value.str.val;
! ib_uname = uname->value.str.val;
! ib_passwd = passwd->value.str.val;
! ib_server_len = server->value.str.len;
! ib_uname_len = uname->value.str.len;
! ib_passwd_len = passwd->value.str.len;
! hashed_details_length = server->value.str.len+uname->value.str.len+passwd->value.str.len+5+3;
! hashed_details = (char *) emalloc(hashed_details_length+1);
! sprintf(hashed_details, "ibase_%s_%s_%s", ib_server, ib_uname, ib_passwd);
! }
! break;
! default:
                  WRONG_PARAM_COUNT;
- break;
          }
  
          if (persistent) {
                  list_entry *le;
                  
--- 558,601 ----
          ib_passwd = IBASE_GLOBAL(php3_ibase_module).default_password;
          ib_uname_len = ib_uname ? strlen(ib_uname) : 0;
          ib_passwd_len = ib_passwd ? strlen(ib_passwd) : 0;
!
! if(ARG_COUNT(ht) < 1 || ARG_COUNT(ht) > 4){
                  WRONG_PARAM_COUNT;
          }
+
+ args = emalloc(sizeof(pval*) * ARG_COUNT(ht));
+ if (getParametersArray(ht, ARG_COUNT(ht), args) == FAILURE) {
+ efree(args);
+ RETURN_FALSE;
+ }
  
+ switch(ARG_COUNT(ht)) {
+ case 4:
+ convert_to_string(args[3]);
+ ib_charset = args[3]->value.str.val;
+ hashed_details_length += args[3]->value.str.len;
+ /* fallout */
+ case 3:
+ convert_to_string(args[2]);
+ ib_passwd = args[2]->value.str.val;
+ hashed_details_length += args[2]->value.str.len;
+ /* fallout */
+ case 2:
+ convert_to_string(args[1]);
+ ib_uname = args[1]->value.str.val;
+ hashed_details_length += args[1]->value.str.len;
+ /* fallout */
+ case 1:
+ convert_to_string(args[0]);
+ ib_server = args[0]->value.str.val;
+ hashed_details_length += args[0]->value.str.len;
+ }/* case */
+
+ efree(args);
+
+ hashed_details = (char *) emalloc(hashed_details_length+strlen("ibase_%s_%s_%s_%s")+1);
+ sprintf(hashed_details, "ibase_%s_%s_%s_%s", ib_server, ib_uname, ib_passwd, ib_charset);
+
          if (persistent) {
                  list_entry *le;
                  
***************
*** 607,625 ****
                          list_entry new_le;
                          
                          if (IBASE_GLOBAL(php3_ibase_module).max_links!=-1 && IBASE_GLOBAL(php3_ibase_module).num_links>=IBASE_GLOBAL(php3_ibase_module).max_links) {
! _php3_module_error("Too many open links (%d)", IBASE_GLOBAL(php3_ibase_module).num_links);
                                  efree(hashed_details);
                                  RETURN_FALSE;
                          }
                          if (IBASE_GLOBAL(php3_ibase_module).max_persistent!=-1 && IBASE_GLOBAL(php3_ibase_module).num_persistent>=IBASE_GLOBAL(php3_ibase_module).max_persistent) {
! _php3_module_error("Too many open persistent links (%d)", IBASE_GLOBAL(php3_ibase_module).num_persistent);
                                  efree(hashed_details);
                                  RETURN_FALSE;
                          }
  
                          /* create the ib_link */
  
! if (_php_ibase_attach_db(ib_server, ib_uname, ib_passwd, NULL, 0, NULL, &db_handle)) {
                                  efree(hashed_details);
                                  RETURN_FALSE;
                          }
--- 603,621 ----
                          list_entry new_le;
                          
                          if (IBASE_GLOBAL(php3_ibase_module).max_links!=-1 && IBASE_GLOBAL(php3_ibase_module).num_links>=IBASE_GLOBAL(php3_ibase_module).max_links) {
! _php3_ibase_module_error("Too many open links (%d)", IBASE_GLOBAL(php3_ibase_module).num_links);
                                  efree(hashed_details);
                                  RETURN_FALSE;
                          }
                          if (IBASE_GLOBAL(php3_ibase_module).max_persistent!=-1 && IBASE_GLOBAL(php3_ibase_module).num_persistent>=IBASE_GLOBAL(php3_ibase_module).max_persistent) {
! _php3_ibase_module_error("Too many open persistent links (%d)", IBASE_GLOBAL(php3_ibase_module).num_persistent);
                                  efree(hashed_details);
                                  RETURN_FALSE;
                          }
  
                          /* create the ib_link */
  
! if (_php_ibase_attach_db(ib_server, ib_uname, ib_passwd, ib_charset, 0, NULL, &db_handle) == FAILURE) {
                                  efree(hashed_details);
                                  RETURN_FALSE;
                          }
***************
*** 676,688 ****
                          }
                  }
                  if (IBASE_GLOBAL(php3_ibase_module).max_links!=-1 && IBASE_GLOBAL(php3_ibase_module).num_links>=IBASE_GLOBAL(php3_ibase_module).max_links) {
! _php3_module_error("Too many open links (%d)", IBASE_GLOBAL(php3_ibase_module).num_links);
                          efree(hashed_details);
                          RETURN_FALSE;
                  }
                  /* create the ib_link */
  
! if (_php_ibase_attach_db(ib_server, ib_uname, ib_passwd, NULL, 0, NULL, &db_handle)) {
                          efree(hashed_details);
                          RETURN_FALSE;
                  }
--- 672,684 ----
                          }
                  }
                  if (IBASE_GLOBAL(php3_ibase_module).max_links!=-1 && IBASE_GLOBAL(php3_ibase_module).num_links>=IBASE_GLOBAL(php3_ibase_module).max_links) {
! _php3_ibase_module_error("Too many open links (%d)", IBASE_GLOBAL(php3_ibase_module).num_links);
                          efree(hashed_details);
                          RETURN_FALSE;
                  }
                  /* create the ib_link */
  
! if (_php_ibase_attach_db(ib_server, ib_uname, ib_passwd, ib_charset, 0, NULL, &db_handle) == FAILURE) {
                          efree(hashed_details);
                          RETURN_FALSE;
                  }
***************
*** 712,744 ****
  /* }}} */
  
  
! /* {{{ proto int ibase_connect(string database [, string username] [, string password]) */ /*fold00*/
  /* Open a connection to an InterBase database */
! void php3_ibase_connect(INTERNAL_FUNCTION_PARAMETERS)
  {
          _php3_ibase_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
  }
  /* }}} */
  
  
! /* {{{ proto int ibase_pconnect(string database [, string username] [, string password]) */ /*fold00*/
  /* Open a persistent connection to an InterBase database */
! void php3_ibase_pconnect(INTERNAL_FUNCTION_PARAMETERS)
  {
          _php3_ibase_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
  }
  /* }}} */
  
  
! /* {{{ proto int ibase_close([int link_identifier]) */ /*fold00*/
  /* Close an InterBase connection */
! void php3_ibase_close(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *link_arg;
          ibase_db_link *ib_link;
          int link_id, trans_n;
          IBASE_TLS_VARS;
          
          RESET_ERRMSG;
          
          switch (ARG_COUNT(ht)) {
--- 708,741 ----
  /* }}} */
  
  
! /* {{{ proto int ibase_connect(string database [, string username] [, string password] [, string charset]) */
  /* Open a connection to an InterBase database */
! PHP_FUNCTION(ibase_connect)
  {
          _php3_ibase_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
  }
  /* }}} */
  
  
! /* {{{ proto int ibase_pconnect(string database [, string username] [, string password] [, string charset] ) */
  /* Open a persistent connection to an InterBase database */
! PHP_FUNCTION(ibase_pconnect)
  {
          _php3_ibase_connect(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
  }
  /* }}} */
  
  
! /* {{{ proto int ibase_close([int link_identifier]) */
  /* Close an InterBase connection */
! PHP_FUNCTION(ibase_close)
  {
          pval *link_arg;
          ibase_db_link *ib_link;
          int link_id, trans_n;
          IBASE_TLS_VARS;
          
+
          RESET_ERRMSG;
          
          switch (ARG_COUNT(ht)) {
***************
*** 764,812 ****
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_alloc_query() */ /*fold00*/
  /* allocate and prepare query */
  static int _php3_ibase_alloc_query(ibase_query **ib_queryp, isc_db_handle link, isc_tr_handle trans, char *query)
  {
  #define IB_QUERY (*ib_queryp)
!
! ISC_STATUS status[20];
!
          IB_QUERY = emalloc(sizeof(ibase_query));
          IB_QUERY->link = link;
          IB_QUERY->trans = trans;
          IB_QUERY->stmt = NULL;
!
! if (isc_dsql_allocate_statement(status, &link, &IB_QUERY->stmt)) {
! _php3_ibase_error(status);
! efree(IB_QUERY);
! IB_QUERY=NULL;
! return FAILURE;
          }
  
          IB_QUERY->out_sqlda = emalloc(XSQLDA_LENGTH(0));
          IB_QUERY->out_sqlda->sqln = 0;
          IB_QUERY->out_sqlda->version = SQLDA_VERSION1;
  
! if (isc_dsql_prepare(status, &IB_QUERY->trans, &IB_QUERY->stmt, 0, query, SQLDA_VERSION1, IB_QUERY->out_sqlda)) {
! _php3_ibase_error(status);
! efree(IB_QUERY->out_sqlda);
! efree(IB_QUERY);
! IB_QUERY = NULL;
! return FAILURE;
          }
          /* not enough output variables ? */
          if(IB_QUERY->out_sqlda->sqld > IB_QUERY->out_sqlda->sqln){
                  IB_QUERY->out_sqlda = erealloc(IB_QUERY->out_sqlda,XSQLDA_LENGTH(IB_QUERY->out_sqlda->sqld));
                  IB_QUERY->out_sqlda->sqln = IB_QUERY->out_sqlda->sqld;
                  IB_QUERY->out_sqlda->version = SQLDA_VERSION1;
! if (isc_dsql_describe(status, &IB_QUERY->stmt, SQLDA_VERSION1, IB_QUERY->out_sqlda)) {
! _php3_ibase_error(status);
! efree(IB_QUERY->out_sqlda);
! efree(IB_QUERY);
! IB_QUERY = NULL;
! return FAILURE;
                  }
          }
  
--- 761,902 ----
  }
  /* }}} */
  
+ /* {{{ _php3_ibase_alloc_array() */
+ static int _php3_ibase_alloc_array(ibase_array **ib_arrayp, int *array_cntp,
+ XSQLDA *sqlda, isc_db_handle link, isc_tr_handle trans)
+ {
+ #define IB_ARRAY (*ib_arrayp)
+
+ int i, dim, ar_cnt, ar_length;
+ XSQLVAR *var;
+
+
+ IB_ARRAY = NULL;
+
+ ar_cnt = 0; /* find arrays */
+ var = sqlda->sqlvar;
+ for(i = 0; i < sqlda->sqld; i++, var++){
+ if((var->sqltype & ~1) == SQL_ARRAY)
+ ar_cnt++;
+ }
+
+ if(ar_cnt){ /* have arrays ? */
+
+ *array_cntp = ar_cnt;
+ IB_ARRAY = emalloc(sizeof(ibase_array)*ar_cnt);
+ ar_cnt = 0;
+ var = sqlda->sqlvar;
+ for(i = 0; i < sqlda->sqld; i++, var++){
+ if((var->sqltype & ~1) == SQL_ARRAY){
+
+ ISC_ARRAY_DESC *ar_desc = &IB_ARRAY[ar_cnt].ar_desc;
+
+ if(isc_array_lookup_bounds(IB_STATUS, &link, &trans,
+ var->relname, var->sqlname, ar_desc)){
+ _php3_ibase_error();
+ efree(IB_ARRAY);
+ IB_ARRAY = NULL;
+ return FAILURE;
+ }
+
+ switch (ar_desc->array_desc_dtype){
+ case blr_text:
+ case blr_text2:
+ IB_ARRAY[ar_cnt].el_type = SQL_TEXT;
+ IB_ARRAY[ar_cnt].el_size = ar_desc->array_desc_length+1;
+ break;
+ case blr_short:
+ IB_ARRAY[ar_cnt].el_type = SQL_SHORT;
+ IB_ARRAY[ar_cnt].el_size = sizeof(short);
+ break;
+ case blr_long:
+ IB_ARRAY[ar_cnt].el_type = SQL_LONG;
+ IB_ARRAY[ar_cnt].el_size = sizeof(long);
+ break;
+ case blr_float:
+ IB_ARRAY[ar_cnt].el_type = SQL_FLOAT;
+ IB_ARRAY[ar_cnt].el_size = sizeof(float);
+ break;
+ case blr_double:
+ IB_ARRAY[ar_cnt].el_type = SQL_DOUBLE;
+ IB_ARRAY[ar_cnt].el_size = sizeof(double);
+ break;
+ case blr_date:
+ IB_ARRAY[ar_cnt].el_type = SQL_DATE;
+ IB_ARRAY[ar_cnt].el_size = sizeof(ISC_QUAD);
+ break;
+ case blr_varying:
+ case blr_varying2: /* changed to SQL_TEXT ? */
+ /* sql_type = SQL_VARYING; Why? FIXME: ??? */
+ IB_ARRAY[ar_cnt].el_type = SQL_TEXT;
+ IB_ARRAY[ar_cnt].el_size = ar_desc->array_desc_length+sizeof(short);
+ break;
+ default:
+ _php3_ibase_module_error("unexpected array type %d in relation '%s' column '%s')",
+ ar_desc->array_desc_dtype,var->relname, var->sqlname);
+ efree(IB_ARRAY);
+ IB_ARRAY = NULL;
+ return FAILURE;
+ }/* switch array_desc_type */
+
+ ar_length = 0; /* calculate elements count */
+ for(dim = 0; dim < ar_desc->array_desc_dimensions; dim++){
+ ar_length += 1 + ar_desc->array_desc_bounds[dim].array_bound_upper
+ - ar_desc->array_desc_bounds[dim].array_bound_lower;
+ }
+ IB_ARRAY[ar_cnt].ar_size = IB_ARRAY[ar_cnt].el_size * ar_length;
+
+ ar_cnt++;
+
+ }/* if SQL_ARRAY */
+ }/* for column */
+ }/* if array_cnt */
+
+ return SUCCESS;
+ #undef IB_ARRAY
+ }
+ /* }}} */
+
  
! /* {{{ _php3_ibase_alloc_query() */
  /* allocate and prepare query */
  static int _php3_ibase_alloc_query(ibase_query **ib_queryp, isc_db_handle link, isc_tr_handle trans, char *query)
  {
  #define IB_QUERY (*ib_queryp)
!
          IB_QUERY = emalloc(sizeof(ibase_query));
          IB_QUERY->link = link;
          IB_QUERY->trans = trans;
          IB_QUERY->stmt = NULL;
! IB_QUERY->out_sqlda = NULL;
! IB_QUERY->in_sqlda = NULL;
! IB_QUERY->in_array = NULL;
! IB_QUERY->in_array_cnt = 0;
! IB_QUERY->out_array = NULL;
! IB_QUERY->out_array_cnt = 0;
!
! if (isc_dsql_allocate_statement(IB_STATUS, &link, &IB_QUERY->stmt)) {
! _php3_ibase_error();
! goto _php3_ibase_alloc_query_error;
          }
  
          IB_QUERY->out_sqlda = emalloc(XSQLDA_LENGTH(0));
          IB_QUERY->out_sqlda->sqln = 0;
          IB_QUERY->out_sqlda->version = SQLDA_VERSION1;
  
! if (isc_dsql_prepare(IB_STATUS, &IB_QUERY->trans, &IB_QUERY->stmt, 0, query, SQLDA_VERSION1, IB_QUERY->out_sqlda)) {
! _php3_ibase_error();
! goto _php3_ibase_alloc_query_error;
          }
+
          /* not enough output variables ? */
          if(IB_QUERY->out_sqlda->sqld > IB_QUERY->out_sqlda->sqln){
                  IB_QUERY->out_sqlda = erealloc(IB_QUERY->out_sqlda,XSQLDA_LENGTH(IB_QUERY->out_sqlda->sqld));
                  IB_QUERY->out_sqlda->sqln = IB_QUERY->out_sqlda->sqld;
                  IB_QUERY->out_sqlda->version = SQLDA_VERSION1;
! if (isc_dsql_describe(IB_STATUS, &IB_QUERY->stmt, SQLDA_VERSION1, IB_QUERY->out_sqlda)) {
! _php3_ibase_error();
! goto _php3_ibase_alloc_query_error;
                  }
          }
  
***************
*** 814,842 ****
          IB_QUERY->in_sqlda = emalloc(XSQLDA_LENGTH(0));
          IB_QUERY->in_sqlda->sqln = 0;
          IB_QUERY->in_sqlda->version = SQLDA_VERSION1;
! if (isc_dsql_describe_bind(status, &IB_QUERY->stmt, SQLDA_VERSION1, IB_QUERY->in_sqlda)) {
! efree(IB_QUERY->out_sqlda);
! efree(IB_QUERY->in_sqlda);
! efree(IB_QUERY);
! IB_QUERY = NULL;
! _php3_ibase_error(status);
! return FAILURE;
          }
          /* not enough input variables ? */
          if(IB_QUERY->in_sqlda->sqln < IB_QUERY->in_sqlda->sqld){
                  IB_QUERY->in_sqlda = erealloc(IB_QUERY->in_sqlda,XSQLDA_LENGTH(IB_QUERY->in_sqlda->sqld));
                  IB_QUERY->in_sqlda->sqln = IB_QUERY->in_sqlda->sqld;
                  IB_QUERY->in_sqlda->version = SQLDA_VERSION1;
! if (isc_dsql_describe_bind(status, &IB_QUERY->stmt, SQLDA_VERSION1, IB_QUERY->in_sqlda)) {
! efree(IB_QUERY->out_sqlda);
! efree(IB_QUERY->in_sqlda);
! efree(IB_QUERY);
! IB_QUERY = NULL;
! _php3_ibase_error(status);
! return FAILURE;
                  }
          }
          
          /* no, haven't placeholders at all */
          if(IB_QUERY->in_sqlda->sqld == 0){
                  efree(IB_QUERY->in_sqlda);
--- 904,936 ----
          IB_QUERY->in_sqlda = emalloc(XSQLDA_LENGTH(0));
          IB_QUERY->in_sqlda->sqln = 0;
          IB_QUERY->in_sqlda->version = SQLDA_VERSION1;
! if (isc_dsql_describe_bind(IB_STATUS, &IB_QUERY->stmt, SQLDA_VERSION1, IB_QUERY->in_sqlda)) {
! _php3_ibase_error();
! goto _php3_ibase_alloc_query_error;
          }
+
          /* not enough input variables ? */
          if(IB_QUERY->in_sqlda->sqln < IB_QUERY->in_sqlda->sqld){
                  IB_QUERY->in_sqlda = erealloc(IB_QUERY->in_sqlda,XSQLDA_LENGTH(IB_QUERY->in_sqlda->sqld));
                  IB_QUERY->in_sqlda->sqln = IB_QUERY->in_sqlda->sqld;
                  IB_QUERY->in_sqlda->version = SQLDA_VERSION1;
! if (isc_dsql_describe_bind(IB_STATUS, &IB_QUERY->stmt, SQLDA_VERSION1, IB_QUERY->in_sqlda)) {
! _php3_ibase_error();
! goto _php3_ibase_alloc_query_error;
                  }
          }
          
+ /* allocate arrays... */
+ if (_php3_ibase_alloc_array(&IB_QUERY->in_array, &IB_QUERY->in_array_cnt,
+ IB_QUERY->in_sqlda, link, trans) == FAILURE){
+ goto _php3_ibase_alloc_query_error; /* error report already done */
+ }
+
+ if (_php3_ibase_alloc_array(&IB_QUERY->out_array, &IB_QUERY->out_array_cnt,
+ IB_QUERY->out_sqlda, link, trans) == FAILURE){
+ goto _php3_ibase_alloc_query_error;
+ }
+
          /* no, haven't placeholders at all */
          if(IB_QUERY->in_sqlda->sqld == 0){
                  efree(IB_QUERY->in_sqlda);
***************
*** 847,872 ****
                  efree(IB_QUERY->out_sqlda);
                  IB_QUERY->out_sqlda = NULL;
          }
!
          return SUCCESS;
  #undef IB_QUERY
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_bind() */ /*fold00*/
  /* bind php variables to XSQLDA */
  static int _php3_ibase_bind(XSQLDA *sqlda, pval **b_vars, BIND_BUF *buf)
  {
          XSQLVAR *var;
          pval *b_var;
          int i;
  
          var = sqlda->sqlvar;
          for(i = 0; i < sqlda->sqld; var++, i++) { /* binded vars */
                  buf[i].sqlind = 0;
                  var->sqlind = &buf[i].sqlind;
                  b_var = b_vars[i];
                  switch(var->sqltype & ~1) {
                          case SQL_TEXT: /* direct to variable */
                          case SQL_VARYING:
--- 941,982 ----
                  efree(IB_QUERY->out_sqlda);
                  IB_QUERY->out_sqlda = NULL;
          }
!
          return SUCCESS;
+
+ _php3_ibase_alloc_query_error:
+
+ if(IB_QUERY->out_sqlda)
+ efree(IB_QUERY->out_sqlda);
+ if(IB_QUERY->in_sqlda)
+ efree(IB_QUERY->in_sqlda);
+ if(IB_QUERY->out_array)
+ efree(IB_QUERY->out_array);
+ efree(IB_QUERY);
+ IB_QUERY = NULL;
+
+ return FAILURE;
  #undef IB_QUERY
  }
  /* }}} */
  
  
! /* {{{ _php3_ibase_bind() */
  /* bind php variables to XSQLDA */
  static int _php3_ibase_bind(XSQLDA *sqlda, pval **b_vars, BIND_BUF *buf)
  {
          XSQLVAR *var;
          pval *b_var;
          int i;
+
  
          var = sqlda->sqlvar;
          for(i = 0; i < sqlda->sqld; var++, i++) { /* binded vars */
+
                  buf[i].sqlind = 0;
                  var->sqlind = &buf[i].sqlind;
                  b_var = b_vars[i];
+
                  switch(var->sqltype & ~1) {
                          case SQL_TEXT: /* direct to variable */
                          case SQL_VARYING:
***************
*** 878,884 ****
                          case SQL_SHORT:
                                  convert_to_long(b_var);
                                  if(b_var->value.lval > SHRT_MAX || b_var->value.lval < SHRT_MIN){
! _php3_module_error("field %*s overflow", var->aliasname_length, var->aliasname);
                                          return FAILURE;
                                  }
                                  buf[i].val.sval = (short)b_var->value.lval;
--- 988,994 ----
                          case SQL_SHORT:
                                  convert_to_long(b_var);
                                  if(b_var->value.lval > SHRT_MAX || b_var->value.lval < SHRT_MIN){
! _php3_ibase_module_error("field %*s overflow", var->aliasname_length, var->aliasname);
                                          return FAILURE;
                                  }
                                  buf[i].val.sval = (short)b_var->value.lval;
***************
*** 905,918 ****
                                                  t.tm_min = t.tm_sec = 0;
                                          
                                          convert_to_string(b_var);
  #if HAVE_STRFTIME /*FIXME: HAVE_STRPTIME ?*/
                                          strptime(b_var->value.str.val, IBASE_GLOBAL(php3_ibase_module).timeformat, &t);
  #else
                                          {
                                                  int n = sscanf(b_var->value.str.val,"%d%*[/]%d%*[/]%d %d%*[:]%d%*[:]%d",
                                                                             &t.tm_mon, &t.tm_mday, &t.tm_year, &t.tm_hour, &t.tm_min, &t.tm_sec);
                                                  if(n != 3 && n != 6){
! _php3_module_error("invalid date/time format");
                                                          return FAILURE;
                                                  }
                                          
--- 1015,1030 ----
                                                  t.tm_min = t.tm_sec = 0;
                                          
                                          convert_to_string(b_var);
+
  #if HAVE_STRFTIME /*FIXME: HAVE_STRPTIME ?*/
+
                                          strptime(b_var->value.str.val, IBASE_GLOBAL(php3_ibase_module).timeformat, &t);
  #else
                                          {
                                                  int n = sscanf(b_var->value.str.val,"%d%*[/]%d%*[/]%d %d%*[:]%d%*[:]%d",
                                                                             &t.tm_mon, &t.tm_mday, &t.tm_year, &t.tm_hour, &t.tm_min, &t.tm_sec);
                                                  if(n != 3 && n != 6){
! _php3_ibase_module_error("invalid date/time format");
                                                          return FAILURE;
                                                  }
                                          
***************
*** 930,936 ****
                                          if(b_var->type != IS_STRING
                                             || b_var->value.str.len != sizeof(ibase_blob_handle)
                                             || ((ibase_blob_handle *)(b_var->value.str.val))->bl_handle != 0){
! _php3_module_error("invalid blob id string");
                                                  return FAILURE;
                                          }
                                          ib_blob_id = (ibase_blob_handle *)b_var->value.str.val;
--- 1042,1048 ----
                                          if(b_var->type != IS_STRING
                                             || b_var->value.str.len != sizeof(ibase_blob_handle)
                                             || ((ibase_blob_handle *)(b_var->value.str.val))->bl_handle != 0){
! _php3_ibase_module_error("invalid blob id string");
                                                  return FAILURE;
                                          }
                                          ib_blob_id = (ibase_blob_handle *)b_var->value.str.val;
***************
*** 939,945 ****