SMF Development > Applied or Declined Requests

Automatically convert Rand() to Random()

<< < (2/3) > >>

Joshua Dickerson:
RANDOM() works in all?

Yoshi:
RAND() works only in and MySQL.

An option would be to check the engine used and then convert the RAND() to RANDOM() for PostgreSQL and SQLite, if that hasn't been said before, skipped over the post.

Though you can also use PHP for it, search for RAND() and insert a number generated with rand() in it's place. Dunno if that works in all cases.

Nibogo:

--- Quote from: Joshua Dickerson on April 05, 2012, 12:06:17 PM ---RANDOM() works in all?

--- End quote ---

No, that's the problem, that MySQL uses Rand() while SQLite and PostgreSQL are using Random(), and no, php cannot be used here to just throw a random number.

Joshua Dickerson:
Nibogo, submit a pull request through Github. Seems simple enough to replace RAND() with RANDOM() for non-MySQL installs to make it easier for mod authors (who probably aren't testing with anything besides MySQL anyway).

Arantor:
Or, even use the feature already in SMF to handle this. There are perfectly good reasons not to just rewrite queries on the fly, performance, maintainability, that sort of thing.

Subs-Members.php, generateValidationCode() has this already.


--- Code: --- $request = $smcFunc['db_query']('get_random_number', '
SELECT RAND()',
array(
)
);
--- End code ---

That's what the first parameter to db_query is: specific indications for certain backends that things require work.

It's not elegant, but the entire way multi-architecture is implemented is not elegant. But that's the way it should be done, using what is already there for that purpose.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version