00001 <?php
00002 require_once dirname(__FILE__) . '/dbfield.text.cls.php'; 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 class DBFieldBlob extends DBFieldText {
00011         
00012 
00013 
00014 
00015         protected function do_format_not_null($value) {
00016                 if ($value !== '') {
00017                         return '0x' . bin2hex($value);
00018                 }
00019                 else {
00020                         return parent::format('');
00021                 }
00022         }
00023         
00024 
00025 
00026 
00027 
00028 
00029 
00030         public function validate($value) {
00031                 $ret = new Status();
00032                 $l = strlen(strval($value));
00033                 if ($l > $this->length) {
00034                         $ret->append(tr(
00035                                 '%field may have no more than %num bytes', 
00036                                 'core', 
00037                                 array(
00038                                         '%field' => $this->get_field_name_translation(),
00039                                         '%num' => $this->length
00040                                 )
00041                         ));
00042                 }
00043                 else if ($l == 0 && !$this->get_null_allowed()) {
00044                         $ret->append(tr(
00045                                 '%field may not be empty', 
00046                                 'core', 
00047                                 array(
00048                                         '%field' => $this->get_field_name_translation(),
00049                                 )
00050                         ));
00051                 }
00052                 return $ret;
00053         }       
00054 }