在 JSL 脚本的 SQL 语句中从文本框中插入字符串嗨,我第一次尝试 jmp 应用程序。
我想在用于对数据库进行 JMP 查询的 SQL 语句中的文本框中插入一个字符串。 这个字符串是我的搜索参数。
我制作的脚本似乎不起作用,解决方案可能很简单——但我缺少一些基本的 JSL 语法理解,并希望能帮助我克服这个问题,对我来说,这是关键点。
调用和获取字符串的脚本:
parameterScript = Function( {this},
{text},
// This function is called when the Text Edit Box value is committed
input = this << Get Text
);
查询数据库的脚本:
importDataPress = Function( {this},
// This function is called when the button is pressed
name = New SQL Query(
Connection( "ODBC:DSN=DATABASE;PWD=XXX;" ),
QueryName( "my_table" ),
CustomSQL( "SELECT * FROM DATABASE WHERE parameter == \!" + input + \!";" )
) << Run;
<<GET button="" name=""></GET>
谢谢 !
脚本回复:在 JSL 脚本的 SQL 语句中从文本框中插入字符串非常感谢,这成功了:)回复:在 JSL 脚本的 SQL 语句中从文本框中插入字符串尝试这样的事情。注意 evalinsert、panelbox、hlistbox 等的使用。在脚本索引中查找它们以获取更多信息。
importDataPress = Function( {parameter_value},
sql_statement = evalinsert(
"SELECT * FROM DATABASE WHERE parameter = '^parameter_value^'");
show(sql_statement);
// This function is called when the button is pressed
name = New SQL Query(
Connection( "ODBC:DSN=DATABASE;PWD=XXX;" ),
QueryName( "my_table" ),
CustomSQL( sql_statement )
) << Run;
);
nw = new window("Example Input for SQL",
panelbox("Parameter Specification",
hlistbox(
text box("Enter value for parameter: "),
teb = text edit box("", << set width(200)),
),
),
panelbox("Actions",
hlistbox(
button box("Cancel", nw << close window),
button box("OK",
pvalue = teb << get text;
if (pvalue == "",
ew = new window("Error", << modal,
text box("Nothing specified")
);
,
// else import the data
importdatapress(pvalue);
nw << close window;
);
),
),
),
);回复:在 JSL 脚本的 SQL 语句中从文本框中插入字符串您应该从构建更小的块和学习语法开始(如何在 JMP 中连接字符串,命名空间/函数如何工作,等等)
一些材料建议:
JSL 语法参考
JMP15 脚本指南
从 JMP 帮助菜单中找到的脚本索引
非常简短的示例(更改窗口中的文本时检查日志):
Names Default To Here(1);
importDataPress=Function({this},
retVal = this << get text;
sqlString = "select * from * where " || retVal;
Show(sqlString);
);
win = New Window("Example", Text Edit Box("Example Text",
<< set function(
function({this},
importDataPress(this)
)
))
);