implemented postgres table exists

This commit is contained in:
Sascha Kuehl 2023-11-26 20:12:13 +01:00
parent 640dcfadb6
commit a436af5293
1 changed files with 7 additions and 1 deletions

View File

@ -134,7 +134,13 @@ sql::record postgres_connection::describe(const std::string &table)
bool postgres_connection::exists(const std::string &table_name)
{
return false;
std::string stmt("SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = '" + table_name + "'");
PGresult *res = PQexec(conn_, stmt.c_str());
throw_postgres_error(res, conn_, "postgres", stmt);
return sql::to_long_long(PQcmdTuples(res)) == 1;
}
}