Esempio n. 1
0
 /**
  * 格式化为字符串
  *
  * @param QDB_Adapter_Abstract $conn
  * @param string $table_name
  * @param array $mapping
  * @param callback $callback
  *
  * @return string
  */
 function formatToString($conn, $table_name = null, array $mapping = null, $callback = null)
 {
     if (!is_array($mapping)) {
         $mapping = array();
     }
     return $conn->qsql($this->_expr, $table_name, $mapping, $callback);
 }
Esempio n. 2
0
 function close()
 {
     if (is_resource($this->_conn)) {
         mysql_close($this->_conn);
     }
     parent::_clear();
 }
Esempio n. 3
0
 /**
  * 设置当前数据表的元数据
  */
 protected function _setupMeta()
 {
     $table_name = $this->getFullTableName();
     $this->_cache_id = $this->_conn->getID() . '-' . $table_name;
     if (isset(self::$_meta[$this->_cache_id])) {
         return;
     }
     $cached = Q::getIni('db_meta_cached');
     if ($cached) {
         // 尝试从缓存读取
         $policy = array('encoding_filename' => true, 'serialize' => true, 'life_time' => Q::getIni('db_meta_lifetime'), 'cache_dir' => Q::getIni('runtime_cache_dir'));
         $backend = Q::getIni('db_meta_cache_backend');
         $data = Q::getCache($this->_cache_id, $policy, $backend);
         if (is_array($data) && !empty($data)) {
             self::$_meta[$this->_cache_id] = $data[0];
             self::$_fields[$this->_cache_id] = $data[1];
             return;
         }
     }
     // 从数据库获得 meta
     $meta = $this->_conn->metaColumns($table_name);
     $fields = array();
     foreach ($meta as $field) {
         $fields[$field['name']] = true;
     }
     self::$_meta[$this->_cache_id] = $meta;
     self::$_fields[$this->_cache_id] = $fields;
     $data = array($meta, $fields);
     if ($cached) {
         // 缓存数据
         Q::setCache($this->_cache_id, $data, $policy, $backend);
     }
 }
Esempio n. 4
0
 private function _insertIntoPosts($nums)
 {
     $time = time();
     $sql = "INSERT INTO q_posts (title, body, created, updated) VALUES ('title', 'body', {$time}, {$time})";
     $idList = array();
     for ($i = 0; $i < $nums; $i++) {
         $this->dbo->execute($sql);
         $idList[] = $this->dbo->insertID();
     }
     return $idList;
 }
Esempio n. 5
0
 /**
  * 查询指定数据表,指定键值的记录
  */
 protected function _queryRow($table_name, $idname, $id)
 {
     $prefix = $this->_conn->getTablePrefix();
     $sql = "SELECT * FROM {$prefix}{$table_name} WHERE {$idname} = ?";
     return $this->_conn->getRow($sql, array($id));
 }
Esempio n. 6
0
 function close()
 {
     if (is_resource($this->_conn)) {
         pg_close($this->_conn);
     }
     parent::close();
 }
Esempio n. 7
0
 /**
  * 添加一个集合查询
  *
  * @param int $type
  * @param string|QDB_Expr $field
  * @param string $alias
  *
  * @return QDB_Select
  */
 protected function _addAggregate($type, $field, $alias)
 {
     $this->_parts[self::COLUMNS] = array();
     $this->_query_params[self::RECURSION] = 0;
     if ($field instanceof QDB_Expr) {
         $field = $field->formatToString($this->_conn, $this->_getCurrentTableName(), $this->_columns_mapping);
     } else {
         if (isset($this->_columns_mapping[$field])) {
             $field = $this->_columns_mapping[$field];
         }
         $field = $this->_conn->qsql($field, $this->_getCurrentTableName(), $this->_columns_mapping);
         $field = "{$type}({$field})";
     }
     $this->_parts[self::AGGREGATE][] = array($type, $field, $alias);
     $this->_query_params[self::AS_ARRAY] = true;
     return $this;
 }
Esempio n. 8
0
 public function close()
 {
     parent::_clear();
 }
Esempio n. 9
0
 /**
  * 确定事务过程中是否出现失败的查询
  */
 function hasFailedQuery()
 {
     return $this->_dbo->hasFailedQuery();
 }