148 lines
3.8 KiB
PHP
148 lines
3.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
class biTest
|
|
{
|
|
public function __construct()
|
|
{
|
|
global $tester;
|
|
$this->objectModel = $tester->loadModel('bi');
|
|
}
|
|
|
|
/**
|
|
* Parse sql test
|
|
*
|
|
* @param string $sql
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function parseSqlTest($sql)
|
|
{
|
|
$columns = $this->objectModel->parseSql($sql);
|
|
|
|
$result = array();
|
|
foreach($columns as $field => $column)
|
|
{
|
|
if(empty($column['table'])) continue;
|
|
|
|
$result[$field] = "{$column['table']['originTable']}=>{$column['table']['column']}";
|
|
}
|
|
|
|
arsort($result);
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* get expression test.
|
|
*
|
|
* @param string $table
|
|
* @param string $column
|
|
* @param string $alias
|
|
* @param string $function
|
|
* @access public
|
|
* @return string
|
|
*/
|
|
public function getExpressionTest($table = null, $column = null, $alias = null, $function = null)
|
|
{
|
|
$expression = $this->objectModel->getExpression($table, $column, $alias, $function);
|
|
return trim($expression->build($expression));
|
|
}
|
|
|
|
/**
|
|
* get condition test.
|
|
*
|
|
* @param mixed $tableA
|
|
* @param mixed $columnA
|
|
* @param string $operator
|
|
* @param mixed $tableB
|
|
* @param mixed $columnB
|
|
* @param int $group
|
|
* @access public
|
|
* @return string
|
|
*/
|
|
public function getConditionTest(mixed $tableA = null, mixed $columnA = null, string $operator = '', mixed $tableB = null, mixed $columnB = null, int $group = 1, bool $quote = true): string
|
|
{
|
|
$condition = $this->objectModel->getCondition($tableA, $columnA, $operator, $tableB, $columnB, $group, $quote);
|
|
return $condition->build($condition);
|
|
}
|
|
|
|
/**
|
|
* build SQL test.
|
|
*
|
|
* @param array $args
|
|
* @access public
|
|
* @return string
|
|
*/
|
|
public function buildSQLTest(array $args): string
|
|
{
|
|
$selects = zget($args, 'selects', array());
|
|
$from = zget($args, 'from', array());
|
|
$joins = zget($args, 'joins', array());
|
|
$functions = zget($args, 'functions', array());
|
|
$wheres = zget($args, 'wheres', array());
|
|
$querys = zget($args, 'querys', array());
|
|
$groups = zget($args, 'groups', array());
|
|
$statement = $this->objectModel->buildSQL($selects, $from, $joins, $functions, $wheres, $querys, $groups);
|
|
return str_replace(PHP_EOL, '', $statement->build());
|
|
}
|
|
|
|
/**
|
|
* get columns native type
|
|
*
|
|
* @param string $sql
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getColumns($sql)
|
|
{
|
|
$columns = $this->objectModel->getColumns($sql, 'mysql');
|
|
|
|
$nativeTypes = array();
|
|
foreach($columns as $field => $fieldInfo)
|
|
{
|
|
$nativeTypes[$field] = $fieldInfo['native_type'];
|
|
}
|
|
|
|
return $nativeTypes;
|
|
}
|
|
|
|
/**
|
|
* get tables and fields
|
|
*
|
|
* @param string $sql
|
|
* @access public
|
|
* @return array
|
|
*/
|
|
public function getTableAndFields($sql)
|
|
{
|
|
$tableAndFields = $this->objectModel->getTableAndFields($sql);
|
|
return $tableAndFields;
|
|
}
|
|
|
|
/**
|
|
* Test process vars.
|
|
*
|
|
* @param string $sql
|
|
* @param array $filters
|
|
* @param bool $emptyValue
|
|
* @access public
|
|
* @return string
|
|
*/
|
|
public function processVarsTest($sql, $filters, $emptyValue)
|
|
{
|
|
return $this->objectModel->processVars($sql, $filters, $emptyValue);
|
|
}
|
|
|
|
/**
|
|
* Test prepareBuiltinPivot.
|
|
*
|
|
* @param string $operate
|
|
* @access public
|
|
* @return string
|
|
*/
|
|
public function prepareBuiltinPivotSQLTest($operate)
|
|
{
|
|
return $this->objectModel->prepareBuiltinPivotSQL($operate);
|
|
}
|
|
}
|