4

I feel like I'm having a moment where I'm missing something small here; I've been having issues using the insert() method on the QueryBuilder component on Dotrine DBAL 2.2.x / 2.3.x.

I did some investigation and here's the snippet from the QueryBuilder page from the DBAL Documantation

The \Doctrine\DBAL\Query\QueryBuilder supports building SELECT, INSERT, UPDATE and DELETE queries. Which sort of query you are building depends on the methods you are using.

It goes on further to explain code examples, such that I can simply do:

$builder = $connection->createQueryBuilder();
$result = $builder
    ->insert('table_name')
    // ...

To use the query builder in Insert Mode. Except when I do I get a complaint here from PHP:

Fatal error: Call to undefined method Doctrine\DBAL\Query\QueryBuilder::insert()

On further inspection of The QueryBuilder.php Source Code

I see no reference to any method insert(...), no class to inherit this from, no traits added to the QueryBuilder that could expose the insert mechanism. In addition I see this right at the top:

/* The query types. */
const SELECT = 0;
const DELETE = 1;
const UPDATE = 2;

There's no insert query type; there is however this interesting method comment for execute():

/**
 * Execute this query using the bound parameters and their types.
 *
 * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate}
 * for insert, update and delete statements.
 *
 * @return mixed
 */

Bottom Line:

This is a massive project with 100's of maintainers, I'm more likely to find my interpretation suspect here than a screwup on something so fundamental over numerous versions, but I cannot for the life of me figure out what I'm missing. Please help me see the obvious.

Aren
  • 54,668
  • 9
  • 68
  • 101
  • I reached the exact same conclusion you did and apparently we didn't screw up anything :) . Just waiting for a stable release of Doctrine/DBAL v2.5 and everything should be fine. The good news is that it will still work with PHP 5.3, which is great news for production environments where upgrading is tricky at best. – Radu Murzea Sep 09 '14 at 13:34

1 Answers1

4

It depends on your version. Insert has been added since v2.5.0-BETA3.

Viz https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Query/QueryBuilder.php#L563 and commit

You can decide to update package version or check this alternative solution

Community
  • 1
  • 1
Tomas Votruba
  • 23,240
  • 9
  • 79
  • 115
  • 2
    That's strange though, because their docs for 2.1 -> 2.4 seem to indicate the functionality should be there, but it's not. I'd like to use a stable build if possible. – Aren Aug 22 '14 at 18:33
  • Maybe the creator though it's already in stable, or "latest" in the documentation means dev version (since there are no other versions of that page). I wrote reference to this issue under [the commit](https://github.com/doctrine/dbal/commit/55c60cd4e0ea6609b234793b8e63c9554ddb107e) to find out. – Tomas Votruba Aug 23 '14 at 17:48
  • 2
    If I click on the documentation for 2.1 it takes me to "Latest" There's no way to go see documentation for specific versions. I just confirmed this, and that's likely why it's so confusing. – Aren Sep 03 '14 at 18:07
  • Viz [answer from Doctrine collaborator](https://github.com/doctrine/dbal/commit/55c60cd4e0ea6609b234793b8e63c9554ddb107e#commitcomment-7506710). It's confusing, and that's the way it is. Also he points to the repository, where you can try to find a bug. – Tomas Votruba Sep 04 '14 at 08:17
  • 2
    Just noting that DBAL now is at RC1 – kaiser Sep 05 '14 at 11:22