#129 ADODB Active Record doesn't deal with empty string correctly in doquote

v1.0 (example)
open
nobody
None
5
2014-02-24
2013-09-11
Richard Hildred
No
    case 'B':   
    case 'N':
    case 'C':
    case 'X':
        if (is_null($val)) return 'null';

        if (strlen($val)>0 && 
            (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")) { 
            return $db->qstr($val);
            break;
        }

// need to return something here.My preference is 'null'

Discussion

  • dregad
    dregad
    2014-02-24

    Can you test this code ?

    diff --git a/adodb-active-record.inc.php b/adodb-active-record.inc.php
    index 38a53e1..261e941 100644
    --- a/adodb-active-record.inc.php
    +++ b/adodb-active-record.inc.php
    @@ -641,13 +641,13 @@ class ADODB_Active_Record {
                    case 'N':
                    case 'C':
                    case 'X':
    -                       if (is_null($val)) return 'null';
    -
    -                       if (strlen($val)>0 &&
    -                               (strncmp($val,"'",1) != 0 || substr($val,strlen($val)-1,1) != "'")) {
    +                       if (!is_null($val) &&
    +                           strlen($val) > 0 &&
    +                           (strncmp($val, "'", 1) != 0 || substr($val, -1) != "'")
    +                       ) {
                                    return $db->qstr($val);
    -                               break;
                            }
    +                       return 'null';
                    default:
                            return $val;
                            break;