-$Id: Changes,v 1.36 2006-06-13 16:44:51 mike Exp $
+$Id: Changes,v 1.37 2006-06-15 15:43:13 mike Exp $
Revision history for Perl extension Net::Z3950::ZOOM.
+1.10 Thu Jun 15 16:42:47 BST 2006
+ - No functional changes, but use Adam's modified API to
+ ZOOM_query_ccl2rpn(). This incompatible change means that
+ RELEASE 1.09 WILL NOT BUILD against any recent YAZ.
+
1.09 Tue Jun 13 17:44:43 2006
- Add new function Net::Z3950::ZOOM::query_ccl2rpn(), for
client-side CCL compilation.
-/* $Id: ZOOM.xs,v 1.41 2006-06-13 16:44:21 mike Exp $ */
+/* $Id: ZOOM.xs,v 1.42 2006-06-15 15:43:13 mike Exp $ */
#include "EXTERN.h"
#include "perl.h"
ZOOM_connection conn
int
-ZOOM_query_ccl2rpn(s, str, conn)
+ZOOM_query_ccl2rpn(s, query_str, config, errcode, errstr, errpos)
ZOOM_query s
- const char* str
- ZOOM_connection conn
+ const char* query_str
+ const char* config
+ int &errcode
+ const char* &errstr
+ int &errpos
+ OUTPUT:
+ RETVAL
+ errcode
+ errstr
+ errpos
int
ZOOM_query_prefix(s, str)
-# $Id: ZOOM.pm,v 1.34 2006-06-13 16:44:21 mike Exp $
+# $Id: ZOOM.pm,v 1.35 2006-06-15 15:43:14 mike Exp $
use strict;
use warnings;
+use IO::File;
use Net::Z3950::ZOOM;
sub SCANTERM { 20007 }
sub LOGLEVEL { 20008 }
+# Separate space for CCL errors. Great.
+package ZOOM::CCL::Error;
+sub OK { Net::Z3950::ZOOM::CCL_ERR_OK }
+sub TERM_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_TERM_EXPECTED }
+sub RP_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_RP_EXPECTED }
+sub SETNAME_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_SETNAME_EXPECTED }
+sub OP_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_OP_EXPECTED }
+sub BAD_RP { Net::Z3950::ZOOM::CCL_ERR_BAD_RP }
+sub UNKNOWN_QUAL { Net::Z3950::ZOOM::CCL_ERR_UNKNOWN_QUAL }
+sub DOUBLE_QUAL { Net::Z3950::ZOOM::CCL_ERR_DOUBLE_QUAL }
+sub EQ_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_EQ_EXPECTED }
+sub BAD_RELATION { Net::Z3950::ZOOM::CCL_ERR_BAD_RELATION }
+sub TRUNC_NOT_LEFT { Net::Z3950::ZOOM::CCL_ERR_TRUNC_NOT_LEFT }
+sub TRUNC_NOT_BOTH { Net::Z3950::ZOOM::CCL_ERR_TRUNC_NOT_BOTH }
+sub TRUNC_NOT_RIGHT { Net::Z3950::ZOOM::CCL_ERR_TRUNC_NOT_RIGHT }
+
# The "Event" package contains constants returned by last_event()
package ZOOM::Event;
sub NONE { Net::Z3950::ZOOM::EVENT_NONE }
sub _oops {
my($code, $addinfo, $diagset) = @_;
- die new ZOOM::Exception($code, diag_str($code), $addinfo, $diagset);
+ die new ZOOM::Exception($code, undef, $addinfo, $diagset);
}
# ----------------------------------------------------------------------------
my $class = shift();
my($code, $message, $addinfo, $diagset) = @_;
+ $diagset ||= "ZOOM";
+ if ($diagset eq "ZOOM") {
+ $message ||= ZOOM::diag_str($code);
+ } else {
+ # Should fill in messages for other diagsets, too.
+ }
+
return bless {
code => $code,
message => $message,
addinfo => $addinfo,
- diagset => $diagset || "ZOOM",
+ diagset => $diagset,
}, $class;
}
}
-# It's distressing how very similar this is to CQL2RPN
+# We have to work around the retarded ZOOM_query_ccl2rpn() API
package ZOOM::Query::CCL2RPN;
our @ISA = qw(ZOOM::Query);
my $q = Net::Z3950::ZOOM::query_create()
or ZOOM::_oops(ZOOM::Error::CREATE_QUERY);
- # check() throws the exception we want; but we only want it on failure!
- Net::Z3950::ZOOM::query_ccl2rpn($q, $string, $conn->_conn()) == 0
- or $conn->_check();
+
+ my $config = $conn->option("cclqual");
+ if (!defined $config) {
+ my $cclfile = $conn->option("cclfile")
+ or ZOOM::_oops(ZOOM::Error::CCL_CONFIG,
+ "no 'cclqual' or 'cclfile' specified");
+ my $fh = new IO::File("<$cclfile")
+ or ZOOM::_oops(ZOOM::Error::CCL_CONFIG,
+ "can't open cclfile '$cclfile': $!");
+ $config = join("", <$fh>);
+ $fh->close();
+ }
+
+ my($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0, "", 0);
+ if (Net::Z3950::ZOOM::query_ccl2rpn($q, $string, $config,
+ $ccl_errcode, $ccl_errstr,
+ $ccl_errpos) < 0) {
+ # We have no use for $ccl_errcode or $ccl_errpos
+ ZOOM::_oops(ZOOM::Error::CCL_PARSE, $ccl_errstr);
+ }
return bless {
_query => $q,
-# $Id: 12-query.t,v 1.6 2006-06-13 16:15:12 mike Exp $
+# $Id: 12-query.t,v 1.7 2006-06-15 15:43:19 mike Exp $
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 12-query.t'
check_record($conn, $q);
Net::Z3950::ZOOM::query_destroy($q);
-# Client-side compiled CCL: this will fail due to lack of qualifier-file
+# Client-side compiled CCL: this will fail due to incorrect syntax
$q = Net::Z3950::ZOOM::query_create();
ok(defined $q, "create empty query");
+my($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0, "", 0);
+
+### change documentation
$res = Net::Z3950::ZOOM::query_ccl2rpn($q,
- 'ti=utah and ab=epicenter',
- $conn);
-$errcode = Net::Z3950::ZOOM::connection_error_x($conn, $errmsg, $addinfo,
- $diagset);
+ 'ti=utah and',
+ "ti u=4 s=pw\nab u=62 s=pw",
+ $ccl_errcode, $ccl_errstr, $ccl_errpos);
ok($res < 0 &&
- $errcode == Net::Z3950::ZOOM::ERROR_CCL_CONFIG &&
- $diagset eq "ZOOM",
- "can't make CCL2RPN query: error " . $errcode);
+ $ccl_errcode == Net::Z3950::ZOOM::CCL_ERR_TERM_EXPECTED,
+ "can't make CCL2RPN query: error $ccl_errcode ($ccl_errstr)");
Net::Z3950::ZOOM::query_destroy($q);
# Do a successful client-compiled CCL search
"samples/ccl/default.bib");
$res = Net::Z3950::ZOOM::query_ccl2rpn($q,
'ti=utah and ab=epicenter',
- $conn);
+ "ti u=4 s=pw\nab u=62 s=pw",
+ $ccl_errcode,
+ $ccl_errstr,
+ $ccl_errpos);
ok($res == 0, "created CCL2RPN query");
check_record($conn, $q);
Net::Z3950::ZOOM::query_destroy($q);
-# $Id: 15-scan.t,v 1.10 2006-06-13 16:44:21 mike Exp $
+# $Id: 15-scan.t,v 1.11 2006-06-15 15:45:48 mike Exp $
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 15-scan.t'
ok(1, "destroyed third scanset");
# Now using CCL
-Net::Z3950::ZOOM::connection_option_set($conn, cclfile =>
- "samples/ccl/default.bib");
$q = Net::Z3950::ZOOM::query_create();
-Net::Z3950::ZOOM::query_ccl2rpn($q, 'ti=w', $conn);
+my($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0, "", 0);
+Net::Z3950::ZOOM::query_ccl2rpn($q, 'ti=w', "ti u=4 s=pw",
+ $ccl_errcode, $ccl_errstr, $ccl_errpos);
($ss, $n) = scan($conn, 1, $q, 4);
# Get last term and use it as seed for next scan
$term = Net::Z3950::ZOOM::scanset_term($ss, $n-1, $occ, $len);
-# $Id: 22-query.t,v 1.7 2006-06-13 16:14:58 mike Exp $
+# $Id: 22-query.t,v 1.8 2006-06-15 15:43:19 mike Exp $
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 22-query.t'
$conn->option(cqlfile => "samples/cql/pqf.properties");
eval { $q = new ZOOM::Query::CQL2RPN('title=utah and description=epicenter',
$conn) };
-ok(!$@, "created CQL2RPN query: \@=$@");
+ok(!$@, "created CQL2RPN query");
check_record($conn, $q);
$q->destroy();
ok(1, "[no need to create empty query]");
$conn->option(cclfile => "samples/ccl/default.bib");
eval { $q = new ZOOM::Query::CCL2RPN('ti=utah and ab=epicenter', $conn) };
-ok(!$@, "created CCL2RPN query: \@=$@");
+ok(!$@, "created CCL2RPN query");
check_record($conn, $q);
$q->destroy();