Changeset 195

Show
Ignore:
Timestamp:
02/01/07 23:16:45 (1 year ago)
Author:
mikey
Message:

playing around with SDBP API: creating tables

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/rdbms/persistence/annotations/DBColumn.php

    r182 r195  
    2525    protected $name; 
    2626    /** 
     27     * type of the column 
     28     * 
     29     * @var  string 
     30     */ 
     31    protected $type; 
     32    /** 
     33     * size of the field 
     34     * 
     35     * @var  int|string 
     36     */ 
     37    protected $size; 
     38    /** 
     39     * switch whether column is unsigned or not 
     40     * 
     41     * @var  bool 
     42     */ 
     43    protected $isUnsigned   = false; 
     44    /** 
     45     * switch whether the column can be null or not 
     46     * 
     47     * @var  bool 
     48     */ 
     49    protected $isNullable   = true; 
     50    /** 
     51     * default value of the column 
     52     * 
     53     * @var  mixed 
     54     */ 
     55    protected $defaultValue = null; 
     56    /** 
    2757     * switch whether column is a primary key or not 
    2858     * 
     
    3060     */ 
    3161    protected $isPrimaryKey = false; 
     62    /** 
     63     * switch whether column is a key or not 
     64     * 
     65     * @var  bool 
     66     */ 
     67    protected $isKey        = false; 
    3268     
    3369    /** 
     
    5086        $this->name = $name; 
    5187    } 
    52      
    53     /** 
    54      * alias for setName() 
    55      * 
    56      * @param  string  $name 
    57      * @see    setName() 
    58      */ 
    59     public function setValue($name) 
    60     { 
    61         $this->setName($name); 
    62     } 
    63      
     88 
    6489    /** 
    6590     * returns the name of the column 
     
    7398     
    7499    /** 
     100     * sets the type of the column 
     101     * 
     102     * @param  string  $type 
     103     */ 
     104    public function setType($type) 
     105    { 
     106        $this->type = $type; 
     107    } 
     108 
     109    /** 
     110     * returns the type of the column 
     111     * 
     112     * @return  string 
     113     */ 
     114    public function getType() 
     115    { 
     116        return $this->type; 
     117    } 
     118     
     119    /** 
     120     * sets the size of the column 
     121     * 
     122     * @param  int|string  $type 
     123     */ 
     124    public function setSize($size) 
     125    { 
     126        $this->size = $size; 
     127    } 
     128 
     129    /** 
     130     * returns the size of the column 
     131     * 
     132     * @return  int|string 
     133     */ 
     134    public function getSize() 
     135    { 
     136        return $this->size; 
     137    } 
     138     
     139    /** 
     140     * set whether the column may be null or not 
     141     * 
     142     * @param  bool  $isUnsigned 
     143     */ 
     144    public function setIsUnsigned($isUnsigned) 
     145    { 
     146        if (is_string($isUnsigned) == true && 'false' == $isUnsigned) { 
     147            $isUnsigned = false; 
     148        } 
     149         
     150        $this->isUnsigned = $isUnsigned; 
     151    } 
     152     
     153    /** 
     154     * check whether the column may be null or not 
     155     * 
     156     * @return  bool 
     157     */ 
     158    public function isUnsigned() 
     159    { 
     160        return (strstr(strtoupper($this->type), 'INT') == true && true == $this->isUnsigned); 
     161    } 
     162     
     163    /** 
     164     * set whether the column may be null or not 
     165     * 
     166     * @param  bool  $isNullable 
     167     */ 
     168    public function setIsNullable($isNullable) 
     169    { 
     170        if (is_string($isNullable) == true && 'false' == $isNullable) { 
     171            $isNullable = false; 
     172        } 
     173         
     174        $this->isNullable = $isNullable; 
     175    } 
     176     
     177    /** 
     178     * check whether the column may be null or not 
     179     * 
     180     * @return  bool 
     181     */ 
     182    public function isNullable() 
     183    { 
     184        return (false == $this->isPrimaryKey && true == $this->isNullable); 
     185    } 
     186     
     187    /** 
     188     * sets the default value of the column 
     189     * 
     190     * @param  mixed  $defaultValue 
     191     */ 
     192    public function setDefaultValue($defaultValue) 
     193    { 
     194        $this->defaultValue = $defaultValue; 
     195    } 
     196 
     197    /** 
     198     * returns the default value of the column 
     199     * 
     200     * @return  mixed 
     201     */ 
     202    public function getDefaultValue() 
     203    { 
     204        return $this->defaultValue; 
     205    } 
     206     
     207    /** 
    75208     * set whether the column is a primary key or not 
    76209     * 
     
    79212    public function setIsPrimaryKey($isPrimaryKey) 
    80213    { 
     214        if (is_string($isPrimaryKey) == true && 'false' == $isPrimaryKey) { 
     215            $isPrimaryKey = false; 
     216        } 
     217         
    81218        $this->isPrimaryKey = $isPrimaryKey; 
    82219    } 
     
    90227    { 
    91228        return $this->isPrimaryKey; 
     229    } 
     230     
     231    /** 
     232     * set whether the column is a primary key or not 
     233     * 
     234     * @param  bool  $isPrimaryKey 
     235     */ 
     236    public function setIsKey($isKey) 
     237    { 
     238        if (is_string($isKey) == true && 'false' == $isKey) { 
     239            $isKey = false; 
     240        } 
     241         
     242        $this->isKey = $isKey; 
     243    } 
     244     
     245    /** 
     246     * check whether the column is a primary key or not 
     247     * 
     248     * @return  bool 
     249     */ 
     250    public function isKey() 
     251    { 
     252        return (false == $this->isPrimaryKey && true == $this->isKey); 
    92253    } 
    93254} 
  • trunk/src/main/php/net/stubbles/rdbms/persistence/annotations/DBTable.php

    r182 r195  
    2424     */ 
    2525    protected $name; 
     26    /** 
     27     * type of the table 
     28     * 
     29     * @var  string 
     30     */ 
     31    protected $type; 
    2632     
    2733    /** 
     
    4450        $this->name = $name; 
    4551    } 
    46      
    47     /** 
    48      * alias for setName() 
    49      * 
    50      * @param  string  $name 
    51      * @see    setName() 
    52      */ 
    53     public function setValue($name) 
    54     { 
    55         $this->setName($name); 
    56     } 
    57      
     52 
    5853    /** 
    5954     * returns the name of the table 
     
    6560        return $this->name; 
    6661    } 
     62     
     63    /** 
     64     * sets the type of the column 
     65     * 
     66     * @param  string  $type 
     67     */ 
     68    public function setType($type) 
     69    { 
     70        $this->type = $type; 
     71    } 
     72 
     73    /** 
     74     * returns the type of the column 
     75     * 
     76     * @return  string 
     77     */ 
     78    public function getType() 
     79    { 
     80        return $this->type; 
     81    } 
    6782} 
    6883?> 
  • trunk/src/main/php/net/stubbles/rdbms/persistence/querybuilder/stubDatabaseMySQLQueryBuilder.php

    r182 r195  
    77 * @subpackage  rdbms_persistence_querybuilder 
    88 */ 
    9 stubClassLoader::load('net.stubbles.rdbms.querybuilder.stubDatabaseQueryBuilder'); 
     9stubClassLoader::load('net.stubbles.rdbms.persistence.querybuilder.stubDatabaseQueryBuilder'); 
    1010/** 
    1111 * Class for creating MySQL specific queries. 
     
    2828        foreach ($tableNames as $tableName) { 
    2929            $columns = $value->getColumnsForTable($tableName); 
    30             $queries[$tableName] = 'INSERT INTO Ž' . $tableName . 'Ž (Ž' . join('Ž, Ž', array_keys($columns)) . "Ž) VALUES ('" . join("', '", array_values($columns)) . "')"; 
     30            $queries[$tableName] = 'INSERT INTO `' . $tableName . '` (`' . join('`, `', array_keys($columns)) . "`) VALUES ('" . join("', '", array_values($columns)) . "')"; 
    3131        } 
    3232         
     
    4646        foreach ($tableNames as $tableName) { 
    4747            $columns = $value->getColumnsForTable($tableName); 
    48             $query   = 'UPDATE Ž' . $tableName . 'Ž SET '; 
     48            $query   = 'UPDATE `' . $tableName . '` SET '; 
    4949            $where   = array(); 
    5050            $counter = 0; 
     
    5454                } 
    5555                 
    56                 $query .= 'Ž' . $columnName . "Ž = '" . $columnValue . "'"; 
     56                $query .= '`' . $columnName . "` = '" . $columnValue . "'"; 
    5757                $counter++; 
    5858                 
    5959                if ($value->isPrimaryKey($tableName, $columnName) == true) { 
    60                     $where[] = 'Ž' . $columnName . "Ž = '" . $columnValue . "'"; 
     60                    $where[] = '`' . $columnName . "` = '" . $columnValue . "'"; 
    6161                } 
    6262            } 
  • trunk/src/main/php/net/stubbles/rdbms/persistence/stubPersistable.php

    r182 r195  
    1313 * @subpackage  rdbms_persistence 
    1414 */ 
    15 interface stubPersistable extends stubBaseObject 
     15interface stubPersistable extends stubObject 
    1616{ 
    1717    /**