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
9b723baa
Commit
9b723baa
authored
Jan 16, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added `TableSchema::fullName` property
parent
e13557d3
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
81 additions
and
79 deletions
+81
-79
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Connection.php
framework/db/Connection.php
+3
-3
Schema.php
framework/db/Schema.php
+4
-0
TableSchema.php
framework/db/TableSchema.php
+9
-2
Schema.php
framework/db/cubrid/Schema.php
+32
-32
Schema.php
framework/db/mssql/Schema.php
+10
-9
Schema.php
framework/db/mysql/Schema.php
+2
-1
Schema.php
framework/db/oci/Schema.php
+13
-23
Schema.php
framework/db/pgsql/Schema.php
+5
-7
Schema.php
framework/db/sqlite/Schema.php
+2
-2
No files found.
framework/CHANGELOG.md
View file @
9b723baa
...
...
@@ -78,6 +78,7 @@ Yii Framework 2 Change Log
-
Enh: Added support for installing packages conforming to PSR-4 standard (qiangxue)
-
Enh: Better exception message when class cannot be loaded (samdark)
-
Enh:
`init`
of advanced application now allows to specify answer for overwriting files via
`init --overwrite=n`
(samdark)
-
Enh: Added
`TableSchema::fullName`
property (qiangxue)
-
Enh #1839: Added support for getting file extension and basename from uploaded file (anfrantic)
-
Chg #1519:
`yii\web\User::loginRequired()`
now returns the
`Response`
object instead of exiting the application (qiangxue)
-
Chg #1586:
`QueryBuilder::buildLikeCondition()`
will now escape special characters and use percentage characters by default (qiangxue)
...
...
framework/db/Connection.php
View file @
9b723baa
...
...
@@ -423,9 +423,9 @@ class Connection extends Component
}
else
{
$driver
=
$this
->
getDriverName
();
if
(
isset
(
$this
->
schemaMap
[
$driver
]))
{
$
this
->
_schema
=
Yii
::
createObject
(
$this
->
schemaMap
[
$driver
])
;
$
this
->
_schema
->
db
=
$this
;
return
$this
->
_schema
;
$
config
=
!
is_array
(
$this
->
schemaMap
[
$driver
])
?
[
'class'
=>
$this
->
schemaMap
[
$driver
]]
:
$this
->
schemaMap
[
$driver
]
;
$
config
[
'db'
]
=
$this
;
return
$this
->
_schema
=
Yii
::
createObject
(
$config
)
;
}
else
{
throw
new
NotSupportedException
(
"Connection does not support reading schema information for '
$driver
' DBMS."
);
}
...
...
framework/db/Schema.php
View file @
9b723baa
...
...
@@ -56,6 +56,10 @@ abstract class Schema extends Object
*/
public
$db
;
/**
* @var string the default schema name used for the current session.
*/
public
$defaultSchema
;
/**
* @var array list of ALL table names in the database
*/
private
$_tableNames
=
[];
...
...
framework/db/TableSchema.php
View file @
9b723baa
...
...
@@ -21,14 +21,20 @@ use yii\base\InvalidParamException;
class
TableSchema
extends
Object
{
/**
* @var string name of the schema that this table belongs to.
* @var string
the
name of the schema that this table belongs to.
*/
public
$schemaName
;
/**
* @var string
name of this table
.
* @var string
the name of this table. The schema name is not included. Use [[fullName]] to get the name with schema name prefix
.
*/
public
$name
;
/**
* @var string the full name of this table, which includes the schema name prefix, if any.
* Note that if the schema name is the same as the [[Schema::defaultSchema|default schema name]],
* the schema name will not be included.
*/
public
$fullName
;
/**
* @var string[] primary keys of this table.
*/
public
$primaryKey
=
[];
...
...
@@ -53,6 +59,7 @@ class TableSchema extends Object
*/
public
$columns
=
[];
/**
* Gets the named column metadata.
* This is a convenient method for retrieving a named column even if it does not exist.
...
...
framework/db/cubrid/Schema.php
View file @
9b723baa
...
...
@@ -128,45 +128,45 @@ class Schema extends \yii\db\Schema
$this
->
db
->
open
();
$tableInfo
=
$this
->
db
->
pdo
->
cubrid_schema
(
\PDO
::
CUBRID_SCH_TABLE
,
$name
);
if
(
isset
(
$tableInfo
[
0
][
'NAME'
]))
{
$table
=
new
TableSchema
()
;
$table
->
name
=
$tableInfo
[
0
][
'NAME'
];
if
(
!
isset
(
$tableInfo
[
0
][
'NAME'
]))
{
return
null
;
}
$sql
=
'SHOW FULL COLUMNS FROM '
.
$this
->
quoteSimpleTableName
(
$table
->
name
);
$columns
=
$this
->
db
->
createCommand
(
$sql
)
->
queryAll
()
;
$table
=
new
TableSchema
(
);
$table
->
fullName
=
$table
->
name
=
$tableInfo
[
0
][
'NAME'
]
;
foreach
(
$columns
as
$info
)
{
$column
=
$this
->
loadColumnSchema
(
$info
);
$table
->
columns
[
$column
->
name
]
=
$column
;
}
$sql
=
'SHOW FULL COLUMNS FROM '
.
$this
->
quoteSimpleTableName
(
$table
->
name
);
$columns
=
$this
->
db
->
createCommand
(
$sql
)
->
queryAll
();
$primaryKeys
=
$this
->
db
->
pdo
->
cubrid_schema
(
\PDO
::
CUBRID_SCH_PRIMARY_KEY
,
$table
->
name
);
foreach
(
$primaryKeys
as
$key
)
{
$column
=
$table
->
columns
[
$key
[
'ATTR_NAME'
]];
$column
->
isPrimaryKey
=
true
;
$table
->
primaryKey
[]
=
$column
->
name
;
if
(
$column
->
autoIncrement
)
{
$table
->
sequenceName
=
''
;
}
}
foreach
(
$columns
as
$info
)
{
$column
=
$this
->
loadColumnSchema
(
$info
);
$table
->
columns
[
$column
->
name
]
=
$column
;
}
$foreignKeys
=
$this
->
db
->
pdo
->
cubrid_schema
(
\PDO
::
CUBRID_SCH_IMPORTED_KEYS
,
$table
->
name
);
foreach
(
$foreignKeys
as
$key
)
{
if
(
isset
(
$table
->
foreignKeys
[
$key
[
'FK_NAME'
]]))
{
$table
->
foreignKeys
[
$key
[
'FK_NAME'
]][
$key
[
'FKCOLUMN_NAME'
]]
=
$key
[
'PKCOLUMN_NAME'
];
}
else
{
$table
->
foreignKeys
[
$key
[
'FK_NAME'
]]
=
[
$key
[
'PKTABLE_NAME'
],
$key
[
'FKCOLUMN_NAME'
]
=>
$key
[
'PKCOLUMN_NAME'
]
];
}
$primaryKeys
=
$this
->
db
->
pdo
->
cubrid_schema
(
\PDO
::
CUBRID_SCH_PRIMARY_KEY
,
$table
->
name
);
foreach
(
$primaryKeys
as
$key
)
{
$column
=
$table
->
columns
[
$key
[
'ATTR_NAME'
]];
$column
->
isPrimaryKey
=
true
;
$table
->
primaryKey
[]
=
$column
->
name
;
if
(
$column
->
autoIncrement
)
{
$table
->
sequenceName
=
''
;
}
$table
->
foreignKeys
=
array_values
(
$table
->
foreignKeys
);
}
return
$table
;
}
else
{
return
null
;
$foreignKeys
=
$this
->
db
->
pdo
->
cubrid_schema
(
\PDO
::
CUBRID_SCH_IMPORTED_KEYS
,
$table
->
name
);
foreach
(
$foreignKeys
as
$key
)
{
if
(
isset
(
$table
->
foreignKeys
[
$key
[
'FK_NAME'
]]))
{
$table
->
foreignKeys
[
$key
[
'FK_NAME'
]][
$key
[
'FKCOLUMN_NAME'
]]
=
$key
[
'PKCOLUMN_NAME'
];
}
else
{
$table
->
foreignKeys
[
$key
[
'FK_NAME'
]]
=
[
$key
[
'PKTABLE_NAME'
],
$key
[
'FKCOLUMN_NAME'
]
=>
$key
[
'PKCOLUMN_NAME'
]
];
}
}
$table
->
foreignKeys
=
array_values
(
$table
->
foreignKeys
);
return
$table
;
}
/**
...
...
framework/db/mssql/Schema.php
View file @
9b723baa
...
...
@@ -18,15 +18,14 @@ use yii\db\ColumnSchema;
class
Schema
extends
\yii\db\Schema
{
/**
*
Default schema name to be used
.
*
@var string the default schema used for the current session
.
*/
const
DEFAULT_SCHEMA
=
'dbo'
;
public
$defaultSchema
=
'dbo'
;
/**
* @var array mapping from physical column types (keys) to abstract column types (values)
*/
public
$typeMap
=
[
// exact num
eric
s
// exact num
ber
s
'bigint'
=>
self
::
TYPE_BIGINT
,
'numeric'
=>
self
::
TYPE_DECIMAL
,
'bit'
=>
self
::
TYPE_SMALLINT
,
...
...
@@ -37,7 +36,7 @@ class Schema extends \yii\db\Schema
'tinyint'
=>
self
::
TYPE_SMALLINT
,
'money'
=>
self
::
TYPE_MONEY
,
// approximate num
eric
s
// approximate num
ber
s
'float'
=>
self
::
TYPE_FLOAT
,
'real'
=>
self
::
TYPE_FLOAT
,
...
...
@@ -137,14 +136,16 @@ class Schema extends \yii\db\Schema
$table
->
catalogName
=
$parts
[
0
];
$table
->
schemaName
=
$parts
[
1
];
$table
->
name
=
$parts
[
2
];
$table
->
fullName
=
$table
->
catalogName
.
'.'
.
$table
->
schemaName
.
'.'
.
$table
->
name
;
}
elseif
(
$partCount
==
2
)
{
// only schema name and table name passed
$table
->
schemaName
=
$parts
[
0
];
$table
->
name
=
$parts
[
1
];
$table
->
fullName
=
$table
->
schemaName
!==
$this
->
defaultSchema
?
$table
->
schemaName
.
'.'
.
$table
->
name
:
$table
->
name
;
}
else
{
// only
schema
name passed
$table
->
schemaName
=
static
::
DEFAULT_SCHEMA
;
$table
->
name
=
$parts
[
0
];
// only
table
name passed
$table
->
schemaName
=
$this
->
defaultSchema
;
$table
->
fullName
=
$table
->
name
=
$parts
[
0
];
}
}
...
...
@@ -339,7 +340,7 @@ SQL;
protected
function
findTableNames
(
$schema
=
''
)
{
if
(
$schema
===
''
)
{
$schema
=
static
::
DEFAULT_SCHEMA
;
$schema
=
$this
->
defaultSchema
;
}
$sql
=
<<<SQL
...
...
framework/db/mysql/Schema.php
View file @
9b723baa
...
...
@@ -109,8 +109,9 @@ class Schema extends \yii\db\Schema
if
(
isset
(
$parts
[
1
]))
{
$table
->
schemaName
=
$parts
[
0
];
$table
->
name
=
$parts
[
1
];
$table
->
fullName
=
$table
->
schemaName
.
'.'
.
$table
->
name
;
}
else
{
$table
->
name
=
$parts
[
0
];
$table
->
fullName
=
$table
->
name
=
$parts
[
0
];
}
}
...
...
framework/db/oci/Schema.php
View file @
9b723baa
...
...
@@ -15,14 +15,21 @@ use yii\db\ColumnSchema;
*
* @todo mapping from physical types to abstract types
*
* @property string $defaultSchema Default schema.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
Schema
extends
\yii\db\Schema
{
private
$_defaultSchema
;
/**
* @inheritdoc
*/
public
function
init
()
{
parent
::
init
();
if
(
$this
->
defaultSchema
===
null
)
{
$this
->
defaultSchema
=
$this
->
db
->
username
;
}
}
/**
* @inheritdoc
...
...
@@ -77,28 +84,11 @@ class Schema extends \yii\db\Schema
$table
->
schemaName
=
$parts
[
0
];
$table
->
name
=
$parts
[
1
];
}
else
{
$table
->
schemaName
=
$this
->
getDefaultSchema
()
;
$table
->
name
=
$
parts
[
0
]
;
$table
->
schemaName
=
$this
->
defaultSchema
;
$table
->
name
=
$
name
;
}
}
/**
* @return string default schema.
*/
public
function
getDefaultSchema
()
{
if
(
$this
->
_defaultSchema
===
null
)
{
$this
->
setDefaultSchema
(
strtoupper
(
$this
->
db
->
username
));
}
return
$this
->
_defaultSchema
;
}
/**
* @param string $schema default schema.
*/
public
function
setDefaultSchema
(
$schema
)
{
$this
->
_defaultSchema
=
$schema
;
$table
->
fullName
=
$table
->
schemaName
!==
$this
->
defaultSchema
?
$table
->
schemaName
.
'.'
.
$table
->
name
:
$table
->
name
;
}
/**
...
...
framework/db/pgsql/Schema.php
View file @
9b723baa
...
...
@@ -20,13 +20,10 @@ use yii\db\ColumnSchema;
*/
class
Schema
extends
\yii\db\Schema
{
/**
* The default schema used for the current session.
* @var string
* @var string the default schema used for the current session.
*/
public
$defaultSchema
=
'public'
;
/**
* @var array mapping from physical column types (keys) to abstract
* column types (values)
...
...
@@ -92,15 +89,16 @@ class Schema extends \yii\db\Schema
protected
function
resolveTableNames
(
$table
,
$name
)
{
$parts
=
explode
(
'.'
,
str_replace
(
'"'
,
''
,
$name
));
if
(
isset
(
$parts
[
1
]))
{
$table
->
schemaName
=
$parts
[
0
];
$table
->
name
=
$parts
[
1
];
}
else
{
$table
->
name
=
$parts
[
0
];
}
if
(
$table
->
schemaName
===
null
)
{
$table
->
schemaName
=
$this
->
defaultSchema
;
$table
->
name
=
$name
;
}
$table
->
fullName
=
$table
->
schemaName
!==
$this
->
defaultSchema
?
$table
->
schemaName
.
'.'
.
$table
->
name
:
$table
->
name
;
}
/**
...
...
framework/db/sqlite/Schema.php
View file @
9b723baa
...
...
@@ -84,8 +84,7 @@ class Schema extends \yii\db\Schema
/**
* Returns all table names in the database.
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
* If not empty, the returned table names will be prefixed with the schema name.
* @return array all table names in the database.
* @return array all table names in the database. The names have NO schema name prefix.
*/
protected
function
findTableNames
(
$schema
=
''
)
{
...
...
@@ -102,6 +101,7 @@ class Schema extends \yii\db\Schema
{
$table
=
new
TableSchema
;
$table
->
name
=
$name
;
$table
->
fullName
=
$name
;
if
(
$this
->
findColumns
(
$table
))
{
$this
->
findConstraints
(
$table
);
...
...
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