views:

25

answers:

0

hi, I'm trying to change the code of query-tool "Technology Explorer for IBM DB2", so only selected query will be run... I already got some help from the developer himself,but this only helped me find the right parts of code, not with coding new functionality... http://sourceforge.net/projects/db2mc/forums/forum/761212/topic/3821430 I folowed the instructions and changed the Code here:

executeQuery: function(service) { 
var jetztHier = ""; 

if (window.getSelection) { 
  jetztHier = window.getSelection(); 
  } else if (document.getSelection) { 
   jetztHier = document.getSelection(); 
  } else if (document.selection) { 
  jetztHier = document.selection.createRange(); 
  } 
            var adhocStore = ""; 
            var thisObject = this; 
            var parameters = new Object(); 
            parameters.pageID = this.elementUniqueID; 
            parameters.stageID = this.parentStageID; 
            parameters.windowID = this.parentWindowID; 
            parameters.panelID = this.parentPanelID; 
            parameters.USE_CONNECTION = ACTIVE_DATABASE_CONNECTION; 
            //this.adhocEditor.saveHTML(); 
//          var adHocSQLText = $(this.elementUniqueID + '_SQL_TEXT_FRAME').value; 
            var adHocSQLOptions = $(this.elementUniqueID + '_adhocForm').serialize(true); 
            RaiseToTop(this.elementUniqueID + '_RESULT_STAGE', "RESULTS"); 
            var currentTime = new Date(); 
            currentTime = (currentTime.getHours()%12) + ":" + (currentTime.getMinutes() < 10 ? "0" + currentTime.getMinutes() : currentTime.getMinutes())+ ":" + (currentTime.getSeconds() < 10 ? "0" + currentTime.getSeconds() : currentTime.getSeconds()) + (currentTime.getHours() > 11 ? " PM" : " AM" );
//          $(this.elementUniqueID + "_AdhocExecutionHistory_List").insert({top:"<li><a title=\"" + adHocSQLText.replace(/"/g, "&quot;")+ "\" onclick=\"$('" + this.elementUniqueID + "_SQL_TEXT_FRAME').value = decodeURIComponent('" + escape(adHocSQLText) + "'); closeOpenFloatingObject();\">" + currentTime + "</a></li>"});
            var queryPack = this.analyzeQuery(jetztHier, adHocSQLOptions.STMTermChar); 
            //adHocSQLText 
            $i = 0; 
            queryPack.each(function(item) { 
                    parameters['SQL[' + $i + ']'] = item.serverQuery; 
//                  $i++; 
            }); 

as you can see I can already read and out into a variable what user was highlighting, but no I get another error in another part of the script -.- queryText.split is not a function var charSplit = queryText.split("");

analyzeQuery: function(queryText, statmentTermChar) { 
            var charSplit = queryText.split(""); 
            var currentStatment = { 
                    paramCount:0, 
                    serverQuery:"" 
            }; 
            var statmentSet = []; 
            var currentChar = ""; 
            var inQuote = false; 
            var lastCharWasEscape = false; 
            var lastWasSingalQuote = false; 
            var quoteType = ""; 

            charSplit = charSplit.reverse(); 
            while(currentchar = charSplit.pop()) 
            { 
                    if(currentchar == statmentTermChar && !inQuote) 
                    { 
                            lastCharWasEscape = false; 
                            lastWasSingalQuote = false; 
                            if(!currentStatment.serverQuery.match(/^\s*$/)) 
                                    statmentSet.push(currentStatment); 
                            currentStatment = { 
                                                    paramCount:0, 
                                                    serverQuery:"" 
                                            }; 
                    } 
                    else if(currentchar == "\\") 
                    { 
                            lastCharWasEscape = !lastCharWasEscape; 
                            lastWasSingalQuote = false; 
                            currentStatment.serverQuery += currentchar; 
                    } 
                    else if(currentchar == "\"" && !inQuote) 
                    { 
                            lastWasSingalQuote = false; 
                            quoteType = "\""; 
                            inQuote = true; 
                            currentStatment.serverQuery += currentchar; 
                    } 
                    else if(currentchar == "'" && !inQuote) 
                    { 
                            lastCharWasEscape = false; 
                            quoteType = "'"; 
                            inQuote = true; 
                            currentStatment.serverQuery += currentchar; 
                    } 
                    else if(currentchar == '"' && !inQuote) 
                    { 
                            lastWasSingalQuote = false; 
                            lastCharWasEscape = false; 
                            quoteType = '"'; 
                            inQuote = true; 
                            currentStatment.serverQuery += currentchar; 
                    } 
                    else if(currentchar == quoteType && inQuote && (!lastCharWasEscape) ) 
                    { 
                            quoteType = ""; 
                            inQuote = false; 
                            currentStatment.serverQuery += currentchar; 
                    } 
                    else if(currentchar == "?" && !inQuote) 
                    { 
                            lastCharWasEscape = false; 
                            lastWasSingalQuote = false; 
                            currentStatment.paramCount++; 
                            currentStatment.serverQuery += currentchar; 
                    } 
                    else if(currentchar == "/" && charSplit.length > 0 && !inQuote) 
                    { 
                            if(charSplit[charSplit.length-1] == '/') 
                            { 
                                    currentchar = charSplit.pop(); 
                                    while(charSplit.pop() != "\n" && charSplit.length > 0); 
                                    continue; 
                            } 
                            else if(charSplit[charSplit.length-1] == '*') 
                            { 
                                    currentchar = charSplit.pop(); 
                                    while(currentchar = charSplit.pop()) 
                                    { 
                                            if(currentchar == '*' && charSplit.length > 0) 
                                            { 
                                                    if(charSplit[charSplit.length-1] == '/') 
                                                    { 
                                                            currentchar = charSplit.pop(); 
                                                            break; 
                                                    } 
                                            } 
                                    } 
                                    continue; 
                            } 

                            lastWasSingalQuote = false; 
                            lastCharWasEscape = false; 
                            currentStatment.serverQuery += currentchar; 
                    } 
                    else if(currentchar == "-" && charSplit.length > 0 && !inQuote && !lastCharWasEscape) 
                    { 
                            if(charSplit[charSplit.length-1] == '-') 
                            { 
                                    currentchar = charSplit.pop(); 
                                    while(charSplit.pop() != "\n" && charSplit.length > 0); 
                                    continue; 
                            } 

                            lastWasSingalQuote = false; 
                            lastCharWasEscape = false; 
                            currentStatment.serverQuery += currentchar; 
                    } 
                    else if(currentchar == "<" && charSplit.length > 2 && !inQuote && !lastCharWasEscape) 
                    { 
                            if(charSplit[charSplit.length-1] == '!' && charSplit[charSplit.length-2] == '-' && charSplit[charSplit.length-3] == '-')
                            { 
                                    charSplit.pop(); 
                                    charSplit.pop(); 
                                    currentchar = charSplit.pop(); 
                                    while(currentchar = charSplit.pop()) 
                                    { 
                                            if(currentchar == '-' && charSplit.length > 1) 
                                            { 
                                                    if(charSplit[charSplit.length-1] == '-' && charSplit[charSplit.length-2] == '>')
                                                    { 
                                                            charSplit.pop(); 
                                                            currentchar = charSplit.pop(); 
                                                            break; 
                                                    } 
                                            } 
                                    } 
                                    continue; 
                            } 

                            lastWasSingalQuote = false; 
                            lastCharWasEscape = false; 
                            currentStatment.serverQuery += currentchar; 
                    } 
                    else 
                    { 
                            lastWasSingalQuote = false; 
                            lastCharWasEscape = false; 
                            currentStatment.serverQuery += currentchar; 
                    } 
            } 
            if(!currentStatment.serverQuery.match(/^\s*$/)) 
                    statmentSet.push(currentStatment); 
            return statmentSet; 
    }, 
    play: function() { 
            if(this.AllreadyRunning) 
                    return; 
            this.AllreadyRunning = true; 

            var callText = ""; 

            if(this.scriptMode == "SHELL") 
                    callText = this.callBackText + ".executScript();"; 
            else if(this.scriptMode == "SQL") 
                    callText = this.callBackText + ".executeQuery('" + ACTION_PROCESSOR + "?action=executeSQL');"; 
            if(this.parentControlerObject != null) 
                    this.parentControlerObject.runPreAdHocScript(callText); 
            else 
                    eval(callText); 
    }, 

I don't know where the problem is, cause when I tried to use plain text for setting the variable there was no problem, so has to be the function (get.selection) or anything caused by what function is returning? hope someone can help =) thx