Posted to tcl by crshults at Thu Nov 07 06:05:00 GMT 2013view raw

  1. package require sqlite3
  2. sqlite3 db transactionlog.sqlite
  3.  
  4. db eval {
  5. CREATE TABLE IF NOT EXISTS TransactionLog(
  6. LogIndex INTEGER PRIMARY KEY,
  7. RecordNumber INTEGER,
  8. TimeStamp INTEGER,
  9. EntryType TEXT,
  10. Amount INTEGER,
  11. SpecialIdentifier INTEGER DEFAULT unknown,
  12. Completed TEXT DEFAULT no
  13. );
  14. }
  15.  
  16. set max_transaction_log_entries 10
  17.  
  18. proc create_transaction_log_entry {entry_type amount} {
  19. set record_number [db eval {SELECT MAX(RecordNumber) FROM TransactionLog}]
  20. if {$record_number == "{}"} {
  21. set log_index 0
  22. set record_number 1
  23. } else {
  24. incr record_number
  25. set log_index [expr {$record_number % $::max_transaction_log_entries}]
  26. }
  27.  
  28. set time_stamp [clock microseconds]
  29.  
  30. db eval {
  31. INSERT OR REPLACE INTO TransactionLog (LogIndex, RecordNumber, TimeStamp, EntryType, Amount)
  32. VALUES ($log_index, $record_number, $time_stamp, $entry_type, $amount);
  33. }
  34. }
  35.  
  36. # Example Usage
  37. create_transaction_log_entry "Cash" 2000
  38. create_transaction_log_entry "Check" 2001
  39. create_transaction_log_entry "Cash" 2002
  40. create_transaction_log_entry "Check" 2003
  41. create_transaction_log_entry "Check" 2004
  42. create_transaction_log_entry "Cash" 2005
  43. create_transaction_log_entry "Credit" 2006
  44. create_transaction_log_entry "Credit" 2007
  45. create_transaction_log_entry "Cash" 2008
  46. create_transaction_log_entry "Credit" 2009
  47. create_transaction_log_entry "Cash" 2010
  48.