[development] Do not let postgresql hold back great patches

Larry Garfield larry at garfieldtech.com
Mon Dec 3 06:49:01 UTC 2007

On Monday 03 December 2007, adrian rossouw wrote:
> On 03 Dec 2007, at 6:38 AM, Larry Garfield wrote:
> > #3 is what I'm pushing for in the D7 database overhaul, within
> > reason.  How to
> > abstract everything without making the syntax insane or the
> > performance
> > terrible is what I'm currently trying to wrap my head around.  The
> > biggest
> > problem is field type handling, which I want to keep away from module
> > developers but varies greatly depending on the database.
> and the biggest issue here is date / time types.
> it's fscking crazy how different these are between databases.

Actually, that one I think I have a solution for, or the beginnings of one.  
In PHP 5, there is the DateTime class to represent a date/time in some 
timezone.  It's great, but not a proper value object.  Writing a value object 
around DateTime is easy, however, and I've already done one.  

So, each database driver defines internally its own format string to convert a 
DateTime/DateValue class into the string format it expects for a date/time 
stamp.  The database driver then detects the presence of an object as an 
argument to a query/prepared statement and formats it to its desired format, 
which is then inserted into the query.  That works for putting a date/time 
value into a query (be it insert, update, delete, or select).  For reading, I 
believe we can use schema API to check if a field is a timestamp field and 
then cast it back to a DateValue object.  What the performance implication of 
that is, though, I do not know.  It may be something that we just have to 
swallow if we want real database independence, along with always using an 
object to represent a date/time (which I think we should be doing anyway).

As for in-SQL operations on the date value, like MONTH() or YEAR() in MySQL?  
If someone has an idea for those that doesn't involve regexing every query I 
would dearly love to hear it. :-)

Larry Garfield			AIM: LOLG42
larry at garfieldtech.com		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 

More information about the development mailing list