[Gambas-devel] Change to gb.db.odbc to use ODBC Connection Strings.

Tobias Boege taboege at ...176...
Thu Aug 27 15:49:55 CEST 2015


On Thu, 27 Aug 2015, zxMarce wrote:
> Beno??t,
> 
> It's alive! Mbwehehehe...
> Well, kind of. It does work as intended, but the connection's *.User*
> property must be set to something, even if it is not the real username from
> the connection string. Otherwise, if the *.User* property is not set: Bam!
> *SegFault*.
> 
> This connects OK (using 'Johnny' as user name in the conn string, but not in
> the conn.User property):
> 
> This explodes with SegFault (also using 'Johnny' as user name in the conn
> string):
> 
> So, here's where my C drowns. I do not know the "chain of command" (I mean,
> what is called by who), and thus I have no way of knowing what code needs
> the *.User* property populated.
> I saw several debug blocks like this in the code but I don't know how to
> properly activate them, or where to look for their output once they're
> active:
> 
> Care to throw me a 'pointer' to where I should start?
> I need to know what happens at low level when Gambas runs Connection.Open; I
> mean the whole code and file paths that end in *gb.db.odbc/src/main.c*, so I
> can check every step.
> Also, knowing this, maybe I can make some progress regarding the *RowCount =
> -1* that MSSQL usually returns when running a query that returns a Result.
> 

Have a look at main/lib/db. This is the gb.db component which declares the
Connection class. As I don't know how far you've come with programming
components in Gambas, I'll point you to things in small steps.

If you are interested in Connection, open CConnection.c and look for the
declaration of the class interface which you will usually find at the end of
the source file:

  GB_DESC CConnectionDesc[] =
  {
  	GB_DECLARE("_Connection", sizeof(CCONNECTION)),
	...
  };

Notice that the class being declared is actually named "_Connection". But
this is the base class for gb.db's Connection (the real Connection class
is written in the Gambas part of the component and inherits _Connection).

You can find the implementation of Connection.Open by parsing this interface
description: it is the function CCONNECTION_open(). From there you trace
your way to open_connection() where the important line is:

  if (DB_Open(&THIS->desc, &THIS->driver, &THIS->db))
  	return;

DB_Open() brings you to main.c where you learn that different database types
are implemented by driver structures. The gb.db.mysql component declares a
driver structure for converting access to the Connection object into MySQL
language, the gb.db.sqlite3 does the same for SQLite3, etc..

Similarly gb.db.odbc has a DECLARE_DRIVER statement somewhere in its main.c.
There it lists ODBC-specific implementations of various methods of the
Connection class. This should enable you to trace the complete path from
the Connection class to your driver.

I think you should not just call the user "Johnny". If there is no sensible
username in ODBC, return an empty string.

Also, as you may not be aware of it, I have written an article about native
component programming for Gambas. It is here[0] and may be of some use for
you.

Regards,
Tobi

[0] http://www-e.uni-magdeburg.de/tboege/gambas/

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the Devel mailing list