We should not allow editing of system catalogs.
This commit is contained in:
parent
5e7fb68c55
commit
66267334c8
2 changed files with 28 additions and 7 deletions
|
|
@ -1,8 +1,12 @@
|
||||||
#include "ResultSourceMapping.h"
|
#include "ResultSourceMapping.h"
|
||||||
|
|
||||||
#include "Pgsql_Result.h"
|
#include "Pgsql_Result.h"
|
||||||
|
#include "catalog/PgClass.h"
|
||||||
#include "catalog/PgDatabaseCatalog.h"
|
#include "catalog/PgDatabaseCatalog.h"
|
||||||
#include "catalog/PgConstraintContainer.h"
|
#include "catalog/PgConstraintContainer.h"
|
||||||
|
#include "catalog/PgNamespace.h"
|
||||||
|
#include "catalog/PgNamespaceContainer.h"
|
||||||
|
#include "catalog/PgClassContainer.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
@ -107,6 +111,20 @@ const ResultSourceMapping::TableInfo *ResultSourceMapping::findTable(Oid tableOi
|
||||||
return found == m_tables.end() ? nullptr : &*found;
|
return found == m_tables.end() ? nullptr : &*found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
/// Catalog tables (pg_catalog, information_schema, ...) are views or system tables and must never be edited.
|
||||||
|
bool isSystemCatalogTable(const PgDatabaseCatalog &catalog, Oid tableOid)
|
||||||
|
{
|
||||||
|
const PgClass *cls = catalog.classes()->getByKey(tableOid);
|
||||||
|
if (!cls)
|
||||||
|
return false;
|
||||||
|
const PgNamespace *ns = catalog.namespaces()->getByKey(cls->nsOid());
|
||||||
|
return ns && ns->isSystemCatalog();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
ResultSourceMapping createResultSourceMapping(const Pgsql::Result &result, const PgDatabaseCatalog &catalog)
|
ResultSourceMapping createResultSourceMapping(const Pgsql::Result &result, const PgDatabaseCatalog &catalog)
|
||||||
{
|
{
|
||||||
std::vector<ResultColumnSource> columns;
|
std::vector<ResultColumnSource> columns;
|
||||||
|
|
@ -129,9 +147,11 @@ ResultSourceMapping createResultSourceMapping(const Pgsql::Result &result, const
|
||||||
|
|
||||||
TablePrimaryKey pk;
|
TablePrimaryKey pk;
|
||||||
pk.tableOid = source.tableOid;
|
pk.tableOid = source.tableOid;
|
||||||
|
if (!isSystemCatalogTable(catalog, source.tableOid)) {
|
||||||
auto constraint = catalog.constraints()->getPrimaryForRelation(source.tableOid);
|
auto constraint = catalog.constraints()->getPrimaryForRelation(source.tableOid);
|
||||||
if (constraint)
|
if (constraint)
|
||||||
pk.attnums.assign(constraint->key.begin(), constraint->key.end());
|
pk.attnums.assign(constraint->key.begin(), constraint->key.end());
|
||||||
|
}
|
||||||
primaryKeys.push_back(pk);
|
primaryKeys.push_back(pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@ features:
|
||||||
Query results are now shown in the same grid as the table data tab. Columns
|
Query results are now shown in the same grid as the table data tab. Columns
|
||||||
can be sorted by clicking their headers, and cells that belong to a table
|
can be sorted by clicking their headers, and cells that belong to a table
|
||||||
with a primary key present in the result can be edited directly. Changes
|
with a primary key present in the result can be edited directly. Changes
|
||||||
are saved with an ``UPDATE`` by primary key.
|
are saved with an ``UPDATE`` by primary key. Tables in system catalog
|
||||||
|
schemas such as ``pg_catalog`` and ``information_schema`` are never editable.
|
||||||
other:
|
other:
|
||||||
- |
|
- |
|
||||||
Read-only cells in query results, such as expression columns or columns of
|
Read-only cells in query results, such as expression columns, columns of
|
||||||
tables without a primary key in the result, are now shown in grey so they
|
tables without a primary key in the result, or columns of system catalog
|
||||||
can be told apart from editable cells.
|
tables, are now shown in grey so they can be told apart from editable cells.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue