use of easik.ui.datamanip.FreeQueryDialog in project fql by CategoricalData.
the class ExecPreparedInsertAction method actionPerformed.
/**
* Create the new entity and set up its name
*
* @param e
* The action event
*/
@Override
public void actionPerformed(ActionEvent e) {
Object[] currentSelection = _theSketch.getSelectionCells();
if (!(currentSelection[0] instanceof EntityNode)) {
return;
}
EntityNode table = (EntityNode) currentSelection[0];
JDBCDriver dbd = null;
dbd = _theSketch.getDatabase().getJDBCDriver();
if (dbd == null) {
// The user hit Cancel
return;
}
FreeQueryDialog afqd;
String text = "INSERT INTO " + table.getName() + "() VALUES()";
while (true) {
afqd = new FreeQueryDialog(_theSketch.getFrame(), text);
if (!afqd.isAccepted()) {
return;
}
try {
String input = afqd.getInput();
dbd.executeUpdate(input);
return;
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
text = afqd.getInput();
continue;
}
}
}
use of easik.ui.datamanip.FreeQueryDialog in project fql by CategoricalData.
the class JDBCDriver method overrideConstraints.
/**
* Toggle constraints and let the user modify the table.
*
* @param sketch
* Sketch to override triggers for
* @throws Exception
*/
@Override
public void overrideConstraints(Sketch sketch) throws Exception {
// Get update type (in case they need to be treated separately)
final String INSERT = "Insert";
final String DELETE = "Delete";
String[] options = { INSERT, DELETE };
String edit = (String) JOptionPane.showInputDialog(sketch.getFrame(), "Select constraint override update", "What would you like to do?", JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
if (edit == null) {
return;
}
// Get which table to update
ArrayList<EntityNode> ens = new ArrayList<>(sketch.getEntities());
options = new String[ens.size()];
for (int i = 0; i < options.length; i++) {
options[i] = ens.get(i).getName();
}
String table = (String) JOptionPane.showInputDialog(sketch.getFrame(), "Select table to modify", "Which table to modify?", JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
if (table == null) {
return;
}
FreeQueryDialog afqd;
String text;
if (INSERT.equals(edit)) {
text = "INSERT INTO " + table + "() VALUES()";
} else {
text = "DELETE FROM " + table + "\n WHERE()";
}
afqd = new FreeQueryDialog(sketch.getFrame(), text);
if (!afqd.isAccepted()) {
return;
}
try {
// Disable constraint
toggleConstraint(true);
executeUpdate(afqd.getInput());
} finally {
// Enable constraints
toggleConstraint(false);
}
}
use of easik.ui.datamanip.FreeQueryDialog in project fql by CategoricalData.
the class ExecPreparedDeleteAction method actionPerformed.
/**
* Create the new entity and set up its name
*
* @param e
* The action event
*/
@Override
public void actionPerformed(ActionEvent e) {
Object[] currentSelection = _theSketch.getSelectionCells();
if (!(currentSelection[0] instanceof EntityNode)) {
return;
}
EntityNode table = (EntityNode) currentSelection[0];
JDBCDriver dbd = null;
dbd = _theSketch.getDatabase().getJDBCDriver();
if (dbd == null) {
// The user hit Cancel
return;
}
FreeQueryDialog afqd;
String text = "DELETE FROM " + table.getName() + "\n WHERE()";
while (true) {
afqd = new FreeQueryDialog(_theSketch.getFrame(), text);
if (!afqd.isAccepted()) {
return;
}
try {
String input = afqd.getInput();
dbd.executeUpdate(input);
return;
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
text = afqd.getInput();
continue;
}
}
}
Aggregations