Okay
  Public Ticket #3681260
Wrong Sum Script
Open

Comments

  •  2
    Alejandro started the conversation

    HI.

    SELECT suxy_condos_balance.`ID_BA`,
           suxy_condos_balance.`amount`,
           suxy_condos_checking_balance_view.`amount2` as `amount2`,
    FROM suxy_condos_balance  
    INNER JOIN suxy_condos_checking_balance_view ON suxy_condos_balance.`ID_BA` = suxy_condos_checking_balance_view.`ID_BA`
    WHERE 
    suxy_condos_balance.`ID_B` = %VAR1%

    SUM function does not work when table is not the main table.

    As you see "FROM suxy_condos_balance " is my main table "and suxy_condos_checking_balance_view" is a join secundary table. 

    So the SUM funtion does not work well when you configure to get Sum Column in 

    suxy_condos_checking_balance_view.`amount2` as `amount2` ".

     This issue happend as well with your filter function.. 

    I have to fix through 

        function wpdatatables_filter_mysql_query($query, $tableId){
            if($tableId != $this->tableId) return $query;

            $query = str_replace("suxy_condos_balance.`amount2`","suxy_condos_checking_balance_view.`amount2`",$query);
            return $query;
        }

    As you see in your filter function does not seems to be checking what table belong this the field `amount2`  in the query

    I suppose that same thing happend with the Sum function. But I could find the if you have a hook that I could use to fix the SUM function bug.

    I eft the picture issue

    https://drive.google.com/file/d/1vf60jgdls9WarLAsnEDZ-6yYimX2cQTX/view?usp=sharing

    Regards

    Alejandro

  •  1,767
    Miloš replied

    Hi Alejandro,

    This is not a bug, it is rather a limitation we have with our SQL Parser when you have server-side processing enabled on your Table.

    I will do my best to elaborate why this happens :

    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 kind of complex Query or specific SQL functions such as JOIN, etc, 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

  •  2
    Alejandro replied

    Hi Milos.

    Thanks for your reply.

    View wont be an option because my table is editable so.

    I can try disable the serverside and look how it works.

    Regards

    Alejandro

  •  1,767
    Miloš replied

    Hi Alejandro,

    Sorry to disappoint you, but you won't be able to edit a table that has any SQL JOIN in it.

    And you also can't edit when server side option is disabled.

    We noted this under the limitations in our editing documentation.

    Only one MySQL table can be edited at a time. Queries from multiple tables with joins cannot be used as an editable feature, since SQL UPDATE and INSERT statements are generated automatically, and there currently is no way to update multiple tables.

    • Only MySQL tables or tables created with “Create a table manually” and “Create a table by importing data from data source” options of “Create a Table” page can be edited.
    • Server-side processing MUST be turned on for front-end editing – Note: It will turn on automatically if you forget to enable it.


    The only way to call one or more columns from foreign tables and have it editable as single value selectbox is with our foreign key relation feature : https://wpdatatables.com/documentation/front-end-editing/configuring-table-relations-foreign-key/.


    I hope that 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