Sequential Query Execution Mobile

Dear Team, sorry for continuing to waste your time with stupid questions.
I'm trying to run some simple sequential queries, using the suggestion given here: Sequential query execution,
and configuring as in figure below.
I report the following:

  1. inserted the record in the fishes table and executing the getFishLastId query instead of getting 1 I get 0 (that mean there are no record in the table).
  2. despite having set the Disabled and Loading properties with insertFishTrigger.isFetching, I am immediately redirected to the screen defined in the navigateTo() function (setted in the Run JS Script Query).
  3. as shown in the figure below the updateFishesGallery query fails, but I don't understand why.




Thank you

Hey @Cotrariello!

You've been asking great questions :grin:

Even when you await a query call the actual object isn't updated in the script you're running so the data property you're accessing is still from before you ran the query. The await expression will, however, return the current call's data so you can do something like:

var fishData = await getFishes.trigger();
var fishId = fishData.lastid;

Can you let me know if that works?

Hi @Kabirdas,
I tried your suggestions, here some notes:

  1. how can you see in the insertFishNavigateBeforFinish figure, the fish variable is empy, is this a correct behaviour?
  2. how can you, always, see in the insertFishNavigateBeforFinish figure (I was using debug console to figure out the various problems), navigate to screen runs before the code was reached. (the screen go to FishListScreen ) maybe because that steatment code is no await?
  3. sometimes I get a Error 500 for some url call, how you can see in the figure insertFist500.
  4. last but not least, when I run the code to execute getFishById query I get an Error500, but I can't figure out why. Not always sometimes, myabe is the same of point 3.


    insertFistEmpty
console.log("Starting creating fish")
var fish = await insertFish.trigger()
console.log("Insert Fish Done")
console.log(fish)

await getFishes.trigger()      
console.log("Reload Fish Done")

var lastfishid = await getLastFishId.trigger()  
console.log("Get Last Fish Done: "+lastfishid.lastid)

await createFishGalleryEntity.trigger()
console.log("Create Gallery Fish Done")
await getGalleries.trigger()
var lastgalleryid = await getLastGalleriesId.trigger()
var galleryId = lastgalleryid.lastid
console.log("Get Last Gallery Id: "+galleryId)
console.log("Gallery Id: "+galleryId)

var fishId = lastfishid.lastid
console.log("Fish Id: "+fishId)

await getPhotos.trigger()

var lastphotoid = await getLastPhotosId.trigger()
var photoId = lastphotoid.lastid
console.log("Get Last Photos Id: "+photoId)

await updateFishGallery.trigger({
  additionalScope: {fish_scope_gallery: galleryId, fish_scope_id: fishId}
})

var fisha = await getFishById.trigger({
  additionalScope: {fish_scope_id: fishId }
})

await createFishPhotoEntity.trigger({
  additionalScope:{
    fish_scope_photo_id: photoId,
    fish_scope_gallery_id: galleryId,
    fish_scope_photo_value: fisha.photo
  }
})
navigator.navigateTo(FishesListScreen)

In add to the previous points:
is it correct the way I use to do insert?

insert into photos(id, id_gallery, is_favorite, value) values(replace(REPLACE({{fish_scope_photo_id}}, '{"', ''), '"}', '')::INTEGER+1, replace(REPLACE({{fish_scope_gallery_id}, '{"', ''), '"}', '')::INTEGER, false, replace(REPLACE({{fish_scope_photo_value}, '{"', ''), '"}', ''))

I mean, Have I obligatory use a replace replace functions to get the correct value? I did it because the {{fish_scope_gallery_id}} is returned always in the way {'1'}

usecaseretool(1)

Hey @Cotrariello!

1. That is expected behavior for regular insert queries in SQL mode, if you want your insert query to return a value you may try using a RETURNING clause e.g.

2. :thinking: the navigator should execute last in that script,await causes the queries to run synchronously so any code below them should only be executed after the query has returned, so I'd expect navigator.navigateTo(FishesListScreen) to run last. It looks like you have another navigation handler on your insertFish query though:

That, and other similar event handlers, are what I'd imagine is causing the early navigation.

3./4. How often are you seeing the errors and when did you notice them starting? Is it only when you run the queries as part of your script, or does it happen if you hardcode in a value and run the query manually?

For the insert - it seems like it may be more than is necessary. You might want to look at how you're defining fishId and galleryId, can you try using var fishId = lastfishid.lastid[0] instead, for instance?