修正模型类的getDbFields方法 改进数据库驱动类的参数绑定功能

This commit is contained in:
ThinkPHP
2013-04-20 16:15:41 +08:00
parent 998c0e2685
commit ef8434da54
2 changed files with 1937 additions and 1924 deletions

View File

@@ -341,7 +341,7 @@ abstract class Driver {
*/ */
protected function parseValue($value) { protected function parseValue($value) {
if(is_string($value)) { if(is_string($value)) {
$value = '\''.$this->escapeString($value).'\''; $value = strpos($value,':') === 0 ? $this->escapeString($value) : '\''.$this->escapeString($value).'\'';
}elseif(isset($value[0]) && is_string($value[0]) && strtolower($value[0]) == 'exp'){ }elseif(isset($value[0]) && is_string($value[0]) && strtolower($value[0]) == 'exp'){
$value = $this->escapeString($value[1]); $value = $this->escapeString($value[1]);
}elseif(is_array($value)) { }elseif(is_array($value)) {
@@ -489,6 +489,8 @@ abstract class Driver {
}else{ }else{
$whereStr .= $key.' '.$this->comparison[strtolower($val[0])].' '.$this->parseValue($val[1]); $whereStr .= $key.' '.$this->comparison[strtolower($val[0])].' '.$this->parseValue($val[1]);
} }
}elseif('bind'==strtolower($val[0])){ // 使用表达式
$whereStr .= ' ('.$key.' = :'.$val[1].') ';
}elseif('exp'==strtolower($val[0])){ // 使用表达式 }elseif('exp'==strtolower($val[0])){ // 使用表达式
$whereStr .= ' ('.$key.' '.$val[1].') '; $whereStr .= ' ('.$key.' '.$val[1].') ';
}elseif(preg_match('/IN/i',$val[0])){ // IN 运算 }elseif(preg_match('/IN/i',$val[0])){ // IN 运算
@@ -901,7 +903,7 @@ abstract class Driver {
Debug::remark('queryStartTime','time'); Debug::remark('queryStartTime','time');
}else{ }else{
$this->modelSql[$this->model] = $this->queryStr; $this->modelSql[$this->model] = $this->queryStr;
$this->model = '_think_'; //$this->model = '_think_';
// 记录操作结束时间 // 记录操作结束时间
Debug::remark('queryEndTime','time'); Debug::remark('queryEndTime','time');
Log::record($this->queryStr.' [ RunTime:'.Debug::getUseTime('queryStartTime','queryEndTime').'s ]','SQL'); Log::record($this->queryStr.' [ RunTime:'.Debug::getUseTime('queryStartTime','queryEndTime').'s ]','SQL');

View File

@@ -637,12 +637,12 @@ class Model {
// 记录字段类型信息 // 记录字段类型信息
$this->fields['_type'] = $type; $this->fields['_type'] = $type;
Cache::set(md5($this->trueTableName),$this->fields); Cache::set(md5($this->trueTableName),$this->fields);
return array_keys($fields); $fields = $this->fields;
}else{ }else{
$this->fields = $fields; $this->fields = $fields;
unset($fields['_pk'],$fields['_type']);
return array_keys($fields);
} }
unset($fields['_pk'],$fields['_type']);
return $fields;
} }
} }
@@ -929,6 +929,17 @@ class Model {
return $this; return $this;
} }
/**
* 指定参数绑定
* @access public
* @param string $filter 指定过滤方法
* @return Model
*/
public function bind($bind){
$this->options['bind'] = $bind;
return $this;
}
/** /**
* 查询注释 * 查询注释
* @access public * @access public