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 keywords = m_config.getKeywords();
|
||||||
auto values = m_config.getValues();
|
auto values = m_config.getValues();
|
||||||
#if true
|
#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
|
#else
|
||||||
while (!terminateRequested) {
|
while (!terminateRequested) {
|
||||||
|
|
||||||
|
|
@ -234,11 +238,12 @@ void ASyncDBConnection::Thread::doStateCallback(State state)
|
||||||
|
|
||||||
void ASyncDBConnection::Thread::waitForAndSendCommand()
|
void ASyncDBConnection::Thread::waitForAndSendCommand()
|
||||||
{
|
{
|
||||||
|
using namespace std::chrono_literals;
|
||||||
// lock the data
|
// lock the data
|
||||||
std::unique_lock<std::mutex> lk(m_commandQueue.m_mutex);
|
std::unique_lock<std::mutex> lk(m_commandQueue.m_mutex);
|
||||||
if (m_commandQueue.m_queue.empty()) {
|
if (m_commandQueue.m_queue.empty()) {
|
||||||
// no data wait till there is data
|
// 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;});
|
// can we use the predicate to reimplement the stop function???, []{return ready;});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -266,10 +271,7 @@ void ASyncDBConnection::Thread::waitForAndSendCommand()
|
||||||
|
|
||||||
void ASyncDBConnection::Thread::doNewCommand()
|
void ASyncDBConnection::Thread::doNewCommand()
|
||||||
{
|
{
|
||||||
// todo: send command
|
|
||||||
// get command from top of queue (but leave it in the queue, we need the callback)
|
// 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()) {
|
if (! m_commandQueue.m_queue.empty()) {
|
||||||
const Command &command = m_commandQueue.m_queue.front();
|
const Command &command = m_commandQueue.m_queue.front();
|
||||||
if (!command.command.empty()) {
|
if (!command.command.empty()) {
|
||||||
|
|
@ -289,7 +291,6 @@ void ASyncDBConnection::Thread::doNewCommand()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -336,7 +337,7 @@ void ASyncDBConnection::Thread::waitForResult()
|
||||||
timeout.tv_sec = 5;
|
timeout.tv_sec = 5;
|
||||||
timeout.tv_usec = 0;
|
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 (select_result > 0) {
|
||||||
if (FD_ISSET(sock, &readfds)) {
|
if (FD_ISSET(sock, &readfds)) {
|
||||||
if (consumeResultInput()) {
|
if (consumeResultInput()) {
|
||||||
|
|
|
||||||
|
|
@ -201,12 +201,12 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>23</height>
|
<height>24</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>File</string>
|
<string>Fi&le</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionQuit_application"/>
|
<addaction name="actionQuit_application"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
@ -240,7 +240,7 @@
|
||||||
<action name="actionAdd_Connection">
|
<action name="actionAdd_Connection">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="resources.qrc">
|
<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>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Add Connection</string>
|
<string>Add Connection</string>
|
||||||
|
|
@ -248,9 +248,9 @@
|
||||||
</action>
|
</action>
|
||||||
<action name="actionDelete_connection">
|
<action name="actionDelete_connection">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset resource="resources.qrc">
|
||||||
<normalon>:/icons/server_delete.png</normalon>
|
<normaloff>:/icons/delete_connection.png</normaloff>
|
||||||
</iconset>
|
<normalon>:/icons/delete_connection.png</normalon>:/icons/delete_connection.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Delete connection</string>
|
<string>Delete connection</string>
|
||||||
|
|
@ -261,8 +261,9 @@
|
||||||
</action>
|
</action>
|
||||||
<action name="actionConnect">
|
<action name="actionConnect">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="resources.qrc">
|
<iconset>
|
||||||
<normaloff>:/icons/server_go.png</normaloff>:/icons/server_go.png</iconset>
|
<normalon>:/icons/open_query_window.png</normalon>
|
||||||
|
</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Connect</string>
|
<string>Connect</string>
|
||||||
|
|
@ -270,14 +271,14 @@
|
||||||
</action>
|
</action>
|
||||||
<action name="actionQuit_application">
|
<action name="actionQuit_application">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Quit application</string>
|
<string>&Quit application</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionBackup_database">
|
<action name="actionBackup_database">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset resource="resources.qrc">
|
||||||
<normalon>:/icons/backups.png</normalon>
|
<normaloff>:/icons/backup_database.png</normaloff>
|
||||||
</iconset>
|
<normalon>:/icons/backups.png</normalon>:/icons/backup_database.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Backup database</string>
|
<string>Backup database</string>
|
||||||
|
|
@ -286,7 +287,7 @@
|
||||||
<action name="actionManage_server">
|
<action name="actionManage_server">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset>
|
||||||
<normalon>:/icons/server_edit.png</normalon>
|
<normalon>:/icons/manage_server.png</normalon>
|
||||||
</iconset>
|
</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,9 @@ void MainWindow::on_actionAbout_triggered()
|
||||||
"\n"
|
"\n"
|
||||||
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
|
"Icons by fatcow http://www.fatcow.com/free-icons provided under Creative Commons "
|
||||||
"attribution 3.0 license\n"
|
"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>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>993</width>
|
<width>993</width>
|
||||||
<height>22</height>
|
<height>24</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuTest">
|
<widget class="QMenu" name="menuTest">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>File</string>
|
<string>Fi&le</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionNew_SQL"/>
|
<addaction name="actionNew_SQL"/>
|
||||||
<addaction name="actionLoad_SQL"/>
|
<addaction name="actionLoad_SQL"/>
|
||||||
|
|
@ -69,7 +69,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuQuery">
|
<widget class="QMenu" name="menuQuery">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Query</string>
|
<string>&Query</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionExecute_SQL"/>
|
<addaction name="actionExecute_SQL"/>
|
||||||
<addaction name="actionExplain"/>
|
<addaction name="actionExplain"/>
|
||||||
|
|
@ -79,7 +79,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuView">
|
<widget class="QMenu" name="menuView">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Window</string>
|
<string>Wi&ndow</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionShow_connection_manager"/>
|
<addaction name="actionShow_connection_manager"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
@ -126,7 +126,7 @@
|
||||||
<normaloff>:/icons/folder.png</normaloff>:/icons/folder.png</iconset>
|
<normaloff>:/icons/folder.png</normaloff>:/icons/folder.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Load SQL</string>
|
<string>&Load SQL</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+O</string>
|
<string>Ctrl+O</string>
|
||||||
|
|
@ -138,7 +138,7 @@
|
||||||
<normaloff>:/icons/script_save.png</normaloff>:/icons/script_save.png</iconset>
|
<normaloff>:/icons/script_save.png</normaloff>:/icons/script_save.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save SQL</string>
|
<string>&Save SQL</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+S</string>
|
<string>Ctrl+S</string>
|
||||||
|
|
@ -150,7 +150,7 @@
|
||||||
<normaloff>:/icons/table_save.png</normaloff>:/icons/table_save.png</iconset>
|
<normaloff>:/icons/table_save.png</normaloff>:/icons/table_save.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Export data</string>
|
<string>&Export data</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionClose">
|
<action name="actionClose">
|
||||||
|
|
@ -160,7 +160,7 @@
|
||||||
</iconset>
|
</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Close</string>
|
<string>&Close</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+F4</string>
|
<string>Ctrl+F4</string>
|
||||||
|
|
@ -168,12 +168,12 @@
|
||||||
</action>
|
</action>
|
||||||
<action name="actionAbout">
|
<action name="actionAbout">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset resource="resources.qrc">
|
||||||
<normalon>:/icons/information.png</normalon>
|
<normaloff>:/icons/about.png</normaloff>
|
||||||
</iconset>
|
<normalon>:/icons/information.png</normalon>:/icons/about.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>About</string>
|
<string>&About</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionExecute_SQL">
|
<action name="actionExecute_SQL">
|
||||||
|
|
@ -183,7 +183,7 @@
|
||||||
</iconset>
|
</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Execute queries</string>
|
<string>&Execute queries</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Execute the (selected) queries</string>
|
<string>Execute the (selected) queries</string>
|
||||||
|
|
@ -199,7 +199,7 @@
|
||||||
</iconset>
|
</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Cancel</string>
|
<string>&Cancel</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Alt+Pause</string>
|
<string>Alt+Pause</string>
|
||||||
|
|
@ -211,7 +211,7 @@
|
||||||
<normaloff>:/icons/lightbulb.png</normaloff>:/icons/lightbulb.png</iconset>
|
<normaloff>:/icons/lightbulb.png</normaloff>:/icons/lightbulb.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Explain Analyze</string>
|
<string>Ex&plain Analyze</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Shift+F7</string>
|
<string>Shift+F7</string>
|
||||||
|
|
@ -219,22 +219,22 @@
|
||||||
</action>
|
</action>
|
||||||
<action name="actionSave_SQL_as">
|
<action name="actionSave_SQL_as">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save SQL as</string>
|
<string>Sa&ve SQL as</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionSave_copy_of_SQL_as">
|
<action name="actionSave_copy_of_SQL_as">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Save copy of SQL as</string>
|
<string>Save copy &of SQL as</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionNew_SQL">
|
<action name="actionNew_SQL">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset resource="resources.qrc">
|
||||||
<normalon>:/icons/page_white_add.png</normalon>
|
<normaloff>:/icons/new_query_tab.png</normaloff>
|
||||||
</iconset>
|
<normalon>:/icons/page_white_add.png</normalon>:/icons/new_query_tab.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>New SQL</string>
|
<string>&New SQL</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+N</string>
|
<string>Ctrl+N</string>
|
||||||
|
|
@ -247,7 +247,7 @@
|
||||||
</iconset>
|
</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Explain</string>
|
<string>E&xplain</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Explain the (selected) query</string>
|
<string>Explain the (selected) query</string>
|
||||||
|
|
@ -258,7 +258,7 @@
|
||||||
</action>
|
</action>
|
||||||
<action name="actionShow_connection_manager">
|
<action name="actionShow_connection_manager">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Show connection manager</string>
|
<string>&Show connection manager</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionCopy">
|
<action name="actionCopy">
|
||||||
|
|
@ -268,7 +268,7 @@
|
||||||
</iconset>
|
</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Copy</string>
|
<string>&Copy</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+C</string>
|
<string>Ctrl+C</string>
|
||||||
|
|
@ -281,7 +281,7 @@
|
||||||
</iconset>
|
</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Copy as C-string</string>
|
<string>Copy as C-&string</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+Alt+C</string>
|
<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>
|
<RCC>
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<file>icons/server_add.png</file>
|
|
||||||
<file>icons/server_delete.png</file>
|
<file>icons/server_delete.png</file>
|
||||||
<file>icons/server_go.png</file>
|
<file>icons/server_go.png</file>
|
||||||
<file>icons/script_delete.png</file>
|
<file>icons/script_delete.png</file>
|
||||||
|
|
@ -12,13 +11,18 @@
|
||||||
<file>icons/page_white_add.png</file>
|
<file>icons/page_white_add.png</file>
|
||||||
<file>icons/page_white_delete.png</file>
|
<file>icons/page_white_delete.png</file>
|
||||||
<file>icons/lightbulb_off.png</file>
|
<file>icons/lightbulb_off.png</file>
|
||||||
<file>icons/information.png</file>
|
|
||||||
<file>icons/16x16/document_green.png</file>
|
<file>icons/16x16/document_green.png</file>
|
||||||
<file>icons/16x16/document_red.png</file>
|
<file>icons/16x16/document_red.png</file>
|
||||||
<file>icons/16x16/document_yellow.png</file>
|
<file>icons/16x16/document_yellow.png</file>
|
||||||
<file>icons/backups.png</file>
|
|
||||||
<file>icons/page_white_copy.png</file>
|
<file>icons/page_white_copy.png</file>
|
||||||
<file>icons/token_shortland_character.png</file>
|
<file>icons/token_shortland_character.png</file>
|
||||||
<file>icons/server_edit.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>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ public:
|
||||||
bool empty();
|
bool empty();
|
||||||
t_Callable pop();
|
t_Callable pop();
|
||||||
|
|
||||||
//HANDLE getNewDataEventHandle();
|
//HANDLE getNewDataEventHandle(); Looks like this wasn't use at all so we can leave the event out.
|
||||||
private:
|
private:
|
||||||
using t_CallableQueue = std::deque<t_Callable>;
|
using t_CallableQueue = std::deque<t_Callable>;
|
||||||
|
|
||||||
|
|
|
||||||