fetus Diary

2007/11/21(水) - pg_query_params と bool

PHP のマニュアルより

When inserting into a pg column of type bool, you cannot supply a PHP type of bool. You must instead use a string "t" or "f". PHP attempts to change boolean values supplied as parameters to strings, and then attempts to use a blank string for false.

ということは、

<?php
class ADODB_postgres7 extends ADODB_postgres64 {
    
    ...
    
    function _query($sql,$inputarr)
    {
        if (! $this->_bindInputArray) {
            // We don't have native support for parameterized queries, so let's emulate it at the parent
            return ADODB_postgres64::_query($sql, $inputarr);
        }
        $this->_errorMsg = false;
        // -- added Cristiano da Cunha Duarte
        if ($inputarr) {
            $sqlarr = explode('?',trim($sql));
            $sql = '';
            $i = 1;
            $last = sizeof($sqlarr)-1;
            foreach($sqlarr as $v) {
                if ($last < $i) $sql .= $v;
                else $sql .= $v.' $'.$i;
                $i++;
            }
            
            // ここから
            foreach($inputarr as &$val) {
                if(is_bool($val)) {
                    $val = $val ? $this->true : $this->false;
                }
            }
            // ここまで
            
            $rez = pg_query_params($this->_connectionID,$sql, $inputarr);
        } else {
            $rez = pg_query($this->_connectionID,$sql);
        }
        // check if no data returned, then no need to create real recordset
        if ($rez && pg_numfields($rez) <= 0) {
            if (is_resource($this->_resultid) && get_resource_type($this->_resultid) === 'pgsql result') {
                pg_freeresult($this->_resultid);
            }
            $this->_resultid = $rez;
            return true;
        }        
        return $rez;
    }
    
    ...
}
?>

こうでいいのか?

コメント

コメントはありません。

名前
メール
コメント

※HTML タグは使えません。HTTP URL には自動リンクが張られます。

Captcha
画像から読み取れる文字を入力: