Error: lastval is not yet defined in this session

Hi,

So i’m running into an error, and can’t seem to find the solution. the error i’m getting is from PostgreSQL: “lastval is not yet defined in this session”. the error comes up when the on success is being triggered for notifications. the data is being stored in the DB.

The form, from which it’s posted, is generated by a repeat from a card group(like the image below). This to show a grid, on each grid tile there should be a form to add data to the information shown on the tile.

Setup:
image

Any one an idea to solve this, or built the structure in a better way?

Kind regards,

Nick

Which Server Model do you use? It seems to me that you try to do a database insert, does the table have an id column and if so what type is it?

I looked up the error, the lastval is to get the last inserted id from the database and it seems not to be set in your case.

My apologies for the late reply.

The server is running on PHP(7.3.2). And there is an ID column, it’s set do serial+PK(auto increment) in postgres which translate to an integer. it’s only used for updating values on a particular row.

To add more information after some searching.

The error is comming from the connection.php file:

file: “\dmxConnectLib\lib\db\Connection.php”
line: 95
message: “SQLSTATE[55000]: Object not in prerequisite state: 7 ERROR: lastval is not yet defined in this session”

And line 95 says: ‘identity’ => $this->pdo->lastInsertId()

I’m seeing online, is that it’s not advised to use lastval() with Postgres, but better would be to use “returning ;”.

Some explanation: https://stackoverflow.com/a/17824444

here is also some information regarding when you could call lastval: https://stackoverflow.com/questions/24012239/postgres-get-last-update-id

I also found this: https://stackoverflow.com/a/10492645
it shows a way how to get the sequence in postgres and I tried this in the connection.php file to see what would happen. But then I got this error message: “currval of sequence “classassignment__id_seq” is not yet defined in this session"”.

This is what I have found at this moment, but I have no idea what to do now on fixing it besides commenting it off in the connection.php file(this does work and does not give an error, but i guess this does not give any identity back then anymore in the steps?).

Thanks for the research. I checked the lastInsertId documentation from PDO. Seems that Postgres requires the name of a serial object as parameter. https://www.php.net/manual/en/pdo.lastinsertid.php

To fix it I have to know which name I have to pass there, will have a look at it.

1 Like

any update on this?

I’m running into issues where i get this error during an update action while the action has correctly performed. I tried to put a response 200 in the catch, to try to trigger my notification and alert, but that does not work.

So at this moment i cannot inform the users they successfully changed their password, which overflows my mailbox with questions…:expressionless:

Regards,

Nick

Will you need the inserted id? I can at least ignore the error

uhm in this case, i can ignore it too.

but my notification does not work, the server connect does not return a success because of this error and trying to force a status 200 via catch(because a step fails) does not work.

But is there an ETA when this is going to be fixed?

I’m working on an update at this moment, most are fixes for ASP.NET, but doing also some fixes for ASP and PHP. Update will be included in the Wappler update of this week.

that’s great news Patrick, thank you very much.

Did you still get an error after the latest Wappler update?

Do you know that your server has the latest PHP PDO_PGSQL Driver installed?
https://www.php.net/manual/en/ref.pdo-pgsql.php

@patrick, i will try today to update Wappler, just updating Wappler and re-opening the project should update it?

@NewMedia,The PDO installed is version 9.6.9.

Could you try the file mentioned in this topic, we have some additional fixes there:

@George, jep, this solved it for me.

I could not find it any where, but with Wappler updates, does the DMX framework also get updated for all projects(during opening/import) or does this require manual actions?

Hi Nick,

If you refer to Server Connect - the server side framework and its files - those get updated automatically when you save a server action file. You can see the updated files in the publishing panel below if you expand it.