/*
删除数据
$table:表名
$data:插入数据
972925
public function delete($table = '', $id = '')
    {
        $sql = 'DELETE FROM '.$table.' WHERE id='.$id;
        echo $sql.'<br/>';
        return $this->execute($sql);
    }
134857
public function delete($data = null)
    {
        // 分析查询表达式
        $options = $this->parseExpress();
        $pk      = $this->getPk($options);
        if (isset($options['cache']) && is_string($options['cache']['key'])) {
            $key = $options['cache']['key'];
        }

        if (!is_null($data) && true !== $data) {
            if (!isset($key) && !is_array($data)) {
                // 缓存标识
                $key = 'think:' . $options['table'] . '|' . $data;
            }
            // AR模式分析主键条件
            $this->parsePkWhere($data, $options);
        } elseif (!isset($key) && is_string($pk) && isset($options['where']['AND'][$pk])) {
            $key = $this->getCacheKey($options['where']['AND'][$pk], $options, $this->bind);
        }

        if (true !== $data && empty($options['where'])) {
            // 如果条件为空 不进行删除操作 除非设置 1=1
            throw new Exception('delete without condition');
        }
        // 生成删除SQL语句
        $sql = $this->builder->delete($options);
        // 获取参数绑定
        $bind = $this->getBind();
        if ($options['fetch_sql']) {
            // 获取实际执行的SQL语句
            return $this->connection->getRealSql($sql, $bind);
        }

        // 执行操作
        $result = $this->execute($sql, $bind);
        if ($result) {
            if (!is_array($data) && is_string($pk) && isset($key) && strpos($key, '|')) {
                list($a, $val) = explode('|', $key);
                unset($a);
                $item[$pk]     = $val;
                $data          = $item;
            }
            $options['data'] = $data;
            $this->trigger('after_delete', $options);
        }
        return $result;
    }
213215
public function setNameFromTable()
    {
        $fullName = '';
        $upperCase = true;
        for ($i = 0; $i < strlen($this->table); $i++) {
            $character = $this->table[$i];

            if ($character === '_') {
                $upperCase = true;
            } else {
                $fullName .= $upperCase ? strtoupper($character) : $character;
                $upperCase = false;
            }
        }

        if (substr($fullName, -3) === 'ies') {
            $fullName = substr($fullName, 0, -3) . 'y';
        } elseif (substr($fullName, -3) === 'ses') {
            $fullName = substr($fullName, 0, -3) . 's';
        } elseif (substr($fullName, -1) === 's') {
            $fullName = substr($fullName, 0, -1);
        }

        $this->name = $fullName;
        return $this;
    }
402422
public function make_sign($data){
        /*去空*/
        $data=array_filter($data);
        /*签名步骤一：按字典序排序参数*/
        ksort($data);
        $string_a=http_build_query($data);
        $string_a=urldecode($string_a);

        /*签名步骤二：在string后加入KEY*/
        $config=$this->config;

        $string_sign_temp=$string_a."&key=".$config['key'];
        /*签名步骤三：MD5加密*/
        $sign = md5($string_sign_temp);
        /*签名步骤四：所有字符转为大写*/
        $result=strtoupper($sign);
        return $result;
    }
492130
public function table($table, $as=null)
    {
        if ($as) {
            if (is_array($table)) {
                foreach ($table as $k => $v) {
                    if (isset($as[$k])) $table[$k] .= ' AS ' . $as[$k];
                }
            } else {
                $table .= ' AS ' . $as;
            }
        }
        $this->getQuery()->set('table', $table);    // 设置query对象的table，用于后边生成查询
        return $this;
    }
419996
public function buildInsertSQL($table = null, $data = array())
	{
		$data = $this->parseParams($data);
		if(isAssocArray($data))
		{
			$keys = array_keys($data);
			$valuesKeys = $keys;
			foreach($valuesKeys as $i => $v)
			{
				$valuesKeys[$i] = $this->parseParamName($valuesKeys[$i]);
			}
			return 'insert into ' . $this->parseTable($table) . '(' . implode(',',array_map(array($this,'parseKeyword'),$keys)) . ') values(:' . implode(',:',$valuesKeys) . ')' . $this->parseLock();
		}
		else
		{
			return 'insert into ' . $this->parseTable($table) . ' values(' . substr(str_repeat('?,',count($data)),0,-1) . ')' . $this->parseLock();
		}
	}
