From: konrad Date: Sun, 23 May 2010 20:15:03 +0000 (+0000) Subject: better handling of NULL and booleans in Postgres adapter X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=048cc2e6f19dec6e1d6e2101f00664aef25f845a;p=konrad%2Fpack.git better handling of NULL and booleans in Postgres adapter git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@467 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/phpbase/db_pgsql.php b/phpbase/db_pgsql.php index 9eac6b1..49aa9c8 100644 --- a/phpbase/db_pgsql.php +++ b/phpbase/db_pgsql.php @@ -138,10 +138,20 @@ class PGsqlEngine extends DbEngine $crw=array(); for($j=0;$j<$nf;$j++){ $fn=$fnames[$j]; - if($dbScheme->isIntColumn($table,$fn))$crw[$j]=$row[$j]+0;else - if($dbScheme->isBlobColumn($table,$fn))$crw[$j]=pg_unescape_bytea($row[$j]);else - if($dbScheme->isBoolColumn($table,$fn))$crw[$j]=$row[$j]=='t'; - else $crw[$j]=$row[$j]; + if(pg_field_is_null($res,$i,$j)) + $crw[$j]=null; + else + if($dbScheme->isIntColumn($table,$fn)) + $crw[$j]=$row[$j]+0; + else + if($dbScheme->isBlobColumn($table,$fn)) + $crw[$j]=pg_unescape_bytea($row[$j]); + else + if($dbScheme->isBoolColumn($table,$fn)) + $crw[$j]=$this->unescapeBool($row[$j]); + else //any other type: hope string is ok + $crw[$j]=$row[$j]; + //copy to named index $crw[$fn]=$crw[$j]; } $ret[]=$crw; @@ -275,6 +285,17 @@ class PGsqlEngine extends DbEngine if($s === false||$s===null) return "NULL"; return "'".pg_escape_bytea($this->dbhdl,$s)."'"; } + + /**internal: unescape a postgres bool towards PHP bool*/ + protected function unescapeBool($b) + { + if($b===null)return null; + if(is_bool($b))return $b; + if(is_numeric($b))return ($b+0)!=0; + $b=strtolower($b); + if($b=="t" || $b=="true" || $b=="yes" || $b=="y" || $b=="on")return true; + else return false; + } }; ?> \ No newline at end of file