I did not fix all the DB problems in search, there are too many there for me to be prepared to clean up other people's mess.
(For once, it was not me making this mistake ;-))
/// Try to replace some well-known serialised contents (html blocks)
notify('Replacing in html blocks...');
$sql = "SELECT bi.*
- FROM {$CFG->prefix}block_instance bi
- JOIN {$CFG->prefix}block b ON b.id = bi.blockid
+ FROM {block_instance} bi
+ JOIN {block} b ON b.id = bi.blockid
WHERE b.name = 'html'";
if ($instances = $DB->get_records_sql($sql)) {
foreach ($instances as $instance) {
function LogoutNotification($SessionID){
- global $CFG, $SESSION;
+ global $CFG, $SESSION, $DB;
// Delete session of user using $SessionID
if(empty($CFG->dbsessions)) {
$ADODB_SESS_LIFE = $CFG->sessiontimeout;
}
- if ($user_session_data = get_records_sql('SELECT sesskey, sessdata FROM '. $CFG->prefix .'sessions2 WHERE expiry > NOW()')) {
+ if ($user_session_data = $DB->get_records_sql('SELECT sesskey, sessdata FROM {sessions2} WHERE expiry > NOW()')) {
foreach ($user_session_data as $session_data) {
// Get user session
} else {
/// please note that we must fetch all grade_grades fields if we want to contruct grade_grade object from it!
$sql = "SELECT g.*
- FROM {$CFG->prefix}grade_items gi,
- {$CFG->prefix}grade_grades g
+ FROM {grade_items} gi,
+ {grade_grades} g
WHERE g.itemid = gi.id AND gi.courseid = {$this->courseid} {$this->userselect}";
- $grades = get_records_sql($sql);
+ $grades = $DB->get_records_sql($sql);
}
$userids = array_keys($this->users);
$this->users = $DB->get_records_sql($sql, $params);
} else {
$sql = "SELECT u.id, u.firstname, u.lastname, u.imagealt, u.picture, u.idnumber
- FROM {$CFG->prefix}user u
- JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid
+ FROM {user) u
+ JOIN {role_assignments} ra ON u.id = ra.userid
$this->groupsql
WHERE ra.roleid in ($this->gradebookroles)
$this->groupwheresql
AND ra.contextid ".get_related_contexts_string($this->context);
- $this->users = get_records_sql($sql);
+ $this->users = $DB->get_records_sql($sql);
}
if (empty($this->users)) {
} else {
/// please note that we must fetch all grade_grades fields if we want to contruct grade_grade object from it!
$sql = "SELECT g.*
- FROM {$CFG->prefix}grade_items gi,
- {$CFG->prefix}grade_grades g
+ FROM {grade_items} gi,
+ {grade_grades} g
WHERE g.itemid = gi.id AND gi.courseid = {$this->courseid} {$this->userselect}";
$grades = get_records_sql($sql);
ctx.id AS ctxid, ctx.path AS ctxpath,
ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel,
cc.path AS categorypath
- FROM {$CFG->prefix}course c
- JOIN {$CFG->prefix}course_categories cc
+ FROM {course} c
+ JOIN {course_categories} cc
ON c.category=cc.id
- JOIN {$CFG->prefix}context ctx
+ JOIN {context} ctx
ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.")
- JOIN {$CFG->prefix}role_assignments ra
+ JOIN {role_assignments} ra
ON (ra.contextid=ctx.id AND ra.userid=:userid)
UNION
SELECT c.id,
ctx.id AS ctxid, ctx.path AS ctxpath,
ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel,
cc.path AS categorypath
- FROM {$CFG->prefix}course c
- JOIN {$CFG->prefix}course_categories cc
+ FROM {course} c
+ JOIN {course_categories} cc
ON c.category=cc.id
- JOIN {$CFG->prefix}context ctx
+ JOIN {context} ctx
ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.")
- JOIN {$CFG->prefix}role_capabilities rc
+ JOIN {role_capabilities} rc
ON (rc.contextid=ctx.id AND (rc.capability=:cap $capany)) ";
if (!empty($catclause)) { /// If we have found the right in categories, add child courses here too
ctx.id AS ctxid, ctx.path AS ctxpath,
ctx.depth AS ctxdepth, ctx.contextlevel AS ctxlevel,
cc.path AS categorypath
- FROM {$CFG->prefix}course c
- JOIN {$CFG->prefix}course_categories cc
+ FROM {course} c
+ JOIN {course_categories} cc
ON c.category=cc.id
- JOIN {$CFG->prefix}context ctx
+ JOIN {context} ctx
ON (c.id=ctx.instanceid AND ctx.contextlevel=".CONTEXT_COURSE.")
$catclause";
}
/// Close the inline_view and join with courses table to get requested $coursefields
$sql .= "
) inline_view
- INNER JOIN {$CFG->prefix}course c
+ INNER JOIN {course} c
ON inline_view.id = c.id";
/// To keep cross-db we need to strip any prefix in the ORDER BY clause for queries using UNION
if ($groupid) {
$groupselect = "AND gm.groupid = $groupid";
- $groupjoin = "JOIN {$CFG->prefix}groups_members gm ON gm.userid=u.id";
+ $groupjoin = "JOIN {groups_members} gm ON gm.userid=u.id";
} else {
$groupselect = "";
$groupjoin = "";
docid,
itemtype
FROM
- {$CFG->prefix}{$table}
+ {" . $table . "}
WHERE
doctype = ?
$itemtypes
SELECT id,
{$values[0]} as docid
FROM
- {$CFG->prefix}{$values[1]}
+ {" . $values[1] . "
WHERE
id NOT IN ('{$docIdList}') and
{$values[2]} > {$indexdate}
id,
{$values[0]}
FROM
- {$CFG->prefix}{$values[1]}
+ {" . $values[1] . "}
$where
";
$docIds = get_records_sql($query);
id,
docid
FROM
- {$CFG->prefix}{$table}
+ {" . $table . "}
WHERE
doctype = '{$mod->name}' AND
$itemtypes
SELECT
c.*
FROM
- {$CFG->prefix}data_content as c,
- {$CFG->prefix}data_records as r
+ {data_content} as c,
+ {data_records} as r
WHERE
c.recordid = r.id AND
r.dataid = {$database_id}
c.modified,
r.dataid
FROM
- {$CFG->prefix}data_comments as c,
- {$CFG->prefix}data_records as r
+ {data_comments} as c,
+ {data_records} as r
WHERE
c.recordid = r.id
";
u.firstname,
u.lastname
FROM
- {$CFG->prefix}forum_discussions d
+ {forum_discussions} d
JOIN
- {$CFG->prefix}forum_posts p
+ {forum_posts} p
ON
p.discussion = d.id
JOIN
- {$CFG->prefix}user u
+ {user} u
ON
p.userid = u.id
WHERE
u.firstname,
u.lastname
FROM
- {$CFG->prefix}forum_discussions d
+ {forum_discussions} d
JOIN
- {$CFG->prefix}forum_posts p
+ {forum_posts} p
ON
p.discussion = d.id
JOIN
- {$CFG->prefix}user u
+ {user} u
ON
p.userid = u.id
WHERE
id as trueid,
r.*
FROM
- {$CFG->prefix}resource as r
+ {resource} as r
WHERE
alltext != '' AND
alltext != ' ' AND
r.type as type,
r.timemodified as timemodified
FROM
- {$CFG->prefix}resource as r,
- {$CFG->prefix}course_modules as cm,
- {$CFG->prefix}modules as m
+ {resource} as r,
+ {course_modules} as cm,
+ {modules} as m
WHERE
r.type = 'file' AND
cm.instance = r.id AND
r.type as type,
r.timemodified as timemodified
FROM
- {$CFG->prefix}resource as r,
- {$CFG->prefix}course_modules as cm,
- {$CFG->prefix}modules as m
+ {resource} as r,
+ {course_modules} as cm,
+ {modules} as m
WHERE
cm.instance = r.id AND
cm.course = r.course AND
docid,
itemtype
FROM
- {$CFG->prefix}{$table}
+ {" . $table . "}
WHERE
doctype = ?
$itemtypes
id,
{$values[0]} as docid
FROM
- {$CFG->prefix}{$values[1]}
+ {" . $values[1] . "}
WHERE
{$values[3]} > {$indexdate} AND
id IN ('{$docIdList}')