joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

[4.2] Missing ParameterType::DOUBLE in case of prepared statements

Open sandewt opened this issue 3 years ago • 4 comments

Steps to reproduce the issue

Use the ParameterType::DOUBLE

Expected result

No error message

Actual result

Error message: Undefined class constant 'DOUBLE'

System information (as much as possible)

J4.x

Additional comments

Honestly I don't know if this is really a bug, but a conscious choice of Joomla design in the past.

sandewt avatar Sep 09 '22 07:09 sandewt

It's a kinda conscious choice. The parameter types are a way for us to backport PDO's parameter types into the other languages. Double isn't one of these types (the 5 we have are a mapping to the non-php 7.2 param types here https://www.php.net/manual/en/pdo.constants.php) so we've not done anything special for it

wilsonge avatar Sep 10 '22 22:09 wilsonge

@wilsonge

1) Joomla has defined the following parameters:

JOOMLA\libraries\vendor\joomla\database\src\Sqlsrv\SqlsrvStatement.php

protected $parameterTypeMapping = [ ParameterType::BOOLEAN => ParameterType::BOOLEAN, ParameterType::INTEGER => ParameterType::INTEGER, ParameterType::LARGE_OBJECT => ParameterType::LARGE_OBJECT, ParameterType::NULL => ParameterType::NULL, ParameterType::STRING => ParameterType::STRING, ];

2) I compare the Joomla parameters with the following:

https://www.php.net/manual/en/mysqli-stmt.bind-param.php

i corresponding variable has type integer d corresponding variable has type double s corresponding variable has type string b corresponding variable is a blob and will be sent in packets

3) That's why I started this issue. But I may be seeing this wrong.

sandewt avatar Sep 11 '22 06:09 sandewt

you do realise that the first file you reference is for sql server?

brianteeman avatar Sep 11 '22 06:09 brianteeman

This is an example of what I mean. The ParameterType::DOUBLE is not available.

$test = (float) $value; // e.g. $value = 2.2311

$query = $db->getQuery(true)
	->select($db->quoteName('id'))
	->from($db->quoteName('#__example'))
	->where($db->quoteName('test') . ' = :test')
	->bind(':test', $test, ParameterType::DOUBLE);
$db->setQuery($query);
$db->execute();


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38730.

sandewt avatar Sep 12 '22 08:09 sandewt

Closed

sandewt avatar Jan 31 '23 17:01 sandewt