http://qs321.pair.com?node_id=243779


in reply to Re: Re: Apache::DBI, DBI, DBD::MySql and MySQL cache?
in thread Apache::DBI, DBI, DBD::MySql and MySQL cache?

Ok, code, Flame's scratchpad. This is the "school project" (Code is too long to be posted here) The sub you are looking for is called quotes, it's near the end of the program. (Any packages not used there are loaded by mod_perl ahead of time.)



My code doesn't have bugs, it just develops random features.

Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

Replies are listed 'Best First'.
Re: Re: Re: Re: Apache::DBI, DBI, DBD::MySql and MySQL cache?
by perrin (Chancellor) on Mar 17, 2003 at 21:08 UTC
    The code is really hard to read because you didn't put in CODE tags. However, I don't see anything wrong with that sub. I think this is a MySQL issue after all. Take a look at this coment from the MySQL manual:

    As of MySQL 3.23.52, MySQL changed the way RAND() functions, such that you MUST supply a SEED to get an actual random number. If you do not, each new connection will return close to the same number as the previous new connection. An example to test this would be to run the follow command multiple times in a row. mysql -u username -p -e'select rand()' A basic way to seed this would be to run RAND(NOW()).

      Ok the code tags are an oops, I thought they were there, must have deleted them (there was an older version of the same program already there, and I deleted that and pasted in the new one.)

      Update: Fixed code tags



      My code doesn't have bugs, it just develops random features.

      Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

      Hmm, your quote from the MySQL manual seems to work. Only I'm twisting it a little to use RAND(?) and I pass a Perl-generated rand :) It's still not quite as random as I would like, but it's definately better. As to the console select statement test, sorry but that failed (diff number each time), but with perl passing different rand numbers most of the time, it's interesting at least.

      Modified Code:
      my $sth = $state->{'DBH'}->prepare('SELECT quote,author FROM quotes + ORDER BY RAND(?) LIMIT 1'); $sth->execute(rand(10000)); my $row = $sth->fetchrow_arrayref; $sth->finish;




      My code doesn't have bugs, it just develops random features.

      Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

Re: Re: Re: Re: Apache::DBI, DBI, DBD::MySql and MySQL cache?
by Hero Zzyzzx (Curate) on Mar 17, 2003 at 20:50 UTC

    I think you need to fix your code tags. . .And you're using package globals. Because these don't change between script invocations between

    Read the CGI to mod_perl porting guide, specifically this part of it.

    -Any sufficiently advanced technology is
    indistinguishable from doubletalk.

      Code tags fixed... sorry. As for the package globals, I only use those for things that never change, I pass around the $state variable (which contains the ARGS, DBH and session info) to any subs I call that need to know what anything else is doing.





      My code doesn't have bugs, it just develops random features.

      Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)