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
25bf486b
Commit
25bf486b
authored
Aug 12, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save some function calls on AR insert
parent
0a709b10
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
18 deletions
+22
-18
ActiveRecord.php
framework/db/ActiveRecord.php
+1
-1
QueryBuilder.php
framework/db/QueryBuilder.php
+9
-7
QueryBuilder.php
framework/db/pgsql/QueryBuilder.php
+7
-6
QueryBuilder.php
framework/db/sqlite/QueryBuilder.php
+5
-4
No files found.
framework/db/ActiveRecord.php
View file @
25bf486b
...
...
@@ -282,7 +282,7 @@ class ActiveRecord extends BaseActiveRecord
*/
public
static
function
getTableSchema
()
{
$schema
=
static
::
getDb
()
->
getTableSchema
(
static
::
tableName
());
$schema
=
static
::
getDb
()
->
get
Schema
()
->
get
TableSchema
(
static
::
tableName
());
if
(
$schema
!==
null
)
{
return
$schema
;
}
else
{
...
...
framework/db/QueryBuilder.php
View file @
25bf486b
...
...
@@ -131,7 +131,8 @@ class QueryBuilder extends \yii\base\Object
*/
public
function
insert
(
$table
,
$columns
,
&
$params
)
{
if
((
$tableSchema
=
$this
->
db
->
getTableSchema
(
$table
))
!==
null
)
{
$schema
=
$this
->
db
->
getSchema
();
if
((
$tableSchema
=
$schema
->
getTableSchema
(
$table
))
!==
null
)
{
$columnSchemas
=
$tableSchema
->
columns
;
}
else
{
$columnSchemas
=
[];
...
...
@@ -139,7 +140,7 @@ class QueryBuilder extends \yii\base\Object
$names
=
[];
$placeholders
=
[];
foreach
(
$columns
as
$name
=>
$value
)
{
$names
[]
=
$
this
->
db
->
quoteColumnName
(
$name
);
$names
[]
=
$
schema
->
quoteColumnName
(
$name
);
if
(
$value
instanceof
Expression
)
{
$placeholders
[]
=
$value
->
expression
;
foreach
(
$value
->
params
as
$n
=>
$v
)
{
...
...
@@ -152,7 +153,7 @@ class QueryBuilder extends \yii\base\Object
}
}
return
'INSERT INTO '
.
$
this
->
db
->
quoteTableName
(
$table
)
return
'INSERT INTO '
.
$
schema
->
quoteTableName
(
$table
)
.
' ('
.
implode
(
', '
,
$names
)
.
') VALUES ('
.
implode
(
', '
,
$placeholders
)
.
')'
;
}
...
...
@@ -178,7 +179,8 @@ class QueryBuilder extends \yii\base\Object
*/
public
function
batchInsert
(
$table
,
$columns
,
$rows
)
{
if
((
$tableSchema
=
$this
->
db
->
getTableSchema
(
$table
))
!==
null
)
{
$schema
=
$this
->
db
->
getSchema
();
if
((
$tableSchema
=
$schema
->
getTableSchema
(
$table
))
!==
null
)
{
$columnSchemas
=
$tableSchema
->
columns
;
}
else
{
$columnSchemas
=
[];
...
...
@@ -192,7 +194,7 @@ class QueryBuilder extends \yii\base\Object
$value
=
$columnSchemas
[
$columns
[
$i
]]
->
dbTypecast
(
$value
);
}
if
(
is_string
(
$value
))
{
$value
=
$
this
->
db
->
quoteValue
(
$value
);
$value
=
$
schema
->
quoteValue
(
$value
);
}
elseif
(
$value
===
false
)
{
$value
=
0
;
}
elseif
(
$value
===
null
)
{
...
...
@@ -204,10 +206,10 @@ class QueryBuilder extends \yii\base\Object
}
foreach
(
$columns
as
$i
=>
$name
)
{
$columns
[
$i
]
=
$
this
->
db
->
quoteColumnName
(
$name
);
$columns
[
$i
]
=
$
schema
->
quoteColumnName
(
$name
);
}
return
'INSERT INTO '
.
$
this
->
db
->
quoteTableName
(
$table
)
return
'INSERT INTO '
.
$
schema
->
quoteTableName
(
$table
)
.
' ('
.
implode
(
', '
,
$columns
)
.
') VALUES '
.
implode
(
', '
,
$values
);
}
...
...
framework/db/pgsql/QueryBuilder.php
View file @
25bf486b
...
...
@@ -128,8 +128,8 @@ class QueryBuilder extends \yii\db\QueryBuilder
public
function
checkIntegrity
(
$check
=
true
,
$schema
=
''
,
$table
=
''
)
{
$enable
=
$check
?
'ENABLE'
:
'DISABLE'
;
$schema
=
$schema
?
$schema
:
$this
->
db
->
schema
->
defaultSchema
;
$tableNames
=
$table
?
[
$table
]
:
$this
->
db
->
schema
->
getTableNames
(
$schema
);
$schema
=
$schema
?
$schema
:
$this
->
db
->
getSchema
()
->
defaultSchema
;
$tableNames
=
$table
?
[
$table
]
:
$this
->
db
->
getSchema
()
->
getTableNames
(
$schema
);
$command
=
''
;
foreach
(
$tableNames
as
$tableName
)
{
...
...
@@ -165,7 +165,8 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/
public
function
batchInsert
(
$table
,
$columns
,
$rows
)
{
if
((
$tableSchema
=
$this
->
db
->
getTableSchema
(
$table
))
!==
null
)
{
$schema
=
$this
->
db
->
getSchema
();
if
((
$tableSchema
=
$schema
->
getTableSchema
(
$table
))
!==
null
)
{
$columnSchemas
=
$tableSchema
->
columns
;
}
else
{
$columnSchemas
=
[];
...
...
@@ -179,7 +180,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
$value
=
$columnSchemas
[
$columns
[
$i
]]
->
dbTypecast
(
$value
);
}
if
(
is_string
(
$value
))
{
$value
=
$
this
->
db
->
quoteValue
(
$value
);
$value
=
$
schema
->
quoteValue
(
$value
);
}
elseif
(
$value
===
true
)
{
$value
=
'TRUE'
;
}
elseif
(
$value
===
false
)
{
...
...
@@ -193,10 +194,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
}
foreach
(
$columns
as
$i
=>
$name
)
{
$columns
[
$i
]
=
$
this
->
db
->
quoteColumnName
(
$name
);
$columns
[
$i
]
=
$
schema
->
quoteColumnName
(
$name
);
}
return
'INSERT INTO '
.
$
this
->
db
->
quoteTableName
(
$table
)
return
'INSERT INTO '
.
$
schema
->
quoteTableName
(
$table
)
.
' ('
.
implode
(
', '
,
$columns
)
.
') VALUES '
.
implode
(
', '
,
$values
);
}
}
framework/db/sqlite/QueryBuilder.php
View file @
25bf486b
...
...
@@ -70,7 +70,8 @@ class QueryBuilder extends \yii\db\QueryBuilder
return
parent
::
batchInsert
(
$table
,
$columns
,
$rows
);
}
if
((
$tableSchema
=
$this
->
db
->
getTableSchema
(
$table
))
!==
null
)
{
$schema
=
$this
->
db
->
getSchema
();
if
((
$tableSchema
=
$schema
->
getTableSchema
(
$table
))
!==
null
)
{
$columnSchemas
=
$tableSchema
->
columns
;
}
else
{
$columnSchemas
=
[];
...
...
@@ -84,7 +85,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
$value
=
$columnSchemas
[
$columns
[
$i
]]
->
dbTypecast
(
$value
);
}
if
(
is_string
(
$value
))
{
$value
=
$
this
->
db
->
quoteValue
(
$value
);
$value
=
$
schema
->
quoteValue
(
$value
);
}
elseif
(
$value
===
false
)
{
$value
=
0
;
}
elseif
(
$value
===
null
)
{
...
...
@@ -96,10 +97,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
}
foreach
(
$columns
as
$i
=>
$name
)
{
$columns
[
$i
]
=
$
this
->
db
->
quoteColumnName
(
$name
);
$columns
[
$i
]
=
$
schema
->
quoteColumnName
(
$name
);
}
return
'INSERT INTO '
.
$
this
->
db
->
quoteTableName
(
$table
)
return
'INSERT INTO '
.
$
schema
->
quoteTableName
(
$table
)
.
' ('
.
implode
(
', '
,
$columns
)
.
') SELECT '
.
implode
(
' UNION SELECT '
,
$values
);
}
...
...
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