From: Frederik E. <fre...@a5...> - 2005-11-09 15:25:36
Attachments:
hsql.patch
|
Hi, I just added a new SqlBind instance to HSQL.hsc instance SqlBind a => SqlBind (Maybe a) which returns NULL values as Nothing. I needed this because I'm using an algorithm that uses NULL values and I didn't want to have to call getFieldValueMB all the time. Actually I'm using my own wrapper module which uses heterogenous lists so handling NULL values through the type system is just much more convenient for me: http://ofb.net/~frederik/futility/src/HSQLExtras.hs Anyway, it was a bit of work to add this. I had to add a new method to the SqlBind class fromSqlCStringLen :: SqlType -> CString -> Int -> IO (Maybe a) fromSqlCStringLen sqlType cstr cstrLen = if cstr == nullPtr then return Nothing else fromNonNullSqlCStringLen sqlType cstr cstrLen to be used instead of fromNonNullSqlCStringLen :: SqlType -> CString -> Int -> IO (Maybe a) This is because apparently NULL values originally get into the system as nullPtr's, so SqlBind needs to be able to know about those nullPtr's in order to process NULL values. Now getFieldValueMB passes fromSqlCStringLen rather than fromNonNullSqlCStringLen to the driver. The drivers have to be updated to make use of this feature - currently they intercept NULL values and return Nothing, but they have to be changed so that they pass these along to value extractor (which will return Just Nothing in the case of my new instance). If they aren't changed, the old behavior will just be preserved so it's *not* necessary to change all of them at once. I updated MySQL (tested) and PostgreSQL (not tested), so you can see what has to be done. Now I can write something like this (it uses another wrapper, http://ofb.net/~frederik/futility/src/DBTool.hs) query0 (sql "insert into $bar values (2,null)") Just ((a::Maybe Int) :. (b::Maybe Int) :. Nil) <- query1 (sql "select * from $bar limit 1") print (a,b) ==> (Just 2,Nothing) I hope this patch is suitable. If it isn't accepted then I'll have to create my own fork of the library, because I depend on this feature in other stuff I'm distributing. Cheers, Frederik |
From: Frederik E. <fre...@a5...> - 2006-07-31 10:55:48
Attachments:
hsql.patch
|
Hi, I'm attaching another HSQL patch. It allows users to specify a port number with the server name in the MySQL client. Frederik -- http://ofb.net/~frederik/ |
From: Frederik E. <fre...@a5...> - 2006-08-10 15:19:31
|
In HSQL, why are 'datetime' columns interpreted as being in the local timezone? I would think that UTC would be more useful. If the local timezone is used, then it makes it more difficult to move a server between timezones, or to have multiple servers in multiple timezones. Frederik On Sat, Aug 05, 2006 at 06:59:21PM +0100, Frederik Eaton wrote: > Thanks! >=20 > On Sat, Aug 05, 2006 at 05:27:04PM +0200, Bjorn Bringert wrote: > > On Aug 5, 2006, at 3:34 PM, Frederik Eaton wrote: > >=20 > > >On Sat, Aug 05, 2006 at 11:15:19AM +0200, Bjorn Bringert wrote: > > >>On Jul 31, 2006, at 12:55 PM, Frederik Eaton wrote: > > >> > > >>>Hi, > > >>> > > >>>I'm attaching another HSQL patch. > > >>> > > >>>It allows users to specify a port number with the server name in t= he > > >>>MySQL client. > > >>> > > >>>Frederik > > >> > > >>Hi Frederik, > > >> > > >>the patch doesn't apply cleanly against the current CVS version. Is > > >>there any chance you could make a patch against the CVS version > > >>instead? > > > > > >It's a very simple modification, can't you just copy and paste from > > >the patch? > >=20 > > It appears to have been a simple whitespace mismatch problem (tabs in= the original HSQL source). I=20 > > have committed your patch to CVS. > >=20 > > Thanks! > >=20 > > /Bj=F6rn > >=20 > >=20 > >=20 >=20 > --=20 > http://ofb.net/~frederik/ >=20 --=20 http://ofb.net/~frederik/ |
From: Frederik E. <fre...@a5...> - 2006-08-23 01:18:13
|
Hi, Here is another patch. Many schemata, for instance that of Wikipedia, use "tinyint" as a synonym for "bit". So I thought it would be good to support those: ---------------------------------------------------------------- diff -ur HSQL-1.7-modified-2/HSQL/Database/HSQL.hsc HSQL-1.7-modified-3/HSQL/Database/HSQL.hsc --- HSQL-1.7-modified-2/HSQL/Database/HSQL.hsc 2006-08-23 02:14:59.000000000 +0100 +++ HSQL-1.7-modified-3/HSQL/Database/HSQL.hsc 2006-08-23 02:15:34.000000000 +0100 @@ -277,6 +277,7 @@ instance SqlBind Bool where fromSqlValue SqlBit s = Just (s == "t") + fromSqlValue SqlTinyInt s = Just (read s /= (0::Int)) fromSqlValue _ _ = Nothing toSqlValue True = "'t'" ---------------------------------------------------------------- Are these patches making it in? Thanks, Frederik -- http://ofb.net/~frederik/ |
From: <bri...@cs...> - 2006-08-25 09:26:14
|
Thanks, committed. /Bj=F6rn Frederik Eaton wrote: > Hi, >=20 > Here is another patch. Many schemata, for instance that of Wikipedia, > use "tinyint" as a synonym for "bit". So I thought it would be good to > support those: >=20 > ---------------------------------------------------------------- > diff -ur HSQL-1.7-modified-2/HSQL/Database/HSQL.hsc HSQL-1.7-modified-3= /HSQL/Database/HSQL.hsc > --- HSQL-1.7-modified-2/HSQL/Database/HSQL.hsc 2006-08-23 02:14:59.000= 000000 +0100 > +++ HSQL-1.7-modified-3/HSQL/Database/HSQL.hsc 2006-08-23 02:15:34.000= 000000 +0100 > @@ -277,6 +277,7 @@ > =20 > instance SqlBind Bool where > fromSqlValue SqlBit s =3D Just (s =3D=3D "t") > + fromSqlValue SqlTinyInt s =3D Just (read s /=3D (0::Int)) > fromSqlValue _ _ =3D Nothing > =20 > toSqlValue True =3D "'t'" > ---------------------------------------------------------------- >=20 > Are these patches making it in? >=20 > Thanks, >=20 > Frederik >=20 |