entity query and record progress
This commit is contained in:
@@ -51,14 +51,13 @@ std::unique_ptr<sql::query_result_impl> postgres_connection::fetch(const std::st
|
||||
|
||||
throw_postgres_error(res, conn_, "postgres", stmt);
|
||||
|
||||
sql::record prototype;
|
||||
std::vector<sql::column_definition> prototype;
|
||||
auto num_col = PQnfields(res);
|
||||
for (int i = 0; i < num_col; ++i) {
|
||||
const char *col_name = PQfname(res, i);
|
||||
auto type = PQftype(res, i);
|
||||
auto size = PQfmod(res, i);
|
||||
// std::cout << "column " << col_name << ", type " << type << " (size: " << size << ")\n";
|
||||
prototype.append(sql::column_definition{col_name});
|
||||
prototype.emplace_back(col_name);
|
||||
}
|
||||
return std::move(std::make_unique<sql::query_result_impl>(std::make_unique<postgres_result_reader>(res), std::move(prototype)));
|
||||
}
|
||||
@@ -131,7 +130,7 @@ sql::data_type_t string2type(const char *type)
|
||||
}
|
||||
}
|
||||
|
||||
sql::record postgres_connection::describe(const std::string &table)
|
||||
std::vector<sql::column_definition> postgres_connection::describe(const std::string &table)
|
||||
{
|
||||
std::string stmt(
|
||||
"SELECT ordinal_position, column_name, udt_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_schema='public' AND table_name='" + table + "'");
|
||||
@@ -141,7 +140,7 @@ sql::record postgres_connection::describe(const std::string &table)
|
||||
throw_postgres_error(res, conn_, "postgres", stmt);
|
||||
|
||||
postgres_result_reader reader(res);
|
||||
sql::record prototype;
|
||||
std::vector<sql::column_definition> prototype;
|
||||
while (reader.fetch()) {
|
||||
char *end = nullptr;
|
||||
// Todo: Handle error
|
||||
@@ -156,7 +155,7 @@ sql::record postgres_connection::describe(const std::string &table)
|
||||
null_opt = sql::null_option::NOT_NULL;
|
||||
}
|
||||
// f.default_value(res->column(4));
|
||||
prototype.append({name, type, utils::null_attributes, null_opt, index});
|
||||
prototype.emplace_back(name, type, utils::null_attributes, null_opt, index);
|
||||
}
|
||||
|
||||
return std::move(prototype);
|
||||
|
||||
Reference in New Issue
Block a user