*** 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 | |
dregad | Paul_46 - can I pick your brains | 04:25 |
---|---|---|
dregad | I know what you think about adodb but still this is bugging me as I don't understand what's happening | 04:25 |
dregad | consider this code | 04:25 |
dregad | $sql = 'SELECT DISTINCT reporter_id FROM mantis_bugnote_table WHERE bug_id = 157'; | 04:26 |
dregad | $r = $db->Execute( $sql ); | 04:26 |
dregad | for( $i = 0; $i < $r->RecordCount(); $i++) { | 04:26 |
dregad | var_dump( db_result($r, $i) ); | 04:26 |
dregad | echo "$i\n"; | 04:26 |
dregad | } | 04:26 |
dregad | -- loosely adapted from email_api.php / email_collect_recipients() | 04:27 |
dregad | the strange thing is, that the loop is executed only once in my test case | 04:27 |
dregad | even though the query returns 3 records | 04:27 |
dregad | after the call to $p_result->GetArray() in db_result(), the value of $i is bumped to 3 | 04:28 |
dregad | how is that possible !? | 04:28 |
Paul_46 | on what db engine? | 04:32 |
dregad | mysql | 04:34 |
Paul_46 | so your saying it prints | 04:35 |
Paul_46 | 0, 3 | 04:35 |
dregad | i mean, regardless of adodb and the dbengine, how can a function alter the value in the caller's space | 04:35 |
Paul_46 | ? | 04:35 |
dregad | if you omit the var_dump(), yes | 04:35 |
Paul_46 | if you remove the whole var_dump line includign the db_result does it still print 0,3? | 04:36 |
dregad | and btw, the same occurs if you call $r->GetArray() directly, so db_result() is not the culprit here | 04:36 |
dregad | no, in that case it goes 0,1,2 | 04:36 |
Paul_46 | well first off if there's a & type thing around | 04:38 |
Paul_46 | i.e. function getarray( &$r ) | 04:38 |
Paul_46 | but i can't see that if that's the cae | 04:38 |
dregad | nope, no & in adodb.inc.php | 04:39 |
Paul_46 | if you do for (4i=0; $i < 3; $i++ ) wwhat doesi t do | 04:40 |
dregad | function GetArray($nRows = -1) | 04:40 |
dregad | { | 04:40 |
dregad | global $ADODB_EXTENSION; if ($ADODB_EXTENSION) { | 04:40 |
dregad | $results = adodb_getall($this,$nRows); | 04:40 |
dregad | return $results; | 04:40 |
dregad | } | 04:40 |
dregad | $results = array(); | 04:40 |
dregad | $cnt = 0; | 04:40 |
dregad | while (!$this->EOF && $nRows != $cnt) { | 04:40 |
dregad | $results[] = $this->fields; | 04:40 |
dregad | $this->MoveNext(); | 04:40 |
dregad | $cnt++; | 04:40 |
dregad | } | 04:40 |
dregad | return $results; | 04:40 |
dregad | } | 04:40 |
dregad | let me check | 04:40 |
Paul_46 | i'm inclined to think what php version | 04:41 |
dregad | same thing | 04:41 |
dregad | i'm on 5.3.10 here | 04:41 |
Paul_46 | so for ( $i = 0 to 3 ) { GetArray(); print $i} returns 0,3 | 04:42 |
Paul_46 | and for ( $i = 0 to 3 ) { print $i} returns 0,1,2,3 | 04:42 |
dregad | yep | 04:43 |
Paul_46 | can you run a different php version ? | 04:44 |
dregad | I think I have a 5.2. somewhere | 04:44 |
Paul_46 | I was thinking newer | 04:45 |
Paul_46 | 5.4.5 or 5.3.15 | 04:45 |
dregad | Not sure I want to mess with this box atm ;) | 04:45 |
Paul_46 | anyway | 04:45 |
Paul_46 | should just get rid of adodb | 04:45 |
Paul_46 | :) | 04:45 |
dregad | I knew you'd say that | 04:46 |
dregad | :P | 04: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_46 | what file ? | 04:47 |
Paul_46 | email api ? | 04:47 |
dregad | yes | 04:47 |
dregad | line ~260 | 04:47 |
dregad | http://www.mantisbt.org/bugs/view.php?id=14549 | 04:47 |
Paul_46 | https://github.com/mantisbt/mantisbt/blob/next/application/core/email_api.php | 04:49 |
Paul_46 | dhx changed iti n next already / | 04:49 |
Paul_46 | effectively with https://github.com/mantisbt/mantisbt/commit/153577f000aa80ad9072045359400a444d1b8ec6 | 04:50 |
Paul_46 | and whilst it says 3 months ago | 04:51 |
Paul_46 | that's due to rebasing etc | 04:51 |
Paul_46 | so was actually changedi n Author: Paul <paul@mantisforge.org> 2011-04-19 21:54:33 | 04:51 |
Paul_46 | 16 months ago | 04:51 |
dregad | btw, must indeed be a php version thing, because on my 5.2.14 server here, it works | 04:54 |
dregad | backporting that code to 1.2.x still shows the erroneous behavior | 05:02 |
Paul_46 | hmm | 05:03 |
Paul_46 | can you see what first version of 5.3 it works on ? ;p | 05:03 |
Paul_46 | assuming it works on 5.3.15 and not 5.3.10 | 05:04 |
dregad | probably not worth the effort... | 05:09 |
dregad | i'll just get rid of db_result and use db_fetch_array | 05:09 |
Paul_46 | well | 05:09 |
Paul_46 | no | 05:09 |
Paul_46 | if it's a php version issue | 05:10 |
Paul_46 | we dont need to make a change | 05:10 |
Paul_46 | TBH | 05:10 |
Paul_46 | and the code works fine as it is | 05:10 |
Paul_46 | so no change required :) | 05:10 |
Paul_46 | if there's a broken php version out there, we should identify the broken php version | 05:12 |
Paul_46 | and just make sure users aren't running it | 05:12 |
Paul_46 | rather then work around it | 05:12 |
Paul_46 | as what you are basically saying is we should never use db_result | 05:12 |
Paul_46 | and if you can produce the bug in a db setup, shouldnt' be too hard to try with 5.3.15 | 05:14 |
Paul_46 | other option is just bump the minimum requirements to 5.3.11 | 05:17 |
Paul_46 | as we know 5.3.10 is broken in some way | 05:17 |
dregad | no, what I'm saying is that it does not make sense to use db_result in this context | 05:32 |
dregad | or rather, in that way | 05:32 |
dregad | db_result expects a recordset in the right position and returns the corresponding value | 05:33 |
Paul_46 | my point was more | 05:33 |
Paul_46 | as it's already been changed in next | 05:33 |
Paul_46 | there shouldn't be any point in changing it | 05:33 |
dregad | if you look at the loop, the recordset is never re-positioned | 05:33 |
Paul_46 | or well | 05:33 |
Paul_46 | gonna be fun merging | 05:33 |
Paul_46 | if we do different implementations of the same fixes | 05:33 |
dregad | it's not the *same* fix | 05:34 |
dregad | you got rid of record_count() | 05:34 |
dregad | the code in next will just end up in an endless loop | 05:35 |
dregad | i'm sure you'll agree that's a bug :P | 05:35 |
Paul_46 | i 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_46 | gah | 05:35 |
dregad | i'm not touching the sql at all | 05: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_46 | while( $t_user_id = db_result( $t_result ) ) { | 05:35 |
Paul_46 | $t_recipients[$t_user_id] = true; | 05:35 |
Paul_46 | is what the current latest version of that code block looks like | 05:36 |
dregad | this ==> while( $t_user_id = db_result( $t_result ) ) { <== will loop forever | 05:36 |
Paul_46 | how'd you work that one out | 05:37 |
Paul_46 | :) | 05:37 |
dregad | just try it | 05:37 |
Paul_46 | also it might in new db layer it doesn't ;p | 05:37 |
dregad | in that case, you changed the definition of the function too | 05:37 |
Paul_46 | function db_result( $p_result, $p_index1 = 0 ) { | 05:37 |
Paul_46 | ---- | 05:38 |
Paul_46 | function db_result( $p_result, $p_index1 = 0 ) { | 05:38 |
Paul_46 | return $p_result->fetchColumn($p_index1); | 05:38 |
Paul_46 | } | 05:38 |
Paul_46 | is the new version | 05:38 |
Paul_46 | so gets rid of the index2 bit | 05:38 |
Paul_46 | as we never used that | 05:38 |
Paul_46 | and just fetches a column | 05:38 |
dregad | * Retrieve a result returned from a specific database query | 05:39 |
dregad | * @param bool|ADORecordSet $p_result Database Query Record Set to retrieve next result for. | 05:39 |
Paul_46 | yea and that just uses pdo's fetch column | 05:39 |
Paul_46 | http://uk3.php.net/manual/en/pdostatement.fetchcolumn.php | 05:39 |
Paul_46 | Returns a single column from the next row of a result set or FALSE if there are no more rows. | 05:40 |
Paul_46 | so in next, it's fine | 05:40 |
Paul_46 | :) | 05:40 |
dregad | but it's not in 1.2.x | 05:41 |
Paul_46 | i'd still be inclined to make it a php bug :) | 05:41 |
Paul_46 | in any case, basically means we dont want to merge next<>master<>2.0 | 05:42 |
Paul_46 | but review patches manually | 05:42 |
dregad | you kinda said so the other day, did you not ? | 05:44 |
dregad | so the guy is on 5.4.3 | 06:30 |
Paul_46 | he replied ? | 06:31 |
dregad | yes | 06:32 |
Paul_46 | got a small test version script for this? :P | 06:35 |
dregad | sure | 06:43 |
dregad | you want the mantis-based version, or bare-bones adodb ? | 06:44 |
*** Quits: kirillka (~Miranda@195.242.142.17) (Quit: kirillka) | 07:03 | |
dregad | sure | 07:07 |
dregad | <?php | 07:11 |
dregad | include( 'core.php' ); | 07:11 |
dregad | ob_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 |
dregad | echo "query results (". $r->RecordCount() . " records)\n"; | 07:11 |
dregad | print_r($r->Getarray()); | 07:11 |
dregad | echo "simplified NEXT code with endless loop protection\n"; | 07:11 |
dregad | $i = 0; | 07:11 |
dregad | while( ( $t_user_id = db_result( $r ) ) && ( $i < $r->RecordCount() + 2 ) ) { | 07:11 |
dregad | echo "$t_user_id\n"; | 07:11 |
dregad | $i++; | 07:11 |
dregad | } | 07:11 |
dregad | Paul_46 - run this from command line | 07:11 |
dregad | in mantis home | 07:11 |
Paul_46 | argh | 07:27 |
Paul_46 | dont have a db | 07:27 |
Paul_46 | or do i | 07:27 |
* Paul_46 thinks | 07:28 | |
Paul_46 | dregad | 07:33 |
dregad | yo | 07:33 |
Paul_46 | which one works fine ? | 07:33 |
Paul_46 | 03:11.23] <dregad> print_r($r->Getarray()); | 07:33 |
Paul_46 | should fail ? | 07:33 |
dregad | if I use only getarray, it's working OK (adodb returns an array of values) | 07:33 |
dregad | the problem is the processing done by db_result to return a single value | 07:34 |
dregad | as the recordset is not respositioned | 07:34 |
dregad | by adodb | 07:34 |
dregad | in my code, this print_r just servers to show what is the expected results | 07:35 |
dregad | *serves not servers | 07:35 |
dregad | basically, in 1.2.x, db_result does not have the behavior you mentioned earlier, i.e. get result for current record and position on next | 07:36 |
dregad | consequently you can't use it in a while loop like this | 07:36 |
Paul_46 | for( $i = 0;$i < $r->RecordCount();$i++ ) { | 07:37 |
Paul_46 | $t_user_id = db_result( $r, $i ); | 07:37 |
Paul_46 | echo "$i $t_user_id\n"; | 07:37 |
Paul_46 | } | 07:37 |
Paul_46 | that wroks fine | 07:37 |
Paul_46 | in php 5.3.10 | 07:37 |
dregad | for me it doesn't | 07:38 |
dregad | with my test issue where 3 users posted bugnotes, it only returns 2 of them | 07:38 |
Paul_46 | 0 2 | 07:39 |
Paul_46 | 1 3 | 07:39 |
Paul_46 | 2 4 | 07:39 |
Paul_46 | http://pastebin.com/sH4H3DMU | 07:41 |
Paul_46 | so does that work or break | 07:41 |
Paul_46 | if you give it the correct bug id for you | 07:41 |
dregad | with my bug id, i get | 07:43 |
dregad | 3 25 | 07:43 |
dregad | btw, probably missing a $r->MoveFirst(); after print_r | 07:44 |
dregad | in which case I get | 07:44 |
dregad | 0 25 | 07:44 |
dregad | 3 27 | 07:44 |
dregad | I would expect | 07:45 |
dregad | 0 25 | 07:45 |
dregad | 1 27 | 07:45 |
dregad | 2 28 | 07:45 |
Paul_46 | so the code i linked doesn't work for you? | 07:49 |
dregad | no | 08:14 |
dregad | Paul_46 sorry I was away | 08:15 |
Paul_46 | mm, works fine here | 08:15 |
Paul_46 | :) | 08:15 |
Paul_46 | and that's on php5.3.10 | 08:15 |
Paul_46 | are you using mysqli or mysql ? | 08:15 |
Paul_46 | actually that makes no difference | 08:16 |
Paul_46 | are you using php with suhosin? | 08:16 |
dregad | yes | 08:16 |
Paul_46 | can you try without? | 08:16 |
dregad | standard ubuntu install | 08:16 |
Paul_46 | as if php5.3.10 is fine here and that's stock | 08:17 |
Paul_46 | must be something different with your setup | 08:17 |
Paul_46 | :) | 08:17 |
dregad | not just mine apparently | 08:18 |
Paul_46 | nods, 1 user | 08:18 |
dregad | looks like my setup indeed | 08:23 |
Paul_46 | ? :) | 08:24 |
dregad | just tried on mantisbt.org with 14549 and get the expected 3 users | 08:24 |
dregad | that's on 5.3.2 /suhosin | 08:25 |
Paul_46 | i'd like to know why it breaks :P | 08:26 |
dregad | me too | 08:26 |
Paul_46 | [i'd rather add a check to say 'this verison/combination is broken' then change code to fix broken versions | 08:27 |
dregad | agreed | 08:27 |
Paul_46 | as the next version might break the opposite way :) | 08:27 |
Paul_46 | if it was a case of "its broken in windows but not linux" or vice versa | 08:28 |
Paul_46 | then adding code to handle is different | 08:28 |
Paul_46 | you know, this php function is only available in windows requires a code change to handle inu linux | 08:28 |
dregad | so 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 suhosin | 08:32 |
dregad | i just have no idea what to do to find out why | 08:32 |
Paul_46 | yea | 08:34 |
Paul_46 | i'd normally compile from source | 08:35 |
Paul_46 | but well | 08:35 |
Paul_46 | we know 5.3.10 works | 08:35 |
Paul_46 | could get the package source from ubuntu | 08:35 |
Paul_46 | compile cmd line version | 08:35 |
Paul_46 | check it breaks | 08:35 |
Paul_46 | then try and turn off stuff e.g. dont include whatever patches they add to php | 08:35 |
Paul_46 | e.g. suhosin | 08:35 |
Paul_46 | one at a time and see when it starts to work | 08:36 |
dregad | sounds like work :( | 08:36 |
dregad | also i'm not an expert in package management etc and I don't want to screw up my system | 08:37 |
dregad | and by the way the 'next' code with while (db_results) still goes on endless loop with adodb | 08:43 |
dregad | but that's a different story | 08:43 |
Paul_46 | well ignore next :P | 08:50 |
*** Quits: giallu (~giallu@fedora/giallu) (Ping timeout: 246 seconds) | 09:02 | |
dregad | Paul_46, can you pls run this | 09:07 |
dregad | var_dump(function_exists( 'adodb_getall') ); | 09:07 |
dregad | it's false on the 2 systems where the function is behaving as expected | 09:08 |
dregad | and true on my dev box where it fails | 09:08 |
Paul_46 | ahh | 09:12 |
Paul_46 | you have adodb's extension installed? | 09:12 |
dregad | turns out I have got this 'adodb extension' enabled | 09:12 |
dregad | I disabled it and now it works | 09:12 |
dregad | :/ | 09:13 |
dregad | how to spend one afternoon ;) | 09:13 |
Paul_46 | ubuntu install that by default? | 09:13 |
dregad | dunno | 09:13 |
dregad | i may have done it while testing ages ago | 09:13 |
Paul_46 | anyway, should be able to add a check on extension_loaded whether adodb is there | 09:14 |
Paul_46 | and say that for mantis we require it not to be :) | 09:14 |
dregad | right | 09:15 |
dregad | on my system the ini file was created in 2010 | 09:15 |
dregad | that does not tell me who did it (root :-/) | 09:16 |
dregad | but there's a good chance it was part of my tests | 09:16 |
dregad | anyway this extension is way out-dated | 09:18 |
Paul_46 | well see if user has same crap :P | 09:18 |
dregad | i'm updating the bug note | 09:19 |
dregad | http://www.mantisbt.org/bugs/view.php?id=14552 | 09:26 |
dregad | going home | 09:31 |
dregad | cya | 09: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!