Commit 779e20b7 authored by Medicean's avatar Medicean

db(php mysql): 编辑列名

parent 05c1bdc7
......@@ -379,7 +379,7 @@ module.exports = {
showcreatetable: 'Create Table SQL',
deltable: 'Del Table',
addcolumn: 'New Column',
editcolumn: 'Edit Column',
editcolumn: 'Edit ColumnName',
delcolumn: 'Del Column',
}
},
......@@ -478,7 +478,11 @@ module.exports = {
},
editcolumn: {
title: "New column name",
invalid_tablename: "Column names should not contain special symbols",
get_column_type_error: "Get column type error",
success: 'Update column name successfully',
error: 'Failed to update column',
},
delcolumn: {
title:'Delete Column',
......
......@@ -380,7 +380,7 @@ module.exports = {
showcreatetable: '建表语句',
desctable: '查看表结构',
addcolumn: '添加列',
editcolumn: '编辑列',
editcolumn: '编辑列',
delcolumn: '删除列',
}
},
......@@ -479,7 +479,11 @@ module.exports = {
},
editcolumn: {
title: "输入新列名",
invalid_tablename: "列名不能带有特殊符号",
get_column_type_error: "获取列属性失败",
success: '修改列名成功',
error: '修改列名失败'
},
delcolumn: {
title:'删除列',
......
......@@ -1149,7 +1149,50 @@ class PHP {
let dbname = new Buffer(treeselect.split('::')[1].split(":")[1],"base64").toString();
let tablename = new Buffer(treeselect.split('::')[1].split(":")[2],"base64").toString();
let columnname = new Buffer(treeselect.split('::')[1].split(":")[3],"base64").toString();
let columntyperaw = this.tree.getSelectedItemText();
let columntype = null;
var ctypereg = new RegExp(columnname+'\\s\\((.+?\\))\\)');
var res = columntyperaw.match(ctypereg);
if (res.length == 2) {
columntype = res[1];
}
if (columntype == null) {
toastr.error(LANG['form']['editcolumn']['get_column_type_error'], LANG_T['error']);
return
}
layer.prompt({
value: columnname,
title: `<i class="fa fa-file-code-o"></i> ${LANG['form']['editcolumn']['title']}`
},(value, i, e) => {
if(!value.match(/^[a-zA-Z0-9_]+$/)){
toastr.error(LANG['form']['editcolumn']['invalid_tablename'], LANG_T['error']);
return
}
layer.close(i);
switch(this.dbconf['type']){
case "mysqli":
case "mysql":
let sql = `ALTER TABLE \`${dbname}\`.\`${tablename}\` CHANGE COLUMN \`${columnname}\` \`${value}\` ${columntype};`;
this.manager.query.editor.session.setValue(sql);
this.execSQLAsync(sql, (res, err) => {
if(err){
toastr.error(LANG['result']['error']['query'](err['status'] || JSON.stringify(err)), LANG_T['error']);
return;
}
let result = this.parseResult(res['text']);
if(result.datas[0][0]=='True'){
toastr.success(LANG['form']['editcolumn']['success'],LANG_T['success']);
this.getColumns(id,dbname,tablename);
}else{
toastr.error(LANG['form']['editcolumn']['error'],LANG_T['error']);
}
});
break;
default:
toastr.warning(LANG['notsupport'], LANG_T['warning']);
break;
}
});
}
delColumn() {
......
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