Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91179

Re: Camelot a good tool for me

From Lele Gaifax <lele@metapensiero.it>
Subject Re: Camelot a good tool for me
Date 2015-05-24 15:28 +0200
Organization Nautilus Entertainments
References <87fv6ol93p.fsf@nautilus.nautilus> <20150522224229.GA62222@cskk.homeip.net> <CAPTjJmpCuhqTwkxfCW48e8We=9Hp7UG3EeOiynH1nNy_LjnsZw@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.17.1432474106.5151.python-list@python.org> (permalink)

Show all headers | View raw


Chris Angelico <rosuav@gmail.com> writes:

> You don't automatically get nice objects with attributes named after
> columns, but neither will SQLAlchemy unless you're doing the
> equivalent of "select * from". Example:
>
>>>> session.query(Student).all()
> [<__main__.Student object at 0x7fc2de3fc290>, <__main__.Student object
> at 0x7fc2de3fc350>, <__main__.Student object at 0x7fc2de3fc3d0>]
>
> That's a list of Student objects, because I asked for the entire table.
>
>>>> session.query(Student.name, Student.year).all()
> [(u'Fred', 2015), (u'Joe', 2015), (u"Robert'); DROP TABLE Students;--", 2012)]
>
> That's a list of tuples, because I asked for just two columns.

Wrong:

    >>> res = session.query(Student.name, Student.year).all()
    >>> type(res)
    <class 'list'>
    >>> type(res[0])
    <class 'sqlalchemy.util._collections.result'>
    >>> type(res[0].name)
    <class 'str'>
    >>> type(res[0][0])
    <class 'str'>
    >>> res[0].name == res[0][0]
    True

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Camelot a good tool for me Lele Gaifax <lele@metapensiero.it> - 2015-05-24 15:28 +0200

csiph-web