Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
Yeray Santana Hualde
syncEnrollments
Commits
1ec6fc76
Commit
1ec6fc76
authored
Jan 29, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added support for database table prefixes.
parent
97fcea1e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
22 deletions
+73
-22
database.php
application/config/database.php
+4
-0
connection.php
laravel/database/connection.php
+4
-4
grammar.php
laravel/database/grammar.php
+39
-0
grammar.php
laravel/database/query/grammars/grammar.php
+7
-5
schema.php
laravel/database/schema.php
+14
-12
grammar.php
laravel/database/schema/grammars/grammar.php
+5
-1
No files found.
application/config/database.php
View file @
1ec6fc76
...
...
@@ -38,6 +38,7 @@ return array(
'sqlite'
=>
array
(
'driver'
=>
'sqlite'
,
'database'
=>
'application'
,
'prefix'
=>
''
,
),
'mysql'
=>
array
(
...
...
@@ -47,6 +48,7 @@ return array(
'username'
=>
'root'
,
'password'
=>
''
,
'charset'
=>
'utf8'
,
'prefix'
=>
''
,
),
'pgsql'
=>
array
(
...
...
@@ -56,6 +58,7 @@ return array(
'username'
=>
'root'
,
'password'
=>
''
,
'charset'
=>
'utf8'
,
'prefix'
=>
''
,
),
'sqlsrv'
=>
array
(
...
...
@@ -64,6 +67,7 @@ return array(
'database'
=>
'database'
,
'username'
=>
'root'
,
'password'
=>
''
,
'prefix'
=>
''
,
),
),
...
...
laravel/database/connection.php
View file @
1ec6fc76
...
...
@@ -14,7 +14,7 @@ class Connection {
*
* @var array
*/
p
rotected
$config
;
p
ublic
$config
;
/**
* The query grammar instance for the connection.
...
...
@@ -74,13 +74,13 @@ class Connection {
switch
(
isset
(
$this
->
config
[
'grammar'
])
?
$this
->
config
[
'grammar'
]
:
$this
->
driver
())
{
case
'mysql'
:
return
$this
->
grammar
=
new
Query\Grammars\MySQL
;
return
$this
->
grammar
=
new
Query\Grammars\MySQL
(
$this
)
;
case
'sqlsrv'
:
return
$this
->
grammar
=
new
Query\Grammars\SQLServer
;
return
$this
->
grammar
=
new
Query\Grammars\SQLServer
(
$this
)
;
default
:
return
$this
->
grammar
=
new
Query\Grammars\Grammar
;
return
$this
->
grammar
=
new
Query\Grammars\Grammar
(
$this
)
;
}
}
...
...
laravel/database/grammar.php
View file @
1ec6fc76
...
...
@@ -9,6 +9,45 @@ abstract class Grammar {
*/
protected
$wrapper
=
'"%s"'
;
/**
* The database connection instance for the grammar.
*
* @var Connection
*/
protected
$connection
;
/**
* Create a new database grammar instance.
*
* @param Connection $connection
* @return void
*/
public
function
__construct
(
Connection
$connection
)
{
$this
->
connection
=
$connection
;
}
/**
* Wrap a table in keyword identifiers.
*
* @param string $table
* @return string
*/
public
function
wrap_table
(
$table
)
{
$prefix
=
''
;
// Tables may be prefixed with a string. This allows developers to
// prefix tables by application on the same database which may be
// required in some brown-field situations.
if
(
isset
(
$this
->
connection
->
config
[
'prefix'
]))
{
$prefix
=
$this
->
connection
->
config
[
'prefix'
];
}
return
$this
->
wrap
(
$prefix
.
$table
);
}
/**
* Wrap a value in keyword identifiers.
*
...
...
laravel/database/query/grammars/grammar.php
View file @
1ec6fc76
...
...
@@ -101,7 +101,7 @@ class Grammar extends \Laravel\Database\Grammar {
*/
protected
function
from
(
Query
$query
)
{
return
'FROM '
.
$this
->
wrap
(
$query
->
from
);
return
'FROM '
.
$this
->
wrap
_table
(
$query
->
from
);
}
/**
...
...
@@ -121,7 +121,7 @@ class Grammar extends \Laravel\Database\Grammar {
// set of joins in valid SQL that can appended to the query.
foreach
(
$query
->
joins
as
$join
)
{
$table
=
$this
->
wrap
(
$join
[
'table'
]);
$table
=
$this
->
wrap
_table
(
$join
[
'table'
]);
$column1
=
$this
->
wrap
(
$join
[
'column1'
]);
...
...
@@ -141,6 +141,8 @@ class Grammar extends \Laravel\Database\Grammar {
*/
final
protected
function
wheres
(
Query
$query
)
{
if
(
is_null
(
$query
->
wheres
))
return
''
;
// Each WHERE clause array has a "type" that is assigned by the query
// builder, and each type has its own compiler function. We will call
// the appropriate compiler for each where clause in the query.
...
...
@@ -311,7 +313,7 @@ class Grammar extends \Laravel\Database\Grammar {
*/
public
function
insert
(
Query
$query
,
$values
)
{
$table
=
$this
->
wrap
(
$query
->
from
);
$table
=
$this
->
wrap
_table
(
$query
->
from
);
// Force every insert to be treated like a batch insert. This simply makes
// creating the SQL syntax a little easier on us since we can always treat
...
...
@@ -342,7 +344,7 @@ class Grammar extends \Laravel\Database\Grammar {
*/
public
function
update
(
Query
$query
,
$values
)
{
$table
=
$this
->
wrap
(
$query
->
from
);
$table
=
$this
->
wrap
_table
(
$query
->
from
);
// Each column in the UPDATE statement needs to be wrapped in keyword
// identifiers, and a place-holder needs to be created for each value
...
...
@@ -370,7 +372,7 @@ class Grammar extends \Laravel\Database\Grammar {
*/
public
function
delete
(
Query
$query
)
{
$table
=
$this
->
wrap
(
$query
->
from
);
$table
=
$this
->
wrap
_table
(
$query
->
from
);
// Like the UPDATE statement, the DELETE statement is constrained
// by WHERE clauses, so we'll need to run the "wheres" method to
...
...
laravel/database/schema.php
View file @
1ec6fc76
...
...
@@ -33,7 +33,7 @@ class Schema {
{
$connection
=
DB
::
connection
(
$table
->
connection
);
$grammar
=
static
::
grammar
(
$connection
->
driver
()
);
$grammar
=
static
::
grammar
(
$connection
);
// Each grammar has a function that corresponds to the command type
// and is responsible for building that's commands SQL. This lets
...
...
@@ -43,10 +43,10 @@ class Schema {
{
$statements
=
$grammar
->
$method
(
$table
,
$command
);
// Once we have the statements, we will cast them to an array
even
//
though not all of the commands return an array. This is just in
//
case the command needs to run more than one query to do what
//
it needs to do what is requested by the developer
.
// Once we have the statements, we will cast them to an array
//
even though not all of the commands return an array just
//
in case the command needs to run more than one query to
//
do what it needs to do
.
foreach
((
array
)
$statements
as
$statement
)
{
$connection
->
statement
(
$statement
);
...
...
@@ -66,7 +66,7 @@ class Schema {
// If the developer has specified columns for the table and the
// table is not being created, we will assume they simply want
// to add the columns to the table, and will generate an add
// command
for them, adding the columns to the command
.
// command
on the schema automatically
.
if
(
count
(
$table
->
columns
)
>
0
and
!
$table
->
creating
())
{
$command
=
new
Fluent
(
array
(
'type'
=>
'add'
));
...
...
@@ -92,24 +92,26 @@ class Schema {
/**
* Create the appropriate schema grammar for the driver.
*
* @param
string $driver
* @param
Connection $connection
* @return Grammar
*/
public
static
function
grammar
(
$driver
)
public
static
function
grammar
(
Connection
$connection
)
{
$driver
=
$connection
->
driver
();
switch
(
$driver
)
{
case
'mysql'
:
return
new
Schema\Grammars\MySQL
;
return
new
Schema\Grammars\MySQL
(
$connection
)
;
case
'pgsql'
:
return
new
Schema\Grammars\Postgres
;
return
new
Schema\Grammars\Postgres
(
$connection
)
;
case
'sqlsrv'
:
return
new
Schema\Grammars\SQLServer
;
return
new
Schema\Grammars\SQLServer
(
$connection
)
;
case
'sqlite'
:
return
new
Schema\Grammars\SQLite
;
return
new
Schema\Grammars\SQLite
(
$connection
)
;
}
throw
new
\Exception
(
"Schema operations not supported for [
$driver
]."
);
...
...
laravel/database/schema/grammars/grammar.php
View file @
1ec6fc76
...
...
@@ -27,7 +27,11 @@ abstract class Grammar extends \Laravel\Database\Grammar {
// This method is primarily for convenience so we can just pass a
// column or table instance into the wrap method without sending
// in the name each time we need to wrap one of these objects.
if
(
$value
instanceof
Table
or
$value
instanceof
Fluent
)
if
(
$value
instanceof
Table
)
{
return
$this
->
wrap_table
(
$value
->
name
);
}
elseif
(
$value
instanceof
Fluent
)
{
$value
=
$value
->
name
;
}
...
...
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