How do I echo-out table-join statements that include where_group()?

How do I echo-out table-join statements that include where_group()?

pansengtatpansengtat Posts: 66Questions: 26Answers: 1

I came across some interesting methods in class Query for Editor, seen here at (http://editor.datatables.net/docs/1.4.0-beta/php/source-class-DataTables.Database.Query.html#574) and I have been using where_group() and and_where() methods within a where (function) written in the server-side script (PHP being my choice).

Question is that if I wish to test if the way I write my table joins correctly; if I were to test out my query in, say, phpMyAdmin-SQL, that query would work. But what if I were to translate my original query wrongly into the Editor syntax? I felt that if there is a way to echo-out or debug/backtrace what I wrote, I can diagnose/troubleshoot abit better.

Here is a sample of what I wrote:

->where( function ( $q ) {
                $q->where( 'myTimetable.isApproved', 1 );
                $q->where_group( true, "OR" );
                $q->where( 'myTimetable.isApproved', 3 );
                $q->and_where( 'myTimetable.CurrentTimePlanned', 0, "!=" );
                $q->and_where( 'myTimetable.OverTimePlanned', 0, "=" );
                $q->and_where( 'myTimetable.SpecialTimePlanned', 0, "=" );
                $q->where_group( false );
            } )

The original query being this:

select *
from myTimetable as tt
left join myIncoming as ic on tt.IncomingID = ic.ID
...
where myTimetable.isApproved = 1
or (myTimetable.isApproved = 3 
and myTimetable.CurrentTimePlanned != 0 
and 'myTimetable.OverTimePlanned = 0 
and myTimetable.SpecialTimePlanned = 0)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    What you have looks correct to me! I'm planning on introducing a debug mode to Editor soon to be able to get this kind of SQL construction information, but at the moment what you would need to do is have a look int he Query.php file for the driver for your database type. You will find an _prepare() method - next the end of that you will be able to dump the $sql variable into a file (or even just echo it) to see exactly what it is doing.

    Regards,
    Allan

This discussion has been closed.