Exemple #1
0
 /**
  * return the SQL string corresponding to the given column.
  * private method, should be used only by a jDbTable object
  * @param jDbColumn $col  the column
  * @return string the sql string
  * @access private
  */
 function _prepareSqlColumn($col)
 {
     $this->normalizeColumn($col);
     $colstr = $this->conn->encloseName($col->name) . ' ' . $col->nativeType;
     if ($col->length) {
         $colstr .= '(' . $col->length . ')';
     }
     $colstr .= $col->notNull ? ' NOT NULL' : ' NULL';
     if ($col->hasDefault && !$col->autoIncrement) {
         if (!($col->notNull && $col->default === null)) {
             if ($col->default === null) {
                 $colstr .= ' DEFAULT NULL';
             } else {
                 $colstr .= ' DEFAULT ' . $this->conn->quote($col->default);
             }
         }
     }
     return $colstr;
 }
 /**
  * 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 'int':
         case 'integer':
         case 'autoincrement':
             $value = intval($value);
             break;
         case 'double':
         case 'float':
             $value = doubleval($value);
             break;
         case 'numeric':
             //usefull for bigint and stuff
         //usefull for bigint and stuff
         case 'bigautoincrement':
             if (is_numeric($value)) {
                 //was numeric, we can sends it as is
                 // no cast with intval else overflow
                 return $value;
             } else {
                 //not a numeric, nevermind, casting it
                 return intval($value);
             }
             break;
         case 'boolean':
             if ($value === true || strtolower($value) == 'true' || $value == '1' || $value === 't') {
                 $value = $this->trueValue;
             } else {
                 $value = $this->falseValue;
             }
             break;
         default:
             $value = $this->_conn->quote($value, true, $fieldType == 'varbinary');
     }
     return $value;
 }
Exemple #3
0
 /**
  * @param string $unifiedType  the unified type name
  * @param mixed $value        the value
  * @return string  the value which is ready to include a SQL query string
  * @since 1.2
  */
 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) . "'";
             }
     }
 }