Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 2b92c040c889b133241ae96816d1101d29c13bc9 1 parent 4dce0cf
paca70 authored
Showing with 58 additions and 31 deletions.
  1. +58 −31 mod/wiki/ewikimoodlelib.php
View
89 mod/wiki/ewikimoodlelib.php
@@ -32,7 +32,7 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
*/
# Ugly, but we need to choose which wiki we are about to change/read
case "GET":
- $id = "'" . mysql_escape_string($args["id"]) . "'";
+ $id = "'" . anydb_escape_string($args["id"]) . "'";
($version = 0 + @$args["version"]) and ($version = "AND (version=$version)") or ($version="");
# $result = mysql_query("SELECT * FROM " . EWIKI_DB_TABLE_NAME
@@ -69,10 +69,10 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
with "id" index key.
*/
case "HIT":
- #mysql_query("UPDATE " . EWIKI_DB_TABLE_NAME . " SET hits=(hits+1) WHERE pagename='" . mysql_escape_string($args["id"]) . "'");
+ #mysql_query("UPDATE " . EWIKI_DB_TABLE_NAME . " SET hits=(hits+1) WHERE pagename='" . anydb_escape_string($args["id"]) . "'");
# set_field does not work because of the "hits+1" construct
- #print "DO ".mysql_escape_string($args["id"]); exit;
- 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);
+ #print "DO ".anydb__escape_string($args["id"]); exit;
+ 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);
break;
/* Stores the $data array into the database, while not overwriting
existing entries (using WRITE); returns 0 on failure and 1 if
@@ -98,7 +98,7 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
# }
# $a = ($sql1 ? ', ' : '');
# $sql1 .= $a . $index;
- # $sql2 .= $a . "'" . mysql_escape_string($value) . "'";
+ # $sql2 .= $a . "'" . anydb_escape_string($value) . "'";
#}
#strlen(@$COMMAND) || ($COMMAND = "INSERT");
@@ -107,7 +107,7 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
if (is_int($index)) {
continue;
}
- $args[$index] =mysql_escape_string($value);
+ $args[$index] =anydb_escape_string($value);
}
$args["wiki"]=$wiki_entry->id;
@@ -143,7 +143,7 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
if (strlen($id)) {
$r[$id] = 0;
$select .= ($select ? " OR " : "") .
- "(pagename='" . mysql_escape_string($id) . "')";
+ "(pagename='" . anydb_escape_string($id) . "')";
}
}
if($select) {
@@ -181,17 +181,21 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
e.g. array("flags","meta","lastmodified");
*/
case "GETALL":
-
- #$result = mysql_query("SELECT pagename AS id, ".
- # implode(", ", $args) .
- # " FROM ". EWIKI_DB_TABLE_NAME .
- # " GROUP BY id, version DESC"
- #);
- $sql= "SELECT pagename AS id, ".
- implode(", ", $args) .
- " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
- " WHERE wiki = ".$wiki_entry->id.
- " GROUP BY id, version";
+ switch ($CFG->dbtype) {
+ case 'postgres7':
+ $sql= "SELECT pagename AS id, ".
+ implode(", ", $args) .
+ " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
+ " WHERE wiki = ".$wiki_entry->id.
+ " GROUP BY pagename, ".implode(", ", $args);
+ break;
+ default:
+ $sql= "SELECT pagename AS id, ".
+ implode(", ", $args) .
+ " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
+ " WHERE wiki = ".$wiki_entry->id.
+ " GROUP BY id, version " ;
+ }
#print "$sql";
$result=get_records_sql($sql);
@@ -231,19 +235,24 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
$field = implode("", array_keys($args));
$content = strtolower(implode("", $args));
if ($field == "id") { $field = "pagename"; }
-
- #$result = mysql_query("SELECT pagename AS id, version, flags" .
- # (EWIKI_DBQUERY_BUFFER && ($field!="pagename") ? ", $field" : "") .
- # " FROM " . EWIKI_DB_TABLE_NAME .
- # " WHERE LOCATE('" . mysql_escape_string($content) . "', LCASE($field)) " .
- # " GROUP BY id, version DESC"
- #);
- $sql= "SELECT pagename AS id, version, flags" .
- (EWIKI_DBQUERY_BUFFER && ($field!="pagename") ? ", $field" : "") .
- " FROM " . $CFG->prefix.EWIKI_DB_TABLE_NAME .
- " WHERE LOCATE('" . mysql_escape_string($content) . "', LCASE($field)) and wiki=".$wiki_entry->id .
- " GROUP BY id, version DESC";
+ switch ($CFG->dbtype) {
+ case 'postgres7':
+ $sql= "SELECT pagename AS id, version, flags" .
+ (EWIKI_DBQUERY_BUFFER && ($field!="pagename") ? ", $field" : "") .
+ " FROM " . $CFG->prefix.EWIKI_DB_TABLE_NAME .
+ " WHERE $field ILIKE '%".$content."%' and wiki=".$wiki_entry->id .
+ " GROUP BY id, version, flags ".
+ (EWIKI_DBQUERY_BUFFER && ($field!="pagename") ? ", $field" : "") ;
+ break;
+ default:
+ $sql= "SELECT pagename AS id, version, flags" .
+ (EWIKI_DBQUERY_BUFFER && ($field!="pagename") ? ", $field" : "") .
+ " FROM " . $CFG->prefix.EWIKI_DB_TABLE_NAME .
+ " WHERE LOCATE('" . anydb_escape_string($content) . "', LCASE($field)) and wiki=".$wiki_entry->id .
+ " GROUP BY id, version DESC";
+ }
$result=get_records_sql($sql);
+
$r = new ewiki_dbquery_result(array("id","version",$field));
$drop = "";
#while ($result && ($row = mysql_fetch_array($result, MYSQL_ASSOC))) {
@@ -265,7 +274,7 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
case "DELETE":
- $id = mysql_escape_string($args["id"]);
+ $id = anydb_escape_string($args["id"]);
$version = $args["version"];
#mysql_query("DELETE FROM " . EWIKI_DB_TABLE_NAME ."
@@ -299,3 +308,21 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
return($r);
}
+
+function anydb_escape_string($s) {
+ global $CFG ;
+ $type = ($CFG->dbtype);
+ switch ($CFG->dbtype) {
+ case 'mysql':
+ $s = mysql_escape_string($s);
+ break;
+ case 'postgres7':
+ $s = pg_escape_string($s);
+ break;
+ default:
+ $s = addslashes($s);
+ }
+
+ return($s);
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.