зеркало из https://github.com/microsoft/msphpsql.git
Database setup (#367)
* porting database setup files for functional tests * Updating yml files to setup test databases before running the tests * update spacing * Renaming env variables * Modifying cleanup_dbs.py and setup_dbs.py scripts so that they can execute database setup files * update env variables * Fix typo * Update .travis.yml * update env variables * update travis scripts * Checking sqlcmd setup on travis * Checking sqlcmd setup on travis * sqlcmd bcp fix * sqlcmd bcp fix * sqlcmd bcp fix * sqlcmd bcp fix * sqlcmd bcp fix * sqlcmd bcp fix * sqlcmd bcp fix * sqlcmd bcp fix * sqlcmd bcp fix * Adding a test to make sure the database is setup properly * update exec_sql_scripts.py * update sqlsrv_num_fields.phpt * update sqlsrv_num_fields.phpt * update * Fixing identation
This commit is contained in:
Родитель
041d3129bc
Коммит
41af6fc0a2
14
.travis.yml
14
.travis.yml
|
@ -10,25 +10,31 @@ env:
|
|||
global:
|
||||
- REPORT_EXIT_STATUS=1
|
||||
- ACCEPT_EULA=Y
|
||||
- PHPSQLDIR=/REPO/msphpsql-PHP-7.0-Linux
|
||||
- SQLSERVERHOSTNAME=sql
|
||||
- PHPSQLDIR=/REPO/msphpsql-dev
|
||||
- TEST_PHP_SQL_SERVER=sql
|
||||
- SQLSRV_DBNAME=msphpsql_sqlsrv
|
||||
- PDOSQLSRV_DBNAME=msphpsql_pdosqlsrv
|
||||
|
||||
before_install:
|
||||
- docker pull microsoft/mssql-server-linux
|
||||
|
||||
install:
|
||||
- docker build --build-arg PHPSQLDIR=$PHPSQLDIR -t msphpsql-dev -f Dockerfile-msphpsql .
|
||||
- docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<YourStrong!Passw0rd>' -p 1433:1433 --name=$SQLSERVERHOSTNAME -d microsoft/mssql-server-linux
|
||||
- docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Password12@' -p 1433:1433 --name=$TEST_PHP_SQL_SERVER -d microsoft/mssql-server-linux
|
||||
|
||||
script:
|
||||
- docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --link $SQLSERVERHOSTNAME --name=client msphpsql-dev
|
||||
- docker run -e TRAVIS_JOB_ID -t -d -w $PHPSQLDIR --link $TEST_PHP_SQL_SERVER --name=client msphpsql-dev
|
||||
- docker ps -a
|
||||
- docker exec client python ./test/setup/setup_dbs.py -dbname $SQLSRV_DBNAME
|
||||
- docker exec client python ./test/setup/setup_dbs.py -dbname $PDOSQLSRV_DBNAME
|
||||
- docker exec client php ./source/pdo_sqlsrv/run-tests.php ./test/pdo_sqlsrv/*.phpt
|
||||
- docker exec client php ./source/sqlsrv/run-tests.php ./test/sqlsrv/*.phpt
|
||||
- docker exec client bash -c 'for f in ./test/sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true'
|
||||
- docker exec client bash -c 'for f in ./test/sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true'
|
||||
- docker exec client bash -c 'for f in ./test/pdo_sqlsrv/*.diff; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true'
|
||||
- docker exec client bash -c 'for f in ./test/pdo_sqlsrv/*.out; do ls $f 2>/dev/null; cat $f 2>/dev/null; done || true'
|
||||
- docker exec client python ./test/setup/cleanup_dbs.py -dbname $SQLSRV_DBNAME
|
||||
- docker exec client python ./test/setup/cleanup_dbs.py -dbname $PDOSQLSRV_DBNAME
|
||||
- docker exec client coveralls -e ./source/shared/ --gcov-options '\-lp'
|
||||
- docker stop client
|
||||
- docker ps -a
|
||||
|
|
|
@ -23,7 +23,10 @@ RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && \
|
|||
unixodbc-dev \
|
||||
unzip && apt-get clean
|
||||
|
||||
ARG PHPSQLDIR=/REPO/msphpsql-PHP-7.0-Linux
|
||||
ARG PHPSQLDIR=/REPO/msphpsql-dev
|
||||
ENV TEST_PHP_SQL_SERVER sql
|
||||
ENV TEST_PHP_SQL_UID sa
|
||||
ENV TEST_PHP_SQL_PWD Password12@
|
||||
|
||||
# set locale to utf-8
|
||||
RUN locale-gen en_US.UTF-8
|
||||
|
@ -37,6 +40,8 @@ RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt
|
|||
#RUN apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
|
||||
RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools
|
||||
|
||||
ENV PATH="/opt/mssql-tools/bin:${PATH}"
|
||||
|
||||
#install coveralls
|
||||
RUN pip install --upgrade pip && pip install cpp-coveralls
|
||||
|
||||
|
@ -64,9 +69,12 @@ RUN phpize && ./configure LDFLAGS="-lgcov" CXXFLAGS="-O0 --coverage" && make &&
|
|||
# set name of sql server host to use
|
||||
WORKDIR $PHPSQLDIR/test/pdo_sqlsrv
|
||||
RUN sed -i -e 's/localhost/sql/g' autonomous_setup.php
|
||||
RUN sed -i -e 's/<YourStrong!Passw0rd>/'"$TEST_PHP_SQL_PWD"'/g' autonomous_setup.php
|
||||
|
||||
WORKDIR $PHPSQLDIR/test/sqlsrv
|
||||
RUN sed -i -e 's/localhost/sql/g' autonomous_setup.php
|
||||
RUN sed -i -e 's/<YourStrong!Passw0rd>/'"$TEST_PHP_SQL_PWD"'/g' autonomous_setup.php
|
||||
|
||||
ENV REPORT_EXIT_STATUS 1
|
||||
ENV TEST_PHP_EXECUTABLE /usr/bin/php
|
||||
|
||||
|
|
25
appveyor.yml
25
appveyor.yml
|
@ -11,13 +11,15 @@ branches:
|
|||
|
||||
environment:
|
||||
# MSSQL credentials from https://www.appveyor.com/docs/services-databases/
|
||||
MSSQL_PASSWORD: Password12!
|
||||
MSSQL_USERNAME: sa
|
||||
TEST_PHP_SQL_PWD: Password12!
|
||||
TEST_PHP_SQL_UID: sa
|
||||
SQLSRV_DBNAME: msphpsql_sqlsrv
|
||||
PDOSQLSRV_DBNAME: msphpsql_pdosqlsrv
|
||||
PHP_DEPSVER: 7.0
|
||||
PHP_SDK: c:\projects\php
|
||||
matrix:
|
||||
- BUILD_PLATFORM: x64
|
||||
MSSQL_SERVERNAME: (local)\SQL2012SP1
|
||||
TEST_PHP_SQL_SERVER: (local)\SQL2012SP1
|
||||
SQL_INSTANCE: SQL2012SP1
|
||||
PHP_VC: 14
|
||||
PHP_MAJOR_VER: 7.0
|
||||
|
@ -27,7 +29,7 @@ environment:
|
|||
PHP_ZTS: --disable-zts
|
||||
platform: x64
|
||||
- BUILD_PLATFORM: x86
|
||||
MSSQL_SERVERNAME: (local)\SQL2014
|
||||
TEST_PHP_SQL_SERVER: (local)\SQL2014
|
||||
SQL_INSTANCE: SQL2014
|
||||
PHP_VC: 14
|
||||
PHP_MAJOR_VER: 7.0
|
||||
|
@ -36,7 +38,7 @@ environment:
|
|||
PHP_INSTALL_DIR: c:\projects\php\x86\bin
|
||||
platform: x86
|
||||
- BUILD_PLATFORM: x64
|
||||
MSSQL_SERVERNAME: (local)\SQL2016
|
||||
TEST_PHP_SQL_SERVER: (local)\SQL2016
|
||||
SQL_INSTANCE: SQL2016
|
||||
PHP_VC: 14
|
||||
PHP_MAJOR_VER: 7.1
|
||||
|
@ -45,7 +47,7 @@ environment:
|
|||
PHP_INSTALL_DIR: c:\projects\php\x64\bin
|
||||
platform: x64
|
||||
- BUILD_PLATFORM: x86
|
||||
MSSQL_SERVERNAME: (local)\SQL2008R2SP2
|
||||
TEST_PHP_SQL_SERVER: (local)\SQL2008R2SP2
|
||||
SQL_INSTANCE: SQL2008R2SP2
|
||||
PHP_VC: 14
|
||||
PHP_MAJOR_VER: 7.1
|
||||
|
@ -120,9 +122,9 @@ install:
|
|||
- 7z x -y php-sdk-binary-tools-20110915.zip -o%PHP_SDK%
|
||||
- 7z x -y php.zip -o%PHP_SDK_DIR%
|
||||
- echo update SQL connection string
|
||||
- ps: (Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\autonomous_setup.php) | ForEach-Object { $_ -replace "localhost", ${env:MSSQL_SERVERNAME} -replace "<YourStrong!Passw0rd>", ${env:MSSQL_PASSWORD} } | Set-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\autonomous_setup.php
|
||||
- ps: (Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\autonomous_setup.php) | ForEach-Object { $_ -replace "localhost", ${env:TEST_PHP_SQL_SERVER} -replace "<YourStrong!Passw0rd>", ${env:TEST_PHP_SQL_PWD} } | Set-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\autonomous_setup.php
|
||||
- ps: Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\pdo_sqlsrv\autonomous_setup.php
|
||||
- ps: (Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\autonomous_setup.php) | ForEach-Object { $_ -replace "localhost", ${env:MSSQL_SERVERNAME} -replace "<YourStrong!Passw0rd>", ${env:MSSQL_PASSWORD} } | Set-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\autonomous_setup.php
|
||||
- ps: (Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\autonomous_setup.php) | ForEach-Object { $_ -replace "localhost", ${env:TEST_PHP_SQL_SERVER} -replace "<YourStrong!Passw0rd>", ${env:TEST_PHP_SQL_PWD} } | Set-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\autonomous_setup.php
|
||||
- ps: Get-Content ${env:APPVEYOR_BUILD_FOLDER}\test\sqlsrv\autonomous_setup.php
|
||||
|
||||
build_script:
|
||||
|
@ -158,10 +160,17 @@ test_script:
|
|||
- cd %PHP_INSTALL_DIR%
|
||||
- php --ini
|
||||
- php -i
|
||||
- python -V
|
||||
- Echo setup test database for SQLSRV tests - %SQLSRV_DBNAME%
|
||||
- python %APPVEYOR_BUILD_FOLDER%\test\setup\setup_dbs.py -dbname %SQLSRV_DBNAME%
|
||||
- Echo setup test database for PDO_SQLSRV tests - %PDOSQLSRV_DBNAME%
|
||||
- python %APPVEYOR_BUILD_FOLDER%\test\setup\setup_dbs.py -dbname %PDOSQLSRV_DBNAME%
|
||||
- php run-tests.php -p php.exe %APPVEYOR_BUILD_FOLDER%\test\sqlsrv\*.phpt > %APPVEYOR_BUILD_FOLDER%\test\sqlsrv.log 2>&1
|
||||
- type %APPVEYOR_BUILD_FOLDER%\test\sqlsrv.log
|
||||
- php run-tests.php -p php.exe %APPVEYOR_BUILD_FOLDER%\test\pdo_sqlsrv\*.phpt > %APPVEYOR_BUILD_FOLDER%\test\pdo_sqlsrv.log 2>&1
|
||||
- type %APPVEYOR_BUILD_FOLDER%\test\pdo_sqlsrv.log
|
||||
- python %APPVEYOR_BUILD_FOLDER%\test\setup\cleanup_dbs.py -dbname %SQLSRV_DBNAME%
|
||||
- python %APPVEYOR_BUILD_FOLDER%\test\setup\cleanup_dbs.py -dbname %PDOSQLSRV_DBNAME%
|
||||
|
||||
after_test:
|
||||
- cd %APPVEYOR_BUILD_FOLDER%\test\
|
||||
|
|
Двоичный файл не отображается.
|
@ -0,0 +1,13 @@
|
|||
9.0
|
||||
11
|
||||
1 SQLINT 0 4 "" 1 SalesOrderID ""
|
||||
2 SQLINT 0 4 "" 2 SalesOrderDetailID ""
|
||||
3 SQLNCHAR 2 50 "" 3 CarrierTrackingNumber Latin1_General_CS_AS
|
||||
4 SQLSMALLINT 0 2 "" 4 OrderQty ""
|
||||
5 SQLINT 0 4 "" 5 ProductID ""
|
||||
6 SQLINT 0 4 "" 6 SpecialOfferID ""
|
||||
7 SQLMONEY 0 8 "" 7 UnitPrice ""
|
||||
8 SQLMONEY 0 8 "" 8 UnitPriceDiscount ""
|
||||
9 SQLNUMERIC 1 19 "" 9 LineTotal ""
|
||||
10 SQLUNIQUEID 1 16 "" 10 rowguid ""
|
||||
11 SQLDATETIME 0 8 "" 11 ModifiedDate ""
|
|
@ -0,0 +1,24 @@
|
|||
USE $(dbname)
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT * FROM sys.objects
|
||||
WHERE object_id = OBJECT_ID(N'[dbo].[168256]') AND type in (N'U'))
|
||||
|
||||
BEGIN
|
||||
DROP TABLE [168256]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE TABLE [168256] (
|
||||
[SalesOrderID] [int] NOT NULL,
|
||||
[SalesOrderDetailID] [int] IDENTITY(1,1) NOT NULL,
|
||||
[CarrierTrackingNumber] [nvarchar](25) NULL,
|
||||
[OrderQty] [smallint] NOT NULL,
|
||||
[ProductID] [int] NOT NULL,
|
||||
[SpecialOfferID] [int] NOT NULL,
|
||||
[UnitPrice] [money] NOT NULL,
|
||||
[UnitPriceDiscount] [money] NOT NULL DEFAULT ((0.0)),
|
||||
[LineTotal] AS (isnull(([UnitPrice]*((1.0)-[UnitPriceDiscount]))*[OrderQty],(0.0))),
|
||||
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL DEFAULT (newid()),
|
||||
[ModifiedDate] [datetime] NOT NULL DEFAULT (getdate()));
|
||||
GO
|
Двоичный файл не отображается.
|
@ -0,0 +1,12 @@
|
|||
9.0
|
||||
10
|
||||
1 SQLCHAR 2 10 "" 1 asin SQL_Latin1_General_CP1_CI_AS
|
||||
2 SQLCHAR 2 12 "" 2 upc SQL_Latin1_General_CP1_CI_AS
|
||||
3 SQLCHAR 2 50 "" 3 title SQL_Latin1_General_CP1_CI_AS
|
||||
4 SQLCHAR 2 50 "" 4 artist SQL_Latin1_General_CP1_CI_AS
|
||||
5 SQLCHAR 2 12 "" 5 rel_date SQL_Latin1_General_CP1_CI_AS
|
||||
6 SQLCHAR 2 50 "" 6 label SQL_Latin1_General_CP1_CI_AS
|
||||
7 SQLCHAR 2 500 "" 7 image SQL_Latin1_General_CP1_CI_AS
|
||||
8 SQLCHAR 2 500 "" 8 med_image SQL_Latin1_General_CP1_CI_AS
|
||||
9 SQLCHAR 8 0 "" 9 review1 SQL_Latin1_General_CP1_CI_AS
|
||||
10 SQLCHAR 8 0 "" 10 review2 SQL_Latin1_General_CP1_CI_AS
|
|
@ -0,0 +1,47 @@
|
|||
USE $(dbname)
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT * FROM sys.objects
|
||||
WHERE object_id = OBJECT_ID(N'[dbo].[tracks]') AND type in (N'U'))
|
||||
|
||||
BEGIN
|
||||
ALTER TABLE $(dbname)..[tracks] DROP CONSTRAINT [FK__tracks__asin__7F60ED59]
|
||||
END
|
||||
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT * FROM sys.objects
|
||||
WHERE object_id = OBJECT_ID(N'[dbo].[cd_info]') AND type in (N'U'))
|
||||
|
||||
BEGIN
|
||||
DROP TABLE [cd_info]
|
||||
END
|
||||
|
||||
GO
|
||||
|
||||
/****** Object: Table [dbo].[cd_info] Script Date: 09/26/2007 11:26:52 ******/
|
||||
SET ANSI_NULLS ON
|
||||
GO
|
||||
SET QUOTED_IDENTIFIER ON
|
||||
GO
|
||||
SET ANSI_PADDING ON
|
||||
GO
|
||||
CREATE TABLE [dbo].[cd_info](
|
||||
[asin] [char](10) NOT NULL,
|
||||
[upc] [char](12) NULL,
|
||||
[title] [varchar](50) NULL,
|
||||
[artist] [varchar](50) NULL,
|
||||
[rel_date] [varchar](12) NOT NULL CONSTRAINT [DF_cd_info_rel_date] DEFAULT ((0)),
|
||||
[label] [varchar](50) NULL,
|
||||
[image] [varchar](500) NULL,
|
||||
[med_image] [varchar](500) NULL,
|
||||
[review1] [varchar](max) NULL,
|
||||
[review2] [varchar](max) NULL,
|
||||
CONSTRAINT [PK_cd_info] PRIMARY KEY CLUSTERED
|
||||
(
|
||||
[asin] ASC
|
||||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
|
||||
)
|
||||
|
||||
GO
|
||||
SET ANSI_PADDING OFF
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env python
|
||||
# py cleanup_dbs.py -dbname <DBNAME>
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import platform
|
||||
import argparse
|
||||
from subprocess import Popen, PIPE
|
||||
from exec_sql_scripts import *
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-dbname', '--DBNAME', required=True)
|
||||
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']
|
||||
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")
|
||||
print("TEST_PHP_SQL_PWD environment variable must be set to the password of the use to authenticate with")
|
||||
sys.exit(1)
|
||||
|
||||
conn_options = ' -S ' + server + ' -U ' + uid + ' -P ' + pwd + ' '
|
||||
|
||||
executeSQLscript( os.path.join( os.path.dirname(os.path.realpath(__file__)), 'drop_db.sql'), conn_options, args.DBNAME)
|
|
@ -0,0 +1,13 @@
|
|||
USE [master]
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT name FROM sys.databases WHERE name = '$(dbname)' )
|
||||
|
||||
BEGIN
|
||||
DROP DATABASE $(dbname)
|
||||
END
|
||||
|
||||
CREATE DATABASE $(dbname)
|
||||
|
||||
GO
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
USE [master]
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT name FROM sys.databases WHERE name = '$(dbname)' )
|
||||
|
||||
BEGIN
|
||||
DROP DATABASE $(dbname)
|
||||
END
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env python3
|
||||
# contains helper methods
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import platform
|
||||
import argparse
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
def executeCommmand(inst_command):
|
||||
proc = subprocess.Popen(inst_command , stdout=PIPE, stderr= PIPE, shell=True)
|
||||
print ( inst_command )
|
||||
oo,ee = proc.communicate()
|
||||
print (ee)
|
||||
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
|
||||
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
|
||||
|
||||
inst_command = redirect_string.format(dbname, sqlfile, tmpFileName) + sqlcmd
|
||||
executeCommmand(inst_command)
|
||||
os.remove(tmpFileName)
|
|
@ -0,0 +1,79 @@
|
|||
#!/usr/bin/env python3
|
||||
# py setup_dbs.py -dbname <DBNAME> -azure <yes or no>
|
||||
# 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 createLoginUsers(conn_options, dbname, azure):
|
||||
if (azure.lower() == 'yes'):
|
||||
# can only create logins in the master database
|
||||
createLoginUsersAzure('create_logins_azure.sql', conn_options, 'master')
|
||||
# create users to use those logins to access the test database (dbname)
|
||||
createLoginUsersAzure('create_users_azure.sql', conn_options, dbname)
|
||||
else:
|
||||
executeSQLscript('test_password.sql', conn_options, dbname)
|
||||
|
||||
def createLoginUsersAzure(sqlfile, conn_options, dbname):
|
||||
inst_command = 'sqlcmd ' + conn_options + ' -i ' + sqlfile + ' -d ' + dbname
|
||||
executeCommmand(inst_command)
|
||||
|
||||
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
|
||||
|
||||
for sqlFile in sqlFiles:
|
||||
executeSQLscript(sqlFile, conn_options, dbname)
|
||||
|
||||
def populateTables(conn_options, dbname):
|
||||
executeBulkCopy(conn_options, dbname, 'cd_info', 'cd_info')
|
||||
executeBulkCopy(conn_options, dbname, 'tracks', 'tracks')
|
||||
executeBulkCopy(conn_options, dbname, 'test_streamable_types', 'test_streamable_types')
|
||||
executeBulkCopy(conn_options, dbname, '159137', 'xml')
|
||||
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
|
||||
executeCommmand(inst_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']
|
||||
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")
|
||||
print("TEST_PHP_SQL_PWD environment variable must be set to the password of the use to authenticate with")
|
||||
sys.exit(1)
|
||||
|
||||
current_working_dir=os.getcwd()
|
||||
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
||||
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)
|
||||
|
||||
# create login users
|
||||
createLoginUsers(conn_options, args.DBNAME, args.AZURE)
|
||||
# create tables in the new database
|
||||
setupTestDatabase(conn_options, args.DBNAME, args.AZURE)
|
||||
# populate these tables
|
||||
populateTables(conn_options, args.DBNAME)
|
||||
os.chdir(current_working_dir)
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
--first, create new logins (user id / password pair) if not yet created
|
||||
USE master;
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (SELECT name FROM master..syslogins WHERE name = 'test_password')
|
||||
BEGIN
|
||||
CREATE LOGIN test_password WITH PASSWORD='! ;4triou';
|
||||
END
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (SELECT name FROM master..syslogins WHERE name = 'test_password2')
|
||||
BEGIN
|
||||
CREATE LOGIN test_password2 WITH PASSWORD='!} ;4triou';
|
||||
END
|
||||
GO
|
||||
|
||||
IF NOT EXISTS (SELECT name FROM master..syslogins WHERE name = 'test_password3')
|
||||
BEGIN
|
||||
CREATE LOGIN test_password3 WITH PASSWORD='! ;4triou}';
|
||||
END
|
||||
GO
|
||||
|
||||
--the following users will be granted access to the test database
|
||||
USE $(dbname);
|
||||
GO
|
||||
|
||||
CREATE USER test_password FROM LOGIN test_password;
|
||||
CREATE USER test_password2 FROM LOGIN test_password2;
|
||||
CREATE USER test_password3 FROM LOGIN test_password3;
|
||||
GO
|
||||
|
Двоичный файл не отображается.
|
@ -0,0 +1,15 @@
|
|||
9.0
|
||||
13
|
||||
1 SQLCHAR 8 0 "" 1 varchar_type SQL_Latin1_General_CP1_CI_AS
|
||||
2 SQLNCHAR 8 0 "" 2 nvarchar_type SQL_Latin1_General_CP1_CI_AS
|
||||
3 SQLBINARY 8 0 "" 3 varbinary_type ""
|
||||
4 SQLCHAR 4 0 "" 4 text_type SQL_Latin1_General_CP1_CI_AS
|
||||
5 SQLNCHAR 4 0 "" 5 ntext_type SQL_Latin1_General_CP1_CI_AS
|
||||
6 SQLIMAGE 4 0 "" 6 image_type ""
|
||||
7 SQLNCHAR 8 0 "" 7 xml_type ""
|
||||
8 SQLCHAR 2 256 "" 8 char_short_type SQL_Latin1_General_CP1_CI_AS
|
||||
9 SQLCHAR 2 256 "" 9 varchar_short_type SQL_Latin1_General_CP1_CI_AS
|
||||
10 SQLNCHAR 2 512 "" 10 nchar_short_type SQL_Latin1_General_CP1_CI_AS
|
||||
11 SQLNCHAR 2 512 "" 11 nvarchar_short_type SQL_Latin1_General_CP1_CI_AS
|
||||
12 SQLBINARY 2 256 "" 12 binary_short_type ""
|
||||
13 SQLBINARY 2 256 "" 13 varbinary_short_type ""
|
|
@ -0,0 +1,67 @@
|
|||
USE $(dbname)
|
||||
GO
|
||||
|
||||
CREATE TABLE [test_types] ([bigint_type] BIGINT null,
|
||||
[int_type] INT null,
|
||||
[smallint_type] SMALLINT null,
|
||||
[tinyint_type] TINYINT null,
|
||||
[bit_type] BIT null,
|
||||
[decimal_type] DECIMAL(38,0) null,
|
||||
[money_type] MONEY null,
|
||||
[smallmoney_type] SMALLMONEY null,
|
||||
[float_type] FLOAT(53) null,
|
||||
[real_type] REAL null,
|
||||
[datetime_type] DATETIME null,
|
||||
[smalldatetime_type] SMALLDATETIME null );
|
||||
GO
|
||||
|
||||
-- maximum test
|
||||
INSERT INTO $(dbname)..[test_types] (bigint_type, int_type, smallint_type, tinyint_type, bit_type, decimal_type, datetime_type, money_type, smallmoney_type, float_type, real_type)
|
||||
VALUES (9223372036854775807, 2147483647, 32767, 255, 1, 9999999999999999999999999999999999999, '12/12/1968 16:20', 922337203685477.5807, 214748.3647, 1.79E+308, 1.18E-38 )
|
||||
-- minimum test
|
||||
INSERT INTO $(dbname)..[test_types] (bigint_type, int_type, smallint_type, tinyint_type, bit_type, decimal_type, datetime_type, money_type, smallmoney_type, float_type, real_type)
|
||||
VALUES (-9223372036854775808, -2147483648, -32768, 0, 0, -10000000000000000000000000000000000001,'12/12/1968 16:20', -922337203685477.5808, -214748.3648, -1.79E+308, -1.18E-38 )
|
||||
-- zero test
|
||||
INSERT INTO $(dbname)..[test_types] (bigint_type, int_type, smallint_type, tinyint_type, bit_type, decimal_type, datetime_type, money_type, smallmoney_type, float_type, real_type)
|
||||
VALUES (0, 0, 0, 0, 0, 0, '12/12/1968 16:20', 0, 0, 0, 0)
|
||||
|
||||
GO
|
||||
|
||||
CREATE TABLE [test_streamable_types] (
|
||||
[varchar_type] VARCHAR(MAX) null,
|
||||
[nvarchar_type] NVARCHAR(MAX) null,
|
||||
[varbinary_type] VARBINARY(MAX) null,
|
||||
[text_type] TEXT null,
|
||||
[ntext_type] NTEXT null,
|
||||
[image_type] IMAGE null,
|
||||
[xml_type] XML null,
|
||||
[char_short_type] CHAR(256) null,
|
||||
[varchar_short_type] VARCHAR(256) null,
|
||||
[nchar_short_type] NCHAR(256) null,
|
||||
[nvarchar_short_type] NVARCHAR(256) null,
|
||||
[binary_short_type] BINARY(256) null,
|
||||
[varbinary_short_type] VARBINARY(256) null );
|
||||
GO
|
||||
|
||||
CREATE TABLE [155671] ([cat_id] [int] IDENTITY (1,1) NOT NULL, [cat_title] [varchar](50) NOT NULL, [cat_order][int] NOT NULL) ON [PRIMARY];
|
||||
GO
|
||||
|
||||
CREATE TABLE [159137] ([xml_type][xml] null) ON [PRIMARY];
|
||||
GO
|
||||
|
||||
IF EXISTS ( SELECT *
|
||||
FROM sys.objects
|
||||
WHERE object_id = OBJECT_ID(N'test_out')
|
||||
AND type IN ( N'P', N'PC' ) )
|
||||
BEGIN
|
||||
DROP proc test_out
|
||||
END
|
||||
GO
|
||||
|
||||
create proc test_out @p1 integer, @p2 integer, @p3 integer output
|
||||
as
|
||||
begin
|
||||
select @p3 = @p1 + @p2
|
||||
print @p3
|
||||
end
|
||||
go
|
Двоичный файл не отображается.
|
@ -0,0 +1,4 @@
|
|||
9.0
|
||||
2
|
||||
1 SQLCHAR 2 100 "" 1 track SQL_Latin1_General_CP1_CI_AS
|
||||
2 SQLCHAR 2 10 "" 2 asin SQL_Latin1_General_CP1_CI_AS
|
|
@ -0,0 +1,32 @@
|
|||
USE $(dbname)
|
||||
GO
|
||||
|
||||
IF EXISTS (SELECT * FROM sys.objects
|
||||
WHERE object_id = OBJECT_ID(N'[dbo].[tracks]') AND type in (N'U'))
|
||||
|
||||
BEGIN
|
||||
DROP TABLE [tracks]
|
||||
END
|
||||
GO
|
||||
|
||||
/****** Object: Table [dbo].[tracks] Script Date: 09/26/2007 11:33:41 ******/
|
||||
SET ANSI_NULLS ON
|
||||
GO
|
||||
SET QUOTED_IDENTIFIER ON
|
||||
GO
|
||||
SET ANSI_PADDING ON
|
||||
GO
|
||||
CREATE TABLE [dbo].[tracks](
|
||||
[track] [varchar](100) NULL,
|
||||
[asin] [char](10) NOT NULL
|
||||
) ON [PRIMARY]
|
||||
GO
|
||||
|
||||
SET ANSI_PADDING OFF
|
||||
GO
|
||||
|
||||
ALTER TABLE [dbo].[tracks] WITH NOCHECK ADD CONSTRAINT [FK__tracks__asin__7F60ED59] FOREIGN KEY([asin])
|
||||
REFERENCES [dbo].[cd_info] ([asin])
|
||||
GO
|
||||
|
||||
ALTER TABLE [dbo].[tracks] CHECK CONSTRAINT [FK__tracks__asin__7F60ED59]
|
Двоичный файл не отображается.
|
@ -0,0 +1,3 @@
|
|||
9.0
|
||||
1
|
||||
1 SQLBINARY 8 0 "" 1 xml_type ""
|
Загрузка…
Ссылка в новой задаче