mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
fixup field events for oracle and mysql
This commit is contained in:
88
extra/jheidi/fieldEventsMySQL.ajl
Normal file
88
extra/jheidi/fieldEventsMySQL.ajl
Normal file
@@ -0,0 +1,88 @@
|
||||
import javax.swing.*;
|
||||
|
||||
String who = arg("source");
|
||||
WindowContext context = argObj("windowContext");
|
||||
log.debug("event received" + who);
|
||||
|
||||
if ( "Add Field".equals(who) || "Update Field".equals(who) )
|
||||
{
|
||||
Dialog d = context.get("/");
|
||||
|
||||
StringBuilder buffer = new StringBuilder(1000);
|
||||
|
||||
String fieldName = ((Field)context.get("/fieldName")).getText();
|
||||
String dbName = (String)context.get("currentDB");
|
||||
String tableName = (String)context.get("currentTable");
|
||||
String position = ((Combo)context.get("/positions")).getText();
|
||||
String lengthSet = ((Field)context.get("/lengthSet")).getText();
|
||||
String defValue = ((Field)context.get("/defaultValue")).getText();
|
||||
String comment = ((Field)context.get("/comment")).getText();
|
||||
|
||||
if ( fieldName == null || fieldName.trim().length() == 0 )
|
||||
{
|
||||
d.popupMessage(who, "Please provide a field name before saving.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
buffer.append("alter table `").append(dbName).append("`.`").append(tableName).append("`");
|
||||
if ( who.startsWith("Add") )
|
||||
{
|
||||
buffer.append(" add ").append("`").append(fieldName).append("`");
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.append(" change ").append(context.get("fieldToEdit")).append(" ").append(fieldName);
|
||||
}
|
||||
buffer.append(" ").append(((Combo)context.get("/types")).getText());
|
||||
if ( lengthSet != null && lengthSet.trim().length() > 0)
|
||||
{
|
||||
buffer.append("(").append(lengthSet.trim()).append(")");
|
||||
}
|
||||
if ( ((JCheckBox)context.get("/binary")).isSelected() )
|
||||
buffer.append(" binary");
|
||||
if ( ((JCheckBox)context.get("/unsigned")).isSelected() )
|
||||
buffer.append(" unsigned");
|
||||
if ( ((JCheckBox)context.get("/zeroFill")).isSelected() )
|
||||
buffer.append(" zerofill");
|
||||
|
||||
if ( defValue != null && defValue.trim().length() > 0)
|
||||
{
|
||||
buffer.append(" default '").append(defValue.trim()).append("'");
|
||||
}
|
||||
|
||||
if ( ((JCheckBox)context.get("/notNull")).isSelected() )
|
||||
buffer.append(" not null");
|
||||
|
||||
if ( comment != null & comment.trim().length() > 0 )
|
||||
{
|
||||
buffer.append(" comment '").append(comment.trim()).append("'");
|
||||
}
|
||||
|
||||
if ( !position.equals("Last") )
|
||||
{
|
||||
buffer.append(" ").append(position);
|
||||
}
|
||||
|
||||
log.debug("heres the statement: " + buffer.toString());
|
||||
DB db = context.get("db");
|
||||
db.execute(buffer.toString());
|
||||
|
||||
context.put("dlgResult", Boolean.TRUE);
|
||||
|
||||
d.dispose();
|
||||
|
||||
}
|
||||
else if ( "Cancel".equals(who) )
|
||||
{
|
||||
Dialog d = context.get("/");
|
||||
d.dispose();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
105
extra/jheidi/fieldEventsOracle.ajl
Normal file
105
extra/jheidi/fieldEventsOracle.ajl
Normal file
@@ -0,0 +1,105 @@
|
||||
import javax.swing.*;
|
||||
|
||||
String event = arg("source");
|
||||
WindowContext context = argObj("windowContext");
|
||||
log.debug("event received" + event);
|
||||
|
||||
if ( event == "Add Field" || event == "Update Field" )
|
||||
{
|
||||
Dialog d = context.get("/");
|
||||
|
||||
final StringBuilder sql = new StringBuilder(1000);
|
||||
String commentStmt = null;
|
||||
String renameStmt = null;
|
||||
|
||||
String fieldName = ((Field)context.get("/fieldName")).getText();
|
||||
String dbName = (String)context.get("currentDB");
|
||||
String tableName = (String)context.get("currentTable");
|
||||
String lengthSet = ((Field)context.get("/lengthSet")).getText();
|
||||
String defValue = ((Field)context.get("/defaultValue")).getText();
|
||||
String comment = ((Field)context.get("/comment")).getText();
|
||||
String type = ((Combo)context.get("/types")).getText();
|
||||
|
||||
if ( fieldName == null || fieldName.trim().length() == 0 )
|
||||
{
|
||||
d.popupMessage(event, "Please provide a field name before saving.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ( type.contains("char") && (lengthSet == null || lengthSet.trim().length() == 0))
|
||||
{
|
||||
d.popupMessage(event, "Character types require a length.");
|
||||
return;
|
||||
}
|
||||
|
||||
sql.append("alter table ").append(dbName).append(".").append(tableName).append("");
|
||||
if ( event.startsWith("Add") )
|
||||
{
|
||||
sql.append(" add ").append(fieldName);
|
||||
}
|
||||
else
|
||||
{
|
||||
sql.append(" modify ").append(fieldName);
|
||||
}
|
||||
sql.append(" ").append(type);
|
||||
if ( lengthSet != null && lengthSet.trim().length() > 0)
|
||||
{
|
||||
sql.append("(").append(lengthSet.trim()).append(")");
|
||||
}
|
||||
if ( defValue != null && defValue.trim().length() > 0)
|
||||
{
|
||||
if ( type.contains("char"))
|
||||
{
|
||||
sql.append(" default '").append(defValue.trim()).append("'");
|
||||
}
|
||||
else
|
||||
{
|
||||
sql.append(" default ").append(defValue.trim());
|
||||
}
|
||||
}
|
||||
|
||||
if ( ((JCheckBox)context.get("/notNull")).isSelected() )
|
||||
sql.append(" not null");
|
||||
else
|
||||
sql.append(" null ");
|
||||
|
||||
if ( comment != null & comment.trim().length() > 0 )
|
||||
{
|
||||
commentStmt = "comment on column %s.%s.%s is '%s'";
|
||||
commentStmt = String.format(commentStmt, dbName, tableName, fieldName, comment);
|
||||
}
|
||||
|
||||
// ALTER TABLE tablename ADD turd TINYINT(5) UNSIGNED ZEROFILL DEFAULT 'wow' NOT NULL
|
||||
log.debug("heres the statement: " + sql.toString());
|
||||
final DB db = context.get("db");
|
||||
final String myCommentStmt = commentStmt;
|
||||
DB.AutoCleanupTX tx = new DB.AutoCleanupTX() {
|
||||
public void execute() throws Exception {
|
||||
db.execute(sql.toString());
|
||||
if ( myCommentStmt != null )
|
||||
{
|
||||
db.execute(myCommentStmt);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
db.execute(tx);
|
||||
|
||||
context.put("dlgResult", Boolean.TRUE);
|
||||
|
||||
d.dispose();
|
||||
|
||||
}
|
||||
else if ( event == "Cancel" )
|
||||
{
|
||||
Dialog d = context.get("/");
|
||||
d.dispose();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user