Posted to tcl by crshults at Thu Nov 07 06:05:00 GMT 2013view raw
- package require sqlite3
- sqlite3 db transactionlog.sqlite
- db eval {
- CREATE TABLE IF NOT EXISTS TransactionLog(
- LogIndex INTEGER PRIMARY KEY,
- RecordNumber INTEGER,
- TimeStamp INTEGER,
- EntryType TEXT,
- Amount INTEGER,
- SpecialIdentifier INTEGER DEFAULT unknown,
- Completed TEXT DEFAULT no
- );
- }
- set max_transaction_log_entries 10
- proc create_transaction_log_entry {entry_type amount} {
- set record_number [db eval {SELECT MAX(RecordNumber) FROM TransactionLog}]
- if {$record_number == "{}"} {
- set log_index 0
- set record_number 1
- } else {
- incr record_number
- set log_index [expr {$record_number % $::max_transaction_log_entries}]
- }
- set time_stamp [clock microseconds]
- db eval {
- INSERT OR REPLACE INTO TransactionLog (LogIndex, RecordNumber, TimeStamp, EntryType, Amount)
- VALUES ($log_index, $record_number, $time_stamp, $entry_type, $amount);
- }
- }
- # Example Usage
- create_transaction_log_entry "Cash" 2000
- create_transaction_log_entry "Check" 2001
- create_transaction_log_entry "Cash" 2002
- create_transaction_log_entry "Check" 2003
- create_transaction_log_entry "Check" 2004
- create_transaction_log_entry "Cash" 2005
- create_transaction_log_entry "Credit" 2006
- create_transaction_log_entry "Credit" 2007
- create_transaction_log_entry "Cash" 2008
- create_transaction_log_entry "Credit" 2009
- create_transaction_log_entry "Cash" 2010