Re: [Gambas-devel] Cannot populate database Connection.Name from ODBC driver.
Brought to you by:
gambas
|
From: Benoît M. <ga...@us...> - 2017-08-18 01:25:29
|
Le 18/08/2017 à 02:26, zxMarce a écrit : > Hi there. This is mainly intended to be tackled by Benoît, but anyone with > the necessary knowledge (Toby?) please feel free to butt in. > > The ODBC driver can use Connection Strings since some time now. I also have > a patched up module that can run successfully non-data-producing queries > (the SQL_NO_DATA return code is no longer treated as an error), thanks to a > bug submitted by Piccoro. > > Problem is in the open_database() function. When using connstrings, the > database name is usually part of this string, and no .Name property is > expected to be populated from the BASIC program, nor actually used. > So, I'm trying to populate the property from the ODBC backend. I can > successfully fetch the DB Name from the lower level database driver in use > (SQLite3 does not provide a name, tho, be warned). > What I cannot do, be it via copying char[] or Gambas String buffer pointers, > is to get the .Name property populated back to the running BASIC program. > > The open_database() call has two parameters: DB_DESC *desc and DB_DATABASE > *db. My best guess is that I have to fiddle with desc, but not really sure > if that's correct nor exactly how. > > To further salt the issue, queries exist in big RDBMS that allow to > hot-switch databases while connected to a server (example: USE <newDBName> > in MSSQL). So, the connection's .Name property should also be "refetched" > after a successful query is run. > > Any suggestions? > > The open_database(DB_DESC *desc, DB_DATABASE *db) driver function takes two arguments: - DB_DESC *desc : a pointer to a structure that contains all connections string properties and an integer option field. - DB_DATABASE *db : a pointer to another structure that should be filled with all necessary information about the connection. By modifying the desc fields, you are modifying the corresponding Connection object properties, as this is where they are stored. But you must use GB.FreeString() and GB.NewString() to replace a string property value. For example: const char *new_value; GB.FreeString(&desc->name); // Free the Gambas string containing the old database name desc->name = GB.NewZeroString(new_value); // Create a new Gambas string from the zero-terminated string new_value, and store it. That's it. -- Benoît Minisini |