diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..7ff14d1 --- /dev/null +++ b/BUILD @@ -0,0 +1,4 @@ + +If it doesn't detect Qt CMAKE_PREFIX_PATH needs to be set + +export CMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dcfbb3..871c289 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,29 +1,35 @@ cmake_minimum_required(VERSION 3.1.0) project(pglaball) -#include(CheckCXXCompilerFlag) +set (CMAKE_PREFIX_PATH /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/cmake) + find_package(PkgConfig REQUIRED) +# include(CheckCXXCompilerFlag) +# +# # Check for standard to use +# check_cxx_compiler_flag(-std=c++17 HAVE_FLAG_STD_CXX17) +# if(HAVE_FLAG_STD_CXX17) +# # Have -std=c++17, use it +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") +# else() +# check_cxx_compiler_flag(-std=c++1z HAVE_FLAG_STD_CXX1Z) +# if(HAVE_FLAG_STD_CXX1Z) +# # Have -std=c++1z, use it +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z") +# else() +# check_cxx_compiler_flag(-std=c++14 HAVE_FLAG_STD_CXX14) +# if(HAVE_FLAG_STD_CXX14) +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") +# endif() +# +# # And so on and on... +# endif() +# endif() -# Check for standard to use -#set(CMAKE_CXX_STANDARD 14) - -include(CheckCXXCompilerFlag) - -# Check for standard to use -check_cxx_compiler_flag(-std=c++17 HAVE_FLAG_STD_CXX17) -if(HAVE_FLAG_STD_CXX17) - # Have -std=c++17, use it - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") -else() - check_cxx_compiler_flag(-std=c++1z HAVE_FLAG_STD_CXX1Z) - if(HAVE_FLAG_STD_CXX1Z) - # Have -std=c++1z, use it - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z") - else() - # And so on and on... - endif() -endif() +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) add_compile_options( -Wall -fpic -march=native ) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og") @@ -32,6 +38,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og") set(CMAKE_INCLUDE_CURRENT_DIR ON) # Instruct CMake to run moc automatically when needed. set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) pkg_check_modules(Botan REQUIRED botan-2) include_directories( ${Botan_INCLUDE_DIRS} ) @@ -94,17 +101,27 @@ add_executable(pglab pglab/QueryTab.cpp pglab/RolesTableModel.cpp pglab/ServerWindow.cpp - pglab/sqlhighlighter.cpp + pglab/SqlHighlighter.cpp pglab/sqlparser.cpp pglab/SqlSyntaxHighlighter.cpp pglab/stopwatch.cpp pglab/tsqueue.cpp pglab/tuplesresultwidget.cpp - pglab/typeselectionitemmodel.cpp + pglab/TypeSelectionItemModel.cpp pglab/util.cpp pglab/waithandlelist.cpp pglab/win32event.cpp ) + target_include_directories(pglab PUBLIC ./core ) + +target_link_libraries( pglab + core + ${Boost_LIBRARIES} + Qt5::Widgets + ${Pq_LIBRARIES} + ${Botan_LIBRARIES} + pthread + ) diff --git a/pglab/ASyncDBConnection.cpp b/pglab/ASyncDBConnection.cpp index eb4387b..29366e4 100644 --- a/pglab/ASyncDBConnection.cpp +++ b/pglab/ASyncDBConnection.cpp @@ -2,6 +2,7 @@ #include "waithandlelist.h" #include "ScopeGuard.h" #include +#include ASyncDBConnection::ASyncDBConnection() { @@ -46,7 +47,7 @@ bool ASyncDBConnection::send(const std::string &command, on_result_callback on_r { std::lock_guard lg(m_threadData.m_commandQueue.m_mutex); m_threadData.m_commandQueue.m_queue.emplace(command, on_result); - m_threadData.m_commandQueue.m_newEvent.set(); + m_threadData.m_commandQueue.m_newEvent.notify_one(); } return true; } @@ -56,7 +57,7 @@ bool ASyncDBConnection::send(const std::string &command, Pgsql::Params params, o { std::lock_guard lg(m_threadData.m_commandQueue.m_mutex); m_threadData.m_commandQueue.m_queue.emplace(command, std::move(params), on_result); - m_threadData.m_commandQueue.m_newEvent.set(); + m_threadData.m_commandQueue.m_newEvent.notify_one(); } return true; } @@ -79,7 +80,6 @@ void ASyncDBConnection::setNoticeCallback(on_notice_callback notice_callback) } ASyncDBConnection::Thread::Thread() - : m_stopEvent(Win32Event::Reset::Manual, Win32Event::Initial::Clear) {} void ASyncDBConnection::Thread::run() @@ -124,14 +124,16 @@ bool ASyncDBConnection::Thread::cancel() bool ASyncDBConnection::Thread::makeConnection() { - using namespace std::chrono_literals; + //using namespace std::literals::chrono_literals; + // start connecting + auto keywords = m_config.getKeywords(); + auto values = m_config.getValues(); +#if true + return m_connection.connect(keywords, values, 0); +#else while (!terminateRequested) { - // start connecting - //bool ok = m_connection.connectStart(m_initString + " client_encoding=utf8"); - auto keywords = m_config.getKeywords(); - auto values = m_config.getValues(); bool ok = m_connection.connectStart(keywords, values); auto start = std::chrono::steady_clock::now(); if (ok && m_connection.status() != CONNECTION_BAD) { @@ -144,7 +146,7 @@ bool ASyncDBConnection::Thread::makeConnection() WSAEventSelect(sock, socket_event.handle(), fd); WaitHandleList whl; auto wait_result_socket_event = whl.add(socket_event); - auto wait_result_stop = whl.add(m_stopEvent); + //auto wait_result_stop = whl.add(m_stopEvent); auto nu = std::chrono::steady_clock::now(); std::chrono::duration diff = -(nu-start); @@ -185,6 +187,7 @@ bool ASyncDBConnection::Thread::makeConnection() } } return false; +#endif } void ASyncDBConnection::Thread::communicate() @@ -217,7 +220,7 @@ void ASyncDBConnection::Thread::communicate() void ASyncDBConnection::Thread::stop() { terminateRequested = true; - m_stopEvent.set(); + //m_stopEvent.set(); } void ASyncDBConnection::Thread::doStateCallback(State state) @@ -231,10 +234,21 @@ void ASyncDBConnection::Thread::doStateCallback(State state) void ASyncDBConnection::Thread::waitForAndSendCommand() { + // lock the data + std::unique_lock lk(m_commandQueue.m_mutex); + if (m_commandQueue.m_queue.empty()) { + // no data wait till there is data + m_commandQueue.m_newEvent.wait(lk); + // can we use the predicate to reimplement the stop function???, []{return ready;}); + + } + doNewCommand(); + +#if false WaitHandleList whl; auto wait_result_new_command = whl.add(m_commandQueue.m_newEvent); //auto wait_result_stop = - whl.add(m_stopEvent); + //whl.add(m_stopEvent); DWORD res = MsgWaitForMultipleObjectsEx( whl.count(), // _In_ DWORD nCount, @@ -247,6 +261,7 @@ void ASyncDBConnection::Thread::waitForAndSendCommand() doNewCommand(); } // if (res == wait_result_stop) return; +#endif } void ASyncDBConnection::Thread::doNewCommand() @@ -278,10 +293,60 @@ void ASyncDBConnection::Thread::doNewCommand() } +bool ASyncDBConnection::Thread::consumeResultInput() +{ + bool finished = false; + if (m_connection.consumeInput()) { + while ( ! finished && ! m_connection.isBusy()) { + auto res(m_connection.getResult()); + { + qint64 ms = m_timer.restart(); + std::lock_guard lg(m_commandQueue.m_mutex); + m_commandQueue.m_queue.front().on_result(res, ms); + if (res == nullptr) { + m_timer.invalidate(); + m_commandQueue.m_queue.pop(); + doStateCallback(State::Connected); + finished = true; + } + } + + } + // else is still waiting for more data + + } + else { + // error during consume + + } + return finished; +} + void ASyncDBConnection::Thread::waitForResult() { - int sock = m_connection.socket(); + + fd_set readfds; + timeval timeout; + bool finished = false; + while (!finished && !terminateRequested) { + FD_ZERO(&readfds); + FD_SET(sock, &readfds); + + timeout.tv_sec = 5; + timeout.tv_usec = 0; + + int select_result = select(1, &readfds, nullptr, nullptr, &timeout); + if (select_result > 0) { + if (FD_ISSET(sock, &readfds)) { + if (consumeResultInput()) { + finished = true; + } + } + } + + } +#if false Win32Event socket_event(Win32Event::Reset::Manual, Win32Event::Initial::Clear); long fd = FD_READ | FD_CLOSE; @@ -292,7 +357,7 @@ void ASyncDBConnection::Thread::waitForResult() WaitHandleList whl; auto wait_result_socket = whl.add(socket_event); - auto wait_result_stop = whl.add(m_stopEvent); + //auto wait_result_stop = whl.add(m_stopEvent); DWORD res = MsgWaitForMultipleObjectsEx( whl.count(), // _In_ DWORD nCount, @@ -306,29 +371,9 @@ void ASyncDBConnection::Thread::waitForResult() WSAEnumNetworkEvents(sock, socket_event.handle(), &net_events); if (net_events.lNetworkEvents & FD_READ) { - if (m_connection.consumeInput()) { - while ( ! finished && ! m_connection.isBusy()) { - auto res(m_connection.getResult()); - { - qint64 ms = m_timer.restart(); - std::lock_guard lg(m_commandQueue.m_mutex); - m_commandQueue.m_queue.front().on_result(res, ms); - if (res == nullptr) { - m_timer.invalidate(); - m_commandQueue.m_queue.pop(); - doStateCallback(State::Connected); - finished = true; - } - } - - } - // else is still waiting for more data - - } - else { - // error during consume - - } + if (consumeResultInput()) { + finished = true; + } } } if (res == wait_result_stop) { @@ -339,6 +384,7 @@ void ASyncDBConnection::Thread::waitForResult() } } // end while // When last result received, remove command from queue +#endif } void ASyncDBConnection::Thread::processNotice(const PGresult *result) diff --git a/pglab/ASyncDBConnection.h b/pglab/ASyncDBConnection.h index 033beb5..cfc5dae 100644 --- a/pglab/ASyncDBConnection.h +++ b/pglab/ASyncDBConnection.h @@ -3,10 +3,10 @@ #include "PgsqlConn.h" #include "Pgsql_Params.h" -#include "win32event.h" #include "ConnectionConfig.h" #include #include +#include #include #include #include @@ -86,9 +86,8 @@ private: struct t_Command { std::mutex m_mutex; t_CommandQueue m_queue; - Win32Event m_newEvent; + std::condition_variable m_newEvent; t_Command() - : m_newEvent(Win32Event::Reset::Auto, Win32Event::Initial::Clear) {} } m_commandQueue; @@ -108,8 +107,8 @@ private: private: - - Win32Event m_stopEvent; + /// \todo Implement new method to stop the thread + //Win32Event m_stopEvent; Pgsql::Connection m_connection; bool terminateRequested = false; ///< is set when the thread should stop bool m_terminated = true; @@ -128,6 +127,11 @@ private: void processNotice(const PGresult *result); + /** Function to call when after sending a command the socket is ready for reading. + * + * It might take several consumes before all data is read. + */ + bool consumeResultInput(); }; Thread m_threadData; diff --git a/pglab/BackupDialog.cpp b/pglab/BackupDialog.cpp index 56a4c66..a5be3e2 100644 --- a/pglab/BackupDialog.cpp +++ b/pglab/BackupDialog.cpp @@ -1,5 +1,5 @@ -#include "backupdialog.h" -#include "ui_backupdialog.h" +#include "BackupDialog.h" +#include "ui_BackupDialog.h" #include "BackupFormatModel.h" @@ -9,8 +9,6 @@ #include #include -#include - BackupDialog::BackupDialog(QWidget *parent) : QDialog(parent), ui(new Ui::BackupDialog) @@ -234,13 +232,14 @@ void BackupDialog::on_btnStart_clicked() auto p = new QProcess(this); ConnectTo(p); p->setProcessEnvironment(env); - +#ifdef _WIN32 p->setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments *args) { args->flags |= CREATE_NEW_CONSOLE; args->flags &= ~DETACHED_PROCESS; args->startupInfo->dwFlags &= ~STARTF_USESTDHANDLES; }); +#endif p->start(program, arguments); } diff --git a/pglab/BackupRestore.cpp b/pglab/BackupRestore.cpp index 801d582..5cbfe07 100644 --- a/pglab/BackupRestore.cpp +++ b/pglab/BackupRestore.cpp @@ -1,6 +1,6 @@ #include #include -#include "connectionconfig.h" +#include "ConnectionConfig.h" void setupEnvironment(const ConnectionConfig &cc) { diff --git a/pglab/ConnectionConfig.cpp b/pglab/ConnectionConfig.cpp index 7b14dbb..d6fcb21 100644 --- a/pglab/ConnectionConfig.cpp +++ b/pglab/ConnectionConfig.cpp @@ -1,4 +1,4 @@ -#include "connectionconfig.h" +#include "ConnectionConfig.h" #include "util.h" #include #include diff --git a/pglab/ConnectionList.cpp b/pglab/ConnectionList.cpp index 39eb6ed..c373474 100644 --- a/pglab/ConnectionList.cpp +++ b/pglab/ConnectionList.cpp @@ -1,5 +1,5 @@ #include "ConnectionList.h" -#include "scopeguard.h" +#include "ScopeGuard.h" #include "util.h" #include #include diff --git a/pglab/ConnectionListModel.cpp b/pglab/ConnectionListModel.cpp index 597ea13..dfb87c2 100644 --- a/pglab/ConnectionListModel.cpp +++ b/pglab/ConnectionListModel.cpp @@ -1,6 +1,6 @@ #include "ConnectionListModel.h" #include "ConnectionList.h" -#include "scopeguard.h" +#include "ScopeGuard.h" #include "util.h" #include diff --git a/pglab/ConnectionListModel.h b/pglab/ConnectionListModel.h index acbfa31..78ce96a 100644 --- a/pglab/ConnectionListModel.h +++ b/pglab/ConnectionListModel.h @@ -6,8 +6,8 @@ #include -#include "connectionconfig.h" -#include "expected.h" +#include "ConnectionConfig.h" +#include "Expected.h" class ConnectionList; diff --git a/pglab/ConnectionManagerWindow.cpp b/pglab/ConnectionManagerWindow.cpp index 5e431a5..cd5740a 100644 --- a/pglab/ConnectionManagerWindow.cpp +++ b/pglab/ConnectionManagerWindow.cpp @@ -1,12 +1,11 @@ -#include "connectionmanagerwindow.h" -#include "ui_connectionmanagerwindow.h" +#include "ConnectionManagerWindow.h" +#include "ui_ConnectionManagerWindow.h" //#include "mainwindow.h" #include "MasterController.h" #include #include #include - -#include "connectionlistmodel.h" +#include "ConnectionListModel.h" ConnectionManagerWindow::ConnectionManagerWindow(MasterController *master, QWidget *parent) : QMainWindow(parent) diff --git a/pglab/DatabaseInspectorWidget.cpp b/pglab/DatabaseInspectorWidget.cpp index 93d7f38..aa0be11 100644 --- a/pglab/DatabaseInspectorWidget.cpp +++ b/pglab/DatabaseInspectorWidget.cpp @@ -1,5 +1,5 @@ -#include "databaseinspectorwidget.h" -#include "ui_databaseinspectorwidget.h" +#include "DatabaseInspectorWidget.h" +#include "ui_DatabaseInspectorWidget.h" DatabaseInspectorWidget::DatabaseInspectorWidget(QWidget *parent) : QWidget(parent), diff --git a/pglab/DatabaseWindow.cpp b/pglab/DatabaseWindow.cpp index 5494534..db0653e 100644 --- a/pglab/DatabaseWindow.cpp +++ b/pglab/DatabaseWindow.cpp @@ -1,5 +1,5 @@ -#include "databasewindow.h" -#include "ui_databasewindow.h" +#include "DatabaseWindow.h" +#include "ui_DatabaseWindow.h" #include DatabaseWindow::DatabaseWindow(QWidget *parent) : diff --git a/pglab/DatabaseWindow.h b/pglab/DatabaseWindow.h index 6addd3d..d5a87d7 100644 --- a/pglab/DatabaseWindow.h +++ b/pglab/DatabaseWindow.h @@ -1,7 +1,7 @@ #ifndef DATABASEWINDOW_H #define DATABASEWINDOW_H -#include "asyncdbconnection.h" +#include "ASyncDBConnection.h" #include "tsqueue.h" #include diff --git a/pglab/ExplainTreeModelItem.cpp b/pglab/ExplainTreeModelItem.cpp index deacd17..f756b1f 100644 --- a/pglab/ExplainTreeModelItem.cpp +++ b/pglab/ExplainTreeModelItem.cpp @@ -1,4 +1,4 @@ -#include "explaintreemodelitem.h" +#include "ExplainTreeModelItem.h" #include "json/json.h" #include diff --git a/pglab/MainWindow.cpp b/pglab/MainWindow.cpp index 76300f1..f830664 100644 --- a/pglab/MainWindow.cpp +++ b/pglab/MainWindow.cpp @@ -1,17 +1,16 @@ #include "MainWindow.h" -#include "ui_mainwindow.h" +#include "ui_MainWindow.h" #include #include #include #include #include -#include #include #include #include #include -#include +#include "QueryTab.h" #include "util.h" #include "MasterController.h" #include "OpenDatabase.h" diff --git a/pglab/MainWindow.h b/pglab/MainWindow.h index 13edb47..b1fa2cb 100644 --- a/pglab/MainWindow.h +++ b/pglab/MainWindow.h @@ -1,8 +1,8 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include "asyncdbconnection.h" -#include "connectionconfig.h" +#include "ASyncDBConnection.h" +#include "ConnectionConfig.h" #include "tsqueue.h" #include #include "ASyncWindow.h" diff --git a/pglab/OpenDatabase.cpp b/pglab/OpenDatabase.cpp index 2cb0832..56b1991 100644 --- a/pglab/OpenDatabase.cpp +++ b/pglab/OpenDatabase.cpp @@ -1,7 +1,7 @@ #include "OpenDatabase.h" -#include "pgsqldatabasecatalogue.h" +#include "PgsqlDatabaseCatalogue.h" #include "PgsqlConn.h" -#include "typeselectionitemmodel.h" +#include "TypeSelectionItemModel.h" Expected OpenDatabase::createOpenDatabase(const ConnectionConfig &cfg) { diff --git a/pglab/OpenDatabase.h b/pglab/OpenDatabase.h index 19de20f..871ea5a 100644 --- a/pglab/OpenDatabase.h +++ b/pglab/OpenDatabase.h @@ -2,8 +2,8 @@ #define OPENDATABASE_H #include -#include "connectionconfig.h" -#include "expected.h" +#include "ConnectionConfig.h" +#include "Expected.h" class PgsqlDatabaseCatalogue; class TypeSelectionItemModel; diff --git a/pglab/PgAuthId.h b/pglab/PgAuthId.h index bea69e6..c71c4f8 100644 --- a/pglab/PgAuthId.h +++ b/pglab/PgAuthId.h @@ -1,7 +1,7 @@ #ifndef PGAUTHID_H #define PGAUTHID_H -#include +#include #include #include diff --git a/pglab/PgClass.cpp b/pglab/PgClass.cpp index 3d066ad..c4d74ed 100644 --- a/pglab/PgClass.cpp +++ b/pglab/PgClass.cpp @@ -1,3 +1,3 @@ -#include "pgclass.h" +#include "PgClass.h" PgClass::PgClass() = default; diff --git a/pglab/PgClass.h b/pglab/PgClass.h index acdec0d..05f0c64 100644 --- a/pglab/PgClass.h +++ b/pglab/PgClass.h @@ -2,7 +2,7 @@ #define PGCLASS_H #include -#include +#include class PgClass { public: diff --git a/pglab/PgContainer.h b/pglab/PgContainer.h index 835b848..ecde222 100644 --- a/pglab/PgContainer.h +++ b/pglab/PgContainer.h @@ -3,7 +3,7 @@ #include #include -#include +#include class PgsqlDatabaseCatalogue; diff --git a/pglab/PgDatabase.h b/pglab/PgDatabase.h index 724e2b9..679c0dd 100644 --- a/pglab/PgDatabase.h +++ b/pglab/PgDatabase.h @@ -2,7 +2,7 @@ #define PGDATABASE_H #include -#include +#include class PgDatabase { public: diff --git a/pglab/PgNamespace.cpp b/pglab/PgNamespace.cpp index a1d6590..c395bf5 100644 --- a/pglab/PgNamespace.cpp +++ b/pglab/PgNamespace.cpp @@ -1,4 +1,4 @@ -#include "pgnamespace.h" +#include "PgNamespace.h" PgNamespace::PgNamespace() = default; diff --git a/pglab/PgNamespace.h b/pglab/PgNamespace.h index 2c33805..f406c20 100644 --- a/pglab/PgNamespace.h +++ b/pglab/PgNamespace.h @@ -2,7 +2,7 @@ #define PGNAMESPACE_H #include -#include +#include class PgNamespace { diff --git a/pglab/PgType.cpp b/pglab/PgType.cpp index 71939b7..7b19a7a 100644 --- a/pglab/PgType.cpp +++ b/pglab/PgType.cpp @@ -1,4 +1,4 @@ -#include "pgtype.h" +#include "PgType.h" #include "PgsqlConn.h" PgType::PgType() = default; diff --git a/pglab/PgType.h b/pglab/PgType.h index 1246700..b39b42d 100644 --- a/pglab/PgType.h +++ b/pglab/PgType.h @@ -2,7 +2,7 @@ #define PGTYPE_H #include -#include +#include class PgType { public: diff --git a/pglab/PgTypeContainer.cpp b/pglab/PgTypeContainer.cpp index f1538c6..652ef3d 100644 --- a/pglab/PgTypeContainer.cpp +++ b/pglab/PgTypeContainer.cpp @@ -1,4 +1,4 @@ -#include "pgtypecontainer.h" +#include "PgTypeContainer.h" #include "PgsqlConn.h" #include diff --git a/pglab/PgTypeContainer.h b/pglab/PgTypeContainer.h index 7c5656d..d7f059c 100644 --- a/pglab/PgTypeContainer.h +++ b/pglab/PgTypeContainer.h @@ -2,7 +2,7 @@ #define PGTYPECONTAINER_H #include -#include "pgtype.h" +#include "PgType.h" #include "PgContainer.h" namespace Pgsql { diff --git a/pglab/PgsqlDatabaseCatalogue.h b/pglab/PgsqlDatabaseCatalogue.h index 0fa8162..0357237 100644 --- a/pglab/PgsqlDatabaseCatalogue.h +++ b/pglab/PgsqlDatabaseCatalogue.h @@ -1,7 +1,7 @@ #ifndef PGSQLDATABASECATALOGUE_H #define PGSQLDATABASECATALOGUE_H -#include +#include #include #include diff --git a/pglab/Pgsql_Value.cpp b/pglab/Pgsql_Value.cpp index 731b2e8..e4095cb 100644 --- a/pglab/Pgsql_Value.cpp +++ b/pglab/Pgsql_Value.cpp @@ -44,7 +44,7 @@ Value::operator Oid() const return operator int(); } -Value::operator __int64() const +Value::operator long long() const { return std::strtoull(m_val, nullptr, 10); } diff --git a/pglab/QueryExplainModel.cpp b/pglab/QueryExplainModel.cpp index 5e0a27d..67ccfca 100644 --- a/pglab/QueryExplainModel.cpp +++ b/pglab/QueryExplainModel.cpp @@ -1,6 +1,7 @@ -#include "queryexplainmodel.h" +#include "QueryExplainModel.h" #include #include +#include const int c_ColumnNode = 0; const int c_ColumnExclusive = 1; @@ -79,7 +80,7 @@ if (role == Qt::DisplayRole) { } } if (col == c_ColumnEstErr) { - float e = fabs(item->estimateError()); + float e = std::fabs(item->estimateError()); if (e > 1000.0f) { result = QColor(255, 192, 192); } diff --git a/pglab/QueryExplainModel.h b/pglab/QueryExplainModel.h index 721c608..0aa318a 100644 --- a/pglab/QueryExplainModel.h +++ b/pglab/QueryExplainModel.h @@ -2,7 +2,7 @@ #include #include -#include "explaintreemodelitem.h" +#include "ExplainTreeModelItem.h" /** \brief Model class for displaying the explain of a query in a tree like format. */ diff --git a/pglab/QueryResultModel.cpp b/pglab/QueryResultModel.cpp index 623d2be..9371ffd 100644 --- a/pglab/QueryResultModel.cpp +++ b/pglab/QueryResultModel.cpp @@ -1,4 +1,4 @@ -#include "queryresultmodel.h" +#include "QueryResultModel.h" #include "Pgsql_declare.h" #include #include diff --git a/pglab/QueryTab.cpp b/pglab/QueryTab.cpp index 31d41c3..d2c0c15 100644 --- a/pglab/QueryTab.cpp +++ b/pglab/QueryTab.cpp @@ -1,5 +1,5 @@ -#include "querytab.h" -#include "ui_querytab.h" +#include "QueryTab.h" +#include "ui_QueryTab.h" #include "SqlSyntaxHighlighter.h" @@ -12,12 +12,12 @@ #include #include #include -#include "explaintreemodelitem.h" +#include "ExplainTreeModelItem.h" #include "json/json.h" #include "MainWindow.h" #include "OpenDatabase.h" -#include "pgtypecontainer.h" -#include "pgsqldatabasecatalogue.h" +#include "PgTypeContainer.h" +#include "PgsqlDatabaseCatalogue.h" #include "util.h" diff --git a/pglab/QueryTab.h b/pglab/QueryTab.h index e0ed32b..8214b62 100644 --- a/pglab/QueryTab.h +++ b/pglab/QueryTab.h @@ -1,11 +1,11 @@ #ifndef QUERYTAB_H #define QUERYTAB_H -#include "asyncdbconnection.h" +#include "ASyncDBConnection.h" #include "ParamListModel.h" #include "ParamTypeDelegate.h" -#include "queryresultmodel.h" -#include "queryexplainmodel.h" +#include "QueryResultModel.h" +#include "QueryExplainModel.h" #include "stopwatch.h" #include "tuplesresultwidget.h" diff --git a/pglab/sqlhighlighter.cpp b/pglab/SqlHighlighter.cpp similarity index 82% rename from pglab/sqlhighlighter.cpp rename to pglab/SqlHighlighter.cpp index d503f16..36885b4 100644 --- a/pglab/sqlhighlighter.cpp +++ b/pglab/SqlHighlighter.cpp @@ -1,14 +1,14 @@ #include "SqlHighlighter.h" -static const wchar_t *keywords[] = { - L"as", L"alter", L"all", L"and", L"any", L"by", L"char", L"column", L"create", L"database", L"date", L"from", L"full", L"group", L"having", - L"in", L"inner", L"int", L"join", L"left", L"not", L"numeric", L"or", L"order", L"outer", L"right", L"select", L"smallint", L"table", L"time", - L"timestamp", L"timestamptz", L"varchar", L"where" -}; - -static const wchar_t *operators[] = { - L"+", L"-", L"*", L"/", L"<", L">", L"<=", L">=", L"<>", L"!=", L"~" -}; +// static const wchar_t *keywords[] = { +// L"as", L"alter", L"all", L"and", L"any", L"by", L"char", L"column", L"create", L"database", L"date", L"from", L"full", L"group", L"having", +// L"in", L"inner", L"int", L"join", L"left", L"not", L"numeric", L"or", L"order", L"outer", L"right", L"select", L"smallint", L"table", L"time", +// L"timestamp", L"timestamptz", L"varchar", L"where" +// }; +// +// static const wchar_t *operators[] = { +// L"+", L"-", L"*", L"/", L"<", L">", L"<=", L">=", L"<>", L"!=", L"~" +// }; /* @@ -17,7 +17,7 @@ static const wchar_t *operators[] = { There are a few restrictions on your choice of name: - -- and /* cannot appear anywhere in an operator name, since they will be taken as the start of a comment. + -- and C-comment start cannot appear anywhere in an operator name, since they will be taken as the start of a comment. A multicharacter operator name cannot end in + or -, unless the name also contains at least one of these characters: diff --git a/pglab/sqlhighlighter.h b/pglab/SqlHighlighter.h similarity index 100% rename from pglab/sqlhighlighter.h rename to pglab/SqlHighlighter.h diff --git a/pglab/SqlSyntaxHighlighter.cpp b/pglab/SqlSyntaxHighlighter.cpp index 92961ee..8367a80 100644 --- a/pglab/SqlSyntaxHighlighter.cpp +++ b/pglab/SqlSyntaxHighlighter.cpp @@ -1,6 +1,6 @@ #include "SqlSyntaxHighlighter.h" -#include "pgtypecontainer.h" +#include "PgTypeContainer.h" #include "SqlLexer.h" namespace { diff --git a/pglab/typeselectionitemmodel.cpp b/pglab/TypeSelectionItemModel.cpp similarity index 94% rename from pglab/typeselectionitemmodel.cpp rename to pglab/TypeSelectionItemModel.cpp index ed6e930..859058f 100644 --- a/pglab/typeselectionitemmodel.cpp +++ b/pglab/TypeSelectionItemModel.cpp @@ -1,4 +1,4 @@ -#include "typeselectionitemmodel.h" +#include "TypeSelectionItemModel.h" #include "PgTypeContainer.h" #include @@ -61,8 +61,8 @@ void TypeSelectionItemModel::setTypeList(const PgTypeContainer* types) beginResetModel(); m_types.clear(); for (const auto &e : *types) { - if (e.typcategory != 'A' - && e.typtype != 'c') { + if (e.typcategory != "A" + && e.typtype != "c") { m_types.push_back(e.typname); } } diff --git a/pglab/typeselectionitemmodel.h b/pglab/TypeSelectionItemModel.h similarity index 100% rename from pglab/typeselectionitemmodel.h rename to pglab/TypeSelectionItemModel.h diff --git a/pglab/main.cpp b/pglab/main.cpp index e7d0552..c4f3139 100644 --- a/pglab/main.cpp +++ b/pglab/main.cpp @@ -1,12 +1,15 @@ #include "MasterController.h" #include -#include +#ifdef _WIN32 +# include +#endif #include int main(int argc, char *argv[]) { /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ +#ifdef _WIN32 WORD wVersionRequested = MAKEWORD(2, 2); WSADATA wsaData; int err = WSAStartup(wVersionRequested, &wsaData); @@ -16,7 +19,7 @@ int main(int argc, char *argv[]) printf("WSAStartup failed with error: %d\n", err); return 1; } - +#endif QApplication a(argc, argv); QCoreApplication::setOrganizationName("pglab"); @@ -26,8 +29,9 @@ int main(int argc, char *argv[]) auto master_controller = std::make_unique(); master_controller->init(); int result = a.exec(); +#ifdef _WIN32 WSACleanup(); - +#endif return result; } diff --git a/pglab/tsqueue.cpp b/pglab/tsqueue.cpp index 9200692..b49b6a0 100644 --- a/pglab/tsqueue.cpp +++ b/pglab/tsqueue.cpp @@ -1,14 +1,14 @@ #include "tsqueue.h" TSQueue::TSQueue() - : newData(Win32Event::Reset::Manual, Win32Event::Initial::Clear) +// : newData(Win32Event::Reset::Manual, Win32Event::Initial::Clear) {} void TSQueue::add(t_Callable callable) { std::lock_guard g(m); futureQueue.push_back(std::move(callable)); - newData.set(); +// newData.set(); } bool TSQueue::empty() @@ -23,12 +23,12 @@ TSQueue::t_Callable TSQueue::pop() auto f = std::move(futureQueue.front()); futureQueue.pop_front(); if (futureQueue.empty()) { - newData.reset(); +// newData.reset(); } return f; } -HANDLE TSQueue::getNewDataEventHandle() -{ - return newData.handle(); -} +// HANDLE TSQueue::getNewDataEventHandle() +// { +// return newData.handle(); +// } diff --git a/pglab/tsqueue.h b/pglab/tsqueue.h index acb7934..8b93d34 100644 --- a/pglab/tsqueue.h +++ b/pglab/tsqueue.h @@ -1,7 +1,7 @@ #ifndef TSQUEUE_H #define TSQUEUE_H -#include "Win32Event.h" +//#include "Win32Event.h" #include #include #include @@ -15,11 +15,11 @@ public: bool empty(); t_Callable pop(); - HANDLE getNewDataEventHandle(); + //HANDLE getNewDataEventHandle(); private: using t_CallableQueue = std::deque; - Win32Event newData; + //Win32Event newData; std::mutex m; t_CallableQueue futureQueue; }; diff --git a/pglab/tuplesresultwidget.h b/pglab/tuplesresultwidget.h index e1414af..7511404 100644 --- a/pglab/tuplesresultwidget.h +++ b/pglab/tuplesresultwidget.h @@ -1,7 +1,7 @@ #ifndef TUPLESRESULTWIDGET_H #define TUPLESRESULTWIDGET_H -#include "queryresultmodel.h" +#include "QueryResultModel.h" #include namespace Ui { diff --git a/pglab/util.cpp b/pglab/util.cpp index 749c7cc..ae4bb71 100644 --- a/pglab/util.cpp +++ b/pglab/util.cpp @@ -1,5 +1,5 @@ #include "util.h" -#include "csvwriter.h" +#include "CsvWriter.h" #include #include #include @@ -108,8 +108,7 @@ void copySelectionToClipboard(const QTableView *view) QString ConvertToMultiLineCString(const QString &in) { - // We need to atleast escape " and \ - // also any multi byte utf8 char + // We need to atleast escape " and \ and also any multi byte utf8 char QString out; out.append('"'); diff --git a/pglab/waithandlelist.cpp b/pglab/waithandlelist.cpp index e05bba4..e8f507a 100644 --- a/pglab/waithandlelist.cpp +++ b/pglab/waithandlelist.cpp @@ -1,6 +1,7 @@ #include "waithandlelist.h" #include "win32event.h" +#ifdef _WIN32 WaitHandleList::WaitHandleList() = default; WaitHandleList::~WaitHandleList() = default; @@ -29,3 +30,5 @@ WaitHandleList::operator const HANDLE*() const { return m_waitHandles.data(); } + +#endif