Skip to content

Instantly share code, notes, and snippets.

@sevein
Created July 4, 2012 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevein/3047934 to your computer and use it in GitHub Desktop.
Save sevein/3047934 to your computer and use it in GitHub Desktop.
Add verbosity to Propel error messages
Index: vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel/util/BasePeer.php
===================================================================
--- vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel/util/BasePeer.php
+++ vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel/util/BasePeer.php
@@ -283,7 +283,7 @@
$sql = 'INSERT INTO ' . $tableName
. ' (' . implode(',', $columns) . ')'
. ' VALUES (';
- // . substr(str_repeat("?,", count($columns)), 0, -1) .
+ // . substr(str_repeat("?,", count($columns)), 0, -1) .
for($p=1, $cnt=count($columns); $p <= $cnt; $p++) {
$sql .= ':p'.$p;
if ($p !== $cnt) $sql .= ',';
@@ -296,7 +296,7 @@
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
- throw new PropelException("Unable to execute INSERT statement.", $e);
+ throw new PropelException("Unable to execute INSERT statement. SQL: \"$sql\" (".self::getParamValues($qualifiedCols, $criteria).')', $e);
}
// If the primary key column is auto-incremented, get the id now.
@@ -348,7 +348,7 @@
foreach ($tablesColumns as $tableName => $columns) {
$whereClause = array();
-
+
$params = array();
$stmt = null;
@@ -392,15 +392,15 @@
}
}
}
-
+
$params = self::buildParams($updateTablesColumns[$tableName], $updateValues);
-
+
foreach ($columns as $colName) {
$sb = "";
$selectCriteria->getCriterion($colName)->appendPsTo($sb, $params);
$whereClause[] = $sb;
}
-
+
$sql = substr($sql, 0, -2) . " WHERE " . implode(" AND ", $whereClause);
$stmt = $con->prepare($sql);
@@ -847,7 +847,7 @@
// Unique from clause elements
$fromClause = array_unique($fromClause);
$fromClause = array_diff($fromClause, array(''));
-
+
// tables should not exist in both the from and join clauses
if ($joinTables && $fromClause) {
foreach ($fromClause as $fi => $ftable) {
@@ -940,7 +940,7 @@
} else {
$from .= implode(", ", $fromClause);
}
-
+
$from .= $joinClause ? ' ' . implode(' ', $joinClause) : '';
// Build the SQL from the arrays we compiled
@@ -980,6 +980,27 @@
return $params;
}
+ public static function getParamValues($columns, $criteria)
+ {
+ foreach($columns as $key)
+ {
+ if ($criteria->containsKey($key)) {
+ $crit = $criteria->getCriterion($key);
+ $val = $crit->getValue();
+ if ($val instanceof DateTime)
+ {
+ $values[] = $key.' => \''.$val->format('Y-m-d H:i:s').'\'';
+ }
+ else
+ {
+ $values[] = $key.' => \''.$val.'\'';
+ }
+ }
+ }
+
+ return implode(', ', $values);
+ }
+
/**
* This function searches for the given validator $name under propel/validator/$name.php,
* imports and caches it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment