/***************************** {{{ 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_DBDRIVER_H #define DBOBJ_DBDRIVER_H #include "php_dbobj.h" #include "dbTypes.h" #include "objTypes.h" #include "dbType/serial.h" #include "dbCondition.h" #include "basicPropConfig.h" #include "dbVal.h" #include "classConfig.h" //Java like objects typedef struct _dbConnection *DBConnection; typedef struct _dbIterator *DBIterator; //TODO write some common helper functions/macros (eg. call dbVal2raw for an array) //{{{ dbConnection_vtable typedef void (*dbConnection_destroy_t) (DBConnection this TSRMLS_DC); typedef void (*dbConnection_beginTransaction_t) (DBConnection this TSRMLS_DC); typedef void (*dbConnection_commitTransaction_t) (DBConnection this TSRMLS_DC); typedef void (*dbConnection_rollbackTransaction_t) (DBConnection this TSRMLS_DC); typedef zval* (*dbConnection_query_t) (DBConnection this, STRINGLD(sql), void* params[], uint paramsL, uint paramLs[] TSRMLS_DC); typedef uint (*dbConnection_getNewID_t) (DBConnection this, classConfig cConf TSRMLS_DC); typedef uint (*dbConnection_getLastInsertID_t) (DBConnection this, classConfig cConf TSRMLS_DC); //the caller must free the return value typedef dbVal* (*dbConnection_getRow_t) (DBConnection this, classConfig cConf, dbVal PKs[], basicPropConfig load[], uint loadL TSRMLS_DC); typedef struct _dbIterator* (*dbConnection_selectMany_t) (DBConnection this, classConfig cConf, dbCondition conditions[], uint conditionsL, basicPropConfig load[], uint loadL TSRMLS_DC); typedef void (*dbConnection_deleteRow_t) (DBConnection this, classConfig cConf, dbVal PKs[], uint PKsL TSRMLS_DC); typedef void (*dbConnection_insertRow_t) (DBConnection this, classConfig cConf, basicPropConfig savePropConfs[], dbVal savePropVals[], uint savePropsL TSRMLS_DC); typedef void (*dbConnection_updateRow_t) (DBConnection this, classConfig cConf, dbVal PKs[], basicPropConfig savePropConfs[], dbVal savePropVals[], uint savePropsL TSRMLS_DC); typedef struct _dbConnection_vtable { dbConnection_destroy_t destroy; dbConnection_beginTransaction_t beginTransaction; dbConnection_commitTransaction_t commitTransaction; dbConnection_rollbackTransaction_t rollbackTransaction; dbConnection_query_t query; dbConnection_getNewID_t getNewID; /*can be NULL*/ dbConnection_getLastInsertID_t getLastInsertID; dbConnection_getRow_t getRow; dbConnection_selectMany_t selectMany; /* may declare a cursor or simply issue a select */ dbConnection_deleteRow_t deleteRow; dbConnection_insertRow_t insertRow; dbConnection_updateRow_t updateRow; } dbConnection_vtable; //}}} //{{{ dbIterator_vtable /* * @return array of dbVal (caller frees it) */ typedef dbVal* (*dbIterator_getRow_t) (DBIterator this, basicPropConfig loaded[], uint loadedL TSRMLS_DC); typedef void (*dbIterator_rewind_t) (DBIterator this TSRMLS_DC); typedef void (*dbIterator_destroy_t) (DBIterator this TSRMLS_DC); typedef struct _dbIterator_vtable { dbIterator_getRow_t getRow; dbIterator_rewind_t rewind; /* can be NULL */ dbIterator_destroy_t destroy; } dbIterator_vtable; //}}} #define DBCONNECTION_COMMON \ dbConnection_vtable *vt #define DBITERATOR_COMMON \ dbIterator_vtable *vt struct _dbConnection { DBCONNECTION_COMMON; char __[]; //variable lenght struct (abstract class) }; struct _dbIterator { DBITERATOR_COMMON; char __[]; //variable lenght struct (abstract class) }; /* * @param user optional * @param password optional * @param configArr the original (and full) configuration array of the current dbDriver */ typedef DBConnection (*dbDriver_getConnection_t)(STRINGLD(dsn), STRINGLD(username), STRINGLD(password), HashTable* configArray TSRMLS_DC); typedef void (*dbDriver_RSHUTDOWN_t)(TSRMLS_D); typedef struct _dbDriver { char* name; uint nameL; char* version; dbDriver_getConnection_t getConnection; } dbDriver; DBOBJ_API void dbDriver_register(dbDriver* module); /* * gets a database connection * * First it looks at the available connections in the pool, and if there is no suitable, it makes a new connection * * Each module should take care of maintaing this pool and committing and closing it's connections in the end (RSHUTDOWN) * * @param user may be null * @param password may be null */ DBOBJ_API DBConnection dbDriver_getConnection(STRINGLD(driver), STRINGLD(dsn), STRINGLD(username), STRINGLD(password), HashTable* configArray TSRMLS_DC); DBOBJ_API void php_dbobj_MINIT_dbDriver(TSRMLS_D); DBOBJ_API void php_dbobj_RINIT_dbDriver(TSRMLS_D); DBOBJ_API void php_dbobj_RSHUTDOWN_dbDriver(TSRMLS_D); #endif //DBOBJ_DBDRIVER_H /* * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */