• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1579
  • Last Modified:

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()
0
joaquiniglesias
Asked:
joaquiniglesias
  • 2
1 Solution
 
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
0
 
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
0
 
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
0
 
joaquiniglesiasAuthor Commented:
berXpert, best solution !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now