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

Problem with INSERT (...) RETURNING (...) and using dbExpress with Delphi [CORE5592] #5858

Closed
firebird-automations opened this issue Aug 1, 2017 · 15 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Luiz Fernando Trevisan (luizztrevisan)

Attachments:
Insert_Returning.zip

using dbExpress components (TSQLConnection and TSQLDataSet)

running this command:
insert into CAD_CULTURAS (EMPRESA,
CODIGO,
NOME)
values (1,
null,
'soja')
returning CODIGO

The following error message is generated
Cursor is not open.

In Firebird 2.5.7 the code works perfectly

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

Luiz Fernando,

Where is no error message.

@firebird-automations
Copy link
Collaborator Author

Commented by: Luiz Fernando Trevisan (luizztrevisan)

this is source code

In Firebird 2.5.7 the code works perfectly

I am doing tests for migration to Firebird 3.0, and this command is no longer working

@firebird-automations
Copy link
Collaborator Author

Modified by: Luiz Fernando Trevisan (luizztrevisan)

Attachment: Insert_Returning.zip [ 13171 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @ibaseru

this is dbExpress problem, not Firebird.
dbExpress does not understand that insert/update/delete may return anything more than result of operation. So, you have 2 possibilities
1. do not use insert ... returning while working with dbExpress
2. do not use dbExpress at all, use another components that understands insert... returning.

@firebird-automations
Copy link
Collaborator Author

Commented by: Luiz Fernando Trevisan (luizztrevisan)

ok, I got it

Some time ago, in Firebird 2.5, there was a same request for this "problem" where it was solved in build 2.5.1

Follow the link:
CORE3203

@firebird-automations
Copy link
Collaborator Author

Modified by: Sean Leyne (seanleyne)

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

It's looking like a regression, no? Why won't fix?

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

I was acting based on @kdv's comments.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

Luiz Fernando, please check if the problems happens when using Firebird embedded.

@firebird-automations
Copy link
Collaborator Author

Commented by: Luiz Fernando Trevisan (luizztrevisan)

Adriano dos Santos, com o Firebird embedded acontece a mesma coisa.

entrei em contato com os desenvolvedores da DevExpress, eles sugeriram fazer a execução dos comandos com insert ... returning de uma outra forma.
dessa nova forma o valor é retornado sem problemas.

fiz a abertura do chamado pois, utilizando a fbclient 2.5 e o firebird 2.5, ao executar o comando ".Open" o resultado é retornado sem problemas,
mas, se eu utilizar somente a fbclient 3.0, com o firebird 2.5, recebo a mesma mensagem "Cursor is not open" ou "Cursor not returned from query"

@firebird-automations
Copy link
Collaborator Author

Commented by: Sean Leyne (seanleyne)

Luiz Fernando,

Please post comments in English.

@firebird-automations
Copy link
Collaborator Author

Commented by: Alison Dennis (alisondv)

Hi,

I'm using Firebird 3.0.4 with DBExpress and the same error occurs: "SQL Server Error: Cursor is not open."

Insert Into TBCTENFELOG
(
C2, C3
)
Values
(
'007', 152223
) Returning C1

The Sql above works fine with FB 2.1.

I'm working on the migration to Firebird 3.0.4 and I like to know if this "bug" will be fixed on a future version?

@JonathanGoncalves7
Copy link

The solution I found was to run the INSERT RETURNING inside an EXECUTE BLOCK.

I'm using TSQLDataSet. Remembering that it is necessary to change the ParamCheck property to false, because the component understands the : of the return as a parameter.

EXECUTE BLOCK
RETURNS (
ID INT)
AS
BEGIN
INSERT INTO TABLE(FIELD)
VALUES (FIELD_VALUE)
RETURNING FIELD
INTO :ID;

SUSPEND;
END;

@mrotteveel
Copy link
Member

@Prodevy7 In Firebird 4 and earlier, a statement with RETURNING clause is similar to EXECUTE PROCEDURE. The fact your workaround works, and errors shown earlier, indicates attempts to execute it as a SELECT, which will fail because RETURNING doesn't have a cursor (this will change in Firebird 5 for some statements).

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

3 participants