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()
joaquiniglesiasAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

diasroshanCommented:
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
diasroshanCommented:
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
berXpertCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
joaquiniglesiasAuthor Commented:
berXpert, best solution !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.