Execute a join query in Talend Open Studio for data integration - mysql

I am new to Talend open studio, I need to execute a MySql update query in a job. So I tried using tMysqlrow component and specified the query in Query field. When I run the job it shows "Lock wait timeout exceeded; try restarting transaction" error.
Here is my SQL query:
UPDATE library_export AS updater INNER JOIN
(SELECT id,(max_sequence_3 - coreTable.Level_3_sequence)+1 AS reverse_sequence_3,
(max_sequence_2 - coreTable.Level_2_sequence)+1 AS reverse_sequence_2,
(max_sequence_1 - coreTable.Level_1_sequence)+1 AS reverse_sequence_1
FROM library_export AS coreTable
LEFT JOIN
(SELECT MAX(Level_3_sequence) AS max_sequence_3,Level_2_id
FROM library_export
GROUP BY Level_2_id) AS level3 ON (coreTable.Level_2_id = level3.Level_2_id)
LEFT JOIN
(SELECT MAX(Level_2_sequence) AS max_sequence_2,Level_1_id
FROM library_export GROUP BY Level_1_id) AS level2 ON (coreTable.Level_1_id = level2.Level_1_id),
(SELECT MAX(Level_1_sequence) AS max_sequence_1
FROM library_export) AS level1) AS updataBy ON (updater.id = updataBy.id)
SET updater.Level_1_new_sequence = updataBy.reverse_sequence_1,
updater.Level_2_new_sequence = updataBy.reverse_sequence_2,
updater.Level_3_new_sequence = updataBy.reverse_sequence_3
Can anybody help me to execute the update query?

Related

Lock wait timeout on one server but not another

I have a database update which works on one server but fails on another. The working server is Windows 10 running MySQL 5.7.27 while the other is Linux running MySQL 5.7.26. On both servers there is only a single user, so there cannot be any conflicts with other processes.
I have tried copying exactly the same data from the Linux server to the Windows server to see if it as data problem, but the Windows server never fails.
After the transaction I execute two SELECTS as shown below:
-- QUERY #1
SELECT SQL_CALC_FOUND_ROWS invoice_item.*, invoice_header.party_id_bill_from, invoice_header.currency_code_tx, invoice_header.currency_code_fn, invoice_header.exchange_rate, invoice_header.invoice_date, invoice_header.tax_date, invoice_header.party_id_bill_to, invoice_header.invoice_status_type_id, invoice_header.order_type, invoice_header.order_id, price_component.price_type, product.product_name, product.inventory_type, product.product_subtype, product.uom_id, product.is_revision_controlled, unit_of_measure.uom_desc, unit_of_measure.uom_abbrev, COALESCE(scale, 0) AS uom_scale, party_name AS party_name_bill_to, ROUND((quantity * adjusted_price) - (COALESCE(invoice_item.free_units,0) * unit_price) , 3) AS item_value, ROUND((quantity * adjusted_price_tx) - (COALESCE(invoice_item.free_units,0) * unit_price_tx) , 3) AS item_value_tx, adjusted_price - (unit_price + COALESCE(feature_price , 0) ) AS item_adjustment, adjusted_price_tx - (unit_price_tx + COALESCE(feature_price_tx, 0) ) AS item_adjustment_tx
FROM invoice_item
LEFT JOIN invoice_header ON (invoice_header.invoice_type=invoice_item.invoice_type AND invoice_header.invoice_id=invoice_item.invoice_id)
LEFT JOIN "gmx9_product".price_component ON (price_component.price_component_id=invoice_item.price_component_id)
LEFT JOIN "gmx9_product".product ON (product.product_id=invoice_item.product_id)
LEFT JOIN "gmx9_product".unit_of_measure ON (unit_of_measure.uom_id=invoice_item.uom_id)
LEFT JOIN "gmx9_party".party AS party_bill_to ON (party_bill_to.party_id=invoice_header.party_id_bill_to)
WHERE invoice_item.invoice_type= 'V'
AND invoice_item.invoice_id= 2856045177200000000000000000000000001
AND invoice_item.invoice_item_seq_no= '2'
ORDER BY invoice_item.invoice_id, invoice_item.invoice_item_seq_no asc
FOR UPDATE
-- QUERY #2
SELECT SQL_CALC_FOUND_ROWS invoice_account_item.*, invoice_account_header.journal_desc, invoice_account_header.uom_id_statistic AS uom_id_statistic_header, gl_account.account_id_formatted, gl_account.account_name, invoice_adjustment.adjustment_seq_no AS invoice_adjustment_seq_no, invoice_adjustment.adjustment_desc AS invoice_adjustment_desc, invoice_header.party_id_bill_from, invoice_header.party_id_bill_to, invoice_header.currency_code_fn, invoice_header.currency_code_tx, invoice_header.exchange_rate, invoice_header.adjusted_value_tx, invoice_header.invoice_status_type_id, invoice_item.invoice_item_desc, invoice_item_adjustment.adjustment_seq_no AS invoice_item_adjustment_seq_no, invoice_item_adjustment.adjustment_desc AS invoice_item_adjustment_desc, invoice_item_feature.prod_feature_id AS invoice_item_prod_feature_id
FROM invoice_account_item
LEFT JOIN invoice_account_header ON (invoice_account_header.invoice_type=invoice_account_item.invoice_type
AND invoice_account_header.invoice_id=invoice_account_item.invoice_id)
LEFT JOIN "gmx9_finance_gl".gl_account ON (gl_account.chart_id=invoice_account_item.chart_id
AND gl_account.account_id=invoice_account_item.account_id)
LEFT JOIN "gmx9_invoice".invoice_adjustment ON (invoice_adjustment.invoice_type=invoice_account_item.invoice_type
AND invoice_adjustment.invoice_id=invoice_account_item.invoice_id
AND invoice_adjustment.adjustment_seq_no=invoice_account_item.invoice_adjustment_seq_no)
LEFT JOIN "gmx9_invoice".invoice_header ON (invoice_header.invoice_type=invoice_account_item.invoice_type
AND invoice_header.invoice_id=invoice_account_item.invoice_id)
LEFT JOIN "gmx9_invoice".invoice_item ON (invoice_item.invoice_type=invoice_account_item.invoice_type
AND invoice_item.invoice_id=invoice_account_item.invoice_id
AND invoice_item.invoice_item_seq_no=invoice_account_item.invoice_item_seq_no)
LEFT JOIN "gmx9_invoice".invoice_item_adjustment ON (invoice_item_adjustment.invoice_type=invoice_account_item.invoice_type
AND invoice_item_adjustment.invoice_id=invoice_account_item.invoice_id
AND invoice_item_adjustment.invoice_item_seq_no=invoice_account_item.invoice_item_seq_no
AND invoice_item_adjustment.adjustment_seq_no=invoice_account_item.invoice_item_adjustment_seq_no)
LEFT JOIN "gmx9_invoice".invoice_item_feature ON (invoice_item_feature.invoice_type=invoice_account_item.invoice_type
AND invoice_item_feature.invoice_id=invoice_account_item.invoice_id
AND invoice_item_feature.invoice_item_seq_no=invoice_account_item.invoice_item_seq_no
AND invoice_item_feature.prod_feature_id=invoice_account_item.invoice_item_prod_feature_id)
WHERE invoice_account_item.invoice_type= 'V'
AND invoice_account_item.invoice_id= 2856045177200000000000000000000000001
AND invoice_account_item.invoice_item_seq_no= '2'
LOCK IN SHARE MODE
On the Windows 10 server the 2nd SELECT works, but on the Linux server it fails with "Lock wait timeout exceeded; try restarting transaction"

SSIS Execute SQL Task error

I'm having an SSIS package which gives the following error when executed :
Error: 0xC002F210 at Execute SQL Task 1, Execute SQL Task: Executing the query "Declare #POID as Varchar(50)
Set #POID = 636268
..." failed with the following error: "Unable to populate result columns for single row result type. The query returned an empty result set.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Task failed: Execute SQL Task 1
The package has a single Execute SQL task with the properties listed below :
General Properties
Result Set : Single Row
ConnectionType : OLEDB
Connection : Connected to Server
SQLSourceType : Direct Input
SQL Statement :
Declare #POID as Varchar(50)
Set #POID = 0
SELECT DISTINCT BizTalk_POA_HEADER.PONUMBER, FAN_Suppliers.SupplierName, FAN_Company_Details.CompanyName, FAN_Company_Details.[PrimaryEmail], BizTalk_POA_HEADER.[DeliveryDate]
FROM BizTalk_POA_HEADER
INNER JOIN FAN_PO_Details ON BizTalk_POA_HEADER.PONUMBER = FAN_PO_Details.PoNumber
INNER JOIN FAN_PO ON FAN_PO_Details.PurchaseOrderID = FAN_PO.PurchaseOrderID
INNER JOIN FAN_SupplierDetails ON FAN_PO.SupplierDetailsID = FAN_SupplierDetails.SuppliersDetailsID
INNER JOIN FAN_Suppliers ON FAN_SupplierDetails.SupplierID = FAN_Suppliers.SupplierID
INNER JOIN FAN_Company_Details ON FAN_PO.CompanyID = FAN_Company_Details.CompanyDetailsID
WHERE (BizTalk_POA_HEADER.PONUMBER = #POID)**
IsQueryStorePro : False
BypassPrepare : False
Parameter Mapping Properties
None
ResultSet
ResultName Variable Name
0 User:PONUMBER
1 User:StoreName
2 User:StoreEmail
3 User:Supplier
4 User:DeliveryDate
I would appreciate if anybody can help me out of this issue by suggeting where the problem is.
I then changed my query to the following as the above was showing conversion error in SSMS, when I try to include the below in Execute SQL Task the query isn't saved , any reason?
SELECT DISTINCT BizTalk_POA_HEADER.PONUMBER,FAN_Suppliers.SupplierName, FAN_Company_Details.CompanyName,
FAN_Company_Details.[PrimaryEmail], BizTalk_POA_HEADER.[DeliveryDate]
FROM BizTalk_POA_HEADER INNER JOIN
FAN_PO_Details ON CAST(BizTalk_POA_HEADER.PONUMBER AS VARCHAR(128)) = CAST(FAN_PO_Details.PoNumber AS VARCHAR(128)) INNER JOIN
FAN_PO ON FAN_PO_Details.PurchaseOrderID = FAN_PO.PurchaseOrderID INNER JOIN
FAN_SupplierDetails ON FAN_PO.SupplierDetailsID = FAN_SupplierDetails.SuppliersDetailsID INNER JOIN
FAN_Suppliers ON FAN_SupplierDetails.SupplierID = FAN_Suppliers.SupplierID INNER JOIN
FAN_Company_Details ON FAN_PO.CompanyID = FAN_Company_Details.CompanyDetailsID
Thanks in Advance.
If 0 records are returned from your query and you are trying to populate a result set, that is the error you will get. Change your query so it always returns a single result and the error will go away.

syntax error when running query in MS Access 2010

good day
i am trying to run an update query but getting the following error "syntax error in join operation"
Here is the query:
update (table 1
set SEQ=table2.SEQ)
from (table1 inner join table2 on table1.NBR=table2.NBR and table1.LINE = table2.LINE and table1.VENNO = table2.VENNO and table1.INVNO = table2.INVNO where table1.SEQ <> table2.seq)
Any assistance will be appreciated.
Your syntax is wrong. UPDATE queries don't use FROM. The right syntax is:
update
table1
inner join table2
on table1.NBR=table2.NBR
and table1.LINE = table2.LINE
and table1.VENNO = table2.VENNO
and table1.INVNO = table2.INVNO
set
table1.SEQ = table2.SEQ
where
table1.SEQ <> table2.seq

Convert query to hibernate criteria query

I have the following Sybase query,
select *
from dbo.translation_style_sheet t1
where t1.create_date = (select max(t2.create_date)
from dbo.translation_style_sheet t2
where t1.file_name = t2.file_name);
I'm trying to convert it to a hibernate criteria query, but haven't been able to figure it out. I'm assuming I need to use a DetachedCriteria to handle this, but not sure how to work with it.
This is what I have thus far.
DetachedCriteria maxCreateDate = DetachedCriteria.forClass(TranslationStyleSheet.class, "translationStyleSheet2")
.setProjection( Property.forName("createDate").max() )
.add( Property.forName("translationStyleSheet2.fileName").eqProperty("translationStyleSheet.fileName") );
List<TranslationStyleSheet> translationStyleSheets = this.session.createCriteria(TranslationStyleSheet.class, "translationStyleSheet")
.add( Property.forName("createDate").eq(maxCreateDate))
.list();
I'm getting the following exception.
org.hibernate.exception.GenericJDBCException
could not execute query
SQL
select this_.translation_style_sheet_id as translat1_20_0_, this_.create_date as create2_20_0_, this_.description as descript3_20_0_, this_.file_content as file4_20_0_, this_.file_extension as file5_20_0_, this_.file_name as file6_20_0_, this_.file_size as file7_20_0_, this_.style_sheet_content as style8_20_0_, this_.style_sheet_type as style9_20_0_ from translation_style_sheet this_ where this_.create_date = (select max(translationStyleSheet2_.create_date) as y0_ from translation_style_sheet translationStyleSheet2_ where translationStyleSheet2_.file_name=this_.file_name)
SQLState
ZZZZZ
Does anybody know what I'm doing wrong?
UPDATE
The error seems to be be happening at the max(translationStyleSheet2_.create_date) as y0_
as. When I remove the as y0_ in the sql statement, I'm able to run the query the query, however I'm not sure how to repair this in hibernate criteria though.
So I had no success getting this to work as a criteria query, but I did have success getting it to work as an HQL query.
HQL solution
this.session.createQuery("from TranslationStyleSheet this "
+ "where this.createDate = (select max(translationStyleSheet2.createDate) "
+ "from TranslationStyleSheet translationStyleSheet2 "
+ "where translationStyleSheet2.fileName=this.fileName)")
.list();
I'm still interested in getting the query to work as a criteria query though.

Update a single table based on multiple tables - appears to works MySql not ACCESS 2003

Mysql Version Works
UPDATE results SET rCARRIER = (
SELECT cellCarrierName
FROM tblImportedTempTable, user, cellCarrier
WHERE
userEmployeeNumber = tblImportedTempTable.EMPLOYEENUMBER
AND userId = results.rUserId
AND results.rPHONENUMBER = tblImportedTempTable.PHONENUMBER
AND CARRIER = cellCarrierId )
I have written this sql that works fine in MySql(above) and fails in access 2003(below) any suggestions? Is one or both of the 2 nonstandard sql? Does Access hav an admin problem?
Sorry the field and table names are diferent this is the ACCESS version.
Access version
UPDATE tblWorkerPhoneNumber SET tblWorkerPhoneNumber.PhoneCarrier = (
SELECT PhoneCarrierType.CarrierName
FROM tblImportedPhoneCarrier, tblWorkerMaster, PhoneCarrierType
WHERE
tblWorkerMaster.EmployeeNumber = tblImportedPhoneCarrier.Emp
AND tblWorkerMaster.WorkerID = tblWorkerPhoneNumber.WorkerID
AND tblWorkerPhoneNumber.PhoneNumber = tblImportedPhoneCarrier.Cell
AND tblImportedPhoneCarrier.CarrierCode = PhoneCarrierType.CarrierID )
Error Message
Operation must use and updateable query
Thanks
In MS Access, something like this:
UPDATE tblWorkerPhoneNumber
INNER JOIN tblWorkerMaster ON tblWorkerMaster.WorkerID = tblWorkerPhoneNumber.WorkerID
INNER JOIN tblImportedPhoneCarrier ON tblWorkerPhoneNumber.PhoneNumber = tblImportedPhoneCarrier.Cell
INNER JOIN PhoneCarrierType ON tblImportedPhoneCarrier.CarrierCode = PhoneCarrierType.CarrierID
SET tblWorkerPhoneNumber.PhoneCarrier = PhoneCarrierType.CarrierName
WHERE tblWorkerMaster.EmployeeNumber = tblImportedPhoneCarrier.Emp
(Might need to change the join conditions; I'm not familiar with your schema)