C:\xampp\phpMyAdmin\vendor\phpmyadmin\sql-parser\src\Utils\CLI.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php

/**
 * CLI interface.
 */

namespace PhpMyAdmin\SqlParser\Utils;

use 
PhpMyAdmin\SqlParser\Context;
use 
PhpMyAdmin\SqlParser\Lexer;
use 
PhpMyAdmin\SqlParser\Parser;

/**
 * CLI interface.
 *
 * @category   Exceptions
 *
 * @license    https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
 */
class CLI
{
    public function 
mergeLongOpts(&$params, &$longopts)
    {
        foreach (
$longopts as $value) {
            
$value rtrim($value':');
            if (isset(
$params[$value])) {
                
$params[$value[0]] = $params[$value];
            }
        }
    }

    public function 
usageHighlight()
    {
        echo 
"Usage: highlight-query --query SQL [--format html|cli|text]\n";
    }

    public function 
getopt($opt$long)
    {
        return 
getopt($opt$long);
    }

    public function 
parseHighlight()
    {
        
$longopts = array('help''query:''format:');
        
$params $this->getopt(
            
'hq:f:'$longopts
        
);
        if (
$params === false) {
            return 
false;
        }
        
$this->mergeLongOpts($params$longopts);
        if (!isset(
$params['f'])) {
            
$params['f'] = 'cli';
        }
        if (!
in_array($params['f'], array('html''cli''text'))) {
            echo 
"ERROR: Invalid value for format!\n";

            return 
false;
        }

        return 
$params;
    }

    public function 
runHighlight()
    {
        
$params $this->parseHighlight();
        if (
$params === false) {
            return 
1;
        }
        if (isset(
$params['h'])) {
            
$this->usageHighlight();

            return 
0;
        }
        if (isset(
$params['q'])) {
            echo 
Formatter::format(
                
$params['q'], array('type' => $params['f'])
            );
            echo 
"\n";

            return 
0;
        }
        echo 
"ERROR: Missing parameters!\n";
        
$this->usageHighlight();

        return 
1;
    }

    public function 
usageLint()
    {
        echo 
"Usage: lint-query --query SQL\n";
    }

    public function 
parseLint()
    {
        
$longopts = array('help''query:''context:');
        
$params $this->getopt(
            
'hq:c:'$longopts
        
);
        
$this->mergeLongOpts($params$longopts);

        return 
$params;
    }

    public function 
runLint()
    {
        
$params $this->parseLint();
        if (
$params === false) {
            return 
1;
        }
        if (isset(
$params['h'])) {
            
$this->usageLint();

            return 
0;
        }
        if (isset(
$params['c'])) {
            
Context::load($params['c']);
        }
        if (isset(
$params['q'])) {
            
$lexer = new Lexer($params['q'], false);
            
$parser = new Parser($lexer->list);
            
$errors Error::get(array($lexer$parser));
            if (
count($errors) == 0) {
                return 
0;
            }
            
$output Error::format($errors);
            echo 
implode("\n"$output);
            echo 
"\n";

            return 
10;
        }
        echo 
"ERROR: Missing parameters!\n";
        
$this->usageLint();

        return 
1;
    }

    public function 
usageTokenize()
    {
        echo 
"Usage: tokenize-query --query SQL\n";
    }

    public function 
parseTokenize()
    {
        
$longopts = array('help''query:');
        
$params $this->getopt(
            
'hq:'$longopts
        
);
        
$this->mergeLongOpts($params$longopts);

        return 
$params;
    }

    public function 
runTokenize()
    {
        
$params $this->parseTokenize();
        if (
$params === false) {
            return 
1;
        }
        if (isset(
$params['h'])) {
            
$this->usageTokenize();

            return 
0;
        }
        if (isset(
$params['q'])) {
            
$lexer = new Lexer($params['q'], false);
            foreach (
$lexer->list->tokens as $idx => $token) {
                echo 
'[TOKEN '$idx"]\n";
                echo 
'Type = '$token->type"\n";
                echo 
'Flags = '$token->flags"\n";
                echo 
'Value = ';
                
var_export($token->value);
                echo 
"\n";
                echo 
'Token = ';
                
var_export($token->token);
                echo 
"\n";
                echo 
"\n";
            }

            return 
0;
        }
        echo 
"ERROR: Missing parameters!\n";
        
$this->usageTokenize();

        return 
1;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586