views:

21

answers:

1

I'm experimenting with the built in SQL support in the Safari Browser and I want to select a random query via Javascript.

SELECT * FROM questions ORDER BY random()

Returns not authorized to use function: random

See this screenshot.

Any suggestions?

A: 

Perhaps something like the following would work:

SELECT *
  FROM (SELECT RANDOM() as RANDOM_NUM, Q.*
          FROM QUESTIONS Q)
  ORDER BY RANDOM_NUM

Share and enjoy.

Bob Jarvis
Thanks for your reply but weirdly I get the same error again. not authorized to use function: randomIs this a security issue?
@user422644 - sure sounds that way. Interestingly, this page (http://www.sqlite.org/omitted.html) at the SQLite site says that GRANT and REVOKE aren't supported so I'm not sure how one would work around this. Wish I could offer more ideas.
Bob Jarvis
Another way would be to shuffle the results after I got them. db.transaction( function(transaction) { transaction.executeSql( 'SELECT * FROM questions', [], function (transaction, result) { // best way to shuffle results and loop? }, errorHandler ); }, transactionErrorHandler );