Skip to content

Commit

Permalink
Merge branch 'w13_MDL-37742_m25_dirtyoracle' of git://github.com/skod…
Browse files Browse the repository at this point in the history
…ak/moodle

Conflicts:
	lib/upgrade.txt
  • Loading branch information
stronk7 committed Mar 26, 2013
2 parents 2ac738f + e788339 commit 4efcfaa
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 126 deletions.
2 changes: 1 addition & 1 deletion blocks/rss_client/edit_form.php
Expand Up @@ -54,7 +54,7 @@ protected function specific_definition($mform) {
FROM {block_rss_client}
WHERE userid = ? OR shared = 1
ORDER BY CASE WHEN preferredtitle = ? THEN ' . $DB->sql_compare_text('title', 64) . ' ELSE preferredtitle END ',
array($DB->sql_empty(), $USER->id, $DB->sql_empty()));
array('', $USER->id, ''));
if ($rssfeeds) {
$select = $mform->addElement('select', 'config_rssid', get_string('choosefeedlabel', 'block_rss_client'), $rssfeeds);
$select->setMultiple(true);
Expand Down
1 change: 0 additions & 1 deletion cohort/lib.php
Expand Up @@ -40,7 +40,6 @@ function cohort_add_cohort($cohort) {
$cohort->idnumber = NULL;
}
if (!isset($cohort->description)) {
// sql_empty() does not belong here, this crazy Oracle hack is implemented in insert_record()!
$cohort->description = '';
}
if (!isset($cohort->descriptionformat)) {
Expand Down
2 changes: 1 addition & 1 deletion enrol/database/lib.php
Expand Up @@ -407,7 +407,7 @@ public function sync_enrolments(progress_trace $trace, $onecourse = null) {
$localnotempty = "";
if ($localcoursefield !== 'id') {
$localnotempty = "AND c.$localcoursefield <> :lcfe";
$params['lcfe'] = $DB->sql_empty();
$params['lcfe'] = '';
}
$sql = "SELECT c.id, c.visible, c.$localcoursefield AS mapping, c.shortname
FROM {course} c
Expand Down
4 changes: 2 additions & 2 deletions enrol/manual/locallib.php
Expand Up @@ -411,7 +411,7 @@ function enrol_manual_migrate_plugin_enrolments($enrol) {
}

// First delete potential role duplicates.
$params = array('id'=>$e->id, 'component'=>'enrol_'.$enrol, 'empty'=>$DB->sql_empty());
$params = array('id'=>$e->id, 'component'=>'enrol_'.$enrol, 'empty'=>'');
$sql = "SELECT ra.id
FROM {role_assignments} ra
JOIN {role_assignments} mra ON (mra.contextid = ra.contextid AND mra.userid = ra.userid AND mra.roleid = ra.roleid AND mra.component = :empty AND mra.itemid = 0)
Expand All @@ -425,7 +425,7 @@ function enrol_manual_migrate_plugin_enrolments($enrol) {
$sql = "UPDATE {role_assignments}
SET itemid = 0, component = :empty
WHERE itemid = :id AND component = :component";
$params = array('empty'=>$DB->sql_empty(), 'id'=>$e->id, 'component'=>'enrol_'.$enrol);
$params = array('empty'=>'', 'id'=>$e->id, 'component'=>'enrol_'.$enrol);
$DB->execute($sql, $params);

// Delete potential enrol duplicates.
Expand Down
20 changes: 10 additions & 10 deletions enrol/manual/tests/lib_test.php
Expand Up @@ -151,11 +151,11 @@ public function test_migrate_plugin_enrolments() {
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance1->id, 'userid'=>$user4->id, 'status'=>ENROL_USER_ACTIVE)));
$this->assertEquals(4, $DB->count_records('user_enrolments', array('enrolid'=>$maninstance1->id)));
$this->assertEquals(0, $DB->count_records('user_enrolments', array('enrolid'=>$xxxinstance1->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'contextid'=>$context1->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user1->id, 'roleid'=>$teacherrole->id, 'contextid'=>$context1->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'contextid'=>$context1->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'contextid'=>$context1->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'contextid'=>$context1->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>'', 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'contextid'=>$context1->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>'', 'userid'=>$user1->id, 'roleid'=>$teacherrole->id, 'contextid'=>$context1->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>'', 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'contextid'=>$context1->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>'', 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'contextid'=>$context1->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>'', 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'contextid'=>$context1->id)));
$this->assertEquals(5, $DB->count_records('role_assignments', array('contextid'=>$context1->id)));


Expand All @@ -173,7 +173,7 @@ public function test_migrate_plugin_enrolments() {
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance3->id, 'userid'=>$user2->id, 'status'=>ENROL_USER_SUSPENDED)));
$this->assertEquals(2, $DB->count_records('user_enrolments', array('enrolid'=>$maninstance3->id)));
$this->assertEquals(0, $DB->count_records('user_enrolments', array('enrolid'=>$xxxinstance3->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'contextid'=>$context3->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>'', 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'contextid'=>$context3->id)));
$this->assertEquals(1, $DB->count_records('role_assignments', array('contextid'=>$context3->id)));


