Skip to content

Commit

Permalink
fix: Fix to Error Detection
Browse files Browse the repository at this point in the history
closes #91
  • Loading branch information
usernane committed Oct 28, 2024
1 parent b7cda0c commit a482f81
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tests/webfiori/database/tests/mssql/MSSQLQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@ public function testInsert05() {
* @test
*/
public function testInsert06() {
$this->expectException(DatabaseException::class);
$this->expectExceptionMessage("207 - Statement(s) could not be prepared: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'not_exist'.");
$schema = new MSSQLTestSchema();
$q = $schema->table('users_tasks');
$q->insert([
Expand Down
2 changes: 1 addition & 1 deletion tests/webfiori/database/tests/mssql/MSSQLTestSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
class MSSQLTestSchema extends Database {
public function __construct() {
parent::__construct(new ConnectionInfo('mssql','sa', '1234567890@Eu', 'testing_db', 'localhost'));
parent::__construct(new ConnectionInfo('mssql','sa', '1234567890@Eu', 'testing_db', 'localhost\SQLEXPRESS'));

$table00 = new MSSQLTable('users');
$table00->setComment('This table is used to hold users info.');
Expand Down
4 changes: 2 additions & 2 deletions webfiori/database/mssql/MSSQLConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ private function setSqlErr() {
$lastErr = $allErrs[count($allErrs) - 2];
$this->sqlState = $lastErr['SQLSTATE'];
$this->setErrMessage($lastErr['message']);
} else if (strpos($lastErr['message'], 'Statement(s) could not be prepared') === true) {
$lastErr = $allErrs[count($allErrs) - 1];
} else if ($lastErr['SQLSTATE'] == '42000' && $lastErr['code'] == 8180) {
$lastErr = $allErrs[count($allErrs) - 2];
$this->sqlState = $lastErr['SQLSTATE'];
$this->setErrMessage('Statement(s) could not be prepared: '.$lastErr['message']);
$this->setErrCode($lastErr['code']);
Expand Down

0 comments on commit a482f81

Please sign in to comment.