diff --git a/CREDITS b/CREDITS new file mode 100644 index 0000000..e4e76b4 --- /dev/null +++ b/CREDITS @@ -0,0 +1 @@ +Antony Dovgal diff --git a/EXPERIMENTAL b/EXPERIMENTAL new file mode 100644 index 0000000..e69de29 diff --git a/config.m4 b/config.m4 new file mode 100644 index 0000000..3f2dd0c --- /dev/null +++ b/config.m4 @@ -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 diff --git a/php_tdb.h b/php_tdb.h new file mode 100644 index 0000000..42c1f76 --- /dev/null +++ b/php_tdb.h @@ -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 | + +----------------------------------------------------------------------+ +*/ + +/* $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 + */ diff --git a/tdb.c b/tdb.c new file mode 100644 index 0000000..b58ae19 --- /dev/null +++ b/tdb.c @@ -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 | + +----------------------------------------------------------------------+ +*/ + +/* $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 +#include + +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 + */ diff --git a/tests/tdb_append_001.phpt b/tests/tdb_append_001.phpt new file mode 100644 index 0000000..46f8217 --- /dev/null +++ b/tests/tdb_append_001.phpt @@ -0,0 +1,48 @@ +--TEST-- +tdb_append() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_chainlock_001.phpt b/tests/tdb_chainlock_001.phpt new file mode 100644 index 0000000..f338e9f --- /dev/null +++ b/tests/tdb_chainlock_001.phpt @@ -0,0 +1,50 @@ +--TEST-- +tdb_chainlock() and in-memory TDB +--FILE-- + +--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 diff --git a/tests/tdb_chainlock_002.phpt b/tests/tdb_chainlock_002.phpt new file mode 100644 index 0000000..9be7c5a --- /dev/null +++ b/tests/tdb_chainlock_002.phpt @@ -0,0 +1,57 @@ +--TEST-- +tdb_chainlock() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_chainlock_003.phpt b/tests/tdb_chainlock_003.phpt new file mode 100644 index 0000000..fde472b --- /dev/null +++ b/tests/tdb_chainlock_003.phpt @@ -0,0 +1,40 @@ +--TEST-- +tdb_chainlock() and read chainlock +--FILE-- + +--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 diff --git a/tests/tdb_chainunlock_001.phpt b/tests/tdb_chainunlock_001.phpt new file mode 100644 index 0000000..7e401bf --- /dev/null +++ b/tests/tdb_chainunlock_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +tdb_chainunlock() and in-memory TDB +--FILE-- + +--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 diff --git a/tests/tdb_chainunlock_002.phpt b/tests/tdb_chainunlock_002.phpt new file mode 100644 index 0000000..7d8ab27 --- /dev/null +++ b/tests/tdb_chainunlock_002.phpt @@ -0,0 +1,69 @@ +--TEST-- +tdb_chainunlock() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_close_001.phpt b/tests/tdb_close_001.phpt new file mode 100644 index 0000000..f1c9c89 --- /dev/null +++ b/tests/tdb_close_001.phpt @@ -0,0 +1,44 @@ +--TEST-- +tdb_close() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_delete_001.phpt b/tests/tdb_delete_001.phpt new file mode 100644 index 0000000..f73f18e --- /dev/null +++ b/tests/tdb_delete_001.phpt @@ -0,0 +1,53 @@ +--TEST-- +tdb_delete() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_error_001.phpt b/tests/tdb_error_001.phpt new file mode 100644 index 0000000..d4276b7 --- /dev/null +++ b/tests/tdb_error_001.phpt @@ -0,0 +1,34 @@ +--TEST-- +tdb_error() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_exists_001.phpt b/tests/tdb_exists_001.phpt new file mode 100644 index 0000000..cbe1db4 --- /dev/null +++ b/tests/tdb_exists_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +tdb_exists() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_fetch_001.phpt b/tests/tdb_fetch_001.phpt new file mode 100644 index 0000000..d0dd90e Binary files /dev/null and b/tests/tdb_fetch_001.phpt differ diff --git a/tests/tdb_first_key_001.phpt b/tests/tdb_first_key_001.phpt new file mode 100644 index 0000000..8bc9f5c --- /dev/null +++ b/tests/tdb_first_key_001.phpt @@ -0,0 +1,37 @@ +--TEST-- +tdb_first_key() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_get_flags_001.phpt b/tests/tdb_get_flags_001.phpt new file mode 100644 index 0000000..8d3adae --- /dev/null +++ b/tests/tdb_get_flags_001.phpt @@ -0,0 +1,40 @@ +--TEST-- +tdb_get_flags() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_get_seqnum_001.phpt b/tests/tdb_get_seqnum_001.phpt new file mode 100644 index 0000000..e3e106d --- /dev/null +++ b/tests/tdb_get_seqnum_001.phpt @@ -0,0 +1,49 @@ +--TEST-- +tdb_get_seqnum() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_get_seqnum_002.phpt b/tests/tdb_get_seqnum_002.phpt new file mode 100644 index 0000000..15f4225 --- /dev/null +++ b/tests/tdb_get_seqnum_002.phpt @@ -0,0 +1,22 @@ +--TEST-- +tdb_get_seqnum() without TDB_SEQNUM +--FILE-- + +--EXPECTF-- +int(0) +int(0) +int(0) +Done diff --git a/tests/tdb_insert_001.phpt b/tests/tdb_insert_001.phpt new file mode 100644 index 0000000..eb71b75 --- /dev/null +++ b/tests/tdb_insert_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +tdb_insert() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_lock_001.phpt b/tests/tdb_lock_001.phpt new file mode 100644 index 0000000..0d5fef5 --- /dev/null +++ b/tests/tdb_lock_001.phpt @@ -0,0 +1,41 @@ +--TEST-- +tdb_lock() and in-memory TDB +--FILE-- + +--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 diff --git a/tests/tdb_lock_002.phpt b/tests/tdb_lock_002.phpt new file mode 100644 index 0000000..dc1318a --- /dev/null +++ b/tests/tdb_lock_002.phpt @@ -0,0 +1,44 @@ +--TEST-- +tdb_lock() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_lock_003.phpt b/tests/tdb_lock_003.phpt new file mode 100644 index 0000000..2acaf3b --- /dev/null +++ b/tests/tdb_lock_003.phpt @@ -0,0 +1,40 @@ +--TEST-- +tdb_lock() and read lock +--FILE-- + +--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 diff --git a/tests/tdb_next_key_001.phpt b/tests/tdb_next_key_001.phpt new file mode 100644 index 0000000..2aa4d1f --- /dev/null +++ b/tests/tdb_next_key_001.phpt @@ -0,0 +1,46 @@ +--TEST-- +tdb_next_key() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_open_001.phpt b/tests/tdb_open_001.phpt new file mode 100644 index 0000000..b42bb76 --- /dev/null +++ b/tests/tdb_open_001.phpt @@ -0,0 +1,49 @@ +--TEST-- +tdb_open() errors +--FILE-- + +--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 diff --git a/tests/tdb_open_002.phpt b/tests/tdb_open_002.phpt new file mode 100644 index 0000000..2ecfbb1 --- /dev/null +++ b/tests/tdb_open_002.phpt @@ -0,0 +1,90 @@ +--TEST-- +tdb_open() errors - 2 +--FILE-- + +--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 diff --git a/tests/tdb_open_003.phpt b/tests/tdb_open_003.phpt new file mode 100644 index 0000000..61f49b7 --- /dev/null +++ b/tests/tdb_open_003.phpt @@ -0,0 +1,20 @@ +--TEST-- +tdb_open() in-memory test +--FILE-- + +--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 diff --git a/tests/tdb_replace_001.phpt b/tests/tdb_replace_001.phpt new file mode 100644 index 0000000..48c69ae --- /dev/null +++ b/tests/tdb_replace_001.phpt @@ -0,0 +1,29 @@ +--TEST-- +tdb_replace() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_set_max_dead_001.phpt b/tests/tdb_set_max_dead_001.phpt new file mode 100644 index 0000000..21589ef --- /dev/null +++ b/tests/tdb_set_max_dead_001.phpt @@ -0,0 +1,48 @@ +--TEST-- +tdb_set_max_dead() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_store_001.phpt b/tests/tdb_store_001.phpt new file mode 100644 index 0000000..e34f028 --- /dev/null +++ b/tests/tdb_store_001.phpt @@ -0,0 +1,79 @@ +--TEST-- +tdb_store() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_transactions_001.phpt b/tests/tdb_transactions_001.phpt new file mode 100644 index 0000000..58fe948 --- /dev/null +++ b/tests/tdb_transactions_001.phpt @@ -0,0 +1,80 @@ +--TEST-- +transactions funcs tests - wrong arguments +--FILE-- + +--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 diff --git a/tests/tdb_transactions_002.phpt b/tests/tdb_transactions_002.phpt new file mode 100644 index 0000000..eaabb40 --- /dev/null +++ b/tests/tdb_transactions_002.phpt @@ -0,0 +1,27 @@ +--TEST-- +transactions - in-memory TDB +--FILE-- + +--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 diff --git a/tests/tdb_transactions_003.phpt b/tests/tdb_transactions_003.phpt new file mode 100644 index 0000000..ef53f6e --- /dev/null +++ b/tests/tdb_transactions_003.phpt @@ -0,0 +1,46 @@ +--TEST-- +transactions - basic tests +--FILE-- + +--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 diff --git a/tests/tdb_transactions_004.phpt b/tests/tdb_transactions_004.phpt new file mode 100644 index 0000000..b18b88b --- /dev/null +++ b/tests/tdb_transactions_004.phpt @@ -0,0 +1,31 @@ +--TEST-- +transactions - nested transactions +--FILE-- + +--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 diff --git a/tests/tdb_transactions_005.phpt b/tests/tdb_transactions_005.phpt new file mode 100644 index 0000000..b94e34d --- /dev/null +++ b/tests/tdb_transactions_005.phpt @@ -0,0 +1,41 @@ +--TEST-- +transactions - basic transactions +--FILE-- + +--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 diff --git a/tests/tdb_unlock_001.phpt b/tests/tdb_unlock_001.phpt new file mode 100644 index 0000000..7a56504 --- /dev/null +++ b/tests/tdb_unlock_001.phpt @@ -0,0 +1,45 @@ +--TEST-- +tdb_unlock() and in-memory TDB +--FILE-- + +--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 diff --git a/tests/tdb_unlock_002.phpt b/tests/tdb_unlock_002.phpt new file mode 100644 index 0000000..15a3584 --- /dev/null +++ b/tests/tdb_unlock_002.phpt @@ -0,0 +1,62 @@ +--TEST-- +tdb_unlock() basic tests +--FILE-- + +--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 diff --git a/tests/tdb_update_001.phpt b/tests/tdb_update_001.phpt new file mode 100644 index 0000000..d1afce8 --- /dev/null +++ b/tests/tdb_update_001.phpt @@ -0,0 +1,54 @@ +--TEST-- +tdb_update() basic tests +--FILE-- + +--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