|
8 | 8 | */ |
9 | 9 | class WP_SQLite_Information_Schema_Exception extends Exception { |
10 | 10 | // Information schema exception types. |
11 | | - const TYPE_DUPLICATE_TABLE_NAME = 'duplicate-table-name'; |
12 | | - const TYPE_DUPLICATE_COLUMN_NAME = 'duplicate-column-name'; |
13 | | - const TYPE_DUPLICATE_KEY_NAME = 'duplicate-key-name'; |
14 | | - const TYPE_KEY_COLUMN_NOT_FOUND = 'key-column-not-found'; |
| 11 | + const TYPE_DUPLICATE_TABLE_NAME = 'duplicate-table-name'; |
| 12 | + const TYPE_DUPLICATE_COLUMN_NAME = 'duplicate-column-name'; |
| 13 | + const TYPE_DUPLICATE_KEY_NAME = 'duplicate-key-name'; |
| 14 | + const TYPE_KEY_COLUMN_NOT_FOUND = 'key-column-not-found'; |
| 15 | + const TYPE_CONSTRAINT_DOES_NOT_EXIST = 'constraint-does-not-exist'; |
| 16 | + const TYPE_MULTIPLE_CONSTRAINTS_WITH_NAME = 'multiple-constraints-with-name'; |
15 | 17 |
|
16 | 18 | /** |
17 | 19 | * The exception type. |
@@ -106,11 +108,45 @@ public static function duplicate_key_name( string $key_name ): WP_SQLite_Informa |
106 | 108 | ); |
107 | 109 | } |
108 | 110 |
|
| 111 | + /** |
| 112 | + * Create a key column not found exception. |
| 113 | + * |
| 114 | + * @param string $column_name The name of the affected column. |
| 115 | + * @return self The exception instance. |
| 116 | + */ |
109 | 117 | public static function key_column_not_found( string $column_name ): WP_SQLite_Information_Schema_Exception { |
110 | 118 | return new self( |
111 | 119 | self::TYPE_KEY_COLUMN_NOT_FOUND, |
112 | 120 | sprintf( "Key column '%s' doesn't exist in table.", $column_name ), |
113 | 121 | array( 'column_name' => $column_name ) |
114 | 122 | ); |
115 | 123 | } |
| 124 | + |
| 125 | + /** |
| 126 | + * Create a constraint does not exist exception. |
| 127 | + * |
| 128 | + * @param string $name The name of the affected constraint. |
| 129 | + * @return self The exception instance. |
| 130 | + */ |
| 131 | + public static function constraint_does_not_exist( string $name ): WP_SQLite_Information_Schema_Exception { |
| 132 | + return new self( |
| 133 | + self::TYPE_CONSTRAINT_DOES_NOT_EXIST, |
| 134 | + sprintf( "Constraint '%s' does not exist.", $name ), |
| 135 | + array( 'name' => $name ) |
| 136 | + ); |
| 137 | + } |
| 138 | + |
| 139 | + /** |
| 140 | + * Create a multiple constraints with name exception. |
| 141 | + * |
| 142 | + * @param string $name The name of the affected constraint. |
| 143 | + * @return self The exception instance. |
| 144 | + */ |
| 145 | + public static function multiple_constraints_with_name( string $name ): WP_SQLite_Information_Schema_Exception { |
| 146 | + return new self( |
| 147 | + self::TYPE_MULTIPLE_CONSTRAINTS_WITH_NAME, |
| 148 | + sprintf( "Table has multiple constraints with the name '%s'. Please use constraint specific 'DROP' clause.", $name ), |
| 149 | + array( 'name' => $name ) |
| 150 | + ); |
| 151 | + } |
116 | 152 | } |
0 commit comments