List:Commits« Previous MessageNext Message »
From:capttofu Date:January 6 2007 5:57pm
Subject:[svn:DBD-mysql] r8517 - in DBD-mysql/trunk: . eg
View as plain text  
Author: capttofu
Date: Sat Jan  6 09:57:55 2007
New Revision: 8517

Modified:
   DBD-mysql/trunk/ChangeLog
   DBD-mysql/trunk/README
   DBD-mysql/trunk/dbdimp.c
   DBD-mysql/trunk/eg/proc_example1.pl
   DBD-mysql/trunk/eg/proc_example2.pl
   DBD-mysql/trunk/eg/proc_example3.pl
   DBD-mysql/trunk/mysql.xs

Log:
* Fixed call in st_fetch to dbd_st_finish that blew away subsequent result sets 
* Cleaned up ISO C warning in mysql.xs
* Cleaned up and made strict stored proc examples
* Added entries to Changelog



Modified: DBD-mysql/trunk/ChangeLog
==============================================================================
--- DBD-mysql/trunk/ChangeLog	(original)
+++ DBD-mysql/trunk/ChangeLog	Sat Jan  6 09:57:55 2007
@@ -1,4 +1,4 @@
-<unreleased> Jim Winstead <jimw@stripped> (4.001)
+<unreleased> 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).
 * Fix handling of signed integer values when using server-side prepared
@@ -29,6 +29,10 @@
 * Fixed Bundle::DBD::mysql to only include modules required for using
   DBD::mysql, not the old Mysql package. [rt.cpan.org #24096]
 * Updated Makefile.PL to not include files in .svn directories
+* Fixed various compile warnings in mysql.xs
+* Cleaned up stored procedure examples, made strict
+* Fixed bug that blew away subsequent result sets if you fetched all rows, only in
+  result sets that had more than one row
 
 2006-12-22 Patrick Galbraith <patg@stripped>, Alexey Stroganov (4.00)
 * Added Alexey Stroganov's patch which fixes varying number of columns in 

Modified: DBD-mysql/trunk/README
==============================================================================
--- DBD-mysql/trunk/README	(original)
+++ DBD-mysql/trunk/README	Sat Jan  6 09:57:55 2007
@@ -97,4 +97,5 @@
 
   perl@stripped
 
-You can also get help from MySQL, Patrick Galbraith patg@stripped
+You can also get help from the maintainer, Patrick Galbraith patg@stripped,
+

Modified: DBD-mysql/trunk/dbdimp.c
==============================================================================
--- DBD-mysql/trunk/dbdimp.c	(original)
+++ DBD-mysql/trunk/dbdimp.c	Sat Jan  6 09:57:55 2007
@@ -519,11 +519,12 @@
 
   while (statement_ptr < statement_ptr_end)
   {
-    if (dbis->debug >= 2)
+    /*if (dbis->debug >= 2)
       PerlIO_printf(DBILOGFP,
                     "     parse_params statement_ptr %08lx = %s \
                     statement_ptr_end %08lx\n",
                     statement_ptr, statement_ptr, statement_ptr_end);
+                  */
     /* LIMIT should be the last part of the query, in most cases */
     if (! limit_flag)
     {
@@ -1364,6 +1365,7 @@
 			char* port, char* user, char* password,
 			char* dbname, imp_dbh_t *imp_dbh) {
   int portNr;
+  unsigned int client_flag;
   MYSQL* result;
 
   /* per Monty, already in client.c in API */
@@ -1494,9 +1496,9 @@
 #endif
 
 #ifdef MYSQL_NO_CLIENT_FOUND_ROWS
-    unsigned int client_flag = 0;
+    client_flag = 0;
 #else
-    unsigned int client_flag = CLIENT_FOUND_ROWS;
+    client_flag = CLIENT_FOUND_ROWS;
 #endif
     mysql_init(sock);
 
@@ -2752,11 +2754,11 @@
     DBIc_ACTIVE_off(imp_sth);
 
   next_result_return_code= mysql_next_result(svsock);
-  
+
   if (dbis->debug >= 2)
     PerlIO_printf(DBILOGFP,
                            "\n      <-!!!!!!!!!! dbs_st_more_rows %d\n",
next_result_return_code);
-                              
+
   /*
     mysql_next_result returns
       0 if there are more results
@@ -2765,7 +2767,7 @@
    */
   if (next_result_return_code > 0)
   {
-    do_error(sth, mysql_errno(svsock), mysql_error(svsock), 
+    do_error(sth, mysql_errno(svsock), mysql_error(svsock),
              mysql_sqlstate(svsock));
     return 0;
   }
@@ -3397,12 +3399,13 @@
   AV *av;
   int av_length, av_readonly;
   MYSQL_ROW cols;
+  D_imp_dbh_from_sth;
+  MYSQL* svsock= &imp_dbh->mysql;
   imp_sth_fbh_t *fbh;
 #if MYSQL_VERSION_ID >=SERVER_PREPARE_VERSION
   MYSQL_BIND *buffer;
 #endif
   MYSQL_FIELD *fields;
-  D_imp_dbh_from_sth;
   if (dbis->debug >= 2)
     PerlIO_printf(DBILOGFP, "\t-> dbd_st_fetch\n");
 
@@ -3598,6 +3601,10 @@
 
     if (!(cols= mysql_fetch_row(imp_sth->result)))
     {
+      if (dbis->debug > 2)
+      {
+        PerlIO_printf(DBILOGFP, "\tdbd_st_fetch, no more rows to fetch");
+      }
       if (mysql_errno(&imp_dbh->mysql))
         do_error(sth, mysql_errno(&imp_dbh->mysql),
                  mysql_error(&imp_dbh->mysql)
@@ -3608,7 +3615,8 @@
 #endif
 
 
-      dbd_st_finish(sth, imp_sth);
+      if (!mysql_more_results(svsock))
+        dbd_st_finish(sth, imp_sth);
       return Nullav;
     }
 
@@ -3728,6 +3736,12 @@
   int i;
   int num_fields;
   imp_sth_fbh_t *fbh;
+
+  if (dbis->debug >= 2)
+  {
+    PerlIO_printf(DBILOGFP, "\n--> dbd_st_finish\n");
+  }
+
   if (imp_sth->use_server_side_prepare)
   {
     if (imp_sth && imp_sth->stmt)
@@ -3782,6 +3796,10 @@
     mysql_st_free_result_sets(sth, imp_sth);
   }
   DBIc_ACTIVE_off(imp_sth);
+  if (dbis->debug >= 2)
+  {
+    PerlIO_printf(DBILOGFP, "\n<-- dbd_st_finish\n");
+  }
   return 1;
 }
 

Modified: DBD-mysql/trunk/eg/proc_example1.pl
==============================================================================
--- DBD-mysql/trunk/eg/proc_example1.pl	(original)
+++ DBD-mysql/trunk/eg/proc_example1.pl	Sat Jan  6 09:57:55 2007
@@ -1,47 +1,49 @@
 #!/usr/bin/perl
 
+use strict;
 use DBI;
 
-$DATABASE='test';
-$HOST='localhost';
-$PORT=3306; $USER='root';
-$PASSWORD='';
-
-$dbh = DBI->connect("DBI:mysql:$DATABASE:$HOST:$PORT",
-		    "$USER", "$PASSWORD",
-		  { PrintError => 0}) || die $DBI::errstr;
-
- $dbh->do("drop procedure if exists testproc") or print $DBI::errstr;
-
- $dbh->do("create procedure testproc() deterministic
-  begin
-  declare a,b,c,d int;
-  set a=1;
-  set b=2;
-  set c=3;
-  set d=4;
-  select a, b, c, d;
-  select d, c, b, a;
-  select b, a, c, d;
-  select c, b, d, a;
-  end") or print $DBI::errstr;
-
- $sth=$dbh->prepare('call testproc()') || 
- die $DBI::err.": ".$DBI::errstr;
-
- $sth->execute || die DBI::err.": ".$DBI::errstr; $rowset=0;
- do {
-   print "\nRowset ".++$i."\n---------------------------------------\n\n";
-   foreach $colno (0..$sth->{NUM_OF_FIELDS}) {
-     print $sth->{NAME}->[$colno]."\t";
-   }
-   print "\n";
-   while (@row= $sth->fetchrow_array())  {
-     foreach $field (0..$#row) {
-       print $row[$field]."\t";
-     }
-     print "\n";
-   }
- } until (!$sth->more_results)
+my $db='test';
+my $host='localhost';
+my $user='root';
+my $password='';
+my $i= 0;
+
+my $dbh = DBI->connect("DBI:mysql:$db:$host",
+    "$user", "$password",
+    { PrintError => 0}) || die $DBI::errstr;
+
+$dbh->do("drop procedure if exists testproc") or print $DBI::errstr;
+
+$dbh->do("create procedure testproc() deterministic
+    begin
+    declare a,b,c,d int;
+    set a=1;
+    set b=2;
+    set c=3;
+    set d=4;
+    select a, b, c, d;
+    select d, c, b, a;
+    select b, a, c, d;
+    select c, b, d, a;
+    end") or print $DBI::errstr;
+
+my $sth= $dbh->prepare('call testproc()') || 
+die $DBI::err.": ".$DBI::errstr;
+
+$sth->execute || die DBI::err.": ".$DBI::errstr;
+do {
+  print "\nResult set ".++$i."\n---------------------------------------\n\n";
+  for my $colno (0..$sth->{NUM_OF_FIELDS}) {
+    print $sth->{NAME}->[$colno]."\t";
+  }
+  print "\n";
+  while (my @row= $sth->fetchrow_array())  {
+    for my $field (0..$#row) {
+      print $row[$field]."\t";
+    }
+    print "\n";
+  }
+} until (!$sth->more_results)
 
 

Modified: DBD-mysql/trunk/eg/proc_example2.pl
==============================================================================
--- DBD-mysql/trunk/eg/proc_example2.pl	(original)
+++ DBD-mysql/trunk/eg/proc_example2.pl	Sat Jan  6 09:57:55 2007
@@ -1,15 +1,17 @@
 #!/usr/bin/perl
 
+use strict;
 use DBI;
+use Data::Dumper;
 
-$DATABASE='test';
-$HOST='localhost';
-$PORT=3306; $USER='root';
-$PASSWORD='';
-
-#DBI->trace(3);
-$dbh = DBI->connect("DBI:mysql:$DATABASE:$HOST:$PORT",
-		    "$USER", "$PASSWORD",
+my $db='test';
+my $host='localhost';
+my $user='root';
+my $password='';
+my $i= 0;
+
+my $dbh = DBI->connect("DBI:mysql:$db:$host",
+		    "$user", "$password",
 		  { PrintError => 0}) || die $DBI::errstr;
 
 # DROP TABLE IF EXISTS 
@@ -19,7 +21,8 @@
 
 my $sth= $dbh->prepare("INSERT INTO users VALUES (?, ?)");
 
-for $i(1 .. 20) {
+for $i(1 .. 20)
+{
   my @chars = grep !/[0O1Iil]/, 0..9, 'A'..'Z', 'a'..'z';
   my $random_chars = join '', map { $chars[rand @chars] } 0 .. 31;
 
@@ -31,24 +34,25 @@
 $dbh->do("CREATE PROCEDURE users_proc() DETERMINISTIC 
 BEGIN 
   SELECT id, name FROM users;
+  SELECT name, id FROM users;
 END") or print $DBI::errstr;
 
 $sth = $dbh->prepare('call users_proc()') || 
  die $DBI::err.": ".$DBI::errstr;
 
- $sth->execute || die DBI::err.": ".$DBI::errstr; $rowset=0;
+ $sth->execute || die DBI::err.": ".$DBI::errstr;
  do {
-   print "\nRowset ".++$i."\n---------------------------------------\n\n";
-   foreach $colno (0..$sth->{NUM_OF_FIELDS}) {
-     print $sth->{NAME}->[$colno]."\t";
-   }
-   print "\n";
-   while (@row=$sth->fetchrow_array())  {
-     foreach $field (0..$#row) {
-       print $row[$field]."\t";
-     }
-     print "\n";
-   }
- } until (!$sth->more_results)
+  print "\nResult set ".++$i."\n---------------------------------------\n\n";
+  for my $colno (0..$sth->{NUM_OF_FIELDS}) {
+    print $sth->{NAME}->[$colno]."\t";
+  }
+  print "\n";
+  while (my $rowref=$sth->fetchrow_arrayref())  {
+    for my $field (0..$#$rowref) {
+      print $rowref->[$field]."\t";
+    }
+    print "\n";
+  }
+ } while ($sth->more_results())
 
 

Modified: DBD-mysql/trunk/eg/proc_example3.pl
==============================================================================
--- DBD-mysql/trunk/eg/proc_example3.pl	(original)
+++ DBD-mysql/trunk/eg/proc_example3.pl	Sat Jan  6 09:57:55 2007
@@ -1,53 +1,45 @@
 #!/usr/bin/perl
 
+use strict;
 use DBI;
+use Data::Dumper;
 
-$DATABASE='test';
-$HOST='localhost';
-$PORT=3306; $USER='root';
-$PASSWORD='';
+my $db='test';
+my $host='localhost';
+my $user='root';
+my $password='';
 
-$dbh = DBI->connect("DBI:mysql:$DATABASE:$HOST:$PORT",
-		    "$USER", "$PASSWORD",
+my $dbh = DBI->connect("DBI:mysql:$db:$host",
+		    "$user", "$password",
 		  { PrintError => 0}) || die $DBI::errstr;
-$dbh->trace(3, "./dbd.log");
 
- $dbh->do("drop procedure if exists testproc") or print $DBI::errstr;
+$dbh->do("drop procedure if exists testproc") or print $DBI::errstr;
 
- $dbh->do("create procedure testproc() deterministic
-  begin
-  declare a,b,c,d,e,f int;
-  set a=1;
-  set b=2;
-  set c=3;
-  set d=4;
-  set e=5;
-  set f=6;
-  select a, b, c, d;
-  select d, c, b, a;
-  select b, a, c, d;
-  select c, b, d, a;
-  select a, d;
-  select a, b, c, d, e, f; 
-  select f;
-  end") or print $DBI::errstr;
-
- $sth=$dbh->prepare('call testproc()') || 
- die $DBI::err.": ".$DBI::errstr;
-
- $sth->execute || die DBI::err.": ".$DBI::errstr; $rowset=0;
- do {
-   print "\nRowset ".++$i."\n---------------------------------------\n\n";
-   foreach $colno (0..$sth->{NUM_OF_FIELDS}) {
-     print $sth->{NAME}->[$colno]."\t";
-   }
-   print "\n";
-   while (@row= $sth->fetchrow_array())  {
-     foreach $field (0..$#row) {
-       print $row[$field]."\t";
-     }
-     print "\n";
-   }
- } until (!$sth->more_results)
+$dbh->do("create procedure testproc() deterministic
+    begin
+    declare a,b,c,d,e,f int;
+    set a=1;
+    set b=2;
+    set c=3;
+    set d=4;
+    set e=5;
+    set f=6;
+    select a, b, c, d;
+    select d, c, b, a;
+    select b, a, c, d;
+    select c, b, d, a;
+    select a, d;
+    select f;
+    select a, b, c, d, e, f; 
+    end") or print $DBI::errstr;
+
+my $sth= $dbh->prepare('call testproc()') || 
+die $DBI::err.": ".$DBI::errstr;
+
+$sth->execute || die DBI::err.": ".$DBI::errstr;
+do {
+  my $row= $sth->fetchrow_arrayref();
+  print Dumper $row;
+} while ($sth->more_results())
 
 

Modified: DBD-mysql/trunk/mysql.xs
==============================================================================
--- DBD-mysql/trunk/mysql.xs	(original)
+++ DBD-mysql/trunk/mysql.xs	Sat Jan  6 09:57:55 2007
@@ -737,13 +737,14 @@
 	    break;
 	case SQL_MAXIMUM_TABLES_IN_SELECT:
 	    /* newSViv((sizeof(int) > 32) ? sizeof(int)-1 : 31 ); in general? */
-	    newSViv((sizeof(int) == 64 ) ? 63 : 31 );
+            (sizeof(int) == 64) ? 63: 31;
+	    retsv= newSViv((sizeof(int) == 64 ) ? 63 : 31 );
 	    break;
 	case SQL_MAX_TABLE_NAME_LEN:
-	    newSViv(NAME_LEN);
+	    retsv= newSViv(NAME_LEN);
 	    break;
 	case SQL_SERVER_NAME:
-	    newSVpv(imp_dbh->mysql.host_info,strlen(imp_dbh->mysql.host_info));
+	    retsv= newSVpv(imp_dbh->mysql.host_info,strlen(imp_dbh->mysql.host_info));
 	    break;
     	default:
  		croak("Unknown SQL Info type: %i",dbh);
Thread
[svn:DBD-mysql] r8517 - in DBD-mysql/trunk: . egcapttofu6 Jan