Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBZ-693 Initial SQL statements #516

Closed
wants to merge 3 commits into from
Closed

Conversation

jpechane
Copy link
Contributor

Copy link
Member

@gunnarmorling gunnarmorling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpechane A few small remarks inline. Also what do you think about adding it to PG, too?

.withType(Type.STRING)
.withWidth(Width.LONG)
.withImportance(Importance.LOW)
.withDescription("A semicolon separated list of SQL statements to be executed when connection to database is established. "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should clarify whether that only applies to snapshot reading, log reading, or both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the default (no statements) should be mentioned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to precise it a little bit.

@@ -586,6 +586,10 @@ public synchronized Connection connection() throws SQLException {
if (conn == null) throw new SQLException("Unable to obtain a JDBC connection");
// Always run the initial operations on this new connection
if (initialOps != null) execute(initialOps);
final String statements = config.getString(JdbcConfiguration.ON_CONNECT_STATEMENTS);
if (statements != null) {
execute(statements.split(";"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle the case where a ; is given within a string literal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I tried to postpone the scenario till it happens :-). But we can add a support for escaping - either using backslash or doubling the semicolon. In this case I'd probably prefer doubling the semicolon.

@jpechane
Copy link
Contributor Author

@gunnarmorling Typos fixed, postgres support added, semicolon as a char supported

@@ -581,11 +582,49 @@ public synchronized boolean isConnected() throws SQLException {
}

public synchronized Connection connection() throws SQLException {
return connection(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be safer to not execute the statements when calling the parameterless connection(). Note that when using the PG connector, I see the insert being executed three times, so something is still not quite correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gunnarmorling It is correct, as postgres connector creates multiple connections in sequence. The functionality is not for executing DML (albeit I abuse it for tests) just mainly for session configuration and in this case I expect the session to be configured every time the connection is created.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll expand the option's description a little bit then to clarify that fact.

if (conn == null) {
conn = factory.connect(JdbcConfiguration.adapt(config));
if (conn == null) throw new SQLException("Unable to obtain a JDBC connection");
// Always run the initial operations on this new connection
if (initialOps != null) execute(initialOps);
final String statements = config.getString(JdbcConfiguration.ON_CONNECT_STATEMENTS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to extract all the parsing logic into its own method which then returns the list of statements to here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gunnarmorling
Copy link
Member

Rebased and applied. Added one commit to expend the test a bit and update the connector option description. Thanks, @jpechane!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants