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