in reply to Re: Perl XS - is this code required in DBD::Pg? (cruft)
in thread Perl XS - is this code required in DBD::Pg?
Interesting comments tye. The code as I have it in DBD::ODBC does indeed pass is \$buf from Perl and works fine. The only bit from the DBD::Pg code I omitted was the sv_setpvn. Logically, I think the method I'm creating should pass in a reference to a scalar and that scalar should be grown to fit the returned lob data so I'll play with your suggested changes. Thanks. As it stands I have:
void odbc_lob_read(sth, colno, buf, length, attr = NULL) SV *sth int colno char *buf UV length SV *attr; PROTOTYPE: $$$$;$ PREINIT: SV * const bufsv = SvROK(ST(2)) ? SvRV(ST(2)) : ST(2); UV ret_len; IV sql_type = 0; CODE: if (length == 0) { croak("Cannot retrieve 0 length lob"); } if (attr) { SV **svp; DBD_ATTRIBS_CHECK("odbc_lob_read", sth, attr); DBD_ATTRIB_GET_IV(attr, "Type", 4, svp, sql_type); } sv_setpvn(bufsv, "", 0); /* ensure we can grow +ok */ /* length is the length in chrs/bytes depending on the underlying * datatype. i.e., it is usually bytes but if we are built to sup +port * unicode and the column is not a binary type, we will convert t +o * UTF8 encoding so we need at least 6 * as many bytes. */ buf = SvGROW(bufsv, length * + 1); ret_len = odbc_st_lob_read(sth, colno, bufsv, length, sql_type); if (ret_len > 0) { SvCUR_set(bufsv, ret_len); /* set length in SV */ *SvEND(bufsv) = '\0'; /* NUL terminate */ /*sv_setpvn(ST(3), buf, 4);*/ SvSETMAGIC(ST(2)); } ST(0) = (ret_len >= 0) ? sv_2mortal(newSViv(ret_len)) : &PL_sv_un +def;
and Perl code
my $s = $h->prepare(q{select 'frederick'}); $s->execute; $s->bind_col(1, undef, {BindAsLOB=>1}); $s->fetch; # SQL_SUCCESS = 0 # SQL_SUCCESS_WITH_INFO = 1 # SQL_NO_DATA = 100 while(my $len = $s->odbc_lob_read(1, \my $x, 8)) { print "len=$len, x=$x\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Perl XS - is this code required in DBD::Pg? (empty)
by tye (Sage) on Jul 21, 2010 at 19:14 UTC | |
by mje (Curate) on Jul 21, 2010 at 19:19 UTC | |
by mje (Curate) on Jul 22, 2010 at 10:17 UTC | |
by tye (Sage) on Jul 22, 2010 at 21:06 UTC | |
by mje (Curate) on Jul 23, 2010 at 09:54 UTC |