One Star

If table is empty then do nothing else do

At the moment I try to optimize a bidirectional connection between an interface database and a Sage database.
I nearly solved the whole problem. I still have one big problem.
The data goes from one mysql table to one or more mssql tables. If there is no content in the mysql databas the job
should not run. If there is content the job should run.
At the moment the job runs under an inifinite loop. This is no good solution.
Where and how to place the statement?
5 REPLIES
Community Manager

Re: If table is empty then do nothing else do

Hi
To determine a table is empty or not, only select one row from the table, for example:
tMysqlInput_1--main--tJavaRow
|
tJava---runIf---next processing
on tMysqlInput_1, write the query as below:
"select * from tableName limit 1"
There is a global variable ((Integer)globalMap.get("tMysqlInput_1_NB_LINE")) counts the total number of rows are queried.
on tJava:
if(((Integer)globalMap.get("tMysqlInput_1_NB_LINE"))>0){
globalMap.put("isContinue",true);
}else{
globalMap.put("isContinue", false);
}
set the condition of runIf as:
(Boolean)globalMap.get("isContinue")
The next processing will fires if the table has at least one row.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: If table is empty then do nothing else do

Thank you, for your help! But how to integrate the solution in my case?
One Star

Re: If table is empty then do nothing else do

Hi
I think u need to try tWaitForSqlData
One Star

Re: If table is empty then do nothing else do

Great idea, but where to place in my job?
One Star

Re: If table is empty then do nothing else do

Hi ,
You can use this instead of infiniteLoop, as the loop will only start when there is data in the table or data is inserted.