Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Tomáš Trávníček
doctrine-dbal
Commits
7aabee5e
Commit
7aabee5e
authored
Sep 08, 2009
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Fixing empty insert sql statements (closes #2481)
parent
7c56bfa1
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
139 additions
and
15 deletions
+139
-15
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+12
-0
MsSqlPlatform.php
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
+12
-0
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+12
-0
ClassMetadataFactory.php
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
+11
-4
StandardEntityPersister.php
lib/Doctrine/ORM/Persisters/StandardEntityPersister.php
+13
-11
AllTests.php
tests/Doctrine/Tests/ORM/Functional/AllTests.php
+1
-0
AllTests.php
tests/Doctrine/Tests/ORM/Functional/Ticket/AllTests.php
+34
-0
Ticket2481Test.php
...s/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php
+44
-0
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
7aabee5e
...
@@ -1580,4 +1580,16 @@ abstract class AbstractPlatform
...
@@ -1580,4 +1580,16 @@ abstract class AbstractPlatform
{
{
return
$schemaElementName
;
return
$schemaElementName
;
}
}
/**
* 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)'
;
}
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Platforms/MsSqlPlatform.php
View file @
7aabee5e
...
@@ -506,4 +506,16 @@ class MsSqlPlatform extends AbstractPlatform
...
@@ -506,4 +506,16 @@ class MsSqlPlatform extends AbstractPlatform
return
$query
;
return
$query
;
}
}
/**
* Get the insert sql for an empty insert statement
*
* @param string $tableName
* @param string $identifierColumnName
* @return string $sql
*/
public
function
getEmptyIdentityInsertSql
(
$quotedTableName
,
$quotedIdentifierColumnName
)
{
return
'INSERT INTO '
.
$quotedTableName
.
' DEFAULT VALUES'
;
}
}
}
\ No newline at end of file
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
7aabee5e
...
@@ -770,4 +770,16 @@ class PostgreSqlPlatform extends AbstractPlatform
...
@@ -770,4 +770,16 @@ class PostgreSqlPlatform extends AbstractPlatform
{
{
return
'Y-m-d H:i:sO'
;
return
'Y-m-d H:i:sO'
;
}
}
/**
* Get the insert sql for an empty insert statement
*
* @param string $tableName
* @param string $identifierColumnName
* @return string $sql
*/
public
function
getEmptyIdentityInsertSql
(
$quotedTableName
,
$quotedIdentifierColumnName
)
{
return
'INSERT INTO '
.
$quotedTableName
.
' ('
.
$quotedIdentifierColumnName
.
') VALUES (DEFAULT)'
;
}
}
}
\ No newline at end of file
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
View file @
7aabee5e
...
@@ -369,10 +369,17 @@ class ClassMetadataFactory
...
@@ -369,10 +369,17 @@ class ClassMetadataFactory
$class
->
resultColumnNames
[
$this
->
_targetPlatform
->
getSqlResultCasing
(
$columnName
)]
=
$columnName
;
$class
->
resultColumnNames
[
$this
->
_targetPlatform
->
getSqlResultCasing
(
$columnName
)]
=
$columnName
;
}
}
$class
->
insertSql
=
'INSERT INTO '
.
if
(
empty
(
$columns
))
{
$class
->
getQuotedTableName
(
$this
->
_targetPlatform
)
$class
->
insertSql
=
$this
->
_targetPlatform
->
getEmptyIdentityInsertSql
(
.
' ('
.
implode
(
', '
,
$columns
)
.
') '
$class
->
getQuotedTableName
(
$this
->
_targetPlatform
),
.
'VALUES ('
.
implode
(
', '
,
$values
)
.
')'
;
$class
->
getQuotedColumnName
(
$class
->
identifier
[
0
],
$this
->
_targetPlatform
)
);
}
else
{
$class
->
insertSql
=
'INSERT INTO '
.
$class
->
getQuotedTableName
(
$this
->
_targetPlatform
)
.
' ('
.
implode
(
', '
,
$columns
)
.
') '
.
'VALUES ('
.
implode
(
', '
,
$values
)
.
')'
;
}
}
}
/**
/**
...
...
lib/Doctrine/ORM/Persisters/StandardEntityPersister.php
View file @
7aabee5e
...
@@ -139,17 +139,19 @@ class StandardEntityPersister
...
@@ -139,17 +139,19 @@ class StandardEntityPersister
$insertData
=
array
();
$insertData
=
array
();
$this
->
_prepareData
(
$entity
,
$insertData
,
true
);
$this
->
_prepareData
(
$entity
,
$insertData
,
true
);
$paramIndex
=
1
;
if
(
isset
(
$insertData
[
$primaryTableName
]))
{
if
(
$sqlLogger
)
{
$paramIndex
=
1
;
$params
=
array
();
if
(
$sqlLogger
)
{
foreach
(
$insertData
[
$primaryTableName
]
as
$value
)
{
$params
=
array
();
$params
[
$paramIndex
]
=
$value
;
foreach
(
$insertData
[
$primaryTableName
]
as
$value
)
{
$stmt
->
bindValue
(
$paramIndex
++
,
$value
);
$params
[
$paramIndex
]
=
$value
;
}
$stmt
->
bindValue
(
$paramIndex
++
,
$value
);
$sqlLogger
->
logSql
(
$this
->
_class
->
insertSql
,
$params
);
}
}
else
{
$sqlLogger
->
logSql
(
$this
->
_class
->
insertSql
,
$params
);
foreach
(
$insertData
[
$primaryTableName
]
as
$value
)
{
}
else
{
$stmt
->
bindValue
(
$paramIndex
++
,
$value
);
foreach
(
$insertData
[
$primaryTableName
]
as
$value
)
{
$stmt
->
bindValue
(
$paramIndex
++
,
$value
);
}
}
}
}
}
...
...
tests/Doctrine/Tests/ORM/Functional/AllTests.php
View file @
7aabee5e
...
@@ -43,6 +43,7 @@ class AllTests
...
@@ -43,6 +43,7 @@ class AllTests
$suite
->
addTest
(
Locking\AllTests
::
suite
());
$suite
->
addTest
(
Locking\AllTests
::
suite
());
$suite
->
addTest
(
SchemaTool\AllTests
::
suite
());
$suite
->
addTest
(
SchemaTool\AllTests
::
suite
());
$suite
->
addTest
(
Ticket\AllTests
::
suite
());
return
$suite
;
return
$suite
;
}
}
...
...
tests/Doctrine/Tests/ORM/Functional/Ticket/AllTests.php
0 → 100644
View file @
7aabee5e
<?php
namespace
Doctrine\Tests\ORM\Functional\Ticket
;
if
(
!
defined
(
'PHPUnit_MAIN_METHOD'
))
{
define
(
'PHPUnit_MAIN_METHOD'
,
'Orm_Functional_Ticket_AllTests::main'
);
}
require_once
__DIR__
.
'/../../../TestInit.php'
;
class
AllTests
{
public
static
function
main
()
{
\PHPUnit_TextUI_TestRunner
::
run
(
self
::
suite
());
}
public
static
function
suite
()
{
$suite
=
new
\Doctrine\Tests\OrmFunctionalTestSuite
(
'Doctrine Orm Ticket Tests'
);
$tests
=
glob
(
__DIR__
.
'/Ticket*Test.php'
);
foreach
(
$tests
as
$test
)
{
$info
=
pathinfo
(
$test
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Functional\Ticket\\'
.
$info
[
'filename'
]);
}
return
$suite
;
}
}
if
(
PHPUnit_MAIN_METHOD
==
'Orm_Functional_Ticket_AllTests::main'
)
{
AllTests
::
main
();
}
tests/Doctrine/Tests/ORM/Functional/Ticket/Ticket2481Test.php
0 → 100644
View file @
7aabee5e
<?php
namespace
Doctrine\Tests\ORM\Functional\Ticket
;
require_once
__DIR__
.
'/../../../TestInit.php'
;
class
Ticket2481Test
extends
\Doctrine\Tests\OrmFunctionalTestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
try
{
$this
->
_schemaTool
->
createSchema
(
array
(
$this
->
_em
->
getClassMetadata
(
'Doctrine\Tests\ORM\Functional\Ticket\Ticket2481Product'
)
));
}
catch
(
\Exception
$e
)
{
// Swallow all exceptions. We do not test the schema tool here.
}
$this
->
_conn
=
$this
->
_em
->
getConnection
();
}
public
function
testEmptyInsert
()
{
$test
=
new
Ticket2481Product
();
$this
->
_em
->
persist
(
$test
);
$this
->
_em
->
flush
();
$this
->
assertTrue
(
$test
->
id
>
0
);
}
}
/**
* @Entity
* @Table(name="ticket_2481_products")
*/
class
Ticket2481Product
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
public
$id
;
}
\ No newline at end of file
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