Skip to content

Commit

Permalink
enhance(Modules/Database): PHP 类型新增 SQLite3 支持
Browse files Browse the repository at this point in the history
  • Loading branch information
Medicean committed May 14, 2021
1 parent 8c96e05 commit 6dfa9eb
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
### 核心

* 修复 JSP Shell 无法执行 update/delete/insert 语句问题
* JSP Template 升级至 [v1.6](https://github.com/AntSwordProject/AntSword-JSP-Template/releases/tag/1.6)
* equals支持数组传参方式,兼容各种容器
* build.py中可以手动指定版本号编译,不再需要下载指定jdk
* 部分变量转为类属性,方便调试
* 修正 insert/update/delete 语句无法执行问题
## 数据管理

* 优化出错提示
* PHP 类型新增 SQLite_PDO 支持
* PHP 类型新增 SQLite3 支持

## 2021/03/27 `v(2.1.11.1)`

Expand Down
1 change: 1 addition & 0 deletions source/core/php/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PHP extends Base {
'database/oracle_oci8',
'database/postgresql',
'database/postgresql_pdo',
'database/sqlite3',
'database/sqlite_pdo',
'database/informix'
].map((_) => {
Expand Down
6 changes: 5 additions & 1 deletion source/core/php/template/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ module.exports = () => ({
_: `$m=array('mysql_close','mysqli_close','mssql_close','sqlsrv_close','ora_close','oci_close','ifx_close','sqlite_close','pg_close','dba_close','dbmclose','filepro_fieldcount','sybase_close');
foreach ($m as $f) {
echo($f."\\t".(function_exists($f)?'1':'0')."\\n");
}
};
$n=array('SQLite3');
foreach ($n as $f) {
echo($f."\\t".(class_exists($f)?'1':'0')."\\n");
};
if(function_exists('pdo_drivers')){
foreach(@pdo_drivers() as $f){
echo("pdo_".$f."\\t1\\n");
Expand Down
123 changes: 123 additions & 0 deletions source/core/php/template/database/sqlite3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/**
* 数据库管理模板:: sqlite3
* i 数据分隔符号 => \\t|\\t
*/

module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({
// 显示所有数据库
show_databases: {
_: `$m=get_magic_quotes_gpc();
$hst=$m?stripslashes($_POST["${arg1}"]):$_POST["${arg1}"];
$dbh=new SQLite3($hst);
if(!$dbh){
echo("ERROR://CONNECT ERROR".SQLite3::lastErrorMsg());
}else{
echo("main".chr(9));
$dbh->close();
}`.replace(/\n\s+/g, ''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}'
},
// 显示数据库所有表
show_tables: {
_: `$m=get_magic_quotes_gpc();
$hst=$m?stripslashes($_POST["${arg1}"]):$_POST["${arg1}"];
$dbh=new SQLite3($hst);
if(!$dbh){
echo("ERROR://CONNECT ERROR".SQLite3::lastErrorMsg());
}else{
$query="select tbl_name from sqlite_master where type='table' order by tbl_name;";
$stmt=$dbh->prepare($query);
$result=$stmt->execute();
while($res=$result->fetchArray(SQLITE3_ASSOC)){
echo(trim($res['tbl_name']).chr(9));
}
$dbh->close();
}`.replace(/\n\s+/g, ''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}',
[arg4]: '#{db}'
},
// 显示表字段
show_columns: {
_: `$m=get_magic_quotes_gpc();
$hst=$m?stripslashes($_POST["${arg1}"]):$_POST["${arg1}"];
$dbn=$m?stripslashes($_POST["${arg4}"]):$_POST["${arg4}"];
$tab=$m?stripslashes($_POST["${arg5}"]):$_POST["${arg5}"];
$dbh=new SQLite3($hst);
if(!$dbh){
echo("ERROR://CONNECT ERROR".SQLite3::lastErrorMsg());
}else{
$query="pragma table_info('{$tab}');";
$stmt=$dbh->prepare($query);
$result=$stmt->execute();
while($res=$result->fetchArray(SQLITE3_ASSOC)){
echo(trim($res['name'])." ({$res['type']})".chr(9));
}
$dbh->close();
}`.replace(/\n\s+/g, ''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}',
[arg4]: '#{db}',
[arg5]: '#{table}'
},
// 执行SQL语句
query: {
_: `$m=get_magic_quotes_gpc();
$hst=$m?stripslashes($_POST["${arg1}"]):$_POST["${arg1}"];
$usr=$m?stripslashes($_POST["${arg2}"]):$_POST["${arg2}"];
$pwd=$m?stripslashes($_POST["${arg3}"]):$_POST["${arg3}"];
$dbn=$m?stripslashes($_POST["${arg4}"]):$_POST["${arg4}"];
$sql=base64_decode($_POST["${arg5}"]);
$encode=$m?stripslashes($_POST["${arg6}"]):$_POST["${arg6}"];
$dbh=new SQLite3($hst);
if(!$dbh){
echo("ERROR://CONNECT ERROR".SQLite3::lastErrorMsg());
}else{
$stmt=$dbh->prepare($sql);
if(!$stmt){
echo("Status\\t|\\t\\r\\n");
echo(base64_encode("ERROR://".$dbh->lastErrorMsg())."\\t|\\t\\r\\n");
} else {
$result=$stmt->execute();
if(!$result){
echo("Status\\t|\\t\\r\\n");
echo(base64_encode("ERROR://".$dbh->lastErrorMsg())."\\t|\\t\\r\\n");
}else{
$bool=True;
while($res=$result->fetchArray(SQLITE3_ASSOC)){
if($bool){
foreach($res as $key=>$value){
echo($key."\\t|\\t");
}
echo "\\r\\n";
$bool=False;
}
foreach($res as $key=>$value){
echo(base64_encode($value!==NULL?$value:"NULL")."\\t|\\t");
}
echo "\\r\\n";
}
if($bool){
if(!$result->numColumns()){
echo("Affect Rows\\t|\\t\\r\\n".base64_encode($dbh->changes())."\\t|\\t\\r\\n");
}else{
echo("Status\\t|\\t\\r\\n");
echo(base64_encode("ERROR://Table is empty.")."\\t|\\t\\r\\n");
}
}
}
}
$dbh->close();
}`.replace(/\n\s+/g, ''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}',
[arg4]: '#{db}',
[arg5]: '#{base64::sql}',
[arg6]: '#{encode}'
}
})
3 changes: 3 additions & 0 deletions source/modules/database/php/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class PHP {
'oracle_oci8': ['UTF8','ZHS16GBK','ZHT16BIG5','ZHS16GBKFIXED','ZHT16BIG5FIXED'],
'postgresql': ['utf8', 'big5', 'dec8', 'cp850', 'hp8', 'koi8r', 'latin1', 'latin2', 'ascii', 'euckr', 'gb2312', 'gbk'],
'postgresql_pdo': ['utf8', 'big5', 'dec8', 'cp850', 'hp8', 'koi8r', 'latin1', 'latin2', 'ascii', 'euckr', 'gb2312', 'gbk'],
'sqlite3': ['utf8'],
'sqlite_pdo': ['utf8'],
'informix': ['utf8', 'big5', 'dec8', 'cp850', 'hp8', 'koi8r', 'latin1', 'latin2', 'ascii', 'euckr', 'gb2312', 'gbk'],
}
Expand Down Expand Up @@ -350,6 +351,7 @@ class PHP {
{ text: 'ORACLE_OCI8', value: 'oracle_oci8' },
{ text: 'PostgreSQL', value: 'postgresql' },
{ text: 'PostgreSQL_PDO', value: 'postgresql_pdo' },
{ text: 'SQLite3', value: 'sqlite3' },
{ text: 'SQLite_PDO', value: 'sqlite_pdo' },
{ text: 'INFORMIX', value: 'informix' }
] },
Expand Down Expand Up @@ -427,6 +429,7 @@ class PHP {
passwd: '',
});
break;
case 'sqlite3':
case 'sqlite_pdo':
form.setFormData({
host: '/var/www/html/test.db',
Expand Down

0 comments on commit 6dfa9eb

Please sign in to comment.