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
cc1aeec9
Commit
cc1aeec9
authored
Oct 27, 2014
by
Steve Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix fetching NULL values via fetchColumn()
parent
d1267280
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
12 deletions
+63
-12
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
+10
-5
DataAccessTest.php
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
+41
-0
No files found.
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
View file @
cc1aeec9
...
...
@@ -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 @
cc1aeec9
...
...
@@ -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 @
cc1aeec9
...
...
@@ -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 @
cc1aeec9
...
...
@@ -239,7 +239,9 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$args
=
func_get_args
();
$fetchMode
=
$fetchMode
?:
$this
->
defaultFetchMode
;
if
(
isset
(
self
::
$fetchMap
[
$fetchMode
]))
{
return
sqlsrv_fetch_array
(
$this
->
stmt
,
self
::
$fetchMap
[
$fetchMode
]);
$rows
=
sqlsrv_fetch_array
(
$this
->
stmt
,
self
::
$fetchMap
[
$fetchMode
]);
return
$rows
?:
false
;
}
elseif
(
$fetchMode
==
PDO
::
FETCH_OBJ
||
$fetchMode
==
PDO
::
FETCH_CLASS
)
{
$className
=
$this
->
defaultFetchClass
;
$ctorArgs
=
$this
->
defaultFetchClassCtorArgs
;
...
...
@@ -247,7 +249,10 @@ class SQLSrvStatement implements IteratorAggregate, Statement
$className
=
$args
[
1
];
$ctorArgs
=
(
isset
(
$args
[
2
]))
?
$args
[
2
]
:
array
();
}
return
sqlsrv_fetch_object
(
$this
->
stmt
,
$className
,
$ctorArgs
);
$rows
=
sqlsrv_fetch_object
(
$this
->
stmt
,
$className
,
$ctorArgs
);
return
$rows
?:
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 @
cc1aeec9
...
...
@@ -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