Пример #1
0
 /**
  * constructor
  * @param string $column_name column name
  * @param mixed $value value
  * @return void
  */
 function DefaultValue($column_name, $value)
 {
     $dbParser = DB::getParser();
     $this->column_name = $dbParser->parseColumnName($column_name);
     $this->value = $value;
     $this->value = $this->_setValue();
 }
Пример #2
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 . '"';
                 }
             }
         }
     }
 }
Пример #3
0
 /**
  * Constructor
  *
  * @param object $column
  *
  * @return void
  */
 function InsertColumnTag($column)
 {
     parent::ColumnTag($column->attrs->name);
     $dbParser = DB::getParser();
     $this->name = $dbParser->parseColumnName($this->name);
     $this->argument = new QueryArgument($column);
 }
Пример #4
0
 /**
  * Constructor
  *
  * @param object $column
  *
  * @return void
  */
 function __construct($column)
 {
     parent::__construct($column->attrs->name);
     $dbParser = DB::getParser();
     $this->name = $dbParser->parseColumnName($this->name);
     $this->argument = new QueryArgument($column);
 }
Пример #5
0
 /**
  * Prepare runtime context - tell DB class that current DB is CUBRID
  */
 protected function setUp()
 {
     $oContext =& Context::getInstance();
     $db_info->master_db = array('db_type' => 'sqlite3_pdo', 'db_table_prefix' => 'xe_');
     $db_info->slave_db = array(array('db_type' => 'sqlite3_pdo', 'db_table_prefix' => 'xe_'));
     $oContext->setDbInfo($db_info);
     DB::getParser(true);
 }
Пример #6
0
 function &getParser($force = false)
 {
     static $dbParser = null;
     if (!$dbParser || $force) {
         $oDB =& MockDb::getInstance();
         $dbParser = $oDB->getParser();
         DB::getParser(true);
     }
     return $dbParser;
 }
Пример #7
0
 /**
  * Prepare runtime context - tell DB class that current DB is CUBRID
  */
 protected function setUp()
 {
     $this->markTestSkipped();
     $oContext =& Context::getInstance();
     $db_info->master_db = array('db_type' => 'cubrid', 'db_port' => '33000', 'db_hostname' => '10.0.0.206', 'db_userid' => 'dba', 'db_password' => 'arniarules', 'db_database' => 'xe15QA', 'db_table_prefix' => 'xe_');
     $db_info->slave_db = array(array('db_type' => 'cubrid', 'db_port' => '33000', 'db_hostname' => '10.0.0.206', 'db_userid' => 'dba', 'db_password' => 'arniarules', 'db_database' => 'xe15QA', 'db_table_prefix' => 'xe_'));
     $oContext->setDbInfo($db_info);
     // remove cache dir
     FileHandler::removeDir(_XE_PATH_ . 'files/cache');
     DB::getParser(true);
 }
Пример #8
0
 function getTableString()
 {
     $dbParser = DB::getParser();
     $dbType = ucfirst(Context::getDBType());
     $result = sprintf('new %sTableWithHint(\'%s\'%s, array(', $dbType == 'Mysqli' ? 'Mysql' : $dbType, $dbParser->escape($this->name), $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : ', null');
     foreach ($this->index as $indx) {
         $result .= "new IndexHint(";
         $result .= '\'' . $dbParser->escape($indx->name) . '\', \'' . $indx->type . '\'' . ') , ';
     }
     $result = substr($result, 0, -2);
     $result .= '))';
     return $result;
 }
Пример #9
0
 /**
  * Returns the string to be output in the cache file
  *
  * A select column tag in an XML query can be used for:
  * <ul>
  *   <li> a star expression: SELECT *
  *   <li> a click count expression: SELECT + UPDATE
  *   <li> any other select expression (column name, function call etc). </li>
  * </ul>
  *
  * @return string
  */
 function getExpressionString()
 {
     if ($this->name == '*') {
         return "new StarExpression()";
     }
     if ($this->click_count) {
         return sprintf('new ClickCountExpression(\'%s\', %s, $args->%s)', $this->name, $this->alias ? '\'' . $this->alias . '\'' : "''", $this->click_count);
     }
     if (strpos($this->name, '$') === 0) {
         return sprintf('new SelectExpression($args->%s)', substr($this->name, 1));
     }
     $dbParser = DB::getParser();
     return sprintf('new SelectExpression(\'%s\'%s)', $this->name, $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : '');
 }
	/**
	 * Prepare runtime context - tell DB class about current db connection info
	 *
	 * @author Corina Udrescu (dev@xpressengine.org)
	 */
	protected function setUp()
	{
		parent::setUp();

		$oContext = &Context::getInstance();

		$db_info = include dirname(__FILE__) . '/../config/db.config.php';

		$db = new stdClass();
		$db->master_db = $db_info;
		$db->slave_db = array($db_info);
		$oContext->setDbInfo($db);

		DB::getParser(TRUE);
	}
Пример #11
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) . "'";
             }
         }
     }
 }
Пример #12
0
 /**
  * constructor
  * @param array|string $xml_groups
  * @return void
  */
 function GroupsTag($xml_groups)
 {
     $this->groups = array();
     if ($xml_groups) {
         if (!is_array($xml_groups)) {
             $xml_groups = array($xml_groups);
         }
         $dbParser =& DB::getParser();
         for ($i = 0; $i < count($xml_groups); $i++) {
             $group = $xml_groups[$i];
             $column = trim($group->attrs->column);
             if (!$column) {
                 continue;
             }
             $column = $dbParser->parseExpression($column);
             $this->groups[] = $column;
         }
     }
 }
Пример #13
0
 /**
  * Returns string for printing in PHP query cache file
  * The string contains code for instantiation of either 
  * a Table or a JoinTable object
  * @return string 
  */
 function getTableString()
 {
     $dbParser = DB::getParser();
     if ($this->isJoinTable()) {
         return sprintf('new JoinTable(\'%s\', \'%s\', "%s", %s)', $dbParser->escape($this->name), $dbParser->escape($this->alias), $this->join_type, $this->conditionsTag->toString());
     }
     return sprintf('new Table(\'%s\'%s)', $dbParser->escape($this->name), $this->alias ? ', \'' . $dbParser->escape($this->alias) . '\'' : '');
 }
Пример #14
0
 function setColumnList($columnList)
 {
     $this->columnList = $columnList;
     if (count($this->columnList) > 0) {
         $selectColumns = array();
         $dbParser = DB::getParser();
         foreach ($this->columnList as $columnName) {
             $columnName = $dbParser->escapeColumn($columnName);
             $selectColumns[] = new SelectExpression($columnName);
         }
         unset($this->columns);
         $this->columns = $selectColumns;
     }
 }
Пример #15
0
 /**
  * constructor
  * @param object $query
  * @param bool $isSubQuery
  * @return void
  */
 function QueryTag($query, $isSubQuery = false)
 {
     $this->action = $query->attrs->action;
     $this->query_id = $query->attrs->id;
     $this->priority = $query->attrs->priority;
     $this->query = $query;
     $this->isSubQuery = $isSubQuery;
     if ($this->isSubQuery) {
         $this->action = 'select';
     }
     if ($query->attrs->alias) {
         $dbParser = DB::getParser();
         $this->alias = $dbParser->escape($query->attrs->alias);
     }
     $this->join_type = $query->attrs->join_type;
     $this->getColumns();
     $tables = $this->getTables();
     $this->setTableColumnTypes($tables);
     $this->getSubquery();
     // Used for insert-select
     $this->getConditions();
     $this->getGroups();
     $this->getNavigation();
     $this->getPrebuff();
     $this->getBuff();
 }
Пример #16
0
 /**
 	@brief
 	@developer
 	@return
 	@access
 */
 public static function setMssqlDBInfo()
 {
     $db_info = (object) NULL;
     $db_info->master_db = array('db_type' => 'mssql', 'db_hostname' => NULL, 'db_port' => NULL, 'db_userid' => NULL, 'db_password' => NULL, 'db_database' => NULL, 'db_table_prefix' => NULL, 'resource' => TRUE, 'is_connected' => TRUE);
     $db_info->slave_db = array($db_info->master_db);
     $db_info->use_prepared_statements = TRUE;
     self::setDBInfo($db_info);
     if (array_key_exists('__DB__', $GLOBALS) && array_key_exists($db_info->master_db['db_type'], $GLOBALS['__DB__'])) {
     } else {
         $GLOBALS['__DB__'][$db_info->master_db['db_type']] = new DBMssqlConnectWrapper();
     }
     $oDB = new DB();
     $oDB->getParser(TRUE);
 }
Пример #17
0
 /**
  * escape value
  * @param mixed $value
  * @return mixed
  */
 function escapeValue($value)
 {
     $column_type = $this->getType();
     if ($column_type == 'column_name') {
         $dbParser = DB::getParser();
         return $dbParser->parseExpression($value);
     }
     if (!isset($value)) {
         return null;
     }
     $columnTypeList = array('date' => 1, 'varchar' => 1, 'char' => 1, 'text' => 1, 'bigtext' => 1);
     if (isset($columnTypeList[$column_type])) {
         if (!is_array($value)) {
             $value = $this->_escapeStringValue($value);
         } else {
             foreach ($value as $key => $val) {
                 $value[$key] = $this->_escapeStringValue($val);
             }
         }
     }
     if ($this->uses_default_value) {
         return $value;
     }
     if ($column_type == 'number') {
         if (is_array($value)) {
             foreach ($value as $key => $val) {
                 if (isset($val) && $val !== '') {
                     $value[$key] = (int) $val;
                 }
             }
         } else {
             $value = (int) $value;
         }
     }
     return $value;
 }