3 * @desc The Abstract Data Objects series
5 * @author Marius Orcsik <marius.orcsik@gmail.com>
16 protected $id, // public to allow debugging outside the class
22 * @desc function to implement get_ | set_ virtual methods
24 * @param string $method
28 * @see http://www.ibm.com/developerworks/xml/library/os-php-flexobj/ by Jack Herrington <jherr@pobox.com>
30 function __call ( $method, $args) {
31 $diff = $this->get_members();
32 $all = get_object_vars($this);
34 if ( preg_match( '/set_(.*)/', $method, $found ) ) {
35 // check for fields with $found[1] name
36 if ( array_key_exists( $found[1], $diff) ) {
37 $this->fields
[$found[1]]->setValue($args[0]);
39 // check for obj members with $found[1] name
40 } elseif (array_key_exists( $found[1], $all)){
41 $this->$found[1] = $args[0];
44 } else if ( preg_match( '/get_(.*)/', $method, $found ) ) {
45 if ( array_key_exists( $found[1], $diff ) ) {
46 return $this->fields
[$found[1]]->getValue();
47 } elseif (array_key_exists( $found[1], $all)){
48 return $this->$found[1];
55 * @desc A function to implement a virtual getter member of the class
60 * @see http://www.ibm.com/developerworks/xml/library/os-php-flexobj/ by Jack Herrington <jherr@pobox.com>
62 function __get ( $key ) {
63 return $this->fields
[$key];
67 * @desc A function to implement a virtual setter member for this class
73 * @see http://www.ibm.com/developerworks/xml/library/os-php-flexobj/ by Jack Herrington <jherr@pobox.com>
75 function __set ( $key, $value ) {
77 array_key_exists ($key, $this->get_members()) /*&&
78 $this->isValidMember($this->fields[$key])*/
80 $this->fields
[$key]->set_value ($value);
83 $this->fields
[$key] = new tdoAbstractField ($key, $this->alias
);
84 $this->fields
[$key]->set_value ($value);
88 public function __construct(&$db) {
92 $this->instantiateMembers();
95 public function __destruct() {}
98 * gets the members we consider table fields
100 * @return array ('fieldName' => tdoAbstractField)
102 public function &get_members () {
103 return $this->fields
;
107 * checks if a field is a valid member of the current object
109 * @param tdoAbstractField $incMember
112 public function isValidMember ($incMember) {
114 ! ($incMember instanceof tdoAbstractField
) ||
115 // this prevents an error in php > 5.2 object comparison
116 ! in_array ($incMember, $this->get_members() /**/, true/**/)
124 * instantiating the object's members
126 public function instantiateMembers () {
127 foreach ($this->get_members() as $key => $field) {
128 if ( is_int ($key) && is_string ($field) ) {
129 $this->fields
[$field] = new tdoAbstractField ($field, $this->alias
);
131 // FIXME: this is so bad :D - it implies that the primary key must be the first field containing _id :D
132 if (stristr ($field,'_id') && !isset ($this->id
) && $this->isValidMember ($this->fields
[$field])) {
133 $this->id
= &$this->fields
[$field];
135 unset ($this->fields
[$key]);
139 $this->wheres
= array();
142 $this->refers
= array();
145 * setting the table's index field
147 * @param tdoAbstractField $obj
149 public function set_index (&$obj) {
150 if ($this->isValidMember($obj)) {
152 $this->id
->flags
= PRIMARY
;
157 * setting an alias for the table in case of joins.
158 * this method also sets the alias on all the fields of the current object
160 * @param string $alias
162 public function set_alias ($alias) {
163 foreach ($this->get_members() as $field){
164 if ($field->table
== $this->alias
) {
165 $field->table
= 't'.$alias;
168 $this->alias
= 't'.$alias;
172 * For adding custom sql functions for certain fields
174 * @param string $modif
175 * @param tdoAbstractField $field
177 public function set_fieldModifier ($modif, &$field) {
178 if ($this->isValidMember ($field) && stristr ($modif, '%'))
179 $field->set_modifier ($modif);
183 * method used in join cases to add the joined object's fields
186 * @param array ('fieldName' => tdoAbstractField) $incArr
188 public function addFields (&$incArr) {
189 if (is_array($incArr)) {
190 foreach ($incArr as $fieldName => $field) {
191 $this->fields
[$fieldName] = $field;
197 * Based on field values, we get the _first_ row in the table that matches
199 * TODO: maybe we can have a function that returns _all_ the rows that match
203 public function buildObj () {
204 $sql = $this->buildSql(1);
205 $this->db
->query( $sql );
207 $arr = $this->db
->getAssoc();
208 if (is_array($arr)) {
209 foreach ($arr as $field => $var) {
210 $this->fields
[$field]->set_value ($var);
218 * Gets the row in the table for $id
223 public function get ($id) {
224 $id = $this->db
->escape($id);
226 $this->instantiateMembers();
228 $this->id
->set_value ($id);
232 * Returns the last id of the table
233 * OBS: this assumes that we didn't delete any rows from the table.
237 public function getLastInsertedId () {
238 $sql = $this->db
->_SELECT ($this->id
->name
)
239 .$this->db
->_FROM ($this->name
);
241 $this->addOrder($this->id
, false);
243 $sql .= $this->db
->_ORDER ($this->outputOrders ());
247 $this->db
->query ($sql);
248 return $this->db
->getScalar ();
252 * encapsulating the $this->db->escape() method
254 * @param mixed $value
257 public function escape ($value) {
258 if (is_numeric ($value)) {
261 return '"'.$this->db
->escape ($value).'"';
265 * inserting into the database
266 * TODO: multiple inserts to use with loadFromArray
270 public function insert () {
271 $sql = $this->db
->_INSERT ($this->name
);//`'INSERT INTO '.$this->name;
275 $f = $this->get_members();
277 foreach ($f as $fieldName => $field) {
278 if ($this->isValidMember ($field) && ($field != $this->id
) && !is_null ($field->value
)) {
279 $value = $this->escape ($field->value
);
281 $fieldStr.= (!empty ($fieldStr) ?
', ' : ' ') . $fieldName;
282 $valueStr.= (!empty ($valueStr) ?
', ' : ' ') . $value;
286 $sql.= ' ('.$fieldStr.') VALUES ('.$valueStr.')';
288 $this->db
->query($sql);
290 return $this->getLastInsertedId();
294 public function update ($id = null) {
296 $id = $this->id
->value
;
300 throw new Exception('Cannot update record in table '.$this->name
.' because an id hasn\'t been provided');
304 $sql = $this->db
->_UPDATE (array ($this->name
, $this->alias
) );
306 if (is_array ($this->refers
) && !empty ($this->refers
)){
307 $this->refers
= array_reverse ($this->refers
);
309 foreach ($this->refers
as $ref)
313 $sql .= $this->db
->_SET();
315 $fields = $this->get_members();
317 foreach ($fields as $fieldName => $field) {
318 if (($field instanceof tdoAbstractField
) && $field != $this->id
) { // TODO: make a more real check for field is an id
319 $value = $field->value
;
322 if ((isset($value) && !is_null($value))) {
323 $sql.= $field->table
.'.'.$fieldName.' = '.$this->escape ($value).', ';
327 $sql = substr ($sql, 0, -2);
329 $sql.= $this->db
->_WHERE($this->alias
.'.'.$this->id
->name
.' = '.$this->escape($id));
331 // var_dump($sql);die ('<br/>update');
332 $this->db
->query($sql);
337 public function replace ( $id = null ) {
339 $id = $this->id
->value
;
342 if (is_null($id) ||
!$this->idExists ($id) ) {
343 return $this->insert ();
345 return $this->update ($id);
349 // TODO: make this the same way the find first method works
350 public function delete ($id = null) {
351 $id = (!is_null ($id) ?
$id :$this->id
->value
);
353 if (!is_null ($id)) {
354 // no need for other wheres
355 $this->wheres
= array();
356 $this->addWhere ($this->id
, '=', $id);
359 if (empty($this->wheres
)) {
363 $temp = $this->alias
;
364 $this->set_alias(null);
367 $sql = 'DELETE FROM '.$this->name
.' WHERE '; //$this->id->name.' = '.$this->escape($value).' LIMIT 1';
368 $sql.= $this->outputWheres();
370 $affRows = $this->db
->query($sql);
372 $this->set_alias($temp);
376 public function reset () {
377 foreach ($this->fields
as $key => $field) {
378 if ($field instanceof tdoAbstractField
) {
379 $this->fields
[$key] = new tdoAbstractField($key, $this->alias
);
383 $this->wheres
= array();
384 $this->groups
= array();
385 $this->orders
= array();
386 $this->refers
= array();
390 public function idExists ($id = null) {
392 $id = $this->id
->value
;
397 $this->id
->set_modifier ('COUNT(%s)');
399 $t = sprintf ($this->id
->modifier
, $this->id
->name
);
401 $sql = $this->db
->_SELECT ($t).
402 $this->db
->_FROM ($this->name
).
403 $this->db
->_WHERE ($this->id
->name
.' = '.$this->escape($id));
405 $this->db
->query($sql);
407 if ($this->db
->getScalar()) {
414 protected function outputFieldList () {
416 $f = $this->get_members();
418 foreach ($f as $fieldName => $field) {
419 if ($this->isValidMember ($field)) {
421 if (!is_null ($field->modifier
)) {
422 // i replaced str_replace ('%s', $curField, '%s', $curField)
423 // as sometimes I might need it for something else than %s
424 $fields .= sprintf ($field->modifier
, (!is_null ($field->table
) ?
$field->table
. '.' : '') . $field->name
) .
425 $this->db
->_AS($field->name
) . ', ';
426 } elseif ( !$field->inWhere ()) {
427 $fields .= (!is_null ($field->table
) ?
$field->table
.'.' : '') . $field->name
. ', ';
431 throw new Exception ($fieldName . ' is not a valid member of ' . get_class($this));
435 return substr ($fields,0,-2);//$fields;
438 protected function outputWheres ($bIW = true) {
439 // var_dump($this->wheres);
440 return implode ($this->db
->_AND(), $this->wheres
);
443 protected function outputGroups () {
446 $f = $this->get_members ();
447 foreach ($f as $field)
448 if (!is_null ($field->group
) )
449 $groups .= (!empty($groups) ?
', ' : '') . $field->name
;
454 protected function outputOrders () {
456 $f = $this->get_members();
457 foreach ($f as $field)
458 if (!is_null($field->order
)) {
459 $orders .= (!empty($orders) ?
', ': '').$field->name
.($field->order
== true ?
' ASC' : ' DESC');
464 protected function outputRefers () {
467 if (is_array($this->refers
) && !empty($this->refers
)){
468 $this->refers
= array_reverse($this->refers
);
469 foreach ($this->refers
as $ref)
476 protected function buildInherentWheres () {
477 $diff = $this->get_members();
478 // let's hope this doesn't break stuff.
479 // it's needed when we use more queries on the same instance of the object :D
481 if (is_array ($diff)) {
482 foreach ($diff as $fieldName => $field) {
483 if ( $this->isValidMember ($field) ) {
484 if (!is_null($field->value
))
485 $this->addWhere ($field, '=', $this->escape($field->value
));
487 throw new Exception ($fieldName . ' is not a valid member of ' . get_class($this));
492 if (empty ($this->wheres
)) {
494 $this->wheres
[] = new tdoAbstractClause ($t);
496 // var_dump($this->wheres);
499 * function to add an abstract clause to the current object if it doesn't exist
501 * @param tdoAbstractField|tdoAbstractClause $field1
502 * @param string $condition
503 * @param string $field2
505 public function addWhere (&$field1, $condition = null, $field2 = null) {
506 if (($field1 instanceof tdoAbstractClause
) && ($condition == null ||
$field2 == null)) {
509 $w = new tdoAbstractClause ($field1, $condition, $field2);
511 // this might generate an infinite recursion error on some PHP > 5.2 due to object comparison
512 if (!in_array ($w, $this->wheres
/*, true */))
513 $this->wheres
[] = &$w;
516 public function addOrder (&$orderField, $asc = true) {
517 if (!($orderField instanceof tdoAbstractField
) && is_string ($orderField)) {
518 $orderField = &$this->fields
[$orderField];
520 if ($this->isValidMember ($orderField))
521 $orderField->set_order ($asc);
524 public function addGroup (&$groupField) {
525 if (!($groupField instanceof tdoAbstractField
) && is_string ($groupField)) {
526 $groupField = &$this->fields
[$groupField];
528 if (($groupField instanceof tdoAbstractField
)) {
529 $groupField->set_group (true);
534 * building a normal SELECT query
540 protected function buildSql ($start = 0, $end = 0) {
541 $sql = $this->db
->_SELECT($this->outputFieldList()). ' FROM '.$this->name
.' AS '.$this->alias
.' ';
543 $this->buildInherentWheres(); // will it work
545 $sql .= $this->outputRefers();
547 $sql .= $this->db
->_WHERE($this->outputWheres());// add LIMITS
549 $sql .= $this->db
->_GROUP($this->outputGroups());
551 $sql .= $this->db
->_ORDER($this->outputOrders());
554 $sql .= $this->db
->_LIMIT($start, $end);
559 public function find ($start = 0, $count = 0) {
560 $result = $this->db
->query ($this->buildSql(), $start, $count);
564 public function findFirst () {
565 $this->buildInherentWheres();
567 $this->db
->query($this->buildSql(), 0, 1);
568 $row = $this->db
->getAssoc();
570 foreach ($row as $field => $value){
571 $this->fields
[$field]->value
= $value;
575 public function getArray ($start = 0, $count = 0, $orderBy = null) {
576 $this->buildInherentWheres ();
578 $sql = $this->buildSql ($start, $count, $orderBy);
580 $this->db
->query ($sql);
581 return $this->db
->getArray ();
584 public function getCount() {
585 $this->set_fieldModifier('COUNT(%s)', $this->id
);
586 $this->db
->query($this->buildSql());
587 return $this->db
->getScalar();
590 public function getVector() {
591 // I really don't see why we need this. ?
595 * Function to load the values of current object from an array
596 * of type field_name => field_value
597 * If strict is false, the current object can have fields that are not already
598 * present in $this->fields[]
600 * @param array $valArray
601 * @param bool $strict
603 public function loadFromArray ($valArray, $strict = true) {
604 foreach ($valArray as $fieldName => $value) {
605 if (array_key_exists ($fieldName, $this->fields
)) {
606 $this->fields
[$fieldName]->set_value($value);
607 } elseif (!strinct
) {
608 // if the field name is not in the field list of the current object
609 // it means that the valArray object is got from an JOIN sql
610 $this->fields
[$fieldName] = new tdoAbstractField($field,'j1');
611 $this->fields
[$fieldName]->set_value ($value);
617 * FIXME: make it work when composing with the same object
619 * @param tdoAbstract $incOb
622 private function composeObj ($incOb) {
623 if (!($incOb instanceof tdoAbstract
))
625 $refs = count($this->refers
);
627 foreach ($incOb->refers
as $alias => $ref) {
630 $this->refers
[$tAl] = $ref;//str_replace(array($alias, $aliases[$alias][1]), array($tAl, $aliases[$alias][2]), $ref);
631 $this->refers
[$tAl]->set_state($tAl);
636 * Function to execute a join between two tdoAbstract objects
638 * @param string $jType
639 * @param tdoAbstractField $thisJField
640 * @param tdoAbstract $incOb
641 * @param tdoAbstractField $incObJField
644 public function joinWith ($jType = null, &$thisJField = null, &$incOb = null, &$incObJField = null) {
646 !tdoAbstractJoin
::isValidType($jType) ||
647 !$this->isValidMember ($thisJField)
652 $this->composeObj ($incOb);
654 $tAl = (count($this->refers
));
656 trigger_error('Join aborted for table '.$this->name
.': Too many tables; MySQL can only use 61 tables in a join', E_USER_NOTICE
);
659 $incOb->set_alias($tAl);
661 if($thisJField == null ||
!($thisJField instanceof tdoAbstractField
))
662 $thisJField = $this->id
;
664 if($incObJField == null ||
!($incObJField instanceof tdoAbstractField
))
665 $incObJField = $incOb->id
;
667 $this->refers
[$tAl] = new tdoAbstractJoin ($jType, $this, $incOb, $thisJField, $incObJField, $tAl);
668 $this->refers
[$tAl]->set_state ($tAl);
673 * function to dump a <type>Sql
674 * problem with the field types. :D
676 * @param tdoAbstract $obj
678 static public function dumpSchema ($obj) {
679 if ($obj instanceof tdoAbstract)
680 throw new Exception('Can\'t generate sql dump');
682 $sql = 'CREATE TABLE '. $obj->name . ' (';
684 foreach ($obj->getFields() as $fieldName => $data) {
685 $sql .= $fieldName.' '.$data[0].', ';
694 * class to abstract a where clause in a SQL query
695 * TODO: add possibility of complex wheres: (t1 condition1 OR|AND|XOR t2.condition2)
696 * TODO: abstract the condition part of a where clause - currently string based :D
698 class tdoAbstractClause
{
699 protected $subject, $predicate, $predicative;
702 * initializing a WHERE|ON clause
704 * @param tdoAbstractClause|tdoAbstractField $subject
705 * @param string $predicate
706 * @param tdoAbstractClause|tdoAbstractField|null $complement
708 public function __construct ($subject, $predicate = null, $predicative = null) {
709 // I must be careful with the $subject == 1 because (int)object == 1
710 if (($subject === 1 ||
is_string($subject)) && $predicate == null && $predicative == null) {
711 $this->subject
= $subject;
712 $this->predicate
= '';
713 $this->predicative
= '';
717 if (($subject instanceof tdoAbstractField
) ||
($subject instanceof tdoAbstractClause
)) {
718 $this->subject
= &$subject;
720 $subject->set_where
= true;
722 $this->predicative
= &$predicative;
724 if ($this->validPredicative ($predicate))
725 $this->predicate
= $predicate;
729 $this->predicate
= '';
730 $this->predicative
= '';
735 public function __destruct () {}
737 public function __toString () {
738 // var_dump($this->subject, $this->predicate, $this->predicative);
740 if ($this->subject
=== '1' ||
is_string($this->subject
)) {
741 // var_dump($this->subject);
742 return (string)$this->subject
;
743 } elseif ($this->subject
instanceof tdoAbstractClause
) {
744 $subStr = (string)$this->subject
;
745 } elseif ($this->subject
instanceof tdoAbstractField
) {
746 // without $this->subject->table != 't' we have a bug in the delete op
747 $subStr = ($this->subject
->table
!= 't' ?
$this->subject
->table
.'.': '').$this->subject
->name
;
752 if (is_null($this->predicative
)) {
753 if ($this->validPredicative ($this->predicate
)) {
757 } elseif (is_numeric($this->predicative
)) {
758 $preStr = $this->predicative
;
759 } elseif (is_string($this->predicative
)) {
760 $preStr = $this->predicative
;
762 if ($this->predicate
== 'LIKE') {
763 $preStr = '%'.$this->predicate
.'%';
766 $preStr = (stripos($preStr, '"') !== 0 ?
'"'.$preStr.'"' : $preStr);//'"'.$preStr.'"';
767 } elseif (is_array($this->predicative
)) {
768 $preStr = '("'.implode('", "',$this->predicative
).'")';
769 } elseif ($this->predicative
instanceof tdoAbstractfield
) {
770 $preStr = ($this->predicative
->table
!= 't' ?
$this->predicative
->table
.'.': '').$this->predicative
->name
;
771 } elseif ($this->predicative
instanceof tdoAbstractClause
) {
773 $preStr = $this->predicative
;
776 $retStr = $subStr.' '.$this->predicate
.' '.$preStr;
777 if (($this->subject
instanceof tdoAbstractClause
) && ($this->predicative
instanceof tdoAbstractClause
))
778 return '('.$retStr.')';
783 private function validPredicative ($predicate) {
784 // need to find a way to abstract these
785 // $validPredicates = array (
800 if ($this->predicative
instanceof tdoAbstractClause
) {
801 // we'll have Subject AND|OR|XOR Predicative
802 $validPredicates = array (
809 } elseif (($this->predicative
instanceof tdoAbstractField
) ||
is_numeric($this->predicative
)) {
810 // we'll have Subject =|!= Predicative
811 $validPredicates = array (
819 } elseif (is_array($this->predicative
)) {
820 $validPredicates = array (
824 } elseif (is_string($this->predicative
)) {
825 $validPredicates = array (
834 } elseif (is_null($this->predicative
)) {
835 $validPredicates = array (
841 return in_array($predicate, $validPredicates);
843 // if (in_array($predicate, $validPredicates) && (($predicative instanceof tdoAbstractClause) || ($predicative instanceof tdoAbstractField)))
849 class tdoAbstractJoin
{
850 static public $validTypes = array (
865 public function __construct ($type, &$lt, &$rt, &$lf, &$rf, $state) {
866 if ($rt instanceof tdoAbstract ||
867 $lt instanceof tdoAbstract
869 $this->leftTable
= &$lt;
870 $this->rightTable
= &$rt;
872 if (tdoAbstractJoin
::isValidType($type))
876 $lf instanceof tdoAbstractField
&&
877 $rf instanceof tdoAbstractField
879 $this->rightField
= &$rf;
880 $this->leftField
= &$lf;
883 $this->state
= $state;
886 $this->composeFields ();
887 $this->composeWheres ();
891 public function __destruct () {}
893 public function __toString() {
894 $lAlias = $this->leftTable
->get_alias();
895 return (string)$this->type
.' JOIN '.$this->rightTable
->get_name().
896 ' AS t'.$this->state
.' ON '.(isset($lAlias) ?
$lAlias : $this->leftTable
->get_name()).
897 '.'.$this->leftField
->name
.
898 ' = t'.$this->state
.'.'.$this->rightField
->name
.' ';
902 * Will compose the $rightTable and $leftTable fields
905 public function composeFields () {
906 $leftFields = $this->leftTable
->get_members();
908 $this->rightTable
->set_alias($this->state
);
909 $rightFields = $this->rightTable
->get_members();
912 $this->leftTable
->addFields($rightFields);
916 * Will compose the $rightTable and $leftTable WHERE clauses
919 public function composeWheres () {
920 if (!is_array($this->leftTable
->wheres
))
921 $this->leftTable
->wheres
= array();
922 if (!is_array($this->rightTable
->wheres
))
923 $this->rightTable
->wheres
= array();
925 // var_dump($this->rightTable->wheres, $this->leftTable );die;
926 foreach ($this->rightTable
->wheres
as $where) {
927 $this->leftTable
->addWhere ($where);
929 $this->leftTable
->wheres
= &array_merge($this->rightTable
->wheres
, $this->leftTable
->wheres
);
932 public function set_state ($st) {
936 static public function isValidType ($inc) {
937 if (in_array($inc, tdoAbstractJoin
::$validTypes))
944 define ('PRIMARY', 2);
945 define ('UNIQUE', 4);
946 define ('FULLTEXT', 8);
948 class tdoAbstractField
{
949 static public $validTypes = array (
959 protected $name, $type, $flags, $value, $table, $modifier = null, $order = null, $group = null, $where = false;
961 public function __construct ($incName, $incTable, $incType='INT', $incFlags=0) {
962 $this->name
= $incName;
963 $this->table
= $incTable;
964 $this->type
= $incType;
965 $this->flags
= $incFlags;
968 public function __set ( $key, $value ) {
969 if ( array_key_exists ($key, get_object_vars($this)) ) {
970 $this->$key = $value;
972 // if ($key == 'where')
975 if ( is_null ($this->type
) )
983 public function __get ( $key ) {
987 public function __call ( $method, $args) {
988 $all = get_object_vars($this);
990 if ( preg_match( '/set_(.*)/', $method, $found ) ) {
991 if (array_key_exists( $found[1], $all)){
992 $this->$found[1] = $args[0];
995 } elseif ( preg_match( '/get_(.*)/', $method, $found ) ) {
996 if (array_key_exists( $found[1], $all)){
997 return $this->$found[1];
1003 public function __destruct () {}
1005 public function __toString () {
1006 return (string)$this->value
;
1009 // public function inWhere () {
1010 // return $this->where;
1013 static public function isValidType ($inc) {
1014 if (in_array($inc, tdoAbstractField
::$validTypes)){
1020 public function set_modifier ($modif) {
1021 // if (stristr($modif, '%'))
1022 $this->modifier
= $modif;
1025 public function set_value ($value) {
1026 $this->value
= $value;
1029 public function set_group ($true = true) {
1030 $this->group
= (bool)$true;
1033 public function set_order ($asc = true) {
1034 $this->order
= (bool)$asc;
1037 public function isIndex() {
1038 return (($this->flags
& INDEX
) == INDEX
);
1041 public function isPrimary() {
1042 return (($this->flags
& PRIMARY
) == PRIMARY
);
1045 public function isFullText() {
1046 return (($this->flags
& FULLTEXT
) == FULLTEXT
);
1048 public function isUnique () {
1049 return (($this->flags
& UNIQUE
) == UNIQUE
);
1051 public function setType () {
1052 $incValue = $this->value
;
1054 if (is_int($incValue)) {
1055 $this->type
= 'INT';
1056 } elseif (is_float($incValue)) {
1057 $this->type
= 'FLOAT';
1058 } elseif (is_string($incValue)) {
1059 if (strtotime($this->value
)){
1060 $this->type
= 'DATE';
1061 }elseif (strlen($incValue) > 255)
1062 $this->type
= 'TEXT';
1064 $this->type
= 'VARCHAR';