very basic version of usql
This commit is contained in:
32
ml_usql.cpp
Normal file
32
ml_usql.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user