我正在使用 libpqxx 和准备好的语句,当我尝试以编程方式插入时它失败并出现错误“无效几何”,但我可以通过 sql 提示符执行相同的插入。我错过了什么吗?我试图在prepare语句调用中转义'但同样的错误
con.prepare("chat_insert", "INSERT INTO chat values (nextval('chat_seq'), $1, ST_GeomFromText('POINT($2 $3)', 4326), $4)");
worker.prepared("chat_insert")(chatid)(lon)(lat)(msg).exec();
worker.commit();
我也试过
con.prepare("chat_insert", "INSERT INTO chat values (nextval('chat_seq'), $1, ST_GeomFromText(\'POINT($2 $3)\', 4326), $4)");
输出:
Chat id: chat:user:128946234
Lat: 14.6049
Lon: 121.033
ERROR: parse error - invalid geometry
HINT: "POINT(" <-- parse error at position 6 within geometry
如果我进入 sql 提示符,我可以运行它,它会插入
insert into chat values (nextval('chat_seq'), 'chat:user:128946234', ST_GeomFromText('POINT(121.033 14.6049)', 4326), 'This is a test msg....');