Formatting

This commit is contained in:
Miles Lott 2002-02-10 12:04:10 +00:00
parent 5d6721af18
commit 6ad604a565
6 changed files with 292 additions and 286 deletions

View File

@ -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,7 +40,7 @@
$this->Link_ID=msql_pconnect($this->Host);
}
// Still not connected? Raise error.
/* Still not connected? Raise error. */
if(0 == $this->Link_ID)
{
$this->halt('Link-ID == false, pconnect failed');
@ -57,7 +57,7 @@
{
$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;

View File

@ -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
{
@ -67,7 +68,7 @@
function db_addslashes($str)
{
if (!IsSet($str) || $str == '')
if(!isset($str) || $str == '')
{
return '';
}
@ -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();
}

View File

@ -102,7 +102,7 @@
if(!@mysql_select_db($Database,$this->Link_ID))
{
$this->halt("cannot use database ".$this->Database);
$this->halt('cannot use database ' . $this->Database);
return 0;
}
}
@ -152,11 +152,11 @@
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;
}
@ -203,7 +203,7 @@
$this->Error = mysql_error();
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.
@ -267,7 +267,7 @@
}
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,
* but do not consider this documented or even
* desireable behaviour.
@ -315,12 +315,12 @@
{
$this->connect();
$query = "lock tables ";
$query = 'LOCK TABLES ';
if(is_array($table))
{
while(list($key,$value)=each($table))
{
if ($key == "read" && $key!=0)
if($key == 'read' && $key!=0)
{
$query .= "$value read, ";
}
@ -348,16 +348,15 @@
{
$this->connect();
$res = @mysql_query("unlock tables");
$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,7 +384,7 @@
print $this->num_rows();
}
function f($Name, $strip_slashes = "")
function f($Name, $strip_slashes='')
{
if($strip_slashes || ($this->auto_stripslashes && ! $strip_slashes))
{
@ -410,7 +409,7 @@
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);
@ -420,7 +419,7 @@
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;
@ -487,7 +486,7 @@
$id = @mysql_list_fields($this->Database, $table);
if(!$id)
{
$this->halt("Metadata query failed.");
$this->halt('Metadata query failed.');
}
}
else
@ -495,7 +494,7 @@
$id = $this->Query_ID;
if(!$id)
{
$this->halt("No query specified.");
$this->halt('No query specified.');
}
}
@ -516,7 +515,7 @@
else
{
/* full */
$res["num_fields"]= $count;
$res['num_fields']= $count;
for($i=0; $i<$count; $i++)
{
@ -544,7 +543,7 @@
$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;
}
@ -552,16 +551,16 @@
if($file)
{
printf("<br><b>File:</b> %s",$file);
printf('<br><b>File:</b> %s',$file);
}
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,7 +576,7 @@
function table_names()
{
$this->query("SHOW TABLES");
$this->query('SHOW TABLES');
$i=0;
while($info=mysql_fetch_row($this->Query_ID))
{
@ -605,11 +604,11 @@
{
$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;

View File

@ -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,7 +66,7 @@
function connect()
{
## see above why we do this
/* see above for why we do this */
if($this->OraPutEnv)
{
PutEnv("ORACLE_SID=$this->Database");
@ -138,15 +138,17 @@
}
}
## 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)
{
@ -209,7 +211,8 @@
$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();
@ -230,36 +233,38 @@
}
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";
/* echo"<b>[$col]</b>: $value <br>\n"; */
}
$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)
{
## 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)
{
@ -326,19 +331,21 @@
$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())
@ -376,11 +383,11 @@
{
$res['num_fields']=$i;
}
# $this->disconnect();
/* $this->disconnect(); */
return $res;
}
## THIS FUNCTION IS UNSTESTED!
/* THIS FUNCTION IS UNSTESTED! */
function affected_rows()
{
if($Debug)
@ -390,20 +397,22 @@
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!
/* 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');
@ -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))
{
@ -484,7 +493,7 @@
{
$next_id = 0;
}
if ( Query_ID > 0 )
if($Query_ID > 0)
{
ora_close(Query_ID);
}
@ -500,7 +509,7 @@
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;

View File

@ -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;
@ -95,7 +95,7 @@
}
else
{
$this->query("select version()",__LINE__,__FILE__);
$this->query('SELECT version()',__LINE__,__FILE__);
$this->next_record();
$version = $this->f('version');
@ -130,26 +130,26 @@
}
}
// 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);
@ -157,19 +157,17 @@
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 '';
}
@ -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);
@ -314,7 +312,7 @@
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)
{
return -1;
@ -370,7 +368,7 @@
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);
@ -380,7 +378,7 @@
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,7 +411,7 @@
$res = array();
$this->connect();
$id = pg_exec($this->Link_ID, "select * from $table");
$id = pg_exec($this->Link_ID, "SELECT * FROM $table");
if($id < 0)
{
$this->Error = pg_ErrorMessage($id);
@ -507,7 +505,7 @@
}
else
{
$s .= sprintf("<br><b>File:</b> %s",$file);
$s .= sprintf('<br><b>File:</b> %s',$file);
}
}
@ -548,7 +546,7 @@
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())
{
@ -580,7 +578,7 @@
$currentPassword = $this->Password;
$currentDatabase = $this->Database;
if ($adminname != "")
if($adminname != '')
{
$this->User = $adminname;
$this->Password = $adminpasswd;
@ -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;

View File

@ -29,7 +29,7 @@
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()
{
@ -58,7 +58,7 @@
{
$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;
@ -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');
}
}