List:Commits« Previous MessageNext Message »
From:capttofu Date:March 1 2007 4:47pm
Subject:[svn:DBD-mysql] r9183 - in DBD-mysql/trunk: . lib/DBD t
View as plain text  
Author: capttofu
Date: Thu Mar  1 07:47:39 2007
New Revision: 9183

Modified:
   DBD-mysql/trunk/ChangeLog
   DBD-mysql/trunk/dbdimp.c
   DBD-mysql/trunk/dbdimp.h
   DBD-mysql/trunk/lib/DBD/mysql.pm
   DBD-mysql/trunk/mysql.xs
   DBD-mysql/trunk/t/20createdrop.t
   DBD-mysql/trunk/t/40listfields.t
   DBD-mysql/trunk/t/80procs.t
   DBD-mysql/trunk/t/insertid.t
   DBD-mysql/trunk/t/lib.pl

Log:
* Fixed version to be a string, which was previously a float, which caused problems 
  for certain locales
* Fixed bug #23974. $dbh->column_info now returns empty arrayref upon table not
existing.
  Much thanks to Tim Bunce for help fixing the probelem in mysql.pm vs. dbdimp.c
* Removed #ifdefs for do error (sqlstate being passed as last arg depending on version)
* Fixed insertid test to work with auto_increment_increment replication setup.
* Patch from Tim Bunce fixing do() not set $dbh->{Statement} attribute,
  which prevented DBD::Profile from giving correct results for calls to do() and
  causing ShowErrorStatement to possibly report the wrong statement in the error message
* Patch from Tim Bunce clearing out the sth attribute cache when switching between result,
  sets which prevented the adjustedment of NUM_OF_FIELDS
* Cleanup of several unused variables


Modified: DBD-mysql/trunk/ChangeLog
==============================================================================
--- DBD-mysql/trunk/ChangeLog	(original)
+++ DBD-mysql/trunk/ChangeLog	Thu Mar  1 07:47:39 2007
@@ -1,4 +1,16 @@
-<unreleased> Jim Winstead <jimw@stripped> (4.002)
+2007-02-24 Patrick Galbraith <patg@stripped> Jim Winstead <jimw@stripped>
(4.002)
+* Fixed version to be a string, which was previously a float, which caused problems 
+  for certain locales
+* Fixed bug #23974. $dbh->column_info now returns empty arrayref upon table not
existing.
+  Much thanks to Tim Bunce for help fixing the probelem in mysql.pm vs. dbdimp.c
+* Removed #ifdefs for do error (sqlstate being passed as last arg depending on version)
+* Fixed insertid test to work with auto_increment_increment replication setup.
+* Patch from Tim Bunce fixing do() not set $dbh->{Statement} attribute,
+  which prevented DBD::Profile from giving correct results for calls to do() and 
+  causing ShowErrorStatement to possibly report the wrong statement in the error message 
+* Patch from Tim Bunce clearing out the sth attribute cache when switching between
result,
+  sets which prevented the adjustedment of NUM_OF_FIELDS
+* Cleanup of several unused variables
 * Added support for wildcards in last argument of column_info().
 * Add mysql_is_auto_increment to results of column_info(). (Bug #26603,
   original patch from Dave Rolsky)
@@ -7,6 +19,7 @@
 * Add implementation of foreign_key_info() (Bug #26604, original patch from
   Dave Rolsky, and final implementation based on Connector/J code)
 
+
 2007-1-8 Jim Winstead <jimw@stripped> Patrick Galbraith <patg@stripped>
(4.001)
 * Fix handling of unsigned integer values in result sets when using
   server-side prepared statements (they were not retrieved at all).
@@ -70,6 +83,10 @@
 * Added multiple fixes to dbd_st_prepare which fixed variable overwrite
   and unset increment counter. Also improved loop which checks statements
   for presence of "LIMIT" by using a pointer as opposed to char array
