Kaydet (Commit) ff7d991a authored tarafından Gregory P. Smith's avatar Gregory P. Smith

- bsddb: the bsddb.dbtables Modify method now raises the proper error and

  aborts the db transaction safely when a modifier callback fails.
  Fixes SF python patch/bug #1408584.

Also cleans up the bsddb.dbtables docstrings since thats the only
documentation that exists for that unadvertised module.  (people
really should really just use sqlite3)
üst f0cab1f6
...@@ -131,7 +131,8 @@ def contains_metastrings(s) : ...@@ -131,7 +131,8 @@ def contains_metastrings(s) :
class bsdTableDB : class bsdTableDB :
def __init__(self, filename, dbhome, create=0, truncate=0, mode=0600, def __init__(self, filename, dbhome, create=0, truncate=0, mode=0600,
recover=0, dbflags=0): recover=0, dbflags=0):
"""bsdTableDB.open(filename, dbhome, create=0, truncate=0, mode=0600) """bsdTableDB(filename, dbhome, create=0, truncate=0, mode=0600)
Open database name in the dbhome BerkeleyDB directory. Open database name in the dbhome BerkeleyDB directory.
Use keyword arguments when calling this constructor. Use keyword arguments when calling this constructor.
""" """
...@@ -218,7 +219,8 @@ class bsdTableDB : ...@@ -218,7 +219,8 @@ class bsdTableDB :
def CreateTable(self, table, columns): def CreateTable(self, table, columns):
"""CreateTable(table, columns) - Create a new table in the database """CreateTable(table, columns) - Create a new table in the database.
raises TableDBError if it already exists or for other DB errors. raises TableDBError if it already exists or for other DB errors.
""" """
assert isinstance(columns, ListType) assert isinstance(columns, ListType)
...@@ -286,7 +288,8 @@ class bsdTableDB : ...@@ -286,7 +288,8 @@ class bsdTableDB :
def CreateOrExtendTable(self, table, columns): def CreateOrExtendTable(self, table, columns):
"""CreateOrExtendTable(table, columns) """CreateOrExtendTable(table, columns)
- Create a new table in the database. Create a new table in the database.
If a table of this name already exists, extend it to have any If a table of this name already exists, extend it to have any
additional columns present in the given list as well as additional columns present in the given list as well as
all of its current columns. all of its current columns.
...@@ -411,14 +414,15 @@ class bsdTableDB : ...@@ -411,14 +414,15 @@ class bsdTableDB :
def Modify(self, table, conditions={}, mappings={}): def Modify(self, table, conditions={}, mappings={}):
"""Modify(table, conditions) - Modify in rows matching 'conditions' """Modify(table, conditions={}, mappings={}) - Modify items in rows matching 'conditions' using mapping functions in 'mappings'
using mapping functions in 'mappings'
* conditions is a dictionary keyed on column names * table - the table name
containing condition functions expecting the data string as an * conditions - a dictionary keyed on column names containing
argument and returning a boolean. a condition callable expecting the data string as an
* mappings is a dictionary keyed on column names containint condition argument and returning a boolean.
functions expecting the data string as an argument and returning the * mappings - a dictionary keyed on column names containing a
new string for that column. condition callable expecting the data string as an argument and
returning the new string for that column.
""" """
try: try:
matching_rowids = self.__Select(table, [], conditions) matching_rowids = self.__Select(table, [], conditions)
...@@ -450,7 +454,8 @@ class bsdTableDB : ...@@ -450,7 +454,8 @@ class bsdTableDB :
txn.commit() txn.commit()
txn = None txn = None
except DBError, dberror: # catch all exceptions here since we call unknown callables
except:
if txn: if txn:
txn.abort() txn.abort()
raise raise
...@@ -461,9 +466,10 @@ class bsdTableDB : ...@@ -461,9 +466,10 @@ class bsdTableDB :
def Delete(self, table, conditions={}): def Delete(self, table, conditions={}):
"""Delete(table, conditions) - Delete items matching the given """Delete(table, conditions) - Delete items matching the given
conditions from the table. conditions from the table.
* conditions is a dictionary keyed on column names
containing condition functions expecting the data string as an * conditions - a dictionary keyed on column names containing
argument and returning a boolean. condition functions expecting the data string as an
argument and returning a boolean.
""" """
try: try:
matching_rowids = self.__Select(table, [], conditions) matching_rowids = self.__Select(table, [], conditions)
...@@ -499,11 +505,12 @@ class bsdTableDB : ...@@ -499,11 +505,12 @@ class bsdTableDB :
def Select(self, table, columns, conditions={}): def Select(self, table, columns, conditions={}):
"""Select(table, conditions) - retrieve specific row data """Select(table, columns, conditions) - retrieve specific row data
Returns a list of row column->value mapping dictionaries. Returns a list of row column->value mapping dictionaries.
* columns is a list of which column data to return. If
* columns - a list of which column data to return. If
columns is None, all columns will be returned. columns is None, all columns will be returned.
* conditions is a dictionary keyed on column names * conditions - a dictionary keyed on column names
containing callable conditions expecting the data string as an containing callable conditions expecting the data string as an
argument and returning a boolean. argument and returning a boolean.
""" """
......
...@@ -119,6 +119,10 @@ Extension Modules ...@@ -119,6 +119,10 @@ Extension Modules
results. It could previously incorrectly return 0 in some cases. results. It could previously incorrectly return 0 in some cases.
Fixes SF bug 1493322 (pybsddb bug 1184012). Fixes SF bug 1493322 (pybsddb bug 1184012).
- bsddb: the bsddb.dbtables Modify method now raises the proper error and
aborts the db transaction safely when a modifier callback fails.
Fixes SF python patch/bug #1408584.
Library Library
------- -------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment