Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #85770 > unrolled thread

sqlite3 and dates

Started by"Frank Millman" <frank@chagford.com>
First post2015-02-18 08:19 +0200
Last post2015-02-19 04:45 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  sqlite3 and dates "Frank Millman" <frank@chagford.com> - 2015-02-18 08:19 +0200
    Re: sqlite3 and dates Steve Hayes <hayesstw@telkomsa.net> - 2015-02-19 04:45 +0200

#85770 — sqlite3 and dates

From"Frank Millman" <frank@chagford.com>
Date2015-02-18 08:19 +0200
Subjectsqlite3 and dates
Message-ID<mailman.18804.1424240380.18130.python-list@python.org>
Hi all

sqlite3 does not have a DATE type, but the python module does a pretty good 
job of providing one -

>>> import sqlite3
>>> conn = sqlite3.connect(':memory:', detect_types=sqlite3.PARSE_DECLTYPES)
>>> cur = conn.cursor()
>>> cur.execute('CREATE TABLE test (dob DATE)')
<sqlite3.Cursor object at 0x00FE9BE0>
>>> cur.execute('INSERT INTO TEST (dob) VALUES (?)', ('2015-03-31',))
<sqlite3.Cursor object at 0x00FE9BE0>
>>> cur.execute('SELECT * FROM test')
<sqlite3.Cursor object at 0x00FE9BE0>
>>> cur.fetchone()
(datetime.date(2015, 3, 31),)
>>>

However, the following does not return a date object -

>>> cur.execute('SELECT CAST(? AS DATE)', ('2015-03-31',))
<sqlite3.Cursor object at 0x00FE9BE0>
>>> cur.fetchone()
(2015,)
>>>

I don't know how easy this would be to implement, but it would be nice if it 
could be made to work.

Is it worth filing a feature request?

Frank Millman


[toc] | [next] | [standalone]


#85841

FromSteve Hayes <hayesstw@telkomsa.net>
Date2015-02-19 04:45 +0200
Message-ID<lbjaeapp7927m900csrviaoh99mv4rrjdj@4ax.com>
In reply to#85770
On Wed, 18 Feb 2015 08:19:25 +0200, "Frank Millman"
<frank@chagford.com> wrote:

>Hi all
>
>sqlite3 does not have a DATE type, but the python module does a pretty good 
>job of providing one -

The Rootsmagic genealogy program uses SQLite for its database, 

I don't know whether or to what extent it uses Python to interac t
with the database, but it seems to do a pretty good job of handling
dates, calculating ages etc. 

http://www.rootsmagic.com/


-- 
Steve Hayes from Tshwane, South Africa
Web:  http://www.khanya.org.za/stevesig.htm
Blog: http://khanya.wordpress.com
E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web