mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
89 lines
2.6 KiB
Plaintext
89 lines
2.6 KiB
Plaintext
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("/");
|
|
|
|
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(event, "Please provide a field name before saving.");
|
|
return;
|
|
}
|
|
|
|
|
|
buffer.append("alter table `").append(dbName).append("`.`").append(tableName).append("`");
|
|
if ( event.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 ( event == "Cancel" )
|
|
{
|
|
Dialog d = context.get("/");
|
|
d.dispose();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|