Dialect.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: Dialect.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00019     abstract class /* ANSI's */ Dialect
00020         extends Singleton
00021         implements Instantiatable
00022     {
00023         abstract public function preAutoincrement(DBColumn $column);
00024         abstract public function postAutoincrement(DBColumn $column);
00025         
00026         abstract public function hasTruncate();
00027         abstract public function hasMultipleTruncate();
00028         
00029         public static function quoteValue($value)
00030         {
00031             return
00032                 (
00033                     (
00034                         is_numeric($value)
00035                         // to avoid values like '108E102'
00036                         // (is_numeric()'ll return true)
00037                         && $value == (int) $value
00038                         && strlen($value) == strlen((int) $value)
00039                     ) ||
00040                     (is_string($value) && strtolower($value) == 'null')
00041                 )
00042                     ? $value
00043                     : "'".addslashes($value)."'";
00044         }
00045         
00046         public static function quoteField($field)
00047         {
00048             return self::quoteTable($field);
00049         }
00050         
00051         public static function quoteTable($table)
00052         {
00053             return '"'.$table.'"';
00054         }
00055 
00056         public static function toCasted($field, $type)
00057         {
00058             return "CAST ({$field} AS {$type})";
00059         }
00060         
00061         public static function timeZone($exist = false)
00062         {
00063             return
00064                 $exist
00065                     ? ' WITH TIME ZONE'
00066                     : ' WITHOUT TIME ZONE';
00067         }
00068         
00069         public static function dropTableMode($cascade = false)
00070         {
00071             return
00072                 $cascade
00073                     ? ' CASCADE'
00074                     : ' RESTRICT';
00075         }
00076         
00077         public function toFieldString($expression)
00078         {
00079             return $this->toNeededString($expression, 'quoteField');
00080         }
00081         
00082         public function toValueString($expression)
00083         {
00084             return $this->toNeededString($expression, 'quoteValue');
00085         }
00086         
00087         private function toNeededString($expression, $method)
00088         {
00089             $string = null;
00090             
00091             if (null !== $expression) {
00092                 if ($expression instanceof DialectString) {
00093                     if ($expression instanceof Query)
00094                         $string .= '('.$expression->toDialectString($this).')';
00095                     else
00096                         $string .= $expression->toDialectString($this);
00097                 } else {
00098                     $string .= $this->$method($expression);
00099                 }
00100             }
00101             
00102             return $string;
00103         }
00104         
00105         public function fieldToString($field)
00106         {
00107             return
00108                 $field instanceof DialectString
00109                     ? $field->toDialectString($this)
00110                     : $this->quoteField($field);
00111         }
00112         
00113         public function valueToString($value)
00114         {
00115             return
00116                 $value instanceof DBValue
00117                     ? $value->toDialectString($this)
00118                     : $this->quoteValue($value);
00119         }
00120         
00121         public function fullTextSearch($field, $words, $logic)
00122         {
00123             throw new UnimplementedFeatureException();
00124         }
00125         
00126         public function fullTextRank($field, $words, $logic)
00127         {
00128             throw new UnimplementedFeatureException();
00129         }
00130     }
00131 ?>

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