List Info

Thread: "ocaml_beginners"::[] pgocaml: how to use it?




"ocaml_beginners"::[] pgocaml: how to use it?
country flaguser name
South Africa
2007-08-23 08:05:49

I am trying out pGOCaml and so far I did not have any success:

$ env | grep PG
PGPORT=5432
PGUSER=js
PGDATABASE=js
PGHOST=localhost

Postgresql is running.

====================
$ make test_pgocaml
ocamlfind ocamlc -g -package unix,extlib,pcre,calendar -I
/usr/local/lib/ocaml/3.09.2/csv -linkpkg csv.cma
-pp "camlp4o /usr/lib/ocaml/3.09.2/unix.cma
/usr/lib/ocaml/3.09.2/str.cma -I +pcre
/usr/lib/ocaml/3.09.2/pcre/pcre.cma -I +extlib
/usr/lib/ocaml/3.09.2/extlib/extLib.cma -I +calendar
/usr/lib/ocaml/3.09.2/calendar/calendar.cma -I
/usr/local/lib/ocaml/3.09.2/csv csv.cma ./pgocaml.cma
./pa_pgsql.cmo" -c test_pgocaml.ml
File "", line 0, characters 0-1:
Uncaught exception: End_of_file
Uncaught exception: End_of_file
Preprocessor error
make: *** [test_pgocaml.cmo] Error 2
=========================
When I try out the example on the home page:
=================

Objective Caml version 3.09.2

Findlib has been successfully loaded. Additional directives:
...

# let () =
let dbh = PGOCaml.connect () in
let insert name salary email =
PGSQL(dbh) "insert into employees (name, salary, email)
values ($name, $salary, $?email)"
in
insert "Ann" 10_000_l None;
insert "Bob" 45_000_l None;
insert "Jim" 20_000_l None;
insert "Mary" 30_000_l (Some " mary%40example.com">maryexample.com");

let rows =
PGSQL(dbh) "select id, name, salary, email from employees" in
List.iter (
fun (id, name, salary, email) ->
let email = match email with Some email -> email | None -> "-" in
Printf.printf "%ld %S %ld %Sn" id name salary email
) rows;

PGOCaml.close dbh;;
Characters 92-187:
................"insert into employees (name, salary, email)
values ($name, $salary, $?email)"
Syntax error
#
=======================

And I don't know my way forward from here.

When I try just the 'connect' part, I get the same error as when I try
to compile pg_ocaml:

# let a = PGOCaml.connect ~host:"localhost" ~user:"js" ~database:"js" ();;
Exception: End_of_file.

Regards
Johann
--
Johann Spies Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

"For God hath not appointed us to wrath, but to obtain
salvation by our Lord Jesus Christ, Who died for us,
that, whether we wake or sleep, we should live
together with him."
I Thessalonians 5:9,10

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] pgocaml: how to use it?
country flaguser name
United Kingdom
2007-08-23 17:02:27

On Thu, Aug 23, 2007 at 03:05:49PM +0200, Johann Spies wrote:
> Characters 92-187:
> ................"insert into employees (name, salary, email)
> values ($name, $salary, $?email)"
> Syntax error

This isn't going to work unless the camlp4 syntax extension is loaded.

> # let a = PGOCaml.connect ~host:"localhost" ~user:"js" ~database:"js" ();;
>; Exception: End_of_file.

This seems to be some problem with the database or protocol itself.
Using 'strace' is probably a good idea, because it basically works for
me on lots of versions of PostgreSQL.

Rich.

--
Richard Jones
Red Hat

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] pgocaml: how to use it?
country flaguser name
South Africa
2007-08-31 04:08:51

On Thu, Aug 23, 2007 at 11:02:27PM +0100, Richard Jones wrote:
> On Thu, Aug 23, 2007 at 03:05:49PM +0200, Johann Spies wrote:
> > Characters 92-187:
> > ................"insert into employees (name, salary, email)
> > values ($name, $salary, $?email)"
> > Syntax error
>
> This isn't going to work unless the camlp4 syntax extension is loaded.
>
> > # let a = PGOCaml.connect ~host:"localhost" ~user:"js" ~database:"js" ();;
>; > Exception: End_of_file.
>
> This seems to be some problem with the database or protocol itself.
> Using 'strace' is probably a good idea, because it basically works for
> me on lots of versions of PostgreSQL.
>

I have 'straced' 'make' now. First I found this when I used
LC_MESSAGE="af_ZA" or "en_ZA":

