Lines Matching refs:table
15 # This provides a simple database table interface built on top of
117 def _columns_key(table):
118 return table + _columns
121 # these keys are found within table sub databases
123 _data = '._DATA_.' # this+column+this+rowid key contains table data
125 # row in the table. (no data is stored)
129 def _data_key(table, col, rowid):
130 return table + _data + col + _data + rowid
132 def _search_col_data_key(table, col):
133 return table + _data + col + _data
135 def _search_all_data_key(table):
136 return table + _data
138 def _rowid_key(table, rowid):
139 return table + _rowid + rowid + _rowid
141 def _search_rowid_key(table):
142 return table + _rowid
259 # Initialize the table names list if this is a new database
309 def CreateTable(self, table, columns):
310 """CreateTable(table, columns) - Create a new table in the database.
318 # checking sanity of the table and column names here on
319 # table creation will prevent problems elsewhere.
320 if contains_metastrings(table):
322 "bad table name: contains reserved metastrings")
328 columnlist_key = _columns_key(table)
330 raise TableAlreadyExists, "table already exists"
333 # store the table's column info
337 # add the table name to the tablelist
340 tablelist.append(table)
357 def ListTableColumns(self, table):
358 """Return a list of columns in the given table.
359 [] if the table doesn't exist.
361 assert isinstance(table, str)
362 if contains_metastrings(table):
363 raise ValueError, "bad table name: contains reserved metastrings"
365 columnlist_key = _columns_key(table)
383 def CreateOrExtendTable(self, table, columns):
384 """CreateOrExtendTable(table, columns)
386 Create a new table in the database.
388 If a table of this name already exists, extend it to have any
395 self.CreateTable(table, columns)
397 # the table already existed, add any new columns
400 columnlist_key = _columns_key(table)
407 # create a hash table for fast lookups of column names in the
420 # store the table's new extended column list
431 self.__load_column_info(table)
441 def __load_column_info(self, table) :
446 self.db.get)(_columns_key(table))
448 raise TableDBError, "unknown table: %r" % (table,)
450 raise TableDBError, "unknown table: %r" % (table,)
451 self.__tablecolumns[table] = pickle.loads(tcolpickles)
453 def __new_rowid(self, table, txn) :
470 self.db.put(_rowid_key(table, newid), None, txn=txn,
480 def Insert(self, table, rowdict) :
481 """Insert(table, datadict) - Insert a new row into the table
487 if not getattr(self.db, "has_key")(_columns_key(table)):
488 raise TableDBError, "unknown table"
491 if not table in self.__tablecolumns:
492 self.__load_column_info(table)
494 if not self.__tablecolumns[table].count(column):
499 rowid = self.__new_rowid(table, txn=txn)
501 # insert the row values into the table database
504 self.db.put(_data_key(table, column, rowid), dataitem, txn=txn)
517 self.db.delete(_rowid_key(table, rowid))
524 def Modify(self, table, conditions={}, mappings={}):
525 """Modify(table, conditions={}, mappings={}) - Modify items in rows matching 'conditions' using mapping functions in 'mappings'
527 * table - the table name
537 matching_rowids = self.__Select(table, [], conditions)
549 _data_key(table, column, rowid),
552 _data_key(table, column, rowid),
561 _data_key(table, column, rowid),
578 def Delete(self, table, conditions={}):
579 """Delete(table, conditions) - Delete items matching the given
580 conditions from the table.
588 matching_rowids = self.__Select(table, [], conditions)
591 columns = self.__tablecolumns[table]
599 self.db.delete(_data_key(table, column, rowid),
606 self.db.delete(_rowid_key(table, rowid), txn=txn)
623 def Select(self, table, columns, conditions={}):
624 """Select(table, columns, conditions) - retrieve specific row data
634 if not table in self.__tablecolumns:
635 self.__load_column_info(table)
637 columns = self.__tablecolumns[table]
638 matching_rowids = self.__Select(table, columns, conditions)
648 def __Select(self, table, columns, conditions):
658 if not table in self.__tablecolumns:
659 self.__load_column_info(table)
661 columns = self.tablecolumns[table]
663 if not self.__tablecolumns[table].count(column):
722 searchkey = _search_col_data_key(table, column)
769 _data_key(table, column, rowid))
783 def Drop(self, table):
784 """Remove an entire table from the database"""
790 self.db.delete(_columns_key(table), txn=txn)
795 table_key = _search_all_data_key(table)
801 # only delete items in this table
806 # delete all rowids used by this table
807 table_key = _search_rowid_key(table)
813 # only delete items in this table
820 # delete the tablename from the table name list
825 tablelist.remove(table)
837 if table in self.__tablecolumns:
838 del self.__tablecolumns[table]