Adodb bug in GenID in recent windows php vers

bradymiller wrote on Thursday, August 09, 2012:

Hi,

Finally got around to testing most recent XAMPP (1.8.0) with OpenEMR and noted a bad bug where all calls to the adodb GenID() function were incrementing the sequences table, but always returning zero with the audit engine both off and on(Note this bug does not happen on linux). This causes the encounter numbers to use current date instead of an id and assigns all the forms with a 0 id number; ie. a very bad bug. The fix to this was actually traced back to the GenID() function in library/adodb/drivers/adodb-mysql.inc.php; here is the fix:
http://github.com/bradymiller/openemr/commit/c8f20f3e69972d274ee3f2327050f37a67beac0e

Was hoping others (especially yehster) may have some input here if there is a way to migrate this fix to library/sql.inc to avoid needing to change the adodb library (otherwise, would then need to remember/test this when upgrade adodb in the future).

At least OpenEMR will now support recent version of php/mysql on windows, though.

-brady
OpenEMR

yehster wrote on Thursday, August 09, 2012:

If you copied and pasted the whole modified GenID() function into the ADODB_mysql_log class at the top of sql.inc your version would override the standard adodb version.

Also on ADODB’s website
http://phplens.com/lens/adodb/docs-adodb.htm#hack
This isn’t exactly the same as the current subclassing method, but it’s similar.

yehster wrote on Thursday, August 09, 2012:

Something that might provide some additional insight.
1. Copy and paste GenID from adodb-mysql.inc.php into  ADODB_mysql_log class in sql.inc
2. Change the references to Execute to ExecuteNoLog in the newly included GenID function but leave alone your other change.

$this->genID = mysql_insert_id($this->_connectionID);

and whether that approach fixes the GenID returns zero issue.

yehster wrote on Thursday, August 09, 2012:

http://php.net/manual/en/function.mysql-insert-id.php

Return Values

The ID generated for an AUTO_INCREMENT column by the previous query on success, 0 if the previous query does not generate an AUTO_INCREMENT value, or FALSE if no MySQL connection was established.

What might be happening is that the calls to the overridden Execute function makes second call to _insert_id().  That then resets mysql_insert_id  (the last query was no longer the insert itself, but the select to get the ID), hence we get a value of zero. Thus using ExecuteNoLog in GenID instead may prevent the extra select while in the process of retrieving the next ID. 

bradymiller wrote on Thursday, August 09, 2012:

awesome yehster,

I simply copied the original GenID() function to sql.inc and changed the Execute() calls to ExecuteNoLog(); and it works. Much cleaner. Here’s the code:
http://github.com/bradymiller/openemr/commit/3891a7144567de92542ca5fb28861d3ff42636b2

-brady
OpenEMR

bradymiller wrote on Friday, August 17, 2012:

Hi,
Forgot to mention that I committed this fix to both master and rel-411 last week. OpenEMR (4.1.1+) should now work with all new versions of XAMPP/WAMP/etc.
-brady
OpenEMR

jeyaramt wrote on Sunday, January 18, 2015:

Getting File missing error for adodb-mysql_log.inc.php

cmswest wrote on Monday, January 19, 2015:

Is this for the latest xampp download ?

Have you looked in the directory, /xampp/htdocs/openemr/library/adodb/drivers/ , to confirm it’s missing?