munmap(0x2b126f1e6000, 4096) = 0
open("/usr/share/locale/en_ZA/LC_MESSAGES/make.mo", O_RDONLY) = -1
ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/make.mo", O_RDONLY) = -1 ENOENT
(No such file or directory)
write(2, "make: ", 6make: ) = 6
write(2, "*** [test_pgocaml.cmo] Error 2", 30*** [test_pgocaml.cmo]
Error 2) = 30
write(2, "n", 1
) = 1
rt_sigprocmask(SIG_BLOCK, [HUP INT QUIT TERM XCPU XFSZ], NULL, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
chdir("/home/js/rugsteun/src/pgocaml-0.8") = 0
close(1) = 0
munmap(0x2b126f1e5000, 4096) = 0
exit_group(2) = ?
Process 14543 detached

Changing it to "en_UK" helped. Strace ended with:
stat("test_pgocaml_lowlevel", {st_mode=S_IFREG|0755, st_size=831239,
...}) = 0
stat("test_pgocaml_lowlevel.cmo", {st_mode=S_IFREG|0644,
st_size=11364, ...}) = 0
stat("test_pgocaml_lowlevel.ml", {st_mode=S_IFREG|0644, st_size=3193,
...}) = 0
stat("test_pgocaml";, 0x7fff2b1abf20) = -1 ENOENT (No such file or
directory)
stat("test_pgocaml.cmo", 0x7fff2b1abe30) = -1 ENOENT (No such file or
directory)
stat("test_pgocaml.ml", {st_mode=S_IFREG|0644, st_size=1254, ...}) = 0
fstat(1, {st_mode=S_IFCHR|0700, st_rdev=makedev(4, 3), ...}) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo
...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x2b647fa91000
write(1, "ocamlfind ocamlc -g -package uni"..., 109ocamlfind ocamlc -g
-package unix,extlib,pcre,calendar -I /usr/local/lib/ocaml/3.09.2/csv
-linkpkg csv.cma
) = 109
write(1, "t -pp "camlp4o /usr/lib/ocaml/3"..., 322 -pp "camlp4o
/usr/lib/ocaml/3.09.2/unix.cma /usr/lib/ocaml/3.09.2/str.cma -I +pcre
/usr/lib/ocaml/3.09.2/pcre/pcre.cma -I +extlib
/usr/lib/ocaml/3.09.2/extlib/extLib.cma -I +calendar
/usr/lib/ocaml/3.09.2/calendar/calendar.cma -I
/usr/local/lib/ocaml/3.09.2/csv csv.cma ./pgocaml.cma ./pa_pgsql.cmo"
-c test_pgocaml.ml
) = 322
pipe([3, 4]) = 0
close(4) = 0
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
rt_sigprocmask(SIG_BLOCK, [HUP INT QUIT TERM XCPU XFSZ], NULL, 8) = 0
vfork() = 14577
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
wait4(-1, File "", line 0, characters 0-1:
Uncaught exception: End_of_file
Uncaught exception: End_of_file
Preprocessor error
[{WIFEXITED(s) && WEXITSTATUS(s) == 2}], 0, NULL) = 14577
--- SIGCHLD (Child exited) 0 (0) ---
rt_sigreturn(0xffffffff) = 14577
write(2, "make: ", 6make: ) = 6
write(2, "*** [test_pgocaml.cmo] Error 2", 30*** [test_pgocaml.cmo]
Error 2) = 30
write(2, "n", 1
) = 1
rt_sigprocmask(SIG_BLOCK, [HUP INT QUIT TERM XCPU XFSZ], NULL, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
chdir("/home/js/rugsteun/src/pgocaml-0.8") = 0
close(1) = 0
munmap(0x2b647fa91000, 4096) = 0
exit_group(2) = ?
Process 14565 detached

Regards
Johann

--
Johann Spies Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

" ...Take heed, and beware of covetousness; for a man's
life consisteth not in the abundance of the things
which he possesseth." Luke 12:15

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] pgocaml: how to use it?
country flaguser name
United Kingdom
2007-08-31 17:20:09

On Fri, Aug 31, 2007 at 11:08:51AM +0200, Johann Spies wrote:
> I have 'straced' 'make' now. First I found this when I used
>; LC_MESSAGE="af_ZA" or "en_ZA":
> write(2, "make: ", 6make: ) = 6
> write(2, "*** [test_pgocaml.cmo] Error 2", 30*** [test_pgocaml.cmo]

Not hugely useful because this just shows that make fails. You need
to strace the actual program which fails -- try 'strace -f' and
untangle the failing program from that.

Rich.

--
Richard Jones
Red Hat

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] pgocaml: how to use it?
country flaguser name
South Africa
2007-09-05 08:42:26

On Fri, Aug 31, 2007 at 11:20:09PM +0100, Richard Jones wrote:

> Not hugely useful because this just shows that make fails. You need
>; to strace the actual program which fails -- try 'strace -f' and
> untangle the failing program from that.

Will this help:

[pid 29893] mmap(NULL, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b0a3d099000
[pid 29893] read(4, "127.0.0.1tlocalhostn127.0.1.1twe"..., 4096) =
289
[pid 29893] read(4, "", 4096) = 0
[pid 29893] close(4) = 0
[pid 29893] munmap(0x2b0a3d099000, 4096) = 0
[pid 29893] getrusage(RUSAGE_SELF, {ru_utime={0, 16001}, ru_stime={0,
8000}, ...}) = 0
[pid 29893] getrusage(RUSAGE_CHILDREN, {ru_utime={0, 0}, ru_stime={0,
0}, ...}) = 0
[pid 29893] getppid() = 29892
[pid 29893] uname({sys="Linux", node=";werkesel", ...}) = 0
[pid 29893] socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 4
[pid 29893] connect(4, {sa_family=AF_INET, sin_port=htons(5432),
sin_addr=inet_addr("127.0.0.1")}, 16) = 0
[pid 29893] fcntl(4, F_GETFD) = 0
[pid 29893] fcntl(4, F_SETFD, FD_CLOEXEC) = 0
[pid 29893] lseek(4, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
[pid 29893] lseek(4, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
[pid 29893] write(4, "353user0jsdatabase0js",
29) = 29
[pid 29893] read(4, "Rf05s354p374", 4096) = 13
[pid 29893] write(4, "p(md5d773a278418fa13717d2c01d"..., 41) =
41
[pid 29893] read(4, "E\SFATAAL0C28000Mpassword au"..., 4096)
= 93
[pid 29893] read(4, "", 4096) = 0
[pid 29893] close(3) = 0
[pid 29893] write(2, "File "", line 0, characters 0-1:"..., 65File
"", line 0, characters 0-1:
Uncaught exception: End_of_file
) = 65
[pid 29893] write(2, "Uncaught exception: End_of_filen", 32Uncaught
exception: End_of_file
) = 32
[pid 29893] exit_group(2) = ?
Process 29892 resumed
Process 29893 detached

Regards
Johann

--
Johann Spies Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

"He hath not dealt with us after our sins; nor rewarded
us according to our iniquities. For as the heaven is
high above the earth, so great is his mercy toward
them that fear him. As far as the east is from the
west, so far hath he removed our transgressions from
us." Psalms 103:10-12

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Need traffic?

Drive customers

With search ads

on Yahoo!

Yahoo! Groups

Join a yoga group

and take the stress

out of your life.

Re: "ocaml_beginners"::[] pgocaml: how to use it?
country flaguser name
United Kingdom
2007-09-06 04:11:57

On Wed, Sep 05, 2007 at 03:42:26PM +0200, Johann Spies wrote:
> [pid 29893] read(4, "E\SFATAAL0C28000Mpassword au"..., 4096)

That's the error ... If you run strace with the `-s' option you'll be
able to see more of it.

Rich.

--
Richard Jones
Red Hat

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] pgocaml: how to use it?
country flaguser name
South Africa
2007-09-06 04:39:18

On Thu, Sep 06, 2007 at 10:11:57AM +0100, Richard Jones wrote:
> On Wed, Sep 05, 2007 at 03:42:26PM +0200, Johann Spies wrote:
> > [pid 29893] read(4, "E\SFATAAL0C28000Mpassword au"..., 4096)
>
> That's the error ... If you run strace with the `-s' option you'll be
> able to see more of it.
>
Thanks. I am learning...

But: I can use psql with the same environmental variables ( psql -h
$PGHOST -d $PGDATABASE -U $PGUSER -p $PGPORT --password) and log in
with the same password. Why not using pgocaml?

Regards
Johann
--
Johann Spies Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

"Behold, I stand at the door, and knock; if any man
hear my voice, and open the door, I will come in to
him, and will sup with him, and he with me."
Revelation 3:20

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] pgocaml: how to use it?
country flaguser name
United Kingdom
2007-09-06 06:54:14

On Thu, Sep 06, 2007 at 11:39:18AM +0200, Johann Spies wrote:
> On Thu, Sep 06, 2007 at 10:11:57AM +0100, Richard Jones wrote:
> > On Wed, Sep 05, 2007 at 03:42:26PM +0200, Johann Spies wrote:
> > > [pid 29893] read(4, "E\SFATAAL0C28000Mpassword au"..., 4096)
> >
> > That's the error ... If you run strace with the `-s' option you'll be
> > able to see more of it.
> >
> Thanks. I am learning...
>
> But: I can use psql with the same environmental variables ( psql -h
> $PGHOST -d $PGDATABASE -U $PGUSER -p $PGPORT --password) and log in
> with the same password. Why not using pgocaml?

I've no idea, but I guess the error message will tell you.

Rich.

--
Richard Jones
Red Hat

__._,_.___
.

__,_._,___
Re: "ocaml_beginners"::[] pgocaml: how to use it?
country flaguser name
South Africa
2007-09-07 03:35:43

On Thu, Sep 06, 2007 at 12:54:14PM +0100, Richard Jones wrote:
> On Thu, Sep 06, 2007 at 11:39:18AM +0200, Johann Spies wrote:
> > On Thu, Sep 06, 2007 at 10:11:57AM +0100, Richard Jones wrote:
> > > On Wed, Sep 05, 2007 at 03:42:26PM +0200, Johann Spies wrote:
> > > > [pid 29893] read(4, "E\SFATAAL0C28000Mpassword au"..., 4096)
> > >
>; > > That's the error ... If you run strace with the `-s' option you'll be
> > > able to see more of it.
> > >
>; > Thanks. I am learning...
> >
>; > But: I can use psql with the same environmental variables ( psql -h
> > $PGHOST -d $PGDATABASE -U $PGUSER -p $PGPORT --password) and log in
> > with the same password. Why not using pgocaml?
>
> I've no idea, but I guess the error message will tell you.

Thanks for your trouble. My preference was to use your library, but I
have wasted several hours now to get it working. I do not understand
the logic behind the fact that the connection must be made at
compile-time and do not understand how it can then be possible to
build something that will work on another system.

It is also not clear to me whether your library is using ssl when
connecting over the network - as is the case with psql.

I could at one stage get a test program (from the pdf-documentation
recently published on this list) to compile and connect to
localhost.

But I could not repeat it the following day and I cannot see why.

I can work with the debian library (libpostgresql-ocaml) without these
problems. I can connect and manipulate databases on localhost and
other databases on the network.

Regards
Johann

--
Johann Spies Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch

"For whosoever shall call upon the name of the Lord
shall be saved." Romans 10:13

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Search Ads

Get new customers.

List your web site

in Yahoo! Search.

Yoga Groups

Find Enlightenment

& exchange insights

with other members

Re: "ocaml_beginners"::[] pgocaml: how to use it?
country flaguser name
United Kingdom
2007-09-09 16:03:36

On Fri, Sep 07, 2007 at 10:35:43AM +0200, Johann Spies wrote:
> On Thu, Sep 06, 2007 at 12:54:14PM +0100, Richard Jones wrote:
> > On Thu, Sep 06, 2007 at 11:39:18AM +0200, Johann Spies wrote:
> > > On Thu, Sep 06, 2007 at 10:11:57AM +0100, Richard Jones wrote:
> > > > On Wed, Sep 05, 2007 at 03:42:26PM +0200, Johann Spies wrote:
> > > > > [pid 29893] read(4, "E\SFATAAL0C28000Mpassword au"..., 4096)
> > > >
>; > > > That's the error ... If you run strace with the `-s' option you'll be
> > > > able to see more of it.
> > > >
>; > > Thanks. I am learning...
> > >
>; > > But: I can use psql with the same environmental variables ( psql -h
> > > $PGHOST -d $PGDATABASE -U $PGUSER -p $PGPORT --password) and log in
> > > with the same password. Why not using pgocaml?
> >
> > I've no idea, but I guess the error message will tell you.
>;
> Thanks for your trouble. My preference was to use your library, but I
> have wasted several hours now to get it working. I do not understand
> the logic behind the fact that the connection must be made at
> compile-time and do not understand how it can then be possible to
> build something that will work on another system.
>
> It is also not clear to me whether your library is using ssl when
>; connecting over the network - as is the case with psql.
>
> I could at one stage get a test program (from the pdf-documentation
> recently published on this list) to compile and connect to
> localhost.
>
> But I could not repeat it the following day and I cannot see why.
>;
> I can work with the debian library (libpostgresql-ocaml) without these
> problems. I can connect and manipulate databases on localhost and
> other databases on the network.

You want to pay me to consult on this, then fine. Otherwise it's
free software and when it breaks you get to keep both halves.

Rich.

__._,_.___
.

__,_._,___
[1-10]

about | contact  Other archives ( Real Estate discussion Medical topics )