[Gambas-user] how to override Exec if already inherist from colection (conection pool emulation)

Christof Thalhofer chrisml at deganius.de
Thu Jul 5 15:44:18 CEST 2018


Am 03.07.2018 um 23:59 schrieb PICCORO McKAY Lenz:
> i already made my db pool emulation in rudimentary efforts..

I just saw the code. There is a caveat here. If you define connections
in a collection you have to access them like so:

Dim dbobj As New Dbex
dbobj["conex2"].Exec ...

This is annoying (and not very elegant) if you have to use a lot of
connections in your program, because you always have to write sth like
"conex2" by hand.

If you do not use too much databases (say, up to 50) you could do it
better using a static class with connections as properties, like in the
example class I attached.

Then you do not need to dim any connection and you can do sth simple like

Dbs.Conex1.Exec(sQuery)

Dbs.Conex2.Exec(sQuery)

anywhere in your program without the need to Dim it.

Also every connection exists just one time and lives as long as your
program runs, this is very cool as it avoids the creation of multiple
similar connections to the same db which can easily lead to deadlocks.


Alles Gute

Christof Thalhofer

-- 
[x] nail here for new monitor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Dbs.class
Type: application/x-java
Size: 1707 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180705/e7272985/attachment.bin>


More information about the User mailing list