Most seems to work. Multi threading is not optimal
however some points use a timeout with select or wait_for to poll a condition at the same time.
|
|
@ -130,7 +130,11 @@ bool ASyncDBConnection::Thread::makeConnection()
|
|||
auto keywords = m_config.getKeywords();
|
||||
auto values = m_config.getValues();
|
||||
#if true
|
||||
return m_connection.connect(keywords, values, 0);
|
||||
bool result = m_connection.connect(keywords, values, 0);
|
||||
if (result) {
|
||||
doStateCallback(State::Connected);
|
||||
}
|
||||
return result;
|
||||
#else
|
||||
while (!terminateRequested) {
|
||||
|
||||
|
|
@ -234,11 +238,12 @@ void ASyncDBConnection::Thread::doStateCallback(State state)
|
|||
|
||||
void ASyncDBConnection::Thread::waitForAndSendCommand()
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
// lock the data
|
||||
std::unique_lock<std::mutex> lk(m_commandQueue.m_mutex);
|
||||
if (m_commandQueue.m_queue.empty()) {
|
||||
// no data wait till there is data
|
||||
m_commandQueue.m_newEvent.wait(lk);
|
||||
m_commandQueue.m_newEvent.wait_for(lk, 1000ms);
|
||||
// can we use the predicate to reimplement the stop function???, []{return ready;});
|
||||
|
||||
}
|
||||
|
|
@ -266,30 +271,26 @@ void ASyncDBConnection::Thread::waitForAndSendCommand()
|
|||
|
||||
void ASyncDBConnection::Thread::doNewCommand()
|
||||
{
|
||||
// todo: send command
|
||||
// get command from top of queue (but leave it in the queue, we need the callback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lg(m_commandQueue.m_mutex);
|
||||
if (! m_commandQueue.m_queue.empty()) {
|
||||
const Command &command = m_commandQueue.m_queue.front();
|
||||
if (!command.command.empty()) {
|
||||
bool query_send = false;
|
||||
if (command.params.empty())
|
||||
query_send = m_connection.sendQuery(command.command.c_str());
|
||||
else
|
||||
query_send = m_connection.sendQueryParams(command.command.c_str(), command.params);
|
||||
if (! m_commandQueue.m_queue.empty()) {
|
||||
const Command &command = m_commandQueue.m_queue.front();
|
||||
if (!command.command.empty()) {
|
||||
bool query_send = false;
|
||||
if (command.params.empty())
|
||||
query_send = m_connection.sendQuery(command.command.c_str());
|
||||
else
|
||||
query_send = m_connection.sendQueryParams(command.command.c_str(), command.params);
|
||||
|
||||
if (query_send) {
|
||||
m_timer.start();
|
||||
doStateCallback(State::QuerySend);
|
||||
}
|
||||
else {
|
||||
std::string error = m_connection.getErrorMessage();
|
||||
// todo: need to report the error
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (query_send) {
|
||||
m_timer.start();
|
||||
doStateCallback(State::QuerySend);
|
||||
}
|
||||
else {
|
||||
std::string error = m_connection.getErrorMessage();
|
||||
// todo: need to report the error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -336,7 +337,7 @@ void ASyncDBConnection::Thread::waitForResult()
|
|||
timeout.tv_sec = 5;
|
||||
timeout.tv_usec = 0;
|
||||
|
||||
int select_result = select(1, &readfds, nullptr, nullptr, &timeout);
|
||||
int select_result = select(sock + 1, &readfds, nullptr, nullptr, &timeout);
|
||||
if (select_result > 0) {
|
||||
if (FD_ISSET(sock, &readfds)) {
|
||||
if (consumeResultInput()) {
|
||||
|
|
|
|||
|
|
@ -201,12 +201,12 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>23</height>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
<string>Fi&le</string>
|
||||
</property>
|
||||
<addaction name="actionQuit_application"/>
|
||||
</widget>
|
||||
|
|
@ -240,7 +240,7 @@
|
|||
<action name="actionAdd_Connection">
|
||||
<property name="icon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/icons/server_add.png</normaloff>:/icons/server_add.png</iconset>
|
||||
<normaloff>:/icons/add_connection.png</normaloff>:/icons/add_connection.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add Connection</string>
|
||||
|
|
@ -248,9 +248,9 @@
|
|||
</action>
|
||||
<action name="actionDelete_connection">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normalon>:/icons/server_delete.png</normalon>
|
||||
</iconset>
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/icons/delete_connection.png</normaloff>
|
||||
<normalon>:/icons/delete_connection.png</normalon>:/icons/delete_connection.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete connection</string>
|
||||
|
|
@ -261,8 +261,9 @@
|
|||
</action>
|
||||
<action name="actionConnect">
|
||||
<property name="icon">
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/icons/server_go.png</normaloff>:/icons/server_go.png</iconset>
|
||||
<iconset>
|
||||
<normalon>:/icons/open_query_window.png</normalon>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Connect</string>
|
||||
|
|
@ -270,14 +271,14 @@
|
|||
</action>
|
||||
<action name="actionQuit_application">
|
||||
<property name="text">
|
||||
<string>Quit application</string>
|
||||
<string>&Quit application</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBackup_database">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normalon>:/icons/backups.png</normalon>
|
||||
</iconset>
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/icons/backup_database.png</normaloff>
|
||||
<normalon>:/icons/backups.png</normalon>:/icons/backup_database.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Backup database</string>
|
||||
|
|
@ -286,7 +287,7 @@
|
|||
<action name="actionManage_server">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normalon>:/icons/server_edit.png</normalon>
|
||||
<normalon>:/icons/manage_server.png</normalon>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
|
|
|
|||
|
|
@ -131,6 +131,9 @@ void MainWindow::on_actionAbout_triggered()
|
|||
"\n"
|
||||
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
|
||||
"attribution 3.0 license\n"
|
||||
"\n"
|
||||
"More icons by https://icons8.com/ under Creative Commons Attribution-NoDerivs 3.0 Unported "
|
||||
"license."
|
||||
));
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,12 +45,12 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>993</width>
|
||||
<height>22</height>
|
||||
<height>24</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuTest">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
<string>Fi&le</string>
|
||||
</property>
|
||||
<addaction name="actionNew_SQL"/>
|
||||
<addaction name="actionLoad_SQL"/>
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
</widget>
|
||||
<widget class="QMenu" name="menuQuery">
|
||||
<property name="title">
|
||||
<string>Query</string>
|
||||
<string>&Query</string>
|
||||
</property>
|
||||
<addaction name="actionExecute_SQL"/>
|
||||
<addaction name="actionExplain"/>
|
||||
|
|
@ -79,7 +79,7 @@
|
|||
</widget>
|
||||
<widget class="QMenu" name="menuView">
|
||||
<property name="title">
|
||||
<string>Window</string>
|
||||
<string>Wi&ndow</string>
|
||||
</property>
|
||||
<addaction name="actionShow_connection_manager"/>
|
||||
</widget>
|
||||
|
|
@ -126,7 +126,7 @@
|
|||
<normaloff>:/icons/folder.png</normaloff>:/icons/folder.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load SQL</string>
|
||||
<string>&Load SQL</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+O</string>
|
||||
|
|
@ -138,7 +138,7 @@
|
|||
<normaloff>:/icons/script_save.png</normaloff>:/icons/script_save.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save SQL</string>
|
||||
<string>&Save SQL</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+S</string>
|
||||
|
|
@ -150,7 +150,7 @@
|
|||
<normaloff>:/icons/table_save.png</normaloff>:/icons/table_save.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Export data</string>
|
||||
<string>&Export data</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionClose">
|
||||
|
|
@ -160,7 +160,7 @@
|
|||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
<string>&Close</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+F4</string>
|
||||
|
|
@ -168,12 +168,12 @@
|
|||
</action>
|
||||
<action name="actionAbout">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normalon>:/icons/information.png</normalon>
|
||||
</iconset>
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/icons/about.png</normaloff>
|
||||
<normalon>:/icons/information.png</normalon>:/icons/about.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>About</string>
|
||||
<string>&About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExecute_SQL">
|
||||
|
|
@ -183,7 +183,7 @@
|
|||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Execute queries</string>
|
||||
<string>&Execute queries</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Execute the (selected) queries</string>
|
||||
|
|
@ -199,7 +199,7 @@
|
|||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
<string>&Cancel</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Alt+Pause</string>
|
||||
|
|
@ -211,7 +211,7 @@
|
|||
<normaloff>:/icons/lightbulb.png</normaloff>:/icons/lightbulb.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Explain Analyze</string>
|
||||
<string>Ex&plain Analyze</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Shift+F7</string>
|
||||
|
|
@ -219,22 +219,22 @@
|
|||
</action>
|
||||
<action name="actionSave_SQL_as">
|
||||
<property name="text">
|
||||
<string>Save SQL as</string>
|
||||
<string>Sa&ve SQL as</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave_copy_of_SQL_as">
|
||||
<property name="text">
|
||||
<string>Save copy of SQL as</string>
|
||||
<string>Save copy &of SQL as</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionNew_SQL">
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<normalon>:/icons/page_white_add.png</normalon>
|
||||
</iconset>
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/icons/new_query_tab.png</normaloff>
|
||||
<normalon>:/icons/page_white_add.png</normalon>:/icons/new_query_tab.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>New SQL</string>
|
||||
<string>&New SQL</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+N</string>
|
||||
|
|
@ -247,7 +247,7 @@
|
|||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Explain</string>
|
||||
<string>E&xplain</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Explain the (selected) query</string>
|
||||
|
|
@ -258,7 +258,7 @@
|
|||
</action>
|
||||
<action name="actionShow_connection_manager">
|
||||
<property name="text">
|
||||
<string>Show connection manager</string>
|
||||
<string>&Show connection manager</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCopy">
|
||||
|
|
@ -268,7 +268,7 @@
|
|||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Copy</string>
|
||||
<string>&Copy</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+C</string>
|
||||
|
|
@ -281,7 +281,7 @@
|
|||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Copy as C-string</string>
|
||||
<string>Copy as C-&string</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Alt+C</string>
|
||||
|
|
|
|||
BIN
pglab/icons/about.png
Normal file
|
After Width: | Height: | Size: 436 B |
BIN
pglab/icons/add_connection.png
Normal file
|
After Width: | Height: | Size: 416 B |
BIN
pglab/icons/backup_database.png
Normal file
|
After Width: | Height: | Size: 471 B |
|
Before Width: | Height: | Size: 2.3 KiB |
BIN
pglab/icons/delete_connection.png
Normal file
|
After Width: | Height: | Size: 473 B |
|
Before Width: | Height: | Size: 2.1 KiB |
BIN
pglab/icons/manage_server.png
Normal file
|
After Width: | Height: | Size: 618 B |
BIN
pglab/icons/new_query_tab.png
Normal file
|
After Width: | Height: | Size: 419 B |
BIN
pglab/icons/open_query_window.png
Normal file
|
After Width: | Height: | Size: 525 B |
|
Before Width: | Height: | Size: 1.4 KiB |
|
|
@ -1,6 +1,5 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>icons/server_add.png</file>
|
||||
<file>icons/server_delete.png</file>
|
||||
<file>icons/server_go.png</file>
|
||||
<file>icons/script_delete.png</file>
|
||||
|
|
@ -12,13 +11,18 @@
|
|||
<file>icons/page_white_add.png</file>
|
||||
<file>icons/page_white_delete.png</file>
|
||||
<file>icons/lightbulb_off.png</file>
|
||||
<file>icons/information.png</file>
|
||||
<file>icons/16x16/document_green.png</file>
|
||||
<file>icons/16x16/document_red.png</file>
|
||||
<file>icons/16x16/document_yellow.png</file>
|
||||
<file>icons/backups.png</file>
|
||||
<file>icons/page_white_copy.png</file>
|
||||
<file>icons/token_shortland_character.png</file>
|
||||
<file>icons/server_edit.png</file>
|
||||
<file>icons/new_query_tab.png</file>
|
||||
<file>icons/about.png</file>
|
||||
<file>icons/backup_database.png</file>
|
||||
<file>icons/add_connection.png</file>
|
||||
<file>icons/delete_connection.png</file>
|
||||
<file>icons/open_query_window.png</file>
|
||||
<file>icons/manage_server.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public:
|
|||
bool empty();
|
||||
t_Callable pop();
|
||||
|
||||
//HANDLE getNewDataEventHandle();
|
||||
//HANDLE getNewDataEventHandle(); Looks like this wasn't use at all so we can leave the event out.
|
||||
private:
|
||||
using t_CallableQueue = std::deque<t_Callable>;
|
||||
|
||||
|
|
|
|||