Skip to content

Commit

Permalink
More database tweaking ... looking pretty good with PostgreSQL now
Browse files Browse the repository at this point in the history
  • Loading branch information
moodler committed Dec 23, 2002
1 parent a3eea09 commit 31fefa6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
30 changes: 18 additions & 12 deletions lib/datalib.php
Expand Up @@ -411,9 +411,9 @@ function insert_record($table, $dataobject, $returnid=true) {
}

if ($returnid) {
if ($db->hasInsertID) {
return $db->Insert_ID(); // ADOdb has stored the ID for us
}
//if ($db->hasInsertID) {
//return $db->Insert_ID(); // ADOdb has stored the ID for us
//}

// Try to pull the record out again to find the id. This is the most cross-platform method.
if ($rs = $db->Execute("SELECT id FROM $CFG->prefix$table WHERE $select")) {
Expand Down Expand Up @@ -705,17 +705,22 @@ function get_users_search($search, $sort="u.firstname ASC") {


function get_users_count() {
return count_record_select("user", "username <> 'guest' AND deleted <> 1");
return count_records_select("user", "username <> 'guest' AND deleted <> 1");
}

function get_users_listing($sort, $dir="ASC", $page=1, $recordsperpage=20) {
global $CFG;

if ($CFG->dbtype == "mysql") {
$limit = "LIMIT $page,$recordsperpage";
} else {
$limit = "LIMIT $recordsperpage,$page";
}
return get_records_sql("SELECT id, username, email, firstname, lastname, city, country, lastaccess
FROM {$CFG->prefix}user
WHERE username <> 'guest'
AND deleted <> '1'
ORDER BY $sort $dir
LIMIT $page,$recordsperpage");
ORDER BY $sort $dir $limit");

}

Expand All @@ -742,13 +747,14 @@ function get_users_unconfirmed($cutofftime=999999999) {

function get_users_longtimenosee($cutofftime) {
global $CFG;

$db->debug = true;
return get_records_sql("SELECT u.*
FROM {$CFG->prefix}user u,
{$CFG->prefix}user_students s
WHERE lastaccess > '0'
AND lastaccess < '$cutofftime'
AND u.id = s.userid
GROUP BY u.id");
WHERE u.lastaccess > '0'
AND u.lastaccess < '$cutofftime'
AND u.id = s.userid");
}


Expand Down Expand Up @@ -816,7 +822,7 @@ function add_to_log($course, $module, $action, $url="", $info="") {
/// url = the file and parameters used to see the results of the action
/// info = additional description information

global $db, $USER, $REMOTE_ADDR;
global $db, $CFG, $USER, $REMOTE_ADDR;

if (isset($USER->realuser)) { // Don't log
return;
Expand All @@ -825,7 +831,7 @@ function add_to_log($course, $module, $action, $url="", $info="") {
$timenow = time();
$info = addslashes($info);

$result = $db->Execute("INSERT INTO log (time,
$result = $db->Execute("INSERT INTO {$CFG->prefix}log (time,
userid,
course,
ip,
Expand Down
4 changes: 2 additions & 2 deletions mod/quiz/db/postgres7.sql
Expand Up @@ -151,7 +151,7 @@ CREATE TABLE prefix_quiz_shortanswer (
usecase integer NOT NULL default '0'
);
# --------------------------------------------------------
CREATE INDEX prefix_question_quiz_shortanswer_idx ON quiz_shortanswer (question);
CREATE INDEX question_prefix_quiz_shortanswer_idx ON prefix_quiz_shortanswer (question);

#
# Table structure for table quiz_truefalse
Expand All @@ -163,7 +163,7 @@ CREATE TABLE prefix_quiz_truefalse (
"true" integer NOT NULL default '0',
"false" integer NOT NULL default '0'
);
CREATE INDEX prefix_question_quiz_truefalse_idx ON quiz_truefalse (question);
CREATE INDEX question_prefix_quiz_truefalse_idx ON prefix_quiz_truefalse (question);


INSERT INTO prefix_log_display VALUES ('quiz', 'view', 'quiz', 'name');
Expand Down

0 comments on commit 31fefa6

Please sign in to comment.