vapor / postgres-nio

🐘 Non-blocking, event-driven Swift client for PostgreSQL.
https://api.vapor.codes/postgresnio/documentation/postgresnio/
MIT License
324 stars 75 forks source link

Support simple queries, to support multiple queries in a single command #145

Open NeedleInAJayStack opened 3 years ago

NeedleInAJayStack commented 3 years ago

Describe the bug

When evaluating multiple insert statements in a deferred query, versions <= 1.4.4 would succeed, but >= 1.5.0 will fail with the message "cannot insert multiple commands into a prepared statement"

To Reproduce

Use postgres-nio version >= 1.5.0, and run the following on a test database:

try postgres.simpleQuery("""
CREATE TABLE test (
    user_id serial PRIMARY KEY,
    username VARCHAR ( 50 ) UNIQUE NOT NULL
);
""").wait()

try postgres.simpleQuery("""
SET CONSTRAINTS ALL DEFERRED;
INSERT INTO "test" ("user_id", "username") VALUES ('1', 'user1');
INSERT INTO "test" ("user_id", "username") VALUES ('2', 'user2');
INSERT INTO "test" ("user_id", "username") VALUES ('3', 'user3');
INSERT INTO "test" ("user_id", "username") VALUES ('4', 'user4');
INSERT INTO "test" ("user_id", "username") VALUES ('5', 'user5');
COMMIT;
""").wait()

Expected behavior

That it would complete successfully with the rows inserted into the table. This is the behavior in versions <= 1.4.4.

Environment

This was tested with postgres-kit v2.3.0, and varying versions of postgres-nio.

fabianfett commented 3 years ago

@NeedleInAJayStack Thanks for raising this issue. Work on this has begun: https://github.com/vapor/postgres-nio/pull/146

NeedleInAJayStack commented 3 years ago

Thanks @fabianfett! Let me know if I can help.

stefanspringer1 commented 3 years ago

I also stumbled upon this error and added a procedure in the database to be called from my web app as a (at least preliminary) solution.

Kishimotovn commented 1 year ago

Hi, is there any update on this?