moduleDatabase.HDBC.SqlValue(-- * SQL value marshallingSqlValue(..),safeFromSql,toSql,fromSql,nToSql,iToSql,posixToSql)whereimportData.DynamicimportqualifiedData.ByteString.UTF8asBUTF8importqualifiedData.ByteStringasBimportqualifiedData.ByteString.LazyasBSLimportData.Char(ord,toUpper)importData.WordimportData.IntimportqualifiedSystem.TimeasSTimportData.TimeimportData.Time.Clock.POSIXimportDatabase.HDBC.Locale(defaultTimeLocale,iso8601DateFormat)importData.RatioimportData.ConvertibleimportData.FixedquickError::(Typeablea,ConvertibleSqlValuea)=>SqlValue->ConvertResultaquickErrorsv=convError"incompatible types"sv{- | Convert a value to an 'SqlValue'. This function is simply
a restricted-type wrapper around 'convert'. See extended notes on 'SqlValue'. -}toSql::ConvertibleaSqlValue=>a->SqlValuetoSql=convert{- | Conversions to and from 'SqlValue's and standard Haskell types.
This function converts from an 'SqlValue' to a Haskell value. Many people will use the simpler
'fromSql' instead. This function is simply a restricted-type wrapper around
'safeConvert'. -}safeFromSql::ConvertibleSqlValuea=>SqlValue->ConvertResultasafeFromSql=safeConvert{- | Convert from an 'SqlValue' to a Haskell value. Any problem is indicated by
calling 'error'. This function is simply a restricted-type wrapper around
'convert'. See extended notes on 'SqlValue'. -}fromSql::ConvertibleSqlValuea=>SqlValue->afromSql=convert{- | Converts any Integral type to a 'SqlValue' by using toInteger. -}nToSql::Integrala=>a->SqlValuenToSqln=SqlInteger(toIntegern){- | Convenience function for using numeric literals in your program. -}iToSql::Int->SqlValueiToSql=toSql{- | Convenience function for converting 'POSIXTime' to a 'SqlValue', because
'toSql' cannot do the correct thing in this instance. -}posixToSql::POSIXTime->SqlValueposixToSqlx=SqlPOSIXTimex{- | 'SqlValue' is he main type for expressing Haskell values to SQL databases.
/INTRODUCTION TO SQLVALUE/
This type is used to marshall Haskell data to and from database APIs.
HDBC driver interfaces will do their best to use the most accurate and
efficient way to send a particular value to the database server.
Values read back from the server are constructed with the most appropriate 'SqlValue'
constructor. 'fromSql' or 'safeFromSql'
can then be used to convert them into whatever type
is needed locally in Haskell.
Most people will use 'toSql' and 'fromSql' instead of manipulating
'SqlValue's directly.
/EASY CONVERSIONS BETWEEN HASKELL TYPES/
Conversions are powerful; for instance, you can call 'fromSql' on a SqlInt32
and get a String or a Double out of it. This class attempts to Do
The Right Thing whenever possible, and will raise an error when asked to
do something incorrect. In particular, when converting to any type
except a Maybe, 'SqlNull' as the input will cause an error to be raised.
Conversions are implemented in terms of the "Data.Convertible" module, part of the
convertible package. You can refer to its documentation, and import that module,
if you wish to parse the Left result from 'safeFromSql' yourself, or write your
own conversion instances.
Here are some notes about conversion:
* Fractions of a second are not preserved on time values
* There is no @safeToSql@ because 'toSql' never fails.
See also 'toSql', 'safeFromSql', 'fromSql', 'nToSql', 'iToSql', 'posixToSql'.
/ERROR CONDITIONS/
There may sometimes be an error during conversion. For instance, if you have a
'SqlString' and are attempting to convert it to an Integer, but it doesn't parse as
an Integer, you will get an error. This will be indicated as an exception if using
'fromSql', or a Left result if using 'safeFromSql'.
/SPECIAL NOTE ON POSIXTIME/
Note that a 'NominalDiffTime' or 'POSIXTime' is converted to 'SqlDiffTime' by
'toSql'. HDBC cannot differentiate between 'NominalDiffTime' and 'POSIXTime'
since they are the same underlying type. You must construct 'SqlPOSIXTime'
manually or via 'posixToSql', or use 'SqlUTCTime'.
/DETAILS ON SQL TYPES/
HDBC database backends are expected to marshal date and time data back and
forth using the appropriate representation for the underlying database engine.
Databases such as PostgreSQL with builtin date and time types should see automatic
conversion between these Haskell types to database types. Other databases will be
presented with an integer or a string. Care should be taken to use the same type on
the Haskell side as you use on the database side. For instance, if your database
type lacks timezone information, you ought not to use ZonedTime, but
instead LocalTime or UTCTime. Database type systems are not always as rich
as Haskell. For instance, for data stored in a TIMESTAMP
WITHOUT TIME ZONE column, HDBC may not be able to tell if it is intended
as UTCTime or LocalTime data, and will happily convert it to both,
upon your request. It is
your responsibility to ensure that you treat timezone issues with due care.
This behavior also exists for other types. For instance, many databases do not
have a Rational type, so they will just use the show function and
store a Rational as a string.
The conversion between Haskell types and database types is complex,
and generic code in HDBC or its backends cannot possibly accomodate
every possible situation. In some cases, you may be best served by converting your
Haskell type to a String, and passing that to the database.
/UNICODE AND BYTESTRINGS/
Beginning with HDBC v2.0, interactions with a database are presumed to occur in UTF-8.
To accomplish this, whenever a ByteString must be converted to or from a String,
the ByteString is assumed to be in UTF-8 encoding, and will be decoded or encoded
as appropriate. Database drivers will generally present text or string data they have
received from the database as a SqlValue holding a ByteString, which 'fromSql' will
automatically convert to a String, and thus automatically decode UTF-8, when
you need it. In the other direction, database drivers will generally convert
a 'SqlString' to a ByteString in UTF-8 encoding before passing it to the
database engine.
If you are handling some sort of binary data that is not in UTF-8, you can of course
work with the ByteString directly, which will bypass any conversion.
Due to lack of support by database engines, lazy ByteStrings are not passed to database
drivers. When you use 'toSql' on a lazy ByteString, it will be converted to a strict
ByteString for storage. Similarly, 'fromSql' will convert a strict ByteString to
a lazy ByteString if you demand it.
/EQUALITY OF SQLVALUE/
Two SqlValues are considered to be equal if one of these hold. The
first comparison that can be made is controlling; if none of these
comparisons can be made, then they are not equal:
* Both are NULL
* Both represent the same type and the encapsulated values are considered equal
by applying (==) to them
* The values of each, when converted to a string, are equal.
/STRING VERSIONS OF TIMES/
Default string representations are given as comments below where such are non-obvious.
These are used for 'fromSql' when a 'String' is desired. They are also defaults for
representing data to SQL backends, though individual backends may override them
when a different format is demanded by the underlying database. Date and time formats
use ISO8601 date format, with HH:MM:SS added for time, and -HHMM added for timezone
offsets.
/DEPRECATED CONSTRUCTORS/
'SqlEpochTime' and 'SqlTimeDiff' are no longer created automatically by any
'toSql' or 'fromSql' functions or database backends. They may still be manually
constructed, but are
expected to be removed in a future version. Although these two constructures will
be removed, support for marshalling to and from the old System.Time data will be
maintained as long as System.Time is, simply using the newer data types for conversion.
-}dataSqlValue=SqlStringString|SqlByteStringB.ByteString|SqlWord32Word32|SqlWord64Word64|SqlInt32Int32|SqlInt64Int64|SqlIntegerInteger|SqlCharChar|SqlBoolBool|SqlDoubleDouble|SqlRationalRational|SqlLocalDateDay-- ^ Local YYYY-MM-DD (no timezone)|SqlLocalTimeOfDayTimeOfDay-- ^ Local HH:MM:SS (no timezone)|SqlZonedLocalTimeOfDayTimeOfDayTimeZone-- ^ Local HH:MM:SS -HHMM. Converts to and from (TimeOfDay, TimeZone).|SqlLocalTimeLocalTime-- ^ Local YYYY-MM-DD HH:MM:SS (no timezone)|SqlZonedTimeZonedTime-- ^ Local YYYY-MM-DD HH:MM:SS -HHMM. Considered equal if both convert to the same UTC time.|SqlUTCTimeUTCTime-- ^ UTC YYYY-MM-DD HH:MM:SS|SqlDiffTimeNominalDiffTime-- ^ Calendar diff between seconds. Rendered as Integer when converted to String, but greater precision may be preserved for other types or to underlying database.|SqlPOSIXTimePOSIXTime-- ^ Time as seconds since midnight Jan 1 1970 UTC. Integer rendering as for 'SqlDiffTime'.|SqlEpochTimeInteger-- ^ DEPRECATED Representation of ClockTime or CalendarTime. Use SqlPOSIXTime instead.|SqlTimeDiffInteger-- ^ DEPRECATED Representation of TimeDiff. Use SqlDiffTime instead.|SqlNull-- ^ NULL in SQL or Nothing in Haskellderiving(Show)instanceTypeableSqlValuewheretypeOf_=mkTypeName"SqlValue"instanceEqSqlValuewhereSqlStringa==SqlStringb=a==bSqlByteStringa==SqlByteStringb=a==bSqlWord32a==SqlWord32b=a==bSqlWord64a==SqlWord64b=a==bSqlInt32a==SqlInt32b=a==bSqlInt64a==SqlInt64b=a==bSqlIntegera==SqlIntegerb=a==bSqlChara==SqlCharb=a==bSqlBoola==SqlBoolb=a==bSqlDoublea==SqlDoubleb=a==bSqlRationala==SqlRationalb=a==bSqlLocalTimeOfDaya==SqlLocalTimeOfDayb=a==bSqlZonedLocalTimeOfDayab==SqlZonedLocalTimeOfDaycd=a==c&&b==dSqlLocalTimea==SqlLocalTimeb=a==bSqlLocalDatea==SqlLocalDateb=a==bSqlZonedTimea==SqlZonedTimeb=zonedTimeToUTCa==zonedTimeToUTCbSqlUTCTimea==SqlUTCTimeb=a==bSqlPOSIXTimea==SqlPOSIXTimeb=a==bSqlDiffTimea==SqlDiffTimeb=a==bSqlEpochTimea==SqlEpochTimeb=a==bSqlTimeDiffa==SqlTimeDiffb=a==bSqlNull==SqlNull=TrueSqlNull==_=False_==SqlNull=Falsea==b=((safeFromSqla)::ConvertResultString)==((safeFromSqlb)::ConvertResultString)instanceConvertibleStringSqlValuewheresafeConvert=return.SqlStringinstanceConvertibleSqlValueStringwheresafeConvert(SqlStringx)=returnxsafeConvert(SqlByteStringx)=return.BUTF8.toString$xsafeConvert(SqlInt32x)=return.show$xsafeConvert(SqlInt64x)=return.show$xsafeConvert(SqlWord32x)=return.show$xsafeConvert(SqlWord64x)=return.show$xsafeConvert(SqlIntegerx)=return.show$xsafeConvert(SqlCharx)=return[x]safeConvert(SqlBoolx)=return.show$xsafeConvert(SqlDoublex)=return.show$xsafeConvert(SqlRationalx)=return.show$xsafeConvert(SqlLocalDatex)=return.formatTimedefaultTimeLocale(iso8601DateFormatNothing)$xsafeConvert(SqlLocalTimeOfDayx)=return.formatTimedefaultTimeLocale"%T%Q"$xsafeConvert(SqlZonedLocalTimeOfDaytodtz)=return$formatTimedefaultTimeLocale"%T%Q "tod++formatTimedefaultTimeLocale"%z"tzsafeConvert(SqlLocalTimex)=return.formatTimedefaultTimeLocale(iso8601DateFormat(Just"%T%Q"))$xsafeConvert(SqlZonedTimex)=return.formatTimedefaultTimeLocale(iso8601DateFormat(Just"%T%Q %z"))$xsafeConvert(SqlUTCTimex)=return.formatTimedefaultTimeLocale(iso8601DateFormat(Just"%T%Q"))$xsafeConvert(SqlDiffTimex)=return$showFixedTruefixedvalwherefixedval::Picofixedval=fromRational.toRational$xsafeConvert(SqlPOSIXTimex)=return$showFixedTruefixedvalwherefixedval::Picofixedval=fromRational.toRational$xsafeConvert(SqlEpochTimex)=return.show$xsafeConvert(SqlTimeDiffx)=return.show$xsafeConverty@(SqlNull)=quickErrory#ifdef __HUGS__instanceTypeableB.ByteStringwheretypeOf_=mkTypeName"ByteString"#endifinstanceConvertibleB.ByteStringSqlValuewheresafeConvert=return.SqlByteStringinstanceConvertibleSqlValueB.ByteStringwheresafeConvert(SqlByteStringx)=returnxsafeConverty@(SqlNull)=quickErrorysafeConvertx=safeConvertx>>=return.BUTF8.fromStringinstanceConvertibleBSL.ByteStringSqlValuewheresafeConvert=return.SqlByteString.B.concat.BSL.toChunksinstanceConvertibleSqlValueBSL.ByteStringwheresafeConvertx=dobs<-safeConvertxreturn(BSL.fromChunks[bs])instanceConvertibleIntSqlValuewheresafeConvertx=doi<-((safeConvertx)::ConvertResultInt64)return$SqlInt64iinstanceConvertibleSqlValueIntwheresafeConvert(SqlStringx)=read'xsafeConvert(SqlByteStringx)=(read'.BUTF8.toString)xsafeConvert(SqlInt32x)=safeConvertxsafeConvert(SqlInt64x)=safeConvertxsafeConvert(SqlWord32x)=safeConvertxsafeConvert(SqlWord64x)=safeConvertxsafeConvert(SqlIntegerx)=safeConvertxsafeConvert(SqlCharx)=safeConvertxsafeConvert(SqlBoolx)=return(ifxthen1else0)safeConvert(SqlDoublex)=safeConvertxsafeConvert(SqlRationalx)=safeConvertxsafeConverty@(SqlLocalDate_)=viaIntegeryfromIntegralsafeConverty@(SqlLocalTimeOfDay_)=viaIntegeryfromIntegralsafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=viaIntegeryfromIntegralsafeConverty@(SqlZonedTime_)=viaIntegeryfromIntegralsafeConvert(SqlUTCTimex)=safeConvertxsafeConvert(SqlDiffTimex)=safeConvertxsafeConvert(SqlPOSIXTimex)=safeConvertxsafeConvert(SqlEpochTimex)=safeConvertxsafeConvert(SqlTimeDiffx)=safeConvertxsafeConverty@(SqlNull)=quickErroryinstanceConvertibleInt32SqlValuewheresafeConvert=return.SqlInt32instanceConvertibleSqlValueInt32wheresafeConvert(SqlStringx)=read'xsafeConvert(SqlByteStringx)=(read'.BUTF8.toString)xsafeConvert(SqlInt32x)=returnxsafeConvert(SqlInt64x)=safeConvertxsafeConvert(SqlWord32x)=safeConvertxsafeConvert(SqlWord64x)=safeConvertxsafeConvert(SqlIntegerx)=safeConvertxsafeConvert(SqlCharx)=safeConvertxsafeConvert(SqlBoolx)=return(ifxthen1else0)safeConvert(SqlDoublex)=safeConvertxsafeConvert(SqlRationalx)=safeConvertxsafeConverty@(SqlLocalDate_)=viaIntegeryfromIntegralsafeConverty@(SqlLocalTimeOfDay_)=viaIntegeryfromIntegralsafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=viaIntegeryfromIntegralsafeConverty@(SqlZonedTime_)=viaIntegeryfromIntegralsafeConverty@(SqlUTCTime_)=viaIntegeryfromIntegralsafeConverty@(SqlDiffTime_)=viaIntegeryfromIntegralsafeConverty@(SqlPOSIXTime_)=viaIntegeryfromIntegralsafeConvert(SqlEpochTimex)=safeConvertxsafeConvert(SqlTimeDiffx)=safeConvertxsafeConverty@(SqlNull)=quickErroryinstanceConvertibleInt64SqlValuewheresafeConvert=return.SqlInt64instanceConvertibleSqlValueInt64wheresafeConvert(SqlStringx)=read'xsafeConvert(SqlByteStringx)=(read'.BUTF8.toString)xsafeConvert(SqlInt32x)=safeConvertxsafeConvert(SqlInt64x)=returnxsafeConvert(SqlWord32x)=safeConvertxsafeConvert(SqlWord64x)=safeConvertxsafeConvert(SqlIntegerx)=safeConvertxsafeConvert(SqlCharx)=safeConvertxsafeConvert(SqlBoolx)=return(ifxthen1else0)safeConvert(SqlDoublex)=safeConvertxsafeConvert(SqlRationalx)=safeConvertxsafeConverty@(SqlLocalDate_)=viaIntegeryfromIntegralsafeConverty@(SqlLocalTimeOfDay_)=viaIntegeryfromIntegralsafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=viaIntegeryfromIntegralsafeConverty@(SqlZonedTime_)=viaIntegeryfromIntegralsafeConverty@(SqlUTCTime_)=viaIntegeryfromIntegralsafeConverty@(SqlDiffTime_)=viaIntegeryfromIntegralsafeConverty@(SqlPOSIXTime_)=viaIntegeryfromIntegralsafeConvert(SqlEpochTimex)=safeConvertxsafeConvert(SqlTimeDiffx)=safeConvertxsafeConverty@(SqlNull)=quickErroryinstanceConvertibleWord32SqlValuewheresafeConvert=return.SqlWord32instanceConvertibleSqlValueWord32wheresafeConvert(SqlStringx)=read'xsafeConvert(SqlByteStringx)=(read'.BUTF8.toString)xsafeConvert(SqlInt32x)=safeConvertxsafeConvert(SqlInt64x)=safeConvertxsafeConvert(SqlWord32x)=returnxsafeConvert(SqlWord64x)=safeConvertxsafeConvert(SqlIntegerx)=safeConvertxsafeConvert(SqlCharx)=safeConvertxsafeConvert(SqlBoolx)=return(ifxthen1else0)safeConvert(SqlDoublex)=safeConvertxsafeConvert(SqlRationalx)=safeConvertxsafeConverty@(SqlLocalDate_)=viaIntegeryfromIntegralsafeConverty@(SqlLocalTimeOfDay_)=viaIntegeryfromIntegralsafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=viaIntegeryfromIntegralsafeConverty@(SqlZonedTime_)=viaIntegeryfromIntegralsafeConverty@(SqlUTCTime_)=viaIntegeryfromIntegralsafeConverty@(SqlDiffTime_)=viaIntegeryfromIntegralsafeConverty@(SqlPOSIXTime_)=viaIntegeryfromIntegralsafeConvert(SqlEpochTimex)=safeConvertxsafeConvert(SqlTimeDiffx)=safeConvertxsafeConverty@(SqlNull)=quickErroryinstanceConvertibleWord64SqlValuewheresafeConvert=return.SqlWord64instanceConvertibleSqlValueWord64wheresafeConvert(SqlStringx)=read'xsafeConvert(SqlByteStringx)=(read'.BUTF8.toString)xsafeConvert(SqlInt32x)=safeConvertxsafeConvert(SqlInt64x)=safeConvertxsafeConvert(SqlWord32x)=safeConvertxsafeConvert(SqlWord64x)=returnxsafeConvert(SqlIntegerx)=safeConvertxsafeConvert(SqlCharx)=safeConvertxsafeConvert(SqlBoolx)=return(ifxthen1else0)safeConvert(SqlDoublex)=safeConvertxsafeConvert(SqlRationalx)=safeConvertxsafeConverty@(SqlLocalDate_)=viaIntegeryfromIntegralsafeConverty@(SqlLocalTimeOfDay_)=viaIntegeryfromIntegralsafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=viaIntegeryfromIntegralsafeConverty@(SqlZonedTime_)=viaIntegeryfromIntegralsafeConverty@(SqlUTCTime_)=viaIntegeryfromIntegralsafeConverty@(SqlDiffTime_)=viaIntegeryfromIntegralsafeConverty@(SqlPOSIXTime_)=viaIntegeryfromIntegralsafeConvert(SqlEpochTimex)=safeConvertxsafeConvert(SqlTimeDiffx)=safeConvertxsafeConverty@(SqlNull)=quickErroryinstanceConvertibleIntegerSqlValuewheresafeConvert=return.SqlIntegerinstanceConvertibleSqlValueIntegerwheresafeConvert(SqlStringx)=read'xsafeConvert(SqlByteStringx)=(read'.BUTF8.toString)xsafeConvert(SqlInt32x)=safeConvertxsafeConvert(SqlInt64x)=safeConvertxsafeConvert(SqlWord32x)=safeConvertxsafeConvert(SqlWord64x)=safeConvertxsafeConvert(SqlIntegerx)=returnxsafeConvert(SqlCharx)=safeConvertxsafeConvert(SqlBoolx)=return(ifxthen1else0)safeConvert(SqlDoublex)=safeConvertxsafeConvert(SqlRationalx)=safeConvertxsafeConvert(SqlLocalDatex)=return.toModifiedJulianDay$xsafeConvert(SqlLocalTimeOfDayx)=return.fromIntegral.fromEnum.timeOfDayToTime$xsafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=quickErrorysafeConvert(SqlZonedTimex)=return.truncate.utcTimeToPOSIXSeconds.zonedTimeToUTC$xsafeConvert(SqlUTCTimex)=safeConvertxsafeConvert(SqlDiffTimex)=safeConvertxsafeConvert(SqlPOSIXTimex)=safeConvertxsafeConvert(SqlEpochTimex)=returnxsafeConvert(SqlTimeDiffx)=returnxsafeConverty@(SqlNull)=quickErroryinstanceConvertibleBoolSqlValuewheresafeConvert=return.SqlBoolinstanceConvertibleSqlValueBoolwheresafeConverty@(SqlStringx)=casemaptoUpperxof"TRUE"->RightTrue"T"->RightTrue"FALSE"->RightFalse"F"->RightFalse"0"->RightFalse"1"->RightTrue_->convError"Cannot parse given String as Bool"ysafeConvert(SqlByteStringx)=(safeConvert.SqlString.BUTF8.toString)xsafeConvert(SqlInt32x)=numToBoolxsafeConvert(SqlInt64x)=numToBoolxsafeConvert(SqlWord32x)=numToBoolxsafeConvert(SqlWord64x)=numToBoolxsafeConvert(SqlIntegerx)=numToBoolxsafeConvert(SqlCharx)=numToBool(ordx)safeConvert(SqlBoolx)=returnxsafeConvert(SqlDoublex)=numToBoolxsafeConvert(SqlRationalx)=numToBoolxsafeConverty@(SqlLocalDate_)=quickErrorysafeConverty@(SqlLocalTimeOfDay_)=quickErrorysafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=quickErrorysafeConverty@(SqlZonedTime_)=quickErrorysafeConverty@(SqlUTCTime_)=quickErrorysafeConverty@(SqlDiffTime_)=quickErrorysafeConverty@(SqlPOSIXTime_)=quickErrorysafeConvert(SqlEpochTimex)=numToBoolxsafeConvert(SqlTimeDiffx)=numToBoolxsafeConverty@(SqlNull)=quickErrorynumToBool::Numa=>a->ConvertResultBoolnumToBoolx=Right(x/=0)instanceConvertibleCharSqlValuewheresafeConvert=return.SqlCharinstanceConvertibleSqlValueCharwheresafeConvert(SqlString[x])=returnxsafeConverty@(SqlString_)=convError"String length /= 1"ysafeConverty@(SqlByteStringx)=caseB.lengthxof1->safeConvert.SqlString.BUTF8.toString$x_->convError"ByteString length /= 1"ysafeConverty@(SqlInt32_)=quickErrorysafeConverty@(SqlInt64_)=quickErrorysafeConverty@(SqlWord32_)=quickErrorysafeConverty@(SqlWord64_)=quickErrorysafeConverty@(SqlInteger_)=quickErrorysafeConvert(SqlCharx)=returnxsafeConvert(SqlBoolx)=return(ifxthen'1'else'0')safeConverty@(SqlDouble_)=quickErrorysafeConverty@(SqlRational_)=quickErrorysafeConverty@(SqlLocalDate_)=quickErrorysafeConverty@(SqlLocalTimeOfDay_)=quickErrorysafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=quickErrorysafeConverty@(SqlZonedTime_)=quickErrorysafeConverty@(SqlUTCTime_)=quickErrorysafeConverty@(SqlDiffTime_)=quickErrorysafeConverty@(SqlPOSIXTime_)=quickErrorysafeConverty@(SqlEpochTime_)=quickErrorysafeConverty@(SqlTimeDiff_)=quickErrorysafeConverty@(SqlNull)=quickErroryinstanceConvertibleDoubleSqlValuewheresafeConvert=return.SqlDoubleinstanceConvertibleSqlValueDoublewheresafeConvert(SqlStringx)=read'xsafeConvert(SqlByteStringx)=(read'.BUTF8.toString)xsafeConvert(SqlInt32x)=safeConvertxsafeConvert(SqlInt64x)=safeConvertxsafeConvert(SqlWord32x)=safeConvertxsafeConvert(SqlWord64x)=safeConvertxsafeConvert(SqlIntegerx)=safeConvertxsafeConvert(SqlCharx)=return.fromIntegral.fromEnum$xsafeConvert(SqlBoolx)=return(ifxthen1.0else0.0)safeConvert(SqlDoublex)=returnxsafeConvert(SqlRationalx)=safeConvertxsafeConverty@(SqlLocalDate_)=((safeConverty)::ConvertResultInteger)>>=(return.fromIntegral)safeConvert(SqlLocalTimeOfDayx)=return.fromRational.toRational.timeOfDayToTime$xsafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=quickErrorysafeConvert(SqlZonedTimex)=safeConvert.SqlUTCTime.zonedTimeToUTC$xsafeConvert(SqlUTCTimex)=return.fromRational.toRational.utcTimeToPOSIXSeconds$xsafeConvert(SqlDiffTimex)=safeConvertxsafeConvert(SqlPOSIXTimex)=safeConvertxsafeConvert(SqlEpochTimex)=safeConvertxsafeConvert(SqlTimeDiffx)=safeConvertxsafeConverty@(SqlNull)=quickErroryinstanceConvertibleRationalSqlValuewheresafeConvert=return.SqlRationalinstanceConvertibleSqlValueRationalwheresafeConvert(SqlStringx)=read'xsafeConvert(SqlByteStringx)=(read'.BUTF8.toString)xsafeConvert(SqlInt32x)=safeConvertxsafeConvert(SqlInt64x)=safeConvertxsafeConvert(SqlWord32x)=safeConvertxsafeConvert(SqlWord64x)=safeConvertxsafeConvert(SqlIntegerx)=safeConvertxsafeConvert(SqlCharx)=return.fromIntegral.fromEnum$xsafeConvert(SqlBoolx)=return$ifxthenfromIntegral(1::Int)elsefromIntegral(0::Int)safeConvert(SqlDoublex)=safeConvertxsafeConvert(SqlRationalx)=returnxsafeConverty@(SqlLocalDate_)=((safeConverty)::ConvertResultInteger)>>=(return.fromIntegral)safeConvert(SqlLocalTimeOfDayx)=return.toRational.timeOfDayToTime$xsafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=quickErrorysafeConvert(SqlZonedTimex)=safeConvert.SqlUTCTime.zonedTimeToUTC$xsafeConvert(SqlUTCTimex)=safeConvertxsafeConvert(SqlDiffTimex)=safeConvertxsafeConvert(SqlPOSIXTimex)=safeConvertxsafeConvert(SqlEpochTimex)=return.fromIntegral$xsafeConvert(SqlTimeDiffx)=return.fromIntegral$xsafeConverty@(SqlNull)=quickErrory#ifndef TIME_GT_113instanceTypeableDaywheretypeOf_=mkTypeName"Day"instanceTypeableTimeOfDaywheretypeOf_=mkTypeName"TimeOfDay"instanceTypeableLocalTimewheretypeOf_=mkTypeName"LocalTime"instanceTypeableZonedTimewheretypeOf_=mkTypeName"ZonedTime"instanceTypeableDiffTimewheretypeOf_=mkTypeName"DiffTime"instanceTypeableTimeZonewheretypeOf_=mkTypeName"TimeZone"#endifinstanceTypeableST.ClockTimewheretypeOf_=mkTypeName"ClockTime"instanceTypeableST.TimeDiffwheretypeOf_=mkTypeName"TimeDiff"instanceConvertibleDaySqlValuewheresafeConvert=return.SqlLocalDateinstanceConvertibleSqlValueDaywheresafeConvert(SqlStringx)=parseTime'(iso8601DateFormatNothing)xsafeConvert(SqlByteStringx)=safeConvert(SqlString(BUTF8.toStringx))safeConvert(SqlInt32x)=return$ModifiedJulianDay{toModifiedJulianDay=fromIntegralx}safeConvert(SqlInt64x)=return$ModifiedJulianDay{toModifiedJulianDay=fromIntegralx}safeConvert(SqlWord32x)=return$ModifiedJulianDay{toModifiedJulianDay=fromIntegralx}safeConvert(SqlWord64x)=return$ModifiedJulianDay{toModifiedJulianDay=fromIntegralx}safeConvert(SqlIntegerx)=return$ModifiedJulianDay{toModifiedJulianDay=x}safeConverty@(SqlChar_)=quickErrorysafeConverty@(SqlBool_)=quickErrorysafeConvert(SqlDoublex)=return$ModifiedJulianDay{toModifiedJulianDay=truncatex}safeConvert(SqlRationalx)=safeConvert.SqlDouble.fromRational$xsafeConvert(SqlLocalDatex)=returnxsafeConverty@(SqlLocalTimeOfDay_)=quickErrorysafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConvert(SqlLocalTimex)=return.localDay$xsafeConverty@(SqlZonedTime_)=safeConverty>>=return.localDaysafeConverty@(SqlUTCTime_)=safeConverty>>=return.localDaysafeConverty@(SqlDiffTime_)=quickErrorysafeConverty@(SqlPOSIXTime_)=safeConverty>>=return.localDaysafeConverty@(SqlEpochTime_)=safeConverty>>=return.localDaysafeConverty@(SqlTimeDiff_)=quickErrorysafeConverty@(SqlNull)=quickErroryinstanceConvertibleTimeOfDaySqlValuewheresafeConvert=return.SqlLocalTimeOfDayinstanceConvertibleSqlValueTimeOfDaywheresafeConvert(SqlStringx)=parseTime'"%T%Q"xsafeConvert(SqlByteStringx)=safeConvert(SqlString(BUTF8.toStringx))safeConvert(SqlInt32x)=return.timeToTimeOfDay.fromIntegral$xsafeConvert(SqlInt64x)=return.timeToTimeOfDay.fromIntegral$xsafeConvert(SqlWord32x)=return.timeToTimeOfDay.fromIntegral$xsafeConvert(SqlWord64x)=return.timeToTimeOfDay.fromIntegral$xsafeConvert(SqlIntegerx)=return.timeToTimeOfDay.fromInteger$xsafeConverty@(SqlChar_)=quickErrorysafeConverty@(SqlBool_)=quickErrorysafeConvert(SqlDoublex)=return.timeToTimeOfDay.fromIntegral$((truncatex)::Integer)safeConvert(SqlRationalx)=safeConvert.SqlDouble.fromRational$xsafeConverty@(SqlLocalDate_)=quickErrorysafeConvert(SqlLocalTimeOfDayx)=returnxsafeConvert(SqlZonedLocalTimeOfDaytod_)=returntodsafeConvert(SqlLocalTimex)=return.localTimeOfDay$xsafeConverty@(SqlZonedTime_)=safeConverty>>=return.localTimeOfDaysafeConverty@(SqlUTCTime_)=safeConverty>>=return.localTimeOfDaysafeConverty@(SqlDiffTime_)=quickErrorysafeConverty@(SqlPOSIXTime_)=safeConverty>>=return.localTimeOfDaysafeConverty@(SqlEpochTime_)=safeConverty>>=return.localTimeOfDaysafeConverty@(SqlTimeDiff_)=quickErrorysafeConverty@SqlNull=quickErroryinstanceConvertible(TimeOfDay,TimeZone)SqlValuewheresafeConvert(tod,tz)=return(SqlZonedLocalTimeOfDaytodtz)instanceConvertibleSqlValue(TimeOfDay,TimeZone)wheresafeConvert(SqlStringx)=dotod<-parseTime'"%T%Q %z"xtz<-caseparseTimedefaultTimeLocale"%T%Q %z"xofNothing->convError"Couldn't extract timezone in"(SqlStringx)Justy->Rightyreturn(tod,tz)safeConvert(SqlByteStringx)=safeConvert(SqlString(BUTF8.toStringx))safeConverty@(SqlInt32_)=quickErrorysafeConverty@(SqlInt64_)=quickErrorysafeConverty@(SqlWord32_)=quickErrorysafeConverty@(SqlWord64_)=quickErrorysafeConverty@(SqlInteger_)=quickErrorysafeConverty@(SqlChar_)=quickErrorysafeConverty@(SqlBool_)=quickErrorysafeConverty@(SqlDouble_)=quickErrorysafeConverty@(SqlRational_)=quickErrorysafeConverty@(SqlLocalDate_)=quickErrorysafeConverty@(SqlLocalTimeOfDay_)=quickErrorysafeConvert(SqlZonedLocalTimeOfDayxy)=return(x,y)safeConverty@(SqlLocalTime_)=quickErrorysafeConvert(SqlZonedTimex)=return(localTimeOfDay.zonedTimeToLocalTime$x,zonedTimeZonex)safeConverty@(SqlUTCTime_)=quickErrorysafeConverty@(SqlDiffTime_)=quickErrorysafeConverty@(SqlPOSIXTime_)=quickErrorysafeConverty@(SqlEpochTime_)=quickErrorysafeConverty@(SqlTimeDiff_)=quickErrorysafeConverty@SqlNull=quickErroryinstanceConvertibleLocalTimeSqlValuewheresafeConvert=return.SqlLocalTimeinstanceConvertibleSqlValueLocalTimewheresafeConvert(SqlStringx)=parseTime'(iso8601DateFormat(Just"%T%Q"))xsafeConvert(SqlByteStringx)=safeConvert(SqlString(BUTF8.toStringx))safeConverty@(SqlInt32_)=quickErrorysafeConverty@(SqlInt64_)=quickErrorysafeConverty@(SqlWord32_)=quickErrorysafeConverty@(SqlWord64_)=quickErrorysafeConverty@(SqlInteger_)=quickErrorysafeConverty@(SqlChar_)=quickErrorysafeConverty@(SqlBool_)=quickErrorysafeConverty@(SqlDouble_)=quickErrorysafeConverty@(SqlRational_)=quickErrorysafeConverty@(SqlLocalDate_)=quickErrorysafeConverty@(SqlLocalTimeOfDay_)=quickErrorysafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConvert(SqlLocalTimex)=returnxsafeConvert(SqlZonedTimex)=return.zonedTimeToLocalTime$xsafeConverty@(SqlUTCTime_)=safeConverty>>=return.zonedTimeToLocalTimesafeConverty@(SqlDiffTime_)=quickErrorysafeConverty@(SqlPOSIXTime_)=safeConverty>>=return.zonedTimeToLocalTimesafeConverty@(SqlEpochTime_)=safeConverty>>=return.zonedTimeToLocalTimesafeConverty@(SqlTimeDiff_)=quickErrorysafeConverty@SqlNull=quickErroryinstanceConvertibleZonedTimeSqlValuewheresafeConvert=return.SqlZonedTimeinstanceConvertibleSqlValueZonedTimewheresafeConvert(SqlStringx)=parseTime'(iso8601DateFormat(Just"%T%Q %z"))xsafeConvert(SqlByteStringx)=safeConvert(SqlString(BUTF8.toStringx))safeConvert(SqlInt32x)=safeConvert(SqlInteger(fromIntegralx))safeConvert(SqlInt64x)=safeConvert(SqlInteger(fromIntegralx))safeConvert(SqlWord32x)=safeConvert(SqlInteger(fromIntegralx))safeConvert(SqlWord64x)=safeConvert(SqlInteger(fromIntegralx))safeConverty@(SqlInteger_)=safeConverty>>=return.utcToZonedTimeutcsafeConverty@(SqlChar_)=quickErrorysafeConverty@(SqlBool_)=quickErrorysafeConverty@(SqlDouble_)=safeConverty>>=return.utcToZonedTimeutcsafeConverty@(SqlRational_)=safeConverty>>=return.utcToZonedTimeutcsafeConverty@(SqlLocalDate_)=quickErrorysafeConverty@(SqlLocalTime_)=quickErrorysafeConverty@(SqlLocalTimeOfDay_)=quickErrorysafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConvert(SqlZonedTimex)=returnxsafeConvert(SqlUTCTimex)=return.utcToZonedTimeutc$xsafeConverty@(SqlDiffTime_)=quickErrorysafeConverty@(SqlPOSIXTime_)=safeConverty>>=return.utcToZonedTimeutcsafeConverty@(SqlEpochTime_)=safeConverty>>=return.utcToZonedTimeutcsafeConverty@(SqlTimeDiff_)=quickErrorysafeConverty@SqlNull=quickErroryinstanceConvertibleUTCTimeSqlValuewheresafeConvert=return.SqlUTCTimeinstanceConvertibleSqlValueUTCTimewheresafeConvert(SqlStringx)=parseTime'(iso8601DateFormat(Just"%T%Q"))xsafeConvert(SqlByteStringx)=safeConvert(SqlString(BUTF8.toStringx))safeConverty@(SqlInt32_)=safeConverty>>=return.posixSecondsToUTCTimesafeConverty@(SqlInt64_)=safeConverty>>=return.posixSecondsToUTCTimesafeConverty@(SqlWord32_)=safeConverty>>=return.posixSecondsToUTCTimesafeConverty@(SqlWord64_)=safeConverty>>=return.posixSecondsToUTCTimesafeConverty@(SqlInteger_)=safeConverty>>=return.posixSecondsToUTCTimesafeConverty@(SqlChar_)=quickErrorysafeConverty@(SqlBool_)=quickErrorysafeConverty@(SqlDouble_)=safeConverty>>=return.posixSecondsToUTCTimesafeConverty@(SqlRational_)=safeConverty>>=return.posixSecondsToUTCTimesafeConverty@(SqlLocalDate_)=quickErrorysafeConverty@(SqlLocalTimeOfDay_)=quickErrorysafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=quickErrorysafeConvert(SqlZonedTimex)=return.zonedTimeToUTC$xsafeConvert(SqlUTCTimex)=returnxsafeConverty@(SqlDiffTime_)=convError"incompatible types (did you mean SqlPOSIXTime?)"ysafeConvert(SqlPOSIXTimex)=return.posixSecondsToUTCTime$xsafeConverty@(SqlEpochTime_)=safeConverty>>=return.posixSecondsToUTCTimesafeConverty@(SqlTimeDiff_)=convError"incompatible types (did you mean SqlPOSIXTime?)"ysafeConverty@SqlNull=quickErrorystringToPico::String->ConvertResultPicostringToPicos=let(base,fracwithdot)=span(/='.')sshortfrac=drop1fracwithdot-- strip of dot; don't use tail because it may be emptyfrac=take12(rpad12'0'shortfrac)rpad::Int->a->[a]->[a]-- next line lifted from Data.Timerpadncxs=xs++replicate(n-lengthxs)cmkPico::Integer->Integer->Pico-- next line also lifted from Data.TimemkPicoif=fromIntegeri+fromRational(f%1000000000000)indoparsedBase<-read'baseparsedFrac<-read'fracreturn(mkPicoparsedBaseparsedFrac)instanceConvertibleNominalDiffTimeSqlValuewheresafeConvert=return.SqlDiffTimeinstanceConvertibleSqlValueNominalDiffTimewheresafeConvert(SqlStringx)=stringToPicox>>=return.realToFracsafeConvert(SqlByteStringx)=(stringToPico(BUTF8.toStringx))>>=return.realToFracsafeConvert(SqlInt32x)=return.fromIntegral$xsafeConvert(SqlInt64x)=return.fromIntegral$xsafeConvert(SqlWord32x)=return.fromIntegral$xsafeConvert(SqlWord64x)=return.fromIntegral$xsafeConvert(SqlIntegerx)=return.fromIntegral$xsafeConverty@(SqlChar_)=quickErrorysafeConverty@(SqlBool_)=quickErrorysafeConvert(SqlDoublex)=return.fromRational.toRational$xsafeConvert(SqlRationalx)=return.fromRational$xsafeConvert(SqlLocalDatex)=return.fromIntegral.(\y->y*60*60*24).toModifiedJulianDay$xsafeConvert(SqlLocalTimeOfDayx)=return.fromRational.toRational.timeOfDayToTime$xsafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=quickErrorysafeConvert(SqlZonedTimex)=return.utcTimeToPOSIXSeconds.zonedTimeToUTC$xsafeConvert(SqlUTCTimex)=return.utcTimeToPOSIXSeconds$xsafeConvert(SqlDiffTimex)=returnxsafeConvert(SqlPOSIXTimex)=returnxsafeConvert(SqlEpochTimex)=return.fromIntegral$xsafeConvert(SqlTimeDiffx)=return.fromIntegral$xsafeConverty@SqlNull=quickErroryinstanceConvertibleST.ClockTimeSqlValuewheresafeConvertx=safeConvertx>>=return.SqlPOSIXTimeinstanceConvertibleSqlValueST.ClockTimewheresafeConvert(SqlStringx)=dor<-read'xreturn$ST.TODr0safeConvert(SqlByteStringx)=safeConvert.SqlString.BUTF8.toString$xsafeConvert(SqlInt32x)=return$ST.TOD(fromIntegralx)0safeConvert(SqlInt64x)=return$ST.TOD(fromIntegralx)0safeConvert(SqlWord32x)=return$ST.TOD(fromIntegralx)0safeConvert(SqlWord64x)=return$ST.TOD(fromIntegralx)0safeConvert(SqlIntegerx)=return$ST.TODx0safeConverty@(SqlChar_)=quickErrorysafeConverty@(SqlBool_)=quickErrorysafeConvert(SqlDoublex)=return$ST.TOD(truncatex)0safeConvert(SqlRationalx)=return$ST.TOD(truncatex)0safeConverty@(SqlLocalDate_)=quickErrorysafeConverty@(SqlLocalTimeOfDay_)=quickErrorysafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=quickErrorysafeConverty@(SqlZonedTime_)=safeConverty>>=(\z->return$ST.TODz0)safeConverty@(SqlUTCTime_)=safeConverty>>=(\z->return$ST.TODz0)safeConverty@(SqlDiffTime_)=quickErrorysafeConverty@(SqlPOSIXTime_)=safeConverty>>=(\z->return$ST.TODz0)safeConvert(SqlEpochTimex)=return$ST.TODx0safeConverty@(SqlTimeDiff_)=quickErrorysafeConverty@SqlNull=quickErroryinstanceConvertibleST.TimeDiffSqlValuewheresafeConvertx=safeConvertx>>=return.SqlDiffTimeinstanceConvertibleSqlValueST.TimeDiffwheresafeConverty@(SqlString_)=dor<-safeConvertysafeConvert(SqlDiffTimer)safeConvert(SqlByteStringx)=safeConvert.SqlString.BUTF8.toString$xsafeConvert(SqlInt32x)=secs2td(fromIntegralx)safeConvert(SqlInt64x)=secs2td(fromIntegralx)safeConvert(SqlWord32x)=secs2td(fromIntegralx)safeConvert(SqlWord64x)=secs2td(fromIntegralx)safeConvert(SqlIntegerx)=secs2tdxsafeConverty@(SqlChar_)=quickErrorysafeConverty@(SqlBool_)=quickErrorysafeConvert(SqlDoublex)=secs2td(truncatex)safeConvert(SqlRationalx)=secs2td(truncatex)safeConverty@(SqlLocalDate_)=quickErrorysafeConverty@(SqlLocalTimeOfDay_)=quickErrorysafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=quickErrorysafeConverty@(SqlZonedTime_)=quickErrorysafeConverty@(SqlUTCTime_)=quickErrorysafeConverty@(SqlPOSIXTime_)=quickErrorysafeConvert(SqlDiffTimex)=safeConvertxsafeConverty@(SqlEpochTime_)=quickErrorysafeConvert(SqlTimeDiffx)=secs2tdxsafeConverty@SqlNull=quickErroryinstanceConvertibleDiffTimeSqlValuewheresafeConvert=return.SqlDiffTime.fromRational.toRationalinstanceConvertibleSqlValueDiffTimewheresafeConvert(SqlStringx)=read'x>>=return.fromIntegersafeConvert(SqlByteStringx)=safeConvert.SqlString.BUTF8.toString$xsafeConvert(SqlInt32x)=return.fromIntegral$xsafeConvert(SqlInt64x)=return.fromIntegral$xsafeConvert(SqlWord32x)=return.fromIntegral$xsafeConvert(SqlWord64x)=return.fromIntegral$xsafeConvert(SqlIntegerx)=return.fromIntegral$xsafeConverty@(SqlChar_)=quickErrorysafeConverty@(SqlBool_)=quickErrorysafeConvert(SqlDoublex)=return.fromRational.toRational$xsafeConvert(SqlRationalx)=return.fromRational$xsafeConverty@(SqlLocalDate_)=quickErrorysafeConverty@(SqlLocalTimeOfDay_)=quickErrorysafeConverty@(SqlZonedLocalTimeOfDay__)=quickErrorysafeConverty@(SqlLocalTime_)=quickErrorysafeConverty@(SqlZonedTime_)=quickErrorysafeConverty@(SqlUTCTime_)=quickErrorysafeConvert(SqlDiffTimex)=return.fromRational.toRational$xsafeConverty@(SqlPOSIXTime_)=quickErrorysafeConverty@(SqlEpochTime_)=quickErrorysafeConvert(SqlTimeDiffx)=return.fromIntegral$xsafeConverty@SqlNull=quickErroryinstanceConvertibleST.CalendarTimeSqlValuewhere-- convert via ZonedTimesafeConvertx=safeConvertx>>=return.SqlZonedTimeinstanceConvertibleSqlValueST.CalendarTimewhere-- convert via ZonedTimesafeConvert=convertVia(undefined::ZonedTime)instance(ConvertibleaSqlValue)=>Convertible(Maybea)SqlValuewheresafeConvertNothing=returnSqlNullsafeConvert(Justa)=safeConvertainstance(ConvertibleSqlValuea)=>ConvertibleSqlValue(Maybea)wheresafeConvertSqlNull=returnNothingsafeConverta=safeConverta>>=(return.Just)viaInteger'::(ConvertibleSqlValuea,Boundeda,Showa,ConvertibleaInteger,Typeablea)=>SqlValue->(Integer->ConvertResulta)->ConvertResultaviaInteger'svfunc=doi<-((safeConvertsv)::ConvertResultInteger)boundedConversionfunciviaInteger::(ConvertibleSqlValuea,Boundeda,Showa,ConvertibleaInteger,Typeablea)=>SqlValue->(Integer->a)->ConvertResultaviaIntegersvfunc=viaInteger'sv(return.func)secs2td::Integer->ConvertResultST.TimeDiffsecs2tdx=safeConvertx-- | Read a value from a string, and give an informative message-- if it fails.read'::(Typeablea,Reada,ConvertibleSqlValuea)=>String->ConvertResultaread's=casereadssof[(x,"")]->Rightx_->convError"Cannot read source value as dest type"(SqlStrings)#ifdef __HUGS__parseTime'::(Typeablet,ConvertibleSqlValuet)=>String->String->ConvertResulttparseTime'_inpstr=convError"Hugs does not support time parsing"(SqlStringinpstr)#elseparseTime'::(Typeablet,ConvertibleSqlValuet,ParseTimet)=>String->String->ConvertResulttparseTime'fmtstrinpstr=caseparseTimedefaultTimeLocalefmtstrinpstrofNothing->convError("Cannot parse using default format string "++showfmtstr)(SqlStringinpstr)Justx->Rightx#endif