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 
00020     class MyDialect extends Dialect
00021     {
00022         const IN_BOOLEAN_MODE = 1;
00023         
00027         public static function me()
00028         {
00029             return Singleton::getInstance(__CLASS__);
00030         }
00031         
00032         public static function quoteValue($value)
00033         {
00035             
00036             if ($value instanceof Identifier && !$value->isFinalized())
00037                 return "''"; // instead of 'null', to be compatible with v. 4
00038             
00039             return "'" . mysql_real_escape_string($value) . "'";
00040         }
00041         
00042         public static function quoteField($field)
00043         {
00044             if (strpos($field, '.') !== false)
00045                 throw new WrongArgumentException();
00046             elseif (strpos($field, '::') !== false)
00047                 throw new WrongArgumentException();
00048             
00049             return "`{$field}`";
00050         }
00051         
00052         public static function quoteTable($table)
00053         {
00054             return "`{$table}`";
00055         }
00056         
00057         public static function dropTableMode($cascade = false)
00058         {
00059             return null;
00060         }
00061         
00062         public static function timeZone($exist = false)
00063         {
00064             return null;
00065         }
00066         
00067         public function quoteBinary($data)
00068         {
00069             return mysql_real_escape_string($data);
00070         }
00071         
00072         public function typeToString(DataType $type)
00073         {
00074             if ($type->getId() == DataType::BINARY)
00075                 return 'BLOB';
00076             
00077             return parent::typeToString($type);
00078         }
00079         
00080         public function hasTruncate()
00081         {
00082             return true;
00083         }
00084         
00085         public function hasMultipleTruncate()
00086         {
00087             return false;
00088         }
00089         
00090         public function hasReturning()
00091         {
00092             return false;
00093         }
00094         
00095         public function preAutoincrement(DBColumn $column)
00096         {
00097             $column->setDefault(null);
00098             
00099             return null;
00100         }
00101         
00102         public function postAutoincrement(DBColumn $column)
00103         {
00104             return 'AUTO_INCREMENT';
00105         }
00106         
00107         public function fullTextSearch($fields, $words, $logic)
00108         {
00109             return
00110                 ' MATCH ('
00111                     .implode(
00112                         ', ',
00113                         array_map(
00114                             array($this, 'fieldToString'),
00115                             $fields
00116                         )
00117                     )
00118                     .') AGAINST ('
00119                     .self::prepareFullText($words, $logic)
00120                 .')';
00121         }
00122         
00123         private static function prepareFullText($words, $logic)
00124         {
00125             Assert::isArray($words);
00126             
00127             $retval = self::quoteValue(implode(' ', $words));
00128             
00129             if (self::IN_BOOLEAN_MODE === $logic) {
00130                 return addcslashes($retval, '+-<>()~*"').' '.'IN BOOLEAN MODE';
00131             } else {
00132                 return $retval;
00133             }
00134         }
00135     }
00136 ?>