develooper Front page | perl.dbi.oracle-oci | Postings from September 2001

Segfault on VARRAY fetch

Thread Next
From:
John Gorkos
Date:
September 6, 2001 13:15
Subject:
Segfault on VARRAY fetch
Message ID:
200109062014.PAA10081@kansas-city.sema.slb.com
Help-
  I am trying to read spatial data from a standard SDO structure, as shown in the readgeom.c example in 
$ORACLE_HOME/md/demo/examples (8.1.7)
Using Oracle::OCI, I am able to connect and prepare the query, after describing the objects that 
I want to pull back.  However, when I execute the query, I get segfaults under both Solaris (with coredump) and Linux.  
Here are some code snippets that are relevant (I'm assuming you're looking at readgeom.c 
for the missing pieces).  Commentary follows the code, before the DBI->trace dump.

sub read_geometries {
        my ( $table, $geom_column, $id_column, $num_dimensions ) = @_;
        my $query = "SELECT $id_column, $geom_column from $table";
 
        OCIStmtPrepare( $stmthp, $errhp, oci_buf_len($query), OCI_NTV_SYNTAX, OCI_DEFAULT );
 
        # following are the pre-define statements
#       sizeof(OCINumber)=22, SQLT_VNU=6
#       OCIDefineByPos($stmthp, my $defn1p=0, $errhp, 1, my $global_gid=0, sizeof(OCI_NUMBER),SQLT_VNU, 0, my $rlenp1=0, my $rcodep1=0, OCI_DEFAULT );
        OCIDefineByPos($stmthp, my $defn1p=0, $errhp, 1, my $global_gid=0, 22, 6, 0, my $rlenp1=0, my $rcodep1=0, OCI_DEFAULT );
#       OCIDefineByPos($stmthp, my $defn2p=0, $errhp, 2, 0, 0, SQLT_NTY, 0, my $rlenp2=0, my $rcodep2=0, OCI_DEFAULT );
        OCIDefineByPos($stmthp, my $defn2p=0, $errhp, 2, 0, 0, 108, 0, my $rlenp2=0, my $rcodep2=0, OCI_DEFAULT );
        bless $defn2p=>'OCIDefinePtr';
        my $status=OCIDefineObject($defn2p, $errhp, $geom_tdo, my $global_geom_obj=0, my $pvspsz=0, my $global_geom_ind=0, my $indszp=0 );
        print get_oci_error( $errhp, $status, 'Foo' ), "\n" unless $status==OCI_SUCCESS;
 
        # execute
        # ARRAY_SIZE = 32
        my $snap_in = 0;
        my $snap_out = 0;
        $status = OCIStmtExecute( $svchp, $stmthp, $errhp, 32, 0, $snap_in, $snap_out, OCI_DEFAULT );
        print get_oci_error( $errhp, $status, 'Foo' ), "\n" unless $status==OCI_SUCCESS;
        my $more_data = 1;
        if ( $status==OCI_SUCCESS_WITH_INFO || $status==OCI_NO_DATA ) {
                print "No more data\n";
                $more_data = 0;
        }
        $status=OCIAttrGet( $stmthp, OCI_HTYPE_STMT, my $cols_fetched, 0, OCI_ATTR_PARAM_COUNT, $errhp, 4 );
        print get_oci_error( $errhp, $status, 'Foo' ), "\n" unless $status==OCI_SUCCESS;
        print "Number of Columns fetched is $cols_fetched\n";
        OCIAttrGet( $stmthp, OCI_HTYPE_STMT, my $rows_fetched, 0, OCI_ATTR_ROW_COUNT, $errhp, 4 );
        print get_oci_error( $errhp, $status, 'Foo' ), "\n" unless $status==OCI_SUCCESS;
        print "Number of rows fetched is $rows_fetched\n";
...

According to readgeom.c, I need ARRAY_SIZE (which is 32) as my 'iters' parameter in the OCIStmtExecute.  
When I set this to 0 (zero), the code executes flawlessly, but OCI_ATTR_ROW_COUNT also returns zero
(but the column count always returns 2, which is correct for the query).
I suspect strongly that the error is in the OCIDefineObject statement.  According to the OCI reference book, I need to be
allocating memory space for the statement to return the values into, but I just don't know how to do it.  The keys are the 4th-7th
params of OCIDefineObject.  I'm NOT a C programmer, meaning many of the arcane uses of pointers to pointers and the concept
of pointers pointing to arrays of pointers REALLY fogs my brain, and I don't know how to translate this to Perl.  I suspect that if
I managed to get the right structures, it would all work.
Any thoughts?  Please?

John Gorkos

Following is the OCI dump caused by DBI->trace(9);
    OCIDefineByPos stmtp: converting OCIStmtPtr=SCALAR(0x81c46b0) to OCIStmtPtr at ./oci_test.pl line 88.
    OCIDefineByPos defnp: converting 0 to OCIDefinePtr at ./oci_test.pl line 88.
    OCIDefineByPos defnp: passing as null pointer at ./oci_test.pl line 88.
    OCIDefineByPos errhp: converting OCIErrorPtr=SCALAR(0x81c3e3c) to OCIErrorPtr at ./oci_test.pl line 88.
    OCIDefineByPos valuep: converting 0 to voidPtr at ./oci_test.pl line 88.
    OCIDefineByPos valuep: passing as null pointer at ./oci_test.pl line 88.
    OCIDefineByPos indp: converting 0 to voidPtr at ./oci_test.pl line 88.
    OCIDefineByPos indp: passing as null pointer at ./oci_test.pl line 88.
    OCIDefineByPos setting OCIDefinePtr defnp=0x827eb24/136833828 at ./oci_test.pl line 88.
    OCIDefineByPos returned SUCCESS at ./oci_test.pl line 88.
    OCIDefineByPos stmtp: converting OCIStmtPtr=SCALAR(0x81c46b0) to OCIStmtPtr at ./oci_test.pl line 90.
    OCIDefineByPos defnp: converting 0 to OCIDefinePtr at ./oci_test.pl line 90.
    OCIDefineByPos defnp: passing as null pointer at ./oci_test.pl line 90.
    OCIDefineByPos errhp: converting OCIErrorPtr=SCALAR(0x81c3e3c) to OCIErrorPtr at ./oci_test.pl line 90.
    OCIDefineByPos valuep: converting 0 to voidPtr at ./oci_test.pl line 90.
    OCIDefineByPos valuep: passing as null pointer at ./oci_test.pl line 90.
    OCIDefineByPos indp: converting 0 to voidPtr at ./oci_test.pl line 90.
    OCIDefineByPos indp: passing as null pointer at ./oci_test.pl line 90.
    OCIDefineByPos setting OCIDefinePtr defnp=0x827e980/136833408 at ./oci_test.pl line 90.
    OCIDefineByPos returned SUCCESS at ./oci_test.pl line 90.
    OCIDefineObject defnp: converting OCIDefinePtr=SCALAR(0x81c4e64) to OCIDefinePtr at ./oci_test.pl line 92.
    OCIDefineObject errhp: converting OCIErrorPtr=SCALAR(0x81c3e3c) to OCIErrorPtr at ./oci_test.pl line 92.
    OCIDefineObject type: converting OCITypePtr=SCALAR(0x81c495c) to OCITypePtr at ./oci_test.pl line 92.
    OCIDefineObject pgvpp: converting 0 to voidPtr at ./oci_test.pl line 92.
    OCIDefineObject pgvpp: passing as null pointer at ./oci_test.pl line 92.
    OCIDefineObject indpp: converting 0 to voidPtr at ./oci_test.pl line 92.
    OCIDefineObject indpp: passing as null pointer at ./oci_test.pl line 92.
    OCIDefineObject setting voidPtr pgvpp=0x0/0 at ./oci_test.pl line 92.
    OCIDefineObject setting voidPtr indpp=0x0/0 at ./oci_test.pl line 92.
    OCIDefineObject returned SUCCESS at ./oci_test.pl line 92.
    OCIStmtExecute svchp: converting OCISvcCtxPtr=SCALAR(0x81c3f44) to OCISvcCtxPtr at ./oci_test.pl line 99.
    OCIStmtExecute stmtp: converting OCIStmtPtr=SCALAR(0x81c46b0) to OCIStmtPtr at ./oci_test.pl line 99.
    OCIStmtExecute errhp: converting OCIErrorPtr=SCALAR(0x81c3e3c) to OCIErrorPtr at ./oci_test.pl line 99.
    OCIStmtExecute snap_in: converting 0 to OCISnapshotPtr at ./oci_test.pl line 99.
    OCIStmtExecute snap_in: passing as null pointer at ./oci_test.pl line 99.
    OCIStmtExecute snap_out: converting 0 to OCISnapshotPtr at ./oci_test.pl line 99.
    OCIStmtExecute snap_out: passing as null pointer at ./oci_test.pl line 99.
Segmentation fault

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About