[Haskell-cafe] Re: why 'try' not work in parsec

2008-11-23 Thread Changying Li
thannks very much!!
-- 

Thanks  Regards

Changying Li

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] a question about Database.HDBC.ODBC

2008-09-17 Thread Changying Li
I want to use hdbc to connect my mysql test db. so I set up my
/etc/odbcinst.ini :
[MySQL]
Description = ODBC Driver for MySQL
Driver  = /usr/lib/libmyodbc.so
Setup   = /usr/lib/libodbcmyS.so
FileUsage   = 1

and /etc/odbc.ini:
[test]
Description = MySQL database test
Driver  = MySQL
Server  = localhost
Database= test
Port= 3306
User= root
Socket  = /tmp/mysql.sock
Option  =
Stmt=

user [EMAIL PROTECTED] must use password to connect mysql. other users needn't.
I connect db like this:
Prelude Database.HDBC.ODBC Database.HDBC handleSqlError (connectODBC 
DSN=test)
*** Exception: user error (SQL error: SqlError {seState = [\HY000\], 
seNativeError = -1, seErrorMsg = connectODBC/sqlDriverConnect: [\1045: 
[unixODBC][MySQL][ODBC 3.51 Driver]Access denied for user 'chylli'@'localhost' 
(using password: NO)\]})
Prelude Database.HDBC.ODBC Database.HDBC handleSqlError (connectODBC 
DSN=test;UID=chylli)
Prelude Database.HDBC.ODBC Database.HDBC 

in another term:
mysql show processlist;
++-+---+--+-+--+---+--+
| Id | User| Host  | db   | Command | Time | State | Info   
  |
++-+---+--+-+--+---+--+
| 31 | chylli¶è | localhost | test | Sleep   | 1483 |   | NULL 
| 
| 43 | root| localhost | test | Sleep   |  116 |   | NULL   
  | 

my question is:
1. why not HDBC.ODBC use configuration in /etc/odbc.ini ? if is use,
then connectODBC DSN=test should use root as user without password and
it should succeed.

2. when using UID=chylli, why the user in 'show processlist' is not
chylli but 'chylli¶è' ?  if it use account 'chylli', that connection
should fail. but in fact it succeed !!!



-- 

Thanks  Regards

Changying Li

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: a question about Database.HDBC.ODBC

2008-09-17 Thread Changying Li
thanks for your reply.
I'm sure isql is ok for me:

[EMAIL PROTECTED] tapl-haskell] isql test
+---+
| Connected!|
|   |
| sql-statement |
| help [tablename]  |
| quit  |
|   |
+---+
SQL  show processlist;
+-+--+--+--+++---+--+
| Id  | User | Host | db   | 
Command| Time   | State | Info |
+-+--+--+--+++---+--+
| 1   | root | localhost| test | 
Query  | 0  |   | show processlist |
+-+--+--+--+++---+--+
SQLRowCount returns 1
1 rows fetched



I'm not sure where is the problem.
another problem is, the isql is not read configuration in ~/.dbic



Mads Lindstrøm [EMAIL PROTECTED] writes:

 Hi,

 Changying Li wrote:
 I want to use hdbc to connect my mysql test db. so I set up my
 /etc/odbcinst.ini :
 [MySQL]
 Description = ODBC Driver for MySQL
 Driver  = /usr/lib/libmyodbc.so
 Setup   = /usr/lib/libodbcmyS.so
 FileUsage   = 1
 
 and /etc/odbc.ini:
 [test]
 Description = MySQL database test
 Driver  = MySQL
 Server  = localhost
 Database= test
 Port= 3306
 User= root
 Socket  = /tmp/mysql.sock
 Option  =
 Stmt=
 
 user [EMAIL PROTECTED] must use password to connect mysql. other users 
 needn't.
 I connect db like this:
 Prelude Database.HDBC.ODBC Database.HDBC handleSqlError (connectODBC 
 DSN=test)
 *** Exception: user error (SQL error: SqlError {seState = [\HY000\], 
 seNativeError = -1, seErrorMsg = connectODBC/sqlDriverConnect: [\1045: 
 [unixODBC][MySQL][ODBC 3.51 Driver]Access denied for user 
 'chylli'@'localhost' (using password: NO)\]})
 Prelude Database.HDBC.ODBC Database.HDBC handleSqlError (connectODBC 
 DSN=test;UID=chylli)
 Prelude Database.HDBC.ODBC Database.HDBC 
 
 in another term:
 mysql show processlist;
 ++-+---+--+-+--+---+--+
 | Id | User| Host  | db   | Command | Time | State | Info
  |
 ++-+---+--+-+--+---+--+
 | 31 | chylli¶è | localhost | test | Sleep   | 1483 |   | NULL   
   | 
 | 43 | root| localhost | test | Sleep   |  116 |   | NULL
  | 
 
 my question is:
 1. why not HDBC.ODBC use configuration in /etc/odbc.ini ? if is use,
 then connectODBC DSN=test should use root as user without password and
 it should succeed.

 Are you sure it is a HDBC and not a ODBC-library problem? It seems that
 you use unixODBC and can then try the command:

   isql test

 which will connect though unixODBC without involving HDBC. If you still
 have the same problems, then it must be unrelated to HDBC.

 
 2. when using UID=chylli, why the user in 'show processlist' is not
 chylli but 'chylli¶è' ?  if it use account 'chylli', that connection
 should fail. but in fact it succeed !!!
 
 
 

 Greetings,

 Mads Lindstrøm

-- 

Thanks  Regards

Changying Li

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] why isn't the thread blocked?

2008-08-16 Thread Changying Li
I writed a little program to test forkIO. in fact, I want to know how to
implement the 'select' system call in haskell:

module Main where

import Control.Concurrent.Chan
import Control.Concurrent
import System.IO

main = do
  chan - newChan
  handles - mapM ((flip  openFile) ReadMode) [/tmp/a,/tmp/b,/tmp/c]
  let  readF h = do
  myID - myThreadId
  chan' - dupChan chan
  char - hGetChar h
  writeChan chan' $ show myID
  putStrLn [char]
  threads - mapM (\h - forkIO $ readF h) handles
  nr - readChan chan
  mapM killThread $ filter (\x - show x == nr ) threads
  putStrLn  nr



I first mkfifo /tmp/{a,b,c} , then run 'echo hello /tmp/a', then
'runhaskell thisProgram.hs'

but I got an error: 

test.hs: /tmp/b: hGetChar: end of file

test.hs: /tmp/c: hGetChar: end of file


I think the thread will be blocked when /tmp/b has nothing.
but it get EOF, why ?


-- 

Thanks  Regards

Changying Li

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: please help me to find errors from my first app

2008-08-10 Thread Changying Li
thanks. I know how to do it. I should treat it as a stream. 
-- 

Thanks  Regards

Changying Li

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] please help me to find errors from my first app

2008-08-08 Thread Changying Li
Hi. 
I want to write a reverse proxy like perlbal to practive haskell. Now I
just write a very simple script to forward any request to
www.google.com.

but it dosn't work. I run command ' runhaskell Proxy.hs'  and 'wget
http://localhost:8080/'. but wget just wait forever and runhaskkell can
get request. when I break wget, the 'runhaskell' can print response
returned from www.google.com. 
why?

module Main where

import System.Posix.Process
import Network
import Prelude hiding (putStr)
import System.IO hiding (hGetContents, putStr)

import Control.Concurrent
import System.Posix.Signals
import Data.ByteString.Lazy.Char8 (hGetContents, hPut, putStr,hGet,cons)
listenPort = PortNumber 8080
connectToHost = 208.67.219.230
connectToPort = PortNumber 80

main :: IO ()
main = do
  hSetBuffering stdout NoBuffering
  socket - listenOn listenPort
  let doLoop = do
 (hdl, _, _) - accept socket
 forkIO $ processRequest hdl
 doLoop
  doLoop

processRequest :: Handle - IO ()
processRequest hRequest = do
  installHandler sigPIPE Ignore Nothing; 
  hSetBuffering hRequest NoBuffering
  hSetBuffering stdout NoBuffering
  request - hGetContents hRequest
  putStr $ '' `cons` (' ' `cons` request)
  hResponse - connectTo connectToHost connectToPort
  hSetBuffering hResponse NoBuffering
  hPut hResponse request
  response - hGetContents hResponse
  putStr $ '' `cons` (' ' `cons` response)
  hPut hRequest response
  hClose hRequest
  hClose hResponse





-- 

Thanks  Regards

Changying Li

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe