public function __construct(DB_DataObject $do, $values) { $this->do = $do; if (!is_array($values)) { throw new Exception('Values must be an array !'); } $this->values = $values; $this->db = $do->getDatabaseConnection(); }
/** * Connect to the database. * * @return void * @access public */ public static function connectToDatabase() { global $configArray; if (!defined('DB_DATAOBJECT_NO_OVERLOAD')) { define('DB_DATAOBJECT_NO_OVERLOAD', 0); } $options =& PEAR_Singleton::getStaticProperty('DB_DataObject', 'options'); // If we're using PostgreSQL, we need to set up some extra configuration // settings so that unique ID sequences are properly registered: if (substr($configArray['Database']['database'], 0, 5) == 'pgsql') { $tables = array('comments', 'oai_resumption', 'resource', 'resource_tags', 'search', 'session', 'tags', 'user', 'user_list', 'user_resource'); foreach ($tables as $table) { $configArray['Database']['sequence_' . $table] = $table . '_id_seq'; } } $options = $configArray['Database']; if (substr($configArray['Database']['database'], 0, 5) == 'mysql') { // If we're using MySQL, we need to make certain adjustments (ANSI // quotes, pipes as concatenation operator) for proper compatibility // with code built for other database systems like PostgreSQL or Oracle. $obj = new DB_DataObject(); $conn = $obj->getDatabaseConnection(); $conn->query("SET @@SESSION.sql_mode='ANSI_QUOTES,PIPES_AS_CONCAT'"); } else { if (substr($configArray['Database']['database'], 0, 4) == 'oci8') { // If we are using Oracle, set some portability values: $temp_db = new DB_DataObject(); $db =& $temp_db->getDatabaseConnection(); $db->setOption('portability', DB_PORTABILITY_NUMROWS | DB_PORTABILITY_NULL_TO_EMPTY); // Update the date format to fix issues with Oracle being evil $db->query("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"); } } }
/** * @param DB_DataObject $obj the recordset on which the select query will be executed */ public function getTagsArray($obj) { if (is_array($obj->_tagplugin_cache)) { return $obj->_tagplugin_cache; } if (empty($obj->tagplugin_cache)) { $tag = DB_DataObject::factory('tag'); $dbo = DB_DataObject::factory('tag_record'); $dbo->tagged_table = $obj->tableName(); $dbo->record_id = $obj->pk(); $tag->selectAdd(); $tag->selectAdd('tag.id,tag.strip'); $tag->joinAdd($dbo); $tag->selectAs($dbo, 'link_%s'); $tag->find(); $obj->tagplugin_cache = '|'; while ($tag->fetch()) { if (empty($tag->strip)) { continue; } $obj->tagplugin_cache .= $tag->strip . '|'; $obj->_tagplugin_cache[] = $tag->strip; } $db = $obj->getDatabaseConnection(); $query = sprintf('UPDATE %s SET tagplugin_cache=:cacheval where %s = :pkval', $db->quoteIdentifier($obj->tableName()), $db->quoteIdentifier($obj->pkName())); $sth = $db->prepare($query, array('text', 'text')); if (PEAR::isError($sth)) { throw new Exception($sth->getMessage() . ' HINT: check if your table has a tagplugin_cache field'); } $sth->execute(array('cacheval' => $obj->tagplugin_cache, 'pkval' => $obj->pk())); } $obj->_tagplugin_cache = explode('|', $obj->tagplugin_cache); return $obj->_tagplugin_cache; }