helly Fri Feb 25 18:51:53 2005 EDT
Added files:
/php-src/ext/dba dba_db1.c php_db1.h
/php-src/ext/dba/tests dba_db1.phpt
Modified files:
/php-src/ext/dba config.m4 dba.c
Log:
- Add support for db1 through emulation
# Most probably db4 requires a slightly different detection since functions
# are macros which most probably doesn't work with current configure check.
http://cvs.php.net/diff.php/php-src/ext/dba/config.m4?r1=1.65&r2=1.66&ty=u
Index: php-src/ext/dba/config.m4
diff -u php-src/ext/dba/config.m4:1.65 php-src/ext/dba/config.m4:1.66
--- php-src/ext/dba/config.m4:1.65 Fri Feb 25 15:02:45 2005
+++ php-src/ext/dba/config.m4 Fri Feb 25 18:51:51 2005
@@ -1,5 +1,5 @@
dnl
-dnl $Id: config.m4,v 1.65 2005/02/25 20:02:45 helly Exp $
+dnl $Id: config.m4,v 1.66 2005/02/25 23:51:51 helly Exp $
dnl
dnl Suppose we need FlatFile if no support or only CDB is used.
@@ -226,6 +226,9 @@
AC_DEFINE_UNQUOTED(DB$1_INCLUDE_FILE, "$THIS_INCLUDE", [ ])
fi
fi
+ DB$1_LIBS=$THIS_LIBS
+ DB$1_PREFIX=$THIS_PREFIX
+ DB$1_INCLUDE=$THIS_INCLUDE
PHP_DBA_STD_ASSIGN
PHP_DBA_STD_CHECK
PHP_DBA_STD_ATTACH
@@ -333,6 +336,66 @@
])
AC_DBA_STD_RESULT(db2,Berkeley DB2)
+AC_ARG_WITH(db1,
+[ --with-db1[=DIR] DBA: Include Berkeley DB1 support/emulation],[
+ if test "$withval" != "no"; then
+ PHP_DBA_STD_BEGIN
+ AC_MSG_CHECKING(for DB1 in library)
+ if test "$HAVE_DB4" = "1"; then
+ THIS_VERSION=4
+ THIS_LIBS=$DB4_LIBS
+ THIS_PREFIX=$DB4_PREFIX
+ elif test "$HAVE_DB3" = "1"; then
+ THIS_LIBS=$DB3_LIBS
+ THIS_PREFIX=$DB3_PREFIX
+ elif test "$HAVE_DB2" = "1"; then
+ THIS_VERSION=2
+ THIS_LIBS=$DB2_LIBS
+ THIS_PREFIX=$DB2_PREFIX
+ fi
+ if test "$HAVE_DB4" = "1" -o "$HAVE_DB3" = "1" -o "$HAVE_DB2" = "1"; then
+ AC_DEFINE_UNQUOTED(DB1_VERSION, "Berkeley DB 1.85 emulation in
DB$THIS_VERSION", [ ])
+ for i in db$THIS_VERSION/db_185.h include/db$THIS_VERSION/db_185.h
include/db/db_185.h; do
+ if test -f "$THIS_PREFIX/$i"; then
+ THIS_INCLUDE=$THIS_PREFIX/$i
+ break
+ fi
+ done
+ else
+ AC_DEFINE_UNQUOTED(DB1_VERSION, "Unknown DB1", [ ])
+ for i in $withval /usr/local /usr; do
+ if test -f "$i/db1/db.h"; then
+ THIS_PREFIX=$i
+ THIS_INCLUDE=$i/db1/db.h
+ break
+ elif test -f "$i/include/db1/db.h"; then
+ THIS_PREFIX=$i
+ THIS_INCLUDE=$i/include/db1/db.h
+ break
+ elif test -f "$i/include/db.h"; then
+ THIS_PREFIX=$i
+ THIS_INCLUDE=$i/include/db.h
+ break
+ fi
+ done
+ THIS_LIBS=db
+ fi
+ AC_MSG_RESULT($THIS_LIBS)
+ AC_MSG_CHECKING(for DB1 in header)
+ AC_MSG_RESULT($THIS_INCLUDE)
+ if test -n "$THIS_INCLUDE"; then
+ PHP_CHECK_LIBRARY($THIS_LIBS, dbopen, [
+ AC_DEFINE_UNQUOTED(DB1_INCLUDE_FILE, "$THIS_INCLUDE", [ ])
+ AC_DEFINE(DBA_DB1, 1, [ ])
+ ])
+ fi
+ PHP_DBA_STD_ASSIGN
+ PHP_DBA_STD_CHECK
+ PHP_DBA_STD_ATTACH
+ fi
+])
+AC_DBA_STD_RESULT(db1,DB1)
+
AC_ARG_WITH(dbm,
[ --with-dbm[=DIR] DBA: Include DBM support],[
if test "$withval" != "no"; then
@@ -469,7 +532,7 @@
if test "$HAVE_DBA" = "1"; then
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_DBA, 1, [ ])
- PHP_NEW_EXTENSION(dba, dba.c dba_cdb.c dba_db2.c dba_dbm.c dba_gdbm.c
dba_ndbm.c dba_db3.c dba_db4.c dba_flatfile.c dba_inifile.c dba_qdbm.c
$cdb_sources $flat_sources $ini_sources, $ext_shared)
+ PHP_NEW_EXTENSION(dba, dba.c dba_cdb.c dba_dbm.c dba_gdbm.c dba_ndbm.c
dba_db1.c dba_db2.c dba_db3.c dba_db4.c dba_flatfile.c dba_inifile.c dba_qdbm.c
$cdb_sources $flat_sources $ini_sources, $ext_shared)
PHP_ADD_BUILD_DIR($ext_builddir/libinifile)
PHP_ADD_BUILD_DIR($ext_builddir/libcdb)
PHP_ADD_BUILD_DIR($ext_builddir/libflatfile)
http://cvs.php.net/diff.php/php-src/ext/dba/dba.c?r1=1.109&r2=1.110&ty=u
Index: php-src/ext/dba/dba.c
diff -u php-src/ext/dba/dba.c:1.109 php-src/ext/dba/dba.c:1.110
--- php-src/ext/dba/dba.c:1.109 Thu Jan 8 03:14:39 2004
+++ php-src/ext/dba/dba.c Fri Feb 25 18:51:51 2005
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dba.c,v 1.109 2004/01/08 08:14:39 andi Exp $ */
+/* $Id: dba.c,v 1.110 2005/02/25 23:51:51 helly Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -43,6 +43,7 @@
#include "php_ndbm.h"
#include "php_dbm.h"
#include "php_cdb.h"
+#include "php_db1.h"
#include "php_db2.h"
#include "php_db3.h"
#include "php_db4.h"
@@ -239,6 +240,9 @@
#if DBA_CDB_BUILTIN
DBA_NAMED_HND(cdb_make, cdb, DBA_STREAM_OPEN|DBA_LOCK_ALL) /* No lock in
lib */
#endif
+#if DBA_DB1
+ DBA_HND(db1, DBA_LOCK_ALL) /* No lock in lib */
+#endif
#if DBA_DB2
DBA_HND(db2, DBA_LOCK_ALL) /* No lock in lib */
#endif
@@ -268,6 +272,8 @@
#define DBA_DEFAULT "db3"
#elif DBA_DB2
#define DBA_DEFAULT "db2"
+#elif DBA_DB1
+#define DBA_DEFAULT "db1"
#elif DBA_GDBM
#define DBA_DEFAULT "gdbm"
#elif DBA_NBBM
http://cvs.php.net/co.php/php-src/ext/dba/dba_db1.c?r=1.1&p=1
Index: php-src/ext/dba/dba_db1.c
+++ php-src/ext/dba/dba_db1.c
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2004 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.0 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_0.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [EMAIL PROTECTED] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Shen Cheng-Da <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
/* $Id: dba_db1.c,v 1.1 2005/02/25 23:51:51 helly Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#if DBA_DB1
#include "php_db1.h"
#ifdef DB1_INCLUDE_FILE
#include DB1_INCLUDE_FILE
#endif
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define DB1_DATA dba_db1_data *dba = info->dbf
#define DB1_GKEY DBT gkey; gkey.data = (char *) key; gkey.size = keylen
typedef struct {
DB *dbp;
} dba_db1_data;
DBA_OPEN_FUNC(db1)
{
dba_db1_data *dba;
DB *db;
int gmode;
int filemode = 0644;
if (info->argc > 0) {
convert_to_long_ex(info->argv[0]);
filemode = Z_LVAL_PP(info->argv[0]);
}
gmode = 0;
switch (info->mode) {
case DBA_READER:
gmode = O_RDONLY;
break;
case DBA_WRITER:
gmode = O_RDWR;
break;
case DBA_CREAT:
gmode = O_RDWR | O_CREAT;
break;
case DBA_TRUNC:
gmode = O_RDWR | O_CREAT | O_TRUNC;
break;
default:
return FAILURE; /* not possible */
}
db = dbopen((char *)info->path, gmode, filemode, DB_HASH, NULL);
if (db == NULL) {
return FAILURE;
}
dba = pemalloc(sizeof(*dba), info->flags&DBA_PERSISTENT);
dba->dbp = db;
info->dbf = dba;
return SUCCESS;
}
DBA_CLOSE_FUNC(db1)
{
DB1_DATA;
dba->dbp->close(dba->dbp);
pefree(info->dbf, info->flags&DBA_PERSISTENT);
}
DBA_FETCH_FUNC(db1)
{
DBT gval;
DB1_DATA;
DB1_GKEY;
char *new = NULL;
memset(&gval, 0, sizeof(gval));
if (dba->dbp->get(dba->dbp, &gkey, &gval, 0) == RET_SUCCESS) {
if (newlen) *newlen = gval.size;
new = estrndup(gval.data, gval.size);
}
return new;
}
DBA_UPDATE_FUNC(db1)
{
DBT gval;
DB1_DATA;
DB1_GKEY;
gval.data = (char *) val;
gval.size = vallen;
return dba->dbp->put(dba->dbp, &gkey, &gval, mode == 1 ? R_NOOVERWRITE
: 0) != RET_SUCCESS ? FAILURE : SUCCESS;
}
DBA_EXISTS_FUNC(db1)
{
DBT gval;
DB1_DATA;
DB1_GKEY;
return dba->dbp->get(dba->dbp, &gkey, &gval, 0) != RET_SUCCESS ?
FAILURE : SUCCESS;
}
DBA_DELETE_FUNC(db1)
{
DB1_DATA;
DB1_GKEY;
return dba->dbp->del(dba->dbp, &gkey, 0) != RET_SUCCESS ? FAILURE :
SUCCESS;
}
DBA_FIRSTKEY_FUNC(db1)
{
DBT gkey;
DBT gval;
DB1_DATA;
char *key = NULL;
memset(&gkey, 0, sizeof(gkey));
memset(&gval, 0, sizeof(gval));
if (dba->dbp->seq(dba->dbp, &gkey, &gval, R_FIRST) == RET_SUCCESS) {
if (newlen) *newlen = gkey.size;
key = estrndup(gkey.data, gkey.size);
}
return key;
}
DBA_NEXTKEY_FUNC(db1)
{
DBT gkey;
DBT gval;
DB1_DATA;
char *key = NULL;
memset(&gkey, 0, sizeof(gkey));
memset(&gval, 0, sizeof(gval));
if (dba->dbp->seq(dba->dbp, &gkey, &gval, R_NEXT) == RET_SUCCESS) {
if (newlen) *newlen = gkey.size;
key = estrndup(gkey.data, gkey.size);
}
return key;
}
DBA_OPTIMIZE_FUNC(db1)
{
/* dummy */
return SUCCESS;
}
DBA_SYNC_FUNC(db1)
{
return SUCCESS;
}
DBA_INFO_FUNC(db1)
{
return estrdup(DB1_VERSION);
}
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/
http://cvs.php.net/co.php/php-src/ext/dba/php_db1.h?r=1.1&p=1
Index: php-src/ext/dba/php_db1.h
+++ php-src/ext/dba/php_db1.h
#ifndef PHP_DB1_H
#define PHP_DB1_H
#if DBA_DB1
#include "php_dba.h"
DBA_FUNCS(db1);
#endif
#endif
http://cvs.php.net/co.php/php-src/ext/dba/tests/dba_db1.phpt?r=1.1&p=1
Index: php-src/ext/dba/tests/dba_db1.phpt
+++ php-src/ext/dba/tests/dba_db1.phpt
--TEST--
DBA DB1 handler test
--SKIPIF--
<?php
$handler = 'db1';
require_once('skipif.inc');
?>
--FILE--
<?php
$handler = 'db1';
require_once('test.inc');
require_once('dba_handler.inc');
?>
===DONE===
--EXPECT--
database handler: db1
3NYNYY
Content String 2
Content 2 replaced
Read during write: not allowed
Content 2 replaced 2nd time
The 6th value
array(3) {
["key number 6"]=>
string(13) "The 6th value"
["key2"]=>
string(27) "Content 2 replaced 2nd time"
["key5"]=>
string(23) "The last content string"
}
--NO-LOCK--
3NYNYY
Content String 2
Content 2 replaced
Read during write: not allowed
Content 2 replaced 2nd time
The 6th value
array(3) {
["key number 6"]=>
string(13) "The 6th value"
["key2"]=>
string(27) "Content 2 replaced 2nd time"
["key5"]=>
string(23) "The last content string"
}
===DONE===
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php