Skip to content

Commit

Permalink
fix apache#3838 - SQL File Output Meta - specify connection through v…
Browse files Browse the repository at this point in the history
…ariables
  • Loading branch information
sramazzina authored and hansva committed Jun 7, 2024
1 parent 75cac76 commit cccfa17
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.hop.core.Const;
import org.apache.hop.core.ResultFile;
import org.apache.hop.core.database.Database;
import org.apache.hop.core.database.DatabaseMeta;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.exception.HopTransformException;
import org.apache.hop.core.util.Utils;
Expand Down Expand Up @@ -276,18 +277,19 @@ public boolean init() {

if (super.init()) {
try {
if (meta.getDatabaseMeta() == null) {
DatabaseMeta databaseMeta = getPipelineMeta().findDatabase(meta.getConnection(), variables);
if (databaseMeta == null) {
throw new HopTransformException("The connection is not defined (empty)");
}
if (meta.getDatabaseMeta() == null) {
if (databaseMeta == null) {
logError(
BaseMessages.getString(
PKG, "SQLFileOutput.Init.ConnectionMissing", getTransformName()));
return false;
}
data.db = new Database(this, this, meta.getDatabaseMeta());
data.db = new Database(this, this, databaseMeta);

logBasic("Connected to database [" + meta.getDatabaseMeta() + "]");
logBasic("Connected to database [" + meta.getConnection() + "]");

if (meta.isCreateParentFolder()) {
// Check for parent folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public String open() {
backupChanged = input.hasChanged();

int middle = props.getMiddlePct();
int margin = props.getMargin();
int margin = PropsUi.getMargin();

FormLayout formLayout = new FormLayout();
formLayout.marginWidth = PropsUi.getFormMargin();
Expand Down Expand Up @@ -201,7 +201,7 @@ public String open() {
wGConnection.setLayout(groupLayout);

// Connection line
wConnection = addConnectionLine(wGConnection, wTransformName, input.getDatabaseMeta(), lsMod);
wConnection = addConnectionLine(wGConnection, wTransformName, input.getConnection(), lsMod);

// Schema line...
Label wlSchema = new Label(wGConnection, SWT.RIGHT);
Expand Down Expand Up @@ -822,8 +822,8 @@ public void getData() {
if (input.getTablename() != null) {
wTable.setText(input.getTablename());
}
if (input.getDatabaseMeta() != null) {
wConnection.setText(input.getDatabaseMeta().getName());
if (input.getConnection() != null) {
wConnection.setText(input.getConnection());
}

if (input.getFileName() != null) {
Expand Down Expand Up @@ -869,7 +869,7 @@ private void cancel() {
private void getInfo(SQLFileOutputMeta info) {
info.setSchemaName(wSchema.getText());
info.setTablename(wTable.getText());
info.setDatabaseMeta(pipelineMeta.findDatabase(wConnection.getText(), variables));
info.setConnection(wConnection.getText());
info.setTruncateTable(wTruncate.getSelection());
info.setCreateParentFolder(wCreateParentFolder.getSelection());

Expand All @@ -895,7 +895,7 @@ private void ok() {

getInfo(input);

if (input.getDatabaseMeta() == null) {
if (input.getConnection() == null) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(
BaseMessages.getString(PKG, "SQLFileOutputDialog.ConnectionError.DialogMessage"));
Expand Down Expand Up @@ -946,19 +946,15 @@ private void sql() {
IRowMeta prev = pipelineMeta.getPrevTransformFields(variables, transformName);

TransformMeta transformMeta = pipelineMeta.findTransform(transformName);
DatabaseMeta databaseMeta = pipelineMeta.findDatabase(transformMeta.getName(), variables);

SqlStatement sql =
info.getSqlStatements(variables, pipelineMeta, transformMeta, prev, metadataProvider);
if (!sql.hasError()) {
if (sql.hasSql()) {
SqlEditor sqledit =
new SqlEditor(
shell,
SWT.NONE,
variables,
info.getDatabaseMeta(),
DbCache.getInstance(),
sql.getSql());
shell, SWT.NONE, variables, databaseMeta, DbCache.getInstance(), sql.getSql());
sqledit.open();
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
Expand Down
Loading

0 comments on commit cccfa17

Please sign in to comment.