Solved How to create postgresql subscription with qsqlquery?
-
I am trying to create postgres subscription using qsqlquery, but getting :
"LINE 1:EXCECUTE ('zumbeispiel_slot', TRUE)
42601 QPSQL: Unable to create query"
here is the codelocal_query.prepare("CREATE SUBSCRIPTION :sub_name" "CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'" "PUBLICATION public_realdent_db" "WITH" "slot_name = :slot_name," "create_slot = :create_slot," "synchronous_commit = on"); local_query.bindValue(":sub_name", subscription); local_query.bindValue(":create_slot", create_slot); local_query.bindValue(":slot_name", slot_name); slots_connected = local_query.exec(); if (!slots_connected) { emit database_failed(QUERY_ERROR_HEADER, QUERY_ERROR_PRETEXT + local_query.lastError().text()); return slots_connected; }
What I am doing wrong?
Connection string seems to be correct, many other queries to this database works fine. -
@August-Wiener
I'm not a practicing C++-er. But isn't your multiline string literal going to join without any whitespace character? Isn't"CREATE SUBSCRIPTION :sub_name" "CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'" "..."
going to generate:
"CREATE SUBSCRIPTION :sub_nameCONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'..."
i.e. you need a space at the end/start of each of your literals (inside the quotes), so at present your query won't parse??
-
@JonB
Yeah, it is even funny how I missed that. Now my code looks likelocal_query.prepare("CREATE SUBSCRIPTION :sub_name " "CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'" "PUBLICATION public_dealmed_db " "WITH " "(slot_name = :slot_name, " "create_slot = :create_slot, " "synchronous_commit = on)"); local_query.bindValue(":sub_name", subscription); local_query.bindValue(":create_slot", create_slot); local_query.bindValue(":slot_name", slot_name); slots_connected = local_query.exec();
Unfortunately, I keep getting just the same error :(
-
Hi and welcome to devnet,
Did you check the content of QSqlQuery::executedQuery to see if there's anything wrong in there ?
-
@August-Wiener
If it's as you've pasted it, you still have"CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'" "PUBLICATION public_dealmed_db "
->
"CONNECTION 'postgresql://postgres:root@64.196.144.30:5432/Realdent atlas'PUBLICATION public_dealmed_db "
?
-
-
I'm not sure whether bindValue works with that kind of query.
Does it also fail if you use QString to build the query using
arg
method ? -
This post is deleted!