? Failure

User tests: Successful: Unsuccessful:

avatar alikon
alikon
3 Dec 2017

as per comment on #18915 (comment)

JDatabaseQuery doesn't implement castAsInteger

Summary of Changes

implement castAsInteger() like sql CAST('field' AS integer)

Testing Instructions

$query->select($query->castAsInteger('field'))
same Testing Instructions as #18915

Expected result

implemented

Actual result

JDatabaseQuery doesn't implement castAsInteger()

avatar alikon alikon - open - 3 Dec 2017
avatar alikon alikon - change - 3 Dec 2017
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 3 Dec 2017
Category Libraries Postgresql MS SQL
avatar GeraintEdwards
GeraintEdwards - comment - 3 Dec 2017

How do I test this? it works for mySQL and Postgres and is consistent with the documentation.

One thought though, if we use it to match int(11) ids then the cast should be to a 'bigint' in Postgres and MS SQL ??

avatar wilsonge
wilsonge - comment - 4 Dec 2017

Probably the easiest way to test this is if @alikon implements it in your code we merged yesterday :)

avatar GeraintEdwards
GeraintEdwards - comment - 4 Dec 2017

@wilsonge What I meant was - should there be some sort of unit test for a library method such as this? Do we need to test it in extremis as per my observation about matching int(11) values (does it truncate and missmatch in this circumstance?).

There is a unit test for caseAsChar - I've never looked at the unit tests for Joomla before so not sure where to start about creating a new one/extending the ones that are there

avatar wilsonge
wilsonge - comment - 4 Dec 2017

Unit tests are easy when you know how. I can do a skype/hangout or whatever and take you through if you have a free 15 minutes? Always good to spread the knowledge :)

avatar alikon
alikon - comment - 5 Dec 2017
  • for the BIGINT we can mimic SQL CAST() with a new method castAsBigint() with a new pr
  • i'll add the use of castAsInteger() to the search plugin in this pr
avatar alikon alikon - change - 5 Dec 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - change - 5 Dec 2017
Category Libraries Postgresql MS SQL Libraries Postgresql MS SQL Front End Plugins
avatar alikon alikon - change - 5 Dec 2017
The description was changed
avatar alikon alikon - edited - 5 Dec 2017
avatar alikon
alikon - comment - 5 Dec 2017

can be tested like #18915

avatar mbabker
mbabker - comment - 21 Jul 2018

Can we come up with a more general cast helper than just implementing castAsFoo methods each time we need something?

avatar franz-wohlkoenig franz-wohlkoenig - change - 21 Jul 2018
Status Pending Information Required
avatar alikon
alikon - comment - 21 Jul 2018

did you mean something like this ?

	public function castAs($type, $value, $len = null, $scale = null)
	{
		switch ($type)
		{
			case 'CHAR':
				if (!$len)
				{
					return $value;
				}
				else
				{
					return ' CAST(' . $value . ' AS CHAR(' . $len . '))';
				}
				break;

			case 'INTEGER':
				return ' ('. $value . ' + 0) ';
				break;

			case 'DECIMAL':
				if ((!$len) && (!scale))
				{
					return $value;
				}
				else
				{
					return ' CAST(' . $value . ' AS DECIMAL(' . $len . ', ' . $scale . '))';
				}
				break;

			case 'DATE':
			    //
			case 'TIME':
			   //
			case 'DATETIME':
			   //
		}
	}
avatar franz-wohlkoenig franz-wohlkoenig - change - 21 Jul 2018
Status Information Required Pending
avatar mbabker
mbabker - comment - 21 Jul 2018

That looks nice.

avatar franz-wohlkoenig franz-wohlkoenig - change - 19 Apr 2019
Title
[SQL] - improve CAST() with CAST('field' AS integer)
improve CAST() with CAST('field' AS integer)
avatar franz-wohlkoenig franz-wohlkoenig - edited - 19 Apr 2019
avatar alikon alikon - change - 3 Aug 2019
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2019-08-03 10:09:54
Closed_By alikon
Labels Removed: J3 Issue
avatar alikon alikon - close - 3 Aug 2019

Add a Comment

Login with GitHub to post a comment