Jump to:

7938 Posts in 1541 Topics by 945 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » sql error on file query

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 716 Views
  • adesweb
    Avatar
    Community Member
    39 Posts

    sql error on file query Link to this post

    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

  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: sql error on file query Link to this post

    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.

  • adesweb
    Avatar
    Community Member
    39 Posts

    Re: sql error on file query Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: sql error on file query Link to this post

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

    716 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.