From f77fafeb8a6b89a54b3a4032b673a1fbccba3a00 Mon Sep 17 00:00:00 2001 From: servertood Date: Mon, 29 Dec 2008 19:44:04 +0000 Subject: [PATCH] fixup field events for oracle and mysql --- extra/jheidi/fieldEventsMySQL.ajl | 88 ++++++++++++++++++++++++ extra/jheidi/fieldEventsOracle.ajl | 105 +++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 extra/jheidi/fieldEventsMySQL.ajl create mode 100644 extra/jheidi/fieldEventsOracle.ajl diff --git a/extra/jheidi/fieldEventsMySQL.ajl b/extra/jheidi/fieldEventsMySQL.ajl new file mode 100644 index 00000000..3018366a --- /dev/null +++ b/extra/jheidi/fieldEventsMySQL.ajl @@ -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(); + } + + + + + + + + diff --git a/extra/jheidi/fieldEventsOracle.ajl b/extra/jheidi/fieldEventsOracle.ajl new file mode 100644 index 00000000..e1d93ec8 --- /dev/null +++ b/extra/jheidi/fieldEventsOracle.ajl @@ -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(); + } + + + + + + + +