+* Added patch for SSL Verify Certificate (Thanks Eric Chen!)
+* Added multiple fixes to dbd_st_prepare which fixed variable overwrite
+  and unset increment counter. Also improved loop which checks statements
+  for presence of "LIMIT" by using a pointer as opposed to char array
   increment variable. These errors were showing up in OpenBSD and other
   Unixen (which I think all BSD-based) (Thanks to Kyle George!)
 * Added fix to Makefile.PL to obtain correct build flags on VMS 
@@ -1262,10 +1279,6 @@
 24/11/95:13:01	Added 'NumRows' method to statement handles to return the
 		number of rows returned ( or affected ) by a statement.o
 
-		pre-release distributed to ANDK
-
-25/11/95:09:20	Real release released! No major problems reported.
-
 30/12/95:18:10	Altered mSQL.pm to allow for hostname:port style connections
 		to known remote port machines. Sets ENV var since the
 		msqlConnect API call doesn't support port arguments.

Modified: DBD-mysql/trunk/dbdimp.c
==============================================================================
--- DBD-mysql/trunk/dbdimp.c	(original)
+++ DBD-mysql/trunk/dbdimp.c	Thu Mar  1 07:47:39 2007
@@ -438,11 +438,10 @@
                           bool bind_type_guessing)
 {
 
-  int rc;
   char *salloc, *statement_ptr;
-  char *statement_ptr_end, testchar, *ptr, *valbuf;
+  char *statement_ptr_end, *ptr, *valbuf;
   char *cp, *end;
-  int alen, i, j;
+  int alen, i;
   int slen= *slen_ptr;
   int limit_flag= 0;
   STRLEN vallen;
@@ -576,7 +575,6 @@
         else
         {
           int is_num = FALSE;
-          int c;
 
           valbuf= SvPV(ph->value, vallen);
           if (valbuf)
@@ -1267,11 +1265,7 @@
  *
  **************************************************************************/
 
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
 void do_error(SV* h, int rc, const char* what, const char* sqlstate)
-#else
-void do_error(SV* h, int rc, const char* what)
-#endif
 {
   D_imp_xxh(h);
   STRLEN lna;
@@ -1826,12 +1820,7 @@
   if (!my_login(dbh, imp_dbh))
   {
     do_error(dbh, mysql_errno(&imp_dbh->mysql),
-            mysql_error(&imp_dbh->mysql)
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-            ,mysql_sqlstate(&imp_dbh->mysql));
-#else
-            );
-#endif
+            mysql_error(&imp_dbh->mysql) ,mysql_sqlstate(&imp_dbh->mysql));
     return FALSE;
   }
 
@@ -1877,10 +1866,7 @@
 #endif
     {
       do_error(dbh, mysql_errno(&imp_dbh->mysql),
mysql_error(&imp_dbh->mysql)
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-               ,mysql_sqlstate(&imp_dbh->mysql)
-#endif
-              );
+               ,mysql_sqlstate(&imp_dbh->mysql));
       return FALSE;
     }
   }
@@ -1908,22 +1894,13 @@
 #endif
       {
         do_error(dbh, mysql_errno(&imp_dbh->mysql),
-                 mysql_error(&imp_dbh->mysql)
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-                ,mysql_sqlstate(&imp_dbh->mysql));
-#else
-                );
-#endif
+                 mysql_error(&imp_dbh->mysql)
,mysql_sqlstate(&imp_dbh->mysql));
         return FALSE;
       }
   }
   else
     do_error(dbh, JW_ERR_NOT_IMPLEMENTED,
-             "Rollback ineffective because transactions are not available"
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-             ,NULL
-#endif
-            );
+             "Rollback ineffective because transactions are not available" ,NULL);
   return TRUE;
 }
 
@@ -2048,12 +2025,7 @@
 #else
         if (mysql_rollback(&imp_dbh->mysql))
 #endif
-            do_error(dbh, TX_ERR_ROLLBACK,"ROLLBACK failed"
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-                     ,NULL);
-#else
-                    );
-#endif
+            do_error(dbh, TX_ERR_ROLLBACK,"ROLLBACK failed" ,NULL);
     }
     dbd_db_disconnect(dbh, imp_dbh);
   }
@@ -2118,7 +2090,7 @@
         /* Setting autocommit will do a commit of any pending statement */
         if (mysql_real_query(&imp_dbh->mysql, "SET AUTOCOMMIT=1", 16))
         {
-          do_error(dbh, TX_ERR_AUTOCOMMIT, "Turning on AutoCommit failed");
+          do_error(dbh, TX_ERR_AUTOCOMMIT, "Turning on AutoCommit failed", NULL);
           return FALSE;
         }
       }
@@ -2126,7 +2098,7 @@
       {
         if (mysql_real_query(&imp_dbh->mysql, "SET AUTOCOMMIT=0", 16))
         {
-          do_error(dbh, TX_ERR_AUTOCOMMIT, "Turning off AutoCommit failed");
+          do_error(dbh, TX_ERR_AUTOCOMMIT, "Turning off AutoCommit failed", NULL);
           return FALSE;
         }
       }
@@ -2142,12 +2114,7 @@
       if (!SvTRUE(valuesv))
       {
         do_error(dbh, JW_ERR_NOT_IMPLEMENTED,
-                 "Transactions not supported by database"
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-                 ,NULL);
-#else
-                );
-#endif
+                 "Transactions not supported by database" ,NULL);
         croak("Transactions not supported by database");
       }
     }
@@ -2806,8 +2773,32 @@
                       mysql_affected_rows(svsock));
       }
 
-      /* Store the result in the current statement handle */
-      DBIc_NUM_FIELDS(imp_sth)= mysql_num_fields(imp_sth->result);
+      /* delete cached handle attributes */
+      /* XXX should be driven by a list to ease maintenance */
+      hv_delete((HV*)SvRV(sth), "NAME", 4, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "NULLABLE", 8, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "NUM_OF_FIELDS", 13, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "PRECISION", 9, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "SCALE", 5, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "TYPE", 4, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "mysql_insertid", 14, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "mysql_is_auto_increment", 23, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "mysql_is_blob", 13, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "mysql_is_key", 12, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "mysql_is_num", 12, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "mysql_is_pri_key", 16, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "mysql_length", 12, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "mysql_max_length", 16, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "mysql_table", 11, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "mysql_type", 10, G_DISCARD);
+      hv_delete((HV*)SvRV(sth), "mysql_type_name", 15, G_DISCARD);
+
+      /* Adjust NUM_OF_FIELDS - which also adjusts the row buffer size */
+      DBIc_NUM_FIELDS(imp_sth)= 0; /* for DBI <= 1.53 */
+      DBIS->set_attr_k(sth, sv_2mortal(newSVpvn("NUM_OF_FIELDS",13)), 0,
+          sv_2mortal(newSViv(mysql_num_fields(imp_sth->result)))
+      );
+
       DBIc_ACTIVE_on(imp_sth);
 
       if (dbis->debug >= 5)
@@ -2857,6 +2848,7 @@
   char *table;
   char *salloc;
   int htype;
+  int errno;
   my_ulonglong rows= 0;
 
   /* thank you DBI.c for this info! */
@@ -2922,22 +2914,12 @@
 
     if (!slen)
     {
-      do_error(h, JW_ERR_QUERY, "Missing table name"
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-               ,NULL);
-#else
-              );
-#endif
+      do_error(h, JW_ERR_QUERY, "Missing table name" ,NULL);
       return -2;
     }
     if (!(table= malloc(slen+1)))
     {
-      do_error(h, JW_ERR_MEM, "Out of memory"
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-               ,NULL);
-#else
-              );
-#endif
+      do_error(h, JW_ERR_MEM, "Out of memory" ,NULL);
       return -2;
     }
 
