mirror of
https://github.com/php/pecl-database-tdb.git
synced 2026-03-24 01:02:18 +01:00
add PECL/tdb
This commit is contained in:
0
EXPERIMENTAL
Normal file
0
EXPERIMENTAL
Normal file
47
config.m4
Normal file
47
config.m4
Normal file
@@ -0,0 +1,47 @@
|
||||
dnl $Id$
|
||||
|
||||
PHP_ARG_WITH(tdb, for Trivial DB support,
|
||||
[ --with-tdb Include Trivial DB support])
|
||||
|
||||
if test "$PHP_TDB" != "no"; then
|
||||
|
||||
SEARCH_PATH="/usr/local/ /usr/"
|
||||
SEARCH_FOR="include/tdb.h"
|
||||
if test "$PHP_TDB" = "yes"; then
|
||||
AC_MSG_CHECKING([for Trivial DB files in default path])
|
||||
for i in $SEARCH_PATH ; do
|
||||
if test -r $i/$SEARCH_FOR; then
|
||||
TDB_DIR=$i
|
||||
AC_MSG_RESULT(found in $i)
|
||||
fi
|
||||
done
|
||||
elif test -r $PHP_TDB/$SEARCH_FOR; then
|
||||
AC_MSG_CHECKING([for Trivial DB files in $PHP_TDB])
|
||||
TDB_DIR=$PHP_TDB
|
||||
fi
|
||||
|
||||
if test -z "$TDB_DIR"; then
|
||||
AC_MSG_RESULT([not found])
|
||||
AC_MSG_ERROR([Could not find Trivial DB headers])
|
||||
fi
|
||||
|
||||
PHP_ADD_INCLUDE($TDB_DIR/include)
|
||||
|
||||
LIBNAME=tdb
|
||||
LIBSYMBOL=tdb_open
|
||||
|
||||
PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
|
||||
[
|
||||
PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $TDB_DIR/lib, TDB_SHARED_LIBADD)
|
||||
AC_DEFINE(HAVE_TDBLIB,1,[ ])
|
||||
],[
|
||||
AC_MSG_ERROR([wrong Trivial DB lib version or lib not found])
|
||||
],[
|
||||
-L$TDB_DIR/lib -lm -ldl
|
||||
])
|
||||
|
||||
AC_DEFINE(HAVE_TDB,1,[ ])
|
||||
PHP_SUBST(TDB_SHARED_LIBADD)
|
||||
|
||||
PHP_NEW_EXTENSION(tdb, tdb.c, $ext_shared)
|
||||
fi
|
||||
51
php_tdb.h
Normal file
51
php_tdb.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2007 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.01 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_01.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 |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Antony Dovgal <tony2001@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef PHP_TDB_H
|
||||
#define PHP_TDB_H
|
||||
|
||||
extern zend_module_entry tdb_module_entry;
|
||||
#define phpext_tdb_ptr &tdb_module_entry
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
#define PHP_TDB_API __declspec(dllexport)
|
||||
#else
|
||||
#define PHP_TDB_API
|
||||
#endif
|
||||
|
||||
#ifdef ZTS
|
||||
#include "TSRM.h"
|
||||
#endif
|
||||
|
||||
PHP_MINIT_FUNCTION(tdb);
|
||||
PHP_MSHUTDOWN_FUNCTION(tdb);
|
||||
PHP_MINFO_FUNCTION(tdb);
|
||||
|
||||
#endif /* PHP_TDB_H */
|
||||
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: noet sw=4 ts=4 fdm=marker
|
||||
* vim<600: noet sw=4 ts=4
|
||||
*/
|
||||
803
tdb.c
Normal file
803
tdb.c
Normal file
@@ -0,0 +1,803 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 5 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2007 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 3.01 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_01.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 |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Antony Dovgal <tony2001@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
#include "php_ini.h"
|
||||
#include "ext/standard/info.h"
|
||||
#include "php_tdb.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <tdb.h>
|
||||
|
||||
static int le_tdb;
|
||||
#define le_tdb_name "Trivial DB context"
|
||||
|
||||
#ifdef COMPILE_DL_TDB
|
||||
ZEND_GET_MODULE(tdb)
|
||||
#endif
|
||||
|
||||
typedef struct _php_tdb_context_t {
|
||||
int id;
|
||||
TDB_CONTEXT *tdb;
|
||||
} php_tdb_context_t;
|
||||
|
||||
#define PHP_FETCH_TDB_RESOURCE(tdb_zval, ctx) \
|
||||
ZEND_FETCH_RESOURCE(ctx, php_tdb_context_t*, &tdb_zval, -1, le_tdb_name, le_tdb); \
|
||||
/* this is pure paranoia */ \
|
||||
if (!ctx->tdb) { \
|
||||
RETURN_FALSE; \
|
||||
}
|
||||
|
||||
static void php_tdb_list_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
php_tdb_context_t *ctx = (php_tdb_context_t *)rsrc->ptr;
|
||||
|
||||
if (ctx->tdb) {
|
||||
tdb_close(ctx->tdb);
|
||||
ctx->tdb = NULL;
|
||||
}
|
||||
efree(ctx);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static inline void php_tdb_errmsg(php_tdb_context_t *ctx TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
if (ctx && ctx->tdb && tdb_error(ctx->tdb)) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", tdb_errorstr(ctx->tdb));
|
||||
}
|
||||
}
|
||||
|
||||
#define PHP_TDB_CONSTANT(name) \
|
||||
REGISTER_LONG_CONSTANT( #name, name, CONST_CS | CONST_PERSISTENT)
|
||||
|
||||
/* {{{ PHP_MINIT_FUNCTION
|
||||
*/
|
||||
PHP_MINIT_FUNCTION(tdb)
|
||||
{
|
||||
le_tdb = zend_register_list_destructors_ex(php_tdb_list_dtor, NULL, le_tdb_name, module_number);
|
||||
|
||||
PHP_TDB_CONSTANT(TDB_REPLACE);
|
||||
PHP_TDB_CONSTANT(TDB_INSERT);
|
||||
PHP_TDB_CONSTANT(TDB_MODIFY);
|
||||
|
||||
PHP_TDB_CONSTANT(TDB_CLEAR_IF_FIRST);
|
||||
PHP_TDB_CONSTANT(TDB_INTERNAL);
|
||||
PHP_TDB_CONSTANT(TDB_NOLOCK);
|
||||
PHP_TDB_CONSTANT(TDB_NOMMAP);
|
||||
PHP_TDB_CONSTANT(TDB_NOSYNC);
|
||||
PHP_TDB_CONSTANT(TDB_SEQNUM);
|
||||
|
||||
PHP_TDB_CONSTANT(O_CREAT);
|
||||
PHP_TDB_CONSTANT(O_APPEND);
|
||||
PHP_TDB_CONSTANT(O_EXCL);
|
||||
PHP_TDB_CONSTANT(O_SYNC);
|
||||
PHP_TDB_CONSTANT(O_TRUNC);
|
||||
PHP_TDB_CONSTANT(O_RDONLY);
|
||||
PHP_TDB_CONSTANT(O_RDWR);
|
||||
|
||||
PHP_TDB_CONSTANT(S_IRWXU);
|
||||
PHP_TDB_CONSTANT(S_IRUSR);
|
||||
PHP_TDB_CONSTANT(S_IWUSR);
|
||||
PHP_TDB_CONSTANT(S_IXUSR);
|
||||
PHP_TDB_CONSTANT(S_IRWXG);
|
||||
PHP_TDB_CONSTANT(S_IRGRP);
|
||||
PHP_TDB_CONSTANT(S_IWGRP);
|
||||
PHP_TDB_CONSTANT(S_IXGRP);
|
||||
PHP_TDB_CONSTANT(S_IRWXO);
|
||||
PHP_TDB_CONSTANT(S_IROTH);
|
||||
PHP_TDB_CONSTANT(S_IWOTH);
|
||||
PHP_TDB_CONSTANT(S_IXOTH);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ PHP_MSHUTDOWN_FUNCTION
|
||||
*/
|
||||
PHP_MSHUTDOWN_FUNCTION(tdb)
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ PHP_MINFO_FUNCTION
|
||||
*/
|
||||
PHP_MINFO_FUNCTION(tdb)
|
||||
{
|
||||
php_info_print_table_start();
|
||||
php_info_print_table_header(2, "Trivial DB support", "enabled");
|
||||
php_info_print_table_end();
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto resource tdb_open(string file [, int hash_size [, int tdb_flags [, int open_flags [, int mode ]]]])
|
||||
Open or create the database and return DB resource.
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_open)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
TDB_CONTEXT *tdb;
|
||||
char *file;
|
||||
int file_len;
|
||||
long hash_size = 0;
|
||||
long tdb_flags = 0;
|
||||
long open_flags = O_CREAT|O_RDWR;
|
||||
long mode = S_IRUSR|S_IWUSR;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|llll", &file, &file_len, &hash_size, &tdb_flags, &open_flags, &mode) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((int)hash_size < 0) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The integer value of hash_size cannot be less than zero");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
tdb = tdb_open(file, (int)hash_size, (int)tdb_flags, (int)open_flags, (mode_t)mode);
|
||||
|
||||
if (!tdb) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
ctx = emalloc(sizeof(php_tdb_context_t));
|
||||
ctx->tdb = tdb;
|
||||
|
||||
ctx->id = ZEND_REGISTER_RESOURCE(return_value, ctx, le_tdb);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_close(resource tdb)
|
||||
Close & free the TDB resource
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_close)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
int res;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tdb) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
res = tdb_close(ctx->tdb);
|
||||
ctx->tdb = NULL;
|
||||
zend_list_delete(ctx->id);
|
||||
|
||||
if (res) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string tdb_error(resource tdb)
|
||||
Return the error status of the TDB context or false if no error occured
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_error)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
enum TDB_ERROR err;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tdb) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
err = tdb_error(ctx->tdb);
|
||||
|
||||
/* don't return "Success" error */
|
||||
if (err) {
|
||||
RETURN_STRING((char *)tdb_errorstr(ctx->tdb), 1);
|
||||
}
|
||||
RETURN_FALSE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void php_tdb_store(INTERNAL_FUNCTION_PARAMETERS, long flag) /* {{{ */
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
TDB_DATA tdb_key, tdb_data;
|
||||
char *key, *data;
|
||||
int key_len, data_len, res;
|
||||
|
||||
if (!flag) {
|
||||
/* store */
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssl", &tdb, &key, &key_len, &data, &data_len, &flag) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
switch(flag) {
|
||||
case TDB_REPLACE:
|
||||
case TDB_INSERT:
|
||||
case TDB_MODIFY:
|
||||
break;
|
||||
default:
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid operation mode specified: %ld", flag);
|
||||
RETURN_FALSE;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* update / insert / replace */
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &tdb, &key, &key_len, &data, &data_len) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
tdb_key.dptr = key;
|
||||
tdb_key.dsize = key_len;
|
||||
tdb_data.dptr = data;
|
||||
tdb_data.dsize = data_len;
|
||||
|
||||
res = tdb_store(ctx->tdb, tdb_key, tdb_data, (int)flag);
|
||||
|
||||
if (res) {
|
||||
php_tdb_errmsg(ctx TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_store(resource tdb, string key, string data, int flag)
|
||||
Store the data in the database using the specified key
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_store)
|
||||
{
|
||||
php_tdb_store(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_replace(resource tdb, string key, string data)
|
||||
Replaces or inserts the data in the database using the specified key.
|
||||
This works even if such record doesn't exist.
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_replace)
|
||||
{
|
||||
php_tdb_store(INTERNAL_FUNCTION_PARAM_PASSTHRU, TDB_REPLACE);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_insert(resource tdb, string key, string data)
|
||||
Inserts the data in the database using the specified key.
|
||||
Insert will fail if such record already exists.
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_insert)
|
||||
{
|
||||
php_tdb_store(INTERNAL_FUNCTION_PARAM_PASSTHRU, TDB_INSERT);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_update(resource tdb, string key, string data)
|
||||
Modifies the data in the database using the specified key.
|
||||
This operation will fail if such record doesn't exist.
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_update)
|
||||
{
|
||||
php_tdb_store(INTERNAL_FUNCTION_PARAM_PASSTHRU, TDB_MODIFY);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_append(resource tdb, string key, string data)
|
||||
Appends the data to the record or creates new record with the data.
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_append)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
TDB_DATA tdb_key, tdb_data;
|
||||
char *key, *data;
|
||||
int key_len, data_len, res;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &tdb, &key, &key_len, &data, &data_len) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
tdb_key.dptr = key;
|
||||
tdb_key.dsize = key_len;
|
||||
tdb_data.dptr = data;
|
||||
tdb_data.dsize = data_len;
|
||||
|
||||
res = tdb_append(ctx->tdb, tdb_key, tdb_data);
|
||||
|
||||
if (res) {
|
||||
php_tdb_errmsg(ctx TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string tdb_fetch(resource tdb, string key)
|
||||
Fetch the data from the database.
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_fetch)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
TDB_DATA tdb_key, tdb_data;
|
||||
char *key;
|
||||
int key_len;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &tdb, &key, &key_len) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
tdb_key.dptr = key;
|
||||
tdb_key.dsize = key_len;
|
||||
|
||||
tdb_data = tdb_fetch(ctx->tdb, tdb_key);
|
||||
|
||||
if (tdb_data.dptr == NULL) {
|
||||
php_tdb_errmsg(ctx TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETVAL_STRINGL(tdb_data.dptr, tdb_data.dsize, 1);
|
||||
free(tdb_data.dptr);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_delete(resource tdb, string key)
|
||||
Delete record from the database
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_delete)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
TDB_DATA tdb_key;
|
||||
char *key;
|
||||
int key_len, res;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &tdb, &key, &key_len) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
tdb_key.dptr = key;
|
||||
tdb_key.dsize = key_len;
|
||||
|
||||
res = tdb_delete(ctx->tdb, tdb_key);
|
||||
|
||||
if (res) {
|
||||
php_tdb_errmsg(ctx TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_exists(resource tdb, string key)
|
||||
Return true if such record exists and false otherwise
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_exists)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
TDB_DATA tdb_key;
|
||||
char *key;
|
||||
int key_len, res;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &tdb, &key, &key_len) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
tdb_key.dptr = key;
|
||||
tdb_key.dsize = key_len;
|
||||
|
||||
res = tdb_exists(ctx->tdb, tdb_key);
|
||||
|
||||
if (res) { /* found */
|
||||
RETURN_TRUE;
|
||||
}
|
||||
RETURN_FALSE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_lock(resource tdb [, bool read_lock])
|
||||
Lock the database
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_lock)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
int res;
|
||||
zend_bool read_lock = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|b", &tdb, &read_lock) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
if (!read_lock) {
|
||||
res = tdb_lockall(ctx->tdb);
|
||||
} else {
|
||||
res = tdb_lockall_read(ctx->tdb);
|
||||
}
|
||||
|
||||
if (res) {
|
||||
php_tdb_errmsg(ctx TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_unlock(resource tdb [, bool read_lock])
|
||||
Unlock the database
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_unlock)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
int res;
|
||||
zend_bool read_lock = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|b", &tdb, &read_lock) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
if (!read_lock) {
|
||||
res = tdb_unlockall(ctx->tdb);
|
||||
} else {
|
||||
res = tdb_unlockall_read(ctx->tdb);
|
||||
}
|
||||
|
||||
if (res) {
|
||||
php_tdb_errmsg(ctx TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_chainlock(resource tdb, string key [, bool read_lock])
|
||||
Lock one hash chain
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_chainlock)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
int res;
|
||||
zend_bool read_lock = 0;
|
||||
char *key;
|
||||
int key_len;
|
||||
TDB_DATA tdb_key;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|b", &tdb, &key, &key_len, &read_lock) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
tdb_key.dptr = key;
|
||||
tdb_key.dsize = key_len;
|
||||
|
||||
if (!read_lock) {
|
||||
res = tdb_chainlock(ctx->tdb, tdb_key);
|
||||
} else {
|
||||
res = tdb_chainlock_read(ctx->tdb, tdb_key);
|
||||
}
|
||||
|
||||
if (res) {
|
||||
php_tdb_errmsg(ctx TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_chainunlock(resource tdb, string key [, bool read_lock])
|
||||
Unlock one hash chain
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_chainunlock)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
int res;
|
||||
zend_bool read_lock = 0;
|
||||
char *key;
|
||||
int key_len;
|
||||
TDB_DATA tdb_key;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|b", &tdb, &key, &key_len, &read_lock) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
tdb_key.dptr = key;
|
||||
tdb_key.dsize = key_len;
|
||||
|
||||
if (!read_lock) {
|
||||
res = tdb_chainunlock(ctx->tdb, tdb_key);
|
||||
} else {
|
||||
res = tdb_chainunlock_read(ctx->tdb, tdb_key);
|
||||
}
|
||||
|
||||
if (res) {
|
||||
php_tdb_errmsg(ctx TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ PHP_TDB_1_PARAM_FUNCTION(func) */
|
||||
#define PHP_TDB_1_PARAM_FUNCTION(func) \
|
||||
php_tdb_context_t *ctx; \
|
||||
zval *tdb; \
|
||||
int res; \
|
||||
\
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tdb) == FAILURE) { \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx); \
|
||||
\
|
||||
res = func(ctx->tdb); \
|
||||
\
|
||||
if (res) { \
|
||||
php_tdb_errmsg(ctx TSRMLS_CC); \
|
||||
RETURN_FALSE; \
|
||||
} \
|
||||
RETURN_TRUE;
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_transaction_start(resource tdb)
|
||||
Start transaction
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_transaction_start)
|
||||
{
|
||||
PHP_TDB_1_PARAM_FUNCTION(tdb_transaction_start);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_transaction_commit(resource tdb)
|
||||
Commit transaction
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_transaction_commit)
|
||||
{
|
||||
PHP_TDB_1_PARAM_FUNCTION(tdb_transaction_commit);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_transaction_cancel(resource tdb)
|
||||
Cancel transaction
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_transaction_cancel)
|
||||
{
|
||||
PHP_TDB_1_PARAM_FUNCTION(tdb_transaction_cancel);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_transaction_recover(resource tdb)
|
||||
Recover transaction
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_transaction_recover)
|
||||
{
|
||||
PHP_TDB_1_PARAM_FUNCTION(tdb_transaction_recover);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string tdb_first_key(resource tdb)
|
||||
Return key of the first record in the db
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_first_key)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
TDB_DATA tdb_key;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tdb) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
tdb_key = tdb_firstkey(ctx->tdb);
|
||||
|
||||
if (!tdb_key.dptr) {
|
||||
php_tdb_errmsg(ctx TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETVAL_STRINGL(tdb_key.dptr, tdb_key.dsize, 1);
|
||||
free(tdb_key.dptr);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string tdb_next_key(resource tdb, string key)
|
||||
Return key of the next entry in the db
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_next_key)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
char *key;
|
||||
int key_len;
|
||||
TDB_DATA old_key, tdb_key;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &tdb, &key, &key_len) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
old_key.dptr = key;
|
||||
old_key.dsize = key_len;
|
||||
|
||||
tdb_key = tdb_nextkey(ctx->tdb, old_key);
|
||||
|
||||
if (!tdb_key.dptr) {
|
||||
php_tdb_errmsg(ctx TSRMLS_CC);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETVAL_STRINGL(tdb_key.dptr, tdb_key.dsize, 1);
|
||||
free(tdb_key.dptr);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool tdb_set_max_dead(resource tdb, long dead)
|
||||
Set the maximum number of dead records per hash chain
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_set_max_dead)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
long dead;
|
||||
int dead_int;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &tdb, &dead) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
dead_int = (int)dead;
|
||||
if (dead_int < 0) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Maximum number of dead records cannot be less than zero");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
tdb_set_max_dead(ctx->tdb, dead_int);
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto long tdb_get_seqnum(resource tdb)
|
||||
Get the TDB sequence number.
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_get_seqnum)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
int res;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tdb) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
res = tdb_get_seqnum(ctx->tdb);
|
||||
RETURN_LONG(res);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto long tdb_get_flags(resource tdb)
|
||||
Get the flags used when the db was created.
|
||||
*/
|
||||
static PHP_FUNCTION(tdb_get_flags)
|
||||
{
|
||||
php_tdb_context_t *ctx;
|
||||
zval *tdb;
|
||||
int res;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &tdb) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PHP_FETCH_TDB_RESOURCE(tdb, ctx);
|
||||
|
||||
res = tdb_get_flags(ctx->tdb);
|
||||
RETURN_LONG(res);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ tdb_functions[]
|
||||
*/
|
||||
zend_function_entry tdb_functions[] = {
|
||||
PHP_FE(tdb_open, NULL)
|
||||
PHP_FE(tdb_close, NULL)
|
||||
PHP_FE(tdb_error, NULL)
|
||||
PHP_FE(tdb_store, NULL)
|
||||
PHP_FE(tdb_replace, NULL)
|
||||
PHP_FE(tdb_insert, NULL)
|
||||
PHP_FE(tdb_update, NULL)
|
||||
PHP_FE(tdb_append, NULL)
|
||||
PHP_FE(tdb_fetch, NULL)
|
||||
PHP_FE(tdb_delete, NULL)
|
||||
PHP_FE(tdb_exists, NULL)
|
||||
PHP_FE(tdb_lock, NULL)
|
||||
PHP_FE(tdb_unlock, NULL)
|
||||
PHP_FE(tdb_chainlock, NULL)
|
||||
PHP_FE(tdb_chainunlock, NULL)
|
||||
PHP_FE(tdb_transaction_start, NULL)
|
||||
PHP_FE(tdb_transaction_commit, NULL)
|
||||
PHP_FE(tdb_transaction_cancel, NULL)
|
||||
PHP_FE(tdb_transaction_recover, NULL)
|
||||
PHP_FE(tdb_first_key, NULL)
|
||||
PHP_FE(tdb_next_key, NULL)
|
||||
PHP_FE(tdb_set_max_dead, NULL)
|
||||
PHP_FE(tdb_get_seqnum, NULL)
|
||||
PHP_FE(tdb_get_flags, NULL)
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
/* {{{ tdb_module_entry
|
||||
*/
|
||||
zend_module_entry tdb_module_entry = {
|
||||
#if ZEND_MODULE_API_NO >= 20010901
|
||||
STANDARD_MODULE_HEADER,
|
||||
#endif
|
||||
"tdb",
|
||||
tdb_functions,
|
||||
PHP_MINIT(tdb),
|
||||
PHP_MSHUTDOWN(tdb),
|
||||
NULL,
|
||||
NULL,
|
||||
PHP_MINFO(tdb),
|
||||
#if ZEND_MODULE_API_NO >= 20010901
|
||||
"0.1",
|
||||
#endif
|
||||
STANDARD_MODULE_PROPERTIES
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: noet sw=4 ts=4 fdm=marker
|
||||
* vim<600: noet sw=4 ts=4
|
||||
*/
|
||||
48
tests/tdb_append_001.phpt
Normal file
48
tests/tdb_append_001.phpt
Normal file
@@ -0,0 +1,48 @@
|
||||
--TEST--
|
||||
tdb_append() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_append());
|
||||
var_dump(tdb_append($tdb, "", "", ""));
|
||||
|
||||
var_dump(tdb_append($tdb, "", ""));
|
||||
var_dump(tdb_append($tdb, "key", "value"));
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
var_dump(tdb_fetch($tdb, "key"));
|
||||
|
||||
var_dump(tdb_append($tdb, "", ""));
|
||||
var_dump(tdb_append($tdb, "key", "value2"));
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
var_dump(tdb_fetch($tdb, "key"));
|
||||
|
||||
var_dump(tdb_append($tdb, "", "test"));
|
||||
var_dump(tdb_append($tdb, "key", "value3"));
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
var_dump(tdb_fetch($tdb, "key"));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_append() expects exactly 3 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_append() expects exactly 3 parameters, 4 given in %s on line %d
|
||||
NULL
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(0) ""
|
||||
string(5) "value"
|
||||
|
||||
Warning: tdb_append(): Out of memory in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
string(0) ""
|
||||
string(11) "valuevalue2"
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(4) "test"
|
||||
string(17) "valuevalue2value3"
|
||||
Done
|
||||
50
tests/tdb_chainlock_001.phpt
Normal file
50
tests/tdb_chainlock_001.phpt
Normal file
@@ -0,0 +1,50 @@
|
||||
--TEST--
|
||||
tdb_chainlock() and in-memory TDB
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_chainlock());
|
||||
var_dump(tdb_chainlock($tdb, "", ""));
|
||||
|
||||
var_dump(tdb_chainlock($tdb, ""));
|
||||
var_dump(tdb_chainlock($tdb, ""));
|
||||
var_dump(tdb_chainlock($tdb, "", true));
|
||||
var_dump(tdb_chainlock($tdb, "", true));
|
||||
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_insert($tdb, "", "");
|
||||
|
||||
var_dump(tdb_chainlock($tdb, ""));
|
||||
var_dump(tdb_chainlock($tdb, ""));
|
||||
var_dump(tdb_error($tdb));
|
||||
var_dump(tdb_chainlock($tdb, "", true));
|
||||
var_dump(tdb_chainlock($tdb, "", true));
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_chainlock($tdb, ""));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_chainlock() expects at least 2 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(8) "IO Error"
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(8) "IO Error"
|
||||
|
||||
Warning: tdb_chainlock(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
57
tests/tdb_chainlock_002.phpt
Normal file
57
tests/tdb_chainlock_002.phpt
Normal file
@@ -0,0 +1,57 @@
|
||||
--TEST--
|
||||
tdb_chainlock() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
$tdb = tdb_open($file);
|
||||
|
||||
tdb_lock($tdb);
|
||||
var_dump(tdb_chainlock($tdb, ""));
|
||||
var_dump(tdb_chainlock($tdb, "", true));
|
||||
tdb_unlock($tdb);
|
||||
|
||||
tdb_lock($tdb, true);
|
||||
var_dump(tdb_chainlock($tdb, ""));
|
||||
var_dump(tdb_chainlock($tdb, "", true));
|
||||
tdb_unlock($tdb, true);
|
||||
|
||||
var_dump(tdb_chainlock($tdb, "", true));
|
||||
var_dump(tdb_chainlock($tdb, "", true));
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
var_dump(tdb_chainlock($tdb, ""));
|
||||
var_dump(tdb_chainlock($tdb, ""));
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
var_dump(tdb_chainlock($tdb, "", true));
|
||||
var_dump(tdb_chainlock($tdb, "", true));
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_chainlock($tdb, ""));
|
||||
|
||||
unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_chainlock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(13) "Locking error"
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(13) "Locking error"
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(13) "Locking error"
|
||||
|
||||
Warning: tdb_chainlock(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
40
tests/tdb_chainlock_003.phpt
Normal file
40
tests/tdb_chainlock_003.phpt
Normal file
@@ -0,0 +1,40 @@
|
||||
--TEST--
|
||||
tdb_chainlock() and read chainlock
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
$tdb = tdb_open($file);
|
||||
|
||||
var_dump(tdb_chainlock());
|
||||
var_dump(tdb_chainlock($tdb, "", "", ""));
|
||||
|
||||
tdb_insert($tdb, "", "");
|
||||
|
||||
var_dump(tdb_chainlock($tdb, "", true));
|
||||
var_dump(tdb_chainlock($tdb, "", true));
|
||||
|
||||
var_dump(tdb_chainlock($tdb, ""));
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_chainlock($tdb, ""));
|
||||
|
||||
unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_chainlock() expects at least 2 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_chainlock() expects at most 3 parameters, 4 given in %s on line %d
|
||||
NULL
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(8) "IO Error"
|
||||
|
||||
Warning: tdb_chainlock(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
37
tests/tdb_chainunlock_001.phpt
Normal file
37
tests/tdb_chainunlock_001.phpt
Normal file
@@ -0,0 +1,37 @@
|
||||
--TEST--
|
||||
tdb_chainunlock() and in-memory TDB
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_chainunlock());
|
||||
var_dump(tdb_chainunlock($tdb, "", "", ""));
|
||||
|
||||
var_dump(tdb_chainunlock($tdb, ""));
|
||||
var_dump(tdb_chainunlock($tdb, ""));
|
||||
var_dump(tdb_chainunlock($tdb, "", true));
|
||||
var_dump(tdb_chainunlock($tdb, "", true));
|
||||
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_chainunlock($tdb, ""));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_chainunlock() expects at least 2 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_chainunlock() expects at most 3 parameters, 4 given in %s on line %d
|
||||
NULL
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_chainunlock(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
69
tests/tdb_chainunlock_002.phpt
Normal file
69
tests/tdb_chainunlock_002.phpt
Normal file
@@ -0,0 +1,69 @@
|
||||
--TEST--
|
||||
tdb_chainunlock() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
$tdb = tdb_open($file);
|
||||
|
||||
var_dump(tdb_chainunlock());
|
||||
var_dump(tdb_chainunlock($tdb, "", "", ""));
|
||||
|
||||
tdb_lock($tdb);
|
||||
var_dump(tdb_chainunlock($tdb, ""));
|
||||
var_dump(tdb_chainunlock($tdb, "", true));
|
||||
tdb_unlock($tdb);
|
||||
|
||||
tdb_lock($tdb, true);
|
||||
var_dump(tdb_chainunlock($tdb, ""));
|
||||
var_dump(tdb_chainunlock($tdb, "", true));
|
||||
tdb_unlock($tdb, true);
|
||||
|
||||
tdb_insert($tdb, "key", "");
|
||||
|
||||
var_dump(tdb_chainlock($tdb, "key"));
|
||||
var_dump(tdb_chainunlock($tdb, "key"));
|
||||
var_dump(tdb_chainunlock($tdb, "key"));
|
||||
|
||||
tdb_insert($tdb, "key2", "");
|
||||
|
||||
var_dump(tdb_chainlock($tdb, "key2", true));
|
||||
var_dump(tdb_chainunlock($tdb, "key2"));
|
||||
var_dump(tdb_chainunlock($tdb, "key2", true));
|
||||
var_dump(tdb_chainunlock($tdb, "key2", true));
|
||||
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_chainunlock($tdb, "key"));
|
||||
|
||||
unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_chainunlock() expects at least 2 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_chainunlock() expects at most 3 parameters, 4 given in %s on line %d
|
||||
NULL
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_chainunlock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_chainunlock(): IO Error in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_chainunlock(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
44
tests/tdb_close_001.phpt
Normal file
44
tests/tdb_close_001.phpt
Normal file
@@ -0,0 +1,44 @@
|
||||
--TEST--
|
||||
tdb_close() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
|
||||
var_dump(tdb_close());
|
||||
var_dump(tdb_close(1,2));
|
||||
|
||||
$fp = fopen(__FILE__, "r");
|
||||
var_dump(tdb_close($fp));
|
||||
fclose($fp);
|
||||
var_dump(tdb_close($fp));
|
||||
|
||||
$tdb = tdb_open($file);
|
||||
var_dump(tdb_close($tdb));
|
||||
var_dump(tdb_close($tdb));
|
||||
|
||||
@unlink($file);
|
||||
|
||||
$tdb = tdb_open($file, 0, TDB_INTERNAL);
|
||||
var_dump(tdb_close($tdb));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_close() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_close() expects exactly 1 parameter, 2 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_close(): supplied resource is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_close(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_close(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
Done
|
||||
53
tests/tdb_delete_001.phpt
Normal file
53
tests/tdb_delete_001.phpt
Normal file
@@ -0,0 +1,53 @@
|
||||
--TEST--
|
||||
tdb_delete() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_delete());
|
||||
var_dump(tdb_delete($tdb, "", "", ""));
|
||||
var_dump(tdb_delete($tdb, -1));
|
||||
var_dump(tdb_delete($tdb, ""));
|
||||
|
||||
tdb_insert($tdb, "", "");
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
var_dump(tdb_delete($tdb, ""));
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
|
||||
tdb_insert($tdb, "te\0st", "value");
|
||||
var_dump(tdb_fetch($tdb, "te\0st"));
|
||||
var_dump(tdb_delete($tdb, "te\0st"));
|
||||
var_dump(tdb_fetch($tdb, "te\0st"));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_delete($tdb, "test"));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_delete() expects exactly 2 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_delete() expects exactly 2 parameters, 4 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_delete(): Record does not exist in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_delete(): Record does not exist in %s on line %d
|
||||
bool(false)
|
||||
string(0) ""
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_fetch(): Record does not exist in %s on line %d
|
||||
bool(false)
|
||||
string(5) "value"
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_fetch(): Record does not exist in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_delete(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
34
tests/tdb_error_001.phpt
Normal file
34
tests/tdb_error_001.phpt
Normal file
@@ -0,0 +1,34 @@
|
||||
--TEST--
|
||||
tdb_error() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_error());
|
||||
var_dump(tdb_error($tdb, ""));
|
||||
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_transaction_start($tdb);
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_error() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_error() expects exactly 1 parameter, 2 given in %s on line %d
|
||||
NULL
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_transaction_start(): Invalid parameter in %s on line %d
|
||||
string(17) "Invalid parameter"
|
||||
|
||||
Warning: tdb_error(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
37
tests/tdb_exists_001.phpt
Normal file
37
tests/tdb_exists_001.phpt
Normal file
@@ -0,0 +1,37 @@
|
||||
--TEST--
|
||||
tdb_exists() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_exists());
|
||||
var_dump(tdb_exists($tdb, "", "", ""));
|
||||
var_dump(tdb_exists($tdb, -1));
|
||||
var_dump(tdb_exists($tdb, ""));
|
||||
|
||||
tdb_insert($tdb, "", "");
|
||||
var_dump(tdb_exists($tdb, ""));
|
||||
|
||||
tdb_insert($tdb, "te\0st", "");
|
||||
var_dump(tdb_exists($tdb, "te\0st"));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_exists($tdb, "test"));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_exists() expects exactly 2 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_exists() expects exactly 2 parameters, 4 given in %s on line %d
|
||||
NULL
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_exists(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
BIN
tests/tdb_fetch_001.phpt
Normal file
BIN
tests/tdb_fetch_001.phpt
Normal file
Binary file not shown.
37
tests/tdb_first_key_001.phpt
Normal file
37
tests/tdb_first_key_001.phpt
Normal file
@@ -0,0 +1,37 @@
|
||||
--TEST--
|
||||
tdb_first_key() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_first_key());
|
||||
var_dump(tdb_first_key($tdb, 0, 1));
|
||||
|
||||
var_dump(tdb_first_key($tdb));
|
||||
tdb_insert($tdb, "key", "data");
|
||||
var_dump(tdb_first_key($tdb));
|
||||
tdb_insert($tdb, "key2", "data2");
|
||||
var_dump(tdb_first_key($tdb));
|
||||
tdb_insert($tdb, "a", "data3");
|
||||
var_dump(tdb_first_key($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_first_key($tdb));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_first_key() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_first_key() expects exactly 1 parameter, 3 given in %s on line %d
|
||||
NULL
|
||||
bool(false)
|
||||
string(3) "key"
|
||||
string(3) "key"
|
||||
string(1) "a"
|
||||
|
||||
Warning: tdb_first_key(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
40
tests/tdb_get_flags_001.phpt
Normal file
40
tests/tdb_get_flags_001.phpt
Normal file
@@ -0,0 +1,40 @@
|
||||
--TEST--
|
||||
tdb_get_flags() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL|TDB_SEQNUM);
|
||||
|
||||
var_dump(tdb_get_flags());
|
||||
var_dump(tdb_get_flags($tdb, ""));
|
||||
|
||||
var_dump(tdb_get_flags($tdb));
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
var_dump(tdb_get_flags($tdb));
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
|
||||
$tdb = tdb_open($file, 0, 0);
|
||||
var_dump(tdb_get_flags($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
unlink($file);
|
||||
|
||||
var_dump(tdb_get_flags($tdb));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_get_flags() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_get_flags() expects exactly 1 parameter, 2 given in %s on line %d
|
||||
NULL
|
||||
int(142)
|
||||
int(14)
|
||||
int(0)
|
||||
|
||||
Warning: tdb_get_flags(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
49
tests/tdb_get_seqnum_001.phpt
Normal file
49
tests/tdb_get_seqnum_001.phpt
Normal file
@@ -0,0 +1,49 @@
|
||||
--TEST--
|
||||
tdb_get_seqnum() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL|TDB_SEQNUM);
|
||||
|
||||
var_dump(tdb_get_seqnum());
|
||||
var_dump(tdb_get_seqnum($tdb, ""));
|
||||
|
||||
var_dump(tdb_get_seqnum($tdb));
|
||||
|
||||
tdb_insert($tdb, "", "");
|
||||
var_dump(tdb_get_seqnum($tdb));
|
||||
tdb_insert($tdb, "test", "");
|
||||
var_dump(tdb_get_seqnum($tdb));
|
||||
tdb_insert($tdb, "test2", "");
|
||||
var_dump(tdb_get_seqnum($tdb));
|
||||
tdb_update($tdb, "test", "3");
|
||||
var_dump(tdb_get_seqnum($tdb));
|
||||
tdb_update($tdb, "test", "1");
|
||||
tdb_update($tdb, "test", "1");
|
||||
var_dump(tdb_get_seqnum($tdb));
|
||||
tdb_update($tdb, "test", "2");
|
||||
tdb_update($tdb, "test2", "2");
|
||||
var_dump(tdb_get_seqnum($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_get_seqnum($tdb));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_get_seqnum() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_get_seqnum() expects exactly 1 parameter, 2 given in %s on line %d
|
||||
NULL
|
||||
int(0)
|
||||
int(1)
|
||||
int(2)
|
||||
int(3)
|
||||
int(5)
|
||||
int(7)
|
||||
int(9)
|
||||
|
||||
Warning: tdb_get_seqnum(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
22
tests/tdb_get_seqnum_002.phpt
Normal file
22
tests/tdb_get_seqnum_002.phpt
Normal file
@@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
tdb_get_seqnum() without TDB_SEQNUM
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_get_seqnum($tdb));
|
||||
|
||||
tdb_insert($tdb, "", "");
|
||||
var_dump(tdb_get_seqnum($tdb));
|
||||
tdb_insert($tdb, "test", "");
|
||||
tdb_update($tdb, "test", "2");
|
||||
var_dump(tdb_get_seqnum($tdb));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
int(0)
|
||||
int(0)
|
||||
int(0)
|
||||
Done
|
||||
41
tests/tdb_insert_001.phpt
Normal file
41
tests/tdb_insert_001.phpt
Normal file
@@ -0,0 +1,41 @@
|
||||
--TEST--
|
||||
tdb_insert() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_insert());
|
||||
var_dump(tdb_insert($tdb, "", "", ""));
|
||||
|
||||
var_dump(tdb_insert($tdb, "", ""));
|
||||
var_dump(tdb_insert($tdb, "key", "value"));
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
var_dump(tdb_fetch($tdb, "key"));
|
||||
|
||||
var_dump(tdb_insert($tdb, "", ""));
|
||||
var_dump(tdb_insert($tdb, "key", "value3"));
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
var_dump(tdb_fetch($tdb, "key"));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_insert() expects exactly 3 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_insert() expects exactly 3 parameters, 4 given in %s on line %d
|
||||
NULL
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(0) ""
|
||||
string(5) "value"
|
||||
|
||||
Warning: tdb_insert(): Record exists in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_insert(): Record exists in %s on line %d
|
||||
bool(false)
|
||||
string(0) ""
|
||||
string(5) "value"
|
||||
Done
|
||||
41
tests/tdb_lock_001.phpt
Normal file
41
tests/tdb_lock_001.phpt
Normal file
@@ -0,0 +1,41 @@
|
||||
--TEST--
|
||||
tdb_lock() and in-memory TDB
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_lock());
|
||||
var_dump(tdb_lock($tdb, "", ""));
|
||||
|
||||
var_dump(tdb_lock($tdb));
|
||||
var_dump(tdb_lock($tdb));
|
||||
var_dump(tdb_lock($tdb, true));
|
||||
var_dump(tdb_lock($tdb, true));
|
||||
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_lock($tdb));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_lock() expects at least 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_lock() expects at most 2 parameters, 3 given in %s on line %d
|
||||
NULL
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_lock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_lock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
string(13) "Locking error"
|
||||
|
||||
Warning: tdb_lock(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
44
tests/tdb_lock_002.phpt
Normal file
44
tests/tdb_lock_002.phpt
Normal file
@@ -0,0 +1,44 @@
|
||||
--TEST--
|
||||
tdb_lock() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
$tdb = tdb_open($file);
|
||||
|
||||
var_dump(tdb_lock());
|
||||
var_dump(tdb_lock($tdb, "", ""));
|
||||
|
||||
var_dump(tdb_lock($tdb));
|
||||
var_dump(tdb_lock($tdb));
|
||||
var_dump(tdb_lock($tdb, true));
|
||||
var_dump(tdb_lock($tdb, true));
|
||||
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_lock($tdb));
|
||||
|
||||
unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_lock() expects at least 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_lock() expects at most 2 parameters, 3 given in %s on line %d
|
||||
NULL
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_lock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_lock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
string(13) "Locking error"
|
||||
|
||||
Warning: tdb_lock(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
40
tests/tdb_lock_003.phpt
Normal file
40
tests/tdb_lock_003.phpt
Normal file
@@ -0,0 +1,40 @@
|
||||
--TEST--
|
||||
tdb_lock() and read lock
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
$tdb = tdb_open($file);
|
||||
|
||||
var_dump(tdb_lock());
|
||||
var_dump(tdb_lock($tdb, "", ""));
|
||||
|
||||
var_dump(tdb_lock($tdb, true));
|
||||
var_dump(tdb_lock($tdb, true));
|
||||
|
||||
var_dump(tdb_lock($tdb));
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_lock($tdb));
|
||||
|
||||
unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_lock() expects at least 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_lock() expects at most 2 parameters, 3 given in %s on line %d
|
||||
NULL
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_lock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
string(13) "Locking error"
|
||||
|
||||
Warning: tdb_lock(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
46
tests/tdb_next_key_001.phpt
Normal file
46
tests/tdb_next_key_001.phpt
Normal file
@@ -0,0 +1,46 @@
|
||||
--TEST--
|
||||
tdb_next_key() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_next_key());
|
||||
var_dump(tdb_next_key($tdb, 0, 1));
|
||||
var_dump(tdb_next_key($tdb, ""));
|
||||
|
||||
tdb_insert($tdb, "key", "data");
|
||||
var_dump(tdb_next_key($tdb, "key"));
|
||||
|
||||
tdb_insert($tdb, "key2", "data2");
|
||||
var_dump(tdb_next_key($tdb, "key"));
|
||||
|
||||
tdb_insert($tdb, "a", "data3");
|
||||
|
||||
for ($key = tdb_first_key($tdb); $key !== false; $key = tdb_next_key($tdb, $key)) {
|
||||
var_dump($key);
|
||||
}
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_next_key($tdb, "key"));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_next_key() expects exactly 2 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_next_key() expects exactly 2 parameters, 3 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_next_key(): Record does not exist in %s on line %d
|
||||
bool(false)
|
||||
bool(false)
|
||||
string(4) "key2"
|
||||
string(1) "a"
|
||||
string(3) "key"
|
||||
string(4) "key2"
|
||||
|
||||
Warning: tdb_next_key(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
49
tests/tdb_open_001.phpt
Normal file
49
tests/tdb_open_001.phpt
Normal file
@@ -0,0 +1,49 @@
|
||||
--TEST--
|
||||
tdb_open() errors
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
var_dump(tdb_open("/there/is/no/such/file/or/directory"));
|
||||
|
||||
$dir = dirname(__FILE__)."/test_dir";
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
@rmdir($dir);
|
||||
mkdir($dir);
|
||||
|
||||
var_dump(tdb_open($dir));
|
||||
var_dump(tdb_open(""));
|
||||
|
||||
var_dump(tdb_open($file, -1));
|
||||
var_dump(tdb_open($file,0,0,0,0));
|
||||
var_dump(tdb_open($file,0,-1,0,0));
|
||||
var_dump(tdb_open($file,0,0,-1,0));
|
||||
var_dump(tdb_open($file,0,0,0,-1));
|
||||
|
||||
@rmdir($dir);
|
||||
@unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_open(): No such file or directory in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_open(): Is a directory in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_open(): No such file or directory in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_open(): The integer value of hash_size cannot be less than zero in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_open(): No such file or directory in %s on line %d
|
||||
bool(false)
|
||||
resource(%d) of type (Trivial DB context)
|
||||
|
||||
Warning: tdb_open(): Bad file descriptor in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_open(): Permission denied in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
90
tests/tdb_open_002.phpt
Normal file
90
tests/tdb_open_002.phpt
Normal file
@@ -0,0 +1,90 @@
|
||||
--TEST--
|
||||
tdb_open() errors - 2
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
|
||||
var_dump(tdb_open());
|
||||
var_dump(tdb_open(1,1,1,1,1,1,1));
|
||||
var_dump(tdb_open("1",1,1,1,1,1,1));
|
||||
|
||||
var_dump($tdb = tdb_open($file));
|
||||
var_dump(tdb_close($tdb));
|
||||
@unlink($file);
|
||||
|
||||
var_dump($tdb = tdb_open($file, 1024));
|
||||
var_dump(tdb_close($tdb));
|
||||
@unlink($file);
|
||||
|
||||
var_dump($tdb = tdb_open($file, 0, TDB_INTERNAL|TDB_NOSYNC|TDB_NOLOCK|TDB_NOMMAP|TDB_CLEAR_IF_FIRST|TDB_SEQNUM));
|
||||
var_dump(tdb_close($tdb));
|
||||
@unlink($file);
|
||||
|
||||
var_dump($tdb = tdb_open($file, 0, 0, 0));
|
||||
var_dump($tdb = tdb_open($file, 0, 0, O_RDWR));
|
||||
var_dump($tdb = tdb_open($file, 0, 0, O_RDONLY));
|
||||
var_dump($tdb = tdb_open($file, 0, 0, O_RDWR));
|
||||
var_dump($tdb = tdb_open($file, 0, 0, O_RDWR|O_RDONLY));
|
||||
var_dump($tdb = tdb_open($file, 0, 0, O_CREAT|O_RDONLY));
|
||||
|
||||
var_dump($tdb = tdb_open($file, 0, 0, O_CREAT|O_RDWR));
|
||||
var_dump(tdb_close($tdb));
|
||||
@unlink($file);
|
||||
|
||||
var_dump($tdb = tdb_open($file, 0, 0, O_CREAT|O_RDWR, S_IRUSR));
|
||||
var_dump(tdb_close($tdb));
|
||||
@unlink($file);
|
||||
|
||||
var_dump($tdb = tdb_open($file, 0, 0, O_CREAT|O_RDWR, S_IWUSR));
|
||||
var_dump(tdb_close($tdb));
|
||||
@unlink($file);
|
||||
|
||||
var_dump($tdb = tdb_open($file, 0, 0, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR));
|
||||
var_dump(tdb_close($tdb));
|
||||
@unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_open() expects at least 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_open() expects at most 5 parameters, 7 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_open() expects at most 5 parameters, 7 given in %s on line %d
|
||||
NULL
|
||||
resource(%d) of type (Trivial DB context)
|
||||
bool(true)
|
||||
resource(%d) of type (Trivial DB context)
|
||||
bool(true)
|
||||
resource(%d) of type (Trivial DB context)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_open(): No such file or directory in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_open(): No such file or directory in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_open(): No such file or directory in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_open(): No such file or directory in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_open(): No such file or directory in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_open(): Input/output error in %s on line %d
|
||||
bool(false)
|
||||
resource(%d) of type (Trivial DB context)
|
||||
bool(true)
|
||||
resource(%d) of type (Trivial DB context)
|
||||
bool(true)
|
||||
resource(%d) of type (Trivial DB context)
|
||||
bool(true)
|
||||
resource(%d) of type (Trivial DB context)
|
||||
bool(true)
|
||||
Done
|
||||
20
tests/tdb_open_003.phpt
Normal file
20
tests/tdb_open_003.phpt
Normal file
@@ -0,0 +1,20 @@
|
||||
--TEST--
|
||||
tdb_open() in-memory test
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
|
||||
var_dump($tdb = tdb_open($file, 0, TDB_INTERNAL));
|
||||
var_dump(tdb_close($tdb));
|
||||
var_dump(unlink($file));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
resource(%d) of type (Trivial DB context)
|
||||
bool(true)
|
||||
|
||||
Warning: unlink(%stest.tdb): No such file or directory in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
29
tests/tdb_replace_001.phpt
Normal file
29
tests/tdb_replace_001.phpt
Normal file
@@ -0,0 +1,29 @@
|
||||
--TEST--
|
||||
tdb_replace() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_replace());
|
||||
var_dump(tdb_replace($tdb, "", "", ""));
|
||||
|
||||
var_dump(tdb_replace($tdb, "", ""));
|
||||
var_dump(tdb_replace($tdb, "key", "value"));
|
||||
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
var_dump(tdb_fetch($tdb, "key"));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_replace() expects exactly 3 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_replace() expects exactly 3 parameters, 4 given in %s on line %d
|
||||
NULL
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(0) ""
|
||||
string(5) "value"
|
||||
Done
|
||||
48
tests/tdb_set_max_dead_001.phpt
Normal file
48
tests/tdb_set_max_dead_001.phpt
Normal file
@@ -0,0 +1,48 @@
|
||||
--TEST--
|
||||
tdb_set_max_dead() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_set_max_dead());
|
||||
var_dump(tdb_set_max_dead($tdb, 0, 1));
|
||||
var_dump(tdb_set_max_dead($tdb, -1));
|
||||
|
||||
var_dump(tdb_set_max_dead($tdb, 1));
|
||||
|
||||
tdb_insert($tdb, "", "");
|
||||
tdb_insert($tdb, "1", "1");
|
||||
tdb_insert($tdb, "2", "2");
|
||||
tdb_insert($tdb, "3", "3");
|
||||
|
||||
var_dump(tdb_delete($tdb, ""));
|
||||
var_dump(tdb_delete($tdb, "1"));
|
||||
var_dump(tdb_delete($tdb, "2"));
|
||||
var_dump(tdb_delete($tdb, "3"));
|
||||
|
||||
tdb_close($tdb);
|
||||
|
||||
var_dump(tdb_set_max_dead($tdb, 1));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
|
||||
Warning: tdb_set_max_dead() expects exactly 2 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_set_max_dead() expects exactly 2 parameters, 3 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_set_max_dead(): Maximum number of dead records cannot be less than zero in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_set_max_dead(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
79
tests/tdb_store_001.phpt
Normal file
79
tests/tdb_store_001.phpt
Normal file
@@ -0,0 +1,79 @@
|
||||
--TEST--
|
||||
tdb_store() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_store($tdb));
|
||||
var_dump(tdb_store($tdb, "", "", 0, ""));
|
||||
|
||||
var_dump(tdb_store($tdb, "", "", 0));
|
||||
var_dump(tdb_store($tdb, "", "", -1));
|
||||
var_dump(tdb_store($tdb, "", "", PHP_INT_MAX));
|
||||
|
||||
var_dump(tdb_store($tdb, "", "", TDB_MODIFY));
|
||||
|
||||
var_dump(tdb_store($tdb, "", "", TDB_INSERT));
|
||||
var_dump(tdb_store($tdb, "", "", TDB_INSERT));
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
|
||||
$str = str_repeat("test", 256);
|
||||
var_dump(tdb_store($tdb, "", $str, TDB_MODIFY));
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
|
||||
$str = str_repeat("blah", 64);
|
||||
var_dump(tdb_store($tdb, "", $str, TDB_REPLACE));
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
|
||||
var_dump(tdb_store($tdb, "test key1", "test value", TDB_REPLACE));
|
||||
var_dump(tdb_fetch($tdb, "test key1"));
|
||||
|
||||
var_dump(tdb_store($tdb, "test key2", "test value", TDB_INSERT));
|
||||
var_dump(tdb_fetch($tdb, "test key2"));
|
||||
|
||||
var_dump(tdb_store($tdb, "test key2", "test value2", TDB_MODIFY));
|
||||
var_dump(tdb_fetch($tdb, "test key2"));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_store($tdb, "test key2", "test value2", TDB_MODIFY));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_store() expects exactly 4 parameters, 1 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_store() expects exactly 4 parameters, 5 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_store(): Invalid operation mode specified: 0 in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_store(): Invalid operation mode specified: -1 in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_store(): Invalid operation mode specified: 2147483647 in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_store(): Record does not exist in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_store(): Record exists in %s on line %d
|
||||
bool(false)
|
||||
string(0) ""
|
||||
bool(true)
|
||||
string(1024) "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest"
|
||||
bool(true)
|
||||
string(256) "blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah"
|
||||
bool(true)
|
||||
string(10) "test value"
|
||||
bool(true)
|
||||
string(10) "test value"
|
||||
bool(true)
|
||||
string(11) "test value2"
|
||||
|
||||
Warning: tdb_store(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
80
tests/tdb_transactions_001.phpt
Normal file
80
tests/tdb_transactions_001.phpt
Normal file
@@ -0,0 +1,80 @@
|
||||
--TEST--
|
||||
transactions funcs tests - wrong arguments
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_transaction_start());
|
||||
var_dump(tdb_transaction_start($tdb, 0, 1));
|
||||
var_dump(tdb_transaction_start($tdb, ""));
|
||||
|
||||
var_dump(tdb_transaction_cancel());
|
||||
var_dump(tdb_transaction_cancel($tdb, 0, 1));
|
||||
var_dump(tdb_transaction_cancel($tdb, ""));
|
||||
|
||||
var_dump(tdb_transaction_commit());
|
||||
var_dump(tdb_transaction_commit($tdb, 0, 1));
|
||||
var_dump(tdb_transaction_commit($tdb, ""));
|
||||
|
||||
var_dump(tdb_transaction_recover());
|
||||
var_dump(tdb_transaction_recover($tdb, 0, 1));
|
||||
var_dump(tdb_transaction_recover($tdb, ""));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
var_dump(tdb_transaction_cancel($tdb));
|
||||
var_dump(tdb_transaction_commit($tdb));
|
||||
var_dump(tdb_transaction_recover($tdb));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_transaction_start() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_transaction_start() expects exactly 1 parameter, 3 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_transaction_start() expects exactly 1 parameter, 2 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_transaction_cancel() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_transaction_cancel() expects exactly 1 parameter, 3 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_transaction_cancel() expects exactly 1 parameter, 2 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_transaction_commit() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_transaction_commit() expects exactly 1 parameter, 3 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_transaction_commit() expects exactly 1 parameter, 2 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_transaction_recover() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_transaction_recover() expects exactly 1 parameter, 3 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_transaction_recover() expects exactly 1 parameter, 2 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_transaction_start(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_transaction_cancel(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_transaction_commit(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_transaction_recover(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
27
tests/tdb_transactions_002.phpt
Normal file
27
tests/tdb_transactions_002.phpt
Normal file
@@ -0,0 +1,27 @@
|
||||
--TEST--
|
||||
transactions - in-memory TDB
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_transaction_cancel($tdb));
|
||||
var_dump(tdb_transaction_recover($tdb));
|
||||
var_dump(tdb_transaction_commit($tdb));
|
||||
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_transaction_start(): Invalid parameter in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_transaction_start(): Invalid parameter in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
46
tests/tdb_transactions_003.phpt
Normal file
46
tests/tdb_transactions_003.phpt
Normal file
@@ -0,0 +1,46 @@
|
||||
--TEST--
|
||||
transactions - basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
$tdb = tdb_open($file);
|
||||
|
||||
var_dump(tdb_transaction_cancel($tdb));
|
||||
var_dump(tdb_transaction_recover($tdb));
|
||||
var_dump(tdb_transaction_commit($tdb));
|
||||
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
var_dump(tdb_transaction_cancel($tdb));
|
||||
var_dump(tdb_transaction_cancel($tdb));
|
||||
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
var_dump(tdb_transaction_cancel($tdb));
|
||||
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
var_dump(tdb_transaction_recover($tdb));
|
||||
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
var_dump(tdb_transaction_commit($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
Done
|
||||
31
tests/tdb_transactions_004.phpt
Normal file
31
tests/tdb_transactions_004.phpt
Normal file
@@ -0,0 +1,31 @@
|
||||
--TEST--
|
||||
transactions - nested transactions
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
$tdb = tdb_open($file);
|
||||
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
|
||||
var_dump(tdb_transaction_cancel($tdb));
|
||||
var_dump(tdb_transaction_recover($tdb));
|
||||
var_dump(tdb_transaction_commit($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_transaction_commit(): IO Error in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
41
tests/tdb_transactions_005.phpt
Normal file
41
tests/tdb_transactions_005.phpt
Normal file
@@ -0,0 +1,41 @@
|
||||
--TEST--
|
||||
transactions - basic transactions
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
$tdb = tdb_open($file);
|
||||
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
tdb_insert($tdb, "key", "data");
|
||||
var_dump(tdb_transaction_cancel($tdb));
|
||||
var_dump(tdb_fetch($tdb, "key"));
|
||||
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
tdb_insert($tdb, "key", "data");
|
||||
var_dump(tdb_transaction_commit($tdb));
|
||||
var_dump(tdb_fetch($tdb, "key"));
|
||||
|
||||
var_dump(tdb_transaction_start($tdb));
|
||||
tdb_replace($tdb, "key", "new data");
|
||||
var_dump(tdb_transaction_recover($tdb));
|
||||
var_dump(tdb_fetch($tdb, "key"));
|
||||
|
||||
tdb_close($tdb);
|
||||
unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_fetch(): Record does not exist in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(4) "data"
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(8) "new data"
|
||||
Done
|
||||
45
tests/tdb_unlock_001.phpt
Normal file
45
tests/tdb_unlock_001.phpt
Normal file
@@ -0,0 +1,45 @@
|
||||
--TEST--
|
||||
tdb_unlock() and in-memory TDB
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_unlock());
|
||||
var_dump(tdb_unlock($tdb, "", ""));
|
||||
|
||||
var_dump(tdb_unlock($tdb));
|
||||
var_dump(tdb_unlock($tdb));
|
||||
var_dump(tdb_unlock($tdb, true));
|
||||
var_dump(tdb_unlock($tdb, true));
|
||||
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_unlock($tdb));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_unlock() expects at least 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_unlock() expects at most 2 parameters, 3 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_unlock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_unlock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_unlock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_unlock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
string(13) "Locking error"
|
||||
|
||||
Warning: tdb_unlock(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
62
tests/tdb_unlock_002.phpt
Normal file
62
tests/tdb_unlock_002.phpt
Normal file
@@ -0,0 +1,62 @@
|
||||
--TEST--
|
||||
tdb_unlock() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$file = dirname(__FILE__)."/test.tdb";
|
||||
$tdb = tdb_open($file);
|
||||
|
||||
var_dump(tdb_unlock());
|
||||
var_dump(tdb_unlock($tdb, "", ""));
|
||||
|
||||
var_dump(tdb_unlock($tdb));
|
||||
var_dump(tdb_unlock($tdb, true));
|
||||
|
||||
var_dump(tdb_lock($tdb));
|
||||
var_dump(tdb_unlock($tdb));
|
||||
var_dump(tdb_unlock($tdb));
|
||||
|
||||
var_dump(tdb_lock($tdb, true));
|
||||
var_dump(tdb_unlock($tdb));
|
||||
var_dump(tdb_unlock($tdb, true));
|
||||
var_dump(tdb_unlock($tdb, true));
|
||||
|
||||
var_dump(tdb_error($tdb));
|
||||
|
||||
tdb_close($tdb);
|
||||
var_dump(tdb_unlock($tdb));
|
||||
|
||||
unlink($file);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_unlock() expects at least 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_unlock() expects at most 2 parameters, 3 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_unlock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_unlock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_unlock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_unlock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
|
||||
Warning: tdb_unlock(): Locking error in %s on line %d
|
||||
bool(false)
|
||||
string(13) "Locking error"
|
||||
|
||||
Warning: tdb_unlock(): %d is not a valid Trivial DB context resource in %s on line %d
|
||||
bool(false)
|
||||
Done
|
||||
54
tests/tdb_update_001.phpt
Normal file
54
tests/tdb_update_001.phpt
Normal file
@@ -0,0 +1,54 @@
|
||||
--TEST--
|
||||
tdb_update() basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tdb = tdb_open("", 0, TDB_INTERNAL);
|
||||
|
||||
var_dump(tdb_update());
|
||||
var_dump(tdb_update($tdb, "", "", ""));
|
||||
|
||||
var_dump(tdb_update($tdb, "", ""));
|
||||
var_dump(tdb_update($tdb, "key", "value"));
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
var_dump(tdb_fetch($tdb, "key"));
|
||||
|
||||
var_dump(tdb_insert($tdb, "", ""));
|
||||
var_dump(tdb_insert($tdb, "key", "value2"));
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
var_dump(tdb_fetch($tdb, "key"));
|
||||
|
||||
var_dump(tdb_update($tdb, "", ""));
|
||||
var_dump(tdb_update($tdb, "key", "value3"));
|
||||
var_dump(tdb_fetch($tdb, ""));
|
||||
var_dump(tdb_fetch($tdb, "key"));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: tdb_update() expects exactly 3 parameters, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_update() expects exactly 3 parameters, 4 given in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: tdb_update(): Record does not exist in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_update(): Record does not exist in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_fetch(): Record does not exist in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: tdb_fetch(): Record does not exist in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(0) ""
|
||||
string(6) "value2"
|
||||
bool(true)
|
||||
bool(true)
|
||||
string(0) ""
|
||||
string(6) "value3"
|
||||
Done
|
||||
Reference in New Issue
Block a user