Think/Db/Driver类改进自动参数绑定的处理

This commit is contained in:
ThinkPHP
2013-04-26 21:40:26 +08:00
parent 8365c5d7cd
commit b54ee372f5

View File

@@ -327,11 +327,15 @@ abstract class Driver {
foreach ($data as $key=>$val){ foreach ($data as $key=>$val){
$value = $this->parseValue($val); $value = $this->parseValue($val);
if(is_scalar($value)) {// 过滤非标量数据 if(is_scalar($value)) {// 过滤非标量数据
if(0===strpos($value,':')){
$set[] = $this->parseKey($key).'='.$value;
}else{
$name = md5($key); $name = md5($key);
$set[] = $this->parseKey($key).'=:T'.$name; $set[] = $this->parseKey($key).'=:T'.$name;
$this->bindParam($name,$value); $this->bindParam($name,$value);
} }
} }
}
return ' SET '.implode(',',$set); return ' SET '.implode(',',$set);
} }
@@ -740,11 +744,15 @@ abstract class Driver {
$value = $this->parseValue($val); $value = $this->parseValue($val);
if(is_scalar($value)) { // 过滤非标量数据 if(is_scalar($value)) { // 过滤非标量数据
$fields[] = $this->parseKey($key); $fields[] = $this->parseKey($key);
if(0===strpos($value,':')){
$values[] = $value;
}else{
$name = md5($key); $name = md5($key);
$values[] = ':'.$name; $values[] = ':T'.$name;
$this->bindParam($name,$value); $this->bindParam($name,$value);
} }
} }
}
$sql = ($replace?'REPLACE':'INSERT').' INTO '.$this->parseTable($options['table']).' ('.implode(',', $fields).') VALUES ('.implode(',', $values).')'; $sql = ($replace?'REPLACE':'INSERT').' INTO '.$this->parseTable($options['table']).' ('.implode(',', $fields).') VALUES ('.implode(',', $values).')';
$sql .= $this->parseLock(isset($options['lock'])?$options['lock']:false); $sql .= $this->parseLock(isset($options['lock'])?$options['lock']:false);
$sql .= $this->parseComment(!empty($options['comment'])?$options['comment']:''); $sql .= $this->parseComment(!empty($options['comment'])?$options['comment']:'');