質問編集履歴
2
セキュリティの関わる問題なので削除させていただきました。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
セキュリティの関わる問題なので削除させていただきました。
|
body
CHANGED
@@ -1,123 +1,1 @@
|
|
1
|
-
下記のコードの解読をしているのですが意味が全くわかわずわかる方いらっしゃいましたら教えてください。
|
2
|
-
|
3
|
-
```php
|
4
|
-
//EXPLAINファイルを解析してクエリ種類とデータベース名を抽出
|
5
|
-
function CheckExplainParce($u_userid,$u_id){
|
6
|
-
$cnt=0;
|
7
|
-
$results=array();
|
8
|
-
|
1
|
+
セキュリティの関わる問題なので削除させていただきました。
|
9
|
-
$sql_query="";
|
10
|
-
$sql_query_no=0;
|
11
|
-
$exp_file=DIR_RESULT."/${u_userid}/${u_id}.exp";
|
12
|
-
|
13
|
-
if ( !($fp=fopen($exp_file,"r")) ){ return $results; }
|
14
|
-
while(!feof($fp)){
|
15
|
-
$data = fgets($fp, 10240);
|
16
|
-
$data=str_replace(array("\r\n","\n","\r"), '', $data);
|
17
|
-
if ( eregi("^use ",$data) ){
|
18
|
-
list($dummy,$cur_db)=split("[ ;]",$data);
|
19
|
-
}
|
20
|
-
|
21
|
-
//クエリ
|
22
|
-
if ( eregi("^explain ",$data) ){
|
23
|
-
$sql_query=substr($data,8);
|
24
|
-
//$this->log("QUERY=[$sql_query]",LOG_DEBUG);
|
25
|
-
$sql_query_no++;
|
26
|
-
}
|
27
|
-
|
28
|
-
// トークン部分の解析
|
29
|
-
//
|
30
|
-
// 【解析仕様】
|
31
|
-
// ・トークンは『ABSTRACT SYNTAX TREE』行と『STAGE DEPENDENCIES』行の間にある
|
32
|
-
// ・データベース名及びテーブル名(以降 オブジェクト部)は次のターゲットトークンの次の行以降にインデントされて定義されている
|
33
|
-
// → TOK_TABNAME、TOK_TABTYPE、TOK_ALTERTABLE、TOK_TABTYPE、TOK_SHOW
|
34
|
-
// ・オブジェクト部には『データベース名行 + テーブル名行』または『テーブル名行』のパターンがある
|
35
|
-
// ・オブジェクト部の範囲はターゲットトークンのインデントと同じまたは浅い行の前行までとする
|
36
|
-
// ・オブジェクト部に別のターゲットトークンがあった場合、オブジェクト部はその前行までとし、別のターゲットトークン以降を新しいオブジェクト部として処理する
|
37
|
-
//
|
38
|
-
if (eregi("^ABSTRACT SYNTAX TREE", $data) and !feof($fp)) {
|
39
|
-
$data = fgets($fp, 10240);
|
40
|
-
$data = str_replace(array("\r\n","\n","\r"), '', $data);
|
41
|
-
|
42
|
-
$sql_type="";
|
43
|
-
|
44
|
-
while (!feof($fp)) {
|
45
|
-
if (eregi("^STAGE DEPENDENCIES", $data)) { break; }
|
46
|
-
|
47
|
-
$sql_type = CommonComponent::CheckTOK2SQLtype(trim($data), $sql_type);
|
48
|
-
|
49
|
-
if (eregi("^TOK_TABNAME|^TOK_TABTYPE|^TOK_ALTERTABLE|^TOK_TABTYPE|^TOK_SHOW|^TOK_CREATEDATABASE|^TOK_DROPDATABASE", trim($data))) {
|
50
|
-
$tok_indent = strlen($data) - strlen(ltrim($data));
|
51
|
-
$token = trim($data);
|
52
|
-
|
53
|
-
$data = fgets($fp, 10240);
|
54
|
-
$data = str_replace(array("\r\n","\n","\r"), '', $data);
|
55
|
-
|
56
|
-
$objects = array();
|
57
|
-
|
58
|
-
while (!feof($fp)) {
|
59
|
-
if (eregi("^TOK_TABNAME|^TOK_TABTYPE|^TOK_ALTERTABLE|^TOK_TABTYPE|^TOK_SHOW|^TOK_CREATEDATABASE|^TOK_DROPDATABASE", trim($data))) { break; }
|
60
|
-
if ($tok_indent >= (strlen($data) - strlen(ltrim($data)))) { break; }
|
61
|
-
|
62
|
-
if (!eregi("^TOK_|.", trim($data))) {
|
63
|
-
$objects[] = trim($data);
|
64
|
-
}
|
65
|
-
$data = fgets($fp, 10240);
|
66
|
-
$data=str_replace(array("\r\n","\n","\r"), '', $data);
|
67
|
-
}
|
68
|
-
|
69
|
-
if (count($objects) >= 2) {
|
70
|
-
$results[$cnt]->no = $sql_query_no;
|
71
|
-
$results[$cnt]->type = $sql_type;
|
72
|
-
$results[$cnt]->db = $objects[0];
|
73
|
-
$results[$cnt]->tbl = $objects[1];
|
74
|
-
$cnt++;
|
75
|
-
} else if (count($objects) == 1) {
|
76
|
-
$results[$cnt]->no = $sql_query_no;
|
77
|
-
$results[$cnt]->type = $sql_type;
|
78
|
-
if (eregi("^TOK_SHOW|^TOK_CREATEDATABASE|^TOK_DROPDATABASE", $token)) {
|
79
|
-
$results[$cnt]->db = $objects[0];
|
80
|
-
$results[$cnt]->tbl = "";
|
81
|
-
} else {
|
82
|
-
$results[$cnt]->db = $cur_db;
|
83
|
-
$results[$cnt]->tbl = $objects[0];
|
84
|
-
}
|
85
|
-
$cnt++;
|
86
|
-
} else if (count($objects) == 0 and eregi("^TOK_SHOW", $token)) {
|
87
|
-
$results[$cnt]->no = $sql_query_no;
|
88
|
-
$results[$cnt]->type = $sql_type;
|
89
|
-
$results[$cnt]->db = $cur_db;
|
90
|
-
$results[$cnt]->tbl = "";
|
91
|
-
$cnt++;
|
92
|
-
}
|
93
|
-
} else {
|
94
|
-
$data = fgets($fp, 10240);
|
95
|
-
$data = str_replace(array("\r\n","\n","\r"), '', $data);
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
$sql_query = "";
|
100
|
-
}
|
101
|
-
}
|
102
|
-
fclose($fp);
|
103
|
-
return $results;
|
104
|
-
}
|
105
|
-
```
|
106
|
-
|
107
|
-
```php
|
108
|
-
//トークン名からクエリに変換
|
109
|
-
function CheckTOK2SQLtype($data,$sql_type){
|
110
|
-
if ( $data == "TOK_DESCTABLE" ){ return "desc"; }
|
111
|
-
if ( $data == "TOK_CREATETABLE" ){ return "create table"; }
|
112
|
-
if ( $data == "TOK_TABREF" ){ return "select"; }
|
113
|
-
if ( $data == "TOK_INSERT" ){ return "insert"; }
|
114
|
-
if ( $data == "TOK_DROPTABLE" ){ return "drop table"; }
|
115
|
-
if ( eregi("^TOK_SHOW",$data) ){ return "show"; }
|
116
|
-
if ( eregi("^TOK_ALTER",$data) ){ return "alter table"; }
|
117
|
-
|
118
|
-
if ( $data == "TOK_CREATEDATABASE" ){ return "create database"; }
|
119
|
-
if ( $data == "TOK_DROPDATABASE" ){ return "drop database"; }
|
120
|
-
|
121
|
-
return $sql_type;
|
122
|
-
}
|
123
|
-
```
|
1
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -59,7 +59,7 @@
|
|
59
59
|
if (eregi("^TOK_TABNAME|^TOK_TABTYPE|^TOK_ALTERTABLE|^TOK_TABTYPE|^TOK_SHOW|^TOK_CREATEDATABASE|^TOK_DROPDATABASE", trim($data))) { break; }
|
60
60
|
if ($tok_indent >= (strlen($data) - strlen(ltrim($data)))) { break; }
|
61
61
|
|
62
|
-
if (!eregi("^TOK_|
|
62
|
+
if (!eregi("^TOK_|.", trim($data))) {
|
63
63
|
$objects[] = trim($data);
|
64
64
|
}
|
65
65
|
$data = fgets($fp, 10240);
|
@@ -102,4 +102,22 @@
|
|
102
102
|
fclose($fp);
|
103
103
|
return $results;
|
104
104
|
}
|
105
|
+
```
|
106
|
+
|
107
|
+
```php
|
108
|
+
//トークン名からクエリに変換
|
109
|
+
function CheckTOK2SQLtype($data,$sql_type){
|
110
|
+
if ( $data == "TOK_DESCTABLE" ){ return "desc"; }
|
111
|
+
if ( $data == "TOK_CREATETABLE" ){ return "create table"; }
|
112
|
+
if ( $data == "TOK_TABREF" ){ return "select"; }
|
113
|
+
if ( $data == "TOK_INSERT" ){ return "insert"; }
|
114
|
+
if ( $data == "TOK_DROPTABLE" ){ return "drop table"; }
|
115
|
+
if ( eregi("^TOK_SHOW",$data) ){ return "show"; }
|
116
|
+
if ( eregi("^TOK_ALTER",$data) ){ return "alter table"; }
|
117
|
+
|
118
|
+
if ( $data == "TOK_CREATEDATABASE" ){ return "create database"; }
|
119
|
+
if ( $data == "TOK_DROPDATABASE" ){ return "drop database"; }
|
120
|
+
|
121
|
+
return $sql_type;
|
122
|
+
}
|
105
123
|
```
|