1
0
mirror of synced 2024-12-14 07:06:04 +03:00

Gzip datatype added

This commit is contained in:
zYne 2006-09-20 15:46:25 +00:00
parent ed1f7aca93
commit 43980029d4
5 changed files with 49 additions and 5 deletions

View File

@ -68,6 +68,7 @@ class Doctrine_DataDict {
case "array": case "array":
case "object": case "object":
case "string": case "string":
case "gzip":
if($length <= 255) if($length <= 255)
return "C($length)"; return "C($length)";
elseif($length <= 4000) elseif($length <= 4000)

View File

@ -274,7 +274,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* *
* @return integer * @return integer
*/ */
private function cleanData() { private function cleanData($debug = false) {
$tmp = $this->data; $tmp = $this->data;
$this->data = array(); $this->data = array();
@ -303,8 +303,19 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->data[$name] = $value; $this->data[$name] = $value;
} }
break; break;
case "enum": case "gzip":
if($tmp[$name] !== self::$null) {
$value = gzuncompress($tmp[$name]);
if($value === false)
throw new Doctrine_Record_Exception("Uncompressing of $name failed.");
$this->data[$name] = $value;
}
break;
case "enum":
$this->data[$name] = $this->table->enumValue($name, $tmp[$name]); $this->data[$name] = $this->table->enumValue($name, $tmp[$name]);
break; break;
default: default:
@ -314,6 +325,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
} }
} }
return $count; return $count;
} }
/** /**
@ -500,7 +512,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->data = array_change_key_case($this->data, CASE_LOWER); $this->data = array_change_key_case($this->data, CASE_LOWER);
$this->modified = array(); $this->modified = array();
$this->cleanData(); $this->cleanData(true);
$this->prepareIdentifiers(); $this->prepareIdentifiers();
@ -864,7 +876,10 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
case 'array': case 'array':
case 'object': case 'object':
$a[$v] = serialize($this->data[$v]); $a[$v] = serialize($this->data[$v]);
break;; break;
case 'gzip':
$a[$v] = gzcompress($this->data[$v],5);
break;
case 'enum': case 'enum':
$a[$v] = $this->table->enumIndex($v,$this->data[$v]); $a[$v] = $this->table->enumIndex($v,$this->data[$v]);
break; break;

View File

@ -239,6 +239,7 @@ class Doctrine_Validator {
case 'mbstring': case 'mbstring':
case 'timestamp': case 'timestamp':
case 'date': case 'date':
case 'gzip':
return 'string'; return 'string';
break; break;
default: default:

View File

@ -6,8 +6,31 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
public function prepareTables() { public function prepareTables() {
$this->tables[] = "enumTest"; $this->tables[] = "enumTest";
$this->tables[] = "fieldNameTest"; $this->tables[] = "fieldNameTest";
$this->tables[] = "GzipTest";
parent::prepareTables(); parent::prepareTables();
} }
public function testGzipType() {
$gzip = new GzipTest();
$gzip->gzip = "compressed";
$this->assertEqual($gzip->gzip, "compressed");
$gzip->save();
$this->assertEqual($gzip->gzip, "compressed");
$gzip->refresh();
$this->assertEqual($gzip->gzip, "compressed");
$this->connection->clear();
$gzip = $gzip->getTable()->find($gzip->id);
$this->assertEqual($gzip->gzip, "compressed");
$gzip->gzip = "compressed 2";
$this->assertEqual($gzip->gzip, "compressed 2");
$gzip->save();
$this->assertEqual($gzip->gzip, "compressed 2");
$gzip->refresh();
$this->assertEqual($gzip->gzip, "compressed 2");
}
public function testEnumType() { public function testEnumType() {

View File

@ -409,7 +409,11 @@ class DateTest extends Doctrine_Record {
$this->hasColumn("date", "date", 20); $this->hasColumn("date", "date", 20);
} }
} }
class GzipTest extends Doctrine_Record {
public function setTableDefinition() {
$this->hasColumn("gzip", "gzip", 100000);
}
}
class Tag extends Doctrine_Record { class Tag extends Doctrine_Record {
public function setUp() { public function setUp() {