@@ -2952,16 +2934,13 @@
     *sbuf++= '\0';
 
     *result= mysql_list_fields(svsock, table, NULL);
+
     free(table);
 
     if (!(*result))
     {
       do_error(h, mysql_errno(svsock), mysql_error(svsock)
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
                ,mysql_sqlstate(svsock));
-#else
-              );
-#endif
       return -2;
     }
 
@@ -2973,12 +2952,10 @@
        (mysql_real_query(svsock, sbuf, slen))))
   {
     Safefree(salloc);
-    do_error(h, mysql_errno(svsock), mysql_error(svsock)
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-             ,mysql_sqlstate(svsock));
-#else
-            );
-#endif
+    do_error(h, mysql_errno(svsock), mysql_error(svsock), 
+             mysql_sqlstate(svsock));
+    if (dbis->debug >= 2)
+      PerlIO_printf(DBILOGFP, "IGNORING ERROR errno %d\n", errno);
     return -2;
   }
   Safefree(salloc);
@@ -2989,11 +2966,7 @@
 
   if (mysql_errno(svsock))
     do_error(h, mysql_errno(svsock), mysql_error(svsock)
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
              ,mysql_sqlstate(svsock));
-#else
-            );
-#endif
 
   if (!*result)
     rows= mysql_affected_rows(svsock);
