Ejemplo n.º 1
0
 /**
  * Recupera uma sequencia para um campo
  * 
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br/
  * @param array $field
  * @return string
  */
 public function getSequence($field)
 {
     $st = null;
     $con_st = $this->obj->_getConnection()->getOption('sequence_type');
     if (empty($field['sequence_type'])) {
         $st = $con_st;
     } else {
         $st = $field['sequence_type'];
     }
     $dialect = $this->obj->_getConfiguration()->getProperty('dialect');
     switch ($st) {
         case self::SEQUENCE:
             $class = $dialect . "_Sequence";
             Lumine::load('Sequence_' . $class);
             $this->seq_obj = new $class($obj, $field);
             break;
         case self::COUNT_TABLE:
             $class = $dialect . "_Count";
             Lumine::load('Sequence_' . $class);
             $this->seq_obj = new $class($obj, $field);
             break;
         case self::NATURAL:
         default:
             $class = $dialect . "_Natural";
             Lumine::load('Sequence_' . $class);
             $this->seq_obj = new $class($obj, $field);
     }
     $this->seq_obj->createSequence();
     return $this->seq_obj;
 }
Ejemplo n.º 2
0
 /**
  * Recupera o dialeto para o objeto
  * 
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br/
  * @param Lumine_Base $obj
  * @return ILumine_Dialect
  */
 public static function get(Lumine_Base $obj)
 {
     $dialect = $obj->_getConfiguration()->getProperty('dialect');
     $id = $obj->_getObjectPart('_objectID');
     if (!array_key_exists($dialect, self::$createdItems)) {
         Lumine::load('Lumine_Dialect_' . $dialect);
         $ref = new ReflectionClass('Lumine_Dialect_' . $dialect);
         self::$createdItems[$dialect] = $ref->newInstance();
     }
     self::$createdItems[$dialect]->setConnection($obj->_getConnection());
     self::$createdItems[$dialect]->setObjectId($id);
     self::$createdItems[$dialect]->setTablename($obj->tablename());
     return self::$createdItems[$dialect];
 }
Ejemplo n.º 3
0
 /**
  * Faz o parse do dataselect de uma instancia
  * 
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br/
  * @param string $dataStr
  * @param Lumine_Base $obj
  * @return string
  */
 public static function dataSelect($dataStr, Lumine_Base $obj)
 {
     $idx = 0;
     $total = strlen($dataStr);
     $d = ',';
     $tokens = array();
     $inStr = false;
     $inFunction = 0;
     $inStrStart = '';
     for ($i = 0; $i < $total; $i++) {
         $c = substr($dataStr, $i, 1);
         if ($c == '(' && !$inStr) {
             $inFunction++;
         }
         if ($c == ')' && !$inStr) {
             $inFunction--;
         }
         if (!$inStr && ($c == '"' || $c == "'") && substr($dataStr, $i - 1, 1) != '\\' && $c != '\\') {
             $inStr = true;
             $inStrStart = $c;
         }
         if ($inStr == true && $c == $inStrStart) {
             if (!empty($tokens)) {
                 $tmp_test = str_replace($obj->_getConnection()->getEscapeChar() . $inStrStart, '', $c . $tokens[$idx] . $c);
                 if (substr_count($tmp_test, "'") % 2 == 0) {
                     $inStr = false;
                     $tmp = '';
                     $inStrStart = '';
                 }
             }
         }
         if ($inFunction == 0 && !$inStr && $c == $d) {
             $idx++;
             continue;
         }
         if (!isset($tokens[$idx])) {
             $tokens[$idx] = '';
         }
         $tokens[$idx] .= $c;
     }
     foreach ($tokens as $id => $token) {
         $tokens[$id] = trim($token);
     }
     return $tokens;
 }
Ejemplo n.º 4
0
 /**
  * Faz o parse do valor para SQL
  * 
  * @author Hugo Ferreira da Silva
  * @link http://www.hufersil.com.br/
  * @param Lumine_Base|array $obj
  * @param mixed             $val
  * @param string            $type
  * @param boolean           $islike
  * @return mixed
  */
 public static function getParsedValue($obj, $val, $type, $islike = false, $usingDefault = false)
 {
     if (is_null($val) == true) {
         return 'NULL';
     }
     // se esta informando atraves de um valor padrao
     if ($usingDefault && !is_array($val) && !is_object($val)) {
         // pegamos o prefixo do valor
         $prefix = substr($val, 0, strlen(Lumine::DEFAULT_VALUE_FUNCTION_IDENTIFIER));
         // se for para ser aplicado como uma funcao do banco
         if ($prefix == Lumine::DEFAULT_VALUE_FUNCTION_IDENTIFIER) {
             // removemos o prefixo e devolvemos o valor que sera usado como funcao
             return str_replace($prefix, '', $val);
         }
     }
     switch ($type) {
         case 'smallint':
         case 'int':
         case 'integer':
             $val = sprintf('%d', $val);
             break;
         case 'float':
         case 'double':
             $val = sprintf('%f', $val);
             break;
         case 'date':
             /*
             				if(is_numeric($val))
             				{
             					$val = "'" . date('Y-m-d', $val) . "'";
             				} else {
             					$val = "'" . date('Y-m-d', strtotime($val)) . "'";
             				}*/
             $val = "'" . Lumine_Util::FormatDate($val, '%Y-%m-%d') . "'";
             break;
         case 'datetime':
             /*
             if(is_numeric($val))
             {
             	$val = "'" . date('Y-m-d H:i:s', $val) . "'";
             } else {
             	$val = "'" . date('Y-m-d H:i:s', strtotime($val)) . "'";
             }
             */
             $val = "'" . Lumine_Util::FormatDateTime($val, '%Y-%m-%d %H:%M:%S') . "'";
             break;
         case 'time':
             $val = Lumine_Util::FormatTime($val, '%H:%M:%S');
             $val = "'" . $val . "'";
             break;
         case 'boolean':
             $val = sprintf("'%d'", $val);
             break;
         case 'string':
         case 'text':
         case 'varchar':
         case 'char':
         default:
             if ($islike == true) {
                 $val = "'%" . $obj->_getConnection()->escape($val) . "%'";
             } else {
                 $val = "'" . $obj->_getConnection()->escape($val) . "'";
             }
             break;
     }
     return $val;
 }