File tree Expand file tree Collapse file tree 4 files changed +21
-19
lines changed Expand file tree Collapse file tree 4 files changed +21
-19
lines changed Original file line number Diff line number Diff line change @@ -344,10 +344,6 @@ public function handleSqlError(PDOException $e)
344
344
$ this ->db ->cancelTransaction ();
345
345
$ this ->db ->setLogMessage ($ e ->getMessage ());
346
346
347
- if ($ this ->db ->getDriver ()->isDuplicateKeyError ($ e ->getCode ())) {
348
- return false ;
349
- }
350
-
351
347
throw new SQLException ('SQL Error: ' .$ e ->getMessage ());
352
348
}
353
349
}
Original file line number Diff line number Diff line change @@ -51,12 +51,12 @@ public function testBadSQLQuery()
51
51
52
52
public function testDuplicateKey ()
53
53
{
54
+ $ this ->expectException (\PicoDb \SQLException::class);
55
+
54
56
$ this ->db ->getConnection ()->exec ('CREATE TABLE foobar (something CHAR(1) UNIQUE) ENGINE=InnoDB ' );
55
57
56
58
$ this ->assertNotFalse ($ this ->db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' )));
57
- $ this ->assertFalse ($ this ->db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' )));
58
-
59
- $ this ->assertEquals (1 , $ this ->db ->execute ('SELECT COUNT(*) FROM foobar WHERE something=? ' , array ('a ' ))->fetchColumn ());
59
+ $ this ->db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' ));
60
60
}
61
61
62
62
public function testThatTransactionReturnsAValue ()
@@ -89,11 +89,13 @@ public function testThatTransactionThrowExceptionWhenRollbacked()
89
89
90
90
public function testThatTransactionReturnsFalseWhithDuplicateKey ()
91
91
{
92
- $ this ->assertFalse ($ this ->db ->transaction (function (Database $ db ) {
92
+ $ this ->expectException (\PicoDb \SQLException::class);
93
+
94
+ $ this ->db ->transaction (function (Database $ db ) {
93
95
$ db ->getConnection ()->exec ('CREATE TABLE foobar (something CHAR(1) UNIQUE) ENGINE=InnoDB ' );
94
96
$ r1 = $ db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' ));
95
97
$ r2 = $ db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' ));
96
98
return $ r1 && $ r2 ;
97
- })) ;
99
+ });
98
100
}
99
101
}
Original file line number Diff line number Diff line change @@ -50,12 +50,12 @@ public function testBadSQLQuery()
50
50
51
51
public function testDuplicateKey ()
52
52
{
53
+ $ this ->expectException (\PicoDb \SQLException::class);
54
+
53
55
$ this ->db ->getConnection ()->exec ('CREATE TABLE foobar (something TEXT UNIQUE) ' );
54
56
55
57
$ this ->assertNotFalse ($ this ->db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' )));
56
- $ this ->assertFalse ($ this ->db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' )));
57
-
58
- $ this ->assertEquals (1 , $ this ->db ->execute ('SELECT COUNT(*) FROM foobar WHERE something=? ' , array ('a ' ))->fetchColumn ());
58
+ $ this ->db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' ));
59
59
}
60
60
61
61
public function testThatTransactionReturnsAValue ()
@@ -88,11 +88,13 @@ public function testThatTransactionThrowExceptionWhenRollbacked()
88
88
89
89
public function testThatTransactionReturnsFalseWhithDuplicateKey ()
90
90
{
91
- $ this ->assertFalse ($ this ->db ->transaction (function (Database $ db ) {
91
+ $ this ->expectException (\PicoDb \SQLException::class);
92
+
93
+ $ this ->db ->transaction (function (Database $ db ) {
92
94
$ db ->getConnection ()->exec ('CREATE TABLE foobar (something TEXT UNIQUE) ' );
93
95
$ r1 = $ db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' ));
94
96
$ r2 = $ db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' ));
95
97
return $ r1 && $ r2 ;
96
- })) ;
98
+ });
97
99
}
98
100
}
Original file line number Diff line number Diff line change @@ -48,12 +48,12 @@ public function testBadSQLQuery()
48
48
49
49
public function testDuplicateKey ()
50
50
{
51
+ $ this ->expectException (\PicoDb \SQLException::class);
52
+
51
53
$ this ->db ->getConnection ()->exec ('CREATE TABLE foobar (something TEXT UNIQUE) ' );
52
54
53
55
$ this ->assertNotFalse ($ this ->db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' )));
54
- $ this ->assertFalse ($ this ->db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' )));
55
-
56
- $ this ->assertEquals (1 , $ this ->db ->execute ('SELECT COUNT(*) FROM foobar WHERE something=? ' , array ('a ' ))->fetchColumn ());
56
+ $ this ->db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' ));
57
57
}
58
58
59
59
public function testThatTransactionReturnsAValue ()
@@ -86,12 +86,14 @@ public function testThatTransactionThrowExceptionWhenRollbacked()
86
86
87
87
public function testThatTransactionReturnsFalseWhithDuplicateKey ()
88
88
{
89
- $ this ->assertFalse ($ this ->db ->transaction (function (Database $ db ) {
89
+ $ this ->expectException (\PicoDb \SQLException::class);
90
+
91
+ $ this ->db ->transaction (function (Database $ db ) {
90
92
$ db ->getConnection ()->exec ('CREATE TABLE foobar (something TEXT UNIQUE) ' );
91
93
$ r1 = $ db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' ));
92
94
$ r2 = $ db ->execute ('INSERT INTO foobar (something) VALUES (?) ' , array ('a ' ));
93
95
return $ r1 && $ r2 ;
94
- })) ;
96
+ });
95
97
}
96
98
97
99
public function testGetInstance ()
You can’t perform that action at this time.
0 commit comments