Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Yeray Santana Hualde
syncEnrollments
Commits
53b94468
Commit
53b94468
authored
Jan 07, 2013
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix multi inserts in SQLite.
parent
0f690e83
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
sqlite.php
laravel/database/query/grammars/sqlite.php
+46
-0
No files found.
laravel/database/query/grammars/sqlite.php
View file @
53b94468
...
...
@@ -21,4 +21,50 @@ class SQLite extends Grammar
return
'ORDER BY '
.
implode
(
', '
,
$sql
);
}
/**
* Compile a SQL INSERT statement from a Query instance.
*
* This method handles the compilation of single row inserts and batch inserts.
*
* @param Query $query
* @param array $values
* @return string
*/
public
function
insert
(
Query
$query
,
$values
)
{
// Essentially we will force every insert to be treated as a batch insert which
// simply makes creating the SQL easier for us since we can utilize the same
// basic routine regardless of an amount of records given to us to insert.
$table
=
$this
->
wrap_table
(
$query
->
from
);
if
(
!
is_array
(
reset
(
$values
)))
{
$values
=
array
(
$values
);
}
// If there is only one record being inserted, we will just use the usual query
// grammar insert builder because no special syntax is needed for the single
// row inserts in SQLite. However, if there are multiples, we'll continue.
if
(
count
(
$values
)
==
1
)
{
return
parent
::
insert
(
$query
,
$values
[
0
]);
}
$names
=
$this
->
columnize
(
array_keys
(
$values
[
0
]));
$columns
=
array
();
// SQLite requires us to build the multi-row insert as a listing of select with
// unions joining them together. So we'll build out this list of columns and
// then join them all together with select unions to complete the queries.
foreach
(
array_keys
(
$values
[
0
])
as
$column
)
{
$columns
[]
=
'? AS '
.
$this
->
wrap
(
$column
);
}
$columns
=
array_fill
(
9
,
count
(
$values
),
implode
(
', '
,
$columns
));
return
"INSERT INTO
$table
(
$names
) SELECT "
.
implode
(
' UNION SELECT '
,
$columns
);
}
}
\ No newline at end of file
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