From c69d034a876333863b3942db4651bfd1484970df Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Sun, 29 Dec 2002 15:32:38 +0000 Subject: Added support for db3/db4 error handling/information --- ext/dba/dba_db4.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'ext/dba/dba_db4.c') diff --git a/ext/dba/dba_db4.c b/ext/dba/dba_db4.c index 6cb2debcd7..5de50df2c7 100644 --- a/ext/dba/dba_db4.c +++ b/ext/dba/dba_db4.c @@ -35,6 +35,13 @@ #include #endif +static void php_dba_db4_errcall_fcn(const char *errpfx, char *msg) +{ + TSRMLS_FETCH(); + + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s%s", errpfx?errpfx:"", msg); +} + #define DB4_DATA dba_db4_data *dba = info->dbf #define DB4_GKEY \ DBT gkey; \ @@ -50,7 +57,7 @@ DBA_OPEN_FUNC(db4) { DB *dbp = NULL; DBTYPE type; - int gmode = 0; + int gmode = 0, err; int filemode = 0644; struct stat check_stat; int s = VCWD_STAT(info->path, &check_stat); @@ -73,22 +80,28 @@ DBA_OPEN_FUNC(db4) filemode = Z_LVAL_PP(info->argv[0]); } - if (db_create(&dbp, NULL, 0) == 0 && + if ((err=db_create(&dbp, NULL, 0)) == 0) { + dbp->set_errcall(dbp, php_dba_db4_errcall_fcn); + if ( #if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1) - dbp->open(dbp, 0, info->path, NULL, type, gmode, filemode) == 0) { + (err=dbp->open(dbp, 0, info->path, NULL, type, gmode, filemode)) == 0) { #else - dbp->open(dbp, info->path, NULL, type, gmode, filemode) == 0) { + (err=dbp->open(dbp, info->path, NULL, type, gmode, filemode)) == 0) { #endif - dba_db4_data *data; + dba_db4_data *data; - data = pemalloc(sizeof(*data), info->flags&DBA_PERSISTENT); - data->dbp = dbp; - data->cursor = NULL; - info->dbf = data; + data = pemalloc(sizeof(*data), info->flags&DBA_PERSISTENT); + data->dbp = dbp; + data->cursor = NULL; + info->dbf = data; - return SUCCESS; - } else if (dbp != NULL) { - dbp->close(dbp, 0); + return SUCCESS; + } else { + dbp->close(dbp, 0); + *error = db_strerror(err); + } + } else { + *error = db_strerror(err); } return FAILURE; -- cgit v1.2.1