Okay
  Public Ticket #3662904
SQL Date Function Not Pulling Correctly
Closed

Comments

  •  1
    Kevin started the conversation

    Something changed between updates and now the SQL date filter I use to prepopulate our schedule stopped pulled the "next date."

    https://orchestrasociety.org/schedule/

    SELECT 74c_wpdatatable_30.`starttime`,
          74c_wpdatatable_30.`venue`,
           CONCAT(`composerfirstname`,' ',`composerlastname`),
           74c_wpdatatable_30.`work`,
    CONCAT(`firstname`,' ',`lastname`),
           74c_wpdatatable_30.`role`,
           74c_wpdatatable_30.`instrumentation`,
           74c_wpdatatable_30.`notes`
    FROM 74c_wpdatatable_30
    WHERE 
    LOCALTIME() <= `starttime`

    And this stopped working, but then is working again:

    https://orchestrasociety.org/

    SELECT * FROM `74c_wpdatatable_30`
    where year(starttime) = YEAR (CURDATE())
    AND WEEK(CURDATE())= WEEK(starttime)

    These queries were tested in MYSQL and in fact were working perfectly.

  •  1,805
    Miloš replied



    Hi Kevin,

    Can you please check how many rows do you have in the SQL Table in question?

    Is it possible that you had less than 2 thousand rows before and maybe the server-side processing option was disabled when it was working ok;

    and it perhaps recently went over 2 thousand rows - so it enabled the server-side option?


    Check if you have it enabled, now disable it if that is the case, and refresh the table - check if the table now starts filtering properly.

    If so, I notice you have these accent graves around the second Query table name like :

    SELECT * FROM `74c_wpdatatable_30`

    For the MySQL engine, we are dynamically adding the accent grave ( ` ), so there's no need to use it around the table name in the query. If you were to delete them, searching and filtering should work just fine.


    See if that helps, and try to enable server-side option again if you need it.


    If that does not help, I will do my best to advise you on filtering/sorting/search issue that can happen when you have server-side processing enabled for SQL Query tables.

    On this documentation, there are more details which explain how our server-side processing works :

    https://wpdatatables.com/documentation/table-features/server-side-processing/.

    Basically, when the server-side is enabled, the wpDataTables will give the search results through the Query;

    So, our Plugin sends the Query to the database.

    If that Query is formatted as

     "SELECT ...

     FROM ... 

    WHERE... "

    but after the "FROM" if it has any complex Query, as in your case, there can be errors with sorting/filtering/table search;

    Our SQL Query feature does not work in the same way as a Database Management Tool ( such as PHPMyAdmin and similar),

    and is not meant to be used as one;

    Our logic is based on a PHP SQL parser which has full support for the SQL dialect for the following statement types

    SELECT, INSERT, UPDATE, DELETE, REPLACE, RENAME, SHOW, SET, DROP, CREATE INDEX, CREATE TABLE, EXPLAIN and DESCRIBE.

    Some of them are disabled for security reasons.

    Filtering, sorting, and search may not work properly if you include:

    • Accent graves ( ` ) around the table name
    • JOIN functions
    • UNION functions
    • CONCAT functions
    • sub-queries

    -

    So, first you can check for accent graves around the table name, if you have this, remove it...

    Then, see if you used CONCAT to create any column.

    If so, go into this column setting, and disable it from "global search" in the Filtering tab.

    -

    7138515403.png

    -

    If none of that helps,

    you can try preparing a MySQL view (which will return the data that you need, call it e.g. “view1” and then build a wpDataTables based on a simple query like "SELECT * FROM view1″.

     If you need help with that, you can see our video, where we show an example of using View in our plugin.

    -

    To summarize, it can happen that a specific complex Query might work in PhpMyAdmin but struggles to work perfectly for sorting/filtering through our server-side processing ( and the SQL Parser);

    So when the Server-Side is enabled, our plugin sends a more complex SQL Query which in this case is too complicated for our Parser to handle,

    instead of when the server-side is disabled, it just simply filters the data just by the values already seen in the column.

    I hope that this helps to clarify everything.


    So to solve this particular issue, there can be multiple ways :


    1. You can try to simplify your SQL Query in order for our server-side processing to work;


    2. Or try to make an SQL VIEW in your Database, then call it in our SQL Table like : SELECT * FROM ViewName


    3. Or if you can make it work without server-side processing, if your data/number of rows of  the table does not become too large, let's say above 4, 5, 6 thousand rows,  and if the hosting server performs well,

    you can 'get away' with disabling server-side on the table.


     If your SQL query based tables are not bigger than 2.000 rows, 

    you can disable server-side on SQL tables, and it will work like it does for Excel tables. ( loads all rows regardless of pagination)

    If you need to increase the row count while still having the "toggle" to disable server-side,

    Please go to ../wp-content/plugins/wpdatatables/source/class.wpdatatable.php and around line 2176 you'll see this:

    if (count($res_dataRows) > 2000) {

    You can change that number to a value bigger than the number of rows in your table.

    Same should be applied in ../wp-content/plugins/wpdatatables/source/class.wdtconfigcontroller.php on lines 53:

    if (count($wpDataTable->getDataRows()) > 2000) {
    

    And line 100:

    if (count($wpDataTable->getDataRows()) > 2000) {
    

    That will increase the server-side automatic limit.


    I hope this helps.

    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables