Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merged postgresql fixes from MOODLE_14_STABLE(Revision 1.2.4.1) to HEAD.

  • Loading branch information...
commit 2b92c040c889b133241ae96816d1101d29c13bc9 1 parent 4dce0cf
authored March 09, 2005

Showing 1 changed file with 58 additions and 31 deletions. Show diff stats Hide diff stats

  1. 89  mod/wiki/ewikimoodlelib.php
89  mod/wiki/ewikimoodlelib.php
@@ -32,7 +32,7 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
32 32
       */
33 33
       # Ugly, but we need to choose which wiki we are about to change/read
34 34
      case "GET":
35  
-         $id = "'" . mysql_escape_string($args["id"]) . "'";
  35
+         $id = "'" . anydb_escape_string($args["id"]) . "'";
36 36
          ($version = 0 + @$args["version"]) and ($version = "AND (version=$version)") or ($version="");
37 37
 
38 38
          # $result = mysql_query("SELECT * FROM " . EWIKI_DB_TABLE_NAME
@@ -69,10 +69,10 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
69 69
           with "id" index key.
70 70
       */
71 71
       case "HIT":
72  
-         #mysql_query("UPDATE " . EWIKI_DB_TABLE_NAME . " SET hits=(hits+1) WHERE pagename='" . mysql_escape_string($args["id"]) . "'");
  72
+         #mysql_query("UPDATE " . EWIKI_DB_TABLE_NAME . " SET hits=(hits+1) WHERE pagename='" . anydb_escape_string($args["id"]) . "'");
73 73
          # set_field does not work because of the "hits+1" construct
74  
-         #print "DO ".mysql_escape_string($args["id"]); exit;
75  
-         execute_sql("UPDATE " .$CFG->prefix.EWIKI_DB_TABLE_NAME . " SET hits=(hits+1) WHERE pagename='" . mysql_escape_string($args["id"]) . "' and wiki=".$wiki_entry->id, 0);
  74
+         #print "DO ".anydb__escape_string($args["id"]); exit;
  75
+         execute_sql("UPDATE " .$CFG->prefix.EWIKI_DB_TABLE_NAME . " SET hits=(hits+1) WHERE pagename='" . anydb_escape_string($args["id"]) . "' and wiki=".$wiki_entry->id, 0);
76 76
          break;
77 77
     /*  Stores the $data array into the database, while not overwriting
78 78
           existing entries (using WRITE); returns 0 on failure and 1 if
@@ -98,7 +98,7 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
98 98
          #   }
99 99
          #   $a = ($sql1 ? ', ' : '');
100 100
          #   $sql1 .= $a . $index;
101  
-         #   $sql2 .= $a . "'" . mysql_escape_string($value) . "'";
  101
+         #   $sql2 .= $a . "'" . anydb_escape_string($value) . "'";
102 102
          #}
103 103
 
104 104
          #strlen(@$COMMAND) || ($COMMAND = "INSERT");
@@ -107,7 +107,7 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
107 107
             if (is_int($index)) {
108 108
                continue;
109 109
             }
110  
-            $args[$index] =mysql_escape_string($value);
  110
+            $args[$index] =anydb_escape_string($value);
111 111
          }
112 112
          $args["wiki"]=$wiki_entry->id;
113 113
 
@@ -143,7 +143,7 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
143 143
            if (strlen($id)) {
144 144
             $r[$id] = 0;
145 145
             $select .= ($select ? " OR " : "") .
146  
-                    "(pagename='" . mysql_escape_string($id) . "')";
  146
+                    "(pagename='" . anydb_escape_string($id) . "')";
147 147
             }
148 148
          }
149 149
          if($select) {
@@ -181,17 +181,21 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
181 181
           e.g. array("flags","meta","lastmodified");
182 182
       */
183 183
       case "GETALL":
184  
-
185  
-         #$result = mysql_query("SELECT pagename AS id, ".
186  
-         #   implode(", ", $args) .
187  
-         #   " FROM ". EWIKI_DB_TABLE_NAME .
188  
-         #   " GROUP BY id, version DESC"
189  
-         #);
190  
-         $sql= "SELECT pagename AS id, ".
191  
-            implode(", ", $args) .
192  
-            " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
193  
-            " WHERE wiki = ".$wiki_entry->id.
194  
-            " GROUP BY id, version";
  184
