Re: [eclipse-clp-users] database interface

From: Kish Shen <kisshen_at_cisco.com>
Date: Thu, 30 Oct 2008 15:50:57 +0000
Hi Carlo,

I am posting this to the mailing list again as it may be of more general 
interest.

You are right. I should have looked at the dbi code more closely, as I 
have not looked at it for a while now.

The way to get tuples on backtracking is to do it like 
session_retrieve_tuple/4 in dbi.ecl, using a repeat:

student(Cursor, Age) :-
	repeat,
	(cursor_next_tuple(Cursor,Age) -> true ; !, fail).


I agree that the manual is not too clear on this. I will try and improve 
that.

Thanks and cheers,

Kish

Carlo Matteo Scalzo wrote:
> Here is the code: i'm assuming i have already created a mysql database
> called 'dbpl', and a user called 'dbpluser' (password: dbpluser) who has the
> right to access the dbpl database.
> 
> The first call creates a table 'students' having a single column ('age'),
> and adds 3 rows to it:
> 
> 
> session_start(dbpluser,dbpluser,_,Session),
> session_sql(Session,"use dbpl",_),
> session_sql(Session, "create table students (age decimal(2))", _),
> session_sql(Session, "insert into students values (23)", _),
> session_sql(Session, "insert into students values (31)", _),
> session_sql(Session, "insert into students values (16)", _),
> session_commit(Session),
> session_close(Session).
> 
> 
> The second call 'manually' calls cursor_next_tuple/2 (on the query "select *
> from students") and prints the results. It is called 3 times in order to
> retrieve the 3 rows just inserted.
> 
> 
> session_start(dbpluser,dbpluser,_,Session),
> session_sql(Session,"use dbpl",_),
> session_sql_query(Session,students(age),"select * from students", Cursor),
> cursor_next_tuple(Cursor, students(Age1)),
> writeln(Age1),
> cursor_next_tuple(Cursor, students(Age2)),
> writeln(Age2),
> cursor_next_tuple(Cursor, students(Age3)),
> writeln(Age3),
> session_close(Session).
> 
> Calling the above conjunctive goal correctly prints:
> 
> 23
> 31
> 16
> 
> 
> Now the real test. The following code tries to use backtracking on
> cursor_next_tuple/2.
> 
> 
> session_start(dbpluser,dbpluser,_,Session),
> session_sql(Session,"use dbpl",_),
> session_sql_query(Session,students(age),"select * from students", Cursor),
> cursor_next_tuple(Cursor, students(Age)),
> writeln(Age),
> fail.
> 
> 
> Calling the above goal prints:
> 
> 23
> 
> In fact, using the tracer, you can see that cursor_next_tuple/2 is skipped
> on backtracking. It returns the first tuple only.
> 
> 
> Thanks again for your help.
> 


-- 
This e-mail may contain confidential and privileged material for the
sole use of the intended recipient. Any review, use, distribution or
disclosure by others is strictly prohibited. If you are not the intended
recipient (or authorized to receive for the recipient), please contact
the sender by reply e-mail and delete all copies of this message.
Cisco Systems Limited (Company Number: 02558939), is registered in
England and Wales with its registered office at 1 Callaghan Square,
Cardiff, South Glamorgan CF10 5BT.
Received on Thu Oct 30 2008 - 16:24:31 CET

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET