Révision b4adf10d
Ajouté par Assos Assos il y a plus de 9 ans
drupal7/includes/database/mysql/schema.inc | ||
---|---|---|
40 | 40 |
} |
41 | 41 |
else { |
42 | 42 |
$db_info = Database::getConnectionInfo(); |
43 |
$info['database'] = $db_info['default']['database'];
|
|
43 |
$info['database'] = $db_info[$this->connection->getTarget()]['database'];
|
|
44 | 44 |
$info['table'] = $table; |
45 | 45 |
} |
46 | 46 |
return $info; |
... | ... | |
301 | 301 |
|
302 | 302 |
public function renameTable($table, $new_name) { |
303 | 303 |
if (!$this->tableExists($table)) { |
304 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot rename %table to %table_new: table %table doesn't exist.", array('%table' => $table, '%table_new' => $new_name)));
|
|
304 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot rename @table to @table_new: table @table doesn't exist.", array('@table' => $table, '@table_new' => $new_name)));
|
|
305 | 305 |
} |
306 | 306 |
if ($this->tableExists($new_name)) { |
307 |
throw new DatabaseSchemaObjectExistsException(t("Cannot rename %table to %table_new: table %table_new already exists.", array('%table' => $table, '%table_new' => $new_name)));
|
|
307 |
throw new DatabaseSchemaObjectExistsException(t("Cannot rename @table to @table_new: table @table_new already exists.", array('@table' => $table, '@table_new' => $new_name)));
|
|
308 | 308 |
} |
309 | 309 |
|
310 | 310 |
$info = $this->getPrefixInfo($new_name); |
... | ... | |
322 | 322 |
|
323 | 323 |
public function addField($table, $field, $spec, $keys_new = array()) { |
324 | 324 |
if (!$this->tableExists($table)) { |
325 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add field %table.%field: table doesn't exist.", array('%field' => $field, '%table' => $table)));
|
|
325 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add field @table.@field: table doesn't exist.", array('@field' => $field, '@table' => $table)));
|
|
326 | 326 |
} |
327 | 327 |
if ($this->fieldExists($table, $field)) { |
328 |
throw new DatabaseSchemaObjectExistsException(t("Cannot add field %table.%field: field already exists.", array('%field' => $field, '%table' => $table)));
|
|
328 |
throw new DatabaseSchemaObjectExistsException(t("Cannot add field @table.@field: field already exists.", array('@field' => $field, '@table' => $table)));
|
|
329 | 329 |
} |
330 | 330 |
|
331 | 331 |
$fixnull = FALSE; |
... | ... | |
361 | 361 |
|
362 | 362 |
public function fieldSetDefault($table, $field, $default) { |
363 | 363 |
if (!$this->fieldExists($table, $field)) { |
364 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot set default value of field %table.%field: field doesn't exist.", array('%table' => $table, '%field' => $field)));
|
|
364 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot set default value of field @table.@field: field doesn't exist.", array('@table' => $table, '@field' => $field)));
|
|
365 | 365 |
} |
366 | 366 |
|
367 | 367 |
if (!isset($default)) { |
... | ... | |
376 | 376 |
|
377 | 377 |
public function fieldSetNoDefault($table, $field) { |
378 | 378 |
if (!$this->fieldExists($table, $field)) { |
379 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot remove default value of field %table.%field: field doesn't exist.", array('%table' => $table, '%field' => $field)));
|
|
379 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot remove default value of field @table.@field: field doesn't exist.", array('@table' => $table, '@field' => $field)));
|
|
380 | 380 |
} |
381 | 381 |
|
382 | 382 |
$this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` DROP DEFAULT'); |
... | ... | |
391 | 391 |
|
392 | 392 |
public function addPrimaryKey($table, $fields) { |
393 | 393 |
if (!$this->tableExists($table)) { |
394 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add primary key to table %table: table doesn't exist.", array('%table' => $table)));
|
|
394 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add primary key to table @table: table doesn't exist.", array('@table' => $table)));
|
|
395 | 395 |
} |
396 | 396 |
if ($this->indexExists($table, 'PRIMARY')) { |
397 |
throw new DatabaseSchemaObjectExistsException(t("Cannot add primary key to table %table: primary key already exists.", array('%table' => $table)));
|
|
397 |
throw new DatabaseSchemaObjectExistsException(t("Cannot add primary key to table @table: primary key already exists.", array('@table' => $table)));
|
|
398 | 398 |
} |
399 | 399 |
|
400 | 400 |
$this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . $this->createKeySql($fields) . ')'); |
... | ... | |
411 | 411 |
|
412 | 412 |
public function addUniqueKey($table, $name, $fields) { |
413 | 413 |
if (!$this->tableExists($table)) { |
414 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add unique key %name to table %table: table doesn't exist.", array('%table' => $table, '%name' => $name)));
|
|
414 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add unique key @name to table @table: table doesn't exist.", array('@table' => $table, '@name' => $name)));
|
|
415 | 415 |
} |
416 | 416 |
if ($this->indexExists($table, $name)) { |
417 |
throw new DatabaseSchemaObjectExistsException(t("Cannot add unique key %name to table %table: unique key already exists.", array('%table' => $table, '%name' => $name)));
|
|
417 |
throw new DatabaseSchemaObjectExistsException(t("Cannot add unique key @name to table @table: unique key already exists.", array('@table' => $table, '@name' => $name)));
|
|
418 | 418 |
} |
419 | 419 |
|
420 | 420 |
$this->connection->query('ALTER TABLE {' . $table . '} ADD UNIQUE KEY `' . $name . '` (' . $this->createKeySql($fields) . ')'); |
... | ... | |
431 | 431 |
|
432 | 432 |
public function addIndex($table, $name, $fields) { |
433 | 433 |
if (!$this->tableExists($table)) { |
434 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add index %name to table %table: table doesn't exist.", array('%table' => $table, '%name' => $name)));
|
|
434 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add index @name to table @table: table doesn't exist.", array('@table' => $table, '@name' => $name)));
|
|
435 | 435 |
} |
436 | 436 |
if ($this->indexExists($table, $name)) { |
437 |
throw new DatabaseSchemaObjectExistsException(t("Cannot add index %name to table %table: index already exists.", array('%table' => $table, '%name' => $name)));
|
|
437 |
throw new DatabaseSchemaObjectExistsException(t("Cannot add index @name to table @table: index already exists.", array('@table' => $table, '@name' => $name)));
|
|
438 | 438 |
} |
439 | 439 |
|
440 | 440 |
$this->connection->query('ALTER TABLE {' . $table . '} ADD INDEX `' . $name . '` (' . $this->createKeySql($fields) . ')'); |
... | ... | |
451 | 451 |
|
452 | 452 |
public function changeField($table, $field, $field_new, $spec, $keys_new = array()) { |
453 | 453 |
if (!$this->fieldExists($table, $field)) { |
454 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot change the definition of field %table.%name: field doesn't exist.", array('%table' => $table, '%name' => $field)));
|
|
454 |
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot change the definition of field @table.@name: field doesn't exist.", array('@table' => $table, '@name' => $field)));
|
|
455 | 455 |
} |
456 | 456 |
if (($field != $field_new) && $this->fieldExists($table, $field_new)) { |
457 |
throw new DatabaseSchemaObjectExistsException(t("Cannot rename field %table.%name to %name_new: target field already exists.", array('%table' => $table, '%name' => $field, '%name_new' => $field_new)));
|
|
457 |
throw new DatabaseSchemaObjectExistsException(t("Cannot rename field @table.@name to @name_new: target field already exists.", array('@table' => $table, '@name' => $field, '@name_new' => $field_new)));
|
|
458 | 458 |
} |
459 | 459 |
|
460 | 460 |
$sql = 'ALTER TABLE {' . $table . '} CHANGE `' . $field . '` ' . $this->createFieldSql($field_new, $this->processField($spec)); |
Formats disponibles : Unified diff
Udpate to 7.33