User Tools

Site Tools


pracro:database

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Last revisionBoth sides next revision
pracro:database [2008/11/25 09:00] devapracro:database [2010/06/03 16:33] deva
Line 1: Line 1:
 ======Pracro Database design====== ======Pracro Database design======
 Nothing to see here, move along... 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.
 +<code>
 +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()+"')");
 +}
 +</code>
pracro/database.txt · Last modified: 2010/06/07 11:17 by deva