希望有人可以帮助我使用 PQprepare 和 PQexecPrepared。我确定我一定有什么问题,但我尝试的任何方法似乎都不起作用。
我正在尝试使用准备好的查询插入表中,但我不断收到此错误
ERROR: invalid input syntax for integer: "50.2000008"
这是我将 Oid 设置为 701 (float8) 的纬度值,但它说它是一个整数。我是完全错过了什么还是有什么不对劲的地方?
bool database::AddDataRow(int datasetid, string readingdatetime, float depth, float value, float latitude, float longitude) {
//data_plus
const char* stmtName = "PREPARE_DATA_PLUS_INSERT";
Oid oidTypes[6] = {23, 1114, 701, 701, 701, 701};
int paramFormats[6] = {0, 0, 0, 0, 0, 0};
PGresult* stmt = PQprepare(
conn,
stmtName,
"INSERT INTO data_plus(datasetid, readingdatetime, depth, value, uploaddatetime, longitude, latitude)"
"VALUES ($1, $2, $3, $4, NOW(), $5, $6);",
6,
(const Oid *) oidTypes
);
cout << PQresultErrorMessage(stmt) << " Test";
const char* paramValues[6];
int paramLengths[6];
paramValues[0] = lexical_cast<string>(datasetid).c_str();
paramValues[1] = readingdatetime.c_str();
paramValues[2] = lexical_cast<string>(depth).c_str();
paramValues[3] = lexical_cast<string>(value).c_str();
paramValues[4] = lexical_cast<string>(longitude).c_str();
paramValues[5] = lexical_cast<string>(latitude).c_str();
paramLengths[0] = strlen (paramValues[0]);
paramLengths[1] = strlen (paramValues[1]);
paramLengths[2] = strlen (paramValues[2]);
paramLengths[3] = strlen (paramValues[3]);
paramLengths[4] = strlen (paramValues[4]);
paramLengths[5] = strlen (paramValues[5]);
PGresult* test = PQexecPrepared(conn,
stmtName,
6,
paramValues,
paramLengths,
paramFormats,
0);
cout << PQresultErrorMessage(test);
PQclear(test);
PQclear(stmt);
}
\d 数据加号
View "public.data_plus"
Column | Type | Modifiers
-----------------+-----------------------------+-----------
id | bigint |
datasetid | integer |
readingdatetime | timestamp without time zone |
depth | double precision |
value | double precision |
uploaddatetime | timestamp without time zone |
longitude | double precision |
latitude | double precision |
谢谢,
标记