Ejemplo n.º 1
0
 public function Test_of_compress_decompress()
 {
     $original = file_get_contents(__FILE__);
     $compressed = Ak::compress($original);
     file_put_contents(AK_TMP_DIR . DS . 'gzip_test.gz', $compressed);
     $this->assertTrue(strlen($compressed) < strlen($original));
     $compressed_file = file_get_contents(AK_TMP_DIR . DS . 'gzip_test.gz');
     $this->assertEqual($compressed_file, $compressed);
     $uncompressed_from_file = Ak::uncompress($compressed_file);
     $uncompressed_from_string = Ak::uncompress($compressed);
     $this->assertEqual($uncompressed_from_file, $uncompressed_from_string);
 }
Ejemplo n.º 2
0
 public function castAttributeForDatabase($column_name, $value, $add_quotes = true)
 {
     $result = '';
     switch ($this->getColumnType($column_name)) {
         case 'datetime':
             if (!empty($value)) {
                 $date_time = $this->_db->quote_datetime(Ak::getTimestamp($value));
                 $result = $add_quotes ? $date_time : trim($date_time, "'");
             } else {
                 $result = 'null';
             }
             break;
         case 'date':
             if (!empty($value)) {
                 $date = $this->_db->quote_date(Ak::getTimestamp($value));
                 $result = $add_quotes ? $date : trim($date, "'");
             } else {
                 $result = 'null';
             }
             break;
         case 'boolean':
             $result = is_null($value) ? 'null' : (!empty($value) ? "'1'" : "'0'");
             break;
         case 'binary':
             if (!empty($value) && $this->_shouldCompressColumn($column_name)) {
                 $value = Ak::compress($value);
             }
             if ($this->getDatabaseType() == 'postgre') {
                 $result = is_null($value) ? 'null::bytea ' : " '" . $this->_db->escape_blob($value) . "'::bytea ";
             } else {
                 $result = is_null($value) ? 'null' : ($add_quotes ? $this->_db->quote_string($value) : $value);
             }
             break;
         case 'decimal':
             if (is_null($value)) {
                 $result = 'null';
             } else {
                 if ($scale = $this->getColumnScale($column_name)) {
                     $value = number_format($value, $scale, '.', '');
                 }
                 $result = $add_quotes ? $this->_db->quote_string($value) : $value;
             }
             break;
         case 'serial':
         case 'integer':
             $result = is_null($value) || $value === '' ? 'null' : (int) $value;
             break;
         case 'float':
             $result = empty($value) && $value !== 0 ? 'null' : (is_numeric($value) ? $value : $this->_db->quote_string($value));
             $result = !empty($this->_columns[$column_name]['notNull']) && $result == 'null' && $this->getDatabaseType() == 'sqlite' ? '0' : $result;
             break;
         default:
             if ($this->_shouldSerializeColumn($column_name)) {
                 $value = serialize($value);
             }
             $result = is_null($value) ? 'null' : ($add_quotes ? $this->_db->quote_string($value) : $value);
             break;
     }
     //  !! nullable vs. not nullable !!
     return empty($this->_columns[$column_name]['notNull']) ? $result === '' ? "''" : $result : ($result === 'null' ? '' : $result);
 }