Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert multiple rows with a single query #16

Closed
jakeasmith opened this issue Apr 1, 2014 · 10 comments
Closed

Insert multiple rows with a single query #16

jakeasmith opened this issue Apr 1, 2014 · 10 comments

Comments

@jakeasmith
Copy link
Contributor

Is there a way to build a query that inserts multiple value sets?

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

If not, do you think it makes sense to add that functionality?

@harikt
Copy link
Member

harikt commented Apr 2, 2014

This is a nice functionality to add. Currently we don't have this support.

@harikt
Copy link
Member

harikt commented Apr 2, 2014

I also love to have multiquery execution. But we already discussed this in Aura.Sql auraphp/Aura.Sql#22

@pmjones
Copy link
Member

pmjones commented Apr 15, 2014

I can see where this would be useful, but I'm afraid I have other things that have to take priority. However, if you want to create a new MultipleInsert (or InsertMany or InsertMulti) class that exhibits this behavior and send a PR for it, I'd be happy to review.

@arcturial
Copy link
Contributor

I am working on a prototype for doing bulk inserts.

https://github.com/arcturial/Aura.SqlQuery/tree/feature-bulk-insert

Once the idea is solid I will do some cleanup before doing a PR. Have a look when you have a moment to see if this is what you had in mind.

The way you would use it is as follows:

$query->newBulkInsert()
           ->cols(array('col1', 'col2', 'col3'))
           ->bindValues(array(
                    array(
                            'col1' => 'row1a',
                            'col2' => 'row1b',
                            'col3' => 'row1c',
                    ),
                    array(
                            'col1' => 'row2a',
                            'col2' => 'row2b',
                            'col3' => 'row2c'
                    )
             ));

@harikt
Copy link
Member

harikt commented Mar 16, 2015

@arcturial it looks good to me. Appreciate your good work on it.

arcturial added a commit to arcturial/Aura.SqlQuery that referenced this issue Mar 19, 2015
BulkInsert handler for Common, MySQL, Postgress, SQLserv, SQLite.
arcturial added a commit to arcturial/Aura.SqlQuery that referenced this issue Mar 19, 2015
BulkInsert handler for Common, MySQL, Postgress, SQLserv, SQLite.
@arcturial
Copy link
Contributor

I moved the code to a new branch and changed it so that it now uses the same interface as the Insert() queries.

https://github.com/arcturial/Aura.SqlQuery/tree/feature-bulk-insert

The behaviour of some of the methods had to change slightly (like cols() not supporting associative arrays) since we are dealing with bulk data and not single values, but I don't think this should cause usability problems. I am not really sure why someone would want to use cols() with an associative array when doing bulk inserts anyway.

@arcturial
Copy link
Contributor

I updated the README in that branch with more detailed usage instructions.

@harikt
Copy link
Member

harikt commented Mar 19, 2015

@arcturial send a PR so it will be easy to get reviewed.

Thanks!

@arcturial
Copy link
Contributor

#56, request created

arcturial added a commit to arcturial/Aura.SqlQuery that referenced this issue Mar 19, 2015
BulkInsert handler for Common, MySQL, Postgress, SQLserv, SQLite.
@pmjones
Copy link
Member

pmjones commented Mar 22, 2015

This has been added as of c9dc2af

Many thanks to @arcturial for providing the impetus behind it.

@pmjones pmjones closed this as completed Mar 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants