Projet

Général

Profil

Révision 01dfd3b5

Ajouté par Assos Assos il y a plus de 3 ans

Udpate to 7.77

Voir les différences:

drupal7/includes/database/mysql/database.inc
5 5
 * Database interface code for MySQL database servers.
6 6
 */
7 7

  
8
/**
9
 * The default character for quoting identifiers in MySQL.
10
 */
11
define('MYSQL_IDENTIFIER_QUOTE_CHARACTER_DEFAULT', '`');
12

  
8 13
/**
9 14
 * @addtogroup database
10 15
 * @{
......
19 24
   */
20 25
  protected $needsCleanup = FALSE;
21 26

  
27
  /**
28
   * The list of MySQL reserved key words.
29
   *
30
   * @link https://dev.mysql.com/doc/refman/8.0/en/keywords.html
31
   */
32
  private $reservedKeyWords = array(
33
    'accessible',
34
    'add',
35
    'admin',
36
    'all',
37
    'alter',
38
    'analyze',
39
    'and',
40
    'as',
41
    'asc',
42
    'asensitive',
43
    'before',
44
    'between',
45
    'bigint',
46
    'binary',
47
    'blob',
48
    'both',
49
    'by',
50
    'call',
51
    'cascade',
52
    'case',
53
    'change',
54
    'char',
55
    'character',
56
    'check',
57
    'collate',
58
    'column',
59
    'condition',
60
    'constraint',
61
    'continue',
62
    'convert',
63
    'create',
64
    'cross',
65
    'cube',
66
    'cume_dist',
67
    'current_date',
68
    'current_time',
69
    'current_timestamp',
70
    'current_user',
71
    'cursor',
72
    'database',
73
    'databases',
74
    'day_hour',
75
    'day_microsecond',
76
    'day_minute',
77
    'day_second',
78
    'dec',
79
    'decimal',
80
    'declare',
81
    'default',
82
    'delayed',
83
    'delete',
84
    'dense_rank',
85
    'desc',
86
    'describe',
87
    'deterministic',
88
    'distinct',
89
    'distinctrow',
90
    'div',
91
    'double',
92
    'drop',
93
    'dual',
94
    'each',
95
    'else',
96
    'elseif',
97
    'empty',
98
    'enclosed',
99
    'escaped',
100
    'except',
101
    'exists',
102
    'exit',
103
    'explain',
104
    'false',
105
    'fetch',
106
    'first_value',
107
    'float',
108
    'float4',
109
    'float8',
110
    'for',
111
    'force',
112
    'foreign',
113
    'from',
114
    'fulltext',
115
    'function',
116
    'generated',
117
    'get',
118
    'grant',
119
    'group',
120
    'grouping',
121
    'groups',
122
    'having',
123
    'high_priority',
124
    'hour_microsecond',
125
    'hour_minute',
126
    'hour_second',
127
    'if',
128
    'ignore',
129
    'in',
130
    'index',
131
    'infile',
132
    'inner',
133
    'inout',
134
    'insensitive',
135
    'insert',
136
    'int',
137
    'int1',
138
    'int2',
139
    'int3',
140
    'int4',
141
    'int8',
142
    'integer',
143
    'interval',
144
    'into',
145
    'io_after_gtids',
146
    'io_before_gtids',
147
    'is',
148
    'iterate',
149
    'join',
150
    'json_table',
151
    'key',
152
    'keys',
153
    'kill',
154
    'lag',
155
    'last_value',
156
    'lead',
157
    'leading',
158
    'leave',
159
    'left',
160
    'like',
161
    'limit',
162
    'linear',
163
    'lines',
164
    'load',
165
    'localtime',
166
    'localtimestamp',
167
    'lock',
168
    'long',
169
    'longblob',
170
    'longtext',
171
    'loop',
172
    'low_priority',
173
    'master_bind',
174
    'master_ssl_verify_server_cert',
175
    'match',
176
    'maxvalue',
177
    'mediumblob',
178
    'mediumint',
179
    'mediumtext',
180
    'middleint',
181
    'minute_microsecond',
182
    'minute_second',
183
    'mod',
184
    'modifies',
185
    'natural',
186
    'not',
187
    'no_write_to_binlog',
188
    'nth_value',
189
    'ntile',
190
    'null',
191
    'numeric',
192
    'of',
193
    'on',
194
    'optimize',
195
    'optimizer_costs',
196
    'option',
197
    'optionally',
198
    'or',
199
    'order',
200
    'out',
201
    'outer',
202
    'outfile',
203
    'over',
204
    'partition',
205
    'percent_rank',
206
    'persist',
207
    'persist_only',
208
    'precision',
209
    'primary',
210
    'procedure',
211
    'purge',
212
    'range',
213
    'rank',
214
    'read',
215
    'reads',
216
    'read_write',
217
    'real',
218
    'recursive',
219
    'references',
220
    'regexp',
221
    'release',
222
    'rename',
223
    'repeat',
224
    'replace',
225
    'require',
226
    'resignal',
227
    'restrict',
228
    'return',
229
    'revoke',
230
    'right',
231
    'rlike',
232
    'row',
233
    'rows',
234
    'row_number',
235
    'schema',
236
    'schemas',
237
    'second_microsecond',
238
    'select',
239
    'sensitive',
240
    'separator',
241
    'set',
242
    'show',
243
    'signal',
244
    'smallint',
245
    'spatial',
246
    'specific',
247
    'sql',
248
    'sqlexception',
249
    'sqlstate',
250
    'sqlwarning',
251
    'sql_big_result',
252
    'sql_calc_found_rows',
253
    'sql_small_result',
254
    'ssl',
255
    'starting',
256
    'stored',
257
    'straight_join',
258
    'system',
259
    'table',
260
    'terminated',
261
    'then',
262
    'tinyblob',
263
    'tinyint',
264
    'tinytext',
265
    'to',
266
    'trailing',
267
    'trigger',
268
    'true',
269
    'undo',
270
    'union',
271
    'unique',
272
    'unlock',
273
    'unsigned',
274
    'update',
275
    'usage',
276
    'use',
277
    'using',
278
    'utc_date',
279
    'utc_time',
280
    'utc_timestamp',
281
    'values',
282
    'varbinary',
283
    'varchar',
284
    'varcharacter',
285
    'varying',
286
    'virtual',
287
    'when',
288
    'where',
289
    'while',
290
    'window',
291
    'with',
292
    'write',
293
    'xor',
294
    'year_month',
295
    'zerofill',
296
  );
