diff options
author | Hartmut Holzgraefe <hholzgra@php.net> | 2001-10-01 12:51:12 +0000 |
---|---|---|
committer | Hartmut Holzgraefe <hholzgra@php.net> | 2001-10-01 12:51:12 +0000 |
commit | 41b30151257db033c6d40e17e196f2bac2c05f82 (patch) | |
tree | 7ffc059114cb876f3b4b5c9070b43a55c4007be3 | |
parent | 42b7601378610a7cc7e8a4a7ec9498f03f3255c4 (diff) | |
download | php-git-41b30151257db033c6d40e17e196f2bac2c05f82.tar.gz |
MFH
-rw-r--r-- | ext/dbplus/dbplus.c | 236 | ||||
-rw-r--r-- | ext/dbplus/nonimp_dbplus.c | 141 | ||||
-rw-r--r-- | ext/dbplus/php_dbplus.c | 2020 | ||||
-rw-r--r-- | ext/dbplus/php_dbplus.h | 12 |
4 files changed, 1297 insertions, 1112 deletions
diff --git a/ext/dbplus/dbplus.c b/ext/dbplus/dbplus.c index 8bbd352fc3..8b7ee4e207 100644 --- a/ext/dbplus/dbplus.c +++ b/ext/dbplus/dbplus.c @@ -18,9 +18,15 @@ */ #include "php.h" +#include "ext/standard/info.h" #include "php_ini.h" #include "php_dbplus.h" +#include <saccess.h> +#include <relation.h> +#include <dblight.h> + + /* If you declare any globals in php_dbplus.h uncomment this: ZEND_DECLARE_MODULE_GLOBALS(dbplus) */ @@ -38,17 +44,17 @@ int le_dbplus_tupel; void dbplus_destruct_relation(zend_rsrc_list_entry *rsrc TSRMLS_DC) { - relf *conn = (relf *)(rsrc->ptr); + relf *conn = (relf *)(rsrc->ptr); - cdb_close(conn); + cdb_close(conn); } void dbplus_destruct_tupel(zend_rsrc_list_entry *rsrc TSRMLS_DC) { - tuple *t = (tuple *)(rsrc->ptr); + tuple *t = (tuple *)(rsrc->ptr); - efree(t); + efree(t); } /* }}} */ @@ -58,54 +64,53 @@ void dbplus_destruct_tupel(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* Every user visible function must have an entry in dbplus_functions[]. */ function_entry dbplus_functions[] = { - PHP_FE(dbplus_add, NULL) - PHP_FE(dbplus_aql, NULL) - PHP_FE(dbplus_change, NULL) - PHP_FE(dbplus_chdir, NULL) - PHP_FE(dbplus_close, NULL) - PHP_FE(dbplus_curr, NULL) - PHP_FE(dbplus_errno, NULL) - PHP_FE(dbplus_errcode, NULL) - PHP_FE(dbplus_find, NULL) - PHP_FE(dbplus_first, NULL) - PHP_FE(dbplus_flush, NULL) - PHP_FE(dbplus_freealllocks, NULL) - PHP_FE(dbplus_freelock, NULL) - PHP_FE(dbplus_freerlocks, NULL) - PHP_FE(dbplus_getlock, NULL) - PHP_FE(dbplus_getunique, NULL) - PHP_FE(dbplus_info, NULL) - PHP_FE(dbplus_last, NULL) - PHP_FE(dbplus_next, NULL) - PHP_FE(dbplus_open, NULL) - PHP_FE(dbplus_prev, NULL) - PHP_FE(dbplus_rchperm, NULL) - PHP_FE(dbplus_rcreate, NULL) - PHP_FE(dbplus_rcrtexact, NULL) - PHP_FE(dbplus_rcrtlike, NULL) - PHP_FE(dbplus_resolve, NULL) - PHP_FE(dbplus_restorepos, NULL) - PHP_FE(dbplus_rkeys, NULL) - PHP_FE(dbplus_ropen, NULL) - PHP_FE(dbplus_rquery, NULL) - PHP_FE(dbplus_rrename, NULL) - PHP_FE(dbplus_rsecindex, NULL) - PHP_FE(dbplus_runlink, NULL) - PHP_FE(dbplus_rzap, NULL) - PHP_FE(dbplus_savepos, NULL) - PHP_FE(dbplus_setindex, NULL) - PHP_FE(dbplus_setindexbynumber, NULL) - PHP_FE(dbplus_sql, NULL) - PHP_FE(dbplus_tcl, NULL) - PHP_FE(dbplus_tremove, NULL) - PHP_FE(dbplus_undo, NULL) - PHP_FE(dbplus_undoprepare, NULL) - PHP_FE(dbplus_unlockrel, NULL) - PHP_FE(dbplus_unselect, NULL) - PHP_FE(dbplus_update, NULL) - PHP_FE(dbplus_xlockrel, NULL) - PHP_FE(dbplus_xunlockrel, NULL) - {NULL, NULL, NULL} /* Must be the last line in dbplus_functions[] */ + PHP_FE(dbplus_add, NULL) + PHP_FE(dbplus_aql, NULL) + PHP_FE(dbplus_chdir, NULL) + PHP_FE(dbplus_close, NULL) + PHP_FE(dbplus_curr, NULL) + PHP_FE(dbplus_errno, NULL) + PHP_FE(dbplus_errcode, NULL) + PHP_FE(dbplus_find, NULL) + PHP_FE(dbplus_first, NULL) + PHP_FE(dbplus_flush, NULL) + PHP_FE(dbplus_freealllocks, NULL) + PHP_FE(dbplus_freelock, NULL) + PHP_FE(dbplus_freerlocks, NULL) + PHP_FE(dbplus_getlock, NULL) + PHP_FE(dbplus_getunique, NULL) + PHP_FE(dbplus_info, NULL) + PHP_FE(dbplus_last, NULL) + PHP_FE(dbplus_next, NULL) + PHP_FE(dbplus_open, NULL) + PHP_FE(dbplus_prev, NULL) + PHP_FE(dbplus_rchperm, NULL) + PHP_FE(dbplus_rcreate, NULL) + PHP_FE(dbplus_rcrtexact, NULL) + PHP_FE(dbplus_rcrtlike, NULL) + PHP_FE(dbplus_resolve, NULL) + PHP_FE(dbplus_restorepos, NULL) + PHP_FE(dbplus_rkeys, NULL) + PHP_FE(dbplus_ropen, NULL) + PHP_FE(dbplus_rquery, NULL) + PHP_FE(dbplus_rrename, NULL) + PHP_FE(dbplus_rsecindex, NULL) + PHP_FE(dbplus_runlink, NULL) + PHP_FE(dbplus_rzap, NULL) + PHP_FE(dbplus_savepos, NULL) + PHP_FE(dbplus_setindex, NULL) + PHP_FE(dbplus_setindexbynumber, NULL) + PHP_FE(dbplus_sql, NULL) + PHP_FE(dbplus_tcl, NULL) + PHP_FE(dbplus_tremove, NULL) + PHP_FE(dbplus_undo, NULL) + PHP_FE(dbplus_undoprepare, NULL) + PHP_FE(dbplus_unlockrel, NULL) + PHP_FE(dbplus_unselect, NULL) + PHP_FE(dbplus_update, NULL) + PHP_FE(dbplus_xlockrel, NULL) + PHP_FE(dbplus_xunlockrel, NULL) + {NULL, NULL, NULL} /* Must be the last line in dbplus_functions[] */ }; /* }}} */ @@ -113,14 +118,14 @@ function_entry dbplus_functions[] = { /* {{{ module entry */ zend_module_entry dbplus_module_entry = { - "dbplus", - dbplus_functions, - PHP_MINIT(dbplus), - PHP_MSHUTDOWN(dbplus), - PHP_RINIT(dbplus), /* Replace with NULL if there's nothing to do at request start */ - PHP_RSHUTDOWN(dbplus), /* Replace with NULL if there's nothing to do at request end */ - PHP_MINFO(dbplus), - STANDARD_MODULE_PROPERTIES + "dbplus", + dbplus_functions, + PHP_MINIT(dbplus), + PHP_MSHUTDOWN(dbplus), + PHP_RINIT(dbplus), /* Replace with NULL if there's nothing to do at request start */ + PHP_RSHUTDOWN(dbplus), /* Replace with NULL if there's nothing to do at request end */ + PHP_MINFO(dbplus), + STANDARD_MODULE_PROPERTIES }; /* }}} */ @@ -138,11 +143,52 @@ PHP_INI_END() PHP_MINIT_FUNCTION(dbplus) { - /* resource id for cdb connections */ - le_dbplus_relation = zend_register_list_destructors_ex(dbplus_destruct_relation, NULL, "dbplus_relation", module_number); - le_dbplus_tupel = zend_register_list_destructors_ex(dbplus_destruct_tupel , NULL, "dbplus_tuple" , module_number); - - return SUCCESS; + /* resource id for cdb connections */ + le_dbplus_relation = zend_register_list_destructors_ex(dbplus_destruct_relation, NULL, "dbplus_relation", module_number); + le_dbplus_tupel = zend_register_list_destructors_ex(dbplus_destruct_tupel , NULL, "dbplus_tuple" , module_number); + + /* constants for DBPLUS error codes */ + REGISTER_LONG_CONSTANT("DBPLUS_ERR_NOERR", ERR_NOERR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_DUPLICATE", ERR_DUPLICATE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_EOSCAN", ERR_EOSCAN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_EMPTY", ERR_EMPTY, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_CLOSE", ERR_CLOSE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_WLOCKED", ERR_WLOCKED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_LOCKED", ERR_LOCKED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_NOLOCK", ERR_NOLOCK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_READ", ERR_READ, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_WRITE", ERR_WRITE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_CREATE", ERR_CREATE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_LSEEK", ERR_LSEEK, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_LENGTH", ERR_LENGTH, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_OPEN", ERR_OPEN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_WOPEN", ERR_WOPEN, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_MAGIC", ERR_MAGIC, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_VERSION", ERR_VERSION, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_PGSIZE", ERR_PGSIZE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_CRC", ERR_CRC, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_PIPE", ERR_PIPE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_NIDX", ERR_NIDX, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_MALLOC", ERR_MALLOC, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_NUSERS", ERR_NUSERS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_PREEXIT", ERR_PREEXIT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_ONTRAP", ERR_ONTRAP, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_PREPROC", ERR_PREPROC, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_DBPARSE", ERR_DBPARSE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_DBRUNERR", ERR_DBRUNERR, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_DBPREEXIT", ERR_DBPREEXIT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_WAIT", ERR_WAIT, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_CORRUPT_TUPLE", ERR_CORRUPT_TUPLE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_WARNING0", ERR_WARNING0, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_PANIC", ERR_PANIC, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_FIFO", ERR_FIFO, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_PERM", ERR_PERM, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_TCL", ERR_TCL, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_RESTRICTED", ERR_RESTRICTED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_USER", ERR_USER, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("DBPLUS_ERR_UNKNOWN", ERR_UNKNOWN, CONST_CS | CONST_PERSISTENT); + + return SUCCESS; } /* }}} */ @@ -151,7 +197,7 @@ PHP_MINIT_FUNCTION(dbplus) PHP_MSHUTDOWN_FUNCTION(dbplus) { - return SUCCESS; + return SUCCESS; } /* }}} */ @@ -161,7 +207,7 @@ PHP_MSHUTDOWN_FUNCTION(dbplus) /* Remove if there's nothing to do at request start */ PHP_RINIT_FUNCTION(dbplus) { - return SUCCESS; + return SUCCESS; } /* }}} */ @@ -171,7 +217,7 @@ PHP_RINIT_FUNCTION(dbplus) /* Remove if there's nothing to do at request end */ PHP_RSHUTDOWN_FUNCTION(dbplus) { - return SUCCESS; + return SUCCESS; } /* }}} */ @@ -180,13 +226,13 @@ PHP_RSHUTDOWN_FUNCTION(dbplus) PHP_MINFO_FUNCTION(dbplus) { - php_info_print_table_start(); - php_info_print_table_header(2, "dbplus support", "enabled"); - php_info_print_table_end(); + php_info_print_table_start(); + php_info_print_table_header(2, "dbplus support", "enabled"); + php_info_print_table_end(); - /* Remove comments if you have entries in php.ini - DISPLAY_INI_ENTRIES(); - */ + /* Remove comments if you have entries in php.ini + DISPLAY_INI_ENTRIES(); + */ } /* }}} */ @@ -197,24 +243,24 @@ PHP_MINFO_FUNCTION(dbplus) */ PHP_FUNCTION(dbplus_open) { - relf *conn; + relf *conn; - zval **name, **writing, **searchpath; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &name, &writing, &searchpath) == FAILURE){ - WRONG_PARAM_COUNT; - } + zval **name, **writing, **searchpath; + if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &name, &writing, &searchpath) == FAILURE){ + WRONG_PARAM_COUNT; + } - convert_to_string_ex(name); - convert_to_long_ex(writing); - convert_to_long_ex(searchpath); + convert_to_string_ex(name); + convert_to_long_ex(writing); + convert_to_long_ex(searchpath); - conn = cdb_open((*name)->value.str.val, (*writing)->value.lval, (*searchpath)->value.lval); - if(conn == NULL) { - /* TODO error handling */ - RETURN_FALSE; - } + conn = cdb_open(Z_STRVAL_PP(name), Z_LVAL_PP(writing), Z_LVAL_PP(searchpath)); + if(conn == NULL) { + /* TODO error handling */ + RETURN_FALSE; + } - ZEND_REGISTER_RESOURCE(return_value, conn, le_dbplus); + ZEND_REGISTER_RESOURCE(return_value, conn, le_dbplus); } /* }}} */ @@ -223,16 +269,16 @@ PHP_FUNCTION(dbplus_open) */ PHP_FUNCTION(dbplus_close) { - zval **conn; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &conn) == FAILURE){ - WRONG_PARAM_COUNT; - } + zval **conn; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &conn) == FAILURE){ + WRONG_PARAM_COUNT; + } - convert_to_long_ex(conn); + convert_to_long_ex(conn); - /* TODO resource type check */ + /* TODO resource type check */ - zend_list_delete((*conn)->value.lval); + zend_list_delete(Z_LVAL_PP(conn)); } /* }}} */ #endif diff --git a/ext/dbplus/nonimp_dbplus.c b/ext/dbplus/nonimp_dbplus.c deleted file mode 100644 index 4dbb413208..0000000000 --- a/ext/dbplus/nonimp_dbplus.c +++ /dev/null @@ -1,141 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.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. | - +----------------------------------------------------------------------+ - | Authors: Hartmut Holzgraefe <hartmut@six.de> | - | | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "php_ini.h" -#include "php_dbplus.h" - - -/* {{{ proto int dbplus_change(int handle, string domain) - */ -PHP_FUNCTION(dbplus_change) -{ - zval **handle, **domain; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &handle, &domain) == FAILURE){ - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(handle); - convert_to_string_ex(domain); - - - php_error(E_WARNING, "dbplus_change: not yet implemented"); -} -/* }}} */ - - - - - -/* {{{ proto int dbplus_rcreate(string name, string domlist, int flag) - */ -PHP_FUNCTION(dbplus_rcreate) -{ - zval **name, **domlist, **flag; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &name, &domlist, &flag) == FAILURE){ - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(name); - convert_to_string_ex(domlist); - convert_to_long_ex(flag); - - - php_error(E_WARNING, "dbplus_rcreate: not yet implemented"); -} -/* }}} */ - -/* {{{ proto int dbplus_rcrtexact(string name, int handle, int flag) - */ -PHP_FUNCTION(dbplus_rcrtexact) -{ - zval **name, **handle, **flag; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &name, &handle, &flag) == FAILURE){ - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(name); - convert_to_long_ex(handle); - convert_to_long_ex(flag); - - - php_error(E_WARNING, "dbplus_rcrtexact: not yet implemented"); -} -/* }}} */ - -/* {{{ proto int dbplus_rcrtlike(string name, int handle, int flag) - */ -PHP_FUNCTION(dbplus_rcrtlike) -{ - zval **name, **handle, **flag; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &name, &handle, &flag) == FAILURE){ - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(name); - convert_to_long_ex(handle); - convert_to_long_ex(flag); - - - php_error(E_WARNING, "dbplus_rcrtlike: not yet implemented"); -} -/* }}} */ - -/* {{{ proto int dbplus_resolve(string name, string vname) - */ -PHP_FUNCTION(dbplus_resolve) -{ - zval **name, **vname; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &name, &vname) == FAILURE){ - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(name); - convert_to_string_ex(vname); - - - php_error(E_WARNING, "dbplus_resolve: not yet implemented"); -} -/* }}} */ - -/* {{{ proto int dbplus_tcl(int sid, string script) - */ -PHP_FUNCTION(dbplus_tcl) -{ - zval **sid, **script; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &sid, &script) == FAILURE){ - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(sid); - convert_to_string_ex(script); - - - php_error(E_WARNING, "dbplus_tcl: not yet implemented"); -} -/* }}} */ - - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/dbplus/php_dbplus.c b/ext/dbplus/php_dbplus.c index 8dfd4885ef..9515c5f5dd 100644 --- a/ext/dbplus/php_dbplus.c +++ b/ext/dbplus/php_dbplus.c @@ -21,77 +21,114 @@ #include "php_ini.h" #include "php_dbplus.h" +#include "ext/standard/php_string.h" -#define _STRING(x) ((*x)->value.str.val) -#define _INT(x) ((*x)->value.lval) -#define _HASH(x) ((*x)->value.ht) +#include <saccess.h> +#include <relation.h> +#include <dblight.h> -#define DBPLUS_FETCH_RESOURCE(r, z) ZEND_FETCH_RESOURCE(r, relf *, z, -1, "dbplus_relation", le_dbplus_relation); \ - if(!r) RETURN_LONG(ERR_UNKNOWN); +/* missing prototypes in dbplus header files */ +void string_to_scalop(char *op, enum scalop *sop); +field * string_to_field(char *val, attribute *ap, int flags); +void cdb_tcl(int,char *,char **, int *); +relf * aql_exec(char *, char *); +tuple *rnext(relf *); + + +#define _STRING(x) (Z_STRVAL_PP(x)) +#define _INT(x) (Z_LVAL_PP(x)) +#define _HASH(x) (Z_ARRVAL_PP(x)) + +#define DBPLUS_FETCH_RESOURCE(r, z) ZEND_FETCH_RESOURCE(r, relf *, z, -1, "dbplus_relation", le_dbplus_relation); \ + if(!r) RETURN_LONG(ERR_UNKNOWN); static int -var2tuple(relf *r, zval **zv, tuple *t) +var2tuple(relf *r, zval **zv, tuple *t) { - register attribute *ap ; - unsigned deg ; - zval **element; - - if ((*zv)->type!=IS_ARRAY) - return 1; - - rtupinit(r, t); - - ap = r->r_atts; - deg = r->r_rel.rel_deg; - do { - if(SUCCESS!=zend_hash_find((*zv)->value.ht, ap->att_name, strlen(ap->att_name)+1, (void **)&element)) - continue; - - if (! *element) return 1; - - switch(ap->att_type) { - case FT_SHORT: - convert_to_long_ex(element); - AFFIX(ap, t)->f_short = (short) (*element)->value.lval; - break; - case FT_UNSIGNED: - convert_to_long_ex(element); - AFFIX(ap, t)->f_unsigned = (unsigned) (*element)->value.lval; - break; - case FT_SEQUENCE: - case FT_LONG: - convert_to_long_ex(element); - AFFIX(ap, t)->f_long = (long) (*element)->value.lval; - break; - case FT_DATE: - convert_to_long_ex(element); - AFFIX(ap, t)->f_date = (long) (*element)->value.lval; - break; - case FT_FLOAT: - convert_to_double_ex(element); - AFFIX(ap, t)->f_float = (float) (*element)->value.dval; - break; - case FT_DOUBLE: - convert_to_double_ex(element); - AFFIX(ap, t)->f_double = (double) (*element)->value.dval; - break; - case FT_STRING: case FT_DEUTSCH: case FT_CHAR: - convert_to_string_ex(element); - afput(ap, t, (field *)0, (*element)->value.str.val); - break; - case FT_TIMESTAMP: - /* TODO - str2timestamp(SvPV(sv, na), (timestamp *)AFFIX(ap, t)); - */ - break; - case FT_BINARY: - case FT_BLOB: - case FT_MEMO: - break; - } - } while (ap++, --deg); - return 0; + register attribute *ap ; + unsigned deg ; + zval **element; + + if (Z_TYPE_PP(zv)!=IS_ARRAY) + return 1; + + rtupinit(r, t); + + ap = r->r_atts; + deg = r->r_rel.rel_deg; + do { + if(SUCCESS!=zend_hash_find(Z_ARRVAL_PP(zv), ap->att_name, strlen(ap->att_name)+1, (void **)&element)) { + continue; + } + + if (! *element) { + return 1; + } + + switch(ap->att_type) { + + case FT_SHORT: + /* short integer */ + convert_to_long_ex(element); + AFFIX(ap, t)->f_short = (short) Z_LVAL_PP(element); + break; + + case FT_UNSIGNED: + /* unsigned short integer */ + convert_to_long_ex(element); + AFFIX(ap, t)->f_unsigned = (unsigned) Z_LVAL_PP(element); + break; + + case FT_LONG: + /* 32bit signed long */ + case FT_SEQUENCE: + /* unique sequence number -> just a long to outsiders */ + convert_to_long_ex(element); + AFFIX(ap, t)->f_long = (long4) Z_LVAL_PP(element); + break; + + case FT_DATE: + /* date -> long containing YYYYMMDD */ + convert_to_long_ex(element); + AFFIX(ap, t)->f_date = (long4) Z_LVAL_PP(element); + break; + + case FT_TIME: + /* time as unix timestamp */ + convert_to_long_ex(element); + AFFIX(ap, t)->f_time = (long4) Z_LVAL_PP(element); + break; + + case FT_FLOAT: + /* single prec. floating point */ + convert_to_double_ex(element); + AFFIX(ap, t)->f_float = (float) Z_DVAL_PP(element); + break; + + case FT_DOUBLE: + /* double prec. floating point */ + convert_to_double_ex(element); + AFFIX(ap, t)->f_double = (double) Z_DVAL_PP(element); + break; + + case FT_STRING: + case FT_DEUTSCH: + case FT_CHAR: + case FT_ANSI: + case FT_ISO: + case FT_ISOL: + /* different variants of Strings */ + convert_to_string_ex(element); + afput(ap, t, (field *)0, Z_STRVAL_PP(element)); + break; + + default: + php_error(E_WARNING,"%s is of yet unsupported type %d",ap->att_name,ap->att_type); + break; + } + } while (ap++, --deg); + return 0; } @@ -101,71 +138,63 @@ tuple2var(relf * r, tuple * t, zval **zv) { register attribute *ap ; unsigned deg ; - char buf[20]; - zval *element; + zval *element; - zval_dtor(*zv); - if (array_init(*zv) == FAILURE) { - return 1; - } + zval_dtor(*zv); + if (array_init(*zv) == FAILURE) { + return 1; + } ap = r->r_atts; deg = r->r_rel.rel_deg; do { - MAKE_STD_ZVAL(element); element->type=IS_NULL; - - switch(ap->att_type) { - case FT_SHORT: - ZVAL_LONG(element, AFFIX(ap, t)->f_short); - break; - - case FT_UNSIGNED: - ZVAL_LONG(element, AFFIX(ap, t)->f_unsigned); - break; - - case FT_LONG: - ZVAL_LONG(element, AFFIX(ap, t)->f_long); - break; - - case FT_FLOAT: - ZVAL_DOUBLE(element, AFFIX(ap, t)->f_float); - break; - - case FT_DOUBLE: - ZVAL_DOUBLE(element, AFFIX(ap, t)->f_double); - break; - - case FT_STRING: case FT_DEUTSCH: case FT_CHAR: - ZVAL_STRING(element, AFVAR(ap, t)->f_string, 1); - break; - - /* - case FT_P_SHORT: return "FT_P_SHORT"; - case FT_P_LONG: return "FT_P_LONG"; - case FT_DATE: return "FT_DATE"; - case FT_TIME: return "FT_TIME"; - case FT_BINARY: return "FT_BINARY"; - case FT_BLOB: return "FT_BLOB"; - case FT_ANSI: return "FT_ANSI"; - case FT_TIMESTAMP: return "FT_TIMESTAMP"; - case FT_SEQUENCE: return "FT_SEQUENCE"; - case FT_MEMO: return "FT_MEMO"; - case FT_ISO: return "FT_ISO"; - case FT_ISOL: return "FT_ISOL"; - case FT_ANON: return "FT_ANON"; - case FT_TUPID: return "FT_TUPID"; - case FT_INVALID: return "FT_INVALID"; - */ - } - - if(element->type!=IS_NULL) - zend_hash_update((*zv)->value.ht, - ap->att_name, - strlen(ap->att_name)+1, - (void *)&element, - sizeof(zval*), - NULL); - + MAKE_STD_ZVAL(element); Z_TYPE_P(element)=IS_NULL; + + switch(ap->att_type) { + case FT_SHORT: + ZVAL_LONG(element, AFFIX(ap, t)->f_short); + break; + + case FT_UNSIGNED: + ZVAL_LONG(element, AFFIX(ap, t)->f_unsigned); + break; + + case FT_LONG: + case FT_SEQUENCE: + ZVAL_LONG(element, AFFIX(ap, t)->f_long); + break; + + case FT_TIME: + ZVAL_LONG(element, AFFIX(ap, t)->f_time); + break; + + case FT_FLOAT: + ZVAL_DOUBLE(element, AFFIX(ap, t)->f_float); + break; + + case FT_DOUBLE: + ZVAL_DOUBLE(element, AFFIX(ap, t)->f_double); + break; + + case FT_STRING: + case FT_DEUTSCH: + case FT_CHAR: + ZVAL_STRING(element, AFVAR(ap, t)->f_string, 1); + break; + + default: + php_error(E_WARNING,"%s is of yet unsupported type %d",ap->att_name,ap->att_type); + break; + } + + if(Z_TYPE_P(element)!=IS_NULL) + zend_hash_update(Z_ARRVAL_PP(zv), + ap->att_name, + strlen(ap->att_name)+1, + (void *)&element, + sizeof(zval*), + NULL); + } while (ap++, --deg); return 0; } @@ -173,120 +202,116 @@ tuple2var(relf * r, tuple * t, zval **zv) static constraint * ary2constr(relf * r, zval** constr) { - attribute *ap; - static constraint c; - int len; - int alen; - field *f; - enum scalop sop; - int n_elems; - int n; - char * dom; - char * val; - char * op; - zval **zdata; - - /* init first */ - db_coninit(r, &c); - - if ((*constr)->type != IS_ARRAY) { - php_error(E_WARNING, "Constraint is not an array"); - return NULL; - } + attribute *ap; + static constraint c; + field *f; + enum scalop sop; + char * dom; + char * val; + char * op; + zval **zdata; + + /* init first */ + db_coninit(r, &c); + + if (Z_TYPE_PP(constr) != IS_ARRAY) { + php_error(E_WARNING, "Constraint is not an array"); + return NULL; + } + + zend_hash_internal_pointer_reset(_HASH(constr)); + if(zend_hash_get_current_data(_HASH(constr), (void **)&zdata)!=SUCCESS) { + php_error(E_WARNING, "Constraint array is empty"); + return NULL; + } + + switch(Z_TYPE_PP(zdata)) { + case IS_STRING: /* constraints in plain string array */ + if (_HASH(constr)->nNumOfElements%3) { + php_error(E_WARNING, "Constraint array has to have triples of strings"); + return NULL; + } - zend_hash_internal_pointer_reset(_HASH(constr)); - if(zend_hash_get_current_data(_HASH(constr), (void **)&zdata)!=SUCCESS) { - php_error(E_WARNING, "Constraint array is empty"); - return NULL; - } - - switch((*zdata)->type) { - case IS_STRING: /* constraints in plain string array */ - if (_HASH(constr)->nNumOfElements%3) { - php_error(E_WARNING, "Constraint array has to have triples of strings"); - return NULL; - } - - do { - convert_to_string_ex(zdata); - dom = _STRING(zdata); - zend_hash_move_forward(_HASH(constr)); - zend_hash_get_current_data(_HASH(constr), (void **)&zdata); - convert_to_string_ex(zdata); - op = _STRING(zdata); - zend_hash_move_forward(_HASH(constr)); - zend_hash_get_current_data(_HASH(constr), (void **)&zdata); - convert_to_string_ex(zdata); - val = _STRING(zdata); - zend_hash_move_forward(_HASH(constr)); - - if (!(ap = (attribute *) attno (r, dom))) { - fprintf(stderr, "Invalid domain \"%s\"\n", dom); - return 0; - } - - /* operator */ - string_to_scalop(op, &sop); - - /* value */ - f = string_to_field(val, ap, 0); - - (void) db_constrain(r, &c, dom, sop, f ? f : (field *) val); - } while(SUCCESS==zend_hash_get_current_data(_HASH(constr), (void **)&zdata)); - - break; - case IS_ARRAY: - { - zval **entry; - for(zend_hash_internal_pointer_reset(_HASH(constr)); - SUCCESS==zend_hash_get_current_data(_HASH(constr), (void **)&zdata); - zend_hash_move_forward(_HASH(constr))) { - if(!((*zdata)->type==IS_ARRAY)) { - php_error(E_WARNING, "Constraint array element not an array"); - return NULL; - } - if(_HASH(zdata)->nNumOfElements!=3) { - php_error(E_WARNING, "Constraint array element not an array of size 3"); - return NULL; - } - - zend_hash_internal_pointer_reset(_HASH(zdata)); - zend_hash_get_current_data(_HASH(zdata), (void **)&entry); - convert_to_string_ex(entry); - dom=_STRING(entry); - - zend_hash_move_forward(_HASH(zdata)); - zend_hash_get_current_data(_HASH(zdata), (void **)&entry); - convert_to_string_ex(entry); - op=_STRING(entry); - - zend_hash_move_forward(_HASH(zdata)); - zend_hash_get_current_data(_HASH(zdata), (void **)&entry); - convert_to_string_ex(entry); - val=_STRING(entry); - - if (!(ap = (attribute *) attno (r, dom))) { - fprintf(stderr, "Invalid domain \"%s\"\n", dom); - return 0; - } - - /* operator */ - string_to_scalop(op, &sop); - - /* value */ - f = string_to_field(val, ap, 0); - - (void) db_constrain(r, &c, dom, sop, f ? f : (field *) val); - } - - } - break; - default: - /* TODO error-handling */ - return NULL; - } - - return &c; + do { + convert_to_string_ex(zdata); + dom = _STRING(zdata); + zend_hash_move_forward(_HASH(constr)); + zend_hash_get_current_data(_HASH(constr), (void **)&zdata); + convert_to_string_ex(zdata); + op = _STRING(zdata); + zend_hash_move_forward(_HASH(constr)); + zend_hash_get_current_data(_HASH(constr), (void **)&zdata); + convert_to_string_ex(zdata); + val = _STRING(zdata); + zend_hash_move_forward(_HASH(constr)); + + if (!(ap = (attribute *) attno (r, dom))) { + fprintf(stderr, "Invalid domain \"%s\"\n", dom); + return 0; + } + + /* operator */ + string_to_scalop(op, &sop); + + /* value */ + f = string_to_field(val, ap, 0); + + (void) db_constrain(r, &c, dom, sop, f ? f : (field *) val); + } while(SUCCESS==zend_hash_get_current_data(_HASH(constr), (void **)&zdata)); + + break; + case IS_ARRAY: + { + zval **entry; + for(zend_hash_internal_pointer_reset(_HASH(constr)); + SUCCESS==zend_hash_get_current_data(_HASH(constr), (void **)&zdata); + zend_hash_move_forward(_HASH(constr))) { + if(!(Z_TYPE_PP(zdata)==IS_ARRAY)) { + php_error(E_WARNING, "Constraint array element not an array"); + return NULL; + } + if(_HASH(zdata)->nNumOfElements!=3) { + php_error(E_WARNING, "Constraint array element not an array of size 3"); + return NULL; + } + + zend_hash_internal_pointer_reset(_HASH(zdata)); + zend_hash_get_current_data(_HASH(zdata), (void **)&entry); + convert_to_string_ex(entry); + dom=_STRING(entry); + + zend_hash_move_forward(_HASH(zdata)); + zend_hash_get_current_data(_HASH(zdata), (void **)&entry); + convert_to_string_ex(entry); + op=_STRING(entry); + + zend_hash_move_forward(_HASH(zdata)); + zend_hash_get_current_data(_HASH(zdata), (void **)&entry); + convert_to_string_ex(entry); + val=_STRING(entry); + + if (!(ap = (attribute *) attno (r, dom))) { + fprintf(stderr, "Invalid domain \"%s\"\n", dom); + return 0; + } + + /* operator */ + string_to_scalop(op, &sop); + + /* value */ + f = string_to_field(val, ap, 0); + + (void) db_constrain(r, &c, dom, sop, f ? f : (field *) val); + } + + } + break; + default: + /* TODO error-handling */ + return NULL; + } + + return &c; } @@ -294,65 +319,68 @@ ary2constr(relf * r, zval** constr) Add a tuple to a relation */ PHP_FUNCTION(dbplus_add) { - zval **relation, **data, **element; - enum errorcond stat = ERR_UNKNOWN; - relf *r; - tuple t; + zval **relation, **data; + enum errorcond stat = ERR_UNKNOWN; + relf *r; + tuple t; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &data) == FAILURE){ - WRONG_PARAM_COUNT; - } + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &data) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); - convert_to_array_ex(data); - - if(var2tuple(r, data, &t)) - RETURN_LONG(ERR_UNKNOWN); + DBPLUS_FETCH_RESOURCE(r, relation); + convert_to_array_ex(data); + + if(var2tuple(r, data, &t)) + RETURN_LONG(ERR_UNKNOWN); - stat=cdb_add(r, &t); + stat=cdb_add(r, &t); + if(stat==ERR_NOERR) { + tuple2var(r, &t, data); + } - RETURN_LONG(stat); + RETURN_LONG(stat); } /* }}} */ -/* {{{ proto int dbplus_aql(string query [, string server [, string dbpath]]) +/* {{{ proto resource dbplus_aql(string query [, string server [, string dbpath]]) Perform AQL query */ PHP_FUNCTION(dbplus_aql) { - int argc; - zval **query, **server, **dbpath; - relf *r; - - argc = ZEND_NUM_ARGS(); - if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &query, &server, &dbpath) == FAILURE){ - WRONG_PARAM_COUNT; - } - - switch (argc) { - case 3: - convert_to_string_ex(dbpath); - php_error(E_WARNING, "Arg dbpath: %s", _STRING(dbpath)); - /* Fall-through. */ - case 2: - convert_to_string_ex(server); - php_error(E_WARNING, "Arg server: %s", _STRING(server)); - /* Fall-through. */ - case 1: - convert_to_string_ex(query); - php_error(E_WARNING, "Arg query: %s", _STRING(query)); - break; - } - - r = cdb_aql((argc>=2)?_STRING(server):"localhost", - _STRING(query), - (argc==3)?_STRING(dbpath):NULL); - if(r == NULL) { - /* TODO error handling */ - RETURN_FALSE; - } - - ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); + int argc; + zval **query, **server, **dbpath; + relf *r; + + argc = ZEND_NUM_ARGS(); + if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &query, &server, &dbpath) == FAILURE){ + WRONG_PARAM_COUNT; + } + + switch (argc) { + case 3: + convert_to_string_ex(dbpath); + php_error(E_WARNING, "Arg dbpath: %s", _STRING(dbpath)); + /* Fall-through. */ + case 2: + convert_to_string_ex(server); + php_error(E_WARNING, "Arg server: %s", _STRING(server)); + /* Fall-through. */ + case 1: + convert_to_string_ex(query); + php_error(E_WARNING, "Arg query: %s", _STRING(query)); + break; + } + + r = cdb_aql((argc>=2)?_STRING(server):"localhost", + _STRING(query), + (argc==3)?_STRING(dbpath):NULL); + if(r == NULL) { + /* TODO error handling */ + RETURN_FALSE; + } + + ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); } /* }}} */ @@ -360,17 +388,31 @@ PHP_FUNCTION(dbplus_aql) Get/Set database virtual current directory */ PHP_FUNCTION(dbplus_chdir) { - int argc; - zval **newdir; - - argc = ZEND_NUM_ARGS(); - if (argc > 1 || zend_get_parameters_ex(1, &newdir) == FAILURE){ - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(newdir); - - RETURN_STRING(cdb_chdir((argc==1)?_STRING(newdir):NULL), 1); + int argc; + char *p; + zval **newdir; + + argc = ZEND_NUM_ARGS(); + switch(argc) { + case 0: + break; + case 1: + if(zend_get_parameters_ex(1, &newdir) == FAILURE) { + WRONG_PARAM_COUNT; + } else { + convert_to_string_ex(newdir); + } + break; + default: + WRONG_PARAM_COUNT; + } + + p = cdb_chdir((argc)?_STRING(newdir):NULL); + if(p) { + RETURN_STRING(p, 1); + } else { + RETURN_FALSE; + } } /* }}} */ @@ -378,17 +420,17 @@ PHP_FUNCTION(dbplus_chdir) Close a relation */ PHP_FUNCTION(dbplus_close) { - relf *r; - zval **relation; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - zend_list_delete((*relation)->value.lval); + zend_list_delete(Z_LVAL_PP(relation)); - RETURN_TRUE; + RETURN_TRUE; } /* }}} */ @@ -396,23 +438,23 @@ PHP_FUNCTION(dbplus_close) Get current tuple from relation */ PHP_FUNCTION(dbplus_curr) { - zval **relation, **tname; - relf *r; - tuple t; - int stat; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &tname) == FAILURE){ - WRONG_PARAM_COUNT; - } - - DBPLUS_FETCH_RESOURCE(r, relation); - - stat = cdb_current(r, &t); - if(stat==ERR_NOERR) { - tuple2var(r, &t, tname); - } - - RETURN_LONG(stat); + zval **relation, **tname; + relf *r; + tuple t; + int stat; + + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &tname) == FAILURE){ + WRONG_PARAM_COUNT; + } + + DBPLUS_FETCH_RESOURCE(r, relation); + + stat = cdb_current(r, &t); + if(stat==ERR_NOERR) { + tuple2var(r, &t, tname); + } + + RETURN_LONG(stat); } /* }}} */ @@ -420,70 +462,70 @@ PHP_FUNCTION(dbplus_curr) Get error string for given errorcode or last error */ PHP_FUNCTION(dbplus_errcode) { - zval **err; - int errno; - - switch (ZEND_NUM_ARGS()) { - case 0: - errno=-1; - break; - case 1: - if( zend_get_parameters_ex(1, &err) == FAILURE){ - WRONG_PARAM_COUNT; - } - convert_to_long_ex(err); - errno = _INT(err); - } - - if(errno==-1) errno = Acc_error; - - RETURN_STRING(dbErrorMsg(errno, NULL), 1); + zval **err; + int errno; + + switch (ZEND_NUM_ARGS()) { + case 0: + errno=-1; + break; + case 1: + if( zend_get_parameters_ex(1, &err) == FAILURE){ + WRONG_PARAM_COUNT; + } + convert_to_long_ex(err); + errno = _INT(err); + } + + if(errno==-1) errno = Acc_error; + + RETURN_STRING(dbErrorMsg(errno, NULL), 1); } /* }}} */ -/* {{{ proto string dbplus_errno(void) +/* {{{ proto int dbplus_errno(void) Get error code for last operation */ PHP_FUNCTION(dbplus_errno) { - RETURN_LONG(Acc_error); + RETURN_LONG(Acc_error); } /* }}} */ -/* {{{ proto int dbplus_find(int relation, array constr, array tuple) - */ +/* {{{ proto int dbplus_find(int relation, array constr, mixed tuple) + Set a constraint on a relation*/ PHP_FUNCTION(dbplus_find) { - relf *r; - zval **relation, **constr, **data; - constraint *c; - tuple t; - int stat; - - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &relation, &constr, &data) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation, **constr, **data; + constraint *c; + tuple t; + int stat; - DBPLUS_FETCH_RESOURCE(r, relation); + if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &relation, &constr, &data) == FAILURE){ + WRONG_PARAM_COUNT; + } - if ((*constr)->type != IS_ARRAY) { - php_error(E_WARNING, "Constraint is not an array"); - RETURN_LONG(ERR_UNKNOWN); - } + DBPLUS_FETCH_RESOURCE(r, relation); - convert_to_array_ex(data); + if (Z_TYPE_PP(constr) != IS_ARRAY) { + php_error(E_WARNING, "Constraint is not an array"); + RETURN_LONG(ERR_UNKNOWN); + } - c = ary2constr(r, constr); - - if (!c){ - RETURN_LONG(ERR_USER); - } + convert_to_array_ex(data); - stat = cdb_find(r, &t, c); - - if(stat==ERR_NOERR) - tuple2var(r, &t, data); + c = ary2constr(r, constr); + + if (!c){ + RETURN_LONG(ERR_USER); + } - RETURN_LONG(stat); + stat = cdb_find(r, &t, c); + + if(stat==ERR_NOERR) + tuple2var(r, &t, data); + + RETURN_LONG(stat); } /* }}} */ @@ -491,23 +533,23 @@ PHP_FUNCTION(dbplus_find) Get first tuple from relation */ PHP_FUNCTION(dbplus_first) { - zval **relation, **tname; - relf *r; - tuple t; - int stat; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &tname) == FAILURE){ - WRONG_PARAM_COUNT; - } - - DBPLUS_FETCH_RESOURCE(r, relation); - - stat = cdb_first(r, &t); - if(stat==ERR_NOERR) { - tuple2var(r, &t, tname); - } - - RETURN_LONG(stat); + zval **relation, **tname; + relf *r; + tuple t; + int stat; + + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &tname) == FAILURE){ + WRONG_PARAM_COUNT; + } + + DBPLUS_FETCH_RESOURCE(r, relation); + + stat = cdb_first(r, &t); + if(stat==ERR_NOERR) { + tuple2var(r, &t, tname); + } + + RETURN_LONG(stat); } /* }}} */ @@ -515,15 +557,15 @@ PHP_FUNCTION(dbplus_first) ??? */ PHP_FUNCTION(dbplus_flush) { - relf *r; - zval **relation; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - RETURN_LONG(cdb_flush(r)); + RETURN_LONG(cdb_flush(r)); } /* }}} */ @@ -531,34 +573,34 @@ PHP_FUNCTION(dbplus_flush) Free all locks held by this client */ PHP_FUNCTION(dbplus_freealllocks) { - RETURN_LONG(cdbFreeAllLocks()); + RETURN_LONG(cdbFreeAllLocks()); } /* }}} */ /* {{{ proto int dbplus_freelock(int relation, array tuple) - Give up lock on tuple */ + Release write lock on tuple */ PHP_FUNCTION(dbplus_freelock) { - zval **relation, **data, **element; - enum errorcond stat = ERR_UNKNOWN; - relf *r; - tuple t; + zval **relation, **data; + enum errorcond stat = ERR_UNKNOWN; + relf *r; + tuple t; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &data) == FAILURE){ - WRONG_PARAM_COUNT; - } + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &data) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - convert_to_array_ex(data); - - if(var2tuple(r, data, &t)) - RETURN_LONG(ERR_UNKNOWN); + convert_to_array_ex(data); + + if(var2tuple(r, data, &t)) + RETURN_LONG(ERR_UNKNOWN); - stat=cdb_freelock(r, &t); + stat=cdb_freelock(r, &t); - RETURN_LONG(stat); + RETURN_LONG(stat); } /* }}} */ @@ -566,15 +608,15 @@ PHP_FUNCTION(dbplus_freelock) Free all locks on given relation */ PHP_FUNCTION(dbplus_freerlocks) { - relf *r; - zval **relation; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - RETURN_LONG(cdb_freerlocks(r)); + RETURN_LONG(cdb_freerlocks(r)); } /* }}} */ @@ -582,43 +624,49 @@ PHP_FUNCTION(dbplus_freerlocks) Request locking of tuple */ PHP_FUNCTION(dbplus_getlock) { - zval **relation, **data, **element; - enum errorcond stat = ERR_UNKNOWN; - relf *r; - tuple t; + zval **relation, **data; + enum errorcond stat = ERR_UNKNOWN; + relf *r; + tuple t; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &data) == FAILURE){ - WRONG_PARAM_COUNT; - } + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &data) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - convert_to_array_ex(data); - - if(var2tuple(r, data, &t)) - RETURN_LONG(ERR_UNKNOWN); + convert_to_array_ex(data); + + if(var2tuple(r, data, &t)) + RETURN_LONG(ERR_UNKNOWN); - stat=cdb_getlock(r, &t); + stat=cdb_getlock(r, &t); - RETURN_LONG(stat); + RETURN_LONG(stat); } /* }}} */ -/* {{{ proto int dbplus_getunique(int handle, int uniqueid, int flush) - */ +/* {{{ proto int dbplus_getunique(int handle, int uniqueid) + Get a id number unique to a relation */ PHP_FUNCTION(dbplus_getunique) { - relf *r; - zval **relation, **uniqueid, **flush; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &relation, &uniqueid, &flush) == FAILURE){ - WRONG_PARAM_COUNT; - } - - DBPLUS_FETCH_RESOURCE(r, relation); - convert_to_long_ex(uniqueid); - convert_to_long_ex(flush); - - RETURN_LONG(cdb_getunique(r, &(_INT(uniqueid)), _INT(flush))); + relf *r; + zval **relation, **uniqueid; + long l; + int stat; + + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &uniqueid) == FAILURE){ + WRONG_PARAM_COUNT; + } + + DBPLUS_FETCH_RESOURCE(r, relation); + + stat = cdb_getunique(r, &l, 1); + if(!stat) { + ZVAL_LONG(*uniqueid,l); + } + + RETURN_LONG(stat); } /* }}} */ @@ -626,43 +674,43 @@ PHP_FUNCTION(dbplus_getunique) ??? */ PHP_FUNCTION(dbplus_info) { - zval **relation, **key, **result, *element; - relf *r; - register attribute *ap; - unsigned deg; + zval **relation, **key, **result, *element; + relf *r; + register attribute *ap; + unsigned deg; + + if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &relation, &key, &result) == FAILURE){ + WRONG_PARAM_COUNT; + } + + DBPLUS_FETCH_RESOURCE(r, relation); + + ap = r->r_atts; + deg = r->r_rel.rel_deg; + + convert_to_string_ex(key); + + zval_dtor(*result); + if (array_init(*result) == FAILURE) + RETURN_LONG(ERR_USER); + + if(!strcmp("atts", Z_STRVAL_PP(key))) { + do { + MAKE_STD_ZVAL(element); - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &relation, &key, &result) == FAILURE){ - WRONG_PARAM_COUNT; - } + ZVAL_STRING(element, ap->att_name, 1); - DBPLUS_FETCH_RESOURCE(r, relation); - - ap = r->r_atts; - deg = r->r_rel.rel_deg; - - convert_to_string_ex(key); - - zval_dtor(*result); - if (array_init(*result) == FAILURE) - RETURN_LONG(ERR_USER); - - if(!strcmp("atts", (*key)->value.str.val)) { - do { - MAKE_STD_ZVAL(element); - - ZVAL_STRING(element, ap->att_name, 1); - - zend_hash_update((*result)->value.ht, - ap->att_name, - strlen(ap->att_name)+1, - (void *)&element, - sizeof(zval*), - NULL); - } while (ap++, deg--); - RETURN_LONG(ERR_NOERR); - } + zend_hash_update(Z_ARRVAL_PP(result), + ap->att_name, + strlen(ap->att_name)+1, + (void *)&element, + sizeof(zval*), + NULL); + } while (ap++, deg--); + RETURN_LONG(ERR_NOERR); + } - RETURN_LONG(ERR_USER); + RETURN_LONG(ERR_USER); } /* }}} */ @@ -670,40 +718,40 @@ PHP_FUNCTION(dbplus_info) Get last tuple from relation */ PHP_FUNCTION(dbplus_last) { - zval **relation, **tname; - relf *r; - tuple t; - int stat; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &tname) == FAILURE){ - WRONG_PARAM_COUNT; - } - - DBPLUS_FETCH_RESOURCE(r, relation); - - stat = cdb_last(r, &t); - if(stat==ERR_NOERR) { - tuple2var(r, &t, tname); - } - - RETURN_LONG(stat); + zval **relation, **tname; + relf *r; + tuple t; + int stat; + + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &tname) == FAILURE){ + WRONG_PARAM_COUNT; + } + + DBPLUS_FETCH_RESOURCE(r, relation); + + stat = cdb_last(r, &t); + if(stat==ERR_NOERR) { + tuple2var(r, &t, tname); + } + + RETURN_LONG(stat); } /* }}} */ /* {{{ proto int dbplus_lockrel(int relation) - Request read-lock on relation */ + Request write lock on relation */ PHP_FUNCTION(dbplus_lockrel) { - relf *r; - zval **relation; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - RETURN_LONG(cdb_lockrel(r)); + RETURN_LONG(cdb_lockrel(r)); } /* }}} */ @@ -711,45 +759,51 @@ PHP_FUNCTION(dbplus_lockrel) Get next tuple from relation */ PHP_FUNCTION(dbplus_next) { - zval **relation, **tname, *element; - relf *r; - tuple t; - int stat; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &tname) == FAILURE){ - WRONG_PARAM_COUNT; - } - - DBPLUS_FETCH_RESOURCE(r, relation); - - stat = cdb_next(r, &t); - if(stat==ERR_NOERR) { - tuple2var(r, &t, tname); + zval **relation, **tname; + relf *r; + tuple *t; + int stat; + + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &tname) == FAILURE){ + WRONG_PARAM_COUNT; + } + + DBPLUS_FETCH_RESOURCE(r, relation); + + if(r->r_sid = 9999) { + t = rnext(r); + stat = Acc_error; + } else { + t = (tuple *) pmalloc(sizeof(tuple)); + stat = cdb_next(r, t); } + if(stat==ERR_NOERR) { + tuple2var(r, t, tname); + } - RETURN_LONG(stat); + RETURN_LONG(stat); } /* }}} */ -/* {{{ proto int dbplus_open(string name) +/* {{{ proto resource dbplus_open(string name) Open a relation file */ PHP_FUNCTION(dbplus_open) { - relf *r; - zval **tname; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &tname) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **tname; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &tname) == FAILURE){ + WRONG_PARAM_COUNT; + } - convert_to_string_ex(tname); + convert_to_string_ex(tname); - r = cdb_open((*tname)->value.str.val, 1, 1); - if(r == NULL) { - /* TODO error handling */ - RETURN_FALSE; - } + r = cdb_open(Z_STRVAL_PP(tname), 1, 1); + if(r == NULL) { + /* TODO error handling */ + RETURN_FALSE; + } - ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); + ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); } /* }}} */ @@ -757,23 +811,23 @@ PHP_FUNCTION(dbplus_open) Get previous tuple from relation */ PHP_FUNCTION(dbplus_prev) { - zval **relation, **tname; - relf *r; - tuple t; - int stat; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &tname) == FAILURE){ - WRONG_PARAM_COUNT; - } - - DBPLUS_FETCH_RESOURCE(r, relation); - - stat = cdb_previous(r, &t); - if(stat==ERR_NOERR) { - tuple2var(r, &t, tname); - } - - RETURN_LONG(stat); + zval **relation, **tname; + relf *r; + tuple t; + int stat; + + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &tname) == FAILURE){ + WRONG_PARAM_COUNT; + } + + DBPLUS_FETCH_RESOURCE(r, relation); + + stat = cdb_previous(r, &t); + if(stat==ERR_NOERR) { + tuple2var(r, &t, tname); + } + + RETURN_LONG(stat); } /* }}} */ @@ -781,208 +835,414 @@ PHP_FUNCTION(dbplus_prev) */ PHP_FUNCTION(dbplus_rchperm) { - relf *r; - zval **relation, **mask, **user, **group; - if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &relation, &mask, &user, &group) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation, **mask, **user, **group; + if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &relation, &mask, &user, &group) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - convert_to_long_ex(mask); - convert_to_string_ex(user); - convert_to_string_ex(group); + convert_to_long_ex(mask); + convert_to_string_ex(user); + convert_to_string_ex(group); - RETURN_LONG(cdbRchperm(r, _INT(mask), _STRING(user), _STRING(group))); + RETURN_LONG(cdbRchperm(r, _INT(mask), _STRING(user), _STRING(group))); } /* }}} */ -/* {{{ proto int dbplus_restorepos(int relation, array tuple) - ??? */ -PHP_FUNCTION(dbplus_restorepos) +/* {{{ proto resource dbplus_rcreate(string name, mixed domlist [, int overwrite]) + Create a new db++ reslation +*/ +PHP_FUNCTION(dbplus_rcreate) { - zval **relation, **tname; - relf *r; - tuple t; - int stat; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &tname) == FAILURE){ - WRONG_PARAM_COUNT; - } + zval **name, **domlist, **overwrite; + relf *r=NULL; + int flag, ndoms, argc = ZEND_NUM_ARGS(); + attdef *at0; + + switch(argc) { + case 3: + if(zend_get_parameters_ex(3, &name, &domlist, &overwrite) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long_ex(overwrite); + flag=_INT(overwrite); + break; + case 2: + if(zend_get_parameters_ex(3, &name, &domlist) == FAILURE) { + WRONG_PARAM_COUNT; + } + flag=0; + break; + default: + WRONG_PARAM_COUNT; + break; + } + + convert_to_string_ex(name); + + switch ( Z_TYPE_PP(domlist) ) { + case IS_STRING: + convert_to_string_ex(domlist); + break; + + case IS_ARRAY: + { + zval tmp; + ZVAL_STRING(&tmp," ",0); + php_implode(&tmp,*domlist,*domlist); + } + break; + + default: + } + + at0 = create2att(_STRING(domlist), &ndoms); + if (at0) { + r = cdbRcreate(_STRING(name), 0666, 0, ndoms, at0, flag); + dbxfree((char *) at0); + } + if(r == NULL) { + /* TODO error handling */ + RETURN_FALSE; + } + + ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); +} +/* }}} */ - DBPLUS_FETCH_RESOURCE(r, relation); - - stat = cdb_next(r, &t); - if(stat==ERR_NOERR) { - tuple2var(r, &t, tname); - } +/* {{{ proto resource dbplus_rcrtexact(string name, resource relation [, boolean overwrite]) + Create an exact but empty copy of a relation including indices + */ +PHP_FUNCTION(dbplus_rcrtexact) +{ + zval **name, **relation, **overwrite; + relf *r; + int f,argc = ZEND_NUM_ARGS(); + + switch(argc) { + case 3: + if(zend_get_parameters_ex(3, &name, &relation, &overwrite) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long_ex(overwrite); + f=_INT(overwrite); + break; + case 2: + if(zend_get_parameters_ex(3, &name, &relation) == FAILURE) { + WRONG_PARAM_COUNT; + } + f=0; + break; + default: + WRONG_PARAM_COUNT; + break; + } + + convert_to_string_ex(name); + DBPLUS_FETCH_RESOURCE(r, relation); + + r = cdbRcrtexact(_STRING(name), 0666, r, f); + if(r == NULL) { + /* TODO error handling */ + RETURN_FALSE; + } + + ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); +} +/* }}} */ - RETURN_LONG(stat); +/* {{{ proto resource dbplus_rcrtlike(string name, int handle [, int overwrite]) + Create an empty copy of a relation with default indices +*/ +PHP_FUNCTION(dbplus_rcrtlike) +{ + zval **name, **relation, **overwrite; + relf *r; + int f,argc = ZEND_NUM_ARGS(); + + switch(argc) { + case 3: + if(zend_get_parameters_ex(3, &name, &relation, &overwrite) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long_ex(overwrite); + f=_INT(overwrite); + break; + case 2: + if(zend_get_parameters_ex(3, &name, &relation) == FAILURE) { + WRONG_PARAM_COUNT; + } + f=0; + break; + default: + WRONG_PARAM_COUNT; + break; + } + + convert_to_string_ex(name); + DBPLUS_FETCH_RESOURCE(r, relation); + + r = cdbRcrtlike(_STRING(name), 0666, 0, r, f); + if(r == NULL) { + /* TODO error handling */ + RETURN_FALSE; + } + + ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); } /* }}} */ -/* {{{ proto int dbplus_rkeys(int relation, [string|array] domlist) - */ -PHP_FUNCTION(dbplus_rkeys) +/* {{{ proto int dbplus_resolve(string name) + Resolve host information for relation */ +PHP_FUNCTION(dbplus_resolve) { - relf *r, *rnew; - zval **relation, **domlist, **zdata; - int nkeys=0; - char *p, *name=NULL, *keys[40]; /* TODO hardcoded magic number ??? */ + zval **name, *element; + char * host; + char * host_path; + int sid; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &domlist) == FAILURE){ - WRONG_PARAM_COUNT; - } + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &name) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); - - if((*domlist)->type == IS_ARRAY) { - convert_to_array_ex(domlist); - for(zend_hash_internal_pointer_reset(_HASH(domlist)); - SUCCESS==zend_hash_get_current_data(_HASH(domlist), (void **)&zdata); - zend_hash_move_forward(_HASH(domlist))) { - if((*zdata)->type==IS_STRING) - keys[nkeys++] = _STRING(zdata); - else { - php_error(E_WARNING, "Domlist array contains non-string value(s)"); - Acc_error = ERR_USER; - RETURN_FALSE; - } - } - } else { - convert_to_string_ex(domlist); - name = estrdup(_STRING(domlist)); - while (p = strtok(nkeys ? 0 : name, " ")) - keys[nkeys++] = p; - } - - rnew = cdbRkeys(r, nkeys, keys); - if(name) efree(name); - - if(rnew) { - /* TODO realy delete old relation resource ? */ - zend_list_delete((*relation)->value.lval); - - ZEND_REGISTER_RESOURCE(return_value, rnew, le_dbplus_relation); - } else { - /* TODO error reporting */ - RETURN_FALSE; - } + convert_to_string_ex(name); + + sid = cdb_resolve(_STRING(name), &host, &host_path); + if (sid <= 0) + RETURN_FALSE; + + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + + MAKE_STD_ZVAL(element); Z_TYPE_P(element)=IS_NULL; + ZVAL_LONG(element,sid); + zend_hash_update(Z_ARRVAL_P(return_value), "sid", 4, + &element, sizeof(zval *), NULL); + + MAKE_STD_ZVAL(element); Z_TYPE_P(element)=IS_NULL; + ZVAL_STRING(element,host,1); + zend_hash_update(Z_ARRVAL_P(return_value), "host", 5, + &element, sizeof(zval *), NULL); + + MAKE_STD_ZVAL(element); Z_TYPE_P(element)=IS_NULL; + ZVAL_STRING(element,host_path,1); + zend_hash_update(Z_ARRVAL_P(return_value), "host_path", 10, + &element, sizeof(zval *), NULL); } /* }}} */ -/* {{{ proto int dbplus_ropen(string name) - Open relation file ... ??? */ -PHP_FUNCTION(dbplus_ropen) +/* {{{ proto int dbplus_restorepos(int relation, array tuple) + ??? */ +PHP_FUNCTION(dbplus_restorepos) { - relf *r; - zval **tname; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &tname) == FAILURE){ - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(tname); + zval **relation, **tname; + relf *r; + tuple t; + int stat; + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &tname) == FAILURE){ + WRONG_PARAM_COUNT; + } + + DBPLUS_FETCH_RESOURCE(r, relation); + + stat = cdb_next(r, &t); + if(stat==ERR_NOERR) { + tuple2var(r, &t, tname); + } + + RETURN_LONG(stat); +} +/* }}} */ - r = ropen((*tname)->value.str.val, 0, 0); - if(r == NULL) { - /* TODO error handling */ - RETURN_FALSE; - } +/* {{{ proto resource dbplus_rkeys(resource relation, mixed domlist) + Define primary key for relation +*/ +PHP_FUNCTION(dbplus_rkeys) +{ + relf *r, *rnew; + zval **relation, **domlist, **zdata; + int nkeys=0; + char *name=NULL, *keys[40]; /* TODO hardcoded magic number ??? */ + + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &domlist) == FAILURE){ + WRONG_PARAM_COUNT; + } + + DBPLUS_FETCH_RESOURCE(r, relation); + + switch(Z_TYPE_PP(domlist)) { + case IS_ARRAY: + convert_to_array_ex(domlist); + for(zend_hash_internal_pointer_reset(_HASH(domlist)); + SUCCESS==zend_hash_get_current_data(_HASH(domlist), (void **)&zdata); + zend_hash_move_forward(_HASH(domlist))) { + if(Z_TYPE_PP(zdata)==IS_STRING) + keys[nkeys++] = _STRING(zdata); + else { + php_error(E_WARNING, "dbplus_rkeys: domlist array contains non-string value(s)"); + Acc_error = ERR_USER; + RETURN_FALSE; + } + } + break; + + case IS_STRING: + convert_to_string_ex(domlist); + keys[0] = _STRING(domlist); + nkeys = 1; + break; + + default: + php_error(E_WARNING, "dbplus_rkeys: domlist has to be of type string or an array of strings"); + Acc_error = ERR_USER; + RETURN_FALSE; + } + + rnew = cdbRkeys(r, nkeys, keys); + if(name) efree(name); + + if(rnew) { + /* TODO realy delete old relation resource ? */ +#if 0 + zend_list_delete(Z_LVAL_PP(relation)); +#endif + ZEND_REGISTER_RESOURCE(return_value, rnew, le_dbplus_relation); + } else { + /* TODO error reporting */ + RETURN_FALSE; + } +} +/* }}} */ - ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); +/* {{{ proto resource dbplus_ropen(string name) + Open relation file local */ +PHP_FUNCTION(dbplus_ropen) +{ + relf *r; + zval **tname; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &tname) == FAILURE){ + WRONG_PARAM_COUNT; + } + + convert_to_string_ex(tname); + + r = ropen(Z_STRVAL_PP(tname), 0, 0); + if(r == NULL) { + /* TODO error handling */ + RETURN_FALSE; + } + + r->r_sid = 9999; + + ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); } /* }}} */ -/* {{{ proto int dbplus_rquery(string name, string dbpath) +/* {{{ proto resceour dbplus_rquery(string name, string dbpath) */ PHP_FUNCTION(dbplus_rquery) { - relf *r; - zval **name, **dbpath; - int argc; - - if (argc <1 || argc>2 || zend_get_parameters_ex(1, &name, &dbpath) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **name, **dbpath; + int argc = ZEND_NUM_ARGS(); + + if ((argc <1) || (argc>2) || (zend_get_parameters_ex(2, &name, &dbpath) == FAILURE)){ + WRONG_PARAM_COUNT; + } - r = aql_exec(_STRING(name), (argc==2)?_STRING(dbpath):NULL); + r = aql_exec(_STRING(name), (argc==2)?_STRING(dbpath):NULL); - if(!r) { - /* TODO error handling */ - RETURN_FALSE; - } + if(!r) { + /* TODO error handling */ + RETURN_FALSE; + } + + r->r_sid = 9999; - ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); + ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); } /* }}} */ -/* {{{ proto int dbplus_rrename(int relation, string name, int flag) +/* {{{ proto int dbplus_rrename(int relation, string name) */ PHP_FUNCTION(dbplus_rrename) { - relf *r; - zval **relation, **name, **flag; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &relation, &name, &flag) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation, **name; + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &name) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - convert_to_string_ex(name); - convert_to_long_ex(flag); + convert_to_string_ex(name); - RETURN_LONG(cdbRrename(r, _STRING(name), (*flag)->value.lval)); + RETURN_LONG(cdbRrename(r, _STRING(name), 0)); } /* }}} */ -/* {{{ proto int dbplus_rsecindex(int relation, string domlist, int compact) - */ +/* {{{ proto resource dbplus_rsecindex(resource relation, mixed domlist, int compact) + Create an additional index on relation +*/ PHP_FUNCTION(dbplus_rsecindex) { - relf *r, *rnew; - zval **relation, **domlist, **compact, **zdata; - int nkeys=0; - char *p, *name=NULL, *keys[40]; /* TODO hardcoded magic number ??? */ - - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &relation, &domlist, &compact) == FAILURE){ - WRONG_PARAM_COUNT; - } - - DBPLUS_FETCH_RESOURCE(r, relation); - - if((*domlist)->type == IS_ARRAY) { - convert_to_array_ex(domlist); - for(zend_hash_internal_pointer_reset(_HASH(domlist)); - SUCCESS==zend_hash_get_current_data(_HASH(domlist), (void **)&zdata); - zend_hash_move_forward(_HASH(domlist))) { - if((*zdata)->type==IS_STRING) - keys[nkeys++] = _STRING(zdata); - else { - php_error(E_WARNING, "Domlist array contains non-string value(s)"); - Acc_error = ERR_USER; - RETURN_FALSE; - } - } - } else { - convert_to_string_ex(domlist); - name = estrdup(_STRING(domlist)); - while (p = strtok(nkeys ? 0 : name, " ")) - keys[nkeys++] = p; - } - - convert_to_long_ex(compact); - - rnew = cdbRsecindex(r, nkeys, keys, _INT(compact)); - if(name) efree(name); - - if(rnew) { - /* TODO realy delete old relation resource ? */ - zend_list_delete((*relation)->value.lval); - - ZEND_REGISTER_RESOURCE(return_value, rnew, le_dbplus_relation); - } else { - /* TODO error reporting */ - RETURN_FALSE; - } + relf *r, *rnew; + zval **relation, **domlist, **compact, **zdata; + int nkeys=0; + char *name=NULL, *keys[40]; /* TODO hardcoded magic number ??? */ + + if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &relation, &domlist, &compact) == FAILURE){ + WRONG_PARAM_COUNT; + } + + DBPLUS_FETCH_RESOURCE(r, relation); + + switch ( Z_TYPE_PP(domlist) ) { + case IS_ARRAY: + convert_to_array_ex(domlist); + for(zend_hash_internal_pointer_reset(_HASH(domlist)); + SUCCESS==zend_hash_get_current_data(_HASH(domlist), (void **)&zdata); + zend_hash_move_forward(_HASH(domlist))) { + if(Z_TYPE_PP(zdata)==IS_STRING) + keys[nkeys++] = _STRING(zdata); + else { + php_error(E_WARNING, "dbplus_rsecindex: domlist array contains non-string value(s)"); + Acc_error = ERR_USER; + RETURN_FALSE; + } + } + break; + + case IS_STRING: + convert_to_string_ex(domlist); + keys[0] = _STRING(domlist); + nkeys = 1; + break; + + default: + php_error(E_WARNING, "dbplus_rsecindex: domlist has to be of type string or an array of strings"); + Acc_error = ERR_USER; + RETURN_FALSE; + } + + convert_to_long_ex(compact); + + rnew = cdbRsecindex(r, nkeys, keys, _INT(compact)); + if(name) efree(name); + + if(rnew) { + /* TODO realy delete old relation resource ? */ + zend_list_delete(Z_LVAL_PP(relation)); + + ZEND_REGISTER_RESOURCE(return_value, rnew, le_dbplus_relation); + } else { + /* TODO error reporting */ + RETURN_FALSE; + } } /* }}} */ @@ -990,15 +1250,15 @@ PHP_FUNCTION(dbplus_rsecindex) Remove relation from filesystem */ PHP_FUNCTION(dbplus_runlink) { - relf *r; - zval **relation; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - RETURN_LONG(cdbRunlink(&r)); + RETURN_LONG(cdbRunlink(&r)); } /* }}} */ @@ -1007,18 +1267,16 @@ PHP_FUNCTION(dbplus_runlink) PHP_FUNCTION(dbplus_rzap) { - /* todo: optional argument */ - relf *r; - zval **relation, **truncate; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &truncate) == FAILURE){ - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(truncate); + /* todo: optional argument */ + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } + + DBPLUS_FETCH_RESOURCE(r, relation); - DBPLUS_FETCH_RESOURCE(r, relation); - - RETURN_LONG(cdbRzap(r, (*truncate)->value.lval)); + RETURN_LONG(cdbRzap(r, 1)); } /* }}} */ @@ -1026,13 +1284,13 @@ PHP_FUNCTION(dbplus_rzap) ??? */ PHP_FUNCTION(dbplus_savepos) { - relf *r; - zval **relation; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); RETURN_LONG(cdb_savepos(r)); } @@ -1042,17 +1300,17 @@ PHP_FUNCTION(dbplus_savepos) ???? */ PHP_FUNCTION(dbplus_setindex) { - relf *r; - zval **relation, **idx_name; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &idx_name) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation, **idx_name; + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &idx_name) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - convert_to_string_ex(idx_name); - - RETURN_LONG(cdb_setindex(r, _STRING(idx_name))); + convert_to_string_ex(idx_name); + + RETURN_LONG(cdb_setindex(r, _STRING(idx_name))); } /* }}} */ @@ -1060,88 +1318,114 @@ PHP_FUNCTION(dbplus_setindex) ??? */ PHP_FUNCTION(dbplus_setindexbynumber) { - relf *r; - zval **relation, **idx_number; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &idx_number) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation, **idx_number; + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &relation, &idx_number) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - convert_to_long_ex(idx_number); - - RETURN_LONG(cdb_setindexbynumber(r, (*idx_number)->value.lval)); + convert_to_long_ex(idx_number); + + RETURN_LONG(cdb_setindexbynumber(r, Z_LVAL_PP(idx_number))); } /* }}} */ -/* {{{ proto int dbplus_sql(string query, string server, string dbpath) +/* {{{ proto resource dbplus_sql(string query, string server, string dbpath) Perform SQL query */ PHP_FUNCTION(dbplus_sql) { - int argc; - zval **query, **server, **dbpath; - relf *r; - - argc = ZEND_NUM_ARGS(); - if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &query, &server, &dbpath) == FAILURE){ - WRONG_PARAM_COUNT; - } - - switch (argc) { - case 3: - convert_to_string_ex(dbpath); - php_error(E_WARNING, "Arg dbpath: %s", _STRING(dbpath)); - /* Fall-through. */ - case 2: - convert_to_string_ex(server); - php_error(E_WARNING, "Arg server: %s", _STRING(server)); - /* Fall-through. */ - case 1: - convert_to_string_ex(query); - php_error(E_WARNING, "Arg query: %s", _STRING(query)); - break; - } - - r = cdb_sql((argc>=2)?_STRING(server):"localhost", - _STRING(query), - (argc==3)?_STRING(dbpath):NULL); - if(r == NULL) { - /* TODO error handling */ - RETURN_FALSE; - } - - ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); + int argc; + zval **query, **server, **dbpath; + relf *r; + + argc = ZEND_NUM_ARGS(); + if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &query, &server, &dbpath) == FAILURE){ + WRONG_PARAM_COUNT; + } + + switch (argc) { + case 3: + convert_to_string_ex(dbpath); + php_error(E_WARNING, "Arg dbpath: %s", _STRING(dbpath)); + /* Fall-through. */ + case 2: + convert_to_string_ex(server); + php_error(E_WARNING, "Arg server: %s", _STRING(server)); + /* Fall-through. */ + case 1: + convert_to_string_ex(query); + php_error(E_WARNING, "Arg query: %s", _STRING(query)); + break; + } + + r = cdb_sql((argc>=2)?_STRING(server):"localhost", + _STRING(query), + (argc==3)?_STRING(dbpath):NULL); + if(r == NULL) { + /* TODO error handling */ + RETURN_FALSE; + } + + ZEND_REGISTER_RESOURCE(return_value, r, le_dbplus_relation); } /* }}} */ -/* {{{ proto int dbplus_tremove(int relation, array old [, array current]) - Remove tuple and return new current tuple */ -PHP_FUNCTION(dbplus_tremove) +/* {{{ proto string dbplus_tcl(int sid, string script) + Execute server side TCL code + */ +PHP_FUNCTION(dbplus_tcl) { - zval **relation, **old, **current; - enum errorcond stat = ERR_UNKNOWN; - relf *r; - tuple told, tcurr; - int argc; - - argc = ZEND_NUM_ARGS(); - if ( argc<2 || argc>3 || zend_get_parameters_ex(2, &relation, &old, ¤t) == FAILURE){ - WRONG_PARAM_COUNT; - } + zval **sid, **script; + char *ret; + int result_type; - DBPLUS_FETCH_RESOURCE(r, relation); + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &sid, &script) == FAILURE){ + WRONG_PARAM_COUNT; + } - convert_to_array_ex(old); - - if(var2tuple(r, old, &told)) - RETURN_LONG(ERR_UNKNOWN); + convert_to_long_ex(sid); + convert_to_string_ex(script); - stat=cdbTremove(r, &told, &tcurr); - - if((stat==ERR_NOERR) && (argc==3)) - tuple2var(r, &tcurr, current); + cdb_tcl(_INT(sid),_STRING(script),&ret,&result_type); - RETURN_LONG(stat); + if(ret) { + RETURN_STRING(ret,1); + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto int dbplus_tremove(int relation, array old [, array current]) + Remove tuple and return new current tuple */ +PHP_FUNCTION(dbplus_tremove) +{ + zval **relation, **old, **current; + enum errorcond stat = ERR_UNKNOWN; + relf *r; + tuple told, tcurr; + int argc; + + argc = ZEND_NUM_ARGS(); + if ( argc<2 || argc>3 || zend_get_parameters_ex(2, &relation, &old, ¤t) == FAILURE){ + WRONG_PARAM_COUNT; + } + + DBPLUS_FETCH_RESOURCE(r, relation); + + convert_to_array_ex(old); + + if(var2tuple(r, old, &told)) + RETURN_LONG(ERR_UNKNOWN); + + stat=cdbTremove(r, &told, &tcurr); + + if((stat==ERR_NOERR) && (argc==3)) + tuple2var(r, &tcurr, current); + + RETURN_LONG(stat); } /* }}} */ @@ -1149,15 +1433,15 @@ PHP_FUNCTION(dbplus_tremove) ??? */ PHP_FUNCTION(dbplus_undo) { - relf *r; - zval **relation; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - RETURN_LONG(cdb_undo(r)); + RETURN_LONG(cdb_undo(r)); } /* }}} */ @@ -1165,47 +1449,47 @@ PHP_FUNCTION(dbplus_undo) ??? */ PHP_FUNCTION(dbplus_undoprepare) { - relf *r; - zval **relation; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - RETURN_LONG(cdb_undoprepare(r)); + RETURN_LONG(cdb_undoprepare(r)); } /* }}} */ /* {{{ proto int dbplus_unlockrel(int relation) - Give up read-lock on relation */ + Give up write lock on relation */ PHP_FUNCTION(dbplus_unlockrel) { - relf *r; - zval **relation; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - RETURN_LONG(cdb_unlockrel(r)); + RETURN_LONG(cdb_unlockrel(r)); } /* }}} */ /* {{{ proto int dbplus_unselect(int relation) - ??? */ + Remove constraint from relation */ PHP_FUNCTION(dbplus_unselect) { - relf *r; - zval **relation; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - RETURN_LONG(cdb_unselect(r)); + RETURN_LONG(cdb_unselect(r)); } /* }}} */ @@ -1213,61 +1497,61 @@ PHP_FUNCTION(dbplus_unselect) Update specified tuple in relation */ PHP_FUNCTION(dbplus_update) { - zval **relation, **old, **new; - enum errorcond stat = ERR_UNKNOWN; - relf *r; - tuple told, tnew; + zval **relation, **old, **new; + enum errorcond stat = ERR_UNKNOWN; + relf *r; + tuple told, tnew; - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &relation, &old, &new) == FAILURE){ - WRONG_PARAM_COUNT; - } + if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &relation, &old, &new) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - convert_to_array_ex(old); - convert_to_array_ex(new); - - if(var2tuple(r, old, &told)) - RETURN_LONG(ERR_UNKNOWN); + convert_to_array_ex(old); + convert_to_array_ex(new); + + if(var2tuple(r, old, &told)) + RETURN_LONG(ERR_UNKNOWN); - if(var2tuple(r, new, &tnew)) - RETURN_LONG(ERR_UNKNOWN); + if(var2tuple(r, new, &tnew)) + RETURN_LONG(ERR_UNKNOWN); - stat=cdb_update(r, &told, &tnew); - - RETURN_LONG(stat); + stat=cdb_update(r, &told, &tnew); + + RETURN_LONG(stat); } /* }}} */ /* {{{ proto int dbplus_xlockrel(int relation) - Request exclusive write lock on relation */ + Request exclusive lock on relation */ PHP_FUNCTION(dbplus_xlockrel) { - relf *r; - zval **relation; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - RETURN_LONG(cdb_xlockrel(r)); + RETURN_LONG(cdb_xlockrel(r)); } /* }}} */ /* {{{ proto int dbplus_xunlockrel(int relation) - Free exclusive write lock on relation */ + Free exclusive lock on relation */ PHP_FUNCTION(dbplus_xunlockrel) { - relf *r; - zval **relation; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ - WRONG_PARAM_COUNT; - } + relf *r; + zval **relation; + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &relation) == FAILURE){ + WRONG_PARAM_COUNT; + } - DBPLUS_FETCH_RESOURCE(r, relation); + DBPLUS_FETCH_RESOURCE(r, relation); - RETURN_LONG(cdb_xunlockrel(r)); + RETURN_LONG(cdb_xunlockrel(r)); } /* }}} */ diff --git a/ext/dbplus/php_dbplus.h b/ext/dbplus/php_dbplus.h index 09ab878f65..232c656697 100644 --- a/ext/dbplus/php_dbplus.h +++ b/ext/dbplus/php_dbplus.h @@ -20,9 +20,6 @@ #ifndef PHP_DBPLUS_H #define PHP_DBPLUS_H -#include <saccess.h> -#include <relation.h> -#include <dblight.h> extern zend_module_entry dbplus_module_entry; #define phpext_dbplus_ptr &dbplus_module_entry @@ -41,7 +38,6 @@ PHP_MINFO_FUNCTION(dbplus); PHP_FUNCTION(dbplus_add); PHP_FUNCTION(dbplus_aql); -PHP_FUNCTION(dbplus_change); PHP_FUNCTION(dbplus_chdir); PHP_FUNCTION(dbplus_close); PHP_FUNCTION(dbplus_curr); @@ -89,11 +85,11 @@ PHP_FUNCTION(dbplus_xunlockrel); /* - Declare any global variables you may need between the BEGIN - and END macros here: + Declare any global variables you may need between the BEGIN + and END macros here: ZEND_BEGIN_MODULE_GLOBALS(dbplus) - int global_variable; + int global_variable; ZEND_END_MODULE_GLOBALS(dbplus) */ @@ -118,7 +114,7 @@ void dbplus_destruct_relation(zend_rsrc_list_entry *rsrc TSRMLS_DC); void dbplus_destruct_tupel(zend_rsrc_list_entry *rsrc TSRMLS_DC); -#endif /* PHP_DBPLUS_H */ +#endif /* PHP_DBPLUS_H */ /* |