MySQLdb - create table problem
Ed Hotchkiss
edhotchkiss at gmail.com
Fri Sep 16 22:15:51 EDT 2005
I am trying to use MySQL (use to use access/ASP so i'm lost) with MySQLdb.
I'm trying to read a file with three fields in it, deliminated by commas,
into a MySQL DB.
The code is attached, the access DB and pass etc works :P, and also the txt
file is included. I get a bunch of errors and I have fixed a bunch, but alot
I still don't get. I'm at the 'monkey see, monkey learn a little and type
examples' stage! Thanks again ...
Although it is also attached, the code is below-
-edward
# Script to add links from a comma deliminated file to a MySQL database
# 9/16/05
import MySQLdb
import sys
try:
conn=MySQLdb.connect( host="www.freesql.org <http://www.freesql.org>",
user="edhotchkiss",
port=3306,
passwd="test1",
db="links")
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit(1)
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE links
(
ID INTEGER UNSIGNED
name STRING
URL STRING
category STRING
)
NOT NULL AUTO_INCREMENT
""")
arr=[]
inp = open ("sites1.txt","r")
#read line into array
for line in inp.readlines():
links = map(str, line.split())
arr.append(links)
cursor.execute ("""
INSERT INTO links (name, URL, category)
VALUES
([0:3])
""")
cursor.close()
conn.close()
sys.exit(0)
--
edward hotchkiss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050916/02f3255d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.zip
Type: application/zip
Size: 900 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050916/02f3255d/attachment.zip>
More information about the Python-list
mailing list