View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0014336 | mantisbt | bugtracker | public | 2012-06-01 04:28 | 2012-06-16 06:34 |
Reporter | vincent_sels | Assigned To | dregad | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | no change required | ||
Product Version | 1.2.8 | ||||
Summary | 0014336: Don't throw error when using db_fetch_array on empty resultset | ||||
Description | When you execute a query which returns no results, an error is thrown when using db_fetch_array() on it, because the method tries to access the EOF property of an object which in that case is null. By adding an extra check on the passed p_result to see whether it is null, you can safely use db_fetch_array for instance in while loops, without having to always manually check whether or not the result has rows. This makes code more readable and faster. | ||||
Tags | No tags attached. | ||||
db_query/db_query_bound don't allow $p_result to be null - so this check shouldn't be needed as it's an extra function call... |
|
Dregad: assigned to you |
|
@grangeway - it would have been better if you had written this comment in the pull request 4 months ago when rombert asked for your opinion... @vincent_sels, can you comment on grangeway's note, and maybe provide an example case where your fix is actually useful/necessary ? |
|
I don't recall seeing a mail asking for an opinion... apologies if I missed it. but db_query either returns an object or null on failure [ I'm not sure you'd actually hit the function after a failure due to the fact we tend to call trigger error So basically to hit the fact you dont have an object, it looked at first glance that you'd need to call db_fetch_array() on something that didn't come from a return value db_query/db_query_bound - i.e. that would be a bug elsewhere |
|
Looks like grangeway is totally right, db_query_bound doesn't return null as the result set. Probably didn't initialize it somewhere when I thought I did. Feel free to close this and reject the pull request - although I don't think the extra check can do much harm. |
|
Thanks for your feedback. Commit has been reverted. |
|
MantisBT: master 33170d2d 2012-02-07 07:49 Details Diff |
Don't throw error when using db_fetch_array on empty resultset When you execute a query which returns no results, an error is thrown when using db_fetch_array() on it, because the method tries to access the EOF property of an object which in that case is null. By adding an extra check on the passed p_result to see whether it is null, you can safely use db_fetch_array for instance in while loops, without having to always manually check whether or not the result has rows. This makes code more readable and faster. Fixes 0014336 Signed-off-by: Damien Regad <damien.regad@merckgroup.com> |
Affected Issues 0014336 |
|
mod - core/database_api.php | Diff File | ||
MantisBT: master-1.2.x 9b1a282b 2012-02-07 07:49 Details Diff |
Don't throw error when using db_fetch_array on empty resultset When you execute a query which returns no results, an error is thrown when using db_fetch_array() on it, because the method tries to access the EOF property of an object which in that case is null. By adding an extra check on the passed p_result to see whether it is null, you can safely use db_fetch_array for instance in while loops, without having to always manually check whether or not the result has rows. This makes code more readable and faster. Fixes 0014336 Signed-off-by: Damien Regad <damien.regad@merckgroup.com> |
Affected Issues 0014336 |
|
mod - core/database_api.php | Diff File | ||
MantisBT: master-1.2.x 7b087923 2012-06-04 00:13 Details Diff |
Revert "Don't throw error when using db_fetch_array on empty resultset" As per grangeway's comment and confirmed by vincent_sels (original issue's reporter), this change is actually not necessary. This reverts commit 9b1a282b239dea4095863ed71ac9e129592522a2. Affects 0014336 |
Affected Issues 0014336 |
|
mod - core/database_api.php | Diff File | ||
MantisBT: master a12d6b7c 2012-06-04 00:26 Details Diff |
Revert "Don't throw error when using db_fetch_array on empty resultset" As per grangeway's comment and confirmed by vincent_sels (original issue's reporter), this change is actually not necessary. This reverts commit 33170d2d54643e63b1a60b021dcb0cbbb45e4157. Affects 0014336 |
Affected Issues 0014336 |
|
mod - core/database_api.php | Diff File |