Beispiel #1
0
 function testFloatToStr()
 {
     $this->assertEqual('12', jDb::floatToStr(12));
     $this->assertEqual('12.56', jDb::floatToStr(12.56));
     $this->assertEqual('12', jDb::floatToStr("12"));
     $this->assertEqual('12.56', jDb::floatToStr("12.56"));
     $this->assertEqual('65.78E6', jDb::floatToStr("65.78E6"));
     $this->assertEqual('65.78E6', jDb::floatToStr(65780000.0));
     $this->assertEqual('65.78E42', jDb::floatToStr(6.578E+43));
     // not very good behavior, but this is the behavior in old stable version of jelix
     $this->assertEqual('65', jDb::floatToStr("65,650.98"));
     $this->assertEqual('12', jDb::floatToStr("12,589"));
     // ',' no allowed as decimal separator
     $this->assertEqual('96', jDb::floatToStr("96 000,98"));
     // some test to detect if the behavior of PHP change
     $this->assertFalse(is_numeric("65,650.98"));
     $this->assertFalse(is_float("65,650.98"));
     $this->assertFalse(is_integer("65,650.98"));
     $this->assertEqual('65', floatval("65,650.98"));
 }
 /**
  * prepare the value ready to be used in a dynamic evaluation
  */
 protected final function _prepareValue($value, $fieldType, $notNull = false)
 {
     if (!$notNull && $value === null) {
         return 'NULL';
     }
     switch (strtolower($fieldType)) {
         case 'integer':
             return intval($value);
         case 'double':
         case 'float':
         case 'numeric':
         case 'decimal':
             return jDb::floatToStr($value);
         case 'boolean':
             if ($value === true || strtolower($value) == 'true' || intval($value) === 1 || $value === 't' || $value === 'on') {
                 return $this->trueValue;
             } else {
                 return $this->falseValue;
             }
             break;
         default:
             return $this->_conn->quote2($value, true, $fieldType == 'binary');
     }
 }
Beispiel #3
0
 public function escapeValue($unifiedType, $value, $checkNull = false, $toPhpSource = false)
 {
     if ($checkNull && ($value === null || strtolower($value) == 'null')) {
         return 'NULL';
     }
     switch ($this->unifiedToPHPType($unifiedType)) {
         case 'boolean':
             return $this->getBooleanValue($value);
         case 'integer':
             return (string) intval($value);
         case 'float':
         case 'numeric':
         case 'decimal':
             return jDb::floatToStr($value);
         default:
             if ($toPhpSource) {
                 if ($unifiedType == 'varbinary' || $unifiedType == 'binary') {
                     return '\'.$this->_conn->quote2(\'' . str_replace('\'', '\\\'', $value) . '\',true,true).\'';
                 } else {
                     if (strpos($value, "'") !== false) {
                         return '\'.$this->_conn->quote(\'' . str_replace('\'', '\\\'', $value) . '\').\'';
                     } else {
                         return "\\'" . $value . "\\'";
                     }
                 }
             } elseif ($this->_conn) {
                 return $this->_conn->quote($value);
             } else {
                 return "'" . addslashes($value) . "'";
             }
     }
 }