egroupware/phpgwapi/inc/adodb/drivers/adodb-postgres7.inc.php

243 lines
6.0 KiB
PHP
Raw Normal View History

2003-10-19 21:05:23 +02:00
<?php
/*
2005-09-26 12:12:10 +02:00
V4.65 22 July 2005 (c) 2000-2005 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
2003-10-19 21:05:23 +02:00
the BSD license will take precedence.
Set tabs to 4.
2003-10-19 21:05:23 +02:00
Postgres7 support.
28 Feb 2001: Currently indicate that we support LIMIT
01 Dec 2001: dannym added support for default values
*/
// security - hide paths
if (!defined('ADODB_DIR')) die();
2003-10-19 21:05:23 +02:00
include_once(ADODB_DIR."/drivers/adodb-postgres64.inc.php");
class ADODB_postgres7 extends ADODB_postgres64 {
var $databaseType = 'postgres7';
2003-10-19 21:05:23 +02:00
var $hasLimit = true; // set to true for pgsql 6.5+ only. support pgsql/mysql SELECT * FROM TABLE LIMIT 10
var $ansiOuter = true;
var $charSet = true; //set to true for Postgres 7 and above - PG client supports encodings
function ADODB_postgres7()
2003-10-19 21:05:23 +02:00
{
$this->ADODB_postgres64();
2004-08-15 20:45:20 +02:00
if (ADODB_ASSOC_CASE !== 2) {
$this->rsPrefix .= 'assoc_';
}
2003-10-19 21:05:23 +02:00
}
// the following should be compat with postgresql 7.2,
2003-10-19 21:05:23 +02:00
// which makes obsolete the LIMIT limit,offset syntax
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
2003-10-19 21:05:23 +02:00
{
$offsetStr = ($offset >= 0) ? ' OFFSET '.(int)$offset : '';
$limitStr = ($nrows >= 0) ? ' LIMIT '.(int)$nrows : '';
if ($secs2cache)
$rs =& $this->CacheExecute($secs2cache,$sql.$limitStr.$offsetStr,$inputarr);
else
$rs =& $this->Execute($sql.$limitStr.$offsetStr,$inputarr);
return $rs;
2003-10-19 21:05:23 +02:00
}
/*
function Prepare($sql)
{
$info = $this->ServerInfo();
if ($info['version']>=7.3) {
return array($sql,false);
}
return $sql;
}
*/
// from Edward Jaramilla, improved version - works on pg 7.4
function MetaForeignKeys($table, $owner=false, $upper=false)
{
$sql = 'SELECT t.tgargs as args
FROM
pg_trigger t,pg_class c,pg_proc p
WHERE
t.tgenabled AND
t.tgrelid = c.oid AND
t.tgfoid = p.oid AND
p.proname = \'RI_FKey_check_ins\' AND
c.relname = \''.strtolower($table).'\'
ORDER BY
t.tgrelid';
$rs = $this->Execute($sql);
if ($rs && !$rs->EOF) {
$arr =& $rs->GetArray();
$a = array();
foreach($arr as $v)
{
$data = explode(chr(0), $v['args']);
if ($upper) {
$a[strtoupper($data[2])][] = strtoupper($data[4].'='.$data[5]);
} else {
$a[$data[2]][] = $data[4].'='.$data[5];
}
}
return $a;
}
return false;
}
2003-10-19 21:05:23 +02:00
// this is a set of functions for managing client encoding - very important if the encodings
// of your database and your output target (i.e. HTML) don't match
//for instance, you may have UNICODE database and server it on-site as WIN1251 etc.
// GetCharSet - get the name of the character set the client is using now
// the functions should work with Postgres 7.0 and above, the set of charsets supported
// depends on compile flags of postgres distribution - if no charsets were compiled into the server
// it will return 'SQL_ANSI' always
function GetCharSet()
{
//we will use ADO's builtin property charSet
$this->charSet = @pg_client_encoding($this->_connectionID);
if (!$this->charSet) {
return false;
} else {
return $this->charSet;
}
}
2003-10-19 21:05:23 +02:00
// SetCharSet - switch the client encoding
function SetCharSet($charset_name)
{
$this->GetCharSet();
if ($this->charSet !== $charset_name) {
$if = pg_set_client_encoding($this->_connectionID, $charset_name);
if ($if == "0" & $this->GetCharSet() == $charset_name) {
return true;
} else return false;
} else return true;
}
// use pg_escape_string if available
function qstr($s,$magic_quotes=false)
{
if (!$magic_quotes && function_exists('pg_escape_string')) {
return "'".pg_escape_string($s)."'";
}
return parent::qstr($s,$magic_quotes);
}
function _insertid($table,$column)
{
return parent::_insertid($table,$column,false); // dont try oid
}
2003-10-19 21:05:23 +02:00
}
2003-10-19 21:05:23 +02:00
/*--------------------------------------------------------------------------------------
Class Name: Recordset
--------------------------------------------------------------------------------------*/
class ADORecordSet_postgres7 extends ADORecordSet_postgres64{
var $databaseType = "postgres7";
function ADORecordSet_postgres7($queryID,$mode=false)
2003-10-19 21:05:23 +02:00
{
$this->ADORecordSet_postgres64($queryID,$mode);
}
2003-10-19 21:05:23 +02:00
// 10% speedup to move MoveNext to child class
function MoveNext()
2003-10-19 21:05:23 +02:00
{
if (!$this->EOF) {
$this->_currentRow++;
if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
$this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
2003-10-19 21:05:23 +02:00
if (is_array($this->fields)) {
if ($this->fields && isset($this->_blobArr)) $this->_fixblobs();
2003-10-19 21:05:23 +02:00
return true;
}
}
$this->fields = false;
$this->EOF = true;
}
return false;
}
2003-10-19 21:05:23 +02:00
}
2004-08-15 20:45:20 +02:00
class ADORecordSet_assoc_postgres7 extends ADORecordSet_postgres64{
var $databaseType = "postgres7";
function ADORecordSet_assoc_postgres7($queryID,$mode=false)
2004-08-15 20:45:20 +02:00
{
$this->ADORecordSet_postgres64($queryID,$mode);
}
2004-08-15 20:45:20 +02:00
function _fetch()
{
if ($this->_currentRow >= $this->_numOfRows && $this->_numOfRows >= 0)
return false;
$this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
2004-08-15 20:45:20 +02:00
if ($this->fields) {
if (isset($this->_blobArr)) $this->_fixblobs();
$this->_updatefields();
}
2004-08-15 20:45:20 +02:00
return (is_array($this->fields));
}
2004-08-15 20:45:20 +02:00
// Create associative array
function _updatefields()
{
if (ADODB_ASSOC_CASE == 2) return; // native
2004-08-15 20:45:20 +02:00
$arr = array();
$lowercase = (ADODB_ASSOC_CASE == 0);
2004-08-15 20:45:20 +02:00
foreach($this->fields as $k => $v) {
if (is_integer($k)) $arr[$k] = $v;
else {
if ($lowercase)
$arr[strtolower($k)] = $v;
else
$arr[strtoupper($k)] = $v;
}
}
$this->fields = $arr;
}
function MoveNext()
2004-08-15 20:45:20 +02:00
{
if (!$this->EOF) {
$this->_currentRow++;
if ($this->_numOfRows < 0 || $this->_numOfRows > $this->_currentRow) {
$this->fields = @pg_fetch_array($this->_queryID,$this->_currentRow,$this->fetchMode);
2004-08-15 20:45:20 +02:00
if (is_array($this->fields)) {
if ($this->fields) {
if (isset($this->_blobArr)) $this->_fixblobs();
2004-08-15 20:45:20 +02:00
$this->_updatefields();
}
return true;
}
}
2004-08-15 20:45:20 +02:00
$this->fields = false;
$this->EOF = true;
}
return false;
}
}
2003-10-19 21:05:23 +02:00
?>