Welcome Guest, Not a member yet? Register   Sign In
Prepared Query with an Update Statement Fails
#1

(This post was last modified: 09-21-2022, 12:04 PM by CMGodfather. Edit Reason: Submitted before finishing the post. The site went nuts when I hit the tab key. )

I'm using version 4.2.3 of the framework and I think I've found a bug in the framework within the BaseBuilder class when trying to use a prepared statement for an update action. My example is below. The problem appears to be with the way the query builder operates. The insert equivalent function in the builder returns a results object; however, the update function returns a boolean only. I believe the core needs to return a result object for the update function as well in the similar location as the insert. I've tested doing just that in my project and it works but I'm not certain where this would break other core functionality within the framework. I'd appreciate it if someone can help get this potential bug reported or explain why in the core framework that prepared update statements don't work. See the update and compare it to the insert function within the BaseBuilder.

PHP Code:
$newFieldVal 'newVal';
$idVal 1;
$pQuery = $db->prepare(static function($db)
{
    return $db->table('test_table')->update(['field1' => ''], ['id' => '']); 
});
$pQuery->execute($newFieldVal$idVal);
$pQuery->close(); 

More info:
I'm using a Microsoft SQL Server database. These issues seem to be related to unfamiliarity with such the SQLSRV driver. Upon further inspection, there seems to be issues running select statements as a prepared query as well. The results will not be returned because the results are actually in the statement object that gets generated by the driver. The CI framework needs to return the statement in the _getResult method in the SQLSRV version of the PreparedQuery class. This will allow retrieving the results from a PreparedQuery SELECT statement.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB