Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  database error simply by using a sting in a      variable
      (Damien Mattei)
   2. Re:  database error simply by using a sting in a variable
      (Francesco Ariis)
   3. Re:  (SPAM 3)Re: database error simply by using a sting in a
      variable (Damien Mattei)
   4. Re:  (SPAM 3)Re: database error simply by using a sting in a
      variable (Damien Mattei)
   5. Re:  (SPAM 3)Re: database error simply by using a sting in a
      variable (Francesco Ariis)
   6. Re:  database error simply by using a sting in a  variable
      (Ian Denhardt)
   7.  Regex (mike h)
   8.  database, list result, extraction and conversion (Damien Mattei)


----------------------------------------------------------------------

Message: 1
Date: Wed, 5 Dec 2018 17:02:48 +0100
From: Damien Mattei <mat...@oca.eu>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] database error simply by using a sting in
        a       variable
Message-ID: <5c07f6a8.9010...@oca.eu>
Content-Type: text/plain; charset=utf-8

why i'm getting this error?

code:

let name = "'A    20'"
    let qry = "select `N° BD` from Coordonnées where Nom = " ++ name

    putStrLn qry

    bd_rows <- query_ conn qry


    putStrLn $ show bd_rows
    putStrLn $ show name

    forM_ bd_rows $ \(Only a) ->
      putStrLn $  Text.unpack a



error:

*Main> :load UpdateSidonie
[1 of 1] Compiling Main             ( UpdateSidonie.hs, interpreted )

UpdateSidonie.hs:74:28: error:
    • Couldn't match expected type ‘Query’ with actual type ‘[Char]’
    • In the second argument of ‘query_’, namely ‘qry’
      In a stmt of a 'do' block: bd_rows <- query_ conn qry
      In the expression:
        do conn <- connect
                     defaultConnectInfo
                       {connectHost = "moita", connectUser = "mattei",
                        connectPassword = "sidonie2", connectDatabase =
"sidonie"}
           rows <- query_
                     conn
                     "SELECT Nom,distance FROM AngularDistance WHERE
distance > 0.000278"
           forM_ rows
             $ \ (name, distance)
                 -> putStrLn $ unpack name ++ " " ++ show (distance ::
Double)
           let name = "'A    20'"
           ....
   |
74 |     bd_rows <- query_ conn qry
   |                            ^^^
Failed, no modules loaded.


-- 
damien.mat...@unice.fr, damien.mat...@oca.eu, UNS / OCA / CNRS


------------------------------

Message: 2
Date: Wed, 5 Dec 2018 17:12:03 +0100
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] database error simply by using a
        sting in a variable
Message-ID: <20181205161203.jlrb3viu4hx2l...@x60s.casa>
Content-Type: text/plain; charset=utf-8

Hello Damien,

On Wed, Dec 05, 2018 at 05:02:48PM +0100, Damien Mattei wrote:
>     • Couldn't match expected type ‘Query’ with actual type ‘[Char]’

GHC would like to have a `Query`, but you are providing a `String`.
You didn't specify which library you are using, but I am willing to
bet there is an appropriate ":: String -> Query" function.

That of you need to put

    {-# Language OverloadedStrings -#}

on top of your file. Does that work?
-F



------------------------------

Message: 3
Date: Wed, 5 Dec 2018 17:28:03 +0100
From: Damien Mattei <mat...@oca.eu>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] (SPAM 3)Re: database error simply by
        using a sting in a variable
Message-ID: <5c07fc93.6080...@oca.eu>
Content-Type: text/plain; charset=utf-8



