commit 5c540e0504b72025ff73e72667fbf4d6d13a686b
parent 83a61566ea1fe3ee620c8db9609b078807f47f02
Author: dankert <dankert@braunbaer-laptop>
Date: Tue, 19 Jan 2010 00:08:25 +0100
Zweig zusammengefuehrt.
Diffstat:
7 files changed, 138 insertions(+), 51 deletions(-)
diff --git a/actionClasses/ElementAction.class.php b/actionClasses/ElementAction.class.php
@@ -57,7 +57,7 @@ class ElementAction extends Action
$this->element->save();
$this->element->load();
- $this->addNotice('element',$this->template->name,'SAVED',OR_NOTICE_OK);
+ $this->addNotice('element',$this->element->name,'SAVED',OR_NOTICE_OK);
}
@@ -112,7 +112,7 @@ class ElementAction extends Action
{
// Neuen Typ setzen und speichern
$this->element->setType( $this->getRequestVar('type') );
- $this->addNotice('element',$this->template->name,'SAVED',OR_NOTICE_OK);
+ $this->addNotice('element',$this->element->name,'SAVED',OR_NOTICE_OK);
}
}
diff --git a/db/mysqli.class.php b/db/mysqli.class.php
@@ -112,6 +112,10 @@ class DB_mysqli
{
if ( $this->prepared )
{
+ $ar = array();
+ $ar[-1] = $this->stmt;
+ $ar[0] = '';
+
foreach($this->params as $name => $data)
{
switch( $data['type'] )
@@ -123,15 +127,14 @@ class DB_mysqli
$ar[0] .= 's';
break;
default:
- continue;
+ die('mysqli: unknown data type: '.$data['type']);
}
$ar[] = &$data['value'];
}
- call_user_func_array('bind_param',array($this->stmt,$ar));
+ call_user_func_array('mysqli_stmt_bind_param',$ar);
$this->stmt->execute();
- $this->stmt->bind_result( $a, $b );
return $this->stmt;
}
@@ -149,7 +152,39 @@ class DB_mysqli
function fetchRow( $result, $rownum )
{
- return mysqli_fetch_array( $result,MYSQL_ASSOC );
+ if ( $this->prepared )
+ {
+ $result = $this->stmt->result_metadata();
+ $fields = array();
+ while ($field = mysqli_fetch_field($result)) {
+ $name = $field->name;
+ $fields[$name] = &$$name;
+ }
+ array_unshift($fields, $this->stmt);
+ call_user_func_array('mysqli_stmt_bind_result', $fields);
+
+ array_shift($fields);
+ if ( mysqli_stmt_fetch($this->stmt) )
+ {
+ $temp = array();
+ foreach($fields as $key => $val)
+ $temp[$key] = $val;
+ //array_push($results, $temp);
+ return $temp;
+ }
+ else
+ {
+ mysqli_stmt_close($this->stmt);
+ $this->stmt = null;
+ return false;
+ }
+ }
+ else
+ {
+ // Plain old flat query
+ $row = $result->fetch_assoc();
+ return $row;
+ }
}
@@ -164,15 +199,25 @@ class DB_mysqli
function prepare( $query,$param)
{
+ if ( is_object($this->stmt) )
+ {
+ mysqli_stmt_close($this->stmt);
+ $this->stmt = null;
+ }
+
+ $offset = 0;
foreach( $param as $pos)
{
- foreach( $pos as $pos )
+ foreach( $pos as $posn )
{
- $query = substr($query,0,$pos-1).'?'.substr($query,$pos+1);
+ $posn += $offset++;
+ $query = substr($query,0,$posn).'?'.substr($query,$posn);
}
}
$this->stmt = mysqli_prepare($this->connection,$query);
+ if ( $this->stmt === FALSE )
+ die( 'Mysql-I is unable to prepare the statement: '.$query.' : '.mysqli_error($this->connection) );
$this->prepared = true;
}
diff --git a/db/pdo.class.php b/db/pdo.class.php
@@ -42,7 +42,7 @@ class DB_pdo
*/
var $error;
- var $lowercase = false;
+ var $prepared = false;
function connect( $conf )
@@ -51,9 +51,6 @@ class DB_pdo
$user = $conf['user' ];
$pw = $conf['password'];
- if ( $conf['convert_to_lowercase'] )
- $this->lowercase = true;
-
$options = array();
foreach( $conf as $c )
if ( substr($c,0,7) == 'option_' )
@@ -82,25 +79,41 @@ class DB_pdo
function query($query)
{
- $result = $this->connection->query($query);
-
- if ( ! $result )
+ if ( $this->prepared )
{
- $this->error = 'Database error: '.PDO::errorInfo();
- return FALSE;
+ $ar = array();
+
+ foreach( $query->data as $val )
+ $ar[] = $val['value'];
+ $erg = $this->stmt->execute( $ar );
+
+ if ( $erg === false )
+ {
+ die( 'Could not execute prepared statement "'.$query->query.'" with values "'.implode(',',$ar).'": '.implode('/',$this->connection->errorInfo()) );
+ }
+
+ return $this->stmt;
+ }
+ else
+ {
+ $this->result = $this->connection->query($query);
+
+ if ( ! $this->result )
+ {
+ $this->error = 'Database error: '.implode('/',$this->connection->errorInfo());
+ return FALSE;
+ }
+ return $this->result;
}
- return $result;
}
function fetchRow( $result, $rownum )
{
- $row = $result->fetch( PDO::FETCH_ASSOC );
-
- if ( is_array($row) && $this->lowercase )
- $row = array_change_key_case($row);
-
- return $row;
+ if ( $this->prepared )
+ return $this->stmt->fetch( PDO::FETCH_ASSOC );
+ else
+ return $this->result->fetch( PDO::FETCH_ASSOC );
}
@@ -112,16 +125,22 @@ class DB_pdo
function prepare( $query,$param)
{
+ $offset = 0;
foreach( $param as $pos)
{
foreach( $pos as $posx )
{
- $query = substr($query,0,$posx-1).'?'.substr($query,$posx+1);
+ $posx += $offset++;
+ $query = substr($query,0,$posx).'?'.substr($query,$posx);
}
}
+ $this->prepared = true;
$this->stmt = $this->connection->prepare($query);
+ if ( $this->stmt === false )
+ die( 'Database error: '.implode('/',$this->connection->errorInfo()) );
+
}
@@ -161,6 +180,17 @@ class DB_pdo
}
+
+ /**
+ * Setzt die letzte Abfrage zurueck.
+ */
+ function clear()
+ {
+ $this->prepared = false;
+ $this->params = array();
+ }
+
+
/**
* Why this? See http://e-mats.org/2008/07/fatal-error-exception-thrown-without-a-stack-frame-in-unknown-on-line-0/
*
diff --git a/db/postgresql.class.php b/db/postgresql.class.php
@@ -42,7 +42,7 @@ class DB_postgresql
* Verbinden zum POSTGRES-Server.
*
* @param Array $conf
- * @return boolean
+ * @return boolean 'true', wenn Verbindung aufgebaut wurde
*/
function connect( $conf )
{
@@ -70,7 +70,7 @@ class DB_postgresql
if ( ! is_resource($this->connection) )
{
- $this->error = 'could not connect to database on host '.$host;
+ $this->error = 'Could not connect to postgresql-server '.$host.': '.@pg_errormessage();
return false;
}
@@ -80,7 +80,7 @@ class DB_postgresql
/**
- * Verbindung schlie�en.
+ * Verbindung schliessen.
*
* @return unknown
*/
@@ -125,6 +125,7 @@ class DB_postgresql
{
if ( $this->prepared )
{
+ // Prepared Statement
$ar = array();
foreach($this->params as $name => $data)
{
@@ -149,25 +150,26 @@ class DB_postgresql
if ( $result === false )
{
if ( empty($this->error) )
- $this->error = 'PostgreSQL (prepared) says: '.@pg_errormessage();
+ $this->error = 'PostgreSQL is unable to execute the prepared statement: '.@pg_errormessage();
return FALSE;
}
return $result;
}
-
-
-
- $result = @pg_exec( $this->connection,$query );
-
- if ( ! $result )
- {
- if ( empty($this->error) )
- $this->error = 'PostgreSQL (not prepared) says: '.@pg_errormessage();
- return FALSE;
+ else
+ {
+ // Flat Query:
+ $result = @pg_exec( $this->connection,$query );
+
+ if ( ! $result )
+ {
+ if ( empty($this->error) )
+ $this->error = 'PostgreSQL is unable to execute the flat query: '.@pg_errormessage();
+ return FALSE;
+ }
+
+ return $result;
}
-
- return $result;
}
@@ -208,7 +210,6 @@ class DB_postgresql
}
$nr++;
}
- //Html::debug($query);
$this->stmtid = md5($query);
$this->prepared = true;
@@ -217,7 +218,17 @@ class DB_postgresql
if (pg_num_rows($result) > 0)
return;
- pg_prepare($this->connection,$this->stmtid,$query);
+ $erg = @pg_prepare($this->connection,$this->stmtid,$query);
+
+ if ( $erg === FALSE )
+ {
+ $this->error = 'PostgreSQL is unable to prepare the statement: '.@pg_errormessage();
+ return FALSE;
+ }
+ else
+ {
+ return $erg;
+ }
}
diff --git a/objectClasses/Object.class.php b/objectClasses/Object.class.php
@@ -168,13 +168,16 @@ class Object
$language = Session::getProjectLanguage();
+ if ( is_object($language) )
$this->languageid = $language->languageid;
$model = Session::getProjectModel();
- $this->modelid = $model->modelid;
+ if ( is_object($model) )
+ $this->modelid = $model->modelid;
$project = Session::getProject();
- $this->projectid = $project->projectid;
+ if ( is_object($project) )
+ $this->projectid = $project->projectid;
}
@@ -475,8 +478,7 @@ SQL
' lastchangeuser.mail as lastchange_usermail, '.
' createuser.name as create_username, '.
' createuser.fullname as create_userfullname, '.
- ' createuser.mail as create_usermail, '.
- ' {t_name}.name,{t_name}.descr'.
+ ' createuser.mail as create_usermail '.
' FROM {t_object}'.
' LEFT JOIN {t_name} '.
' ON {t_object}.id={t_name}.objectid AND {t_name}.languageid={languageid} '.
diff --git a/serviceClasses/Sql.class.php b/serviceClasses/Sql.class.php
@@ -255,7 +255,7 @@ class Sql
*/
function setInt( $name,$value )
{
- $this->data[ $name ] = array( 'type'=>'int','value'=>$value );
+ $this->data[ $name ] = array( 'type'=>'int','value'=>(int)$value );
}
diff --git a/themes/default/include/html/inputarea.inc.php b/themes/default/include/html/inputarea.inc.php
@@ -1,5 +1,4 @@
-<?php if ($this->isEditable() && !$this->isEditMode()) $attr_readonly=true;
- if ( !$attr_readonly) {
-?><textarea <?php if ($attr_readonly) echo ' disabled="true"' ?> class="<?php echo $attr_class ?>" name="<?php echo $attr_name ?>" rows="<?php echo $attr_rows ?>" cols="<?php echo $attr_cols ?>"><?php echo htmlentities(isset($$attr_name)?$$attr_name:$attr_default) ?></textarea><?php
+<?php if ($this->isEditMode()) {
+?><textarea class="<?php echo $attr_class ?>" name="<?php echo $attr_name ?>" rows="<?php echo $attr_rows ?>" cols="<?php echo $attr_cols ?>"><?php echo htmlentities(isset($$attr_name)?$$attr_name:$attr_default) ?></textarea><?php
} else {
?><span class="<?php echo $attr_class ?>"><?php echo isset($$attr_name)?$$attr_name:$attr_default ?></span><?php } ?>
\ No newline at end of file