Author: timbo
Date: Mon Feb 16 03:16:34 2004
New Revision: 63
Modified:
dbi/trunk/Changes
dbi/trunk/DBI.pm
dbi/trunk/DBI.xs
dbi/trunk/DBIXS.h
dbi/trunk/Driver.xst
dbi/trunk/Perl.xs
dbi/trunk/lib/DBI/PurePerl.pm
Log:
Added bind_col to Driver.xst so drivers can define their own.
Moved bind_columns into perl and make it call bind_col() for each.
Assorted other tidy ups.
Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes (original)
+++ dbi/trunk/Changes Mon Feb 16 03:16:34 2004
@@ -7,7 +7,6 @@
=head1 CHANGES
Drivers to change how they get debug level (with masked bits).
-Extra hooks in Driver.xst for bind_col etc
Fixed execute_for_array() so tuple_status parameter is optional
as per docs, thanks to Ed Avis.
@@ -36,6 +35,7 @@
Added details of DBI::Const::GetInfoType module to get_info() docs.
Added ref count of inner handle to "DESTROY ignored for outer" msg.
Added Win32 build config checks to DBI::DBD thanks to Andy Hassall.
+ Added bind_col to Driver.xst so drivers can define their own.
Major update to signal handling docs thanks to Lincoln Baxter.
Corrected dbiproxy usage doc thanks to Christian Hammers.
Modified: dbi/trunk/DBI.pm
==============================================================================
--- dbi/trunk/DBI.pm (original)
+++ dbi/trunk/DBI.pm Mon Feb 16 03:16:34 2004
@@ -1642,6 +1642,27 @@
return $sth->DBI::set_err(1, "bind_param_inout_array not supported");
}
+ sub bind_columns {
+ my $sth = shift;
+ my $fields = $sth->FETCH('NUM_OF_FIELDS') || 0;
+ if ($fields <= 0 && !$sth->{Active}) {
+ # XXX ought to be set_err
+ die "Statement has no result columns to bind"
+ ." (perhaps you need to successfully call execute first)";
+ }
+ # Backwards compatibility for old-style call with attribute hash
+ # ref as first arg. Skip arg if undef or a hash ref.
+ my $attr = $_[0]; # maybe
+ shift if !defined $attr or ref($attr) eq 'HASH';
+
+ die "bind_columns called with "[EMAIL PROTECTED]" refs when $fields needed."
+ if @_ != $fields;
+ my $idx = 0;
+ $sth->bind_col(++$idx, shift) or return
+ while (@_);
+ return 1;
+ }
+
sub execute_array {
my $sth = shift;
my ($attr, @array_of_arrays) = @_;
Modified: dbi/trunk/DBI.xs
==============================================================================
--- dbi/trunk/DBI.xs (original)
+++ dbi/trunk/DBI.xs Mon Feb 16 03:16:34 2004
@@ -69,9 +69,10 @@
static SV *dbih_event _((SV *h, char *name, SV*, SV*));
static int dbih_set_attr_k _((SV *h, SV *keysv, int dbikey, SV *valuesv));
static SV *dbih_get_attr_k _((SV *h, SV *keysv, int dbikey));
+static int dbih_sth_bind_col _((SV *sth, SV *col, SV *ref, SV *attribs));
-static int set_err_char _((SV *h, imp_xxh_t *imp_xxh, char *err_c, IV err_i,
char *errstr, char *state, char *method));
-static int set_err_sv _((SV *h, imp_xxh_t *imp_xxh, SV *err, SV *errstr, SV
*state, SV *method));
+static int set_err_char _((SV *h, imp_xxh_t *imp_xxh, char *err_c, IV err_i,
char *errstr, char *state, char *method));
+static int set_err_sv _((SV *h, imp_xxh_t *imp_xxh, SV *err, SV *errstr, SV
*state, SV *method));
static int quote_type _((int sql_type, int p, int s, int *base_type, void *v));
static int dbi_hash _((char *string, long i));
static void dbih_dumphandle _((SV *h, char *msg, int level));
@@ -244,6 +245,7 @@
DBIS->hash = dbi_hash;
DBIS->set_err_sv = set_err_sv;
DBIS->set_err_char= set_err_char;
+ DBIS->bind_col = dbih_sth_bind_col;
/* Remember the last handle used. BEWARE! Sneaky stuff here! */
@@ -3698,38 +3700,6 @@
DBD_ATTRIBS_CHECK("bind_col", sth, attribs);
ST(0) = boolSV(dbih_sth_bind_col(sth, col, ref, attribs));
-void
-bind_columns(sth, ...)
- SV * sth
- CODE:
- D_imp_sth(sth);
- SV *colsv;
- SV *attribs = &sv_undef;
- int fields = DBIc_NUM_FIELDS(imp_sth);
- int skip = 0;
- int i;
- if (fields <= 0 && !DBIc_ACTIVE(imp_sth))
- croak("Statement has no result columns to bind %s",
- "(perhaps you need to successfully call execute first)");
- ST(0) = &sv_yes;
- /* Backwards compatibility for old-style call with attribute hash */
- /* ref as first arg. Skip arg if undef or a hash ref. */
- if (!SvOK(ST(1)) || (SvROK(ST(1)) && SvTYPE(SvRV(ST(1)))==SVt_PVHV)) {
- attribs = ST(1);
- DBD_ATTRIBS_CHECK("bind_columns", sth, attribs);
- skip = 1;
- }
- if (items-(1+skip) != fields)
- croak("bind_columns called with %ld refs when %d needed.", items-(1+skip),
fields);
- colsv = sv_2mortal(newSViv(0));
- for(i=1; i < items-skip; ++i) {
- sv_setiv(colsv, i);
- if (!dbih_sth_bind_col(sth, colsv, ST(skip+i), attribs)) {
- ST(0) = &sv_no;
- break;
- }
- }
-
void
fetchrow_array(sth)
Modified: dbi/trunk/DBIXS.h
==============================================================================
--- dbi/trunk/DBIXS.h (original)
+++ dbi/trunk/DBIXS.h Mon Feb 16 03:16:34 2004
@@ -396,8 +396,9 @@
int (*logmsg) _((imp_xxh_t *imp_xxh, char *fmt, ...));
int (*set_err_sv) _((SV *h, imp_xxh_t *imp_xxh, SV *err, SV *errstr,
SV *state, SV *method));
int (*set_err_char) _((SV *h, imp_xxh_t *imp_xxh, char *err, IV err_i,
char *errstr, char *state, char *method));
+ int (*bind_col) _((SV *sth, SV *col, SV *ref, SV *attribs));
- void *pad2[6];
+ void *pad2[5];
};
/* macros for backwards compatibility */
Modified: dbi/trunk/Driver.xst
==============================================================================
--- dbi/trunk/Driver.xst (original)
+++ dbi/trunk/Driver.xst Mon Feb 16 03:16:34 2004
@@ -427,6 +427,46 @@
#endif /* dbd_st_rows */
+#ifdef dbd_st_bind_col
+
+void
+bind_col(sth, col, ref, attribs=Nullsv)
+ SV * sth
+ SV * col
+ SV * ref
+ SV * attribs
+ CODE:
+ {
+ IV sql_type = 0;
+ D_imp_sth(sth);
+ if (SvGMAGICAL(ref))
+ mg_get(ref);
+ if (attribs) {
+ if (SvNIOK(attribs)) {
+ sql_type = SvIV(attribs);
+ attribs = Nullsv;
+ }
+ else {
+ SV **svp;
+ DBD_ATTRIBS_CHECK("bind_col", sth, attribs);
+ /* XXX we should perhaps complain if TYPE is not SvNIOK */
+ DBD_ATTRIB_GET_IV(attribs, "TYPE",4, svp, sql_type);
+ }
+ }
+ switch(dbd_st_bind_col(sth, imp_sth, col, ref, sql_type, attribs)) {
+ case 2: ST(0) = &sv_yes; /* job done completely */
+ break;
+ case 1: /* fallback to DBI default */
+ ST(0) = (DBIc_DBISTATE(imp_sth)->bind_col(sth, col, ref, attribs))
+ ? &sv_yes : &sv_no;
+ break;
+ default: ST(0) = &sv_no; /* dbd_st_bind_col has called set_err */
+ break;
+ }
+ }
+
+#endif /* dbd_st_bind_col */
+
void
bind_param(sth, param, value, attribs=Nullsv)
SV * sth
Modified: dbi/trunk/Perl.xs
==============================================================================
--- dbi/trunk/Perl.xs (original)
+++ dbi/trunk/Perl.xs Mon Feb 16 03:16:34 2004
@@ -10,15 +10,6 @@
DBISTATE_DECLARE;
-#define dbd_discon_all(drh, imp_drh) (drh=drh,imp_drh=imp_drh,1)
-#define dbd_dr_data_sources(drh, imp_drh, attr)
(drh=drh,imp_drh=imp_drh,Nullav)
-#define dbd_db_do4(dbh,imp_dbh,p3,p4)
(dbh=dbh,imp_dbh=imp_dbh,p3=p3,p4=p4,-2)
-#define dbd_db_last_insert_id(dbh, imp_dbh, p3,p4,p5,p6, attr) \
- (dbh=dbh,imp_dbh=imp_dbh,p3=p3,p4=p4,p5=p5,p6=p6,&sv_undef)
-#define dbd_take_imp_data(h, imp_xxh, p3) (h=h,imp_xxh=imp_xxh,1)
-#define dbd_st_rows(h, imp_xxh) (h=h,imp_xxh=imp_xxh,1)
-#define dbd_st_execute_for_fetch(sth, imp_sth, p3, p4) \
- (sth=sth,imp_sth=imp_sth,p3=p3,p4=p4,&sv_undef)
struct imp_drh_st {
dbih_drc_t com; /* MUST be first element in structure */
@@ -30,15 +21,30 @@
dbih_stc_t com; /* MUST be first element in structure */
};
-static int
-foo_dummy(SV *h)
+
+
+#define dbd_discon_all(drh, imp_drh) (drh=drh,imp_drh=imp_drh,1)
+#define dbd_dr_data_sources(drh, imp_drh, attr)
(drh=drh,imp_drh=imp_drh,Nullav)
+#define dbd_db_do4(dbh,imp_dbh,p3,p4)
(dbh=dbh,imp_dbh=imp_dbh,p3=p3,p4=p4,-2)
+#define dbd_db_last_insert_id(dbh, imp_dbh, p3,p4,p5,p6, attr) \
+ (dbh=dbh,imp_dbh=imp_dbh,p3=p3,p4=p4,p5=p5,p6=p6,&sv_undef)
+#define dbd_take_imp_data(h, imp_xxh, p3) (h=h,imp_xxh=imp_xxh,1)
+#define dbd_st_execute_for_fetch(sth, imp_sth, p3, p4) \
+ (sth=sth,imp_sth=imp_sth,p3=p3,p4=p4,&sv_undef)
+
+#define dbd_st_bind_col(sth, imp_sth, param, ref, sql_type, attribs) \
+
(sth=sth,imp_sth=imp_sth,param=param,ref=ref,sql_type=sql_type,attribs=attribs,1)
+
+int /* just to test syntax of macros etc */
+dbd_st_rows(SV *h, imp_sth_t *imp_sth)
{
- D_imp_xxh(h);
- DBIh_SET_ERR_CHAR(h, imp_xxh, 0, 1, "err msg", "12345", Nullch);
- return 1;
+ DBIh_SET_ERR_CHAR(h, imp_sth, 0, 1, "err msg", "12345", Nullch);
+ return -1;
}
+
MODULE = DBD::Perl PACKAGE = DBD::Perl
INCLUDE: Perl.xsi
+# vim:sw=4:ts=8
Modified: dbi/trunk/lib/DBI/PurePerl.pm
==============================================================================
--- dbi/trunk/lib/DBI/PurePerl.pm (original)
+++ dbi/trunk/lib/DBI/PurePerl.pm Mon Feb 16 03:16:34 2004
@@ -779,17 +779,6 @@
$h->{'_bound_cols'}->[$col] = $value_ref;
return 1;
}
-sub bind_columns {
- my $h = shift;
- shift if !defined $_[0] or ref $_[0] eq 'HASH'; # old style args
- my $fbav = $h->_get_fbav;
- DBI::croak("bind_columns called with wrong number of args")
- if @_ != @$fbav;
- foreach ([EMAIL PROTECTED]) {
- $h->bind_col($_, $_[$_],'from_bind_columns')
- }
- return 1;
-}
sub finish {
my $h = shift;
$h->{'_fbav'} = undef;