getAdapter() public method

Gets the Zend_Db_Adapter_Abstract for this particular Zend_Db_Table object.
public getAdapter ( ) : Zend_Db_Adapter_Abstract
return Zend_Db_Adapter_Abstract
 /**
  * Get configured database adapter
  * 
  * @return Zend_Db_Adapter_Abstract
  */
 public function getDbAdapter()
 {
     if (null === $this->_dbAdapter) {
         if ($this->_dbTable instanceof Zend_Db_Table_Abstract) {
             $this->_dbAdapter = $this->_dbTable->getAdapter();
         } else {
             throw new Engine_ServiceLocator_Exception('Database adapter not configured');
         }
     }
     return $this->_dbAdapter;
 }
示例#2
0
 public function isValid($value)
 {
     $db = $this->_model->getAdapter();
     $where = $db->quoteInto($this->_field . ' = ?', $value);
     if (null !== $this->_where) {
         $where .= " AND {$this->_where}";
     }
     $rows = $this->_model->fetchAll($where);
     if (count($rows)) {
         $this->_messages[] = Axis::translate('core')->__("Record %s already exist", $value);
         return $this->_not;
     }
     $this->_messages[] = Axis::translate('core')->__("Record %s doesn't found", $value);
     return !$this->_not;
 }
 /**
  * Start analyzer
  *
  * @param Zend_Db_Table_Abstract $table
  *
  * @return array
  */
 public function analyzeTable(Zend_Db_Table_Abstract $table)
 {
     $info = $table->info();
     $info['uniques'] = array();
     unset($info['sequence'], $info['schema'], $info['rowClass'], $info['rowsetClass'], $info['dependentTables'], $info['referenceMap']);
     $adapter = $table->getAdapter();
     foreach ($info['metadata'] as $property => $details) {
         // match php types
         $info['phptypes'][$property] = $this->convertMysqlTypeToPhp($details['DATA_TYPE']);
         // find uniques
         $tmp = $adapter->fetchRow('DESCRIBE `' . $info['name'] . '` `' . $property . '`;');
         if (!empty($tmp['Key']) && $tmp['Key'] != 'MUL') {
             $info['uniques'][$property] = $property;
         }
     }
     // get f-keys
     $result = $adapter->fetchAll('SHOW CREATE TABLE `' . $info['name'] . '`');
     $query = $result[0]['Create Table'];
     $lines = explode("\n", $query);
     $tblinfo = array();
     $keys = array();
     foreach ($lines as $line) {
         preg_match('/^\\s*CONSTRAINT `(\\w+)` FOREIGN KEY \\(`(\\w+)`\\) REFERENCES `(\\w+)` \\(`(\\w+)`\\)/', $line, $tblinfo);
         if (sizeof($tblinfo) > 0) {
             $keys[] = $tmp = array('key' => $tblinfo[1], 'column' => $tblinfo[2], 'fk_table' => $tblinfo[3], 'fk_column' => $tblinfo[4]);
             $this->getDependencyChecker()->isChild($info['name'], $tmp['column'], $tmp['key'], $tmp['fk_table'], $tmp['fk_column']);
         }
     }
     $info['foreign_keys'] = $keys;
     return $info;
 }
