mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Fixes bug 477182 on pybsddb.sf.net. DB objects now load the flags and
pay attention to them when opening an existing database. This means that d[] behaves properly even on databases previously created with DB_DUP or DB_DUPSORT flags to allow duplicate keys. http://sourceforge.net/tracker/index.php?func=detail&aid=477182&group_id=13900&atid=113900 Do not backport, this bugfix could be considered an API change.
This commit is contained in:
parent
9c466baa01
commit
ec10a4a402
3 changed files with 34 additions and 15 deletions
|
@ -90,6 +90,30 @@ class MiscTestCase(unittest.TestCase):
|
||||||
db1.close()
|
db1.close()
|
||||||
os.unlink(self.filename)
|
os.unlink(self.filename)
|
||||||
|
|
||||||
|
def test_DB_set_flags_persists(self):
|
||||||
|
try:
|
||||||
|
db1 = db.DB()
|
||||||
|
db1.set_flags(db.DB_DUPSORT)
|
||||||
|
db1.open(self.filename, db.DB_HASH, db.DB_CREATE)
|
||||||
|
db1['a'] = 'eh'
|
||||||
|
db1['a'] = 'A'
|
||||||
|
self.assertEqual([('a', 'A')], db1.items())
|
||||||
|
db1.put('a', 'Aa')
|
||||||
|
self.assertEqual([('a', 'A'), ('a', 'Aa')], db1.items())
|
||||||
|
db1.close()
|
||||||
|
db1 = db.DB()
|
||||||
|
# no set_flags call, we're testing that it reads and obeys
|
||||||
|
# the flags on open.
|
||||||
|
db1.open(self.filename, db.DB_HASH)
|
||||||
|
self.assertEqual([('a', 'A'), ('a', 'Aa')], db1.items())
|
||||||
|
# if it read the flags right this will replace all values
|
||||||
|
# for key 'a' instead of adding a new one. (as a dict should)
|
||||||
|
db1['a'] = 'new A'
|
||||||
|
self.assertEqual([('a', 'new A')], db1.items())
|
||||||
|
finally:
|
||||||
|
db1.close()
|
||||||
|
os.unlink(self.filename)
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -822,6 +822,14 @@ Extension Modules
|
||||||
- Bug #1233: fix bsddb.dbshelve.DBShelf append method to work as
|
- Bug #1233: fix bsddb.dbshelve.DBShelf append method to work as
|
||||||
intended for RECNO databases.
|
intended for RECNO databases.
|
||||||
|
|
||||||
|
- pybsddb.sf.net Bug #477182: Load the database flags at database open
|
||||||
|
time so that opening a database previously created with the DB_DUP or
|
||||||
|
DB_DUPSORT flag set will keep the proper behavior on subsequent opens.
|
||||||
|
Specifically: dictionary assignment to a DB object will replace all
|
||||||
|
values for a given key when the database allows duplicate values.
|
||||||
|
DB users should use DB.put(k, v) when they want to store duplicates; not
|
||||||
|
DB[k] = v.
|
||||||
|
|
||||||
- Bug #1686475: Support stat'ing open files on Windows again.
|
- Bug #1686475: Support stat'ing open files on Windows again.
|
||||||
|
|
||||||
- Patch #1185447: binascii.b2a_qp() now correctly quotes binary characters
|
- Patch #1185447: binascii.b2a_qp() now correctly quotes binary characters
|
||||||
|
|
|
@ -1836,21 +1836,6 @@ DB_open(DBObject* self, PyObject* args, PyObject* kwargs)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 && (DBVER >= 41)
|
|
||||||
if ((!txn) && (txnobj != Py_None) && self->myenvobj
|
|
||||||
&& (self->myenvobj->flags & DB_INIT_TXN))
|
|
||||||
{
|
|
||||||
/* If no 'txn' parameter was supplied (no DbTxn object and None was not
|
|
||||||
* explicitly passed) but we are in a transaction ready environment:
|
|
||||||
* add DB_AUTO_COMMIT to allow for older pybsddb apps using transactions
|
|
||||||
* to work on BerkeleyDB 4.1 without needing to modify their
|
|
||||||
* DBEnv or DB open calls.
|
|
||||||
* TODO make this behaviour of the library configurable.
|
|
||||||
*/
|
|
||||||
flags |= DB_AUTO_COMMIT;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MYDB_BEGIN_ALLOW_THREADS;
|
MYDB_BEGIN_ALLOW_THREADS;
|
||||||
#if (DBVER >= 41)
|
#if (DBVER >= 41)
|
||||||
err = self->db->open(self->db, txn, filename, dbname, type, flags, mode);
|
err = self->db->open(self->db, txn, filename, dbname, type, flags, mode);
|
||||||
|
@ -1864,6 +1849,8 @@ DB_open(DBObject* self, PyObject* args, PyObject* kwargs)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self->db->get_flags(self->db, &self->setflags);
|
||||||
|
|
||||||
self->flags = flags;
|
self->flags = flags;
|
||||||
RETURN_NONE();
|
RETURN_NONE();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue