Hello.
I have a MySQL view ‘Months’ with a column ‘Month’ with values ‘01’, ‘02’, etc. all as strings.
This is the smallest example I came up with showing the problem:
SELECT Month, DATE_ADD(CONCAT('2019-', Month, '-01'), INTERVAL 1 MONTH) FROM Months;
In the SQL designer I can run the query if I select the icon to run it natively, but I need to use it with Calc in a datagrid.
So the BASIC code I use is this:
oDBRange = thisComponent.DataBaseRanges.getByName("DataArea")
oDesc() = oDBRange.getImportDescriptor()
For i = 0 to ubound(oDesc())
oPrp = oDesc(i)
If oPrp.Name = "DatabaseName" then
oPrp.Value = "MyDatabase"
elseIf oPrp.Name = "SourceType" then
oPrp.Value = com.sun.star.sheet.DataImportMode.SQL
elseIf oPrp.Name = "SourceObject" then
oPrp.Value = "SELECT Month, DATE_ADD(CONCAT('2019-', Month, '-01'), INTERVAL 1 MONTH) FROM Months;"
elseif oPrp.Name = "IsNative" then
oPrp.Value = True
Endif
oDesc(i) = oPrp
Next
oDBRange.getReferredCells.doImport(oDesc())
But it seems that it is trying to parse the query and not understanding it.
The error returned is not useful, just syntax error.
Any ideas?
Thanks a lot!!!