User Tools

Site Tools


pracro:database

This is an old revision of the document!


Pracro Database design

Nothing to see here, move along…

Persistent transactions

When a new Pracro session is initiated, a connection to PostgreSQL is made. All commands (strings) issued to this connection, will be appended to a string contained in the session class. This string will be serialised with the rest of the session data upon pracrod shutdown and re-read on startup. The first SQL command issued is BEGIN; If a 'commit' is received by the pracro server, it is translated into a COMMIT; on the SQL connection and the command string is cleared. If the clienbt disconnects without any actions, an ROLLBACK; is sent to the SQL server. On reconnect to the session, the entire command string is replayed as it is, and the session is ready to continue where it left off. On the pracro 'discard' command, a ROLLBACK; is sent to the SQL server, and the command string is cleared.

Sequence numbers

All sequence numbers must be obtained from a seperate SQL conenction, that is not affected by the SQL transactions. It is vital that these numbers are not reused in later sessions. All sequence numbers used in the pracro sessions must therefor be used as strings, directly in the syntax strings.

global Db1
getSeq()
{
  Mutex.lock
  s = Db1.exec("currval('trseq')");
  Mutex.unlock
  return s;
}

do_something
{
   Db2
   Db2.exec("BEGIN");
   Db2.exec("INSERT INTO fields VALUES('foo', 'bar','"+getSeq()+"')");
}
pracro/database.1275575593.txt.gz · Last modified: 2010/06/03 16:33 by deva