Skip to content

Commit efd2044

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents d1c5654 + eb35f30 commit efd2044

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@
4747
- Added `auth:reminders` Artisan command for generating a migration for the password reminders table.
4848
- Added `App::fatal` method for registering an error listener for PHP fatal errors.
4949
- Added `session:table` Artisan command for generating a migration for the session database table.
50-
- Fix bug when using `first` method on a `belongsToMany` relationship.
50+
- Fix bug when using `first` method on a `belongsToMany` relationship.
51+
- Added SQL and bindings array to database query exceptions.

src/Illuminate/Auth/Console/stubs/reminders.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CreatePasswordRemindersTable extends Migration {
1111
*/
1212
public function up()
1313
{
14-
Schema::table('password_reminders', function($t)
14+
Schema::create('password_reminders', function($t)
1515
{
1616
$t->string('email');
1717
$t->string('token');
@@ -29,4 +29,4 @@ public function down()
2929
Schema::drop('password_reminders');
3030
}
3131

32-
}
32+
}

src/Illuminate/Database/Connection.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,42 @@ protected function run($query, $bindings, Closure $callback)
437437
// To execute the statement, we'll simply call the callback, which will actually
438438
// run the SQL against the PDO connection. Then we can calculate the time it
439439
// took to execute and log the query SQL, bindings and time in our memory.
440-
$result = $callback($this, $query, $bindings);
440+
try
441+
{
442+
$result = $callback($this, $query, $bindings);
443+
}
444+
catch (\Exception $e)
445+
{
446+
$this->handleQueryException($e, $query, $bindings);
447+
}
441448

449+
// Once we have run the query we will calculate the time that it took to run and
450+
// then log the query, bindings, and execution time so we will report them on
451+
// the event that the developer needs them. We'll log time in milliseconds.
442452
$time = number_format((microtime(true) - $start) * 1000, 2);
443453

444454
$this->logQuery($query, $bindings, $time);
445455

446456
return $result;
447457
}
448458

459+
/**
460+
* Handle an exception that occurred during a query.
461+
*
462+
* @param Exception $e
463+
* @param string $query
464+
* @param array $bindings
465+
* @return void
466+
*/
467+
protected function handleQueryException(\Exception $e, $query, $bindings)
468+
{
469+
$bindings = var_export($bindings, true);
470+
471+
$message = $e->getMessage()." (SQL: {$query}) (Bindings: {$bindings})";
472+
473+
throw new \Exception($message, 0);
474+
}
475+
449476
/**
450477
* Log a query in the connection's query log.
451478
*

src/Illuminate/Session/Console/stubs/database.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CreateSessionTable extends Migration {
1111
*/
1212
public function up()
1313
{
14-
Schema::table('sessions', function($t)
14+
Schema::create('sessions', function($t)
1515
{
1616
$t->string('id')->unique();
1717
$t->text('payload');
@@ -29,4 +29,4 @@ public function down()
2929
Schema::drop('sessions');
3030
}
3131

32-
}
32+
}

0 commit comments

Comments
 (0)