For example, I adapted the db_update.php code for one of my MODs to do this, and this is how the SQL is assigned:
Code: Select all
//
// Build Array of SQL Statements.
//
$sql = array();
switch ($dbms)
{
case 'mysql':
case 'mysql4':
$sql[] = 'CREATE TABLE ' . $table_prefix . 'version_check (
mod_id INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
mod_name VARCHAR(250) NOT NULL DEFAULT \'\',
mod_current_version TEXT NOT NULL DEFAULT \'\',
mod_new_version TEXT NOT NULL DEFAULT \'\',
mod_secondary_version TEXT NOT NULL DEFAULT \'\',
mod_domain_loc TEXT NOT NULL,
mod_file_name TEXT NOT NULL,
mod_file_loc TEXT NOT NULL,
mod_topic_loc TEXT NOT NULL DEFAULT \'\',
mod_download_loc TEXT NOT NULL DEFAULT \'\',
mod_dev_status TEXT NOT NULL DEFAULT \'\',
mod_error VARCHAR(250) DEFAULT \'\',
mod_status TINYINT(4) NOT NULL DEFAULT 1,
mod_time_stamp INTEGER(11) NOT NULL DEFAULT 0,
mod_author_notes TEXT NOT NULL DEFAULT \'\',
PRIMARY KEY (mod_id)
)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_check VALUES(1,\'phpBB\',\'\',\'\',\'\',\'www.phpbb.com\',\'20x.txt\',\'updatecheck\',\'http://www.phpbb.com\',\'\',\'\',\'\',1,0,\'\')';
$sql[] = 'CREATE TABLE ' . $table_prefix . 'version_config (
config_name VARCHAR(255) NOT NULL,
config_value TEXT NOT NULL DEFAULT \'\',
PRIMARY KEY (config_name)
)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'check_time\',\'86400\')';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'background_check\',1)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'show_admin_index\',1)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'update_email\',0)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'email_address\',\'\')';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'update_pm\',0)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'pm_id\',\'\')';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'update_post\',0)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'post_forum\',\'\')';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'post_contents\',\'\')';
$sql[] = 'CREATE TABLE ' . $table_prefix . 'version_log (
log_id INTEGER(10) UNSIGNED NOT NULL AUTO_INCREMENT,
log_timestamp INTEGER(11) NOT NULL DEFAULT 0,
mod_name VARCHAR(250) NOT NULL DEFAULT \'\',
log_action TEXT NOT NULL DEFAULT \'\',
PRIMARY KEY (log_id)
)';
break;
case 'mssql':
$sql[] = 'CREATE TABLE ' . $table_prefix . 'version_check (
mod_id INTEGER NOT NULL IDENTITY(1, 1),
mod_name VARCHAR(250) NOT NULL DEFAULT (\'\'),
mod_current_version TEXT NOT NULL DEFAULT (\'\'),
mod_new_version TEXT NOT NULL DEFAULT (\'\'),
mod_secondary_version TEXT NOT NULL DEFAULT (\'\'),
mod_domain_loc TEXT NOT NULL,
mod_file_name TEXT NOT NULL,
mod_file_loc TEXT NOT NULL,
mod_topic_loc TEXT NOT NULL DEFAULT (\'\'),
mod_download_loc TEXT NOT NULL DEFAULT (\'\'),
mod_dev_status TEXT NOT NULL DEFAULT (\'\'),
mod_error VARCHAR(250) NULL DEFAULT (\'\'),
mod_status SMALLINT NOT NULL DEFAULT (1),
mod_time_stamp INTEGER NOT NULL DEFAULT (0),
mod_author_notes TEXT NOT NULL DEFAULT (\'\'),
CONSTRAINT ' . $table_prefix . 'version_check_pk PRIMARY KEY (mod_id) ON [PRIMARY],
CHECK (mod_id>=0)
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_check VALUES(1,\'phpBB\',\'\',\'\',\'\',\'www.phpbb.com\',\'20x.txt\',\'updatecheck\',\'http://www.phpbb.com\',\'\',\'\',\'\',1,0,\'\')';
$sql[] = 'CREATE TABLE ' . $table_prefix . 'version_config (
config_name VARCHAR(255) NOT NULL,
config_value TEXT NOT NULL DEFAULT (\'\'),
CONSTRAINT ' . $table_prefix . 'version_config_pk PRIMARY KEY (config_name) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'check_time\',\'86400\')';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'background_check\',1)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'show_admin_index\',1)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'update_email\',0)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'email_address\',\'\')';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'update_pm\',0)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'pm_id\',\'\')';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'update_post\',0)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'post_forum\',\'\')';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'post_contents\',\'\')';
$sql[] = 'CREATE TABLE ' . $table_prefix . 'version_log (
log_id INTEGER NOT NULL IDENTITY(1, 1),
log_timestamp INTEGER NOT NULL DEFAULT (0),
mod_name VARCHAR(250) NOT NULL DEFAULT (\'\'),
log_action TEXT NOT NULL DEFAULT (\'\'),
CONSTRAINT ' . $table_prefix . 'version_log_pk PRIMARY KEY (log_id) ON [PRIMARY],
CHECK (log_id>=0)
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]';
break;
case 'postgres':
$sql[] = 'CREATE TABLE ' . $table_prefix . 'version_check (
mod_id SERIAL,
mod_name VARCHAR(250) NOT NULL DEFAULT \'\',
mod_current_version TEXT NOT NULL DEFAULT \'\',
mod_new_version TEXT NOT NULL DEFAULT \'\',
mod_secondary_version TEXT NOT NULL DEFAULT \'\',
mod_domain_loc TEXT NOT NULL,
mod_file_name TEXT NOT NULL,
mod_file_loc TEXT NOT NULL,
mod_topic_loc TEXT NOT NULL DEFAULT \'\',
mod_download_loc TEXT NOT NULL DEFAULT \'\',
mod_dev_status TEXT NOT NULL DEFAULT \'\',
mod_error VARCHAR(250) DEFAULT \'\',
mod_status SMALLINT NOT NULL DEFAULT 1,
mod_time_stamp INTEGER NOT NULL DEFAULT 0,
mod_author_notes TEXT NOT NULL DEFAULT \'\',
CONSTRAINT ' . $table_prefix . 'version_check_pk PRIMARY KEY (mod_id),
CHECK (mod_id>=0)
)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_check VALUES(1,\'phpBB\',\'\',\'\',\'\',\'www.phpbb.com\',\'20x.txt\',\'updatecheck\',\'http://www.phpbb.com\',\'\',\'\',\'\',1,0,\'\')';
$sql[] = 'CREATE TABLE ' . $table_prefix . 'version_config (
config_name VARCHAR(255) NOT NULL,
config_value TEXT NOT NULL DEFAULT \'\',
CONSTRAINT ' . $table_prefix . 'version_config_pk PRIMARY KEY (config_name)
)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'check_time\',\'86400\')';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'background_check\',1)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'show_admin_index\',1)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'update_email\',0)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'email_address\',\'\')';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'update_pm\',0)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'pm_id\',\'\')';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'update_post\',0)';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'post_forum\',\'\')';
$sql[] = 'INSERT INTO ' . $table_prefix . 'version_config VALUES(\'post_contents\',\'\')';
$sql[] = 'CREATE TABLE ' . $table_prefix . 'version_log (
log_id SERIAL,
log_timestamp INTEGER NOT NULL DEFAULT 0,
mod_name VARCHAR(250) NOT NULL DEFAULT \'\',
log_action TEXT NOT NULL DEFAULT \'\',
CONSTRAINT ' . $table_prefix . 'version_log_pk PRIMARY KEY (log_id),
CHECK (log_id>=0)
)';
break;
default:
message_die(GENERAL_ERROR, 'Sorry, but AVC is not compatible with ' . $dbms . ', it is only compatible with MySQL, PostgreSQL, and Microsoft SQL.');
}
--Fountain of Apples