Skip to content

Commit

Permalink
prepareMethods clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
denizzzka committed Mar 8, 2016
1 parent 739ebde commit f889d07
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
8 changes: 4 additions & 4 deletions .test_pgator.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .test_pgator_rpc_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
24 changes: 8 additions & 16 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f889d07

Please sign in to comment.