Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2bootstrap
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
yii2bootstrap
Commits
66a5b9c3
Commit
66a5b9c3
authored
May 22, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #351 from yiisoft/mssql
Initial MSSQL support.
parents
e1ea91a7
2430ebe9
Changes
14
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
737 additions
and
303 deletions
+737
-303
Connection.php
framework/yii/db/Connection.php
+3
-3
QueryBuilder.php
framework/yii/db/QueryBuilder.php
+2
-1
PDO.php
framework/yii/db/mssql/PDO.php
+61
-0
QueryBuilder.php
framework/yii/db/mssql/QueryBuilder.php
+81
-0
Schema.php
framework/yii/db/mssql/Schema.php
+364
-0
SqlsrvPDO.php
framework/yii/db/mssql/SqlsrvPDO.php
+33
-0
QueryBuilder.php
framework/yii/db/mysql/QueryBuilder.php
+4
-3
QueryBuilder.php
framework/yii/db/sqlite/QueryBuilder.php
+3
-2
config.php
tests/unit/data/config.php
+7
-1
mssql.sql
tests/unit/data/mssql.sql
+81
-293
MssqlActiveRecordTest.php
tests/unit/framework/db/mssql/MssqlActiveRecordTest.php
+12
-0
MssqlCommandTest.php
tests/unit/framework/db/mssql/MssqlCommandTest.php
+31
-0
MssqlConnectionTest.php
tests/unit/framework/db/mssql/MssqlConnectionTest.php
+43
-0
MssqlQueryTest.php
tests/unit/framework/db/mssql/MssqlQueryTest.php
+12
-0
No files found.
framework/yii/db/Connection.php
View file @
66a5b9c3
...
@@ -237,10 +237,10 @@ class Connection extends Component
...
@@ -237,10 +237,10 @@ class Connection extends Component
'mysql'
=>
'yii\db\mysql\Schema'
,
// MySQL
'mysql'
=>
'yii\db\mysql\Schema'
,
// MySQL
'sqlite'
=>
'yii\db\sqlite\Schema'
,
// sqlite 3
'sqlite'
=>
'yii\db\sqlite\Schema'
,
// sqlite 3
'sqlite2'
=>
'yii\db\sqlite\Schema'
,
// sqlite 2
'sqlite2'
=>
'yii\db\sqlite\Schema'
,
// sqlite 2
'mssql'
=>
'yii\db\dao\mssql\Schema'
,
// Mssql driver on windows hosts
'sqlsrv'
=>
'yii\db\mssql\Schema'
,
// newer MSSQL driver on MS Windows hosts
'sqlsrv'
=>
'yii\db\mssql\Schema'
,
// Mssql
'oci'
=>
'yii\db\oci\Schema'
,
// Oracle driver
'oci'
=>
'yii\db\oci\Schema'
,
// Oracle driver
'dblib'
=>
'yii\db\mssql\Schema'
,
// dblib drivers on linux (and maybe others os) hosts
'mssql'
=>
'yii\db\mssql\Schema'
,
// older MSSQL driver on MS Windows hosts
'dblib'
=>
'yii\db\mssql\Schema'
,
// dblib drivers on GNU/Linux (and maybe other OSes) hosts
);
);
/**
/**
* @var Transaction the currently active transaction
* @var Transaction the currently active transaction
...
...
framework/yii/db/QueryBuilder.php
View file @
66a5b9c3
...
@@ -429,10 +429,11 @@ class QueryBuilder extends \yii\base\Object
...
@@ -429,10 +429,11 @@ class QueryBuilder extends \yii\base\Object
* Builds a SQL statement for enabling or disabling integrity check.
* Builds a SQL statement for enabling or disabling integrity check.
* @param boolean $check whether to turn on or off the integrity check.
* @param boolean $check whether to turn on or off the integrity check.
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
* @param string $table the table name. Defaults to empty string, meaning that no table will be changed.
* @return string the SQL statement for checking integrity
* @return string the SQL statement for checking integrity
* @throws NotSupportedException if this is not supported by the underlying DBMS
* @throws NotSupportedException if this is not supported by the underlying DBMS
*/
*/
public
function
checkIntegrity
(
$check
=
true
,
$schema
=
''
)
public
function
checkIntegrity
(
$check
=
true
,
$schema
=
''
,
$table
=
''
)
{
{
throw
new
NotSupportedException
(
$this
->
db
->
getDriverName
()
.
' does not support enabling/disabling integrity check.'
);
throw
new
NotSupportedException
(
$this
->
db
->
getDriverName
()
.
' does not support enabling/disabling integrity check.'
);
}
}
...
...
framework/yii/db/mssql/PDO.php
0 → 100644
View file @
66a5b9c3
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\db\mssql
;
/**
* This is an extension of the default PDO class of MSSQL and DBLIB drivers.
* It provides workarounds for improperly implemented functionalities of the MSSQL and DBLIB drivers.
*
* @author Timur Ruziev <resurtm@gmail.com>
* @since 2.0
*/
class
PDO
extends
\PDO
{
/**
* Returns value of the last inserted ID.
* @param string|null $sequence the sequence name. Defaults to null.
* @return integer last inserted ID value.
*/
public
function
lastInsertId
(
$sequence
=
null
)
{
return
$this
->
query
(
'SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS bigint)'
)
->
fetchColumn
();
}
/**
* Starts a transaction. It is necessary to override PDO's method as MSSQL PDO driver does not
* natively support transactions.
* @return boolean the result of a transaction start.
*/
public
function
beginTransaction
()
{
$this
->
exec
(
'BEGIN TRANSACTION'
);
return
true
;
}
/**
* Commits a transaction. It is necessary to override PDO's method as MSSQL PDO driver does not
* natively support transactions.
* @return boolean the result of a transaction commit.
*/
public
function
commit
()
{
$this
->
exec
(
'COMMIT TRANSACTION'
);
return
true
;
}
/**
* Rollbacks a transaction. It is necessary to override PDO's method as MSSQL PDO driver does not
* natively support transactions.
* @return boolean the result of a transaction rollback.
*/
public
function
rollBack
()
{
$this
->
exec
(
'ROLLBACK TRANSACTION'
);
return
true
;
}
}
framework/yii/db/mssql/QueryBuilder.php
0 → 100644
View file @
66a5b9c3
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\db\mssql
;
use
yii\base\InvalidParamException
;
/**
* QueryBuilder is the query builder for MS SQL Server databases (version 2008 and above).
*
* @author Timur Ruziev <resurtm@gmail.com>
* @since 2.0
*/
class
QueryBuilder
extends
\yii\db\QueryBuilder
{
/**
* @var array mapping from abstract column types (keys) to physical column types (values).
*/
public
$typeMap
=
array
(
Schema
::
TYPE_PK
=>
'int IDENTITY PRIMARY KEY'
,
Schema
::
TYPE_STRING
=>
'varchar(255)'
,
Schema
::
TYPE_TEXT
=>
'text'
,
Schema
::
TYPE_SMALLINT
=>
'smallint(6)'
,
Schema
::
TYPE_INTEGER
=>
'int(11)'
,
Schema
::
TYPE_BIGINT
=>
'bigint(20)'
,
Schema
::
TYPE_FLOAT
=>
'float'
,
Schema
::
TYPE_DECIMAL
=>
'decimal'
,
Schema
::
TYPE_DATETIME
=>
'datetime'
,
Schema
::
TYPE_TIMESTAMP
=>
'timestamp'
,
Schema
::
TYPE_TIME
=>
'time'
,
Schema
::
TYPE_DATE
=>
'date'
,
Schema
::
TYPE_BINARY
=>
'binary'
,
Schema
::
TYPE_BOOLEAN
=>
'tinyint(1)'
,
Schema
::
TYPE_MONEY
=>
'decimal(19,4)'
,
);
// public function update($table, $columns, $condition, &$params)
// {
// return '';
// }
// public function delete($table, $condition, &$params)
// {
// return '';
// }
// public function buildLimit($limit, $offset)
// {
// return '';
// }
// public function resetSequence($table, $value = null)
// {
// return '';
// }
/**
* Builds a SQL statement for enabling or disabling integrity check.
* @param boolean $check whether to turn on or off the integrity check.
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
* @param string $table the table name. Defaults to empty string, meaning that no table will be changed.
* @return string the SQL statement for checking integrity
* @throws InvalidParamException if the table does not exist or there is no sequence associated with the table.
*/
public
function
checkIntegrity
(
$check
=
true
,
$schema
=
''
,
$table
=
''
)
{
if
(
$schema
!==
''
)
{
$table
=
"
{
$schema
}
.
{
$table
}
"
;
}
$table
=
$this
->
db
->
quoteTableName
(
$table
);
if
(
$this
->
db
->
getTableSchema
(
$table
)
===
null
)
{
throw
new
InvalidParamException
(
"Table not found:
$table
"
);
}
$enable
=
$check
?
'CHECK'
:
'NOCHECK'
;
return
"ALTER TABLE
{
$table
}
{
$enable
}
CONSTRAINT ALL"
;
}
}
framework/yii/db/mssql/Schema.php
0 → 100644
View file @
66a5b9c3
This diff is collapsed.
Click to expand it.
framework/yii/db/mssql/SqlsrvPDO.php
0 → 100644
View file @
66a5b9c3
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\db\mssql
;
/**
* This is an extension of the default PDO class of SQLSRV driver.
* It provides workarounds for improperly implemented functionalities of the SQLSRV driver.
*
* @author Timur Ruziev <resurtm@gmail.com>
* @since 2.0
*/
class
SqlsrvPDO
extends
\PDO
{
/**
* Returns value of the last inserted ID.
*
* SQLSRV driver implements [[PDO::lastInsertId()]] method but with a single peculiarity:
* when `$sequence` value is a null or an empty string it returns an empty string.
* But when parameter is not specified it works as expected and returns actual
* last inserted ID (like the other PDO drivers).
* @param string|null $sequence the sequence name. Defaults to null.
* @return integer last inserted ID value.
*/
public
function
lastInsertId
(
$sequence
=
null
)
{
return
!
$sequence
?
parent
::
lastInsertId
()
:
parent
::
lastInsertId
(
$sequence
);
}
}
framework/yii/db/mysql/QueryBuilder.php
View file @
66a5b9c3
...
@@ -120,12 +120,13 @@ class QueryBuilder extends \yii\db\QueryBuilder
...
@@ -120,12 +120,13 @@ class QueryBuilder extends \yii\db\QueryBuilder
/**
/**
* Builds a SQL statement for enabling or disabling integrity check.
* Builds a SQL statement for enabling or disabling integrity check.
* @param boolean $check whether to turn on or off the integrity check.
* @param boolean $check whether to turn on or off the integrity check.
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
* @param string $table the table name. Meaningless for MySQL.
* @param string $schema the schema of the tables. Meaningless for MySQL.
* @return string the SQL statement for checking integrity
* @return string the SQL statement for checking integrity
*/
*/
public
function
checkIntegrity
(
$check
=
true
,
$schema
=
''
)
public
function
checkIntegrity
(
$check
=
true
,
$schema
=
''
,
$table
=
''
)
{
{
return
'SET FOREIGN_KEY_CHECKS
=
'
.
(
$check
?
1
:
0
);
return
'SET FOREIGN_KEY_CHECKS
=
'
.
(
$check
?
1
:
0
);
}
}
/**
/**
...
...
framework/yii/db/sqlite/QueryBuilder.php
View file @
66a5b9c3
...
@@ -77,10 +77,11 @@ class QueryBuilder extends \yii\db\QueryBuilder
...
@@ -77,10 +77,11 @@ class QueryBuilder extends \yii\db\QueryBuilder
/**
/**
* Enables or disables integrity check.
* Enables or disables integrity check.
* @param boolean $check whether to turn on or off the integrity check.
* @param boolean $check whether to turn on or off the integrity check.
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
* @param string $schema the schema of the tables. Meaningless for SQLite.
* @param string $table the table name. Meaningless for SQLite.
* @throws NotSupportedException this is not supported by SQLite
* @throws NotSupportedException this is not supported by SQLite
*/
*/
public
function
checkIntegrity
(
$check
=
true
,
$schema
=
''
)
public
function
checkIntegrity
(
$check
=
true
,
$schema
=
''
,
$table
=
''
)
{
{
throw
new
NotSupportedException
(
__METHOD__
.
' is not supported by SQLite.'
);
throw
new
NotSupportedException
(
__METHOD__
.
' is not supported by SQLite.'
);
}
}
...
...
tests/unit/data/config.php
View file @
66a5b9c3
...
@@ -14,5 +14,11 @@ return array(
...
@@ -14,5 +14,11 @@ return array(
'dsn'
=>
'sqlite::memory:'
,
'dsn'
=>
'sqlite::memory:'
,
'fixture'
=>
__DIR__
.
'/sqlite.sql'
,
'fixture'
=>
__DIR__
.
'/sqlite.sql'
,
),
),
'sqlsrv'
=>
array
(
'dsn'
=>
'sqlsrv:Server=localhost;Database=test'
,
'username'
=>
''
,
'password'
=>
''
,
'fixture'
=>
__DIR__
.
'/mssql.sql'
,
),
),
)
);
);
tests/unit/data/mssql.sql
View file @
66a5b9c3
This diff is collapsed.
Click to expand it.
tests/unit/framework/db/mssql/MssqlActiveRecordTest.php
0 → 100644
View file @
66a5b9c3
<?php
namespace
yiiunit\framework\db\mssql
;
class
MssqlActiveRecordTest
extends
\yiiunit\framework\db\ActiveRecordTest
{
protected
function
setUp
()
{
$this
->
driverName
=
'sqlsrv'
;
parent
::
setUp
();
}
}
tests/unit/framework/db/mssql/MssqlCommandTest.php
0 → 100644
View file @
66a5b9c3
<?php
namespace
yiiunit\framework\db\mssql
;
class
MssqlCommandTest
extends
\yiiunit\framework\db\CommandTest
{
public
function
setUp
()
{
$this
->
driverName
=
'sqlsrv'
;
parent
::
setUp
();
}
function
testAutoQuoting
()
{
$db
=
$this
->
getConnection
(
false
);
$sql
=
'SELECT [[id]], [[t.name]] FROM {{tbl_customer}} t'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
"SELECT [id], [t].[name] FROM [tbl_customer] t"
,
$command
->
sql
);
}
function
testPrepareCancel
()
{
$this
->
markTestIncomplete
();
}
function
testBindParamValue
()
{
$this
->
markTestIncomplete
();
}
}
tests/unit/framework/db/mssql/MssqlConnectionTest.php
0 → 100644
View file @
66a5b9c3
<?php
namespace
yiiunit\framework\db\mssql
;
class
MssqlConnectionTest
extends
\yiiunit\framework\db\ConnectionTest
{
public
function
setUp
()
{
$this
->
driverName
=
'sqlsrv'
;
parent
::
setUp
();
}
function
testQuoteValue
()
{
$connection
=
$this
->
getConnection
(
false
);
$this
->
assertEquals
(
123
,
$connection
->
quoteValue
(
123
));
$this
->
assertEquals
(
"'string'"
,
$connection
->
quoteValue
(
'string'
));
$this
->
assertEquals
(
"'It''s interesting'"
,
$connection
->
quoteValue
(
"It's interesting"
));
}
function
testQuoteTableName
()
{
$connection
=
$this
->
getConnection
(
false
);
$this
->
assertEquals
(
'[table]'
,
$connection
->
quoteTableName
(
'table'
));
$this
->
assertEquals
(
'[table]'
,
$connection
->
quoteTableName
(
'[table]'
));
$this
->
assertEquals
(
'[schema].[table]'
,
$connection
->
quoteTableName
(
'schema.table'
));
$this
->
assertEquals
(
'[schema].[table]'
,
$connection
->
quoteTableName
(
'schema.[table]'
));
$this
->
assertEquals
(
'{{table}}'
,
$connection
->
quoteTableName
(
'{{table}}'
));
$this
->
assertEquals
(
'(table)'
,
$connection
->
quoteTableName
(
'(table)'
));
}
function
testQuoteColumnName
()
{
$connection
=
$this
->
getConnection
(
false
);
$this
->
assertEquals
(
'[column]'
,
$connection
->
quoteColumnName
(
'column'
));
$this
->
assertEquals
(
'[column]'
,
$connection
->
quoteColumnName
(
'[column]'
));
$this
->
assertEquals
(
'[table].[column]'
,
$connection
->
quoteColumnName
(
'table.column'
));
$this
->
assertEquals
(
'[table].[column]'
,
$connection
->
quoteColumnName
(
'table.[column]'
));
$this
->
assertEquals
(
'[[column]]'
,
$connection
->
quoteColumnName
(
'[[column]]'
));
$this
->
assertEquals
(
'{{column}}'
,
$connection
->
quoteColumnName
(
'{{column}}'
));
$this
->
assertEquals
(
'(column)'
,
$connection
->
quoteColumnName
(
'(column)'
));
}
}
tests/unit/framework/db/mssql/MssqlQueryTest.php
0 → 100644
View file @
66a5b9c3
<?php
namespace
yiiunit\framework\db\mssql
;
class
MssqlQueryTest
extends
\yiiunit\framework\db\QueryTest
{
public
function
setUp
()
{
$this
->
driverName
=
'sqlsrv'
;
parent
::
setUp
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment