js/main.js
//Run a command in the database

Run a command in the database
Run a command in the database
function execute(commands, check) {
    try {
        $('#response-SQL').parent().hide()
        check = (typeof check !== 'undefined') ? check : true
        if (checkDBChanges(commands) && !isSandboxMode()) {
            $('#response-SQL').addClass('alert-danger').html('You can only make changes to the database when sandbox mode is enabled!').show().delay(3000).fadeOut(function() {
                $(this).removeClass('alert-danger')
            })
            return
        }
        var results = db.exec(commands)
        if (checkDBChanges(commands)) {
            saveDB(db)
            updateView(false)
            check = false
        }
        else {
            cleanView(false)
        }
        currQuestion = (typeof Cookies.get('CurrQuestion') !== 'undefined') ? Cookies.get('CurrQuestion') : 1
        if (isSandboxMode() === true || check === false) {
            showFeedback('Query executed successfully', 'alert-success');
        } else if (isCompleted(currQuestion)) {
            showFeedback('Well done! The answer was correct', 'alert-success');
        } else {
            var feedback = checkAnswer(results, commands);
            if (feedback === true) {
                $('#btn-q' + currQuestion).addClass('btn-success')
                markComplete(currQuestion)
                showFeedback('Well done! The answer was correct', 'alert-success');
                $('#questions-SQL>div>button:not(.btn-success):first').trigger('click')
            } else {
                showFeedback(feedback, 'alert-danger');
            }
        }
        var html = ''
        if (results.length === 0) {
            html = '<em> No rows returned </em>'
        } else {
            for (var i = 0; i < results.length; i++) {
                html = html + "<div style='margin-bottom:10px;'>Number of Records: " + results[i].values.length + " " + (results[i].values.length > 10 ? ' (Showing first 10 results)' : '') + "</div>";
                html = html + "<table class='table table-striped table-bordered'>"
                results[i].values.length = (results[i].values.length > 10 ? 10 : results[i].values.length)
                html = html + tableCreate(results[i].columns, results[i].values)
            }
            html = html + "</table>"
        }
        $('#results-SQL').html(html)
    }
    catch (e) {
        showFeedback(e, 'alert-danger');
    }
}
function execute ( commands , check ) { try { $ ( '#response-SQL' ) . parent ( ) . hide ( ) check = ( typeof check !== 'undefined' ) ? check : true if ( checkDBChanges ( commands ) && ! isSandboxMode ( ) ) { $ ( '#response-SQL' ) . addClass ( 'alert-danger' ) . html ( 'You can only make changes to the database when sandbox mode is enabled!' ) . show ( ) . delay ( 3000 ) . fadeOut ( function ( ) { $ ( this ) . removeClass ( 'alert-danger' ) } ) return } var results = db . exec ( commands ) if ( checkDBChanges ( commands ) ) { saveDB ( db ) updateView ( false ) check = false } else { cleanView ( false ) } currQuestion = ( typeof Cookies . get ( 'CurrQuestion' ) !== 'undefined' ) ? Cookies . get ( 'CurrQuestion' ) : 1 if ( isSandboxMode ( ) === true || check === false ) { showFeedback ( 'Query executed successfully' , 'alert-success' ) ; } else if ( isCompleted ( currQuestion ) ) { showFeedback ( 'Well done! The answer was correct' , 'alert-success' ) ; } else { var feedback = checkAnswer ( results , commands ) ; if ( feedback === true ) { $ ( '#btn-q' + currQuestion ) . addClass ( 'btn-success' ) markComplete ( currQuestion ) showFeedback ( 'Well done! The answer was correct' , 'alert-success' ) ; $ ( '#questions-SQL>div>button:not(.btn-success):first' ) . trigger ( 'click' ) } else { showFeedback ( feedback , 'alert-danger' ) ; } } var html = '' if ( results . length === 0 ) { html = '<em> No rows returned </em>' } else { for ( var i = 0 ; i < results . length ; i ++ ) { html = html + "<div style='margin-bottom:10px;'>Number of Records: " + results [ i ] . values . length + " " + ( results [ i ] . values . length > 10 ? ' (Showing first 10 results)' : '' ) + "</div>" ; html = html + "<table class='table table-striped table-bordered'>" results [ i ] . values . length = ( results [ i ] . values . length > 10 ? 10 : results [ i ] . values . length ) html = html + tableCreate ( results [ i ] . columns , results [ i ] . values ) } html = html + "</table>" } $ ( '#results-SQL' ) . html ( html ) } catch ( e ) { showFeedback ( e , 'alert-danger' ) ; } }
Run a command in the database
Run a command in the database
// hide the feedback from previous attempt (if any)
 // don't check answer if someone clicks on the sidebar tables for example!
 // only make changes if sandbox mode!
 // if it is sandbox and changes can be made... make them!
 // if it changes the database save the changes
 //Don't check db changes as all questions relate to SELECT
 // only clean if selecting something!
 // if sandbox mode don't even check the cache for the answer just let them play
 //--- correct answer! ---//
 // store the completed questions in a cookie! form of [1, 2 ... 5, 7]
 // display the success ribbon
 // Move on to the next incomplete question in order!
 // incorrect
 // limit results
 //Error running the query! Display error message
