[geeklog-cvs] geeklog: Source code cosmetics: whitespace, indentation, braces, ...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Sun Feb 20 04:08:18 EST 2011
changeset 8121:c12bac9f7cbc
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/c12bac9f7cbc
user: Dirk Haun <dirk at haun-online.de>
date: Sat Feb 19 22:27:11 2011 +0100
description:
Source code cosmetics: whitespace, indentation, braces, ...
diffstat:
system/databases/pgsql.class.php | 368 +++++++++++++++++++-------------------
1 files changed, 187 insertions(+), 181 deletions(-)
diffs (truncated from 670 to 300 lines):
diff -r f3ef0160bd6a -r c12bac9f7cbc system/databases/pgsql.class.php
--- a/system/databases/pgsql.class.php Sat Feb 19 19:39:00 2011 +0100
+++ b/system/databases/pgsql.class.php Sat Feb 19 22:27:11 2011 +0100
@@ -2,13 +2,13 @@
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
-// | Geeklog 1.6 |
+// | Geeklog 1.8 |
// +---------------------------------------------------------------------------+
// | mysql.class.php |
// | |
// | mysql database class |
// +---------------------------------------------------------------------------+
-// | Copyright (C) 2000-2009 by the following authors: |
+// | Copyright (C) 2000-2011 by the following authors: |
// | |
// | Authors: Stanislav Palatnik, spalatnikk AT gmail DoT com |
// +---------------------------------------------------------------------------+
@@ -36,10 +36,10 @@
* This issue will need to be resolved some time ...
*
*/
+class database {
-class DataBase
-{
// PRIVATE PROPERTIES
+
/**
* @access private
*/
@@ -89,6 +89,7 @@
* Logs messages by calling the function held in $_errorlog_fn
*
* @param string $msg Message to log
+ *
*/
function _errorlog($msg)
{
@@ -97,27 +98,27 @@
$function($msg);
}
}
-
+
/**
* Creates a connection string for pg_connect
- * Doesn't show the port because it isnt being provided in class default assumed
- *
+ * Doesn't show the port because it isn't being provided in class default assumed
+ *
*/
function buildString()
{
$conn_string = '';
$conn_string .= (!empty($this->_host))? 'host='.$this->_host:'localhost';
$conn_string .= (!empty($this->_name))? ' dbname='.$this->_name:'';
- $conn_string .= (!empty($this->_user))? ' user='.$this->_user:'';
- $conn_string .= (!empty($this->_pass))? ' password='.$this->_pass:'';
-
+ $conn_string .= (!empty($this->_user))? ' user='.$this->_user:'';
+ $conn_string .= (!empty($this->_pass))? ' password='.$this->_pass:'';
+
return $conn_string;
}
/**
* Connects to the pgSQL database server
*
- * This function connects to the MySQL server and returns the connection object
+ * This function connects to the PostgreSQL server and returns the connection object
*
* @return object Returns connection object
*
@@ -137,31 +138,28 @@
}
if (!($this->_db)) {
- if(pg_connection_busy($this->_db))
- {
+ if(pg_connection_busy($this->_db)) {
if ($this->isVerbose()) {
$this->_errorlog("\n*** The current connection is busy ***");
}
- }
- else
- {
+ } else {
if ($this->isVerbose()) {
$this->_errorlog("\n*** Error in database->_connect ***");
}
}
}
- if ($this->_pgsql_version >= 7.4 && $this->_charset == 'utf-8') {
- pg_query($this->_db,"SET NAMES 'UTF8'");
- }
+ if ($this->_pgsql_version >= 7.4 && $this->_charset == 'utf-8') {
+ pg_query($this->_db,"SET NAMES 'UTF8'");
+ }
if ($this->isVerbose()) {
$this->_errorlog("\n***leaving database->_connect***");
}
}
-
-
+
+
// PUBLIC METHODS
/**
@@ -190,8 +188,8 @@
$this->_connect();
}
-
- /**
+
+ /**
* Retrieves returns the number of effected rows for last query
*
* Retrieves returns the number of effected rows for last query
@@ -202,15 +200,14 @@
*/
function dbAffectedRows($recordset)
{
- if(!isset($recordset))
- {
+ if(!isset($recordset)) {
$recordset = pg_get_result($this->_db);
}
return @pg_affected_rows($recordset);
}
-
- /**
- * Returns the contents of one cell from a MySQL result set
+
+ /**
+ * Returns the contents of one cell from a PostgreSQL result set
*
* @param object $recordset The recordset to operate on
* @param int $row row to get data from
@@ -231,7 +228,7 @@
}
return @pg_fetch_result($recordset,$row,$field);
}
-
+
/**
* Retrieves record from a recordset
*
@@ -247,12 +244,12 @@
if ($both) {
$result_type = PGSQL_BOTH;
} else {
- $result_type = PGSQL_ASSOC;
+ $result_type = PGSQL_ASSOC;
}
return pg_fetch_array($recordset, NULL, $result_type);
-
+
}
-
+
/**
* Retrieves returns the field name for a field
*
@@ -267,7 +264,7 @@
{
return @pg_field_name($recordset,$fnumber);
}
-
+
/**
* Copies a record from one table to another (can be the same table)
*
@@ -311,7 +308,7 @@
return false;
}
} else {
- if (!empty($id) && ( isset($value) || $value != "")) {
+ if (!empty($id) && ( isset($value) || $value != "")) {
$sql .= " WHERE $id = '$value'";
}
}
@@ -323,8 +320,8 @@
$this->_errorlog("\n*** Leaving database->dbCopy ***");
}
}
-
- /**
+
+ /**
* Executes a query on the pgSQL server
*
* This executes the passed SQL and returns the recordset or errors out
@@ -343,7 +340,7 @@
/* Replace some non ANSI keywords */
if(preg_match('#LIMIT ([0-9]+),([\\s])?([0-9]+)#',$sql,$matches))
{
- $sql = str_replace($matches[0],'LIMIT '.$matches[3].' OFFSET '.$matches[1],$sql);
+ $sql = str_replace($matches[0],'LIMIT '.$matches[3].' OFFSET '.$matches[1],$sql);
}
// Run query
if ($ignore_errors == 1) {
@@ -363,7 +360,9 @@
} else {
// callee may want to supress printing of errors
- if ($ignore_errors == 1) return false;
+ if ($ignore_errors == 1) {
+ return false;
+ }
if ($this->isVerbose()) {
$this->_errorlog("\n***sql caused an error***");
@@ -371,8 +370,8 @@
}
}
}
-
- /**
+
+ /**
* Saves information to the database
*
* This will use a REPLACE INTO to save a record into the
@@ -391,93 +390,87 @@
$sql = "SELECT COUNT(*) FROM $table";
$result = $this->dbQuery($sql);
$row = pg_fetch_row($result);
- if($row[0]==0) //nothing in the table yet
- {
- $sql="INSERT INTO $table($fields) VALUES($values)";
- }
- else
- {
- unset($row); unset($result);
- $fields_array = explode(',',$fields);
+ if ($row[0] == 0) {
+ // nothing in the table yet
+ $sql = "INSERT INTO $table($fields) VALUES($values)";
+ } else {
+ unset($row);
+ unset($result);
+ $fields_array = explode(',',$fields);
$values_array = DBINT_parseCsvSqlString($values);
$values = str_replace('0000-00-00 00:00:00','NOW()',$values);
- $row = array();
- $sql = 'SELECT pg_attribute.attname FROM pg_index, pg_class, pg_attribute
- WHERE pg_class.oid = \''.$table.'\'::regclass AND
+ $row = array();
+ $sql = 'SELECT pg_attribute.attname FROM pg_index, pg_class, pg_attribute
+ WHERE pg_class.oid = \''.$table.'\'::regclass AND
indrelid = pg_class.oid AND
- pg_attribute.attrelid = pg_class.oid AND
+ pg_attribute.attrelid = pg_class.oid AND
pg_attribute.attnum = any(pg_index.indkey)
GROUP BY pg_attribute.attname, pg_attribute.attnum;';
-
+
$result = $this->dbQuery($sql);
- while($fetched = pg_fetch_row($result))
- {
- $row[] = $fetched;
+ while($fetched = pg_fetch_row($result)) {
+ $row[] = $fetched;
}
- $counter=count($row);
- if(!empty($row[0]))
- {
- $key = array_search($row[0][0],$fields_array);
- if($key!==FALSE)
- {
- $sql = "DELETE FROM $table WHERE ";
- $uniqno = count($row);
- for($i=0;$i<$uniqno;$i++)
- {
- $key = array_search($row[$i][0],$fields_array);
- if($key!==FALSE) //$fields contains the primary key already
- {
- $validKey=false;
- if(isset($values_array[$key][0]) && $values_array[$key]!='UNIX_TIMESTAMP()'
- && $values_array[$key]!='0000-00-00 00:00:00')
- {
- if($values_array[$key][0]=="'")
- {
- if(substr($sql,-5)!= ' AND ' && substr($sql,-6)!='WHERE ')
- $sql.=' AND ';
- $sql.="{$row[$i][0]}={$values_array[$key]}";
- }
- else
- {
- if(substr($sql,-5)!= ' AND ' && substr($sql,-6)!='WHERE ')
- $sql.=' AND ';
- $sql.="{$row[$i][0]}='{$values_array[$key]}'";
- }
More information about the geeklog-cvs
mailing list