Issue Details (XML | Word | Printable)

Key: MDL-2097
Type: Bug Bug
Status: Closed Closed
Resolution: Cannot Reproduce
Priority: Minor Minor
Assignee: Martin Dougiamas
Reporter: Petri Asikainen
Votes: 0
Watchers: 0
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

get_records..() functions and ADODB_FETCH_MODE

Created: 15/Oct/04 07:18 PM   Updated: 19/Jan/07 03:07 PM
Component/s: General
Affects Version/s: 1.7
Fix Version/s: None

Environment: All

Database: Any
Participants: Martin Dougiamas, Michael Blake, Petri Asikainen and Samuli Karevaara
Security Level: None
Affected Branches: MOODLE_17_STABLE


 Description  « Hide
get_records..() functions return data double keyed like:

array (

[0] => myuser

[username] => myuser

[1] => plaaah

[password] => plaah

....

Maybe we doing lot of duplicate checks all around Moodle. At least all foreach loops is twice logger that needed.

ADODB_FETCH_MODE is controlling how data is returned ( see http://phplens.com/adodb/reference.varibles.adodb_fetch_mode.html )

Is it ok to set default ADODB_FETCH_MODE to ADODB_FETCH_ASSOC to return only accosiative array without numbered keys. Or will it broke something?



 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Martin Dougiamas added a comment - 18/Jul/06 03:02 PM
From Petri Asikainen (paca at sci.fi) Friday, 15 October 2004, 07:36 PM:

$db->SetFetchMode() is other way to set this setting.

From Martin Dougiamas (martin at moodle.com) Friday, 15 October 2004, 07:51 PM:

It doesn't actually duplicate anything ... try this:

foreach ($USER as $key => $data) { echo <p>$key ... $data</p>; }

And it's not lengthening any foreach loops, because there's no reason to loop through the fields of a record ...

Best to leave it as is, I think.

From Petri Asikainen (paca at sci.fi) Sunday, 17 October 2004, 10:37 PM:

I find this out when I was writing user syncronisation and using code like:

$users = get_records(user, 'auth', 'ldap');

foreach($users as $user) {

$update='';

$count=0;

$numddd = count($user);

foreach ($user as $key => $value) {

$count++;

$update .= $key .' = \''. $value .'\''.\n;

if ($count < $numddd) { $update .= ', '; }

}

echo $update.\n\n\n;

}

Every update_record and insert_record (by using getInsertSQL) have to use loops handle data. But I havent tested is there any performance differences or not.


Michael Blake added a comment - 24/Aug/06 01:47 PM
assign to a valid user

Samuli Karevaara added a comment - 19/Jan/07 03:07 PM
Please re-open this bug, put into far future or mark as "deferred" if needed, but the issue still exists. From the forums: "The breakage caused by switching to ADODB_FETCH_ASSOC is not caused by numeric references to fields in Moodle code, but by ADODB's GetAssoc() in /lib/adodb/adodb.inc.php. (BTW, despite the name this function deals with ADODB_FETCH_NUM and *_BOTH too.)

This function always assumes that the first field can be used as a key, so it uses it as a key and slices it off (array_slice($this->fields, 1) from the "value" part of the returned array. Moodle on the other hand very often believes that there is a field named "id" that has the id value in it.

This combination of behaviours works with *_BOTH because now ADODB uses the first field (now the numerical reference to the id field) as a key and then slices it off, still leaving the associative reference to the id field. This is why the ID field is the only non-duplicated field. I used to think that it's pre-pasted in there by Moodle itself, but it's a bit reverse: the dupe of it is removed by ADODB."

More at http://moodle.org/mod/forum/discuss.php?d=27897 and http://moodle.org/mod/forum/discuss.php?d=36219.