laravel / lumen-framework

The Laravel Lumen Framework.
https://lumen.laravel.com
MIT License
1.48k stars 419 forks source link

Exception not thrown when insert fails in QueryBuilder #925

Closed dunhamjared closed 5 years ago

dunhamjared commented 5 years ago

Description:

When an insert fails, an Exception is not thrown.

Steps To Reproduce:

A simple insert with an invalid column name should fail to insert. This will not throw a QueryException.

<?php
/** @var DatabaseManager $db */
$db = app('db');
$db->connection('db_name');
$db->table('table_name')->insert(['invalid_column_name' => 25]);

If you enable query log and run the query manually, the database returns an error: SQL Error (1054): Unknown column column_name

Is this by design?

dunhamjared commented 5 years ago

My bad.

I was assigning my own PDO connection via setPdo and did not know that you have to set the PDO::ATTR_ERRMODE to PDO::ERRMODE_EXCEPTION for exemptions to work when doing this.

For anyone doing this, these are the options set via the SqlServerConnector:

$options = [
    PDO::ATTR_CASE => PDO::CASE_NATURAL,
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
    PDO::ATTR_STRINGIFY_FETCHES => false,
]