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
1dd651df
Commit
1dd651df
authored
Dec 27, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
3301b9d6
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
111 deletions
+14
-111
Driver.php
framework/db/dao/Driver.php
+1
-0
ColumnSchema.php
framework/db/dao/mysql/ColumnSchema.php
+0
-108
Driver.php
framework/db/dao/mysql/Driver.php
+11
-1
QueryBuilder.php
framework/db/dao/mysql/QueryBuilder.php
+2
-2
No files found.
framework/db/dao/Driver.php
View file @
1dd651df
...
@@ -29,6 +29,7 @@ abstract class Driver extends \yii\base\Object
...
@@ -29,6 +29,7 @@ abstract class Driver extends \yii\base\Object
/**
/**
* The followings are the supported abstract column data types.
* The followings are the supported abstract column data types.
*/
*/
const
TYPE_PK
=
'pk'
;
const
TYPE_STRING
=
'string'
;
const
TYPE_STRING
=
'string'
;
const
TYPE_TEXT
=
'text'
;
const
TYPE_TEXT
=
'text'
;
const
TYPE_SMALLINT
=
'smallint'
;
const
TYPE_SMALLINT
=
'smallint'
;
...
...
framework/db/dao/mysql/ColumnSchema.php
deleted
100644 → 0
View file @
3301b9d6
<?php
/**
* ColumnSchema class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\db\dao\mysql
;
/**
* ColumnSchema class describes the meta data of a MySQL table column.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
ColumnSchema
extends
\yii\db\dao\ColumnSchema
{
/**
* Extracts the PHP type from DB type.
* @param string $dbType DB type
*/
public
function
initTypes
(
$dbType
)
{
static
$typeMap
=
array
(
// dbType => type
'tinyint'
=>
self
::
TYPE_SMALLINT
,
'bit'
=>
self
::
TYPE_SMALLINT
,
'smallint'
=>
self
::
TYPE_SMALLINT
,
'mediumint'
=>
self
::
TYPE_INTEGER
,
'int'
=>
self
::
TYPE_INTEGER
,
'integer'
=>
self
::
TYPE_INTEGER
,
'bigint'
=>
self
::
TYPE_BIGINT
,
'float'
=>
self
::
TYPE_FLOAT
,
'double'
=>
self
::
TYPE_FLOAT
,
'real'
=>
self
::
TYPE_FLOAT
,
'decimal'
=>
self
::
TYPE_DECIMAL
,
'numeric'
=>
self
::
TYPE_DECIMAL
,
'tinytext'
=>
self
::
TYPE_TEXT
,
'mediumtext'
=>
self
::
TYPE_TEXT
,
'longtext'
=>
self
::
TYPE_TEXT
,
'text'
=>
self
::
TYPE_TEXT
,
'varchar'
=>
self
::
TYPE_STRING
,
'string'
=>
self
::
TYPE_STRING
,
'char'
=>
self
::
TYPE_STRING
,
'datetime'
=>
self
::
TYPE_DATETIME
,
'year'
=>
self
::
TYPE_DATE
,
'date'
=>
self
::
TYPE_DATE
,
'time'
=>
self
::
TYPE_TIME
,
'timestamp'
=>
self
::
TYPE_TIMESTAMP
,
'enum'
=>
self
::
TYPE_STRING
,
);
$this
->
dbType
=
$dbType
;
$this
->
type
=
self
::
TYPE_STRING
;
$this
->
unsigned
=
strpos
(
$this
->
dbType
,
'unsigned'
)
!==
false
;
if
(
preg_match
(
'/^(\w+)(?:\(([^\)]+)\))?/'
,
$this
->
dbType
,
$matches
))
{
$type
=
$matches
[
1
];
if
(
isset
(
$typeMap
[
$type
]))
{
$this
->
type
=
$typeMap
[
$type
];
}
if
(
!
empty
(
$matches
[
2
]))
{
if
(
$type
===
'enum'
)
{
$values
=
explode
(
','
,
$matches
[
2
]);
foreach
(
$values
as
$i
=>
$value
)
{
$values
[
$i
]
=
trim
(
$value
,
"'"
);
}
$this
->
enumValues
=
$values
;
}
else
{
$values
=
explode
(
','
,
$matches
[
2
]);
$this
->
size
=
$this
->
precision
=
(
int
)
$values
[
0
];
if
(
isset
(
$values
[
1
]))
{
$this
->
scale
=
(
int
)
$values
[
1
];
}
if
(
$this
->
size
===
1
&&
(
$type
===
'tinyint'
||
$type
===
'bit'
))
{
$this
->
type
=
'boolean'
;
}
elseif
(
$type
===
'bit'
)
{
if
(
$this
->
size
>
32
)
{
$this
->
type
=
'bigint'
;
}
elseif
(
$this
->
size
===
32
)
{
$this
->
type
=
'integer'
;
}
}
}
}
}
$this
->
phpType
=
$this
->
extractPhpType
();
}
/**
* Extracts the default value for the column.
* The value is typecast to correct PHP type.
* @param mixed $defaultValue the default value obtained from metadata
*/
public
function
initDefaultValue
(
$defaultValue
)
{
if
(
$this
->
type
===
'timestamp'
&&
$defaultValue
===
'CURRENT_TIMESTAMP'
)
{
$this
->
defaultValue
=
null
;
}
else
{
$this
->
defaultValue
=
$this
->
typecast
(
$defaultValue
);
}
}
}
\ No newline at end of file
framework/db/dao/mysql/Driver.php
View file @
1dd651df
...
@@ -22,7 +22,7 @@ use yii\db\dao\ColumnSchema;
...
@@ -22,7 +22,7 @@ use yii\db\dao\ColumnSchema;
class
Driver
extends
\yii\db\dao\Driver
class
Driver
extends
\yii\db\dao\Driver
{
{
/**
/**
* @var array mapping from physical
types (keys) to abstract
types (values)
* @var array mapping from physical
column types (keys) to abstract column
types (values)
*/
*/
public
$typeMap
=
array
(
// dbType => type
public
$typeMap
=
array
(
// dbType => type
'tinyint'
=>
self
::
TYPE_SMALLINT
,
'tinyint'
=>
self
::
TYPE_SMALLINT
,
...
@@ -260,4 +260,14 @@ class Driver extends \yii\db\dao\Driver
...
@@ -260,4 +260,14 @@ class Driver extends \yii\db\dao\Driver
}
}
return
$names
;
return
$names
;
}
}
/**
* Creates a query builder for the database.
* This method may be overridden by child classes to create a DBMS-specific query builder.
* @return QueryBuilder query builder instance
*/
public
function
createQueryBuilder
()
{
return
new
QueryBuilder
(
$this
->
connection
);
}
}
}
framework/db/dao/mysql/QueryBuilder.php
View file @
1dd651df
...
@@ -19,10 +19,10 @@ namespace yii\db\dao\mysql;
...
@@ -19,10 +19,10 @@ namespace yii\db\dao\mysql;
class
QueryBuilder
extends
\yii\db\dao\QueryBuilder
class
QueryBuilder
extends
\yii\db\dao\QueryBuilder
{
{
/**
/**
* @var array
the abstract column types mapped to physical column types
.
* @var array
mapping from abstract column types (keys) to physical column types (values)
.
*/
*/
public
$typeMap
=
array
(
public
$typeMap
=
array
(
'pk'
=>
'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'
,
Driver
::
TYPE_PK
=>
'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'
,
Driver
::
TYPE_STRING
=>
'varchar(255)'
,
Driver
::
TYPE_STRING
=>
'varchar(255)'
,
Driver
::
TYPE_TEXT
=>
'text'
,
Driver
::
TYPE_TEXT
=>
'text'
,
Driver
::
TYPE_SMALLINT
=>
'smallint(6)'
,
Driver
::
TYPE_SMALLINT
=>
'smallint(6)'
,
...
...
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