drogon
drogon copied to clipboard
execSqlSync stuck
I am new to this framework, and I am trying to learn through the Wiki provided. In the database connection part, when I try to execute a SQL command using execSqlSync, which is as I found out is blocking, it hangs there and does not finish execution. This is my application code,
auto dbClientPtr = drogon::app().getDbClient();
try {
auto result = dbClientPtr->execSqlSync("select * from <table_name>");
} catch (const drogon::orm::DrogonDbException &e) {
std::cerr<<"Error: "<<e.base().what()<<std::endl;
}
There is nothing wrong with the connection parameters I have provided in the config.json file, I have tested them using psql.
Could you check your settings in config file and in C++ code: do you use client name? Is it the same in config and C++ code. Config file:
"db_clients": [
{
"name":"myClientName",
C++ controller code:
auto dbClientPtr = drogon::app().getDbClient("myClientName");
Inside of controller this code works. Also check DLL location in PATH variable. If you have Release DLL in PATH, but run Debug version of application, application will use release all version with undefined consequences. I usually copy debug DLL to the Debug directory to exe application. Sorry, assume you are on Windows.
I have specified the config file as you've specified and passed the name of db client as arfument in getDbClient(), it hasn't fixed the issue. Also, with respect to the DLL path, I didn't fully get you. I'm running this on Mac.
-
Check the error log to see if there is connection issue.
-
Add timeout for sql query in db_clients config, and try again.
- Check the size of data set, returning by select * from <table_name> . Construction of the collection for "auto result" in debug mode require time. If it is 10000> records, it will take significant time (10th seconds or minutes). Release version of C++ STD library much faster. Try it on 1 record.
- Installation instruction require install database support first, then install Drogon. At least it was my case.
I am seeing the same issue with the query select exists(select 1 from migrations where version = 1) as exists
in postgres. If I look at postgres it seems like that the query is never even fired.
I am seeing the same issue with the query select exists(select 1 from migrations where version = 1) as exists in postgres. If I look at postgres it seems like that the query is never even fired.
@MTRNord At least, when you setup everything first time, then everything (this and all your new database code) works smooth and fast. Try to start from looking into PostgreSQL log file. If user does not have enough access right to connect server, database or table, you can see an error message.
My second advice - always include try { } catch(){} block around database call and place breakpoint into catch block - like in the example above, I copied here :
} catch (const drogon::orm::DrogonDbException &e) {
std::cerr<<"Error: "<<e.base().what()<<std::endl;
}
Usually if you have any problem or error, database handling code throws exception with error message. It is not likely , that you got error, but here was no exception.
I am seeing the same issue with the query select exists(select 1 from migrations where version = 1) as exists in postgres. If I look at postgres it seems like that the query is never even fired.
@MTRNord At least, when you setup everything first time, then everything (this and all your new database code) works smooth and fast. Try to start from looking into PostgreSQL log file. If user does not have enough access right to connect server, database or table, you can see an error message.
My second advice - always include try { } catch(){} block around database call and place breakpoint into catch block - like in the example above, I copied here :
} catch (const drogon::orm::DrogonDbException &e) { std::cerr<<"Error: "<<e.base().what()<<std::endl; }
Usually if you have any problem or error, database handling code throws exception with error message. It is not likely , that you got error, but here was no exception.
In the end it turned out that due to using the Fast db thingy I ended up deadlocking the application. After switching to async Mode it works :)