From: <br...@us...> - 2004-06-11 09:38:22
|
Update of /cvsroot/htoolkit/HSQL/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17340/src Modified Files: HSQL.hsc Log Message: Allow converting SqlText values to numeric and date values to support SQLite which reports the types of all columns as SqlText. Index: HSQL.hsc =================================================================== RCS file: /cvsroot/htoolkit/HSQL/src/HSQL.hsc,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** HSQL.hsc 31 May 2004 12:30:15 -0000 1.14 --- HSQL.hsc 11 Jun 2004 09:38:04 -0000 1.15 *************** *** 211,214 **** --- 211,215 ---- fromSqlValue SqlBigInt s = Just (read s) fromSqlValue SqlDouble s = Just (truncate (read s :: Double)) + fromSqlValue SqlText s = Just (read s) fromSqlValue _ _ = Nothing *************** *** 235,238 **** --- 236,240 ---- fromSqlValue SqlBigInt s = Just (read s) fromSqlValue SqlDouble s = Just (truncate (read s :: Double)) + fromSqlValue SqlText s = Just (read s) fromSqlValue _ s = Nothing *************** *** 246,249 **** --- 248,252 ---- fromSqlValue SqlBigInt s = Just (read s) fromSqlValue SqlDouble s = Just (truncate (read s :: Double)) + fromSqlValue SqlText s = Just (read s) fromSqlValue _ _ = Nothing *************** *** 275,278 **** --- 278,282 ---- fromSqlValue SqlReal s = Just (read s) fromSqlValue SqlFloat s = Just (read s) + fromSqlValue SqlText s = Just (read s) fromSqlValue _ _ = Nothing *************** *** 304,307 **** --- 308,336 ---- f_read f s = case readP_to_S f s of {[(x,_)] -> Just x} + readHMS :: ReadP (Int, Int, Int) + readHMS = do + hour <- readDecP + char ':' + minutes <- readDecP + char ':' + seconds <- readDecP + return (hour, minutes, seconds) + + readYMD :: ReadP (Int, Int, Int) + readYMD = do + year <- readDecP + char '-' + month <- readDecP + char '-' + day <- readDecP + return (year, month, day) + + readDateTime :: ReadP (Int, Int, Int, Int, Int, Int) + readDateTime = do + (year, month, day) <- readYMD + skipSpaces + (hour, minutes, seconds) <- readHMS + return (year, month, day, hour, minutes, seconds) + instance SqlBind ClockTime where fromSqlValue SqlTimeTZ s = f_read getTimeTZ s *************** *** 309,320 **** getTimeTZ :: ReadP ClockTime getTimeTZ = do ! hour <- readDecP ! char ':' ! minutes <- readDecP ! char ':' ! seconds <- readDecP ! (char '.' >> readDecP) `mplus` (return 0) ! tz <- parseTZ ! return (mkClockTime 1970 1 1 hour minutes seconds (tz*3600)) fromSqlValue SqlTime s = f_read getTime s --- 338,345 ---- getTimeTZ :: ReadP ClockTime getTimeTZ = do ! (hour, minutes, seconds) <- readHMS ! (char '.' >> readDecP) `mplus` (return 0) ! tz <- parseTZ ! return (mkClockTime 1970 1 1 hour minutes seconds (tz*3600)) fromSqlValue SqlTime s = f_read getTime s *************** *** 322,331 **** getTime :: ReadP ClockTime getTime = do ! hour <- readDecP ! char ':' ! minutes <- readDecP ! char ':' ! seconds <- readDecP ! return (mkClockTime 1970 1 1 hour minutes seconds currTZ) fromSqlValue SqlDate s = f_read getDate s --- 347,352 ---- getTime :: ReadP ClockTime getTime = do ! (hour, minutes, seconds) <- readHMS ! return (mkClockTime 1970 1 1 hour minutes seconds currTZ) fromSqlValue SqlDate s = f_read getDate s *************** *** 333,342 **** getDate :: ReadP ClockTime getDate = do ! year <- readDecP ! char '-' ! month <- readDecP ! char '-' ! day <- readDecP ! return (mkClockTime year month day 0 0 0 currTZ) fromSqlValue SqlDateTimeTZ s = f_read getDateTimeTZ s --- 354,359 ---- getDate :: ReadP ClockTime getDate = do ! (year, month, day) <- readYMD ! return (mkClockTime year month day 0 0 0 currTZ) fromSqlValue SqlDateTimeTZ s = f_read getDateTimeTZ s *************** *** 344,358 **** getDateTimeTZ :: ReadP ClockTime getDateTimeTZ = do ! year <- readDecP ! char '-' ! month <- readDecP ! char '-' ! day <- readDecP ! skipSpaces ! hour <- readDecP ! char ':' ! minutes <- readDecP ! char ':' ! seconds <- readDecP char '.' >> readDecP -- ) `mplus` (return 0) tz <- parseTZ --- 361,365 ---- getDateTimeTZ :: ReadP ClockTime getDateTimeTZ = do ! (year, month, day, hour, minutes, seconds) <- readDateTime char '.' >> readDecP -- ) `mplus` (return 0) tz <- parseTZ *************** *** 362,380 **** -- to be the MySQL driver. MySQL (at least 4.1) uses the same format for datetime and -- timestamp columns. ! fromSqlValue t s | t == SqlDateTime || t == SqlTimeStamp = f_read getDateTime s where getDateTime :: ReadP ClockTime getDateTime = do ! year <- readDecP ! char '-' ! month <- readDecP ! char '-' ! day <- readDecP ! skipSpaces ! hour <- readDecP ! char ':' ! minutes <- readDecP ! char ':' ! seconds <- readDecP return (mkClockTime year month day hour minutes seconds currTZ) --- 369,378 ---- -- to be the MySQL driver. MySQL (at least 4.1) uses the same format for datetime and -- timestamp columns. ! -- Allow SqlText to support SQLite, which reports everything as SqlText ! fromSqlValue t s | t == SqlDateTime || t == SqlTimeStamp || t == SqlText = f_read getDateTime s where getDateTime :: ReadP ClockTime getDateTime = do ! (year, month, day, hour, minutes, seconds) <- readDateTime return (mkClockTime year month day hour minutes seconds currTZ) |