From 4d929cadc2ec628af4c85e69c3cd83c136a383a6 Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Sat, 29 Sep 2001 00:33:05 +0000 Subject: [PATCH] formatting --- phpgwapi/inc/class.db_msql.inc.php | 242 ++++++++++--------- phpgwapi/inc/class.db_odbc.inc.php | 338 +++++++++++++++------------ phpgwapi/inc/class.db_sybase.inc.php | 193 ++++++++------- 3 files changed, 425 insertions(+), 348 deletions(-) diff --git a/phpgwapi/inc/class.db_msql.inc.php b/phpgwapi/inc/class.db_msql.inc.php index 4b0ba63f6a..c3a927649c 100644 --- a/phpgwapi/inc/class.db_msql.inc.php +++ b/phpgwapi/inc/class.db_msql.inc.php @@ -15,133 +15,155 @@ /* $Id$ */ -class db { - var $Host = ""; - var $Database = ""; + class db + { + var $Host = ''; + var $Database = ''; - var $Link_ID = 0; - var $Query_ID = 0; - var $Record = array(); - var $Row; + var $Link_ID = 0; + var $Query_ID = 0; + var $Record = array(); + var $Row; - var $Error = ""; - - var $Auto_Free = 0; ## Set this to 1 for automatic msql_free_result() + var $Error = ''; - function connect() { - // Not connected? Then connect? - if ( 0 == $this->Link_ID ) { - // Check for local connect - $this->Link_ID = empty($this->Host)? - $this->Link_ID=msql_pconnect(): - $this->Link_ID=msql_pconnect($this->Host); - } - - // Still not connected? Raise error. - if ( 0 == $this->Link_ID ) { - $this->halt("Link-ID == false, pconnect failed"); - } + var $Auto_Free = 0; ## Set this to 1 for automatic msql_free_result() - // Select current database - if (!msql_select_db($this->Database, $this->Link_ID)) { - $this->halt("cannot use database ".$this->Database); - } - } - - function query($Query_String) { - $this->connect(); + function connect() + { + // Not connected? Then connect? + if ( 0 == $this->Link_ID ) + { + // Check for local connect + $this->Link_ID = empty($this->Host)? + $this->Link_ID=msql_pconnect(): + $this->Link_ID=msql_pconnect($this->Host); + } -# printf("Debug: query = %s
\n", $Query_String); + // Still not connected? Raise error. + if ( 0 == $this->Link_ID ) + { + $this->halt('Link-ID == false, pconnect failed'); + } - $this->Query_ID = msql_query($Query_String,$this->Link_ID); - $this->Row = 0; - $this->Error = msql_error(); - if (!$this->Query_ID) { - $this->halt("Invalid SQL: ".$Query_String); - } + // Select current database + if (!msql_select_db($this->Database, $this->Link_ID)) + { + $this->halt('cannot use database '.$this->Database); + } + } - return $this->Query_ID; - } + function query($Query_String) + { + $this->connect(); - function next_record() { - $this->Record = msql_fetch_array($this->Query_ID); - $this->Row += 1; - $this->Error = msql_error(); + # printf("Debug: query = %s
\n", $Query_String); - $stat = is_array($this->Record); - if (!$stat && $this->Auto_Free) { - msql_free_result($this->Query_ID); - $this->Query_ID = 0; - } - return $stat; - } + $this->Query_ID = msql_query($Query_String,$this->Link_ID); + $this->Row = 0; + $this->Error = msql_error(); + if (!$this->Query_ID) + { + $this->halt('Invalid SQL: '.$Query_String); + } + return $this->Query_ID; + } - function seek($pos) { - $status = msql_data_seek($this->Query_ID, $pos); - if ($status) - $this->Row = $pos; - return; - } + function next_record() + { + $this->Record = msql_fetch_array($this->Query_ID); + $this->Row += 1; + $this->Error = msql_error(); - function metadata($table) { - $count = 0; - $id = 0; - $res = array(); + $stat = is_array($this->Record); + if (!$stat && $this->Auto_Free) + { + msql_free_result($this->Query_ID); + $this->Query_ID = 0; + } + return $stat; + } - $this->connect(); - $id = @msql_list_fields($this->Database, $table); - if ($id < 0) { - $this->Error = msql_error(); - $this->halt("Metadata query failed."); - } - $count = msql_num_fields($id); - - for ($i=0; $i<$count; $i++) { - $res[$i]["table"] = msql_fieldtable ($id, $i); - $res[$i]["name"] = msql_fieldname ($id, $i); - $res[$i]["type"] = msql_fieldtype ($id, $i); - $res[$i]["len"] = msql_fieldlen ($id, $i); - $res[$i]["flags"] = msql_fieldflags ($id, $i); - $res["meta"][$res[$i]["name"]] = $i; - $res["num_fields"]= $count; - } - - msql_free_result($id); - return $res; - } + function seek($pos) + { + $status = msql_data_seek($this->Query_ID, $pos); + if ($status) + { + $this->Row = $pos; + } + return; + } - function affected_rows() { - return msql_affected_rows($this->Query_ID); - } + function metadata($table) + { + $count = 0; + $id = 0; + $res = array(); - function num_rows() { - return msql_num_rows($this->Query_ID); - } + $this->connect(); + $id = @msql_list_fields($this->Database, $table); + if ($id < 0) + { + $this->Error = msql_error(); + $this->halt('Metadata query failed.'); + } + $count = msql_num_fields($id); - function num_fields() { - return msql_num_fields($this->Query_ID); - } + for ($i=0; $i<$count; $i++) + { + $res[$i]['table'] = msql_fieldtable ($id, $i); + $res[$i]['name'] = msql_fieldname ($id, $i); + $res[$i]['type'] = msql_fieldtype ($id, $i); + $res[$i]['len'] = msql_fieldlen ($id, $i); + $res[$i]['flags'] = msql_fieldflags ($id, $i); + $res['meta'][$res[$i]['name']] = $i; + $res['num_fields']= $count; + } - function nf() { - return $this->num_rows(); - } + msql_free_result($id); + return $res; + } - function np() { - print $this->num_rows(); - } + function affected_rows() + { + return msql_affected_rows($this->Query_ID); + } - function f($Name) { - return $this->Record[$Name]; - } + function num_rows() + { + return msql_num_rows($this->Query_ID); + } - function p($Name) { - print $this->Record[$Name]; - } - - function halt($msg) { - printf("Database error: %s
\n", $msg); - printf("MSQL Error: %s
\n", $this->Error); - die("Session halted."); - } -} + function num_fields() + { + return msql_num_fields($this->Query_ID); + } + + function nf() + { + return $this->num_rows(); + } + + function np() + { + print $this->num_rows(); + } + + function f($Name) + { + return $this->Record[$Name]; + } + + function p($Name) + { + print $this->Record[$Name]; + } + + function halt($msg) + { + printf("Database error: %s
\n", $msg); + printf("MSQL Error: %s
\n", $this->Error); + die('Session halted.'); + } + } ?> diff --git a/phpgwapi/inc/class.db_odbc.inc.php b/phpgwapi/inc/class.db_odbc.inc.php index cad1475e14..36c04cd205 100644 --- a/phpgwapi/inc/class.db_odbc.inc.php +++ b/phpgwapi/inc/class.db_odbc.inc.php @@ -14,165 +14,201 @@ \**************************************************************************/ /* $Id$ */ -class db { - var $Host = ""; - var $Database = ""; - var $User = ""; - var $Password = ""; - var $UseODBCCursor = 0; + class db + { + var $Host = ''; + var $Database = ''; + var $User = ''; + var $Password = ''; + var $UseODBCCursor = 0; - var $Link_ID = 0; - var $Query_ID = 0; - var $Record = array(); - var $Row = 0; - - var $Errno = 0; - var $Error = ""; + var $Link_ID = 0; + var $Query_ID = 0; + var $Record = array(); + var $Row = 0; - var $Auto_Free = 0; ## set this to 1 to automatically free results + var $Errno = 0; + var $Error = ''; - function connect() { - if ( 0 == $this->Link_ID ) { - $this->Link_ID=odbc_pconnect($this->Database, $this->User, $this->Password, $this->UseODBCCursor); - if (!$this->Link_ID) { - $this->halt("Link-ID == false, odbc_pconnect failed"); - } - } - } - - function query($Query_String) { - $this->connect(); - -# printf("
Debug: query = %s
\n", $Query_String); + var $Auto_Free = 0; ## set this to 1 to automatically free results -# rei@netone.com.br suggested that we use this instead of the odbc_exec(). -# He is on NT, connecting to a Unix MySQL server with ODBC. -- KK -# $this->Query_ID = odbc_prepare($this->Link_ID,$Query_String); -# $this->Query_Ok = odbc_execute($this->Query_ID); - - $this->Query_ID = odbc_exec($this->Link_ID,$Query_String); - $this->Row = 0; - odbc_binmode($this->Query_ID, 1); - odbc_longreadlen($this->Query_ID, 4096); - - if (!$this->Query_ID) { - $this->Errno = 1; - $this->Error = "General Error (The ODBC interface cannot return detailed error messages)."; - $this->halt("Invalid SQL: ".$Query_String); - } - return $this->Query_ID; - } - - function next_record() { - $this->Record = array(); - $stat = odbc_fetch_into($this->Query_ID, ++$this->Row, &$this->Record); - if (!$stat) { - if ($this->Auto_Free) { - odbc_free_result($this->Query_ID); - $this->Query_ID = 0; - }; - } else { - // add to Record[] - $count = odbc_num_fields($this->Query_ID); - for ($i=1; $i<=$count; $i++) - $this->Record[strtolower(odbc_field_name ($this->Query_ID, $i)) ] = $this->Record[ $i - 1 ]; - } - return $stat; - } - - function seek($pos) { - $this->Row = $pos; - } + function connect() + { + if ( 0 == $this->Link_ID ) + { + $this->Link_ID=odbc_pconnect($this->Database, $this->User, $this->Password, $this->UseODBCCursor); + if (!$this->Link_ID) + { + $this->halt('Link-ID == false, odbc_pconnect failed'); + } + } + } - function metadata($table) { - $count = 0; - $id = 0; - $res = array(); + function query($Query_String) + { + $this->connect(); - $this->connect(); - $id = odbc_exec($this->Link_ID, "select * from $table"); - if (!$id) { - $this->Errno = 1; - $this->Error = "General Error (The ODBC interface cannot return detailed error messages)."; - $this->halt("Metadata query failed."); - } - $count = odbc_num_fields($id); - - for ($i=1; $i<=$count; $i++) { - $res[$i]["table"] = $table; - $name = odbc_field_name ($id, $i); - $res[$i]["name"] = $name; - $res[$i]["type"] = odbc_field_type ($id, $name); - $res[$i]["len"] = 0; // can we determine the width of this column? - $res[$i]["flags"] = ""; // any optional flags to report? - } - - odbc_free_result($id); - return $res; - } - - function affected_rows() { - return odbc_num_rows($this->Query_ID); - } - - function num_rows() { - # Many ODBC drivers don't support odbc_num_rows() on SELECT statements. - $num_rows = odbc_num_rows($this->Query_ID); - //printf ($num_rows."
"); + # printf("
Debug: query = %s
\n", $Query_String); - # This is a workaround. It is intended to be ugly. - if ($num_rows < 0) { - $i=10; - while (odbc_fetch_row($this->Query_ID, $i)) - $i*=10; + # rei@netone.com.br suggested that we use this instead of the odbc_exec(). + # He is on NT, connecting to a Unix MySQL server with ODBC. -- KK + # $this->Query_ID = odbc_prepare($this->Link_ID,$Query_String); + # $this->Query_Ok = odbc_execute($this->Query_ID); - $j=0; - while ($i!=$j) { - $k= $j+intval(($i-$j)/2); - if (odbc_fetch_row($this->Query_ID, $k)) - $j=$k; - else - $i=$k; - if (($i-$j)==1) { - if (odbc_fetch_row($this->Query_ID, $i)) - $j=$i; - else - $i=$j; - }; - //printf("$i $j $k
"); - }; - $num_rows=$i; - } + $this->Query_ID = odbc_exec($this->Link_ID,$Query_String); + $this->Row = 0; + odbc_binmode($this->Query_ID, 1); + odbc_longreadlen($this->Query_ID, 4096); - return $num_rows; - } - - function num_fields() { - return count($this->Record)/2; - } + if (!$this->Query_ID) + { + $this->Errno = 1; + $this->Error = 'General Error (The ODBC interface cannot return detailed error messages).'; + $this->halt('Invalid SQL: '.$Query_String); + } + return $this->Query_ID; + } - function nf() { - return $this->num_rows(); - } - - function np() { - print $this->num_rows(); - } - - function f($Field_Name) { - return $this->Record[strtolower($Field_Name)]; - } - - function p($Field_Name) { - print $this->f($Field_Name); - } - - function halt($msg) { - printf("Database error: %s
\n", $msg); - printf("ODBC Error: %s (%s)
\n", - $this->Errno, - $this->Error); - die("Session halted."); - } -} + function next_record() + { + $this->Record = array(); + $stat = odbc_fetch_into($this->Query_ID, ++$this->Row, &$this->Record); + if (!$stat) + { + if ($this->Auto_Free) + { + odbc_free_result($this->Query_ID); + $this->Query_ID = 0; + }; + } + else + { + // add to Record[] + $count = odbc_num_fields($this->Query_ID); + for ($i=1; $i<=$count; $i++) + { + $this->Record[strtolower(odbc_field_name ($this->Query_ID, $i)) ] = $this->Record[ $i - 1 ]; + } + } + return $stat; + } + + function seek($pos) + { + $this->Row = $pos; + } + + function metadata($table) + { + $count = 0; + $id = 0; + $res = array(); + + $this->connect(); + $id = odbc_exec($this->Link_ID, "select * from $table"); + if (!$id) + { + $this->Errno = 1; + $this->Error = 'General Error (The ODBC interface cannot return detailed error messages).'; + $this->halt('Metadata query failed.'); + } + $count = odbc_num_fields($id); + + for ($i=1; $i<=$count; $i++) + { + $res[$i]['table'] = $table; + $name = odbc_field_name ($id, $i); + $res[$i]['name'] = $name; + $res[$i]['type'] = odbc_field_type ($id, $name); + $res[$i]['len'] = 0; // can we determine the width of this column? + $res[$i]['flags'] = ''; // any optional flags to report? + } + odbc_free_result($id); + return $res; + } + + function affected_rows() + { + return odbc_num_rows($this->Query_ID); + } + + function num_rows() + { + # Many ODBC drivers don't support odbc_num_rows() on SELECT statements. + $num_rows = odbc_num_rows($this->Query_ID); + //printf ($num_rows."
"); + + # This is a workaround. It is intended to be ugly. + if ($num_rows < 0) + { + $i=10; + while (odbc_fetch_row($this->Query_ID, $i)) + { + $i*=10; + } + + $j=0; + while ($i!=$j) + { + $k= $j+intval(($i-$j)/2); + if (odbc_fetch_row($this->Query_ID, $k)) + { + $j=$k; + } + else + { + $i=$k; + } + if (($i-$j)==1) + { + if (odbc_fetch_row($this->Query_ID, $i)) + { + $j=$i; + } + else + { + $i=$j; + } + } + //printf("$i $j $k
"); + } + $num_rows=$i; + } + return $num_rows; + } + + function num_fields() + { + return count($this->Record)/2; + } + + function nf() + { + return $this->num_rows(); + } + + function np() + { + print $this->num_rows(); + } + + function f($Field_Name) + { + return $this->Record[strtolower($Field_Name)]; + } + + function p($Field_Name) + { + print $this->f($Field_Name); + } + + function halt($msg) + { + printf("Database error: %s
\n", $msg); + printf("ODBC Error: %s (%s)
\n", + $this->Errno, + $this->Error); + die('Session halted.'); + } + } ?> diff --git a/phpgwapi/inc/class.db_sybase.inc.php b/phpgwapi/inc/class.db_sybase.inc.php index 9d1d010045..372b0df773 100644 --- a/phpgwapi/inc/class.db_sybase.inc.php +++ b/phpgwapi/inc/class.db_sybase.inc.php @@ -17,18 +17,19 @@ /* $Id$ */ -class db { - var $Host = ""; - var $Database = ""; - var $User = ""; - var $Password = ""; + class db + { + var $Host = ''; + var $Database = ''; + var $User = ''; + var $Password = ''; - var $Link_ID = 0; - var $Query_ID = 0; - var $Record = array(); - var $Row; + var $Link_ID = 0; + var $Query_ID = 0; + 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() { @@ -45,104 +46,122 @@ class db { } 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'); } if(!sybase_select_db($this->Database, $this->Link_ID)) { - $this->halt("cannot use database ".$this->Database); + $this->halt('cannot use database '.$this->Database); } } - function query($Query_String) { - $this->connect(); + function query($Query_String) + { + $this->connect(); -# printf("Debug: query = %s
\n", $Query_String); + # printf("Debug: query = %s
\n", $Query_String); - $this->Query_ID = sybase_query($Query_String,$this->Link_ID); - $this->Row = 0; - if (!$this->Query_ID) { - $this->halt("Invalid SQL: ".$Query_String); - } + $this->Query_ID = sybase_query($Query_String,$this->Link_ID); + $this->Row = 0; + if (!$this->Query_ID) + { + $this->halt('Invalid SQL: '.$Query_String); + } - return $this->Query_ID; - } + return $this->Query_ID; + } - function next_record() { - $this->Record = sybase_fetch_array($this->Query_ID); - $this->Row += 1; + function next_record() + { + $this->Record = sybase_fetch_array($this->Query_ID); + $this->Row += 1; - $stat = is_array($this->Record); - if (!$stat && $this->Auto_Free) { - sybase_free_result($this->Query_ID); - $this->Query_ID = 0; - } - return $stat; - } + $stat = is_array($this->Record); + if (!$stat && $this->Auto_Free) + { + sybase_free_result($this->Query_ID); + $this->Query_ID = 0; + } + return $stat; + } - function seek($pos) { - $status = sybase_data_seek($this->Query_ID, $pos); - if ($status) - $this->Row = $pos; - return; - } + function seek($pos) + { + $status = sybase_data_seek($this->Query_ID, $pos); + if ($status) + { + $this->Row = $pos; + } + return; + } - function metadata($table) { - $count = 0; - $id = 0; - $res = array(); + function metadata($table) + { + $count = 0; + $id = 0; + $res = array(); - $this->connect(); - $result = $this->query("exec sp_columns $table"); - if ($result < 0) { - $this->Errno = 1; - $this->Error = "Metadata query failed"; - $this->halt("Metadata query failed."); - } - $count = sybase_num_rows($result); + $this->connect(); + $result = $this->query("exec sp_columns $table"); + if ($result < 0) + { + $this->Errno = 1; + $this->Error = 'Metadata query failed'; + $this->halt('Metadata query failed.'); + } + $count = sybase_num_rows($result); - for ($i=0; $i<$count; $i++) { - $res[$i]["table"] = $table ; - $res[$i]["name"] = sybase_result ($result, $i, "COLUMN_NAME"); - $res[$i]["type"] = sybase_result ($result, $i, "TYPE_NAME"); - $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"); + for ($i=0; $i<$count; $i++) + { + $res[$i]['table'] = $table ; + $res[$i]['name'] = sybase_result ($result, $i, 'COLUMN_NAME'); + $res[$i]['type'] = sybase_result ($result, $i, 'TYPE_NAME'); + $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'); - } - } + } + } - function affected_rows() { - return sybase_affected_rows($this->Query_ID); - } + function affected_rows() + { + return sybase_affected_rows($this->Query_ID); + } - function num_rows() { - return sybase_num_rows($this->Query_ID); - } + function num_rows() + { + return sybase_num_rows($this->Query_ID); + } - function num_fields() { - return sybase_num_fields($this->Query_ID); - } + function num_fields() + { + return sybase_num_fields($this->Query_ID); + } - function nf() { - return $this->num_rows(); - } + function nf() + { + return $this->num_rows(); + } - function np() { - print $this->num_rows(); - } + function np() + { + print $this->num_rows(); + } - function f($Name) { - return $this->Record[$Name]; - } + function f($Name) + { + return $this->Record[$Name]; + } - function p($Name) { - print $this->Record[$Name]; - } - - function halt($msg) { - printf("Database error: %s
\n", $msg); - printf("Sybase Error
\n"); - die("Session halted."); - } -} + function p($Name) + { + print $this->Record[$Name]; + } + + function halt($msg) + { + printf("Database error: %s
\n", $msg); + printf("Sybase Error
\n"); + die("Session halted."); + } + } ?>