[pLog-svn] r4605 - in plog/branches/lifetype-1.2/class: dao database database/pdb/drivers

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sun Jan 28 06:39:17 EST 2007


Author: oscar
Date: 2007-01-28 06:39:17 -0500 (Sun, 28 Jan 2007)
New Revision: 4605

Modified:
   plog/branches/lifetype-1.2/class/dao/articles.class.php
   plog/branches/lifetype-1.2/class/dao/model.class.php
   plog/branches/lifetype-1.2/class/database/db.class.php
   plog/branches/lifetype-1.2/class/database/pdb/drivers/pdbdriverbase.class.php
Log:
removed all the getXXXQuery() and related methods that should have been removed long ago.


Modified: plog/branches/lifetype-1.2/class/dao/articles.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/articles.class.php	2007-01-27 23:22:27 UTC (rev 4604)
+++ plog/branches/lifetype-1.2/class/dao/articles.class.php	2007-01-28 11:39:17 UTC (rev 4605)
@@ -656,12 +656,10 @@
 				
 			$articleCategories = new ArticleCategories();
             foreach( $categories as $categoryId ) {
-                $keyValuePairs = array();
-                $keyValuePairs['article_id']  = $articleId;
-                $keyValuePairs['category_id'] = $categoryId;
+	
+				$query = "INSERT INTO ".$this->getPrefix()."article_categories_link (article_id, category_id) VALUES (".
+				         "'".Db::qstr( $articleId )."', '".Db::qstr( $categoryId )."')";
 
-                $query = Db::buildInsertQuery( ARTICLE_CATEGORIES_RELATIONSHIP_TABLENAME,
-                                               $keyValuePairs );
                 $this->Execute( $query );
 
                	$category = $articleCategories->getCategory( $categoryId );                
@@ -687,9 +685,7 @@
             require_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
 
 			$articleId = $article->getId();
-            $query = Db::buildDeleteQuery( ARTICLE_CATEGORIES_RELATIONSHIP_TABLENAME,
-                                           'article_id',
-                                           $articleId );
+			$query = "DELETE FROM ".$this->getPrefix()."article_categories_link WHERE article_id = '".Db::qstr( $article->getId())."'";
 
             if( ( $result = $this->Execute( $query ))) {
             	// updated the category counters
@@ -835,21 +831,16 @@
 		function addArticleText( $newArticle )
 		{
             require_once( PLOG_CLASS_PATH . 'class/data/textfilter.class.php' );
-            require_once( PLOG_CLASS_PATH . 'class/database/db.class.php' );
 
 			$filter = new Textfilter();
+			$query = "INSERT INTO ".$this->getPrefix()."articles_text (article_id, topic, text, normalized_text, normalized_topic, mangled_topic) ".
+			         " VALUES ('".Db::qstr($newArticle->getId())."',".
+			         "'".Db::qstr($newArticle->getTopic())."',".
+			         "'".Db::qstr($newArticle->getText(false))."',".
+			         "'".Db::qstr($filter->normalizeText( $newArticle->getText(false)))."',".
+			         "'".Db::qstr($filter->normalizeText( $newArticle->getTopic()))."',".
+			         "'')";
 
-            $valuesToInsert = array();
-            $valuesToInsert['article_id']       = $newArticle->getId();
-            $valuesToInsert['topic']            = $newArticle->getTopic();
-            $valuesToInsert['text']             = $newArticle->getText(false);
-            $valuesToInsert['normalized_text']  = $filter->normalizeText( $newArticle->getText(false) );
-            $valuesToInsert['normalized_topic'] = $filter->normalizeText( $newArticle->getTopic() );
-            $valuesToInsert['mangled_topic']    = '';
-
-            $query = Db::buildInsertQuery( ARTICLETEXTS_TABLENAME,
-                                           $valuesToInsert );
-
 			return( $this->Execute( $query ));
 		}
 		
@@ -864,19 +855,11 @@
             $text = $this->_cache->getData( $articleId, CACHE_ARTICLETEXT );
 
             if( !$text ) {
-                $query = Db::buildSelectQuery( ARTICLETEXTS_TABLENAME,
-                                               array(),
-                                               'article_id',
-                                               $articleId );
-
-                $result = $this->Execute( $query );
-                
-                if( !$result ) 
-                    return false;
-                    
+				$query = "SELECT text, normalized_text, topic, normalized_topic FROM ".$this->getPrefix()."articles_text ".
+				         "WHERE article_id = '".Db::qstr( $articleId )."'";
+                $result = $this->Execute( $query );    
                 $text = $result->FetchRow();
                 $result->Close();
-
                 $this->_cache->setData( $articleId, CACHE_ARTICLETEXT, $text );
             }
 
@@ -893,18 +876,13 @@
 		{
 			$filter = new Textfilter();
 
-            $keyValuePairs = array();
+			$query = "UPDATE ".$this->getPrefix()."articles_text SET ".
+			         "topic = '".Db::qstr($article->getTopic())."', ".
+			         "text = '".Db::qstr($article->getText(false))."', ".
+			         "normalized_text = '".$filter->normalizeText( $article->getText(false))."', ".
+			         "normalized_topic = '".$filter->normalizeText( $article->getTopic())."' ".
+			         "WHERE article_id = '".Db::qstr( $article->getId())."'";
 
-            $keyValuePairs['topic']            = $article->getTopic();
-            $keyValuePairs['text']             = $article->getText(false);
-            $keyValuePairs['normalized_text']  = $filter->normalizeText( $article->getText(false) );
-            $keyValuePairs['normalized_topic'] = $filter->normalizeText( $article->getTopic() );
-
-            $query = Db::buildUpdateQuery( ARTICLETEXTS_TABLENAME,
-                                           $keyValuePairs,
-                                           'article_id',
-                                           $article->getId() );
-
             $this->_cache->removeData( $article->getId(), CACHE_ARTICLETEXT );
 
 			return($this->Execute( $query ));
@@ -1035,18 +1013,11 @@
 
             $article  = $this->getArticle( $articleId );
             $numReads = $article->getNumReads() + 1;
-
             $article->setNumReads( $numReads );
 
-            $keyValuePairs = array();
-            $keyValuePairs['num_reads'] = $numReads;
-            $keyValuePairs['date']      = '@date';
+			$query = "UPDATE ".$this->getPrefix()."articles SET num_reads = {$numReads} ".
+			         "WHERE article_id = ".Db::qstr( $articleId )."'";
 
-            $query = Db::buildUpdateQuery( ARTICLES_TABLENAME,
-                                           $keyValuePairs,
-                                           'id',
-                                           $articleId );
-
             $result = $this->Execute( $query );
 
             if( $result )
@@ -1147,11 +1118,8 @@
 		 */
 		function deleteArticleText( $articleId )
 		{
-            $query = Db::buildDeleteQuery( ARTICLETEXTS_TABLENAME,
-                                           'article_id',
-                                           $articleId );
-			
-			return( $this->Execute($query) );
+			$query = "DELETE FROM ".$this->getPrefix()."articles_text WHERE article_id = ".Db::qstr( $articleId )."'";
+			return( $this->Execute( $query ));
 		}
 
         /**

Modified: plog/branches/lifetype-1.2/class/dao/model.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/model.class.php	2007-01-27 23:22:27 UTC (rev 4604)
+++ plog/branches/lifetype-1.2/class/dao/model.class.php	2007-01-28 11:39:17 UTC (rev 4605)
@@ -209,41 +209,7 @@
 	        return( $dbObject );
         	
         }
-        
-        /**
-         * given several conditions, concatenates them with an "AND" operator. If one of the
-         * items of the array is an empty string, the condition will not be used
-         *
-         * @deprecated use Db Class build(Select|Insert|...)Query instead
-         * @param conds
-         * @return a string
-         */
-        function buildWhereCondition( $conds = Array(), $useWhere = true )
-        {
-            $valid = 0;
-            $where = "";
-            
-            foreach( $conds as $cond ) {
-                if( $cond ) {
-                    // only if the condition is not empty...
-                    
-                    if( $valid > 0 )
-                        $where .= " AND ";
-                    
-                    // append the condition
-                    $where .= "$cond";
-                    
-                    // we've got a valid condition
-                    $valid++;
-                }
-            }
-            
-            if( $valid > 0 && $useWhere )
-                $where = "WHERE $where";
                 
-            return( $where );
-        }        
-        
 		/**
 		 * Retrieves all the rows from the given table
 		 *

Modified: plog/branches/lifetype-1.2/class/database/db.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/database/db.class.php	2007-01-27 23:22:27 UTC (rev 4604)
+++ plog/branches/lifetype-1.2/class/database/db.class.php	2007-01-28 11:39:17 UTC (rev 4605)
@@ -146,244 +146,7 @@
             }
 		}
 
-
 		/**
-		 * Builds a SELECT query
-		 *
-		 * @param tableName The table from where we want to build the SELECT query
-		 * @param fieldsToFetch An array with the list of fields we'd like to fetch
-		 * @param whereColumn Column used in the WHERE clause
-		 * @param whereValue Value used in the WHERE clause
-		 * @param orderColumn Column used to sort the data
-		 * @param limit Number of records to return
-		 * @param whereGlue Logical operator used to glue the different WHERE conditions, 'AND'
-		 * by default.
-		 * @return Returns the SELECT query defined by the provided parameters
-		 */
-        function buildSelectQuery( $tableName, 
-                                   $fieldsToFetch = array(),
-                                   $whereColumn   = null, 
-                                   $whereValue    = null,
-                                   $orderColumn   = null,
-                                   $limit         = null,
-                                   $whereGlue     = ' AND ')
-        {
-            $db = Db::getDb();
-
-            $tableName = Db::addTablePrefixToTableName( $tableName );
-
-            $query = $db->buildSelectQuery( $tableName,
-                                            $fieldsToFetch,
-                                            $whereColumn,
-                                            $whereValue,
-                                            $orderColumn,
-                                            $limit,
-                                            $whereGlue );
-
-            return $query;
-        }
-
-		/**
-		 * Builds an INSERT query
-		 *
-		 * @param tableName Name of the table where data is to be inserted
-		 * @param keyValuePairs An associative array where the key is the name of the column and the
-		 * value is the value of the column in the query
-		 * @return Returns the INSERT query
-		 */
-        function buildInsertQuery( $tableName,
-                                   $keyValuePairs )
-        {
-            $tableName = Db::addTablePrefixToTableName( $tableName );
-
-            $query  = 'INSERT INTO ' . $tableName;
-
-            foreach( $keyValuePairs as $key => $value ) {
-                $keys[]   = $key;
-                $values[] = Db::quoteValue( $value );
-            }
-            $query .= ' (' . implode( ",", $keys ) . ')';
-            $query .= ' VALUES (';
-            $query .= implode( ",", $values );
-            $query .= ');';
-
-            return $query;
-        }
-
-		/**
-		 * Builds an UPDATE query
-		 *
-		 * @param tableName Name of the table where data is to be inserted
-		 * @param keyValuePairs An associative array where the key is the name of the column and the
-		 * value is the value of the column in the query		
-		 * @param whereColumn Column used in the WHERE clause
-		 * @param whereValue Value used in the WHERE clause		
-		 * @return Returns the UPDATE query
-		 */
-        function buildUpdateQuery( $tableName,
-                                   $keyValuePairs,
-                                   $whereColumn   = null, 
-                                   $whereValue    = null,
-                                   $whereGlue     = ' AND ')
-        {
-            $tableName = Db::addTablePrefixToTableName( $tableName );
-
-            $query  = 'UPDATE ' . $tableName . ' SET ';
-
-            $valuesToSet = array();
-            foreach( $keyValuePairs as $key => $value ) {
-                $queryPart  = $key . ' = ';
-                $queryPart .= Db::quoteValue( $value );
-                $valuesToSet[] = $queryPart;
-            }
-            $query .= implode( ",", $valuesToSet );
-            
-            if( $whereColumn != null )
-                $query .= Db::buildWhereConditions( $whereColumn, $whereValue, $whereGlue );
-
-            return $query;
-        }
-
-		/**
-		 * Builds a DELETE query
-		 * 
-		 * @param tableName Name of the table where data is to be inserted		
-		 * @param whereColumn Column used in the WHERE clause
-		 * @param whereValue Value used in the WHERE clause		
-		 * @param whereGlue Logical operator used to glue the different WHERE conditions, 'AND'
-		 * by default.
-		 */
-        function buildDeleteQuery( $tableName,
-                                   $whereColumn = null,
-                                   $whereValue  = null,
-                                   $whereGlue   = ' AND ')
-        {
-            $tableName = Db::addTablePrefixToTableName( $tableName );
-
-            $query  = 'DELETE FROM ' . $tableName;
-
-            if( $whereColumn != null )
-                $query .= Db::buildWhereConditions( $whereColumn, $whereValue, $whereGlue );
-
-            return $query;
-        }
-
-		/**
-		 * @private
-		 * Adds the current database prefix to the given table name. If the table name does not have
-		 * the prefix yet, it will be added in front of the table name but if it's already there, the table
-		 * name will not be modified
-		 *
-		 * @param tableName Name of the table, without prefix. 
-		 * @return The table name with the prefix
-		 */
-        function addTablePrefixToTableName( $tableName ) {
-            if ( !preg_match( "/^" . Db::getPrefix() . "/", $tableName) ) {
-                $tableName = Db::getPrefix() . $tableName;
-            }
-            return $tableName;
-        }
-
-		/**
-		 * Builds a WHERE clause for SELECT and DELETE queries
-		 *
-		 * @param whereColumn The column, it can either be a single column or an array of columns. If it
-		 * is an array of columns, it should be an associative array where the key is the name of the column
-		 * and the value is the value assigned to this column.
-		 * @param whereValue The value assigned to the column, in case $whereColumn is only one column
-		 * @param whereGlue The glue used to link the different conditions
-		 * @return A string that can be used as a WHERE clause in a query
-		 */
-        function buildWhereConditions( $whereColumn, $whereValue, $whereGlue )
-        {
-            $queryPart = ' WHERE ';
-            if( is_array($whereColumn) ) {
-                $conditions = array();
-                foreach( $whereColumn as $column => $value ) {
-                    if($column && $value){
-                        $conditions[] = Db::buildWhereCondition( $column, $value );
-                    }
-                }
-                $imploded = implode( $whereGlue , $conditions );
-                if(!$imploded)
-                    return null;
-                $queryPart .= $imploded;
-            } elseif( !empty($whereColumn) ) {
-                $queryPart .= Db::buildWhereCondition( $whereColumn, $whereValue );
-            }
-
-            return $queryPart;
-        }
-
-		/**
-		 * Builds one single condition for a WHERE clause
-		 *
-		 * @param columnName the column name
-		 * @param columnValue the value for the column
-		 * @return A string as part of a WHERE clause
-		 */
-        function buildWhereCondition( $columnName, $columnValue )
-        {
-            $db =& Db::getDb();
-            return $db->buildWhereCondition( $columnName, $columnValue );
-        }
-
-		/**
-		 * @private
-		 */
-        function _buildOrderCondition( $orderColumn )
-        {
-            preg_match( '/^(.)(.*)$/', $orderColumn, $matches );
-
-            $queryPart = ' ORDER BY '; 
-            $firstValueCharacter = $matches[1]; 
-            switch( $firstValueCharacter ) {
-                case '-':
-                    $orderColumn = $matches[2];
-                    $direction = ' DESC';
-                case '+':
-                    $orderColumn = $matches[2];
-                default:
-                    $direction  = '';
-                    $queryPart .= $orderColumn . $direction;
-            }
-            return $queryPart;
-        }
-
-        /**
-         * Quote a value for a SQL query. Depending on the type of the
-         * value, this method will return the correct string to store
-         * the value in the database.
-         *
-         * - if the value is numeric, it will return the numeric value
-         * - if the value is a Timestamp(), it will return an isoDate
-         * - if the value is a string, it will return a quoted string
-         * - if the value starts with an '@', it will return the
-         *   unquoted value. this is used e.g. for adding something
-         *   like "date = date" in Articles()->deleteArticle().
-         *
-         * @param value a value to be stored in the database
-         * @return string the correctly quoted value
-         * @access public
-         */
-        function quoteValue( $value )
-        {
-            if( is_numeric($value) )
-                return $value;
-            if( preg_match('/^@(.*)/', $value, $matches) )
-                return $matches[1];
-            elseif( is_object($value) ) {
-                switch (get_class($value)) {
-                    case 'timestamp':
-                        return Db::quoteValue($value->getIsoDate());
-                        break;
-                }
-            }
-            else
-                return '\'' . Db::qstr( $value ) . '\'';
-        }
-
-		/**
 		 * Prepares a string for an SQL query by escaping apostrophe
 		 * characters. If the PHP configuration setting 'magic_quotes_gpc'
 		 * is set to ON, it will first strip the added slashes. Apostrophe

Modified: plog/branches/lifetype-1.2/class/database/pdb/drivers/pdbdriverbase.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/database/pdb/drivers/pdbdriverbase.class.php	2007-01-27 23:22:27 UTC (rev 4604)
+++ plog/branches/lifetype-1.2/class/database/pdb/drivers/pdbdriverbase.class.php	2007-01-28 11:39:17 UTC (rev 4605)
@@ -187,86 +187,6 @@
 		{
 		    $this->_debug = $debug;
 		}
-
-        /**
-         * Start of DB dependent code, be sure to override these methods in
-         * your driver class, if the generic version are not good enough for
-         * your driver.
-         */ 
-        function buildSelectQuery( $tableName,
-                                   $fieldsToFetch,
-                                   $whereColumn,
-                                   $whereValue,
-                                   $orderColumn,
-                                   $limit,
-                                   $whereGlue )
-        {
-            $query = 'SELECT ';
-            if( $fieldsToFetch == array() ) {
-                $query .= '*';
-            } else {
-                $query .= implode(",", $fieldsToFetch);
-            }
-            $query .= ' FROM ' . $tableName;
-
-            if( $orderColumn != null ) {
-                $query .= Db::_buildOrderCondition( $orderColumn );
-            }
-
-            if( $whereColumn != null ) {
-                $query .= Db::buildWhereConditions( $whereColumn, $whereValue, $whereGlue );
-            }
-
-            if( $limit != null ) {
-                $query .= ' LIMIT ' . $limit;
-            }
-
-            // not needed!
-            //$query .= ';';
-
-            return $query;
-        }
-
-
-         
-        /**
-         * Generic method to build where conditions. Column values might start
-         * with a keyword, each db driver may overwrite this method to implement
-         * db specific where conditions.
-         * 
-         * Please allow the following keywords:
-         * ~ - Column Value is a search string, add wildcards at the start
-         *     and the end of the searchstring. Use 'LIKE' or equivalent.
-         * > - Implement a 'greater then' search.
-         * < - Implement a 'less then' search.
-         * = - Equal, 
-         */
-        function buildWhereCondition( $columnName, $columnValue )
-        {
-            preg_match( '/^(.)(.*)$/', $columnValue, $matches );
-            $firstValueCharacter = $matches[1];
-            switch( $firstValueCharacter ) {
-                case '~':
-                    $operator = 'LIKE';
-                    $columnValue = '%' . $matches[2] . '%';
-                case '>':
-                    $operator = '>';
-                    $columnValue = $matches[2];
-                    break;
-                case '<':
-                    $operator = '<';
-                    $columnValue = $matches[2];
-                    break;
-                case '=':
-                    $columnValue = $matches[2];
-                    // no break, we want to continue to the default
-                default:
-                    $operator = '=';
-                }
-            $queryPart  = $columnName . ' ' . $operator . ' ';
-            $queryPart .= Db::quoteValue( $columnValue );
-            return $queryPart;
-        }
         
         /**
          * for compatibility with ADOdb. Use Db::qstr() instead



More information about the pLog-svn mailing list