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

Add database name to queries for Juxtaposer MSSQL driver #1134

Closed
diverdane opened this issue Feb 10, 2020 · 0 comments
Closed

Add database name to queries for Juxtaposer MSSQL driver #1134

diverdane opened this issue Feb 10, 2020 · 0 comments

Comments

@diverdane
Copy link
Contributor

Is your feature request related to a problem? Please describe.
This request is a followup to PR #1119 and Issue #1129, which adds an MSSQL backend tester
to the Juxtaposer test.

While running Juxtaposer with MSSQL on OpenShift using changes proposed in
PR #1119, the following error was encountered:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv mssql_secretless_tcp vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
2020/02/07 17:30:09 Calling Connect from ensureWantedDbDataState, debug=true
2020/02/07 17:30:09 Connect called with debug: true
2020/02/07 17:30:09 Connection string: sqlserver://:@127.0.0.1:11433?app+name=Juxtaposer
2020/02/07 17:30:09 Connected to DB
2020/02/07 17:30:09 Creating database (if it doesn't exist)...
2020/02/07 17:30:09 query string:
		IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'secretless')
			CREATE DATABASE secretless
2020/02/07 17:30:11 Switching database...
2020/02/07 17:30:11 query string: USE secretless
2020/02/07 17:30:11 Query: DROP TABLE IF EXISTS mytable;
2020/02/07 17:30:11
2020/02/07 17:30:11 Query: CREATE TABLE mytable (
    name         TEXT,
    id           INTEGER,
    birth_date   DATE,
    result       DECIMAL,
    passed       BIT
);
2020/02/07 17:30:11
2020/02/07 17:30:11 ERROR sql: Could not execute query!
2020/02/07 17:30:11 Shutting down database connection...
2020/02/07 17:30:11 mssql: CREATE TABLE permission denied in database 'master'.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This error was apparently caused by the MSSQL server not honoring the
USE <database-name> query in any subsequent queries (i.e. the server
would "forget" that the database had already been selected.

Describe the solution you'd like
As discussed with @sgnn7, the fix we devised is twofold:

  • Modify the database existence test so that it is only done once
    at the beginning of testing (i.e. it won't get done for every
    call to Connect(). Otherwise, for tests that are configured with
    recreateConnections set to true, the database existence test would
    be done for every test query.
  • Once the database has been confirmed to exist, include the
    database name in the query for all subsequent queries.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants