bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PostgreSQL issue when dealing with table without PRIMARY KEY

slavino opened this issue · comments

return call_user_func_array([$this->pdo,$func],$args);

https://stackoverflow.com/questions/32991564/how-to-check-in-postgres-that-lastval-is-defined

seems that table needs to have PRIMARY KEY in order to fulfill INSERT statement without throwing an Error

setup:
Windows machine
Postgres 9.6
PHP 7.4.3 Development Server

SQLSTATE[55000]: Object not in prerequisite state: 7 ERROR:  lastval is not yet defined in this session [\workspace\domain.com\devtracks\vendor\bcosca\fatfree-core\db\sql.php:524]

[/workspace/domain.com/_sub/devtracks/vendor/bcosca/fatfree-core/db/sql.php:524] call_user_func_array()
[/workspace/domain.com/_sub/devtracks/vendor/bcosca/fatfree-core/db/sql/mapper.php:489] DB\SQL->__call()
[/workspace/domain.com/_sub/devtracks/vendor/bcosca/fatfree-core/db/cursor.php:245] DB\SQL\Mapper->insert()
[/workspace/domain.com/_sub/devtracks/app/MVC/Controller/MainController.php:58] DB\Cursor->save()
[/workspace/domain.com/_sub/devtracks/vendor/bcosca/fatfree/lib/base.php:1960] MainController->locusTrackerNoResponse()
[/workspace/domain.com/_sub/devtracks/vendor/bcosca/fatfree/lib/base.php:1759] Base->call()
[/workspace/domain.com/_sub/devtracks/index.php:41] Base->run()

PS: the silly part is that it actually successfully inserts such row and only hint is in the log file.

Yes the mapper is trying to reload the inserted record to obtain default values from the table, but without a returning pkey, that's not possible, hence the error.