Skip to content

Commit b1ba58f

Browse files
committed
'Export -> Table(s) to JSON' takes into account the column type
Use SQLite3 and Qt APIs to export the table data using appropriate JSON data types. See issue #1323: JSON table export converts integer and null values to string.
1 parent 379bbb8 commit b1ba58f

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/ExportDataDialog.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,32 @@ bool ExportDataDialog::exportQueryJson(const QString& sQuery, const QString& sFi
220220
QJsonObject json_row;
221221
for(int i=0;i<columns;++i)
222222
{
223-
QString content = QString::fromUtf8(
224-
(const char*)sqlite3_column_blob(stmt, i),
225-
sqlite3_column_bytes(stmt, i));
226-
json_row.insert(column_names[i], content);
223+
int type = sqlite3_column_type(stmt, i);
224+
225+
switch (type) {
226+
case SQLITE_INTEGER: {
227+
qint64 content = sqlite3_column_int64(stmt, i);
228+
json_row.insert(column_names[i], content);
229+
break;
230+
}
231+
case SQLITE_FLOAT: {
232+
double content = sqlite3_column_double(stmt, i);
233+
json_row.insert(column_names[i], content);
234+
break;
235+
}
236+
case SQLITE_NULL: {
237+
json_row.insert(column_names[i], QJsonValue());
238+
break;
239+
}
240+
case SQLITE_TEXT:
241+
case SQLITE_BLOB: {
242+
QString content = QString::fromUtf8(
243+
(const char*)sqlite3_column_blob(stmt, i),
244+
sqlite3_column_bytes(stmt, i));
245+
json_row.insert(column_names[i], content);
246+
break;
247+
}
248+
}
227249
}
228250
json_table.push_back(json_row);
229251

0 commit comments

Comments
 (0)