@@ -108,7 +108,12 @@ public function testUseStatement() {
108
108
}
109
109
110
110
private function assertQuery ( $ sql ) {
111
- $ retval = $ this ->engine ->query ( $ sql );
111
+ try {
112
+ $ retval = $ this ->engine ->query ( $ sql );
113
+ } catch ( Exception $ e ) {
114
+ var_dump ( $ this ->engine ->get_last_sqlite_queries () );
115
+ throw $ e ;
116
+ }
112
117
$ this ->assertNotFalse ( $ retval );
113
118
return $ retval ;
114
119
}
@@ -1567,4 +1572,56 @@ public function testInformationSchemaAlterTableAddForeignKeys(): void {
1567
1572
$ result
1568
1573
);
1569
1574
}
1575
+
1576
+ public function testInformationSchemaAlterTableDropForeignKeys (): void {
1577
+ $ this ->assertQuery ( 'CREATE TABLE t1 (id INT PRIMARY KEY, name VARCHAR(255)) ' );
1578
+ $ this ->assertQuery (
1579
+ 'CREATE TABLE t2 (
1580
+ id INT,
1581
+ t1_id INT REFERENCES t1 (id),
1582
+ FOREIGN KEY (t1_id) REFERENCES t1 (id),
1583
+ CONSTRAINT fk1 FOREIGN KEY (t1_id) REFERENCES t1 (id) ON DELETE CASCADE
1584
+ ) '
1585
+ );
1586
+
1587
+ // INFORMATION_SCHEMA.TABLE_CONSTRAINTS
1588
+ $ result = $ this ->assertQuery ( "SELECT * FROM information_schema.table_constraints WHERE table_name = 't2' " );
1589
+ $ this ->assertCount ( 3 , $ result );
1590
+
1591
+ // INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
1592
+ $ result = $ this ->assertQuery ( "SELECT * FROM information_schema.referential_constraints WHERE table_name = 't2' " );
1593
+ $ this ->assertCount ( 3 , $ result );
1594
+
1595
+ // INFORMATION_SCHEMA.KEY_COLUMN_USAGE
1596
+ $ result = $ this ->assertQuery ( "SELECT * FROM information_schema.key_column_usage WHERE table_name = 't2' " );
1597
+ $ this ->assertCount ( 3 , $ result );
1598
+
1599
+ // SHOW CREATE TABLE
1600
+ $ result = $ this ->assertQuery ( 'SHOW CREATE TABLE t2 ' );
1601
+ $ this ->assertEquals (
1602
+ array (
1603
+ (object ) array (
1604
+ 'Create Table ' => implode (
1605
+ "\n" ,
1606
+ array (
1607
+ 'CREATE TABLE `t2` ( ' ,
1608
+ ' `id` int DEFAULT NULL, ' ,
1609
+ ' `t1_id` int DEFAULT NULL, ' ,
1610
+ ' CONSTRAINT `fk1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`) ON DELETE CASCADE, ' ,
1611
+ ' CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`), ' ,
1612
+ ' CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`) ' ,
1613
+ ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
1614
+ )
1615
+ ),
1616
+ ),
1617
+ ),
1618
+ $ result
1619
+ );
1620
+
1621
+ // DROP FOREIGN KEY
1622
+ $ this ->assertQuery ( 'ALTER TABLE t2 DROP FOREIGN KEY fk1 ' );
1623
+
1624
+ $ result = $ this ->assertQuery ( "SELECT * FROM information_schema.table_constraints WHERE table_name = 't2' " );
1625
+ $ this ->assertCount ( 2 , $ result );
1626
+ }
1570
1627
}
0 commit comments