From f889d07a7278c31cc321cd8980064546e459eab0 Mon Sep 17 00:00:00 2001 From: Denis Feklushkin Date: Wed, 9 Mar 2016 05:17:26 +0700 Subject: [PATCH] prepareMethods clearing --- .test_pgator.conf | 8 ++++---- .test_pgator_rpc_table.sql | 2 +- source/app.d | 24 ++++++++---------------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/.test_pgator.conf b/.test_pgator.conf index 185e3a3..8b8db2a 100644 --- a/.test_pgator.conf +++ b/.test_pgator.conf @@ -4,10 +4,10 @@ "maxConn": 3, "connString": "dbname=pgator-test" }, - "sqlAuthVariables": [ - "pgator.username", - "pgator.password" - ], + "sqlAuthVariables": { + "username": "pgator.username", + "password": "pgator.password" + }, "listenAddresses": ["127.0.0.1", "::1"], "listenPort": 8080, "sqlPgatorTable": "pgator_tests" diff --git a/.test_pgator_rpc_table.sql b/.test_pgator_rpc_table.sql index 5c04248..6a7b6c4 100644 --- a/.test_pgator_rpc_table.sql +++ b/.test_pgator_rpc_table.sql @@ -53,4 +53,4 @@ INSERT INTO pgator_tests (method, sql_query, args, read_only) VALUES ('read_only', 'INSERT INTO pgator_tests VALUES(''a'', ''b'', ''{}'')', '{}', true); INSERT INTO pgator_tests (method, sql_query, args, set_auth_variables) -VALUES ('echo_auth_variables', 'SELECT pgator.username, pgator.password', '{}', true); +VALUES ('echo_auth_variables', 'SELECT current_setting(''pgator.username''), current_setting(''pgator.password'')', '{}', true); diff --git a/source/app.d b/source/app.d index 29f1267..2141cdc 100644 --- a/source/app.d +++ b/source/app.d @@ -147,8 +147,8 @@ void loop(in Bson cfg, PostgresClient client, in Method[string] methods) import vibe.core.core; const varNames = SQLVariablesNames( - cfg["sqlAuthVariables"][0].to!string, - cfg["sqlAuthVariables"][1].to!string + cfg["sqlAuthVariables"]["username"].to!string, + cfg["sqlAuthVariables"]["password"].to!string ); void httpRequestHandler(scope HTTPServerRequest req, HTTPServerResponse res) @@ -251,7 +251,7 @@ private immutable(Answer) transaction(PostgresClient.Connection conn, in Method* if(method.readOnlyFlag) // BEGIN READ ONLY { QueryParams q; - q.preparedStatementName = beginPreparedName; + q.preparedStatementName = beginROPreparedName; conn.execPreparedStatement(q); // FIXME: timeout check transactionStarted = true; @@ -523,27 +523,19 @@ class LoopException : Exception } } -immutable string beginPreparedName = "#B#"; +immutable string beginROPreparedName = "#R#"; immutable string commitPreparedName = "#C#"; /// returns names of unprepared methods private string[] prepareMethods(PostgresClient.Connection conn, ref PrepareMethodsArgs args) { { - trace("try to prepare methods BEGIN READ ONLY and COMMIT"); + trace("try to prepare internal statements"); - Method b; - b.name = beginPreparedName; - b.statement = "BEGIN READ ONLY"; + conn.prepareStatement(beginROPreparedName, "BEGIN READ ONLY", 0); + conn.prepareStatement(commitPreparedName, "COMMIT", 0); - Method c; - c.name = commitPreparedName; - c.statement = "COMMIT"; - - conn.prepareMethod(b); - conn.prepareMethod(c); - - trace("BEGIN READ ONLY and COMMIT prepared"); + trace("internal statements prepared"); } string[] failedMethods;