Commit 250cf34d authored by Nigel McNie's avatar Nigel McNie Committed by Penny Leach
Browse files

Change to how table names are specified in SQL queries.

Now, table names (and other identifiers that could be confused with SQL kewords), should be put into SQL like this:

SELECT * FROM {artefact}

The braces are matched and expanded by DML now to include the prefix and be properly quoted, which means that tables like 'view' and 'group' don't need renaming (and nor should they, there's little reason why we should rename tables to get around such constraints).

This has removed a whole bunch of $prefix = ... and get_config('dbprefix') stuff, which makes things a little simpler yet again.
parent 7f278a16
......@@ -394,8 +394,6 @@ function auth_get_auth_instances_for_institution($institution=null) {
return array();
}
$dbprefix = get_config('dbprefix');
if (!isset($cache[$institution])) {
// Get auth instances in order of priority
// DO NOT CHANGE THE SORT ORDER OF THIS RESULT SET
......@@ -411,8 +409,8 @@ function auth_get_auth_instances_for_institution($institution=null) {
a.requires_config,
a.requires_parent
FROM
'.$dbprefix.'auth_instance i,
'.$dbprefix.'auth_installed a
{auth_instance} i,
{auth_installed} a
WHERE
a.name = i.authname AND
i.institution = '. db_quote($institution).'
......@@ -438,8 +436,6 @@ function auth_get_auth_instances_for_institution($institution=null) {
*/
function auth_get_auth_instances_for_wwwroot($wwwroot) {
$dbprefix = get_config('dbprefix');
// TODO: we just need ai.id and ai.authname... rewrite query, or
// just drop this function
$query = " SELECT
......@@ -447,9 +443,9 @@ function auth_get_auth_instances_for_wwwroot($wwwroot) {
aic.*,
i.*
FROM
{$dbprefix}auth_instance ai,
{$dbprefix}auth_instance_config aic,
{$dbprefix}institution i
{auth_instance} ai,
{auth_instance_config} aic,
{institution} i
WHERE
aic.field = 'wwwroot' AND
aic.value = ? AND
......@@ -474,8 +470,6 @@ function auth_get_auth_instances_for_username($institution, $username) {
// DO NOT CHANGE THE SORT ORDER OF THIS RESULT SET
// YEAH EINSTEIN - THAT MEANS YOU!!!
$dbprefix = get_config('dbprefix');
// TODO: work out why this won't accept a placeholder - had to use db_quote
$sql ='
SELECT DISTINCT
......@@ -486,9 +480,9 @@ function auth_get_auth_instances_for_username($institution, $username) {
a.requires_config,
a.requires_parent
FROM
'.$dbprefix.'auth_instance i,
'.$dbprefix.'auth_installed a,
'.$dbprefix.'usr u
{auth_instance} i,
{auth_installed} a,
{usr} u
WHERE
a.name = i.authname AND
i.institution = ? AND
......@@ -521,17 +515,15 @@ function auth_get_available_auth_types($institution=null) {
return array();
}
$dbprefix = get_config('dbprefix');
// TODO: work out why this won't accept a placeholder - had to use db_quote
$sql ='
SELECT DISTINCT
a.name,
a.requires_config
FROM
'.$dbprefix.'auth_installed a
{auth_installed} a
LEFT JOIN
'.$dbprefix.'auth_instance i
{auth_instance} i
ON
a.name = i.authname AND
i.institution = '. db_quote($institution).'
......@@ -1005,8 +997,7 @@ function login_submit(Pieform $form, $values) {
* Removes registration requests that were not completed in the allowed amount of time
*/
function auth_clean_partial_registrations() {
$prefix = get_config('dbprefix');
delete_records_sql('DELETE FROM ' . $prefix . 'usr_registration
delete_records_sql('DELETE FROM {usr_registration}
WHERE expiry < ?', array(db_format_timestamp(time())));
}
......@@ -1025,13 +1016,12 @@ function auth_clean_partial_registrations() {
*/
function auth_handle_account_expiries() {
// The 'expiry' flag on the usr table
$prefix = get_config('dbprefix');
$sitename = get_config('sitename');
$wwwroot = get_config('wwwroot');
// Expiry warning messages
if ($users = get_records_sql_array('SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, i.defaultaccountinactivewarn AS timeout
FROM ' . $prefix . 'usr u, ' . $prefix . 'institution i
FROM {usr} u, {institution} i
WHERE u.institution = i.name
AND ? - ' . db_format_tsfield('u.expiry', false) . ' < i.defaultaccountinactivewarn
AND expirymailsent = 0', array(time()))) {
......@@ -1050,7 +1040,7 @@ function auth_handle_account_expiries() {
// Actual expired users
if ($users = get_records_sql_array('SELECT id
FROM ' . $prefix . 'usr
FROM {usr}
WHERE ' . db_format_tsfield('expiry', false) . ' < ?', array(time()))) {
// Users have expired!
foreach ($users as $user) {
......@@ -1060,7 +1050,7 @@ function auth_handle_account_expiries() {
// Inactivity (lastlogin is too old)
if ($users = get_records_sql_array('SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, i.defaultaccountinactivewarn AS timeout
FROM ' . $prefix . 'usr u, ' . $prefix . 'institution i
FROM {usr} u, {institution} i
WHERE u.institution = i.name
AND (? - ' . db_format_tsfield('u.lastlogin', false) . ') > (i.defaultaccountinactiveexpire - i.defaultaccountinactivewarn)
AND inactivemailsent = 0', array(time()))) {
......@@ -1078,8 +1068,8 @@ function auth_handle_account_expiries() {
// Actual inactive users
if ($users = get_records_sql_array('SELECT u.id
FROM ' . $prefix . 'usr u
LEFT JOIN ' . $prefix . 'institution i ON (u.institution = i.name)
FROM {usr} u
LEFT JOIN {institution} i ON (u.institution = i.name)
WHERE ' . db_format_tsfield('lastlogin', false) . ' < ? - i.defaultaccountinactiveexpire', array(time()))) {
// Users have become inactive!
foreach ($users as $user) {
......
......@@ -99,15 +99,13 @@ class User {
throw new InvalidArgumentException('parameter must be a positive integer to create a User object');
}
$dbprefix = get_config('dbprefix');
$sql = 'SELECT
*,
' . db_format_tsfield('expiry') . ',
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('suspendedctime') . '
FROM
'.$dbprefix.'usr
{usr}
WHERE
id = ?';
......@@ -134,15 +132,13 @@ class User {
$instanceid = $parentid;
}
$dbprefix = get_config('dbprefix');
$sql = 'SELECT
*,
' . db_format_tsfield('expiry') . ',
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('suspendedctime') . '
FROM
'.$dbprefix.'usr
{usr}
WHERE
LOWER(username) = ? AND
authinstance = ?';
......
......@@ -31,8 +31,6 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('creategroup'));
$prefix = get_config('dbprefix');
$joinoptions = array(
'invite' => get_string('membershiptype.invite'),
'request' => get_string('membershiptype.request'),
......
......@@ -32,7 +32,6 @@ require_once('pieforms/pieform.php');
define('TITLE', get_string('editgroup'));
$id = param_integer('id');
$prefix = get_config('dbprefix');
$group_data = get_record('group', 'id', $id, 'owner', $USER->get('id'));
......
......@@ -36,26 +36,25 @@ $owned = param_boolean('owned', 0);
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$prefix = get_config('dbprefix');
$userid = $USER->get('id');
if (empty($owned)) { // just get groups this user is a member of.
$data = get_member_groups($userid, $offset, $limit);
$count = get_record_sql('SELECT COUNT(distinct g.id) AS count
FROM ' . $prefix . 'group g
JOIN ' . $prefix . 'group_member gm ON gm.group = g.id
FROM {group} g
JOIN {group_member} gm ON gm.group = g.id
WHERE g.owner != ? AND gm.member = ?', array($userid, $userid));
$count = $count->count;
}
else {
$count = count_records_sql('SELECT COUNT(*) FROM ' . $prefix . 'group g WHERE g.owner = ?',
$count = count_records_sql('SELECT COUNT(*) FROM {group} g WHERE g.owner = ?',
array($userid));
$datasql = 'SELECT g.id,g.jointype,g.name,g.owner,count(distinct gmr.group) as requestcount, COUNT(distinct v.view) AS hasviews
FROM ' . $prefix . 'group g
LEFT JOIN ' . $prefix . 'group_member_request gmr ON gmr.group = g.id
LEFT JOIN ' . $prefix . 'view_access_group v ON v.group = c.id
FROM {group} g
LEFT JOIN {group_member_request} gmr ON gmr.group = g.id
LEFT JOIN {view_access_group} v ON v.group = c.id
WHERE c.owner = ?
GROUP BY c.id,c.jointype,c.name,c.owner';
......
......@@ -32,7 +32,6 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
json_headers();
$action = param_variable('action');
$dbprefix = get_config('dbprefix');
if ($action == 'delete') {
$id = param_integer('id');
......
......@@ -48,7 +48,6 @@ if (!$membership = user_can_access_group($id)) {
}
$group = get_record('group', 'id', $id);
$prefix = get_config('dbprefix');
$dbnow = db_format_timestamp(time());
switch ($type) {
......@@ -72,17 +71,17 @@ switch ($type) {
$count = count_records_sql('
SELECT COUNT(DISTINCT id)
FROM ' . $prefix . 'view v
LEFT OUTER JOIN ' . $prefix . 'view_access_group a ON a.view=v.id
FROM {view} v
LEFT OUTER JOIN {view_access_group} a ON a.view=v.id
' . $where,
$values
);
$data = get_records_sql_array('
SELECT DISTINCT v.*, u.username, u.firstname, u.lastname, u.preferredname, u.id AS usr
FROM ' . $prefix . 'view v
LEFT OUTER JOIN ' . $prefix . 'view_access_group a ON a.view=v.id
INNER JOIN ' . $prefix.'usr u ON v.owner = u.id ' . $where,
FROM {view} v
LEFT OUTER JOIN {view_access_group} a ON a.view=v.id
INNER JOIN {usr} u ON v.owner = u.id ' . $where,
$values,
$offset,
$limit
......@@ -98,7 +97,7 @@ switch ($type) {
break;
case 'members':
$select = 'SELECT u.*,g.tutor ';
$sql = ' FROM ' . $prefix . 'usr u JOIN ' . $prefix . 'group_member g
$sql = ' FROM {usr} u JOIN {group_member} g
ON g.member = u.id
WHERE g.group = ?';
if (empty($pending)) { // default behaviour - actual members
......
......@@ -35,7 +35,6 @@ $limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$control = param_boolean('control');
$prefix = get_config('dbprefix');
$userid = $USER->get('id');
......@@ -61,10 +60,10 @@ if ($control) {
if (empty($pending)) {
$count = count_records_select('usr_friend', 'usr1 = ? OR usr2 = ?', array($userid, $userid));
$sql = 'SELECT u.id, u.username, u.firstname, u.lastname, u.preferredname, u.staff
FROM ' . $prefix . 'usr u
FROM {usr} u
WHERE u.id IN (
SELECT (CASE WHEN usr1 = ? THEN usr2 ELSE usr1 END) AS userid
FROM ' . $prefix . 'usr_friend WHERE (usr1 = ? OR usr2 = ?))';
FROM {usr_friend} WHERE (usr1 = ? OR usr2 = ?))';
if (!$data = get_records_sql_assoc($sql, array($userid, $userid, $userid), $offset, $limit)) {
$data = array();
}
......@@ -76,8 +75,8 @@ if (empty($pending)) {
else {
$count = count_records('usr_friend_request' , 'owner', array($userid));
$sql = 'SELECT u.id, u.firstname, u.lastname, u.preferredname, u.username, fr.reason
FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'usr_friend_request fr ON fr.requester = u.id
FROM {usr} u
JOIN {usr_friend_request} fr ON fr.requester = u.id
WHERE fr.owner = ?';
$data = get_records_sql_array($sql, array($userid), $offset, $limit);
$views = array();
......
......@@ -41,14 +41,13 @@ if ($parent === null) {
else {
$parentcondition = ' = ' . $db->quote($parent);
}
$prefix = get_config('dbprefix');
// Get all artefacts we require
$data = get_records_sql_array("SELECT id, artefacttype, container, title
FROM " . $prefix . "artefact
FROM {artefact}
WHERE artefacttype IN (
SELECT name
FROM " . $prefix . "artefact_installed_type
FROM {artefact_installed_type}
WHERE plugin = ?
)
AND parent $parentcondition
......
......@@ -29,14 +29,12 @@ define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
if ($USER->is_logged_in()) {
$prefix = get_config('dbprefix');
$result = get_records_sql_array("
SELECT tag, SUM(count) AS count
FROM (
SELECT tag,COUNT(*) AS count FROM {$prefix}artefact_tag t INNER JOIN {$prefix}artefact a ON t.artefact=a.id WHERE a.owner=? GROUP BY 1
SELECT tag,COUNT(*) AS count FROM {artefact_tag} t INNER JOIN {artefact} a ON t.artefact=a.id WHERE a.owner=? GROUP BY 1
UNION ALL
SELECT tag,COUNT(*) AS count FROM {$prefix}view_tag t INNER JOIN {$prefix}view v ON t.view=v.id WHERE v.owner=? GROUP BY 1
SELECT tag,COUNT(*) AS count FROM {view_tag} t INNER JOIN {view} v ON t.view=v.id WHERE v.owner=? GROUP BY 1
) tags
GROUP BY tag
ORDER BY LOWER(tag)
......
......@@ -95,7 +95,6 @@ function handle_activity($activitytype, $data, $cron=false) {
}
$users = array();
$prefix = get_config('dbprefix');
if (!empty($activitytype->admin)) {
$users = activity_get_users($activitytype->name, null, null, true);
......@@ -228,8 +227,8 @@ function handle_activity($activitytype, $data, $cron=false) {
}
$oldsubject = isset($data->subject) ? $data->subject : '';
$data->subject = get_string('watchlistmessageview', 'activity');
if (!$viewinfo = get_record_sql('SELECT u.*, v.title FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'view v ON v.owner = u.id
if (!$viewinfo = get_record_sql('SELECT u.*, v.title FROM {usr} u
JOIN {view} v ON v.owner = u.id
WHERE v.id = ?', array($data->view))) {
if (!empty($cron)) { // probably deleted already
return;
......@@ -239,10 +238,10 @@ function handle_activity($activitytype, $data, $cron=false) {
$data->message = $oldsubject . ' ' . get_string('onview', 'activity')
. ' ' . $viewinfo->title . ' ' . get_string('ownedby', 'activity');
$sql = 'SELECT u.*, p.method, ' . $casturl . ' AS url
FROM ' . $prefix . 'usr_watchlist_view wv
JOIN ' . $prefix . 'usr u
FROM {usr_watchlist_view} wv
JOIN {usr} u
ON wv.usr = u.id
LEFT JOIN ' . $prefix . 'usr_activity_preference p
LEFT JOIN {usr_activity_preference} p
ON p.usr = u.id
WHERE (p.activity = ? OR p.activity IS NULL)
AND wv.view = ?
......@@ -261,8 +260,8 @@ function handle_activity($activitytype, $data, $cron=false) {
else if (!empty($data->artefact)) {
$data->subject = get_string('watchlistmessageartefact', 'activity')
. (isset($data->subject) ? ': ' . $data->subject : '');
if (!$ainfo = get_record_sql('SELECT u.*, a.title FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'artefact a ON a.owner = u.id
if (!$ainfo = get_record_sql('SELECT u.*, a.title FROM {usr} u
JOIN {artefact} a ON a.owner = u.id
WHERE a.id = ?', array($data->artefact))) {
if (!empty($cron)) { // probably deleted already
return;
......@@ -281,23 +280,23 @@ this query selects four different cases
*/
$sql = '
SELECT DISTINCT u.*, p.method, ?||wa.view AS url
FROM ' . $prefix . 'usr u
LEFT JOIN ' . $prefix . 'usr_activity_preference p
FROM {usr} u
LEFT JOIN {usr_activity_preference} p
ON p.usr = u.id
JOIN (
SELECT wa.usr AS uid, wa.view AS view
FROM ' . $prefix . 'usr_watchlist_artefact wa
FROM {usr_watchlist_artefact} wa
WHERE wa.artefact = ?
UNION SELECT wa.usr AS uid, wa.view AS view
FROM ' . $prefix . 'artefact_parent_cache pc
JOIN ' . $prefix . 'usr_watchlist_artefact wa
FROM {artefact_parent_cache} pc
JOIN {usr_watchlist_artefact} wa
ON wa.artefact = pc.parent
WHERE pc.artefact = ? AND wa.recurse = 1
UNION SELECT wv.usr AS uid, wv.view AS view
FROM ' . $prefix . 'artefact_parent_cache pc
JOIN ' . $prefix . 'view_artefact va
FROM {artefact_parent_cache} pc
JOIN {view_artefact} va
ON va.artefact = pc.parent
JOIN ' . $prefix . 'usr_watchlist_view wv
JOIN {usr_watchlist_view} wv
ON va.view = wv.view
WHERE (pc.artefact = ? OR va.artefact = ?)AND wv.recurse = 1
) wa ON wa.uid = u.id
......@@ -327,10 +326,10 @@ SELECT DISTINCT u.*, p.method, ?||wa.view AS url
$data->subject = get_string('watchlistmessagegroup', 'activity');
$data->message = $oldsubject . ' ' . get_string('ongroup', 'activity') . ' ' . $groupname;
$sql = 'SELECT DISTINCT u.*, p.method, ' . $casturl . ' AS url
FROM ' . $prefix . 'usr_watchlist_group g
JOIN ' . $prefix . 'usr u
FROM {usr_watchlist_group} g
JOIN {usr} u
ON g.usr = u.id
LEFT JOIN ' . $prefix . 'usr_activity_preference p
LEFT JOIN {usr_activity_preference} p
ON p.usr = u.id
WHERE (p.activity = ? OR p.activity IS NULL)
AND g.group = ?
......@@ -347,8 +346,8 @@ SELECT DISTINCT u.*, p.method, ?||wa.view AS url
if (!is_numeric($data->owner) || !is_numeric($data->view)) {
throw new InvalidArgumentException("New view activity type requires view and owner to be set");
}
if (!$viewinfo = get_record_sql('SELECT u.*, v.title FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'view v ON v.owner = u.id
if (!$viewinfo = get_record_sql('SELECT u.*, v.title FROM {usr} u
JOIN {view} v ON v.owner = u.id
WHERE v.id = ?', array($data->view))) {
if (!empty($cron)) { //probably deleted already
return;
......@@ -378,8 +377,8 @@ SELECT DISTINCT u.*, p.method, ?||wa.view AS url
if (!isset($data->oldusers)) {
throw new InvalidArgumentException("view access activity type requires oldusers to be set (even if empty)");
}
if (!$viewinfo = get_record_sql('SELECT u.*, v.title FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'view v ON v.owner = u.id
if (!$viewinfo = get_record_sql('SELECT u.*, v.title FROM {usr} u
JOIN {view} v ON v.owner = u.id
WHERE v.id = ?', array($data->view))) {
if (!empty($cron)) { // probably deleted already
return;
......@@ -455,8 +454,8 @@ SELECT DISTINCT u.*, p.method, ?||wa.view AS url
function activity_get_users($activitytype, $userids=null, $userobjs=null, $adminonly=false) {
$values = array($activitytype);
$sql = 'SELECT u.*, p.method
FROM ' . get_config('dbprefix') .'usr u
LEFT JOIN ' . get_config('dbprefix') . 'usr_activity_preference p
FROM {usr} u
LEFT JOIN {usr_activity_preference} p
ON p.usr = u.id
WHERE (p.activity = ? ' . (empty($adminonly) ? ' OR p.activity IS NULL' : '') . ')';
if (!empty($adminonly)) {
......@@ -505,29 +504,27 @@ function activity_process_queue() {
function activity_get_viewaccess_users($view, $owner, $type) {
$prefix = get_config('dbprefix');
$sql = 'SELECT userid, u.*, p.method
FROM (
SELECT (CASE WHEN usr1 = ? THEN usr2 ELSE usr1 END) AS userid
FROM ' . $prefix . 'usr_friend f
JOIN ' . $prefix . 'view v ON (v.owner = f.usr1 OR v.owner = f.usr2)
JOIN ' . $prefix . 'view_access vu ON vu.view = v.id
FROM {usr_friend} f
JOIN {view} v ON (v.owner = f.usr1 OR v.owner = f.usr2)
JOIN {view_access} vu ON vu.view = v.id
WHERE (usr1 = ? OR usr2 = ?) AND vu.accesstype = ? AND v.id = ?
UNION SELECT usr AS userid
FROM ' . $prefix . 'view_access_usr u
FROM {view_access_usr} u
WHERE u.view = ?
UNION SELECT m.member
FROM ' . $prefix . 'group_member m
JOIN ' . $prefix . 'view_access_group g ON g.group = m.group
WHERE c.view = ? AND (c.tutoronly = ? OR m.tutor = ?)
UNION SELECT c.owner
FROM ' . $prefix . 'group g
JOIN ' . $prefix . 'view_access_group ac ON ac.group = g.id
WHERE ac.view = ?
FROM {group_member} m
JOIN {view_access_group} g ON g.group = m.group
WHERE g.view = ? AND (g.tutoronly = ? OR m.tutor = ?)
UNION SELECT g.owner
FROM {group} g
JOIN {view_access_group} ag ON ag.group = g.id
WHERE ag.view = ?
) AS userlist
JOIN ' . $prefix . 'usr u ON u.id = userlist.userid
LEFT JOIN ' . $prefix . 'usr_activity_preference p ON p.usr = u.id
JOIN {usr} u ON u.id = userlist.userid
LEFT JOIN {usr_activity_preference} p ON p.usr = u.id
WHERE p.activity = ?';
$values = array($owner, $owner, $owner, 'friends', $view, $view, $view, 0, 1, $view, $type);
if (!$u = get_records_sql_assoc($sql, $values)) {
......
......@@ -141,10 +141,9 @@ function artefact_can_render_to($type, $format) {
}
function artefact_instance_from_id($id) {
$prefix = get_config('dbprefix');
$sql = 'SELECT a.*, i.plugin
FROM ' . $prefix . 'artefact a
JOIN ' . $prefix . 'artefact_installed_type i ON a.artefacttype = i.name
FROM {artefact} a
JOIN {artefact_installed_type} i ON a.artefacttype = i.name
WHERE a.id = ?';
if (!$data = get_record_sql($sql, array($id))) {
throw new ArtefactNotFoundException(get_string('artefactnotfound', 'mahara', $id));
......@@ -167,7 +166,6 @@ function artefact_instance_from_id($id) {
*/
function artefact_instance_from_type($artefact_type, $user_id=null) {
global $USER;
$prefix = get_config('dbprefix');
if ($user_id === null) {
$user_id = $USER->get('id');
......@@ -194,8 +192,8 @@ function artefact_instance_from_type($artefact_type, $user_id=null) {
}
else {
$sql = 'SELECT a.*, i.plugin
FROM ' . $prefix . 'artefact a
JOIN ' . $prefix . 'artefact_installed_type i ON a.artefacttype = i.name
FROM {artefact} a
JOIN {artefact_installed_type} i ON a.artefacttype = i.name
WHERE a.artefacttype = ? AND a.owner = ?';
if (!$data = get_record_sql($sql, array($artefact_type, $user_id))) {
throw new ArtefactNotFoundException("Artefact of type '${artefact_type}' doesn't exist");
......
......@@ -31,7 +31,6 @@ require_once('template.php');
function xmldb_core_upgrade($oldversion=0) {
$status = true;
$prefix = get_config('dbprefix');
if ($oldversion < 2006121400) {
......@@ -172,7 +171,7 @@ function xmldb_core_upgrade($oldversion=0) {
$field->setAttributes(XMLDB_TYPE_INTEGER, 10, false, true, null, null, null, 0);
add_field($table, $field);
execute_sql('UPDATE ' . $prefix . 'usr SET quota=10485760');
execute_sql('UPDATE {usr} SET quota=10485760');
}
if ($oldversion < 2007012300) {
......@@ -237,7 +236,7 @@ function xmldb_core_upgrade($oldversion=0) {
}
if ($oldversion < 2007021903) {
execute_sql("UPDATE {$prefix}artefact
execute_sql("UPDATE {artefact}
SET container = 1
WHERE artefacttype = 'blog'");
}
......@@ -249,25 +248,25 @@ function xmldb_core_upgrade($oldversion=0) {
if ($oldversion < 2007042500) {
// migrate everything we had to change to make mysql happy
execute_sql("ALTER TABLE {$prefix}cron DROP CONSTRAINT {$prefix}cron_cal_pk"); // can't drop primary keys using xmldb...
execute_sql("ALTER TABLE {$prefix}cron ADD CONSTRAINT {$prefix}cron_id_pk PRIMARY KEY (id)"); // or add them!
execute_sql("ALTER TABLE {$prefix}cron ADD CONSTRAINT {$prefix}cron_cal_uix UNIQUE (callfunction)");
execute_sql("ALTER TABLE {$prefix}community ALTER COLUMN name TYPE varchar (128)");
execute_sql("ALTER TABLE {$prefix}usr_activity_preference ALTER COLUMN method TYPE varchar(255)");
execute_sql("ALTER TABLE {$prefix}template_category ALTER COLUMN name TYPE varchar(128)");
execute_sql("ALTER TABLE {$prefix}template_category ALTER COLUMN parent TYPE varchar(128)");
execute_sql("ALTER TABLE {$prefix}template ALTER COLUMN name TYPE varchar(128)");
execute_sql("ALTER TABLE {$prefix}template ALTER COLUMN category TYPE varchar(128)");
execute_sql("ALTER TABLE {$prefix}view ALTER COLUMN template TYPE varchar(128)");
execute_sql("ALTER TABLE {$prefix}view_access ALTER COLUMN accesstype SET DEFAULT 'public'");
execute_sql("ALTER TABLE {$prefix}usr ALTER COLUMN email TYPE varchar(255)");
execute_sql("ALTER TABLE {cron} DROP CONSTRAINT {cron_cal_pk}"); // can't drop primary keys using xmldb...
execute_sql("ALTER TABLE {cron} ADD CONSTRAINT {cron_id_pk} PRIMARY KEY (id)"); // or add them!
execute_sql("ALTER TABLE {cron} ADD CONSTRAINT {cron_cal_uix} UNIQUE (callfunction)");
execute_sql("ALTER TABLE {community} ALTER COLUMN name TYPE varchar (128)");
execute_sql("ALTER TABLE {usr_activity_preference} ALTER COLUMN method TYPE varchar(255)");
execute_sql("ALTER TABLE {template_category} ALTER COLUMN name TYPE varchar(128)");
execute_sql("ALTER TABLE {template_category} ALTER COLUMN parent TYPE varchar(128)");
execute_sql("ALTER TABLE {template} ALTER COLUMN name TYPE varchar(128)");
execute_sql("ALTER TABLE {template} ALTER COLUMN category TYPE varchar(128)");
execute_sql("ALTER TABLE {view} ALTER COLUMN template TYPE varchar(128)");
execute_sql("ALTER TABLE {view_access} ALTER COLUMN accesstype SET DEFAULT 'public'");
execute_sql("ALTER TABLE {usr} ALTER COLUMN email TYPE varchar(255)");
}
// everything up to here was pre mysql support.
if ($oldversion < 2007062000) {
if (!get_record('config', 'field', 'lang')) {
execute_sql("INSERT INTO {$prefix}config (field, value) VALUES ('lang', (SELECT value FROM {$prefix}config WHERE field = 'language'))");
execute_sql("INSERT INTO {config} (field, value) VALUES ('lang', (SELECT value FROM {config} WHERE field = 'language'))");
}
delete_records('config', 'field', 'language');
}
......@@ -409,79 +408,79 @@ function xmldb_core_upgrade($oldversion=0) {
// Drop DEFAULT '' from many columns that should not have had them
// *nigel looks angrily at xmldb
execute_sql('
ALTER TABLE ' . $prefix .