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

Adds database name to Juxtaposer mssql queries #1135

Merged
merged 6 commits into from
Feb 10, 2020

Conversation

diverdane
Copy link
Contributor

@diverdane diverdane commented Feb 10, 2020

What does this PR do (include background context, if relevant)?

NOTE FOR REVIEWERS: The changes proposed are based on PR #1119, which hasn't been merged yet.
To review the changes being proposed here, look at the last commit:
1eade0c

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, 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
prior USE <database-name> query in any subsequent queries (i.e. the server
would "forget" that the database had already been selected).

After discussing with @sgnn7, the fix we arrived at is:

  • 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()).

  • Once the database has been confirmed to exist, include the database name in the query for all subsequent queries.

What ticket does this PR close?

Connected to #1134

Where should the reviewer start?

What is the status of the manual tests?

Have you run the following manual tests to verify existing functionality continues to function as expected?

If this feature does not have any/sufficent automated tests, have you created/updated a folder in test/manual that includes:

  • An updated README with instructions on how to manually test this feature
  • Utility start and stop scripts to spin up and tear down the test environments
  • A test script to run some basic manual tests (optional; if does not exist, the README should have detailed instructions)

Links to open issues for related automated integration and unit tests

Links to open issues for related documentation (in READMEs, docs, etc)

Screenshots (if appropriate)

sgnn7
sgnn7 previously approved these changes Feb 10, 2020
sgnn7 and others added 6 commits February 10, 2020 11:43
This new change ensures that all supported DBs _and_ mssql will work
with table creation and data insertion.
The were all named 'db' when they should have the right name for their
DB type.
Juxtaposer can now interact with mssql databases with this change.
We can now deploy mssql juxtaposer into the XA env
With the addition of this driver, there's some informational info that
needed to be put into the README on how to run this.
While attempting to run the Juxtaposer 4-day reliability test
using Secretless with MSSQL, 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.

The fix 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 header for all subsequent queries.
Copy link
Contributor

@sgnn7 sgnn7 left a comment

Choose a reason for hiding this comment

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

@diverdane Yay LGTM!

@sgnn7 sgnn7 merged commit 8287fbc into master Feb 10, 2020
@sgnn7 sgnn7 deleted the juxtaposer-mssql-db-ensure branch February 10, 2020 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants