Inserting NULL/empty string using libpqxx library

烈酒焚心 提交于 2019-12-02 01:02:59

With libpqxx you can send a null value by calling operator () on a prepared statement with no arguments, eg:

xAction.prepared("insertBulkData")()(uuid)(coreNo).exec();

would send NULL as the first parameter for the statement.

I don't think you can get it to automatically replace an empty string with NULL. One way to achieve this would be to modify the SQL you are using:

INSERT INTO T_CORES (MAC, UUID, CORE_NO) VALUES (CASE WHEN $1='' THEN NULL ELSE $1 END, $2, $3)

Fast decision... add a parameter that will indicate when to insert into the NULL field

xAction.prepared("insertBulkData")(mac,!mac.empty())(uuid)(coreNo).exec();

link to doc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!