Open Source PHP RAD Framework with UI.

problem with invokeQueryWith() function while using % as part of the query e.g. Select DATE_FORMAT(trigger_time, '%Y%m%dT%T') as trigger_time from abc;

Reported by Hiteshbhai on 2012-12-17
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PHPDevShell
Low
Greg

Bug Description

Issue:
=====

This is the issue we found during our project development using invokeQueryWith() function to invoke a query which involve % sign as part of query.

 e.g. Select DATE_FORMAT(trigger_time, '%Y%m%dT%T') as trigger_time from abc;

It's giving error:
 ../phpdevshell/includes/PHPDS_utils.inc.php(543): vsprintf('???SELECT????jo...', Array)
Excetion -->vsprintf(): Too few arguments

Explanation:
=========

  The issue is we use vsprintf to replace named parameters in query with arguments passed in query. The syntax of query required '%(abcd)s' format to specify the replacement parameter. Internally, phpdevshell try to mach that replacement parameters and replace it using vsprintf function.
 Somehow there is a bug in vsprintf() method of php and it tries to replace parameters with arguments pass to query starting with whereever it sees % sign within the query. Hench forth it runs sort of replacement arguments or endup replacing arguments at wrong place and throwing error: vsprintf(): Too few arguments

Solution:
=======

  Solution 1:
 -------------- Report bug to php to fix it in vsprintf()

Solution 2:
----------------

  Update documentation of phpdevshell database part, to update users to precede % with another % sign as escape character while executing query involving named parameters.

   e.g. Original Query: Select DATE_FORMAT(trigger_time, '%Y%m%dT%T') as trigger_time from abc; where id=%(arg_id)u

   New Query:
                Select DATE_FORMAT(trigger_time, '%%Y%%m%%dT%%T') as trigger_time from abc; where id=%(arg_id)u

felt necessary report to save others wasting time to debug the code

thanks,
Hitesh

Greg (gregfr) wrote :

Thanks for your contribution.

Your solution #2 is the correct one.

However, I'll study the framework function to see if it can be determined at runtime without too much penalty on the performances.

Changed in phpdevshell:
importance: Undecided → Low
status: New → Triaged
assignee: nobody → Greg (gregfr)
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers