获取表名

@param bool $addTablePrefix 是否返回带表前缀的完整表名
@param bool $addDbName 是否带上dbname

@return string
339439
public function getTableName($addTablePrefix = false, $addDbName = false)
    {
        if (is_null($this->table)) {
            $tmp = get_class($this);
            $this->table = strtolower(substr($tmp, strrpos($tmp, '\\') + 1, -5));
        }

        $dbName = $addDbName ? Config::get($this->getDbConf() . '.master.dbname') . '.' : '';

        if ($addTablePrefix) {
            $tablePrefix = $this->tablePrefix;
            $tablePrefix || $tablePrefix = Config::get($this->getDbConf() . '.master.tableprefix');
            return $dbName . $tablePrefix . $this->table;
        }
        return $dbName . $this->table;
    }
372842
String buildPreparedStatementName(String methodName) {
		String name = methodName + "PreparedStatement" + preparedStatementNames.size();

		preparedStatementNames.add(name);
		return name;
	}
201396
public function statSumDay($db_prefix, $add_time = null)
    {
        if ($add_time === null) {
            $add_time = date('Y-m-d');
        }

        //此处如果使用date_format则不会走索引，因此调整为between，效率提升30倍
        $start_time = $add_time . ' 00:00:00';
        $end_time   = $add_time . ' 23:59:59';

        $sql      = "select sum(num) as num,v1,v2,md5_v2 from {$db_prefix}stat where add_time BETWEEN :start_time and :end_time group by md5_v2";
        $hour_arr = $this->db()->getAll($sql, array('start_time' => $start_time, 'end_time' => $end_time));

        $sql1   = "update {$db_prefix}stat_day set num = :num where md5 = :md5";
        $sql2   = "insert into {$db_prefix}stat_day(num,v1,v2,md5,add_time) values (:num,:v1,:v2,:md5,:add_time)";
        $v1_arr = array();
        foreach ($hour_arr as $v) {

            if ($this->isExist($v['md5_v2'], 'v2', $db_prefix)) {
                $this->db()->execute($sql1, array('num' => $v['num'], 'md5' => $v['md5_v2']));
            } else {
                $this->db()->execute($sql2, array('num' => $v['num'], 'v1' => $v['v1'], 'v2' => $v['v2'], 'md5' => $v['md5_v2'], 'add_time' => $add_time));
                $this->saveStatV1V2($v['v1'], $v['v2'], $db_prefix);
                if (!isset($v1_arr[$v['v1']])) {
                    $this->setStatGroup($v['v1'], $db_prefix);
                    $v1_arr[$v['v1']] = null;
                }
            }

        }

    }
1163498
public function setTableName($tableName)
    {
        $this->tableName = $tableName;
        $this->setPrefix($this->generatePrefix($tableName));
        return $this;
    }
231327
public function getTablePrefix()
    {
        if (isset($this->options['table_prefix'])) {
            $tablePrefix = $this->options['table_prefix'];
        } else {
        	$tablePrefix = $this->getDb()->getTablePrefix();
        }
        
        return $tablePrefix;
    }
1354993
public static function getDbFieldName($propertyName)
    {
        if (!isset(self::$cachedDbFieldNames[$propertyName])) {
            self::$cachedDbFieldNames[$propertyName] = Str::camelToSeparator($propertyName);
        }

        return self::$cachedDbFieldNames[$propertyName];
    }
1025745
public function getName($withoutPrefix = false)
    {
        $name = $this->name;
        if ($withoutPrefix && stripos($name, $this->dbPrefix) === 0) {
            $name = substr($name, strlen($this->dbPrefix));
        }

        return $name;
    }
821671
public function get_context_name($withprefix = true, $short = false) {
        global $DB;

        $name = '';
        if ($user = $DB->get_record('user', array('id'=>$this->_instanceid, 'deleted'=>0))) {
            if ($withprefix){
                $name = get_string('user').': ';
            }
            $name .= fullname($user);
        }
        return $name;
    }
192678
public function getIdColumnName(bool $withTableName = false): string
    {
        return ($withTableName) ? $this->addTableName($this->idColumnName) : $this->idColumnName;
    }