Le 05/12/2018 17:12, Francesco Ariis a écrit :
> Hello Damien,
> 
> On Wed, Dec 05, 2018 at 05:02:48PM +0100, Damien Mattei wrote:
>>     • Couldn't match expected type ‘Query’ with actual type ‘[Char]’
> 
> GHC would like to have a `Query`, but you are providing a `String`.
> You didn't specify which library you are using, but I am willing to
> bet there is an appropriate ":: String -> Query" function.
> 
> That of you need to put
> 
>     {-# Language OverloadedStrings -#}


i had put it alreeady
> 
> on top of your file. Does that work?

no

i begin to understand that {-# Language OverloadedStrings -#} is working
on string but not on string in variable or concatenation , i should have
to create an object of type Query from the String... ???

finally ,having a beginning of solution:

  let qry_head = "select `N° BD` from sidonie.Coordonnées where Nom = ?"
:: Query
    putStrLn qry

    bd_rows <- query conn qry_head (Only (name::String))

> -F
> 
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> 

-- 
damien.mat...@unice.fr, damien.mat...@oca.eu, UNS / OCA / CNRS


------------------------------

Message: 4
Date: Wed, 5 Dec 2018 17:28:43 +0100
From: Damien Mattei <mat...@oca.eu>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] (SPAM 3)Re: database error simply by
        using a sting in a variable
Message-ID: <5c07fcbb.80...@oca.eu>
Content-Type: text/plain; charset=utf-8

thanks for your help

Le 05/12/2018 17:12, Francesco Ariis a écrit :
> Hello Damien,
> 
> On Wed, Dec 05, 2018 at 05:02:48PM +0100, Damien Mattei wrote:
>>     • Couldn't match expected type ‘Query’ with actual type ‘[Char]’
> 
> GHC would like to have a `Query`, but you are providing a `String`.
> You didn't specify which library you are using, but I am willing to
> bet there is an appropriate ":: String -> Query" function.
> 
> That of you need to put
> 
>     {-# Language OverloadedStrings -#}
> 
> on top of your file. Does that work?
> -F
> 
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> 

-- 
damien.mat...@unice.fr, damien.mat...@oca.eu, UNS / OCA / CNRS


------------------------------

Message: 5
Date: Wed, 5 Dec 2018 17:46:55 +0100
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] (SPAM 3)Re: database error simply by
        using a sting in a variable
Message-ID: <20181205164655.yjt2kc74dplxh...@x60s.casa>
Content-Type: text/plain; charset=us-ascii

On Wed, Dec 05, 2018 at 05:28:03PM +0100, Damien Mattei wrote:
> i begin to understand that {-# Language OverloadedStrings -#} is working
> on string but not on string in variable or concatenation , i should have
> to create an object of type Query from the String... ???

Yes, OverloadedStrings works on String *literals* not on String variables!



------------------------------

Message: 6
Date: Wed, 05 Dec 2018 13:19:26 -0500
From: Ian Denhardt <i...@zenhack.net>
To: Damien Mattei <mat...@oca.eu>, The Haskell-Beginners Mailing List
        - Discussion of primarily beginner-level topics related to Haskell
        <beginners@haskell.org>
Subject: Re: [Haskell-beginners] database error simply by using a
        sting in a      variable
Message-ID: <154403396683.872.1499410688028997872@localhost>
Content-Type: text/plain; charset="utf-8"

It sounds from the later posts like you've made some progress. I just
want to call out one thing:

Quoting Damien Mattei (2018-12-05 11:02:48)
> let name = "'A    20'"
>     let qry = "select `N° BD` from Coordonnées where Nom = " ++ name

I'll hazard a guess that you're using the sqlite-simple library. From
their documentation on the Query type:

> This type is intended to make it difficult to construct a SQL query by
> concatenating string fragments, as that is an extremely common way to
> accidentally introduce SQL injection vulnerabilities into an
> application.

From later messages it looks like you worked out the OverloadedStrings
thing and ended up (correctly) moving to some code that uses the ?
interpolation syntax: ".... where Nom = ?". I just wanted to stress that
this is the right way to do things, and the distinction is important.
This is a general thing when working with SQL: don't construct queries
by gluing strings together; it's a great way to have vulnerabilities in
your app.

Happy Hacking,

-Ian


------------------------------

Message: 7
Date: Thu, 6 Dec 2018 10:38:06 +0000
From: mike h <mike_k_hough...@yahoo.co.uk>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Regex
Message-ID: <30682ae0-1182-472f-8677-68065c528...@yahoo.co.uk>
Content-Type: text/plain;       charset=us-ascii

Hi,

Which package is the most popular and/or easy to used for dealing with regular 
expressions?
My regex is quite simple and I just need to get 2 or 3 capture groups from the 
result.

Many thanks

Mike

------------------------------

Message: 8
Date: Thu, 6 Dec 2018 12:16:08 +0100
From: Damien Mattei <mat...@oca.eu>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] database, list result, extraction and
        conversion
Message-ID: <5c0904f8.5030...@oca.eu>
Content-Type: text/plain; charset=utf-8

again un haskell beginner question ;-) ...
i have this: [Only {fromOnly = "-04.3982"}]
as result of a database query, i understand it's a list and i can get
the first element:

*Main> Data.List.head [Only {fromOnly = "-04.3982"}]
Only {fromOnly = "-04.3982"}
*Main> let s = Data.List.head [Only {fromOnly = "-04.3982"}]
*Main> s
Only {fromOnly = "-04.3982"}
*Main> show s
"Only {fromOnly = \"-04.3982\"}"

but how can i get the String "-04.3982" ? and after converting it to a Float
-- 
damien.mat...@unice.fr, damien.mat...@oca.eu, UNS / OCA / CNRS


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 126, Issue 4
*****************************************

Reply via email to