#include "ml_usql.h" using namespace usql; MlValue uSQL::execute(const std::string &command) { std::unique_ptr sql = USql::execute(command); return ivaluize(sql.get()); } MlValue uSQL::ivaluize(const usql::Table *table) { std::vector rows; std::vector columns; columns.reserve(table->columns_count()); rows.reserve(table->rows_count()); for (auto row : table->m_rows) { columns.clear(); for (int i = 0; i < table->columns_count(); i++) { const auto & c = row[i]; const auto type = table->m_col_defs[i].type; if (c.isNull()) { columns.push_back(MlValue::nil()); } else if (type == ColumnType::integer_type || type == ColumnType::date_type) { columns.push_back(MlValue(c.getIntegerValue())); } else if (type == ColumnType::bool_type) { columns.push_back(c.getBoolValue() ? MlValue(c.getIntegerValue()) : MlValue::nil()); } else if (type == ColumnType::float_type) { columns.push_back(MlValue(c.getDoubleValue())); } else { columns.push_back(MlValue::string(c.getStringValue())); } } rows.emplace_back(columns); } return rows; }