We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

powerbuilder, autoincrement get id ?

joaquiniglesias
on
Medium Priority
1,692 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()
Comment
Watch Question

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
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
berXpert, best solution !
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.