in our company's application we have a page in our admin backend where we can run sql queries. we display the results in a table, so i made a script that runs an sql query then checks to see if at least one of the select parameters is visible. here's the code:
// vars
//var $sql_query = "select count(*) from membershipapplications"; // 1 column
var $sql_query = "select id, partyname from membershipapplications where id=1"; // multiple columns
do_admin_sql_search($sql_query);
///////////////FUNCTION CODE/////////////
function do_admin_sql_search($sql_query) {
...
var $regex = /(.*select\s+)(.*)(\s+from.*)/;
var $columns = $sql_query.replace($regex, "$2");
var $untrimmed_column1 = $columns.substring(0, $columns.indexOf(","));
var $column1;
if($untrimmed_column1.length > 0) {
$column1 = $untrimmed_column1.replace(/^\s+|\s+$/g,""); // .trim() doesn't work in sahi apparently
} else {
$column1 = $columns;
}
// assert that the query gave some kind of result
_assert(_isVisible(_tableHeader($column1.toUpperCase())));
}
No comments:
Post a Comment