diff options
author | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-06-26 20:24:19 +0000 |
---|---|---|
committer | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-06-26 20:24:19 +0000 |
commit | 2598d31ef86499a0a3408203d26cbf7e70ef3a86 (patch) | |
tree | 7f605ad0c3b64d63962859da80393ce31c987857 | |
parent | 69a9f5f7e67fada32fa32de9fb5e3315aeb17c30 (diff) | |
download | brdo-2598d31ef86499a0a3408203d26cbf7e70ef3a86.tar.gz brdo-2598d31ef86499a0a3408203d26cbf7e70ef3a86.tar.bz2 |
#150210 by bjaspan and Frando: explicit table names for create table statements and fixing a schema referencing bug
-rw-r--r-- | includes/common.inc | 4 | ||||
-rw-r--r-- | includes/database.inc | 8 | ||||
-rw-r--r-- | includes/database.mysql-common.inc | 14 | ||||
-rw-r--r-- | includes/database.pgsql.inc | 22 | ||||
-rw-r--r-- | modules/system/system.install | 71 |
5 files changed, 92 insertions, 27 deletions
diff --git a/includes/common.inc b/includes/common.inc index f1cb4cfc5..a8e6a7da6 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -3300,8 +3300,8 @@ function drupal_install_schema($module) { _drupal_initialize_schema($module, $schema); $ret = array(); - foreach ($schema as $table) { - db_create_table($ret, $table); + foreach ($schema as $name => $table) { + db_create_table($ret, $name, $table); } } diff --git a/includes/database.inc b/includes/database.inc index 12a529a1c..593a4f329 100644 --- a/includes/database.inc +++ b/includes/database.inc @@ -401,11 +401,13 @@ function db_escape_table($string) { * * @param $ret * Array to which query results will be added. + * @param $name + * The name of the table to create. * @param $table - * A valid and processed table schema definition array. + * A Schema API table definition array. */ -function db_create_table(&$ret, $table) { - $statements = db_create_table_sql($table); +function db_create_table(&$ret, $name, $table) { + $statements = db_create_table_sql($name, $table); foreach ($statements as $statement) { $ret[] = update_sql($statement); } diff --git a/includes/database.mysql-common.inc b/includes/database.mysql-common.inc index 99fde133e..982176640 100644 --- a/includes/database.mysql-common.inc +++ b/includes/database.mysql-common.inc @@ -49,24 +49,26 @@ function db_query($query) { } /** - * Generate SQL to create a new table from a Drupal schema definition. + * Generate SQL to create a new table from a Drupal schema definition. * + * @param $name + * The name of the table to create. * @param $table - * A valid Drupal table definition array. + * A Schema API table definition array. * @return * An array of SQL statements to create the table. */ -function db_create_table_sql($table) { +function db_create_table_sql($name, $table) { if (empty($table['mysql_suffix'])) { $table['mysql_suffix'] = "/*!40100 DEFAULT CHARACTER SET UTF8 */"; } - $sql = "CREATE TABLE {". $table['name'] ."} (\n"; + $sql = "CREATE TABLE {". $name ."} (\n"; // Add the SQL statement for each field. - foreach ($table['fields'] as $name => $field) { - $sql .= _db_create_field_sql($name, _db_process_field($field)) .", \n"; + foreach ($table['fields'] as $field_name => $field) { + $sql .= _db_create_field_sql($field_name, _db_process_field($field)) .", \n"; } // Process keys & indexes. diff --git a/includes/database.pgsql.inc b/includes/database.pgsql.inc index 399a72178..b29983c48 100644 --- a/includes/database.pgsql.inc +++ b/includes/database.pgsql.inc @@ -513,17 +513,19 @@ function db_type_map() { } /** - * Generate SQL to create a new table from a Drupal schema definition. + * Generate SQL to create a new table from a Drupal schema definition. * + * @param $name + * The name of the table to create. * @param $table - * A valid Drupal table definition array. + * A Schema API table definition array. * @return * An array of SQL statements to create the table. */ -function db_create_table_sql($table) { +function db_create_table_sql($name, $table) { $sql_fields = array(); - foreach ($table['fields'] as $name => $field) { - $sql_fields[] = _db_create_field_sql($name, _db_process_field($field)); + foreach ($table['fields'] as $field_name => $field) { + $sql_fields[] = _db_create_field_sql($field_name, _db_process_field($field)); } $sql_keys = array(); @@ -531,12 +533,12 @@ function db_create_table_sql($table) { $sql_keys[] = 'PRIMARY KEY ('. implode(', ', $table['primary key']) .')'; } if (isset($table['unique keys']) && is_array($table['unique keys'])) { - foreach ($table['unique keys'] as $keyname => $key) { - $sql_keys[] = 'CONSTRAINT {'. $table['name'] .'}_'. $keyname .'_key UNIQUE ('. implode(', ', $key) .')'; + foreach ($table['unique keys'] as $key_name => $key) { + $sql_keys[] = 'CONSTRAINT {'. $name .'}_'. $key_name .'_key UNIQUE ('. implode(', ', $key) .')'; } } - $sql = "CREATE TABLE {". $table['name'] ."} (\n\t"; + $sql = "CREATE TABLE {". $name ."} (\n\t"; $sql .= implode(",\n\t", $sql_fields); if (count($sql_keys) > 0) { $sql .= ",\n\t"; @@ -546,8 +548,8 @@ function db_create_table_sql($table) { $statements[] = $sql; if (isset($table['indexes']) && is_array($table['indexes'])) { - foreach ($table['indexes'] as $keyname => $key) { - $statements[] = _db_create_index_sql($table['name'], $keyname, $key); + foreach ($table['indexes'] as $key_name => $key) { + $statements[] = _db_create_index_sql($name, $key_name, $key); } } diff --git a/modules/system/system.install b/modules/system/system.install index 4f9d4bd7b..0f4756174 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -3288,12 +3288,71 @@ function system_update_6019() { function system_update_6020() { $ret = array(); - $schema['menu_router'] = drupal_get_schema_unprocessed('system', 'menu_router'); - $schema['menu_links'] = drupal_get_schema_unprocessed('system', 'menu_links'); - _drupal_initialize_schema('system', $schema); - $ret = array(); - foreach ($schema as $table) { - db_create_table($ret, $table); + $schema['menu_router'] = array( + 'fields' => array( + 'path' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'load_functions' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'to_arg_functions' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'access_callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'access_arguments' => array('type' => 'text', 'not null' => FALSE), + 'page_callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'page_arguments' => array('type' => 'text', 'not null' => FALSE), + 'fit' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'number_parts' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), + 'tab_parent' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'tab_root' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'title_callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'title_arguments' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'type' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'block_callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'description' => array('type' => 'text', 'not null' => TRUE), + 'position' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'file' => array('type' => 'text', 'size' => 'medium') + ), + 'indexes' => array( + 'fit' => array('fit'), + 'tab_parent' => array('tab_parent') + ), + 'primary key' => array('path'), + ); + + $schema['menu_links'] = array( + 'fields' => array( + 'menu_name' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''), + 'mlid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), + 'plid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'link_path' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'router_path' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'hidden' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), + 'external' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), + 'has_children' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), + 'expanded' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), + 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), + 'depth' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'small'), + 'p1' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'p2' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'p3' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'p4' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'p5' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'p6' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), + 'module' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'system'), + 'link_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), + 'options' => array('type' => 'text', 'not null' => FALSE) + ), + 'indexes' => array( + 'expanded_children' => array('expanded', 'has_children'), + 'menu_name_path' => array('menu_name', 'link_path'), + 'plid'=> array('plid'), + 'parents' => array('p1', 'p2', 'p3', 'p4', 'p5'), + 'router_path' => array('router_path'), + ), + 'primary key' => array('mlid'), + ); + + foreach ($schema as $name => $table) { + db_create_table($ret, $name, $table); } return $ret; } |