Expand All @@ -187,10 +187,10 @@ public function test_migrate_plugin_enrolments() {
$this->assertEquals(3, $DB->count_records('user_enrolments', array('enrolid'=>$maninstance4->id)));
$this->assertEquals(0, $DB->count_records('user_enrolments', array('enrolid'=>$xxxinstance4->id)));
$this->assertEquals(0, $DB->count_records('user_enrolments', array('enrolid'=>$xxxinstance4b->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'contextid'=>$context4->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user1->id, 'roleid'=>$teacherrole->id, 'contextid'=>$context4->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'contextid'=>$context4->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user4->id, 'roleid'=>$teacherrole->id, 'contextid'=>$context4->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>'', 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'contextid'=>$context4->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>'', 'userid'=>$user1->id, 'roleid'=>$teacherrole->id, 'contextid'=>$context4->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>'', 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'contextid'=>$context4->id)));
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>'', 'userid'=>$user4->id, 'roleid'=>$teacherrole->id, 'contextid'=>$context4->id)));
$this->assertEquals(4, $DB->count_records('role_assignments', array('contextid'=>$context4->id)));


Expand Down
2 changes: 1 addition & 1 deletion enrol/meta/locallib.php
Expand Up @@ -569,7 +569,7 @@ function enrol_meta_sync($courseid = NULL, $verbose = false) {
}
$enabled[$k] = 'enrol_'.$v;
}
$enabled[] = $DB->sql_empty(); // manual assignments are replicated too
$enabled[] = ''; // manual assignments are replicated too

$onecourse = $courseid ? "AND e.courseid = :courseid" : "";
list($enabled, $params) = $DB->get_in_or_equal($enabled, SQL_PARAMS_NAMED, 'e');
Expand Down
6 changes: 0 additions & 6 deletions lib/accesslib.php
Expand Up @@ -1634,8 +1634,6 @@ function role_assign($roleid, $userid, $contextid, $component = '', $itemid = 0,
}

// Check for existing entry
// TODO: Revisit this sql_empty() use once Oracle bindings are improved. MDL-29765
$component = ($component === '') ? $DB->sql_empty() : $component;
$ras = $DB->get_records('role_assignments', array('roleid'=>$roleid, 'contextid'=>$context->id, 'userid'=>$userid, 'component'=>$component, 'itemid'=>$itemid), 'id');

if ($ras) {
Expand Down Expand Up @@ -1748,10 +1746,6 @@ function role_unassign_all(array $params, $subcontexts = false, $includemanual =
}
}

// TODO: Revisit this sql_empty() use once Oracle bindings are improved. MDL-29765
if (isset($params['component'])) {
$params['component'] = ($params['component'] === '') ? $DB->sql_empty() : $params['component'];
}
$ras = $DB->get_records('role_assignments', $params);
foreach($ras as $ra) {
$DB->delete_records('role_assignments', array('id'=>$ra->id));
Expand Down
4 changes: 2 additions & 2 deletions lib/blocklib.php
Expand Up @@ -587,8 +587,8 @@ public function load_blocks($includeinvisible = null) {
'pagetype' => $this->page->pagetype,
);
if ($this->page->subpage === '') {
$params['subpage1'] = $DB->sql_empty();
$params['subpage2'] = $DB->sql_empty();
$params['subpage1'] = '';
$params['subpage2'] = '';
}
$sql = "SELECT
bi.id,
Expand Down
3 changes: 2 additions & 1 deletion lib/datalib.php
Expand Up @@ -853,7 +853,8 @@ function get_courses_search($searchterms, $sort, $page, $recordsperpage, &$total
if ($DB->get_dbfamily() == 'oracle') {
$concat = $DB->sql_concat('c.summary', "' '", 'c.fullname', "' '", 'c.idnumber', "' '", 'c.shortname');
} else {
$concat = $DB->sql_concat("COALESCE(c.summary, '". $DB->sql_empty() ."')", "' '", 'c.fullname', "' '", 'c.idnumber', "' '", 'c.shortname');
$concat = $DB->sql_concat("COALESCE(c.summary, :empty)", "' '", 'c.fullname', "' '", 'c.idnumber', "' '", 'c.shortname');
$params['empty'] = '';
}

foreach ($searchterms as $searchterm) {
Expand Down
22 changes: 16 additions & 6 deletions lib/dml/moodle_database.php
Expand Up @@ -2012,12 +2012,14 @@ public function sql_position($needle, $haystack) {
}

/**
* Returns the empty string char used by every supported DB. To be used when
* we are searching for that values in our queries. Only Oracle uses this
* for now (will be out, once we migrate to proper NULLs if that days arrives)
* This used to return empty string replacement character.
*
* @deprecated use bound parameter with empty string instead
*
* @return string An empty string.
*/
function sql_empty() {
debugging("sql_empty() is deprecated, please use empty string '' as sql parameter value instead", DEBUG_DEVELOPER);
return '';
}

Expand All @@ -2036,9 +2038,13 @@ function sql_empty() {
*
* ... AND fieldname = '';
*
* are being used. Final result should be:
* are being used. Final result for text fields should be:
*
* ... AND ' . sql_isempty('tablename', 'fieldname', true/false, true);
*
* ... AND ' . sql_isempty('tablename', 'fieldname', true/false, true/false);
* and for varchar fields result should be:
*
* ... AND fieldname = :empty; "; $params['empty'] = '';
*
* (see parameters description below)
*
Expand Down Expand Up @@ -2066,10 +2072,14 @@ public function sql_isempty($tablename, $fieldname, $nullablefield, $textfield)
*
* ... AND fieldname != '';
*
* are being used. Final result should be:
* are being used. Final result for text fields should be:
*
* ... AND ' . sql_isnotempty('tablename', 'fieldname', true/false, true/false);
*
* and for varchar fields result should be:
*
* ... AND fieldname != :empty; "; $params['empty'] = '';
*
* (see parameters description below)
*
* @param string $tablename Name of the table (without prefix). This is not used for now but can be
Expand Down

0 comments on commit 4efcfaa

Please sign in to comment.