1122581
public static function table ($data)
	{
		$in = new self ();
		$in->setData ($data);
		$in->setOutput (new Table ());
		return $in;
	}
807809
public function table($t){
		if(is_array($t)){
			$tArray = $t;
			$t = $t_alias = array_shift(array_keys($tArray));
			$driver = get_called_class();
			if(($tArray[$t_alias] instanceof $driver) === true){
				$this->_placeholders = array_merge($this->_placeholders, $tArray[$t_alias]->queryData());
				$t = $tArray[$t_alias]->queryString();
				$t = "({$t}) AS {$this->formatWithQuote($t_alias, 'alias')}";
			}
			$t = (string) $t;
			$this->_table = trim($t);
		}else{
			$t = \Dorsataio\Squibble\Resource\Extract::fromTable((string) $t);
			$this->_table = trim($t['table']);
			if(isset($t['alias']) && !empty($t['alias'])){
				$this->_table = "{$this->_table} as {$t['alias']}";
			}
		}
		return $this;
	}
473453
private function write($data){
		$result = $this->exdb->delete(
			$this->table_name,
			array($this->table_definition->key_column=>$this->row_id)
		);

		if( !$result ){
			// 書き込みに失敗
			// Sorry, failed to save changes. Please try again later.
			return $this->confirm($data);
		}

		$action = $this->form_endpoint->generate_url($this->table_name, $this->row_id, $this->action_name);
		@header('Location: '.$action.'?'.urlencode(':action').'=done');
		return '';
	}
843380
public function getFields($table)
	{
		// 查询
		$result = $this->query('PRAGMA table_info(' . $this->parseKeyword($table) . ')');
		if (false === $result)
		{
			// 失败
			$result = false;
			return $result;
		}
		else
		{
			$fields = array ();
			$tableSQL = $this->getScalar(<<<SQL
SELECT
	sql
FROM
	(
		SELECT
			*
		FROM
			sqlite_master
		UNION ALL
			SELECT
				*
			FROM
				sqlite_temp_master
	)
WHERE
	name = :name
limit 1
SQL
			, ['name'=>$table]);
			// 处理数据
			foreach($result as $item)
			{
				$fields[$item['name']] = array(
					'name'			=>	$item['name'],
					'type'			=>	$item['type'],
					'length'		=>	0,
					'accuracy'		=>	0,
					'null'			=>	'0' === $item['notnull'],
					'default'		=>	$item['dflt_value'],
					'pk'			=>	'1' === $item['pk'],
					'is_auto_inc'	=>	'1' === $item['pk'] && preg_match('/[^`\[\'"]+[`\[\'"\s]AUTOINCREMENT/im', $tableSQL) > 0,
					'key'			=>	$item['Key'],
					'extra'			=>	$item['Extra']
				);
			}
			// 返回结果
			return $fields;
		}
	}
627088
public function getQueryData($table, array $data)
    {
        $columns = $this->getSchemaManager()->listTableColumns($table);

        $allColumnTypes = $this->getColumnTypes($table);
        $columnTypes = [];
        foreach ($columns as $column) {
            $columnName = $column->getName();
            if (\array_key_exists($columnName, $data)) {
                $columnTypes[$this->connection->quoteIdentifier($columnName)] = $allColumnTypes[$columnName];
            }
        }

        $quotedData = [];
        foreach ($data as $column => $value) {
            $quotedColumn = $this->connection->quoteIdentifier($column);
            if (\array_key_exists($quotedColumn, $columnTypes)) {
                $quotedData[$quotedColumn] = $value;
            }
        }

        \ksort($quotedData);
        \ksort($columnTypes);

        return new QueryData(
            $this->connection->quoteIdentifier($table),
            $quotedData,
            \array_values($columnTypes)
        );
    }
1168082
public function FormatTableName($Table) {

      if (strpos($Table, '.') !== FALSE){
         if(preg_match('/^([^\s]+)\s+(?:as\s+)?`?([^`]+)`?$/', $Table, $Matches)){
            $DatabaseTable = '`' . str_replace('.', '`.`', $Matches[1]) . '`';
            $Table = str_replace($Matches[1], $DatabaseTable, $Table);
         }else
            $Table = '`' . str_replace('.', '`.`', $Table) . '`';
      }
      return $Table;
   }
508086
public function getTableName($table) {
        if (preg_match('#^`?\{[^\}]+\}.*$#', $table)) {
            return $this->sanitize(str_replace(['{', '}'], [$this->tablePrefix, ''], $table));
        } else {
            return $this->sanitize($table);
        }
    }
1212786
private function makeTable($data){
        $return = '<div id="'.base64_encode($data['requestUrl']).'" class="api-main">
        <div class="title">'.$data['methodName'].'</div>
        <div class="body">
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>
                        '.$data['requestName'].'
                        </th>
                        <th rowspan="3">
                        '.$data['requestUrl'].'
                        </th>
                    </tr>
                </thead>
            </table>
        </div>';
        if(count($data['param'])!=0){
            $return .= '                    <div class="body">
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>
                            请求名称
                        </th>
                        <th>
                            请求类型
                        </th>
                        <th>
                            请求说明
                        </th>
                    </tr>
                </thead>
                <tbody>';
            foreach($data['param'] as $param){
                $return .= '<tr>
                <td>
                    '.$param['var'].'
                </td>
                <td>
                '.$param['type'].'
                </td>
                <td>
                '.$param['about'].'
                </td>
            </tr>';
            }
            $return .= '</tbody>
            </table>
        </div>';
        }
        if(count($data['return'])!=0){
            $return .= '<div class="body">
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>
                            返回名称
                        </th>
                        <th>
                            返回类型
                        </th>
                        <th>
                            返回说明
                        </th>
                    </tr>
                </thead>
                <tbody>';
            foreach($data['return'] as $param){
                $return .= '<tr>
                <td>
                    '.$param['var'].'
                </td>
                <td>
                '.$param['type'].'
                </td>
                <td>
                '.$param['about'].'
                </td>
            </tr>';
            }
            $return .= '</tbody>
            </table>
        </div>';
        }

        $return .= ' <hr>
        </div>';

        return $return;
    }
1010349
static function parseHeader($data)
    {
        $header = array();
        $header[0] = array();
        $meta = &$header[0];
        $parts = explode("\r\n\r\n", $data, 2);

        // parts[0] = HTTP头;
        // parts[1] = HTTP主体，GET请求没有body
        $headerLines = explode("\r\n", $parts[0]);

        // HTTP协议头,方法，路径，协议[RFC-2616 5.1]
        list($meta['method'], $meta['uri'], $meta['protocol']) = explode(' ', $headerLines[0], 3);

        //错误的HTTP请求
        if (empty($meta['method']) or empty($meta['uri']) or empty($meta['protocol']))
        {
            return false;
        }
        unset($headerLines[0]);
        //解析Header
        $header = array_merge($header, self::parseHeaderLine($headerLines));
        return $header;
    }
969433
public function field_data($table)
	{
		$sql = 'SELECT "colname" AS "name", "typename" AS "type", "default" AS "default", "length" AS "max_length",
				CASE "keyseq" WHEN NULL THEN 0 ELSE 1 END AS "primary_key"
			FROM "syscat"."columns"
			WHERE LOWER("tabschema") = '.$this->escape(strtolower($this->database)).'
				AND LOWER("tabname") = '.$this->escape(strtolower($table)).'
			ORDER BY "colno"';

		return (($query = $this->query($sql)) !== FALSE)
			? $query->result_object()
			: FALSE;
	}
761969
function &MetaColumnNames($table, $numIndexes = false, $useattnum = false)
        {
                $recordSet = $this->Execute("select name from system.columns where parent='$table'");
                if(!$recordSet){
                        print $this->ErrorMsg();
                        return false;
                }
                else{
                        $i=0;
                        while (!$recordSet->EOF){
                                $arr["FIELD$i"] = $recordSet->fields[0];
                                $recordSet->MoveNext();
                                $i=$i+1;
                        }
                        return $arr;
                }
        }