Help with libdbi code
jralls at ceridwen.us
Fri May 6 17:13:44 EDT 2016
> On May 6, 2016, at 11:17 AM, Colin Law <clanlaw at gmail.com> wrote:
> I want to add some code to adjust the mysql sql_options if necessary,
> in order to avoid bug #765872 . 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?
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, 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. 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.
More information about the gnucash-devel