1078816
public function get_physical_table_name($table_name){
		$prefix = $this->conf()->prefix;
		if( strlen($prefix) ){
			$prefix = preg_replace('/\_*$/', '_', $prefix);
		}
		return $prefix.$table_name;
	}
1160755
public static function getAutoParamName()
    {
        $index = RequestContext::get('dbParamInc', 0);
        if($index >= 65535) // 限制dechex()结果最长为ffff，一般一个查询也不会用到这么多参数，足够了
        {
            $index = 0;
        }
        ++$index;
        RequestContext::set('dbParamInc', $index);
        return ':p' . dechex($index);
    }
1358166
public function getTables($matchPrefix = true)
    {
        if ($matchPrefix) {
            $prefix = str_replace('_', '\\_', $this->getPrefix());
            $sql = "SHOW TABLES LIKE '{$prefix}%'";
        } else {
            $sql = 'SHOW TABLES';
        }

        $tables = $this->getValues($sql);

        return $tables;
    }
540649
public function getDbFields($table, $tablePrefix = null, $filter = 0)
    {
        static $dbFieldCache = [];

        is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
        if ($filter == 1 && Cml::$debug) return '*'; //debug模式时直接返回*
        $table = strtolower($tablePrefix . $table);

        $info = false;

        if (isset($dbFieldCache[$table])) {
            $info = $dbFieldCache[$table];
        } else {
            Config::get('db_fields_cache') && $info = \Cml\simpleFileCache($this->conf['master']['dbname'] . '.' . $table);
            if (!$info || Cml::$debug) {
                $this->currentQueryIsMaster = false;
                $stmt = $this->prepare("SHOW COLUMNS FROM $table", $this->rlink, false);
                $this->execute($stmt, false);
                $info = [];
                while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                    $info[$row['Field']] = [
                        'name' => $row['Field'],
                        'type' => $row['Type'],
                        'notnull' => (bool)($row['Null'] === ''), // not null is empty, null is yes
                        'default' => $row['Default'],
                        'primary' => (strtolower($row['Key']) == 'pri'),
                        'autoinc' => (strtolower($row['Extra']) == 'auto_increment'),
                    ];
                }

                count($info) > 0 && \Cml\simpleFileCache($this->conf['master']['dbname'] . '.' . $table, $info);
            }
            $dbFieldCache[$table] = $info;
        }

        if ($filter) {
            if (count($info) > 0) {
                $info = implode('`,`', array_keys($info));
                $info = '`' . $info . '`';
            } else {
                return '*';
            }
        }
        return $info;
    }
512256
public function get_context_name($withprefix = true, $short = false) {
        global $DB;

        $name = '';
        if ($this->_instanceid == SITEID) {
            $name = get_string('frontpage', 'admin');
        } else {
            if ($course = $DB->get_record('course', array('id'=>$this->_instanceid))) {
                if ($withprefix){
                    $name = get_string('course').': ';
                }
                if ($short){
                    $name .= format_string($course->shortname, true, array('context' => $this));
                } else {
                    $name .= format_string(get_course_display_name_for_list($course));
               }
            }
        }
        return $name;
    }
1334188
public function getTable($withPrefix = true)
    {
        return $withPrefix ? $this->getPrefix() . $this->table : $this->table;
    }
1137453
public function getTableName() {
        if(empty($this->trueTableName)) {
            $tableName  = !empty($this->tablePrefix) ? $this->tablePrefix : '';
            if(!empty($this->tableName)) {
                $tableName .= $this->tableName;
            }else{
                $tableName .= parse_name($this->name);
            }
            $this->trueTableName    =   strtolower($tableName);
        }
        return (!empty($this->dbName)?$this->dbName.'.':'').$this->trueTableName;
    }
1181034
public function getDbFields($table, $tablePrefix = null, $filter = 0)
    {
        is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
        $one = $this->runMongoQuery($tablePrefix . $table, [], ['limit' => 1]);
        return empty($one) ? [] : array_keys($one[0]);
    }