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

SqlConsoleCommand should show results of queries containing RETURNING #871

Merged
merged 2 commits into from
Jan 9, 2016

Conversation

bountin
Copy link
Contributor

@bountin bountin commented Jun 18, 2015

PostgreSQL supports returning values after they are inserted or updated which is especially handy if one wants to get the value of an used sequence. (See http://www.postgresql.org/docs/9.4/static/sql-insert.html) Those returned values are currently omitted but could be displayed.

Currently (with symfony):

vagrant@packer-parallels-iso:/vagrant⟫ app/console doctrine:query:sql "INSERT INTO account (id) VALUES (uuid_generate_v4()) RETURNING id"
int 0

After the patch the output is the following:

array (size=1)
  0 =>
    array (size=1)
      'id' => string 'ad7a7c8f-72fd-48b9-b216-568ac204649d' (length=36)

Looking directly for 'returning' is a bit direct in my eyes but as there is no sql parser present, there is no other easy way to do so. If someone has a better implementation or any suggestion, feel free to comment :)

@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DBAL-1250

We use Jira to track the state of pull requests and the versions they got
included in.

@bountin
Copy link
Contributor Author

bountin commented Jun 18, 2015

Also detecting a SELECT statement by looking at the first SELECT does not always work. E.g. if one is using CTE:

vagrant@packer-parallels-iso:/vagrant⟫ app/console doctrine:query:sql "WITH bar as (SELECT 1) SELECT * FROM bar"
int 0

@billschaller
Copy link
Member

Rather than this nonsense of detecting strings inside queries, I'd rather just create an option that specifies this behavior.

Maybe --force-fetch?

@bountin
Copy link
Contributor Author

bountin commented Jul 2, 2015

@zeroedin-bill I've rewritten the code to your suggestion!

@bountin
Copy link
Contributor Author

bountin commented Jul 6, 2015

And the tests are only failing because of composer timeouts :(

@deeky666 deeky666 added the Tools label Jan 8, 2016
@deeky666 deeky666 added this to the 2.6 milestone Jan 9, 2016
@deeky666 deeky666 self-assigned this Jan 9, 2016
@deeky666 deeky666 merged commit b346106 into doctrine:master Jan 9, 2016
deeky666 added a commit that referenced this pull request Jan 9, 2016
SqlConsoleCommand: Showing results of queries containing RETURNING
@deeky666
Copy link
Member

deeky666 commented Jan 9, 2016

Merged manually, renamed fetch-result to force-fetch as suggested by @zeroedin-bill (to be more explicit about intention). Thanks @bountin

@billschaller
Copy link
Member

👍

@Ocramius Ocramius changed the title SqlConsoleCommand: Showing results of queries containing RETURNING SqlConsoleCommand should show results of queries containing RETURNING Jul 22, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants