mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-08 00:54:15 +01:00
Formatting
This commit is contained in:
parent
5d6721af18
commit
6ad604a565
@ -27,11 +27,11 @@
|
||||
|
||||
var $Error = '';
|
||||
|
||||
var $Auto_Free = 0; ## Set this to 1 for automatic msql_free_result()
|
||||
var $Auto_Free = 0; /* Set this to 1 for automatic msql_free_result() */
|
||||
|
||||
function connect()
|
||||
{
|
||||
// Not connected? Then connect?
|
||||
/* Not connected? Then connect? */
|
||||
if ( 0 == $this->Link_ID )
|
||||
{
|
||||
// Check for local connect
|
||||
@ -40,14 +40,14 @@
|
||||
$this->Link_ID=msql_pconnect($this->Host);
|
||||
}
|
||||
|
||||
// Still not connected? Raise error.
|
||||
if ( 0 == $this->Link_ID )
|
||||
/* Still not connected? Raise error. */
|
||||
if(0 == $this->Link_ID)
|
||||
{
|
||||
$this->halt('Link-ID == false, pconnect failed');
|
||||
}
|
||||
|
||||
// Select current database
|
||||
if (!msql_select_db($this->Database, $this->Link_ID))
|
||||
if(!msql_select_db($this->Database, $this->Link_ID))
|
||||
{
|
||||
$this->halt('cannot use database '.$this->Database);
|
||||
}
|
||||
@ -57,12 +57,12 @@
|
||||
{
|
||||
$this->connect();
|
||||
|
||||
# printf("Debug: query = %s<br>\n", $Query_String);
|
||||
/* printf("Debug: query = %s<br>\n", $Query_String); */
|
||||
|
||||
$this->Query_ID = msql_query($Query_String,$this->Link_ID);
|
||||
$this->Row = 0;
|
||||
$this->Error = msql_error();
|
||||
if (!$this->Query_ID)
|
||||
if(!$this->Query_ID)
|
||||
{
|
||||
$this->halt('Invalid SQL: '.$Query_String);
|
||||
}
|
||||
@ -76,7 +76,7 @@
|
||||
$this->Error = msql_error();
|
||||
|
||||
$stat = is_array($this->Record);
|
||||
if (!$stat && $this->Auto_Free)
|
||||
if(!$stat && $this->Auto_Free)
|
||||
{
|
||||
msql_free_result($this->Query_ID);
|
||||
$this->Query_ID = 0;
|
||||
@ -87,7 +87,7 @@
|
||||
function seek($pos)
|
||||
{
|
||||
$status = msql_data_seek($this->Query_ID, $pos);
|
||||
if ($status)
|
||||
if($status)
|
||||
{
|
||||
$this->Row = $pos;
|
||||
}
|
||||
@ -102,14 +102,14 @@
|
||||
|
||||
$this->connect();
|
||||
$id = @msql_list_fields($this->Database, $table);
|
||||
if ($id < 0)
|
||||
if($id < 0)
|
||||
{
|
||||
$this->Error = msql_error();
|
||||
$this->halt('Metadata query failed.');
|
||||
}
|
||||
$count = msql_num_fields($id);
|
||||
|
||||
for ($i=0; $i<$count; $i++)
|
||||
for($i=0; $i<$count; $i++)
|
||||
{
|
||||
$res[$i]['table'] = msql_fieldtable ($id, $i);
|
||||
$res[$i]['name'] = msql_fieldname ($id, $i);
|
||||
|
@ -3,7 +3,7 @@
|
||||
* phpGroupWare API - MS SQL Server support *
|
||||
* (C) Copyright 1998 Cameron Taggart (cameront@wolfenet.com) *
|
||||
* Modified by Guarneri carmelo (carmelo@melting-soft.com) *
|
||||
* Modified by Cameron Just (C.Just@its.uq.edu.au) *
|
||||
* Modified by Cameron Just (C.Just@its.uq.edu.au) *
|
||||
* ------------------------------------------------------------------------ *
|
||||
* This is not part of phpGroupWare, but is used by phpGroupWare. *
|
||||
* http://www.phpgroupware.org/ *
|
||||
@ -16,8 +16,9 @@
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* echo "<BR>This is using the MSSQL class<BR>"; */
|
||||
// ^^ really ?! :)
|
||||
/* echo '<BR>This is using the MSSQL class<BR>'; */
|
||||
/* ^^ really ?! :) */
|
||||
/* mdean, put your info in the banner, mkay? */
|
||||
|
||||
class db
|
||||
{
|
||||
@ -40,9 +41,9 @@
|
||||
|
||||
function connect()
|
||||
{
|
||||
if ( 0 == $this->Link_ID )
|
||||
if(0 == $this->Link_ID)
|
||||
{
|
||||
if ($GLOBALS['phpgw_info']['server']['db_persistent'])
|
||||
if($GLOBALS['phpgw_info']['server']['db_persistent'])
|
||||
{
|
||||
$this->Link_ID=mssql_pconnect($this->Host, $this->User, $this->Password);
|
||||
}
|
||||
@ -50,7 +51,7 @@
|
||||
{
|
||||
$this->Link_ID=mssql_connect($this->Host, $this->User, $this->Password);
|
||||
}
|
||||
if (!$this->Link_ID)
|
||||
if(!$this->Link_ID)
|
||||
{
|
||||
$this->halt('Link-ID == false, mssql_'.($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'').'connect failed');
|
||||
}
|
||||
@ -67,7 +68,7 @@
|
||||
|
||||
function db_addslashes($str)
|
||||
{
|
||||
if (!IsSet($str) || $str == '')
|
||||
if(!isset($str) || $str == '')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
@ -85,14 +86,14 @@
|
||||
{
|
||||
$this->VEOF = -1;
|
||||
|
||||
if (!$this->Link_ID)
|
||||
if(!$this->Link_ID)
|
||||
{
|
||||
$this->connect();
|
||||
}
|
||||
|
||||
$this->Query_ID = mssql_query($Query_String, $this->Link_ID);
|
||||
$this->Row = 0;
|
||||
if (!$this->Query_ID)
|
||||
if(!$this->Query_ID)
|
||||
{
|
||||
$this->halt("Invalid SQL: " . $Query_String, $line, $file);
|
||||
}
|
||||
@ -113,22 +114,22 @@
|
||||
// public: perform a query with limited result set
|
||||
function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '')
|
||||
{
|
||||
if (! $num_rows)
|
||||
if(!$num_rows)
|
||||
{
|
||||
$num_rows = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
|
||||
}
|
||||
|
||||
if ($this->Debug)
|
||||
if($this->Debug)
|
||||
{
|
||||
printf("Debug: limit_query = %s<br>offset=%d, num_rows=%d<br>\n", $Query_String, $offset, $num_rows);
|
||||
}
|
||||
|
||||
$this->query($Query_String, $line, $file);
|
||||
if ($this->Query_ID)
|
||||
if($this->Query_ID)
|
||||
{
|
||||
$this->Row = $offset;
|
||||
// Push cursor to appropriate row in case next_record() is used
|
||||
if ($offset > 0)
|
||||
if($offset > 0)
|
||||
{
|
||||
@mssql_data_seek($this->Query_ID, $offset);
|
||||
}
|
||||
@ -140,20 +141,20 @@
|
||||
|
||||
function next_record()
|
||||
{
|
||||
if (!$this->Query_ID)
|
||||
if(!$this->Query_ID)
|
||||
{
|
||||
$this->halt("next_record called with no query pending.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($this->VEOF == -1 || ($this->Row++ <= $this->VEOF))
|
||||
if($this->VEOF == -1 || ($this->Row++ <= $this->VEOF))
|
||||
{
|
||||
// Work around for buggy mssql_fetch_array
|
||||
$rec = @mssql_fetch_row($this->Query_ID);
|
||||
if ($rec)
|
||||
if($rec)
|
||||
{
|
||||
$this->Record = array();
|
||||
for ($i = 0; $i < count($rec); $i++)
|
||||
for($i = 0; $i < count($rec); $i++)
|
||||
{
|
||||
$this->Record[$i] = $rec[$i];
|
||||
$o = mssql_fetch_field($this->Query_ID, $i);
|
||||
@ -171,7 +172,7 @@
|
||||
}
|
||||
|
||||
$stat = is_array($this->Record);
|
||||
if (!$stat && $this->Auto_Free)
|
||||
if(!$stat && $this->Auto_Free)
|
||||
{
|
||||
$this->free();
|
||||
}
|
||||
@ -187,7 +188,7 @@
|
||||
|
||||
function transaction_commit()
|
||||
{
|
||||
if (!$this->Errno && $this->Transaction)
|
||||
if(!$this->Errno && $this->Transaction)
|
||||
{
|
||||
$this->Transaction = false;
|
||||
return !!mssql_query('COMMIT TRAN', $this->Link_ID);
|
||||
@ -198,7 +199,7 @@
|
||||
|
||||
function transaction_abort()
|
||||
{
|
||||
if ($this->Transaction)
|
||||
if($this->Transaction)
|
||||
{
|
||||
$this->Transaction = false;
|
||||
return !!mssql_query('ROLLBACK TRAN', $this->Link_ID);
|
||||
@ -221,14 +222,14 @@
|
||||
|
||||
$this->connect();
|
||||
$id = mssql_query("select * from $table", $this->Link_ID);
|
||||
if (!$id)
|
||||
if(!$id)
|
||||
{
|
||||
$this->halt('Metadata query failed.');
|
||||
}
|
||||
|
||||
$count = mssql_num_fields($id);
|
||||
|
||||
for ($i=0; $i<$count; $i++)
|
||||
for($i=0; $i<$count; $i++)
|
||||
{
|
||||
$info = mssql_fetch_field($id, $i);
|
||||
$res[$i]['table'] = $table;
|
||||
@ -283,13 +284,13 @@
|
||||
* and field are required for pgsql compatiblity. MSSQL uses a query to retrieve the last
|
||||
* identity on the connection, so table and field are ignored here as well.
|
||||
*/
|
||||
if (!isset($table) || $table == '' || !isset($field) || $field == '')
|
||||
if(!isset($table) || $table == '' || !isset($field) || $field == '')
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
$result = @mssql_query("select @@identity", $this->Link_ID);
|
||||
if (!$result)
|
||||
if(!$result)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -298,7 +299,7 @@
|
||||
|
||||
function lock($table, $mode="write")
|
||||
{
|
||||
// /me really, really, really hates locks - transactions serve just fine
|
||||
/* /me really, really, really hates locks - transactions serve just fine */
|
||||
return $this->transaction_begin();
|
||||
}
|
||||
|
||||
@ -314,29 +315,29 @@
|
||||
|
||||
$this->Errno = 1;
|
||||
$this->Error = mssql_get_last_message();
|
||||
if ($this->Error == '')
|
||||
if($this->Error == '')
|
||||
{
|
||||
$this->Error = "General Error (The MS-SQL interface did not return a detailed error message).";
|
||||
}
|
||||
|
||||
if ($this->Halt_On_Error == "no")
|
||||
if($this->Halt_On_Error == "no")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->haltmsg($msg);
|
||||
|
||||
if ($file)
|
||||
if($file)
|
||||
{
|
||||
printf("<br><b>File:</b> %s",$file);
|
||||
}
|
||||
|
||||
if ($line)
|
||||
if($line)
|
||||
{
|
||||
printf("<br><b>Line:</b> %s",$line);
|
||||
}
|
||||
|
||||
if ($this->Halt_On_Error != "report")
|
||||
if($this->Halt_On_Error != "report")
|
||||
{
|
||||
echo "<p><b>Session halted.</b>";
|
||||
$GLOBALS['phpgw']->common->phpgw_exit(True);
|
||||
@ -346,7 +347,7 @@
|
||||
function haltmsg($msg)
|
||||
{
|
||||
printf("<b>Database error:</b> %s<br>\n", $msg);
|
||||
if ($this->Errno != "0" && $this->Error != "()")
|
||||
if($this->Errno != "0" && $this->Error != "()")
|
||||
{
|
||||
printf("<b>MS-SQL Error</b>: %s (%s)<br>\n", $this->Errno, $this->Error);
|
||||
}
|
||||
@ -356,7 +357,7 @@
|
||||
{
|
||||
$this->query("select name from sysobjects where type='u' and name != 'dtproperties'");
|
||||
$i = 0;
|
||||
while ($info = @mssql_fetch_row($this->Query_ID))
|
||||
while($info = @mssql_fetch_row($this->Query_ID))
|
||||
{
|
||||
$return[$i]['table_name'] = $info[0];
|
||||
$return[$i]['tablespace_name'] = $this->Database;
|
||||
|
@ -66,26 +66,26 @@
|
||||
function connect($Database = '', $Host = '', $User = '', $Password = '')
|
||||
{
|
||||
/* Handle defaults */
|
||||
if ('' == $Database)
|
||||
if('' == $Database)
|
||||
{
|
||||
$Database = $this->Database;
|
||||
}
|
||||
if ('' == $Host)
|
||||
if('' == $Host)
|
||||
{
|
||||
$Host = $this->Host;
|
||||
}
|
||||
if ('' == $User)
|
||||
if('' == $User)
|
||||
{
|
||||
$User = $this->User;
|
||||
}
|
||||
if ('' == $Password)
|
||||
if('' == $Password)
|
||||
{
|
||||
$Password = $this->Password;
|
||||
}
|
||||
/* establish connection, select database */
|
||||
if ( 0 == $this->Link_ID )
|
||||
if(0 == $this->Link_ID)
|
||||
{
|
||||
if ($GLOBALS['phpgw_info']['server']['db_persistent'])
|
||||
if($GLOBALS['phpgw_info']['server']['db_persistent'])
|
||||
{
|
||||
$this->Link_ID=mysql_pconnect($Host, $User, $Password);
|
||||
}
|
||||
@ -94,15 +94,15 @@
|
||||
$this->Link_ID=mysql_connect($Host, $User, $Password);
|
||||
}
|
||||
|
||||
if (!$this->Link_ID)
|
||||
if(!$this->Link_ID)
|
||||
{
|
||||
$this->halt(($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'')."connect($Host, $User, \$Password) failed.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!@mysql_select_db($Database,$this->Link_ID))
|
||||
if(!@mysql_select_db($Database,$this->Link_ID))
|
||||
{
|
||||
$this->halt("cannot use database ".$this->Database);
|
||||
$this->halt('cannot use database ' . $this->Database);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -126,7 +126,7 @@
|
||||
|
||||
function db_addslashes($str)
|
||||
{
|
||||
if (!isset($str) || $str == '')
|
||||
if(!isset($str) || $str == '')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
@ -150,13 +150,13 @@
|
||||
{
|
||||
echo '<b>Warning: limit() is no longer used, use limit_query()</b>';
|
||||
|
||||
if ($start == 0)
|
||||
if($start == 0)
|
||||
{
|
||||
$s = 'limit ' . $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
|
||||
$s = 'LIMIT ' . $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$s = "limit $start," . $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
|
||||
$s = "LIMIT $start," . $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
@ -177,22 +177,22 @@
|
||||
* when calling the class without a query, e.g. in situations
|
||||
* like these: '$db = new db_Subclass;'
|
||||
*/
|
||||
if ($Query_String == '')
|
||||
if($Query_String == '')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (!$this->connect())
|
||||
if(!$this->connect())
|
||||
{
|
||||
return 0; /* we already complained in connect() about that. */
|
||||
};
|
||||
|
||||
# New query, discard previous result.
|
||||
if ($this->Query_ID)
|
||||
if($this->Query_ID)
|
||||
{
|
||||
$this->free();
|
||||
}
|
||||
|
||||
if ($this->Debug)
|
||||
if($this->Debug)
|
||||
{
|
||||
printf("Debug: query = %s<br>\n", $Query_String);
|
||||
}
|
||||
@ -201,9 +201,9 @@
|
||||
$this->Row = 0;
|
||||
$this->Errno = mysql_errno();
|
||||
$this->Error = mysql_error();
|
||||
if (! $this->Query_ID)
|
||||
if(!$this->Query_ID)
|
||||
{
|
||||
$this->halt("Invalid SQL: ".$Query_String, $line, $file);
|
||||
$this->halt('Invalid SQL: ' . $Query_String, $line, $file);
|
||||
}
|
||||
|
||||
# Will return nada if it fails. That's fine.
|
||||
@ -213,12 +213,12 @@
|
||||
// public: perform a query with limited result set
|
||||
function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '')
|
||||
{
|
||||
if (! $num_rows)
|
||||
if(!$num_rows)
|
||||
{
|
||||
$num_rows = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
|
||||
}
|
||||
|
||||
if ($offset == 0)
|
||||
if($offset == 0)
|
||||
{
|
||||
$Query_String .= ' LIMIT ' . $num_rows;
|
||||
}
|
||||
@ -227,7 +227,7 @@
|
||||
$Query_String .= ' LIMIT ' . $offset . ',' . $num_rows;
|
||||
}
|
||||
|
||||
if ($this->Debug)
|
||||
if($this->Debug)
|
||||
{
|
||||
printf("Debug: limit_query = %s<br>offset=%d, num_rows=%d<br>\n", $Query_String, $offset, $num_rows);
|
||||
}
|
||||
@ -238,7 +238,7 @@
|
||||
/* public: walk result set */
|
||||
function next_record()
|
||||
{
|
||||
if (!$this->Query_ID)
|
||||
if(!$this->Query_ID)
|
||||
{
|
||||
$this->halt('next_record called with no query pending.');
|
||||
return 0;
|
||||
@ -250,7 +250,7 @@
|
||||
$this->Error = mysql_error();
|
||||
|
||||
$stat = is_array($this->Record);
|
||||
if (!$stat && $this->Auto_Free)
|
||||
if(!$stat && $this->Auto_Free)
|
||||
{
|
||||
$this->free();
|
||||
}
|
||||
@ -261,14 +261,14 @@
|
||||
function seek($pos = 0)
|
||||
{
|
||||
$status = @mysql_data_seek($this->Query_ID, $pos);
|
||||
if ($status)
|
||||
if($status)
|
||||
{
|
||||
$this->Row = $pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->halt("seek($pos) failed: result has ".$this->num_rows()." rows");
|
||||
/* half assed attempt to save the day,
|
||||
$this->halt("seek($pos) failed: result has " . $this->num_rows() . ' rows');
|
||||
/* half assed attempt to save the day,
|
||||
* but do not consider this documented or even
|
||||
* desireable behaviour.
|
||||
*/
|
||||
@ -302,7 +302,7 @@
|
||||
* with pgsql, the params must be supplied.
|
||||
*/
|
||||
|
||||
if (!isset($table) || $table == '' || !isset($field) || $field == '')
|
||||
if(!isset($table) || $table == '' || !isset($field) || $field == '')
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -315,12 +315,12 @@
|
||||
{
|
||||
$this->connect();
|
||||
|
||||
$query = "lock tables ";
|
||||
if (is_array($table))
|
||||
$query = 'LOCK TABLES ';
|
||||
if(is_array($table))
|
||||
{
|
||||
while (list($key,$value)=each($table))
|
||||
while(list($key,$value)=each($table))
|
||||
{
|
||||
if ($key == "read" && $key!=0)
|
||||
if($key == 'read' && $key!=0)
|
||||
{
|
||||
$query .= "$value read, ";
|
||||
}
|
||||
@ -336,7 +336,7 @@
|
||||
$query .= "$table $mode";
|
||||
}
|
||||
$res = @mysql_query($query, $this->Link_ID);
|
||||
if (!$res)
|
||||
if(!$res)
|
||||
{
|
||||
$this->halt("lock($table, $mode) failed.");
|
||||
return 0;
|
||||
@ -348,16 +348,15 @@
|
||||
{
|
||||
$this->connect();
|
||||
|
||||
$res = @mysql_query("unlock tables");
|
||||
if (!$res)
|
||||
$res = @mysql_query('UNLOCK TABLES');
|
||||
if(!$res)
|
||||
{
|
||||
$this->halt("unlock() failed.");
|
||||
$this->halt('unlock() failed.');
|
||||
return 0;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/* public: evaluate the result (size, width) */
|
||||
function affected_rows()
|
||||
{
|
||||
@ -385,9 +384,9 @@
|
||||
print $this->num_rows();
|
||||
}
|
||||
|
||||
function f($Name, $strip_slashes = "")
|
||||
function f($Name, $strip_slashes='')
|
||||
{
|
||||
if ($strip_slashes || ($this->auto_stripslashes && ! $strip_slashes))
|
||||
if($strip_slashes || ($this->auto_stripslashes && ! $strip_slashes))
|
||||
{
|
||||
return stripslashes($this->Record[$Name]);
|
||||
}
|
||||
@ -407,20 +406,20 @@
|
||||
{
|
||||
$this->connect();
|
||||
|
||||
if ($this->lock($this->Seq_Table))
|
||||
if($this->lock($this->Seq_Table))
|
||||
{
|
||||
/* get sequence number (locked) and increment */
|
||||
$q = sprintf("select nextid from %s where seq_name = '%s'",
|
||||
$q = sprintf("SELECT nextid FROM %s WHERE seq_name = '%s'",
|
||||
$this->Seq_Table,
|
||||
$seq_name);
|
||||
$id = @mysql_query($q, $this->Link_ID);
|
||||
$res = @mysql_fetch_array($id);
|
||||
|
||||
/* No current value, make one */
|
||||
if (!is_array($res))
|
||||
if(!is_array($res))
|
||||
{
|
||||
$currentid = 0;
|
||||
$q = sprintf("insert into %s values('%s', %s)",
|
||||
$q = sprintf("INSERT INTO %s VALUES('%s', %s)",
|
||||
$this->Seq_Table,
|
||||
$seq_name,
|
||||
$currentid);
|
||||
@ -428,10 +427,10 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
$currentid = $res["nextid"];
|
||||
$currentid = $res['nextid'];
|
||||
}
|
||||
$nextid = $currentid + 1;
|
||||
$q = sprintf("update %s set nextid = '%s' where seq_name = '%s'",
|
||||
$q = sprintf("UPDATE %s SET nextid = '%s' WHERE seq_name = '%s'",
|
||||
$this->Seq_Table,
|
||||
$nextid,
|
||||
$seq_name);
|
||||
@ -440,14 +439,14 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->halt("cannot lock ".$this->Seq_Table." - has it been created?");
|
||||
$this->halt('cannot lock ' . $this->Seq_Table . ' - has it been created?');
|
||||
return 0;
|
||||
}
|
||||
return $nextid;
|
||||
}
|
||||
|
||||
/* public: return table metadata */
|
||||
function metadata($table='',$full=false)
|
||||
function metadata($table='',$full=False)
|
||||
{
|
||||
$count = 0;
|
||||
$id = 0;
|
||||
@ -481,30 +480,30 @@
|
||||
|
||||
/* if no $table specified, assume that we are working with a query */
|
||||
/* result */
|
||||
if ($table)
|
||||
if($table)
|
||||
{
|
||||
$this->connect();
|
||||
$id = @mysql_list_fields($this->Database, $table);
|
||||
if (!$id)
|
||||
if(!$id)
|
||||
{
|
||||
$this->halt("Metadata query failed.");
|
||||
$this->halt('Metadata query failed.');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$id = $this->Query_ID;
|
||||
if (!$id)
|
||||
if(!$id)
|
||||
{
|
||||
$this->halt("No query specified.");
|
||||
$this->halt('No query specified.');
|
||||
}
|
||||
}
|
||||
|
||||
$count = @mysql_num_fields($id);
|
||||
|
||||
/* made this IF due to performance (one if is faster than $count if's) */
|
||||
if (!$full)
|
||||
if(!$full)
|
||||
{
|
||||
for ($i=0; $i<$count; $i++)
|
||||
for($i=0; $i<$count; $i++)
|
||||
{
|
||||
$res[$i]['table'] = @mysql_field_table ($id, $i);
|
||||
$res[$i]['name'] = @mysql_field_name ($id, $i);
|
||||
@ -516,9 +515,9 @@
|
||||
else
|
||||
{
|
||||
/* full */
|
||||
$res["num_fields"]= $count;
|
||||
$res['num_fields']= $count;
|
||||
|
||||
for ($i=0; $i<$count; $i++)
|
||||
for($i=0; $i<$count; $i++)
|
||||
{
|
||||
$res[$i]['table'] = @mysql_field_table ($id, $i);
|
||||
$res[$i]['name'] = @mysql_field_name ($id, $i);
|
||||
@ -530,7 +529,7 @@
|
||||
}
|
||||
|
||||
/* free the result only if we were called on a table */
|
||||
if ($table)
|
||||
if($table)
|
||||
{
|
||||
@mysql_free_result($id);
|
||||
}
|
||||
@ -544,24 +543,24 @@
|
||||
|
||||
$this->Error = @mysql_error($this->Link_ID);
|
||||
$this->Errno = @mysql_errno($this->Link_ID);
|
||||
if ($this->Halt_On_Error == "no")
|
||||
if($this->Halt_On_Error == 'no')
|
||||
{
|
||||
return;
|
||||
}
|
||||
$this->haltmsg($msg);
|
||||
|
||||
if ($file)
|
||||
if($file)
|
||||
{
|
||||
printf("<br><b>File:</b> %s",$file);
|
||||
printf('<br><b>File:</b> %s',$file);
|
||||
}
|
||||
if ($line)
|
||||
if($line)
|
||||
{
|
||||
printf("<br><b>Line:</b> %s",$line);
|
||||
printf('<br><b>Line:</b> %s',$line);
|
||||
}
|
||||
|
||||
if ($this->Halt_On_Error != "report")
|
||||
if($this->Halt_On_Error != 'report')
|
||||
{
|
||||
echo "<p><b>Session halted.</b>";
|
||||
echo '<p><b>Session halted.</b>';
|
||||
$GLOBALS['phpgw']->common->phpgw_exit(True);
|
||||
}
|
||||
}
|
||||
@ -569,7 +568,7 @@
|
||||
function haltmsg($msg)
|
||||
{
|
||||
printf("<b>Database error:</b> %s<br>\n", $msg);
|
||||
if ($this->Errno != "0" && $this->Error != "()")
|
||||
if($this->Errno != '0' && $this->Error != '()')
|
||||
{
|
||||
printf("<b>MySQL Error</b>: %s (%s)<br>\n",$this->Errno,$this->Error);
|
||||
}
|
||||
@ -577,9 +576,9 @@
|
||||
|
||||
function table_names()
|
||||
{
|
||||
$this->query("SHOW TABLES");
|
||||
$this->query('SHOW TABLES');
|
||||
$i=0;
|
||||
while ($info=mysql_fetch_row($this->Query_ID))
|
||||
while($info=mysql_fetch_row($this->Query_ID))
|
||||
{
|
||||
$return[$i]['table_name'] = $info[0];
|
||||
$return[$i]['tablespace_name'] = $this->Database;
|
||||
@ -595,21 +594,21 @@
|
||||
return $return;
|
||||
}
|
||||
|
||||
function create_database($adminname = '', $adminpasswd = '')
|
||||
function create_database($adminname='', $adminpasswd='')
|
||||
{
|
||||
$currentUser = $this->User;
|
||||
$currentPassword = $this->Password;
|
||||
$currentDatabase = $this->Database;
|
||||
|
||||
if ($adminname != '')
|
||||
if($adminname != '')
|
||||
{
|
||||
$this->User = $adminname;
|
||||
$this->Password = $adminpasswd;
|
||||
$this->Database = "mysql";
|
||||
$this->Database = 'mysql';
|
||||
}
|
||||
$this->disconnect();
|
||||
$this->query("CREATE DATABASE $currentDatabase");
|
||||
$this->query("grant all on $currentDatabase.* to $currentUser@localhost identified by '$currentPassword'");
|
||||
$this->query('CREATE DATABASE ' . $currentDatabase);
|
||||
$this->query("GRANT all on $currentDatabase.* to $currentUser@localhost IDENTIFIED BY '$currentPassword'");
|
||||
$this->disconnect();
|
||||
|
||||
$this->User = $currentUser;
|
||||
|
@ -45,7 +45,7 @@
|
||||
var $type = 'oracle';
|
||||
var $revision = '1.2';
|
||||
|
||||
var $Halt_On_Error = 'yes'; ## 'yes' (halt with message), 'no' (ignore errors quietly), 'report' (ignore errror, but spit a warning)
|
||||
var $Halt_On_Error = 'yes'; /* 'yes' (halt with message), 'no' (ignore errors quietly), 'report' (ignore errror, but spit a warning) */
|
||||
|
||||
/* public: constructor */
|
||||
function db($query = '')
|
||||
@ -66,13 +66,13 @@
|
||||
|
||||
function connect()
|
||||
{
|
||||
## see above why we do this
|
||||
if ($this->OraPutEnv)
|
||||
/* see above for why we do this */
|
||||
if($this->OraPutEnv)
|
||||
{
|
||||
PutEnv("ORACLE_SID=$this->Database");
|
||||
PutEnv("ORACLE_HOME=$this->Home");
|
||||
}
|
||||
if ( 0 == $this->Link_ID )
|
||||
if(0 == $this->Link_ID)
|
||||
{
|
||||
if($this->Debug)
|
||||
{
|
||||
@ -121,7 +121,7 @@
|
||||
{
|
||||
printf("<br>connect() Link_ID: $this->Link_ID<br>\n");
|
||||
}
|
||||
if (!$this->Link_ID)
|
||||
if(!$this->Link_ID)
|
||||
{
|
||||
$this->halt('connect() Link-ID == false '
|
||||
. "($this->Link_ID), ora_".($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'').'logon failed');
|
||||
@ -138,31 +138,33 @@
|
||||
}
|
||||
}
|
||||
|
||||
## In order to increase the # of cursors per system/user go edit the
|
||||
## init.ora file and increase the max_open_cursors parameter. Yours is on
|
||||
## the default value, 100 per user.
|
||||
## We tried to change the behaviour of query() in a way, that it tries
|
||||
## to safe cursors, but on the other side be carefull with this, that you
|
||||
## don't use an old result.
|
||||
##
|
||||
## You can also make extensive use of ->disconnect()!
|
||||
## The unused QueryIDs will be recycled sometimes.
|
||||
/*
|
||||
* In order to increase the # of cursors per system/user go edit the
|
||||
* init.ora file and increase the max_open_cursors parameter. Yours is on
|
||||
* the default value, 100 per user.
|
||||
* We tried to change the behaviour of query() in a way, that it tries
|
||||
* to safe cursors, but on the other side be carefull with this, that you
|
||||
* don't use an old result.
|
||||
*
|
||||
* You can also make extensive use of ->disconnect()!
|
||||
* The unused QueryIDs will be recycled sometimes.
|
||||
*/
|
||||
|
||||
function query($Query_String)
|
||||
{
|
||||
/* No empty queries, please, since PHP4 chokes on them. */
|
||||
if ($Query_String == '')
|
||||
if($Query_String == '')
|
||||
{
|
||||
/* The empty query string is passed on from the constructor,
|
||||
* when calling the class without a query, e.g. in situations
|
||||
* like these: '$db = new DB_Sql_Subclass;'
|
||||
*/
|
||||
* when calling the class without a query, e.g. in situations
|
||||
* like these: '$db = new DB_Sql_Subclass;'
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
$this->connect();
|
||||
$this->lastQuery=$Query_String;
|
||||
|
||||
if (!$this->Query_ID)
|
||||
if(!$this->Query_ID)
|
||||
{
|
||||
$this->Query_ID = ora_open($this->Link_ID);
|
||||
}
|
||||
@ -178,7 +180,7 @@
|
||||
$this->Error=ora_error($this->Query_ID);
|
||||
$this->halt("<BR>ora_parse() failed:<BR>$Query_String<BR><small>Snap & paste this to sqlplus!</SMALL>");
|
||||
}
|
||||
elseif (!@ora_exec($this->Query_ID))
|
||||
elseif(!@ora_exec($this->Query_ID))
|
||||
{
|
||||
$this->Errno=ora_errorcode($this->Query_ID);
|
||||
$this->Error=ora_error($this->Query_ID);
|
||||
@ -197,10 +199,10 @@
|
||||
|
||||
function next_record()
|
||||
{
|
||||
if (!$this->no_next_fetch &&
|
||||
if(!$this->no_next_fetch &&
|
||||
0 == ora_fetch($this->Query_ID))
|
||||
{
|
||||
if ($this->Debug)
|
||||
if($this->Debug)
|
||||
{
|
||||
printf("<br>next_record(): ID: %d,Rows: %d<br>\n",
|
||||
$this->Query_ID,$this->num_rows());
|
||||
@ -209,57 +211,60 @@
|
||||
|
||||
$errno=ora_errorcode($this->Query_ID);
|
||||
if(1403 == $errno)
|
||||
{ # 1043 means no more records found
|
||||
{
|
||||
/* 1043 means no more records found */
|
||||
$this->Errno = 0;
|
||||
$this->Error = '';
|
||||
$this->disconnect();
|
||||
$stat=0;
|
||||
$stat = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->Error=ora_error($this->Query_ID);
|
||||
$this->Errno=$errno;
|
||||
$this->Error = ora_error($this->Query_ID);
|
||||
$this->Errno = $errno;
|
||||
if($this->Debug)
|
||||
{
|
||||
printf('<br>%d Error: %s',
|
||||
$this->Errno,
|
||||
$this->Error);
|
||||
}
|
||||
$stat=0;
|
||||
$stat = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->no_next_fetch=false;
|
||||
$this->no_next_fetch = False;
|
||||
for($ix=0;$ix<ora_numcols($this->Query_ID);$ix++)
|
||||
{
|
||||
$col=strtolower(ora_columnname($this->Query_ID,$ix));
|
||||
$value=ora_getcolumn($this->Query_ID,$ix);
|
||||
$this->Record[ "$col" ] = $value;
|
||||
# echo"<b>[$col]</b>: $value <br>\n";
|
||||
$this->Record["$col"] = $value;
|
||||
/* echo"<b>[$col]</b>: $value <br>\n"; */
|
||||
}
|
||||
$stat=1;
|
||||
$stat = 1;
|
||||
}
|
||||
return $stat;
|
||||
}
|
||||
|
||||
## seek() works only for $pos - 1 and $pos
|
||||
## Perhaps I make a own implementation, but my
|
||||
## opinion is, that this should be done by PHP3
|
||||
/*
|
||||
* seek() works only for $pos - 1 and $pos
|
||||
* Perhaps I make a own implementation, but my
|
||||
* opinion is, that this should be done by PHP3
|
||||
*/
|
||||
function seek($pos)
|
||||
{
|
||||
if($this->Row - 1 == $pos)
|
||||
{
|
||||
$this->no_next_fetch=true;
|
||||
$this->no_next_fetch = True;
|
||||
}
|
||||
elseif ($this->Row == $pos )
|
||||
elseif($this->Row == $pos)
|
||||
{
|
||||
## do nothing
|
||||
/* do nothing */
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->halt("Invalid seek(): Position is cannot be handled by API.<BR>".
|
||||
"Difference too big. Wanted: $pos Current pos: $this->Row");
|
||||
$this->halt('Invalid seek(): Position cannot be handled by API.<BR>'
|
||||
. "Difference too big. Wanted: $pos Current pos: $this->Row");
|
||||
}
|
||||
if($Debug)
|
||||
{
|
||||
@ -268,9 +273,9 @@
|
||||
$this->Row=$pos;
|
||||
}
|
||||
|
||||
function lock($table, $mode = 'write')
|
||||
function lock($table, $mode='write')
|
||||
{
|
||||
if ($mode == 'write')
|
||||
if($mode == 'write')
|
||||
{
|
||||
$result = ora_do($this->Link_ID, "lock table $table in row exclusive mode");
|
||||
}
|
||||
@ -326,85 +331,89 @@
|
||||
|
||||
$this->connect();
|
||||
|
||||
## This is a RIGHT OUTER JOIN: '(+)', if you want to see, what
|
||||
## this query results try the following:
|
||||
## $table = new Table; $db = new my_DB_Sql; # you have to make
|
||||
## # your own class
|
||||
## $table->show_results($db->query(see query vvvvvv))
|
||||
##
|
||||
$this->query("SELECT T.table_name,T.column_name,T.data_type,".
|
||||
"T.data_length,T.data_precision,T.data_scale,T.nullable,".
|
||||
"T.char_col_decl_length,I.index_name".
|
||||
" FROM ALL_TAB_COLUMNS T,ALL_IND_COLUMNS I".
|
||||
" WHERE T.column_name=I.column_name (+)".
|
||||
" AND T.table_name=I.table_name (+)".
|
||||
" AND T.table_name=UPPER('$table') ORDER BY T.column_id");
|
||||
/*
|
||||
* This is a RIGHT OUTER JOIN: '(+)', if you want to see, what
|
||||
* this query results try the following:
|
||||
* $table = new Table; $db = new my_DB_Sql;
|
||||
* you have to make your own class
|
||||
* $table->show_results($db->query(see query vvvvvv))
|
||||
*
|
||||
*/
|
||||
$this->query("SELECT T.table_name,T.column_name,T.data_type,"
|
||||
. "T.data_length,T.data_precision,T.data_scale,T.nullable,"
|
||||
. "T.char_col_decl_length,I.index_name"
|
||||
. " FROM ALL_TAB_COLUMNS T,ALL_IND_COLUMNS I"
|
||||
. " WHERE T.column_name=I.column_name (+)"
|
||||
. " AND T.table_name=I.table_name (+)"
|
||||
. " AND T.table_name=UPPER('$table') ORDER BY T.column_id");
|
||||
|
||||
$i=0;
|
||||
while ($this->next_record())
|
||||
while($this->next_record())
|
||||
{
|
||||
$res[$i]['table'] = $this->Record[table_name];
|
||||
$res[$i]['name'] = strtolower($this->Record[column_name]);
|
||||
$res[$i]['type'] = $this->Record[data_type];
|
||||
$res[$i]['len'] = $this->Record[data_length];
|
||||
if ($this->Record[index_name])
|
||||
if($this->Record[index_name])
|
||||
{
|
||||
$res[$i]['flags'] = 'INDEX ';
|
||||
}
|
||||
$res[$i]['flags'] .= ( $this->Record['nullable'] == 'N') ? '' : 'NOT NULL';
|
||||
$res[$i]['format']= (int)$this->Record['data_precision'].','.
|
||||
(int)$this->Record[data_scale];
|
||||
if ('0,0'==$res[$i]['format'])
|
||||
if('0,0'==$res[$i]['format'])
|
||||
{
|
||||
$res[$i]['format']='';
|
||||
}
|
||||
$res[$i]['index'] = $this->Record[index_name];
|
||||
$res[$i]['chars'] = $this->Record[char_col_decl_length];
|
||||
if ($full)
|
||||
if($full)
|
||||
{
|
||||
$j=$res[$i]['name'];
|
||||
$res['meta'][$j] = $i;
|
||||
$res['meta'][strtoupper($j)] = $i;
|
||||
}
|
||||
if ($full)
|
||||
if($full)
|
||||
{
|
||||
$res['meta'][$res[$i]['name']] = $i;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
if ($full)
|
||||
if($full)
|
||||
{
|
||||
$res['num_fields']=$i;
|
||||
}
|
||||
# $this->disconnect();
|
||||
/* $this->disconnect(); */
|
||||
return $res;
|
||||
}
|
||||
|
||||
## THIS FUNCTION IS UNSTESTED!
|
||||
/* THIS FUNCTION IS UNSTESTED! */
|
||||
function affected_rows()
|
||||
{
|
||||
if ($Debug)
|
||||
if($Debug)
|
||||
{
|
||||
echo '<BR>Debug: affected_rows='. ora_numrows($this->Query_ID).'<BR>';
|
||||
}
|
||||
return ora_numrows($this->Query_ID);
|
||||
}
|
||||
|
||||
## Known bugs: It will not work for SELECT DISTINCT and any
|
||||
## other constructs which are depending on the resulting rows.
|
||||
## So you *really need* to check every query you make, if it
|
||||
## will work with it.
|
||||
##
|
||||
## Also, for a qualified replacement you need to parse the
|
||||
## selection, cause this will fail: 'SELECT id, from FROM ...').
|
||||
## 'FROM' is - as far as I know a keyword in Oracle, so it can
|
||||
## only be used in this way. But you have been warned.
|
||||
/*
|
||||
* Known bugs: It will not work for SELECT DISTINCT and any
|
||||
* other constructs which are depending on the resulting rows.
|
||||
* So you *really need* to check every query you make, if it
|
||||
* will work with it.
|
||||
*
|
||||
* Also, for a qualified replacement you need to parse the
|
||||
* selection, cause this will fail: 'SELECT id, from FROM ...').
|
||||
* 'FROM' is - as far as I know a keyword in Oracle, so it can
|
||||
* only be used in this way. But you have been warned.
|
||||
*/
|
||||
function num_rows()
|
||||
{
|
||||
$curs=ora_open($this->Link_ID);
|
||||
|
||||
## this is the important part and it is also the HACK!
|
||||
if (eregi("^[[:space:]]*SELECT[[:space:]]",$this->lastQuery) )
|
||||
/* this is the important part and it is also the HACK! */
|
||||
if(eregi("^[[:space:]]*SELECT[[:space:]]",$this->lastQuery) )
|
||||
{
|
||||
$from_pos = strpos(strtoupper($this->lastQuery),'FROM');
|
||||
$q = 'SELECT count(*) '. substr($this->lastQuery, $from_pos);
|
||||
@ -412,7 +421,7 @@
|
||||
ORA_parse($curs,$q);
|
||||
ORA_exec($curs);
|
||||
ORA_fetch($curs);
|
||||
if ($Debug)
|
||||
if($Debug)
|
||||
{
|
||||
echo '<BR>Debug: num_rows='. ORA_getcolumn($curs,0).'<BR>';
|
||||
}
|
||||
@ -463,7 +472,7 @@
|
||||
|
||||
if(!@ora_parse($Query_ID,"SELECT $seq_name.NEXTVAL FROM DUAL"))
|
||||
{
|
||||
// There is no such sequence yet, then create it
|
||||
/* There is no such sequence yet, then create it */
|
||||
if(!@ora_parse($Query_ID,"CREATE SEQUENCE $seq_name") ||
|
||||
!@ora_exec($Query_ID))
|
||||
{
|
||||
@ -472,11 +481,11 @@
|
||||
}
|
||||
@ora_parse($Query_ID,"SELECT $seq_name.NEXTVAL FROM DUAL");
|
||||
}
|
||||
if (!@ora_exec($Query_ID))
|
||||
if(!@ora_exec($Query_ID))
|
||||
{
|
||||
$this->halt("<BR>ora_exec() failed:<BR>nextID function");
|
||||
}
|
||||
if (@ora_fetch($Query_ID) )
|
||||
if(@ora_fetch($Query_ID) )
|
||||
{
|
||||
$next_id = ora_getcolumn($Query_ID, 0);
|
||||
}
|
||||
@ -484,7 +493,7 @@
|
||||
{
|
||||
$next_id = 0;
|
||||
}
|
||||
if ( Query_ID > 0 )
|
||||
if($Query_ID > 0)
|
||||
{
|
||||
ora_close(Query_ID);
|
||||
}
|
||||
@ -497,26 +506,26 @@
|
||||
{
|
||||
echo "Debug: Disconnecting $this->Query_ID...<br>\n";
|
||||
}
|
||||
if ( $this->Query_ID < 1 )
|
||||
if($this->Query_ID < 1)
|
||||
{
|
||||
echo "<B>Warning</B>: disconnect(): Cannot free ID $this->Query_ID\n";
|
||||
# return();
|
||||
/* return(); */
|
||||
}
|
||||
ora_close($this->Query_ID);
|
||||
$this->Query_ID=0;
|
||||
$this->Query_ID = 0;
|
||||
}
|
||||
|
||||
/* private: error handling */
|
||||
function halt($msg)
|
||||
{
|
||||
if ($this->Halt_On_Error == 'no')
|
||||
if($this->Halt_On_Error == 'no')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->haltmsg($msg);
|
||||
|
||||
if ($this->Halt_On_Error != 'report')
|
||||
if($this->Halt_On_Error != 'report')
|
||||
{
|
||||
die('Session halted.');
|
||||
}
|
||||
@ -534,8 +543,8 @@
|
||||
{
|
||||
$this->connect();
|
||||
$this->query('SELECT table_name,tablespace_name FROM user_tables');
|
||||
$i=0;
|
||||
while ($this->next_record())
|
||||
$i = 0;
|
||||
while($this->next_record())
|
||||
{
|
||||
$info[$i]['table_name'] = $this->Record['table_name'];
|
||||
$info[$R]['tablespace_name'] = $this->Record['tablespace_name'];
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
var $auto_stripslashes = False;
|
||||
|
||||
/* "yes" (halt with message), "no" (ignore errors quietly), "report" (ignore errror, but spit a warning) */
|
||||
/* 'yes' (halt with message), 'no' (ignore errors quietly), 'report' (ignore errror, but spit a warning) */
|
||||
var $Halt_On_Error = 'yes';
|
||||
|
||||
var $Link_ID = 0;
|
||||
@ -40,10 +40,10 @@
|
||||
/* Set this to 1 for automatic pg_freeresult on last record. */
|
||||
var $Auto_Free = 0;
|
||||
|
||||
// PostgreSQL changed somethings from 6.x -> 7.x
|
||||
/* PostgreSQL changed some things from 6.x -> 7.x */
|
||||
var $db_version;
|
||||
|
||||
// For our error handling
|
||||
/* For our error handling */
|
||||
var $xmlrpc = False;
|
||||
var $soap = False;
|
||||
|
||||
@ -60,12 +60,12 @@
|
||||
{
|
||||
$this->query($query);
|
||||
|
||||
if (ereg('xmlrpc.php',$GLOBALS['PHP_SELF']))
|
||||
if(ereg('xmlrpc.php',$GLOBALS['PHP_SELF']))
|
||||
{
|
||||
$this->xmlrpc = True;
|
||||
}
|
||||
|
||||
if (ereg('soap.php',$GLOBALS['PHP_SELF']))
|
||||
if(ereg('soap.php',$GLOBALS['PHP_SELF']))
|
||||
{
|
||||
$this->soap = True;
|
||||
}
|
||||
@ -73,14 +73,14 @@
|
||||
|
||||
function connect()
|
||||
{
|
||||
if (0 == $this->Link_ID)
|
||||
if(0 == $this->Link_ID)
|
||||
{
|
||||
$cstr = 'dbname=' . $this->Database
|
||||
. $this->ifadd($this->Host, 'host=')
|
||||
. $this->ifadd($this->Port, 'port=')
|
||||
. $this->ifadd($this->User, 'user=')
|
||||
. $this->ifadd("'".$this->Password."'", 'password=');
|
||||
if ($GLOBALS['phpgw_info']['server']['db_persistent'])
|
||||
if($GLOBALS['phpgw_info']['server']['db_persistent'])
|
||||
{
|
||||
$this->Link_ID=pg_pconnect($cstr);
|
||||
}
|
||||
@ -89,13 +89,13 @@
|
||||
$this->Link_ID=pg_connect($cstr);
|
||||
}
|
||||
|
||||
if (! $this->Link_ID)
|
||||
if(!$this->Link_ID)
|
||||
{
|
||||
$this->halt('Link-ID == false, '.($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'').'connect failed');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->query("select version()",__LINE__,__FILE__);
|
||||
$this->query('SELECT version()',__LINE__,__FILE__);
|
||||
$this->next_record();
|
||||
|
||||
$version = $this->f('version');
|
||||
@ -108,7 +108,7 @@
|
||||
function to_timestamp($epoch)
|
||||
{
|
||||
$db_version = $this->db_version;
|
||||
if (floor($db_version) == 6)
|
||||
if(floor($db_version) == 6)
|
||||
{
|
||||
return $this->to_timestamp_6($epoch);
|
||||
}
|
||||
@ -120,7 +120,7 @@
|
||||
|
||||
function from_timestamp($timestamp)
|
||||
{
|
||||
if (floor($this->db_version) == 6)
|
||||
if(floor($this->db_version) == 6)
|
||||
{
|
||||
return $this->from_timestamp_6($timestamp);
|
||||
}
|
||||
@ -130,46 +130,44 @@
|
||||
}
|
||||
}
|
||||
|
||||
// For PostgreSQL 6.x
|
||||
/* For PostgreSQL 6.x */
|
||||
function to_timestamp_6($epoch)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// For PostgreSQL 6.x
|
||||
/* For PostgreSQL 6.x */
|
||||
function from_timestamp_6($timestamp)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// For PostgreSQL 7.x
|
||||
/* For PostgreSQL 7.x */
|
||||
function to_timestamp_7($epoch)
|
||||
{
|
||||
// This needs the GMT offset!
|
||||
/* This needs the GMT offset! */
|
||||
return date('Y-m-d H:i:s-00',$epoch);
|
||||
}
|
||||
|
||||
// For PostgreSQL 7.x
|
||||
/* For PostgreSQL 7.x */
|
||||
function from_timestamp_7($timestamp)
|
||||
{
|
||||
ereg('([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})',$timestamp,$parts);
|
||||
|
||||
|
||||
return mktime($parts[4],$parts[5],$parts[6],$parts[2],$parts[3],$parts[1]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function limit($start)
|
||||
{
|
||||
echo '<b>Warning: limit() is no longer used, use limit_query()</b>';
|
||||
|
||||
if ($start == 0)
|
||||
{
|
||||
$s = 'limit ' . $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
|
||||
$s = 'LIMIT ' . $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$s = 'limit ' . $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] . ',' . $start;
|
||||
$s = 'LIMIT ' . $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'] . ',' . $start;
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
@ -182,7 +180,7 @@
|
||||
|
||||
function db_addslashes($str)
|
||||
{
|
||||
if (!IsSet($str) || $str == '')
|
||||
if(!isset($str) || $str == '')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
@ -198,7 +196,7 @@
|
||||
* when calling the class without a query, e.g. in situations
|
||||
* like these: '$db = new db_Subclass;'
|
||||
*/
|
||||
if ($Query_String == '')
|
||||
if($Query_String == '')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -212,7 +210,7 @@
|
||||
|
||||
$this->Error = pg_ErrorMessage($this->Link_ID);
|
||||
$this->Errno = ($this->Error == '') ? 0 : 1;
|
||||
if (! $this->Query_ID)
|
||||
if(!$this->Query_ID)
|
||||
{
|
||||
$this->halt('Invalid SQL: ' . $Query_String, $line, $file);
|
||||
}
|
||||
@ -223,12 +221,12 @@
|
||||
/* public: perform a query with limited result set */
|
||||
function limit_query($Query_String, $offset, $line = '', $file = '', $num_rows = '')
|
||||
{
|
||||
if (! $num_rows)
|
||||
if(!$num_rows)
|
||||
{
|
||||
$num_rows = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
|
||||
}
|
||||
|
||||
if ($offset == 0)
|
||||
if($offset == 0)
|
||||
{
|
||||
$Query_String .= ' LIMIT ' . $num_rows;
|
||||
}
|
||||
@ -237,7 +235,7 @@
|
||||
$Query_String .= ' LIMIT ' . $num_rows . ',' . $offset;
|
||||
}
|
||||
|
||||
if ($this->Debug)
|
||||
if($this->Debug)
|
||||
{
|
||||
printf("Debug: limit_query = %s<br>offset=%d, num_rows=%d<br>\n", $Query_String, $offset, $num_rows);
|
||||
}
|
||||
@ -245,7 +243,7 @@
|
||||
return $this->query($Query_String, $line, $file);
|
||||
}
|
||||
|
||||
// public: discard the query result
|
||||
/* public: discard the query result */
|
||||
function free()
|
||||
{
|
||||
@pg_freeresult($this->Query_ID);
|
||||
@ -260,7 +258,7 @@
|
||||
$this->Errno = ($this->Error == '') ? 0 : 1;
|
||||
|
||||
$stat = is_array($this->Record);
|
||||
if (!$stat && $this->Auto_Free)
|
||||
if(!$stat && $this->Auto_Free)
|
||||
{
|
||||
pg_freeresult($this->Query_ID);
|
||||
$this->Query_ID = 0;
|
||||
@ -280,7 +278,7 @@
|
||||
|
||||
function transaction_commit()
|
||||
{
|
||||
if (! $this->Errno)
|
||||
if(!$this->Errno)
|
||||
{
|
||||
return pg_Exec($this->Link_ID,'commit');
|
||||
}
|
||||
@ -303,26 +301,26 @@
|
||||
* an entire installation. These params allow us to retrieve the sequenced field without adding
|
||||
* conditional code to the apps.
|
||||
*/
|
||||
if (!isset($table) || $table == '' || !isset($field) || $field == '')
|
||||
if(!isset($table) || $table == '' || !isset($field) || $field == '')
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
$oid = pg_getlastoid($this->Query_ID);
|
||||
if ($oid == -1)
|
||||
if($oid == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
$result = @pg_Exec($this->Link_ID, "select $field from $table where oid=$oid");
|
||||
if (!$result)
|
||||
$result = @pg_Exec($this->Link_ID, "SELECT $field FROM $table WHERE oid=$oid");
|
||||
if(!$result)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
$Record = @pg_fetch_array($result, 0);
|
||||
@pg_freeresult($result);
|
||||
if (!is_array($Record)) /* OID not found? */
|
||||
if(!is_array($Record)) /* OID not found? */
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -330,15 +328,15 @@
|
||||
return $Record[0];
|
||||
}
|
||||
|
||||
function lock($table, $mode = 'write')
|
||||
function lock($table, $mode='write')
|
||||
{
|
||||
$result = $this->transaction_begin();
|
||||
|
||||
if ($mode == 'write')
|
||||
if($mode == 'write')
|
||||
{
|
||||
if (is_array($table))
|
||||
if(is_array($table))
|
||||
{
|
||||
while ($t = each($table))
|
||||
while($t = each($table))
|
||||
{
|
||||
$result = pg_Exec($this->Link_ID,'lock table ' . $t[1] . ' in share mode');
|
||||
}
|
||||
@ -367,20 +365,20 @@
|
||||
{
|
||||
$this->connect();
|
||||
|
||||
if ($this->lock($this->Seq_Table))
|
||||
if($this->lock($this->Seq_Table))
|
||||
{
|
||||
/* get sequence number (locked) and increment */
|
||||
$q = sprintf("select nextid from %s where seq_name = '%s'",
|
||||
$q = sprintf("SELECT nextid FROM %s WHERE seq_name = '%s'",
|
||||
$this->Seq_Table,
|
||||
$seq_name);
|
||||
$id = @pg_Exec($this->Link_ID, $q);
|
||||
$res = @pg_Fetch_Array($id, 0);
|
||||
|
||||
/* No current value, make one */
|
||||
if (!is_array($res))
|
||||
if(!is_array($res))
|
||||
{
|
||||
$currentid = 0;
|
||||
$q = sprintf("insert into %s values('%s', %s)",
|
||||
$q = sprintf("INSERT INTO %s VALUES('%s', %s)",
|
||||
$this->Seq_Table,
|
||||
$seq_name,
|
||||
$currentid);
|
||||
@ -391,7 +389,7 @@
|
||||
$currentid = $res['nextid'];
|
||||
}
|
||||
$nextid = $currentid + 1;
|
||||
$q = sprintf("update %s set nextid = '%s' where seq_name = '%s'",
|
||||
$q = sprintf("UPDATE %s SET nextid = '%s' WHERE seq_name = '%s'",
|
||||
$this->Seq_Table,
|
||||
$nextid,
|
||||
$seq_name);
|
||||
@ -413,8 +411,8 @@
|
||||
$res = array();
|
||||
|
||||
$this->connect();
|
||||
$id = pg_exec($this->Link_ID, "select * from $table");
|
||||
if ($id < 0)
|
||||
$id = pg_exec($this->Link_ID, "SELECT * FROM $table");
|
||||
if($id < 0)
|
||||
{
|
||||
$this->Error = pg_ErrorMessage($id);
|
||||
$this->Errno = 1;
|
||||
@ -422,12 +420,12 @@
|
||||
}
|
||||
$count = pg_NumFields($id);
|
||||
|
||||
for ($i=0; $i<$count; $i++)
|
||||
for($i=0; $i<$count; $i++)
|
||||
{
|
||||
$res[$i]['table'] = $table;
|
||||
$res[$i]['name'] = pg_FieldName ($id, $i);
|
||||
$res[$i]['type'] = pg_FieldType ($id, $i);
|
||||
$res[$i]['len'] = pg_FieldSize ($id, $i);
|
||||
$res[$i]['name'] = pg_FieldName($id, $i);
|
||||
$res[$i]['type'] = pg_FieldType($id, $i);
|
||||
$res[$i]['len'] = pg_FieldSize($id, $i);
|
||||
$res[$i]['flags'] = '';
|
||||
}
|
||||
|
||||
@ -462,7 +460,7 @@
|
||||
|
||||
function f($Name,$strip_slashes = '')
|
||||
{
|
||||
if ($strip_slashes || ($this->auto_stripslashes && ! $strip_slashes))
|
||||
if($strip_slashes || ($this->auto_stripslashes && ! $strip_slashes))
|
||||
{
|
||||
return stripslashes($this->Record[$Name]);
|
||||
}
|
||||
@ -479,7 +477,7 @@
|
||||
|
||||
function halt($msg, $line = '', $file = '')
|
||||
{
|
||||
if ($this->Halt_On_Error == 'no')
|
||||
if($this->Halt_On_Error == 'no')
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -488,7 +486,7 @@
|
||||
$this->transaction_abort();
|
||||
|
||||
|
||||
if ($this->xmlrpc || $this->soap)
|
||||
if($this->xmlrpc || $this->soap)
|
||||
{
|
||||
$s = sprintf("Database error: %s\n", $msg);
|
||||
$s .= sprintf("PostgreSQL Error: %s\n\n (%s)\n\n",$this->Errno,$this->Error);
|
||||
@ -499,43 +497,43 @@
|
||||
$s .= sprintf("<b>PostgreSQL Error</b>: %s (%s)<br>\n",$this->Errno,$this->Error);
|
||||
}
|
||||
|
||||
if ($file)
|
||||
if($file)
|
||||
{
|
||||
if ($this->xmlrpc || $this->soap)
|
||||
if($this->xmlrpc || $this->soap)
|
||||
{
|
||||
$s .= sprintf("File: %s\n",$file);
|
||||
$s .= sprintf("File: %s\n",$file);
|
||||
}
|
||||
else
|
||||
{
|
||||
$s .= sprintf("<br><b>File:</b> %s",$file);
|
||||
$s .= sprintf('<br><b>File:</b> %s',$file);
|
||||
}
|
||||
}
|
||||
|
||||
if ($line)
|
||||
if($line)
|
||||
{
|
||||
if ($this->xmlrpc || $this->soap)
|
||||
if($this->xmlrpc || $this->soap)
|
||||
{
|
||||
$s .= sprintf("Line: %s\n",$line);
|
||||
$s .= sprintf("Line: %s\n",$line);
|
||||
}
|
||||
else
|
||||
{
|
||||
$s .= sprintf("<br><b>Line:</b> %s",$line);
|
||||
$s .= sprintf("<br><b>Line:</b> %s",$line);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->Halt_On_Error == 'yes')
|
||||
if($this->Halt_On_Error == 'yes')
|
||||
{
|
||||
if (! $this->xmlrpc && ! $this->soap)
|
||||
if(!$this->xmlrpc && !$this->soap)
|
||||
{
|
||||
$s .= '<p><b>Session halted.</b>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->xmlrpc)
|
||||
if($this->xmlrpc)
|
||||
{
|
||||
xmlrpcfault($s);
|
||||
}
|
||||
elseif ($this->soap)
|
||||
elseif($this->soap)
|
||||
{
|
||||
|
||||
}
|
||||
@ -548,9 +546,9 @@
|
||||
|
||||
function table_names()
|
||||
{
|
||||
$this->query("select relname from pg_class where relkind = 'r' and not relname like 'pg_%'");
|
||||
$this->query("SELECT relname FROM pg_class WHERE relkind = 'r' AND NOT relname LIKE 'pg_%'");
|
||||
$i=0;
|
||||
while ($this->next_record())
|
||||
while($this->next_record())
|
||||
{
|
||||
$return[$i]['table_name']= $this->f(0);
|
||||
$return[$i]['tablespace_name']=$this->Database;
|
||||
@ -564,7 +562,7 @@
|
||||
{
|
||||
$this->query("SELECT relname FROM pg_class WHERE NOT relname ~ 'pg_.*' AND relkind ='i' ORDER BY relname");
|
||||
$i=0;
|
||||
while ($this->next_record())
|
||||
while($this->next_record())
|
||||
{
|
||||
$return[$i]['index_name']= $this->f(0);
|
||||
$return[$i]['tablespace_name']=$this->Database;
|
||||
@ -580,13 +578,13 @@
|
||||
$currentPassword = $this->Password;
|
||||
$currentDatabase = $this->Database;
|
||||
|
||||
if ($adminname != "")
|
||||
if($adminname != '')
|
||||
{
|
||||
$this->User = $adminname;
|
||||
$this->Password = $adminpasswd;
|
||||
}
|
||||
|
||||
if (! $this->Host)
|
||||
if(!$this->Host)
|
||||
{
|
||||
system('createdb ' . $currentDatabase, $outval);
|
||||
}
|
||||
@ -598,8 +596,8 @@
|
||||
if($outval != 0)
|
||||
{
|
||||
/* either the rights r not available or the postmaster is not running .... */
|
||||
echo 'database creation failure <BR>';
|
||||
echo 'please setup the postreSQL database manually<BR>';
|
||||
echo 'Database creation failure <BR>';
|
||||
echo 'Please setup the postreSQL database manually<BR>';
|
||||
}
|
||||
|
||||
$this->User = $currentUser;
|
||||
|
@ -29,22 +29,22 @@
|
||||
var $Record = array();
|
||||
var $Row;
|
||||
|
||||
var $Auto_Free = 0; ## Set this to 1 for automatic sybase_free_result()
|
||||
var $Auto_Free = 0; /* Set this to 1 for automatic sybase_free_result() */
|
||||
|
||||
function connect()
|
||||
{
|
||||
if ( 0 == $this->Link_ID )
|
||||
if(0 == $this->Link_ID)
|
||||
{
|
||||
if ($GLOBALS['phpgw_info']['server']['db_persistent'])
|
||||
if($GLOBALS['phpgw_info']['server']['db_persistent'])
|
||||
{
|
||||
$this->Link_ID=sybase_pconnect($this->Host,$this->User,$this->Password);
|
||||
$this->Link_ID = sybase_pconnect($this->Host,$this->User,$this->Password);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->Link_ID=sybase_connect($this->Host,$this->User,$this->Password);
|
||||
$this->Link_ID = sybase_connect($this->Host,$this->User,$this->Password);
|
||||
}
|
||||
}
|
||||
if (!$this->Link_ID)
|
||||
if(!$this->Link_ID)
|
||||
{
|
||||
$this->halt('Link-ID == false, '.($GLOBALS['phpgw_info']['server']['db_persistent']?'p':'')..'connect failed');
|
||||
}
|
||||
@ -58,11 +58,11 @@
|
||||
{
|
||||
$this->connect();
|
||||
|
||||
# printf("Debug: query = %s<br>\n", $Query_String);
|
||||
/* printf("Debug: query = %s<br>\n", $Query_String); */
|
||||
|
||||
$this->Query_ID = sybase_query($Query_String,$this->Link_ID);
|
||||
$this->Row = 0;
|
||||
if (!$this->Query_ID)
|
||||
if(!$this->Query_ID)
|
||||
{
|
||||
$this->halt('Invalid SQL: '.$Query_String);
|
||||
}
|
||||
@ -76,7 +76,7 @@
|
||||
$this->Row += 1;
|
||||
|
||||
$stat = is_array($this->Record);
|
||||
if (!$stat && $this->Auto_Free)
|
||||
if(!$stat && $this->Auto_Free)
|
||||
{
|
||||
sybase_free_result($this->Query_ID);
|
||||
$this->Query_ID = 0;
|
||||
@ -87,7 +87,7 @@
|
||||
function seek($pos)
|
||||
{
|
||||
$status = sybase_data_seek($this->Query_ID, $pos);
|
||||
if ($status)
|
||||
if($status)
|
||||
{
|
||||
$this->Row = $pos;
|
||||
}
|
||||
@ -102,7 +102,7 @@
|
||||
|
||||
$this->connect();
|
||||
$result = $this->query("exec sp_columns $table");
|
||||
if ($result < 0)
|
||||
if($result < 0)
|
||||
{
|
||||
$this->Errno = 1;
|
||||
$this->Error = 'Metadata query failed';
|
||||
@ -110,7 +110,7 @@
|
||||
}
|
||||
$count = sybase_num_rows($result);
|
||||
|
||||
for ($i=0; $i<$count; $i++)
|
||||
for($i=0; $i<$count; $i++)
|
||||
{
|
||||
$res[$i]['table'] = $table ;
|
||||
$res[$i]['name'] = sybase_result ($result, $i, 'COLUMN_NAME');
|
||||
@ -118,7 +118,6 @@
|
||||
$res[$i]['len'] = sybase_result ($result, $i, 'LENGTH');
|
||||
$res[$i]['position'] = sybase_result ($result, $i, 'ORDINAL_POSITION');
|
||||
$res[$i]['flags'] = sybase_result ($result, $i, 'REMARKS');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user