Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

sql error on file query


Go to End


4 Posts   1027 Views

Avatar
adesweb

Community Member, 39 Posts

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

Avatar
adesweb

Community Member, 39 Posts

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.

Avatar
adesweb

Community Member, 39 Posts

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

Avatar
UncleCheese

Forum Moderator, 4102 Posts

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 (!)