7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » sql error on file query
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 591 Views |
-
sql error on file query

3 September 2010 at 1:50am
Hi,
My site breaks after upgrading to 2.4.1 from 2.3.2 with the following error
I upgraded both the FileDataObjectManager module and the Silverstripe files. Everything else now works fine, apart from this code which I used to determine whether there were any files (in this case, case study videos) associated with a given page)
The code I used is:
$videos = DataObject::get('CaseStudyVideo','CaseStudyPageID="'.$this->Top()->ID.'"');
$noVideos = $videos->TotalItems();The error I get back is:
[User Error] Couldn't run query: SELECT "CaseStudyVideo"."ClassName", "CaseStudyVideo"."Created", "CaseStudyVideo"."LastEdited", "CaseStudyVideo"."Name", "CaseStudyVideo"."Width", "CaseStudyVideo"."Height", "CaseStudyVideo"."SortOrder", "CaseStudyVideo"."AttachmentID", "CaseStudyVideo"."ThumbnailID", "CaseStudyVideo"."CaseStudyPageID", "CaseStudyVideo"."ID", CASE WHEN "CaseStudyVideo"."ClassName" IS NOT NULL THEN "CaseStudyVideo"."ClassName" ELSE 'CaseStudyVideo' END AS "RecordClassName" FROM "CaseStudyVideo" WHERE (CaseStudyPageID="188") ORDER BY SortOrder ASC Unknown column '188' in 'where clause'
CaseStudyVideo is the DataObject
This worked fine before the upgrade. Can you spot anything amiss with the code?
Adrian
-
Re: sql error on file query

3 September 2010 at 1:51am
I should clarify actually that I am running this code within a function on CaseStudyImage, so I am trying essentially to get any videos associated with the same page as the images.
-
Re: sql error on file query

3 September 2010 at 2:43am
Resolved this issue. Seems to be that it is an apostrope vs double apostrophe issue
replacing with DataObject::get('CaseStudyVideo',"CaseStudyPageID='".$this->CaseStudyPageID."'") seemed to do the trick
-
Re: sql error on file query

3 September 2010 at 3:20am
Yeah, double quotes will get parsed as tickmarks (`), I believe, which would make your comparison operator CaseStudyImageID = "188" become CaseStudyImageID = `188`, which means MySQL will parse 188 as a column name (!)
| 591 Views | ||
|
Page:
1
|
Go to Top |

