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

Date: Sunday January 31, 1999 @ 5:33
Author: andrew

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

Modified Files:
        interbase.c php3_interbase.h
Log Message:
Add InterBase blob support. Blobs read only yet.
Add ibase_errmsg() user-level function.

Index: php3/functions/interbase.c
diff -c php3/functions/interbase.c:1.9 php3/functions/interbase.c:1.10
*** php3/functions/interbase.c:1.9 Sat Jan 23 09:45:22 1999
--- php3/functions/interbase.c Sun Jan 31 05:33:09 1999
***************
*** 28,34 ****
     +----------------------------------------------------------------------+
   */
  
! /* $Id: interbase.c,v 1.9 1999/01/23 14:45:22 eschmid Exp $ */
  
  /* TODO: A lot... */
  
--- 28,34 ----
     +----------------------------------------------------------------------+
   */
  
! /* $Id: interbase.c,v 1.10 1999/01/31 10:33:09 andrew Exp $ */
  
  /* TODO: A lot... */
  
***************
*** 56,68 ****
          {"ibase_bind", php3_ibase_bind, 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},
! {NULL, NULL, NULL}
  };
  
  php3_module_entry ibase_module_entry =
--- 56,82 ----
          {"ibase_bind", php3_ibase_bind, 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}
  };
  
  php3_module_entry ibase_module_entry =
***************
*** 78,83 ****
--- 92,102 ----
  };
  /* }}} */
  
+ /* {{{ prototype for blob destructor */
+ static void _php3_ibase_free_blob(ibase_blob_handle *ib_blob);
+ /* }}} */
+
+
  /* {{{ thread safety stuff */
  #if defined(THREAD_SAFE)
  typedef ibase_global_struct{
***************
*** 96,128 ****
  ibase_module php3_ibase_module;
  #endif
  /* }}} */
  
! /* {{{ print interbase error */
! static void _php3_isc_interprete(ISC_STATUS *status)
  {
! #define IB_MSGSIZE 256
! char msg[IB_MSGSIZE*3], *s;
  
! s = msg;
! while((s - msg) < IB_MSGSIZE + 2 && isc_interprete(s, &status)){
! strcat(msg, " ");
! s = msg + strlen(msg);
          }
! php3_error(E_WARNING, "InterBase: %s",msg);
! #undef IB_MSGSIZE
  }
  /* }}} */
  
  /* {{{ _php3_ibase_rollback_trans() */
  static void _php3_ibase_rollback_trans(ibase_trans *ib_trans)
  {
- isc_tr_handle trans;
          ISC_STATUS status[20];
          IBASE_TLS_VARS;
          
          if(ib_trans->trans != NULL){
                  if(isc_rollback_transaction(status, &ib_trans->trans)){
! _php3_isc_interprete(status);
                  }
          }
          efree(ib_trans);
--- 115,180 ----
  ibase_module php3_ibase_module;
  #endif
  /* }}} */
+
+
+
+ #define RESET_ERRMSG { IBASE_GLOBAL(php3_ibase_module).errmsg[0] = '\0';}
+ #define TEST_ERRMSG ( IBASE_GLOBAL(php3_ibase_module).errmsg[0] != '\0')
+
+ /* {{{ 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);
+ }
+ RETURN_FALSE;
+ }
+ /* }}} */
  
! /* {{{ _php3_ibase_error(ISC_STATUS *status)
! 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);
          }
! php3_error(E_WARNING, "InterBase: %s",errmsg);
! }
! /* }}} */
!
! /* {{{ _php3_module_error(char *msg, ...)
! 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;
! int len;
!
! va_start(ap, msg);
! len = vsnprintf(errmsg, MAX_ERRMSG - 1, msg, ap);
! va_end(ap);
! errmsg[len] = '\0';
!
! php3_error(E_WARNING, "InterBase module: %s",errmsg);
  }
  /* }}} */
  
  /* {{{ _php3_ibase_rollback_trans() */
  static void _php3_ibase_rollback_trans(ibase_trans *ib_trans)
  {
          ISC_STATUS status[20];
          IBASE_TLS_VARS;
          
          if(ib_trans->trans != NULL){
                  if(isc_rollback_transaction(status, &ib_trans->trans)){
! _php3_ibase_error(status);
                  }
          }
          efree(ib_trans);
***************
*** 137,143 ****
  
          if(link->default_trans != NULL){
                  if(isc_rollback_transaction(status, &link->default_trans)){
! _php3_isc_interprete(status);
                  }
          }
          isc_detach_database(status, &link->link);
--- 189,195 ----
  
          if(link->default_trans != NULL){
                  if(isc_rollback_transaction(status, &link->default_trans)){
! _php3_ibase_error(status);
                  }
          }
          isc_detach_database(status, &link->link);
***************
*** 154,166 ****
  
          if(link->default_trans != NULL){
                  if(isc_rollback_transaction(status, &link->default_trans)){
! _php3_isc_interprete(status);
                  }
          }
          isc_detach_database(status, &link->link);
          php3_ibase_module.num_persistent--;
          php3_ibase_module.num_links--;
! efree(link);
  }
  /* }}} */
  
--- 206,218 ----
  
          if(link->default_trans != NULL){
                  if(isc_rollback_transaction(status, &link->default_trans)){
! _php3_ibase_error(status);
                  }
          }
          isc_detach_database(status, &link->link);
          php3_ibase_module.num_persistent--;
          php3_ibase_module.num_links--;
! free(link);
  }
  /* }}} */
  
***************
*** 171,178 ****
          ISC_STATUS status[20];
          IBASE_TLS_VARS;
  
! if (result->result_trans != NULL) { /*FIXME : commit or rollback?*/
! isc_commit_transaction(status, &result->result_trans);
          }
          if (result->sqlda != NULL) {
                  for (i = 0; i < result->sqlda->sqld; i++) {
--- 223,230 ----
          ISC_STATUS status[20];
          IBASE_TLS_VARS;
  
! if (result->trans_single) { /*FIXME : commit or rollback?*/
! isc_commit_transaction(status, &result->trans_handle);
          }
          if (result->sqlda != NULL) {
                  for (i = 0; i < result->sqlda->sqld; i++) {
***************
*** 192,199 ****
          int i;
          ISC_STATUS status[20];
  
! if (query->query_trans != NULL) { /*FIXME : commit or rollback?*/
! isc_commit_transaction(status, &query->query_trans);
          }
          if (query->sqlda != NULL) {
                  if (query->alloced) {
--- 244,251 ----
          int i;
          ISC_STATUS status[20];
  
! if (query->trans_single) { /*FIXME : commit or rollback?*/
! isc_commit_transaction(status, &query->trans_handle);
          }
          if (query->sqlda != NULL) {
                  if (query->alloced) {
***************
*** 238,243 ****
--- 290,296 ----
          IBASE_GLOBAL(php3_ibase_module).le_result = register_list_destructors(_php3_ibase_free_result, NULL);
          IBASE_GLOBAL(php3_ibase_module).le_query = register_list_destructors(_php3_ibase_free_query, NULL);
          IBASE_GLOBAL(php3_ibase_module).le_trans = register_list_destructors(_php3_ibase_rollback_trans, NULL);
+ 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(NULL, _php3_ibase_close_plink);
          return SUCCESS;
***************
*** 250,255 ****
--- 303,309 ----
          IBASE_GLOBAL(php3_ibase_module).default_link= -1;
          IBASE_GLOBAL(php3_ibase_module).num_links = php3_ibase_module.num_persistent;
          IBASE_GLOBAL(php3_ibase_module).timeformat = estrndup(IBASE_GLOBAL(php3_ibase_module).cfg_timeformat, strlen(IBASE_GLOBAL(php3_ibase_module).cfg_timeformat));
+ IBASE_GLOBAL(php3_ibase_module).errmsg = emalloc(sizeof(char)*MAX_ERRMSG);
          return SUCCESS;
  }
  
***************
*** 265,270 ****
--- 319,325 ----
          IBASE_TLS_VARS;
  
          efree(IBASE_GLOBAL(php3_ibase_module).timeformat);
+ efree(IBASE_GLOBAL(php3_ibase_module).errmsg);
          return SUCCESS;
  }
  
***************
*** 280,286 ****
          char dpb_buffer[256], *dpb, *p;
          int dpb_length, len;
          ISC_STATUS status[20];
- char msg[512];
  
          dpb = dpb_buffer;
  
--- 335,340 ----
***************
*** 328,338 ****
  
          dpb_length = dpb - dpb_buffer;
  
! isc_attach_database(status, strlen(server), server, db, dpb_length, dpb_buffer);
!
! if (status[0] == 1 && status[1]) {
! _php3_isc_interprete(status);
! php3_error(E_WARNING,"Unable to connect to InterBase server: %s", msg);
                          return 1;
          }
          return 0;
--- 382,389 ----
  
          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;
***************
*** 350,357 ****
          char *hashed_details;
          int hashed_details_length;
          ibase_db_link *ib_link;
! IBASE_TLS_VARS;
!
          ib_uname = IBASE_GLOBAL(php3_ibase_module).default_user;
          ib_passwd = IBASE_GLOBAL(php3_ibase_module).default_password;
          ib_uname_len = ib_uname ? strlen(ib_uname) : 0;
--- 401,410 ----
          char *hashed_details;
          int hashed_details_length;
          ibase_db_link *ib_link;
! IBASE_TLS_VARS;
!
! RESET_ERRMSG;
!
          ib_uname = IBASE_GLOBAL(php3_ibase_module).default_user;
          ib_passwd = IBASE_GLOBAL(php3_ibase_module).default_password;
          ib_uname_len = ib_uname ? strlen(ib_uname) : 0;
***************
*** 418,429 ****
                          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_error(E_WARNING,"InterBase: 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_error(E_WARNING,"InterBase: Too many open persistent links (%d)", IBASE_GLOBAL(php3_ibase_module).num_persistent);
                                  efree(hashed_details);
                                  RETURN_FALSE;
                          }
--- 471,482 ----
                          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;
                          }
***************
*** 462,469 ****
                  list_entry *index_ptr, new_index_ptr;
                  
                  /* first we check the hash for the hashed_details key. if it exists,
! * it should point us to the right offset where the actual pgsql ib_link sits.
! * if it doesn't, open a new pgsql ib_link, add it to the resource list,
                   * and add a pointer to it with hashed_details as the key.
                   */
                  if (_php3_hash_find(list,hashed_details,hashed_details_length+1,(void **) &index_ptr)==SUCCESS) {
--- 515,522 ----
                  list_entry *index_ptr, new_index_ptr;
                  
                  /* first we check the hash for the hashed_details key. if it exists,
! * it should point us to the right offset where the actual ib_link sits.
! * if it doesn't, open a new ib_link, add it to the resource list,
                   * and add a pointer to it with hashed_details as the key.
                   */
                  if (_php3_hash_find(list,hashed_details,hashed_details_length+1,(void **) &index_ptr)==SUCCESS) {
***************
*** 485,491 ****
                          }
                  }
                  if (IBASE_GLOBAL(php3_ibase_module).max_links!=-1 && IBASE_GLOBAL(php3_ibase_module).num_links>=IBASE_GLOBAL(php3_ibase_module).max_links) {
! php3_error(E_WARNING,"InterBase: Too many open links (%d)", IBASE_GLOBAL(php3_ibase_module).num_links);
                          efree(hashed_details);
                          RETURN_FALSE;
                  }
--- 538,544 ----
                          }
                  }
                  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;
                  }
***************
*** 541,549 ****
          pval *link_arg;
          ibase_db_link *ib_link;
          int link_id, type;
- isc_db_handle db_handle;
          IBASE_TLS_VARS;
          
          switch (ARG_COUNT(ht)) {
                  case 0:
                          link_id = IBASE_GLOBAL(php3_ibase_module).default_link;
--- 594,603 ----
          pval *link_arg;
          ibase_db_link *ib_link;
          int link_id, type;
          IBASE_TLS_VARS;
          
+ RESET_ERRMSG;
+
          switch (ARG_COUNT(ht)) {
                  case 0:
                          link_id = IBASE_GLOBAL(php3_ibase_module).default_link;
***************
*** 562,568 ****
          
          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_error(E_WARNING, "%d is not an InterBase link index",link_id);
                  RETURN_FALSE;
          }
          
--- 616,622 ----
          
          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 index",link_id);
                  RETURN_FALSE;
          }
          
***************
*** 583,595 ****
  
          if (isc_dsql_allocate_statement(status, &db, query_handle)) {
                  efree(isqlda);
! _php3_isc_interprete(status);
                  return NULL;
          }
  
          if (isc_dsql_prepare(status, &tr, query_handle, 0, query, 1, isqlda)) {
                  efree(isqlda);
! _php3_isc_interprete(status);
                  return NULL;
          }
          
--- 637,649 ----
  
          if (isc_dsql_allocate_statement(status, &db, query_handle)) {
                  efree(isqlda);
! _php3_ibase_error(status);
                  return NULL;
          }
  
          if (isc_dsql_prepare(status, &tr, query_handle, 0, query, 1, isqlda)) {
                  efree(isqlda);
! _php3_ibase_error(status);
                  return NULL;
          }
          
***************
*** 601,607 ****
  
          if (isc_dsql_describe_bind(status, query_handle, 1, isqlda)) {
                  efree(isqlda);
! _php3_isc_interprete(status);
                  return NULL;
          }
          
--- 655,661 ----
  
          if (isc_dsql_describe_bind(status, query_handle, 1, isqlda)) {
                  efree(isqlda);
! _php3_ibase_error(status);
                  return NULL;
          }
          
***************
*** 611,617 ****
                  isqlda->version = SQLDA_VERSION1;
                  if (isc_dsql_describe(status, query_handle, 1, isqlda)) {
                          efree(isqlda);
! _php3_isc_interprete(status);
                          return NULL;
                  }
                  return isqlda;
--- 665,671 ----
                  isqlda->version = SQLDA_VERSION1;
                  if (isc_dsql_describe(status, query_handle, 1, isqlda)) {
                          efree(isqlda);
! _php3_ibase_error(status);
                          return NULL;
                  }
                  return isqlda;
***************
*** 654,660 ****
  
                  if (isc_dsql_describe(status, &query_handle, 1, osqlda)) {
                          efree(osqlda);
! _php3_isc_interprete(status);
                          return NULL;
                  }
  
--- 708,714 ----
  
                  if (isc_dsql_describe(status, &query_handle, 1, osqlda)) {
                          efree(osqlda);
! _php3_ibase_error(status);
                          return NULL;
                  }
  
***************
*** 664,670 ****
                          osqlda->version = SQLDA_VERSION1;
                          if (isc_dsql_describe(status, &query_handle, 1, osqlda)) {
                                  efree(osqlda);
! _php3_isc_interprete(status);
                                  return NULL;
                          }
                  }
--- 718,724 ----
                          osqlda->version = SQLDA_VERSION1;
                          if (isc_dsql_describe(status, &query_handle, 1, osqlda)) {
                                  efree(osqlda);
! _php3_ibase_error(status);
                                  return NULL;
                          }
                  }
***************
*** 705,711 ****
                  if (isqlda == NULL) {
                          if (isc_dsql_execute(status, &tr_handle, &query_handle, 1, NULL)) {
                                  efree(osqlda);
! _php3_isc_interprete(status);
                                  return NULL;
                          } else {
                                  return osqlda;
--- 759,765 ----
                  if (isqlda == NULL) {
                          if (isc_dsql_execute(status, &tr_handle, &query_handle, 1, NULL)) {
                                  efree(osqlda);
! _php3_ibase_error(status);
                                  return NULL;
                          } else {
                                  return osqlda;
***************
*** 714,720 ****
                  } else {
                          if (isc_dsql_execute2(status, &tr_handle, &query_handle, 1, isqlda, osqlda)) {
                                  efree(osqlda);
! _php3_isc_interprete(status);
                                  return NULL;
                          } else {
                                  return osqlda;
--- 768,774 ----
                  } else {
                          if (isc_dsql_execute2(status, &tr_handle, &query_handle, 1, isqlda, osqlda)) {
                                  efree(osqlda);
! _php3_ibase_error(status);
                                  return NULL;
                          } else {
                                  return osqlda;
***************
*** 724,755 ****
          } else {
                  /* Not select */
                  if (isc_dsql_execute(status, &tr_handle, &query_handle, 1, isqlda)) {
! efree(osqlda);
! _php3_isc_interprete(status);
                          return NULL;
                  }
- /*
- if (!php3_ibase_module.manualtransactions) {
- if(0) {
- isc_commit_transaction(status, tr_handle);
- } else {
- isc_rollback_transaction(status, tr_handle);
- }
- }
- */
          }
  
          return NULL;
  }
  /* }}} */
  
  /* {{{ proto int ibase_trans([int link_identifier, ][string trans_args])
     Start transaction */
  void php3_ibase_trans(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *link_arg, *trans_arg;
          char tpb[20], *tpbp = NULL, *trans_args = NULL;
! int tpb_len = 0, link_id, trans_id, type, trans_def = 0, slot;
          ibase_db_link *ib_link;
          ibase_trans *ib_trans;
          isc_tr_handle tr_handle = NULL;
--- 778,814 ----
          } else {
                  /* Not select */
                  if (isc_dsql_execute(status, &tr_handle, &query_handle, 1, isqlda)) {
! _php3_ibase_error(status);
                          return NULL;
                  }
          }
  
          return NULL;
  }
  /* }}} */
  
+
+ #define GET_TRANS_ARG(trans_arg,trans_ptr) { \
+ int type; \
+ convert_to_long(trans_arg); \
+ trans_ptr = (ibase_trans *) php3_list_find(trans_arg->value.lval, &type);\
+ if (type!=IBASE_GLOBAL(php3_ibase_module).le_trans) {\
+ _php3_module_error("%d is not transaction index",trans_arg->value.lval);\
+ RETURN_FALSE;\
+ } \
+ }
+
+ #define TRANS_HANDLE(ib_trans,ib_link) \
+ (ib_trans ? ib_trans->trans : (ib_link->default_trans ? ib_link->default_trans : 0))
+
+
  /* {{{ proto int ibase_trans([int link_identifier, ][string trans_args])
     Start transaction */
  void php3_ibase_trans(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *link_arg, *trans_arg;
          char tpb[20], *tpbp = NULL, *trans_args = NULL;
! int tpb_len = 0, link_id, trans_id, type, trans_def = 0;
          ibase_db_link *ib_link;
          ibase_trans *ib_trans;
          isc_tr_handle tr_handle = NULL;
***************
*** 757,762 ****
--- 816,823 ----
          IBASE_TLS_VARS;
          
  
+ RESET_ERRMSG;
+
          switch (ARG_COUNT(ht)) {
                  case 0:
                          link_id = IBASE_GLOBAL(php3_ibase_module).default_link;
***************
*** 784,816 ****
          }
          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_error(E_WARNING, "%d is not an InterBase link index",link_id);
                  RETURN_FALSE;
          }
          if(trans_args){
                  tpb[tpb_len++] = isc_tpb_version3;
! tpbp = tpb;
! if(strstr(trans_args,"DEFAULT")){
                          trans_def = 1;
                          if(ib_link->default_trans != NULL){
! php3_error(E_WARNING, "InterBase: DEFAULT transaction already started");
                                  RETURN_FALSE;
                          }
                  }
                  /* access mode */
! if(strstr(trans_args,"READ")) /* READ ONLY TRANSACTION */
                          tpb[tpb_len++] = isc_tpb_read;
                  else
                          tpb[tpb_len++] = isc_tpb_write;
                  /* isolation level */
! if(strstr(trans_args,"COMMITED"))
                          tpb[tpb_len++] = isc_tpb_read_committed;
! else if (strstr(trans_args,"CONSISTENCY"))
                          tpb[tpb_len++] = isc_tpb_consistency;
                  else
                          tpb[tpb_len++] = isc_tpb_concurrency;
                  /* lock resolution */
! if(strstr(trans_args,"NOWAIT"))
                          tpb[tpb_len++] = isc_tpb_nowait;
                  else
                          tpb[tpb_len++] = isc_tpb_wait;
--- 845,877 ----
          }
          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 index",link_id);
                  RETURN_FALSE;
          }
          if(trans_args){
                  tpb[tpb_len++] = isc_tpb_version3;
! tpbp = tpb;
! if(strstr(trans_args,"DEFAULT")||strstr(trans_args,"default")){
                          trans_def = 1;
                          if(ib_link->default_trans != NULL){
! _php3_module_error("default transaction already started");
                                  RETURN_FALSE;
                          }
                  }
                  /* access mode */
! if(strstr(trans_args,"READ")||strstr(trans_args,"read")) /* READ ONLY TRANSACTION */
                          tpb[tpb_len++] = isc_tpb_read;
                  else
                          tpb[tpb_len++] = isc_tpb_write;
                  /* isolation level */
! if(strstr(trans_args,"COMMITED")||strstr(trans_args,"commited"))
                          tpb[tpb_len++] = isc_tpb_read_committed;
! else if (strstr(trans_args,"CONSISTENCY")||strstr(trans_args,"consistency"))
                          tpb[tpb_len++] = isc_tpb_consistency;
                  else
                          tpb[tpb_len++] = isc_tpb_concurrency;
                  /* lock resolution */
! if(strstr(trans_args,"NOWAIT")||strstr(trans_args,"nowait"))
                          tpb[tpb_len++] = isc_tpb_nowait;
                  else
                          tpb[tpb_len++] = isc_tpb_wait;
***************
*** 818,824 ****
          }
  
          if (isc_start_transaction(status, &tr_handle, 1, &ib_link->link, tpb_len, tpbp)) {
! _php3_isc_interprete(status);
                  RETURN_FALSE;
          }
  
--- 879,885 ----
          }
  
          if (isc_start_transaction(status, &tr_handle, 1, &ib_link->link, tpb_len, tpbp)) {
! _php3_ibase_error(status);
                  RETURN_FALSE;
          }
  
***************
*** 842,851 ****
          pval *trans_arg;
          int trans_id, type;
          ibase_db_link *ib_link;
! ibase_trans *ib_trans;
          isc_tr_handle tr_handle;
          ISC_STATUS status[20];
! IBASE_TLS_VARS;
  
          switch (ARG_COUNT(ht)) {
                  case 0:
--- 903,915 ----
          pval *trans_arg;
          int trans_id, type;
          ibase_db_link *ib_link;
! ibase_trans *ib_trans = NULL;
          isc_tr_handle tr_handle;
          ISC_STATUS status[20];
! IBASE_TLS_VARS;
!
!
! RESET_ERRMSG;
  
          switch (ARG_COUNT(ht)) {
                  case 0:
***************
*** 872,899 ****
                  ib_link = NULL; /* manual transaction */
                  tr_handle = ib_trans->trans;
          }else{
! php3_error(E_WARNING, "%d is not an InterBase link or transaction index",trans_id);
                  RETURN_FALSE;
          }
  
          if (commit) {
                  if(isc_commit_transaction(status, &tr_handle)){
! _php3_isc_interprete(status);
! RETURN_FALSE;
                  }
          }else{
                  if(isc_rollback_transaction(status, &tr_handle)){
! _php3_isc_interprete(status);
! RETURN_FALSE;
                  }
          }
  
! if(ib_link){ /* default transaction */
! ib_link->default_trans = NULL;
! }else{ /* manual transaction */
                  ib_trans->trans = NULL; /* already commited or rolled...*/
! php3_list_delete(trans_id);
! }
          
          RETURN_TRUE;
  }
--- 936,963 ----
                  ib_link = NULL; /* manual transaction */
                  tr_handle = ib_trans->trans;
          }else{
! _php3_module_error("%d is not link or transaction index",trans_id);
                  RETURN_FALSE;
          }
  
          if (commit) {
                  if(isc_commit_transaction(status, &tr_handle)){
! _php3_ibase_error(status);
! RETURN_FALSE;
                  }
          }else{
                  if(isc_rollback_transaction(status, &tr_handle)){
! _php3_ibase_error(status);
! RETURN_FALSE;
                  }
          }
  
