On Sep 8, 6:18 pm, "Michael Bayer" <mike...@zzzcomputing.com> wrote:
> "julianday" being a SQLite function ?  i.e. you'd like SQLite to do the
> date arithmetic from the ISO value for you ?  or you'd like your custom
> type to provide the "julianday" numeric value ?
>
> better yet, to ensure perfect clarity here, provide a plain pysqlite
> script that illustrates what API/sqlite features you'd like to use.

Yes, julianday is sqlite function. It accepts ISO string and returns
julianday number. SQLite's datetime stuff description can be found
here: http://sqlite.org/lang_datefunc.html

I'll try to explain what I want to achieve.
I have the table description:

dates_table = Table('dates', md,
                    Column('id', Integer, primary_key=True),
                    Column('dt', sqlalchemy.DateTime),
                    )

I have the mapping:

class Record:
    def __init__(self, dt):
        self.dt = dt

    def __repr__(self):
        return "<Record({0})>".format(self.dt)

mapper(Record, dates_table)

Now I'm adding the object into the DB:

session.add(Record(datetime.utcnow()))
session.commit()

It produces the following query:
INSERT INTO dates (dt) VALUES (?)

I want the following instead (for sqlite only):
INSERT INTO dates(dt) VALUES(julianday(?))

Also when retrieving or filtering, instead of
SELECT id, dt FROM dates WHERE dt < ?

I want:
SELECT id, strftime('%Y-%m-%d %H:%M:%f', dt) FROM dates WHERE dt <
julianday(?)

So only textual modifications to the queries are needed. Values to and
from the query shall be passed as it is now, as ISO strings.

Thanks for your help.
--~--~---------~--~----~------------~-------~--~----~
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