/***************************** {{{ LICENSE ********************************\ * dbobj, the relational object persistence module for PHP * * Copyright (C) 2006 Adam Banko * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * \***************************** LICENSE }}} ********************************/ #ifndef DBOBJ_H #define DBOBJ_H #include "php_dbobj.h" #include "dbTypes.h" #include "objTypes.h" #include "SQL.h" #include "localClassConfig.h" #include "dbCondition.h" #ifdef ZTS #include "TSRM.h" #endif extern zend_class_entry *dbobj_class_entry_ptr; extern zend_object_handlers dbobj_object_handlers; extern zval zConstuctor_name; DBOBJ_API void php_dbobj_MINIT_dbobj(int module_number TSRMLS_DC); DBOBJ_API void php_dbobj_RINIT_dbobj(TSRMLS_D); DBOBJ_API void php_dbobj_RSHUTDOWN_dbobj(TSRMLS_D); //TSRM global HashTable objCache; typedef struct _dbProp { dbVal value; basicPropConfig config; bool changed; } *dbProp; enum dbobj_dbStatus { DBSTATUS_IN_DATABASE, //maching recrod exist in the DBMS DBSTATUS_IN_MEMORY, }; typedef struct _dbobj { unsigned char overloadedRecursionCounter; LocalClassConfig lConf; HashTable dbProps; enum dbobj_dbStatus dbStatus; enum dbobj_dbStatus desired_dbStatus; dbProp *PKs;//array of dbProps int PKsL; int changedDbPropCount; zend_object_handle handle; HashTable zPropCache; } *dbobj; typedef struct _uidT { uint uidL; //full length of the structure uint classNameL; //length of the class name without '\0' char data[]; /* variable size structure (size = classNameL + 1 + PKsS) * Note that the '\0' character of the classname is stored, but * it's not counted in classNameL! */ } *uidT; /*enum sql_orderBy { SQL_ORDER_ASC, SQL_ORDER_DESC, SQL_ORDER_UNORDERED, };*/ typedef struct _dbobj_garbage_list { dbobj obj; struct _dbobj_garbage_list* next; } dbobj_garbage_list; ///////////////////////// ///////PHP methods/////// ///////////////////////// PHP_METHOD(dbobj, __construct); PHP_METHOD(dbobj, save); PHP_METHOD(dbobj, delete_on_save); PHP_METHOD(dbobj, is_in_database); PHP_FUNCTION(dbobj_find); ////////////////////////// /////dbobj_php_object///// ////////////////////////// DBOBJ_API zend_object_value dbobj_z_clone(zval *object TSRMLS_DC); DBOBJ_API zval* dbobj_read_property(zval *object, zval* member, int type TSRMLS_DC); DBOBJ_API void dbobj_write_property(zval *object, zval* member, zval* value TSRMLS_DC); DBOBJ_API int dbobj_has_property(zval *object, zval* member, int has_set_exists TSRMLS_DC); DBOBJ_API void dbobj_unset_property(zval *object, zval* member TSRMLS_DC); DBOBJ_API int dbobj_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS); DBOBJ_API void dbobj_z_add_ref(zval *object TSRMLS_DC); DBOBJ_API void dbobj_z_del_ref(zval *object TSRMLS_DC); DBOBJ_API void dbobj_copy(void *object, void **object_clone TSRMLS_DC); DBOBJ_API zend_class_entry* dbobj_get_class(zval *object TSRMLS_DC); DBOBJ_API int dbobj_get_className(zval *object, char** className, zend_uint* classNameL, int parent TSRMLS_DC); DBOBJ_API int dbobj_compare(zval* object1, zval* object2 TSRMLS_DC); DBOBJ_API int dbobj_count_elements(zval *object, long* count TSRMLS_DC); DBOBJ_API zend_object_value dbobj_create_object(zend_class_entry *class_type TSRMLS_DC); DBOBJ_API union _zend_function* dbobj_get_constructor(zval* object TSRMLS_DC); DBOBJ_API union _zend_function* dbobj_get_method(zval** object, char *methodName, int methodNameL TSRMLS_DC); DBOBJ_API HashTable *dbobj_get_properties(zval *object TSRMLS_DC); #if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 2 DBOBJ_API int dbobj_cast(zval* readObj, zval* writeObj, int type TSRMLS_DC); #else DBOBJ_API int dbobj_cast(zval* readObj, zval* writeObj, int type, void *extra TSRMLS_DC); #endif DBOBJ_API void dbobj_destroy_object(dbobj object, zend_object_handle handle TSRMLS_DC); DBOBJ_API void dbobj_garbage_collection(TSRMLS_D); ////////////////////////// ///dbobj_zend_functions/// ////////////////////////// DBOBJ_API zval* dbobj_zObjProp_get(zval* object, STRINGLD(propName) TSRMLS_DC); DBOBJ_API void dbobj_zObjProp_set(zval* object, STRINGLD(propName), zval* value TSRMLS_DC); DBOBJ_API void dbobj_ZObjPropRevert(zval* object, STRINGLD(propName) TSRMLS_DC); ///////////////////////// //////////dbobj////////// ///////////////////////// //static: DBOBJ_API dbobj dbobj_create(LocalClassConfig lConf TSRMLS_DC); DBOBJ_API dbobj dbobj_findOne(LocalClassConfig lConf, dbVal PKs[], basicPropConfig load[], uint loadL TSRMLS_DC); DBOBJ_API dbobj dbobj_findOne_by_conditions(LocalClassConfig lConf, dbCondition conditions[], uint conditionsL, basicPropConfig load[], uint loadL TSRMLS_DC); DBOBJ_API dbobj dbobj_dbobj_from_UID(uidT uid, basicPropConfig load[], uint loadL TSRMLS_DC); //DBOBJ_API uint dbobj_objChainSolver_count(objPropConfig conf); //DBOBJ_API dbCondition* dbobj_objChainSolver_conditions(dbCondition* conditionCursor, objPropConfig conf, objVal val TSRMLS_DC); DBOBJ_API dbobj dbobj_lookup_in_cache(uidT uid TSRMLS_DC); DBOBJ_API zend_object_handle dbobj_register(dbobj o, uidT uid TSRMLS_DC); //members: DBOBJ_API uidT dbobj_get_UID(dbobj object TSRMLS_DC); DBOBJ_API void dbobj_objProp_set(dbobj object, objPropConfig objPropConf, objVal val TSRMLS_DC); DBOBJ_API void dbobj_save(dbobj object TSRMLS_DC); DBOBJ_API void dbobj_discard_changes(dbobj object TSRMLS_DC); DBOBJ_API basicVal dbobj_basicVal_get(dbobj o, basicPropConfig basicPropConf TSRMLS_DC); DBOBJ_API complexVal dbobj_complexVal_get(dbobj o, complexPropConfig complexPropConf TSRMLS_DC); DBOBJ_API objVal dbobj_objVal_get(dbobj object, objPropConfig objPropConf TSRMLS_DC); DBOBJ_API void dbobj_destroy(dbobj object TSRMLS_DC); // call save(), free memory DBOBJ_API dbProp dbobj_dbProp_get(dbobj object, basicPropConfig conf TSRMLS_DC); DBOBJ_API void dbobj_dbProp_set(dbobj object, basicPropConfig conf, dbVal newVal TSRMLS_DC); DBOBJ_API bool dbobj_dbPropsLoad(dbobj object, basicPropConfig dbprops[], uint dbPropsL TSRMLS_DC); DBOBJ_API void dbobj_objPropRevert(dbobj object, objPropConfig objPropConf TSRMLS_DC); DBOBJ_API bool dbobj_objProp_is_valid(dbobj o, objPropConfig objPropConf TSRMLS_DC); DBOBJ_API void dbobj_copyForInsert(dbobj object, dbobj copy TSRMLS_DC); // copies all data to the parameter except for the PKs, sets it to be inserted on destruction DBOBJ_API dbobj dbobj_allocate_and_init(LocalClassConfig lConf TSRMLS_DC); DBOBJ_API void dbobj_deallocate(dbobj o); DBOBJ_API void dbobj_add_ref(dbobj o TSRMLS_DC); DBOBJ_API void dbobj_del_ref(dbobj o TSRMLS_DC); ///////////////////////// ////////// UID ////////// ///////////////////////// #define UID_SIZE(classNameL, PKsS) (sizeof(struct _uidT) + classNameL + PKsS) #define UID_GETLEN(uid) (uid->uidL) #endif /* DBOBJ_H */ /* * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */