use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.
the class SQLStatementsDialog method getData.
/**
* Copy information from the meta-data input to the dialog fields.
*/
public void getData() {
for (int i = 0; i < stats.size(); i++) {
SQLStatement stat = stats.get(i);
TableItem ti = wFields.table.getItem(i);
String name = stat.getStepname();
DatabaseMeta dbinfo = stat.getDatabase();
String sql = stat.getSQL();
String error = stat.getError();
if (name != null) {
ti.setText(1, name);
}
if (dbinfo != null) {
ti.setText(2, dbinfo.getName());
}
if (sql != null) {
ti.setText(3, sql);
}
if (error != null) {
ti.setText(4, error);
}
Color col = ti.getBackground();
if (stat.hasError()) {
col = red;
}
ti.setBackground(col);
}
wFields.setRowNums();
wFields.optWidth(true);
}
use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.
the class SynchronizeAfterMergeDialog method create.
// Generate code for create table...
// Conversions done by Database
private void create() {
try {
SynchronizeAfterMergeMeta info = new SynchronizeAfterMergeMeta();
getInfo(info);
// new name might not yet be linked to other steps!
String name = stepname;
StepMeta stepMeta = new StepMeta(BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.StepMeta.Title"), name, info);
RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, repository, metaStore);
if (!sql.hasError()) {
if (sql.hasSQL()) {
SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
sqledit.open();
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
mb.setMessage(BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.NoSQLNeeds.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.NoSQLNeeds.DialogTitle"));
mb.open();
}
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(sql.getError());
mb.setText(BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.SQLError.DialogTitle"));
mb.open();
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.CouldNotBuildSQL.DialogTitle"), BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.CouldNotBuildSQL.DialogMessage"), ke);
}
}
use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.
the class TableOutputDialog method sql.
// Generate code for create table...
// Conversions done by Database
//
private void sql() {
try {
TableOutputMeta info = new TableOutputMeta();
getInfo(info);
RowMetaInterface prev = transMeta.getPrevStepFields(stepname);
if (info.isTableNameInField() && !info.isTableNameInTable() && info.getTableNameField().length() > 0) {
int idx = prev.indexOfValue(info.getTableNameField());
if (idx >= 0) {
prev.removeValueMeta(idx);
}
}
StepMeta stepMeta = transMeta.findStep(stepname);
if (info.specifyFields()) {
// Only use the fields that were specified.
RowMetaInterface prevNew = new RowMeta();
for (int i = 0; i < info.getFieldDatabase().length; i++) {
ValueMetaInterface insValue = prev.searchValueMeta(info.getFieldStream()[i]);
if (insValue != null) {
ValueMetaInterface insertValue = insValue.clone();
insertValue.setName(info.getFieldDatabase()[i]);
prevNew.addValueMeta(insertValue);
} else {
throw new KettleStepException(BaseMessages.getString(PKG, "TableOutputDialog.FailedToFindField.Message", info.getFieldStream()[i]));
}
}
prev = prevNew;
}
boolean autoInc = false;
String pk = null;
//
if (info.isReturningGeneratedKeys() && !Utils.isEmpty(info.getGeneratedKeyField())) {
ValueMetaInterface valueMeta = new ValueMetaInteger(info.getGeneratedKeyField());
valueMeta.setLength(15);
prev.addValueMeta(0, valueMeta);
autoInc = true;
pk = info.getGeneratedKeyField();
}
if (isValidRowMeta(prev)) {
SQLStatement sql = info.getSQLStatements(transMeta, stepMeta, prev, pk, autoInc, pk);
if (!sql.hasError()) {
if (sql.hasSQL()) {
SQLEditor sqledit = new SQLEditor(transMeta, shell, SWT.NONE, info.getDatabaseMeta(), transMeta.getDbCache(), sql.getSQL());
sqledit.open();
} else {
String message = getBaseMessage("TableOutputDialog.NoSQL.DialogMessage");
String text = getBaseMessage("TableOutputDialog.NoSQL.DialogTitle");
showMessage(shell, SWT.OK | SWT.ICON_INFORMATION, message, text);
}
} else {
String text = getBaseMessage("System.Dialog.Error.Title");
showMessage(shell, SWT.OK | SWT.ICON_ERROR, sql.getError(), text);
}
} else {
String message = getBaseMessage("TableOutputDialog.NoSQL.EmptyCSVFields");
String text = getBaseMessage("TableOutputDialog.NoSQL.DialogTitle");
showMessage(shell, SWT.OK | SWT.ICON_ERROR, message, text);
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "TableOutputDialog.BuildSQLError.DialogTitle"), BaseMessages.getString(PKG, "TableOutputDialog.BuildSQLError.DialogMessage"), ke);
}
}
use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.
the class SpoonDBDelegate method getTransSQL.
/**
* Get & show the SQL required to run the loaded transformation...
*/
public void getTransSQL(TransMeta transMeta) {
GetSQLProgressDialog pspd = new GetSQLProgressDialog(spoon.getShell(), transMeta);
List<SQLStatement> stats = pspd.open();
if (stats != null) {
if (stats.size() > 0) {
SQLStatementsDialog ssd = new SQLStatementsDialog(spoon.getShell(), Variables.getADefaultVariableSpace(), SWT.NONE, stats);
String sn = ssd.open();
if (sn != null) {
StepMeta esi = transMeta.findStep(sn);
if (esi != null) {
spoon.delegates.steps.editStep(transMeta, esi);
}
}
} else {
MessageBox mb = new MessageBox(spoon.getShell(), SWT.OK | SWT.ICON_INFORMATION);
mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.NoSQLNeedEexecuted.Message"));
// "SQL"
mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.NoSQLNeedEexecuted.Title"));
mb.open();
}
}
}
use of org.pentaho.di.core.SQLStatement in project pentaho-kettle by pentaho.
the class SpoonDBDelegate method getJobSQL.
/**
* Get & show the SQL required to run the loaded job entry...
*/
public void getJobSQL(JobMeta jobMeta) {
GetJobSQLProgressDialog pspd = new GetJobSQLProgressDialog(spoon.getShell(), jobMeta, spoon.getRepository());
List<SQLStatement> stats = pspd.open();
if (stats != null) {
if (stats.size() > 0) {
SQLStatementsDialog ssd = new SQLStatementsDialog(spoon.getShell(), jobMeta, SWT.NONE, stats);
ssd.open();
} else {
MessageBox mb = new MessageBox(spoon.getShell(), SWT.OK | SWT.ICON_INFORMATION);
mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.JobNoSQLNeedEexecuted.Message"));
mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.JobNoSQLNeedEexecuted.Title"));
mb.open();
}
}
}
Aggregations