[Haskell-beginners] Takusen and inserting type Maybe with sqlite3
Neil Jensen
neilcjensen at gmail.com
Fri May 13 23:43:11 CEST 2011
I just answered my own question... I had forgotten the type signature on the
storeSummary function. When I added the type signature below, it coerced the
Maybe RoR (which is a Double) into a REAL in sqlite3.
storeSummary :: ISODateInt -> AccountId -> [Maybe RoR] -> IO Int
Problem solved.
Neil
On Fri, May 13, 2011 at 2:35 PM, Neil Jensen <neilcjensen at gmail.com> wrote:
> Hello, I'm stumped on using Takusen to insert values of type Maybe into a
> sqlite database when the underlying database has a field type of REAL.
>
> When I bind a Maybe to an underlying sqlite field of type DATETIME or
> INTEGER, the value is stored correctly. However, when I bind a Maybe value
> to a database field of type REAL, the value is inserted as "Just ..." or
> "Nothing".
>
> I thought bindP would coerce the Maybe type either into the value or a
> database null. What am I missing?
>
> Here is an example of an inserted record in the database:
>
> sqlite> select * from summary;
> 20110331|100002|Just 0.37427717861180376|Just 2.198753718609092|Just
> 9.402720712996771|Just 17.50143032492688|Just
> 8.250653601136904|Nothing|Nothing|Just 6.190434991035554
>
>
> Here is the function:
>
> storeSummary date account returns = do
> dbh <- openDb
> withSession dbh (do
> execDML(cmdbind "REPLACE INTO summary
> (date,account_id,one_mo,three_mo,one_yr,two_yr,three_yr,four_yr,five_yr,incept)
> \
> \VALUES
> (?,?,?,?,?,?,?,?,?,?)" [bindP (Just date), bindP (Just account),
>
> bindP (returns !! 0),bindP (returns !! 1),bindP (returns !! 2),bindP
> (returns !! 3),
>
> bindP (returns !! 4),bindP (returns !! 5),bindP (returns !! 6),bindP
> (returns !! 7) ])
> )
>
>
> And the database:
>
> sqlite>.schema summary
> CREATE TABLE "SUMMARY" ("DATE" DATETIME NOT NULL ,"ACCOUNT_ID" INTEGER NOT
> NULL ,"ONE_MO" REAL,"THREE_MO" REAL,"ONE_YR" REAL,"TWO_YR" REAL,"THREE_YR"
> REAL,"FOUR_YR" REAL,"FIVE_YR" REAL,"INCEPT" REAL, PRIMARY KEY
> ("DATE","ACCOUNT_ID") )
>
> Thanks in advance,
> Neil
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110513/bb64f442/attachment.htm>
More information about the Beginners
mailing list