Jun-01-2020, 10:48 AM
I have been using sqlalchemy both within and without Flask and never had ant issues.
I know that my model is OK as I use it to populate my database.
However when trying to do a simple query, I'm getting improper results.
First I tested a standard select statement using DB Browser:
and it returns the correct result '005'
then I try sqlalchemy.orm query and get wrong value (which happens to be in the first row of the table.
001 is the first CountyId in the table, result should have been 005
I don't know if I'm just too tired and can't see what's wrong (been up most of the night), but I don't see what I am doing wrong?
I've done this sort of thing numerous times in the past and never had a problem.
Can anyone see my obvious mistake?
I know that my model is OK as I use it to populate my database.
However when trying to do a simple query, I'm getting improper results.
First I tested a standard select statement using DB Browser:
select CountyId from CountyInfo where StateAbbr = 'IL' and CountyName = 'Bond County';
and it returns the correct result '005'
then I try sqlalchemy.orm query and get wrong value (which happens to be in the first row of the table.
1 2 3 4 5 6 7 8 9 10 |
>>> from sqlalchemy.orm import sessionmaker >>> import IL_Model >>> tmap = IL_Model >>> db = tmap.engine >>> Session = sessionmaker(bind = db) >>> session = Session() >>> ci = tmap.CountyInfo >>> county_id = session.query(ci.CountyId). filter (ci.StateAbbr = = 'IL' and ci.CountyName = = "Bond County" ).first() >>> county_id ( '001' ,) |
I don't know if I'm just too tired and can't see what's wrong (been up most of the night), but I don't see what I am doing wrong?
I've done this sort of thing numerous times in the past and never had a problem.
Can anyone see my obvious mistake?