[DBAL-320] allow SQL QueryBuilder to do INSERTS Created: 13/Aug/12  Updated: 23/Dec/13  Resolved: 23/Dec/13

Status: Resolved
Project: Doctrine DBAL
Component/s: None
Affects Version/s: 2.3
Fix Version/s: 2.5
Security Level: All

Type: New Feature Priority: Major
Reporter: Tim Mundt Assignee: Steve Müller
Resolution: Fixed Votes: 0
Labels: None

Attachments: Text File INSERT-for-doctrine-SQL-QueryBuilder.patch    
Issue Links:
Reference
relates to DBAL-636 QueryBuilder insert Resolved
is referenced by DBAL-182 Insert and Merge Query Objects Open
is referenced by DBAL-599 Add support of insert and insert sele... Open

 Description   

With

$db = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
$qb = $db->createQueryBuilder();

this QueryBuilder I'm able to do SELECT, UPDATE and DELETE. However, INSERT is not possible. Are there any good reasons for this?

Attached you find a patch that until now works fine for me. I don't know, however, if there are any side effects.



 Comments   
Comment by Marco Pivetta [ 13/Aug/12 ]

Insert is not supported by DQL

Comment by Tim Mundt [ 13/Aug/12 ]

Well, that was quick and not helpful. I have read about the QueryBuilder in the ORM package. For some reason with persistence (that other libraries don't have), insert cannot be supported. However, I'm talking about DBAL here. What good reason is there not to support INSERT??

Comment by Tim Mundt [ 13/Aug/12 ]

see previous comment, I'd appreciate some clarification

Comment by Marco Pivetta [ 13/Aug/12 ]

Tim Mundt Ouch, no, it was my fault, sorry.
I confused the project related to the issue.

Comment by Marco Pivetta [ 13/Aug/12 ]

This is actually valid (even the patch, though it needs to adds tests)

Comment by Tim Mundt [ 13/Aug/12 ]

Glad to hear there seems to be no fundamental problem with this. Can I somehow help this patch go into the code? I'm not familiar with the tests here. If you give me some pointer, maybe I can come up with something useful. On the other hand, it could be a good idea for some more involved people to have a look at this before.

Comment by Marco Pivetta [ 13/Aug/12 ]

You'd need to add tests in https://github.com/doctrine/dbal/blob/master/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php (to be included in your patch or in a github pull request)
A Github PR is also the fastest way to get your code reviewed since not everyone visits the issue tracker.

Comment by Tim Mundt [ 13/Aug/12 ]

Here's the PR: https://github.com/doctrine/dbal/pull/184

Comment by Doctrine Bot [ 20/Dec/13 ]

A related Github Pull-Request [GH-184] was closed:
https://github.com/doctrine/dbal/pull/184

Comment by Steve Müller [ 23/Dec/13 ]

Fixed in commit: https://github.com/doctrine/dbal/commit/7502dae2e0d8e01e2f6f08cb5323ed754e72bac4

Generated at Thu Jul 31 07:35:46 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.