PluginProbe
SQLite Database Integration / 3.0.2
SQLite Database Integration v3.0.2
3.0.2 3.0.1 trunk 2.1.13 2.1.14 2.1.15 2.1.16 2.2.0 2.2.1 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.2.2 2.2.20 2.2.21 2.2.22 2.2.23 2.2.3 All 32 releases
sqlite-database-integration / wp-includes / database / sqlite / class-wp-sqlite-information-schema-exception.php

class-wp-sqlite-information-schema-exception.php in SQLite Database Integration 3.0.2, at wp-includes/database/sqlite/class-wp-sqlite-information-schema-exception.php

170 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * SQLite information schema exception.
5 *
6 * This class is used to represent errors that may occur when building
7 * the MySQL information schema for emulation in SQLite.
8 *
9 * @access private
10 */
11 class WP_SQLite_Information_Schema_Exception extends Exception {
12 // Information schema exception types.
13 const TYPE_DUPLICATE_TABLE_NAME = 'duplicate-table-name';
14 const TYPE_DUPLICATE_COLUMN_NAME = 'duplicate-column-name';
15 const TYPE_DUPLICATE_KEY_NAME = 'duplicate-key-name';
16 const TYPE_KEY_COLUMN_NOT_FOUND = 'key-column-not-found';
17 const TYPE_CONSTRAINT_DOES_NOT_EXIST = 'constraint-does-not-exist';
18 const TYPE_MULTIPLE_CONSTRAINTS_WITH_NAME = 'multiple-constraints-with-name';
19 const TYPE_INVALID_DEFAULT_VALUE = 'invalid-default-value';
20
21 /**
22 * The exception type.
23 *
24 * @var string
25 */
26 private $type;
27
28 /**
29 * The data to be passed with the exception.
30 *
31 * @var array
32 */
33 private $data;
34
35 /**
36 * Constructor.
37 *
38 * @param string $type The exception type.
39 * @param string $message The exception message.
40 * @param array $data The data to be passed with the exception.
41 * @param Throwable|null $previous The previous throwable used for the exception chaining.
42 */
43 public function __construct(
44 string $type,
45 string $message,
46 array $data = array(),
47 ?Throwable $previous = null
48 ) {
49 parent::__construct( $message, 0, $previous );
50 $this->type = $type;
51 $this->data = $data;
52 }
53
54 /**
55 * Get the type of the exception.
56 *
57 * @return string The type of the exception.
58 */
59 public function get_type(): string {
60 return $this->type;
61 }
62
63 /**
64 * Get the data associated with the exception.
65 *
66 * @return array The data associated with the exception.
67 */
68 public function get_data(): array {
69 return $this->data;
70 }
71
72 /**
73 * Create a duplicate table name exception.
74 *
75 * @param string $table_name The name of the affected table.
76 * @return self The exception instance.
77 */
78 public static function duplicate_table_name( string $table_name ): WP_SQLite_Information_Schema_Exception {
79 return new self(
80 self::TYPE_DUPLICATE_TABLE_NAME,
81 sprintf( "Table '%s' already exists.", $table_name ),
82 array( 'table_name' => $table_name )
83 );
84 }
85
86 /**
87 * Create a duplicate column name exception.
88 *
89 * @param string $column_name The name of the affected column.
90 * @return self The exception instance.
91 */
92 public static function duplicate_column_name( string $column_name ): WP_SQLite_Information_Schema_Exception {
93 return new self(
94 self::TYPE_DUPLICATE_COLUMN_NAME,
95 sprintf( "Column '%s' already exists.", $column_name ),
96 array( 'column_name' => $column_name )
97 );
98 }
99
100 /**
101 * Create a duplicate key name exception.
102 *
103 * @param string $key_name The name of the affected key.
104 * @return self The exception instance.
105 */
106 public static function duplicate_key_name( string $key_name ): WP_SQLite_Information_Schema_Exception {
107 return new self(
108 self::TYPE_DUPLICATE_KEY_NAME,
109 sprintf( "Key '%s' already exists.", $key_name ),
110 array( 'key_name' => $key_name )
111 );
112 }
113
114 /**
115 * Create a key column not found exception.
116 *
117 * @param string $column_name The name of the affected column.
118 * @return self The exception instance.
119 */
120 public static function key_column_not_found( string $column_name ): WP_SQLite_Information_Schema_Exception {
121 return new self(
122 self::TYPE_KEY_COLUMN_NOT_FOUND,
123 sprintf( "Key column '%s' doesn't exist in table.", $column_name ),
124 array( 'column_name' => $column_name )
125 );
126 }
127
128 /**
129 * Create a constraint does not exist exception.
130 *
131 * @param string $name The name of the affected constraint.
132 * @return self The exception instance.
133 */
134 public static function constraint_does_not_exist( string $name ): WP_SQLite_Information_Schema_Exception {
135 return new self(
136 self::TYPE_CONSTRAINT_DOES_NOT_EXIST,
137 sprintf( "Constraint '%s' does not exist.", $name ),
138 array( 'name' => $name )
139 );
140 }
141
142 /**
143 * Create a multiple constraints with name exception.
144 *
145 * @param string $name The name of the affected constraint.
146 * @return self The exception instance.
147 */
148 public static function multiple_constraints_with_name( string $name ): WP_SQLite_Information_Schema_Exception {
149 return new self(
150 self::TYPE_MULTIPLE_CONSTRAINTS_WITH_NAME,
151 sprintf( "Table has multiple constraints with the name '%s'. Please use constraint specific 'DROP' clause.", $name ),
152 array( 'name' => $name )
153 );
154 }
155
156 /**
157 * Create an invalid default value exception.
158 *
159 * @param string $column_name The name of the affected column.
160 * @return self The exception instance.
161 */
162 public static function invalid_default_value( string $column_name ): WP_SQLite_Information_Schema_Exception {
163 return new self(
164 self::TYPE_INVALID_DEFAULT_VALUE,
165 sprintf( "Invalid default value for '%s'.", $column_name ),
166 array( 'column_name' => $column_name )
167 );
168 }
169 }
170