! if(ib_link){ /* default transaction */
! ib_link->default_trans = NULL;
! }else{ /* manual transaction */
                  ib_trans->trans = NULL; /* already commited or rolled...*/
! php3_list_delete(trans_id);
! }
          
          RETURN_TRUE;
  }
***************
*** 903,909 ****
     Commit transaction */
  void php3_ibase_commit(INTERNAL_FUNCTION_PARAMETERS)
  {
! _php3_ibase_trans_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, COMMIT);
  }
  /* }}} */
  
--- 967,973 ----
     Commit transaction */
  void php3_ibase_commit(INTERNAL_FUNCTION_PARAMETERS)
  {
! _php3_ibase_trans_end(INTERNAL_FUNCTION_PARAM_PASSTHRU, COMMIT);
  }
  /* }}} */
  
***************
*** 915,935 ****
  }
  /* }}} */
  
! /* {{{ proto int ibase_query([int link_identifier, ]string query)
! Execute a query (without parameter placeholders). */
  void php3_ibase_query(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *link_arg, *query_arg, *trans_arg;
! int link_id, trans_id = 0, type, trans_query = 0;
          ibase_db_link *ib_link;
          ibase_trans *ib_trans;
! isc_tr_handle tr_handle = NULL;
          isc_stmt_handle query_handle = NULL;
          ISC_STATUS status[20];
          XSQLDA *isqlda, *osqlda;
          ibase_result_handle *ibase_result;
! IBASE_TLS_VARS;
  
          switch (ARG_COUNT(ht)) {
                  case 1:
                          if (getParameters(ht, 1, &query_arg) == FAILURE) {
--- 979,1001 ----
  }
  /* }}} */
  
! /* {{{ proto int ibase_query([int link_identifier, ]string query[, trans])
! Execute a query (without parameter placeholders). */
  void php3_ibase_query(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *link_arg, *query_arg, *trans_arg;
! int link_id, type, trans_single = 0;
          ibase_db_link *ib_link;
          ibase_trans *ib_trans;
! isc_tr_handle trans_handle = NULL;
          isc_stmt_handle query_handle = NULL;
          ISC_STATUS status[20];
          XSQLDA *isqlda, *osqlda;
          ibase_result_handle *ibase_result;
! IBASE_TLS_VARS;
  
+ RESET_ERRMSG;
+
          switch (ARG_COUNT(ht)) {
                  case 1:
                          if (getParameters(ht, 1, &query_arg) == FAILURE) {
***************
*** 949,957 ****
                                  RETURN_FALSE;
                          }
                          convert_to_long(link_arg);
! link_id = link_arg->value.lval;
! convert_to_long(trans_arg);
! trans_id = trans_arg->value.lval;
                          break;
                  default:
                          WRONG_PARAM_COUNT;
--- 1015,1022 ----
                                  RETURN_FALSE;
                          }
                          convert_to_long(link_arg);
! link_id = link_arg->value.lval;
! GET_TRANS_ARG(trans_arg,ib_trans);
                          break;
                  default:
                          WRONG_PARAM_COUNT;
***************
*** 960,1012 ****
          
          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_error(E_WARNING, "%d is not an InterBase link index",link_id);
                  RETURN_FALSE;
! }
  
! if(trans_id != 0){ /* manual transaction */
! ib_trans = (ibase_trans *) php3_list_find(trans_id, &type);
! if (type!=IBASE_GLOBAL(php3_ibase_module).le_trans) {
! php3_error(E_WARNING, "%d is not an InterBase transaction index",trans_id);
! RETURN_FALSE;
! }
! tr_handle = ib_trans->trans;
! }else if (ib_link->default_trans == NULL) { /* separate transaction */
! trans_query = 1;
! if (isc_start_transaction(status, &tr_handle, 1, &ib_link->link, 0, NULL)) {
! _php3_isc_interprete(status);
! RETURN_FALSE;
! }
! } else
! tr_handle = ib_link->default_trans;
!
          convert_to_string(query_arg);
  
! isqlda = _php3_ibase_prepare(ib_link->link, tr_handle, &query_handle, query_arg->value.str.val);
          if (isqlda != NULL) {
! if(trans_query)
! isc_rollback_transaction(status, &tr_handle);
                  isc_dsql_free_statement(status, &query_handle, DSQL_drop);
! php3_error(E_WARNING, "InterBase: ibase_query doesn't support parameter placeholders in query");
                  RETURN_FALSE;
          }
  
! osqlda = _php3_ibase_execute(tr_handle, query_handle, isqlda, status);
          if (osqlda != NULL) {
                  ibase_result = (ibase_result_handle *) emalloc(sizeof(ibase_result_handle));
                  ibase_result->result = query_handle;
                  ibase_result->sqlda = osqlda;
! ibase_result->result_trans = trans_query ? tr_handle : 0;
! return_value->value.lval = php3_list_insert(ibase_result, php3_ibase_module.le_result);
! return_value->type = IS_LONG;
          } else {
! if (trans_query) {
! if (status[0] == 1 && status[1]) {
! isc_rollback_transaction(status, &tr_handle);
                                  isc_dsql_free_statement(status, &query_handle, DSQL_drop);
                                  RETURN_FALSE;
                          } else {
! isc_commit_transaction(status, &tr_handle);
                                  isc_dsql_free_statement(status, &query_handle, DSQL_drop);
                                  RETURN_TRUE;
                          }
--- 1025,1075 ----
          
          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 index",link_id);
                  RETURN_FALSE;
! }
  
! trans_handle = TRANS_HANDLE(ib_trans,ib_link);
!
! trans_single = (trans_handle == NULL);
! if(trans_single){
! if (isc_start_transaction(status, &trans_handle, 1, &ib_link->link, 0, NULL)) {
! _php3_ibase_error(status);
! RETURN_FALSE;
! }
! }
!
          convert_to_string(query_arg);
  
! isqlda = _php3_ibase_prepare(ib_link->link, trans_handle, &query_handle, query_arg->value.str.val);
! if(TEST_ERRMSG){
! RETURN_FALSE;
! }
          if (isqlda != NULL) {
! if(trans_single)
! isc_rollback_transaction(status, &trans_handle);
                  isc_dsql_free_statement(status, &query_handle, DSQL_drop);
! _php3_module_error("ibase_query doesn't support parameter placeholders in query");
                  RETURN_FALSE;
          }
  
! osqlda = _php3_ibase_execute(trans_handle, query_handle, isqlda, status);
          if (osqlda != NULL) {
                  ibase_result = (ibase_result_handle *) emalloc(sizeof(ibase_result_handle));
                  ibase_result->result = query_handle;
                  ibase_result->sqlda = osqlda;
! ibase_result->trans_handle = trans_handle;
! ibase_result->trans_single = trans_single;
! ibase_result->link = ib_link->link;
! RETURN_LONG(php3_list_insert(ibase_result, php3_ibase_module.le_result));
          } else {
! if (trans_single) {
! if (status[0] && status[1]) {
! isc_rollback_transaction(status, &trans_handle);
                                  isc_dsql_free_statement(status, &query_handle, DSQL_drop);
                                  RETURN_FALSE;
                          } else {
! isc_commit_transaction(status, &trans_handle);
                                  isc_dsql_free_statement(status, &query_handle, DSQL_drop);
                                  RETURN_TRUE;
                          }
***************
*** 1015,1025 ****
  }
  /* }}} */
  
  /* {{{ _php3_ibase_fetch_hash() */
  static void _php3_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *result_var;
! int type, i, collen;
          char string_data[255], *char_data;
          ibase_result_handle *ibase_result;
          ISC_STATUS status[20];
--- 1078,1089 ----
  }
  /* }}} */
  
+
  /* {{{ _php3_ibase_fetch_hash() */
  static void _php3_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *result_arg, *blflag_arg;
! int type, blobchar = 0, i, collen;
          char string_data[255], *char_data;
          ibase_result_handle *ibase_result;
          ISC_STATUS status[20];
***************
*** 1027,1047 ****
          IBASE_VCHAR *vchar;
          IBASE_TLS_VARS;
  
  
! if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &result_var)==FAILURE) {
! WRONG_PARAM_COUNT;
! }
          
- convert_to_long(result_var);
- ibase_result = (ibase_result_handle *) php3_list_find(result_var->value.lval, &type);
-
          if (type!=IBASE_GLOBAL(php3_ibase_module).le_result) {
! php3_error(E_WARNING,"%d is not an InterBase result index", result_var->value.lval);
                  RETURN_FALSE;
          }
  
          if (ibase_result->sqlda == NULL) {
! php3_error(E_WARNING,"InterBase: trying to fetch results from a non-select query");
                  RETURN_FALSE;
          }
  
--- 1091,1132 ----
          IBASE_VCHAR *vchar;
          IBASE_TLS_VARS;
  
+ RESET_ERRMSG;
  
! switch(ARG_COUNT(ht)){
! case 1:
! if (ARG_COUNT(ht)==1 && getParameters(ht, 1, &result_arg)==FAILURE) {
! RETURN_FALSE;
! }
! break;
! case 2:
! if(ARG_COUNT(ht)==2 && getParameters(ht, 2, &result_arg, &blflag_arg)==FAILURE) {
! RETURN_FALSE;
! }
! convert_to_string(blflag_arg);
! if(strcasecmp(blflag_arg->value.str.val,"TEXT")){ /* FIXME: need? */
! _php3_module_error("invalid blob flag '%s'", blflag_arg->value.str.val);
! RETURN_FALSE;
! }else{
! blobchar = 1;
! }
! break;
! default:
! WRONG_PARAM_COUNT;
! break;
!
! }
!
! convert_to_long(result_arg);
! ibase_result = (ibase_result_handle *) php3_list_find(result_arg->value.lval, &type);
          
          if (type!=IBASE_GLOBAL(php3_ibase_module).le_result) {
! _php3_module_error("%d is not result index", result_arg->value.lval);
                  RETURN_FALSE;
          }
  
          if (ibase_result->sqlda == NULL) {
! _php3_module_error("trying to fetch results from a non-select query");
                  RETURN_FALSE;
          }
  
***************
*** 1062,1073 ****
                                                  if (php3_ini.magic_quotes_runtime) {
                                                          int newlen;
                                                          char *tmp = _php3_addslashes(char_data, collen, &newlen, 0);
! add_get_index_stringl(return_value, i, tmp, newlen, (void **) &result_var, 0);
                                                  } else {
! add_get_index_stringl(return_value, i, char_data, collen, (void **) &result_var, 1);
                                                  }
! _php3_hash_pointer_update(return_value->value.ht, var->sqlname, var->sqlname_length+1, result_var);
! efree(char_data);
                                          }
                                          break;
                                  case SQL_VARYING:
--- 1147,1158 ----
                                                  if (php3_ini.magic_quotes_runtime) {
                                                          int newlen;
                                                          char *tmp = _php3_addslashes(char_data, collen, &newlen, 0);
! efree(char_data);
! add_get_index_stringl(return_value, i, tmp, newlen, (void **) &result_arg, 0);
                                                  } else {
! add_get_index_stringl(return_value, i, char_data, collen, (void **) &result_arg, 0);
                                                  }
! _php3_hash_pointer_update(return_value->value.ht, var->aliasname, var->aliasname_length+1, result_arg);
                                          }
                                          break;
                                  case SQL_VARYING:
***************
*** 1078,1095 ****
                                                  if (php3_ini.magic_quotes_runtime) {
                                                         &n