Hi there,
I use the SQLQuery() from time to time for some custom queries.
Had to recognize, that if you choose multiple tables you have to add ',' inside the FROM Strings inside the from array.
Here is an example to see what I mean:
$sqlQuery->select = array(
'Referencefile.Name',
'Referencefile.Description',
'File.Filename',
'Referencefile.URL',
'Referencefile.ID as id'
);
$sqlQuery->from = array(
'Referencefile,',
'File,',
'SiteTree'
);
$sqlQuery->where = array(
'Referencefile.Bildtyp="Referenzbild"',
'Referencefile.ReferencePageID='.$referenz['id'],
'Referencefile.AttachmentID=File.ID',
'Referencefile.active = 1',
'SiteTree.ID=Referencefile.ReferencePageID'
);
As you can see I had to use
$sqlQuery->from = array(
'Referencefile,',
'File,',
'SiteTree'
);
If I don't insert the ',' in 'Referencefile,' and File,', the real resulting SQL String look something like that:
...
SELECT ......
FROM Referencefile File SiteTree
WHERE
...
But it has to be
...
SELECT ......
FROM Referencefile, File, SiteTree
WHERE
...
I could only trigger that by adding ',' like in my example above. Is that normal behaviour or instead a little bug in SQLQuery() function?
Tested with Version 2.3.0 and 2.3.3.
Thanx a lot to make that clear!
Silverstripe is a great CMS and we all should make it even better!
cabby