-
Notifications
You must be signed in to change notification settings - Fork 375
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
Dropped dbname variable and set QUOTED_IDENTIFIER to ON #911
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
USE [master] | ||
GO | ||
|
||
IF EXISTS (SELECT name FROM sys.databases WHERE name = '$(dbname)' ) | ||
|
||
BEGIN | ||
DROP DATABASE $(dbname) | ||
END | ||
|
||
CREATE DATABASE $(dbname) | ||
|
||
GO | ||
|
||
IF EXISTS (SELECT name FROM sys.databases WHERE name = 'TEST_DB' ) DROP DATABASE TEST_DB | ||
|
||
CREATE DATABASE TEST_DB | ||
GO | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1 @@ | ||
USE [master] | ||
GO | ||
|
||
IF EXISTS (SELECT name FROM sys.databases WHERE name = '$(dbname)' ) | ||
|
||
BEGIN | ||
DROP DATABASE $(dbname) | ||
END | ||
IF EXISTS (SELECT name FROM sys.databases WHERE name = 'TEST_DB' ) DROP DATABASE TEST_DB |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
#!/usr/bin/env python3 | ||
# contains helper methods | ||
# contains helper methods | ||
import os | ||
import sys | ||
import subprocess | ||
import platform | ||
import argparse | ||
from subprocess import Popen, PIPE | ||
|
||
def executeCommmand(inst_command): | ||
|
@@ -15,29 +12,17 @@ def executeCommmand(inst_command): | |
print (oo) | ||
|
||
def executeSQLscript(sqlfile, conn_options, dbname): | ||
if platform.system() == 'Windows': | ||
executeSQLscriptWindows(sqlfile, conn_options, dbname) | ||
elif platform.system() == 'Linux' or platform.system() == 'Darwin': | ||
executeSQLscriptUnix(sqlfile, conn_options, dbname) | ||
|
||
def executeSQLscriptWindows(sqlfile, conn_options, dbname): | ||
inst_command = 'sqlcmd ' + conn_options + ' -i ' + sqlfile + ' -v dbname =' + dbname | ||
inst_command = 'sqlcmd -I ' + conn_options + ' -i ' + sqlfile + ' -d ' + dbname | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable dbname is always appended at the end of |
||
executeCommmand(inst_command) | ||
|
||
def executeSQLscriptUnix(sqlfile, conn_options, dbname): | ||
# This is a workaround because sqlcmd in Unix does not support -v option for variables. | ||
# It inserts setvar dbname into the beginning of a temp .sql file | ||
tmpFileName = sqlfile[0:-4] + '_tmp.sql' | ||
redirect_string = '(echo :setvar dbname {0}) > {2}; cat {1} >> {2}; ' | ||
sqlcmd = 'sqlcmd ' + conn_options + ' -i ' + tmpFileName | ||
def manageTestDB(sqlfile, conn_options, dbname): | ||
tmp_sql_file = 'test_db_tmp.sql' | ||
if os.path.exists(tmp_sql_file): | ||
os.remove(tmp_sql_file) | ||
with open(sqlfile, 'r') as infile: | ||
script = infile.read().replace('TEST_DB', dbname) | ||
with open(tmp_sql_file, 'w') as outfile: | ||
outfile.write(script) | ||
|
||
# Execute a simple query via sqlcmd: without this step, the next step fails in travis CI | ||
simple_cmd = 'sqlcmd ' + conn_options + ' -Q \"select @@Version\" ' | ||
executeCommmand(simple_cmd) | ||
|
||
# inst_command = redirect_string.format(dbname, sqlfile, tmpFileName) + sqlcmd | ||
inst_command = redirect_string.format(dbname, sqlfile, tmpFileName) | ||
executeCommmand(inst_command) | ||
executeCommmand(sqlcmd) | ||
|
||
os.remove(tmpFileName) | ||
executeSQLscript(tmp_sql_file, conn_options, 'master') | ||
os.remove(tmp_sql_file) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,15 @@ | ||
#!/usr/bin/env python3 | ||
# py setup_dbs.py -dbname <DBNAME> -azure <yes or no> | ||
# OR | ||
# py setup_dbs.py -dbname <DBNAME> | ||
# OR | ||
# py setup_dbs.py -dbname <DBNAME> | ||
import os | ||
import sys | ||
import subprocess | ||
import platform | ||
import argparse | ||
from subprocess import Popen, PIPE | ||
from exec_sql_scripts import * | ||
|
||
def setupTestDatabase(conn_options, dbname, azure): | ||
sqlFiles = ['test_types.sql', '168256.sql', 'cd_info.sql', 'tracks.sql'] | ||
|
||
# for Azure, must specify the database for the sql scripts to work | ||
if (azure.lower() == 'yes'): | ||
conn_options += ' -d ' + dbname | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this not needed anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see my other comment |
||
|
||
for sqlFile in sqlFiles: | ||
executeSQLscript(sqlFile, conn_options, dbname) | ||
|
@@ -28,29 +22,29 @@ def populateTables(conn_options, dbname): | |
executeBulkCopy(conn_options, dbname, '168256', '168256') | ||
|
||
def executeBulkCopy(conn_options, dbname, tblname, datafile): | ||
redirect_string = 'bcp {0}..[{1}] in {2}.dat -f {2}.fmt ' | ||
inst_command = redirect_string.format(dbname, tblname, datafile) + conn_options | ||
redirect_string = 'bcp {0}..{1} in {2}.dat -f {2}.fmt -q' | ||
inst_command = redirect_string.format(dbname, tblname, datafile) + conn_options | ||
executeCommmand(inst_command) | ||
|
||
def setupAE(conn_options, dbname): | ||
if (platform.system() == 'Windows'): | ||
# import self signed certificate | ||
inst_command = "certutil -user -p '' -importPFX My PHPcert.pfx NoRoot" | ||
executeCommmand(inst_command) | ||
# create Column Master Key and Column Encryption Key | ||
script_command = 'sqlcmd ' + conn_options + ' -i ae_keys.sql -d ' + dbname | ||
script_command = 'sqlcmd -I ' + conn_options + ' -i ae_keys.sql -d ' + dbname | ||
executeCommmand(script_command) | ||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-dbname', '--DBNAME', required=True) | ||
parser.add_argument('-azure', '--AZURE', required=False, default='no') | ||
args = parser.parse_args() | ||
try: | ||
server = os.environ['TEST_PHP_SQL_SERVER'] | ||
uid = os.environ['TEST_PHP_SQL_UID'] | ||
pwd = os.environ['TEST_PHP_SQL_PWD'] | ||
|
||
try: | ||
server = os.environ['TEST_PHP_SQL_SERVER'] | ||
uid = os.environ['TEST_PHP_SQL_UID'] | ||
pwd = os.environ['TEST_PHP_SQL_PWD'] | ||
except : | ||
print("TEST_PHP_SQL_SERVER environment variable must be set to the name of the server to use") | ||
print("TEST_PHP_SQL_UID environment variable must be set to the name of the user to authenticate with") | ||
|
@@ -59,18 +53,17 @@ def setupAE(conn_options, dbname): | |
|
||
current_working_dir=os.getcwd() | ||
os.chdir(os.path.dirname(os.path.realpath(__file__))) | ||
conn_options = ' -S ' + server + ' -U ' + uid + ' -P ' + pwd + ' ' | ||
conn_options = ' -S ' + server + ' -U ' + uid + ' -P ' + pwd + ' ' | ||
|
||
# In Azure, assume an empty test database has been created using Azure portal | ||
if (args.AZURE.lower() == 'no'): | ||
executeSQLscript('create_db.sql', conn_options, args.DBNAME) | ||
manageTestDB('create_db.sql', conn_options, args.DBNAME) | ||
|
||
# create tables in the new database | ||
setupTestDatabase(conn_options, args.DBNAME, args.AZURE) | ||
setupTestDatabase(conn_options, args.DBNAME, args.AZURE) | ||
# populate these tables | ||
populateTables(conn_options, args.DBNAME) | ||
# setup AE (certificate, column master key and column encryption key) | ||
setupAE(conn_options, args.DBNAME) | ||
|
||
os.chdir(current_working_dir) | ||
|
||
|
||
os.chdir(current_working_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these changes are to make the scripts work with DW - but then we are using these scripts for all the other platforms we test on, correct? I assume we've tested these scripts in Bamboo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change we no longer need the clumsy workaround outside Windows platforms