Bug 53867 - VIEWING: Base MySQL (JDBC) Problem with Query Builder
Summary: VIEWING: Base MySQL (JDBC) Problem with Query Builder
Status: CLOSED INVALID
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
3.5.6.2 release
Hardware: Other Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-21 06:39 UTC by Tyler
Modified: 2012-08-23 18:12 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Attached is a screenshot from where I tested the SQL statement (the smaller box) using Tools -> SQL... The main image is the same SQL statement failing to be made in the Query Builder. (98.03 KB, image/png)
2012-08-21 06:39 UTC, Tyler
Details
screenshot of new resultset display from Tools > SQL statement execution (72.28 KB, image/png)
2012-08-21 13:16 UTC, Alex Thurgood
Details
This is a photo that contains both the fact that the query runs with the Parser off, but will not make a usable form. (68.65 KB, image/png)
2012-08-21 16:54 UTC, Tyler
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tyler 2012-08-21 06:39:37 UTC
Created attachment 65864 [details]
Attached is a screenshot from where I tested the SQL statement (the smaller box) using Tools -> SQL... The main image is the same SQL statement failing to be made in the Query Builder.

Problem description: 
I have my LibreOffice Base connected to my MySQL database server. I have a valid query that I have tested. Attached is a picture where I show you the query is valid using Tools -> SQL... This query also works (without the grave accents LibreOffice uses for MySQL) directly in MySQL.

The problem is with the Query Builder and the MySQL function, DATE_SUB. Query Builder has a problem with the second parameter, the INTERVAL 2 WEEK.

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add explains that there is nothing wrong with this statement. I also tried to put the 2 in quotes as it is technically a string, but Query Builder wouldn't allow this either.

In short, the run SQL command (and MySQL) has no problem with the statement, but Query Builder claims the statement is invalid.

Steps to reproduce:
1. Connect to a MySQL database.
2. Click 'Create Query in SQL view...'
3. Create a query that uses the DATE_ADD or DATE_SUB functions.

Current behavior:
Gives Error Code:  1000 and will not proceed.

Expected behavior:
As the statement is valid, it should allow you to save and run the query.

Platform (if different from the browser): 
I am using 64-bit Microsoft Windows 7.
              
Browser: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.79 Safari/537.1
Comment 1 Alex Thurgood 2012-08-21 12:34:17 UTC
Hi,

My personal experience of using DATE_ADD/SUB functions with OOo and LO is that :

- you generally have to add an alias to your function ;

- sometimes you have to use an explicit cast for the data type, otherwise OOo/LO gets confused and the function fails.

Try defining the DATE_SUB value with an ALIAS and/or CASTing your date_sub to a specific data type.


Alex
Comment 2 Alex Thurgood 2012-08-21 12:47:06 UTC
For example, the following works for me in 

LibreOffice 3.5.5.3 
Version ID : 7122e39-92ed229-498d286-15e43b4-d70da21


with a JDBC driver connection :

DATE_ADD(Prio_FF_date1, INTERVAL 30 MONTH),DATE_ADD(Filing_date1, INTERVAL 30 MONTH)) as 'NATPHA'
Comment 3 Alex Thurgood 2012-08-21 12:53:04 UTC
Note that this also works for me :


DATE_SUB(CURDATE(),INTERVAL 30 MONTH) <= Filing_date1 order by filing_date1


and I haven't explicitly CAST or created an ALIAS for the result of my function


Can not confirm, at least not on Mac OSX 10.8
Comment 4 Alex Thurgood 2012-08-21 12:57:26 UTC
Changing to Windows OS for moment as I can not reproduce on Mac.
Comment 5 Alex Thurgood 2012-08-21 13:04:38 UTC
Hmm, should've read closer :

"using Tools -> SQL... "

this is the wrong tool for the job, the Tools > SQL can be used for executing queries, but it won't return any visible result (at least not for the time being, but I believe it is being worked on). However, it should at least report that the query was executed with success.

If you want your queries to fiddle with your queries, you need to do so from the Query editor within the ODB document, either via the SQL parser, which will thrown an error like the one you indicated, or by deactivating the LO SQL parser, and using the "DirectSQL" mode which sends the query statement unaltered to the backend db engine.

So, for me, this is not a bug, I can not reproduce it, even from the Tools > SQL menu.


Alex
Comment 6 Alex Thurgood 2012-08-21 13:16:03 UTC
Having now tested with the master build of 21/08, I can even state that the feature I mentioned as under development works and the result set is now displayed in the Tools > SQL window, as per screenshot attachment. Note that the result set is displayed as a list of comma separated values.


Alex
Comment 7 Alex Thurgood 2012-08-21 13:16:52 UTC
Created attachment 65882 [details]
screenshot of new resultset display from Tools > SQL statement execution
Comment 8 Tyler 2012-08-21 16:27:31 UTC
Hi Alex,

Thank you for your comments. I will try to address them all, and if this is not a true bug, we will mark it as such and move on.

When you connected to MySQL, under 'Connect to an existing database' did you choose MySQL? On the next screen, 'Set up MySQL Connection', is where I specified to use the JDBC. I only stress this because I'm aware of JDBC being an option at the beginning, and (while it probably does) I'm not sure if it works the same.

My query is this:

SELECT AVG( `sys` ) AS `Systolic`, AVG( `dia` ) AS `Diastolic` FROM `Reading` WHERE `date` >= DATE_SUB( NOW( ), INTERVAL 2 WEEK )

I'm using DATE_SUB in the WHERE clause, and I'm not sure how using an alias would help.

As for using Tools -> SQL..., I was merely using it to show that the statement ran successfully. It does in fact, run successfully on mine, too. I don't imagine the parser checks here, so it wouldn't have a problem.

As to using 'Run SQL command directly' inside of the Query Builder, this worked. My statement ran (I took out the grave accents) just fine with this on. I didn't have this on before (I didn't know exactly what it did), and the problem was the INTERVAL 2 WEEK part. If I enclosed it all in a string 'INTERVAL 2 WEEK', the parser was happy, and it let me save and close it with no errors. Obviously, MySQL threw an exception when it was given that statement with 'INTERVAL 2 WEEK' in quotes though.

I leave the future of this report up to you as you have more experience than I. On my end, the SQL parser will not let statements with DATE_ADD or DATE_SUB through, but turning the parser off allows me to run the same statement with no error. That sounds like a bug to me, but as I develop all of my queries in MySQL first, I'll probably never turn the Parser back on anyway (I won't have to add grave accents).

As this is a problem with the SQL Parser (on my end at least), my original bug description may not be valid anymore. Since I can just turn the parser off, I can get back to business.
Comment 9 Tyler 2012-08-21 16:53:36 UTC
Despite the fact that the query now runs on its own, (I can double click it and the table view opens up with the correct information) I cannot make a report based on this query. I'm going to add a picture that shows the query is now running with no problems (except prehypertention) and the error dialog box that opens when I try to open a form based on this query. (The form was made with no problems, but won't open.)

Is there anyway to turn the SQL Parser off for the entire program?
Comment 10 Tyler 2012-08-21 16:54:35 UTC
Created attachment 65900 [details]
This is a photo that contains both the fact that the query runs with the Parser off, but will not make a usable form.
Comment 11 Tyler 2012-08-21 17:01:30 UTC
The workaround for this is to Edit the Form. Show the Properties (F4), look under the Data tab, click the ellipse (...) next to Content which will bring up another Query Builder with the SQL statement. Once again, you have to Run the SQL Statement Directly. The Form will load properly after this is done.
Comment 12 Alex Thurgood 2012-08-23 18:12:01 UTC
(In reply to comment #8)

Hi Tyler,


> When you connected to MySQL, under 'Connect to an existing database' did you
> choose MySQL? On the next screen, 'Set up MySQL Connection', is where I
> specified to use the JDBC. I only stress this because I'm aware of JDBC being
> an option at the beginning, and (while it probably does) I'm not sure if it
> works the same.

Yes, I have had a JDBC mysql connection set up to one of my work database servers for the last 6 or 7 years, as a backup for the native mysql connector in case that gets broken by LO development (which it has, unfortunately, on more than one occasion). 



> 
> I leave the future of this report up to you as you have more experience than I.
> On my end, the SQL parser will not let statements with DATE_ADD or DATE_SUB
> through, but turning the parser off allows me to run the same statement with no
> error. That sounds like a bug to me, but as I develop all of my queries in
> MySQL first, I'll probably never turn the Parser back on anyway (I won't have
> to add grave accents).
> 
> As this is a problem with the SQL Parser (on my end at least), my original bug
> description may not be valid anymore. Since I can just turn the parser off, I
> can get back to business.

The parser used by LO internally is, ermmm, how can I say, "suboptimal", and has been for a long time. It tries to be all things to all database engines, which unfortunately is a Herculean task, and something in the end that it doesn't do very well when it comes to what many would consider to be basic SQL functions (for that user's respective database). Add to that the fact that sometimes the db engines or their drivers do not always tell LO the truth about their own capabilities (over/understated), and you have a recipe for disaster, or at least, many "gotchas", which only can be avoided by direct SQL processing.

So, I'm going to close this bug as invalid, since it appears to me that this is a limitation of the parser and not a buggy piece of code. If you want to open up a request for enhancement bug relating to support in the parser for "advanced mysql functions", please go ahead, it'll be another one added to the pile ;-)


Alex