Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

DATE_FORMAT() function in queries for reports Topic is solved

Questions related to nuBuilder Forte Reports and the Report Builder.
Post Reply
capstefano
Posts: 21
Joined: Sat Jan 21, 2023 12:17 am
Has thanked: 19 times
Been thanked: 4 times

DATE_FORMAT() function in queries for reports

Unread post by capstefano »

Hello everyone.
I'm preparing SQLs for several reports with a date filter criteria (like: WHERE table.date_field BETWEEN '#start_date#' AND '#end_date#') and I've noticed that the parser doesn't accept queries that are using the DATE_FORMAT() function (I'm using mariadb).
[I've used the DATE_FORMAT for the select obvously, NOT for the clauses]
Firstly I though it was because my DATE_FORMAT was included in a CONCAT, but then I verified that the formatted value broke the report creation process (with no tables shown when selecting the query from the lookup) even if it's an alone value.
Of course, every field was aliased.

I know that nubuilder has a built-in function for managing formats, but had localization issues with that, so I though that formatting values at the query level could be a good idea (entering a string like 'it_IT' in the function) and the query is working as expected in the regular SQL parser (like in phpmyadmin) but had no luck.

I also tried to create a php procedure from my query, but fields are not shown anyway in report editor.

What I'd like to know is:
Can you confirm that the nubuilder parser doesn't accept DATE_FORMAT() values?
Is there a viable way to localize the formats created with the format editor? Or a way to bypass my problem?
I'd like to obtain a value like DATE_FORMAT(table.date_fields, '%d %M %Y', 'it_IT')*

*(in some queries I have a database field, in some others I use an '#hash_cookie#' from a form object, of appropriate data type/structure)

EDIT: I have noticed that I actually HAVE some working queries with a DATE_FORMAT() function (moreover, inside a CONCAT()) :-( so I have to somehow work around the SQLs, I suppose. I'll maybe try to write them from scratch (only a few), but I was wondering why the same queries run without a problem using phpmyadmin. If the nubuilder parser require any special condition than the server's it's not a big issue, in my opinion, but it would be an useful information to have.
By the way, it's probably just me messing up something while writing down the query.
Everything as usual :-)
Last edited by capstefano on Mon Oct 21, 2024 7:16 pm, edited 1 time in total.
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: DATE_FORMAT() function in queries for reports

Unread post by steven »

Hi capstefano,

If your SQL isn't working, check the debugger.

If your SQL has a problem, it will tell you there...

errors.png

Like this...

debug.png


Steven
You do not have the required permissions to view the files attached to this post.
A short post is a good post.
capstefano
Posts: 21
Joined: Sat Jan 21, 2023 12:17 am
Has thanked: 19 times
Been thanked: 4 times

Re: DATE_FORMAT() function in queries for reports

Unread post by capstefano »

thanks, as usual, for your help Steven
capstefano
Posts: 21
Joined: Sat Jan 21, 2023 12:17 am
Has thanked: 19 times
Been thanked: 4 times

Re: DATE_FORMAT() function in queries for reports

Unread post by capstefano »

Solved.

Code: Select all

CONCAT('some_string', DATE_FORMAT('#hash_cookie#')) AS alias
is not parsed and the debug output is:

Code: Select all

SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect datetime value: '#diario_inizio#'
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'albagest2.___nu16716a55c011ee___' doesn't exist
BUT if the DATE_FORMAT() is nested in a CONCAT() AND in the concatenation function at least a regular data field exists, like

Code: Select all

CONCAT(table.field, ' ', DATE_FORMAT('#hash_cookie#'))
then the query is processed, fields appear in the report-building form, and no output is shown in nuDebug. The created report works as well.

I can't even imagine (and really don't mind about) the causes for this peculiar behavior, but maybe is of some interest for you. Bye!
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: DATE_FORMAT() function in queries for reports

Unread post by steven »

capstefano,

If you find an SQL statement that works but you're not sure why, change it so that it would create an error eg.

Change SELECT * FROM bob

to SELECT1 * FROM bob

It will create an error in the debugger (nuDebug).

That will give you the SQL of the statement that worked - even though you're not sure why.


Steven
A short post is a good post.
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: DATE_FORMAT() function in queries for reports

Unread post by steven »

capstefano,

I have created a video for the debugger...

Using nuBuilder's debugger - nuDebug()



Steven
You do not have the required permissions to view the files attached to this post.
A short post is a good post.
capstefano
Posts: 21
Joined: Sat Jan 21, 2023 12:17 am
Has thanked: 19 times
Been thanked: 4 times

Re: DATE_FORMAT() function in queries for reports

Unread post by capstefano »

useful tool indeed, thanks a lot Steven
Post Reply