mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
'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.
This commit is contained in:
@@ -220,10 +220,32 @@ bool ExportDataDialog::exportQueryJson(const QString& sQuery, const QString& sFi
|
||||
QJsonObject json_row;
|
||||
for(int i=0;i<columns;++i)
|
||||
{
|
||||
QString content = QString::fromUtf8(
|
||||
(const char*)sqlite3_column_blob(stmt, i),
|
||||
sqlite3_column_bytes(stmt, i));
|
||||
json_row.insert(column_names[i], content);
|
||||
int type = sqlite3_column_type(stmt, i);
|
||||
|
||||
switch (type) {
|
||||
case SQLITE_INTEGER: {
|
||||
qint64 content = sqlite3_column_int64(stmt, i);
|
||||
json_row.insert(column_names[i], content);
|
||||
break;
|
||||
}
|
||||
case SQLITE_FLOAT: {
|
||||
double content = sqlite3_column_double(stmt, i);
|
||||
json_row.insert(column_names[i], content);
|
||||
break;
|
||||
}
|
||||
case SQLITE_NULL: {
|
||||
json_row.insert(column_names[i], QJsonValue());
|
||||
break;
|
||||
}
|
||||
case SQLITE_TEXT:
|
||||
case SQLITE_BLOB: {
|
||||
QString content = QString::fromUtf8(
|
||||
(const char*)sqlite3_column_blob(stmt, i),
|
||||
sqlite3_column_bytes(stmt, i));
|
||||
json_row.insert(column_names[i], content);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
json_table.push_back(json_row);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user