]> git.mjollnir.org Git - moodle.git/commitdiff
More database tweaking ... looking pretty good with PostgreSQL now
authormoodler <moodler>
Mon, 23 Dec 2002 13:48:31 +0000 (13:48 +0000)
committermoodler <moodler>
Mon, 23 Dec 2002 13:48:31 +0000 (13:48 +0000)
lib/datalib.php
mod/quiz/db/postgres7.sql

index c92ea328d96cba4e9b38b75018951efa5baa378f..34bdc116848274b93bd942d55fbeb14dda104aa7 100644 (file)
@@ -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")) {
@@ -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");
 
 }
 
@@ -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");
 }
 
 
@@ -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;
@@ -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,
index 11f689e26832a8c2446e0ec7635c89747b1a9aca..854da8858de114e05bb5157c97c6b23af39894cb 100644 (file)
@@ -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
@@ -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');