Author: timbo
Date: Sun Feb 15 13:10:26 2004
New Revision: 60

Added:
   dbi/trunk/dbivport.h
Modified:
   dbi/trunk/Perl.xs
   dbi/trunk/dbd_xsh.h
   dbi/trunk/lib/DBI/DBD.pm
Log:
Added dbivport.h to provide backwards compat for drivers


Modified: dbi/trunk/Perl.xs
==============================================================================
--- dbi/trunk/Perl.xs   (original)
+++ dbi/trunk/Perl.xs   Sun Feb 15 13:10:26 2004
@@ -1,6 +1,15 @@
+/* This is a skeleton driver that only serves as a basic sanity check
+   that the Driver.xst mechansim doesn't have compile-time errors in it.
+*/
+
 #include "DBIXS.h"
 #include "dbd_xsh.h"
 
+#undef DBIh_SET_ERR_CHAR       /* to syntax check emulation */
+#include "dbivport.h"
+
+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)
@@ -21,6 +30,13 @@
     dbih_stc_t com;     /* MUST be first element in structure   */
 };
 
+static int
+foo_dummy(SV *h)
+{
+       D_imp_xxh(h);
+       DBIh_SET_ERR_CHAR(h, imp_xxh, 0, 1, "err msg", "12345", Nullch);
+       return 1;
+}
 
 DBISTATE_DECLARE;
 

Modified: dbi/trunk/dbd_xsh.h
==============================================================================
--- dbi/trunk/dbd_xsh.h (original)
+++ dbi/trunk/dbd_xsh.h Sun Feb 15 13:10:26 2004
@@ -8,6 +8,9 @@
  * dbdimp.h file in the driver source.
  */
 
+#ifndef DBI_DBD_XSH_H
+#define DBI_DBD_XSH_H
+
 void     dbd_init _((dbistate_t *dbistate));
 
 int      dbd_discon_all _((SV *drh, imp_drh_t *imp_drh));
@@ -29,6 +32,7 @@
 void     dbd_db_destroy    _((SV *dbh, imp_dbh_t *imp_dbh));
 int      dbd_db_STORE_attrib _((SV *dbh, imp_dbh_t *imp_dbh, SV *keysv, SV *valuesv));
 SV      *dbd_db_FETCH_attrib _((SV *dbh, imp_dbh_t *imp_dbh, SV *keysv));
+SV     *dbd_db_last_insert_id _((SV *dbh, SV *imp_dbh, SV *catalog, SV *schema, SV 
*table, SV *field, SV *attr));
 
 int      dbd_st_prepare _((SV *sth, imp_sth_t *imp_sth, char *statement, SV 
*attribs));
 int      dbd_st_rows    _((SV *sth, imp_sth_t *imp_sth));
@@ -46,4 +50,4 @@
                 SV *param, SV *value, IV sql_type, SV *attribs,
                                int is_inout, IV maxlen));
 
-/* end of dbd_xsh.h */
+#endif /* end of dbd_xsh.h */

Added: dbi/trunk/dbivport.h
==============================================================================
--- (empty file)
+++ dbi/trunk/dbivport.h        Sun Feb 15 13:10:26 2004
@@ -0,0 +1,25 @@
+/* dbivport.h
+
+       Provides macros that enable greater portability between DBI versions.
+
+       This file should be *copied* and included in driver distributions
+       and #included into the source, after #include DBIXS.h
+
+       New driver releases should include an updated copy of dbivport.h
+       from the most recent DBI release.
+*/
+
+#ifndef DBI_VPORT_H
+#define DBI_VPORT_H
+
+#ifndef DBIh_SET_ERR_CHAR
+/* Emulate DBIh_SET_ERR_CHAR
+       Only uses the err_i, errstr and state parameters.
+*/
+#define DBIh_SET_ERR_CHAR(h, imp_xxh, err_c, err_i, errstr, state, method) \
+        sv_setiv(DBIc_ERR(imp_xxh), err_i); \
+        sv_setpv(DBIc_STATE(imp_xxh), state); \
+        sv_setpv(DBIc_ERRSTR(imp_xxh), errstr)
+#endif
+
+#endif /* !DBI_VPORT_H */

Modified: dbi/trunk/lib/DBI/DBD.pm
==============================================================================
--- dbi/trunk/lib/DBI/DBD.pm    (original)
+++ dbi/trunk/lib/DBI/DBD.pm    Sun Feb 15 13:10:26 2004
@@ -1890,6 +1890,8 @@
 
   #include "dbdimp.h"
 
+  #include "dbivport.h"   /* see below                    */
+
   #include <dbd_xsh.h>    /* installed by the DBI module  */
 
   #endif /* DRIVER_H_INCLUDED */
@@ -1905,6 +1907,24 @@
 specified in the dbd_xsh.h header.
 You might also add extra driver-specific functions in Driver.xs.
 
+The dbivport.h file should be I<copied> from the latest DBI release into
+your distribution each time you enhance your driver to use new features
+for which the DBI is offering backwards compatibility via dbivport.h.
+
+Its job is to allow you to enhance your code to work with the latest
+DBI API while still allowing your driver to be compiled and used
+with older versions of the DBI. For example, when the DBIh_SET_ERR_CHAR
+macro was added to DBI 1.41 in an emulation of it was added to dbivport.h.
+
+Copying dbivport.h into your driver distribution and #including it
+in Driver.h, as shown above, lets you enhance your driver to use
+the new DBIh_SET_ERR_CHAR macro even with versions of the DBI earlier
+than 1.41. This makes users happy and your life easier.
+
+Always read the notes in dbivport.h to check for any limitations
+in the emulation that you should be aware of.
+
+
 =head2 Implementation header dbdimp.h
 
 This header file has two jobs:
@@ -2110,16 +2130,8 @@
 
 As you can see, any parameters that aren't relevant to you can be Null.
 
-To make drivers compatible with DBI < 1.41 you can use this:
-
-#ifndef DBIh_SET_ERR_CHAR
-#define DBIh_SET_ERR_CHAR(h, imp_xxh, err_c, err_i, errstr, state, method) \
-       sv_setiv(DBIc_ERR(imp_xxh), err_i); \
-       sv_setpv(DBIc_STATE(imp_xxh), state); \
-       sv_setpv(DBIc_ERRSTR(imp_xxh), errstr)
-#endif
-
-and pass Null for the err_c and method parameters.
+To make drivers compatible with DBI < 1.41 you should be using dbivport.h
+as described in L</Driver.h> above.
 
 The (obsolete) macros such as DBIh_EVENT2 should be removed from drivers.
 
@@ -3446,9 +3458,10 @@
 The approved method for handling these is now the four macros:
 
   DBIc_is(imp, flag)
-  DBIc_has(imp, flag)    an alias for DBIc_is
+  DBIc_has(imp, flag)       an alias for DBIc_is
   DBIc_on(imp, flag)
   DBIc_off(imp, flag)
+  DBIc_set(imp, flag, on)   set if on is true, else clear
 
 Consequently, the DBIc_XXXXX family of macros is now mostly deprecated
 and new drivers should avoid using them, even though the older drivers

Reply via email to