Ejemplo n.º 1
0
 function __construct(array $config)
 {
     if (!isset($config['db'])) {
         throw new Exception(__("sqlite config error,can't found \$config['db'] value."));
     }
     parent::__construct($config);
 }
Ejemplo n.º 2
0
 function __construct(array $config)
 {
     if (!isset($config['port']) || !$config['port'] > 0) {
         $config['port'] = 5432;
     }
     parent::__construct($config);
 }
Ejemplo n.º 3
0
 /**
  * Escapes a column name for a query.
  *
  * @param   string  string to escape
  * @return  string
  */
 public function escapeColumn($column)
 {
     return $this->_driver->escapeColumn($column);
 }
Ejemplo n.º 4
0
 public function datatype($type)
 {
     static $types = array('blob' => array('type' => 'string', 'binary' => true, 'character_maximum_length' => '65535'), 'bool' => array('type' => 'bool'), 'bigint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '18446744073709551615'), 'datetime' => array('type' => 'string'), 'decimal unsigned' => array('type' => 'float', 'exact' => true, 'min' => '0'), 'double' => array('type' => 'float'), 'double precision unsigned' => array('type' => 'float', 'min' => '0'), 'double unsigned' => array('type' => 'float', 'min' => '0'), 'enum' => array('type' => 'string'), 'fixed' => array('type' => 'float', 'exact' => true), 'fixed unsigned' => array('type' => 'float', 'exact' => true, 'min' => '0'), 'float unsigned' => array('type' => 'float', 'min' => '0'), 'int unsigned' => array('type' => 'int', 'min' => '0', 'max' => '4294967295'), 'integer unsigned' => array('type' => 'int', 'min' => '0', 'max' => '4294967295'), 'longblob' => array('type' => 'string', 'binary' => true, 'character_maximum_length' => '4294967295'), 'longtext' => array('type' => 'string', 'character_maximum_length' => '4294967295'), 'mediumblob' => array('type' => 'string', 'binary' => true, 'character_maximum_length' => '16777215'), 'mediumint' => array('type' => 'int', 'min' => '-8388608', 'max' => '8388607'), 'mediumint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '16777215'), 'mediumtext' => array('type' => 'string', 'character_maximum_length' => '16777215'), 'national varchar' => array('type' => 'string'), 'numeric unsigned' => array('type' => 'float', 'exact' => true, 'min' => '0'), 'nvarchar' => array('type' => 'string'), 'point' => array('type' => 'string', 'binary' => true), 'real unsigned' => array('type' => 'float', 'min' => '0'), 'set' => array('type' => 'string'), 'smallint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '65535'), 'text' => array('type' => 'string', 'character_maximum_length' => '65535'), 'tinyblob' => array('type' => 'string', 'binary' => true, 'character_maximum_length' => '255'), 'tinyint' => array('type' => 'int', 'min' => '-128', 'max' => '127'), 'tinyint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '255'), 'tinytext' => array('type' => 'string', 'character_maximum_length' => '255'), 'year' => array('type' => 'string'));
     $type = \str_replace(' zerofill', '', $type);
     if (isset($types[$type])) {
         return $types[$type];
     }
     return parent::datatype($type);
 }
