Hello,
after having talked to Derick Rethans at LinuxTag and him suggesting I
put up a mail on php-dev about it, I guess I will give it a try.

The following is my issue:
http://bugs.php.net/bug.php?id=16960

Derick told me all of PHPs database extensions simpy return strings for
everything except NULLs and that changing this behaviour will brake code
existing out there. As I do not believe it will, this is why I felt it
might be worth discussing it.

As people rely on the fact (do they?) that what "comes out of"
sybase_fetch_row() is an array of strings, they will probably do
something like this to check on NULLs:

if (!$data['field_to_test_on_null_values']) { do_something(); }
This will, of course, not be broken. !(null) = !(false) = true

Whatever you do with fields containing numbers (int, float) will not be
affected by my patch either: $num= $data['count']+ 1; will be equivalent
whether $data['count'] is int(5) or string(1) "5", except PHP will no
longer need to automagically make string(1) "5" to int(5) before
performing the addition, right?

What I do right now:
------------------------------------------------------------------

  $result= sybase_query($sql, $this->handle);
  if (FALSE === $result) return FALSE;

  $i= -1;
  while (++$i < @sybase_num_fields($result)) {
    $field= sybase_fetch_field($result, $i);
    $this->fields[$field->name]= $field->type;
  }

[...and later on, when fetching the results...]

   $row= sybase_fetch_array($query);
   if (FALSE === $row) return FALSE;
      
   foreach($row as $key=> $val) {
     if ($val === FALSE) { $row[$key]= NULL; continue; }

     switch ($this->fields[$key]) {
       case 'bit':
       case 'int': 
         settype($row[$key], 'integer'); 
         break;
            
       case 'real':
         // very ugly ["numeric(10)" => int, "numeric(10, 2)" => double]
         if (floor($val) == $val) {
           settype($row[$key], 'integer');
         } else {
           settype($row[$key], 'double'); 
         }
         break;
     }
   }
------------------------------------------------------------------

...which of course is overhead. I'd like to get rid of it but of course
not break any code. My question is, is there anybody out there using
Sybase who can think of impacts from my patch(es)?

Greetings from Karlsruhe,
Timm


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to