@@ -143,123 +143,103 @@ abstract class Context
143
143
];
144
144
145
145
/**
146
- * The mode of the MySQL server that will be used in lexing, parsing and
147
- * building the statements.
146
+ * The mode of the MySQL server that will be used in lexing, parsing and building the statements.
147
+ *
148
+ * @internal use the {@see Context::getMode()} method instead.
148
149
*
149
150
* @var int
150
151
*/
151
- public static $ MODE = 0 ;
152
-
153
- /*
154
- * Server SQL Modes
155
- * https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html
156
- */
152
+ public static $ MODE = SqlModes::NONE ;
157
153
158
- // Compatibility mode for Microsoft's SQL server.
159
- // This is the equivalent of ANSI_QUOTES.
160
- public const SQL_MODE_COMPAT_MYSQL = 2 ;
154
+ /** @deprecated Use {@see SqlModes::COMPAT_MYSQL} instead. */
155
+ public const SQL_MODE_COMPAT_MYSQL = SqlModes::COMPAT_MYSQL ;
161
156
162
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_allow_invalid_dates
163
- public const SQL_MODE_ALLOW_INVALID_DATES = 1 ;
157
+ /** @deprecated Use {@see SqlModes::ALLOW_INVALID_DATES} instead. */
158
+ public const SQL_MODE_ALLOW_INVALID_DATES = SqlModes:: ALLOW_INVALID_DATES ;
164
159
165
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_ansi_quotes
166
- public const SQL_MODE_ANSI_QUOTES = 2 ;
160
+ /** @deprecated Use {@see SqlModes::ANSI_QUOTES} instead. */
161
+ public const SQL_MODE_ANSI_QUOTES = SqlModes:: ANSI_QUOTES ;
167
162
168
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_error_for_division_by_zero
169
- public const SQL_MODE_ERROR_FOR_DIVISION_BY_ZERO = 4 ;
163
+ /** @deprecated Use {@see SqlModes::ERROR_FOR_DIVISION_BY_ZERO} instead. */
164
+ public const SQL_MODE_ERROR_FOR_DIVISION_BY_ZERO = SqlModes:: ERROR_FOR_DIVISION_BY_ZERO ;
170
165
171
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_high_not_precedence
172
- public const SQL_MODE_HIGH_NOT_PRECEDENCE = 8 ;
166
+ /** @deprecated Use {@see SqlModes::HIGH_NOT_PRECEDENCE} instead. */
167
+ public const SQL_MODE_HIGH_NOT_PRECEDENCE = SqlModes:: HIGH_NOT_PRECEDENCE ;
173
168
174
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_ignore_space
175
- public const SQL_MODE_IGNORE_SPACE = 16 ;
169
+ /** @deprecated Use {@see SqlModes::IGNORE_SPACE} instead. */
170
+ public const SQL_MODE_IGNORE_SPACE = SqlModes:: IGNORE_SPACE ;
176
171
177
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_auto_create_user
178
- public const SQL_MODE_NO_AUTO_CREATE_USER = 32 ;
172
+ /** @deprecated Use {@see SqlModes::NO_AUTO_CREATE_USER} instead. */
173
+ public const SQL_MODE_NO_AUTO_CREATE_USER = SqlModes:: NO_AUTO_CREATE_USER ;
179
174
180
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_auto_value_on_zero
181
- public const SQL_MODE_NO_AUTO_VALUE_ON_ZERO = 64 ;
175
+ /** @deprecated Use {@see SqlModes::NO_AUTO_VALUE_ON_ZERO} instead. */
176
+ public const SQL_MODE_NO_AUTO_VALUE_ON_ZERO = SqlModes:: NO_AUTO_VALUE_ON_ZERO ;
182
177
183
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_backslash_escapes
184
- public const SQL_MODE_NO_BACKSLASH_ESCAPES = 128 ;
178
+ /** @deprecated Use {@see SqlModes::NO_BACKSLASH_ESCAPES} instead. */
179
+ public const SQL_MODE_NO_BACKSLASH_ESCAPES = SqlModes:: NO_BACKSLASH_ESCAPES ;
185
180
186
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_dir_in_create
187
- public const SQL_MODE_NO_DIR_IN_CREATE = 256 ;
181
+ /** @deprecated Use {@see SqlModes::NO_DIR_IN_CREATE} instead. */
182
+ public const SQL_MODE_NO_DIR_IN_CREATE = SqlModes:: NO_DIR_IN_CREATE ;
188
183
189
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_dir_in_create
190
- public const SQL_MODE_NO_ENGINE_SUBSTITUTION = 512 ;
184
+ /** @deprecated Use {@see SqlModes::NO_ENGINE_SUBSTITUTION} instead. */
185
+ public const SQL_MODE_NO_ENGINE_SUBSTITUTION = SqlModes:: NO_ENGINE_SUBSTITUTION ;
191
186
192
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_field_options
193
- public const SQL_MODE_NO_FIELD_OPTIONS = 1024 ;
187
+ /** @deprecated Use {@see SqlModes::NO_FIELD_OPTIONS} instead. */
188
+ public const SQL_MODE_NO_FIELD_OPTIONS = SqlModes:: NO_FIELD_OPTIONS ;
194
189
195
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_key_options
196
- public const SQL_MODE_NO_KEY_OPTIONS = 2048 ;
190
+ /** @deprecated Use {@see SqlModes::NO_KEY_OPTIONS} instead. */
191
+ public const SQL_MODE_NO_KEY_OPTIONS = SqlModes:: NO_KEY_OPTIONS ;
197
192
198
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_table_options
199
- public const SQL_MODE_NO_TABLE_OPTIONS = 4096 ;
193
+ /** @deprecated Use {@see SqlModes::NO_TABLE_OPTIONS} instead. */
194
+ public const SQL_MODE_NO_TABLE_OPTIONS = SqlModes:: NO_TABLE_OPTIONS ;
200
195
201
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_unsigned_subtraction
202
- public const SQL_MODE_NO_UNSIGNED_SUBTRACTION = 8192 ;
196
+ /** @deprecated Use {@see SqlModes::NO_UNSIGNED_SUBTRACTION} instead. */
197
+ public const SQL_MODE_NO_UNSIGNED_SUBTRACTION = SqlModes:: NO_UNSIGNED_SUBTRACTION ;
203
198
204
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_zero_date
205
- public const SQL_MODE_NO_ZERO_DATE = 16384 ;
199
+ /** @deprecated Use {@see SqlModes::NO_ZERO_DATE} instead. */
200
+ public const SQL_MODE_NO_ZERO_DATE = SqlModes:: NO_ZERO_DATE ;
206
201
207
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_no_zero_in_date
208
- public const SQL_MODE_NO_ZERO_IN_DATE = 32768 ;
202
+ /** @deprecated Use {@see SqlModes::NO_ZERO_IN_DATE} instead. */
203
+ public const SQL_MODE_NO_ZERO_IN_DATE = SqlModes:: NO_ZERO_IN_DATE ;
209
204
210
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_only_full_group_by
211
- public const SQL_MODE_ONLY_FULL_GROUP_BY = 65536 ;
205
+ /** @deprecated Use {@see SqlModes::ONLY_FULL_GROUP_BY} instead. */
206
+ public const SQL_MODE_ONLY_FULL_GROUP_BY = SqlModes:: ONLY_FULL_GROUP_BY ;
212
207
213
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_pipes_as_concat
214
- public const SQL_MODE_PIPES_AS_CONCAT = 131072 ;
208
+ /** @deprecated Use {@see SqlModes::PIPES_AS_CONCAT} instead. */
209
+ public const SQL_MODE_PIPES_AS_CONCAT = SqlModes:: PIPES_AS_CONCAT ;
215
210
216
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_real_as_float
217
- public const SQL_MODE_REAL_AS_FLOAT = 262144 ;
211
+ /** @deprecated Use {@see SqlModes::REAL_AS_FLOAT} instead. */
212
+ public const SQL_MODE_REAL_AS_FLOAT = SqlModes:: REAL_AS_FLOAT ;
218
213
219
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_strict_all_tables
220
- public const SQL_MODE_STRICT_ALL_TABLES = 524288 ;
214
+ /** @deprecated Use {@see SqlModes::STRICT_ALL_TABLES} instead. */
215
+ public const SQL_MODE_STRICT_ALL_TABLES = SqlModes:: STRICT_ALL_TABLES ;
221
216
222
- // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_strict_trans_tables
223
- public const SQL_MODE_STRICT_TRANS_TABLES = 1048576 ;
217
+ /** @deprecated Use {@see SqlModes::STRICT_TRANS_TABLES} instead. */
218
+ public const SQL_MODE_STRICT_TRANS_TABLES = SqlModes:: STRICT_TRANS_TABLES ;
224
219
225
- // Custom modes.
226
-
227
- // The table and column names and any other field that must be escaped will
228
- // not be.
229
- // Reserved keywords are being escaped regardless this mode is used or not.
230
- public const SQL_MODE_NO_ENCLOSING_QUOTES = 1073741824 ;
231
-
232
- /*
233
- * Combination SQL Modes
234
- * https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sql-mode-combo
235
- */
220
+ /** @deprecated Use {@see SqlModes::NO_ENCLOSING_QUOTES} instead. */
221
+ public const SQL_MODE_NO_ENCLOSING_QUOTES = SqlModes::NO_ENCLOSING_QUOTES ;
236
222
237
- // REAL_AS_FLOAT, PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE
238
- public const SQL_MODE_ANSI = 393234 ;
223
+ /** @deprecated Use {@see SqlModes::ANSI} instead. */
224
+ public const SQL_MODE_ANSI = SqlModes:: ANSI ;
239
225
240
- // PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,
241
- // NO_TABLE_OPTIONS, NO_FIELD_OPTIONS,
242
- public const SQL_MODE_DB2 = 138258 ;
226
+ /** @deprecated Use {@see SqlModes::DB2} instead. */
227
+ public const SQL_MODE_DB2 = SqlModes::DB2 ;
243
228
244
- // PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,
245
- // NO_TABLE_OPTIONS, NO_FIELD_OPTIONS, NO_AUTO_CREATE_USER
246
- public const SQL_MODE_MAXDB = 138290 ;
229
+ /** @deprecated Use {@see SqlModes::MAXDB} instead. */
230
+ public const SQL_MODE_MAXDB = SqlModes::MAXDB ;
247
231
248
- // PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,
249
- // NO_TABLE_OPTIONS, NO_FIELD_OPTIONS
250
- public const SQL_MODE_MSSQL = 138258 ;
232
+ /** @deprecated Use {@see SqlModes::MSSQL} instead. */
233
+ public const SQL_MODE_MSSQL = SqlModes::MSSQL ;
251
234
252
- // PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,
253
- // NO_TABLE_OPTIONS, NO_FIELD_OPTIONS, NO_AUTO_CREATE_USER
254
- public const SQL_MODE_ORACLE = 138290 ;
235
+ /** @deprecated Use {@see SqlModes::ORACLE} instead. */
236
+ public const SQL_MODE_ORACLE = SqlModes::ORACLE ;
255
237
256
- // PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,
257
- // NO_TABLE_OPTIONS, NO_FIELD_OPTIONS
258
- public const SQL_MODE_POSTGRESQL = 138258 ;
238
+ /** @deprecated Use {@see SqlModes::POSTGRESQL} instead. */
239
+ public const SQL_MODE_POSTGRESQL = SqlModes::POSTGRESQL ;
259
240
260
- // STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE,
261
- // ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER
262
- public const SQL_MODE_TRADITIONAL = 1622052 ;
241
+ /** @deprecated Use {@see SqlModes::TRADITIONAL} instead. */
242
+ public const SQL_MODE_TRADITIONAL = SqlModes::TRADITIONAL ;
263
243
264
244
// -------------------------------------------------------------------------
265
245
// Keyword.
@@ -572,17 +552,25 @@ public static function loadClosest($context = '')
572
552
*/
573
553
public static function setMode ($ mode = '' )
574
554
{
575
- static ::$ MODE = 0 ;
555
+ static ::$ MODE = SqlModes:: NONE ;
576
556
if (empty ($ mode )) {
577
557
return ;
578
558
}
579
559
580
560
$ mode = explode (', ' , $ mode );
581
561
foreach ($ mode as $ m ) {
582
- static ::$ MODE |= constant (' static::SQL_MODE_ ' . $ m );
562
+ static ::$ MODE |= constant (SqlModes::class . ' :: ' . $ m );
583
563
}
584
564
}
585
565
566
+ /**
567
+ * Gets the SQL mode.
568
+ */
569
+ public static function getMode (): int
570
+ {
571
+ return static ::$ MODE ;
572
+ }
573
+
586
574
/**
587
575
* Escapes the symbol by adding surrounding backticks.
588
576
*
@@ -601,11 +589,11 @@ public static function escape($str, $quote = '`')
601
589
return $ str ;
602
590
}
603
591
604
- if ((static ::$ MODE & self :: SQL_MODE_NO_ENCLOSING_QUOTES ) && (! static ::isKeyword ($ str , true ))) {
592
+ if ((static ::$ MODE & SqlModes:: NO_ENCLOSING_QUOTES ) && (! static ::isKeyword ($ str , true ))) {
605
593
return $ str ;
606
594
}
607
595
608
- if (static ::$ MODE & self :: SQL_MODE_ANSI_QUOTES ) {
596
+ if (static ::$ MODE & SqlModes:: ANSI_QUOTES ) {
609
597
$ quote = '" ' ;
610
598
}
611
599
@@ -619,13 +607,13 @@ public static function escape($str, $quote = '`')
619
607
*/
620
608
public static function getIdentifierQuote ()
621
609
{
622
- return self ::hasMode (self :: SQL_MODE_ANSI_QUOTES ) ? '" ' : '` ' ;
610
+ return self ::hasMode (SqlModes:: ANSI_QUOTES ) ? '" ' : '` ' ;
623
611
}
624
612
625
613
/**
626
614
* Function verifies that given SQL Mode constant is currently set
627
615
*
628
- * @param int $flag for example Context::SQL_MODE_ANSI_QUOTES
616
+ * @param int $flag for example {@see SqlModes::ANSI_QUOTES}
629
617
*
630
618
* @return bool false on empty param, true/false on given constant/int value
631
619
*/
0 commit comments