Basic support for update in Crud implementation, error reporting and transfering data to modified set is still missing.
This commit is contained in:
parent
3fb32f1200
commit
d626c19e14
15 changed files with 530 additions and 83 deletions
|
|
@ -3,8 +3,11 @@
|
|||
|
||||
#include <libpq-fe.h>
|
||||
#include <vector>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
using AttNumVec = std::vector<int16_t>;
|
||||
template<int size>
|
||||
using SmallAttNumVec = boost::container::small_vector<int16_t, size>;
|
||||
using OidVec = std::vector<Oid>;
|
||||
|
||||
#endif // PGCATALOGTYPES_H
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ public:
|
|||
bool islocal;
|
||||
int32_t inhcount;
|
||||
bool noinherit;
|
||||
AttNumVec key; // list of constraint columns attnum
|
||||
AttNumVec fkey; // fkey list of referenced columns
|
||||
SmallAttNumVec<5> key; // list of constraint columns attnum
|
||||
SmallAttNumVec<5> fkey; // fkey list of referenced columns
|
||||
OidVec pfeqop;
|
||||
OidVec ppeqop;
|
||||
OidVec ffeqop;
|
||||
|
|
|
|||
22
pglablib/QueryGenerator.cpp
Normal file
22
pglablib/QueryGenerator.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include "QueryGenerator.h"
|
||||
#include "PgDatabaseCatalog.h"
|
||||
#include "PgClass.h"
|
||||
#include "PgNamespace.h"
|
||||
#include "PgNamespaceContainer.h"
|
||||
|
||||
using namespace Querygen;
|
||||
|
||||
QueryGeneratorFactory::QueryGeneratorFactory(std::shared_ptr<PgDatabaseCatalog> catalog)
|
||||
: m_catalog(catalog)
|
||||
{}
|
||||
|
||||
UpdatePtr QueryGeneratorFactory::update(QString ns, QString table_name, QString alias)
|
||||
{
|
||||
return std::make_shared<Update>(ns, table_name, alias);
|
||||
}
|
||||
|
||||
UpdatePtr QueryGeneratorFactory::update(const PgClass &table_class, QString alias)
|
||||
{
|
||||
//QString nsname = m_catalog->namespaces()->getByKey(table_class.relnamespace_name)
|
||||
return update(table_class.relnamespace_name, table_class.name, alias);
|
||||
}
|
||||
60
pglablib/QueryGenerator.h
Normal file
60
pglablib/QueryGenerator.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#ifndef QUERYGENERATOR_H
|
||||
#define QUERYGENERATOR_H
|
||||
|
||||
#include <QString>
|
||||
#include <memory>
|
||||
|
||||
class PgDatabaseCatalog;
|
||||
class PgClass;
|
||||
|
||||
namespace Querygen {
|
||||
|
||||
|
||||
class QueryGeneratorFactory;
|
||||
using QueryGeneratorFactoryPtr = std::shared_ptr<QueryGeneratorFactory>;
|
||||
|
||||
class Update;
|
||||
using UpdatePtr = std::shared_ptr<Update>;
|
||||
|
||||
class ColumnRef;
|
||||
using ColumnRefPtr = std::shared_ptr<ColumnRef>;
|
||||
|
||||
class FQTableName {
|
||||
public:
|
||||
QString nsName;
|
||||
QString tableName;
|
||||
};
|
||||
|
||||
|
||||
class ColumnRef {
|
||||
public:
|
||||
virtual QString getFCQS() const = 0;
|
||||
};
|
||||
|
||||
class Update {
|
||||
public:
|
||||
Update(QString ns, QString tbl, QString alias)
|
||||
: table{ns, tbl}
|
||||
{}
|
||||
|
||||
private:
|
||||
FQTableName table;
|
||||
QString tableAlias;
|
||||
};
|
||||
|
||||
using UpdatePtr = std::shared_ptr<Update>;
|
||||
|
||||
|
||||
class QueryGeneratorFactory {
|
||||
public:
|
||||
QueryGeneratorFactory(std::shared_ptr<PgDatabaseCatalog> catalog);
|
||||
|
||||
UpdatePtr update(QString ns, QString table_name, QString alias = QString());
|
||||
UpdatePtr update(const PgClass &table_class, QString alias = QString());
|
||||
private:
|
||||
std::shared_ptr<PgDatabaseCatalog> m_catalog;
|
||||
};
|
||||
|
||||
} // end namespace Querygen
|
||||
|
||||
#endif // QUERYGENERATOR_H
|
||||
|
|
@ -94,7 +94,7 @@ private:
|
|||
QString m_str;
|
||||
};
|
||||
|
||||
QString getColumnNameList(const PgDatabaseCatalog &catalog, Oid relid, const AttNumVec &attnums)
|
||||
QString getColumnNameList(const PgDatabaseCatalog &catalog, Oid relid, const SmallAttNumVec<5> &attnums)
|
||||
{
|
||||
IdentListString result;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ class PgConstraint;
|
|||
class PgDatabaseCatalog;
|
||||
|
||||
bool identNeedsQuotes(QString ident);
|
||||
QString quoteIdent(QString ident);
|
||||
|
||||
QString genFQTableName(const PgDatabaseCatalog &catalog, const PgClass &cls);
|
||||
QString getDropConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint);
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ SOURCES += \
|
|||
ParamListModel.cpp \
|
||||
util.cpp \
|
||||
SqlFormattingUtils.cpp \
|
||||
PgKeywordList.cpp
|
||||
PgKeywordList.cpp \
|
||||
QueryGenerator.cpp
|
||||
|
||||
HEADERS += \
|
||||
Pglablib.h \
|
||||
|
|
@ -80,7 +81,8 @@ HEADERS += \
|
|||
util.h \
|
||||
SqlFormattingUtils.h \
|
||||
PgCatalogTypes.h \
|
||||
PgKeywordList.h
|
||||
PgKeywordList.h \
|
||||
QueryGenerator.h
|
||||
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
|
|
|
|||
|
|
@ -62,9 +62,9 @@ void exportTable(const QTableView *view, QTextStream &out)
|
|||
csv.setSeperator('\t');
|
||||
csv.setQuote('"');
|
||||
|
||||
const int cols = model->columnCount();
|
||||
const int rows = model->rowCount();
|
||||
for (int row = 0; row < rows; ++row) {
|
||||
auto cols = model->columnCount();
|
||||
auto rows = model->rowCount();
|
||||
for (auto row = 0; row < rows; ++row) {
|
||||
for (int col = 0; col < cols; ++col) {
|
||||
auto idx = model->index(row, col);
|
||||
auto display_text = idx.data(Qt::DisplayRole).toString();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue