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
4ba05468
Commit
4ba05468
authored
Dec 25, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
a9439e90
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
60 additions
and
66 deletions
+60
-66
ColumnSchema.php
framework/db/dao/ColumnSchema.php
+1
-1
Command.php
framework/db/dao/Command.php
+4
-7
Connection.php
framework/db/dao/Connection.php
+1
-2
Query.php
framework/db/dao/Query.php
+4
-0
QueryBuilder.php
framework/db/dao/QueryBuilder.php
+2
-15
Schema.php
framework/db/dao/Schema.php
+19
-3
TableSchema.php
framework/db/dao/TableSchema.php
+0
-10
Transaction.php
framework/db/dao/Transaction.php
+1
-2
QueryBuilder.php
framework/db/dao/mysql/QueryBuilder.php
+16
-16
Schema.php
framework/db/dao/mysql/Schema.php
+6
-4
mysql.sql
tests/unit/data/mysql.sql
+6
-6
CommandTest.php
tests/unit/framework/db/dao/CommandTest.php
+0
-0
No files found.
framework/db/dao/ColumnSchema.php
View file @
4ba05468
...
@@ -32,7 +32,7 @@ class ColumnSchema extends \yii\base\Component
...
@@ -32,7 +32,7 @@ class ColumnSchema extends \yii\base\Component
public
$allowNull
;
public
$allowNull
;
/**
/**
* @var string logical type of this column. Possible logic types include:
* @var string logical type of this column. Possible logic types include:
* string, text, boolean, smallint, integer, bigint, float, decimal, datetime, timestamp, time, date, binary
* string, text, boolean, smallint, integer, bigint, float, decimal, datetime, timestamp, time, date, binary
, money
*/
*/
public
$type
;
public
$type
;
/**
/**
...
...
framework/db/dao/Command.php
View file @
4ba05468
...
@@ -163,8 +163,7 @@ class Command extends \yii\base\Component
...
@@ -163,8 +163,7 @@ class Command extends \yii\base\Component
$sql
=
$this
->
getSql
();
$sql
=
$this
->
getSql
();
try
{
try
{
$this
->
pdoStatement
=
$this
->
connection
->
pdo
->
prepare
(
$sql
);
$this
->
pdoStatement
=
$this
->
connection
->
pdo
->
prepare
(
$sql
);
}
}
catch
(
\Exception
$e
)
{
catch
(
\Exception
$e
)
{
\Yii
::
error
(
$e
->
getMessage
()
.
"
\n
Failed to prepare SQL:
$sql
"
,
__CLASS__
);
\Yii
::
error
(
$e
->
getMessage
()
.
"
\n
Failed to prepare SQL:
$sql
"
,
__CLASS__
);
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
throw
new
Exception
(
$e
->
getMessage
(),
(
int
)
$e
->
getCode
(),
$errorInfo
);
throw
new
Exception
(
$e
->
getMessage
(),
(
int
)
$e
->
getCode
(),
$errorInfo
);
...
@@ -289,8 +288,7 @@ class Command extends \yii\base\Component
...
@@ -289,8 +288,7 @@ class Command extends \yii\base\Component
\Yii
::
endProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS__
);
\Yii
::
endProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS__
);
}
}
return
$n
;
return
$n
;
}
}
catch
(
\Exception
$e
)
{
catch
(
Exception
$e
)
{
if
(
$this
->
connection
->
enableProfiling
)
{
if
(
$this
->
connection
->
enableProfiling
)
{
\Yii
::
endProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS__
);
\Yii
::
endProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS__
);
}
}
...
@@ -360,7 +358,7 @@ class Command extends \yii\base\Component
...
@@ -360,7 +358,7 @@ class Command extends \yii\base\Component
*/
*/
public
function
queryScalar
(
$params
=
array
())
public
function
queryScalar
(
$params
=
array
())
{
{
$result
=
$this
->
queryInternal
(
'fetchColumn'
,
$params
);
$result
=
$this
->
queryInternal
(
'fetchColumn'
,
$params
,
0
);
if
(
is_resource
(
$result
)
&&
get_resource_type
(
$result
)
===
'stream'
)
{
if
(
is_resource
(
$result
)
&&
get_resource_type
(
$result
)
===
'stream'
)
{
return
stream_get_contents
(
$result
);
return
stream_get_contents
(
$result
);
}
else
{
}
else
{
...
@@ -452,8 +450,7 @@ class Command extends \yii\base\Component
...
@@ -452,8 +450,7 @@ class Command extends \yii\base\Component
}
}
return
$result
;
return
$result
;
}
}
catch
(
\Exception
$e
)
{
catch
(
Exception
$e
)
{
if
(
$db
->
enableProfiling
)
{
if
(
$db
->
enableProfiling
)
{
\Yii
::
endProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS__
);
\Yii
::
endProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS__
);
}
}
...
...
framework/db/dao/Connection.php
View file @
4ba05468
...
@@ -61,8 +61,7 @@ use yii\db\Exception;
...
@@ -61,8 +61,7 @@ use yii\db\Exception;
* $connection->createCommand($sql2)->execute();
* $connection->createCommand($sql2)->execute();
* // ... executing other SQL statements ...
* // ... executing other SQL statements ...
* $transaction->commit();
* $transaction->commit();
* }
* } catch(Exception $e) {
* catch(Exception $e) {
* $transaction->rollBack();
* $transaction->rollBack();
* }
* }
* ~~~
* ~~~
...
...
framework/db/dao/Query.php
View file @
4ba05468
...
@@ -77,6 +77,10 @@ class Query extends \yii\base\Object
...
@@ -77,6 +77,10 @@ class Query extends \yii\base\Object
public
$union
;
public
$union
;
/**
* @param Connection $connection
* @return string
*/
public
function
getSql
(
$connection
)
public
function
getSql
(
$connection
)
{
{
return
$connection
->
getQueryBuilder
()
->
build
(
$this
);
return
$connection
->
getQueryBuilder
()
->
build
(
$this
);
...
...
framework/db/dao/QueryBuilder.php
View file @
4ba05468
...
@@ -22,22 +22,9 @@ class QueryBuilder extends \yii\base\Object
...
@@ -22,22 +22,9 @@ class QueryBuilder extends \yii\base\Object
{
{
/**
/**
* @var array the abstract column types mapped to physical column types.
* @var array the abstract column types mapped to physical column types.
* Child classes should override this property to declare possible type mappings.
*/
*/
public
$typeMap
=
array
(
public
$typeMap
=
array
();
'pk'
=>
'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'
,
'string'
=>
'varchar(255)'
,
'text'
=>
'text'
,
'integer'
=>
'int(11)'
,
'float'
=>
'float'
,
'decimal'
=>
'decimal'
,
'datetime'
=>
'datetime'
,
'timestamp'
=>
'timestamp'
,
'time'
=>
'time'
,
'date'
=>
'date'
,
'binary'
=>
'blob'
,
'boolean'
=>
'tinyint(1)'
,
'money'
=>
'decimal(19,4)'
,
);
/**
/**
* @var Connection the database connection.
* @var Connection the database connection.
*/
*/
...
...
framework/db/dao/Schema.php
View file @
4ba05468
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
...
@@ -20,6 +20,22 @@ use yii\db\Exception;
...
@@ -20,6 +20,22 @@ use yii\db\Exception;
*/
*/
abstract
class
Schema
extends
\yii\base\Object
abstract
class
Schema
extends
\yii\base\Object
{
{
const
TYPE_PK
=
'pk'
;
const
TYPE_STRING
=
'string'
;
const
TYPE_TEXT
=
'text'
;
const
TYPE_SMALLINT
=
'smallint'
;
const
TYPE_INTEGER
=
'integer'
;
const
TYPE_BIGINT
=
'bigint'
;
const
TYPE_FLOAT
=
'float'
;
const
TYPE_DECIMAL
=
'decimal'
;
const
TYPE_DATETIME
=
'datetime'
;
const
TYPE_TIMESTAMP
=
'timestamp'
;
const
TYPE_TIME
=
'time'
;
const
TYPE_DATE
=
'date'
;
const
TYPE_BINARY
=
'binary'
;
const
TYPE_BOOLEAN
=
'boolean'
;
const
TYPE_MONEY
=
'money'
;
/**
/**
* @var \yii\db\dao\Connection the database connection
* @var \yii\db\dao\Connection the database connection
*/
*/
...
@@ -38,7 +54,7 @@ abstract class Schema extends \yii\base\Object
...
@@ -38,7 +54,7 @@ abstract class Schema extends \yii\base\Object
/**
/**
* Constructor.
* Constructor.
* @param C
DbC
onnection $connection database connection.
* @param Connection $connection database connection.
*/
*/
public
function
__construct
(
$connection
)
public
function
__construct
(
$connection
)
{
{
...
@@ -48,7 +64,7 @@ abstract class Schema extends \yii\base\Object
...
@@ -48,7 +64,7 @@ abstract class Schema extends \yii\base\Object
/**
/**
* Obtains the metadata for the named table.
* Obtains the metadata for the named table.
* @param string $name table name. The table name may contain schema name if any. Do not quote the table name.
* @param string $name table name. The table name may contain schema name if any. Do not quote the table name.
* @return
CDb
TableSchema table metadata. Null if the named table does not exist.
* @return TableSchema table metadata. Null if the named table does not exist.
*/
*/
public
function
getTableSchema
(
$name
)
public
function
getTableSchema
(
$name
)
{
{
...
...
framework/db/dao/TableSchema.php
View file @
4ba05468
...
@@ -15,16 +15,6 @@ namespace yii\db\dao;
...
@@ -15,16 +15,6 @@ namespace yii\db\dao;
*
*
* It may be extended by different DBMS driver to provide DBMS-specific table metadata.
* It may be extended by different DBMS driver to provide DBMS-specific table metadata.
*
*
* TableSchema provides the following information about a table:
* <ul>
* <li>{@link name}</li>
* <li>{@link rawName}</li>
* <li>{@link columns}</li>
* <li>{@link primaryKey}</li>
* <li>{@link foreignKeys}</li>
* <li>{@link sequenceName}</li>
* </ul>
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
...
...
framework/db/dao/Transaction.php
View file @
4ba05468
...
@@ -27,8 +27,7 @@ use yii\db\Exception;
...
@@ -27,8 +27,7 @@ use yii\db\Exception;
* $connection->createCommand($sql2)->execute();
* $connection->createCommand($sql2)->execute();
* //.... other SQL executions
* //.... other SQL executions
* $transaction->commit();
* $transaction->commit();
* }
* } catch(Exception $e) {
* catch(Exception $e) {
* $transaction->rollBack();
* $transaction->rollBack();
* }
* }
* ~~~
* ~~~
...
...
framework/db/dao/mysql/QueryBuilder.php
View file @
4ba05468
...
@@ -21,22 +21,22 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
...
@@ -21,22 +21,22 @@ class QueryBuilder extends \yii\db\dao\QueryBuilder
/**
/**
* @var array the abstract column types mapped to physical column types.
* @var array the abstract column types mapped to physical column types.
*/
*/
public
$
columnTypes
=
array
(
public
$
typeMap
=
array
(
'pk'
=>
'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'
,
Schema
::
TYPE_PK
=>
'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'
,
'string'
=>
'varchar(255)'
,
Schema
::
TYPE_STRING
=>
'varchar(255)'
,
'text'
=>
'text'
,
Schema
::
TYPE_TEXT
=>
'text'
,
'smallint'
=>
'smallint
'
,
Schema
::
TYPE_SMALLINT
=>
'smallint(6)
'
,
'integer'
=>
'int(11)'
,
Schema
::
TYPE_INTEGER
=>
'int(11)'
,
'bigint'
=>
'bigint
'
,
Schema
::
TYPE_BIGINT
=>
'bigint(20)
'
,
'boolean'
=>
'tinyint(1)
'
,
Schema
::
TYPE_FLOAT
=>
'float
'
,
'float'
=>
'float
'
,
Schema
::
TYPE_DECIMAL
=>
'decimal
'
,
'decimal'
=>
'decimal
'
,
Schema
::
TYPE_DATETIME
=>
'datetime
'
,
'money'
=>
'decimal(19,4)
'
,
Schema
::
TYPE_TIMESTAMP
=>
'timestamp
'
,
'datetime'
=>
'date
time'
,
Schema
::
TYPE_TIME
=>
'
time'
,
'timestamp'
=>
'timestamp
'
,
Schema
::
TYPE_DATE
=>
'date
'
,
'time'
=>
'time
'
,
Schema
::
TYPE_BINARY
=>
'blob
'
,
'date'
=>
'date
'
,
Schema
::
TYPE_BOOLEAN
=>
'tinyint(1)
'
,
'binary'
=>
'blob
'
,
Schema
::
TYPE_MONEY
=>
'decimal(19,4)
'
,
);
);
/**
/**
...
...
framework/db/dao/mysql/Schema.php
View file @
4ba05468
...
@@ -10,6 +10,8 @@
...
@@ -10,6 +10,8 @@
namespace
yii\db\dao\mysql
;
namespace
yii\db\dao\mysql
;
use
yii\db\dao\TableSchema
;
/**
/**
* Schema is the class for retrieving metadata information from a MySQL database (version 4.1.x and 5.x).
* Schema is the class for retrieving metadata information from a MySQL database (version 4.1.x and 5.x).
*
*
...
@@ -43,7 +45,7 @@ class Schema extends \yii\db\dao\Schema
...
@@ -43,7 +45,7 @@ class Schema extends \yii\db\dao\Schema
/**
/**
* Loads the metadata for the specified table.
* Loads the metadata for the specified table.
* @param string $name table name
* @param string $name table name
* @return TableSchema driver dependent table metadata. Null if the table does not exist.
* @return
\yii\db\dao\
TableSchema driver dependent table metadata. Null if the table does not exist.
*/
*/
protected
function
loadTableSchema
(
$name
)
protected
function
loadTableSchema
(
$name
)
{
{
...
@@ -58,7 +60,7 @@ class Schema extends \yii\db\dao\Schema
...
@@ -58,7 +60,7 @@ class Schema extends \yii\db\dao\Schema
/**
/**
* Generates various kinds of table names.
* Generates various kinds of table names.
* @param
CMysql
TableSchema $table the table instance
* @param
\yii\db\dao\
TableSchema $table the table instance
* @param string $name the unquoted table name
* @param string $name the unquoted table name
*/
*/
protected
function
resolveTableNames
(
$table
,
$name
)
protected
function
resolveTableNames
(
$table
,
$name
)
...
@@ -96,7 +98,7 @@ class Schema extends \yii\db\dao\Schema
...
@@ -96,7 +98,7 @@ class Schema extends \yii\db\dao\Schema
/**
/**
* Collects the table column metadata.
* Collects the table column metadata.
* @param
CMysql
TableSchema $table the table metadata
* @param
\yii\db\dao\
TableSchema $table the table metadata
* @return boolean whether the table exists in the database
* @return boolean whether the table exists in the database
*/
*/
protected
function
findColumns
(
$table
)
protected
function
findColumns
(
$table
)
...
@@ -128,7 +130,7 @@ class Schema extends \yii\db\dao\Schema
...
@@ -128,7 +130,7 @@ class Schema extends \yii\db\dao\Schema
/**
/**
* Collects the foreign key column details for the given table.
* Collects the foreign key column details for the given table.
* @param
CMysql
TableSchema $table the table metadata
* @param
\yii\db\dao\
TableSchema $table the table metadata
*/
*/
protected
function
findConstraints
(
$table
)
protected
function
findConstraints
(
$table
)
{
{
...
...
tests/unit/data/mysql.sql
View file @
4ba05468
...
@@ -43,18 +43,18 @@ CREATE TABLE yii_post
...
@@ -43,18 +43,18 @@ CREATE TABLE yii_post
(
(
id
INTEGER
NOT
NULL
PRIMARY
KEY
AUTO_INCREMENT
,
id
INTEGER
NOT
NULL
PRIMARY
KEY
AUTO_INCREMENT
,
title
VARCHAR
(
128
)
NOT
NULL
,
title
VARCHAR
(
128
)
NOT
NULL
,
create_time
TIMESTAMP
NOT
NULL
,
create_time
INTEGER
NOT
NULL
,
author_id
INTEGER
NOT
NULL
,
author_id
INTEGER
NOT
NULL
,
content
TEXT
,
content
TEXT
,
CONSTRAINT
FK_post_author
FOREIGN
KEY
(
author_id
)
CONSTRAINT
FK_post_author
FOREIGN
KEY
(
author_id
)
REFERENCES
yii_user
(
id
)
ON
DELETE
CASCADE
ON
UPDATE
RESTRICT
REFERENCES
yii_user
(
id
)
ON
DELETE
CASCADE
ON
UPDATE
RESTRICT
)
TYPE
=
INNODB
;
)
TYPE
=
INNODB
;
INSERT
INTO
yii_post
(
title
,
create_time
,
author_id
,
content
)
VALUES
(
'post 1'
,
'
2000-01-01
'
,
1
,
'content 1'
);
INSERT
INTO
yii_post
(
title
,
create_time
,
author_id
,
content
)
VALUES
(
'post 1'
,
'
1324854194
'
,
1
,
'content 1'
);
INSERT
INTO
yii_post
(
title
,
create_time
,
author_id
,
content
)
VALUES
(
'post 2'
,
'
2000-01-02
'
,
2
,
'content 2'
);
INSERT
INTO
yii_post
(
title
,
create_time
,
author_id
,
content
)
VALUES
(
'post 2'
,
'
1324855194
'
,
2
,
'content 2'
);
INSERT
INTO
yii_post
(
title
,
create_time
,
author_id
,
content
)
VALUES
(
'post 3'
,
'
2000-01-03
'
,
2
,
'content 3'
);
INSERT
INTO
yii_post
(
title
,
create_time
,
author_id
,
content
)
VALUES
(
'post 3'
,
'
1324856194
'
,
2
,
'content 3'
);
INSERT
INTO
yii_post
(
title
,
create_time
,
author_id
,
content
)
VALUES
(
'post 4'
,
'
2000-01-0
4'
,
2
,
'content 4'
);
INSERT
INTO
yii_post
(
title
,
create_time
,
author_id
,
content
)
VALUES
(
'post 4'
,
'
132485719
4'
,
2
,
'content 4'
);
INSERT
INTO
yii_post
(
title
,
create_time
,
author_id
,
content
)
VALUES
(
'post 5'
,
'
2000-01-05
'
,
3
,
'content 5'
);
INSERT
INTO
yii_post
(
title
,
create_time
,
author_id
,
content
)
VALUES
(
'post 5'
,
'
1324858194
'
,
3
,
'content 5'
);
CREATE
TABLE
yii_comment
CREATE
TABLE
yii_comment
(
(
...
...
tests/unit/framework/db/dao/CommandTest.php
View file @
4ba05468
This diff is collapsed.
Click to expand it.
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