Hoping someone can help me with the usage of PQprepare and PQexecPrepared. I'm sure I must have something wrong but nothing I try seems to work.
I'm trying to insert into a table using a prepared query but I keep getting this error
ERROR: invalid input syntax for integer: "50.2000008"
This is the value for latitude which I've set the Oid to be 701 (float8) but it says its an integer. Am I totally missing something or have something the wrong way round?
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 |
Thanks,
Mark