ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Query tag that's in a snnipet throws error in Wiki pages

January 02, 2012 3:24pm

Subscribe [3]
  • #1 / Jan 02, 2012 3:24pm

    glenndavisgroup

    436 posts

    Hi Guys,

    I hope everyone had a very Merry Christmas and Happy New Year!

    I’m having a problem where one of my query tags that’s in a snippet which works perfect in my standard template pages but throws the following error when I try to load it in my wiki pages:

    Error Number: 1064
    
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'current_time format='%Y'} and month(FROM_UNIXTIME(cd.field_id_8)) = {current_t' at line 1
    
    SELECT cd.channel_id,ct.title,cd.field_id_8 as dt,cd.field_id_9 as rate FROM exp_channels c, exp_channel_data cd, exp_channel_titles ct where c.channel_name = 'exchange_rates' and cd.channel_id = c.channel_id and ct.channel_id = cd.channel_id and ct.entry_id = cd.entry_id and ct.status = 'open' and year(FROM_UNIXTIME(cd.field_id_8)) = {current_time format='%Y'} and month(FROM_UNIXTIME(cd.field_id_8)) = {current_time format='%m'}
    
    Filename: modules/query/mod.query.php
    
    Line Number: 181

    Here is the full code in my snippet:

    <div id="divExchangeRateContainer">
       <div id="divExchangeRateSymbolContainer">
          <div id="divExchangeRateSymbol">$</div>
       </div>
       <div id="divExchangeRate">
    {exp:query limit="1" sql="SELECT cd.channel_id,ct.title,cd.field_id_8 as dt,cd.field_id_9 as rate 
    FROM exp_channels c, exp_channel_data cd, exp_channel_titles ct 
    where c.channel_name = 'exchange_rates' 
      and cd.channel_id = c.channel_id 
      and ct.channel_id = cd.channel_id 
      and ct.entry_id = cd.entry_id 
      and ct.status = 'open'
      and year(FROM_UNIXTIME(cd.field_id_8)) = {current_time format='%Y'}
      and month(FROM_UNIXTIME(cd.field_id_8)) = {current_time format='%m'}"}
    
    <a href="/exchange-rates/{dt">{dt format="%M %Y"} US Rate_$1.00USD = ${rate}CAD</a>
    
    {/exp:query}
       </div>
    </div>

    Am I doing something wrong or is this a bug? Any help is appreciated.

    Thank you,

    Mike

  • #2 / Jan 02, 2012 4:23pm

    ahmad saad

    364 posts

  • #3 / Jan 02, 2012 4:35pm

    glenndavisgroup

    436 posts

    Hi Ahmad,

    Did you post something that didn’t make it through?

    Mike

  • #4 / Jan 02, 2012 5:07pm

    glenndavisgroup

    436 posts

    I ran some tests and it looks like the wiki module doesn’t like the following tag:

    {current_time format="%Y"}

    I changed my query to use the mysql now() function like so and it all works now:

    <div id="divExchangeRateContainer">
       <div id="divExchangeRateSymbolContainer">
          <div id="divExchangeRateSymbol">$</div>
       </div>
       <div id="divExchangeRate">
    {exp:query limit="1" sql="SELECT cd.channel_id,ct.title,cd.field_id_8 as dt,cd.field_id_9 as rate 
    FROM exp_channels c, exp_channel_data cd, exp_channel_titles ct 
    where c.channel_name = 'exchange_rates' 
      and cd.channel_id = c.channel_id 
      and ct.channel_id = cd.channel_id 
      and ct.entry_id = cd.entry_id 
      and ct.status = 'open'
      and year(FROM_UNIXTIME(cd.field_id_8)) = year(now())
      and month(FROM_UNIXTIME(cd.field_id_8)) = month(now())"}
    
    <a href="/exchange-rates/{dt">{dt format="%M %Y"} US Rate_$1.00USD = ${rate}CAD</a>
    
    {/exp:query}
       </div>
    </div>

    I hope this helps someone else that might run into this issue. Is there a reason why the EE current_time var is not working in the wiki module?

    Thank you,

    Mike

  • #5 / Jan 03, 2012 2:44pm

    Dan Decker

    7338 posts

    Hi Mike,

    I’m glad you have found a workaround! I don’t believe the issue was that {current_time} is unsupported in the Wiki, but more to do with the parse order. {current_time} is parsed before embeds, and therefore might not be available inside the embed. Embed variables are parsed before {current_time}, so you should be able to pass the value along to your embedded templates, if needed.

    Cheers!

  • #6 / Jan 03, 2012 5:18pm

    ahmad saad

    364 posts

    Hi Moderator.

    I do some checkes on it (put {current_time} in Wiki templeate and it not parssing), so I return to ./system/expressionengine/modules/wiki/mod.wiki.php file and I find that the issue was that {current_time} is unsupported in the Wiki.

    I think that a good Feature Request

  • #7 / Jan 03, 2012 6:27pm

    glenndavisgroup

    436 posts

    Hi Mike,

    I’m glad you have found a workaround! I don’t believe the issue was that {current_time} is unsupported in the Wiki, but more to do with the parse order. {current_time} is parsed before embeds, and therefore might not be available inside the embed. Embed variables are parsed before {current_time}, so you should be able to pass the value along to your embedded templates, if needed.

    Cheers!

    Hi Dan,

    Thanks for the reply. I did test the {current_time} var in the wiki page without using a snippet and it does not work. Correct me if I’m wrong but I thought this var is supposed to be a global var accessible from any template/module in EE? Is this not the case? If not then there is no mention of it anywhere in the docs. Unless it’s a bug?

    P.S.: Didn’t add this in but I’m running the latest version of EE 2.3.1 - Build 20111017 in case anyone is wondering.

    Thank you,

    Mike

  • #8 / Jan 05, 2012 12:42am

    Dan Decker

    7338 posts

    Hi Mike,

    I follow your thinking here, and I would expect it to be available as well. I’m not sure it’s a bug, but it certainly produces and un-expected result. I’ll ping the devs on this for clarification.

    Thanks!

  • #9 / Jan 11, 2012 2:53pm

    Dan Decker

    7338 posts

    Hi Mike,

    I got a response from our developers and we reported this as a bug. If you need anything else, just let us know!

    Cheers!

  • #10 / Jan 11, 2012 3:56pm

    glenndavisgroup

    436 posts

    Hi Dan,

    Thanks for the update. Looking forward to the fix.

    Thank you,

    Mike

  • #11 / Jan 15, 2012 9:46am

    Sean C. Smith

    3818 posts

    Hi Mike,

    Since it looks like Dan has found the answer for you, I’m going to close out this thread, but feel free to post again when you have more questions.

    Sean

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases