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
20bde29f
Commit
20bde29f
authored
Jul 22, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added typecasting for SQL insertion and update.
parent
ec23b1b4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
3 deletions
+26
-3
ColumnSchema.php
framework/yii/db/ColumnSchema.php
+3
-0
QueryBuilder.php
framework/yii/db/QueryBuilder.php
+13
-2
QueryBuilder.php
framework/yii/db/mysql/QueryBuilder.php
+10
-1
No files found.
framework/yii/db/ColumnSchema.php
View file @
20bde29f
...
@@ -88,6 +88,9 @@ class ColumnSchema extends \yii\base\Component
...
@@ -88,6 +88,9 @@ class ColumnSchema extends \yii\base\Component
if
(
$value
===
null
||
gettype
(
$value
)
===
$this
->
phpType
||
$value
instanceof
Expression
)
{
if
(
$value
===
null
||
gettype
(
$value
)
===
$this
->
phpType
||
$value
instanceof
Expression
)
{
return
$value
;
return
$value
;
}
}
if
(
$value
===
''
&&
$this
->
type
!==
Schema
::
TYPE_TEXT
&&
$this
->
type
!==
Schema
::
TYPE_STRING
)
{
return
null
;
}
switch
(
$this
->
phpType
)
{
switch
(
$this
->
phpType
)
{
case
'string'
:
case
'string'
:
return
(
string
)
$value
;
return
(
string
)
$value
;
...
...
framework/yii/db/QueryBuilder.php
View file @
20bde29f
...
@@ -94,6 +94,11 @@ class QueryBuilder extends \yii\base\Object
...
@@ -94,6 +94,11 @@ class QueryBuilder extends \yii\base\Object
*/
*/
public
function
insert
(
$table
,
$columns
,
&
$params
)
public
function
insert
(
$table
,
$columns
,
&
$params
)
{
{
if
((
$tableSchema
=
$this
->
db
->
getTableSchema
(
$table
))
!==
null
)
{
$columnSchemas
=
$tableSchema
->
columns
;
}
else
{
$columnSchemas
=
array
();
}
$names
=
array
();
$names
=
array
();
$placeholders
=
array
();
$placeholders
=
array
();
foreach
(
$columns
as
$name
=>
$value
)
{
foreach
(
$columns
as
$name
=>
$value
)
{
...
@@ -106,7 +111,7 @@ class QueryBuilder extends \yii\base\Object
...
@@ -106,7 +111,7 @@ class QueryBuilder extends \yii\base\Object
}
else
{
}
else
{
$phName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$phName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$placeholders
[]
=
$phName
;
$placeholders
[]
=
$phName
;
$params
[
$phName
]
=
$value
;
$params
[
$phName
]
=
isset
(
$columnSchemas
[
$name
])
?
$columnSchemas
[
$name
]
->
typecast
(
$value
)
:
$value
;
}
}
}
}
...
@@ -164,6 +169,12 @@ class QueryBuilder extends \yii\base\Object
...
@@ -164,6 +169,12 @@ class QueryBuilder extends \yii\base\Object
*/
*/
public
function
update
(
$table
,
$columns
,
$condition
,
&
$params
)
public
function
update
(
$table
,
$columns
,
$condition
,
&
$params
)
{
{
if
((
$tableSchema
=
$this
->
db
->
getTableSchema
(
$table
))
!==
null
)
{
$columnSchemas
=
$tableSchema
->
columns
;
}
else
{
$columnSchemas
=
array
();
}
$lines
=
array
();
$lines
=
array
();
foreach
(
$columns
as
$name
=>
$value
)
{
foreach
(
$columns
as
$name
=>
$value
)
{
if
(
$value
instanceof
Expression
)
{
if
(
$value
instanceof
Expression
)
{
...
@@ -174,7 +185,7 @@ class QueryBuilder extends \yii\base\Object
...
@@ -174,7 +185,7 @@ class QueryBuilder extends \yii\base\Object
}
else
{
}
else
{
$phName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$phName
=
self
::
PARAM_PREFIX
.
count
(
$params
);
$lines
[]
=
$this
->
db
->
quoteColumnName
(
$name
)
.
'='
.
$phName
;
$lines
[]
=
$this
->
db
->
quoteColumnName
(
$name
)
.
'='
.
$phName
;
$params
[
$phName
]
=
$value
;
$params
[
$phName
]
=
isset
(
$columnSchemas
[
$name
])
?
$columnSchemas
[
$name
]
->
typecast
(
$value
)
:
$value
;
}
}
}
}
...
...
framework/yii/db/mysql/QueryBuilder.php
View file @
20bde29f
...
@@ -161,6 +161,12 @@ class QueryBuilder extends \yii\db\QueryBuilder
...
@@ -161,6 +161,12 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/
*/
public
function
batchInsert
(
$table
,
$columns
,
$rows
)
public
function
batchInsert
(
$table
,
$columns
,
$rows
)
{
{
if
((
$tableSchema
=
$this
->
db
->
getTableSchema
(
$table
))
!==
null
)
{
$columnSchemas
=
$tableSchema
->
columns
;
}
else
{
$columnSchemas
=
array
();
}
foreach
(
$columns
as
$i
=>
$name
)
{
foreach
(
$columns
as
$i
=>
$name
)
{
$columns
[
$i
]
=
$this
->
db
->
quoteColumnName
(
$name
);
$columns
[
$i
]
=
$this
->
db
->
quoteColumnName
(
$name
);
}
}
...
@@ -168,7 +174,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
...
@@ -168,7 +174,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
$values
=
array
();
$values
=
array
();
foreach
(
$rows
as
$row
)
{
foreach
(
$rows
as
$row
)
{
$vs
=
array
();
$vs
=
array
();
foreach
(
$row
as
$value
)
{
foreach
(
$row
as
$i
=>
$value
)
{
if
(
isset
(
$columnSchemas
[
$columns
[
$i
]]))
{
$value
=
$columnSchemas
[
$columns
[
$i
]]
->
typecast
(
$value
);
}
$vs
[]
=
is_string
(
$value
)
?
$this
->
db
->
quoteValue
(
$value
)
:
$value
;
$vs
[]
=
is_string
(
$value
)
?
$this
->
db
->
quoteValue
(
$value
)
:
$value
;
}
}
$values
[]
=
'('
.
implode
(
', '
,
$vs
)
.
')'
;
$values
[]
=
'('
.
implode
(
', '
,
$vs
)
.
')'
;
...
...
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