Commit 640caf91 authored by Medicean's avatar Medicean

(Enhance:Database) 优化PHP Oracle OCI8 字符编码

parent 50cec46b
...@@ -26,8 +26,13 @@ module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({ ...@@ -26,8 +26,13 @@ module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({
echo(trim(@oci_result($q,1)).chr(9)); echo(trim(@oci_result($q,1)).chr(9));
} }
}else{ }else{
echo("Status\t|\t\r\n");
$e=@oci_error($q); $e=@oci_error($q);
echo("ERROR://{$e['message']} in [{$e['sqltext']}] col:{$e['offset']}"); if($e){
echo(base64_encode("ERROR://{$e['message']} in [{$e['sqltext']}] col:{$e['offset']}")."\t|\t\r\n");
}else{
echo("RmFsc2U="."\t|\t\r\n");
}
} }
@oci_close($H); @oci_close($H);
};`.replace(/\n\s+/g, ''), };`.replace(/\n\s+/g, ''),
...@@ -52,12 +57,23 @@ module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({ ...@@ -52,12 +57,23 @@ module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({
}else{ }else{
$q=@oci_parse($H,$sql); $q=@oci_parse($H,$sql);
if(@oci_execute($q)){ if(@oci_execute($q)){
while(@oci_fetch($q)){ $n=@oci_fetch_all($q,$res,0,-1,OCI_FETCHSTATEMENT_BY_ROW+OCI_NUM);
echo(trim(@oci_result($q,1)).chr(9)); if($n==0){
echo("ERROR://Database has no tables or no privilege");
}else{
for($i=0;$i<$n;$i++){
$row=$res[$i];
echo(trim($row[0]).chr(9));
}
} }
}else{ }else{
echo("Status\t|\t\r\n");
$e=@oci_error($q); $e=@oci_error($q);
echo("ERROR://{$e['message']} in [{$e['sqltext']}] col:{$e['offset']}"); if($e){
echo(base64_encode("ERROR://{$e['message']} in [{$e['sqltext']}] col:{$e['offset']}")."\t|\t\r\n");
}else{
echo("RmFsc2U="."\t|\t\r\n");
}
} }
@oci_close($H); @oci_close($H);
};`.replace(/\n\s+/g, ''), };`.replace(/\n\s+/g, ''),
...@@ -84,12 +100,23 @@ module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({ ...@@ -84,12 +100,23 @@ module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({
}else{ }else{
$q=@oci_parse($H,$sql); $q=@oci_parse($H,$sql);
if(@oci_execute($q)){ if(@oci_execute($q)){
while(@oci_fetch($q)){ $n=@oci_fetch_all($q,$res,0,-1,OCI_FETCHSTATEMENT_BY_ROW+OCI_NUM);
echo(trim(@oci_result($q,1))." (".@oci_result($q,2)."(".@oci_result($q,3)."))".chr(9)); if($n==0){
echo("ERROR://Table has no columns or no privilege");
}else{
for($i=0;$i<$n;$i++){
$row=$res[$i];
echo(trim($row[0])." (".$row[1]."(".$row[2]."))".chr(9));
}
} }
}else{ }else{
echo("Status\t|\t\r\n");
$e=@oci_error($q); $e=@oci_error($q);
echo("ERROR://{$e['message']} in [{$e['sqltext']}] col:{$e['offset']}"); if($e){
echo(base64_encode("ERROR://{$e['message']} in [{$e['sqltext']}] col:{$e['offset']}")."\t|\t\r\n");
}else{
echo("RmFsc2U="."\t|\t\r\n");
}
} }
@oci_close($H); @oci_close($H);
};`.replace(/\n\s+/g, ''), };`.replace(/\n\s+/g, ''),
...@@ -134,8 +161,13 @@ module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({ ...@@ -134,8 +161,13 @@ module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({
@oci_free_statement($q); @oci_free_statement($q);
} }
}else{ }else{
echo("Status\t|\t\r\n");
$e=@oci_error($q); $e=@oci_error($q);
echo("ERROR://{$e['message']} in [{$e['sqltext']}] col:{$e['offset']}"); if($e){
echo(base64_encode("ERROR://{$e['message']} in [{$e['sqltext']}] col:{$e['offset']}")."\t|\t\r\n");
}else{
echo("RmFsc2U="."\t|\t\r\n");
}
} }
@oci_close($H); @oci_close($H);
}`.replace(/\n\s+/g, ''), }`.replace(/\n\s+/g, ''),
......
...@@ -70,6 +70,7 @@ class PHP { ...@@ -70,6 +70,7 @@ class PHP {
// 生成查询SQL语句 // 生成查询SQL语句
case 'column': case 'column':
let _co = arr[1].split(':'); let _co = arr[1].split(':');
const db = new Buffer(_co[1], 'base64').toString();
const table = new Buffer(_co[2], 'base64').toString(); const table = new Buffer(_co[2], 'base64').toString();
const column = new Buffer(_co[3], 'base64').toString(); const column = new Buffer(_co[3], 'base64').toString();
...@@ -79,6 +80,10 @@ class PHP { ...@@ -79,6 +80,10 @@ class PHP {
case 'sqlsrv': case 'sqlsrv':
sql = `SELECT TOP 20 [${column}] FROM [${table}] ORDER BY 1 DESC;`; sql = `SELECT TOP 20 [${column}] FROM [${table}] ORDER BY 1 DESC;`;
break; break;
case 'oracle':
case 'oracle_oci8':
sql = `SELECT ${column} FROM ${db}.${table} WHERE ROWNUM < 20 ORDER BY 1`;
break;
default: default:
sql = `SELECT \`${column}\` FROM \`${table}\` ORDER BY 1 DESC LIMIT 0,20;`; sql = `SELECT \`${column}\` FROM \`${table}\` ORDER BY 1 DESC LIMIT 0,20;`;
break; break;
...@@ -383,7 +388,20 @@ class PHP { ...@@ -383,7 +388,20 @@ class PHP {
})() } })() }
]}, ]},
{ text: 'ORACLE', value: 'oracle' }, { text: 'ORACLE', value: 'oracle' },
{ text: 'ORACLE_OCI8', value: 'oracle_oci8' }, { text: 'ORACLE_OCI8', value: 'oracle_oci8', list: [
{ type: 'settings', position: 'label-left', offsetLeft: 70, labelWidth: 90, inputWidth: 150 },
{ type: 'label', label: LANG['form']['encode'] },
{ type: 'combo', label: '', name: 'encode', options: (() => {
let ret = [];
['UTF8','ZHS16GBK','ZHT16BIG5','ZHS16GBKFIXED','ZHT16BIG5FIXED'].map((_) => {
ret.push({
text: _,
value: _,
});
})
return ret;
})() }
]},
{ text: 'INFORMIX', value: 'informix' } { text: 'INFORMIX', value: 'informix' }
] }, ] },
{ type: 'input', label: LANG['form']['host'], name: 'host', required: true, value: 'localhost' }, { type: 'input', label: LANG['form']['host'], name: 'host', required: true, value: 'localhost' },
...@@ -417,6 +435,13 @@ class PHP { ...@@ -417,6 +435,13 @@ class PHP {
passwd: '' passwd: ''
}); });
break; break;
case 'oracle_oci8':
form.setFormData({
host: 'localhost/orcl',
user: '',
passwd: '',
})
break;
default: default:
form.setFormData({ form.setFormData({
user: 'dbuser', user: 'dbuser',
...@@ -593,7 +618,21 @@ class PHP { ...@@ -593,7 +618,21 @@ class PHP {
})() } })() }
]}, ]},
{ text: 'ORACLE', value: 'oracle', selected: conf['type'] === 'oracle' }, { text: 'ORACLE', value: 'oracle', selected: conf['type'] === 'oracle' },
{ text: 'ORACLE_OCI8', value: 'oracle_oci8', selected: conf['type'] === 'oracle_oci8' }, { text: 'ORACLE_OCI8', value: 'oracle_oci8', selected: conf['type'] === 'oracle_oci8', list: [
{ type: 'settings', position: 'label-left', offsetLeft: 70, labelWidth: 90, inputWidth: 150 },
{ type: 'label', label: LANG['form']['encode'] },
{ type: 'combo', label: '', name: 'encode', options: (() => {
let ret = [];
['UTF8','ZHS16GBK','ZHT16BIG5','ZHS16GBKFIXED','ZHT16BIG5FIXED'].map((_) => {
ret.push({
text: _,
value: _,
selected: conf['encode'] === _
});
})
return ret;
})() }
]},
{ text: 'INFORMIX', value: 'informix', selected: conf['type'] === 'informix' } { text: 'INFORMIX', value: 'informix', selected: conf['type'] === 'informix' }
] }, ] },
{ type: 'input', label: LANG['form']['host'], name: 'host', required: true, value: conf['host'] }, { type: 'input', label: LANG['form']['host'], name: 'host', required: true, value: conf['host'] },
...@@ -602,7 +641,7 @@ class PHP { ...@@ -602,7 +641,7 @@ class PHP {
]} ]}
], true); ], true);
form.attachEvent('onChange', (_, id) => { form.attachEvent('onChange', (_, id, state) => {
if (_ == 'type') { if (_ == 'type') {
switch(id) { switch(id) {
case 'mysql': case 'mysql':
...@@ -628,11 +667,13 @@ class PHP { ...@@ -628,11 +667,13 @@ class PHP {
}); });
} }
}; };
if(_ == 'encode') { // if(_ == 'encode') {
form.setFormData({ // if(state){
encode: id, // form.setFormData({
}); // encode: id,
} // });
// }
// }
}); });
// 工具栏点击事件 // 工具栏点击事件
...@@ -1404,6 +1445,9 @@ class PHP { ...@@ -1404,6 +1445,9 @@ class PHP {
}) })
).then((res) => { ).then((res) => {
let ret = res['text']; let ret = res['text'];
if(ret.indexOf("ERROR://") > -1) {
throw ret;
}
const arr = ret.split('\t'); const arr = ret.split('\t');
if (arr.length === 1 && ret === '') { if (arr.length === 1 && ret === '') {
toastr.warning(LANG['result']['warning'], LANG_T['warning']); toastr.warning(LANG['result']['warning'], LANG_T['warning']);
...@@ -1448,6 +1492,9 @@ class PHP { ...@@ -1448,6 +1492,9 @@ class PHP {
}) })
).then((res) => { ).then((res) => {
let ret = res['text']; let ret = res['text'];
if(ret.indexOf("ERROR://") > -1) {
throw ret;
}
const arr = ret.split('\t'); const arr = ret.split('\t');
const _db = new Buffer(db).toString('base64'); const _db = new Buffer(db).toString('base64');
// 删除子节点 // 删除子节点
...@@ -1492,6 +1539,9 @@ class PHP { ...@@ -1492,6 +1539,9 @@ class PHP {
}) })
).then((res) => { ).then((res) => {
let ret = res['text']; let ret = res['text'];
if(ret.indexOf("ERROR://") > -1) {
throw ret;
}
const arr = ret.split('\t'); const arr = ret.split('\t');
const _db = new Buffer(db).toString('base64'); const _db = new Buffer(db).toString('base64');
const _table = new Buffer(table).toString('base64'); const _table = new Buffer(table).toString('base64');
...@@ -1517,6 +1567,10 @@ class PHP { ...@@ -1517,6 +1567,10 @@ class PHP {
case 'sqlsrv': case 'sqlsrv':
presql = `SELECT TOP 20 * from [${table}] ORDER BY 1 DESC;`; presql = `SELECT TOP 20 * from [${table}] ORDER BY 1 DESC;`;
break; break;
case 'oracle':
case 'oracle_oci8':
presql = `SELECT * FROM ${db}.${table} WHERE ROWNUM < 20 ORDER BY 1`;
break;
default: default:
presql = `SELECT * FROM \`${table}\` ORDER BY 1 DESC LIMIT 0,20;`; presql = `SELECT * FROM \`${table}\` ORDER BY 1 DESC LIMIT 0,20;`;
break; break;
...@@ -1594,7 +1648,23 @@ class PHP { ...@@ -1594,7 +1648,23 @@ class PHP {
for (let i = 0; i < _data.length; i ++) { for (let i = 0; i < _data.length; i ++) {
let buff = new Buffer(_data[i], "base64"); let buff = new Buffer(_data[i], "base64");
let encoding = Decodes.detectEncoding(buff, {defaultEncoding: "unknown"}); let encoding = Decodes.detectEncoding(buff, {defaultEncoding: "unknown"});
encoding = encoding != "unknown" ? encoding : this.dbconf['encode']; if(encoding == "unknown") {
switch(this.dbconf['type']){
case 'oracle_oci8':
var oci8_characterset_mapping = {
'UTF8': 'utf8',
'ZHS16GBK':'gbk',
'ZHT16BIG5': 'big5',
'ZHS16GBKFIXED': 'gbk',
'ZHT16BIG5FIXED': 'big5',
}
encoding = oci8_characterset_mapping[this.dbconf['encode']] || '';
break;
default:
encoding = this.dbconf['encode'] || '';
break;
}
}
encoding = encoding != "" ? encoding : this.opt['encode']; encoding = encoding != "" ? encoding : this.opt['encode'];
let text = Decodes.decode(buff, encoding); let text = Decodes.decode(buff, encoding);
_data[i] = antSword.noxss(text); _data[i] = antSword.noxss(text);
...@@ -1633,7 +1703,23 @@ class PHP { ...@@ -1633,7 +1703,23 @@ class PHP {
// _data[i] = antSword.noxss(new Buffer(_data[i], "base64").toString(), false); // _data[i] = antSword.noxss(new Buffer(_data[i], "base64").toString(), false);
let buff = new Buffer(_data[i], "base64"); let buff = new Buffer(_data[i], "base64");
let encoding = Decodes.detectEncoding(buff, {defaultEncoding: "unknown"}); let encoding = Decodes.detectEncoding(buff, {defaultEncoding: "unknown"});
encoding = encoding != "unknown" ? encoding : this.dbconf['encode']; if(encoding == "unknown") {
switch(this.dbconf['type']){
case 'oracle_oci8':
var oci8_characterset_mapping = {
'UTF8': 'utf8',
'ZHS16GBK':'gbk',
'ZHT16BIG5': 'big5',
'ZHS16GBKFIXED': 'gbk',
'ZHT16BIG5FIXED': 'big5',
}
encoding = oci8_characterset_mapping[this.dbconf['encode']] || '';
break;
default:
encoding = this.dbconf['encode'] || '';
break;
}
}
encoding = encoding != "" ? encoding : this.opt['encode']; encoding = encoding != "" ? encoding : this.opt['encode'];
let text = Decodes.decode(buff, encoding); let text = Decodes.decode(buff, encoding);
_data[i] = antSword.noxss(text, false); _data[i] = antSword.noxss(text, false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment