Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
3796db7d
Commit
3796db7d
authored
Jun 09, 2013
by
gevik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- Ported addPrimaryKey and created dropConstraint.
- The dropConstraint method can be used both for dropPrimaryKey and dropForeignKey
parent
c2b47d81
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
QueryBuilder.php
framework/yii/db/QueryBuilder.php
+30
-0
No files found.
framework/yii/db/QueryBuilder.php
View file @
3796db7d
...
@@ -270,6 +270,36 @@ class QueryBuilder extends \yii\base\Object
...
@@ -270,6 +270,36 @@ class QueryBuilder extends \yii\base\Object
}
}
/**
/**
* Builds a SQL statement for adding a primary key constraint to an existing table.
* @param string $name the name of the primary key constraint.
* @param string $table the table that the primary key constraint will be added to.
* @param string|array $columns comma separated string or array of columns that the primary key will consist of.
* @return string the SQL statement for adding a primary key constraint to an existing table.
*/
public
function
addPrimaryKey
(
$name
,
$table
,
$columns
)
{
if
(
is_string
(
$columns
))
$columns
=
preg_split
(
'/\s*,\s*/'
,
$columns
,
-
1
,
PREG_SPLIT_NO_EMPTY
);
foreach
(
$columns
as
$i
=>
$col
)
$columns
[
$i
]
=
$this
->
quoteColumnName
(
$col
);
return
'ALTER TABLE '
.
$this
->
quoteTableName
(
$table
)
.
' ADD CONSTRAINT '
.
$this
->
quoteColumnName
(
$name
)
.
' PRIMARY KEY ('
.
implode
(
', '
,
$columns
)
.
' )'
;
}
/**
* Builds a SQL statement for removing a constraint to an existing table.
* @param string $name the name of the constraint to be removed.
* @param string $table the table that constraint will be removed from.
* @return string the SQL statement for removing constraint from an existing table.
*/
public
function
dropConstraint
(
$name
,
$table
)
{
return
'ALTER TABLE '
.
$this
->
quoteTableName
(
$table
)
.
' DROP CONSTRAINT '
.
$this
->
quoteColumnName
(
$name
);
}
/**
* Builds a SQL statement for truncating a DB table.
* Builds a SQL statement for truncating a DB table.
* @param string $table the table to be truncated. The name will be properly quoted by the method.
* @param string $table the table to be truncated. The name will be properly quoted by the method.
* @return string the SQL statement for truncating a DB table.
* @return string the SQL statement for truncating a DB table.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment