|
|
@@ -77,13 +77,6 @@ class DboSource extends DataSource {
|
|
|
public $fullDebug = false;
|
|
|
|
|
|
/**
|
|
|
- * Error description of last query
|
|
|
- *
|
|
|
- * @var string
|
|
|
- */
|
|
|
- public $error = null;
|
|
|
-
|
|
|
-/**
|
|
|
* String to hold how many rows were affected by the last SQL operation.
|
|
|
*
|
|
|
* @var string
|
|
|
@@ -383,7 +376,7 @@ class DboSource extends DataSource {
|
|
|
* @return boolean
|
|
|
*/
|
|
|
public function rawQuery($sql, $params = array()) {
|
|
|
- $this->took = $this->error = $this->numRows = false;
|
|
|
+ $this->took = $this->numRows = false;
|
|
|
return $this->execute($sql, $params);
|
|
|
}
|
|
|
|
|
|
@@ -403,7 +396,6 @@ class DboSource extends DataSource {
|
|
|
*/
|
|
|
public function execute($sql, $options = array(), $params = array()) {
|
|
|
$options += array('log' => $this->fullDebug);
|
|
|
- $this->error = null;
|
|
|
|
|
|
$t = microtime(true);
|
|
|
$this->_result = $this->_execute($sql, $params);
|
|
|
@@ -414,10 +406,6 @@ class DboSource extends DataSource {
|
|
|
$this->logQuery($sql);
|
|
|
}
|
|
|
|
|
|
- if ($this->error) {
|
|
|
- $this->showQuery($sql);
|
|
|
- return false;
|
|
|
- }
|
|
|
return $this->_result;
|
|
|
}
|
|
|
|
|
|
@@ -440,25 +428,18 @@ class DboSource extends DataSource {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- try {
|
|
|
- $query = $this->_connection->prepare($sql, $prepareOptions);
|
|
|
- $query->setFetchMode(PDO::FETCH_LAZY);
|
|
|
- if (!$query->execute($params)) {
|
|
|
- $this->_results = $query;
|
|
|
- $this->error = $this->lastError($query);
|
|
|
- $query->closeCursor();
|
|
|
- return false;
|
|
|
- }
|
|
|
- if (!$query->columnCount()) {
|
|
|
- $query->closeCursor();
|
|
|
- return true;
|
|
|
- }
|
|
|
- return $query;
|
|
|
- } catch (PDOException $e) {
|
|
|
- $this->_results = null;
|
|
|
- $this->error = $e->getMessage();
|
|
|
+ $query = $this->_connection->prepare($sql, $prepareOptions);
|
|
|
+ $query->setFetchMode(PDO::FETCH_LAZY);
|
|
|
+ if (!$query->execute($params)) {
|
|
|
+ $this->_results = $query;
|
|
|
+ $query->closeCursor();
|
|
|
return false;
|
|
|
}
|
|
|
+ if (!$query->columnCount()) {
|
|
|
+ $query->closeCursor();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return $query;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -885,7 +866,7 @@ class DboSource extends DataSource {
|
|
|
echo $View->element('sql_dump', array('_forced_from_dbo_' => true));
|
|
|
} else {
|
|
|
foreach ($log['log'] as $k => $i) {
|
|
|
- print (($k + 1) . ". {$i['query']} {$i['error']}\n");
|
|
|
+ print (($k + 1) . ". {$i['query']}\n");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -894,15 +875,13 @@ class DboSource extends DataSource {
|
|
|
* Log given SQL query.
|
|
|
*
|
|
|
* @param string $sql SQL statement
|
|
|
- * @return void|boolean
|
|
|
- * @todo: Add hook to log errors instead of returning false
|
|
|
+ * @return void
|
|
|
*/
|
|
|
public function logQuery($sql) {
|
|
|
$this->_queriesCnt++;
|
|
|
$this->_queriesTime += $this->took;
|
|
|
$this->_queriesLog[] = array(
|
|
|
'query' => $sql,
|
|
|
- 'error' => $this->error,
|
|
|
'affected' => $this->affected,
|
|
|
'numRows' => $this->numRows,
|
|
|
'took' => $this->took
|
|
|
@@ -910,32 +889,6 @@ class DboSource extends DataSource {
|
|
|
if (count($this->_queriesLog) > $this->_queriesLogMax) {
|
|
|
array_pop($this->_queriesLog);
|
|
|
}
|
|
|
- if ($this->error) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-/**
|
|
|
- * Output information about an SQL query. The SQL statement, number of rows in resultset,
|
|
|
- * and execution time in microseconds. If the query fails, an error is output instead.
|
|
|
- *
|
|
|
- * @param string $sql Query to show information on.
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function showQuery($sql) {
|
|
|
- $error = $this->error;
|
|
|
- if (strlen($sql) > 200 && !$this->fullDebug && Configure::read('debug') > 1) {
|
|
|
- $sql = substr($sql, 0, 200) . '[...]';
|
|
|
- }
|
|
|
- if (Configure::read('debug') > 0) {
|
|
|
- $out = null;
|
|
|
- if ($error) {
|
|
|
- trigger_error('<span style="color:Red;text-align:left"><b>' . __d('cake_dev', 'SQL Error:') . "</b> {$this->error}</span>", E_USER_WARNING);
|
|
|
- } else {
|
|
|
- $out = ('<small>[' . __d('cake_dev', 'Aff:%s Num:%s Took:%sms', $this->affected, $this->numRows, $this->took) . ']</small>');
|
|
|
- }
|
|
|
- pr(sprintf('<p style="text-align:left"><b>' . __d('cake_dev', 'Query:') . '</b> %s %s</p>', $sql, $out));
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1161,16 +1114,8 @@ class DboSource extends DataSource {
|
|
|
public function queryAssociation($model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive, $stack) {
|
|
|
if ($query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet)) {
|
|
|
if (!is_array($resultSet)) {
|
|
|
- if (Configure::read('debug') > 0) {
|
|
|
- echo '<div style = "font: Verdana bold 12px; color: #FF0000">' . __d('cake_dev', 'SQL Error in model %s:', $model->alias) . ' ';
|
|
|
- if (isset($this->error) && $this->error != null) {
|
|
|
- echo $this->error;
|
|
|
- }
|
|
|
- echo '</div>';
|
|
|
- }
|
|
|
- return null;
|
|
|
+ throw new CakeException(__d('cake_dev', 'Error in Model %s', get_class($model)));
|
|
|
}
|
|
|
-
|
|
|
if ($type === 'hasMany' && empty($assocData['limit']) && !empty($assocData['foreignKey'])) {
|
|
|
$ins = $fetch = array();
|
|
|
foreach ($resultSet as &$result) {
|