示例#4
0
 /**
  * Sets the primary table name and retrieves the table schema.
  *
  * @param Zend_Db_Table_Abstract $adapter
  * @return Zend_Db_Select This Zend_Db_Select object.
  */
 public function setTable(Zend_Db_Table_Abstract $table)
 {
     $this->_adapter = $table->getAdapter();
     $this->_info = $table->info();
     $this->_table = $table;
     return $this;
 }
 /**
  * unlockTable   
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0 
  */
 public function unlockTable()
 {
     try {
         $this->objTable->getAdapter()->query('UNLOCK TABLES;');
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
示例#6
0
 /**
  * Delete Entry
  *
  * @param Postr_Model_Entry $entry
  * @return Postr_Model_EntryMapper          Provides a fluent interface
  */
 public function deleteEntry(Postr_Model_Entry $entry)
 {
     $dbAdapter = $this->_entryTable->getAdapter();
     $dbAdapter->beginTransaction();
     $entryRow = $this->_entryTable->find($entry->getId())->current();
     $entryRow->delete();
     $dbAdapter->commit();
     return $this;
 }
示例#7
0
 /**
  * _getWhereStatement
  *
  * @param  mixed $id
  * @return mixed (string/array)
  */
 private function _getWhereStatement($id)
 {
     if (is_numeric($id)) {
         $where = $this->obj->getAdapter()->quoteInto($this->primaryKey[0] . ' = ?', $id);
     } else {
         $id = unserialize($id);
         foreach ($id as $key => $value) {
             $where[] = $this->obj->getAdapter()->quoteInto($key . ' = ?', $value);
         }
     }
     return $where;
 }
示例#8
0
 /**
  * Set the table object, to re-establish a live connection
  * to the database for a Rowset that has been de-serialized.
  *
  * @param Zend_Db_Table_Abstract $table
  * @return boolean
  * @throws Zend_Db_Table_Row_Exception
  */
 public function setTable(Zend_Db_Table_Abstract $table)
 {
     $this->_table = $table;
     if ($this->_table->getAdapter() == null) {
         $this->_connected = false;
         return false;
     }
     $this->_connected = false;
     // @todo This works only if we have iterated through
     // the result set once to instantiate the rows.
     foreach ($this->_rows as $row) {
         $connected = $row->setTable($table);
         if ($connected == true) {
             $this->_connected = true;
         }
     }
     return $this->_connected;
 }
示例#9
0
 /**
  * Get basic select (select {$fields} from {$table}) and add filters, order and limit info from request
  * @param Zend_Db_Table_Abstract $table
  * @param string|array $fields array of fields or "*" Use as {@see Zend_Db_Select::from()} second params
  * @return Zend_Db_Select
  */
 public function getSelect(Zend_Db_Table_Abstract $table, $fields = "*")
 {
     //create basic selects
     $select = $table->getAdapter()->select()->from($table->info(Zend_Db_Table_Abstract::NAME), $fields);
     $cols = $table->info(Zend_Db_Table::COLS);
     //add filters support
     foreach ((array) $this->getRequest()->getParam('filter') as $value) {
         $field = $value['field'];
         if (in_array($field, $cols)) {
             $filter = System_Controller_Action_Helper_GridFilter_Abstract::factory($value['data']);
             $filter->setField($field);
             $filter->filter($select);
         }
     }
     //add sort
     $sortCol = $this->getRequest()->getParam('sort');
     if (in_array($sortCol, $cols)) {
         $select->order($sortCol . ' ' . $this->_getDirState('dir'));
     }
     //set limit
     $select->limit((int) $this->getRequest()->getParam('limit', 25), (int) $this->getRequest()->getParam('start'));
     return $select;
 }
示例#10
0
 public static function getTableFromString($tableName, Zend_Db_Table_Abstract $referenceTable = null)
 {
     if ($referenceTable instanceof Zend_Db_Table_Abstract) {
         $tableDefinition = $referenceTable->getDefinition();
         if ($tableDefinition !== null && $tableDefinition->hasTableConfig($tableName)) {
             return new Zend_Db_Table($tableName, $tableDefinition);
         }
     }
     // assume the tableName is the class name
     if (!class_exists($tableName)) {
         try {
             require_once 'Zend/Loader.php';
             Zend_Loader::loadClass($tableName);
         } catch (Zend_Exception $e) {
             require_once 'Zend/Db/Table/Row/Exception.php';
             throw new Zend_Db_Table_Row_Exception($e->getMessage(), $e->getCode(), $e);
         }
     }
     $options = array();
     if ($referenceTable instanceof Zend_Db_Table_Abstract) {
         $options['db'] = $referenceTable->getAdapter();
     }
     if (isset($tableDefinition) && $tableDefinition !== null) {
         $options[Zend_Db_Table_Abstract::DEFINITION] = $tableDefinition;
     }
     return new $tableName($options);
 }
示例#11
0
 /**
  * The database adapter used by the model.
  *
  * @return \Zend_Db_Adapter_Abstract
  */
 public function getAdapter()
 {
     return $this->_table->getAdapter();
 }