Roundtrip SQL data especially datetime
dyork
reverseyorkage at david.com
Fri Dec 15 23:27:54 EST 2006
"John Machin" <sjmachin at lexicon.net> wrote in message
news:1166211949.065578.292600 at f1g2000cwa.googlegroups.com...
> I suppose it all depends on your definition of obvious :-)
I was looking for a constructor that was the complement of str(). Most/many
languages would provide that. Sometimes it's called parse().
> The constructor is datetime.datetime(year, ....., second) so the
> following (which works all the way back to Python 2.3) seems not too
> obscure to me:
But unobvious in a different way :). Thanks, I'll use that.
> If you have, as you should, Python 2.5, you can use this:
I would like to do that, but the tools I need are not released in 2.5 yet.
RSN!
> How do you push a str or float object back into an SQL column of
> appropriate type? What's the difference? Your DB API should handle this
> quite transparently. Try it and see what happens.
Most values tend to work, but only because the SQL string representation
happens to be the same as the Python representation. That may not apply to
some float values, bool, perhaps others. I had hoped the tools would have
solved those problems so I don't have to. In typed languages (Java, C#)
those things tend to just work.
DY
More information about the Python-list
mailing list