May 9, 2008

Trouble Getting a Date

Filed under: database, python — Andy Todd @ 8:04 am

I’m having trouble with dates. This can be summed up in a couple of high level issues;

1. Date support in relational databases is insane, or at the best inconsistent.

As far as I can tell the ANSI SQL-92 standard defines date, time, interval and timestamp data types. Which doesn’t help when SQL Server only implements something called ‘datetime’ - at least I think so, have you tried accessing any sort of manual for a Microsoft product online? Blimey, I thought billg had embraced this web thing years ago. Oracle has the ‘date’ data type (which is actually a time stamp) and MySQL, well they’ve gone and outdone everyone by implementing DATETIME, DATE, TIMESTAMP, TIME, and YEAR.

2. The Python DB-API does not cope with date data type ambiguity well.

When it comes to the date question the Python DB-API states (and I quote) ” … may use mx.DateTime”, which if you ask me isn’t much of a standard. This needs to change so that all DB-API modules return consistent datetime objects, not such a big issue as datetime has been part of the standard library since, what, Python 2.3?

Sadly even if we fix this it won’t work with Sqlite as it doesn’t consistently support data typing. In my experiments regardless of what sort of date you insert into the database you get a unicode string back. Don’t believe me? Try this in Python 2.5;

>>> from sqlite3 import dbapi2
>>> db = dbapi2.connect('test_db')
>>> cursor = db.cursor()
>>> cursor.execute('create table date_test (id integer not null primary key autoincrement, sample_date DATE NOT NULL)'
>>> stmt = "INSERT INTO date_test (sample_date) VALUES (?)"
>>> cursor.execute(stmt, (1234, ))
>>> import datetime
>>> cursor.execute(stmt, (datetime.date(2008, 3, 10), ))
>>> cursor.execute(stmt, ('My name is Earl', ))
>>> db.commit()
>>> cursor.execute("SELECT * FROM date_test")
>>> results = cursor.fetchall()
>>> for item in results:
...     print item[1], type(item[1])
1234 
2008-03-10 
My name is Earl 
>>>

But note that it is fine for integers.

3. The people writing the Python standard library modules are on crack.

Outside of the database world and within the batteries included Python standard library some modules use datetime, others time and there are even uses of calendar.

O.K. I’ll accept that maybe the module authors aren’t on full strength crack, because the time module just exposes underlying posix functions. But the people who wrote those were on something strong and hallucinogenic. I table the following function signatures from section 14.2 of the Python Library Reference 2.5 as an example;

strftime(format[, t ])
strptime(string[, format ])

This has bitten me twice in the last twenty four hours and frankly I’m not happy.

I appreciate that there are historical reasons for having inconsistent function signatures but can someone please fix this in Python 3.0. All we need is a single module that can access the underlying system clock and then convert between a number of different representations of that and other epoch driven dates. How hard can it be? As far as I can tell this is not part of the proposed standard library re-organisation. I think it should be.

April 30, 2008

May Sydney Python Meeting

Filed under: python — Andy Todd @ 11:51 am

This Thursday, the 1st of May, 2008 from 6:30pm there will be a social gathering of the Sydney Python Users Group and any individuals interested in discussing Python, Web, Ruby, Perl etc.

Laptops, OLPC’s, code review, show and tell etc allowed and encouraged.

We meet in the ground floor area next to P.J. O’Briens Pub internal entrance in the;

Grace Hotel at the corner of York and King Street in Sydney, New South Wales 2000. See you there

February 3, 2008

February Sydney Python Meetup

Filed under: python — Andy Todd @ 9:26 am

Checking my calendar it would appear that one month of the new year already gone. Which must mean that this Thursday, the 7th of February, 2008 from 6:30pm, there will be a social gathering of Sydney Python Users Group and any individuals interested in discussing Python, Web, Ruby, Perl etc.

Laptops, code review, show and tell etc allowed and encouraged.

We meet in the ground floor area next to P.J. O’Briens Pub internal entrance in the Grace Hotel, at the corner of York and King Streets in Sydney, New South Wales. See you there.

January 20, 2008

Gerald release 0.2.2

Filed under: database, python — Andy Todd @ 7:11 am

I have packaged and released version 0.2.2 of gerald. You can find all of the details on the project page but in a nutshell the changes from the last release are;

  • A serious bug in the packaging script has been fixed and the distributed archive is now complete and valid.

Bug reports, patches and test cases to the usual email address please. Or just a message to let me know you are using the code would be nice.

November 29, 2007

December Sydney Python Meeting

Filed under: python — Andy Todd @ 9:37 pm

On Thursday the 6th of December, 2007 from 6:30PM, there will be a social gathering of the Sydney Python Users Group. Any individuals interested in discussing Python, Web, Ruby, Perl etc. are welcomed, nay encouraged, to attend. Laptops, code review, show and tell etc. are allowed and encouraged.

We meet in the ground floor area next to P.J. O’Briens Pub internal entrance in the Grace Hotel at the corner of York and King Street, Sydney, New South Wales 2000.

I’m going to do my best to be there, although my new job is keeping me somewhat busy. I should turn up even if it is only to increase the level of sartorial elegance and to show off my shiny new Macbook.

September 30, 2007

Gerald release 0.2.1

Filed under: database, python — Andy Todd @ 4:01 pm

I have packaged and released version 0.2.1 of gerald. You can find all of the details on the project page but in a nutshell the changes from the last release are;

Bug reports, patches and test cases to the usual email address please. Or just a message to let me know you are using the code, that would be nice.

September 11, 2007

September Sydney Python Meetup

Filed under: python — Andy Todd @ 12:59 pm

On Thursday the 13th of September, 2007 from 6:30PM, there will be a social gathering of Sydney Python Users Group and any individuals interested in discussing Python, Web, Ruby, Perl etc. Laptops, code review, show and tell etc. allowed and encouraged.

We meet in the ground floor area next to P.J. O’Briens Pub internal entrance in the Grace Hotel at the corner of York and King Street, Sydney, New South Wales 2000.

If you are planning on coming please register your attendance at upcoming.

August 2, 2007

Laws of Software Development

Filed under: python — Andy Todd @ 12:14 pm

There have been recent flurries of blog posts talking about various laws of software development (part 1, part 2). I’d like to provide my own addition.

Todd’s adaptation of Greenspun’s Tenth Rule

"Any sufficiently complicated Python application contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of the standard library."

August Sydney Python Meetup

Filed under: python — Andy Todd @ 11:57 am

Its the monthly Sydney Python get together this evening. I’ll be there consuming a couple of cold drinks, will you?

July 12, 2007

In Search of Technologists

Filed under: General, database, python — Andy Todd @ 5:52 pm

In my new executive position I’m responsible for maintaining adequate staffing levels in the technology department of my company. We are pretty much staffed up at the moment but there are some potential projects on the horizon that will tax the capacity of my team. In a novel fit of forward planning I’m trying to find a consulting partner who will be able to help us in these times of high workload. It is proving quite tricky.

So, dear lazyweb, do you know of any reputable consulting companies who will fit our bill. They must be;

  1. On the ground in Australia. A Sydney office is a bonus.
  2. Have competencies in one or more of; Python, PostgreSQL and scaling internet applications
  3. Have a track record and reputable references. I will be checking.
  4. Not cost the earth. Although I’m very aware of how much consultants cost, having been one myself for most of the last fifteen years.

Any and all suggestions are welcomed in the comments or to my email address. As long as they fit our criteria. Outsourcing and offshore development are not an option at this time so please don’t suggest these.

Next Page »

Powered by WordPress