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
691d68ba
Commit
691d68ba
authored
May 30, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve / fix postgres support.
parent
56c6202d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
73 additions
and
11 deletions
+73
-11
connection.php
laravel/database/connection.php
+10
-0
postgres.php
laravel/database/connectors/postgres.php
+12
-0
model.php
laravel/database/eloquent/model.php
+1
-1
query.php
laravel/database/query.php
+13
-8
grammar.php
laravel/database/query/grammars/grammar.php
+13
-0
postgres.php
laravel/database/query/grammars/postgres.php
+20
-0
postgres.php
laravel/database/schema/grammars/postgres.php
+1
-1
table.php
laravel/database/schema/table.php
+3
-1
No files found.
laravel/database/connection.php
View file @
691d68ba
...
...
@@ -89,6 +89,9 @@ class Connection {
case
'sqlsrv'
:
return
$this
->
grammar
=
new
Query\Grammars\SQLServer
(
$this
);
case
'pgsql'
:
return
$this
->
grammar
=
new
Query\Grammars\Postgres
(
$this
);
default
:
return
$this
->
grammar
=
new
Query\Grammars\Grammar
(
$this
);
}
...
...
@@ -190,6 +193,13 @@ class Connection {
{
return
$statement
->
rowCount
();
}
// For insert statements that use the "returning" clause, which is allowed
// by databsae systems such as Postgres, we need to actually return the
// real query result so the consumer can get the ID.
elseif
(
stripos
(
$sql
,
'insert'
)
===
0
and
stripos
(
$sql
,
'returning'
)
!==
false
)
{
return
$this
->
fetch
(
$statement
,
Config
::
get
(
'database.fetch'
));
}
else
{
return
$result
;
...
...
laravel/database/connectors/postgres.php
View file @
691d68ba
...
...
@@ -2,6 +2,18 @@
class
Postgres
extends
Connector
{
/**
* The PDO connection options.
*
* @var array
*/
protected
$options
=
array
(
PDO
::
ATTR_CASE
=>
PDO
::
CASE_LOWER
,
PDO
::
ATTR_ERRMODE
=>
PDO
::
ERRMODE_EXCEPTION
,
PDO
::
ATTR_ORACLE_NULLS
=>
PDO
::
NULL_NATURAL
,
PDO
::
ATTR_STRINGIFY_FETCHES
=>
false
,
);
/**
* Establish a PDO database connection.
*
...
...
laravel/database/eloquent/model.php
View file @
691d68ba
...
...
@@ -399,7 +399,7 @@ abstract class Model {
// then we can consider the insert successful.
else
{
$id
=
$this
->
query
()
->
insert_get_id
(
$this
->
attributes
,
$this
->
sequence
());
$id
=
$this
->
query
()
->
insert_get_id
(
$this
->
attributes
,
$this
->
key
());
$this
->
set_key
(
$id
);
...
...
laravel/database/query.php
View file @
691d68ba
...
...
@@ -3,6 +3,7 @@
use
Closure
;
use
Laravel\Database
;
use
Laravel\Paginator
;
use
Laravel\Database\Query\Grammars\Postgres
;
use
Laravel\Database\Query\Grammars\SQLServer
;
class
Query
{
...
...
@@ -751,19 +752,23 @@ class Query {
* Insert an array of values into the database table and return the ID.
*
* @param array $values
* @param string $
sequence
* @param string $
column
* @return int
*/
public
function
insert_get_id
(
$values
,
$
sequence
=
null
)
public
function
insert_get_id
(
$values
,
$
column
=
'id'
)
{
$sql
=
$this
->
grammar
->
insert
(
$this
,
$values
);
$sql
=
$this
->
grammar
->
insert
_get_id
(
$this
,
$values
,
$column
);
$this
->
connection
->
query
(
$sql
,
array_values
(
$values
));
$
result
=
$
this
->
connection
->
query
(
$sql
,
array_values
(
$values
));
// Some database systems (Postgres) require a sequence name to be
// given when retrieving the auto-incrementing ID, so we'll pass
// the given sequence into the method just in case.
return
(
int
)
$this
->
connection
->
pdo
->
lastInsertId
(
$sequence
);
if
(
$this
->
grammar
instanceof
Postgres
)
{
return
(
int
)
$result
[
0
]
->
$column
;
}
else
{
return
(
int
)
$this
->
connection
->
pdo
->
lastInsertId
();
}
}
/**
...
...
laravel/database/query/grammars/grammar.php
View file @
691d68ba
...
...
@@ -375,6 +375,19 @@ class Grammar extends \Laravel\Database\Grammar {
return
"INSERT INTO
{
$table
}
(
{
$columns
}
) VALUES
{
$parameters
}
"
;
}
/**
* Compile a SQL INSERT and get ID statment from a Query instance.
*
* @param Query $query
* @param array $values
* @param string $column
* @return string
*/
public
function
insert_get_id
(
Query
$query
,
$values
,
$column
)
{
return
$this
->
insert
(
$query
,
$values
);
}
/**
* Compile a SQL UPDATE statment from a Query instance.
*
...
...
laravel/database/query/grammars/postgres.php
0 → 100644
View file @
691d68ba
<?php
namespace
Laravel\Database\Query\Grammars
;
use
Laravel\Database\Query
;
class
Postgres
extends
Grammar
{
/**
* Compile a SQL INSERT and get ID statment from a Query instance.
*
* @param Query $query
* @param array $values
* @param string $column
* @return string
*/
public
function
insert_get_id
(
Query
$query
,
$values
,
$column
)
{
return
$this
->
insert
(
$query
,
$values
)
.
" RETURNING
$column
"
;
}
}
\ No newline at end of file
laravel/database/schema/grammars/postgres.php
View file @
691d68ba
...
...
@@ -324,7 +324,7 @@ class Postgres extends Grammar {
*/
protected
function
type_integer
(
Fluent
$column
)
{
return
(
$column
->
increment
)
?
'SERIAL'
:
'
INTEGER
'
;
return
(
$column
->
increment
)
?
'SERIAL'
:
'
BIGINT
'
;
}
/**
...
...
laravel/database/schema/table.php
View file @
691d68ba
...
...
@@ -136,7 +136,9 @@ class Table {
// the index that can be used when dropping indexes.
if
(
is_null
(
$name
))
{
$name
=
$this
->
name
.
'_'
.
implode
(
'_'
,
$columns
)
.
'_'
.
$type
;
$name
=
str_replace
(
array
(
'-'
,
'.'
),
'_'
,
$this
->
name
);
$name
=
$name
.
'_'
.
implode
(
'_'
,
$columns
)
.
'_'
.
$type
;
}
return
$this
->
command
(
$type
,
compact
(
'name'
,
'columns'
));
...
...
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