bmSearch  0.0.4
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
sqlQuery.sqlQuery Class Reference

Public Member Functions

def __init__ (self, db)
 
def addEntry (self, tupl)
 
def close (self)
 
def deleteEntriesOlderThan (self, tupl)
 
def deleteEntry (self, tupl)
 
def initDb (self)
 
def purgeIndexTable (self)
 
def updateTrigger (self, dbStoreMaxDays)
 
def verifyIfMessageidExists (self, messageid)
 

Public Attributes

 c
 
 conn
 

Static Public Attributes

string addTrigger
 
 dropTrigger
 
string query = "SELECT count(*) FROM `index` WHERE messageid=\""
 
 res = self.c.fetchone()
 

Detailed Description

sqlQuery : 
        This class offers all methods to manage message-id in time in datastoring them in a simple table index containing two columns ('messageid', 'timestamp') 
        This DB contain tables :
                `index` (`messageid` INTEGER NOT NULL UNIQUE, `timestamp` INTEGER NOT NULL, PRIMARY KEY(messageid) )

Constructor & Destructor Documentation

def sqlQuery.sqlQuery.__init__ (   self,
  db 
)
 __init__ 
        init the connection to the database stored in db file
        Args :
"db" : the full path to the db file, by default '/var/lib/bmSearch/bmSearch.sqlite' 
33  def __init__(self, db):
34  """
35  __init__
36  init the connection to the database stored in db file
37  Args :
38  "db" : the full path to the db file, by default '/var/lib/bmSearch/bmSearch.sqlite'
39 
40  """
41 
42  try:
43  self.conn = sqlite3.connect(db)
44  self.c = self.conn.cursor()
45 
46  except Exception as error:
47  pass
48 
49 
50 

Member Function Documentation

def sqlQuery.sqlQuery.addEntry (   self,
  tupl 
)
addEntry:
        add in index table single tupl(messageid, timestamp)
187  def addEntry(self, tupl):
188  """
189  addEntry:
190  add in index table single tupl(messageid, timestamp)
191  """
192  query = "insert into `index` (messageid,timestamp) values (?,?) ;"
193 
def sqlQuery.sqlQuery.close (   self)
close :
        close the connection to the dabase
51  def close(self):
52  """
53  close :
54  close the connection to the dabase
55 
56  """
57  try:
58  self.c.close()
59  del self.c
60  self.conn.close()
61 
62  except Exception as error:
63  pass
64 
65 
66 
def sqlQuery.sqlQuery.deleteEntriesOlderThan (   self,
  tupl 
)
deleteEntriesOlderThan:
        delete all index entries older than tupl(timestamp) value
154  def deleteEntriesOlderThan(self, tupl):
155  """
156  deleteEntriesOlderThan:
157  delete all index entries older than tupl(timestamp) value
158 
159  """
160  try:
161 
162  self.c.execute("""delete FROM index WHERE timestamp<?""",tupl)
163  self.conn.commit()
164  return 0
165 
166  except Exception as error:
167  pass
168 
169 
170 
def sqlQuery.sqlQuery.deleteEntry (   self,
  tupl 
)
deleteEntry:
        delete single entry tupl(columnName, value) in index table.
171  def deleteEntry(self, tupl):
172  """
173  deleteEntry:
174  delete single entry tupl(columnName, value) in index table.
175 
176  """
177  try:
178  self.c.execute("""delete FROM index WHERE ?=?""",tupl)
179  self.conn.commit()
180  return 0
181 
182  except Exception as error:
183  pass
184 
185 
186 
def sqlQuery.sqlQuery.initDb (   self)
initDb: 
        create the sqlite database, by default '/var/lib/bmSearch/bmSearch.sqlite' 
89  def initDb(self):
90  """
91  initDb:
92  create the sqlite database, by default '/var/lib/bmSearch/bmSearch.sqlite'
93  """
94  try:
95  self.c.execute("""
96  CREATE TABLE IF NOT EXISTS `index` (
97  `messageid` TEXT NOT NULL UNIQUE,
98  `timestamp` INTEGER NOT NULL,
99  PRIMARY KEY(messageid)
100  );
101  """)
102 
103  self.c.execute("vacuum")
104  self.conn.commit()
105 
106  except Exception as error:
107  pass
108 
109 
110 
def sqlQuery.sqlQuery.purgeIndexTable (   self)
*86400) ;
    END;
purgeIndexTable:
        do a truncate of index table.
139  def purgeIndexTable(self):
140  """
141  purgeIndexTable:
142  do a truncate of index table.
143  """
144  try:
145  self.c.execute("""truncate index ;""")
146  self.c.execute("vacuum")
147  self.conn.commit()
148 
149  except Exception as error:
150  pass
151 
152 
153 
def sqlQuery.sqlQuery.updateTrigger (   self,
  dbStoreMaxDays 
)
updateTrigger:
        the bmSearch sqlite database has a trigger which delete entries older than dbStoreMaxDays days, 5 by default.
        this method renew the trigger with new value
111  def updateTrigger(self, dbStoreMaxDays):
112  """
113  updateTrigger:
114  the bmSearch sqlite database has a trigger which delete entries older than dbStoreMaxDays days, 5 by default.
115  this method renew the trigger with new value
116  """
def sqlQuery.sqlQuery.verifyIfMessageidExists (   self,
  messageid 
)
verifyIfMessageidExists:
        return "True" or "False" if tupl(messageid) exists or not in table "index"
67  def verifyIfMessageidExists(self, messageid):
68  """
69  verifyIfMessageidExists:
70  return "True" or "False" if tupl(messageid) exists or not in table "index"
71 
72  """

Member Data Documentation

string sqlQuery.sqlQuery.addTrigger
static
Initial value:
1 = """
2 CREATE TRIGGER IF NOT EXISTS purge_old_data AFTER INSERT ON `index`
3  BEGIN
4  DELETE FROM `index` WHERE timestamp < (strftime('%s', 'now') - """
DROP TRIGGER IF EXISTS purge_old_data ;
sqlQuery.sqlQuery.c
sqlQuery.sqlQuery.conn
sqlQuery.sqlQuery.dropTrigger
static
string sqlQuery.sqlQuery.query = "SELECT count(*) FROM `index` WHERE messageid=\""
static
sqlQuery.sqlQuery.res = self.c.fetchone()
static

The documentation for this class was generated from the following file: