改进Query的参数绑定

This commit is contained in:
thinkphp
2016-07-20 17:01:18 +08:00
parent 8a5f4ff402
commit 64f2ae3df8

View File

@@ -1599,13 +1599,15 @@ class Query
$options = $this->parseExpress(); $options = $this->parseExpress();
// 生成SQL语句 // 生成SQL语句
$sql = $this->builder()->insert($data, $options, $replace); $sql = $this->builder()->insert($data, $options, $replace);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_sql']) { if ($options['fetch_sql']) {
// 获取实际执行的SQL语句 // 获取实际执行的SQL语句
return $this->connection->getRealSql($sql, $this->bind); return $this->connection->getRealSql($sql, $bind);
} }
$sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null); $sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null);
// 执行操作 // 执行操作
return $this->execute($sql, $this->getBind(), $getLastInsID, $sequence); return $this->execute($sql, $bind, $getLastInsID, $sequence);
} }
/** /**
@@ -1636,12 +1638,14 @@ class Query
} }
// 生成SQL语句 // 生成SQL语句
$sql = $this->builder()->insertAll($dataSet, $options); $sql = $this->builder()->insertAll($dataSet, $options);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_sql']) { if ($options['fetch_sql']) {
// 获取实际执行的SQL语句 // 获取实际执行的SQL语句
return $this->connection->getRealSql($sql, $this->bind); return $this->connection->getRealSql($sql, $bind);
} else { } else {
// 执行操作 // 执行操作
return $this->execute($sql, $this->getBind()); return $this->execute($sql, $bind);
} }
} }
@@ -1660,12 +1664,14 @@ class Query
// 生成SQL语句 // 生成SQL语句
$table = $this->parseSqlTable($table); $table = $this->parseSqlTable($table);
$sql = $this->builder()->selectInsert($fields, $table, $options); $sql = $this->builder()->selectInsert($fields, $table, $options);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_sql']) { if ($options['fetch_sql']) {
// 获取实际执行的SQL语句 // 获取实际执行的SQL语句
return $this->connection->getRealSql($sql, $this->bind); return $this->connection->getRealSql($sql, $bind);
} else { } else {
// 执行操作 // 执行操作
return $this->execute($sql, $this->getBind()); return $this->execute($sql, $bind);
} }
} }
@@ -1708,9 +1714,11 @@ class Query
} }
// 生成UPDATE SQL语句 // 生成UPDATE SQL语句
$sql = $this->builder()->update($data, $options); $sql = $this->builder()->update($data, $options);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_sql']) { if ($options['fetch_sql']) {
// 获取实际执行的SQL语句 // 获取实际执行的SQL语句
return $this->connection->getRealSql($sql, $this->bind); return $this->connection->getRealSql($sql, $bind);
} else { } else {
// 检测缓存 // 检测缓存
if (isset($key) && Cache::get($key)) { if (isset($key) && Cache::get($key)) {
@@ -1718,7 +1726,7 @@ class Query
Cache::rm($key); Cache::rm($key);
} }
// 执行操作 // 执行操作
return '' == $sql ? 0 : $this->execute($sql, $this->getBind()); return '' == $sql ? 0 : $this->execute($sql, $bind);
} }
} }
@@ -1760,12 +1768,14 @@ class Query
if (!$resultSet) { if (!$resultSet) {
// 生成查询SQL // 生成查询SQL
$sql = $this->builder()->select($options); $sql = $this->builder()->select($options);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_sql']) { if ($options['fetch_sql']) {
// 获取实际执行的SQL语句 // 获取实际执行的SQL语句
return $this->connection->getRealSql($sql, $this->bind); return $this->connection->getRealSql($sql, $bind);
} }
// 执行查询操作 // 执行查询操作
$resultSet = $this->query($sql, $this->getBind(), $options['master'], $options['fetch_class']); $resultSet = $this->query($sql, $bind, $options['master'], $options['fetch_class']);
if ($resultSet instanceof \PDOStatement) { if ($resultSet instanceof \PDOStatement) {
// 返回PDOStatement对象 // 返回PDOStatement对象
@@ -1845,12 +1855,14 @@ class Query
if (!$result) { if (!$result) {
// 生成查询SQL // 生成查询SQL
$sql = $this->builder()->select($options); $sql = $this->builder()->select($options);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_sql']) { if ($options['fetch_sql']) {
// 获取实际执行的SQL语句 // 获取实际执行的SQL语句
return $this->connection->getRealSql($sql, $this->bind); return $this->connection->getRealSql($sql, $bind);
} }
// 执行查询 // 执行查询
$result = $this->query($sql, $this->getBind(), $options['master'], $options['fetch_class']); $result = $this->query($sql, $bind, $options['master'], $options['fetch_class']);
if ($result instanceof \PDOStatement) { if ($result instanceof \PDOStatement) {
// 返回PDOStatement对象 // 返回PDOStatement对象
@@ -2015,10 +2027,11 @@ class Query
} }
// 生成删除SQL语句 // 生成删除SQL语句
$sql = $this->builder()->delete($options); $sql = $this->builder()->delete($options);
// 获取参数绑定
$bind = $this->getBind();
if ($options['fetch_sql']) { if ($options['fetch_sql']) {
// 获取实际执行的SQL语句 // 获取实际执行的SQL语句
return $this->connection->getRealSql($sql, $this->bind); return $this->connection->getRealSql($sql, $bind);
} }
// 检测缓存 // 检测缓存
@@ -2027,7 +2040,7 @@ class Query
Cache::rm($key); Cache::rm($key);
} }
// 执行操作 // 执行操作
return $this->execute($sql, $this->getBind()); return $this->execute($sql, $bind);
} }
/** /**