/**
  * Converts this instance into a DELETE string in SQL.
  *
  * @return string
  */
 private function getSQLForDelete()
 {
     $table = $this->_sqlParts['from']['table'] . ($this->_sqlParts['from']['alias'] ? ' ' . $this->_sqlParts['from']['alias'] : '');
     $query = 'DELETE FROM ' . $table . ($this->_sqlParts['where'] !== null ? ' WHERE ' . (string) $this->_sqlParts['where'] : '');
     $query = $this->_maxResults === null && $this->_firstResult == null ? $query : $this->_connection->getAdapter()->applyLimit($query, $this->_firstResult, $this->_maxResults);
     return $query;
 }
 /**
  * Get List Table Column
  *
  * @param string $table
  */
 private function _getListTableColumn($table)
 {
     $column = array();
     $stmt = $this->_conn->query('DESCRIBE ' . $this->_conn->getAdapter()->quoteIdentifierTable($table));
     $result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     for ($i = 0, $size = sizeof($result); $i < $size; ++$i) {
         $val = array_change_key_case($result[$i], CASE_LOWER);
         $decl = $this->getPortableDeclaration($val);
         $values = isset($decl['values']) ? $decl['values'] : array();
         $description = array('name' => $val['field'], 'type' => $decl['php_type'], 'db_type' => $decl['type'][0], 'alltypes' => $decl['type'], 'ntype' => $val['type'], 'length' => $decl['length'], 'fixed' => (bool) $decl['fixed'], 'unsigned' => (bool) $decl['unsigned'], 'values' => $values, 'primary' => strtolower($val['key']) == 'pri', 'unique' => strtolower($val['key']) == 'uni', 'default' => $val['default'], 'notnull' => (bool) ($val['null'] != 'YES'), 'auto_increment' => (bool) (strpos($val['extra'], 'auto_increment') !== false), 'extra' => strtolower($val['extra']));
         if ($description['default'] == 'CURRENT_TIMESTAMP') {
             $description['default'] = null;
             $description['notnull'] = false;
             $description['current_timestamp'] = true;
         }
         $column[$val['field']] = $description;
     }
     return $column;
 }
 public static function initConnection($name, $config)
 {
     $adapter = self::getAdapter($name);
     if (!isset($config['dsn']) || null === $config['dsn']) {
         throw new Exception('No dsn specified in your connection parameters in config ' . $name);
     }
     $dbUser = isset($config['db_user']) ? $config['db_user'] : null;
     $dbPass = isset($config['db_pass']) ? $config['db_pass'] : null;
     $options = isset($config['options']) ? $config['options'] : array();
     try {
         $conn = new Connection($config['dsn'], $dbUser, $dbPass, $options);
         $conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
         $conn->setAttribute(Connection::ATTR_CONNECTION_NAME, $name);
     } catch (Exception $dbe) {
         throw new Exception('Unable to open PDO connection', $dbe);
     }
     $adapter->initConnection($conn, isset($config['settings']) && is_array($config['settings']) ? $config['settings'] : array());
     return $conn;
 }