bool Model_Report::get_objects_from_sql(const wxString& query, PrettyWriter<StringBuffer>& json_writer) { wxSQLite3Statement stmt; try { stmt = this->db_->PrepareStatement(query); if (!stmt.IsReadOnly()) { json_writer.Key("msg"); json_writer.String("the sql is not readonly"); return false; } } catch (const wxSQLite3Exception& e) { json_writer.Key("msg"); json_writer.String(e.GetMessage().c_str()); return false; } try { json_writer.Key("results"); json_writer.StartArray(); wxSQLite3ResultSet q = stmt.ExecuteQuery(); int columns = q.GetColumnCount(); while (q.NextRow()) { json_writer.StartObject(); for (int i = 0; i < columns; ++i) { wxString column_name = q.GetColumnName(i); switch (q.GetColumnType(i)) { case WXSQLITE_INTEGER: json_writer.Key(column_name.c_str()); json_writer.Int(q.GetInt(i)); break; case WXSQLITE_FLOAT: json_writer.Key(column_name.c_str()); json_writer.Double(q.GetDouble(i)); break; default: json_writer.Key(column_name.c_str()); json_writer.String(q.GetString(i).c_str()); break; } } json_writer.EndObject(); } q.Finalize(); json_writer.EndArray(); } catch (const wxSQLite3Exception& e) { json_writer.Key("msg"); json_writer.String(e.GetMessage().c_str()); return false; } return true; }