| @@ 380-412 (lines=33) @@ | ||
| 377 | * @param boolean $notnull not null status, default value is false |
|
| 378 | * @return void |
|
| 379 | */ |
|
| 380 | function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = null, $notnull = false) |
|
| 381 | { |
|
| 382 | if($this->isColumnExists($table_name, $column_name)) |
|
| 383 | { |
|
| 384 | return; |
|
| 385 | } |
|
| 386 | $type = $this->column_type[$type]; |
|
| 387 | if(strtoupper($type) == 'INTEGER') |
|
| 388 | { |
|
| 389 | $size = ''; |
|
| 390 | } |
|
| 391 | ||
| 392 | $query = sprintf("alter table %s%s add %s ", $this->prefix, $table_name, $column_name); |
|
| 393 | if($size) |
|
| 394 | { |
|
| 395 | $query .= sprintf(" %s(%s) ", $type, $size); |
|
| 396 | } |
|
| 397 | else |
|
| 398 | { |
|
| 399 | $query .= sprintf(" %s ", $type); |
|
| 400 | } |
|
| 401 | ||
| 402 | if(isset($default)) |
|
| 403 | { |
|
| 404 | $query .= sprintf(" default '%s' ", $default); |
|
| 405 | } |
|
| 406 | if($notnull) |
|
| 407 | { |
|
| 408 | $query .= " not null "; |
|
| 409 | } |
|
| 410 | ||
| 411 | return $this->_query($query); |
|
| 412 | } |
|
| 413 | ||
| 414 | /** |
|
| 415 | * Drop a column from the table |
|
| @@ 302-329 (lines=28) @@ | ||
| 299 | * @param boolean $notnull not null status, default value is false |
|
| 300 | * @return void |
|
| 301 | */ |
|
| 302 | function addColumn($table_name, $column_name, $type = 'number', $size = '', $default = null, $notnull = false) |
|
| 303 | { |
|
| 304 | $type = $this->column_type[$type]; |
|
| 305 | if(strtoupper($type) == 'INTEGER') |
|
| 306 | { |
|
| 307 | $size = ''; |
|
| 308 | } |
|
| 309 | ||
| 310 | $query = sprintf("alter table `%s%s` add `%s` ", $this->prefix, $table_name, $column_name); |
|
| 311 | if($size) |
|
| 312 | { |
|
| 313 | $query .= sprintf(" %s(%s) ", $type, $size); |
|
| 314 | } |
|
| 315 | else |
|
| 316 | { |
|
| 317 | $query .= sprintf(" %s ", $type); |
|
| 318 | } |
|
| 319 | if(isset($default)) |
|
| 320 | { |
|
| 321 | $query .= sprintf(" default '%s' ", $default); |
|
| 322 | } |
|
| 323 | if($notnull) |
|
| 324 | { |
|
| 325 | $query .= " not null "; |
|
| 326 | } |
|
| 327 | ||
| 328 | return $this->_query($query); |
|
| 329 | } |
|
| 330 | ||
| 331 | /** |
|
| 332 | * Drop a column from the table |
|