PostgresDialect.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: PostgresDialect.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00020     final class PostgresDialect extends Dialect
00021     {
00022         public static $tsConfiguration = 'utf8_russian';
00023         
00027         public static function me()
00028         {
00029             return Singleton::getInstance(__CLASS__);
00030         }
00031 
00032         public static function getTsConfiguration()
00033         {
00034             return self::$tsConfiguration;
00035         }
00036 
00037         public static function setTsConfiguration($configuration)
00038         {
00039             self::$tsConfiguration = $configuration;
00040         }
00041         
00042         public static function quoteValue($value)
00043         {
00044             if (Assert::checkInteger($value))
00045                 return $value;
00046             
00047             return "'".pg_escape_string($value)."'";
00048         }
00049 
00050         public static function toCasted($field, $type)
00051         {
00052             return "{$field}::{$type}";
00053         }
00054 
00055         public static function prepareFullText($words, $logic)
00056         {
00057             Assert::isArray($words);
00058             
00059             $glue = ($logic == DB::FULL_TEXT_AND) ? ' & ' : ' | ';
00060 
00061             return
00062                 strtolower(
00063                     implode(
00064                         $glue,
00065                         array_map(
00066                             array('PostgresDialect', 'quoteValue'),
00067                             $words
00068                         )
00069                     )
00070                 );
00071         }
00072         
00073         public function hasTruncate()
00074         {
00075             return true;
00076         }
00077         
00078         public function hasMultipleTruncate()
00079         {
00080             return true;
00081         }
00082         
00083         public function fullTextSearch($field, $words, $logic)
00084         {
00085             $searchString = self::prepareFullText($words, $logic);
00086             $field = $this->fieldToString($field);
00087 
00088             return
00089                 "({$field} @@ to_tsquery('".self::$tsConfiguration."', ".
00090                 self::quoteValue($searchString)."))";
00091         }
00092         
00093         public function fullTextRank($field, $words, $logic)
00094         {
00095             $searchString = self::prepareFullText($words, $logic);
00096             $field = $this->fieldToString($field);
00097             
00098             return
00099                 "rank({$field}, to_tsquery('".self::$tsConfiguration."', ".
00100                 self::quoteValue($searchString)."))";
00101         }
00102         
00103         public function preAutoincrement(DBColumn $column)
00104         {
00105             self::checkColumn($column);
00106             
00107             return
00108                 'CREATE SEQUENCE "'
00109                 .$this->makeSequenceName($column).'";';
00110         }
00111         
00112         public function postAutoincrement(DBColumn $column)
00113         {
00114             self::checkColumn($column);
00115             
00116             return
00117                 'default nextval(\''
00118                 .$this->makeSequenceName($column).'\')';
00119         }
00120         
00121         protected function makeSequenceName(DBColumn $column)
00122         {
00123             return $column->getTable()->getName().'_'.$column->getName();
00124         }
00125         
00126         private static function checkColumn(DBColumn $column)
00127         {
00128             Assert::isTrue(
00129                 ($column->getTable() !== null)
00130                 && ($column->getDefault() === null)
00131             );
00132         }
00133     }
00134 ?>

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