[Gambas-user] Connection via ODBC

First Last d4t4full at gmail.com
Mon Oct 19 20:09:07 CEST 2020

Gianluigi et al,

With the usual *I need to connect to database XXX using ODBC* claim, I
think a couple of clarifications are needed.

1- Important: The Gambas ODBC interface targets unixODBC, not iODBC
(actually I did not test against iODBC myself; it may or may not work).

2- ODBC is not a database driver per-sé; instead, it is a *Driver Manager*.

You do not connect to a *FooBar* database with ODBC, you connect to a
*FooBar* database with a *FooBar ODBC Driver*, managed by ODBC.
That is why all connection strings have at the very least a
*Driver={FooBar}* parameter; it tells ODBC which actual low-level,
ODBC-compliant driver to use.
In turn, the Gambas application uses the standardized database-interface
offered by ODBC to send/receive queries/data to/from the actual database.

ODBC is, then, some kind of "middle man" standing between the actual
low-level connectivity driver and your application, "filing the burrs"
between them.

The advantage is simple yet powerful: Your application can connect to a
DB2, MySQL, MSSQL or any other database that provides an ODBC-compliant
driver, and you do (almost-)nothing at the application level to issue
queries and get results back. You want to change DB2 for MySQL? Change the
connstring, and you're mostly done... Well, yes, subtle differences between
vendor database features may call for some kind of code adjusting, but it
is usually minimal... or that's at least the goal.


On Mon, Oct 19, 2020 at 2:45 PM Gianluigi <bagonergi at gmail.com> wrote:

> Il giorno lun 19 ott 2020 alle ore 19:35 First Last <d4t4full at gmail.com>
> ha scritto:
>> (Sorry for the "mailus interruptus", I'll start over.)
>> In *this link*
>> <https://www.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.apdv.cli.doc/doc/t0006349.html>
>> you'll find info about setting up the whole DB2 under ODBC environment for
>> Linux/Unix, courtesy of IBM.
>> Note that since Aug 2015, though, there are two ways to set up pretty
>> much *any* database using ODBC in Gambas.
>> The first one is setting up the whole unixODBC Driver Manager environment
>> as above described and normally used, but it takes time, is kind of
>> error-prone and tiresome if you have to deploy the same app to a bunch of
>> end users (same setup over and over...).
>> The second approach I tried to assimilate as smoothly as possible to
>> whatever already existed, and is similar to what exists on Windows
>> platforms, and it is the use of "Connection Strings".
>> Basically, you tell ODBC all the settings that normally go in the several
>> ODBC config files in a single string, and the ODBC Driver Manager will take
>> care of the connection.
>> This is an example Connection String for connecting to a MSSQL Server
>> 2005 using freeTDS from ODBC
>> *"Driver=FreeTDS;TDS_Version=7.2;Server={serverIP};Port=1433;Database={databaseName};UId={userName};Password={password}"*
>> In Gambas, you'd connect this way:
>> *' Gambas class file*
>> *Private $conn As Connection*
>> *'[...]*
>> *Private Sub Connect(connString As String)*
>> *  $conn = New Connection*
>> *  $conn.Type = "odbc" 'Yup, lowercase.*
>> *  $conn.Host = connString*
>> *  $conn.Open()*
>> *End*
>> You just call Connect() with the adequate connection string.
>> Now, parameters for the vast amount of different drivers depend on the
>> actual driver used by ODBC (unfortunately, I don't have access to anything
>> besides MSSQL), as an example, the *TDS_Version* parameter in the
>> example above sets some defaults in FreeTDS so it knows "beforehand" to
>> what kind of server it will connect.
>> Beware: Some parameters may, others WILL, affect connectivity and may
>> also impact overall speed.
>> HTH,
>> zxMarce.
> Hi,
> thank you very much, I pass the information to our friend immediately...
> Regards
> Gianluigi
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201019/a65942d2/attachment.htm>

More information about the User mailing list