very basic version of usql

This commit is contained in:
2021-07-14 12:01:44 +02:00
parent f594437b61
commit 577370caef
21 changed files with 3189 additions and 1072 deletions

32
ml_usql.cpp Normal file
View File

@@ -0,0 +1,32 @@
#include "ml_usql.h"
using namespace usql;
MlValue uSQL::execute(const std::string &command) {
std::unique_ptr<usql::Table> sql = USql::execute(command);
return ivaluize(sql.get());
}
MlValue uSQL::ivaluize(const usql::Table *table) {
std::vector<MlValue> rows;
std::vector<MlValue> columns;
for (auto row : table->m_rows) {
columns.clear();
for (int i = 0; i < table->columns_count(); i++) {
auto c = row.ithColumn(i);
auto type = table->m_col_defs[i].type;
if (type == ColumnType::integer_type) {
columns.push_back(MlValue((long)c->integerValue()));
} else if (type == ColumnType::float_type) {
columns.push_back(MlValue((double)c->floatValue()));
} else {
columns.push_back(MlValue::string(c->stringValue()));
}
}
rows.push_back(columns);
}
return rows;
}