Here is code that works for me:

from datetime import datetime
from sqlalchemy import Column, DateTime, Integer, create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('sqlite://', echo=True)

Base = declarative_base(engine)

Session = sessionmaker()
session = Session()

class LogEntry(Base):
    """Log class"""

    __tablename__ = 'log'

    #common data
    id = Column(Integer, primary_key=True)
    timestamp = Column(DateTime)

    def __init__(self):
        self.timestamp = datetime.now()

log = LogEntry()

Base.metadata.create_all()

session.add(log)
session.flush()

log = session.query(LogEntry).one()

print type(log.timestamp)


On Thursday, June 21, 2012 2:35:24 PM UTC+2, Fabien Ribes wrote:
>
> Hi all, 
>
> I'm using Python 2.6.5 and SQLAlchemy-0.7.8 over sqlite3 to store and 
> retrieve logs with in table like this :
>
> class LogEntry(Base):
>     """Log class"""
>     
>     __tablename__ = 'log'
>     
>     #common data
>     id = Column(Integer, primary_key=True)
>     timestamp = Column(DateTime())
>
> When querying back object, how comes I get unicode string in timestamp 
> attribute ? Isn't SA supposed to convert ISO formatted string stored in 
> sqlite back to python datetime object ?
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/N6IlGbBTzyUJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to