| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 239 |
liveuser |
6 |
Copyright (C) 2014~2026 MIN ZHI, CHEN
|
| 3 |
liveuser |
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
提供apache hive相關應用的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class hive{
|
| 226 |
liveuser |
33 |
|
| 3 |
liveuser |
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#參考資料:
|
|
|
45 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
46 |
*/
|
|
|
47 |
public function __call($method,$arguments){
|
| 226 |
liveuser |
48 |
|
| 3 |
liveuser |
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
51 |
|
| 3 |
liveuser |
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
| 226 |
liveuser |
54 |
|
| 3 |
liveuser |
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
57 |
|
| 3 |
liveuser |
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
60 |
|
| 3 |
liveuser |
61 |
#回傳結果
|
|
|
62 |
return $result;
|
| 226 |
liveuser |
63 |
|
| 3 |
liveuser |
64 |
}#function __call end
|
| 226 |
liveuser |
65 |
|
| 3 |
liveuser |
66 |
/*
|
|
|
67 |
#函式說明:
|
|
|
68 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
69 |
#回傳結果:
|
|
|
70 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
71 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
72 |
#$result["function"],當前執行的函式名稱.
|
|
|
73 |
#必填參數:
|
|
|
74 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
75 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
76 |
#參考資料:
|
|
|
77 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
78 |
*/
|
|
|
79 |
public static function __callStatic($method,$arguments){
|
| 226 |
liveuser |
80 |
|
| 3 |
liveuser |
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
83 |
|
| 3 |
liveuser |
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
| 226 |
liveuser |
86 |
|
| 3 |
liveuser |
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
89 |
|
| 3 |
liveuser |
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
92 |
|
| 3 |
liveuser |
93 |
#回傳結果
|
|
|
94 |
return $result;
|
| 226 |
liveuser |
95 |
|
| 3 |
liveuser |
96 |
}#function __callStatic end
|
| 226 |
liveuser |
97 |
|
| 3 |
liveuser |
98 |
/*
|
|
|
99 |
#函數說明:
|
|
|
100 |
#apache hive官方提供的PHP API
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
103 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
104 |
#$result["error"],陣列,錯訊訊息.
|
|
|
105 |
#$result["content"],執行完query的回傳內容.
|
|
|
106 |
#$result["qStr"],查詢的語句.
|
|
|
107 |
#必填參數:
|
|
|
108 |
#$conf["thrift_root"],字串,存有 hive 散布的 php THRIFT_ROOT 路徑.
|
|
|
109 |
$conf["thrift_root"]="";
|
|
|
110 |
#可省略參數:
|
|
|
111 |
#$conf["fileArgu"],字串,__FILE__的內容,預設為__FILE__.
|
|
|
112 |
#$conf["fileArgu"]=__FILE__;
|
|
|
113 |
#備註:
|
|
|
114 |
#建構中...,套件THRIFT有問題
|
|
|
115 |
*/
|
|
|
116 |
/*
|
|
|
117 |
function nativeQuery(&$conf=array()){
|
| 226 |
liveuser |
118 |
|
| 3 |
liveuser |
119 |
#初始化要回傳的結果
|
|
|
120 |
$result=array();
|
|
|
121 |
|
|
|
122 |
#取得當前執行的函數名稱
|
|
|
123 |
$result["function"]=__FUNCTION__;
|
|
|
124 |
|
|
|
125 |
#如果沒有參數
|
|
|
126 |
if(func_num_args()==0){
|
| 226 |
liveuser |
127 |
|
| 3 |
liveuser |
128 |
#設置執行失敗
|
|
|
129 |
$result["status"]="false";
|
| 226 |
liveuser |
130 |
|
| 3 |
liveuser |
131 |
#設置執行錯誤訊息
|
|
|
132 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
133 |
|
| 3 |
liveuser |
134 |
#回傳結果
|
|
|
135 |
return $result;
|
| 226 |
liveuser |
136 |
|
| 3 |
liveuser |
137 |
}#if end
|
|
|
138 |
|
|
|
139 |
#取得參數
|
|
|
140 |
$result["argu"]=$conf;
|
|
|
141 |
|
|
|
142 |
#如果 $conf 不為陣列
|
|
|
143 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
144 |
|
| 3 |
liveuser |
145 |
#設置執行失敗
|
|
|
146 |
$result["status"]="false";
|
| 226 |
liveuser |
147 |
|
| 3 |
liveuser |
148 |
#設置執行錯誤訊息
|
|
|
149 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
150 |
|
| 3 |
liveuser |
151 |
#如果傳入的參數為 null
|
|
|
152 |
if($conf==null){
|
| 226 |
liveuser |
153 |
|
| 3 |
liveuser |
154 |
#設置執行錯誤訊息
|
|
|
155 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
156 |
|
| 3 |
liveuser |
157 |
}#if end
|
|
|
158 |
|
|
|
159 |
#回傳結果
|
|
|
160 |
return $result;
|
| 226 |
liveuser |
161 |
|
| 3 |
liveuser |
162 |
}#if end
|
| 226 |
liveuser |
163 |
|
| 3 |
liveuser |
164 |
#檢查參數
|
|
|
165 |
#函式說明:
|
|
|
166 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
167 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
168 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
169 |
#$result["function"],當前執行的函式名稱.
|
|
|
170 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
171 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
172 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
173 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
174 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
175 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
176 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
177 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
178 |
#必填寫的參數:
|
|
|
179 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
180 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
181 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
182 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("thrift_root");
|
|
|
183 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
184 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
185 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
186 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
187 |
#可以省略的參數:
|
|
|
188 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
189 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
190 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
191 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
192 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
193 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu");
|
| 226 |
liveuser |
194 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
195 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
196 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
197 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__);
|
|
|
198 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
199 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
200 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
201 |
#參考資料來源:
|
|
|
202 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
203 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
204 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
205 |
|
| 3 |
liveuser |
206 |
#如果檢查參數失敗
|
|
|
207 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
208 |
|
| 3 |
liveuser |
209 |
#設置執行不正常
|
|
|
210 |
$result["status"]="false";
|
| 226 |
liveuser |
211 |
|
| 3 |
liveuser |
212 |
#設置執行錯誤
|
|
|
213 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
214 |
|
| 3 |
liveuser |
215 |
#回傳結果
|
|
|
216 |
return $result;
|
| 226 |
liveuser |
217 |
|
| 3 |
liveuser |
218 |
}#if end
|
| 226 |
liveuser |
219 |
|
| 3 |
liveuser |
220 |
#如果檢查參數不通過
|
|
|
221 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
222 |
|
| 3 |
liveuser |
223 |
#設置執行不正常
|
|
|
224 |
$result["status"]="false";
|
| 226 |
liveuser |
225 |
|
| 3 |
liveuser |
226 |
#設置執行錯誤
|
|
|
227 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
228 |
|
| 3 |
liveuser |
229 |
#回傳結果
|
|
|
230 |
return $result;
|
| 226 |
liveuser |
231 |
|
| 3 |
liveuser |
232 |
}#if end
|
| 226 |
liveuser |
233 |
|
| 3 |
liveuser |
234 |
#轉換 $conf["thrift_root"] 路徑為伺服器上的絕對路徑
|
|
|
235 |
#函數說明:
|
|
|
236 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
237 |
#回傳結果:
|
|
|
238 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
239 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
240 |
#$result["function"],函數名稱.
|
| 3 |
liveuser |
241 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
242 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
243 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
|
|
|
244 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
245 |
#必填參數:
|
|
|
246 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
247 |
$conf["fileAccess::getInternetAddress"]["address"]=$conf["thrift_root"];
|
|
|
248 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
249 |
$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
|
|
|
250 |
#可省略參數:
|
|
|
251 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
252 |
$conf["fileAccess::getInternetAddress"]["userDir"]="true";
|
|
|
253 |
#備註:
|
|
|
254 |
#在命令列執行,所得的路徑是錯誤的。
|
| 226 |
liveuser |
255 |
$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
|
| 3 |
liveuser |
256 |
unset($conf["fileAccess::getInternetAddress"]);
|
|
|
257 |
|
|
|
258 |
#如果轉換路徑失敗
|
|
|
259 |
if($getInternetAddress["status"]=="false"){
|
| 226 |
liveuser |
260 |
|
| 3 |
liveuser |
261 |
#設置執行不正常
|
|
|
262 |
$result["status"]="false";
|
| 226 |
liveuser |
263 |
|
| 3 |
liveuser |
264 |
#設置執行錯誤
|
|
|
265 |
$result["error"]=$getInternetAddress;
|
| 226 |
liveuser |
266 |
|
| 3 |
liveuser |
267 |
#回傳結果
|
|
|
268 |
return $result;
|
| 226 |
liveuser |
269 |
|
| 3 |
liveuser |
270 |
}#if end
|
| 226 |
liveuser |
271 |
|
| 3 |
liveuser |
272 |
// set THRIFT_ROOT to php directory of the hive distribution
|
|
|
273 |
$GLOBALS['THRIFT_ROOT'] = $getInternetAddress["fileSystemAbsoulutePosition"];
|
| 226 |
liveuser |
274 |
|
| 3 |
liveuser |
275 |
#檢查檔案是否存在
|
|
|
276 |
#涵式說明:檢查多個檔案與資料夾是否存在.
|
|
|
277 |
#回傳的結果:
|
|
|
278 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
279 |
#$result["error"],錯誤訊息陣列.
|
|
|
280 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
281 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
282 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
283 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
|
|
|
284 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
|
|
|
285 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
286 |
#必填參數:
|
|
|
287 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
288 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($GLOBALS['THRIFT_ROOT'] . '/packages/hive_service/ThriftHive.php',$GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php',$GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php',$GLOBALS['THRIFT_ROOT'] . '/packages/hive_metastore/metastore/ThriftHiveMetastore.php');
|
|
|
289 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
290 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
291 |
#可省略參數
|
|
|
292 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
293 |
#$conf["disableWebSearch"]="false";
|
|
|
294 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
295 |
#$conf["userDir"]="true";
|
|
|
296 |
#參考資料來源:
|
|
|
297 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
298 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
299 |
#備註:
|
|
|
300 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
301 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
| 226 |
liveuser |
302 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
303 |
|
| 3 |
liveuser |
304 |
#如果檢查檔案是否存在失敗
|
|
|
305 |
if($checkMultiFileExist["status"]=="false"){
|
| 226 |
liveuser |
306 |
|
| 3 |
liveuser |
307 |
#設置執行不正常
|
|
|
308 |
$result["status"]="false";
|
| 226 |
liveuser |
309 |
|
| 3 |
liveuser |
310 |
#設置執行錯誤
|
|
|
311 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
312 |
|
| 3 |
liveuser |
313 |
#回傳結果
|
|
|
314 |
return $result;
|
| 226 |
liveuser |
315 |
|
| 3 |
liveuser |
316 |
}#if end
|
| 226 |
liveuser |
317 |
|
| 3 |
liveuser |
318 |
#如果檔案不存在
|
|
|
319 |
if($checkMultiFileExist["allExist"]=="false"){
|
| 226 |
liveuser |
320 |
|
| 3 |
liveuser |
321 |
#設置執行不正常
|
|
|
322 |
$result["status"]="false";
|
| 226 |
liveuser |
323 |
|
| 3 |
liveuser |
324 |
#設置執行錯誤
|
|
|
325 |
$result["error"]=$checkMultiFileExist;
|
| 226 |
liveuser |
326 |
|
| 3 |
liveuser |
327 |
#回傳結果
|
|
|
328 |
return $result;
|
| 226 |
liveuser |
329 |
|
| 3 |
liveuser |
330 |
}#if end
|
| 226 |
liveuser |
331 |
|
| 3 |
liveuser |
332 |
// load the required files for connecting to Hive
|
|
|
333 |
require_once $GLOBALS['THRIFT_ROOT'] . '/packages/hive_metastore/metastore/ThriftHiveMetastore.php';
|
|
|
334 |
require_once $GLOBALS['THRIFT_ROOT'] . '/packages/hive_service/ThriftHive.php';
|
|
|
335 |
require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php';
|
|
|
336 |
require_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php';
|
| 226 |
liveuser |
337 |
|
| 3 |
liveuser |
338 |
// Set up the transport/protocol/client
|
|
|
339 |
$transport = new TSocket('localhost', 10000);
|
|
|
340 |
$protocol = new TBinaryProtocol($transport);
|
|
|
341 |
$client = new ThriftHiveClient($protocol);
|
|
|
342 |
$transport->open();
|
| 226 |
liveuser |
343 |
|
| 3 |
liveuser |
344 |
// run queries, metadata calls etc
|
|
|
345 |
$client->execute('SELECT * from pokes;');
|
|
|
346 |
$result["content"]=($client->fetchAll());
|
|
|
347 |
$transport->close();
|
| 226 |
liveuser |
348 |
|
| 3 |
liveuser |
349 |
#設置執行正常
|
|
|
350 |
$result["status"]="true";
|
| 226 |
liveuser |
351 |
|
| 3 |
liveuser |
352 |
#回傳結果
|
|
|
353 |
return $result;
|
| 226 |
liveuser |
354 |
|
| 3 |
liveuser |
355 |
}#function nativeQuery end
|
|
|
356 |
*/
|
| 226 |
liveuser |
357 |
|
| 3 |
liveuser |
358 |
/*
|
|
|
359 |
#涵式說明:
|
|
|
360 |
#執行hiveSQL,取得未解析的SQL結果.
|
|
|
361 |
#回傳結果:
|
|
|
362 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
363 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
364 |
#$result["error"],陣列,錯訊訊息.
|
|
|
365 |
#$result["argu"],字串陣列,呼叫web service所用的參數.
|
|
|
366 |
#$result["content"],執行完query的回傳內容.
|
|
|
367 |
#$result["cmd"],執行的指令.
|
|
|
368 |
#必填參數:
|
|
|
369 |
#$conf["sql"],字串,要執行的sql字串.
|
|
|
370 |
$conf["sql"]="";
|
|
|
371 |
#$conf["beeline"],字串,beeline程式的位置.
|
| 226 |
liveuser |
372 |
$conf["beeline"]="beeline";
|
| 3 |
liveuser |
373 |
#可省略參數:
|
|
|
374 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
375 |
#$conf["fileArgu"]=__FILE__;
|
|
|
376 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
377 |
#$conf["userName"]="liveuser";
|
|
|
378 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
379 |
#$conf["userPass"]="password";
|
|
|
380 |
#備註:
|
|
|
381 |
#若使用 $conf["userName"] 跟 $conf["userPass"] 則會因為$conf["sql"]中含有「'或"」而造成指令錯誤.
|
|
|
382 |
*/
|
|
|
383 |
function query(&$conf){
|
| 226 |
liveuser |
384 |
|
| 3 |
liveuser |
385 |
#初始化要回傳的結果
|
|
|
386 |
$result=array();
|
|
|
387 |
|
|
|
388 |
#取得當前執行的函數名稱
|
|
|
389 |
$result["function"]=__FUNCTION__;
|
|
|
390 |
|
|
|
391 |
#如果沒有參數
|
|
|
392 |
if(func_num_args()==0){
|
| 226 |
liveuser |
393 |
|
| 3 |
liveuser |
394 |
#設置執行失敗
|
|
|
395 |
$result["status"]="false";
|
| 226 |
liveuser |
396 |
|
| 3 |
liveuser |
397 |
#設置執行錯誤訊息
|
|
|
398 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
399 |
|
| 3 |
liveuser |
400 |
#回傳結果
|
|
|
401 |
return $result;
|
| 226 |
liveuser |
402 |
|
| 3 |
liveuser |
403 |
}#if end
|
|
|
404 |
|
|
|
405 |
#取得參數
|
|
|
406 |
$result["argu"]=$conf;
|
|
|
407 |
|
|
|
408 |
#如果 $conf 不為陣列
|
|
|
409 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
410 |
|
| 3 |
liveuser |
411 |
#設置執行失敗
|
|
|
412 |
$result["status"]="false";
|
| 226 |
liveuser |
413 |
|
| 3 |
liveuser |
414 |
#設置執行錯誤訊息
|
|
|
415 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
416 |
|
| 3 |
liveuser |
417 |
#如果傳入的參數為 null
|
|
|
418 |
if($conf==null){
|
| 226 |
liveuser |
419 |
|
| 3 |
liveuser |
420 |
#設置執行錯誤訊息
|
|
|
421 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
422 |
|
| 3 |
liveuser |
423 |
}#if end
|
|
|
424 |
|
|
|
425 |
#回傳結果
|
|
|
426 |
return $result;
|
| 226 |
liveuser |
427 |
|
| 3 |
liveuser |
428 |
}#if end
|
| 226 |
liveuser |
429 |
|
| 3 |
liveuser |
430 |
#檢查參數
|
|
|
431 |
#函式說明:
|
|
|
432 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
433 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
434 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
435 |
#$result["function"],當前執行的函式名稱.
|
|
|
436 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
437 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
438 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
439 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
440 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
441 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
442 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
443 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
444 |
#必填寫的參數:
|
|
|
445 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
446 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
447 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
448 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sql","beeline");
|
|
|
449 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
450 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
451 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
452 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
453 |
#可以省略的參數:
|
|
|
454 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
455 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
456 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
457 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
458 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
459 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","userName","userPass");
|
| 226 |
liveuser |
460 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
461 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
462 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
463 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,null,null);
|
|
|
464 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
465 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
466 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
467 |
#參考資料來源:
|
|
|
468 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
469 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
470 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
471 |
|
| 3 |
liveuser |
472 |
#如果檢查參數失敗
|
|
|
473 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
474 |
|
| 3 |
liveuser |
475 |
#設置執行不正常
|
|
|
476 |
$result["status"]="false";
|
| 226 |
liveuser |
477 |
|
| 3 |
liveuser |
478 |
#設置執行錯誤
|
|
|
479 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
480 |
|
| 3 |
liveuser |
481 |
#回傳結果
|
|
|
482 |
return $result;
|
| 226 |
liveuser |
483 |
|
| 3 |
liveuser |
484 |
}#if end
|
| 226 |
liveuser |
485 |
|
| 3 |
liveuser |
486 |
#如果檢查參數不通過
|
|
|
487 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
488 |
|
| 3 |
liveuser |
489 |
#設置執行不正常
|
|
|
490 |
$result["status"]="false";
|
| 226 |
liveuser |
491 |
|
| 3 |
liveuser |
492 |
#設置執行錯誤
|
|
|
493 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
494 |
|
| 3 |
liveuser |
495 |
#回傳結果
|
|
|
496 |
return $result;
|
| 226 |
liveuser |
497 |
|
| 3 |
liveuser |
498 |
}#if end
|
| 226 |
liveuser |
499 |
|
| 3 |
liveuser |
500 |
#產生暫存的檔案名稱
|
|
|
501 |
#函數說明:
|
|
|
502 |
#回傳西元的目前時間,格式為2010年07月24日15時30分33秒
|
|
|
503 |
#回傳結果:
|
|
|
504 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
505 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
506 |
#$result["function"],當前執行的函式名稱.
|
|
|
507 |
#$result["content"],西元的目前時間,格式為2010年07月24日15時30分33秒
|
|
|
508 |
#必填參數:
|
|
|
509 |
#$conf["timeZone"],字串,時區代號,可以設定的時區列表:http://www.php.net/manual/en/timezones.php, ex:"Asia/Taipei".
|
|
|
510 |
$conf["time::getFullDateAndTime"]["timeZone"]="Asia/Taipei";
|
|
|
511 |
#可省略參數:
|
| 226 |
liveuser |
512 |
#$conf["showSecond"],字串,若爲"true"則會顯示秒數,預設為"true".
|
| 3 |
liveuser |
513 |
$conf["time::getFullDateAndTime"]["showSecond"]="true";
|
|
|
514 |
#參考資料:
|
|
|
515 |
#date函數用法=>http://php.net/manual/en/function.date.php.
|
|
|
516 |
$getFullDateAndTime=time::getFullDateAndTime($conf["time::getFullDateAndTime"]);
|
|
|
517 |
unset($conf["time::getFullDateAndTime"]);
|
| 226 |
liveuser |
518 |
|
| 3 |
liveuser |
519 |
#如果取得時間失敗
|
|
|
520 |
if($getFullDateAndTime["status"]=="false"){
|
| 226 |
liveuser |
521 |
|
| 3 |
liveuser |
522 |
#設置執行不正常
|
|
|
523 |
$result["status"]="false";
|
| 226 |
liveuser |
524 |
|
| 3 |
liveuser |
525 |
#設置執行錯誤
|
|
|
526 |
$result["error"]=$getFullDateAndTime;
|
| 226 |
liveuser |
527 |
|
| 3 |
liveuser |
528 |
#回傳結果
|
|
|
529 |
return $result;
|
| 226 |
liveuser |
530 |
|
| 3 |
liveuser |
531 |
}#if end
|
| 226 |
liveuser |
532 |
|
|
|
533 |
#取得暫存的檔案名稱
|
| 3 |
liveuser |
534 |
$tempCsvFile=$getFullDateAndTime["content"];
|
| 226 |
liveuser |
535 |
|
| 3 |
liveuser |
536 |
#暫存的目錄
|
|
|
537 |
$tempPath=".hive";
|
| 226 |
liveuser |
538 |
|
| 3 |
liveuser |
539 |
#轉換暫存的目錄為絕對路徑
|
|
|
540 |
#函數說明:
|
|
|
541 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
542 |
#回傳結果:
|
|
|
543 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
544 |
#$result["error"],錯誤訊息陣列.
|
| 226 |
liveuser |
545 |
#$result["function"],函數名稱.
|
| 3 |
liveuser |
546 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
547 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
548 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
|
|
|
549 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
550 |
#必填參數:
|
|
|
551 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
552 |
$conf["fileAccess::getInternetAddress"]["address"]=$tempPath;
|
|
|
553 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
554 |
$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
|
|
|
555 |
#可省略參數:
|
|
|
556 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
557 |
#$conf["fileAccess::getInternetAddress"]["userDir"]="false";
|
|
|
558 |
#備註:
|
|
|
559 |
#在命令列執行,所得的路徑是錯誤的。
|
|
|
560 |
$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
|
|
|
561 |
unset($conf["fileAccess::getInternetAddress"]);
|
| 226 |
liveuser |
562 |
|
| 3 |
liveuser |
563 |
#如果取得網路位置失敗
|
|
|
564 |
if($getInternetAddress["status"]=="false"){
|
| 226 |
liveuser |
565 |
|
| 3 |
liveuser |
566 |
#設置執行不正常
|
|
|
567 |
$result["status"]="false";
|
| 226 |
liveuser |
568 |
|
| 3 |
liveuser |
569 |
#設置執行錯誤
|
|
|
570 |
$result["error"]=$getInternetAddress;
|
| 226 |
liveuser |
571 |
|
| 3 |
liveuser |
572 |
#回傳結果
|
|
|
573 |
return $result;
|
| 226 |
liveuser |
574 |
|
| 3 |
liveuser |
575 |
}#if end
|
| 226 |
liveuser |
576 |
|
| 3 |
liveuser |
577 |
#取得轉換好的絕對位置
|
|
|
578 |
$tempPath=$getInternetAddress["fileSystemAbsoulutePosition"];
|
| 226 |
liveuser |
579 |
|
| 3 |
liveuser |
580 |
#函式說明:
|
|
|
581 |
#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
|
|
|
582 |
#回傳的結果:
|
|
|
583 |
#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
|
|
|
584 |
#$result["error"],錯誤訊息陣列.
|
|
|
585 |
#$result["function"],當前執行的函數名稱.
|
|
|
586 |
#$result["createdFileName"],建立好的檔案名稱.
|
|
|
587 |
#$result["createdFilePath"],檔案建立的路徑.
|
|
|
588 |
#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
589 |
#必填的參數:
|
|
|
590 |
#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
|
|
|
591 |
$conf["fileAccess::createFileAfterCheck"]["checkedFileAndPath"]=$tempPath."/".$tempCsvFile.".csv";
|
|
|
592 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
593 |
$conf["fileAccess::createFileAfterCheck"]["fileArgu"]=$conf["fileArgu"];
|
|
|
594 |
$createFileAfterCheck=fileAccess::createFileAfterCheck($conf["fileAccess::createFileAfterCheck"]);
|
|
|
595 |
unset($conf["fileAccess::createFileAfterCheck"]);
|
| 226 |
liveuser |
596 |
|
| 3 |
liveuser |
597 |
#如果建立檔案失敗
|
|
|
598 |
if($createFileAfterCheck["status"]=="false"){
|
|
|
599 |
|
|
|
600 |
#設置執行不正常
|
|
|
601 |
$result["status"]="false";
|
| 226 |
liveuser |
602 |
|
| 3 |
liveuser |
603 |
#設置執行錯誤
|
|
|
604 |
$result["error"]=$createFileAfterCheck;
|
| 226 |
liveuser |
605 |
|
| 3 |
liveuser |
606 |
#回傳結果
|
|
|
607 |
return $result;
|
| 226 |
liveuser |
608 |
|
| 3 |
liveuser |
609 |
}#if end
|
| 226 |
liveuser |
610 |
|
|
|
611 |
#取得暫存的csv檔案路徑
|
| 3 |
liveuser |
612 |
$tempCsvFile=$createFileAfterCheck["createdFilePathAndName"];
|
| 226 |
liveuser |
613 |
|
| 3 |
liveuser |
614 |
#初始化要執行的指令
|
|
|
615 |
$cmd="";
|
| 226 |
liveuser |
616 |
|
| 3 |
liveuser |
617 |
#如果有設定 $conf["userName"] 跟 $conf["userPass"]
|
|
|
618 |
if(isset($conf["userName"]) && isset($conf["userPass"])){
|
| 226 |
liveuser |
619 |
|
| 3 |
liveuser |
620 |
$cmd="echo ".$conf["userPass"]." | su ".$conf["userName"]." -c '".$conf["beeline"]." --silent=true --outputformat=csv2 -u jdbc:hive2://localhost:10000 -e \"".$conf["sql"]."\" > \"".$tempCsvFile."\"' ";
|
|
|
621 |
|
| 226 |
liveuser |
622 |
}#if end
|
|
|
623 |
|
| 3 |
liveuser |
624 |
#反之
|
|
|
625 |
else{
|
| 226 |
liveuser |
626 |
|
| 3 |
liveuser |
627 |
$cmd=$conf["beeline"]." --silent=true --outputformat=csv2 -u jdbc:hive2://localhost:10000 -e \"".$conf["sql"]."\" > \"".$tempCsvFile."\"";
|
| 226 |
liveuser |
628 |
|
| 3 |
liveuser |
629 |
}#else end
|
| 226 |
liveuser |
630 |
|
| 3 |
liveuser |
631 |
#運行beeline執行hiveSQL
|
|
|
632 |
#涵式說明:
|
|
|
633 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
634 |
#回傳的結果:
|
|
|
635 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
636 |
#$result["error"],錯誤訊息陣列.
|
|
|
637 |
#$result["function"],當前執行的函數名稱.
|
|
|
638 |
#$result["cmd"],執行的指令內容.
|
|
|
639 |
#$result["output"],爲執行完二元碼後的輸出陣列.
|
|
|
640 |
#必填的參數
|
|
|
641 |
#$conf["command"],字串,要執行的指令與.
|
|
|
642 |
$conf["external::callShell"]["command"]=$cmd;
|
|
|
643 |
#可省略參數:
|
|
|
644 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
645 |
#$conf["argu"]=array("");
|
|
|
646 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
647 |
#$conf["enablePrintDescription"]="true";
|
|
|
648 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
649 |
#$conf["printDescription"]="";
|
|
|
650 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
651 |
#$conf["escapeshellarg"]="false";
|
|
|
652 |
#備註:
|
|
|
653 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
|
|
|
654 |
#參考資料:
|
|
|
655 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
656 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
657 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
658 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
659 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
660 |
|
| 3 |
liveuser |
661 |
#如果執行beeline失敗
|
|
|
662 |
if($callShell["status"]=="false"){
|
| 226 |
liveuser |
663 |
|
| 3 |
liveuser |
664 |
#設置執行不正常
|
|
|
665 |
$result["status"]="false";
|
| 226 |
liveuser |
666 |
|
| 3 |
liveuser |
667 |
#設置執行錯誤
|
|
|
668 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
669 |
|
| 3 |
liveuser |
670 |
#回傳結果
|
|
|
671 |
return $result;
|
| 226 |
liveuser |
672 |
|
| 3 |
liveuser |
673 |
}#if end
|
| 226 |
liveuser |
674 |
|
| 3 |
liveuser |
675 |
#取得執行的指令
|
|
|
676 |
$result["cmd"]=$callShell["cmd"];
|
| 226 |
liveuser |
677 |
|
| 3 |
liveuser |
678 |
#取得暫存檔案裡面的內容
|
|
|
679 |
$result["content"]=file($tempCsvFile);
|
| 226 |
liveuser |
680 |
|
| 3 |
liveuser |
681 |
#移除暫存的檔案
|
|
|
682 |
unlink($tempCsvFile);
|
| 226 |
liveuser |
683 |
|
| 3 |
liveuser |
684 |
#設置執行正常
|
|
|
685 |
$result["status"]="true";
|
| 226 |
liveuser |
686 |
|
| 3 |
liveuser |
687 |
#回傳結果
|
|
|
688 |
return $result;
|
| 226 |
liveuser |
689 |
|
| 3 |
liveuser |
690 |
}#function query end
|
| 226 |
liveuser |
691 |
|
| 3 |
liveuser |
692 |
/*
|
|
|
693 |
#涵式說明:
|
|
|
694 |
#執行hiveSQL,取得資料庫列表.
|
|
|
695 |
#回傳結果:
|
|
|
696 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
697 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
698 |
#$result["error"],陣列,錯訊訊息.
|
|
|
699 |
#$result["content"],執行完query的回傳內容.
|
|
|
700 |
#$result["cmd"],執行的指令.
|
|
|
701 |
#必填參數:
|
|
|
702 |
#$conf["beeline"],字串,beeline程式的位置.
|
| 226 |
liveuser |
703 |
$conf["beeline"]="beeline";
|
| 3 |
liveuser |
704 |
#可省略參數:
|
|
|
705 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
706 |
#$conf["fileArgu"]=__FILE__
|
|
|
707 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
708 |
#$conf["userName"]="liveuser";
|
|
|
709 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
710 |
#$conf["userPass"]="password";
|
|
|
711 |
*/
|
|
|
712 |
function getDbList(&$conf){
|
| 226 |
liveuser |
713 |
|
| 3 |
liveuser |
714 |
#初始化要回傳的結果
|
|
|
715 |
$result=array();
|
|
|
716 |
|
|
|
717 |
#取得當前執行的函數名稱
|
|
|
718 |
$result["function"]=__FUNCTION__;
|
|
|
719 |
|
|
|
720 |
#如果沒有參數
|
|
|
721 |
if(func_num_args()==0){
|
| 226 |
liveuser |
722 |
|
| 3 |
liveuser |
723 |
#設置執行失敗
|
|
|
724 |
$result["status"]="false";
|
| 226 |
liveuser |
725 |
|
| 3 |
liveuser |
726 |
#設置執行錯誤訊息
|
|
|
727 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
728 |
|
| 3 |
liveuser |
729 |
#回傳結果
|
|
|
730 |
return $result;
|
| 226 |
liveuser |
731 |
|
| 3 |
liveuser |
732 |
}#if end
|
|
|
733 |
|
|
|
734 |
#取得參數
|
|
|
735 |
$result["argu"]=$conf;
|
|
|
736 |
|
|
|
737 |
#如果 $conf 不為陣列
|
|
|
738 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
739 |
|
| 3 |
liveuser |
740 |
#設置執行失敗
|
|
|
741 |
$result["status"]="false";
|
| 226 |
liveuser |
742 |
|
| 3 |
liveuser |
743 |
#設置執行錯誤訊息
|
|
|
744 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
745 |
|
| 3 |
liveuser |
746 |
#如果傳入的參數為 null
|
|
|
747 |
if($conf==null){
|
| 226 |
liveuser |
748 |
|
| 3 |
liveuser |
749 |
#設置執行錯誤訊息
|
|
|
750 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
751 |
|
| 3 |
liveuser |
752 |
}#if end
|
|
|
753 |
|
|
|
754 |
#回傳結果
|
|
|
755 |
return $result;
|
| 226 |
liveuser |
756 |
|
| 3 |
liveuser |
757 |
}#if end
|
| 226 |
liveuser |
758 |
|
| 3 |
liveuser |
759 |
#檢查參數
|
|
|
760 |
#函式說明:
|
|
|
761 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
762 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
763 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
764 |
#$result["function"],當前執行的函式名稱.
|
|
|
765 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
766 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
767 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
768 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
769 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
770 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
771 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
772 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
773 |
#必填寫的參數:
|
|
|
774 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
775 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
776 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
777 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("beeline");
|
|
|
778 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
779 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
780 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
781 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
782 |
#可以省略的參數:
|
|
|
783 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
784 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
785 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
786 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
787 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
788 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","userName","userPass");
|
| 226 |
liveuser |
789 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
790 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
791 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
792 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,null,null);
|
|
|
793 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
794 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
795 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
796 |
#參考資料來源:
|
|
|
797 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
798 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
799 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
800 |
|
| 3 |
liveuser |
801 |
#如果檢查參數失敗
|
|
|
802 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
803 |
|
| 3 |
liveuser |
804 |
#設置執行不正常
|
|
|
805 |
$result["status"]="false";
|
| 226 |
liveuser |
806 |
|
| 3 |
liveuser |
807 |
#設置執行錯誤
|
|
|
808 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
809 |
|
| 3 |
liveuser |
810 |
#回傳結果
|
|
|
811 |
return $result;
|
| 226 |
liveuser |
812 |
|
| 3 |
liveuser |
813 |
}#if end
|
| 226 |
liveuser |
814 |
|
| 3 |
liveuser |
815 |
#如果檢查參數不通過
|
|
|
816 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
817 |
|
| 3 |
liveuser |
818 |
#設置執行不正常
|
|
|
819 |
$result["status"]="false";
|
| 226 |
liveuser |
820 |
|
| 3 |
liveuser |
821 |
#設置執行錯誤
|
|
|
822 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
823 |
|
| 3 |
liveuser |
824 |
#回傳結果
|
|
|
825 |
return $result;
|
| 226 |
liveuser |
826 |
|
| 3 |
liveuser |
827 |
}#if end
|
| 226 |
liveuser |
828 |
|
| 3 |
liveuser |
829 |
#涵式說明:
|
|
|
830 |
#執行hiveSQL,取得未解析的SQL結果.
|
|
|
831 |
#回傳結果:
|
|
|
832 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
833 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
834 |
#$result["error"],陣列,錯訊訊息.
|
|
|
835 |
#$result["content"],執行完query的回傳內容.
|
|
|
836 |
#$result["cmd"],執行的指令.
|
|
|
837 |
#必填參數:
|
|
|
838 |
#$conf["sql"],字串,要執行的sql字串.
|
|
|
839 |
$conf["hive::query"]["sql"]="show databases;";
|
|
|
840 |
#$conf["beeline"],字串,beeline程式的位置.
|
| 226 |
liveuser |
841 |
$conf["hive::query"]["beeline"]=$conf["beeline"];
|
| 3 |
liveuser |
842 |
#可省略參數:
|
|
|
843 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
844 |
$conf["hive::query"]["fileArgu"]=$conf["fileArgu"];
|
| 226 |
liveuser |
845 |
|
| 3 |
liveuser |
846 |
#如果有設置 $conf["userName"] 與 $conf["userPass"]
|
|
|
847 |
if(isset($conf["userName"]) && isset($conf["userPass"])){
|
| 226 |
liveuser |
848 |
|
| 3 |
liveuser |
849 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
850 |
$conf["hive::query"]["userName"]=$conf["userName"];
|
| 226 |
liveuser |
851 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
| 3 |
liveuser |
852 |
$conf["hive::query"]["userPass"]=$conf["userPass"];
|
| 226 |
liveuser |
853 |
|
| 3 |
liveuser |
854 |
}#if end
|
| 226 |
liveuser |
855 |
|
| 3 |
liveuser |
856 |
#備註:
|
|
|
857 |
#若使用 $conf["userName"] 跟 $conf["userPass"] 則會因為$conf["sql"]中含有「'或"」而造成指令錯誤.
|
|
|
858 |
$query=hive::query($conf["hive::query"]);
|
|
|
859 |
unset($conf["hive::query"]);
|
| 226 |
liveuser |
860 |
|
| 3 |
liveuser |
861 |
#如果查詢失敗
|
|
|
862 |
if($query["status"]=="false"){
|
| 226 |
liveuser |
863 |
|
| 3 |
liveuser |
864 |
#設置執行不正常
|
|
|
865 |
$result["status"]="false";
|
| 226 |
liveuser |
866 |
|
| 3 |
liveuser |
867 |
#設置執行錯誤
|
|
|
868 |
$result["error"]=$query;
|
| 226 |
liveuser |
869 |
|
| 3 |
liveuser |
870 |
#回傳結果
|
|
|
871 |
return $result;
|
| 226 |
liveuser |
872 |
|
| 3 |
liveuser |
873 |
}#if end
|
| 226 |
liveuser |
874 |
|
|
|
875 |
#解析回傳的內容
|
| 3 |
liveuser |
876 |
#涵式說明:
|
|
|
877 |
#處理多個字串避免網頁出錯
|
|
|
878 |
#回傳的結果:
|
|
|
879 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
880 |
#$result["function"],當前執行的函數.
|
|
|
881 |
#$result["error"],錯誤訊息
|
|
|
882 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
883 |
#必填的參數:
|
|
|
884 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=$query["content"];#爲要處理的字串陣列
|
|
|
885 |
#可省略的參數:
|
|
|
886 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array("\n");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
887 |
#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
|
|
|
888 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
889 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
890 |
$correctMutiStrCharacter=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
891 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
| 226 |
liveuser |
892 |
|
| 3 |
liveuser |
893 |
#如果過濾字串失敗
|
|
|
894 |
if($correctMutiStrCharacter["status"]=="false"){
|
| 226 |
liveuser |
895 |
|
| 3 |
liveuser |
896 |
#設置執行不正常
|
|
|
897 |
$result["status"]="false";
|
| 226 |
liveuser |
898 |
|
| 3 |
liveuser |
899 |
#設置執行錯誤
|
|
|
900 |
$result["error"]=$correctMutiStrCharacter;
|
| 226 |
liveuser |
901 |
|
| 3 |
liveuser |
902 |
#回傳結果
|
|
|
903 |
return $result;
|
| 226 |
liveuser |
904 |
|
| 3 |
liveuser |
905 |
}#if end
|
| 226 |
liveuser |
906 |
|
| 3 |
liveuser |
907 |
#移除資料庫的名稱的標題
|
|
|
908 |
#涵式說明:
|
|
|
909 |
#將陣列中特定元素剔除,並重新按照順序排序
|
|
|
910 |
#回傳的結果:
|
|
|
911 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
912 |
#$result["error"],錯誤訊息
|
|
|
913 |
#$result["function"],當前執行的函數
|
|
|
914 |
#$result["empty"],移除完元素後是否為空陣列,"true"為是,"false"為否.
|
|
|
915 |
#$result["content"]["byName"],剔除掉特定元素的陣列,使用原來陣列的key來儲存.
|
|
|
916 |
#$result["content"]["byNumber"],剔除掉特定元素的陣列,使用從0開始的整數key來儲存.
|
|
|
917 |
#必填的參數:
|
|
|
918 |
$conf["arrays::eraseElement"]["rawInputArray"]=$correctMutiStrCharacter["processedStrArray"];#要處理的原始數字陣列
|
| 226 |
liveuser |
919 |
$conf["arrays::eraseElement"]["eraseElementKey"]="0";#要移除的元素key值
|
| 3 |
liveuser |
920 |
$eraseElement=arrays::eraseElement($conf["arrays::eraseElement"]);
|
|
|
921 |
unset($conf["arrays::eraseElement"]);
|
| 226 |
liveuser |
922 |
|
| 3 |
liveuser |
923 |
#如果移除元素失敗
|
|
|
924 |
if($eraseElement["status"]=="false"){
|
| 226 |
liveuser |
925 |
|
| 3 |
liveuser |
926 |
#設置執行不正常
|
|
|
927 |
$result["status"]="false";
|
| 226 |
liveuser |
928 |
|
| 3 |
liveuser |
929 |
#設置執行錯誤
|
|
|
930 |
$result["error"]=$eraseElement;
|
| 226 |
liveuser |
931 |
|
| 3 |
liveuser |
932 |
#回傳結果
|
|
|
933 |
return $result;
|
| 226 |
liveuser |
934 |
|
| 3 |
liveuser |
935 |
}#if end
|
| 226 |
liveuser |
936 |
|
| 3 |
liveuser |
937 |
#取得解析好的內容
|
|
|
938 |
$result["content"]=$eraseElement["content"]["byNumber"];
|
| 226 |
liveuser |
939 |
|
| 3 |
liveuser |
940 |
#設置執行正常
|
|
|
941 |
$result["status"]="true";
|
| 226 |
liveuser |
942 |
|
| 3 |
liveuser |
943 |
#回傳結果
|
| 226 |
liveuser |
944 |
return $result;
|
|
|
945 |
|
| 3 |
liveuser |
946 |
}#function getDbList end
|
| 226 |
liveuser |
947 |
|
| 3 |
liveuser |
948 |
/*
|
|
|
949 |
#涵式說明:
|
|
|
950 |
#執行hiveSQL,取得資料表列表.
|
|
|
951 |
#回傳結果:
|
|
|
952 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
953 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
954 |
#$result["error"],陣列,錯訊訊息.
|
|
|
955 |
#$result["content"],執行完query的回傳內容.
|
|
|
956 |
#$result["cmd"],執行的指令.
|
|
|
957 |
#必填參數:
|
|
|
958 |
#$conf["beeline"],字串,beeline程式的位置.
|
| 226 |
liveuser |
959 |
$conf["beeline"]="beeline";
|
| 3 |
liveuser |
960 |
#$conf["dbName"],字串,要取得資料表列表的目標資料庫名稱.
|
| 226 |
liveuser |
961 |
$conf["dbName"]="";
|
| 3 |
liveuser |
962 |
#可省略參數:
|
|
|
963 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
964 |
#$conf["fileArgu"]=__FILE__
|
|
|
965 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
966 |
#$conf["userName"]="liveuser";
|
|
|
967 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
968 |
#$conf["userPass"]="password";
|
|
|
969 |
*/
|
|
|
970 |
function getDtList(&$conf){
|
| 226 |
liveuser |
971 |
|
| 3 |
liveuser |
972 |
#初始化要回傳的結果
|
|
|
973 |
$result=array();
|
|
|
974 |
|
|
|
975 |
#取得當前執行的函數名稱
|
|
|
976 |
$result["function"]=__FUNCTION__;
|
|
|
977 |
|
|
|
978 |
#如果沒有參數
|
|
|
979 |
if(func_num_args()==0){
|
| 226 |
liveuser |
980 |
|
| 3 |
liveuser |
981 |
#設置執行失敗
|
|
|
982 |
$result["status"]="false";
|
| 226 |
liveuser |
983 |
|
| 3 |
liveuser |
984 |
#設置執行錯誤訊息
|
|
|
985 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
986 |
|
| 3 |
liveuser |
987 |
#回傳結果
|
|
|
988 |
return $result;
|
| 226 |
liveuser |
989 |
|
| 3 |
liveuser |
990 |
}#if end
|
|
|
991 |
|
|
|
992 |
#取得參數
|
|
|
993 |
$result["argu"]=$conf;
|
|
|
994 |
|
|
|
995 |
#如果 $conf 不為陣列
|
|
|
996 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
997 |
|
| 3 |
liveuser |
998 |
#設置執行失敗
|
|
|
999 |
$result["status"]="false";
|
| 226 |
liveuser |
1000 |
|
| 3 |
liveuser |
1001 |
#設置執行錯誤訊息
|
|
|
1002 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
1003 |
|
| 3 |
liveuser |
1004 |
#如果傳入的參數為 null
|
|
|
1005 |
if($conf==null){
|
| 226 |
liveuser |
1006 |
|
| 3 |
liveuser |
1007 |
#設置執行錯誤訊息
|
|
|
1008 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1009 |
|
| 3 |
liveuser |
1010 |
}#if end
|
|
|
1011 |
|
|
|
1012 |
#回傳結果
|
|
|
1013 |
return $result;
|
| 226 |
liveuser |
1014 |
|
| 3 |
liveuser |
1015 |
}#if end
|
| 226 |
liveuser |
1016 |
|
| 3 |
liveuser |
1017 |
#檢查參數
|
|
|
1018 |
#函式說明:
|
|
|
1019 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1020 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1021 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1022 |
#$result["function"],當前執行的函式名稱.
|
|
|
1023 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1024 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1025 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1026 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1027 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1028 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1029 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1030 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1031 |
#必填寫的參數:
|
|
|
1032 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1033 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1034 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1035 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("beeline","dbName");
|
|
|
1036 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1037 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
1038 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1039 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1040 |
#可以省略的參數:
|
|
|
1041 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1042 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1043 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1044 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1045 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1046 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","userName","userPass");
|
| 226 |
liveuser |
1047 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1048 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1049 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1050 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,null,null);
|
|
|
1051 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1052 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
1053 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
1054 |
#參考資料來源:
|
|
|
1055 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1056 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1057 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1058 |
|
| 3 |
liveuser |
1059 |
#如果檢查參數失敗
|
|
|
1060 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
1061 |
|
| 3 |
liveuser |
1062 |
#設置執行不正常
|
|
|
1063 |
$result["status"]="false";
|
| 226 |
liveuser |
1064 |
|
| 3 |
liveuser |
1065 |
#設置執行錯誤
|
|
|
1066 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1067 |
|
| 3 |
liveuser |
1068 |
#回傳結果
|
|
|
1069 |
return $result;
|
| 226 |
liveuser |
1070 |
|
| 3 |
liveuser |
1071 |
}#if end
|
| 226 |
liveuser |
1072 |
|
| 3 |
liveuser |
1073 |
#如果檢查參數不通過
|
|
|
1074 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
1075 |
|
| 3 |
liveuser |
1076 |
#設置執行不正常
|
|
|
1077 |
$result["status"]="false";
|
| 226 |
liveuser |
1078 |
|
| 3 |
liveuser |
1079 |
#設置執行錯誤
|
|
|
1080 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1081 |
|
| 3 |
liveuser |
1082 |
#回傳結果
|
|
|
1083 |
return $result;
|
| 226 |
liveuser |
1084 |
|
| 3 |
liveuser |
1085 |
}#if end
|
| 226 |
liveuser |
1086 |
|
| 3 |
liveuser |
1087 |
#涵式說明:
|
|
|
1088 |
#執行hiveSQL,取得未解析的SQL結果.
|
|
|
1089 |
#回傳結果:
|
|
|
1090 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
1091 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
1092 |
#$result["error"],陣列,錯訊訊息.
|
|
|
1093 |
#$result["content"],執行完query的回傳內容.
|
|
|
1094 |
#$result["cmd"],執行的指令.
|
|
|
1095 |
#必填參數:
|
|
|
1096 |
#$conf["sql"],字串,要執行的sql字串.
|
|
|
1097 |
$conf["hive::query"]["sql"]="use ".$conf["dbName"]."; show tables;";
|
|
|
1098 |
#$conf["beeline"],字串,beeline程式的位置.
|
| 226 |
liveuser |
1099 |
$conf["hive::query"]["beeline"]=$conf["beeline"];
|
| 3 |
liveuser |
1100 |
#可省略參數:
|
|
|
1101 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
1102 |
$conf["hive::query"]["fileArgu"]=$conf["fileArgu"];
|
| 226 |
liveuser |
1103 |
|
| 3 |
liveuser |
1104 |
#如果有設置 $conf["userName"] 與 $conf["userPass"]
|
|
|
1105 |
if(isset($conf["userName"]) && isset($conf["userPass"])){
|
| 226 |
liveuser |
1106 |
|
| 3 |
liveuser |
1107 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
1108 |
$conf["hive::query"]["userName"]=$conf["userName"];
|
| 226 |
liveuser |
1109 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
| 3 |
liveuser |
1110 |
$conf["hive::query"]["userPass"]=$conf["userPass"];
|
| 226 |
liveuser |
1111 |
|
| 3 |
liveuser |
1112 |
}#if end
|
| 226 |
liveuser |
1113 |
|
| 3 |
liveuser |
1114 |
#備註:
|
|
|
1115 |
#若使用 $conf["userName"] 跟 $conf["userPass"] 則會因為$conf["sql"]中含有「'或"」而造成指令錯誤.
|
|
|
1116 |
$query=hive::query($conf["hive::query"]);
|
|
|
1117 |
unset($conf["hive::query"]);
|
| 226 |
liveuser |
1118 |
|
| 3 |
liveuser |
1119 |
#如果查詢失敗
|
|
|
1120 |
if($query["status"]=="false"){
|
| 226 |
liveuser |
1121 |
|
| 3 |
liveuser |
1122 |
#設置執行不正常
|
|
|
1123 |
$result["status"]="false";
|
| 226 |
liveuser |
1124 |
|
| 3 |
liveuser |
1125 |
#設置執行錯誤
|
|
|
1126 |
$result["error"]=$query;
|
| 226 |
liveuser |
1127 |
|
| 3 |
liveuser |
1128 |
#回傳結果
|
|
|
1129 |
return $result;
|
| 226 |
liveuser |
1130 |
|
| 3 |
liveuser |
1131 |
}#if end
|
| 226 |
liveuser |
1132 |
|
|
|
1133 |
#解析回傳的內容
|
| 3 |
liveuser |
1134 |
#涵式說明:
|
|
|
1135 |
#處理多個字串避免網頁出錯
|
|
|
1136 |
#回傳的結果:
|
|
|
1137 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
1138 |
#$result["function"],當前執行的函數.
|
|
|
1139 |
#$result["error"],錯誤訊息
|
|
|
1140 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
1141 |
#必填的參數:
|
|
|
1142 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=$query["content"];#爲要處理的字串陣列
|
|
|
1143 |
#可省略的參數:
|
|
|
1144 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array("\n");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
1145 |
#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
|
|
|
1146 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
1147 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
1148 |
$correctMutiStrCharacter=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
1149 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
| 226 |
liveuser |
1150 |
|
| 3 |
liveuser |
1151 |
#如果過濾字串失敗
|
|
|
1152 |
if($correctMutiStrCharacter["status"]=="false"){
|
| 226 |
liveuser |
1153 |
|
| 3 |
liveuser |
1154 |
#設置執行不正常
|
|
|
1155 |
$result["status"]="false";
|
| 226 |
liveuser |
1156 |
|
| 3 |
liveuser |
1157 |
#設置執行錯誤
|
|
|
1158 |
$result["error"]=$correctMutiStrCharacter;
|
| 226 |
liveuser |
1159 |
|
| 3 |
liveuser |
1160 |
#回傳結果
|
|
|
1161 |
return $result;
|
| 226 |
liveuser |
1162 |
|
| 3 |
liveuser |
1163 |
}#if end
|
| 226 |
liveuser |
1164 |
|
| 3 |
liveuser |
1165 |
#移除資料庫的名稱的標題
|
|
|
1166 |
#涵式說明:
|
|
|
1167 |
#將陣列中特定元素剔除,並重新按照順序排序
|
|
|
1168 |
#回傳的結果:
|
|
|
1169 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1170 |
#$result["error"],錯誤訊息
|
|
|
1171 |
#$result["function"],當前執行的函數
|
|
|
1172 |
#$result["empty"],移除完元素後是否為空陣列,"true"為是,"false"為否.
|
|
|
1173 |
#$result["content"]["byName"],剔除掉特定元素的陣列,使用原來陣列的key來儲存.
|
|
|
1174 |
#$result["content"]["byNumber"],剔除掉特定元素的陣列,使用從0開始的整數key來儲存.
|
|
|
1175 |
#必填的參數:
|
|
|
1176 |
$conf["arrays::eraseElement"]["rawInputArray"]=$correctMutiStrCharacter["processedStrArray"];#要處理的原始數字陣列
|
| 226 |
liveuser |
1177 |
$conf["arrays::eraseElement"]["eraseElementKey"]="0";#要移除的元素key值
|
| 3 |
liveuser |
1178 |
$eraseElement=arrays::eraseElement($conf["arrays::eraseElement"]);
|
|
|
1179 |
unset($conf["arrays::eraseElement"]);
|
| 226 |
liveuser |
1180 |
|
| 3 |
liveuser |
1181 |
#如果移除元素失敗
|
|
|
1182 |
if($eraseElement["status"]=="false"){
|
| 226 |
liveuser |
1183 |
|
| 3 |
liveuser |
1184 |
#設置執行不正常
|
|
|
1185 |
$result["status"]="false";
|
| 226 |
liveuser |
1186 |
|
| 3 |
liveuser |
1187 |
#設置執行錯誤
|
|
|
1188 |
$result["error"]=$eraseElement;
|
| 226 |
liveuser |
1189 |
|
| 3 |
liveuser |
1190 |
#回傳結果
|
|
|
1191 |
return $result;
|
| 226 |
liveuser |
1192 |
|
| 3 |
liveuser |
1193 |
}#if end
|
| 226 |
liveuser |
1194 |
|
| 3 |
liveuser |
1195 |
#取得解析好的內容
|
|
|
1196 |
$result["content"]=$eraseElement["content"]["byNumber"];
|
| 226 |
liveuser |
1197 |
|
| 3 |
liveuser |
1198 |
#設置執行正常
|
|
|
1199 |
$result["status"]="true";
|
| 226 |
liveuser |
1200 |
|
| 3 |
liveuser |
1201 |
#回傳結果
|
| 226 |
liveuser |
1202 |
return $result;
|
|
|
1203 |
|
| 3 |
liveuser |
1204 |
}#function getDtList end
|
| 226 |
liveuser |
1205 |
|
| 3 |
liveuser |
1206 |
/*
|
|
|
1207 |
#涵式說明:
|
|
|
1208 |
#執行hiveSQL,取得資料表結構.
|
|
|
1209 |
#回傳結果:
|
|
|
1210 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
1211 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
1212 |
#$result["error"],陣列,錯訊訊息.
|
|
|
1213 |
#$result["content"],執行完query的回傳內容.
|
|
|
1214 |
#$result["cmd"],執行的指令.
|
|
|
1215 |
#必填參數:
|
|
|
1216 |
#$conf["beeline"],字串,beeline程式的位置.
|
| 226 |
liveuser |
1217 |
$conf["beeline"]="beeline";
|
| 3 |
liveuser |
1218 |
#$conf["dbName"],字串,要取得資料表結構的目標資料庫名稱.
|
| 226 |
liveuser |
1219 |
$conf["dbName"]="";
|
| 3 |
liveuser |
1220 |
#$conf["dtName"],字串,要取得結構的目標資料表名稱.
|
| 226 |
liveuser |
1221 |
$conf["dtName"]="";
|
| 3 |
liveuser |
1222 |
#可省略參數:
|
|
|
1223 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
1224 |
#$conf["fileArgu"]=__FILE__
|
|
|
1225 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
1226 |
#$conf["userName"]="liveuser";
|
|
|
1227 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
1228 |
#$conf["userPass"]="password";
|
|
|
1229 |
*/
|
|
|
1230 |
function getDtStruc(&$conf){
|
| 226 |
liveuser |
1231 |
|
| 3 |
liveuser |
1232 |
#初始化要回傳的結果
|
|
|
1233 |
$result=array();
|
|
|
1234 |
|
|
|
1235 |
#取得當前執行的函數名稱
|
|
|
1236 |
$result["function"]=__FUNCTION__;
|
|
|
1237 |
|
|
|
1238 |
#如果沒有參數
|
|
|
1239 |
if(func_num_args()==0){
|
| 226 |
liveuser |
1240 |
|
| 3 |
liveuser |
1241 |
#設置執行失敗
|
|
|
1242 |
$result["status"]="false";
|
| 226 |
liveuser |
1243 |
|
| 3 |
liveuser |
1244 |
#設置執行錯誤訊息
|
|
|
1245 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
1246 |
|
| 3 |
liveuser |
1247 |
#回傳結果
|
|
|
1248 |
return $result;
|
| 226 |
liveuser |
1249 |
|
| 3 |
liveuser |
1250 |
}#if end
|
|
|
1251 |
|
|
|
1252 |
#取得參數
|
|
|
1253 |
$result["argu"]=$conf;
|
|
|
1254 |
|
|
|
1255 |
#如果 $conf 不為陣列
|
|
|
1256 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1257 |
|
| 3 |
liveuser |
1258 |
#設置執行失敗
|
|
|
1259 |
$result["status"]="false";
|
| 226 |
liveuser |
1260 |
|
| 3 |
liveuser |
1261 |
#設置執行錯誤訊息
|
|
|
1262 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
1263 |
|
| 3 |
liveuser |
1264 |
#如果傳入的參數為 null
|
|
|
1265 |
if($conf==null){
|
| 226 |
liveuser |
1266 |
|
| 3 |
liveuser |
1267 |
#設置執行錯誤訊息
|
|
|
1268 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1269 |
|
| 3 |
liveuser |
1270 |
}#if end
|
|
|
1271 |
|
|
|
1272 |
#回傳結果
|
|
|
1273 |
return $result;
|
| 226 |
liveuser |
1274 |
|
| 3 |
liveuser |
1275 |
}#if end
|
| 226 |
liveuser |
1276 |
|
| 3 |
liveuser |
1277 |
#檢查參數
|
|
|
1278 |
#函式說明:
|
|
|
1279 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1280 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1281 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1282 |
#$result["function"],當前執行的函式名稱.
|
|
|
1283 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1284 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1285 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1286 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1287 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1288 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1289 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1290 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1291 |
#必填寫的參數:
|
|
|
1292 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1293 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1294 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1295 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("beeline","dbName","dtName");
|
|
|
1296 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1297 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
1298 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1299 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1300 |
#可以省略的參數:
|
|
|
1301 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1302 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1303 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1304 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1305 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1306 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","userName","userPass");
|
| 226 |
liveuser |
1307 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1308 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1309 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1310 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,null,null);
|
|
|
1311 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1312 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
1313 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
1314 |
#參考資料來源:
|
|
|
1315 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1316 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1317 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1318 |
|
| 3 |
liveuser |
1319 |
#如果檢查參數失敗
|
|
|
1320 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
1321 |
|
| 3 |
liveuser |
1322 |
#設置執行不正常
|
|
|
1323 |
$result["status"]="false";
|
| 226 |
liveuser |
1324 |
|
| 3 |
liveuser |
1325 |
#設置執行錯誤
|
|
|
1326 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1327 |
|
| 3 |
liveuser |
1328 |
#回傳結果
|
|
|
1329 |
return $result;
|
| 226 |
liveuser |
1330 |
|
| 3 |
liveuser |
1331 |
}#if end
|
| 226 |
liveuser |
1332 |
|
| 3 |
liveuser |
1333 |
#如果檢查參數不通過
|
|
|
1334 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
1335 |
|
| 3 |
liveuser |
1336 |
#設置執行不正常
|
|
|
1337 |
$result["status"]="false";
|
| 226 |
liveuser |
1338 |
|
| 3 |
liveuser |
1339 |
#設置執行錯誤
|
|
|
1340 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1341 |
|
| 3 |
liveuser |
1342 |
#回傳結果
|
|
|
1343 |
return $result;
|
| 226 |
liveuser |
1344 |
|
| 3 |
liveuser |
1345 |
}#if end
|
| 226 |
liveuser |
1346 |
|
| 3 |
liveuser |
1347 |
#涵式說明:
|
|
|
1348 |
#執行hiveSQL,取得未解析的SQL結果.
|
|
|
1349 |
#回傳結果:
|
|
|
1350 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
1351 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
1352 |
#$result["error"],陣列,錯訊訊息.
|
|
|
1353 |
#$result["content"],執行完query的回傳內容.
|
|
|
1354 |
#$result["cmd"],執行的指令.
|
|
|
1355 |
#必填參數:
|
|
|
1356 |
#$conf["sql"],字串,要執行的sql字串.
|
|
|
1357 |
$conf["hive::query"]["sql"]="use ".$conf["dbName"]."; DESCRIBE ".$conf["dtName"].";";
|
|
|
1358 |
#$conf["beeline"],字串,beeline程式的位置.
|
| 226 |
liveuser |
1359 |
$conf["hive::query"]["beeline"]=$conf["beeline"];
|
| 3 |
liveuser |
1360 |
#可省略參數:
|
|
|
1361 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
1362 |
$conf["hive::query"]["fileArgu"]=$conf["fileArgu"];
|
| 226 |
liveuser |
1363 |
|
| 3 |
liveuser |
1364 |
#如果有設置 $conf["userName"] 與 $conf["userPass"]
|
|
|
1365 |
if(isset($conf["userName"]) && isset($conf["userPass"])){
|
| 226 |
liveuser |
1366 |
|
| 3 |
liveuser |
1367 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
1368 |
$conf["hive::query"]["userName"]=$conf["userName"];
|
| 226 |
liveuser |
1369 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
| 3 |
liveuser |
1370 |
$conf["hive::query"]["userPass"]=$conf["userPass"];
|
| 226 |
liveuser |
1371 |
|
| 3 |
liveuser |
1372 |
}#if end
|
| 226 |
liveuser |
1373 |
|
| 3 |
liveuser |
1374 |
#備註:
|
|
|
1375 |
#若使用 $conf["userName"] 跟 $conf["userPass"] 則會因為$conf["sql"]中含有「'或"」而造成指令錯誤.
|
|
|
1376 |
$query=hive::query($conf["hive::query"]);
|
|
|
1377 |
unset($conf["hive::query"]);
|
| 226 |
liveuser |
1378 |
|
| 3 |
liveuser |
1379 |
#如果查詢失敗
|
|
|
1380 |
if($query["status"]=="false"){
|
| 226 |
liveuser |
1381 |
|
| 3 |
liveuser |
1382 |
#設置執行不正常
|
|
|
1383 |
$result["status"]="false";
|
| 226 |
liveuser |
1384 |
|
| 3 |
liveuser |
1385 |
#設置執行錯誤
|
|
|
1386 |
$result["error"]=$query;
|
| 226 |
liveuser |
1387 |
|
| 3 |
liveuser |
1388 |
#回傳結果
|
|
|
1389 |
return $result;
|
| 226 |
liveuser |
1390 |
|
| 3 |
liveuser |
1391 |
}#if end
|
| 226 |
liveuser |
1392 |
|
|
|
1393 |
#解析回傳的內容
|
| 3 |
liveuser |
1394 |
#涵式說明:
|
|
|
1395 |
#處理多個字串避免網頁出錯
|
|
|
1396 |
#回傳的結果:
|
|
|
1397 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
1398 |
#$result["function"],當前執行的函數.
|
|
|
1399 |
#$result["error"],錯誤訊息
|
|
|
1400 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
1401 |
#必填的參數:
|
|
|
1402 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=$query["content"];#爲要處理的字串陣列
|
|
|
1403 |
#可省略的參數:
|
|
|
1404 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array("\n");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
1405 |
#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
|
|
|
1406 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
1407 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
1408 |
$correctMutiStrCharacter=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
1409 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
| 226 |
liveuser |
1410 |
|
| 3 |
liveuser |
1411 |
#如果過濾字串失敗
|
|
|
1412 |
if($correctMutiStrCharacter["status"]=="false"){
|
| 226 |
liveuser |
1413 |
|
| 3 |
liveuser |
1414 |
#設置執行不正常
|
|
|
1415 |
$result["status"]="false";
|
| 226 |
liveuser |
1416 |
|
| 3 |
liveuser |
1417 |
#設置執行錯誤
|
|
|
1418 |
$result["error"]=$correctMutiStrCharacter;
|
| 226 |
liveuser |
1419 |
|
| 3 |
liveuser |
1420 |
#回傳結果
|
|
|
1421 |
return $result;
|
| 226 |
liveuser |
1422 |
|
| 3 |
liveuser |
1423 |
}#if end
|
| 226 |
liveuser |
1424 |
|
| 3 |
liveuser |
1425 |
#移除資料庫的名稱的標題
|
|
|
1426 |
#涵式說明:
|
|
|
1427 |
#將陣列中特定元素剔除,並重新按照順序排序
|
|
|
1428 |
#回傳的結果:
|
|
|
1429 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1430 |
#$result["error"],錯誤訊息
|
|
|
1431 |
#$result["function"],當前執行的函數
|
|
|
1432 |
#$result["empty"],移除完元素後是否為空陣列,"true"為是,"false"為否.
|
|
|
1433 |
#$result["content"]["byName"],剔除掉特定元素的陣列,使用原來陣列的key來儲存.
|
|
|
1434 |
#$result["content"]["byNumber"],剔除掉特定元素的陣列,使用從0開始的整數key來儲存.
|
|
|
1435 |
#必填的參數:
|
|
|
1436 |
$conf["arrays::eraseElement"]["rawInputArray"]=$correctMutiStrCharacter["processedStrArray"];#要處理的原始數字陣列
|
| 226 |
liveuser |
1437 |
$conf["arrays::eraseElement"]["eraseElementKey"]="0";#要移除的元素key值
|
| 3 |
liveuser |
1438 |
$eraseElement=arrays::eraseElement($conf["arrays::eraseElement"]);
|
|
|
1439 |
unset($conf["arrays::eraseElement"]);
|
| 226 |
liveuser |
1440 |
|
| 3 |
liveuser |
1441 |
#如果移除元素失敗
|
|
|
1442 |
if($eraseElement["status"]=="false"){
|
| 226 |
liveuser |
1443 |
|
| 3 |
liveuser |
1444 |
#設置執行不正常
|
|
|
1445 |
$result["status"]="false";
|
| 226 |
liveuser |
1446 |
|
| 3 |
liveuser |
1447 |
#設置執行錯誤
|
|
|
1448 |
$result["error"]=$eraseElement;
|
| 226 |
liveuser |
1449 |
|
| 3 |
liveuser |
1450 |
#回傳結果
|
|
|
1451 |
return $result;
|
| 226 |
liveuser |
1452 |
|
| 3 |
liveuser |
1453 |
}#if end
|
| 226 |
liveuser |
1454 |
|
| 3 |
liveuser |
1455 |
#取得欄位的名稱、類型、註解
|
|
|
1456 |
#涵式說明:
|
|
|
1457 |
#將多個固定格式的字串分開,並回傳分開的結果
|
|
|
1458 |
#回傳的參數:
|
|
|
1459 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
1460 |
#$result["error"],錯誤訊息陣列.
|
|
|
1461 |
#$result["function"],當前執行的函數名稱.
|
|
|
1462 |
#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
|
|
|
1463 |
#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
|
|
|
1464 |
#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
|
|
|
1465 |
#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
|
|
|
1466 |
#必填的參數:
|
|
|
1467 |
#$conf["stringIn"],字串陣列,要處理的字串陣列.
|
|
|
1468 |
$conf["stringProcess::spiltMutiString"]["stringIn"]=$eraseElement["content"]["byName"];
|
|
|
1469 |
#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
|
|
|
1470 |
$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=",";
|
|
|
1471 |
$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
|
|
|
1472 |
unset($conf["stringProcess::spiltMutiString"]);
|
| 226 |
liveuser |
1473 |
|
| 3 |
liveuser |
1474 |
#如果分割欄位資訊失敗
|
|
|
1475 |
if($spiltMutiString["status"]=="false"){
|
| 226 |
liveuser |
1476 |
|
| 3 |
liveuser |
1477 |
#設置執行不正常
|
|
|
1478 |
$result["status"]="false";
|
| 226 |
liveuser |
1479 |
|
| 3 |
liveuser |
1480 |
#設置執行錯誤
|
|
|
1481 |
$result["error"]=$spiltMutiString;
|
| 226 |
liveuser |
1482 |
|
| 3 |
liveuser |
1483 |
#回傳結果
|
|
|
1484 |
return $result;
|
| 226 |
liveuser |
1485 |
|
| 3 |
liveuser |
1486 |
}#if end
|
| 226 |
liveuser |
1487 |
|
| 3 |
liveuser |
1488 |
#針對每個欄位
|
|
|
1489 |
foreach($spiltMutiString["spiltString"] as $num=>$col){
|
| 226 |
liveuser |
1490 |
|
| 3 |
liveuser |
1491 |
#如果欄位資訊沒有大於等於2個
|
|
|
1492 |
if($col["dataCounts"]<2){
|
| 226 |
liveuser |
1493 |
|
| 3 |
liveuser |
1494 |
#設置執行不正常
|
|
|
1495 |
$result["status"]="false";
|
| 226 |
liveuser |
1496 |
|
| 3 |
liveuser |
1497 |
#設置執行錯誤
|
|
|
1498 |
$result["error"][]="欄位資訊解析錯誤";
|
| 226 |
liveuser |
1499 |
|
| 3 |
liveuser |
1500 |
#回傳結果
|
|
|
1501 |
return $result;
|
| 226 |
liveuser |
1502 |
|
| 3 |
liveuser |
1503 |
}#if end
|
| 226 |
liveuser |
1504 |
|
|
|
1505 |
#取得欄位的名稱
|
| 3 |
liveuser |
1506 |
$result["content"][$num]["name"]=$col["dataArray"][0];
|
| 226 |
liveuser |
1507 |
|
| 3 |
liveuser |
1508 |
#取得欄位的類型
|
|
|
1509 |
$result["content"][$num]["type"]=$col["dataArray"][1];
|
| 226 |
liveuser |
1510 |
|
| 3 |
liveuser |
1511 |
#如果存在註解
|
|
|
1512 |
if(isset($col["dataArray"][2])){
|
| 226 |
liveuser |
1513 |
|
| 3 |
liveuser |
1514 |
#取得註解
|
|
|
1515 |
$result["content"][$num]["comment"]=$col["dataArray"][2];
|
| 226 |
liveuser |
1516 |
|
| 3 |
liveuser |
1517 |
}#if end
|
| 226 |
liveuser |
1518 |
|
| 3 |
liveuser |
1519 |
}#foreach end
|
| 226 |
liveuser |
1520 |
|
| 3 |
liveuser |
1521 |
#設置執行正常
|
|
|
1522 |
$result["status"]="true";
|
| 226 |
liveuser |
1523 |
|
| 3 |
liveuser |
1524 |
#回傳結果
|
| 226 |
liveuser |
1525 |
return $result;
|
|
|
1526 |
|
| 3 |
liveuser |
1527 |
}#function getDtStruc end
|
| 226 |
liveuser |
1528 |
|
| 3 |
liveuser |
1529 |
/*
|
|
|
1530 |
#涵式說明:
|
|
|
1531 |
#執行hiveSQL,取得資料表資料.
|
|
|
1532 |
#回傳結果:
|
|
|
1533 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
1534 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
1535 |
#$result["error"],陣列,錯訊訊息.
|
|
|
1536 |
#$result["content"],執行完query的回傳內容.
|
|
|
1537 |
#$result["colName"],陣列,欄位的名稱.
|
|
|
1538 |
#$result["cmd"],執行的指令.
|
|
|
1539 |
#必填參數:
|
|
|
1540 |
#$conf["beeline"],字串,beeline程式的位置.
|
| 226 |
liveuser |
1541 |
$conf["beeline"]="beeline";
|
| 3 |
liveuser |
1542 |
#$conf["dbName"],字串,要取得資料表資料的目標資料庫名稱.
|
| 226 |
liveuser |
1543 |
$conf["dbName"]="";
|
| 3 |
liveuser |
1544 |
#$conf["dtName"],字串,要取得資料的目標資料表名稱.
|
| 226 |
liveuser |
1545 |
$conf["dtName"]="";
|
| 3 |
liveuser |
1546 |
#可省略參數:
|
|
|
1547 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
1548 |
#$conf["fileArgu"]=__FILE__
|
|
|
1549 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
1550 |
#$conf["userName"]="liveuser";
|
|
|
1551 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
1552 |
#$conf["userPass"]="password";
|
|
|
1553 |
*/
|
|
|
1554 |
function getDtData(&$conf){
|
| 226 |
liveuser |
1555 |
|
| 3 |
liveuser |
1556 |
#初始化要回傳的結果
|
|
|
1557 |
$result=array();
|
|
|
1558 |
|
|
|
1559 |
#取得當前執行的函數名稱
|
|
|
1560 |
$result["function"]=__FUNCTION__;
|
|
|
1561 |
|
|
|
1562 |
#如果沒有參數
|
|
|
1563 |
if(func_num_args()==0){
|
| 226 |
liveuser |
1564 |
|
| 3 |
liveuser |
1565 |
#設置執行失敗
|
|
|
1566 |
$result["status"]="false";
|
| 226 |
liveuser |
1567 |
|
| 3 |
liveuser |
1568 |
#設置執行錯誤訊息
|
|
|
1569 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
1570 |
|
| 3 |
liveuser |
1571 |
#回傳結果
|
|
|
1572 |
return $result;
|
| 226 |
liveuser |
1573 |
|
| 3 |
liveuser |
1574 |
}#if end
|
|
|
1575 |
|
|
|
1576 |
#取得參數
|
|
|
1577 |
$result["argu"]=$conf;
|
|
|
1578 |
|
|
|
1579 |
#如果 $conf 不為陣列
|
|
|
1580 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1581 |
|
| 3 |
liveuser |
1582 |
#設置執行失敗
|
|
|
1583 |
$result["status"]="false";
|
| 226 |
liveuser |
1584 |
|
| 3 |
liveuser |
1585 |
#設置執行錯誤訊息
|
|
|
1586 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
1587 |
|
| 3 |
liveuser |
1588 |
#如果傳入的參數為 null
|
|
|
1589 |
if($conf==null){
|
| 226 |
liveuser |
1590 |
|
| 3 |
liveuser |
1591 |
#設置執行錯誤訊息
|
|
|
1592 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1593 |
|
| 3 |
liveuser |
1594 |
}#if end
|
|
|
1595 |
|
|
|
1596 |
#回傳結果
|
|
|
1597 |
return $result;
|
| 226 |
liveuser |
1598 |
|
| 3 |
liveuser |
1599 |
}#if end
|
| 226 |
liveuser |
1600 |
|
| 3 |
liveuser |
1601 |
#檢查參數
|
|
|
1602 |
#函式說明:
|
|
|
1603 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1604 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1605 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1606 |
#$result["function"],當前執行的函式名稱.
|
|
|
1607 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1608 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1609 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1610 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1611 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1612 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1613 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1614 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1615 |
#必填寫的參數:
|
|
|
1616 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1617 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1618 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1619 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("beeline","dbName","dtName");
|
|
|
1620 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1621 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
1622 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1623 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1624 |
#可以省略的參數:
|
|
|
1625 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1626 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1627 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1628 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1629 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1630 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","userName","userPass");
|
| 226 |
liveuser |
1631 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1632 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1633 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1634 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,null,null);
|
|
|
1635 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1636 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
1637 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
1638 |
#參考資料來源:
|
|
|
1639 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1640 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1641 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1642 |
|
| 3 |
liveuser |
1643 |
#如果檢查參數失敗
|
|
|
1644 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
1645 |
|
| 3 |
liveuser |
1646 |
#設置執行不正常
|
|
|
1647 |
$result["status"]="false";
|
| 226 |
liveuser |
1648 |
|
| 3 |
liveuser |
1649 |
#設置執行錯誤
|
|
|
1650 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1651 |
|
| 3 |
liveuser |
1652 |
#回傳結果
|
|
|
1653 |
return $result;
|
| 226 |
liveuser |
1654 |
|
| 3 |
liveuser |
1655 |
}#if end
|
| 226 |
liveuser |
1656 |
|
| 3 |
liveuser |
1657 |
#如果檢查參數不通過
|
|
|
1658 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
1659 |
|
| 3 |
liveuser |
1660 |
#設置執行不正常
|
|
|
1661 |
$result["status"]="false";
|
| 226 |
liveuser |
1662 |
|
| 3 |
liveuser |
1663 |
#設置執行錯誤
|
|
|
1664 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
1665 |
|
| 3 |
liveuser |
1666 |
#回傳結果
|
|
|
1667 |
return $result;
|
| 226 |
liveuser |
1668 |
|
| 3 |
liveuser |
1669 |
}#if end
|
| 226 |
liveuser |
1670 |
|
| 3 |
liveuser |
1671 |
#涵式說明:
|
|
|
1672 |
#執行hiveSQL,取得未解析的SQL結果.
|
|
|
1673 |
#回傳結果:
|
|
|
1674 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
1675 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
1676 |
#$result["error"],陣列,錯訊訊息.
|
|
|
1677 |
#$result["argu"],字串陣列,呼叫web service所用的參數.
|
|
|
1678 |
#$result["content"],執行完query的回傳內容.
|
|
|
1679 |
#$result["cmd"],執行的指令.
|
|
|
1680 |
#必填參數:
|
|
|
1681 |
#$conf["sql"],字串,要執行的sql字串.
|
|
|
1682 |
$conf["hive::query"]["sql"]="use ".$conf["dbName"]."; select * from pokes;";
|
|
|
1683 |
#$conf["beeline"],字串,beeline程式的位置.
|
| 226 |
liveuser |
1684 |
$conf["hive::query"]["beeline"]=$conf["beeline"];
|
| 3 |
liveuser |
1685 |
#可省略參數:
|
|
|
1686 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
1687 |
#$conf["fileArgu"]=__FILE__;
|
|
|
1688 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
1689 |
#$conf["userName"]="liveuser";
|
|
|
1690 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
1691 |
#$conf["userPass"]="password";
|
|
|
1692 |
#備註:
|
|
|
1693 |
#若使用 $conf["userName"] 跟 $conf["userPass"] 則會因為$conf["sql"]中含有「'或"」而造成指令錯誤.
|
|
|
1694 |
$query=hive::query($conf["hive::query"]);
|
|
|
1695 |
unset($conf["hive::query"]);
|
| 226 |
liveuser |
1696 |
|
| 3 |
liveuser |
1697 |
#如果 query 失敗
|
|
|
1698 |
if($query["status"]=="false"){
|
| 226 |
liveuser |
1699 |
|
| 3 |
liveuser |
1700 |
#設置執行不正常
|
|
|
1701 |
$result["status"]="false";
|
| 226 |
liveuser |
1702 |
|
| 3 |
liveuser |
1703 |
#設置執行錯誤
|
|
|
1704 |
$result["error"]=$query;
|
| 226 |
liveuser |
1705 |
|
| 3 |
liveuser |
1706 |
#回傳結果
|
| 226 |
liveuser |
1707 |
return $result;
|
|
|
1708 |
|
| 3 |
liveuser |
1709 |
}#if end
|
| 226 |
liveuser |
1710 |
|
| 3 |
liveuser |
1711 |
#初始化儲存標題欄位名稱的變數
|
|
|
1712 |
$colName=array();
|
| 226 |
liveuser |
1713 |
|
| 3 |
liveuser |
1714 |
#依據 $query["content"] 的數量
|
|
|
1715 |
for($i=0;$i<count($query["content"]);$i++){
|
| 226 |
liveuser |
1716 |
|
| 3 |
liveuser |
1717 |
#用逗號分割欄位
|
|
|
1718 |
#涵式說明:
|
|
|
1719 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
1720 |
#回傳結果:
|
|
|
1721 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1722 |
#$result["error"],錯誤訊息陣列
|
|
|
1723 |
#$result["function"],當前執行的函數名稱.
|
|
|
1724 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
1725 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
1726 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
1727 |
#必填的參數:
|
|
|
1728 |
$conf["stringProcess::spiltString"]["stringIn"]=$query["content"][$i];#要處理的字串。
|
|
|
1729 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=",";#爲以哪個符號作爲分割
|
|
|
1730 |
#可省略參數:
|
|
|
1731 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
1732 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
1733 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
1734 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
1735 |
|
| 3 |
liveuser |
1736 |
#如果分割字串失敗
|
|
|
1737 |
if($spiltString["status"]=="false"){
|
| 226 |
liveuser |
1738 |
|
| 3 |
liveuser |
1739 |
#設置執行不正常
|
|
|
1740 |
$result["status"]="false";
|
| 226 |
liveuser |
1741 |
|
| 3 |
liveuser |
1742 |
#設置執行錯誤
|
|
|
1743 |
$result["error"]=$spiltString;
|
| 226 |
liveuser |
1744 |
|
| 3 |
liveuser |
1745 |
#回傳結果
|
|
|
1746 |
return $result;
|
| 226 |
liveuser |
1747 |
|
| 3 |
liveuser |
1748 |
}#if end
|
| 226 |
liveuser |
1749 |
|
| 3 |
liveuser |
1750 |
#如果是標題欄位
|
|
|
1751 |
if($i==0){
|
| 226 |
liveuser |
1752 |
|
| 3 |
liveuser |
1753 |
#針對每個欄位
|
|
|
1754 |
for($j=0;$j<$spiltString["dataCounts"];$j++){
|
| 226 |
liveuser |
1755 |
|
| 3 |
liveuser |
1756 |
#將標題欄位的資料庫名稱剃除
|
|
|
1757 |
#涵式說明:
|
|
|
1758 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
1759 |
#回傳結果:
|
|
|
1760 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1761 |
#$result["error"],錯誤訊息陣列
|
|
|
1762 |
#$result["function"],當前執行的函數名稱.
|
|
|
1763 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
1764 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
1765 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
1766 |
#必填的參數:
|
|
|
1767 |
$conf["stringProcess::spiltString"]["stringIn"]=$spiltString["dataArray"][$j];#要處理的字串。
|
|
|
1768 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
|
|
|
1769 |
#可省略參數:
|
|
|
1770 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
1771 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
1772 |
$spiltColStr=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
1773 |
unset($conf["stringProcess::spiltString"]);
|
| 226 |
liveuser |
1774 |
|
| 3 |
liveuser |
1775 |
#如果分割字串失敗
|
|
|
1776 |
if($spiltColStr["status"]=="false"){
|
| 226 |
liveuser |
1777 |
|
| 3 |
liveuser |
1778 |
#設置執行不正常
|
|
|
1779 |
$result["status"]="false";
|
| 226 |
liveuser |
1780 |
|
| 3 |
liveuser |
1781 |
#設置執行錯誤
|
|
|
1782 |
$result["error"]=$spiltColStr;
|
| 226 |
liveuser |
1783 |
|
| 3 |
liveuser |
1784 |
#回傳結果
|
|
|
1785 |
return $result;
|
| 226 |
liveuser |
1786 |
|
| 3 |
liveuser |
1787 |
}#if end
|
| 226 |
liveuser |
1788 |
|
| 3 |
liveuser |
1789 |
#過濾欄位的換行符號
|
|
|
1790 |
#涵式說明:
|
|
|
1791 |
#處理字串避免網頁出錯
|
|
|
1792 |
#回傳的結果:
|
|
|
1793 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1794 |
#$result["function"],當前執行的函數.
|
|
|
1795 |
#$result["content"],爲處理好的字串.
|
|
|
1796 |
#$result["error"],錯誤訊息陣列.
|
|
|
1797 |
#必填的參數:
|
|
|
1798 |
$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltColStr["dataArray"][1];#爲要處理的字串
|
|
|
1799 |
#可省略的參數:
|
|
|
1800 |
$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("\n");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
1801 |
#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
|
|
|
1802 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
1803 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
1804 |
$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
|
|
|
1805 |
unset($conf["stringProcess::correctCharacter"]);
|
| 226 |
liveuser |
1806 |
|
| 3 |
liveuser |
1807 |
#如果過濾字串失敗
|
|
|
1808 |
if($correctCharacter["status"]=="false"){
|
| 226 |
liveuser |
1809 |
|
| 3 |
liveuser |
1810 |
#設置執行不正常
|
|
|
1811 |
$result["status"]="false";
|
| 226 |
liveuser |
1812 |
|
| 3 |
liveuser |
1813 |
#設置執行錯誤
|
|
|
1814 |
$result["error"]=$correctCharacter;
|
| 226 |
liveuser |
1815 |
|
| 3 |
liveuser |
1816 |
#回傳結果
|
|
|
1817 |
return $result;
|
| 226 |
liveuser |
1818 |
|
|
|
1819 |
}#if end
|
|
|
1820 |
|
| 3 |
liveuser |
1821 |
#取得欄位名稱
|
|
|
1822 |
$colName[]=$correctCharacter["content"];
|
| 226 |
liveuser |
1823 |
|
| 3 |
liveuser |
1824 |
}#for end
|
| 226 |
liveuser |
1825 |
|
| 3 |
liveuser |
1826 |
}#if end
|
| 226 |
liveuser |
1827 |
|
|
|
1828 |
#反之是資料欄位
|
| 3 |
liveuser |
1829 |
else{
|
| 226 |
liveuser |
1830 |
|
| 3 |
liveuser |
1831 |
#針對每個資料欄位
|
|
|
1832 |
for($j=0;$j<$spiltString["dataCounts"];$j++){
|
| 226 |
liveuser |
1833 |
|
| 3 |
liveuser |
1834 |
#取得欄位資料
|
|
|
1835 |
#$result["content"][$colName[$j]][]=$spiltString["dataArray"][$j];
|
|
|
1836 |
$result["content"][$i-1][][$colName[$j]]=$spiltString["dataArray"][$j];
|
| 226 |
liveuser |
1837 |
|
| 3 |
liveuser |
1838 |
}#for end
|
| 226 |
liveuser |
1839 |
|
| 3 |
liveuser |
1840 |
}#else end
|
| 226 |
liveuser |
1841 |
|
| 3 |
liveuser |
1842 |
}#for end
|
| 226 |
liveuser |
1843 |
|
| 3 |
liveuser |
1844 |
#儲存欄位的名稱
|
| 226 |
liveuser |
1845 |
$result["colName"]=$colName;
|
|
|
1846 |
|
| 3 |
liveuser |
1847 |
#設置執行正常
|
|
|
1848 |
$result["status"]="true";
|
| 226 |
liveuser |
1849 |
|
| 3 |
liveuser |
1850 |
#回傳結果
|
|
|
1851 |
return $result;
|
| 226 |
liveuser |
1852 |
|
| 3 |
liveuser |
1853 |
}#function getDtData end
|
| 226 |
liveuser |
1854 |
|
| 3 |
liveuser |
1855 |
/*
|
| 226 |
liveuser |
1856 |
|
| 3 |
liveuser |
1857 |
*/
|
|
|
1858 |
function updateData(&$conf=array()){
|
| 226 |
liveuser |
1859 |
|
| 3 |
liveuser |
1860 |
}#function updateDate end
|
| 226 |
liveuser |
1861 |
|
| 3 |
liveuser |
1862 |
/*
|
| 226 |
liveuser |
1863 |
|
| 3 |
liveuser |
1864 |
*/
|
|
|
1865 |
function delData(&$conf=array()){
|
| 226 |
liveuser |
1866 |
|
| 3 |
liveuser |
1867 |
}#function delData
|
| 226 |
liveuser |
1868 |
|
| 3 |
liveuser |
1869 |
/*
|
|
|
1870 |
|
| 226 |
liveuser |
1871 |
*/
|
| 3 |
liveuser |
1872 |
function createTable(&$conf=array()){
|
| 226 |
liveuser |
1873 |
|
| 3 |
liveuser |
1874 |
}#function create table end
|
| 226 |
liveuser |
1875 |
|
| 3 |
liveuser |
1876 |
/*
|
| 226 |
liveuser |
1877 |
|
| 3 |
liveuser |
1878 |
*/
|
|
|
1879 |
function modifyTable(&$conf=array()){
|
| 226 |
liveuser |
1880 |
|
| 3 |
liveuser |
1881 |
}#function modifyTable end
|
| 226 |
liveuser |
1882 |
|
| 3 |
liveuser |
1883 |
/*
|
| 226 |
liveuser |
1884 |
|
| 3 |
liveuser |
1885 |
*/
|
|
|
1886 |
function delTable(&$conf=array()){
|
| 226 |
liveuser |
1887 |
|
| 3 |
liveuser |
1888 |
}#function delTable end
|
| 226 |
liveuser |
1889 |
|
| 3 |
liveuser |
1890 |
/*
|
|
|
1891 |
#函數說明:
|
|
|
1892 |
#建立資料庫,並回傳資料庫列表.
|
|
|
1893 |
#回傳結果:
|
|
|
1894 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
1895 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
1896 |
#$result["error"],陣列,錯訊訊息.
|
|
|
1897 |
#$result["content"],資料庫列表.
|
|
|
1898 |
#$result["cmd"],執行的指令.
|
|
|
1899 |
#必填參數:
|
|
|
1900 |
#$conf["beeline"],字串,beeline程式的位置.
|
| 226 |
liveuser |
1901 |
$conf["beeline"]="beeline";
|
| 3 |
liveuser |
1902 |
#$conf["dbName"],字串,要建立的資料庫名稱.
|
| 226 |
liveuser |
1903 |
$conf["dbName"]="";
|
| 3 |
liveuser |
1904 |
#可省略參數:
|
|
|
1905 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
1906 |
#$conf["fileArgu"]=__FILE__
|
|
|
1907 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
1908 |
#$conf["userName"]="liveuser";
|
|
|
1909 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
| 226 |
liveuser |
1910 |
#$conf["userPass"]="password";
|
| 3 |
liveuser |
1911 |
*/
|
|
|
1912 |
function createDb(&$conf=array()){
|
| 226 |
liveuser |
1913 |
|
| 3 |
liveuser |
1914 |
#初始化要回傳的結果
|
|
|
1915 |
$result=array();
|
|
|
1916 |
|
|
|
1917 |
#取得當前執行的函數名稱
|
|
|
1918 |
$result["function"]=__FUNCTION__;
|
|
|
1919 |
|
|
|
1920 |
#如果沒有參數
|
|
|
1921 |
if(func_num_args()==0){
|
| 226 |
liveuser |
1922 |
|
| 3 |
liveuser |
1923 |
#設置執行失敗
|
|
|
1924 |
$result["status"]="false";
|
| 226 |
liveuser |
1925 |
|
| 3 |
liveuser |
1926 |
#設置執行錯誤訊息
|
|
|
1927 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
1928 |
|
| 3 |
liveuser |
1929 |
#回傳結果
|
|
|
1930 |
return $result;
|
| 226 |
liveuser |
1931 |
|
| 3 |
liveuser |
1932 |
}#if end
|
|
|
1933 |
|
|
|
1934 |
#取得參數
|
|
|
1935 |
$result["argu"]=$conf;
|
|
|
1936 |
|
|
|
1937 |
#如果 $conf 不為陣列
|
|
|
1938 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1939 |
|
| 3 |
liveuser |
1940 |
#設置執行失敗
|
|
|
1941 |
$result["status"]="false";
|
| 226 |
liveuser |
1942 |
|
| 3 |
liveuser |
1943 |
#設置執行錯誤訊息
|
|
|
1944 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
1945 |
|
| 3 |
liveuser |
1946 |
#如果傳入的參數為 null
|
|
|
1947 |
if($conf==null){
|
| 226 |
liveuser |
1948 |
|
| 3 |
liveuser |
1949 |
#設置執行錯誤訊息
|
|
|
1950 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1951 |
|
| 3 |
liveuser |
1952 |
}#if end
|
|
|
1953 |
|
|
|
1954 |
#回傳結果
|
|
|
1955 |
return $result;
|
| 226 |
liveuser |
1956 |
|
| 3 |
liveuser |
1957 |
}#if end
|
| 226 |
liveuser |
1958 |
|
| 3 |
liveuser |
1959 |
#檢查參數
|
|
|
1960 |
#函式說明:
|
|
|
1961 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1962 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1963 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1964 |
#$result["function"],當前執行的函式名稱.
|
|
|
1965 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1966 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1967 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1968 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1969 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1970 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1971 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1972 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1973 |
#必填寫的參數:
|
|
|
1974 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1975 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1976 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1977 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("beeline","dbName");
|
|
|
1978 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1979 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
1980 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1981 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1982 |
#可以省略的參數:
|
|
|
1983 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1984 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1985 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1986 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1987 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1988 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","userName","userPass");
|
| 226 |
liveuser |
1989 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1990 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1991 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1992 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,null,null);
|
|
|
1993 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1994 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
1995 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
1996 |
#參考資料來源:
|
|
|
1997 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1998 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1999 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2000 |
|
| 3 |
liveuser |
2001 |
#如果檢查參數失敗
|
|
|
2002 |
if($checkArguments["status"]=="false"){
|
| 226 |
liveuser |
2003 |
|
| 3 |
liveuser |
2004 |
#設置執行不正常
|
|
|
2005 |
$result["status"]="false";
|
| 226 |
liveuser |
2006 |
|
| 3 |
liveuser |
2007 |
#設置執行錯誤
|
|
|
2008 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2009 |
|
| 3 |
liveuser |
2010 |
#回傳結果
|
|
|
2011 |
return $result;
|
| 226 |
liveuser |
2012 |
|
| 3 |
liveuser |
2013 |
}#if end
|
| 226 |
liveuser |
2014 |
|
| 3 |
liveuser |
2015 |
#如果檢查參數不通過
|
|
|
2016 |
if($checkArguments["passed"]=="false"){
|
| 226 |
liveuser |
2017 |
|
| 3 |
liveuser |
2018 |
#設置執行不正常
|
|
|
2019 |
$result["status"]="false";
|
| 226 |
liveuser |
2020 |
|
| 3 |
liveuser |
2021 |
#設置執行錯誤
|
|
|
2022 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
2023 |
|
| 3 |
liveuser |
2024 |
#回傳結果
|
|
|
2025 |
return $result;
|
| 226 |
liveuser |
2026 |
|
| 3 |
liveuser |
2027 |
}#if end
|
| 226 |
liveuser |
2028 |
|
| 3 |
liveuser |
2029 |
#涵式說明:
|
|
|
2030 |
#執行hiveSQL,取得未解析的SQL結果.
|
|
|
2031 |
#回傳結果:
|
|
|
2032 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
2033 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
2034 |
#$result["error"],陣列,錯訊訊息.
|
|
|
2035 |
#$result["content"],執行完query的回傳內容.
|
|
|
2036 |
#$result["cmd"],執行的指令.
|
|
|
2037 |
#必填參數:
|
|
|
2038 |
#$conf["sql"],字串,要執行的sql字串.
|
|
|
2039 |
$conf["hive::query"]["sql"]="create ".$conf["dbName"]."; show databases;";
|
|
|
2040 |
#$conf["beeline"],字串,beeline程式的位置.
|
| 226 |
liveuser |
2041 |
$conf["hive::query"]["beeline"]=$conf["beeline"];
|
| 3 |
liveuser |
2042 |
#可省略參數:
|
|
|
2043 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
2044 |
$conf["hive::query"]["fileArgu"]=$conf["fileArgu"];
|
| 226 |
liveuser |
2045 |
|
| 3 |
liveuser |
2046 |
#如果有設置 $conf["userName"] 與 $conf["userPass"]
|
|
|
2047 |
if(isset($conf["userName"]) && isset($conf["userPass"])){
|
| 226 |
liveuser |
2048 |
|
| 3 |
liveuser |
2049 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
2050 |
$conf["hive::query"]["userName"]=$conf["userName"];
|
| 226 |
liveuser |
2051 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
| 3 |
liveuser |
2052 |
$conf["hive::query"]["userPass"]=$conf["userPass"];
|
| 226 |
liveuser |
2053 |
|
| 3 |
liveuser |
2054 |
}#if end
|
| 226 |
liveuser |
2055 |
|
| 3 |
liveuser |
2056 |
#備註:
|
|
|
2057 |
#若使用 $conf["userName"] 跟 $conf["userPass"] 則會因為$conf["sql"]中含有「'或"」而造成指令錯誤.
|
|
|
2058 |
$query=hive::query($conf["hive::query"]);
|
|
|
2059 |
unset($conf["hive::query"]);
|
| 226 |
liveuser |
2060 |
|
| 3 |
liveuser |
2061 |
#取得建立資料庫執行的cmd
|
| 226 |
liveuser |
2062 |
$result["cmd"][]=$query["cmd"];
|
|
|
2063 |
|
| 3 |
liveuser |
2064 |
#如果查詢失敗
|
|
|
2065 |
if($query["status"]=="false"){
|
| 226 |
liveuser |
2066 |
|
| 3 |
liveuser |
2067 |
#設置執行不正常
|
|
|
2068 |
$result["status"]="false";
|
| 226 |
liveuser |
2069 |
|
| 3 |
liveuser |
2070 |
#設置執行錯誤
|
|
|
2071 |
$result["error"]=$query;
|
| 226 |
liveuser |
2072 |
|
| 3 |
liveuser |
2073 |
#回傳結果
|
|
|
2074 |
return $result;
|
| 226 |
liveuser |
2075 |
|
| 3 |
liveuser |
2076 |
}#if end
|
| 226 |
liveuser |
2077 |
|
| 3 |
liveuser |
2078 |
#涵式說明:
|
|
|
2079 |
#執行hiveSQL,取得資料庫列表.
|
|
|
2080 |
#回傳結果:
|
|
|
2081 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
2082 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
2083 |
#$result["error"],陣列,錯訊訊息.
|
|
|
2084 |
#$result["content"],執行完query的回傳內容.
|
|
|
2085 |
#$result["cmd"],執行的指令.
|
|
|
2086 |
#必填參數:
|
|
|
2087 |
#$conf["beeline"],字串,beeline程式的位置.
|
| 226 |
liveuser |
2088 |
$conf["hive::getDbList"]["beeline"]=$conf["beeline"];
|
| 3 |
liveuser |
2089 |
#可省略參數:
|
|
|
2090 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
2091 |
$conf["hive::getDbList"]["fileArgu"]=$conf["fileArgu"];
|
| 226 |
liveuser |
2092 |
|
| 3 |
liveuser |
2093 |
#如果有設定 $conf["userName"]
|
|
|
2094 |
if(isset($conf["userName"])){
|
| 226 |
liveuser |
2095 |
|
| 3 |
liveuser |
2096 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
2097 |
$conf["hive::getDbList"]["userName"]="liveuser";
|
| 226 |
liveuser |
2098 |
|
| 3 |
liveuser |
2099 |
}#if end
|
| 226 |
liveuser |
2100 |
|
| 3 |
liveuser |
2101 |
#如果有設定 $conf["userPass"]
|
|
|
2102 |
if(isset($conf["userPass"])){
|
| 226 |
liveuser |
2103 |
|
| 3 |
liveuser |
2104 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
2105 |
$conf["hive::getDbList"]["userPass"]="password";
|
| 226 |
liveuser |
2106 |
|
| 3 |
liveuser |
2107 |
}#if end
|
| 226 |
liveuser |
2108 |
|
| 3 |
liveuser |
2109 |
$getDbList=hive::getDbList($conf["hive::getDbList"]);
|
|
|
2110 |
unset($conf["hive::getDbList"]);
|
| 226 |
liveuser |
2111 |
|
| 3 |
liveuser |
2112 |
#如果取得資料庫列表失敗
|
|
|
2113 |
if($getDbList["status"]=="false"){
|
| 226 |
liveuser |
2114 |
|
| 3 |
liveuser |
2115 |
#設置執行不正常
|
|
|
2116 |
$result["status"]="false";
|
| 226 |
liveuser |
2117 |
|
| 3 |
liveuser |
2118 |
#設置執行錯誤
|
|
|
2119 |
$result["error"]=$query;
|
| 226 |
liveuser |
2120 |
|
| 3 |
liveuser |
2121 |
#回傳結果
|
|
|
2122 |
return $result;
|
| 226 |
liveuser |
2123 |
|
| 3 |
liveuser |
2124 |
}#if end
|
| 226 |
liveuser |
2125 |
|
| 3 |
liveuser |
2126 |
#取得資料庫列表執行的cmd
|
| 226 |
liveuser |
2127 |
$result["cmd"][]=$getDbList["cmd"];
|
|
|
2128 |
|
| 3 |
liveuser |
2129 |
#取得資料庫列表
|
|
|
2130 |
$result["content"]=$getDbList["content"];
|
| 226 |
liveuser |
2131 |
|
| 3 |
liveuser |
2132 |
#設置執行正常
|
|
|
2133 |
$result["status"]="true";
|
| 226 |
liveuser |
2134 |
|
| 3 |
liveuser |
2135 |
#回傳結果
|
|
|
2136 |
return $result;
|
| 226 |
liveuser |
2137 |
|
| 3 |
liveuser |
2138 |
}#function createDb end
|
| 226 |
liveuser |
2139 |
|
| 3 |
liveuser |
2140 |
/*
|
| 226 |
liveuser |
2141 |
|
| 3 |
liveuser |
2142 |
*/
|
|
|
2143 |
function dropDb(&$conf=array()){
|
| 226 |
liveuser |
2144 |
|
| 3 |
liveuser |
2145 |
}#function dropDb end
|
| 226 |
liveuser |
2146 |
|
| 3 |
liveuser |
2147 |
}#class hive end
|
|
|
2148 |
|
|
|
2149 |
?>
|