添加获取数据表属性原始类型的接口
This commit is contained in:
parent
90e0599dd9
commit
57fecb7a30
|
|
@ -87,7 +87,15 @@ private:
|
||||||
EditState state = Clean;
|
EditState state = Clean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DataType //数据类型
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
QString type;
|
||||||
|
QString db; //为哪个数据库的可用类型
|
||||||
|
};
|
||||||
|
|
||||||
void iniDisplayField();
|
void iniDisplayField();
|
||||||
|
void getDataTypes();
|
||||||
void loadPageData(); // 加载当前页数据
|
void loadPageData(); // 加载当前页数据
|
||||||
void updateTotalCount(); // 更新总记录数
|
void updateTotalCount(); // 更新总记录数
|
||||||
|
|
||||||
|
|
@ -99,6 +107,7 @@ private:
|
||||||
QList<FieldInfo> m_displayField;
|
QList<FieldInfo> m_displayField;
|
||||||
QList<RowData> m_currentPageData;
|
QList<RowData> m_currentPageData;
|
||||||
QHash<int, RowData> m_modifiedRows; //key:global row number
|
QHash<int, RowData> m_modifiedRows; //key:global row number
|
||||||
|
QMap<int, DataType> m_dataTypes;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //ATTRIBUTETABLEMODEL_H
|
#endif //ATTRIBUTETABLEMODEL_H
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,24 @@ struct Model
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Attribute
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
QString name; //中文展示名称(filed:attribute_name)
|
||||||
|
QString type; //英文表示名称(filed:attribute),不可重名
|
||||||
|
int dataTypeID;
|
||||||
|
int dataLength; //filed:length_precision
|
||||||
|
QString defaultValue;
|
||||||
|
|
||||||
|
Attribute(int id, QString name, QString type, int dataTypeID, int dataLength, QString defaultVaule)
|
||||||
|
:id(id),
|
||||||
|
name(std::move(name)),
|
||||||
|
type(std::move(type)),
|
||||||
|
dataTypeID(dataTypeID),
|
||||||
|
dataLength(dataLength),
|
||||||
|
defaultValue(std::move(defaultVaule)){}
|
||||||
|
};
|
||||||
|
|
||||||
struct ModelAttributeGroup
|
struct ModelAttributeGroup
|
||||||
{
|
{
|
||||||
int modelID;
|
int modelID;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
#include <QMap>
|
#include <QHash>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
class SqlQueryExecutor : public QObject
|
class SqlQueryExecutor : public QObject
|
||||||
|
|
@ -21,6 +21,7 @@ public:
|
||||||
*/
|
*/
|
||||||
QSqlQuery executeBatchSQL(const QString& strConnectionName, const QStringList& sqlStatements,
|
QSqlQuery executeBatchSQL(const QString& strConnectionName, const QStringList& sqlStatements,
|
||||||
const QList<QVariantHash>& paramsList = QList<QVariantHash>(), bool useTranscation = false);
|
const QList<QVariantHash>& paramsList = QList<QVariantHash>(), bool useTranscation = false);
|
||||||
|
QHash<QString, QString> getFiledType(const QString& strConnectionName, const QString& table, const QString& schema = "basic");
|
||||||
//基于具体业务的查询接口-对外调用
|
//基于具体业务的查询接口-对外调用
|
||||||
const QVector<Model> getModels(const QString&);
|
const QVector<Model> getModels(const QString&);
|
||||||
const QVector<AttributeGroup> getAttributeGroup(const QString&);
|
const QVector<AttributeGroup> getAttributeGroup(const QString&);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ AttributeTableModel::AttributeTableModel(const ModelAttributeGroup& modelAttribu
|
||||||
m_paginationInfo.currentPage = 1;
|
m_paginationInfo.currentPage = 1;
|
||||||
m_paginationInfo.totalEntries = 0;
|
m_paginationInfo.totalEntries = 0;
|
||||||
|
|
||||||
|
getDataTypes();
|
||||||
iniDisplayField();
|
iniDisplayField();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -158,32 +159,60 @@ void AttributeTableModel::iniDisplayField()
|
||||||
FieldInfo field1;
|
FieldInfo field1;
|
||||||
field1.originalName = "attribute";
|
field1.originalName = "attribute";
|
||||||
field1.displayName = QString::fromWCharArray(L"属性类别");
|
field1.displayName = QString::fromWCharArray(L"属性类别");
|
||||||
field1.dataType = "character varying(128)";
|
//field1.dataType = "character varying(128)";
|
||||||
m_displayField.append(field1);
|
m_displayField.append(field1);
|
||||||
|
|
||||||
FieldInfo field2;
|
FieldInfo field2;
|
||||||
field2.originalName = "attribute_name";
|
field2.originalName = "attribute_name";
|
||||||
field2.displayName = QString::fromWCharArray(L"属性名称");
|
field2.displayName = QString::fromWCharArray(L"属性名称");
|
||||||
field2.dataType = "character varying(64)";
|
//field2.dataType = "character varying(64)";
|
||||||
m_displayField.append(field2);
|
m_displayField.append(field2);
|
||||||
|
|
||||||
FieldInfo field3;
|
FieldInfo field3;
|
||||||
field3.originalName = "data_type_id";
|
field3.originalName = "data_type_id";
|
||||||
field3.displayName = QString::fromWCharArray(L"数据类型");
|
field3.displayName = QString::fromWCharArray(L"数据类型");
|
||||||
field3.dataType = "bigint";
|
//field3.dataType = "bigint";
|
||||||
m_displayField.append(field3);
|
m_displayField.append(field3);
|
||||||
|
|
||||||
FieldInfo field4;
|
FieldInfo field4;
|
||||||
field4.originalName = "length_precision";
|
field4.originalName = "length_precision";
|
||||||
field4.displayName = QString::fromWCharArray(L"数据精度");
|
field4.displayName = QString::fromWCharArray(L"数据长度");
|
||||||
field4.dataType = "integer";
|
//field4.dataType = "integer";
|
||||||
m_displayField.append(field4);
|
m_displayField.append(field4);
|
||||||
|
|
||||||
FieldInfo field5;
|
FieldInfo field5;
|
||||||
field5.originalName = "default_value";
|
field5.originalName = "default_value";
|
||||||
field5.displayName = QString::fromWCharArray(L"默认值");
|
field5.displayName = QString::fromWCharArray(L"默认值");
|
||||||
field5.dataType = "character varying(64)";
|
//field5.dataType = "character varying(64)";
|
||||||
m_displayField.append(field5);
|
m_displayField.append(field5);
|
||||||
|
|
||||||
|
QHash<QString, QString> fieldType = SqlQueryExecutor::instance().getFiledType(m_connection, "attribute", "basic");
|
||||||
|
for(int i = 0; i < m_displayField.count(); i++)
|
||||||
|
{
|
||||||
|
QString strFiled = m_displayField.at(i).originalName;
|
||||||
|
m_displayField[i].dataType = fieldType.value(strFiled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AttributeTableModel::getDataTypes()
|
||||||
|
{
|
||||||
|
QString strSQL = "SELECT * FROM basic.data_type ORDER BY id ASC";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
QSqlQuery query = SqlQueryExecutor::instance().executeSQL(m_connection, strSQL);
|
||||||
|
while(query.next())
|
||||||
|
{
|
||||||
|
DataType dataType;
|
||||||
|
dataType.id = query.value(0).toInt();
|
||||||
|
dataType.type = query.value(1).toString();
|
||||||
|
dataType.db = query.value(2).toString();
|
||||||
|
m_dataTypes.insert(dataType.id, dataType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const DatabaseException& e)
|
||||||
|
{
|
||||||
|
LOG_ERROR("SQL", QString::fromWCharArray(L"获取数据类型失败"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AttributeTableModel::loadPageData()
|
void AttributeTableModel::loadPageData()
|
||||||
|
|
@ -358,14 +387,14 @@ void AttributeTableModel::removeRecord(int row)
|
||||||
|
|
||||||
|
|
||||||
int globalRow = (m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage + row;
|
int globalRow = (m_paginationInfo.currentPage - 1) * m_paginationInfo.entriesPerPage + row;
|
||||||
/*if(m_currentPageData.at(row).state == New) //新添加未提交的记录,直接删除
|
if(m_currentPageData.at(row).state == New) //新添加未提交的记录,直接删除
|
||||||
{
|
{
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
m_modifiedRows.remove(globalRow);
|
m_modifiedRows.remove(globalRow);
|
||||||
m_currentPageData.removeAt(row);
|
m_currentPageData.removeAt(row);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
else*/ //整行画红线进行标记
|
else //整行画红线进行标记
|
||||||
{
|
{
|
||||||
m_currentPageData[row].state = Deleted;
|
m_currentPageData[row].state = Deleted;
|
||||||
m_modifiedRows[globalRow] = m_currentPageData[row];
|
m_modifiedRows[globalRow] = m_currentPageData[row];
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,35 @@ QSqlQuery SqlQueryExecutor::executeBatchSQL(const QString& strConnectionName, co
|
||||||
|
|
||||||
return lastQuery;
|
return lastQuery;
|
||||||
}
|
}
|
||||||
|
//获取表的字段类型信息(目前只针对PostgerSQL)
|
||||||
|
QHash<QString, QString> SqlQueryExecutor::getFiledType(const QString& strConnectionName, const QString& table, const QString& schema)
|
||||||
|
{
|
||||||
|
QHash<QString, QString> fieldTypes;
|
||||||
|
QString strSQL = QString(
|
||||||
|
"SELECT a.attname, pg_catalog.format_type(a.atttypid, a.atttypmod) "
|
||||||
|
"FROM pg_catalog.pg_attribute a "
|
||||||
|
"JOIN pg_catalog.pg_class c ON a.attrelid = c.oid "
|
||||||
|
"JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid "
|
||||||
|
"WHERE c.relname = LOWER(:table_name) "
|
||||||
|
"AND n.nspname = LOWER(:schema_name) "
|
||||||
|
"AND a.attnum > 0 AND NOT a.attisdropped;"
|
||||||
|
);
|
||||||
|
QVariantHash params;
|
||||||
|
params.insert(":table_name", table);
|
||||||
|
params.insert(":schema_name", schema);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
QSqlQuery query = executeSQL(strConnectionName, strSQL, params);
|
||||||
|
while(query.next())
|
||||||
|
fieldTypes.insert(query.value(0).toString(), query.value(1).toString());
|
||||||
|
}
|
||||||
|
catch (const DatabaseException& e)
|
||||||
|
{
|
||||||
|
LOG_ERROR("SQL", QString::fromWCharArray(L"获取属性原始数据类型失败"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return fieldTypes;
|
||||||
|
}
|
||||||
|
|
||||||
//具体业务查询接口
|
//具体业务查询接口
|
||||||
const QVector<Model> SqlQueryExecutor::getModels(const QString& strConnectionName)
|
const QVector<Model> SqlQueryExecutor::getModels(const QString& strConnectionName)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue