Subject Re: Insert ... returning ...
Author arfernandes2005
A little test case:

- Firebird: 2.0 (final)
- JayBird: 2.1.1
- OS: Linux (Ubuntu 6.10 [Edgy Eft])
- Java: 1.5.0_08


--**-- database --**--

create database 'localhost:/databases/ReturningTest.fdb'
user 'SYSDBA' password 'masterkey'
default character set iso8859_1;

create sequence s_id;

create table Test (
id integer not null primary key,
name varchar(50) not null collate pt_br
);

set term ^;

create trigger t_Test_id_seq for Test before insert or update as begin
if (new.id is null or new.id = 0) then begin
new.id = next value for s_id;
end
end^

set term ;^

commit;


--**-- class --**--

import java.sql.*;

import org.firebirdsql.jdbc.*;


public class ReturningTest {

public static void main(String[] args) {
try {
Class.forName("org.firebirdsql.jdbc.FBDriver");

FirebirdConnection conn =
(FirebirdConnection)DriverManager.getConnection(
"jdbc:firebirdsql:localhost:/databases/ReturningTest.fdb",
"SYSDBA", "masterkey");

try {
String sql =
"insert into Test (name) values (?) returning id";

FirebirdPreparedStatement stat =
(FirebirdPreparedStatement)conn.prepareStatement(sql);

try {
stat.setString(1, "Test");

ResultSet rs = stat.executeQuery();

try {
if (rs.next()) {
System.out.println(rs.getInt("id"));
}
} finally {
rs.close();
rs = null;
}
} finally {
stat.close();
stat = null;
}
} finally {
conn.close();
conn = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}

}


--**-- error --**--

org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544364. request
synchronization error
at
org.firebirdsql.jdbc.FBStatementFetcher.fetch(FBStatementFetcher.java:206)
at
org.firebirdsql.jdbc.FBStatementFetcher.next(FBStatementFetcher.java:119)
at org.firebirdsql.jdbc.FBResultSet.next(FBResultSet.java:250)
at ReturningTest.main(ReturningTest.java:27)
at org.firebirdsql.gds.GDSException: request synchronization error
at
org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2124)
at
org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.receiveResponse(AbstractJavaGDSImpl.java:2074)
at
org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscDsqlFetch(AbstractJavaGDSImpl.java:1320)
at org.firebirdsql.gds.impl.GDSHelper.fetch(GDSHelper.java:262)
at
org.firebirdsql.jdbc.FBStatementFetcher.fetch(FBStatementFetcher.java:201)
at
org.firebirdsql.jdbc.FBStatementFetcher.next(FBStatementFetcher.java:119)
at org.firebirdsql.jdbc.FBResultSet.next(FBResultSet.java:250)
at ReturningTest.main(ReturningTest.java:27)


Thanks,

Adilson.




--- In Firebird-Java@yahoogroups.com, "Roman Rokytskyy"
<rrokytskyy@...> wrote:
>
> Hi,
>
> > Please, is the statement "insert into Table (col1, col2) values (val1,
> > val2) *returning col1*" implemented in JayBird 2.1.1?
> > I get the error: "GDS Exception. 335544364. request synchronization
> > error"...
>
> I did not try it, but if you get that error, that means that it is not
> currently not supported. I will check the issue next week.
>
> Roman
>