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
87c2fefe
Commit
87c2fefe
authored
May 06, 2013
by
resurtm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial MSSQL related commit.
parent
ac8c6c16
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
219 additions
and
4 deletions
+219
-4
Connection.php
framework/db/Connection.php
+6
-4
PDO.php
framework/db/mssql/PDO.php
+68
-0
QueryBuilder.php
framework/db/mssql/QueryBuilder.php
+19
-0
Schema.php
framework/db/mssql/Schema.php
+93
-0
SqlsrvPDO.php
framework/db/mssql/SqlsrvPDO.php
+33
-0
No files found.
framework/db/Connection.php
View file @
87c2fefe
...
@@ -242,10 +242,10 @@ class Connection extends Component
...
@@ -242,10 +242,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'
=>
'yi\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
...
@@ -351,7 +351,9 @@ class Connection extends Component
...
@@ -351,7 +351,9 @@ class Connection extends Component
$pdoClass
=
'\PDO'
;
$pdoClass
=
'\PDO'
;
if
((
$pos
=
strpos
(
$this
->
dsn
,
':'
))
!==
false
)
{
if
((
$pos
=
strpos
(
$this
->
dsn
,
':'
))
!==
false
)
{
$driver
=
strtolower
(
substr
(
$this
->
dsn
,
0
,
$pos
));
$driver
=
strtolower
(
substr
(
$this
->
dsn
,
0
,
$pos
));
if
(
$driver
===
'mssql'
||
$driver
===
'dblib'
||
$driver
===
'sqlsrv'
)
{
if
(
$driver
===
'sqlsrv'
)
{
$pdoClass
=
'yii\db\mssql\SqlsrvPDO'
;
}
elseif
(
$driver
===
'mssql'
||
$driver
===
'dblib'
)
{
$pdoClass
=
'yii\db\mssql\PDO'
;
$pdoClass
=
'yii\db\mssql\PDO'
;
}
}
}
}
...
...
framework/db/mssql/PDO.php
0 → 100644
View file @
87c2fefe
<?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 default PDO class for MSSQL and DBLIB drivers. It provides workaround for improperly
* implemented functionalities of the drivers.
*
* @author Timur Ruziev <qiang.xue@gmail.com>
* @since 2.0
*/
class
PDO
extends
\PDO
{
/**
* Returns last inserted ID value.
*
* @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
();
}
/**
* Begin a transaction.
*
* Is is necessary to override PDO's method as MSSQL PDO drivers does not support transactions.
*
* @return boolean
*/
public
function
beginTransaction
()
{
$this
->
exec
(
'BEGIN TRANSACTION'
);
return
true
;
}
/**
* Commit a transaction.
*
* Is is necessary to override PDO's method as MSSQL PDO drivers does not support transactions.
*
* @return boolean
*/
public
function
commit
()
{
$this
->
exec
(
'COMMIT TRANSACTION'
);
return
true
;
}
/**
* Rollback a transaction.
*
* Is is necessary to override PDO's method as MSSQL PDO drivers does not support transaction.
*
* @return boolean
*/
public
function
rollBack
()
{
$this
->
exec
(
'ROLLBACK TRANSACTION'
);
return
true
;
}
}
framework/db/mssql/QueryBuilder.php
0 → 100644
View file @
87c2fefe
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\db\mssql
;
/**
* QueryBuilder is the query builder for MS SQL databases.
*
* @author Timur Ruziev <resurtm@gmail.com>
* @since 2.0
*/
class
QueryBuilder
extends
\yii\db\QueryBuilder
{
// TODO: mssql driver
}
framework/db/mssql/Schema.php
0 → 100644
View file @
87c2fefe
<?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\db\TableSchema
;
/**
* Schema is the class for retrieving metadata from a MS SQL database (version 2008 and above).
*
* @author Timur Ruziev <qiang.xue@gmail.com>
* @since 2.0
*/
class
Schema
extends
\yii\db\Schema
{
/**
* Default schema name to be used.
*/
const
DEFAULT_SCHEMA
=
'dbo'
;
/**
* @var array mapping from physical column types (keys) to abstract column types (values)
*/
public
$typeMap
=
array
(
// TODO: mssql driver
);
/**
* @param string $name
* @return TableSchema
*/
public
function
loadTableSchema
(
$name
)
{
return
null
;
}
/**
* Quotes a table name for use in a query.
* A simple table name has no schema prefix.
* @param string $name table name.
* @return string the properly quoted table name.
*/
public
function
quoteSimpleTableName
(
$name
)
{
return
strpos
(
$name
,
'['
)
!==
false
?
$name
:
'['
.
$name
.
']'
;
}
/**
* Quotes a column name for use in a query.
* A simple column name has no prefix.
* @param string $name column name.
* @return string the properly quoted column name.
*/
public
function
quoteSimpleColumnName
(
$name
)
{
return
strpos
(
$name
,
'['
)
!==
false
||
$name
===
'*'
?
$name
:
'['
.
$name
.
']'
;
}
/**
* Creates a query builder for the MSSQL database.
* @return QueryBuilder query builder interface.
*/
public
function
createQueryBuilder
()
{
return
new
QueryBuilder
(
$this
->
db
);
}
/**
* Returns all table names in the database.
* This method should be overridden by child classes in order to support this feature
* because the default implementation simply throws an exception.
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
* @return array all table names in the database. The names have NO the schema name prefix.
*/
protected
function
findTableNames
(
$schema
=
''
)
{
if
(
''
===
$schema
)
{
$schema
=
self
::
DEFAULT_SCHEMA
;
}
$sql
=
"SELECT TABLE_NAME FROM [INFORMATION_SCHEMA].[TABLES] WHERE TABLE_SCHEMA = :schema AND TABLE_TYPE = 'BASE TABLE'"
;
$names
=
$this
->
db
->
createCommand
(
$sql
,
array
(
':schema'
=>
$schema
))
->
queryColumn
();
if
(
self
::
DEFAULT_SCHEMA
!==
$schema
)
{
foreach
(
$names
as
$index
=>
$name
)
{
$names
[
$index
]
=
$schema
.
'.'
.
$name
;
}
}
return
$names
;
}
}
framework/db/mssql/SqlsrvPDO.php
0 → 100644
View file @
87c2fefe
<?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 default PDO class for MSSQL SQLSRV driver. It provides workaround for improperly
* implemented functionalities of the PDO SQLSRV driver.
*
* @author Timur Ruziev <resurtm@gmail.com>
* @since 2.0
*/
class
SqlsrvPDO
extends
\PDO
{
/**
* Returns last inserted ID value.
*
* SQLSRV driver supports PDO::lastInsertId() with one peculiarity: when $sequence value is null
* or empty string it returns empty string. But when parameter is not specified it's working
* 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
);
}
}
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