Commit 3dbc7070 authored by 刘乐's avatar 刘乐

1, 新街口

parent 7a7924a1
......@@ -14,17 +14,8 @@ int main(int argc, char* argv[])
const char* uri = "host=192.168.19.100 port=5432 dbname=JinXian user=postgres password=admin";
char* findUri = const_cast<char*>(uri);
char net[128];
char flag[128];
const char* file = "test.inp";
const char netName[128] = "水力模型管网";
strcpy_s(net, "水力模型管网");
strcpy_s(flag, "QUALITY");
bool msg = simulation(findUri, net, flag);
std::cout << msg << std::endl;
int succ = hdyrSimulation(findUri);
std::cout << succ << std::endl;
/*const char* date = "2020-07-02";
char* dates = const_cast<char*>(date);
......
......@@ -24,12 +24,14 @@ CivInpBuilder::CivInpBuilder()
:mDbConn(nullptr)
{
mNewInp = new CivNewInp();
mNewInp->setTtitle("");
}
CivInpBuilder::CivInpBuilder(CivDbConn* dbConn)
:mDbConn(dbConn)
{
mNewInp = new CivNewInp();
mNewInp->setTtitle("");
}
CivInpBuilder::~CivInpBuilder()
......@@ -52,8 +54,7 @@ void CivInpBuilder::buildNode()
ASSERT(mDbConn, mNewInp)
CivNode node;
bool succ = mDbConn->getNode(node);
if (succ)
if (!mDbConn->getNode(node))
return;
mNewInp->setNode(node);
......@@ -64,8 +65,7 @@ void CivInpBuilder::buildPipe()
ASSERT(mDbConn, mNewInp)
CivPipe pipe;
bool succ = mDbConn->getPipe(pipe);
if (succ)
if (!mDbConn->getPipe(pipe))
return;
mNewInp->setPipes(pipe);
......@@ -76,8 +76,7 @@ void CivInpBuilder::buildTank()
ASSERT(mDbConn, mNewInp)
CivTank tank;
bool succ = mDbConn->getTank(tank);
if (succ)
if (!mDbConn->getTank(tank))
return;
mNewInp->setTank(tank);
......@@ -88,8 +87,7 @@ void CivInpBuilder::buildVavle()
ASSERT(mDbConn, mNewInp)
CivValve valve;
bool succ = mDbConn->getValve(valve);
if (succ)
if (!mDbConn->getValve(valve))
return;
mNewInp->setValves(valve);
......@@ -100,8 +98,7 @@ void CivInpBuilder::buildPump()
ASSERT(mDbConn, mNewInp)
CivPumps valve;
bool succ = mDbConn->getPumps(valve);
if (succ)
if (!mDbConn->getPumps(valve))
return;
mNewInp->setPumps(valve);
......@@ -112,8 +109,7 @@ void CivInpBuilder::buildReservoir()
ASSERT(mDbConn, mNewInp)
CivReservoirs res;
bool succ = mDbConn->getReservoirs(res);
if (succ)
if (!mDbConn->getReservoirs(res))
return;
mNewInp->setReservoirs(res);
......@@ -124,8 +120,7 @@ void CivInpBuilder::buildEmitter()
ASSERT(mDbConn, mNewInp)
CivEmitters emmiters;
bool succ = mDbConn->getEmitters(emmiters);
if (succ)
if (!mDbConn->getEmitters(emmiters))
return;
mNewInp->setEmitters(emmiters);
......@@ -168,8 +163,7 @@ void CivInpBuilder::buildCoordnates()
ASSERT(mDbConn, mNewInp)
CivCoordinates coords;
bool succ = mDbConn->getCoordinates(coords);
if (succ)
if (!mDbConn->getCoordinates(coords))
return;
mNewInp->setCoordnates(coords);
......@@ -185,8 +179,7 @@ void CivInpBuilder::buildLabels()
ASSERT(mDbConn, mNewInp)
CivLabels labels;
bool succ = mDbConn->getLabels(labels);
if (succ)
if (!mDbConn->getLabels(labels))
return;
mNewInp->setLabels(labels);
......@@ -197,8 +190,7 @@ void CivInpBuilder::buildTags()
ASSERT(mDbConn, mNewInp)
CivTags tag;
bool succ = mDbConn->getTags(tag);
if (succ)
if (!mDbConn->getTags(tag))
return;
mNewInp->setTags(tag);
......@@ -214,8 +206,7 @@ void CivInpBuilder::buildQuality()
ASSERT(mDbConn, mNewInp)
CivQuality quality;
bool succ = mDbConn->getQuality(quality);
if (succ)
if (!mDbConn->getQuality(quality))
return;
mNewInp->setQuality(quality);
......@@ -226,8 +217,7 @@ void CivInpBuilder::buildSources()
ASSERT(mDbConn, mNewInp)
CivSources sources;
bool succ = mDbConn->getSources(sources);
if (succ)
if (!mDbConn->getSources(sources))
return;
mNewInp->setSources(sources);
......@@ -238,8 +228,7 @@ void CivInpBuilder::buildMixing()
ASSERT(mDbConn, mNewInp)
CivMixing mixing;
bool succ = mDbConn->getMixing(mixing);
if (succ)
if (!mDbConn->getMixing(mixing))
return;
mNewInp->setMixing(mixing);
......@@ -250,8 +239,7 @@ void CivInpBuilder::buildCurves()
ASSERT(mDbConn, mNewInp)
CivCurves curves;
bool succ = mDbConn->getCurves(curves);
if (succ)
if (!mDbConn->getCurves(curves))
return;
mNewInp->setCurves(curves);
......@@ -262,8 +250,7 @@ void CivInpBuilder::buildStatus()
ASSERT(mDbConn, mNewInp)
CivStatus status;
bool succ = mDbConn->getStatus(status);
if (succ)
if (!mDbConn->getStatus(status))
return;
mNewInp->setStatus(status);
......@@ -284,8 +271,7 @@ void CivInpBuilder::buildDemands()
ASSERT(mDbConn, mNewInp)
CivDemands mand;
bool succ = mDbConn->getDemands(mand);
if (succ)
if (!mDbConn->getDemands(mand))
return;
mNewInp->setDemands(mand);
......
......@@ -7,8 +7,8 @@
#include <time.h>
#include "CivBuilder.h"
#include "CivInpDirector.h"
#include"CivDbConn.h"
#include"CivPgConn.h"
#include "CivDbConn.h"
#include "CivPgConn.h"
#include <iostream>
CivHydrCalc::CivHydrCalc(char* uri, std::string netName)
......@@ -229,36 +229,18 @@ bool CivHydrCalc::qualitySimulation(char* inpFile, char* rptFile, char* binOutFi
bool CivHydrCalc::exportInp(char* fileName)
{
////1 ,获取管网组件
//if (!mDbConn)
// return false;
//1 ,获取管网组件
if (!mDbConn)
return false;
//if (!mDbConn->open())
// return false;
CivBuilder* builder = new CivInpBuilder();
builder->registDb(mPgConn);
CivInpDirector director;
director.setBuilder(builder);
director.create();
CivNewInp* newInp = builder->getNewInp();
if (!newInp->writeToFile(fileName))
{
delete builder;
delete newInp;
if (!mDbConn->open())
return false;
}
delete builder;
delete newInp;
return true;
/*bool pattern = mDbConn->createTable(*CivPatternTableTemp());
bool cii = mDbConn->createTable(OPTIONTTABLE, "public", CivTableTemp::PARAMETER_TABLE);
bool curve = mDbConn->createTable(CURVETABLE, "public", CivTableTemp::CURVE_TABLE);
bool node = mDbConn->createTable(NODERESULTTABLE, "public", CivTableTemp::NODE_TABLE);
bool link = mDbConn->createTable(PIPERESULTTABLE, "public", CivTableTemp::PIPE_TABLE);*/
///*bool pattern = mDbConn->createTable(*CivPatternTableTemp());
//bool cii = mDbConn->createTable(OPTIONTTABLE, "public", CivTableTemp::PARAMETER_TABLE);
//bool curve = mDbConn->createTable(CURVETABLE, "public", CivTableTemp::CURVE_TABLE);
//bool node = mDbConn->createTable(NODERESULTTABLE, "public", CivTableTemp::NODE_TABLE);
//bool link = mDbConn->createTable(PIPERESULTTABLE, "public", CivTableTemp::PIPE_TABLE);*/
// 获取表格
Tables tables = mDbConn->getTables(mNetname);
......@@ -312,7 +294,7 @@ bool CivHydrCalc::exportInp(char* fileName)
civInp.setTimeStart("REPORT", 1);
civInp.writeToFile(fileName);
return true;
return false;
}
void CivHydrCalc::assemble(const std::string& table, CivInp& inp)
......@@ -776,4 +758,4 @@ void CivHydrCalc::getLinkQuality(short time)
}
free(typeCode);
free(quality);
}
}
\ No newline at end of file
......@@ -39,10 +39,10 @@ bool DLLEXPORT hdySimulation(char* uri, char* netName)
return true;
}
bool DLLEXPORT qualitySimulation(char* uri, char* netName, char* type)
{
return true;
}
//bool DLLEXPORT qualitySimulation(char* uri, char* netName, char* type)
//{
// return true;
//}
bool DLLEXPORT qualityTrackingSimulation(char* uri, char* netName, char* nodeSn, char* time)
{
......@@ -61,5 +61,61 @@ bool DLLEXPORT getDataByInterval(char* uri, char* date, char* interval)
std::cout << flag << std::endl;
//flag = calc->getDataByInterval(date, interval);
delete calc;
return flag;
}
#include "CivPgConn.h"
#include "CivHydrSimulation.h"
int DLLEXPORT hdyrSimulation(char* uri)
{
// 创建数据库连接
CivDbConn* pgConn = new CivPgConn(uri);
// 模拟计算对象
CivHydrSimulation* mHyDr = new CivHydrSimulation();
mHyDr->registDb(pgConn);
//开始模拟
int flag = mHyDr->hdyrSimulation();
/* delete mHyDr;
delete pgConn;*/
return flag;
}
int DLLEXPORT qualitySimulation(char* uri)
{
// 创建数据库连接
CivPgConn* pgConn = new CivPgConn(uri);
// 模拟计算对象
CivHydrSimulation* mHyDr = new CivHydrSimulation();
mHyDr->registDb(pgConn);
//开始模拟
int flag = mHyDr->qualitySimulation();
delete pgConn;
delete mHyDr;
return flag;
}
int DLLEXPORT trackingSimulation(char* uri, char* sN)
{
// 创建数据库连接
CivPgConn* pgConn = new CivPgConn(uri);
// 模拟计算对象
CivHydrSimulation* mHyDr = new CivHydrSimulation();
mHyDr->registDb(pgConn);
//开始模拟
int flag = mHyDr->trackingSimulation(sN);
delete pgConn;
delete mHyDr;
return flag;
}
\ No newline at end of file
......@@ -5,6 +5,11 @@
#if defined(__cplusplus)
extern "C" {
#endif
int DLLEXPORT hdyrSimulation(char* uri);
int DLLEXPORT qualitySimulation(char* uri);
int DLLEXPORT trackingSimulation(char* uri,char* sN);
/**
*@brief 模拟计算
*@uri: 管网数据库连接
......@@ -12,7 +17,7 @@ extern "C" {
*@flag: 标记
*/
bool DLLEXPORT simulation(char* uri, char* netName, char* flag);
/**
*@brief 水力模拟计算
*@uri: 管网数据库连接
......@@ -26,7 +31,7 @@ extern "C" {
*@netName: 管网名
*@type: 水质模拟类型选择,水龄,追踪,化学成分
*/
bool DLLEXPORT qualitySimulation(char* uri, char* netName, char* type);
//bool DLLEXPORT qualitySimulation(char* uri, char* netName, char* type);
/**
*@brief 水质追踪模拟计算
......
This diff is collapsed.
#pragma once
#include "CivSimulResultCache.h"
class CivDbConn;
/**
水力模拟计算类
*/
class CivHydrSimulation
{
public:
explicit CivHydrSimulation();
explicit CivHydrSimulation(CivDbConn* dbConn);
~CivHydrSimulation();
/**
*@biref 注册数据库
*/
void registDb(CivDbConn* dbConn);
/**
*@brief 水力模拟
*/
int hdyrSimulation();
/**
*@brief 水质模拟,水龄,化学物质
*/
int qualitySimulation();
/**
*@brief 追踪分析,本质仍然式水质分析
*@snNode:追踪的节点号
*/
int trackingSimulation(char* snNode);
/**
*@导出inp文件
*/
bool convertInp();
inline char* getInpFile();
inline void setInpFile(const std::string& inpFile);
inline char* getRptFile();
inline void setRptFile(const std::string& rptFile);
inline char* getBinFile();
inline void setBinFile(const std::string& binFile);
private:
void getNodeResult(short time);
void getLinkResult(short time);
void getNodeQuality(short time);
void getLinkQuality(short time);
private:
CivDbConn* mDbConn;
CivSimulResultCache mResultCache; // 存储模拟结果缓存类
std::string mInpFile;// inp文件名
std::string mRptFile; // 报告文件名
std::string mBinFile;// 二进制文件名
};
......@@ -412,7 +412,7 @@ void CivInp::writeString(const std::string& s)
void CivInp::setPattern(StrQuote pId, std::vector<Str> pValue)
{
}
void CivInp::setOption(Options options, const std::map<std::string, std::string>& others)
......
......@@ -12,10 +12,10 @@ void CivInpDirector::create()
if (mBuilder == NULL)
return;
mBuilder->buildNode();
mBuilder->buildPipe();
mBuilder->buildTank();
mBuilder->buildReservoir();
mBuilder->buildNode();
mBuilder->buildPipe();
mBuilder->buildPump();
mBuilder->buildVavle();
mBuilder->buildEmitter();
......
......@@ -70,6 +70,7 @@ void CivNewInp::setNode(const CivNode& node)
writeStringFormat(nodeTable.Demand);
writeString(nodeTable.PatternId);
}
writeString("");
}
void CivNewInp::setPipes(const CivPipe& pipes)
......@@ -91,6 +92,7 @@ void CivNewInp::setPipes(const CivPipe& pipes)
writeStringFormat(pipesTable.MinorLoss);
writeString(pipesTable.Status);
}
writeString("");
}
void CivNewInp::setTank(const CivTank& tank)
......@@ -112,6 +114,7 @@ void CivNewInp::setTank(const CivTank& tank)
writeStringFormat(table.MinVol);
writeString(table.VolCurve);
}
writeString("");
}
void CivNewInp::setValves(const CivValve& valve)
......@@ -132,6 +135,7 @@ void CivNewInp::setValves(const CivValve& valve)
writeStringFormat(table.Setting);
writeString(table.MinorLoss);
}
writeString("");
}
void CivNewInp::setPumps(const CivPumps& pumps)
......@@ -149,6 +153,7 @@ void CivNewInp::setPumps(const CivPumps& pumps)
writeStringFormat(table.Node2);
writeString(table.Parameters);
}
writeString("");
}
void CivNewInp::setEmitters(const CivEmitters& mitters)
......@@ -165,6 +170,7 @@ void CivNewInp::setEmitters(const CivEmitters& mitters)
writeStringFormat(table.ID);
writeString(table.coeff);
}
writeString("");
}
void CivNewInp::setReservoirs(const CivReservoirs& res)
......@@ -183,6 +189,7 @@ void CivNewInp::setReservoirs(const CivReservoirs& res)
writeStringFormat(table.Head);
writeString(table.Pattern);
}
writeString("");
}
// 系统运行
......@@ -202,7 +209,7 @@ void CivNewInp::setCurves(const CivCurves& cureves)
writeStringFormat(table.XCoord);
writeString(table.YCoord);
}
writeString("");
}
......@@ -221,6 +228,7 @@ void CivNewInp::setPatterns(const CivPatterns& patterns)
writeStringFormat(table.name);
writeString(table.val);
}
writeString("");
}
......@@ -238,6 +246,7 @@ void CivNewInp::setStatus(const CivStatus& status)
writeStringFormat(table.ID);
writeString(table.Setting);
}
writeString("");
}
void CivNewInp::setControls(const std::string& control)
......@@ -269,6 +278,7 @@ void CivNewInp::setDemands(const CivDemands& demands)
writeStringFormat(table.PatternId);
writeString(table.DemandType);
}
writeString("");
}
// 水质
......@@ -284,8 +294,9 @@ void CivNewInp::setQuality(const CivQuality& quality)
{
CivQuality::Table table = *iter;
writeStringFormat(table.ID);
writeStringFormat(table.InitQuality);
writeString(table.InitQuality);
}
writeString("");
}
void CivNewInp::setSources(const CivSources& sources)
......@@ -305,6 +316,7 @@ void CivNewInp::setSources(const CivSources& sources)
writeStringFormat(table.Quality);
writeString(table.Pattern);
}
writeString("");
}
void CivNewInp::setMixing(const CivMixing& mixing)
......@@ -322,6 +334,7 @@ void CivNewInp::setMixing(const CivMixing& mixing)
writeStringFormat(table.hyModel);
writeString(table.volume);
}
writeString("");
}
// 选项和报表
......@@ -340,6 +353,7 @@ void CivNewInp::setParamter(const CivParameter& params,const std::string& type)
writeStringFormat(table.name);
writeString(table.val);
}
writeString("");
}
//管网地图/标签
......@@ -359,6 +373,7 @@ void CivNewInp::setCoordnates(const CivCoordinates& coords)
writeStringFormat(table.XCoord);
writeString(table.YCoord);
}
writeString("");
}
void CivNewInp::setVertices()
......@@ -384,6 +399,7 @@ void CivNewInp::setLabels(const CivLabels& labels)
writeStringFormat(table.Label);
writeStringFormat(table.ID);
}
writeString("");
}
void CivNewInp::setBackDrop()
......@@ -408,6 +424,7 @@ void CivNewInp::setTags(const CivTags& tags)
writeStringFormat(table.Id);
writeString(table.Label);
}
writeString("");
}
void CivNewInp::writeString(const std::string& s)
......
......@@ -35,6 +35,38 @@ void CivSimulResultCache::addLinkItems(const LinkResultItem& linkItem)
mLinkItemsMap[linkItem.dInterval][linkItem.szNo] = linkItem;
}
bool CivSimulResultCache::updateToDb(CivDbConn* dbConn)
{
CivSysLog::getInstance()->error("开始写入数据库", "CivSimulResultCache", __FUNCTION__);
if (dbConn == nullptr)
{
CivSysLog::getInstance()->error("dbConn == nullptr", "CivSimulResultCache", __FUNCTION__);
return false;
}
for (auto iter = mNodeItemsMap.begin(); iter != mNodeItemsMap.end(); iter++)
{
NodeResultItems nodeItems = iter->second;
if (!dbConn->updateNode(nodeItems))
{
CivSysLog::getInstance()->error("存储节点数据失败", "CivSimulResultCache", __FUNCTION__);
}
}
for (auto iter = mLinkItemsMap.begin(); iter != mLinkItemsMap.end(); iter++)
{
LinkResultItems nodeItems = iter->second;
if (!dbConn->updateLink(nodeItems))
{
CivSysLog::getInstance()->error("存储管段数据失败", "CivSimulResultCache", __FUNCTION__);
}
}
CivSysLog::getInstance()->error("写入数据库完成", "CivSimulResultCache", __FUNCTION__);
clear();
return true;
}
bool CivSimulResultCache::updateToDb(CivDbConnection* dbConn)
{
CivSysLog::getInstance()->error("开始写入数据库", "CivSimulResultCache", __FUNCTION__);
......
......@@ -50,7 +50,7 @@ public:
*@dbConn:数据库连接对象
*/
bool updateToDb(CivDbConnection* dbConn);
bool updateToDb(CivDbConn* dbConn);
private:
std::map<int, NodeResultItems> mNodeItemsMap; // 模拟
std::map<int, LinkResultItems> mLinkItemsMap; // 计算的
......
......@@ -155,6 +155,7 @@
<ClCompile Include="..\pandaDbManager\CivCommonUtils.cpp" />
<ClCompile Include="CivHydrCalc.cpp" />
<ClCompile Include="CivHydrFuncInter.cpp" />
<ClCompile Include="CivHydrSimulation.cpp" />
<ClCompile Include="CivInp.cpp" />
<ClCompile Include="CivBuilder.cpp" />
<ClCompile Include="CivInpDirector.cpp" />
......@@ -164,6 +165,7 @@
<ItemGroup>
<ClInclude Include="CivHydrCalc.h" />
<ClInclude Include="CivHydrFuncInter.h" />
<ClInclude Include="CivHydrSimulation.h" />
<ClInclude Include="CivInp.h" />
<ClInclude Include="CivBuilder.h" />
<ClInclude Include="CivInpDirector.h" />
......
......@@ -39,6 +39,9 @@
<ClCompile Include="CivSimulResultCache.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivHydrSimulation.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CivHydrCalc.h">
......@@ -65,5 +68,8 @@
<ClInclude Include="CivMiddlewareQuery.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivHydrSimulation.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -8,6 +8,7 @@ CivDbConn::CivDbConn()
CivDbConn::~CivDbConn()
{
}
bool CivDbConn::isValid() const
......
......@@ -62,7 +62,7 @@ public:
bool isValid() const;
private:
/**
*@brief 根据字段值条件删除数据
*@table:表
......@@ -88,12 +88,12 @@ private:
// 获取当前执行错误信息
Str getLastError() const;
private:
/**
*@brief 执行sql语句
*@sql: 需要执行的sql语句
*/
virtual bool execSql(Str sql) = 0;
virtual bool execSql(StrQuote sql) = 0;
protected:
bool mIsOpen = false; // 数据库连接信息
......
#include "CivPgConn.h"
#include "CivCommonUtils.h"
#include<iostream>
CivPgConn::CivPgConn(char* uri)
:mUri(uri), CivDbConn()
......@@ -10,7 +11,7 @@ CivPgConn::CivPgConn(char* uri)
CivPgConn::~CivPgConn()
{
close();
}
bool CivPgConn::open()
......@@ -28,14 +29,15 @@ bool CivPgConn::open()
void CivPgConn::close()
{
if (mConn != NULL)
{
PQfinish(mConn);
}
mIsOpen = false;
}
bool CivPgConn::tableExist(StrQuote tableName)
{
char sql[256] = "select count(*) from pg_class where relname = '";
strcat_s(sql, tableName.c_str());
strcat_s(sql, "'");
......@@ -50,7 +52,7 @@ bool CivPgConn::tableExist(StrQuote tableName)
return number > 0 ? true : false;
}
bool CivPgConn::execSql(Str sql)
bool CivPgConn::execSql(StrQuote sql)
{
if (sql.empty())
return false;
......@@ -65,6 +67,7 @@ bool CivPgConn::execSql(Str sql)
if (!errorStr.empty())
{
mLastError = error;
std::cout << errorStr << std::endl;
PQclear(mResult);
return false;
}
......@@ -82,10 +85,12 @@ bool CivPgConn::getNode(CivNode& node)
strcat_s(sql, ",");
strcat_s(sql, nodeTable.elev.c_str());
strcat_s(sql, ",");
strcat_s(sql, nodeTable.pattern.c_str());
strcat_s(sql, ",");
strcat_s(sql, nodeTable.demand.c_str());
strcat_s(sql, " from 节点");
strcat_s(sql, ",");
strcat_s(sql, nodeTable.pattern.c_str());
strcat_s(sql, " from public.\"");
strcat_s(sql, PIPENODE.c_str());
strcat_s(sql, "\"");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
......@@ -174,7 +179,9 @@ bool CivPgConn::getTank(CivTank& tank)
strcat_s(sql, tankTable.capacity.c_str());
strcat_s(sql, ",");
strcat_s(sql, tankTable.volCurve.c_str());
strcat_s(sql, " from 水池");
strcat_s(sql, " from public.\"");
strcat_s(sql, TANK.c_str());
strcat_s(sql, "\"");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
......@@ -219,7 +226,9 @@ bool CivPgConn::getValve(CivValve& valve)
strcat_s(sql, vaveTable.setting.c_str());
strcat_s(sql, ",");
strcat_s(sql, vaveTable.loss.c_str());
strcat_s(sql, " from 阀门");
strcat_s(sql, " from public.\"");
strcat_s(sql, VALVE.c_str());
strcat_s(sql, "\"");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
......@@ -257,7 +266,9 @@ bool CivPgConn::getPumps(CivPumps& pump)
strcat_s(sql, pmTable.endPoint.c_str());
strcat_s(sql, ",");
strcat_s(sql, pmTable.headCurve.c_str());
strcat_s(sql, " from 水泵");
strcat_s(sql, " from public.\"");
strcat_s(sql, PUMP.c_str());
strcat_s(sql, "\"");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
......@@ -290,7 +301,9 @@ bool CivPgConn::getReservoirs(CivReservoirs& reservoirs)
strcat_s(sql, restemTable.head.c_str());
strcat_s(sql, ",");
strcat_s(sql, restemTable.headPattern.c_str());
strcat_s(sql, " from public.\"__pattern__\"");
strcat_s(sql, " from public.\"");
strcat_s(sql, RESIVOIR.c_str());
strcat_s(sql,"\"");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
......@@ -320,16 +333,37 @@ bool CivPgConn::getCoordinates(CivCoordinates& coord)
{
CivJunctionTableTemp::JunctionTable nodeTable;
char sql[256] = "select ";
strcat_s(sql, nodeTable.thePoint.c_str());
char sql[512] = "select ";
strcat_s(sql, TransUTFCoding(nodeTable.thePoint).c_str());
strcat_s(sql, ",");
strcat_s(sql, nodeTable.xCoord.c_str());
strcat_s(sql, TransUTFCoding(nodeTable.xCoord).c_str());
strcat_s(sql, ",");
strcat_s(sql, nodeTable.yCoord.c_str());
strcat_s(sql, " from 节点");
strcat_s(sql, TransUTFCoding(nodeTable.yCoord).c_str());
strcat_s(sql, " from public.\"");
strcat_s(sql, TransUTFCoding(PIPENODE).c_str());
strcat_s(sql, "\"");
std::string utf8Sql = TransUTFCoding(sql);
if (!execSql(utf8Sql))
strcat_s(sql, " UNION select ");
strcat_s(sql, TransUTFCoding(nodeTable.thePoint).c_str());
strcat_s(sql, ",");
strcat_s(sql, TransUTFCoding(nodeTable.xCoord).c_str());
strcat_s(sql, ",");
strcat_s(sql, TransUTFCoding(nodeTable.yCoord).c_str());
strcat_s(sql, " from public.\"");
strcat_s(sql, TransUTFCoding(TANK).c_str());
strcat_s(sql, "\"");
strcat_s(sql, " UNION select ");
strcat_s(sql, TransUTFCoding(nodeTable.thePoint).c_str());
strcat_s(sql, ",");
strcat_s(sql, TransUTFCoding(nodeTable.xCoord).c_str());
strcat_s(sql, ",");
strcat_s(sql, TransUTFCoding(nodeTable.yCoord).c_str());
strcat_s(sql, " from public.\"");
strcat_s(sql, TransUTFCoding(RESIVOIR).c_str());
strcat_s(sql, "\"");
if (!execSql(sql))
return false;
int rows = PQntuples(mResult);
......@@ -337,7 +371,7 @@ bool CivPgConn::getCoordinates(CivCoordinates& coord)
for (int i = 0; i < rows; i++)
{
CivCoordinates::CoordTable coordTable;
nodeTable.ID = PQgetvalue(mResult, i, 0);
coordTable.ID = PQgetvalue(mResult, i, 0);
coordTable.XCoord = PQgetvalue(mResult, i, 1);
coordTable.YCoord = PQgetvalue(mResult, i, 2);
......@@ -421,11 +455,12 @@ bool CivPgConn::getPatterns(CivPatterns& patterns)
int columns = PQnfields(mResult);
std::map<std::string, std::vector<std::string>> typeMap;
for (int i = 0; i < rows; i++)
{
char* val = PQgetvalue(mResult, i, 2);
char* type = PQgetvalue(mResult, i, 3);
{
char* name = PQgetvalue(mResult, i, 0);
char* val = PQgetvalue(mResult, i, 1);
char* type = PQgetvalue(mResult, i, 2);
typeMap[type].push_back(name);
typeMap[type].push_back(val);
}
......
......@@ -3,6 +3,7 @@
#include <libpq-fe.h>
#include "CivDbConn.h"
/**
postgress 数据库
*/
......@@ -12,7 +13,6 @@ public:
CivPgConn(char* uri);
~CivPgConn();
private:
/**
*@brief 连接数据库,与具体的数据有关子类实现
*/
......@@ -33,7 +33,7 @@ private:
*@brief 执行sql语句
*@sql: 需要执行的sql语句
*/
virtual bool execSql(Str sql);
virtual bool execSql(StrQuote sql);
virtual bool getNode(CivNode& node) ;
virtual bool getPipe(CivPipe& pipe) ;
virtual bool getTank(CivTank& tank) ;
......
......@@ -117,8 +117,8 @@ public:
Str ID = "id";
Str geom = "geom";
Str snNo = "编号";
Str thePoint = "点号";
Str lastPoint = "点号";
Str thePoint = "点号";
Str lastPoint = "点号";
Str length = "管长";
Str material = "管材";
Str diameter = "管径";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment