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
0b3e0043
Commit
0b3e0043
authored
Nov 05, 2014
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #709 from deeky666/DBAL-1028
[DBAL-1028] Fix fetching NULL values via fetchColumn()
parents
c6887c12
857b9500
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
15 deletions
+66
-15
DB2Statement.php
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
+4
-3
OCI8Statement.php
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
+5
-1
SQLAnywhereStatement.php
...Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php
+3
-3
SQLSrvStatement.php
lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
+13
-8
DataAccessTest.php
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
+41
-0
No files found.
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
View file @
0b3e0043
...
...
@@ -262,11 +262,12 @@ class DB2Statement implements \IteratorAggregate, Statement
public
function
fetchColumn
(
$columnIndex
=
0
)
{
$row
=
$this
->
fetch
(
\PDO
::
FETCH_NUM
);
if
(
$row
&&
isset
(
$row
[
$columnIndex
]))
{
return
$row
[
$columnIndex
];
if
(
false
===
$row
)
{
return
false
;
}
return
false
;
return
isset
(
$row
[
$columnIndex
])
?
$row
[
$columnIndex
]
:
null
;
}
/**
...
...
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
View file @
0b3e0043
...
...
@@ -289,7 +289,11 @@ class OCI8Statement implements \IteratorAggregate, Statement
{
$row
=
oci_fetch_array
(
$this
->
_sth
,
OCI_NUM
|
OCI_RETURN_NULLS
|
OCI_RETURN_LOBS
);
return
isset
(
$row
[
$columnIndex
])
?
$row
[
$columnIndex
]
:
false
;
if
(
false
===
$row
)
{
return
false
;
}
return
isset
(
$row
[
$columnIndex
])
?
$row
[
$columnIndex
]
:
null
;
}
/**
...
...
lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php
View file @
0b3e0043
...
...
@@ -266,11 +266,11 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
{
$row
=
$this
->
fetch
(
PDO
::
FETCH_NUM
);
if
(
$row
&&
isset
(
$row
[
$columnIndex
])
)
{
return
$row
[
$columnIndex
]
;
if
(
false
===
$row
)
{
return
false
;
}
return
false
;
return
isset
(
$row
[
$columnIndex
])
?
$row
[
$columnIndex
]
:
null
;
}
/**
...
...
lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
View file @
0b3e0043
...
...
@@ -236,18 +236,23 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*/
public
function
fetch
(
$fetchMode
=
null
)
{
$args
=
func_get_args
();
$args
=
func_get_args
();
$fetchMode
=
$fetchMode
?:
$this
->
defaultFetchMode
;
if
(
isset
(
self
::
$fetchMap
[
$fetchMode
]))
{
return
sqlsrv_fetch_array
(
$this
->
stmt
,
self
::
$fetchMap
[
$fetchMode
]);
}
elseif
(
$fetchMode
==
PDO
::
FETCH_OBJ
||
$fetchMode
==
PDO
::
FETCH_CLASS
)
{
return
sqlsrv_fetch_array
(
$this
->
stmt
,
self
::
$fetchMap
[
$fetchMode
])
?:
false
;
}
if
(
$fetchMode
==
PDO
::
FETCH_OBJ
||
$fetchMode
==
PDO
::
FETCH_CLASS
)
{
$className
=
$this
->
defaultFetchClass
;
$ctorArgs
=
$this
->
defaultFetchClassCtorArgs
;
if
(
count
(
$args
)
>=
2
)
{
$className
=
$args
[
1
];
$ctorArgs
=
(
isset
(
$args
[
2
]))
?
$args
[
2
]
:
array
();
$ctorArgs
=
(
isset
(
$args
[
2
]))
?
$args
[
2
]
:
array
();
}
return
sqlsrv_fetch_object
(
$this
->
stmt
,
$className
,
$ctorArgs
);
return
sqlsrv_fetch_object
(
$this
->
stmt
,
$className
,
$ctorArgs
)
?:
false
;
}
throw
new
SQLSrvException
(
"Fetch mode is not supported!"
);
...
...
@@ -287,11 +292,11 @@ class SQLSrvStatement implements IteratorAggregate, Statement
{
$row
=
$this
->
fetch
(
PDO
::
FETCH_NUM
);
if
(
$row
&&
isset
(
$row
[
$columnIndex
])
)
{
return
$row
[
$columnIndex
]
;
if
(
false
===
$row
)
{
return
false
;
}
return
false
;
return
isset
(
$row
[
$columnIndex
])
?
$row
[
$columnIndex
]
:
null
;
}
/**
...
...
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
View file @
0b3e0043
...
...
@@ -767,6 +767,47 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
assertEquals
(
array
(),
$rows
);
}
/**
* @group DBAL-1028
*/
public
function
testFetchColumnNullValue
()
{
$this
->
_conn
->
executeUpdate
(
'INSERT INTO fetch_table (test_int, test_string) VALUES (?, ?)'
,
array
(
1
,
'foo'
)
);
$this
->
assertNull
(
$this
->
_conn
->
fetchColumn
(
'SELECT test_datetime FROM fetch_table WHERE test_int = ?'
,
array
(
1
))
);
}
/**
* @group DBAL-1028
*/
public
function
testFetchColumnNonExistingIndex
()
{
if
(
$this
->
_conn
->
getDriver
()
->
getName
()
===
'pdo_sqlsrv'
)
{
$this
->
markTestSkipped
(
'Test does not work for pdo_sqlsrv driver as it throws a fatal error for a non-existing column index.'
);
}
$this
->
assertNull
(
$this
->
_conn
->
fetchColumn
(
'SELECT test_int FROM fetch_table WHERE test_int = ?'
,
array
(
1
),
1
)
);
}
/**
* @group DBAL-1028
*/
public
function
testFetchColumnNoResult
()
{
$this
->
assertFalse
(
$this
->
_conn
->
fetchColumn
(
'SELECT test_int FROM fetch_table WHERE test_int = ?'
,
array
(
-
1
))
);
}
private
function
setupFixture
()
{
$this
->
_conn
->
executeQuery
(
'DELETE FROM fetch_table'
)
->
execute
();
...
...
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