Show SQL Statement

Show SQL Statement

karasukarasu Posts: 27Questions: 2Answers: 0
edited May 2019 in Free community support

Hi,

how can I show in the browser the SQL Statement (select) ?
I tried with debug and debugInfo but I have no success.
Also tried console.log

Thank you

Replies

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @karasu ,

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • karasukarasu Posts: 27Questions: 2Answers: 0

    Hi @colin , thank you for your fast reply.

    In the php-file I paste it like
    Editor::inst( $db, 'rooms', 'uid' ) ->debug(true)

    But where I can see the output or have I missing some more code?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @karasu ,

    It'll be in the JSON returned back to the client. So, if you look in the client's developer tools, you should see it under the "network" tab,

    Cheers,

    Colin

  • karasukarasu Posts: 27Questions: 2Answers: 0
    edited May 2019

    Hi @colin ,

    this is correct that I can see whole data I get back but
    I cannot see the SQL select statement in this JSON.
    Have I implement more code ?

    This is my PHP file

    date_default_timezone_set("Europe/Berlin");
    
    include( "lib/DataTables.php" );
    
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;
    
    Editor::inst( $db, 'rooms', 'uid' )
        ->field( 
            Field::inst( 'rooms.start_date' )
                ->set( false )
                ->validator( 'Validate::dateFormat', 'Y-m-d' )
                ->validator( 'Validate::notEmpty' )
                ->getFormatter( 'Format::date_sql_to_format', 'Y-m-d' )
                ->setFormatter( 'Format::date_format_to_sql', 'Y-m-d' )
        )
        ->process($_POST)
        ->debug(true)
        ->json();
    

    This is my JS File

    var editor; 
    
    (function($) {
        $(document).ready(function() {
            console.log('START');
            editor = new $.fn.dataTable.Editor({
                ajax: '/php/table.bookings_test.php',
                table: '#bookings_test',
                fields: [
                    {
                        label:     "Anreise:",
                        name:      "rooms.start_date",
                        type:      "datetime"
                    }]
            });
    
            $('#bookings_test').on('click', 'tbody td, tbody span.dtr-data', function(e) {
                if ($(this).hasClass('control') || $(this).hasClass('select-checkbox')) {
                    return;
                }
            });
    
    
            var table = $('#bookings_test').DataTable({
                "language": {
                  "url": "/i18n/de_de.lang"
                },
                dom: "Bfrtip",
                ajax: '/php/table.bookings_test.php',
                order: [
                    [0, "asc"],
                    [2, "asc"],
                    [1, "asc"]
                ],
                Processing: true,
                ServerSide: false,
                "lengthMenu": [[10, 20, 50, -1], [10, 20, 50, "alle"]],
                "pageLength": 20,
                columns: [
                    { data: "rooms.start_date" }
                ],
                responsive: true,
                columnDefs: [
                    { type: 'date-eu', targets: 0 },
                    { type: 'date-eu', targets: 10 },
                    { responsivePriority: 1, targets: 0 }
                ],
                select: true,
                buttons: [
                    { extend: 'create', editor: editor },
                    { extend: 'edit',   editor: editor },
                    { extend: 'remove', editor: editor }
                ]
            });
        });
    }(jQuery));
    
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    Flip these two lines:

        ->process($_POST)
        ->debug(true)
    

    The debug must be enabled for process to be able to use it, and its sequential!

    Allan

  • karasukarasu Posts: 27Questions: 2Answers: 0

    Hi @allan ,
    it works. Now I can see the select statements.
    Thank you.

  • karasukarasu Posts: 27Questions: 2Answers: 0

    @allan
    How can I close this ticket or mark as answered ?

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @karasu ,

    I think if you hover a message and click the cog, you have an option to make the reply as the answer - to be honest, I've never done it :)

    Cheers,

    Colin

This discussion has been closed.