Let me be more explanatory:
you create a SEQUENCE object in your database using SQL as so:
CREATE SEQUENCE RESOURCE_SEQ INCREMENT BY 1 START WITH 1 NOMINVALUE
NOMAXVALUE NOCYCLE NOCACHE ORDER
Then, when you want a unique number to keep a handle to, while using it in
an insert you:
SELECT RESOURCE_SEQ.nextval from dual
This will return a result set where you can do a rs.getInt(1) (or whatever
language you are using). This will be the number to use. It will also have
incremented the next available number for you.
You can then store that number in a variable and use it in your insert
E.G. (using Java)
int i = rs.getInt(1);
String sql = "INSERT INTO mytable VALUES (" + i + ")";
//then run your insert or whatever.
That make sense?
Carl
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Carl Olivier
Sent: 26 September 2002 04:43 PM
To: Alexei Livchits; [EMAIL PROTECTED]
Subject: RE: ODBC, serial data type, adding new row, getting new id
You should loom into the sapdb SEQUENCE objects. This is how I do it.
Carl
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Alexei Livchits
Sent: 26 September 2002 04:26 PM
To: [EMAIL PROTECTED]
Subject: ODBC, serial data type, adding new row, getting new id
Hi,
i have a problem: after inserting a new line with
addnew/update, I need the new ID. With ms ACCESS is it
simple: I just get a new id. But with sap db is it
impossible. Here is my code:
------------------------------------------------------------
----------------
oRs.Open "SELECT * FROM TESTTABLE", Conn, 1, 3
oRs.AddNew
oRs("TESTCOLUMN") = False
oRs.Update
NewID = oRs("BLOCK_ID")
' NewID is empty
------------------------------------------------------------
----------------
at the moment i do it in this way:
------------------------------------------------------------
----------------
oRs.Open "SELECT * FROM TESTTABLE", Conn, 3(!), 3
oRs.AddNew
oRs("TESTCOLUMN") = False
oRs.Update
oRs.Requery
oRs.MoveLast
NewID = oRs("BLOCK_ID")
------------------------------------------------------------
----------------
This way is not ideal.
Best regards,
Alexei Livchits
e-mail: [EMAIL PROTECTED]
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general