297

  
22 298
  public function __construct(array $connection_options = array()) {
23 299
    // This driver defaults to transaction support, except if explicitly passed FALSE.
24 300
    $this->transactionSupport = !isset($connection_options['transactions']) || ($connection_options['transactions'] !== FALSE);
......
86 362
    $connection_options += array(
87 363
      'init_commands' => array(),
88 364
    );
365

  
366
    $sql_mode = 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO';
367
    // NO_AUTO_CREATE_USER was removed in MySQL 8.0.11
368
    // https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-11.html#mysqld-8-0-11-deprecation-removal
369
    if (version_compare($this->getAttribute(PDO::ATTR_SERVER_VERSION), '8.0.11', '<')) {
370
      $sql_mode .= ',NO_AUTO_CREATE_USER';
371
    }
89 372
    $connection_options['init_commands'] += array(
90
      'sql_mode' => "SET sql_mode = 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER'",
373
      'sql_mode' => "SET sql_mode = '$sql_mode'",
91 374
    );
375

  
92 376
    // Execute initial commands.
93 377
    foreach ($connection_options['init_commands'] as $sql) {
94 378
      $this->exec($sql);
95 379
    }
96 380
  }
97 381

  
382
  /**
383
   * {@inheritdoc}}
384
   */
385
  protected function setPrefix($prefix) {
386
    parent::setPrefix($prefix);
387
    // Successive versions of MySQL have become increasingly strict about the
388
    // use of reserved keywords as table names. Drupal 7 uses at least one such
389
    // table (system). Therefore we surround all table names with quotes.
390
    $quote_char = variable_get('mysql_identifier_quote_character', MYSQL_IDENTIFIER_QUOTE_CHARACTER_DEFAULT);
391
    foreach ($this->prefixSearch as $i => $prefixSearch) {
392
      if (substr($prefixSearch, 0, 1) === '{') {
393
        // If the prefix already contains one or more quotes remove them.
394
        // This can happen when - for example - DrupalUnitTestCase sets up a
395
        // "temporary prefixed database". Also if there's a dot in the prefix,
396
        // wrap it in quotes to cater for schema names in prefixes.
397
        $search = array($quote_char, '.');
398
        $replace = array('', $quote_char . '.' . $quote_char);
399
        $this->prefixReplace[$i] = $quote_char . str_replace($search, $replace, $this->prefixReplace[$i]);
400
      }
401
      if (substr($prefixSearch, -1) === '}') {
402
        $this->prefixReplace[$i] .= $quote_char;
403
      }
404
    }
405
  }
406

  
407
  /**
408
   * {@inheritdoc}
409
   */
410
  public function escapeField($field) {
411
    $field = parent::escapeField($field);
412
    return $this->quoteIdentifier($field);
413
  }
414

  
415
  public function escapeFields(array $fields) {
416
    foreach ($fields as &$field) {
417
      $field = $this->escapeField($field);
418
    }
419
    return $fields;
420
  }
421

  
422
  /**
423
   * {@inheritdoc}
424
   */
425
  public function escapeAlias($field) {
426
    $field = parent::escapeAlias($field);
427
    return $this->quoteIdentifier($field);
428
  }
429

  
430
  /**
431
   * Quotes an identifier if it matches a MySQL reserved keyword.
432
   *
433
   * @param string $identifier
434
   *   The field to check.
435
   *
436
   * @return string
437
   *   The identifier, quoted if it matches a MySQL reserved keyword.
438
   */
439
  private function quoteIdentifier($identifier) {
440
    // Quote identifiers so that MySQL reserved words like 'function' can be
441
    // used as column names. Sometimes the 'table.column_name' format is passed
442
    // in. For example, menu_load_links() adds a condition on "ml.menu_name".
443
    if (strpos($identifier, '.') !== FALSE) {
444
      list($table, $identifier) = explode('.', $identifier, 2);
445
    }
446
    if (in_array(strtolower($identifier), $this->reservedKeyWords, TRUE)) {
447
      // Quote the string for MySQL reserved keywords.
448
      $quote_char = variable_get('mysql_identifier_quote_character', MYSQL_IDENTIFIER_QUOTE_CHARACTER_DEFAULT);
449
      $identifier = $quote_char . $identifier . $quote_char;
450
    }
451
    return isset($table) ? $table . '.' . $identifier : $identifier;
452
  }
453

  
98 454
  public function __destruct() {
99 455
    if ($this->needsCleanup) {
100 456
      $this->nextIdDelete();

Formats disponibles : Unified diff