get_records_*_assoc giving incorrect false when records exists

Bug #1698978 reported by Robert Lyon
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
High
Robert Lyon

Bug Description

If you try to do a get_records_*_assoc but only want 1 field returned you get 'false' instead.

This is because the get_records_*_assoc functions need at least 2 fields to be selected to work correctly but doesn't give a warning if you only provide one

For example

    $test = get_records_sql_assoc("SELECT username FROM {usr} WHERE username LIKE 'adm%'", array());
    $test2 = get_records_sql_array("SELECT username FROM {usr} WHERE username LIKE 'adm%'", array());

The $test will return false but the $test2 will return an array with the users starting with 'adm'

So I'll add a SQL exception to avoid this trap in the future

I'll mark the bug 'high' in case we are relying in this anywhere in Mahara currently

Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "master" branch: https://reviews.mahara.org/7828

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/7828
Committed: https://git.mahara.org/mahara/mahara/commit/be550b4e067879a184d82764a9404e632be63b4b
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit be550b4e067879a184d82764a9404e632be63b4b
Author: Robert Lyon <email address hidden>
Date: Tue Jun 20 11:49:14 2017 +1200

Bug 1698978: get_records_*_assoc functions fail on one field

If we are trying to fetch only 1 field then we can't use the
$rs->GetAssoc() function as that expects 2 fields minimum.

We can get around this in lib/dml.php by creating our own assoc return
object.

behatnotneeded

Change-Id: I6a4a9beadc4abeebc5d73bac6128d56f46ce4676
Signed-off-by: Robert Lyon <email address hidden>

Robert Lyon (robertl-9)
Changed in mahara:
status: In Progress → Fix Committed
Robert Lyon (robertl-9)
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.