mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
Some more uses of $CFG->dbfamily. MDL-7061
This commit is contained in:
parent
bb48a53735
commit
a4bad45c2c
@ -169,14 +169,15 @@ class data_field_latlong extends data_field_base {
|
||||
function get_sort_sql($fieldname) {
|
||||
global $CFG;
|
||||
|
||||
switch ($CFG->dbtype) {
|
||||
switch ($CFG->dbfamily) {
|
||||
case 'mysql': // string in an arithmetic operation is converted to a floating-point number
|
||||
return '('.$fieldname.'+0.0)';
|
||||
|
||||
default:
|
||||
case 'postgres': //cast is for PG
|
||||
return 'CAST('.$fieldname.' AS REAL)';
|
||||
default: //Return just the fieldname. TODO: Look behaviour under MSSQL and Oracle
|
||||
return $fieldname;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
@ -47,12 +47,13 @@ class data_field_number extends data_field_base {
|
||||
function get_sort_sql($fieldname) {
|
||||
global $CFG;
|
||||
|
||||
switch ($CFG->dbtype) {
|
||||
switch ($CFG->dbfamily) {
|
||||
case 'mysql': // string in an arithmetic operation is converted to a floating-point number
|
||||
return '('.$fieldname.'+0.0)';
|
||||
|
||||
default:
|
||||
case 'postgres': // cast for PG
|
||||
return 'CAST('.$fieldname.' AS REAL)';
|
||||
default: // the rest, just the field name. TODO: Analyse behaviour under MSSQL and Oracle
|
||||
return $fieldname;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1278,7 +1278,7 @@ function forum_search_posts($searchterms, $courseid=0, $limitfrom=0, $limitnum=5
|
||||
// Some differences SQL
|
||||
$LIKE = sql_ilike();
|
||||
$NOTLIKE = 'NOT ' . $LIKE;
|
||||
if ($CFG->dbtype == 'postgres7') {
|
||||
if ($CFG->dbfamily == 'postgres') {
|
||||
$REGEXP = '~*';
|
||||
$NOTREGEXP = '!~*';
|
||||
} else {
|
||||
@ -1584,8 +1584,7 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
|
||||
}
|
||||
|
||||
//TODO: there must be a nice way to do this that keeps both postgres and mysql 3.2x happy but I can't find it right now.
|
||||
if ($CFG->dbtype == 'postgres7' || $CFG->dbtype == 'mssql' ||
|
||||
$CFG->dbtype == 'mssql_n' || $CFG->dbtype == 'odbc_mssql' || $CFG->dbtype == 'oci8po') {
|
||||
if ($CFG->dbfamily == 'postgres' || $CFG->dbfamily == 'mssql' || $CFG->dbfamily == 'oracle') {
|
||||
return get_records_sql("SELECT $postdata, d.name, d.timemodified, d.usermodified, d.groupid,
|
||||
u.firstname, u.lastname, u.email, u.picture $umfields
|
||||
FROM {$CFG->prefix}forum_discussions d
|
||||
@ -1596,7 +1595,7 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC",
|
||||
AND p.parent = 0
|
||||
$timelimit $groupselect $userselect
|
||||
ORDER BY $forumsort", $limitfrom, $limitnum);
|
||||
} else {
|
||||
} else { // MySQL query. TODO: Check if this is needed (MySQL 4.1 should work with the above query)
|
||||
return get_records_sql("SELECT $postdata, d.name, d.timemodified, d.usermodified, d.groupid,
|
||||
u.firstname, u.lastname, u.email, u.picture $umfields
|
||||
FROM ({$CFG->prefix}forum_posts p,
|
||||
@ -4074,7 +4073,7 @@ function forum_tp_count_forum_read_records($userid, $forumid, $groupid=false) {
|
||||
$groupsel = ' AND (d.groupid = '.$groupid.' OR d.groupid = -1)';
|
||||
}
|
||||
|
||||
if ($CFG->dbtype === 'postgres7') {
|
||||
if ($CFG->dbfamily === 'postgres' || $CFG->dbfamily === 'mssql' || $CFG->dbfamily === 'oracle') {
|
||||
// this query takes 20ms, vs several minutes for the one below
|
||||
$sql = " SELECT COUNT (DISTINCT u.id ) "
|
||||
. " FROM ( "
|
||||
@ -4091,7 +4090,7 @@ function forum_tp_count_forum_read_records($userid, $forumid, $groupid=false) {
|
||||
. " WHERE d.forum = $forumid $groupsel "
|
||||
. " AND p.modified < $cutoffdate"
|
||||
. ") u";
|
||||
} else {
|
||||
} else { // This is for MySQL. TODO: Check if the above works for MySQL 4.1
|
||||
$sql = 'SELECT COUNT(DISTINCT p.id) '.
|
||||
'FROM '.$CFG->prefix.'forum_posts p,'.$CFG->prefix.'forum_read r,'.$CFG->prefix.'forum_discussions d '.
|
||||
'WHERE d.forum = '.$forumid.$groupsel.' AND p.discussion = d.id AND '.
|
||||
|
@ -294,7 +294,7 @@ function forum_print_big_search_form($course) {
|
||||
echo '<td class="c1"><input type="text" size="35" name="notwords" value="'.s($notwords).'" alt="" /></td>';
|
||||
echo '</tr>';
|
||||
|
||||
if ($CFG->dbtype == 'mysql' || $CFG->dbtype == 'postgres7') {
|
||||
if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
|
||||
echo '<tr>';
|
||||
echo '<td class="c0">'.get_string('searchfullwords', 'forum').':</td>';
|
||||
echo '<td class="c1"><input type="text" size="35" name="fullwords" value="'.s($fullwords).'" alt="" /></td>';
|
||||
|
@ -946,8 +946,8 @@ function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL)
|
||||
}
|
||||
|
||||
/// Some differences in syntax for entrygreSQL
|
||||
switch ($CFG->dbtype) {
|
||||
case 'postgres7':
|
||||
switch ($CFG->dbfamily) {
|
||||
case 'postgres':
|
||||
$LIKE = "ILIKE"; // case-insensitive
|
||||
$NOTLIKE = "NOT ILIKE"; // case-insensitive
|
||||
$REGEXP = "~*";
|
||||
@ -976,7 +976,7 @@ function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL)
|
||||
|
||||
/// Under Oracle and MSSQL, trim the + and - operators and perform
|
||||
/// simpler LIKE search
|
||||
if ($CFG->dbtype == 'oci8po' || $CFG->dbtype == 'mssql' || $CFG->dbtype == 'mssql_n' || $CFG->dbtype == 'odbc_mssql') {
|
||||
if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') {
|
||||
$searchterm = trim($searchterm, '+-');
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@
|
||||
case 'search':
|
||||
|
||||
/// Some differences in syntax for PostgreSQL
|
||||
if ($CFG->dbtype == "postgres7") {
|
||||
if ($CFG->dbfamily == "postgres") {
|
||||
$REGEXP = "~*";
|
||||
$NOTREGEXP = "!~*";
|
||||
} else {
|
||||
@ -163,7 +163,7 @@
|
||||
|
||||
/// Under Oracle and MSSQL, trim the + and - operators and perform
|
||||
/// simpler LIKE search
|
||||
if ($CFG->dbtype == 'oci8po' || $CFG->dbtype == 'mssql' || $CFG->dbtype == 'mssql_n' || $CFG->dbtype == 'odbc_mssql') {
|
||||
if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') {
|
||||
$searchterm = trim($searchterm, '+-');
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user