plainblack.com
Username Password
search
Bookmark and Share

    

^SQL or ^SQLEx macro on JavaScript

User sysred
Date 3/23/2016 7:15 am
Views 9088
Rating 2    Rate [
|
]
Previous · Next
User Message
sysred

Hi,

When I try to use the ^SQL otr the ^SQLEx macro from a javaScript method with a WHERE clause, I get an error which says "Cannot execute this type of query".

I know the query is well builted. If I use it, for example, in a form, it works.

Any clue?

Regards

--- (Edited on 3/23/2016 7:15 am [GMT-0500] by sysred) ---



Back to Top
Rate [
|
]
 
 
bartjol

Hi, looking at the code, this comes from the macro itself. It checks whether a select, show or describe query is done, and if not, it returns this error.

Is this one of these three type of queries?


Kind regards
Bart

--- (Edited on 23-March-2016 13:39 [GMT+0100] by bartjol) ---

--- (Edited on 23-March-2016 13:40 [GMT+0100] by bartjol) ---



Back to Top
Rate [
|
]
 
 
sysred

Hi, looking at the code, this comes from the macro itself. It checks whether a select, show or describe query is done, and if not, it returns this error.

Is this one of these three type of queries?


Kind regards
Bart

--- (Edited on 23-March-2016 13:39 [GMT+0100] by bartjol) ---

--- (Edited on 23-March-2016 13:40 [GMT+0100] by bartjol) ---


Yes, it's a simple select with a WHERE clause

--- (Edited on 3/23/2016 10:10 am [GMT-0500] by sysred) ---

--- (Edited on 3/23/2016 10:31 am [GMT-0500] by sysred) ---



Back to Top
Rate [
|
]
 
 
sysred

Ok, I've managed to enter the WHERE clause (must escape the ' chars with \).

So, this works:

<script>

function RefreshGroup(group) {

document.getElementById("familiaProducto").outerHTML='^SQL("SELECT DISTINCT Familly FROM db.Products WHERE Group=\'hardCodedGroupNotTheParameterButWorks\'", ^0;, "databaseLinkId");';

}

</script>

This doesn't work (and i need it working!):

<script>

function RefreshGroup(group) {

document.getElementById("familiaProducto").outerHTML='^SQL("SELECT DISTINCT Familly FROM db.Products WHERE Group=\'' + group + '\'", ^0;, "databaseLinkId");';

}

</script>

I've alse tried to, unsuccessfully, use this function to format the string (similar ti C# .Net)

<script>
    String.format = function() {
        var s = arguments[0];
        for (var i = 0; i < arguments.length - 1; i++) {       
            var reg = new RegExp("\\{" + i + "\\}", "gm");             
            s = s.replace(reg, arguments[i + 1]);
        }
        return s;
    }
</script>

Regards

--- (Edited on 3/23/2016 12:12 pm [GMT-0500] by sysred) ---



Back to Top
Rate [
|
]
 
 
roryzweistra
I don’t think you can use the sql macro the way you want it to. I haven’t used WebGUI in a while but as far as I can remember the macro’s are precompiled and therefore cannot be used to update stuff dynamically from javascript functions.

Correct me if I’m wrong of course!



On 23 Mar 2016, at 18:12, <soporte@syspol.es> <soporte@syspol.es> wrote:

sysred wrote:

Ok, I've managed to enter the WHERE clause (must escape the ' chars with \).

So, this works:

<script>

function RefreshGroup(group) {

document.getElementById("familiaProducto").outerHTML='^SQL("SELECT DISTINCT Familly FROM db.Products WHERE Group=\'hardCodedGroupNotTheParameterButWorks\'", ^0;, "databaseLinkId");';

}

</script>

This doesn't work (and i need it working!):


<script>

function RefreshGroup(group) {

document.getElementById("familiaProducto").outerHTML='^SQL("SELECT DISTINCT Familly FROM db.Products WHERE Group=\'' + group + '\'", ^0;, "databaseLinkId");';

}

</script>

I've alse tried to, unsuccessfully, use this function to format the string (similar ti C# .Net)

<script>
    String.format = function() {
        var s = arguments[0];
        for (var i = 0; i < arguments.length - 1; i++) {       
            var reg = new RegExp("\\{" + i + "\\}", "gm");             
            s = s.replace(reg, arguments[i + 1]);
        }
        return s;
    }
</script>

Regards

--- (Edited on 3/23/2016 12:12 pm [GMT-0500] by sysred) ---



http://www.webgui.org/etcetera/-94-sql-or-94-sqlex-macro-on-javascript/3

--

WebGUI
http://www.webgui.org

--- (Edited on 3/23/2016 12:30 pm [GMT-0500] by Visitor) ---



Back to Top
Rate [
|
]
 
 
bartjol

I don’t think you can use the sql macro the way you want it to. I haven’t used WebGUI in a while but as far as I can remember the macro’s are precompiled and therefore cannot be used to update stuff dynamically from javascript functions.
Correct me if I’m wrong of course!

I thought in the same direction, but sysred gets an error from the macro itself, meaning it is getting processed as far as I can tell. Allthough, I think youŕe right on that the won't get evaluated again on a js input.

--- (Edited on 23-March-2016 20:18 [GMT+0100] by bartjol) ---



Back to Top
Rate [
|
]
 
 
roryzweistra
Yeah I still think this is the case, I reckon the first error he got was because of the js ‘group’ vari which can’t be set because the page hasn’t initialised yet, so that must be where the macro error comes from.

chatty-mode

how’s the mongodb course going :P
Will call you soon!

/chatty-mode


On 23 Mar 2016, at 20:18, <bart@procolix.com> <bart@procolix.com> wrote:

bartjol wrote:



I don’t think you can use the sql macro the way you want it to. I haven’t used WebGUI in a while but as far as I can remember the macro’s are precompiled and therefore cannot be used to update stuff dynamically from javascript functions.
Correct me if I’m wrong of course!


I thought in the same direction, but sysred gets an error from the macro itself, meaning it is getting processed as far as I can tell. Allthough, I think youŕe right on that the won't get evaluated again on a js input.


--- (Edited on 23-March-2016 20:18 [GMT+0100] by bartjol) ---



http://www.webgui.org/etcetera/-94-sql-or-94-sqlex-macro-on-javascript/4/re:-94-sql-or-94-sqlex-macro-on-javascript

--

WebGUI
http://www.webgui.org

--- (Edited on 3/23/2016 2:30 pm [GMT-0500] by Visitor) ---



Back to Top
Rate [
|
]
 
 
bartjol

chatty-mode
how’s the mongodb course going :P
Will call you soon!
/chatty-mode
not so good, too busy debugging js+macros

--- (Edited on 23-March-2016 20:35 [GMT+0100] by bartjol) ---



Back to Top
Rate [
|
]
 
 
bartjol

I think the concatenating goes awry:

If I look at where the single quotes are placed, I think it only gets:

'^SQL("SELECT DISTINCT Familly FROM db.Products WHERE Group=\''

(that are 2 sigle quotes on the end) and the next part falls off:

 + group + '\'", ^0;, "databaseLinkId");'

Not sure whether the js variable within a macro gets evaluated properly, allthough nested macros are possible. You might want to try:

document.getElementById("familiaProducto").outerHTML='^SQL("SELECT DISTINCT Familly FROM db.Products WHERE Group=\'" + group + "\'", ^0;, "databaseLinkId");';

but no garantuees, as I really doubt it will work :)

--- (Edited on 23-March-2016 20:32 [GMT+0100] by bartjol) ---



Back to Top
Rate [
|
]
 
 
sysred

I think the concatenating goes awry:

If I look at where the single quotes are placed, I think it only gets:

'^SQL("SELECT DISTINCT Familly FROM db.Products WHERE Group=\''

(that are 2 sigle quotes on the end) and the next part falls off:

 + group + '\'", ^0;, "databaseLinkId");'

Not sure whether the js variable within a macro gets evaluated properly, allthough nested macros are possible. You might want to try:

document.getElementById("familiaProducto").outerHTML='^SQL("SELECT DISTINCT Familly FROM db.Products WHERE Group=\'" + group + "\'", ^0;, "databaseLinkId");';

but no garantuees, as I really doubt it will work :)

--- (Edited on 23-March-2016 20:32 [GMT+0100] by bartjol) ---

First of all, thank you very much for all your replies! (:


Setting the outerHTML was one of my first "bullets" against this problem, I tried it without success. But I've managed to solve my problem using a SQL Report.

Looks like the ^SQL macro is designed to "fire" a SQL sentence "as is" (without any kind of custom parameters)

--- (Edited on 3/30/2016 9:43 am [GMT-0500] by sysred) ---



Back to Top
Rate [
|
]
 
 
    



© 2023 Plain Black Corporation | All Rights Reserved