mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-05-05 19:39:42 -05:00
Use Niels Lohmann's JSON library instead of Qt's
Replace Qt's own JSON library functions by Niels Lohmann's JSON library in the Export JSON dialog. This was necessary because for very large JSON objects Qt's library functions generated incomplete JSON exports. See issue #1789.
This commit is contained in:
+4
-3
@@ -76,6 +76,7 @@ else()
|
||||
find_package(QCustomPlot)
|
||||
endif()
|
||||
set(QHEXEDIT_DIR libs/qhexedit)
|
||||
set(JSON_DIR libs/json)
|
||||
|
||||
if(NOT ANTLR2_FOUND)
|
||||
set(ANTLR_DIR libs/antlr-2.7.7)
|
||||
@@ -86,6 +87,7 @@ if(NOT QSCINTILLA_FOUND)
|
||||
add_subdirectory(${QSCINTILLA_DIR})
|
||||
endif()
|
||||
add_subdirectory(${QHEXEDIT_DIR})
|
||||
add_subdirectory(${JSON_DIR})
|
||||
if(NOT QCUSTOMPLOT_FOUND)
|
||||
set(QCUSTOMPLOT_DIR libs/qcustomplot-source)
|
||||
add_subdirectory(${QCUSTOMPLOT_DIR})
|
||||
@@ -354,6 +356,7 @@ endif()
|
||||
include_directories(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
${QHEXEDIT_DIR}
|
||||
${JSON_DIR}
|
||||
${ADDITIONAL_INCLUDE_PATHS}
|
||||
src)
|
||||
if(QCUSTOMPLOT_FOUND)
|
||||
@@ -401,9 +404,7 @@ if(NOT QSCINTILLA_FOUND)
|
||||
add_dependencies(${PROJECT_NAME} qscintilla2)
|
||||
endif()
|
||||
|
||||
link_directories(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${QHEXEDIT_DIR}"
|
||||
)
|
||||
link_directories("${CMAKE_CURRENT_BINARY_DIR}/${QHEXEDIT_DIR}")
|
||||
if(NOT QCUSTOMPLOT_FOUND)
|
||||
link_directories("${CMAKE_CURRENT_BINARY_DIR}/${QCUSTOMPLOT_DIR}")
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
cmake_minimum_required(VERSION 2.8.12.2)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
set(JSON11_HDR
|
||||
json.hpp
|
||||
)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2013-2018 Niels Lohmann
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+1297
File diff suppressed because it is too large
Load Diff
+20587
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
TEMPLATE = lib
|
||||
|
||||
CONFIG += staticlib
|
||||
CONFIG += debug_and_release
|
||||
|
||||
HEADERS += \
|
||||
json.hpp
|
||||
@@ -6,4 +6,5 @@ SUBDIRS = libs/antlr-2.7.7/antlr.pro \
|
||||
libs/qhexedit/qhexedit.pro \
|
||||
libs/qcustomplot-source/qcustomplot.pro \
|
||||
libs/qscintilla/Qt4Qt5/qscintilla.pro \
|
||||
libs/json/json.pro \
|
||||
src
|
||||
|
||||
+13
-13
@@ -8,10 +8,10 @@
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QMessageBox>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QTextCodec>
|
||||
#include <json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
ExportDataDialog::ExportDataDialog(DBBrowserDB& db, ExportFormats format, QWidget* parent, const QString& query, const sqlb::ObjectIdentifier& selection)
|
||||
: QDialog(parent),
|
||||
@@ -204,7 +204,7 @@ bool ExportDataDialog::exportQueryJson(const QString& sQuery, const QString& sFi
|
||||
auto pDb = pdb.get(tr("exporting JSON"));
|
||||
int status = sqlite3_prepare_v2(pDb.get(), utf8Query.data(), utf8Query.size(), &stmt, nullptr);
|
||||
|
||||
QJsonArray json_table;
|
||||
json json_table;
|
||||
|
||||
if(SQLITE_OK == status)
|
||||
{
|
||||
@@ -221,31 +221,32 @@ bool ExportDataDialog::exportQueryJson(const QString& sQuery, const QString& sFi
|
||||
column_names.push_back(QString::fromUtf8(sqlite3_column_name(stmt, i)));
|
||||
}
|
||||
|
||||
QJsonObject json_row;
|
||||
json json_row;
|
||||
for(int i=0;i<columns;++i)
|
||||
{
|
||||
int type = sqlite3_column_type(stmt, i);
|
||||
std::string column_name = column_names[i].toStdString();
|
||||
|
||||
switch (type) {
|
||||
case SQLITE_INTEGER: {
|
||||
qint64 content = sqlite3_column_int64(stmt, i);
|
||||
json_row.insert(column_names[i], content);
|
||||
json_row[column_name] = content;
|
||||
break;
|
||||
}
|
||||
case SQLITE_FLOAT: {
|
||||
double content = sqlite3_column_double(stmt, i);
|
||||
json_row.insert(column_names[i], content);
|
||||
json_row[column_name] = content;
|
||||
break;
|
||||
}
|
||||
case SQLITE_NULL: {
|
||||
json_row.insert(column_names[i], QJsonValue());
|
||||
json_row[column_name] = nullptr;
|
||||
break;
|
||||
}
|
||||
case SQLITE_TEXT: {
|
||||
QString content = QString::fromUtf8(
|
||||
reinterpret_cast<const char*>(sqlite3_column_text(stmt, i)),
|
||||
sqlite3_column_bytes(stmt, i));
|
||||
json_row.insert(column_names[i], content);
|
||||
json_row[column_name] = content.toStdString();
|
||||
break;
|
||||
}
|
||||
case SQLITE_BLOB: {
|
||||
@@ -253,11 +254,12 @@ bool ExportDataDialog::exportQueryJson(const QString& sQuery, const QString& sFi
|
||||
sqlite3_column_bytes(stmt, i));
|
||||
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
|
||||
QString string = codec->toUnicode(content.toBase64(QByteArray::Base64Encoding));
|
||||
json_row.insert(column_names[i], string);
|
||||
json_row[column_name] = string.toStdString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
json_table.push_back(json_row);
|
||||
|
||||
if(counter % 1000 == 0)
|
||||
@@ -269,9 +271,7 @@ bool ExportDataDialog::exportQueryJson(const QString& sQuery, const QString& sFi
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
// Create JSON document
|
||||
QJsonDocument json_doc;
|
||||
json_doc.setArray(json_table);
|
||||
file.write(json_doc.toJson(ui->checkPrettyPrint->isChecked() ? QJsonDocument::Indented : QJsonDocument::Compact));
|
||||
file.write(json_table.dump(ui->checkPrettyPrint->isChecked() ? 4 : -1).c_str());
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
qApp->processEvents();
|
||||
|
||||
+7
-4
@@ -191,6 +191,7 @@ LIBPATH_QHEXEDIT=$$OUT_PWD/../libs/qhexedit
|
||||
LIBPATH_ANTLR=$$OUT_PWD/../libs/antlr-2.7.7
|
||||
LIBPATH_QCUSTOMPLOT=$$OUT_PWD/../libs/qcustomplot-source
|
||||
LIBPATH_QSCINTILLA=$$OUT_PWD/../libs/qscintilla/Qt4Qt5
|
||||
LIBPATH_JSON=$$OUT_PWD/../libs/json
|
||||
unix {
|
||||
LIBS += -ldl
|
||||
}
|
||||
@@ -205,13 +206,15 @@ win32 {
|
||||
LIBPATH_QHEXEDIT = $$LIBPATH_QHEXEDIT/debug
|
||||
LIBPATH_ANTLR = $$LIBPATH_ANTLR/debug
|
||||
LIBPATH_QCUSTOMPLOT = $$LIBPATH_QCUSTOMPLOT/debug
|
||||
LIBPATH_QSCINTILLA = $$LIBPATH_QSCINTILLA/debug
|
||||
LIBPATH_QSCINTILLA = $$LIBPATH_QSCINTILLA/debug
|
||||
LIBPATH_JSON = $$LIBPATH_JSON/debug
|
||||
}
|
||||
CONFIG(release,debug|release) {
|
||||
LIBPATH_QHEXEDIT = $$LIBPATH_QHEXEDIT/release
|
||||
LIBPATH_ANTLR = $$LIBPATH_ANTLR/release
|
||||
LIBPATH_QCUSTOMPLOT = $$LIBPATH_QCUSTOMPLOT/release
|
||||
LIBPATH_QSCINTILLA = $$LIBPATH_QSCINTILLA/release
|
||||
LIBPATH_QSCINTILLA = $$LIBPATH_QSCINTILLA/release
|
||||
LIBPATH_JSON = $$LIBPATH_JSON/release
|
||||
}
|
||||
QMAKE_CXXFLAGS += -DCHECKNEWVERSION
|
||||
|
||||
@@ -236,9 +239,9 @@ CONFIG(all_warnings) {
|
||||
}
|
||||
|
||||
UI_DIR = .ui
|
||||
INCLUDEPATH += $$PWD/../libs/antlr-2.7.7 $$PWD/../libs/qhexedit $$PWD/../libs/qcustomplot-source $$PWD/../libs/qscintilla/Qt4Qt5 $$PWD/..
|
||||
INCLUDEPATH += $$PWD/../libs/antlr-2.7.7 $$PWD/../libs/qhexedit $$PWD/../libs/qcustomplot-source $$PWD/../libs/qscintilla/Qt4Qt5 $$PWD/../libs/json $$PWD/..
|
||||
LIBS += -L$$LIBPATH_QHEXEDIT -L$$LIBPATH_ANTLR -L$$LIBPATH_QCUSTOMPLOT -L$$LIBPATH_QSCINTILLA -lantlr -lqhexedit -lqcustomplot -lqscintilla2
|
||||
DEPENDPATH += $$PWD/../libs/antlr-2.7.7 $$PWD/../libs/qhexedit $$PWD/../libs/qcustomplot-source $$PWD/../libs/qscintilla/Qt4Qt5
|
||||
DEPENDPATH += $$PWD/../libs/antlr-2.7.7 $$PWD/../libs/qhexedit $$PWD/../libs/qcustomplot-source $$PWD/../libs/qscintilla/Qt4Qt5 $$PWD/../libs/json
|
||||
|
||||
unix {
|
||||
# Below, the user can specify where all generated file can be placed
|
||||
|
||||
Reference in New Issue
Block a user