mwild1 / luadbi

Multi-backend SQL database library for Lua
MIT License
38 stars 14 forks source link

Suggestion to further improve connection and statement registration #30

Closed GoogleCodeExporter closed 6 years ago

GoogleCodeExporter commented 8 years ago
I spent some time messing with the Debian luadbi package trying to get it work 
with LUA 5.2 before I realised that this work had already been performed 
recently.  I arrived at a similar solution to the issue but there are a couple 
of advantages to the way I did it that could be useful to apply.

Firstly, I have factored out the code that is used to register the LUA for 
connection and statement objects into a single function.  This means any 
further changes can be made in one place.

Secondly, I have amended the registration code to no longer create global 
variables or pollute the package.loaded table.  This also allows the Connect 
method to be simplified and not contain conditional code based on the LUA 
version.

I have tested this with LUA 5.1 and LUA 5.2 against SQLite3 and DB2 and it is 
working nicely for me.  However, please note that I have never used the LUA C 
API before this week so there may be subtle problems with the code I haven't 
noticed.

I thought it was worth sharing though.

Original issue reported on code.google.com by lbbrow...@gmail.com on 14 Jun 2015 at 5:19

Attachments:

sparked435 commented 8 years ago

Still evaluating this patch - it survives the unit tests I just checked in under 5.2. That being said the tests are also new, I'd prefer to be through and try 5.1 and some of my applications.

sparked435 commented 6 years ago

Patch appears to work nicely, committed.