Okay
  Public Ticket #2963314
WPdatatables rewrites my SQL query
Closed

Comments

  • FREDRIK JONASSON started the conversation

    I have a MySql Query that is rewritten by the wpdatatable GUI when pressing save and is not valid anymore.

    My SQL uses a NATURAL LEFT JOIN to produce a summary of two columns and a procentage differance, In my sql progam the SQL is OK, byt when i put it into WPdatatables and press sage  the "NATURAL" is dropped from the sql. Is this a bug or some feature that can be configured?

    Original SQL:

    SELECT
    SANKTION.Jurisdiction, 
    SANKTION.Gruppering, 
    count( DISTINCT SANKTION.Sanktion_timestamp ) AS Totalt_Antal, 
    count( DISTINCT SANKTION_KOMPONENT.Sanktion_timestamp ) AS Behandlat_Antal, 
    count( DISTINCT SANKTION_KOMPONENT.Sanktion_timestamp ) / count( DISTINCT SANKTION.Sanktion_timestamp ) * 100 AS pct
    FROM
    SANKTION
    NATURAL LEFT JOIN
    SANKTION_KOMPONENT
    GROUP BY
    SANKTION.Jurisdiction
    ORDER BY
    pct DESC 

    SQL generated from wpdatatable:

    SELECT
    SANKTION.Jurisdiction,
    SANKTION.Gruppering,
    count( DISTINCT SANKTION.Sanktion_timestamp ) Totalt_Antal,
    count( DISTINCT SANKTION_KOMPONENT.Sanktion_timestamp ) Behandlat_Antal,
    count( DISTINCT SANKTION_KOMPONENT.Sanktion_timestamp ) / count( DISTINCT SANKTION.Sanktion_timestamp ) * 100 pct 
    FROM
    SANKTION
    LEFT JOIN SANKTION_KOMPONENT 
    GROUP BY
    SANKTION.Jurisdiction 
    ORDER BY
    pct DESC 
    LIMIT 10


  •  2,498
    Aleksandar replied

    Hello Fredrik.

    Unfortunately, since wpDataTables is not a database management plugin, and is using a 3rd party PHP SQL parser, it's not expected that it works correctly with all statements you add.

    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

    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″.

    Kind Regards, 

    Aleksandar Vuković
    [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