Subversion Repositories php-qbpwcf

Rev

Rev 3 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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