Exemple #1
0
 /**
  * 
  * Check if a value validates against the 'timestamp' data type.
  * 
  * @static
  * 
  * @access public
  * 
  * @param mixed $value The value to validate.
  * 
  * @return boolean True if the value is valid for the data type, false
  * if not.
  * 
  */
 function isTimestamp($value)
 {
     // yyyy-mm-dd hh:ii:ss
     // 0123456789012345678
     $date = substr($value, 0, 10);
     $sep = substr($value, 10, 1);
     $time = substr($value, 11, 8);
     if (strlen($value) != 19 || $sep != ' ' || !DB_Table_Valid::isDate($date) || !DB_Table_Valid::isTime($time)) {
         return false;
     } else {
         return true;
     }
 }
Exemple #2
0
 /**
  * 
  * Checks if a value validates against the DB_Table data type for a
  * given column. This only checks that it matches the data type; it
  * does not do extended validation.
  * 
  * @access public
  * 
  * @param array $val A value to check against the column's DB_Table
  * data type.
  * 
  * @param array $col A column name from $this->col.
  * 
  * @return boolean True if the value validates (matches the
  * data type), false if not.
  * 
  * @see DB_Table_Valid
  * 
  */
 function isValid($val, $col)
 {
     // is the value null?
     if (is_null($val)) {
         // is the column required?
         if ($this->isRequired($col)) {
             // yes, so not valid
             return false;
         } else {
             // not required, so it's valid
             return true;
         }
     }
     // make sure we have the validation class
     include_once 'DB/Table/Valid.php';
     // validate values per the column type.  we use sqlite
     // as the single authentic list of allowed column types,
     // regardless of the actual rdbms being used.
     $map = array_keys($GLOBALS['_DB_TABLE']['type']['sqlite']);
     // is the column type on the map?
     if (!in_array($this->col[$col]['type'], $map)) {
         return $this->throwError(DB_TABLE_ERR_VALIDATE_TYPE, "'{$col}' ('{$this->col[$col]['type']}')");
     }
     // validate for the type
     switch ($this->col[$col]['type']) {
         case 'char':
         case 'varchar':
             $result = DB_Table_Valid::isChar($val, $this->col[$col]['size']);
             break;
         case 'decimal':
             $result = DB_Table_Valid::isDecimal($val, $this->col[$col]['size'], $this->col[$col]['scope']);
             break;
         default:
             $result = call_user_func(array('DB_Table_Valid', 'is' . ucwords($this->col[$col]['type'])), $val);
             break;
     }
     // have we passed the check so far, and should we
     // also check for allowed values?
     if ($result && isset($this->col[$col]['qf_vals'])) {
         $keys = array_keys($this->col[$col]['qf_vals']);
         $result = in_array($val, array_keys($this->col[$col]['qf_vals']));
     }
     return $result;
 }