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 DataReader [DNET770] #710

Closed
firebird-automations opened this issue Jun 14, 2017 · 8 comments

Comments

@firebird-automations
Copy link

Submitted by: Remigiusz Babicz (reik)

Is duplicated by DNET319

INSERT (...) RETURNING (...) statement:
* works fine when using ExecuteScalar()
* doesn't work when using Executereader()

Full Code:

using System;
using FirebirdSql.Data.FirebirdClient;

namespace FirebirdClient
{
class Program
{
static void Main(string[] args)
{
object generatedID;
string command = @"
INSERT INTO CUSTOMER(CUSTOMER, CONTACT_FIRST, CONTACT_LAST, PHONE_NO, ADDRESS_LINE1, ADDRESS_LINE2, CITY, STATE_PROVINCE, COUNTRY, POSTAL_CODE, ON_HOLD)
VALUES('aaa', 'Jan','Kowalski', '1256', 'ulica', 'miasto', 'city', 'province', 'USA', '123', '*' ) RETURNING CUST_NO";
string connectionString = @"DataSource = localhost;Database = ""localhost:C:\Program Files\Firebird\Firebird_2_5\examples\empbuild\EMPLOYEE.FDB""; User = sysdba; Password = masterkey";
using (FbConnection con = new FbConnection(connectionString))
{
con.Open();
using (FbCommand fbc = new FbCommand(command, con))
{
if (false)
{
generatedID = fbc.ExecuteScalar(); //this works fine!
}
else
{
//this doesn't work
FbDataReader dr = fbc.ExecuteReader();
int fielsCount = dr.FieldCount; //return 1
string namse = dr.GetName(0); //return CUST_NO
Type type = dr.GetFieldType(0); //return int
bool rows = dr.HasRows; //return false
bool read = dr.Read(); //return false
generatedID = dr.GetValue(0); //throws exception
}
}
}
}
}
}

Commits: d3f9cd2

@firebird-automations
Copy link
Author

Commented by: Andre Litfin (andrelitfin)

You can change Method Fetch() in GdsStatement.cs and FesStatement and write

        if \(this\.StatementType == DbStatementType\.StoredProcedure && \!\_allRowsFetched\)
        \{
            \_allRowsFetched = true;
            return this\.GetOutputParameters\(\);
        \}
        else if \(\_statementType == DbStatementType\.Insert && \_allRowsFetched\)
        \{
            return null;
        \}
        else if \(\_statementType \!= DbStatementType\.Select && \_statementType \!= DbStatementType\.SelectForUpdate\)
        \{
            return null;
        \}

instead of

        //Original
        /\*
        if \(\_statementType \!= DbStatementType\.Select &&
			\_statementType \!= DbStatementType\.SelectForUpdate\)
		\{
			return null;
		\}\*/

to make it work :-)

@firebird-automations
Copy link
Author

Commented by: Rafael Almeida (ralmsdeveloper)

Very good suggestion Andre Litfin , these days I had this need.

I'll be trying to help Cincura. I did some testing here and everything went well!

@firebird-automations
Copy link
Author

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue is related to DNET319 [ DNET319 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue is duplicated by DNET319 [ DNET319 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

Link: This issue is related to DNET319 [ DNET319 ] =>

@firebird-automations
Copy link
Author

Modified by: @cincuranet

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

resolution: Fixed [ 1 ]

Fix Version: 6.0.0.0 [ 10850 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

summary: Problem with INSERT (...) RETURNING (...) and using DataReader => Problem with INSERT (...) RETURNING (...) and using DataReader #⁠breaking

@cincuranet cincuranet changed the title Problem with INSERT (...) RETURNING (...) and using DataReader #breaking [DNET770] Problem with INSERT (...) RETURNING (...) and using DataReader [DNET770] May 26, 2021
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

2 participants