Example #1
0
 /**
  * Constructor
  *
  * @param object $column
  * @return void
  */
 function __construct($column)
 {
     parent::__construct($column->attrs->name);
     $dbParser = DB::getParser();
     $this->name = $dbParser->parseColumnName($this->name);
     if ($column->attrs->var) {
         $this->argument = new QueryArgument($column);
     } else {
         if (strpos($column->attrs->default, '.') !== FALSE) {
             $this->default_value = "'" . $dbParser->parseColumnName($column->attrs->default) . "'";
         } else {
             $default_value = new DefaultValue($this->name, $column->attrs->default);
             if ($default_value->isOperation()) {
                 $this->argument = new QueryArgument($column, TRUE);
             } else {
                 $this->default_value = $default_value->toString();
                 if ($default_value->isStringFromFunction()) {
                     $this->default_value = '"\'".' . $this->default_value . '."\'"';
                 }
                 if ($default_value->isString()) {
                     $this->default_value = '"' . $this->default_value . '"';
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * constructor
  * @param object $condition
  * @return void
  */
 function __construct($condition)
 {
     $this->operation = $condition->attrs->operation;
     $this->pipe = $condition->attrs->pipe;
     $dbParser = DB::getParser();
     $this->column_name = $dbParser->parseExpression($condition->attrs->column);
     // If default value is column name, it should be escaped
     if ($isColumnName = strpos($condition->attrs->default, '.') !== FALSE && strpos($condition->attrs->default, '.') !== 0 && strpos($condition->attrs->default, '%') === FALSE) {
         $condition->attrs->default = $dbParser->parseExpression($condition->attrs->default);
     }
     if ($condition->node_name == 'query') {
         $this->query = new QueryTag($condition, TRUE);
         $this->default_column = $this->query->toString();
     } else {
         if ($condition->attrs->var && !strpos($condition->attrs->var, '.')) {
             $this->argument = new QueryArgument($condition);
             $this->argument_name = $this->argument->getArgumentName();
         } else {
             if (isset($condition->attrs->default)) {
                 $operationList = array('in' => 1, 'between' => 1, 'notin' => 1, 'not_in' => 1);
                 if (isset($operationList[$this->operation])) {
                     $default_value = $condition->attrs->default;
                     if (strpos($default_value, "'") !== FALSE) {
                         $default_value = "\"" . $default_value . "\"";
                     } else {
                         $default_value = "'" . $default_value . "'";
                     }
                 } else {
                     $default_value_object = new DefaultValue($this->column_name, $condition->attrs->default);
                     $default_value = $default_value_object->toString();
                     if ($default_value_object->isStringFromFunction()) {
                         $default_value = '"\'".' . $default_value . '."\'"';
                     }
                     if ($default_value_object->isString() && !$isColumnName && !is_numeric($condition->attrs->default)) {
                         if (strpos($default_value, "'") !== FALSE) {
                             $default_value = "\"" . $default_value . "\"";
                         } else {
                             $default_value = "'" . $default_value . "'";
                         }
                     }
                 }
                 $this->default_column = $default_value;
             } else {
                 $this->default_column = "'" . $dbParser->parseColumnName($condition->attrs->var) . "'";
             }
         }
     }
 }
Example #3
0
 public function testDefaultValue()
 {
     $default = new DefaultValue("var", '');
     $this->assertEquals('\'\'', $default->toString());
 }