84 return 'CREATE DATABASE ' . $name;
96 return 'DROP DATABASE ' . $name;
113 $foreignKey = $foreignKey->getQuotedName($this);
116 if ($table instanceof \Doctrine\DBAL\Schema\
Table) {
117 $table = $table->getQuotedName($this);
120 return 'ALTER TABLE ' . $table .
' DROP CONSTRAINT ' . $foreignKey;
128 if ($index instanceof \Doctrine\DBAL\Schema\
Index) {
130 $index = $index->getQuotedName($this);
131 }
else if (!is_string($index)) {
132 throw new \InvalidArgumentException(
'AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
135 if (!isset($table)) {
136 return 'DROP INDEX ' . $index;
138 if ($table instanceof \Doctrine\DBAL\Schema\
Table) {
139 $table = $table->getQuotedName($this);
142 return "IF EXISTS (SELECT * FROM sysobjects WHERE name = '$index')
143 ALTER TABLE " . $table .
" DROP CONSTRAINT " . $index .
"
145 DROP INDEX " . $index .
" ON " . $table;
156 foreach ($columns as &$column) {
157 if (isset($column[
'primary']) && $column[
'primary']) {
158 $column[
'notnull'] =
true;
164 if (isset($options[
'uniqueConstraints']) && !empty($options[
'uniqueConstraints'])) {
165 foreach ($options[
'uniqueConstraints'] as $name => $definition) {
170 if (isset($options[
'primary']) && !empty($options[
'primary'])) {
171 $columnListSql .=
', PRIMARY KEY(' . implode(
', ', array_unique(array_values($options[
'primary']))) .
')';
174 $query =
'CREATE TABLE ' . $tableName .
' (' . $columnListSql;
177 if (!empty($check)) {
178 $query .=
', ' . $check;
184 if (isset($options[
'indexes']) && !empty($options[
'indexes'])) {
185 foreach ($options[
'indexes'] AS $index) {
190 if (isset($options[
'foreignKeys'])) {
191 foreach ((array) $options[
'foreignKeys'] AS $definition) {
204 $constraint = parent::getUniqueConstraintDeclarationSQL($name, $index);
206 $constraint = $this->_appendUniqueConstraintDefinition($constraint, $index);
216 $constraint = parent::getCreateIndexSQL($index, $table);
219 $constraint = $this->_appendUniqueConstraintDefinition($constraint, $index);
232 private function _appendUniqueConstraintDefinition($sql,
Index $index)
235 foreach ($index->
getColumns() as $field => $definition) {
236 if (!is_array($definition)) {
237 $field = $definition;
240 $fields[] = $field .
' IS NOT NULL';
243 return $sql .
' WHERE ' . implode(
' AND ', $fields);
251 $queryParts = array();
252 if ($diff->newName !==
false) {
253 $queryParts[] =
'RENAME TO ' . $diff->newName;
256 foreach ($diff->addedColumns AS $fieldName => $column) {
260 foreach ($diff->removedColumns AS $column) {
261 $queryParts[] =
'DROP COLUMN ' . $column->getQuotedName($this);
264 foreach ($diff->changedColumns AS $columnDiff) {
266 $column = $columnDiff->column;
267 $queryParts[] =
'CHANGE ' . ($columnDiff->oldColumnName) .
' '
271 foreach ($diff->renamedColumns AS $oldColumnName => $column) {
272 $queryParts[] =
'CHANGE ' . $oldColumnName .
' '
278 foreach ($queryParts as $query) {
279 $sql[] =
'ALTER TABLE ' . $diff->name .
' ' . $query;
292 return 'INSERT INTO ' . $quotedTableName .
' DEFAULT VALUES';
300 return 'SHOW DATABASES';
308 return "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
316 return 'exec sp_columns @table_name = ' . $table;
324 return "SELECT f.name AS ForeignKey,
325 SCHEMA_NAME (f.SCHEMA_ID) AS SchemaName,
326 OBJECT_NAME (f.parent_object_id) AS TableName,
327 COL_NAME (fc.parent_object_id,fc.parent_column_id) AS ColumnName,
328 SCHEMA_NAME (o.SCHEMA_ID) ReferenceSchemaName,
329 OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
330 COL_NAME(fc.referenced_object_id,fc.referenced_column_id) AS ReferenceColumnName,
331 f.delete_referential_action_desc,
332 f.update_referential_action_desc
333 FROM sys.foreign_keys AS f
334 INNER JOIN sys.foreign_key_columns AS fc
335 INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id
336 ON f.OBJECT_ID = fc.constraint_object_id
337 WHERE OBJECT_NAME (f.parent_object_id) = '" . $table .
"'";
345 return "exec sp_helpindex '" . $table .
"'";
353 return 'CREATE VIEW ' . $name .
' AS ' . $sql;
361 return "SELECT name FROM sysobjects WHERE type = 'V' ORDER BY name";
369 return 'DROP VIEW ' . $name;
399 if ($startPos ==
false) {
400 return 'CHARINDEX(' . $substr .
', ' . $str .
')';
402 return 'CHARINDEX(' . $substr .
', ' . $str .
', ' . $startPos .
')';
411 return $expression1 .
' % ' . $expression2;
422 if ($pos == self::TRIM_LEADING) {
424 }
else if ($pos == self::TRIM_TRAILING) {
427 return 'LTRIM(RTRIM(' . $str .
'))';
430 return $trimFn .
'(' . $str .
')';
441 $pattern =
"'%[^' + $char + ']%'";
443 if ($pos == self::TRIM_LEADING) {
444 return 'stuff(' . $str .
', 1, patindex(' . $pattern .
', ' . $str .
') - 1, null)';
445 }
else if ($pos == self::TRIM_TRAILING) {
446 return 'reverse(stuff(reverse(' . $str .
'), 1, patindex(' . $pattern .
', reverse(' . $str .
')) - 1, null))';
448 return 'reverse(stuff(reverse(stuff(' . $str .
', 1, patindex(' . $pattern .
', ' . $str .
') - 1, null)), 1, patindex(' . $pattern .
', reverse(stuff(' . $str .
', 1, patindex(' . $pattern .
', ' . $str .
') - 1, null))) - 1, null))';
458 $args = func_get_args();
459 return '(' . implode(
' + ', $args) .
')';
464 return 'SELECT * FROM SYS.DATABASES';
472 if (!is_null($len)) {
473 return 'SUBSTRING(' . $value .
', ' . $from .
', ' . $len .
')';
475 return 'SUBSTRING(' . $value .
', ' . $from .
', LEN(' . $value .
') - ' . $from .
' + 1)';
483 return 'LEN(' . $column .
')';
521 if (!isset($field[
'length'])) {
522 if (array_key_exists(
'default', $field)) {
525 $field[
'length'] =
false;
530 $fixed = (isset($field[
'fixed'])) ? $field[
'fixed'] :
false;
532 return $fixed ? ($length ?
'NCHAR(' . $length .
')' :
'CHAR(255)') : ($length ?
'NVARCHAR(' . $length .
')' :
'NTEXT');
547 if (!empty($columnDef[
'autoincrement'])) {
548 $autoinc =
' IDENTITY';
550 $unsigned = (isset($columnDef[
'unsigned']) && $columnDef[
'unsigned']) ?
' UNSIGNED' :
'';
552 return $unsigned . $autoinc;
561 return 'DATETIME2(6)';
600 $count = intval($limit);
601 $offset = intval($offset);
604 throw new Doctrine_Connection_Exception(
"LIMIT argument offset=$offset is not valid");
608 $query = preg_replace(
'/^SELECT\s/i',
'SELECT TOP ' . $count .
' ', $query);
610 $orderby = stristr($query,
'ORDER BY');
613 $over =
'ORDER BY (SELECT 0)';
615 $over = preg_replace(
'/\"[^,]*\".\"([^,]*)\"/i',
'"inner_tbl"."$1"', $orderby);
619 $query = preg_replace(
'/\s+ORDER BY(.*)/',
'', $query);
622 $query =
"SELECT ROW_NUMBER() OVER ($over) AS \"doctrine_rownum\", * FROM ($query) AS inner_tbl";
624 $start = $offset + 1;
625 $end = $offset + $count;
627 $query =
"WITH outer_tbl AS ($query) SELECT * FROM outer_tbl WHERE \"doctrine_rownum\" BETWEEN $start AND $end";
639 if (is_array($item)) {
640 foreach ($item as $key => $value) {
641 if (is_bool($value) || is_numeric($item)) {
642 $item[$key] = ($value) ?
'TRUE' :
'FALSE';
646 if (is_bool($item) || is_numeric($item)) {
647 $item = ($item) ?
'TRUE' :
'FALSE';
658 return "CREATE TABLE";
666 return '#' . $tableName;
674 return 'Y-m-d H:i:s.u';
700 $this->doctrineTypeMapping = array(
701 'bigint' =>
'bigint',
702 'numeric' =>
'decimal',
704 'smallint' =>
'smallint',
705 'decimal' =>
'decimal',
706 'smallmoney' =>
'integer',
708 'tinyint' =>
'smallint',
709 'money' =>
'integer',
713 'double precision' =>
'float',
715 'datetimeoffset' =>
'datetimetz',
716 'datetime2' =>
'datetime',
717 'smalldatetime' =>
'datetime',
718 'datetime' =>
'datetime',
721 'varchar' =>
'string',
724 'nvarchar' =>
'string',
727 'varbinary' =>
'text',
740 return 'SAVE TRANSACTION ' . $savepoint;
762 return 'ROLLBACK TRANSACTION ' . $savepoint;
772 return $fromClause .
' WITH (tablockx)';
774 return $fromClause .
' WITH (tablockx)';