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


Groups > comp.lang.python > #85775

Re: sqlite3 and dates

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!lightspeed.eweka.nl!lightspeed.eweka.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'type,': 0.09; 'python': 0.11; 'wrote': 0.14; '"mark': 0.16; 'before.': 0.16; 'fine.': 0.16; 'magic': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:dates': 0.16; 'subject:sqlite3': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'looked': 0.18; 'module': 0.19; 'looks': 0.24; 'header:X-Complaints-To:1': 0.27; 'but': 0.35; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'providing': 0.61; 'frank': 0.68; 'useful.': 0.68; 'experiment': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From "Frank Millman" <frank@chagford.com>
Subject Re: sqlite3 and dates
Date Wed, 18 Feb 2015 10:22:04 +0200
References <mc1atd$cq0$1@ger.gmane.org> <mc1g3n$q8j$1@ger.gmane.org>
X-Gmane-NNTP-Posting-Host 197.86.206.166
X-MSMail-Priority Normal
X-Newsreader Microsoft Outlook Express 6.00.3790.4657
X-RFC2646 Format=Flowed; Response
X-MimeOLE Produced By Microsoft MimeOLE V6.00.3790.4913
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.18809.1424247734.18130.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424247734 news.xs4all.nl 2940 [2001:888:2000:d::a6]:50673
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 3353
X-Received-Body-CRC 48313005
Xref csiph.com comp.lang.python:85775

Show key headers only | View raw


"Mark Lawrence" <breamoreboy@yahoo.co.uk> wrote in message 
news:mc1g3n$q8j$1@ger.gmane.org...
> On 18/02/2015 06:19, Frank Millman wrote:
>> Hi all
>>
>> sqlite3 does not have a DATE type, but the python module does a pretty 
>> good
>> job of providing one -
>>
>> 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,)
>>>>>
>>
>
> Will this do?
>
> cur.execute('select current_date as "d [date]", current_timestamp as "ts 
> [timestamp]"')
> row = cur.fetchone()
> print("current_date", row[0], type(row[0]))
> print("current_timestamp", row[1], type(row[1]))
>


I will have to experiment a bit, It looks as if it will do just fine.

The magic incantation is 
'detect_types=sqlite3.PARSE_DECLTYPES|PARSE_COLNAMES'

I had not looked at PARSE_COLNAMES before. Very useful.

Thanks, Mark

Frank


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: sqlite3 and dates "Frank Millman" <frank@chagford.com> - 2015-02-18 10:22 +0200

csiph-web