Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
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
PSDI Army
yii2
Commits
879b494a
Commit
879b494a
authored
Jun 07, 2013
by
Gevik Babakhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed custom pgsql PDO and added defaultSchema as public property.
parent
8b61ab7f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
115 deletions
+5
-115
Connection.php
framework/yii/db/Connection.php
+0
-2
PDO.php
framework/yii/db/pgsql/PDO.php
+0
-103
Schema.php
framework/yii/db/pgsql/Schema.php
+5
-10
No files found.
framework/yii/db/Connection.php
View file @
879b494a
...
...
@@ -343,8 +343,6 @@ class Connection extends Component
$driver
=
strtolower
(
substr
(
$this
->
dsn
,
0
,
$pos
));
if
(
$driver
===
'mssql'
||
$driver
===
'dblib'
||
$driver
===
'sqlsrv'
)
{
$pdoClass
=
'yii\db\mssql\PDO'
;
}
else
if
(
$driver
===
'pgsql'
)
{
$pdoClass
=
'yii\db\pgsql\PDO'
;
}
}
return
new
$pdoClass
(
$this
->
dsn
,
$this
->
username
,
$this
->
password
,
$this
->
attributes
);
...
...
framework/yii/db/pgsql/PDO.php
deleted
100644 → 0
View file @
8b61ab7f
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\db\pgsql
;
/**
* This is an extension of the default PDO class for PostgreSQL drivers.
* It provides additional low level functionality for setting database
* configuration parameters.
*
* @author Gevik babakhani <gevikb@gmail.com>
* @since 2.0
*/
class
PDO
extends
\PDO
{
const
OPT_SEARCH_PATH
=
'search_path'
;
const
OPT_DEFAULT_SCHEMA
=
'default_schema'
;
const
DEFAULT_SCHEMA
=
'public'
;
private
$_currentDatabase
;
/**
* 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
)
{
if
(
$sequence
!==
null
)
{
$sequence
=
$this
->
quote
(
$sequence
);
return
$this
->
query
(
"SELECT currval(
{
$sequence
}
)"
)
->
fetchColumn
();
}
else
{
return
null
;
}
}
/**
* Here we override the default PDO constructor in order to
* find and set the default schema search path.
*/
public
function
__construct
(
$dsn
,
$username
,
$passwd
,
$options
)
{
$searchPath
=
null
;
if
(
is_array
(
$options
))
{
if
(
isset
(
$options
[
self
::
OPT_SEARCH_PATH
]))
{
$matches
=
null
;
if
(
preg_match
(
"/(\s?)+(\w)+((\s+)?,(\s+)?\w+)*/"
,
$options
[
self
::
OPT_SEARCH_PATH
],
$matches
)
===
1
)
{
$searchPath
=
$matches
[
0
];
}
}
if
(
isset
(
$options
[
self
::
OPT_DEFAULT_SCHEMA
]))
{
$schema
=
trim
(
$options
[
self
::
OPT_DEFAULT_SCHEMA
]);
if
(
!
empty
(
$schema
))
{
Schema
::
$DEFAULT_SCHEMA
=
$schema
;
}
}
if
(
is_null
(
Schema
::
$DEFAULT_SCHEMA
)
||
empty
(
Schema
::
$DEFAULT_SCHEMA
))
{
Schema
::
$DEFAULT_SCHEMA
=
self
::
DEFAULT_SCHEMA
;
}
}
parent
::
__construct
(
$dsn
,
$username
,
$passwd
,
$options
);
if
(
!
is_null
(
$searchPath
))
{
$this
->
setSchemaSearchPath
(
$searchPath
);
}
}
/**
* Returns the name of the current (connected) database
* @return string
*/
public
function
getCurrentDatabase
()
{
if
(
is_null
(
$this
->
_currentDatabase
))
{
return
$this
->
query
(
'select current_database()'
)
->
fetchColumn
();
}
}
/**
* Sets the schema search path of the current users session.
* The syntax of the path is a comma separated string with
* your custom search path at the beginning and the "public"
* schema at the end.
*
* This method automatically adds the "public" schema at the
* end of the search path if it is not provied.
* @param string custom schema search path. defaults to public
*/
public
function
setSchemaSearchPath
(
$searchPath
=
'public'
)
{
$schemas
=
explode
(
','
,
str_replace
(
' '
,
''
,
$searchPath
));
if
(
end
(
$schemas
)
!==
'public'
)
{
$schemas
[]
=
'public'
;
}
foreach
(
$schemas
as
$k
=>
$item
)
{
$schemas
[
$k
]
=
'"'
.
str_replace
(
array
(
'"'
,
"'"
,
';'
),
''
,
$item
)
.
'"'
;
}
$path
=
implode
(
', '
,
$schemas
);
$this
->
exec
(
'SET search_path TO '
.
$path
);
}
}
framework/yii/db/pgsql/Schema.php
View file @
879b494a
...
...
@@ -22,11 +22,10 @@ class Schema extends \yii\db\Schema
{
/**
* The default schema used for the current session. This value is
* automatically set to "public" by the PDO driver.
* The default schema used for the current session.
* @var string
*/
public
static
$DEFAULT_SCHEMA
;
public
$defaultSchema
=
'public'
;
/**
* @var array mapping from physical column types (keys) to abstract
...
...
@@ -95,10 +94,10 @@ class Schema extends \yii\db\Schema
$table
->
name
=
$parts
[
0
];
}
if
(
$table
->
schemaName
===
null
)
{
$table
->
schemaName
=
self
::
$DEFAULT_SCHEMA
;
$table
->
schemaName
=
$this
->
defaultSchema
;
}
}
/**
* Quotes a table name for use in a query.
* A simple table name has no schema prefix.
...
...
@@ -122,7 +121,7 @@ class Schema extends \yii\db\Schema
return
$table
;
}
}
/**
* Collects the foreign key column details for the given table.
* @param TableSchema $table the table metadata
...
...
@@ -131,7 +130,6 @@ class Schema extends \yii\db\Schema
$tableName
=
$this
->
quoteValue
(
$table
->
name
);
$tableSchema
=
$this
->
quoteValue
(
$table
->
schemaName
);
$database
=
$this
->
quoteValue
(
$this
->
db
->
pdo
->
getCurrentDatabase
());
//We need to extract the constraints de hard way since:
//http://www.postgresql.org/message-id/26677.1086673982@sss.pgh.pa.us
...
...
@@ -158,7 +156,6 @@ where
ct.contype='f'
and c.relname={$tableName}
and ns.nspname={$tableSchema}
and current_database() = {$database}
SQL;
try
{
...
...
@@ -184,7 +181,6 @@ SQL;
* @return boolean whether the table exists in the database
*/
protected
function
findColumns
(
$table
)
{
$dbname
=
$this
->
db
->
quoteValue
(
$this
->
db
->
pdo
->
getCurrentDatabase
());
$tableName
=
$this
->
db
->
quoteValue
(
$table
->
name
);
$schemaName
=
$this
->
db
->
quoteValue
(
$table
->
schemaName
);
$sql
=
<<<SQL
...
...
@@ -239,7 +235,6 @@ WHERE
a.attnum > 0
and c.relname = {$tableName}
and d.nspname = {$schemaName}
and current_database() = {$dbname}
ORDER BY
a.attnum;
SQL;
...
...
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