@@ -4106,7 +4079,6 @@
         if (DBIc_NUM_PARAMS(imp_sth))
         {
             unsigned int n;
-            SV *sv;
             char key[100];
             I32 keylen;
             for (n= 0; n < DBIc_NUM_PARAMS(imp_sth); n++)

Modified: DBD-mysql/trunk/dbdimp.h
==============================================================================
--- DBD-mysql/trunk/dbdimp.h	(original)
+++ DBD-mysql/trunk/dbdimp.h	Thu Mar  1 07:47:39 2007
@@ -36,6 +36,12 @@
 #define NEW_DATATYPE_VERSION 50003
 #define SSL_VERIFY_VERSION 50023
 #define MYSQL_VERSION_5_0 50001
+/* This is to avoid the ugly #ifdef mess in dbdimp.c */
+#if MYSQL_VERSION_ID < SQL_STATE_VERSION
+#define mysql_sqlstate(svsock) (NULL)
+#endif
+
+
 
 /*
  *  The following are return codes passed in $h->err in case of

Modified: DBD-mysql/trunk/lib/DBD/mysql.pm
==============================================================================
--- DBD-mysql/trunk/lib/DBD/mysql.pm	(original)
+++ DBD-mysql/trunk/lib/DBD/mysql.pm	Thu Mar  1 07:47:39 2007
@@ -9,7 +9,7 @@
 use Carp ();
 @ISA = qw(DynaLoader);
 
-$VERSION = 4.002;
+$VERSION = '4.002';
 
 bootstrap DBD::mysql $VERSION;
 
@@ -303,6 +303,8 @@
     # ODBC allows a NULL to mean all columns, so we'll accept undef
     $column = '%' unless defined $column;
 
+    my $ER_NO_SUCH_TABLE= 1146;
+
     my $table_id = $dbh->quote_identifier($catalog, $schema, $table);
 
     my @names = qw(
@@ -321,10 +323,22 @@
     my %col_info;
 
     local $dbh->{FetchHashKeyName} = 'NAME_lc';
+    # only ignore ER_NO_SUCH_TABLE in internal_execute if issued from here
     my $desc_sth = $dbh->prepare("DESCRIBE $table_id " . $dbh->quote($column));
     my $desc = $dbh->selectall_arrayref($desc_sth, { Columns=>{} });
 
-    return $desc_sth if $desc_sth->err();
+    #return $desc_sth if $desc_sth->err();
+    if (my $err = $desc_sth->err())
+    {
+        # return the error, unless it is due to the table not 
+        # existing per DBI spec
+        if ($err != $ER_NO_SUCH_TABLE)
+        {
+          return undef;
+        }
+        $dbh->set_err(undef,undef);
+        $desc = [];
+    }
 
     my $ordinal_pos = 0;
     foreach my $row (@$desc) {

Modified: DBD-mysql/trunk/mysql.xs
==============================================================================
--- DBD-mysql/trunk/mysql.xs	(original)
+++ DBD-mysql/trunk/mysql.xs	Thu Mar  1 07:47:39 2007
@@ -54,12 +54,7 @@
       MYSQL_RES* res = mysql_list_dbs(sock, NULL);
       if (!res)
       {
-        do_error(drh, mysql_errno(sock), mysql_error(sock)
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-                 , mysql_sqlstate(sock));
-#else
-                );
-#endif
+        do_error(drh, mysql_errno(sock), mysql_error(sock), mysql_sqlstate(sock));
       }
       else
       {
@@ -103,12 +98,8 @@
     sock = mysql_dr_connect(drh, &mysql, NULL, host, port, user,  password, NULL,
NULL);
     if (sock == NULL)
     {
-      do_error(drh, mysql_errno(&mysql), mysql_error(&mysql)
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-               , mysql_sqlstate(&mysql));
-#else
-              );
-#endif
+      do_error(drh, mysql_errno(&mysql), mysql_error(&mysql),
+               mysql_sqlstate(&mysql));
       XSRETURN_NO;
     }
   }
@@ -129,12 +120,7 @@
     char* buffer = malloc(strlen(dbname)+50);
     if (buffer == NULL)
     {
-      do_error(drh, JW_ERR_MEM, "Out of memory"
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-               ,NULL);
-#else
-              );
-#endif
+      do_error(drh, JW_ERR_MEM, "Out of memory" ,NULL);
       XSRETURN_NO;
     }
     else
@@ -154,12 +140,7 @@
     char* buffer = malloc(strlen(dbname)+50);
     if (buffer == NULL)
     {
-      do_error(drh, JW_ERR_MEM, "Out of memory"
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-               ,NULL);
-#else
-              );
-#endif
+      do_error(drh, JW_ERR_MEM, "Out of memory" ,NULL);
       XSRETURN_NO;
     }
     else
@@ -178,12 +159,7 @@
   if (retval)
   {
     do_error(SvOK(dbh) ? dbh : drh, mysql_errno(sock),
-             mysql_error(sock)
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-             ,mysql_sqlstate(sock));
-#else
-            );
-#endif
+             mysql_error(sock) ,mysql_sqlstate(sock));
   }
 
   if (SvOK(dbh))
@@ -232,12 +208,7 @@
        !(res = mysql_list_dbs(&imp_dbh->mysql, NULL))))
 {
   do_error(dbh, mysql_errno(&imp_dbh->mysql),
-           mysql_error(&imp_dbh->mysql)
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-           ,mysql_sqlstate(&imp_dbh->mysql));
-#else
-          );
-#endif
+           mysql_error(&imp_dbh->mysql), mysql_sqlstate(&imp_dbh->mysql));
 }
 else
 {
@@ -300,6 +271,8 @@
                   "mysql.xs do() use_server_side_prepare %d\n",
                   use_server_side_prepare);
 
+  hv_store((HV*)SvRV(dbh), "Statement", 9, SvREFCNT_inc(statement), 0);
+
   if (use_server_side_prepare)
   {
     str_ptr= SvPV(statement, slen);
@@ -317,11 +290,7 @@
       else
       {
         do_error(dbh, mysql_stmt_errno(stmt), mysql_stmt_error(stmt)
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
                  ,mysql_stmt_sqlstate(stmt));
-#else
-                );
-#endif
         retval=-2;
       }
       mysql_stmt_close(stmt);
@@ -613,23 +582,13 @@
       else
       {
         RETVAL = 0;
-        do_error(sth, JW_ERR_NOT_ACTIVE, "Statement not active"
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-                 ,NULL);
-#else
-                );
-#endif
+        do_error(sth, JW_ERR_NOT_ACTIVE, "Statement not active" ,NULL);
       }
     }
     else
     {
       RETVAL = 0;
-      do_error(sth, JW_ERR_NOT_ACTIVE, "No result set"
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-               ,NULL);
-#else
-              );
-#endif
+      do_error(sth, JW_ERR_NOT_ACTIVE, "No result set" ,NULL);
     }
   }
   else
@@ -640,12 +599,7 @@
     RETVAL = 1;
   } else {
     RETVAL = 0;
-    do_error(sth, JW_ERR_NOT_ACTIVE, "Statement not active"
-#if MYSQL_VERSION_ID >= SQL_STATE_VERSION
-             ,NULL);
-#else
-            );
-#endif
+    do_error(sth, JW_ERR_NOT_ACTIVE, "Statement not active" ,NULL);
   }
 #if (MYSQL_VERSION_ID >=SERVER_PREPARE_VERSION) 
   }

Modified: DBD-mysql/trunk/t/20createdrop.t
==============================================================================
--- DBD-mysql/trunk/t/20createdrop.t	(original)
+++ DBD-mysql/trunk/t/20createdrop.t	Thu Mar  1 07:47:39 2007
@@ -73,6 +73,12 @@
 	   or DbiError($dbh->err, $dbh->errstr);
 
     #
+    #   ... check do() sets $dbh->{Statement}
+    #
+    Test($state or $dbh->{Statement} eq "DROP TABLE $table")
+	   or DbiError(1, "do() didn't set Statement attribute");
+
+    #
     #   Finally disconnect.
     #
     Test($state or $dbh->disconnect())

Modified: DBD-mysql/trunk/t/40listfields.t
==============================================================================
--- DBD-mysql/trunk/t/40listfields.t	(original)
+++ DBD-mysql/trunk/t/40listfields.t	Thu Mar  1 07:47:39 2007
@@ -75,14 +75,13 @@
     Test($state or $dbh->column_info(undef,undef,$table,'%'));
 
     #
-    # Bug #23974: column_info does not return error when table does not exist
+    # Bug #23974: "column_info does not return error when table does not exist"
+    # DBI spec specifies that empty ref should be returned, not error 
     #
-    {
-     local $dbh->{PrintError}= 0;
-      Test($state or
-           ($sth= $dbh->column_info(undef,undef,"this_does_not_exist",'%')));
-      Test($sth and $sth->err());
-    }
+    Test($state or
+        ($sth= $dbh->column_info(undef,undef,"this_does_not_exist",'%')));
+
+    Test($sth and ! $sth->err());
 
     Test($state or $sth = $dbh->prepare("SELECT * FROM $table"))
 	   or DbiError($dbh->err, $dbh->errstr);

Modified: DBD-mysql/trunk/t/80procs.t
==============================================================================
--- DBD-mysql/trunk/t/80procs.t	(original)
+++ DBD-mysql/trunk/t/80procs.t	Thu Mar  1 07:47:39 2007
@@ -113,6 +113,8 @@
     Test($state or $sth->execute()) or 
       DbiError($dbh->err, $dbh->errstr);
 
+    $sth->finish;
+
     my $proc_select = 'SELECT @a';
     Test($state or $sth = $dbh->prepare($proc_select)) or
     DbiError($dbh->err, $dbh->errstr);
@@ -120,6 +122,8 @@
     Test($state or $sth->execute()) or 
       DbiError($dbh->err, $dbh->errstr);
 
+    $sth->finish;
+
   Test($state or ($sth=$dbh->prepare("DROP PROCEDURE testproc"))) or
     DbiError($dbh->err, $dbh->errstr);
 
@@ -148,6 +152,9 @@
 
   my $dataset;
 
+  Test($state or ($sth->{NUM_OF_FIELDS} == 1)) or
+    DbiError($dbh->err, $dbh->errstr);
+
   Test($state or $dataset = $sth->fetchrow_arrayref()) or 
     DbiError($dbh->err, $dbh->errstr);
   
@@ -159,6 +166,9 @@
   Test($state or $more_results =  $sth->more_results()) or
     DbiError($dbh->err, $dbh->errstr);
 
+  Test($state or ($sth->{NUM_OF_FIELDS} == 2)) or
+    DbiError($dbh->err, $dbh->errstr);
+
   Test($state or $dataset = $sth->fetchrow_arrayref()) or
     DbiError($dbh->err, $dbh->errstr);
 
@@ -168,6 +178,9 @@
   Test($state or $more_results =  $sth->more_results()) or
     DbiError($dbh->err, $dbh->errstr);
 
+  Test($state or ($sth->{NUM_OF_FIELDS} == 3)) or
+    DbiError($dbh->err, $dbh->errstr);
+
   Test($state or $dataset = $sth->fetchrow_arrayref()) or
     DbiError($dbh->err, $dbh->errstr);
 
@@ -177,7 +190,7 @@
   Test($state or !($more_results =  $sth->more_results())) or
     DbiError($dbh->err, $dbh->errstr);
 
-  $SIG{__WARN__} = sub { die @_ };
+  local $SIG{__WARN__} = sub { die @_ };
 
   Test($state or $dbh->disconnect()) or 
     DbiError($dbh->err, $dbh->errstr);

Modified: DBD-mysql/trunk/t/insertid.t
==============================================================================
--- DBD-mysql/trunk/t/insertid.t	(original)
+++ DBD-mysql/trunk/t/insertid.t	Thu Mar  1 07:47:39 2007
@@ -7,7 +7,8 @@
 require "t/lib.pl";
 
 while (Testing()) {
-  my $dbh;
+  my ($dbh, $sth, $sth2);
+  my $max_id;
   #
   # Connect to the database
   Test($state or
@@ -43,12 +44,18 @@
   #
   # Insert another row
   #
-  my $sth;
   Test($state or ($sth = $dbh->prepare($q)));
   Test($state or $sth->execute());
-  Test($state or $sth->{'mysql_insertid'} eq 2);
-  Test($state or $dbh->{'mysql_insertid'} eq 2);
+  Test($state or ($sth2= $dbh->prepare("SELECT max(id) FROM $table"))); 
+  Test($state or $sth2->execute());
+  Test($state or ($max_id= $sth2->fetch()));
+  # IMPORTANT: this will fail if you are using replication with
+  # an offset and auto_increment_increment, where your 
+  # auto_increment values are stepped (ex: 1, 11, 21, ...)
+  Test($state or $sth->{'mysql_insertid'} == $max_id->[0]);
+  Test($state or $dbh->{'mysql_insertid'} == $max_id->[0]);
   Test($state or $sth->finish());
+  Test($state or $sth2->finish());
 
   #
   # Drop the table

Modified: DBD-mysql/trunk/t/lib.pl
==============================================================================
--- DBD-mysql/trunk/t/lib.pl	(original)
+++ DBD-mysql/trunk/t/lib.pl	Thu Mar  1 07:47:39 2007
@@ -11,6 +11,7 @@
 use strict;
 use vars qw($mdriver $dbdriver $childPid $test_dsn $test_user $test_password);
 
+$| = 1; # flush stdout asap to keep in sync with stderr
 
 #
 #   Driver names; EDIT THIS!
@@ -166,7 +167,8 @@
 		print "ok $::numTests\n";
 		return 1;
 	    } else {
-		printf("not ok $::numTests%s\n",
+		my ($pack, $file, $line) = caller();
+		printf("not ok $::numTests%s at line $line\n",
 			(defined($error) ? " $error" : ""));
 		return 0;
 	    }
Thread
[svn:DBD-mysql] r9183 - in DBD-mysql/trunk: . lib/DBD tcapttofu1 Mar