Link to home
Start Free TrialLog in
Avatar of joaquiniglesias
joaquiniglesias

asked on

powerbuilder, autoincrement get id ?

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()
Avatar of diasroshan
diasroshan
Flag of Kuwait image

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
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
ASKER CERTIFIED SOLUTION
Avatar of berXpert
berXpert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joaquiniglesias
joaquiniglesias

ASKER

berXpert, best solution !