[pLog-svn] r4676 - plog/branches/lifetype-1.2/class/database/pdb/drivers

oscar at devel.lifetype.net oscar at devel.lifetype.net
Fri Feb 2 17:54:59 EST 2007


Author: oscar
Date: 2007-02-02 17:54:59 -0500 (Fri, 02 Feb 2007)
New Revision: 4676

Modified:
   plog/branches/lifetype-1.2/class/database/pdb/drivers/pdbdriverbase.class.php
   plog/branches/lifetype-1.2/class/database/pdb/drivers/pdbmysqldriver.class.php
Log:
Added driver-specific support for FULLTEXT indexes, so now the driver can tell the user classes whether fulltext queries are supported or not. Fulltext is disabled by default in the base driver class but the MySQL driver will first check the database character encoding to determine whether FULLTEXT is supported or not. The method PDbMySQLDriver::isFullTextSupported() holds an array with "blacklisted" character sets that don't support FULLTEXT but it currently is set to empty (meaning that FULLTEXT is supported accross all mysql character sets so I'm hoping that Mark or somebody more familiar with this will help me fill in the array.


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-02-02 15:30:18 UTC (rev 4675)
+++ plog/branches/lifetype-1.2/class/database/pdb/drivers/pdbdriverbase.class.php	2007-02-02 22:54:59 UTC (rev 4676)
@@ -393,5 +393,24 @@
 			global $__pdb_num_queries;
 			return( $__pdb_num_queries );
 		}
+		
+		/**
+		 * @return Returns the name of current character set, or 'default' if none has been explicitely selected
+		 */
+		function getDbCharacterSet()
+		{
+			return( 'default' );
+		}
+		
+		/**
+		 * Returns true if the current database supports FULLTEXT searches. This method needs to be
+		 * implemented by child classes.
+		 *
+		 * @return true if FULLTEXT is supported
+		 */
+		function isFullTextSupported()
+		{
+			return( false );
+		}
 	}
 ?>

Modified: plog/branches/lifetype-1.2/class/database/pdb/drivers/pdbmysqldriver.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/database/pdb/drivers/pdbmysqldriver.class.php	2007-02-02 15:30:18 UTC (rev 4675)
+++ plog/branches/lifetype-1.2/class/database/pdb/drivers/pdbmysqldriver.class.php	2007-02-02 22:54:59 UTC (rev 4676)
@@ -12,6 +12,7 @@
 		
 		var $_res;
 		var $_dbname;
+		var $_charset;
 	
 	    /**
 	     * Constructor of the driver. Doesn't do much.
@@ -22,6 +23,9 @@
 			
 			// the driver name
 			$this->_type = 'mysql';	
+			
+			// character set, 'default' until one is explicitely set
+			$this->_charset = 'default';
 		}
 		
 		/**
@@ -76,8 +80,10 @@
 				return false;
 				
 			// set the right character encoding for mysql 4.1+ client, connection and collation
-			if( !empty( $dbcharset ) && $dbcharset != "default" )
+			if( !empty( $dbcharset ) && $dbcharset != "default" ) {
 	           	mysql_query( "SET NAMES ".$dbcharset, $this->_res );
+				$this->_charset = $dbcharset;
+			}
 				
 			// continue otherwise and try to select our db
 			if( $dbname )
@@ -99,8 +105,10 @@
 				return false;				
 				
 			// set the right character encoding for mysql 4.1+ client, connection and collation
-			if( !empty( $dbcharset ) && $dbcharset != "default" )
+			if( !empty( $dbcharset ) && $dbcharset != "default" ) {
 	           	mysql_query( "SET NAMES ".$dbcharset, $this->_res );
+				$this->_charset = $dbcharset;	
+			}
 
 			// continue otherwise and try to select our db
 			if( $dbname )
@@ -148,5 +156,29 @@
         {
             return( PDbDriverBase::getDriverDataDictionary( 'mysql' ));
         }
+
+		/**
+		 * Returns true if the current database supports FULLTEXT searches. This method needs to be
+		 * implemented by child classes.
+		 *
+		 * @return true if FULLTEXT is supported, which is the case for most character encodings
+		 */
+		function isFullTextSupported()
+		{			
+			// array with all those MySQL character sets that don't support FULLTEXT searches
+			$unsupportedCharacterSets = Array();
+			
+			return( !in_array( $this->getDbCharacterSet(), $unsupportedCharacterSets ));
+		}
+		
+		/**
+		 * Return the name of the character set currently being used
+		 *
+		 * @see PDbDriverBase::getDbCharacterSet()
+		 */
+		function getDbCharacterSet()
+		{
+			return( $this->_charset );
+		}
 	}
 ?>
\ No newline at end of file



More information about the pLog-svn mailing list