?
Solved

powerbuilder, autoincrement get id ?

Posted on 2006-03-27
4
Medium Priority
?
1,523 Views
Last Modified: 2013-12-26
Dear Experts ;

I have a situation where i insert a blob into a table, this table autogenerate its id with autoincrement, thats how i get the new blob.
But when i need to update the table i cant find the way to get the "Autoincrement" value , so instead i have to write it and disable autoincrement.
How can i get the autoincrement value and tell the table to update from that value?
I have a table called "Fotografias" with its primary key which is "id" and it is set to autoincrement, a varchar called "descripcion" and a blob object called "Object"
Here is my code:

//Insert new data
insert into fotografias (id,descripcion)
values  (default,:sle_5.text) ;
//Update new data
UPDATEBLOB fotografias SET object = :lblb_foto
WHERE id=  // ¿ AUTOINCREMENT ?
IF sqlca.sqlcode=0 THEN
messagebox('','Ingreso existoso.')
ELSE
messagebox('','Error en el ingreso')
END IF
dw_1.retrieve()
0
Comment
Question by:joaquiniglesias
  • 2
4 Comments
 
LVL 18

Expert Comment

by:diasroshan
ID: 16308008
Hi,

u can try this until i get a better solution...

//Insert new data
insert into fotografias (id,descripcion)
values  (default,:sle_5.text) ;

Select id
Into :ll_id
From fotografias
Where description = :sle_5.text ;

//Update new data
UPDATEBLOB fotografias SET object = :lblb_foto
WHERE id=  :ll_id;

IF sqlca.sqlcode=0 THEN
messagebox('','Ingreso existoso.')
ELSE
messagebox('','Error en el ingreso')
END IF
dw_1.retrieve()

Cheers,
Rosh
0
 
LVL 18

Expert Comment

by:diasroshan
ID: 16308046
Hi,

guess this is a better/right solution... hope it works... havent tried it...

//Insert new data
insert into fotografias (id,descripcion)
values  (default,:sle_5.text) ;

select cast(scope_identity() as int)  into :ll_id //Returns the last IDENTITY value inserted into an IDENTITY column in the same scope.

//Update new data
UPDATEBLOB fotografias SET object = :lblb_foto
WHERE id=  :ll_id;

IF sqlca.sqlcode=0 THEN
messagebox('','Ingreso existoso.')
ELSE
messagebox('','Error en el ingreso')
END IF
dw_1.retrieve()

Cheers,
Rosh
0
 
LVL 5

Accepted Solution

by:
berXpert earned 500 total points
ID: 16313958
Hi Joaquiin,

You can create a datawindow "dw_fotos" for your table fotografias with only those 2 fields: id, descripcion

Now, let DW handle for you this identity isue, here's the code:



Long ll_id
Datastore lds_fotos

lds_fotos = create datastore
lds_fotos.DataObject = 'dw_fotos'
lds_fotos.SetTransObject(SQLCA)

// New record
lds_fotos.InsertRow(0)
lds_fotos.Object.Descripcion[1] = sle_5.text
lds_fotos.Update()

// Get ID
ll_id = lds_fotos.Object.ID[1]

//Update new data
UPDATEBLOB fotografias SET object = :lblb_foto
WHERE id= :ll_id

IF sqlca.sqlcode=0 THEN
    messagebox('','Ingreso existoso.')
ELSE
    messagebox('','Error en el ingreso')
END IF
dw_1.retrieve()


Regards,

BerX
0
 

Author Comment

by:joaquiniglesias
ID: 16317352
berXpert, best solution !
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question