[Tutor] Create new MySQL database from user input.

Decibels decibelshelp@charter.net
Mon Jun 16 10:40:02 2003


That worked! I am positive that is one of the ones I tried. I was up several
hours after sending the help request and must have had some typo.

cursor.execute ("CREATE DATABASE %s" % (DBName))
print "Database Created"
cursor.execute ("USE %s" % (DBName))

Finally got these results:

$  python stockpicker6.py --db test
database will be called test
DB doesn't exist. Going to Create it.
Database Created
Creating test Tables
Creating Table portfolio
Creating Table stockinfo
Creating Table stockhistory
,......

> Paul DuBois' book on MySQL is pretty good, though lacking Python coverage.
> MySQLdb is not well documented, but generally follows the db-API.2 spec
> from the python db-sig.  The source code is readable.

 Probably going to have to break down and get me a MySQL book also. But that is the problem
I am having even with the web, is lack of MySQLdb documentation.  

 At least with the stumblers you guys have helped me over and what else I have done. The program
is functional. The database is created, tables created and filled with starter information.  Error checking
might have to be increased, so it spits out useful information. So far so good.

Thanks a lot. Maybe I will finally actually accomplish this.

Dave


On Monday 16 June 2003 07:31 am, you wrote:
> cursor.execute ("CREATE DATABASE %s" (DBName))
>                                     ^^^^
> cursor.execute ("CREATE DATABASE %s", (DBName))
>
> Not tested, but I think that is right.  The MySQLdb module will make the
> substitutions into the %s place holders for you from the second argument
> back into the first argument.  For this case, it would also be quite
> reasonable to build the string yourself in python
>       cursor.execute ("CREATE DATABASE %s" % (DBName))
>
> Paul DuBois' book on MySQL is pretty good, though lacking Python coverage.
> MySQLdb is not well documented, but generally follows the db-API.2 spec
> from the python db-sig.  The source code is readable.
>