PluginProbe
SQLite Database Integration / 2.2.21
SQLite Database Integration v2.2.21
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 2.2.21, at wp-includes/database/sqlite/class-wp-sqlite-information-schema-exception.php

153 lines 4.4 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 class WP_SQLite_Information_Schema_Exception extends Exception {
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';
15 const TYPE_CONSTRAINT_DOES_NOT_EXIST = 'constraint-does-not-exist';
16 const TYPE_MULTIPLE_CONSTRAINTS_WITH_NAME = 'multiple-constraints-with-name';
17
18 /**
19 * The exception type.
20 *
21 * @var string
22 */
23 private $type;
24
25 /**
26 * The data to be passed with the exception.
27 *
28 * @var array
29 */
30 private $data;
31
32 /**
33 * Constructor.
34 *
35 * @param string $type The exception type.
36 * @param string $message The exception message.
37 * @param array $data The data to be passed with the exception.
38 * @param Throwable|null $previous The previous throwable used for the exception chaining.
39 */
40 public function __construct(
41 string $type,
42 string $message,
43 array $data = array(),
44 ?Throwable $previous = null
45 ) {
46 parent::__construct( $message, 0, $previous );
47 $this->type = $type;
48 $this->data = $data;
49 }
50
51 /**
52 * Get the type of the exception.
53 *
54 * @return string The type of the exception.
55 */
56 public function get_type(): string {
57 return $this->type;
58 }
59
60 /**
61 * Get the data associated with the exception.
62 *
63 * @return array The data associated with the exception.
64 */
65 public function get_data(): array {
66 return $this->data;
67 }
68
69 /**
70 * Create a duplicate table name exception.
71 *
72 * @param string $table_name The name of the affected table.
73 * @return self The exception instance.
74 */
75 public static function duplicate_table_name( string $table_name ): WP_SQLite_Information_Schema_Exception {
76 return new self(
77 self::TYPE_DUPLICATE_TABLE_NAME,
78 sprintf( "Table '%s' already exists.", $table_name ),
79 array( 'table_name' => $table_name )
80 );
81 }
82
83 /**
84 * Create a duplicate column name exception.
85 *
86 * @param string $column_name The name of the affected column.
87 * @return self The exception instance.
88 */
89 public static function duplicate_column_name( string $column_name ): WP_SQLite_Information_Schema_Exception {
90 return new self(
91 self::TYPE_DUPLICATE_COLUMN_NAME,
92 sprintf( "Column '%s' already exists.", $column_name ),
93 array( 'column_name' => $column_name )
94 );
95 }
96
97 /**
98 * Create a duplicate key name exception.
99 *
100 * @param string $key_name The name of the affected key.
101 * @return self The exception instance.
102 */
103 public static function duplicate_key_name( string $key_name ): WP_SQLite_Information_Schema_Exception {
104 return new self(
105 self::TYPE_DUPLICATE_KEY_NAME,
106 sprintf( "Key '%s' already exists.", $key_name ),
107 array( 'key_name' => $key_name )
108 );
109 }
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 */
117 public static function key_column_not_found( string $column_name ): WP_SQLite_Information_Schema_Exception {
118 return new self(
119 self::TYPE_KEY_COLUMN_NOT_FOUND,
120 sprintf( "Key column '%s' doesn't exist in table.", $column_name ),
121 array( 'column_name' => $column_name )
122 );
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 }
152 }
153