Skip to content

Can I run a query inside of a QtScript function? #3874

Answered by JrgMyr
JrgMyr asked this question in Q&A
Discussion options

You must be logged in to vote

This is how far I got:

function analyzeTBL();

var table = arguments[0];
var field = arguments[1];

var sql = 'SELECT COUNT(*), ' +
          'SUM(CASE WHEN ' + field + ' ISNULL THEN 0 ELSE 1 END), ' +
          'SUM(CASE ' + field + ' WHEN "" THEN 1 ELSE 0 END), ' +
          'COUNT(DISTINCT ' + field + '), ' +
          'MIN(' + field + '), ' +
          'MAX(' + field + ') ' +
          'FROM ' + table;

var record = db.eval(sql);

return 'Table ' + table + ' ' + record[0][0] + ' lines, ' +
       'field ' + field + ' ' + record[0][1] + ' values, ' +
       'thereof ' + record[0][2] + ' not blank, ' +
       'from ' + record[0][3] + ' different values.';

https://github.com/pawelsalawa…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by JrgMyr
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3874 on December 09, 2020 11:32.