Ejemplo n.º 5
0
 function __construct(array $config)
 {
     static $c = null;
     if (null === $c) {
         $c = version_compare(PHP_VERSION, '5.4', '<');
     }
     if ($c) {
         # php5.4以下有注入漏洞,所以本系统不允许使用PDO
         throw new Exception(__('If use pdo Driver, need php 5.4+, because less php 5.4 has the SQL injection vulnerability.'));
     }
     if (is_array($config['connection']['hostname'])) {
         $pdo = current($config['connection']['hostname']);
         if (is_array($pdo)) {
             $pdo = current($pdo);
         }
     } else {
         $pdo = $config['connection']['hostname'];
     }
     list($type, $host) = explode(':', $pdo, 2);
     if (isset($config['pdo_type']) && $config['pdo_type']) {
         $type = strtolower($config['pdo_type']);
     } else {
         if (!$type) {
             throw new Exception(__('pdo config connection hostname error. need pdo driver type'));
         }
         if ($type === 'uri') {
             // uri:file:///path/to/dsnfile
             $config['connection']['hostname'] = $pdo = file_get_contents($host);
             list($type, $host) = explode(':', $pdo, 2);
             if (!$type) {
                 throw new Exception(__('pdo :host error. need pdo driver type'), array(':host', $host));
             }
         }
         $type = strtolower($type);
     }
     if (!in_array($type, Database_Driver_PDO::$_pdo_types)) {
         throw new Exception(__('Unknown driver type: :type'), array(':type' => $type));
     }
     $this->_pdo_driver_type = $type;
     # driver option
     if (!isset($config['options']) || !is_array($config['options'])) {
         $config['options'] = array();
     }
     if (isset($config['persistent']) && $config['persistent']) {
         $config['options'][PDO::ATTR_PERSISTENT] = true;
     }
     parse_str(str_replace(';', '&', $host), $ot);
     $default_port = null;
     switch ($type) {
         case 'ibm':
         case 'odbc':
             $db_name = 'DATABASE';
             break;
         case 'informix':
             $db_name = 'database';
             break;
         case 'sqlsrv':
             $db_name = 'Database';
             $default_port = 1433;
             break;
         case 'mysql':
             $db_name = 'dbname';
             $this->mysql = true;
             $this->_identifier = '`';
             if ($config['charset']) {
                 $options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES '{$config['charset']}';";
             }
             $default_port = 3306;
             break;
         default:
             $db_name = 'dbname';
             break;
     }
     if (!isset($ot[$db_name])) {
         if ($config['connection']['database']) {
             $ot[$db_name] = $config['connection']['database'];
             # 重新还原
             $config['connection']['hostname'] = $type . ':' . http_build_query($ot, '', ';');
         }
     } else {
         $config['connection']['database'] = $ot[$db_name];
     }
     # 默认端口
     if ($default_port) {
         if (!isset($config['connection']['port']) || !$config['connection']['port']) {
             $config['connection']['port'] = isset($ot['port']) && $ot['port'] ? (int) $ot['port'] : $default_port;
         }
     }
     parent::__construct($config);
 }
Ejemplo n.º 6
0
 /**
  * Clears the internal query cache
  *
  * @param  string $sql
  */
 public function clear_cache($sql = NULL)
 {
     if (empty($sql)) {
         self::$query_cache = array();
     } else {
         unset(self::$query_cache[$this->query_hash($sql)]);
     }
     Eight::log('debug', 'Database cache cleared: ' . get_class($this));
 }
Ejemplo n.º 7
0
 /**
  * Set up class properties etc.
  */
 private function Setup()
 {
     // place for additional sets
     // e.g. $this->aConfig[ section_key ][ value_key ] = value
     $sAppConfigIni = DOCROOT . $this->oConfig->getValue(sprintf('applications.%s.config_file', $this->oRouter->getApplicationName()));
     $this->oConfig->loadIniFile($sAppConfigIni);
     $this->sLogsDirectory = $this->getConfig('General.Logs_directory', DOCROOT . 'logs/');
     $this->sLogsDirectory .= date('Y-m-d') . '/';
     // set main framework path
     $this->addPath('Lithium');
     // set application path received from config file
     if ($sAppPath = $this->getConfig('General.App_path')) {
         $this->addPath($sAppPath);
         Loader::addPath(DOCROOT . $sAppPath);
     }
     // add path for external classes
     Loader::addPath(DOCROOT);
     // set language
     if ($sLanguage = $this->getConfig('Locale.Language')) {
         $this->sLanguage = $sLanguage;
     }
     Core_Model::setLithium($this);
     Core_Module::setLithium($this);
     Database_Driver::setLithium($this);
     // initialize router
     $this->oRouter->init();
     View::setRouter($this->oRouter);
     Module_Sorter::setRouter($this->oRouter);
     Module_Pagination::setRouter($this->oRouter);
 }
Ejemplo n.º 8
0
 /**
  * Builds and returns the sql select statement
  * 
  * @param Database_Query $oQuery
  * @return string
  */
 protected function buildSqlSelect(Database_Query $oQuery)
 {
     $sSql = parent::buildSqlSelect($oQuery);
     if ($oQuery->limit() > 0) {
         $sSql .= ' LIMIT ';
         if ($oQuery->offset() > 0) {
             $sSql .= $oQuery->offset() . ', ';
         }
         $sSql .= $oQuery->limit();
     }
     return $sSql;
 }
Ejemplo n.º 9
0
 /**
  * Setter for Lithium instance
  * 
  * @param Lithium $oLithium
  */
 public static function setLithium($oLithium)
 {
     self::$oLithium = $oLithium;
 }
Ejemplo n.º 10
0
 /**
  * Clears the internal query cache.
  *
  * @param  string  SQL query
  */
 public function clear_cache($sql = NULL)
 {
     parent::clear_cache($sql);
     $this->tables_cache = array();
     $this->fields_cache = array();
 }