Re: [eclipse-clp-users] Dbi prepare query issue.

From: Kish Shen <kish.shen_at_...6...>
Date: Tue, 8 Mar 2016 20:37:30 +0000
Shrirang,

>Kindly let me know what could be wrong.

It looks like you are not using cursor_next_execute/2 correctly. Have you
read the documentation for lib(dbi) -- both the chapter in the embedding
and interface manual

http://eclipseclp.org/doc/embedding/embroot059.html

and the reference documentations for the library predicates, such as
cursor_next_execute/2:

http://eclipseclp.org/doc/bips/lib/dbi/cursor_next_execute-2.html

both these explains how to use prepared SQL statements, and should have the
information on your problem..

I think the reason you are getting the bad template error is because you
are calling cursor_next_execute(Cursor, Result1) with Result1 being
count(Result2) where Result2 being a variable. Judging from your code, you
seem to be expecting cursor_next_execute/2 to be returning results from
some results to be returned from the prepared SQL query. This is incorrect--
cursor_execute/2 is actually used to *execute* the prepared SQL statement
from session_sql_prepare/4: this should be clear from the summary of the
reference documentation:

cursor_next_execute(++Cursor, +Tuple)Executes the parametrised prepared SQL
statement represented by Cursor.*Cursor*A cursor handle*Tuple*A tuple of
parameter values matching the template for this cursor (structure)
The second argument, which you call Resuts1, is actually there to supply
the parameter value for the prepared SQL statement represented by Cursor -
the ? in your  "select count(column) from table where column > ?" so in
your case, if you call cursor_next_execute(Cursor, count(7), that will
execute the SQL query

"select count(column) from table where column > 7".

Your code is also missing a predicate such as cursor_all_tuples/2 to
collect the results from the SQL query. Again, this is stated clearly in
the reference documentation:

>If the SQL statement is a query, and was prepared as a query using
session_sql_prepare_query/5, results can be obtained from the query by the
cursor_*_tuple family of predicates.

Cheers,

Kish



On Tue, Mar 8, 2016 at 4:28 AM, Edgaonkar, Shrirang <
Shrirang.Edgaonkar@...390...> wrote:

> Dear clp users,
>
>
>
>   I am facing a problem with prepare statement in 32 bit as well as 64 bit
> Windows OS using respective ECLipSe.
>
> Eclipse version is 6.1 217. Kindly let me know what could be wrong. Please
> find the console output at the end of the email.
>
>
>
> :- lib(dbi).
> :- lib(ic).
> solveDB(Result):-
>     Result2 :: 1..10,
>     Template = count(24),
>     session_start("blah"@"blah", "blah", [dbname:"blah"], Session),
>  writeln("TEST"),
>     SQL = "select count(column) from table where column > ?",
>  writeln("TEST1"),
>     session_sql_prepare(Session, Template, SQL, Cursor),
>  writeln([Cursor,"TEST2"]),
>  Result1 = count(Result2),
>     cursor_next_execute(Cursor, Result1),
>  writeln(Result1),
>     cursor_close(Cursor).
>
>
>
>
> ----------------------------------------------------------------------------------------------------------------
>
>
>
> console output:-
>
>
>
> TEST
> TEST1
> [cursor('MySQLC'(16'327ee0), 'MySQLS'(16'327e40)), TEST2]
> DBI General exception Code:-5 in
> cursor_next_exec(cursor('MySQLC'(16'327ee0), 'M
> ySQLS'(16'327e40)), count(_138309), options(_138404, _138405, "client",
> "read_on
> ly"))
> DBI-005: bad template
> Aborting execution ...
> abort
>
> Thanks and Regards,
>
> Shrirang Edgaonkar
>
>
>
> ______________________________________________________________________
> Disclaimer: This email and any attachments are sent in strictest confidence
> for the sole use of the addressee and may contain legally privileged,
> confidential, and proprietary data. If you are not the intended recipient,
> please advise the sender by replying promptly to this email and then delete
> and destroy this email and any attachments without any further use, copying
> or forwarding.
>
>
> ------------------------------------------------------------------------------
> Transform Data into Opportunity.
> Accelerate data analysis in your applications with
> Intel Data Analytics Acceleration Library.
> Click to learn more.
> http://makebettercode.com/inteldaal-eval
> _______________________________________________
> ECLiPSe-CLP-Users mailing list
> ECLiPSe-CLP-Users_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users
>
>
Received on Tue Mar 08 2016 - 20:37:38 CET

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:30 CEST