PHP Classes
Icontem

File: DATA/SQLChar.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Martin Alterisio  >  DATA  >  DATA/SQLChar.php  
File: DATA/SQLChar.php
Role: Class source
Content type: text/plain
Description: ANSI SQL Character data type representation.
Class: DATA
Access data stored in MySQL tables like arrays
 

Contents

Class file image Download
<?php
/**
 * @package DATA
 */

/**
 * ANSI SQL Character data type representation.
 * 
 * When inboxing, if the field cannot hold the desired value
 * {@link DATA_StringTooLarge} is thrown.
 * 
 * Field contents are padded to the field size with spaces.
 * 
 * @todo String operations.
 */
class DATA_SQLChar extends DATA_SQLType {
    
/**
     * How many characters are stored by this field type.
     * 
     * @var int
     */
    
protected $size;
    
/**
     * The characters stored in this instance.
     * 
     * @var string
     */
    
protected $chars;
    
    
/**
     * Construct a sql char type with requested field size and initial value (optional).
     * 
     * Throws {@link DATA_StringTooLarge} when the chars to be stored are more than the field can hold.
     * 
     * @param boolean $nullable True if the type is nullable.
     * @param int $size The field size.
     * @param null|string $chars The characters stored in this object.
     */
    
public function __construct($nullable$size$chars '') {
        
$this->size $size;
        
$this->setChars($chars);
        
parent::__construct($nullableis_null($chars));
    }
    
    
/**
     * Returns the field size.
     * 
     * @return int Field size.
     */
    
public function getSize() {
        return 
$this->size;
    }
    
    
/**
     * Returns the characters stored in this field.
     * 
     * @return string The characters stored.
     */
    
public function getChars() {
        return 
str_pad($this->chars$this->size);
    }
    
    
/**
     * Sets the chars stored in this field.
     * 
     * Throws {@link DATA_StringTooLarge} when the chars to be stored are more than the field can hold.
     * 
     * @param string $chars The characters stored in this object.
     */
    
public function setChars($chars) {
        if (
strlen($chars) > $this->size) {
            
throw new DATA_StringTooLarge($this->size$chars);
        }
        
$this->chars $chars;
        
$this->setNotNull();
    }
    
    
public function setNull() {
        
parent::setNull();
        
$this->chars null;
    }
    
    
public function __toString() {
        return 
$this->getChars();
    }
}
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products