Monday, 2012-08-06

*** Joins: kirillka (~Miranda@195.242.142.17)00:16
*** Joins: dregad (~dregad@155.250.128.35)00:55
*** Joins: Paul_46 (~IceChat09@cpc1-enfi15-2-0-cust580.hari.cable.virginmedia.com)01:44
dregadPaul_46 - can I pick your brains04:25
dregadI know what you think about adodb but still this is bugging me as I don't understand what's happening04:25
dregadconsider this code04:25
dregad$sql = 'SELECT DISTINCT reporter_id FROM mantis_bugnote_table WHERE bug_id = 157';04:26
dregad$r = $db->Execute( $sql );04:26
dregadfor( $i = 0; $i < $r->RecordCount(); $i++) {04:26
dregadvar_dump( db_result($r, $i) );04:26
dregadecho "$i\n";04:26
dregad}04:26
dregad-- loosely adapted from email_api.php / email_collect_recipients()04:27
dregadthe strange thing is, that the loop is executed only once in my test case04:27
dregadeven though the query returns 3 records04:27
dregadafter the call to $p_result->GetArray() in db_result(), the value of $i is bumped to 304:28
dregadhow is that possible !?04:28
Paul_46on what db engine?04:32
dregadmysql04:34
Paul_46so your saying it prints04:35
Paul_460, 304:35
dregadi mean, regardless of adodb and the dbengine, how can a function alter the value in the caller's space04:35
Paul_46?04:35
dregadif you omit the var_dump(), yes04:35
Paul_46if you remove the whole var_dump line includign the db_result does it still print 0,3?04:36
dregadand btw, the same occurs if you call $r->GetArray() directly, so db_result() is not the culprit here04:36
dregadno, in that case it goes 0,1,204:36
Paul_46well first off if there's a & type thing around04:38
Paul_46i.e. function getarray( &$r )04:38
Paul_46but i can't see that if that's the cae04:38
dregadnope, no & in adodb.inc.php04:39
Paul_46if you do for (4i=0; $i < 3; $i++ ) wwhat doesi t do04:40
dregadfunction GetArray($nRows = -1)04:40
dregad{04:40
dregadglobal $ADODB_EXTENSION; if ($ADODB_EXTENSION) {04:40
dregad$results = adodb_getall($this,$nRows);04:40
dregadreturn $results;04:40
dregad}04:40
dregad$results = array();04:40
dregad$cnt = 0;04:40
dregadwhile (!$this->EOF && $nRows != $cnt) {04:40
dregad$results[] = $this->fields;04:40
dregad$this->MoveNext();04:40
dregad$cnt++;04:40
dregad}04:40
dregadreturn $results;04:40
dregad}04:40
dregadlet me check04:40
Paul_46i'm inclined to think what php version04:41
dregadsame thing04:41
dregadi'm on 5.3.10 here04:41
Paul_46so for ( $i = 0 to 3 ) { GetArray(); print $i} returns 0,304:42
Paul_46and for ( $i = 0 to 3 ) {  print $i} returns 0,1,2,304:42
dregadyep04:43
Paul_46can you run a different php version ?04:44
dregadI think I have a 5.2. somewhere04:44
Paul_46I was thinking newer04:45
Paul_465.4.5 or 5.3.1504:45
dregadNot sure I want to mess with this box atm ;)04:45
Paul_46anyway04:45
Paul_46should just get rid of adodb04:45
Paul_46:)04:45
dregadI knew you'd say that04:46
dregad:P04:46
dregad(and btw I think doing the loop in the way is written is retarded in my opinion - should just call db_fetch_array)04:46
Paul_46what file ?04:47
Paul_46email api ?04:47
dregadyes04:47
dregadline ~26004:47
dregadhttp://www.mantisbt.org/bugs/view.php?id=1454904:47
Paul_46https://github.com/mantisbt/mantisbt/blob/next/application/core/email_api.php04:49
Paul_46dhx changed iti n next already /04:49
Paul_46effectively with https://github.com/mantisbt/mantisbt/commit/153577f000aa80ad9072045359400a444d1b8ec604:50
Paul_46and whilst it says 3 months ago04:51
Paul_46that's due to rebasing etc04:51
Paul_46so was actually changedi n Author: Paul <paul@mantisforge.org>  2011-04-19 21:54:3304:51
Paul_4616 months ago04:51
dregadbtw, must indeed be a php version thing, because on my 5.2.14 server here, it works04:54
dregadbackporting that code to 1.2.x still shows the erroneous behavior05:02
Paul_46hmm05:03
Paul_46can you see what first version of 5.3 it works on ? ;p05:03
Paul_46assuming it works on 5.3.15 and not 5.3.1005:04
dregadprobably not worth the effort...05:09
dregadi'll just get rid of db_result and use db_fetch_array05:09
Paul_46well05:09
Paul_46no05:09
Paul_46if it's a php version issue05:10
Paul_46we dont need to make a change05:10
Paul_46TBH05:10
Paul_46and the code works fine as it is05:10
Paul_46so no change required :)05:10
Paul_46if there's a broken php version out there, we should identify the broken php version05:12
Paul_46and just make sure users aren't running it05:12
Paul_46rather then work around it05:12
Paul_46as what you are basically saying is we should never use db_result05:12
Paul_46and if you can produce the bug in a db setup, shouldnt' be too hard to try with 5.3.1505:14
Paul_46other option is just bump the minimum requirements to 5.3.1105:17
Paul_46as we know 5.3.10 is broken in some way05:17
dregadno, what I'm saying is that it does not make sense to use db_result in this context05:32
dregador rather, in that way05:32
dregaddb_result expects a recordset in the right position and returns the corresponding value05:33
Paul_46my point was more05:33
Paul_46as it's already been changed in next05:33
Paul_46there shouldn't be any point in changing it05:33
dregadif you look at the loop, the recordset is never re-positioned05:33
Paul_46or well05:33
Paul_46gonna be fun merging05:33
Paul_46if we do different implementations of the same fixes05:33
dregadit's not the *same* fix05:34
dregadyou got rid of record_count()05:34
dregadthe code in next will just end up in an endless loop05:35
dregadi'm sure you'll agree that's a bug :P05:35
Paul_46i guess what i  mean is - in mbt2:05:35
Paul_46$t_query = 'SELECT DISTINCT reporter_id FROM {bugnote} WHERE bug_id = %d';05:35
Paul_46gah05:35
dregadi'm not touching the sql at all05:35
Paul_46$t_query = 'SELECT DISTINCT reporter_id FROM {bugnote} WHERE bug_id = %d';05:35
Paul_46$t_result = db_query( $t_query, array( $p_bug_id ) );05:35
Paul_46while( $t_user_id = db_result( $t_result ) ) {05:35
Paul_46$t_recipients[$t_user_id] = true;05:35
Paul_46is what the current latest version of that code block looks like05:36
dregadthis ==> while( $t_user_id = db_result( $t_result ) ) {  <== will loop forever05:36
Paul_46how'd you work that one out05:37
Paul_46:)05:37
dregadjust try it05:37
Paul_46also it might in new db layer it doesn't ;p05:37
dregadin that case, you changed the definition of the function too05:37
Paul_46function db_result( $p_result, $p_index1 = 0 ) {05:37
Paul_46----05:38
Paul_46function db_result( $p_result, $p_index1 = 0 ) {05:38
Paul_46return $p_result->fetchColumn($p_index1);05:38
Paul_46}05:38
Paul_46is the new version05:38
Paul_46so gets rid of the index2 bit05:38
Paul_46as we never used that05:38
Paul_46and just fetches a column05:38
dregad * Retrieve a result returned from a specific database query05:39
dregad * @param bool|ADORecordSet $p_result Database Query Record Set to retrieve next result for.05:39
Paul_46yea and that just uses pdo's fetch column05:39
Paul_46http://uk3.php.net/manual/en/pdostatement.fetchcolumn.php05:39
Paul_46Returns a single column from the next row of a result set or FALSE if there are no more rows.05:40
Paul_46so in next, it's fine05:40
Paul_46:)05:40
dregadbut it's not in 1.2.x05:41
Paul_46i'd still be inclined to make it a php bug :)05:41
Paul_46in any case, basically means we dont want to merge next<>master<>2.005:42
Paul_46but review patches manually05:42
dregadyou kinda said so the other day, did you not ?05:44
dregadso the guy is on 5.4.306:30
Paul_46he replied ?06:31
dregadyes06:32
Paul_46got a small test version script for this? :P06:35
dregadsure06:43
dregadyou want the mantis-based version, or bare-bones adodb ?06:44
*** Quits: kirillka (~Miranda@195.242.142.17) (Quit: kirillka)07:03
dregadsure07:07
dregad<?php07:11
dregadinclude( 'core.php' );07:11
dregadob_end_flush();07:11
dregad$sql = 'SELECT DISTINCT reporter_id FROM mantis_bugnote_table WHERE bug_id = ' . db_param();07:11
dregad$r = db_query_bound( $sql, array( 157 ) );07:11
dregadecho "query results (". $r->RecordCount() . " records)\n";07:11
dregadprint_r($r->Getarray());07:11
dregadecho "simplified NEXT code with endless loop protection\n";07:11
dregad$i = 0;07:11
dregadwhile( ( $t_user_id = db_result( $r ) ) && ( $i < $r->RecordCount() + 2 ) ) {07:11
dregadecho "$t_user_id\n";07:11
dregad$i++;07:11
dregad}07:11
dregadPaul_46 - run this from command line07:11
dregadin mantis home07:11
Paul_46argh07:27
Paul_46dont have a db07:27
Paul_46or do i07:27
* Paul_46 thinks07:28
Paul_46dregad07:33
dregadyo07:33
Paul_46which one works fine ?07:33
Paul_4603:11.23] <dregad> print_r($r->Getarray());07:33
Paul_46should fail ?07:33
dregadif I use only getarray, it's working OK (adodb returns an array of values)07:33
dregadthe problem is the processing done by db_result to return a single value07:34
dregadas the recordset is not respositioned07:34
dregadby adodb07:34
dregadin my code, this print_r just servers to show what is the expected results07:35
dregad*serves not servers07:35
dregadbasically, in 1.2.x, db_result does not have the behavior you mentioned earlier, i.e. get result for current record and position on next07:36
dregadconsequently you can't use it in a while loop like this07:36
Paul_46for( $i = 0;$i < $r->RecordCount();$i++ ) {07:37
Paul_46$t_user_id = db_result( $r, $i );07:37
Paul_46echo "$i $t_user_id\n";07:37
Paul_46}07:37
Paul_46that wroks fine07:37
Paul_46in php 5.3.1007:37
dregadfor me it doesn't07:38
dregadwith my test issue where 3 users posted bugnotes, it only returns 2 of them07:38
Paul_460 207:39
Paul_461 307:39
Paul_462 407:39
Paul_46http://pastebin.com/sH4H3DMU07:41
Paul_46so does that work or break07:41
Paul_46if you give it the correct bug id for you07:41
dregadwith my bug id, i get07:43
dregad3 2507:43
dregadbtw, probably missing a $r->MoveFirst(); after print_r07:44
dregadin which case I get07:44
dregad0 2507:44
dregad3 2707:44
dregadI would expect07:45
dregad0 2507:45
dregad1 2707:45
dregad2 2807:45
Paul_46so the code i linked doesn't work for you?07:49
dregadno08:14
dregadPaul_46 sorry I was away08:15
Paul_46mm, works fine here08:15
Paul_46:)08:15
Paul_46and that's on php5.3.1008:15
Paul_46are you using mysqli or mysql ?08:15
Paul_46actually that makes no difference08:16
Paul_46are you using php with suhosin?08:16
dregadyes08:16
Paul_46can you try without?08:16
dregadstandard ubuntu install08:16
Paul_46as if php5.3.10 is fine here and that's stock08:17
Paul_46must be something different with your setup08:17
Paul_46:)08:17
dregadnot just mine apparently08:18
Paul_46nods, 1 user08:18
dregadlooks like my setup indeed08:23
Paul_46? :)08:24
dregadjust tried on mantisbt.org with 14549 and get the expected 3 users08:24
dregadthat's on 5.3.2 /suhosin08:25
Paul_46i'd like to know why it breaks :P08:26
dregadme too08:26
Paul_46[i'd rather add a check to say 'this verison/combination is broken' then change code to fix broken versions08:27
dregadagreed08:27
Paul_46as the next version might break the opposite way :)08:27
Paul_46if it was a case of "its broken in windows but not linux" or vice versa08:28
Paul_46then adding code to handle is different08:28
Paul_46you know, this php function is only available in windows requires a code change to handle inu linux08:28
dregadso it's broken on my dev box here (ubuntu 12.04 / php 5.3.10 suhosin), but works on ubuntu/5.3.2 suhosin and also ok on sles 11/5.2.14 suhosin08:32
dregadi just have no idea what to do to find out why08:32
Paul_46yea08:34
Paul_46i'd normally compile from source08:35
Paul_46but well08:35
Paul_46we know 5.3.10 works08:35
Paul_46could get the package source from ubuntu08:35
Paul_46compile cmd line version08:35
Paul_46check it breaks08:35
Paul_46then try and turn off stuff e.g. dont include whatever patches they add to php08:35
Paul_46e.g. suhosin08:35
Paul_46one at a time and see when it starts to work08:36
dregadsounds like work :(08:36
dregadalso i'm not an expert in package management etc and I don't want to screw up my system08:37
dregadand by the way the 'next' code with while (db_results) still goes on endless loop with adodb08:43
dregadbut that's a different story08:43
Paul_46well ignore next :P08:50
*** Quits: giallu (~giallu@fedora/giallu) (Ping timeout: 246 seconds)09:02
dregadPaul_46, can you pls run this09:07
dregadvar_dump(function_exists( 'adodb_getall') );09:07
dregadit's false on the 2 systems where the function is behaving as expected09:08
dregadand true on my dev box where it fails09:08
Paul_46ahh09:12
Paul_46you have adodb's extension installed?09:12
dregadturns out I have got this 'adodb extension' enabled09:12
dregadI disabled it and now it works09:12
dregad:/09:13
dregadhow to spend one afternoon ;)09:13
Paul_46ubuntu install that by default?09:13
dregaddunno09:13
dregadi may have done it while testing ages ago09:13
Paul_46anyway, should be able to add a check on extension_loaded whether adodb is there09:14
Paul_46and say that for mantis we require it not to be :)09:14
dregadright09:15
dregadon my system the ini file was created in 201009:15
dregadthat does not tell me who did it (root :-/)09:16
dregadbut there's a good chance it was part of my tests09:16
dregadanyway this extension is way out-dated09:18
Paul_46well see if user has same crap :P09:18
dregadi'm updating the bug note09:19
dregadhttp://www.mantisbt.org/bugs/view.php?id=1455209:26
dregadgoing home09:31
dregadcya09:31
*** Quits: dregad (~dregad@155.250.128.35) (Quit: Ex-Chat)09:31
*** Joins: giallu (~giallu@fedora/giallu)14:12
*** Quits: giallu (~giallu@fedora/giallu) (Ping timeout: 246 seconds)16:32
*** Quits: sdfjkljkdfsljkl (~sdfjkljkd@static.96.23.63.178.clients.your-server.de) (Remote host closed the connection)17:00
*** Joins: sdfjkljkdfsljkl (~sdfjkljkd@static.96.23.63.178.clients.your-server.de)17:00
*** Quits: Paul_46 (~IceChat09@cpc1-enfi15-2-0-cust580.hari.cable.virginmedia.com) (Quit: For Sale: Intergalactic Proton Powered Electrical Tentacled Advertising Droids)17:37
*** Quits: micahg (~micahg@ubuntu/member/micahg) (Read error: Connection reset by peer)23:29
*** Joins: micahg (~micahg@ubuntu/member/micahg)23:29
*** Quits: micahg (~micahg@ubuntu/member/micahg) (Remote host closed the connection)23:30
*** Joins: micahg (~micahg@ubuntu/member/micahg)23:30
*** Joins: giallu (~giallu@fedora/giallu)23:35

Generated by irclog2html.py 2.10.0 by Marius Gedminas - find it at mg.pov.lt!