On Tue, May 19, 2009 at 12:50 PM, AJ ONeal <[email protected]> wrote: > I'm trying to create a passoff script for a database class and don't want to > restrict the students to using the names which I'm using. > > I suspect that this can't be done so I'm just going to require them to use > the same table and field names that I'm using, but if I'm wrong and it can > be done I'd be happy to know how. > > > SET @db = 'University'; > SELECT @db FROM DUAL; > +------------+ > | @db | > +------------+ > | University | > +------------+ > 1 row in set (0.00 sec) > USE @db; > ERROR 1049 (42000): Unknown database '@db' > SET @table = 'Class'; > Query OK, 0 rows affected (0.00 sec) > SELECT * FROM @table; > ERROR 1064 (42000): You have an error in your SQL syntax; check the manual > that corresponds to your MySQL server version for the right syntax to use > near '@table' at line 1 >
The obvious answer is that can be accomplished with a scripting language of your choice such as Perl,PHP, or Bash. If you want to stay SQL-ish, you can use mysqltest, the tool used in the MySQL test suite. It has eval command, so you can do something like this: let $db = `select db from databases where id = 1`; eval use $db; You do have to use a hack, though, since that tool is not meant for regular non-testing use: mysqltest -r -R /tmp/out.txt script.sql cat /tmp/out.txt However, if it is for testing, the test nature of the tool can come handy, because it is capable of comparing the actual output with a master file. For more details, mysqltest --help -- Sasha Pachev AskSasha Linux Consulting http://asksasha.com Fast Running Blog. http://fastrunningblog.com Run. Blog. Improve. Repeat. -------------------- BYU Unix Users Group http://uug.byu.edu/ The opinions expressed in this message are the responsibility of their author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG. ___________________________________________________________________ List Info (unsubscribe here): http://uug.byu.edu/mailman/listinfo/uug-list
