本文整理汇总了PHP中db_create_table函数的典型用法代码示例。如果您正苦于以下问题:PHP db_create_table函数的具体用法?PHP db_create_table怎么用?PHP db_create_table使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_create_table函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
parent::setUp();
module_load_install('system');
$schema = system_schema();
db_create_table('key_value_expire', $schema['key_value_expire']);
}
示例2: ensureAppTable
/**
* Ensure that the table for an app exists.
* @param $nid
* The app nid.
*/
private function ensureAppTable($nid)
{
if (!db_table_exists('app_' . $nid)) {
db_create_table('app_' . $nid, $this->getAppTableSchema($nid));
} else {
$this->pruneAppTable($nid);
}
}
示例3: initialise_JumpStart
/**
* Setup website with assumption on blank state.
*/
function initialise_JumpStart()
{
require_once 'include/database/database-basic.php';
$conn = db_connect();
// Create table for SFU
db_create_table($conn, 'users_sfu', array("username varchar(32) UNIQUE NOT NULL", "fullname text NOT NULL", "password varchar(60) NOT NULL", "sex varchar(8) NOT NULL", "interest_1 text", "interest_2 text", "interest_3 text", "PRIMARY KEY (username)"));
// Create table for UBC
db_create_table($conn, 'users_ubc', array("username varchar(32) UNIQUE NOT NULL", "fullname text NOT NULL", "password varchar(60) NOT NULL", "sex varchar(8) NOT NULL", "interest_1 text", "interest_2 text", "interest_3 text", "PRIMARY KEY (username)"));
// Users for activation
db_create_table($conn, 'users_activate', array("username varchar(32) NOT NULL", "password varchar(60) NOT NULL", "table_name varchar(32) NOT NULL", "access_code varchar(12) NOT NULL", "PRIMARY KEY (username)"));
}
示例4: setUp
protected function setUp()
{
parent::setUp();
module_load_install('system');
$schema = system_schema();
db_create_table('key_value', $schema['key_value']);
$this->container->register('database', 'Drupal\\Core\\Database\\Connection')->setFactoryClass('Drupal\\Core\\Database\\Database')->setFactoryMethod('getConnection')->addArgument('default');
$this->container->register('keyvalue.database', 'Drupal\\Core\\KeyValueStore\\KeyValueDatabaseFactory')->addArgument(new Reference('serialization.phpserialize'))->addArgument(new Reference('database'));
$this->container->register('serialization.phpserialize', 'Drupal\\Component\\Serialization\\PhpSerialize');
$this->settingsSet('keyvalue_default', 'keyvalue.database');
}
示例5: setup_create_tables
/**
* Create tables
*/
function setup_create_tables($conn = NULL)
{
if ($conn == NULL) {
$conn = db_connect();
}
db_create_table($conn, 'settings', array("vid int UNIQUE NOT NULL AUTO_INCREMENT", "type varchar(32) NOT NULL", "value varchar(64) NOT NULL", "PRIMARY KEY (vid)"));
db_create_table($conn, 'users', array("uid int UNIQUE NOT NULL AUTO_INCREMENT", "username varchar(32) NOT NULL", "email varchar(32) NOT NULL", "password varchar(32) NOT NULL", "PRIMARY KEY (uid)"));
db_create_table($conn, 'forms', array("fid int UNIQUE NOT NULL AUTO_INCREMENT", "status boolean DEFAULT '0' NOT NULL", "name varchar(32) NOT NULL", "date_created timestamp NOT NULL", "PRIMARY KEY (fid)"));
db_create_table($conn, 'forms_qid', array("fid int UNIQUE NOT NULL AUTO_INCREMENT", "qid_1 int NOT NULL", "qid_2 int", "qid_3 int", "qid_4 int", "qid_5 int", "qid_6 int", "qid_7 int", "qid_8 int", "PRIMARY KEY (fid)"));
db_create_table($conn, 'forms_questions', array("qid int UNIQUE NOT NULL AUTO_INCREMENT", "status boolean DEFAULT '0' NOT NULL", "type varchar(8) NOT NULL", "value varchar(256) NOT NULL", "PRIMARY KEY (qid)"));
}
示例6: setUp
protected function setUp()
{
parent::setUp();
// Install system tables to test the key/value storage without installing a
// full Drupal environment.
module_load_install('system');
$schema = system_schema();
db_create_table('semaphore', $schema['semaphore']);
db_create_table('key_value_expire', $schema['key_value_expire']);
// Create several objects for testing.
for ($i = 0; $i <= 3; $i++) {
$this->objects[$i] = $this->randomObject();
}
}
示例7: testInvalidMigration
/**
* Tests that updates from schema versions prior to 8000 are prevented.
*/
function testInvalidMigration()
{
// Mock a D7 system table so that the schema value of the system module
// can be retrieved.
db_create_table('system', $this->getSystemSchema());
// Assert that the table exists.
$this->assertTrue(db_table_exists('system'), 'The table exists.');
// Insert a value for the system module.
db_insert('system')->fields(array('name' => 'system', 'schema_version' => 7000))->execute();
$system_schema = db_query('SELECT schema_version FROM {system} WHERE name = :system', array(':system' => 'system'))->fetchField();
$this->drupalGet($this->update_url, array('external' => TRUE));
$text = 'Your system schema version is ' . $system_schema . '. Updating directly from a schema version prior to 8000 is not supported. You must <a href="https://drupal.org/node/2179269">migrate your site to Drupal 8</a> first.';
$this->assertRaw($text, 'Updates from schema versions prior to 8000 are prevented.');
}
示例8: createVolume
function createVolume($volume = '')
{
global $XPFS_DEFAULT_VOLUME;
if ($volume == '') {
$volume = $XPFS_DEFAULT_VOLUME;
}
if (db_count('xpfs_volumes', '`name`="' . addslashes($volume) . '"') > 0) {
return false;
}
$name = $volume;
$volume = 'xpfs_volume_' . $volume;
if (!db_table_exists($volume)) {
db_create_table($volume, array('id' => 'INT NOT NULL PRIMARY KEY AUTO_INCREMENT', 'pid' => 'INT', 'name' => 'TEXT', 'data' => 'LONGBLOB', 'mtime' => 'INT DEFAULT 0', 'access' => 'INT DEFAULT 0', 'attr' => 'INT DEFAULT 0'));
db_insert('xpfs_volumes', array('name' => '"' . addslashes($name) . '"'));
db_insert($volume, array('name' => '"/"', 'pid' => 0));
return true;
}
return false;
}
示例9: manage_check_tables
function manage_check_tables()
{
db_create_table_safe('datatypes', array('id' => 'INT NOT NULL PRIMARY KEY AUTO_INCREMENT', 'name' => 'TEXT', 'class' => 'TEXT', 'refcount' => 'INT DEFAULT 0', 'settings' => 'TEXT DEFAULT ""'));
db_create_table_safe('dataset', array('id' => 'INT NOT NULL PRIMARY KEY AUTO_INCREMENT', 'name' => 'TEXT', 'refcount' => 'INT DEFAULT 0'));
db_create_table_safe('dataset_assoc', array('id' => 'INT NOT NULL PRIMARY KEY AUTO_INCREMENT', 'order' => 'INT', 'dataset' => 'INT', 'datatype' => 'INT', 'title' => 'TEXT', 'field' => 'TEXT', 'settings' => 'TEXT DEFAULT ""'));
if (!db_table_exists('settings')) {
db_create_table('settings', array('id' => 'INT NOT NULL PRIMARY KEY AUTO_INCREMENT', 'section' => 'TEXT', 'name' => 'TEXT', 'ident' => 'TEXT', 'class' => 'TEXT', 'used' => 'INT DEFAULT 0', 'settings' => 'TEXT DEFAULT ""'));
db_insert('settings', array('section' => '"Системные"', 'name' => '"Максимальная длина логина пользователя"', 'ident' => '"max_user_login_len"', 'class' => '"CSCNumber"', 'settings' => '"' . addslashes('a:1:{s:5:"value";s:2:"14";}') . '"', 'used' => '1'));
db_insert('settings', array('section' => '"Системные"', 'name' => '"Максимальная длина имени пользователя"', 'ident' => '"max_user_name_len"', 'class' => '"CSCNumber"', 'settings' => '"' . addslashes('a:1:{s:5:"value";s:2:"32";}') . '"', 'used' => '1'));
db_insert('settings', array('section' => '"Системные"', 'name' => '"Максимальная длина пароля пользователя"', 'ident' => '"max_user_passwd_len"', 'class' => '"CSCNumber"', 'settings' => '"' . addslashes('a:1:{s:5:"value";s:2:"16";}') . '"', 'used' => '1'));
db_insert('settings', array('section' => '"Системные"', 'name' => '"Количество записей на странице «Пользователи и группы»"', 'ident' => '"user_count"', 'class' => '"CSCNumber"', 'settings' => '"' . addslashes('a:1:{s:5:"value";s:2:"15";}') . '"', 'used' => '1'));
db_insert('settings', array('section' => '"Системные"', 'name' => '"Блокировать сайт"', 'ident' => '"site_lock"', 'class' => '"CSCCheckBox"', 'settings' => '"' . addslashes('a:1:{s:5:"value";b:0;}') . '"', 'used' => '1'));
db_insert('settings', array('section' => '"Системные"', 'name' => '"Стартовый каталог"', 'ident' => '"start_root"', 'class' => '"CSCText"', 'settings' => '"' . addslashes('a:1:{s:5:"value";s:1:"/";}') . '"', 'used' => '1'));
}
db_create_table_safe('storage', array('id' => 'INT NOT NULL PRIMARY KEY AUTO_INCREMENT', 'name' => 'TEXT', 'path' => 'TEXT', 'refcount' => 'INT DEFAULT 0'));
if (!db_table_exists('templates')) {
db_create_table_safe('templates', array('id' => 'INT NOT NULL PRIMARY KEY AUTO_INCREMENT', 'name' => 'TEXT', 'text' => 'LONGTEXT', 'refcount' => 'INT DEFAULT 0', 'settings' => 'TEXT DEFAULT ""'));
}
manage_template_register_default();
}
示例10: _securesite_schema
/**
* Set up password and nonce storage.
*/
function _securesite_schema()
{
global $db_url, $db_type;
$schema['securesite_passwords'] = array('module' => 'securesite', 'name' => 'securesite_passwords', 'description' => 'Stores user passwords.', 'fields' => array('name' => array('type' => 'varchar', 'length' => 60, 'not null' => TRUE, 'default' => '', 'description' => "User's {users}.name."), 'realm' => array('type' => 'text', 'description' => "User's realm."), 'pass' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => '', 'description' => "User's password (plain text).")), 'primary key' => array('name, realm'), 'indexes' => array('name' => array('name'), 'realm' => array('realm')));
$schema['securesite_nonce'] = array('module' => 'securesite', 'name' => 'securesite_nonce', 'description' => 'Stores nonce values.', 'fields' => array('nonce' => array('type' => 'text', 'not null' => TRUE, 'default' => '', 'description' => 'Nonce value.'), 'qop' => array('type' => 'text', 'description' => 'Quality of protection.'), 'nc' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => 'Number of times nonce has been used.'), 'opaque' => array('type' => 'text', 'description' => 'Opaque value.'), 'hash' => array('type' => 'text', 'description' => 'Hashed entity body to see if message was tampered with.'), 'time' => array('type' => 'int', 'description' => 'Last use timestamp.'), 'realm' => array('type' => 'text', 'description' => "Nonce realm.")), 'primary key' => array('nonce, realm'), 'indexes' => array('nonce' => array('nonce'), 'opaque' => array('opaque'), 'realm' => array('realm')));
$ret = array();
foreach ($schema as $name => $table) {
$url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url);
$database = substr($url['path'], 1);
switch ($db_type) {
case 'mysql':
case 'mysqli':
$sql = "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '%s' AND table_name = '%s'";
break;
case 'pgsql':
$sql = "SELECT COUNT(*) FROM information_schema.tables WHERE table_catalog = '%s' AND table_schema = 'public' AND table_name = '%s'";
break;
}
if (db_result(db_query($sql, $database, $name)) == 0) {
db_create_table($ret, $name, $table);
}
}
return $ret;
}
示例11: update_create_batch_table
/**
* Create the batch table.
*
* This is part of the Drupal 5.x to 6.x migration.
*/
function update_create_batch_table()
{
// If batch table exists, update is not necessary
if (db_table_exists('batch')) {
return;
}
$schema['batch'] = array('fields' => array('bid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), 'token' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE), 'timestamp' => array('type' => 'int', 'not null' => TRUE), 'batch' => array('type' => 'text', 'not null' => FALSE, 'size' => 'big')), 'primary key' => array('bid'), 'indexes' => array('token' => array('token')));
$ret = array();
db_create_table($ret, 'batch', $schema['batch']);
return $ret;
}
示例12: db_create_table
<?php
/**
* @file
* Filled installation of Drupal 7.0, for test purposes.
*
* This file was generated by the dump-database-d7.sh tool, from an
* installation of Drupal 7, filled with data using the generate-d7-content.sh
* tool. It has the following modules installed:
* - userpoints
*/
db_create_table('userpoints', array('fields' => array('pid' => array('type' => 'serial', 'not null' => TRUE), 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'points' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'max_points' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'last_update' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'tid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0)), 'primary key' => array('pid'), 'indexes' => array('last_update' => array('last_update'), 'points' => array('points')), 'unique keys' => array('uid_tid' => array('uid', 'tid')), 'module' => 'userpoints', 'name' => 'userpoints'));
db_insert('userpoints')->fields(array('pid', 'uid', 'points', 'max_points', 'last_update', 'tid'))->values(array('pid' => '1', 'uid' => '1', 'points' => '4', 'max_points' => '5', 'last_update' => '1361395354', 'tid' => '0'))->values(array('pid' => '2', 'uid' => '1', 'points' => '-1', 'max_points' => '8', 'last_update' => '1361395411', 'tid' => '2'))->values(array('pid' => '3', 'uid' => '1', 'points' => '7', 'max_points' => '7', 'last_update' => '1361395402', 'tid' => '1'))->execute();
db_create_table('userpoints_total', array('fields' => array('uid' => array('type' => 'int', 'not null' => TRUE), 'points' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'max_points' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'last_update' => array('type' => 'int', 'not null' => TRUE, 'default' => 0)), 'primary key' => array('uid'), 'indexes' => array('last_update' => array('last_update'), 'points' => array('points')), 'module' => 'userpoints', 'name' => 'userpoints_total'));
db_insert('userpoints_total')->fields(array('uid', 'points', 'max_points', 'last_update'))->values(array('uid' => '1', 'points' => '10', 'max_points' => '19', 'last_update' => '1361395411'))->execute();
db_create_table('userpoints_txn', array('fields' => array('txn_id' => array('type' => 'serial', 'not null' => TRUE), 'uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'approver_uid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'points' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'time_stamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'changed' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'status' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0), 'description' => array('type' => 'text'), 'reference' => array('type' => 'varchar', 'length' => 128), 'expirydate' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'expired' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0), 'parent_txn_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'tid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'entity_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'entity_type' => array('type' => 'varchar', 'length' => 128), 'operation' => array('type' => 'varchar', 'length' => 48)), 'primary key' => array('txn_id'), 'indexes' => array('operation' => array('operation'), 'reference' => array('reference'), 'status_expired_expiry' => array('status', 'expired', 'expirydate'), 'changed' => array('changed'), 'uid' => array('uid'), 'approver_uid' => array('approver_uid'), 'points' => array('points')), 'module' => 'userpoints', 'name' => 'userpoints_txn'));
db_insert('userpoints_txn')->fields(array('txn_id', 'uid', 'approver_uid', 'points', 'time_stamp', 'changed', 'status', 'description', 'reference', 'expirydate', 'expired', 'parent_txn_id', 'tid', 'entity_id', 'entity_type', 'operation'))->values(array('txn_id' => '1', 'uid' => '1', 'approver_uid' => '1', 'points' => '5', 'time_stamp' => '1361395345', 'changed' => '1361395345', 'status' => '0', 'description' => '', 'reference' => '', 'expirydate' => '0', 'expired' => '0', 'parent_txn_id' => '0', 'tid' => '0', 'entity_id' => '0', 'entity_type' => NULL, 'operation' => 'admin'))->values(array('txn_id' => '2', 'uid' => '1', 'approver_uid' => '1', 'points' => '-1', 'time_stamp' => '1361395354', 'changed' => '1361395354', 'status' => '0', 'description' => '', 'reference' => '', 'expirydate' => '0', 'expired' => '0', 'parent_txn_id' => '0', 'tid' => '0', 'entity_id' => '0', 'entity_type' => NULL, 'operation' => 'admin'))->values(array('txn_id' => '3', 'uid' => '1', 'approver_uid' => '1', 'points' => '-3', 'time_stamp' => '1361395364', 'changed' => '1361395364', 'status' => '0', 'description' => '', 'reference' => '', 'expirydate' => '0', 'expired' => '0', 'parent_txn_id' => '0', 'tid' => '2', 'entity_id' => '0', 'entity_type' => NULL, 'operation' => 'admin'))->values(array('txn_id' => '4', 'uid' => '1', 'approver_uid' => '1', 'points' => '1', 'time_stamp' => '1361395371', 'changed' => '1361395371', 'status' => '0', 'description' => '', 'reference' => '', 'expirydate' => '0', 'expired' => '0', 'parent_txn_id' => '0', 'tid' => '2', 'entity_id' => '0', 'entity_type' => NULL, 'operation' => 'admin'))->values(array('txn_id' => '5', 'uid' => '1', 'approver_uid' => '1', 'points' => '5', 'time_stamp' => '1361395380', 'changed' => '1361395380', 'status' => '0', 'description' => '', 'reference' => '', 'expirydate' => '0', 'expired' => '0', 'parent_txn_id' => '0', 'tid' => '1', 'entity_id' => '0', 'entity_type' => NULL, 'operation' => 'admin'))->values(array('txn_id' => '6', 'uid' => '1', 'approver_uid' => '1', 'points' => '10', 'time_stamp' => '1361395390', 'changed' => '1361395390', 'status' => '0', 'description' => '', 'reference' => '', 'expirydate' => '0', 'expired' => '0', 'parent_txn_id' => '0', 'tid' => '2', 'entity_id' => '0', 'entity_type' => NULL, 'operation' => 'admin'))->values(array('txn_id' => '7', 'uid' => '1', 'approver_uid' => '1', 'points' => '2', 'time_stamp' => '1361395402', 'changed' => '1361395402', 'status' => '0', 'description' => '', 'reference' => '', 'expirydate' => '0', 'expired' => '0', 'parent_txn_id' => '0', 'tid' => '1', 'entity_id' => '0', 'entity_type' => NULL, 'operation' => 'admin'))->values(array('txn_id' => '8', 'uid' => '1', 'approver_uid' => '1', 'points' => '-9', 'time_stamp' => '1361395411', 'changed' => '1361395411', 'status' => '0', 'description' => '', 'reference' => '', 'expirydate' => '0', 'expired' => '0', 'parent_txn_id' => '0', 'tid' => '2', 'entity_id' => '0', 'entity_type' => NULL, 'operation' => 'admin'))->execute();
db_insert('system')->fields(array('name', 'filename', 'type', 'owner', 'bootstrap', 'weight', 'schema_version', 'status'))->values(array('name' => 'userpoints', 'filename' => drupal_get_path('module', 'userpoints') . '/userpoints.module', 'type' => 'module', 'owner' => '', 'bootstrap' => 0, 'weight' => 0, 'schema_version' => '7199', 'status' => 1))->values(array('name' => 'entity', 'filename' => drupal_get_path('module', 'entity') . '/entity.module', 'type' => 'module', 'owner' => '', 'bootstrap' => 0, 'weight' => 0, 'schema_version' => '7002', 'status' => 1))->execute();
示例13: gettext
* *****
* ***** Add all new fields above
* *****
* ************************************************************************************* */
$createTables = true;
if (isset($_GET['create']) || isset($_GET['update']) || isset($_GET['protect_files']) && db_connect($_zp_conf_vars)) {
if (!isset($_GET['protect_files'])) {
if ($taskDisplay[substr($task, 0, 8)] == 'create') {
echo "<h3>" . gettext("About to create tables") . "...</h3>";
} else {
echo "<h3>" . gettext("About to update tables") . "...</h3>";
}
setupLog(gettext("Begin table creation"));
foreach ($db_schema as $sql) {
@set_time_limit(60);
$result = db_create_table($sql);
echo ' ';
// keep alive
if (!$result) {
$createTables = false;
setupLog(sprintf(gettext('Query %1$s Failed. Error: %2$s'), $sql, db_error()));
echo '<div class="error">';
echo sprintf(gettext('Table creation failure:<br />Query: %1$s<br />Error: %2$s'), $sql, db_error());
echo '</div>';
} else {
setupLog(sprintf(gettext('Query ( %s ) Success.'), $sql));
}
}
// always run the update queries to insure the tables are up to current level
setupLog(gettext("Begin table updates"));
foreach ($sql_statements as $sql) {
示例14: db_create_table
<?php
/**
* @file
* Test content for the trigger upgrade path.
*/
db_create_table('trigger_assignments', array('fields' => array('hook' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), 'op' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''), 'aid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), 'weight' => array('type' => 'int', 'not null' => TRUE, 'default' => 0)), 'primary key' => array('hook', 'op', 'aid'), 'module' => 'trigger', 'name' => 'trigger_assignments'));
// Add several trigger configurations.
db_insert('trigger_assignments')->fields(array('hook', 'op', 'aid', 'weight'))->values(array('hook' => 'node', 'op' => 'presave', 'aid' => 'node_publish_action', 'weight' => '1'))->values(array('hook' => 'comment', 'op' => 'presave', 'aid' => 'comment_publish_action', 'weight' => '1'))->values(array('hook' => 'comment_delete', 'op' => 'presave', 'aid' => 'node_save_action', 'weight' => '1'))->values(array('hook' => 'nodeapi', 'op' => 'presave', 'aid' => 'node_make_sticky_action', 'weight' => '1'))->values(array('hook' => 'nodeapi', 'op' => 'somehow_nodeapi_got_a_very_long', 'aid' => 'node_save_action', 'weight' => '1'))->execute();
db_update('system')->fields(array('schema_version' => '6000', 'status' => '1'))->condition('filename', 'modules/trigger/trigger.module')->execute();
示例15: update_structure
function update_structure($verbose, $action)
{
global $a, $db;
$errors = false;
logger('updating structure', LOGGER_DEBUG);
// Get the current structure
$database = array();
$tables = q("show tables");
foreach ($tables as $table) {
$table = current($table);
$database[$table] = table_structure($table);
}
// Get the definition
$definition = db_definition();
// Compare it
foreach ($definition as $name => $structure) {
$sql3 = "";
if (!isset($database[$name])) {
$r = db_create_table($name, $structure["fields"], $verbose, $action);
if (false === $r) {
$errors .= t('Errors encountered creating database tables.') . $name . EOL;
}
} else {
// Drop the index if it isn't present in the definition
foreach ($database[$name]["indexes"] as $indexname => $fieldnames) {
if (!isset($structure["indexes"][$indexname])) {
$sql2 = db_drop_index($indexname);
if ($sql3 == "") {
$sql3 = "ALTER TABLE `" . $name . "` " . $sql2;
} else {
$sql3 .= ", " . $sql2;
}
}
}
// Compare the field structure field by field
foreach ($structure["fields"] as $fieldname => $parameters) {
if (!isset($database[$name]["fields"][$fieldname])) {
$sql2 = db_add_table_field($fieldname, $parameters);
if ($sql3 == "") {
$sql3 = "ALTER TABLE `" . $name . "` " . $sql2;
} else {
$sql3 .= ", " . $sql2;
}
} else {
// Compare the field definition
$current_field_definition = implode(",", $database[$name]["fields"][$fieldname]);
$new_field_definition = implode(",", $parameters);
if ($current_field_definition != $new_field_definition) {
$sql2 = db_modify_table_field($fieldname, $parameters);
if ($sql3 == "") {
$sql3 = "ALTER TABLE `" . $name . "` " . $sql2;
} else {
$sql3 .= ", " . $sql2;
}
}
}
}
}
// Create the index
foreach ($structure["indexes"] as $indexname => $fieldnames) {
if (!isset($database[$name]["indexes"][$indexname])) {
$sql2 = db_create_index($indexname, $fieldnames);
if ($sql2 != "") {
if ($sql3 == "") {
$sql3 = "ALTER TABLE `" . $name . "` " . $sql2;
} else {
$sql3 .= ", " . $sql2;
}
}
}
}
if ($sql3 != "") {
$sql3 .= ";";
if ($verbose) {
echo $sql3 . "\n";
}
if ($action) {
$r = @$db->q($sql3);
if (false === $r) {
$errors .= t('Errors encountered performing database changes.') . $sql3 . EOL;
}
}
}
}
return $errors;
}