Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: database access,extracting result... (Damien Mattei)
2. About Installing Sqlite3, HDBC and convertible (Eyüp Kaan AKAY)
3. Re: About Installing Sqlite3, HDBC and convertible
(Damien Mattei)
4. Database simple-mysql (Damien Mattei)
----------------------------------------------------------------------
Message: 1
Date: Tue, 4 Dec 2018 16:33:55 +0100
From: Damien Mattei <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] database access,extracting result...
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
thank you David, i did something like that:
rows <- query_ conn "SELECT Nom,distance FROM AngularDistance WHERE
distance > 0.000278"
forM_ rows $ \(name,distance) ->
putStrLn $ Text.unpack name ++ " " ++ show (distance :: Double)
output:
...
HJ 2900 3.333333333882682e-2
HJ 3340 1.6666666646205367e-2
HLD 73 1.666666666807325e-2
HLD 152 1.666666666807325e-2
HLD 158 1.666666666807325e-2
HO 6 0.19569724135990224
HO 15 1.666666666807325e-2
...
and it works
Damien
Le 03/12/2018 15:42, David McBride a écrit :
> Here's how it works, every time you supply a query, you supply the
> parameters to the query in a tuple. Furthermore the results can be
> gotten back as a tuple by type hinting each value. Warning: I have not
> run this code, but it should be close.
>
> query "select age, is_old from user where uid = ? and name = ? (uid ::
> Int, name :: String) :: IO [(Integer, Bool)]
>
> But what happens when you want to supply a single parameter (or receive
> a single value?)
>
> query "select * from user where uid = ?" (uid)
>
> The problem with that is (uid) is not a tuple. It's just an integer in
> parenthesis. There in fact is no way to specify a tuple of one length.
> So mysql-simple (and other libraries) very often have a single type
> meant to be used as a single element tuple. In mysql-simple's (and
> postgresql-simple) case that is the (Only a) type. (Side note, I wish
> these were in the standard Tuple module, as this comes once in awhile).
>
> query "select name from user where uid = ?" (Only uid) :: IO [Only String]
>
> Remember that you can also make your own records implement the
> QueryParams and QueryResults classes so that you can write
>
> On Mon, Dec 3, 2018 at 6:22 AM Damien Mattei <[email protected]
> <mailto:[email protected]>> wrote:
>
> {-# LANGUAGE OverloadedStrings #-}
>
> import Database.MySQL.Simple
> import Control.Monad
> import Data.Text as Text
> import Data.Int
>
>
> main :: IO ()
> main = do
> conn <- connect defaultConnectInfo
> { connectHost = "moita",
> connectUser = "mattei",
> connectPassword = "******",
> connectDatabase = "sidonie" }
>
> rows <- query_ conn "select `N° BD` from sidonie.Coordonnées where Nom
> = 'A 20'"
>
> --putStrLn $ show rows
>
> forM_ rows $ \(fname, lname) ->
> putStrLn $ fname ++ " " ++ Text.unpack lname ++ " "
>
>
> here is the error:
>
> *Main> :load Toto
> [1 of 1] Compiling Main ( Toto.hs, interpreted )
> Ok, one module loaded.
> *Main> main
> *** Exception: ConversionFailed {errSQLType = "1 values:
> [(VarString,Just \"-04.3982\")]", errHaskellType = "2 slots in target
> type", errFieldName = "[\"N\\194\\176 BD\"]", errMessage = "mismatch
> between number of columns to convert and number in target type"}
>
> -04.3982 is the values i want to put in a variable,it's the N° BD
> (Durchmusterung Number)
>
>
> ???
>
> any help greatly appeciated ;-)
>
>
> --
> [email protected] <mailto:[email protected]>,
> [email protected] <mailto:[email protected]>, UNS / OCA / CNRS
> _______________________________________________
> Beginners mailing list
> [email protected] <mailto:[email protected]>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
[email protected], [email protected], UNS / OCA / CNRS
------------------------------
Message: 2
Date: Wed, 05 Dec 2018 11:15:59 +0000
From: Eyüp Kaan AKAY <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] About Installing Sqlite3, HDBC and
convertible
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"; Format="flowed"
Hi. I want to use sqlite3. When I work to install it, I got this error:
hdbc-sqlite3-master$ ghc --make -o setup Setup.lhs
hdbc-sqlite3-master$ ghc --make -o setup Setup.hs
[1 of 1] Compiling Main ( Setup.hs, Setup.o )
Linking setup ...
hdbc-sqlite3-master$ ./setup configure
Configuring HDBC-sqlite3-2.3.3.1...
setup: At least the following
dependencies are missing:
HDBC >=2.3.0.0, utf8-string -any
When I want to install HDBC, I got this error:
HDBC-2.4.0.2$ ghc --make -o setup Setup.lhs
HDBC-2.4.0.2$ ./setup configure
Configuring HDBC-2.4.0.2...
setup: At least the following dependencies are missing:
convertible >=1.1.0.0, utf8-string -any
Then I install convertible and I got any errors then first I work to
install HDBC but I got the same error. So what can I do else?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20181205/05683bff/attachment-0001.html>
------------------------------
Message: 3
Date: Wed, 5 Dec 2018 09:40:51 +0100
From: Damien Mattei <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] About Installing Sqlite3, HDBC and
convertible
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
i'm new to haskell and i'm assume you're trying to compile all the stuff
"by hand", instead why don't you install cabal and install them using cabal?
i'm trying also to use database with haskell,i use cabal to install HDBC
this way:(from my comments in code)
-- install those modules with cabal:
/usr/local/bin/cabal update (if needed)
/usr/local/bin/cabal install HDBC
Damien
Le 05/12/2018 12:15, Eyüp Kaan AKAY a écrit :
> Hi. I want to use sqlite3. When I work to install it, I got this error:
> *hdbc-sqlite3-master$* ghc --make -o setup Setup.lhs
> *hdbc-sqlite3-master$* ghc --make -o setup Setup.hs
> [1 of 1] Compiling Main ( Setup.hs, Setup.o )
> Linking setup ...
> *hdbc-sqlite3-master$* ./setup configure
> Configuring HDBC-sqlite3-2.3.3.1...
> setup: At least the following dependencies are missing:
> HDBC >=2.3.0.0, utf8-string -any
>
> When I want to install HDBC, I got this error:
>
> *HDBC-2.4.0.2$* ghc --make -o setup Setup.lhs
> *HDBC-2.4.0.2$ *./setup configure
> Configuring HDBC-2.4.0.2...
> setup: At least the following dependencies are missing:
> convertible >=1.1.0.0, utf8-string -any
>
> Then I install convertib le and I got any errors then first I work to
> install HDBC but I got the same error. So what can I do else?
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
[email protected], [email protected], UNS / OCA / CNRS
------------------------------
Message: 4
Date: Wed, 5 Dec 2018 11:29:30 +0100
From: Damien Mattei <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Database simple-mysql
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
why does this works:
let name = "'A 20'"
bd_rows <- query_ conn "select `N° BD` from sidonie.Coordonnées where
Nom = 'A 20'"
putStrLn $ show bd_rows
putStrLn $ show name
i got:
[Only {fromOnly = "-04.3982"}]
"'A 20'"
-04.3982
but not with this:
bd_rows <- query conn "select `N° BD` from sidonie.Coordonnées where
Nom = ?" (Only (name::String))
i got an empty result:
[]
...
???
--
[email protected], [email protected], UNS / OCA / CNRS
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 126, Issue 3
*****************************************