MyDialect.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-2007 by Konstantin V. Arkhipov                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: MyDialect.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00021     class MyDialect extends Dialect
00022     {
00023         const IN_BOOLEAN_MODE = 1;
00024         
00028         public static function me()
00029         {
00030             return Singleton::getInstance(__CLASS__);
00031         }
00032         
00033         public static function quoteValue($value)
00034         {
00036             
00037             if ($value instanceof Identifier && !$value->isFinalized())
00038                 return "''"; // instead of 'null', to be compatible with v. 4
00039             
00040             if (Assert::checkInteger($value))
00041                 return $value;
00042             
00043             return "'" . mysql_real_escape_string($value) . "'";
00044         }
00045         
00046         public static function quoteField($field)
00047         {
00048             if (strpos($field, '.') !== false)
00049                 throw new WrongArgumentException();
00050             elseif (strpos($field, '::') !== false)
00051                 throw new WrongArgumentException();
00052 
00053             return "`{$field}`";
00054         }
00055         
00056         public static function quoteTable($table)
00057         {
00058             return "`{$table}`";
00059         }
00060         
00061         public static function dropTableMode($cascade = false)
00062         {
00063             return null;
00064         }
00065         
00066         public static function timeZone($exist = false)
00067         {
00068             return null;
00069         }
00070         
00071         public function hasTruncate()
00072         {
00073             return true;
00074         }
00075         
00076         public function hasMultipleTruncate()
00077         {
00078             return false;
00079         }
00080         
00081         public function preAutoincrement(DBColumn $column)
00082         {
00083             $column->setDefault(null);
00084             
00085             return null;
00086         }
00087         
00088         public function postAutoincrement(DBColumn $column)
00089         {
00090             return 'AUTO_INCREMENT';
00091         }
00092         
00093         public function fullTextSearch($fields, $words, $logic)
00094         {
00095             return
00096                 ' MATCH ('
00097                     .implode(
00098                         ', ',
00099                         array_map(
00100                             array($this, 'fieldToString'),
00101                             $fields
00102                         )
00103                     )
00104                     .') AGAINST ('
00105                     .self::prepareFullText($words, $logic)
00106                 .')';
00107         }
00108         
00109         private static function prepareFullText($words, $logic)
00110         {
00111             Assert::isArray($words);
00112             
00113             $retval = self::quoteValue(implode(' ', $words));
00114             
00115             if (self::IN_BOOLEAN_MODE === $logic) {
00116                 return addcslashes($retval, '+-<>()~*"').' '.'IN BOOLEAN MODE';
00117             } else {
00118                 return $retval;
00119             }
00120         }
00121     }
00122 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4