Help with libdbi code

Colin Law clanlaw at
Fri May 6 17:29:07 EDT 2016

On 6 May 2016 at 22:13, John Ralls <jralls at> wrote:
>> On May 6, 2016, at 11:17 AM, Colin Law <clanlaw at> wrote:
>> I want to add some code to adjust the mysql sql_options if necessary,
>> in order to avoid bug #765872 [1].  I believe that this needs to be
>> called from gnc-backend-dbi.c in gnc_dbi_mysql_session_begin.  I need
>> to adjust the options after the mysql connection is made but before
>> the database is opened (since I need to do it before creating the
>> database in the case that the database does not already exist).  I
>> thought that I should do it before the call to dbi_conn_error_handler
>> at line 867 (maint branch) but cannot get it to work there.  If,
>> however, I put it after the line
>> result = dbi_conn_connect( be->conn );
>> then (provided the database already exists) it does work.
>> The failing code is
>>    result = dbi_conn_query( connection, "SELECT @@sql_mode");
>> If the database has not been opened then this returns NULL, but when I
>> then call dbi_conn_error this returns 0, which seems odd. The error
>> message is also empty.
>> If I run the SELECT query from the mysql command line before opening a
>> database then it works correctly.
>> Can anyone point out where I am going wrong?
> Colin,
> If you've got dbi_conn_error_handler() at line 867 you're looking at the master branch (it will be gnc-backend-dbi.cpp unless you have an old commit). It's at line 841 in maint.

Yes, you are right, I looked at the wrong file to get the line number,
I am actually working with the right file.  I couldn't get the line
number from my working copy as I have inserted the function to do the
changes above that point.  Sorry for the confusion.

> Yes, of course it needs to go after dbi_conn_connect: That's what connects to the server. Up to that point you're just talking to the dbi driver.

Ah, I misunderstood, I assumed that dbi_conn_new_r connected to the
server.  I will have to go and look at the docs more carefully.

>  Look at the DB creation code a little further down to see how to connect to the server without connecting to a database, but notice that you'll have to disconnect and reconnect with the database when you're finished. That means that either you set the sql_mode with the database connected--and it sounds from above like that works--or you permit the gnucash user to have SUPER privilege, which I think would be a tough sell if the server is also being used for other things.

Thanks, I will look at that.  I don't fully follow what you are saying
about SUPER privileges, but will go away and think about it some more.



More information about the gnucash-devel mailing list