| 1102 | |
| 1103 | |
| 1104 | QJsonArray OMSFileLoad::exportTableToJSON_(const QString& table, const QString& order_by) |
| 1105 | { |
| 1106 | // code based on: https://stackoverflow.com/a/18067555 |
| 1107 | String sql = "SELECT * FROM " + table; |
| 1108 | if (!order_by.isEmpty()) |
| 1109 | { |
| 1110 | sql += " ORDER BY " + order_by; |
| 1111 | } |
| 1112 | |
| 1113 | SQLite::Statement query(*db_, sql); |
| 1114 | |
| 1115 | QJsonArray array; |
| 1116 | while (query.executeStep()) |
| 1117 | { |
| 1118 | QJsonObject record; |
| 1119 | for (int i = 0; i < query.getColumnCount(); ++i) |
| 1120 | { |
| 1121 | // @TODO: this will repeat field names for every row - |
| 1122 | // avoid this with separate "header" and "rows" (array)? |
| 1123 | |
| 1124 | // sqlite stores each cell based on the actual value, not the declared column type; |
| 1125 | // thus, we could use query.getColumnDeclaredType(i), but it would incur conversion |
| 1126 | switch (query.getColumn(i).getType()) |
| 1127 | { |
| 1128 | case SQLITE_INTEGER: record.insert(query.getColumnName(i), qint64(query.getColumn(i).getInt64())); break; |
| 1129 | case SQLITE_FLOAT: record.insert(query.getColumnName(i), query.getColumn(i).getDouble()); break; |
| 1130 | case SQLITE_BLOB: record.insert(query.getColumnName(i), query.getColumn(i).getText()); break; |
| 1131 | case SQLITE_NULL: record.insert(query.getColumnName(i), ""); break; |
| 1132 | case SQLITE3_TEXT: record.insert(query.getColumnName(i), query.getColumn(i).getText()); break; |
| 1133 | default: |
| 1134 | throw Exception::NotImplemented(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION); |
| 1135 | } |
| 1136 | } |
| 1137 | array.push_back(record); |
| 1138 | } |
| 1139 | return array; |
| 1140 | } |
| 1141 | |
| 1142 | |
| 1143 | void OMSFileLoad::exportToJSON(ostream& output) |
nothing calls this directly
no test coverage detected