Oy...this turned out to be due to my own fiddling with the DB outside
of sqlalchemy, where I swapped out the user_snapshot table with a copy
that had

  id int primary key

instead of

  id integer primary key

Apparently sqlite treats these differently:

sqlite> create table a (a integer primary key, b integer);
sqlite> insert into a (b) values (0);
sqlite> select * from a;
1|0
sqlite> create table b (a int primary key, b integer);
sqlite> insert into b (b) values (0);
sqlite> select * from b;
|0

I couldn't find in http://www.sqlite.org/autoinc.html or
http://www.sqlite.org/datatype3.html any mention of this peculiar
distinguishing behavior.  Anyway, that's that.

On Fri, Nov 18, 2011 at 4:45 PM, Yang Zhang <yanghates...@gmail.com> wrote:
> I'm using sqlalchemy 0.6.6 and sqlite 3.6.22 on Python 2.6.  When I do:
>
>    In [1]: for i in ses.query(UserSnapshot):
>       ...:     print i
>       ...:     if i is None: break
>       ...:
>
> I see:
>
>    ...
>    <twopt.UserSnapshot object at 0x86a52f50>
>    <twopt.UserSnapshot object at 0x86a55050>
>    <twopt.UserSnapshot object at 0x86a55110>
>    <twopt.UserSnapshot object at 0x86a551d0>
>    <twopt.UserSnapshot object at 0x86a55290>
>    <twopt.UserSnapshot object at 0x86a55350>
>    None
>
> My schema:
>
>    class User(Base):
>      __tablename__ = 'user'
>      id = Column(Integer, primary_key=True)
>      blob = Column(LargeBinary, nullable=False)
>      since = Column(DateTime, nullable=False)
>
>    class UserSnapshot(Base):
>      __tablename__ = 'user_snapshot'
>      id = Column(Integer, primary_key=True)
>      uid = Column(Integer, ForeignKey(User.id), nullable=False)
>      blob = Column(LargeBinary, nullable=False)
>      time = Column(DateTime, nullable=False)
>
> Short of dumping my entire DB, any hints as to what might cause `None`
> to be returned?  I searched the documentation but couldn't find any
> leads.  Thanks.
>
> --
> Yang Zhang
> http://yz.mit.edu/
>



-- 
Yang Zhang
http://yz.mit.edu/

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to