CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 CCToSQL with ccsInteger returns float

Print topic Send  topic

Author Message
Bart00

Posts: 8
Posted: 03/05/2010, 7:18 AM

Today I tried to check if an array key exists:

  
$id = CCToSQL(CCGetFromGet('id'), ccsInteger);  
if (array_key_exists($id, $testArray)) {  
  // do smth.  
}  

This code doesn't work, because array_key_exists expects either an int or a string, instead CCToSQL returns a float. Should this be changed?

  
function CCToSQL($Value, $ValueType) {  
  if(!strlen($Value)) {  
    return "NULL";  
  }  
  else {  
    if($ValueType == ccsInteger) {  
      return intval($Value);  
    }  
    else if ($ValueType == ccsFloat) {  
      return doubleval(str_replace(",", ".", $Value));  
    }  
    else {  
      return "'" . str_replace("'", "''", $Value) . "'";  
    }  
  }  
}  
View profile  Send private message
datadoit
Posted: 03/05/2010, 11:36 AM

What does it do if you:

$id = (int) CCToSQL(CCGetFromGet('id'), ccsInteger);
Bart00

Posts: 8
Posted: 03/05/2010, 12:55 PM

Quote datadoit:
What does it do if you:

$id = (int) CCToSQL(CCGetFromGet('id'), ccsInteger);


Well yea, that would work, but it makes no sense, IMO. I'm asking for an Integer, so I expect one...
View profile  Send private message
datadoit
Posted: 03/07/2010, 12:41 PM

The (int) is telling CCS you want an integer DAMMIT! :)

I agree - repost this to the wishes forum and I'll second it.
Bart00

Posts: 8
Posted: 03/09/2010, 5:47 AM

I reposted it :)
View profile  Send private message
rho


Posts: 85
Posted: 03/16/2010, 2:37 AM

The behavior of the CCToSQL() function is to format a datatype to be used in an SQL-statement. For example, adding single quotes around text. Therefore, the function should not be used to do typecasting of any sort.

Rob.
View profile  Send private message
Bart00

Posts: 8
Posted: 04/23/2010, 1:34 AM

I bumped into this issue again, and this time it has nothing to do with my using this function to do typecasting:

I have a checkbox list, with a ListOfValues "0;f;1;m", data type Integer. In my code I want to see if the value is allowed:

if ($Component->gender->getValue() !== 0 && $Component->gender->getValue() !== 1) {
$Component->gender->Errors->AddError( "Please select" );
}

even if $Component->gender->getValue() is 0, this if() block evaluates false, because $Component->gender->getValue() is float(0), rather than int(0). I actually have to test against 0.0 and 1.0 to make this work.

To me this makes no sense, as I'm requesting an Integer
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.