Commit 02686d8d authored by 刘乐's avatar 刘乐

first commit

parent 397a563e
#pragma once
#include "CivTypes.h"
#include <vector>
#include <libpq-fe.h>
#define DLLEXPORT __declspec(dllexport)
class CivDbConnection;
/**
数据库连接类,获取数据,写入数据接口
*/
class DLLEXPORT CivDbConnection
{
public:
CivDbConnection(char* uri);
~CivDbConnection();
/**
*@brief 获取管网的所有表
*@netName: 管网名
*/
Tables getTables(StrQuote netName);
/**
*@brief 获取管网组件数据:管线,节点,水源等(必须组件) 水泵,阀门(可选组件)
*@tableName: 组件表
*/
Componets getComponets(StrQuote tableName);
/**
*@brief 创建表格
*/
bool createTable(StrQuote tableName);
bool open();
void close();
bool isValid();
private:
PGconn* mConn;
bool mIsOpen = false;
char* mUri;
};
\ No newline at end of file
#pragma once
#include <string>
#define DBNAME std::string("dbname")
#define HOSTADDR std::string("host")
#define USER std::string("user");
#define PASSWORD std::string("password")
#define PORT std::string("port")
class CivDbSourceUri
{
public:
CivDbSourceUri();
CivDbSourceUri(std::string uri);
std::string uri();
void setDbName(const std::string& dbname);
std::string dbName() const;
void setHostAddr(const std::string hostAddr);
std::string hostAddr() const;
void setPort(const std::string& port);
std::string port() const;
void setUserName(const std::string& user);
std::string userName() const;
void setPassword(const std::string& password);
std::string password() const;
private:
private:
std::string mDbName;
std::string mHostAddr;
std::string mUser;
std::string mPassWord;
std::string mPort;
};
\ No newline at end of file
#pragma once
#include <map>
#include<string>
typedef std::string Str;
typedef const std::string& StrQuote;
#define Tables std::vector<Str>
#define PIPELINE Str("管段")
#define PIPENODE Str("节点")
#define RESIVOIR Str("水源")
#define TANK Str("水池")
#define PUMP Str("水泵")
// 管点
#define Node std::map<Str,Str>
#define Nodes std::vector<Node>
// 管线集合
#define Componet std::map<Str,Str>
#define Componets std::vector<Componet>
// 组件类型
enum SectType {
_TITLE, _JUNCTIONS, _RESERVOIRS, _TANKS, _PIPES, _PUMPS,
_VALVES, _CONTROLS, _RULES, _DEMANDS, _SOURCES, _EMITTERS,
_PATTERNS, _CURVES, _QUALITY, _STATUS, _ROUGHNESS, _ENERGY,
_REACTIONS, _MIXING, _REPORT, _TIMES, _OPTIONS,
_COORDS, _VERTICES, _LABELS, _BACKDROP, _TAGS, _END
};
// 数据库与inp文件所需字段的映射
// REACTIONS
// 定义对应于管网中与化学成分反应的参数。
struct Reactions {
};
// [REPORT]
// 描述模拟生成的输出报表内容。
struct Report {
};
/*
*/
// pump
struct PumpFields {
};
//;ID Node1 Node2 Length Diameter Roughness MinorLoss Status
struct PipeFields {
Str ID = "编号";
Str Node1 = Str("上点号");
Str Node2 = Str("本点号");
Str Length = Str("管长");
Str Diameter = Str("管径") ; // 管径
Str Roughness = Str("摩阻系数") ; //
Str MinorLoss = Str("局部水头损");
Str Status = Str("状态");
};
// 节点
struct JunctionsFields {
Str ID = "本点号";
Str Elev = "高程";
Str Demand = "需水量";
Str Pattern = "需水量模式";
Str X_Coord = "横坐标";
Str Y_Coord = "纵坐标";
Str InitQual = "初始水质";
} ;
// 水池
//[TANKS] ;ID Elevation InitLevel MinLevel MaxLevel Diameter MinVol VolCurve
struct TanksFields {
Str ID = "本点号";
Str Elev = "高程";
Str InitLevel = "初始水位";
Str MinLevel = "最低水位";
Str MaxLevel = "最高水位";
Str Diameter = "直径";
Str MinVol = "容量";
Str VolCurve = "容积取线ID";
Str X_Coord = "横坐标";
Str Y_Coord = "纵坐标";
};
#ifndef _EPANETOUT_H
#define _EPANETOUT_H
/* These are codes used by the DLL functions */
// --- Define the EPANET toolkit constants
/// Node property codes
typedef enum {
EN_ELEVATION = 0, /**< Node Elevation */
EN_BASEDEMAND = 1, /**< Node Base Demand, from last demand category */
EN_PATTERN = 2, /**< Node Demand Pattern */
EN_EMITTER = 3, /**< Node Emitter Coefficient */
EN_INITQUAL = 4, /**< Node initial quality */
EN_SOURCEQUAL = 5, /**< Node source quality */
EN_SOURCEPAT = 6, /**< Node source pattern index */
EN_SOURCETYPE = 7, /**< Node source type */
EN_TANKLEVEL = 8, /**< Tank Level */
EN_DEMAND = 9, /**< Node current simulated demand */
EN_HEAD = 10, /**< Node Head value */
EN_PRESSURE = 11, /**< Node pressure value */
EN_QUALITY = 12, /**< Node quality value */
EN_SOURCEMASS = 13, /**< Node source mass value */
EN_INITVOLUME = 14, /**< Tank or Reservoir initial volume */
EN_MIXMODEL = 15, /**< Tank mixing model */
EN_MIXZONEVOL = 16, /**< Tank mixing zone volume */
EN_TANKDIAM = 17, /**< Tank diameter */
EN_MINVOLUME = 18, /**< Tank minimum volume */
EN_VOLCURVE = 19, /**< Tank volume curve index */
EN_MINLEVEL = 20, /**< Tank minimum level */
EN_MAXLEVEL = 21, /**< Tank maximum level */
EN_MIXFRACTION = 22, /**< Tank mixing fraction */
EN_TANK_KBULK = 23, /**< Tank bulk decay coefficient */
EN_TANKVOLUME = 24, /**< Tank current volume */
EN_MAXVOLUME = 25 /**< Tank maximum volume */
} EN_NodeProperty;
/// Link property codes
typedef enum {
EN_DIAMETER = 0,
EN_LENGTH = 1,
EN_ROUGHNESS = 2,
EN_MINORLOSS = 3,
EN_INITSTATUS = 4,
EN_INITSETTING = 5,
EN_KBULK = 6,
EN_KWALL = 7,
EN_FLOW = 8,
EN_VELOCITY = 9,
EN_HEADLOSS = 10,
EN_STATUS = 11,
EN_SETTING = 12,
EN_ENERGY = 13,
EN_LINKQUAL = 14,
EN_LINKPATTERN = 15
} EN_LinkProperty;
/// Time parameter codes
typedef enum {
EN_DURATION = 0,
EN_HYDSTEP = 1,
EN_QUALSTEP = 2,
EN_PATTERNSTEP = 3,
EN_PATTERNSTART = 4,
EN_REPORTSTEP = 5,
EN_REPORTSTART = 6,
EN_RULESTEP = 7,
EN_STATISTIC = 8,
EN_PERIODS = 9,
EN_STARTTIME = 10,
EN_HTIME = 11,
EN_QTIME = 12,
EN_HALTFLAG = 13,
EN_NEXTEVENT = 14
} EN_TimeProperty;
typedef enum {
EN_ITERATIONS = 0,
EN_RELATIVEERROR = 1
} EN_AnalysisStatistic;
typedef enum {
EN_NODECOUNT = 0, /**< Number of Nodes (Juntions + Tanks + Reservoirs) */
EN_TANKCOUNT = 1, /**< Number of Tanks */
EN_LINKCOUNT = 2, /**< Number of Links (Pipes + Pumps + Valves) */
EN_PATCOUNT = 3, /**< Number of Time Patterns */
EN_CURVECOUNT = 4, /**< Number of Curves */
EN_CONTROLCOUNT = 5 /**< Number of Control Statements */
} EN_CountType;
typedef enum {
EN_JUNCTION = 0,
EN_RESERVOIR = 1,
EN_TANK = 2
} EN_NodeType;
typedef enum {
EN_CVPIPE = 0, /* Link types. */
EN_PIPE = 1, /* See LinkType in TYPES.H */
EN_PUMP = 2,
EN_PRV = 3,
EN_PSV = 4,
EN_PBV = 5,
EN_FCV = 6,
EN_TCV = 7,
EN_GPV = 8
} EN_LinkType;
typedef enum {
EN_NONE = 0, /* Quality analysis types. */
EN_CHEM = 1, /* See QualType in TYPES.H */
EN_AGE = 2,
EN_TRACE = 3
} EN_QualityType;
typedef enum {
EN_CONCEN = 0, /* Source quality types. */
EN_MASS = 1, /* See SourceType in TYPES.H. */
EN_SETPOINT = 2,
EN_FLOWPACED = 3
} EN_SourceType;
typedef enum {
EN_CFS = 0, /* Flow units types. */
EN_GPM = 1, /* See FlowUnitsType */
EN_MGD = 2, /* in TYPES.H. */
EN_IMGD = 3,
EN_AFD = 4,
EN_LPS = 5,
EN_LPM = 6,
EN_MLD = 7,
EN_CMH = 8,
EN_CMD = 9
} EN_FlowUnits;
/// Simulation Option codes
typedef enum {
EN_TRIALS = 0,
EN_ACCURACY = 1,
EN_TOLERANCE = 2,
EN_EMITEXPON = 3,
EN_DEMANDMULT = 4
} EN_Option;
typedef enum {
EN_LOWLEVEL = 0, /* Control types. */
EN_HILEVEL = 1, /* See ControlType */
EN_TIMER = 2, /* in TYPES.H. */
EN_TIMEOFDAY = 3
} EN_ControlType;
typedef enum {
EN_AVERAGE = 1, /* Time statistic types. */
EN_MINIMUM = 2, /* See TstatType in TYPES.H */
EN_MAXIMUM = 3,
EN_RANGE = 4
} EN_StatisticType;
typedef enum {
EN_MIX1 = 0, /* Tank mixing models */
EN_MIX2 = 1,
EN_FIFO = 2,
EN_LIFO = 3
} EN_MixingModel;
typedef enum {
EN_NOSAVE = 0,
EN_SAVE = 1,
EN_INITFLOW = 10,
EN_SAVE_AND_INIT = 11
} EN_SaveOption;
typedef enum {
EN_CONST_HP = 0, /* constant horsepower */
EN_POWER_FUNC = 1, /* power function */
EN_CUSTOM = 2 /* user-defined custom curve */
} EN_CurveType;
#ifdef _EPANETDLL_
#define API __declspec(dllexport)
#else
#define API __declspec(dllimport) _stdcall
#endif
#if defined(__cplusplus)
extern "C"
{
#endif
int API ENepanet(char *, char *, char *, void (*) (char *));
int API ENGetVal(int n, float* fRtn);
int API ENopen(char *, char *, char *);
int API ENsaveinpfile(char *);
int API ENclose(void);
int API ENsolveH(void);
int API ENsaveH(void);
int API ENopenH(void);
int API ENinitH(int);
int API ENrunH(long *);
int API ENnextH(long *);
int API ENcloseH(void);
int API ENsavehydfile(char *);
int API ENusehydfile(char *);
int API ENsolveQ(void);
int API ENopenQ(void);
int API ENinitQ(int);
int API ENrunQ(long *);
int API ENnextQ(long *);
int API ENstepQ(long *);
int API ENcloseQ(void);
int API ENwriteline(char *);
int API ENreport(void);
int API ENresetreport(void);
int API ENsetreport(char *);
int API ENgetcontrol(int, int *, int *, float *,int *, float *);
int API ENgetcount(int, int *);
int API ENgetoption(int, float *);
int API ENgettimeparam(int, long *);
int API ENgetflowunits(int *);
int API ENgetpatternindex(char *, int *);
int API ENgetpatternid(int, char *);
int API ENgetpatternlen(int, int *);
int API ENgetpatternvalue(int, int, float *);
int API ENgetqualtype(int *, int *);
int API ENgeterror(int, char *, int);
int API ENgetnodeindex(char *, int *);
int API ENgetnodeid(int, char *);
int API ENgetnodetype(int, int *);
int API ENgetnodevalue(int, int, float *);
int API ENgetlinkindex(char *, int *);
int API ENgetlinkid(int, char *);
int API ENgetlinktype(int, int *);
int API ENgetlinknodes(int, int *, int *);
int API ENgetlinkvalue(int, int, float *);
/*** Updated 10/25/00 ***/
int API ENgetversion(int *);
int API ENsetcontrol(int, int, int, float, int, float);
int API ENsetnodevalue(int, int, float);
int API ENsetlinkvalue(int, int, float);
int API ENsetpattern(int, float *, int);
int API ENsetpatternvalue(int, int, float);
int API ENsettimeparam(int, long);
int API ENsetoption(int, float);
int API ENsetstatusreport(int);
int API ENsetqualtype(int, char *, char *, char *);
//设置水力指数
void API ENsetHexp(double exp);
//设置管网类型
void API ENsetnettype(short type);
//设置管段的管材与压力状态内存
void API ENsetpipestatekindmem(long* pipesk);
//设置资源中心内存
void API ENsetresourcemem(double* pData);
//获得输入错误文件路径
int API ENgetMyErrFile(char* filePath);
int API ENnetSize(int);
int API ENgetpumpvalue(int, float *);
#if defined(__cplusplus)
}
#endif
#ifndef _EPANETDLL_
#ifdef _DEBUG
#pragma comment(lib, "Epanet2D.lib")
#else
#pragma comment(lib, "Epanet2.lib")
#endif
#endif
#endif
/** @file epanet2.h
@see http://github.com/openwateranalytics/epanet
*/
/*
*******************************************************************
EPANET2.H - Prototypes for EPANET Functions Exported to DLL Toolkit
VERSION: 2.00
DATE: 5/8/00
10/25/00
3/1/01
8/15/07 (2.00.11)
2/14/08 (2.00.12)
AUTHORS: L. Rossman - US EPA - NRMRL
OpenWaterAnalytics members: see git stats for contributors
*******************************************************************
*/
#ifndef EPANET2_H
#define EPANET2_H
// the toolkit can be compiled with support for double-precision as well.
// just make sure that you use the correct #define in your client code.
#ifndef EN_API_FLOAT_TYPE
#define EN_API_FLOAT_TYPE float
#endif
// --- define WINDOWS
#undef WINDOWS
#ifdef _WIN32
#define WINDOWS
#endif
#ifdef __WIN32__
#define WINDOWS
#endif
// --- define DLLEXPORT
#ifndef DLLEXPORT
#ifdef WINDOWS
#ifdef __cplusplus
#define DLLEXPORT extern "C" __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllexport) __stdcall
#endif // __cplusplus
#elif defined(CYGWIN)
#define DLLEXPORT __stdcall
#elif defined(__APPLE__)
#ifdef __cplusplus
#define DLLEXPORT
#else
#define DLLEXPORT
#endif
#else
#define DLLEXPORT
#endif
#endif
// --- Define the EPANET toolkit constants
/// Node property codes
typedef enum {
EN_ELEVATION = 0, /**< Node Elevation */
EN_BASEDEMAND = 1, /**< Node Base Demand, from last demand category */
EN_PATTERN = 2, /**< Node Demand Pattern */
EN_EMITTER = 3, /**< Node Emitter Coefficient */
EN_INITQUAL = 4, /**< Node initial quality */
EN_SOURCEQUAL = 5, /**< Node source quality */
EN_SOURCEPAT = 6, /**< Node source pattern index */
EN_SOURCETYPE = 7, /**< Node source type */
EN_TANKLEVEL = 8, /**< Tank Level */
EN_DEMAND = 9, /**< Node current simulated demand */
EN_HEAD = 10, /**< Node Head value */
EN_PRESSURE = 11, /**< Node pressure value */
EN_QUALITY = 12, /**< Node quality value */
EN_SOURCEMASS = 13, /**< Node source mass value */
EN_INITVOLUME = 14, /**< Tank or Reservoir initial volume */
EN_MIXMODEL = 15, /**< Tank mixing model */
EN_MIXZONEVOL = 16, /**< Tank mixing zone volume */
EN_TANKDIAM = 17, /**< Tank diameter */
EN_MINVOLUME = 18, /**< Tank minimum volume */
EN_VOLCURVE = 19, /**< Tank volume curve index */
EN_MINLEVEL = 20, /**< Tank minimum level */
EN_MAXLEVEL = 21, /**< Tank maximum level */
EN_MIXFRACTION = 22, /**< Tank mixing fraction */
EN_TANK_KBULK = 23, /**< Tank bulk decay coefficient */
EN_TANKVOLUME = 24, /**< Tank current volume */
EN_MAXVOLUME = 25 /**< Tank maximum volume */
} EN_NodeProperty;
/// Link property codes
typedef enum {
EN_DIAMETER = 0,
EN_LENGTH = 1,
EN_ROUGHNESS = 2,
EN_MINORLOSS = 3,
EN_INITSTATUS = 4,
EN_INITSETTING = 5,
EN_KBULK = 6,
EN_KWALL = 7,
EN_FLOW = 8,
EN_VELOCITY = 9,
EN_HEADLOSS = 10,
EN_STATUS = 11,
EN_SETTING = 12,
EN_ENERGY = 13,
EN_LINKQUAL = 14,
EN_LINKPATTERN = 15
} EN_LinkProperty;
/// Time parameter codes
typedef enum {
EN_DURATION = 0,
EN_HYDSTEP = 1,
EN_QUALSTEP = 2,
EN_PATTERNSTEP = 3,
EN_PATTERNSTART = 4,
EN_REPORTSTEP = 5,
EN_REPORTSTART = 6,
EN_RULESTEP = 7,
EN_STATISTIC = 8,
EN_PERIODS = 9,
EN_STARTTIME = 10,
EN_HTIME = 11,
EN_QTIME = 12,
EN_HALTFLAG = 13,
EN_NEXTEVENT = 14
} EN_TimeProperty;
typedef enum {
EN_ITERATIONS = 0,
EN_RELATIVEERROR = 1
} EN_AnalysisStatistic;
typedef enum {
EN_NODECOUNT = 0, /**< Number of Nodes (Juntions + Tanks + Reservoirs) */
EN_TANKCOUNT = 1, /**< Number of Tanks */
EN_LINKCOUNT = 2, /**< Number of Links (Pipes + Pumps + Valves) */
EN_PATCOUNT = 3, /**< Number of Time Patterns */
EN_CURVECOUNT = 4, /**< Number of Curves */
EN_CONTROLCOUNT = 5 /**< Number of Control Statements */
} EN_CountType;
typedef enum {
EN_JUNCTION = 0,
EN_RESERVOIR = 1,
EN_TANK = 2
} EN_NodeType;
typedef enum {
EN_CVPIPE = 0, /* Link types. */
EN_PIPE = 1, /* See LinkType in TYPES.H */
EN_PUMP = 2,
EN_PRV = 3,
EN_PSV = 4,
EN_PBV = 5,
EN_FCV = 6,
EN_TCV = 7,
EN_GPV = 8
} EN_LinkType;
typedef enum {
EN_NONE = 0, /* Quality analysis types. */
EN_CHEM = 1, /* See QualType in TYPES.H */
EN_AGE = 2,
EN_TRACE = 3
} EN_QualityType;
typedef enum {
EN_CONCEN = 0, /* Source quality types. */
EN_MASS = 1, /* See SourceType in TYPES.H. */
EN_SETPOINT = 2,
EN_FLOWPACED = 3
} EN_SourceType;
typedef enum {
EN_CFS = 0, /* Flow units types. */
EN_GPM = 1, /* See FlowUnitsType */
EN_MGD = 2, /* in TYPES.H. */
EN_IMGD = 3,
EN_AFD = 4,
EN_LPS = 5,
EN_LPM = 6,
EN_MLD = 7,
EN_CMH = 8,
EN_CMD = 9
} EN_FlowUnits;
/// Simulation Option codes
typedef enum {
EN_TRIALS = 0,
EN_ACCURACY = 1,
EN_TOLERANCE = 2,
EN_EMITEXPON = 3,
EN_DEMANDMULT = 4
} EN_Option;
typedef enum {
EN_LOWLEVEL = 0, /* Control types. */
EN_HILEVEL = 1, /* See ControlType */
EN_TIMER = 2, /* in TYPES.H. */
EN_TIMEOFDAY = 3
} EN_ControlType;
typedef enum {
EN_AVERAGE = 1, /* Time statistic types. */
EN_MINIMUM = 2, /* See TstatType in TYPES.H */
EN_MAXIMUM = 3,
EN_RANGE = 4
} EN_StatisticType;
typedef enum {
EN_MIX1 = 0, /* Tank mixing models */
EN_MIX2 = 1,
EN_FIFO = 2,
EN_LIFO = 3
} EN_MixingModel;
typedef enum {
EN_NOSAVE = 0,
EN_SAVE = 1,
EN_INITFLOW = 10,
EN_SAVE_AND_INIT = 11
} EN_SaveOption;
typedef enum {
EN_CONST_HP = 0, /* constant horsepower */
EN_POWER_FUNC = 1, /* power function */
EN_CUSTOM = 2 /* user-defined custom curve */
} EN_CurveType;
// --- Declare the EPANET toolkit functions
#if defined(__cplusplus)
extern "C" {
#endif
/**
@brief runs a complete EPANET simulation
@param inpFile pointer to name of input file (must exist)
@param rptFile pointer to name of report file (to be created)
@param binOutFile pointer to name of binary output file (to be created)
@param callback a callback function that takes a character string (char *) as its only parameter.
@return error code
The callback function should reside in and be used by the calling
code to display the progress messages that EPANET generates
as it carries out its computations. If this feature is not
needed then the argument should be NULL.
*/
int DLLEXPORT ENepanet(char *inpFile, char *rptFile, char *binOutFile, void (*callback) (char *));
int DLLEXPORT ENGetVal(int n, float* fRtn);
/**
@brief Opens EPANET input file & reads in network data
@param inpFile pointer to name of input file (must exist)
@param rptFile pointer to name of report file (to be created)
@param binOutFile pointer to name of binary output file (to be created)
@return error code
*/
int DLLEXPORT ENopen(char *inpFile, char *rptFile, char *binOutFile);
/**
@brief Saves current data to "INP" formatted text file.
@param filename The file path to create
@return Error code
*/
int DLLEXPORT ENsaveinpfile(char *filename);
/**
@brief Frees all memory and files used by EPANET
@return Error code
*/
int DLLEXPORT ENclose();
/**
@brief Solves the network hydraulics for all time periods
@return Error code
*/
int DLLEXPORT ENsolveH();
/**
@brief Saves hydraulic results to binary file
@return Error code
Must be called before ENreport() if no WQ simulation has been made.
Should not be called if ENsolveQ() will be used.
*/
int DLLEXPORT ENsaveH();
/**
@brief Sets up data structures for hydraulic analysis
@return Error code
*/
int DLLEXPORT ENopenH();
/**
@brief Initializes hydraulic analysis
@param initFlag 2-digit flag where 1st (left) digit indicates if link flows should be re-initialized (1) or not (0), and 2nd digit indicates if hydraulic results should be saved to file (1) or not (0).
@return Error code
*/
int DLLEXPORT ENinitH(int initFlag);
/**
@brief Run a hydraulic solution period
@param[out] currentTime The current simulation time in seconds
@return Error or warning code
@see ENsolveH
This function is used in a loop with ENnextH() to run
an extended period hydraulic simulation.
See ENsolveH() for an example.
*/
int DLLEXPORT ENrunH(long *currentTime);
/**
@brief Determine time (in seconds) until next hydraulic event
@param[out] tStep Time (seconds) until next hydraulic event. 0 marks end of simulation period.
@return Error code
This function is used in a loop with ENrunH() to run an extended period hydraulic simulation.
See ENsolveH() for an example.
*/
int DLLEXPORT ENnextH(long *tStep);
/**
@brief Frees data allocated by hydraulics solver
@return Error code
*/
int DLLEXPORT ENcloseH();
/**
@brief Copies binary hydraulics file to disk
@param filename Name of file to be created
@return Error code
*/
int DLLEXPORT ENsavehydfile(char *filename);
/**
@brief Opens previously saved binary hydraulics file
@param filename Name of file to be used
@return Error code
*/
int DLLEXPORT ENusehydfile(char *filename);
/**
@brief Solves for network water quality in all time periods
@return Error code
*/
int DLLEXPORT ENsolveQ();
/**
@brief Sets up data structures for WQ analysis
@return Error code
*/
int DLLEXPORT ENopenQ();
/**
@brief Initializes water quality analysis
@param saveFlag EN_SAVE (1) if results saved to file, EN_NOSAVE (0) if not
@return Error code
*/
int DLLEXPORT ENinitQ(int saveFlag);
/**
@brief Retrieves hydraulic & WQ results at time t.
@param[out] currentTime Current simulation time, in seconds.
@return Error code
This function is used in a loop with ENnextQ() to run
an extended period WQ simulation. See ENsolveQ() for
an example.
*/
int DLLEXPORT ENrunQ(long *currentTime);
/**
@brief Advances WQ simulation to next hydraulic event.
@param[out] tStep Time in seconds until next hydraulic event. 0 marks end of simulation period.
@return Error code
This function is used in a loop with ENrunQ() to run
an extended period WQ simulation. See ENsolveQ() for
an example.
*/
int DLLEXPORT ENnextQ(long *tStep);
/**
@brief Advances WQ simulation by a single WQ time step
@param[out] timeLeft Time left in overall simulation (in seconds)
@return Error code
This function is used in a loop with ENrunQ() to run
an extended period WQ simulation.
*/
int DLLEXPORT ENstepQ(long *timeLeft);
/**
@brief Frees data allocated by water quality solver.
@return Error code.
*/
int DLLEXPORT ENcloseQ();
/**
@brief Writes line of text to the report file.
@param line Text string to write
@return Error code.
*/
int DLLEXPORT ENwriteline(char *line);
/**
@brief Writes simulation report to the report file
@return Error code
*/
int DLLEXPORT ENreport();
/**
@brief Resets report options to default values
@return Error code
*/
int DLLEXPORT ENresetreport();
/**
@brief Processes a reporting format command
@return Error code
*/
int DLLEXPORT ENsetreport(char *reportFormat);
/**
@brief Retrieves parameters that define a simple control
@param controlIndex Control index (position of control statement in the input file, starting from 1)
@param[out] controlType Control type code (see EPANET2.H)
@param[out] linkIndex Index of controlled link
@param[out] setting Control setting on link
@param[out] nodeIndex Index of controlling node (0 for TIMER or TIMEOFDAY control)
@param[out] level Control level (tank level, junction pressure, or time (seconds))
@return Error code
*/
int DLLEXPORT ENgetcontrol(int controlIndex, int *controlType, int *linkIndex, EN_API_FLOAT_TYPE *setting, int *nodeIndex, EN_API_FLOAT_TYPE *level);
/**
@brief Retrieves the number of components of a given type in the network.
@param code Component code (see EPANET2.H)
@param[out] count Number of components in network
@return Error code
*/
int DLLEXPORT ENgetcount(int code, int *count);
/**
@brief Gets value for an analysis option
@param code Option code (see EPANET2.H)
@param[out] value Option value
@return Error code
*/
int DLLEXPORT ENgetoption(int code, EN_API_FLOAT_TYPE *value);
/**
@brief Retrieves value of specific time parameter.
@param code Time parameter code
@param[out] value Value of time parameter.
@return Error code
*/
int DLLEXPORT ENgettimeparam(int code, long *value);
/**
@brief Retrieves the flow units code
@param[out] code Code of flow units in use
@return Error code
*/
int DLLEXPORT ENgetflowunits(int *code);
/**
@brief Retrieves the index of the time pattern with specified ID
@param id String ID of the time pattern
@param[out] index Index of the specified time pattern
@return Error code
@see ENgetpatternid
*/
int DLLEXPORT ENgetpatternindex(char *id, int *index);
/**
@brief Retrieves ID of a time pattern with specific index.
@param index The index of a time pattern.
@param[out] id The string ID of the time pattern.
@return Error code
@see ENgetpatternindex
*/
int DLLEXPORT ENgetpatternid(int index, char *id);
/**
@brief Retrieves the number of multipliers in a time pattern.
@param index The index of a time pattern.
@param[out] len The length of the time pattern.
@return Error code
*/
int DLLEXPORT ENgetpatternlen(int index, int *len);
/**
@brief Retrive a multiplier from a pattern for a specific time period.
@param index The index of a time pattern
@param period The pattern time period. First time period is 1.
@param[out] value Pattern multiplier
@return Error code
*/
int DLLEXPORT ENgetpatternvalue(int index, int period, EN_API_FLOAT_TYPE *value);
/**
@brief Retrieve the average multiplier value in a time pattern
@param index The index of a time pattern
@param[out] value The average of all of this time pattern's values
@return Error code
*/
int DLLEXPORT ENgetaveragepatternvalue(int index, EN_API_FLOAT_TYPE *value);
/**
@brief Retrieve the type of quality analytis to be run.
@param[out] qualcode The quality analysis code number.
@param[out] tracenode The index of node being traced, if qualcode == trace
@return Error code
@see ENsetqualtype
*/
int DLLEXPORT ENgetqualtype(int *qualcode, int *tracenode);
/**
@brief Get the text of an error code.
@param errcode The error code
@param[out] errmsg The error string represented by the code
@param maxLen The maximum number of characters to copy into the char pointer errmsg
@return Error code
*/
int DLLEXPORT ENgeterror(int errcode, char *errmsg, int maxLen);
/**
@brief Get hydraulic simulation statistic
@param code The type of statistic to get
@param[out] value The value of the statistic
@return Error code
*/
int DLLEXPORT ENgetstatistic(int code, EN_API_FLOAT_TYPE* value);
/**
@brief Get index of node with specified ID
@param id The string ID of the node
@param[out] index The node's index (first node is index 1)
@return Error code
@see ENgetnodeid
*/
int DLLEXPORT ENgetnodeindex(char *id, int *index);
/**
@brief Get the string ID of the specified node.
@param index The index of the node (first node is index 1)
@param[out] id The string ID of the specified node. Up to MAXID characters will be copied, so id must be pre-allocated by the calling code to hold at least that many characters.
@return Error code
@see ENgetnodeindex
*/
int DLLEXPORT ENgetnodeid(int index, char *id);
/**
@brief Get the type of node with specified index.
@param index The index of a node (first node is index 1)
@param[out] code The type code for the node.
@return Error code
*/
int DLLEXPORT ENgetnodetype(int index, int *code);
/**
@brief Get a property value for specified node
@param index The index of a node (first node is index 1).
@param code The property type code
@param[out] value The value of the node's property.
@return Error code
@see EN_NodeProperty
*/
int DLLEXPORT ENgetnodevalue(int index, int code, EN_API_FLOAT_TYPE *value);
/**
@brief Get coordinates (x,y) for a node.
@param index The index of a node (first node is index 1).
@param[out] x X-value of node's coordinate
@param[out] y Y-value of node's coordinate
@return Error code
@see ENsetcoord
*/
int DLLEXPORT ENgetcoord(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y);
/**
@brief Set coordinates (x,y) for a node.
@param index The index of a node (first node is index 1)
@param x X-value of node's coordinate
@param y Y-value of node's coordinate
@return Error code
@see ENgetcoord
*/
int DLLEXPORT ENsetcoord(int index, EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y);
/**
@brief Get the number of demand categories for a node.
@param nodeIndex The index of a node (first node is index 1)
@param[out] numDemands The number of demand categories
@return Error code
*/
int DLLEXPORT ENgetnumdemands(int nodeIndex, int *numDemands);
/**
@brief Get a node's base demand for a specified category.
@param nodeIndex The index of a node (first node is index 1)
@param demandIndex The index of the demand category (starting at 1)
@return Error code
*/
int DLLEXPORT ENgetbasedemand(int nodeIndex, int demandIndex, EN_API_FLOAT_TYPE *baseDemand);
/**
@brief Get the index of the demand pattern assigned to a node for a category index.
@param nodeIndex The index of a node (first node is index 1).
@param demandIndex The index of a category (first category is index 1).
@param[out] pattIndex The index of the pattern for this node and category.
@return Error code
*/
int DLLEXPORT ENgetdemandpattern(int nodeIndex, int demandIndex, int *pattIndex);
/**
@brief Get the index of a Link with specified ID.
@param id The string ID of a link.
@param[out] index The index of the named link (first link is index 1)
@return Error code
@see ENgetlinkid
*/
int DLLEXPORT ENgetlinkindex(char *id, int *index);
/**
@brief Get the string ID of a link with specified index
@param index The index of a link (first link is index 1)
@param[out] id The ID of the link. Up to MAXID characters will be copied, so id must be pre-allocated by the calling code to hold at least that many characters.
@return Error code
@see ENgetlinkindex
*/
int DLLEXPORT ENgetlinkid(int index, char *id);
/**
@brief Get the link type code for a specified link
@param index The index of a link (first link is index 1)
@param[out] code The type code of the link.
@return Error code
@see EN_LinkType
*/
int DLLEXPORT ENgetlinktype(int index, int *code);
/**
@brief Get the indexes of a link's start- and end-nodes.
@param index The index of a link (first link is index 1)
@param[out] node1 The index of the link's start node (first node is index 1).
@param[out] node2 The index of the link's end node (first node is index 1).
@return Error code
@see ENgetnodeid, ENgetlinkid
*/
int DLLEXPORT ENgetlinknodes(int index, int *node1, int *node2);
/**
@brief Get a property value for specified link.
@param index The index of a node (first node is index 1).
@param code The parameter desired.
@param[out] value The value of the link's specified property.
@return Error code
@see ENgetnodevalue, EN_LinkProperty
*/
int DLLEXPORT ENgetlinkvalue(int index, int code, EN_API_FLOAT_TYPE *value);
/**
@brief Get a curve's properties.
@param curveIndex The index of a curve (first curve is index 1).
@param[out] id The curve's string ID. Client code must preallocate at least MAXID characters.
@param[out] nValues The number of values in the curve's (x,y) list.
@param[out] xValues The curve's x-values. Must be freed by client.
@param[out] yValues The curve's y-values. Must be freed by client.
@return Error code.
*/
int DLLEXPORT ENgetcurve(int curveIndex, char* id, int *nValues, EN_API_FLOAT_TYPE **xValues, EN_API_FLOAT_TYPE **yValues);
/**
@brief Retrieves the curve index for a specified pump index.
@param pumpIndex The index of a pump
@param[out] curveIndex The index of the curve used by the pump.
@return Error code.
*/
int DLLEXPORT ENgetheadcurveindex(int pumpIndex, int *curveIndex);
/**
@brief Get the type of pump
@param linkIndex The index of the pump element
@param[out] outType The integer-typed pump curve type signifier (output parameter)
@return Error code
@see EN_CurveType
*/
int DLLEXPORT ENgetpumptype(int linkIndex, int *outType);
/**
@brief Get the version number. This number is to be interpreted with implied decimals, i.e., "20100" == "2(.)01(.)00"
@param[out] version The version of EPANET
@return Error code.
*/
int DLLEXPORT ENgetversion(int *version);
/**
@brief Specify parameters to define a simple control
@param cindex The index of the control to edit. First control is index 1.
@param ctype The type code to set for this control.
@param lindex The index of a link to control.
@param setting The control setting applied to the link.
@param nindex The index of a node used to control the link, or 0 for TIMER / TIMEOFDAY control.
@param level control point (tank level, junction pressure, or time in seconds).
@return Error code.
*/
int DLLEXPORT ENsetcontrol(int cindex, int ctype, int lindex, EN_API_FLOAT_TYPE setting, int nindex, EN_API_FLOAT_TYPE level);
/**
@brief Set a property value for a node.
@param index The index of a node. First node is index 1.
@param code The code for the proprty to set.
@param v The value to set for this node and property.
@return Error code.
@see EN_NodeProperty
*/
int DLLEXPORT ENsetnodevalue(int index, int code, EN_API_FLOAT_TYPE v);
/**
@brief Set a proprty value for a link.
@param index The index of a link. First link is index 1.
@param code The code for the property to set.
@param v The value to set for this link and property.
@return Error code.
@see EN_LinkProperty
*/
int DLLEXPORT ENsetlinkvalue(int index, int code, EN_API_FLOAT_TYPE v);
/**
@brief Add a new time pattern.
@param id The string ID of the pattern to add.
@return Error code.
@see ENgetpatternindex
*/
int DLLEXPORT ENaddpattern(char *id);
/**
@brief Set multipliers for a specific pattern
@param index The index of a pattern. First pattern is index 1.
@param f An array of multipliers
@param len The length of array f.
@return Error code.
@see ENgetpatternindex
*/
int DLLEXPORT ENsetpattern(int index, EN_API_FLOAT_TYPE *f, int len);
/**
@brief Set the multiplier for a specific pattern at a specific period.
@param index The index of a pattern. First pattern is index 1.
@param period The period of the pattern to set.
@param value The value of the multiplier to set.
@return Error code.
*/
int DLLEXPORT ENsetpatternvalue(int index, int period, EN_API_FLOAT_TYPE value);
/**
@brief Set the value for a time parameter.
@param code The code for the parameter to set.
@param value The desired value of the parameter.
@return Error code.
@see EN_TimeProperty
*/
int DLLEXPORT ENsettimeparam(int code, long value);
/**
@brief Set a value for an anlysis option.
@param code The code for the desired option.
@param v The desired value for the option specified.
@return Error code.
@see EN_Option
*/
int DLLEXPORT ENsetoption(int code, EN_API_FLOAT_TYPE v);
/**
@brief Sets the level of hydraulic status reporting.
@param code Status reporting code.
@return Error code.
*/
int DLLEXPORT ENsetstatusreport(int code);
/**
@brief Sets type of quality analysis called for
@param qualcode WQ parameter code, EN_QualityType
@param chemname Name of WQ constituent
@param chemunits Concentration units of WQ constituent
@param tracenode ID of node being traced (if applicable)
@return Error code.
@see EN_QualityType
chemname and chemunits only apply when WQ analysis is for chemical. tracenode only applies when WQ analysis is source tracing.
*/
int DLLEXPORT ENsetqualtype(int qualcode, char *chemname, char *chemunits, char *tracenode);
/**
@brief Get quality analysis information (type, chemical name, units, trace node ID)
@param[out] qualcode The EN_QualityType code being used.
@param[out] chemname The name of the WQ constituent.
@param[out] chemunits The cencentration units of the WQ constituent.
@param[out] tracenode The trace node ID.
@return Error code.
@see EN_QualityType
*/
int DLLEXPORT ENgetqualinfo(int *qualcode, char *chemname, char *chemunits, int *tracenode);
/**
@brief Sets the node's base demand for a category.
@param nodeIndex The index of a node.
@param demandIdx The index of a demand category.
@param baseDemand The base demand multiplier for the selected category.
@return Error code.
@see ENgetbasedemand
*/
int DLLEXPORT ENsetbasedemand(int nodeIndex, int demandIdx, EN_API_FLOAT_TYPE baseDemand);
/**
@brief Retrieves index of curve with specific ID.
@param id The ID of a curve.
@param[out] index The index of the named curve
@return Error code.
@see ENgetcurveid
*/
int DLLEXPORT ENgetcurveindex(char *id, int *index);
/**
@brief Retrieves ID of a curve with specific index.
@param index The index of a curve.
@param[out] id The ID of the curve specified.
@return Error code.
@see ENsetcurveindex
NOTE: 'id' must be able to hold MAXID characters
*/
int DLLEXPORT ENgetcurveid(int index, char *id);
/**
@brief Retrieves number of points in a curve
@param index The index of a curve.
@param[out] len The length of the curve coordinate list
@return Error code.
@see ENgetcurvevalue
*/
int DLLEXPORT ENgetcurvelen(int index, int *len);
/**
@brief retrieves x,y point for a specific point number and curve
@param curveIndex The index of a curve
@param pointIndex The index of a point in the curve
@param[out] x The x-value of the specified point.
@param[out] y The y-value of the specified point.
@return Error code.
@see ENgetcurvelen ENsetcurvevalue
*/
int DLLEXPORT ENgetcurvevalue(int curveIndex, int pointIndex, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y);
/**
@brief Sets x,y point for a specific point and curve.
@param curveIndex The index of a curve.
@param pointIndex The index of a point in the curve.
@param x The x-value of the point.
@param y The y-value of the point.
@return Error code.
*/
int DLLEXPORT ENsetcurvevalue(int curveIndex, int pointIndex, EN_API_FLOAT_TYPE x, EN_API_FLOAT_TYPE y);
/**
@brief Sets x,y values for a specified curve.
@param index The index of a curve.
@param x An array of x-values for the curve.
@param y An array of y-values for the curve.
@param len The length of the arrays x and y.
@return Error code.
*/
int DLLEXPORT ENsetcurve(int index, EN_API_FLOAT_TYPE *x, EN_API_FLOAT_TYPE *y, int len);
/**
@brief Adds a new curve appended to the end of the existing curves.
@param id The name of the curve to be added.
@return Error code.
@see ENgetcurveindex ENsetcurve
*/
int DLLEXPORT ENaddcurve(char *id);
// Update at 2018/1/8.==============================================================================
//设置水力指数
void DLLEXPORT ENsetHexp(double exp);
//设置管网类型
void DLLEXPORT ENsetnettype(short type);
//设置管段的管材与压力状态内存
void DLLEXPORT ENsetpipestatekindmem(long* pipesk);
//设置资源中心内存
void DLLEXPORT ENsetresourcemem(double* pData);
//获得输入错误文件路径
int DLLEXPORT ENgetMyErrFile(char* filePath);
// Update at 2018/4/11.
int DLLEXPORT ENnetSize(int);
int DLLEXPORT ENgetpumpvalue(int, float *);
// Update end.======================================================================================
#if defined(__cplusplus)
}
#endif
#endif //EPANET2_H
/*-------------------------------------------------------------------------
*
* libpq-fe.h
* This file contains definitions for structures and
* externs for functions used by frontend postgres applications.
*
* Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/interfaces/libpq/libpq-fe.h
*
*-------------------------------------------------------------------------
*/
#ifndef LIBPQ_FE_H
#define LIBPQ_FE_H
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdio.h>
/*
* postgres_ext.h defines the backend's externally visible types,
* such as Oid.
*/
#include "postgres_ext.h"
/*
* Option flags for PQcopyResult
*/
#define PG_COPYRES_ATTRS 0x01
#define PG_COPYRES_TUPLES 0x02 /* Implies PG_COPYRES_ATTRS */
#define PG_COPYRES_EVENTS 0x04
#define PG_COPYRES_NOTICEHOOKS 0x08
/* Application-visible enum types */
/*
* Although it is okay to add to these lists, values which become unused
* should never be removed, nor should constants be redefined - that would
* break compatibility with existing code.
*/
typedef enum
{
CONNECTION_OK,
CONNECTION_BAD,
/* Non-blocking mode only below here */
/*
* The existence of these should never be relied upon - they should only
* be used for user feedback or similar purposes.
*/
CONNECTION_STARTED, /* Waiting for connection to be made. */
CONNECTION_MADE, /* Connection OK; waiting to send. */
CONNECTION_AWAITING_RESPONSE, /* Waiting for a response from the
* postmaster. */
CONNECTION_AUTH_OK, /* Received authentication; waiting for
* backend startup. */
CONNECTION_SETENV, /* Negotiating environment. */
CONNECTION_SSL_STARTUP, /* Negotiating SSL. */
CONNECTION_NEEDED, /* Internal state: connect() needed */
CONNECTION_CHECK_WRITABLE, /* Check if we could make a writable
* connection. */
CONNECTION_CONSUME, /* Wait for any pending message and consume
* them. */
CONNECTION_GSS_STARTUP /* Negotiating GSSAPI. */
} ConnStatusType;
typedef enum
{
PGRES_POLLING_FAILED = 0,
PGRES_POLLING_READING, /* These two indicate that one may */
PGRES_POLLING_WRITING, /* use select before polling again. */
PGRES_POLLING_OK,
PGRES_POLLING_ACTIVE /* unused; keep for awhile for backwards
* compatibility */
} PostgresPollingStatusType;
typedef enum
{
PGRES_EMPTY_QUERY = 0, /* empty query string was executed */
PGRES_COMMAND_OK, /* a query command that doesn't return
* anything was executed properly by the
* backend */
PGRES_TUPLES_OK, /* a query command that returns tuples was
* executed properly by the backend, PGresult
* contains the result tuples */
PGRES_COPY_OUT, /* Copy Out data transfer in progress */
PGRES_COPY_IN, /* Copy In data transfer in progress */
PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from the
* backend */
PGRES_NONFATAL_ERROR, /* notice or warning message */
PGRES_FATAL_ERROR, /* query failed */
PGRES_COPY_BOTH, /* Copy In/Out data transfer in progress */
PGRES_SINGLE_TUPLE /* single tuple from larger resultset */
} ExecStatusType;
typedef enum
{
PQTRANS_IDLE, /* connection idle */
PQTRANS_ACTIVE, /* command in progress */
PQTRANS_INTRANS, /* idle, within transaction block */
PQTRANS_INERROR, /* idle, within failed transaction */
PQTRANS_UNKNOWN /* cannot determine status */
} PGTransactionStatusType;
typedef enum
{
PQERRORS_TERSE, /* single-line error messages */
PQERRORS_DEFAULT, /* recommended style */
PQERRORS_VERBOSE, /* all the facts, ma'am */
PQERRORS_SQLSTATE /* only error severity and SQLSTATE code */
} PGVerbosity;
typedef enum
{
PQSHOW_CONTEXT_NEVER, /* never show CONTEXT field */
PQSHOW_CONTEXT_ERRORS, /* show CONTEXT for errors only (default) */
PQSHOW_CONTEXT_ALWAYS /* always show CONTEXT field */
} PGContextVisibility;
/*
* PGPing - The ordering of this enum should not be altered because the
* values are exposed externally via pg_isready.
*/
typedef enum
{
PQPING_OK, /* server is accepting connections */
PQPING_REJECT, /* server is alive but rejecting connections */
PQPING_NO_RESPONSE, /* could not establish connection */
PQPING_NO_ATTEMPT /* connection not attempted (bad params) */
} PGPing;
/* PGconn encapsulates a connection to the backend.
* The contents of this struct are not supposed to be known to applications.
*/
typedef struct pg_conn PGconn;
/* PGresult encapsulates the result of a query (or more precisely, of a single
* SQL command --- a query string given to PQsendQuery can contain multiple
* commands and thus return multiple PGresult objects).
* The contents of this struct are not supposed to be known to applications.
*/
typedef struct pg_result PGresult;
/* PGcancel encapsulates the information needed to cancel a running
* query on an existing connection.
* The contents of this struct are not supposed to be known to applications.
*/
typedef struct pg_cancel PGcancel;
/* PGnotify represents the occurrence of a NOTIFY message.
* Ideally this would be an opaque typedef, but it's so simple that it's
* unlikely to change.
* NOTE: in Postgres 6.4 and later, the be_pid is the notifying backend's,
* whereas in earlier versions it was always your own backend's PID.
*/
typedef struct pgNotify
{
char *relname; /* notification condition name */
int be_pid; /* process ID of notifying server process */
char *extra; /* notification parameter */
/* Fields below here are private to libpq; apps should not use 'em */
struct pgNotify *next; /* list link */
} PGnotify;
/* Function types for notice-handling callbacks */
typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res);
typedef void (*PQnoticeProcessor) (void *arg, const char *message);
/* Print options for PQprint() */
typedef char pqbool;
typedef struct _PQprintOpt
{
pqbool header; /* print output field headings and row count */
pqbool align; /* fill align the fields */
pqbool standard; /* old brain dead format */
pqbool html3; /* output html tables */
pqbool expanded; /* expand tables */
pqbool pager; /* use pager for output if needed */
char *fieldSep; /* field separator */
char *tableOpt; /* insert to HTML <table ...> */
char *caption; /* HTML <caption> */
char **fieldName; /* null terminated array of replacement field
* names */
} PQprintOpt;
/* ----------------
* Structure for the conninfo parameter definitions returned by PQconndefaults
* or PQconninfoParse.
*
* All fields except "val" point at static strings which must not be altered.
* "val" is either NULL or a malloc'd current-value string. PQconninfoFree()
* will release both the val strings and the PQconninfoOption array itself.
* ----------------
*/
typedef struct _PQconninfoOption
{
char *keyword; /* The keyword of the option */
char *envvar; /* Fallback environment variable name */
char *compiled; /* Fallback compiled in default value */
char *val; /* Option's current value, or NULL */
char *label; /* Label for field in connect dialog */
char *dispchar; /* Indicates how to display this field in a
* connect dialog. Values are: "" Display
* entered value as is "*" Password field -
* hide value "D" Debug option - don't show
* by default */
int dispsize; /* Field size in characters for dialog */
} PQconninfoOption;
/* ----------------
* PQArgBlock -- structure for PQfn() arguments
* ----------------
*/
typedef struct
{
int len;
int isint;
union
{
int *ptr; /* can't use void (dec compiler barfs) */
int integer;
} u;
} PQArgBlock;
/* ----------------
* PGresAttDesc -- Data about a single attribute (column) of a query result
* ----------------
*/
typedef struct pgresAttDesc
{
char *name; /* column name */
Oid tableid; /* source table, if known */
int columnid; /* source column, if known */
int format; /* format code for value (text/binary) */
Oid typid; /* type id */
int typlen; /* type size */
int atttypmod; /* type-specific modifier info */
} PGresAttDesc;
/* ----------------
* Exported functions of libpq
* ----------------
*/
/* === in fe-connect.c === */
/* make a new client connection to the backend */
/* Asynchronous (non-blocking) */
extern PGconn *PQconnectStart(const char *conninfo);
extern PGconn *PQconnectStartParams(const char *const *keywords,
const char *const *values, int expand_dbname);
extern PostgresPollingStatusType PQconnectPoll(PGconn *conn);
/* Synchronous (blocking) */
extern PGconn *PQconnectdb(const char *conninfo);
extern PGconn *PQconnectdbParams(const char *const *keywords,
const char *const *values, int expand_dbname);
extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport,
const char *pgoptions, const char *pgtty,
const char *dbName,
const char *login, const char *pwd);
#define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME) \
PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL)
/* close the current connection and free the PGconn data structure */
extern void PQfinish(PGconn *conn);
/* get info about connection options known to PQconnectdb */
extern PQconninfoOption *PQconndefaults(void);
/* parse connection options in same way as PQconnectdb */
extern PQconninfoOption *PQconninfoParse(const char *conninfo, char **errmsg);
/* return the connection options used by a live connection */
extern PQconninfoOption *PQconninfo(PGconn *conn);
/* free the data structure returned by PQconndefaults() or PQconninfoParse() */
extern void PQconninfoFree(PQconninfoOption *connOptions);
/*
* close the current connection and restablish a new one with the same
* parameters
*/
/* Asynchronous (non-blocking) */
extern int PQresetStart(PGconn *conn);
extern PostgresPollingStatusType PQresetPoll(PGconn *conn);
/* Synchronous (blocking) */
extern void PQreset(PGconn *conn);
/* request a cancel structure */
extern PGcancel *PQgetCancel(PGconn *conn);
/* free a cancel structure */
extern void PQfreeCancel(PGcancel *cancel);
/* issue a cancel request */
extern int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize);
/* backwards compatible version of PQcancel; not thread-safe */
extern int PQrequestCancel(PGconn *conn);
/* Accessor functions for PGconn objects */
extern char *PQdb(const PGconn *conn);
extern char *PQuser(const PGconn *conn);
extern char *PQpass(const PGconn *conn);
extern char *PQhost(const PGconn *conn);
extern char *PQhostaddr(const PGconn *conn);
extern char *PQport(const PGconn *conn);
extern char *PQtty(const PGconn *conn);
extern char *PQoptions(const PGconn *conn);
extern ConnStatusType PQstatus(const PGconn *conn);
extern PGTransactionStatusType PQtransactionStatus(const PGconn *conn);
extern const char *PQparameterStatus(const PGconn *conn,
const char *paramName);
extern int PQprotocolVersion(const PGconn *conn);
extern int PQserverVersion(const PGconn *conn);
extern char *PQerrorMessage(const PGconn *conn);
extern int PQsocket(const PGconn *conn);
extern int PQbackendPID(const PGconn *conn);
extern int PQconnectionNeedsPassword(const PGconn *conn);
extern int PQconnectionUsedPassword(const PGconn *conn);
extern int PQclientEncoding(const PGconn *conn);
extern int PQsetClientEncoding(PGconn *conn, const char *encoding);
/* SSL information functions */
extern int PQsslInUse(PGconn *conn);
extern void *PQsslStruct(PGconn *conn, const char *struct_name);
extern const char *PQsslAttribute(PGconn *conn, const char *attribute_name);
extern const char *const *PQsslAttributeNames(PGconn *conn);
/* Get the OpenSSL structure associated with a connection. Returns NULL for
* unencrypted connections or if any other TLS library is in use. */
extern void *PQgetssl(PGconn *conn);
/* Tell libpq whether it needs to initialize OpenSSL */
extern void PQinitSSL(int do_init);
/* More detailed way to tell libpq whether it needs to initialize OpenSSL */
extern void PQinitOpenSSL(int do_ssl, int do_crypto);
/* Return true if GSSAPI encryption is in use */
extern int PQgssEncInUse(PGconn *conn);
/* Returns GSSAPI context if GSSAPI is in use */
extern void *PQgetgssctx(PGconn *conn);
/* Set verbosity for PQerrorMessage and PQresultErrorMessage */
extern PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);
/* Set CONTEXT visibility for PQerrorMessage and PQresultErrorMessage */
extern PGContextVisibility PQsetErrorContextVisibility(PGconn *conn,
PGContextVisibility show_context);
/* Enable/disable tracing */
extern void PQtrace(PGconn *conn, FILE *debug_port);
extern void PQuntrace(PGconn *conn);
/* Override default notice handling routines */
extern PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn,
PQnoticeReceiver proc,
void *arg);
extern PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn,
PQnoticeProcessor proc,
void *arg);
/*
* Used to set callback that prevents concurrent access to
* non-thread safe functions that libpq needs.
* The default implementation uses a libpq internal mutex.
* Only required for multithreaded apps that use kerberos
* both within their app and for postgresql connections.
*/
typedef void (*pgthreadlock_t) (int acquire);
extern pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler);
/* === in fe-exec.c === */
/* Simple synchronous query */
extern PGresult *PQexec(PGconn *conn, const char *query);
extern PGresult *PQexecParams(PGconn *conn,
const char *command,
int nParams,
const Oid *paramTypes,
const char *const *paramValues,
const int *paramLengths,
const int *paramFormats,
int resultFormat);
extern PGresult *PQprepare(PGconn *conn, const char *stmtName,
const char *query, int nParams,
const Oid *paramTypes);
extern PGresult *PQexecPrepared(PGconn *conn,
const char *stmtName,
int nParams,
const char *const *paramValues,
const int *paramLengths,
const int *paramFormats,
int resultFormat);
/* Interface for multiple-result or asynchronous queries */
extern int PQsendQuery(PGconn *conn, const char *query);
extern int PQsendQueryParams(PGconn *conn,
const char *command,
int nParams,
const Oid *paramTypes,
const char *const *paramValues,
const int *paramLengths,
const int *paramFormats,
int resultFormat);
extern int PQsendPrepare(PGconn *conn, const char *stmtName,
const char *query, int nParams,
const Oid *paramTypes);
extern int PQsendQueryPrepared(PGconn *conn,
const char *stmtName,
int nParams,
const char *const *paramValues,
const int *paramLengths,
const int *paramFormats,
int resultFormat);
extern int PQsetSingleRowMode(PGconn *conn);
extern PGresult *PQgetResult(PGconn *conn);
/* Routines for managing an asynchronous query */
extern int PQisBusy(PGconn *conn);
extern int PQconsumeInput(PGconn *conn);
/* LISTEN/NOTIFY support */
extern PGnotify *PQnotifies(PGconn *conn);
/* Routines for copy in/out */
extern int PQputCopyData(PGconn *conn, const char *buffer, int nbytes);
extern int PQputCopyEnd(PGconn *conn, const char *errormsg);
extern int PQgetCopyData(PGconn *conn, char **buffer, int async);
/* Deprecated routines for copy in/out */
extern int PQgetline(PGconn *conn, char *string, int length);
extern int PQputline(PGconn *conn, const char *string);
extern int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize);
extern int PQputnbytes(PGconn *conn, const char *buffer, int nbytes);
extern int PQendcopy(PGconn *conn);
/* Set blocking/nonblocking connection to the backend */
extern int PQsetnonblocking(PGconn *conn, int arg);
extern int PQisnonblocking(const PGconn *conn);
extern int PQisthreadsafe(void);
extern PGPing PQping(const char *conninfo);
extern PGPing PQpingParams(const char *const *keywords,
const char *const *values, int expand_dbname);
/* Force the write buffer to be written (or at least try) */
extern int PQflush(PGconn *conn);
/*
* "Fast path" interface --- not really recommended for application
* use
*/
extern PGresult *PQfn(PGconn *conn,
int fnid,
int *result_buf,
int *result_len,
int result_is_int,
const PQArgBlock *args,
int nargs);
/* Accessor functions for PGresult objects */
extern ExecStatusType PQresultStatus(const PGresult *res);
extern char *PQresStatus(ExecStatusType status);
extern char *PQresultErrorMessage(const PGresult *res);
extern char *PQresultVerboseErrorMessage(const PGresult *res,
PGVerbosity verbosity,
PGContextVisibility show_context);
extern char *PQresultErrorField(const PGresult *res, int fieldcode);
extern int PQntuples(const PGresult *res);
extern int PQnfields(const PGresult *res);
extern int PQbinaryTuples(const PGresult *res);
extern char *PQfname(const PGresult *res, int field_num);
extern int PQfnumber(const PGresult *res, const char *field_name);
extern Oid PQftable(const PGresult *res, int field_num);
extern int PQftablecol(const PGresult *res, int field_num);
extern int PQfformat(const PGresult *res, int field_num);
extern Oid PQftype(const PGresult *res, int field_num);
extern int PQfsize(const PGresult *res, int field_num);
extern int PQfmod(const PGresult *res, int field_num);
extern char *PQcmdStatus(PGresult *res);
extern char *PQoidStatus(const PGresult *res); /* old and ugly */
extern Oid PQoidValue(const PGresult *res); /* new and improved */
extern char *PQcmdTuples(PGresult *res);
extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
extern int PQgetlength(const PGresult *res, int tup_num, int field_num);
extern int PQgetisnull(const PGresult *res, int tup_num, int field_num);
extern int PQnparams(const PGresult *res);
extern Oid PQparamtype(const PGresult *res, int param_num);
/* Describe prepared statements and portals */
extern PGresult *PQdescribePrepared(PGconn *conn, const char *stmt);
extern PGresult *PQdescribePortal(PGconn *conn, const char *portal);
extern int PQsendDescribePrepared(PGconn *conn, const char *stmt);
extern int PQsendDescribePortal(PGconn *conn, const char *portal);
/* Delete a PGresult */
extern void PQclear(PGresult *res);
/* For freeing other alloc'd results, such as PGnotify structs */
extern void PQfreemem(void *ptr);
/* Exists for backward compatibility. bjm 2003-03-24 */
#define PQfreeNotify(ptr) PQfreemem(ptr)
/* Error when no password was given. */
/* Note: depending on this is deprecated; use PQconnectionNeedsPassword(). */
#define PQnoPasswordSupplied "fe_sendauth: no password supplied\n"
/* Create and manipulate PGresults */
extern PGresult *PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);
extern PGresult *PQcopyResult(const PGresult *src, int flags);
extern int PQsetResultAttrs(PGresult *res, int numAttributes, PGresAttDesc *attDescs);
extern void *PQresultAlloc(PGresult *res, size_t nBytes);
extern size_t PQresultMemorySize(const PGresult *res);
extern int PQsetvalue(PGresult *res, int tup_num, int field_num, char *value, int len);
/* Quoting strings before inclusion in queries. */
extern size_t PQescapeStringConn(PGconn *conn,
char *to, const char *from, size_t length,
int *error);
extern char *PQescapeLiteral(PGconn *conn, const char *str, size_t len);
extern char *PQescapeIdentifier(PGconn *conn, const char *str, size_t len);
extern unsigned char *PQescapeByteaConn(PGconn *conn,
const unsigned char *from, size_t from_length,
size_t *to_length);
extern unsigned char *PQunescapeBytea(const unsigned char *strtext,
size_t *retbuflen);
/* These forms are deprecated! */
extern size_t PQescapeString(char *to, const char *from, size_t length);
extern unsigned char *PQescapeBytea(const unsigned char *from, size_t from_length,
size_t *to_length);
/* === in fe-print.c === */
extern void PQprint(FILE *fout, /* output stream */
const PGresult *res,
const PQprintOpt *ps); /* option structure */
/*
* really old printing routines
*/
extern void PQdisplayTuples(const PGresult *res,
FILE *fp, /* where to send the output */
int fillAlign, /* pad the fields with spaces */
const char *fieldSep, /* field separator */
int printHeader, /* display headers? */
int quiet);
extern void PQprintTuples(const PGresult *res,
FILE *fout, /* output stream */
int printAttName, /* print attribute names */
int terseOutput, /* delimiter bars */
int width); /* width of column, if 0, use variable
* width */
/* === in fe-lobj.c === */
/* Large-object access routines */
extern int lo_open(PGconn *conn, Oid lobjId, int mode);
extern int lo_close(PGconn *conn, int fd);
extern int lo_read(PGconn *conn, int fd, char *buf, size_t len);
extern int lo_write(PGconn *conn, int fd, const char *buf, size_t len);
extern int lo_lseek(PGconn *conn, int fd, int offset, int whence);
extern pg_int64 lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence);
extern Oid lo_creat(PGconn *conn, int mode);
extern Oid lo_create(PGconn *conn, Oid lobjId);
extern int lo_tell(PGconn *conn, int fd);
extern pg_int64 lo_tell64(PGconn *conn, int fd);
extern int lo_truncate(PGconn *conn, int fd, size_t len);
extern int lo_truncate64(PGconn *conn, int fd, pg_int64 len);
extern int lo_unlink(PGconn *conn, Oid lobjId);
extern Oid lo_import(PGconn *conn, const char *filename);
extern Oid lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId);
extern int lo_export(PGconn *conn, Oid lobjId, const char *filename);
/* === in fe-misc.c === */
/* Get the version of the libpq library in use */
extern int PQlibVersion(void);
/* Determine length of multibyte encoded char at *s */
extern int PQmblen(const char *s, int encoding);
/* Determine display length of multibyte encoded char at *s */
extern int PQdsplen(const char *s, int encoding);
/* Get encoding id from environment variable PGCLIENTENCODING */
extern int PQenv2encoding(void);
/* === in fe-auth.c === */
extern char *PQencryptPassword(const char *passwd, const char *user);
extern char *PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, const char *algorithm);
/* === in encnames.c === */
extern int pg_char_to_encoding(const char *name);
extern const char *pg_encoding_to_char(int encoding);
extern int pg_valid_server_encoding_id(int encoding);
#ifdef __cplusplus
}
#endif
#endif /* LIBPQ_FE_H */
/*
* src/include/pg_config_ext.h.win32. This is generated manually, not by
* autoheader, since we want to limit which symbols get defined here.
*/
/* Define to the name of a signed 64-bit integer type. */
#define PG_INT64_TYPE long long int
/*-------------------------------------------------------------------------
*
* postgres_ext.h
*
* This file contains declarations of things that are visible everywhere
* in PostgreSQL *and* are visible to clients of frontend interface libraries.
* For example, the Oid type is part of the API of libpq and other libraries.
*
* Declarations which are specific to a particular interface should
* go in the header file for that interface (such as libpq-fe.h). This
* file is only for fundamental Postgres declarations.
*
* User-written C functions don't count as "external to Postgres."
* Those function much as local modifications to the backend itself, and
* use header files that are otherwise internal to Postgres to interface
* with the backend.
*
* src/include/postgres_ext.h
*
*-------------------------------------------------------------------------
*/
#ifndef POSTGRES_EXT_H
#define POSTGRES_EXT_H
#include "pg_config_ext.h"
/*
* Object ID is a fundamental type in Postgres.
*/
typedef unsigned int Oid;
#ifdef __cplusplus
#define InvalidOid (Oid(0))
#else
#define InvalidOid ((Oid) 0)
#endif
#define OID_MAX UINT_MAX
/* you will need to include <limits.h> to use the above #define */
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
/* the above needs <stdlib.h> */
/* Define a signed 64-bit integer type for use in client API declarations. */
typedef PG_INT64_TYPE pg_int64;
/*
* Identifiers of error message fields. Kept here to keep common
* between frontend and backend, and also to export them to libpq
* applications.
*/
#define PG_DIAG_SEVERITY 'S'
#define PG_DIAG_SEVERITY_NONLOCALIZED 'V'
#define PG_DIAG_SQLSTATE 'C'
#define PG_DIAG_MESSAGE_PRIMARY 'M'
#define PG_DIAG_MESSAGE_DETAIL 'D'
#define PG_DIAG_MESSAGE_HINT 'H'
#define PG_DIAG_STATEMENT_POSITION 'P'
#define PG_DIAG_INTERNAL_POSITION 'p'
#define PG_DIAG_INTERNAL_QUERY 'q'
#define PG_DIAG_CONTEXT 'W'
#define PG_DIAG_SCHEMA_NAME 's'
#define PG_DIAG_TABLE_NAME 't'
#define PG_DIAG_COLUMN_NAME 'c'
#define PG_DIAG_DATATYPE_NAME 'd'
#define PG_DIAG_CONSTRAINT_NAME 'n'
#define PG_DIAG_SOURCE_FILE 'F'
#define PG_DIAG_SOURCE_LINE 'L'
#define PG_DIAG_SOURCE_FUNCTION 'R'
#endif /* POSTGRES_EXT_H */
File added
File added
File added
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