+         switch ($CFG->dbtype) {
  185
+             case 'postgres7':
  186
+                 $sql= "SELECT pagename AS id, ".
  187
+                      implode(", ", $args) .
  188
+                      " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
  189
+                      " WHERE wiki = ".$wiki_entry->id.
  190
+                      " GROUP BY pagename, ".implode(", ", $args);
  191
+                 break;
  192
+             default:
  193
+                 $sql= "SELECT pagename AS id, ".
  194
+                 implode(", ", $args) .
  195
+                      " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
  196
+                      " WHERE wiki = ".$wiki_entry->id.
  197
+                      " GROUP BY id, version " ;
  198
+         }
195 199
 
196 200
          #print "$sql";
197 201
          $result=get_records_sql($sql);
@@ -231,19 +235,24 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
231 235
          $field = implode("", array_keys($args));
232 236
          $content = strtolower(implode("", $args));
233 237
          if ($field == "id") { $field = "pagename"; }
234  
-
235  
-         #$result = mysql_query("SELECT pagename AS id, version, flags" .
236  
-         #   (EWIKI_DBQUERY_BUFFER && ($field!="pagename") ? ", $field" : "") .
237  
-         #   " FROM " . EWIKI_DB_TABLE_NAME .
238  
-         #   " WHERE LOCATE('" . mysql_escape_string($content) . "', LCASE($field)) " .
239  
-         #   " GROUP BY id, version DESC"
240  
-         #);
241  
-         $sql= "SELECT pagename AS id, version, flags" .
242  
-            (EWIKI_DBQUERY_BUFFER && ($field!="pagename") ? ", $field" : "") .
243  
-            " FROM " . $CFG->prefix.EWIKI_DB_TABLE_NAME .
244  
-            " WHERE LOCATE('" . mysql_escape_string($content) . "', LCASE($field))  and wiki=".$wiki_entry->id .
245  
-            " GROUP BY id, version DESC";
  238
+         switch ($CFG->dbtype) {
  239
+            case 'postgres7':
  240
+                $sql= "SELECT pagename AS id, version, flags" .
  241
+                    (EWIKI_DBQUERY_BUFFER && ($field!="pagename") ? ", $field" : "") .
  242
+                    " FROM " . $CFG->prefix.EWIKI_DB_TABLE_NAME .
  243
+                    " WHERE $field ILIKE '%".$content."%'  and wiki=".$wiki_entry->id .
  244
+                    " GROUP BY id, version, flags ". 
  245
+                    (EWIKI_DBQUERY_BUFFER && ($field!="pagename") ? ", $field" : "") ;
  246
+                break;
  247
+            default: 
  248
+                $sql= "SELECT pagename AS id, version, flags" .
  249
+                    (EWIKI_DBQUERY_BUFFER && ($field!="pagename") ? ", $field" : "") .
  250
+                    " FROM " . $CFG->prefix.EWIKI_DB_TABLE_NAME .
  251
+                    " WHERE LOCATE('" . anydb_escape_string($content) . "', LCASE($field))  and wiki=".$wiki_entry->id .
  252
+                    " GROUP BY id, version DESC";
  253
+         }
246 254
          $result=get_records_sql($sql);
  255
+
247 256
          $r = new ewiki_dbquery_result(array("id","version",$field));
248 257
          $drop = "";
249 258
          #while ($result && ($row = mysql_fetch_array($result, MYSQL_ASSOC))) {
@@ -265,7 +274,7 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
265 274
 
266 275
 
267 276
       case "DELETE":
268  
-         $id = mysql_escape_string($args["id"]);
  277
+         $id = anydb_escape_string($args["id"]);
269 278
          $version = $args["version"];
270 279
 
271 280
          #mysql_query("DELETE FROM " . EWIKI_DB_TABLE_NAME ."
@@ -299,3 +308,21 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
299 308
 
300 309
    return($r);
301 310
 }
  311
+
  312
+function anydb_escape_string($s) {
  313
+   global $CFG ;
  314
+   $type = ($CFG->dbtype);
  315
+   switch ($CFG->dbtype) {
  316
+        case 'mysql':
  317
+            $s = mysql_escape_string($s);
  318
+            break;
  319
+        case 'postgres7':
  320
+            $s = pg_escape_string($s);
  321
+            break;
  322
+        default:
  323
+            $s = addslashes($s);
  324
+   }
  325
+
  326
+   return($s);
  327
+}
  328
+

0 notes on commit 2b92c04

Please sign in to comment.
Something went wrong with that request. Please try again.