Changeset 195
- Timestamp:
- 02/01/07 23:16:45 (1 year ago)
- Files:
-
- trunk/experiments/people/mikey/persistence (added)
- trunk/experiments/people/mikey/persistence/MyNewsArticle.php (added)
- trunk/experiments/people/mikey/persistence/createTable.php (added)
- trunk/src/main/php/net/stubbles/rdbms/persistence/annotations/DBColumn.php (modified) (6 diffs)
- trunk/src/main/php/net/stubbles/rdbms/persistence/annotations/DBTable.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/rdbms/persistence/querybuilder/stubDatabaseMySQLQueryBuilder.php (modified) (4 diffs)
- trunk/src/main/php/net/stubbles/rdbms/persistence/stubPersistable.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/rdbms/persistence/annotations/DBColumn.php
r182 r195 25 25 protected $name; 26 26 /** 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 /** 27 57 * switch whether column is a primary key or not 28 58 * … … 30 60 */ 31 61 protected $isPrimaryKey = false; 62 /** 63 * switch whether column is a key or not 64 * 65 * @var bool 66 */ 67 protected $isKey = false; 32 68 33 69 /** … … 50 86 $this->name = $name; 51 87 } 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 64 89 /** 65 90 * returns the name of the column … … 73 98 74 99 /** 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 /** 75 208 * set whether the column is a primary key or not 76 209 * … … 79 212 public function setIsPrimaryKey($isPrimaryKey) 80 213 { 214 if (is_string($isPrimaryKey) == true && 'false' == $isPrimaryKey) { 215 $isPrimaryKey = false; 216 } 217 81 218 $this->isPrimaryKey = $isPrimaryKey; 82 219 } … … 90 227 { 91 228 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); 92 253 } 93 254 } trunk/src/main/php/net/stubbles/rdbms/persistence/annotations/DBTable.php
r182 r195 24 24 */ 25 25 protected $name; 26 /** 27 * type of the table 28 * 29 * @var string 30 */ 31 protected $type; 26 32 27 33 /** … … 44 50 $this->name = $name; 45 51 } 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 58 53 /** 59 54 * returns the name of the table … … 65 60 return $this->name; 66 61 } 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 } 67 82 } 68 83 ?> trunk/src/main/php/net/stubbles/rdbms/persistence/querybuilder/stubDatabaseMySQLQueryBuilder.php
r182 r195 7 7 * @subpackage rdbms_persistence_querybuilder 8 8 */ 9 stubClassLoader::load('net.stubbles.rdbms. querybuilder.stubDatabaseQueryBuilder');9 stubClassLoader::load('net.stubbles.rdbms.persistence.querybuilder.stubDatabaseQueryBuilder'); 10 10 /** 11 11 * Class for creating MySQL specific queries. … … 28 28 foreach ($tableNames as $tableName) { 29 29 $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)) . "')"; 31 31 } 32 32 … … 46 46 foreach ($tableNames as $tableName) { 47 47 $columns = $value->getColumnsForTable($tableName); 48 $query = 'UPDATE Ž' . $tableName . 'ŽSET ';48 $query = 'UPDATE `' . $tableName . '` SET '; 49 49 $where = array(); 50 50 $counter = 0; … … 54 54 } 55 55 56 $query .= ' Ž' . $columnName . "Ž= '" . $columnValue . "'";56 $query .= '`' . $columnName . "` = '" . $columnValue . "'"; 57 57 $counter++; 58 58 59 59 if ($value->isPrimaryKey($tableName, $columnName) == true) { 60 $where[] = ' Ž' . $columnName . "Ž= '" . $columnValue . "'";60 $where[] = '`' . $columnName . "` = '" . $columnValue . "'"; 61 61 } 62 62 } trunk/src/main/php/net/stubbles/rdbms/persistence/stubPersistable.php
r182 r195 13 13 * @subpackage rdbms_persistence 14 14 */ 15 interface stubPersistable extends stub BaseObject15 interface stubPersistable extends stubObject 16 16 { 17 17 /**
