誰かが 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 data_plus
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 |
ありがとう、
マーク