Add tests for loading the catalog
This commit is contained in:
parent
591573b6b8
commit
a1ac545086
13 changed files with 203 additions and 32 deletions
|
|
@ -21,6 +21,7 @@ add_library(pglablib STATIC
|
|||
catalog/PgIndexContainer.cpp
|
||||
catalog/PgConstraint.cpp
|
||||
catalog/PgConstraintContainer.cpp
|
||||
catalog/PgDatabaseSizes.cpp
|
||||
ParamListJson.cpp
|
||||
ParamListModel.cpp
|
||||
sqlite/SQLiteConnection.cpp
|
||||
|
|
@ -95,6 +96,7 @@ add_library(pglablib STATIC
|
|||
catalog/PgIndexContainer.h
|
||||
catalog/PgConstraint.h
|
||||
catalog/PgConstraintContainer.h
|
||||
catalog/PgDatabaseSizes.h
|
||||
ParamListJson.h
|
||||
ParamListModel.h
|
||||
sqlite/SQLiteConnection.h
|
||||
|
|
|
|||
25
pglablib/catalog/PgDatabaseSizes.cpp
Normal file
25
pglablib/catalog/PgDatabaseSizes.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "PgDatabaseSizes.h"
|
||||
|
||||
#include "Pgsql_Result.h"
|
||||
|
||||
PgDatabaseSizes loadDatabaseSizes(Pgsql::Connection &connection)
|
||||
{
|
||||
std::string q =
|
||||
"SELECT pg_database.oid, "
|
||||
" case when has_database_privilege(current_role, pg_database.oid, \n"
|
||||
" 'connect') then pg_database_size(pg_database.oid) else -1 end \n"
|
||||
"FROM pg_database";
|
||||
|
||||
Pgsql::Result sizesResult = connection.query(q.c_str());
|
||||
|
||||
PgDatabaseSizes result;
|
||||
result.reserve(sizesResult.rows());
|
||||
for (auto& row : sizesResult)
|
||||
{
|
||||
PgDatabaseSize ds;
|
||||
ds.oid = row.get(0);
|
||||
ds.totalBytes = row.get(1);
|
||||
result.push_back(ds);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
25
pglablib/catalog/PgDatabaseSizes.h
Normal file
25
pglablib/catalog/PgDatabaseSizes.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef PGDATABASESIZES_H
|
||||
#define PGDATABASESIZES_H
|
||||
|
||||
#include "Pgsql_Connection.h"
|
||||
#include <libpq-fe.h>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
class PgDatabaseSize {
|
||||
public:
|
||||
Oid oid;
|
||||
int64_t totalBytes;
|
||||
|
||||
PgDatabaseSize()
|
||||
: oid(InvalidOid)
|
||||
, totalBytes(-1)
|
||||
{}
|
||||
};
|
||||
|
||||
using PgDatabaseSizes = std::vector<PgDatabaseSize>;
|
||||
|
||||
/// Returns the size of every database. The size is -1 when the current role has no CONNECT privilege.
|
||||
PgDatabaseSizes loadDatabaseSizes(Pgsql::Connection &connection);
|
||||
|
||||
#endif // PGDATABASESIZES_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue