12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645 |
- <?php
- /*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the LGPL. For more information, see
- * <http://www.doctrine-project.org>.
- */
- namespace Doctrine\DBAL\Platforms;
- use Doctrine\DBAL\DBALException,
- Doctrine\DBAL\Connection,
- Doctrine\DBAL\Types,
- Doctrine\DBAL\Schema\Table,
- Doctrine\DBAL\Schema\Index,
- Doctrine\DBAL\Schema\ForeignKeyConstraint,
- Doctrine\DBAL\Schema\TableDiff,
- Doctrine\DBAL\Schema\Column,
- Doctrine\DBAL\Schema\ColumnDiff,
- Doctrine\DBAL\Types\Type,
- Doctrine\DBAL\Events,
- Doctrine\Common\EventManager,
- Doctrine\DBAL\Event\SchemaCreateTableEventArgs,
- Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs,
- Doctrine\DBAL\Event\SchemaDropTableEventArgs,
- Doctrine\DBAL\Event\SchemaAlterTableEventArgs,
- Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs,
- Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs,
- Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs,
- Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs;
- /**
- * Base class for all DatabasePlatforms. The DatabasePlatforms are the central
- * point of abstraction of platform-specific behaviors, features and SQL dialects.
- * They are a passive source of information.
- *
- * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
- * @link www.doctrine-project.org
- * @since 2.0
- * @version $Revision: 3938 $
- * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
- * @author Jonathan Wage <jonwage@gmail.com>
- * @author Roman Borschel <roman@code-factory.org>
- * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
- * @author Benjamin Eberlei <kontakt@beberlei.de>
- * @todo Remove any unnecessary methods.
- */
- abstract class AbstractPlatform
- {
- /**
- * @var int
- */
- const CREATE_INDEXES = 1;
- /**
- * @var int
- */
- const CREATE_FOREIGNKEYS = 2;
- /**
- * @var int
- */
- const TRIM_UNSPECIFIED = 0;
- /**
- * @var int
- */
- const TRIM_LEADING = 1;
- /**
- * @var int
- */
- const TRIM_TRAILING = 2;
- /**
- * @var int
- */
- const TRIM_BOTH = 3;
- /**
- * @var array
- */
- protected $doctrineTypeMapping = null;
- /**
- * Contains a list of all columns that should generate parseable column comments for type-detection
- * in reverse engineering scenarios.
- *
- * @var array
- */
- protected $doctrineTypeComments = null;
- /**
- * @var Doctrine\Common\EventManager
- */
- protected $_eventManager;
- /**
- * Constructor.
- */
- public function __construct() {}
- /**
- * Sets the EventManager used by the Platform.
- *
- * @param \Doctrine\Common\EventManager
- */
- public function setEventManager(EventManager $eventManager)
- {
- $this->_eventManager = $eventManager;
- }
- /**
- * Gets the EventManager used by the Platform.
- *
- * @return \Doctrine\Common\EventManager
- */
- public function getEventManager()
- {
- return $this->_eventManager;
- }
- /**
- * Gets the SQL snippet that declares a boolean column.
- *
- * @param array $columnDef
- * @return string
- */
- abstract public function getBooleanTypeDeclarationSQL(array $columnDef);
- /**
- * Gets the SQL snippet that declares a 4 byte integer column.
- *
- * @param array $columnDef
- * @return string
- */
- abstract public function getIntegerTypeDeclarationSQL(array $columnDef);
- /**
- * Gets the SQL snippet that declares an 8 byte integer column.
- *
- * @param array $columnDef
- * @return string
- */
- abstract public function getBigIntTypeDeclarationSQL(array $columnDef);
- /**
- * Gets the SQL snippet that declares a 2 byte integer column.
- *
- * @param array $columnDef
- * @return string
- */
- abstract public function getSmallIntTypeDeclarationSQL(array $columnDef);
- /**
- * Gets the SQL snippet that declares common properties of an integer column.
- *
- * @param array $columnDef
- * @return string
- */
- abstract protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef);
- /**
- * Lazy load Doctrine Type Mappings
- *
- * @return void
- */
- abstract protected function initializeDoctrineTypeMappings();
- /**
- * Gets the SQL snippet used to declare a VARCHAR column type.
- *
- * @param array $field
- */
- public function getVarcharTypeDeclarationSQL(array $field)
- {
- if ( !isset($field['length'])) {
- $field['length'] = $this->getVarcharDefaultLength();
- }
- $fixed = (isset($field['fixed'])) ? $field['fixed'] : false;
- if ($field['length'] > $this->getVarcharMaxLength()) {
- return $this->getClobTypeDeclarationSQL($field);
- } else {
- return $this->getVarcharTypeDeclarationSQLSnippet($field['length'], $fixed);
- }
- }
- protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
- {
- throw DBALException::notSupported('VARCHARs not supported by Platform.');
- }
- /**
- * Gets the SQL snippet used to declare a CLOB column type.
- *
- * @param array $field
- */
- abstract public function getClobTypeDeclarationSQL(array $field);
- /**
- * Gets the SQL Snippet used to declare a BLOB column type.
- */
- abstract public function getBlobTypeDeclarationSQL(array $field);
- /**
- * Gets the name of the platform.
- *
- * @return string
- */
- abstract public function getName();
- /**
- * Register a doctrine type to be used in conjunction with a column type of this platform.
- *
- * @param string $dbType
- * @param string $doctrineType
- */
- public function registerDoctrineTypeMapping($dbType, $doctrineType)
- {
- if ($this->doctrineTypeMapping === null) {
- $this->initializeDoctrineTypeMappings();
- }
- if (!Types\Type::hasType($doctrineType)) {
- throw DBALException::typeNotFound($doctrineType);
- }
- $dbType = strtolower($dbType);
- $this->doctrineTypeMapping[$dbType] = $doctrineType;
- }
- /**
- * Get the Doctrine type that is mapped for the given database column type.
- *
- * @param string $dbType
- * @return string
- */
- public function getDoctrineTypeMapping($dbType)
- {
- if ($this->doctrineTypeMapping === null) {
- $this->initializeDoctrineTypeMappings();
- }
- $dbType = strtolower($dbType);
- if (isset($this->doctrineTypeMapping[$dbType])) {
- return $this->doctrineTypeMapping[$dbType];
- } else {
- throw new \Doctrine\DBAL\DBALException("Unknown database type ".$dbType." requested, " . get_class($this) . " may not support it.");
- }
- }
- /**
- * Check if a database type is currently supported by this platform.
- *
- * @param string $dbType
- * @return bool
- */
- public function hasDoctrineTypeMappingFor($dbType)
- {
- if ($this->doctrineTypeMapping === null) {
- $this->initializeDoctrineTypeMappings();
- }
- $dbType = strtolower($dbType);
- return isset($this->doctrineTypeMapping[$dbType]);
- }
- /**
- * Initialize the Doctrine Type comments instance variable for in_array() checks.
- *
- * @return void
- */
- protected function initializeCommentedDoctrineTypes()
- {
- $this->doctrineTypeComments = array(Type::TARRAY, Type::OBJECT);
- }
- /**
- * Is it necessary for the platform to add a parsable type comment to allow reverse engineering the given type?
- *
- * @param Type $doctrineType
- * @return bool
- */
- public function isCommentedDoctrineType(Type $doctrineType)
- {
- if ($this->doctrineTypeComments === null) {
- $this->initializeCommentedDoctrineTypes();
- }
- return in_array($doctrineType->getName(), $this->doctrineTypeComments);
- }
- /**
- * Mark this type as to be commented in ALTER TABLE and CREATE TABLE statements.
- *
- * @param Type $doctrineType
- * @return void
- */
- public function markDoctrineTypeCommented(Type $doctrineType)
- {
- if ($this->doctrineTypeComments === null) {
- $this->initializeCommentedDoctrineTypes();
- }
- $this->doctrineTypeComments[] = $doctrineType->getName();
- }
- /**
- * Get the comment to append to a column comment that helps parsing this type in reverse engineering.
- *
- * @param Type $doctrineType
- * @return string
- */
- public function getDoctrineTypeComment(Type $doctrineType)
- {
- return '(DC2Type:' . $doctrineType->getName() . ')';
- }
- /**
- * Return the comment of a passed column modified by potential doctrine type comment hints.
- *
- * @param Column $column
- * @return string
- */
- protected function getColumnComment(Column $column)
- {
- $comment = $column->getComment();
- if ($this->isCommentedDoctrineType($column->getType())) {
- $comment .= $this->getDoctrineTypeComment($column->getType());
- }
- return $comment;
- }
- /**
- * Gets the character used for identifier quoting.
- *
- * @return string
- */
- public function getIdentifierQuoteCharacter()
- {
- return '"';
- }
- /**
- * Gets the string portion that starts an SQL comment.
- *
- * @return string
- */
- public function getSqlCommentStartString()
- {
- return "--";
- }
- /**
- * Gets the string portion that ends an SQL comment.
- *
- * @return string
- */
- public function getSqlCommentEndString()
- {
- return "\n";
- }
- /**
- * Gets the maximum length of a varchar field.
- *
- * @return integer
- */
- public function getVarcharMaxLength()
- {
- return 4000;
- }
- /**
- * Gets the default length of a varchar field.
- *
- * @return integer
- */
- public function getVarcharDefaultLength()
- {
- return 255;
- }
- /**
- * Gets all SQL wildcard characters of the platform.
- *
- * @return array
- */
- public function getWildcards()
- {
- return array('%', '_');
- }
- /**
- * Returns the regular expression operator.
- *
- * @return string
- */
- public function getRegexpExpression()
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Returns global unique identifier
- *
- * @return string to get global unique identifier
- */
- public function getGuidExpression()
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Returns the average value of a column
- *
- * @param string $column the column to use
- * @return string generated sql including an AVG aggregate function
- */
- public function getAvgExpression($column)
- {
- return 'AVG(' . $column . ')';
- }
- /**
- * Returns the number of rows (without a NULL value) of a column
- *
- * If a '*' is used instead of a column the number of selected rows
- * is returned.
- *
- * @param string|integer $column the column to use
- * @return string generated sql including a COUNT aggregate function
- */
- public function getCountExpression($column)
- {
- return 'COUNT(' . $column . ')';
- }
- /**
- * Returns the highest value of a column
- *
- * @param string $column the column to use
- * @return string generated sql including a MAX aggregate function
- */
- public function getMaxExpression($column)
- {
- return 'MAX(' . $column . ')';
- }
- /**
- * Returns the lowest value of a column
- *
- * @param string $column the column to use
- * @return string
- */
- public function getMinExpression($column)
- {
- return 'MIN(' . $column . ')';
- }
- /**
- * Returns the total sum of a column
- *
- * @param string $column the column to use
- * @return string
- */
- public function getSumExpression($column)
- {
- return 'SUM(' . $column . ')';
- }
- // scalar functions
- /**
- * Returns the md5 sum of a field.
- *
- * Note: Not SQL92, but common functionality
- *
- * @return string
- */
- public function getMd5Expression($column)
- {
- return 'MD5(' . $column . ')';
- }
- /**
- * Returns the length of a text field.
- *
- * @param string $expression1
- * @param string $expression2
- * @return string
- */
- public function getLengthExpression($column)
- {
- return 'LENGTH(' . $column . ')';
- }
- /**
- * Rounds a numeric field to the number of decimals specified.
- *
- * @param string $expression1
- * @param string $expression2
- * @return string
- */
- public function getRoundExpression($column, $decimals = 0)
- {
- return 'ROUND(' . $column . ', ' . $decimals . ')';
- }
- /**
- * Returns the remainder of the division operation
- * $expression1 / $expression2.
- *
- * @param string $expression1
- * @param string $expression2
- * @return string
- */
- public function getModExpression($expression1, $expression2)
- {
- return 'MOD(' . $expression1 . ', ' . $expression2 . ')';
- }
- /**
- * Trim a string, leading/trailing/both and with a given char which defaults to space.
- *
- * @param string $str
- * @param int $pos
- * @param string $char has to be quoted already
- * @return string
- */
- public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = false)
- {
- $posStr = '';
- $trimChar = ($char != false) ? $char . ' FROM ' : '';
- if ($pos == self::TRIM_LEADING) {
- $posStr = 'LEADING '.$trimChar;
- } else if($pos == self::TRIM_TRAILING) {
- $posStr = 'TRAILING '.$trimChar;
- } else if($pos == self::TRIM_BOTH) {
- $posStr = 'BOTH '.$trimChar;
- }
- return 'TRIM(' . $posStr . $str . ')';
- }
- /**
- * rtrim
- * returns the string $str with proceeding space characters removed
- *
- * @param string $str literal string or column name
- * @return string
- */
- public function getRtrimExpression($str)
- {
- return 'RTRIM(' . $str . ')';
- }
- /**
- * ltrim
- * returns the string $str with leading space characters removed
- *
- * @param string $str literal string or column name
- * @return string
- */
- public function getLtrimExpression($str)
- {
- return 'LTRIM(' . $str . ')';
- }
- /**
- * upper
- * Returns the string $str with all characters changed to
- * uppercase according to the current character set mapping.
- *
- * @param string $str literal string or column name
- * @return string
- */
- public function getUpperExpression($str)
- {
- return 'UPPER(' . $str . ')';
- }
- /**
- * lower
- * Returns the string $str with all characters changed to
- * lowercase according to the current character set mapping.
- *
- * @param string $str literal string or column name
- * @return string
- */
- public function getLowerExpression($str)
- {
- return 'LOWER(' . $str . ')';
- }
- /**
- * returns the position of the first occurrence of substring $substr in string $str
- *
- * @param string $substr literal string to find
- * @param string $str literal string
- * @param int $pos position to start at, beginning of string by default
- * @return integer
- */
- public function getLocateExpression($str, $substr, $startPos = false)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Returns the current system date.
- *
- * @return string
- */
- public function getNowExpression()
- {
- return 'NOW()';
- }
- /**
- * return string to call a function to get a substring inside an SQL statement
- *
- * Note: Not SQL92, but common functionality.
- *
- * SQLite only supports the 2 parameter variant of this function
- *
- * @param string $value an sql string literal or column name/alias
- * @param integer $from where to start the substring portion
- * @param integer $len the substring portion length
- * @return string
- */
- public function getSubstringExpression($value, $from, $len = null)
- {
- if ($len === null)
- return 'SUBSTRING(' . $value . ' FROM ' . $from . ')';
- else {
- return 'SUBSTRING(' . $value . ' FROM ' . $from . ' FOR ' . $len . ')';
- }
- }
- /**
- * Returns a series of strings concatinated
- *
- * concat() accepts an arbitrary number of parameters. Each parameter
- * must contain an expression
- *
- * @param string $arg1, $arg2 ... $argN strings that will be concatinated.
- * @return string
- */
- public function getConcatExpression()
- {
- return join(' || ' , func_get_args());
- }
- /**
- * Returns the SQL for a logical not.
- *
- * Example:
- * <code>
- * $q = new Doctrine_Query();
- * $e = $q->expr;
- * $q->select('*')->from('table')
- * ->where($e->eq('id', $e->not('null'));
- * </code>
- *
- * @return string a logical expression
- */
- public function getNotExpression($expression)
- {
- return 'NOT(' . $expression . ')';
- }
- /**
- * Returns the SQL to check if a value is one in a set of
- * given values.
- *
- * in() accepts an arbitrary number of parameters. The first parameter
- * must always specify the value that should be matched against. Successive
- * must contain a logical expression or an array with logical expressions.
- * These expressions will be matched against the first parameter.
- *
- * @param string $column the value that should be matched against
- * @param string|array(string) values that will be matched against $column
- * @return string logical expression
- */
- public function getInExpression($column, $values)
- {
- if ( ! is_array($values)) {
- $values = array($values);
- }
- $values = $this->getIdentifiers($values);
- if (count($values) == 0) {
- throw \InvalidArgumentException('Values must not be empty.');
- }
- return $column . ' IN (' . implode(', ', $values) . ')';
- }
- /**
- * Returns SQL that checks if a expression is null.
- *
- * @param string $expression the expression that should be compared to null
- * @return string logical expression
- */
- public function getIsNullExpression($expression)
- {
- return $expression . ' IS NULL';
- }
- /**
- * Returns SQL that checks if a expression is not null.
- *
- * @param string $expression the expression that should be compared to null
- * @return string logical expression
- */
- public function getIsNotNullExpression($expression)
- {
- return $expression . ' IS NOT NULL';
- }
- /**
- * Returns SQL that checks if an expression evaluates to a value between
- * two values.
- *
- * The parameter $expression is checked if it is between $value1 and $value2.
- *
- * Note: There is a slight difference in the way BETWEEN works on some databases.
- * http://www.w3schools.com/sql/sql_between.asp. If you want complete database
- * independence you should avoid using between().
- *
- * @param string $expression the value to compare to
- * @param string $value1 the lower value to compare with
- * @param string $value2 the higher value to compare with
- * @return string logical expression
- */
- public function getBetweenExpression($expression, $value1, $value2)
- {
- return $expression . ' BETWEEN ' .$value1 . ' AND ' . $value2;
- }
- public function getAcosExpression($value)
- {
- return 'ACOS(' . $value . ')';
- }
- public function getSinExpression($value)
- {
- return 'SIN(' . $value . ')';
- }
- public function getPiExpression()
- {
- return 'PI()';
- }
- public function getCosExpression($value)
- {
- return 'COS(' . $value . ')';
- }
- /**
- * Calculate the difference in days between the two passed dates.
- *
- * Computes diff = date1 - date2
- *
- * @param string $date1
- * @param string $date2
- * @return string
- */
- public function getDateDiffExpression($date1, $date2)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Add the number of given days to a date.
- *
- * @param string $date
- * @param int $days
- * @return string
- */
- public function getDateAddDaysExpression($date, $days)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Substract the number of given days to a date.
- *
- * @param string $date
- * @param int $days
- * @return string
- */
- public function getDateSubDaysExpression($date, $days)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Add the number of given months to a date.
- *
- * @param string $date
- * @param int $months
- * @return string
- */
- public function getDateAddMonthExpression($date, $months)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Substract the number of given months to a date.
- *
- * @param string $date
- * @param int $months
- * @return string
- */
- public function getDateSubMonthExpression($date, $months)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Gets SQL bit AND comparison expression
- *
- * @param string $value1
- * @param string $value2
- * @return string
- */
- public function getBitAndComparisonExpression($value1, $value2)
- {
- return '(' . $value1 . ' & ' . $value2 . ')';
- }
- /**
- * Gets SQL bit OR comparison expression
- *
- * @param string $value1
- * @param string $value2
- * @return string
- */
- public function getBitOrComparisonExpression($value1, $value2)
- {
- return '(' . $value1 . ' | ' . $value2 . ')';
- }
- public function getForUpdateSQL()
- {
- return 'FOR UPDATE';
- }
- /**
- * Honors that some SQL vendors such as MsSql use table hints for locking instead of the ANSI SQL FOR UPDATE specification.
- *
- * @param string $fromClause
- * @param int $lockMode
- * @return string
- */
- public function appendLockHint($fromClause, $lockMode)
- {
- return $fromClause;
- }
- /**
- * Get the sql snippet to append to any SELECT statement which locks rows in shared read lock.
- *
- * This defaults to the ASNI SQL "FOR UPDATE", which is an exclusive lock (Write). Some database
- * vendors allow to lighten this constraint up to be a real read lock.
- *
- * @return string
- */
- public function getReadLockSQL()
- {
- return $this->getForUpdateSQL();
- }
- /**
- * Get the SQL snippet to append to any SELECT statement which obtains an exclusive lock on the rows.
- *
- * The semantics of this lock mode should equal the SELECT .. FOR UPDATE of the ASNI SQL standard.
- *
- * @return string
- */
- public function getWriteLockSQL()
- {
- return $this->getForUpdateSQL();
- }
- public function getDropDatabaseSQL($database)
- {
- return 'DROP DATABASE ' . $database;
- }
- /**
- * Drop a Table
- *
- * @throws \InvalidArgumentException
- * @param Table|string $table
- * @return string
- */
- public function getDropTableSQL($table)
- {
- $tableArg = $table;
- if ($table instanceof \Doctrine\DBAL\Schema\Table) {
- $table = $table->getQuotedName($this);
- } else if(!is_string($table)) {
- throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
- }
- if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaDropTable)) {
- $eventArgs = new SchemaDropTableEventArgs($tableArg, $this);
- $this->_eventManager->dispatchEvent(Events::onSchemaDropTable, $eventArgs);
- if ($eventArgs->isDefaultPrevented()) {
- return $eventArgs->getSql();
- }
- }
- return 'DROP TABLE ' . $table;
- }
- /**
- * Get SQL to safely drop a temporary table WITHOUT implicitly committing an open transaction.
- *
- * @param Table|string $table
- * @return string
- */
- public function getDropTemporaryTableSQL($table)
- {
- return $this->getDropTableSQL($table);
- }
- /**
- * Drop index from a table
- *
- * @param Index|string $name
- * @param string|Table $table
- * @return string
- */
- public function getDropIndexSQL($index, $table=null)
- {
- if($index instanceof \Doctrine\DBAL\Schema\Index) {
- $index = $index->getQuotedName($this);
- } else if(!is_string($index)) {
- throw new \InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
- }
- return 'DROP INDEX ' . $index;
- }
- /**
- * Get drop constraint sql
- *
- * @param \Doctrine\DBAL\Schema\Constraint $constraint
- * @param string|Table $table
- * @return string
- */
- public function getDropConstraintSQL($constraint, $table)
- {
- if ($constraint instanceof \Doctrine\DBAL\Schema\Constraint) {
- $constraint = $constraint->getQuotedName($this);
- }
- if ($table instanceof \Doctrine\DBAL\Schema\Table) {
- $table = $table->getQuotedName($this);
- }
- return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $constraint;
- }
- /**
- * @param ForeignKeyConstraint|string $foreignKey
- * @param Table|string $table
- * @return string
- */
- public function getDropForeignKeySQL($foreignKey, $table)
- {
- if ($foreignKey instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) {
- $foreignKey = $foreignKey->getQuotedName($this);
- }
- if ($table instanceof \Doctrine\DBAL\Schema\Table) {
- $table = $table->getQuotedName($this);
- }
- return 'ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $foreignKey;
- }
- /**
- * Gets the SQL statement(s) to create a table with the specified name, columns and constraints
- * on this platform.
- *
- * @param string $table The name of the table.
- * @param int $createFlags
- * @return array The sequence of SQL statements.
- */
- public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXES)
- {
- if ( ! is_int($createFlags)) {
- throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSQL() has to be integer.");
- }
- if (count($table->getColumns()) == 0) {
- throw DBALException::noColumnsSpecifiedForTable($table->getName());
- }
- $tableName = $table->getQuotedName($this);
- $options = $table->getOptions();
- $options['uniqueConstraints'] = array();
- $options['indexes'] = array();
- $options['primary'] = array();
- if (($createFlags&self::CREATE_INDEXES) > 0) {
- foreach ($table->getIndexes() AS $index) {
- /* @var $index Index */
- if ($index->isPrimary()) {
- $options['primary'] = $index->getColumns();
- } else {
- $options['indexes'][$index->getName()] = $index;
- }
- }
- }
- $columnSql = array();
- $columns = array();
- foreach ($table->getColumns() AS $column) {
- /* @var \Doctrine\DBAL\Schema\Column $column */
- if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn)) {
- $eventArgs = new SchemaCreateTableColumnEventArgs($column, $table, $this);
- $this->_eventManager->dispatchEvent(Events::onSchemaCreateTableColumn, $eventArgs);
- $columnSql = array_merge($columnSql, $eventArgs->getSql());
- if ($eventArgs->isDefaultPrevented()) {
- continue;
- }
- }
- $columnData = array();
- $columnData['name'] = $column->getQuotedName($this);
- $columnData['type'] = $column->getType();
- $columnData['length'] = $column->getLength();
- $columnData['notnull'] = $column->getNotNull();
- $columnData['fixed'] = $column->getFixed();
- $columnData['unique'] = false; // TODO: what do we do about this?
- $columnData['version'] = ($column->hasPlatformOption("version"))?$column->getPlatformOption('version'):false;
- if(strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
- $columnData['length'] = 255;
- }
- $columnData['unsigned'] = $column->getUnsigned();
- $columnData['precision'] = $column->getPrecision();
- $columnData['scale'] = $column->getScale();
- $columnData['default'] = $column->getDefault();
- $columnData['columnDefinition'] = $column->getColumnDefinition();
- $columnData['autoincrement'] = $column->getAutoincrement();
- $columnData['comment'] = $this->getColumnComment($column);
- if(in_array($column->getName(), $options['primary'])) {
- $columnData['primary'] = true;
- }
- $columns[$columnData['name']] = $columnData;
- }
- if (($createFlags&self::CREATE_FOREIGNKEYS) > 0) {
- $options['foreignKeys'] = array();
- foreach ($table->getForeignKeys() AS $fkConstraint) {
- $options['foreignKeys'][] = $fkConstraint;
- }
- }
- if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) {
- $eventArgs = new SchemaCreateTableEventArgs($table, $columns, $options, $this);
- $this->_eventManager->dispatchEvent(Events::onSchemaCreateTable, $eventArgs);
- if ($eventArgs->isDefaultPrevented()) {
- return array_merge($eventArgs->getSql(), $columnSql);
- }
- }
- $sql = $this->_getCreateTableSQL($tableName, $columns, $options);
- if ($this->supportsCommentOnStatement()) {
- foreach ($table->getColumns() AS $column) {
- if ($this->getColumnComment($column)) {
- $sql[] = $this->getCommentOnColumnSQL($tableName, $column->getName(), $this->getColumnComment($column));
- }
- }
- }
- return array_merge($sql, $columnSql);
- }
- public function getCommentOnColumnSQL($tableName, $columnName, $comment)
- {
- return "COMMENT ON COLUMN " . $tableName . "." . $columnName . " IS '" . $comment . "'";
- }
- /**
- * @param string $tableName
- * @param array $columns
- * @param array $options
- * @return array
- */
- protected function _getCreateTableSQL($tableName, array $columns, array $options = array())
- {
- $columnListSql = $this->getColumnDeclarationListSQL($columns);
- if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
- foreach ($options['uniqueConstraints'] as $name => $definition) {
- $columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($name, $definition);
- }
- }
- if (isset($options['primary']) && ! empty($options['primary'])) {
- $columnListSql .= ', PRIMARY KEY(' . implode(', ', array_unique(array_values($options['primary']))) . ')';
- }
- if (isset($options['indexes']) && ! empty($options['indexes'])) {
- foreach($options['indexes'] as $index => $definition) {
- $columnListSql .= ', ' . $this->getIndexDeclarationSQL($index, $definition);
- }
- }
- $query = 'CREATE TABLE ' . $tableName . ' (' . $columnListSql;
- $check = $this->getCheckDeclarationSQL($columns);
- if ( ! empty($check)) {
- $query .= ', ' . $check;
- }
- $query .= ')';
- $sql[] = $query;
- if (isset($options['foreignKeys'])) {
- foreach ((array) $options['foreignKeys'] AS $definition) {
- $sql[] = $this->getCreateForeignKeySQL($definition, $tableName);
- }
- }
- return $sql;
- }
- public function getCreateTemporaryTableSnippetSQL()
- {
- return "CREATE TEMPORARY TABLE";
- }
- /**
- * Gets the SQL to create a sequence on this platform.
- *
- * @param \Doctrine\DBAL\Schema\Sequence $sequence
- * @throws DBALException
- */
- public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Gets the SQL statement to change a sequence on this platform.
- *
- * @param \Doctrine\DBAL\Schema\Sequence $sequence
- * @return string
- */
- public function getAlterSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Gets the SQL to create a constraint on a table on this platform.
- *
- * @param Constraint $constraint
- * @param string|Table $table
- * @return string
- */
- public function getCreateConstraintSQL(\Doctrine\DBAL\Schema\Constraint $constraint, $table)
- {
- if ($table instanceof \Doctrine\DBAL\Schema\Table) {
- $table = $table->getQuotedName($this);
- }
- $query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $constraint->getQuotedName($this);
- $columns = array();
- foreach ($constraint->getColumns() as $column) {
- $columns[] = $column;
- }
- $columnList = '('. implode(', ', $columns) . ')';
- $referencesClause = '';
- if ($constraint instanceof \Doctrine\DBAL\Schema\Index) {
- if($constraint->isPrimary()) {
- $query .= ' PRIMARY KEY';
- } elseif ($constraint->isUnique()) {
- $query .= ' UNIQUE';
- } else {
- throw new \InvalidArgumentException(
- 'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().'
- );
- }
- } else if ($constraint instanceof \Doctrine\DBAL\Schema\ForeignKeyConstraint) {
- $query .= ' FOREIGN KEY';
- $foreignColumns = array();
- foreach ($constraint->getForeignColumns() AS $column) {
- $foreignColumns[] = $column;
- }
- $referencesClause = ' REFERENCES '.$constraint->getForeignTableName(). ' ('.implode(', ', $foreignColumns).')';
- }
- $query .= ' '.$columnList.$referencesClause;
- return $query;
- }
- /**
- * Gets the SQL to create an index on a table on this platform.
- *
- * @param Index $index
- * @param string|Table $table name of the table on which the index is to be created
- * @return string
- */
- public function getCreateIndexSQL(Index $index, $table)
- {
- if ($table instanceof Table) {
- $table = $table->getQuotedName($this);
- }
- $name = $index->getQuotedName($this);
- $columns = $index->getColumns();
- if (count($columns) == 0) {
- throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
- }
- if ($index->isPrimary()) {
- return $this->getCreatePrimaryKeySQL($index, $table);
- } else {
- $type = '';
- if ($index->isUnique()) {
- $type = 'UNIQUE ';
- }
- $query = 'CREATE ' . $type . 'INDEX ' . $name . ' ON ' . $table;
- $query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')';
- }
- return $query;
- }
- /**
- * Get SQL to create an unnamed primary key constraint.
- *
- * @param Index $index
- * @param string|Table $table
- * @return string
- */
- public function getCreatePrimaryKeySQL(Index $index, $table)
- {
- return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index->getColumns()) . ')';
- }
- /**
- * Quotes a string so that it can be safely used as a table or column name,
- * even if it is a reserved word of the platform. This also detects identifier
- * chains seperated by dot and quotes them independently.
- *
- * NOTE: Just because you CAN use quoted identifiers doesn't mean
- * you SHOULD use them. In general, they end up causing way more
- * problems than they solve.
- *
- * @param string $str identifier name to be quoted
- * @return string quoted identifier string
- */
- public function quoteIdentifier($str)
- {
- if (strpos($str, ".") !== false) {
- $parts = array_map(array($this, "quoteIdentifier"), explode(".", $str));
- return implode(".", $parts);
- }
- return $this->quoteSingleIdentifier($str);
- }
- /**
- * Quote a single identifier (no dot chain seperation)
- *
- * @param string $str
- * @return string
- */
- public function quoteSingleIdentifier($str)
- {
- $c = $this->getIdentifierQuoteCharacter();
- return $c . str_replace($c, $c.$c, $str) . $c;
- }
- /**
- * Create a new foreign key
- *
- * @param ForeignKeyConstraint $foreignKey ForeignKey instance
- * @param string|Table $table name of the table on which the foreign key is to be created
- * @return string
- */
- public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
- {
- if ($table instanceof \Doctrine\DBAL\Schema\Table) {
- $table = $table->getQuotedName($this);
- }
- $query = 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSQL($foreignKey);
- return $query;
- }
- /**
- * Gets the sql statements for altering an existing table.
- *
- * The method returns an array of sql statements, since some platforms need several statements.
- *
- * @param TableDiff $diff
- * @return array
- */
- public function getAlterTableSQL(TableDiff $diff)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * @param Column $column
- * @param TableDiff $diff
- * @param array $columnSql
- */
- protected function onSchemaAlterTableAddColumn(Column $column, TableDiff $diff, &$columnSql)
- {
- if (null === $this->_eventManager) {
- return false;
- }
- if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTableAddColumn)) {
- return false;
- }
- $eventArgs = new SchemaAlterTableAddColumnEventArgs($column, $diff, $this);
- $this->_eventManager->dispatchEvent(Events::onSchemaAlterTableAddColumn, $eventArgs);
- $columnSql = array_merge($columnSql, $eventArgs->getSql());
- return $eventArgs->isDefaultPrevented();
- }
- /**
- * @param Column $column
- * @param TableDiff $diff
- * @param array $columnSql
- */
- protected function onSchemaAlterTableRemoveColumn(Column $column, TableDiff $diff, &$columnSql)
- {
- if (null === $this->_eventManager) {
- return false;
- }
- if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTableRemoveColumn)) {
- return false;
- }
- $eventArgs = new SchemaAlterTableRemoveColumnEventArgs($column, $diff, $this);
- $this->_eventManager->dispatchEvent(Events::onSchemaAlterTableRemoveColumn, $eventArgs);
- $columnSql = array_merge($columnSql, $eventArgs->getSql());
- return $eventArgs->isDefaultPrevented();
- }
- /**
- * @param ColumnDiff $columnDiff
- * @param TableDiff $diff
- * @param array $columnSql
- */
- protected function onSchemaAlterTableChangeColumn(ColumnDiff $columnDiff, TableDiff $diff, &$columnSql)
- {
- if (null === $this->_eventManager) {
- return false;
- }
- if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTableChangeColumn)) {
- return false;
- }
- $eventArgs = new SchemaAlterTableChangeColumnEventArgs($columnDiff, $diff, $this);
- $this->_eventManager->dispatchEvent(Events::onSchemaAlterTableChangeColumn, $eventArgs);
- $columnSql = array_merge($columnSql, $eventArgs->getSql());
- return $eventArgs->isDefaultPrevented();
- }
- /**
- * @param string $oldColumnName
- * @param Column $column
- * @param TableDiff $diff
- * @param array $columnSql
- */
- protected function onSchemaAlterTableRenameColumn($oldColumnName, Column $column, TableDiff $diff, &$columnSql)
- {
- if (null === $this->_eventManager) {
- return false;
- }
- if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTableRenameColumn)) {
- return false;
- }
- $eventArgs = new SchemaAlterTableRenameColumnEventArgs($oldColumnName, $column, $diff, $this);
- $this->_eventManager->dispatchEvent(Events::onSchemaAlterTableRenameColumn, $eventArgs);
- $columnSql = array_merge($columnSql, $eventArgs->getSql());
- return $eventArgs->isDefaultPrevented();
- }
- /**
- * @param TableDiff $diff
- * @param array $columnSql
- */
- protected function onSchemaAlterTable(TableDiff $diff, &$sql)
- {
- if (null === $this->_eventManager) {
- return false;
- }
- if (!$this->_eventManager->hasListeners(Events::onSchemaAlterTable)) {
- return false;
- }
- $eventArgs = new SchemaAlterTableEventArgs($diff, $this);
- $this->_eventManager->dispatchEvent(Events::onSchemaAlterTable, $eventArgs);
- $sql = array_merge($sql, $eventArgs->getSql());
- return $eventArgs->isDefaultPrevented();
- }
- protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
- {
- $tableName = $diff->name;
- $sql = array();
- if ($this->supportsForeignKeyConstraints()) {
- foreach ($diff->removedForeignKeys AS $foreignKey) {
- $sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
- }
- foreach ($diff->changedForeignKeys AS $foreignKey) {
- $sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName);
- }
- }
- foreach ($diff->removedIndexes AS $index) {
- $sql[] = $this->getDropIndexSQL($index, $tableName);
- }
- foreach ($diff->changedIndexes AS $index) {
- $sql[] = $this->getDropIndexSQL($index, $tableName);
- }
- return $sql;
- }
- protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
- {
- if ($diff->newName !== false) {
- $tableName = $diff->newName;
- } else {
- $tableName = $diff->name;
- }
- $sql = array();
- if ($this->supportsForeignKeyConstraints()) {
- foreach ($diff->addedForeignKeys AS $foreignKey) {
- $sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName);
- }
- foreach ($diff->changedForeignKeys AS $foreignKey) {
- $sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName);
- }
- }
- foreach ($diff->addedIndexes AS $index) {
- $sql[] = $this->getCreateIndexSQL($index, $tableName);
- }
- foreach ($diff->changedIndexes AS $index) {
- $sql[] = $this->getCreateIndexSQL($index, $tableName);
- }
- return $sql;
- }
- /**
- * Common code for alter table statement generation that updates the changed Index and Foreign Key definitions.
- *
- * @param TableDiff $diff
- * @return array
- */
- protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff)
- {
- return array_merge($this->getPreAlterTableIndexForeignKeySQL($diff), $this->getPostAlterTableIndexForeignKeySQL($diff));
- }
- /**
- * Get declaration of a number of fields in bulk
- *
- * @param array $fields a multidimensional associative array.
- * The first dimension determines the field name, while the second
- * dimension is keyed with the name of the properties
- * of the field being declared as array indexes. Currently, the types
- * of supported field properties are as follows:
- *
- * length
- * Integer value that determines the maximum length of the text
- * field. If this argument is missing the field should be
- * declared to have the longest length allowed by the DBMS.
- *
- * default
- * Text value to be used as default for this field.
- *
- * notnull
- * Boolean flag that indicates whether this field is constrained
- * to not be set to null.
- * charset
- * Text value with the default CHARACTER SET for this field.
- * collation
- * Text value with the default COLLATION for this field.
- * unique
- * unique constraint
- *
- * @return string
- */
- public function getColumnDeclarationListSQL(array $fields)
- {
- $queryFields = array();
- foreach ($fields as $fieldName => $field) {
- $query = $this->getColumnDeclarationSQL($fieldName, $field);
- $queryFields[] = $query;
- }
- return implode(', ', $queryFields);
- }
- /**
- * Obtain DBMS specific SQL code portion needed to declare a generic type
- * field to be used in statements like CREATE TABLE.
- *
- * @param string $name name the field to be declared.
- * @param array $field associative array with the name of the properties
- * of the field being declared as array indexes. Currently, the types
- * of supported field properties are as follows:
- *
- * length
- * Integer value that determines the maximum length of the text
- * field. If this argument is missing the field should be
- * declared to have the longest length allowed by the DBMS.
- *
- * default
- * Text value to be used as default for this field.
- *
- * notnull
- * Boolean flag that indicates whether this field is constrained
- * to not be set to null.
- * charset
- * Text value with the default CHARACTER SET for this field.
- * collation
- * Text value with the default COLLATION for this field.
- * unique
- * unique constraint
- * check
- * column check constraint
- * columnDefinition
- * a string that defines the complete column
- *
- * @return string DBMS specific SQL code portion that should be used to declare the column.
- */
- public function getColumnDeclarationSQL($name, array $field)
- {
- if (isset($field['columnDefinition'])) {
- $columnDef = $this->getCustomTypeDeclarationSQL($field);
- } else {
- $default = $this->getDefaultValueDeclarationSQL($field);
- $charset = (isset($field['charset']) && $field['charset']) ?
- ' ' . $this->getColumnCharsetDeclarationSQL($field['charset']) : '';
- $collation = (isset($field['collation']) && $field['collation']) ?
- ' ' . $this->getColumnCollationDeclarationSQL($field['collation']) : '';
- $notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : '';
- $unique = (isset($field['unique']) && $field['unique']) ?
- ' ' . $this->getUniqueFieldDeclarationSQL() : '';
- $check = (isset($field['check']) && $field['check']) ?
- ' ' . $field['check'] : '';
- $typeDecl = $field['type']->getSqlDeclaration($field, $this);
- $columnDef = $typeDecl . $charset . $default . $notnull . $unique . $check . $collation;
- }
- if ($this->supportsInlineColumnComments() && isset($field['comment']) && $field['comment']) {
- $columnDef .= " COMMENT '" . $field['comment'] . "'";
- }
- return $name . ' ' . $columnDef;
- }
- /**
- * Gets the SQL snippet that declares a floating point column of arbitrary precision.
- *
- * @param array $columnDef
- * @return string
- */
- public function getDecimalTypeDeclarationSQL(array $columnDef)
- {
- $columnDef['precision'] = ( ! isset($columnDef['precision']) || empty($columnDef['precision']))
- ? 10 : $columnDef['precision'];
- $columnDef['scale'] = ( ! isset($columnDef['scale']) || empty($columnDef['scale']))
- ? 0 : $columnDef['scale'];
- return 'NUMERIC(' . $columnDef['precision'] . ', ' . $columnDef['scale'] . ')';
- }
- /**
- * Obtain DBMS specific SQL code portion needed to set a default value
- * declaration to be used in statements like CREATE TABLE.
- *
- * @param array $field field definition array
- * @return string DBMS specific SQL code portion needed to set a default value
- */
- public function getDefaultValueDeclarationSQL($field)
- {
- $default = empty($field['notnull']) ? ' DEFAULT NULL' : '';
- if (isset($field['default'])) {
- $default = " DEFAULT '".$field['default']."'";
- if (isset($field['type'])) {
- if (in_array((string)$field['type'], array("Integer", "BigInteger", "SmallInteger"))) {
- $default = " DEFAULT ".$field['default'];
- } else if ((string)$field['type'] == 'DateTime' && $field['default'] == $this->getCurrentTimestampSQL()) {
- $default = " DEFAULT ".$this->getCurrentTimestampSQL();
- } else if ((string) $field['type'] == 'Boolean') {
- $default = " DEFAULT '" . $this->convertBooleans($field['default']) . "'";
- }
- }
- }
- return $default;
- }
- /**
- * Obtain DBMS specific SQL code portion needed to set a CHECK constraint
- * declaration to be used in statements like CREATE TABLE.
- *
- * @param array $definition check definition
- * @return string DBMS specific SQL code portion needed to set a CHECK constraint
- */
- public function getCheckDeclarationSQL(array $definition)
- {
- $constraints = array();
- foreach ($definition as $field => $def) {
- if (is_string($def)) {
- $constraints[] = 'CHECK (' . $def . ')';
- } else {
- if (isset($def['min'])) {
- $constraints[] = 'CHECK (' . $field . ' >= ' . $def['min'] . ')';
- }
- if (isset($def['max'])) {
- $constraints[] = 'CHECK (' . $field . ' <= ' . $def['max'] . ')';
- }
- }
- }
- return implode(', ', $constraints);
- }
- /**
- * Obtain DBMS specific SQL code portion needed to set a unique
- * constraint declaration to be used in statements like CREATE TABLE.
- *
- * @param string $name name of the unique constraint
- * @param Index $index index definition
- * @return string DBMS specific SQL code portion needed
- * to set a constraint
- */
- public function getUniqueConstraintDeclarationSQL($name, Index $index)
- {
- if (count($index->getColumns()) == 0) {
- throw \InvalidArgumentException("Incomplete definition. 'columns' required.");
- }
- return 'CONSTRAINT ' . $name . ' UNIQUE ('
- . $this->getIndexFieldDeclarationListSQL($index->getColumns())
- . ')';
- }
- /**
- * Obtain DBMS specific SQL code portion needed to set an index
- * declaration to be used in statements like CREATE TABLE.
- *
- * @param string $name name of the index
- * @param Index $index index definition
- * @return string DBMS specific SQL code portion needed to set an index
- */
- public function getIndexDeclarationSQL($name, Index $index)
- {
- $type = '';
- if($index->isUnique()) {
- $type = 'UNIQUE ';
- }
- if (count($index->getColumns()) == 0) {
- throw \InvalidArgumentException("Incomplete definition. 'columns' required.");
- }
- return $type . 'INDEX ' . $name . ' ('
- . $this->getIndexFieldDeclarationListSQL($index->getColumns())
- . ')';
- }
- /**
- * getCustomTypeDeclarationSql
- * Obtail SQL code portion needed to create a custom column,
- * e.g. when a field has the "columnDefinition" keyword.
- * Only "AUTOINCREMENT" and "PRIMARY KEY" are added if appropriate.
- *
- * @return string
- */
- public function getCustomTypeDeclarationSQL(array $columnDef)
- {
- return $columnDef['columnDefinition'];
- }
- /**
- * getIndexFieldDeclarationList
- * Obtain DBMS specific SQL code portion needed to set an index
- * declaration to be used in statements like CREATE TABLE.
- *
- * @return string
- */
- public function getIndexFieldDeclarationListSQL(array $fields)
- {
- $ret = array();
- foreach ($fields as $field => $definition) {
- if (is_array($definition)) {
- $ret[] = $field;
- } else {
- $ret[] = $definition;
- }
- }
- return implode(', ', $ret);
- }
- /**
- * A method to return the required SQL string that fits between CREATE ... TABLE
- * to create the table as a temporary table.
- *
- * Should be overridden in driver classes to return the correct string for the
- * specific database type.
- *
- * The default is to return the string "TEMPORARY" - this will result in a
- * SQL error for any database that does not support temporary tables, or that
- * requires a different SQL command from "CREATE TEMPORARY TABLE".
- *
- * @return string The string required to be placed between "CREATE" and "TABLE"
- * to generate a temporary table, if possible.
- */
- public function getTemporaryTableSQL()
- {
- return 'TEMPORARY';
- }
- /**
- * Some vendors require temporary table names to be qualified specially.
- *
- * @param string $tableName
- * @return string
- */
- public function getTemporaryTableName($tableName)
- {
- return $tableName;
- }
- /**
- * Get sql query to show a list of database.
- *
- * @return string
- */
- public function getShowDatabasesSQL()
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
- * of a field declaration to be used in statements like CREATE TABLE.
- *
- * @param array $definition an associative array with the following structure:
- * name optional constraint name
- *
- * local the local field(s)
- *
- * foreign the foreign reference field(s)
- *
- * foreignTable the name of the foreign table
- *
- * onDelete referential delete action
- *
- * onUpdate referential update action
- *
- * deferred deferred constraint checking
- *
- * The onDelete and onUpdate keys accept the following values:
- *
- * CASCADE: Delete or update the row from the parent table and automatically delete or
- * update the matching rows in the child table. Both ON DELETE CASCADE and ON UPDATE CASCADE are supported.
- * Between two tables, you should not define several ON UPDATE CASCADE clauses that act on the same column
- * in the parent table or in the child table.
- *
- * SET NULL: Delete or update the row from the parent table and set the foreign key column or columns in the
- * child table to NULL. This is valid only if the foreign key columns do not have the NOT NULL qualifier
- * specified. Both ON DELETE SET NULL and ON UPDATE SET NULL clauses are supported.
- *
- * NO ACTION: In standard SQL, NO ACTION means no action in the sense that an attempt to delete or update a primary
- * key value is not allowed to proceed if there is a related foreign key value in the referenced table.
- *
- * RESTRICT: Rejects the delete or update operation for the parent table. NO ACTION and RESTRICT are the same as
- * omitting the ON DELETE or ON UPDATE clause.
- *
- * SET DEFAULT
- *
- * @return string DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
- * of a field declaration.
- */
- public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey)
- {
- $sql = $this->getForeignKeyBaseDeclarationSQL($foreignKey);
- $sql .= $this->getAdvancedForeignKeyOptionsSQL($foreignKey);
- return $sql;
- }
- /**
- * Return the FOREIGN KEY query section dealing with non-standard options
- * as MATCH, INITIALLY DEFERRED, ON UPDATE, ...
- *
- * @param ForeignKeyConstraint $foreignKey foreign key definition
- * @return string
- */
- public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey)
- {
- $query = '';
- if ($this->supportsForeignKeyOnUpdate() && $foreignKey->hasOption('onUpdate')) {
- $query .= ' ON UPDATE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onUpdate'));
- }
- if ($foreignKey->hasOption('onDelete')) {
- $query .= ' ON DELETE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onDelete'));
- }
- return $query;
- }
- /**
- * returns given referential action in uppercase if valid, otherwise throws
- * an exception
- *
- * @throws Doctrine_Exception_Exception if unknown referential action given
- * @param string $action foreign key referential action
- * @param string foreign key referential action in uppercase
- */
- public function getForeignKeyReferentialActionSQL($action)
- {
- $upper = strtoupper($action);
- switch ($upper) {
- case 'CASCADE':
- case 'SET NULL':
- case 'NO ACTION':
- case 'RESTRICT':
- case 'SET DEFAULT':
- return $upper;
- break;
- default:
- throw new \InvalidArgumentException('Invalid foreign key action: ' . $upper);
- }
- }
- /**
- * Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
- * of a field declaration to be used in statements like CREATE TABLE.
- *
- * @param ForeignKeyConstraint $foreignKey
- * @return string
- */
- public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey)
- {
- $sql = '';
- if (strlen($foreignKey->getName())) {
- $sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' ';
- }
- $sql .= 'FOREIGN KEY (';
- if (count($foreignKey->getLocalColumns()) == 0) {
- throw new \InvalidArgumentException("Incomplete definition. 'local' required.");
- }
- if (count($foreignKey->getForeignColumns()) == 0) {
- throw new \InvalidArgumentException("Incomplete definition. 'foreign' required.");
- }
- if (strlen($foreignKey->getForeignTableName()) == 0) {
- throw new \InvalidArgumentException("Incomplete definition. 'foreignTable' required.");
- }
- $sql .= implode(', ', $foreignKey->getLocalColumns())
- . ') REFERENCES '
- . $foreignKey->getForeignTableName() . ' ('
- . implode(', ', $foreignKey->getForeignColumns()) . ')';
- return $sql;
- }
- /**
- * Obtain DBMS specific SQL code portion needed to set the UNIQUE constraint
- * of a field declaration to be used in statements like CREATE TABLE.
- *
- * @return string DBMS specific SQL code portion needed to set the UNIQUE constraint
- * of a field declaration.
- */
- public function getUniqueFieldDeclarationSQL()
- {
- return 'UNIQUE';
- }
- /**
- * Obtain DBMS specific SQL code portion needed to set the CHARACTER SET
- * of a field declaration to be used in statements like CREATE TABLE.
- *
- * @param string $charset name of the charset
- * @return string DBMS specific SQL code portion needed to set the CHARACTER SET
- * of a field declaration.
- */
- public function getColumnCharsetDeclarationSQL($charset)
- {
- return '';
- }
- /**
- * Obtain DBMS specific SQL code portion needed to set the COLLATION
- * of a field declaration to be used in statements like CREATE TABLE.
- *
- * @param string $collation name of the collation
- * @return string DBMS specific SQL code portion needed to set the COLLATION
- * of a field declaration.
- */
- public function getColumnCollationDeclarationSQL($collation)
- {
- return '';
- }
- /**
- * Whether the platform prefers sequences for ID generation.
- * Subclasses should override this method to return TRUE if they prefer sequences.
- *
- * @return boolean
- */
- public function prefersSequences()
- {
- return false;
- }
- /**
- * Whether the platform prefers identity columns (eg. autoincrement) for ID generation.
- * Subclasses should override this method to return TRUE if they prefer identity columns.
- *
- * @return boolean
- */
- public function prefersIdentityColumns()
- {
- return false;
- }
- /**
- * Some platforms need the boolean values to be converted.
- *
- * The default conversion in this implementation converts to integers (false => 0, true => 1).
- *
- * @param mixed $item
- */
- public function convertBooleans($item)
- {
- if (is_array($item)) {
- foreach ($item as $k => $value) {
- if (is_bool($value)) {
- $item[$k] = (int) $value;
- }
- }
- } else if (is_bool($item)) {
- $item = (int) $item;
- }
- return $item;
- }
- /**
- * Gets the SQL statement specific for the platform to set the charset.
- *
- * This function is MySQL specific and required by
- * {@see \Doctrine\DBAL\Connection::setCharset($charset)}
- *
- * @param string $charset
- * @return string
- */
- public function getSetCharsetSQL($charset)
- {
- return "SET NAMES '".$charset."'";
- }
- /**
- * Gets the SQL specific for the platform to get the current date.
- *
- * @return string
- */
- public function getCurrentDateSQL()
- {
- return 'CURRENT_DATE';
- }
- /**
- * Gets the SQL specific for the platform to get the current time.
- *
- * @return string
- */
- public function getCurrentTimeSQL()
- {
- return 'CURRENT_TIME';
- }
- /**
- * Gets the SQL specific for the platform to get the current timestamp
- *
- * @return string
- */
- public function getCurrentTimestampSQL()
- {
- return 'CURRENT_TIMESTAMP';
- }
- /**
- * Get sql for transaction isolation level Connection constant
- *
- * @param integer $level
- */
- protected function _getTransactionIsolationLevelSQL($level)
- {
- switch ($level) {
- case Connection::TRANSACTION_READ_UNCOMMITTED:
- return 'READ UNCOMMITTED';
- case Connection::TRANSACTION_READ_COMMITTED:
- return 'READ COMMITTED';
- case Connection::TRANSACTION_REPEATABLE_READ:
- return 'REPEATABLE READ';
- case Connection::TRANSACTION_SERIALIZABLE:
- return 'SERIALIZABLE';
- default:
- throw new \InvalidArgumentException('Invalid isolation level:' . $level);
- }
- }
- public function getListDatabasesSQL()
- {
- throw DBALException::notSupported(__METHOD__);
- }
- public function getListSequencesSQL($database)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- public function getListTableConstraintsSQL($table)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- public function getListTableColumnsSQL($table, $database = null)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- public function getListTablesSQL()
- {
- throw DBALException::notSupported(__METHOD__);
- }
- public function getListUsersSQL()
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Get the SQL to list all views of a database or user.
- *
- * @param string $database
- * @return string
- */
- public function getListViewsSQL($database)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Get the list of indexes for the current database.
- *
- * The current database parameter is optional but will always be passed
- * when using the SchemaManager API and is the database the given table is in.
- *
- * Attention: Some platforms only support currentDatabase when they
- * are connected with that database. Cross-database information schema
- * requests may be impossible.
- *
- * @param string $table
- * @param string $currentDatabase
- */
- public function getListTableIndexesSQL($table, $currentDatabase = null)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- public function getListTableForeignKeysSQL($table)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- public function getCreateViewSQL($name, $sql)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- public function getDropViewSQL($name)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- public function getDropSequenceSQL($sequence)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- public function getSequenceNextValSQL($sequenceName)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- public function getCreateDatabaseSQL($database)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Get sql to set the transaction isolation level
- *
- * @param integer $level
- */
- public function getSetTransactionIsolationSQL($level)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Obtain DBMS specific SQL to be used to create datetime fields in
- * statements like CREATE TABLE
- *
- * @param array $fieldDeclaration
- * @return string
- */
- public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Obtain DBMS specific SQL to be used to create datetime with timezone offset fields.
- *
- * @param array $fieldDeclaration
- */
- public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration)
- {
- return $this->getDateTimeTypeDeclarationSQL($fieldDeclaration);
- }
- /**
- * Obtain DBMS specific SQL to be used to create date fields in statements
- * like CREATE TABLE.
- *
- * @param array $fieldDeclaration
- * @return string
- */
- public function getDateTypeDeclarationSQL(array $fieldDeclaration)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- /**
- * Obtain DBMS specific SQL to be used to create time fields in statements
- * like CREATE TABLE.
- *
- * @param array $fieldDeclaration
- * @return string
- */
- public function getTimeTypeDeclarationSQL(array $fieldDeclaration)
- {
- throw DBALException::notSupported(__METHOD__);
- }
- public function getFloatDeclarationSQL(array $fieldDeclaration)
- {
- return 'DOUBLE PRECISION';
- }
- /**
- * Gets the default transaction isolation level of the platform.
- *
- * @return integer The default isolation level.
- * @see Doctrine\DBAL\Connection\TRANSACTION_* constants.
- */
- public function getDefaultTransactionIsolationLevel()
- {
- return Connection::TRANSACTION_READ_COMMITTED;
- }
- /* supports*() methods */
- /**
- * Whether the platform supports sequences.
- *
- * @return boolean
- */
- public function supportsSequences()
- {
- return false;
- }
- /**
- * Whether the platform supports identity columns.
- * Identity columns are columns that recieve an auto-generated value from the
- * database on insert of a row.
- *
- * @return boolean
- */
- public function supportsIdentityColumns()
- {
- return false;
- }
- /**
- * Whether the platform supports indexes.
- *
- * @return boolean
- */
- public function supportsIndexes()
- {
- return true;
- }
- public function supportsAlterTable()
- {
- return true;
- }
- /**
- * Whether the platform supports transactions.
- *
- * @return boolean
- */
- public function supportsTransactions()
- {
- return true;
- }
- /**
- * Whether the platform supports savepoints.
- *
- * @return boolean
- */
- public function supportsSavepoints()
- {
- return true;
- }
- /**
- * Whether the platform supports releasing savepoints.
- *
- * @return boolean
- */
- public function supportsReleaseSavepoints()
- {
- return $this->supportsSavepoints();
- }
- /**
- * Whether the platform supports primary key constraints.
- *
- * @return boolean
- */
- public function supportsPrimaryConstraints()
- {
- return true;
- }
- /**
- * Does the platform supports foreign key constraints?
- *
- * @return boolean
- */
- public function supportsForeignKeyConstraints()
- {
- return true;
- }
- /**
- * Does this platform supports onUpdate in foreign key constraints?
- *
- * @return bool
- */
- public function supportsForeignKeyOnUpdate()
- {
- return ($this->supportsForeignKeyConstraints() && true);
- }
- /**
- * Whether the platform supports database schemas.
- *
- * @return boolean
- */
- public function supportsSchemas()
- {
- return false;
- }
- /**
- * Can this platform emulate schemas?
- *
- * Platforms that either support or emulate schemas don't automatically
- * filter a schema for the namespaced elements in {@link
- * AbstractManager#createSchema}.
- *
- * @return bool
- */
- public function canEmulateSchemas()
- {
- return false;
- }
- /**
- * Some databases don't allow to create and drop databases at all or only with certain tools.
- *
- * @return bool
- */
- public function supportsCreateDropDatabase()
- {
- return true;
- }
- /**
- * Whether the platform supports getting the affected rows of a recent
- * update/delete type query.
- *
- * @return boolean
- */
- public function supportsGettingAffectedRows()
- {
- return true;
- }
- /**
- * Does this plaform support to add inline column comments as postfix.
- *
- * @return bool
- */
- public function supportsInlineColumnComments()
- {
- return false;
- }
- /**
- * Does this platform support the propriortary synatx "COMMENT ON asset"
- *
- * @return bool
- */
- public function supportsCommentOnStatement()
- {
- return false;
- }
- public function getIdentityColumnNullInsertSQL()
- {
- return "";
- }
- /**
- * Gets the format string, as accepted by the date() function, that describes
- * the format of a stored datetime value of this platform.
- *
- * @return string The format string.
- */
- public function getDateTimeFormatString()
- {
- return 'Y-m-d H:i:s';
- }
- /**
- * Gets the format string, as accepted by the date() function, that describes
- * the format of a stored datetime with timezone value of this platform.
- *
- * @return string The format string.
- */
- public function getDateTimeTzFormatString()
- {
- return 'Y-m-d H:i:s';
- }
- /**
- * Gets the format string, as accepted by the date() function, that describes
- * the format of a stored date value of this platform.
- *
- * @return string The format string.
- */
- public function getDateFormatString()
- {
- return 'Y-m-d';
- }
- /**
- * Gets the format string, as accepted by the date() function, that describes
- * the format of a stored time value of this platform.
- *
- * @return string The format string.
- */
- public function getTimeFormatString()
- {
- return 'H:i:s';
- }
- /**
- * Modify limit query
- *
- * @param string $query
- * @param int $limit
- * @param int $offset
- * @return string
- */
- final public function modifyLimitQuery($query, $limit, $offset = null)
- {
- if ( $limit !== null) {
- $limit = (int)$limit;
- }
- if ( $offset !== null) {
- $offset = (int)$offset;
- if ($offset < 0) {
- throw new DBALException("LIMIT argument offset=$offset is not valid");
- }
- if ( $offset > 0 && ! $this->supportsLimitOffset()) {
- throw new DBALException(sprintf("Platform %s does not support offset values in limit queries.", $this->getName()));
- }
- }
- return $this->doModifyLimitQuery($query, $limit, $offset);
- }
- /**
- * @param string $query
- * @param int $limit
- * @param int $offset
- * @return string
- */
- protected function doModifyLimitQuery($query, $limit, $offset)
- {
- if ( $limit !== null) {
- $query .= ' LIMIT ' . $limit;
- }
- if ( $offset !== null) {
- $query .= ' OFFSET ' . $offset;
- }
- return $query;
- }
- /**
- * Does the database platform support offsets in modify limit clauses?
- *
- * @return bool
- */
- public function supportsLimitOffset()
- {
- return true;
- }
- /**
- * Gets the character casing of a column in an SQL result set of this platform.
- *
- * @param string $column The column name for which to get the correct character casing.
- * @return string The column name in the character casing used in SQL result sets.
- */
- public function getSQLResultCasing($column)
- {
- return $column;
- }
- /**
- * Makes any fixes to a name of a schema element (table, sequence, ...) that are required
- * by restrictions of the platform, like a maximum length.
- *
- * @param string $schemaName
- * @return string
- */
- public function fixSchemaElementName($schemaElementName)
- {
- return $schemaElementName;
- }
- /**
- * Maximum length of any given databse identifier, like tables or column names.
- *
- * @return int
- */
- public function getMaxIdentifierLength()
- {
- return 63;
- }
- /**
- * Get the insert sql for an empty insert statement
- *
- * @param string $tableName
- * @param string $identifierColumnName
- * @return string $sql
- */
- public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName)
- {
- return 'INSERT INTO ' . $tableName . ' (' . $identifierColumnName . ') VALUES (null)';
- }
- /**
- * Generate a Truncate Table SQL statement for a given table.
- *
- * Cascade is not supported on many platforms but would optionally cascade the truncate by
- * following the foreign keys.
- *
- * @param string $tableName
- * @param bool $cascade
- * @return string
- */
- public function getTruncateTableSQL($tableName, $cascade = false)
- {
- return 'TRUNCATE '.$tableName;
- }
- /**
- * This is for test reasons, many vendors have special requirements for dummy statements.
- *
- * @return string
- */
- public function getDummySelectSQL()
- {
- return 'SELECT 1';
- }
- /**
- * Generate SQL to create a new savepoint
- *
- * @param string $savepoint
- * @return string
- */
- public function createSavePoint($savepoint)
- {
- return 'SAVEPOINT ' . $savepoint;
- }
- /**
- * Generate SQL to release a savepoint
- *
- * @param string $savepoint
- * @return string
- */
- public function releaseSavePoint($savepoint)
- {
- return 'RELEASE SAVEPOINT ' . $savepoint;
- }
- /**
- * Generate SQL to rollback a savepoint
- *
- * @param string $savepoint
- * @return string
- */
- public function rollbackSavePoint($savepoint)
- {
- return 'ROLLBACK TO SAVEPOINT ' . $savepoint;
- }
- /**
- * Return the keyword list instance of this platform.
- *
- * Throws exception if no keyword list is specified.
- *
- * @throws DBALException
- * @return KeywordList
- */
- final public function getReservedKeywordsList()
- {
- $class = $this->getReservedKeywordsClass();
- $keywords = new $class;
- if (!$keywords instanceof \Doctrine\DBAL\Platforms\Keywords\KeywordList) {
- throw DBALException::notSupported(__METHOD__);
- }
- return $keywords;
- }
- /**
- * The class name of the reserved keywords list.
- *
- * @return string
- */
- protected function getReservedKeywordsClass()
- {
- throw DBALException::notSupported(__METHOD__);
- }
- }
|