Skip to content

Commit

Permalink
Added clean up code for persistent connections to avoid some problems…
Browse files Browse the repository at this point in the history
… with

autocommit.
  • Loading branch information
Hénot David committed Sep 29, 2000
1 parent 5844b74 commit a68a224
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 40 additions & 1 deletion ext/ingres_ii/ii.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,42 @@ static void _close_ii_plink(II_LINK *link)
IIG(num_persistent)--;
}

/* cleans up the given persistent link.
used when the request ends to 'refresh' the link for use
by the next request
*/
static void _clean_ii_plink(II_LINK *link)
{
IIAPI_AUTOPARM autoParm;
IILS_FETCH();

if(link->autocommit) {

if(link->stmtHandle && _close_statement(link)) {
php_error(E_WARNING,"Ingres II: Unable to close statement !!");
}

autoParm.ac_genParm.gp_callback = NULL;
autoParm.ac_genParm.gp_closure = NULL;
autoParm.ac_connHandle = link->connHandle;
autoParm.ac_tranHandle = link->tranHandle;

IIapi_autocommit(&autoParm);
ii_sync(&(autoParm.ac_genParm));

if(ii_success(&(autoParm.ac_genParm))==II_FAIL) {
php_error(E_WARNING,"Ingres II: Unable to disable autocommit");
}

link->autocommit = 0;
link->tranHandle = NULL;
}

if(link->tranHandle && _rollback_transaction(link)) {
php_error(E_WARNING,"Ingres II: Unable to rollback transaction !!");
}
}

/* sets the default link
*/
static void php_ii_set_default_link(int id)
Expand Down Expand Up @@ -212,7 +248,7 @@ PHP_MINIT_FUNCTION(ii)
REGISTER_INI_ENTRIES();

le_ii_link = register_list_destructors(_close_ii_link,NULL);
le_ii_plink = register_list_destructors(NULL,_close_ii_plink);
le_ii_plink = register_list_destructors(_clean_ii_plink,_close_ii_plink);

IIG(num_persistent) = 0;

Expand Down Expand Up @@ -444,6 +480,7 @@ static void php_ii_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent)
link->stmtHandle = NULL;
link->fieldCount = 0;
link->descriptor = NULL;
link->autocommit = 0;

/* hash it up */
new_le.type = le_ii_plink;
Expand Down Expand Up @@ -526,6 +563,7 @@ static void php_ii_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent)
link->stmtHandle = NULL;
link->fieldCount = 0;
link->descriptor = NULL;
link->autocommit = 0;

/* add it to the list */
ZEND_REGISTER_RESOURCE(return_value, link, le_ii_link);
Expand Down Expand Up @@ -1324,6 +1362,7 @@ PHP_FUNCTION(ingres_autocommit)
RETURN_FALSE;
}

ii_link->autocommit = (ii_link->autocommit ? 0 : 1);
ii_link->tranHandle = autoParm.ac_tranHandle;
RETURN_TRUE;
}
Expand Down
2 changes: 2 additions & 0 deletions ext/ingres_ii/ii.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "iiapi.h"

typedef struct _II_LINK {
int autocommit;
II_PTR connHandle;
II_PTR tranHandle;
II_PTR stmtHandle;
Expand All @@ -45,6 +46,7 @@ static int _close_statement(II_LINK *link);
static int _rollback_transaction(II_LINK *link);
static void _close_ii_link(II_LINK *link);
static void _close_ii_plink(II_LINK *link);
static void _clean_ii_plink(II_LINK *link);
static int php_ii_get_default_link(INTERNAL_FUNCTION_PARAMETERS IILS_DC);
static void php_ii_set_default_link(int id);
static void php_ii_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent);
Expand Down

0 comments on commit a68a224

Please sign in to comment.