Merge pull request #284 from al42and/upsert_id
Fix bug when UPSERTing a column named 'id'
This commit is contained in:
commit
6baff6fa34
@ -29,8 +29,14 @@ class Table(object):
|
|||||||
self.name = normalize_table_name(table_name)
|
self.name = normalize_table_name(table_name)
|
||||||
self._table = None
|
self._table = None
|
||||||
self._indexes = []
|
self._indexes = []
|
||||||
self._primary_id = primary_id
|
if primary_id is not None:
|
||||||
self._primary_type = primary_type
|
self._primary_id = primary_id
|
||||||
|
else:
|
||||||
|
self._primary_id = self.PRIMARY_DEFAULT
|
||||||
|
if primary_type is not None:
|
||||||
|
self._primary_type = primary_type
|
||||||
|
else:
|
||||||
|
self._primary_type = Types.integer
|
||||||
self._auto_create = auto_create
|
self._auto_create = auto_create
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -235,8 +241,8 @@ class Table(object):
|
|||||||
if self._primary_id is not False:
|
if self._primary_id is not False:
|
||||||
# This can go wrong on DBMS like MySQL and SQLite where
|
# This can go wrong on DBMS like MySQL and SQLite where
|
||||||
# tables cannot have no columns.
|
# tables cannot have no columns.
|
||||||
primary_id = self._primary_id or self.PRIMARY_DEFAULT
|
primary_id = self._primary_id
|
||||||
primary_type = self._primary_type or Types.integer
|
primary_type = self._primary_type
|
||||||
increment = primary_type in [Types.integer, Types.bigint]
|
increment = primary_type in [Types.integer, Types.bigint]
|
||||||
column = Column(primary_id, primary_type,
|
column = Column(primary_id, primary_type,
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
|
|||||||
@ -232,6 +232,12 @@ class TableTestCase(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
assert len(self.tbl) == len(TEST_DATA) + 1, len(self.tbl)
|
assert len(self.tbl) == len(TEST_DATA) + 1, len(self.tbl)
|
||||||
|
|
||||||
|
def test_upsert_id(self):
|
||||||
|
table = self.db['banana_with_id']
|
||||||
|
data = dict(id=10, title='I am a banana!')
|
||||||
|
table.upsert(data, ['id'])
|
||||||
|
assert len(table) == 1, len(table)
|
||||||
|
|
||||||
def test_update_while_iter(self):
|
def test_update_while_iter(self):
|
||||||
for row in self.tbl:
|
for row in self.tbl:
|
||||||
row['foo'] = 'bar'
|
row['foo'] = 'bar'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user