Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HuangJunbo
antSword
Commits
640caf91
Commit
640caf91
authored
Mar 08, 2019
by
Medicean
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Enhance:Database) 优化PHP Oracle OCI8 字符编码
parent
50cec46b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
18 deletions
+136
-18
oracle_oci8.js
source/core/php/template/database/oracle_oci8.js
+40
-8
index.js
source/modules/database/php/index.js
+96
-10
No files found.
source/core/php/template/database/oracle_oci8.js
View file @
640caf91
...
...
@@ -26,8 +26,13 @@ module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({
echo(trim(@oci_result($q,1)).chr(9));
}
}else{
echo("Status\t|\t\r\n");
$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);
};`
.
replace
(
/
\n\s
+/g
,
''
),
...
...
@@ -52,12 +57,23 @@ module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({
}else{
$q=@oci_parse($H,$sql);
if(@oci_execute($q)){
while(@oci_fetch($q)){
echo(trim(@oci_result($q,1)).chr(9));
$n=@oci_fetch_all($q,$res,0,-1,OCI_FETCHSTATEMENT_BY_ROW+OCI_NUM);
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{
echo("Status\t|\t\r\n");
$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);
};`
.
replace
(
/
\n\s
+/g
,
''
),
...
...
@@ -84,12 +100,23 @@ module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({
}else{
$q=@oci_parse($H,$sql);
if(@oci_execute($q)){
while(@oci_fetch($q)){
echo(trim(@oci_result($q,1))." (".@oci_result($q,2)."(".@oci_result($q,3)."))".chr(9));
$n=@oci_fetch_all($q,$res,0,-1,OCI_FETCHSTATEMENT_BY_ROW+OCI_NUM);
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{
echo("Status\t|\t\r\n");
$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);
};`
.
replace
(
/
\n\s
+/g
,
''
),
...
...
@@ -134,8 +161,13 @@ module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({
@oci_free_statement($q);
}
}else{
echo("Status\t|\t\r\n");
$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);
}`
.
replace
(
/
\n\s
+/g
,
''
),
...
...
source/modules/database/php/index.js
View file @
640caf91
...
...
@@ -70,6 +70,7 @@ class PHP {
// 生成查询SQL语句
case
'column'
:
let
_co
=
arr
[
1
].
split
(
':'
);
const
db
=
new
Buffer
(
_co
[
1
],
'base64'
).
toString
();
const
table
=
new
Buffer
(
_co
[
2
],
'base64'
).
toString
();
const
column
=
new
Buffer
(
_co
[
3
],
'base64'
).
toString
();
...
...
@@ -79,6 +80,10 @@ class PHP {
case
'sqlsrv'
:
sql
=
`SELECT TOP 20 [
${
column
}
] FROM [
${
table
}
] ORDER BY 1 DESC;`
;
break
;
case
'oracle'
:
case
'oracle_oci8'
:
sql
=
`SELECT
${
column
}
FROM
${
db
}
.
${
table
}
WHERE ROWNUM < 20 ORDER BY 1`
;
break
;
default
:
sql
=
`SELECT \`
${
column
}
\` FROM \`
${
table
}
\` ORDER BY 1 DESC LIMIT 0,20;`
;
break
;
...
...
@@ -383,7 +388,20 @@ class PHP {
})()
}
]},
{
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'
}
]
},
{
type
:
'input'
,
label
:
LANG
[
'form'
][
'host'
],
name
:
'host'
,
required
:
true
,
value
:
'localhost'
},
...
...
@@ -417,6 +435,13 @@ class PHP {
passwd
:
''
});
break
;
case
'oracle_oci8'
:
form
.
setFormData
({
host
:
'localhost/orcl'
,
user
:
''
,
passwd
:
''
,
})
break
;
default
:
form
.
setFormData
({
user
:
'dbuser'
,
...
...
@@ -593,7 +618,21 @@ class PHP {
})()
}
]},
{
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'
}
]
},
{
type
:
'input'
,
label
:
LANG
[
'form'
][
'host'
],
name
:
'host'
,
required
:
true
,
value
:
conf
[
'host'
]
},
...
...
@@ -602,7 +641,7 @@ class PHP {
]}
],
true
);
form
.
attachEvent
(
'onChange'
,
(
_
,
id
)
=>
{
form
.
attachEvent
(
'onChange'
,
(
_
,
id
,
state
)
=>
{
if
(
_
==
'type'
)
{
switch
(
id
)
{
case
'mysql'
:
...
...
@@ -628,11 +667,13 @@ class PHP {
});
}
};
if
(
_
==
'encode'
)
{
form
.
setFormData
({
encode
:
id
,
});
}
// if(_ == 'encode') {
// if(state){
// form.setFormData({
// encode: id,
// });
// }
// }
});
// 工具栏点击事件
...
...
@@ -1404,6 +1445,9 @@ class PHP {
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
if
(
ret
.
indexOf
(
"ERROR://"
)
>
-
1
)
{
throw
ret
;
}
const
arr
=
ret
.
split
(
'
\
t'
);
if
(
arr
.
length
===
1
&&
ret
===
''
)
{
toastr
.
warning
(
LANG
[
'result'
][
'warning'
],
LANG_T
[
'warning'
]);
...
...
@@ -1448,6 +1492,9 @@ class PHP {
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
if
(
ret
.
indexOf
(
"ERROR://"
)
>
-
1
)
{
throw
ret
;
}
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
// 删除子节点
...
...
@@ -1492,6 +1539,9 @@ class PHP {
})
).
then
((
res
)
=>
{
let
ret
=
res
[
'text'
];
if
(
ret
.
indexOf
(
"ERROR://"
)
>
-
1
)
{
throw
ret
;
}
const
arr
=
ret
.
split
(
'
\
t'
);
const
_db
=
new
Buffer
(
db
).
toString
(
'base64'
);
const
_table
=
new
Buffer
(
table
).
toString
(
'base64'
);
...
...
@@ -1517,6 +1567,10 @@ class PHP {
case
'sqlsrv'
:
presql
=
`SELECT TOP 20 * from [
${
table
}
] ORDER BY 1 DESC;`
;
break
;
case
'oracle'
:
case
'oracle_oci8'
:
presql
=
`SELECT * FROM
${
db
}
.
${
table
}
WHERE ROWNUM < 20 ORDER BY 1`
;
break
;
default
:
presql
=
`SELECT * FROM \`
${
table
}
\` ORDER BY 1 DESC LIMIT 0,20;`
;
break
;
...
...
@@ -1594,7 +1648,23 @@ class PHP {
for
(
let
i
=
0
;
i
<
_data
.
length
;
i
++
)
{
let
buff
=
new
Buffer
(
_data
[
i
],
"base64"
);
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'
];
let
text
=
Decodes
.
decode
(
buff
,
encoding
);
_data
[
i
]
=
antSword
.
noxss
(
text
);
...
...
@@ -1633,7 +1703,23 @@ class PHP {
// _data[i] = antSword.noxss(new Buffer(_data[i], "base64").toString(), false);
let
buff
=
new
Buffer
(
_data
[
i
],
"base64"
);
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'
];
let
text
=
Decodes
.
decode
(
buff
,
encoding
);
_data
[
i
]
=
antSword
.
noxss
(
text
,
false
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment