Merge commit '2566581442eff9b17ee439296e7c4e9c232cee26'
This commit is contained in:
commit
ec9a2c56d1
@ -1,5 +1,9 @@
|
|||||||
import logging
|
import logging
|
||||||
from itertools import count
|
from itertools import count
|
||||||
|
try:
|
||||||
|
from collections import OrderedDict
|
||||||
|
except ImportError:
|
||||||
|
from ordereddict import OrderedDict # Python < 2.7 drop-in
|
||||||
|
|
||||||
from sqlalchemy.sql import and_, expression
|
from sqlalchemy.sql import and_, expression
|
||||||
from sqlalchemy.schema import Column, Index
|
from sqlalchemy.schema import Column, Index
|
||||||
@ -281,7 +285,7 @@ class Table(object):
|
|||||||
rp = self.database.executable.execute(query)
|
rp = self.database.executable.execute(query)
|
||||||
data = rp.fetchone()
|
data = rp.fetchone()
|
||||||
if data is not None:
|
if data is not None:
|
||||||
return dict(zip(rp.keys(), data))
|
return OrderedDict(zip(rp.keys(), data))
|
||||||
|
|
||||||
def _args_to_order_by(self, order_by):
|
def _args_to_order_by(self, order_by):
|
||||||
if order_by[0] == '-':
|
if order_by[0] == '-':
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from inspect import isgenerator
|
from inspect import isgenerator
|
||||||
|
try:
|
||||||
|
from collections import OrderedDict
|
||||||
|
except ImportError:
|
||||||
|
from ordereddict import OrderedDict # Python < 2.7 drop-in
|
||||||
|
|
||||||
from sqlalchemy import Integer, UnicodeText, Float, DateTime, Boolean
|
from sqlalchemy import Integer, UnicodeText, Float, DateTime, Boolean
|
||||||
|
|
||||||
@ -46,7 +50,7 @@ class ResultIter(object):
|
|||||||
else:
|
else:
|
||||||
# stop here
|
# stop here
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
return dict(zip(self.keys, row))
|
return OrderedDict(zip(self.keys, row))
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
|
|||||||
@ -244,5 +244,11 @@ class TableTestCase(unittest.TestCase):
|
|||||||
assert FLOAT == type(tbl.table.c['foo'].type), tbl.table.c['foo'].type
|
assert FLOAT == type(tbl.table.c['foo'].type), tbl.table.c['foo'].type
|
||||||
assert 'foo' in tbl.columns, tbl.columns
|
assert 'foo' in tbl.columns, tbl.columns
|
||||||
|
|
||||||
|
def test_key_order(self):
|
||||||
|
res = self.db.query('SELECT temperature, place FROM weather LIMIT 1')
|
||||||
|
keys = res.next().keys()
|
||||||
|
assert keys[0] == 'temperature'
|
||||||
|
assert keys[1] == 'place'
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user