|
Jim Gallacher
jg.lists at sympatico.ca
Sat Sep 17 16:35:48 EDT 2005
Can you be a little more specific about the errors you're seeing?
Tracebacks? Input data? Is anything getting inserted into the table?
Jim
Ed Hotchkiss wrote:
> Ok. I am trying to read a csv file with three strings separated by commas.
> I am trying to insert them into a MySQL DB online.
> MySQLdb is installed, no problems.
>
> I think that I am having some kind of error with my csv going into the
> fields and being broken apart correctly. Can someone please help? I
> attached the code below, it does work with that SQL server also if you
> want to try and run it. Thanks in advance ..
>
> -----
>
> # Script to add links from a comma deliminated file to a MySQL database
> # 9/16/05
>
> import MySQLdb
>
> conn=MySQLdb.connect( host="www.freesql.org",
> user="edhotchkiss",
> port=3306,
> passwd="test1",
> db="links")
>
> cursor = conn.cursor()
> stmt = "DROP TABLE IF EXISTS links"
> cursor.execute(stmt)
> stmt = """CREATE TABLE links (
> ID INT NOT NULL,
> Name TEXT,
> URL LONGTEXT,
> Category LONGTEXT,
> primary key (ID)
> )"""
> cursor.execute(stmt)
>
>
> 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 (%s, %s, %s)""" % tuple(links[0:3])
> )
> cursor.close()
> conn.close()
>
>
>
>
> ------------------------------------------------------------------------
>
>
> # Script to add links from a comma deliminated file to a MySQL database
> # 9/16/05
>
> import MySQLdb
>
> conn=MySQLdb.connect( host="www.freesql.org",
> user="edhotchkiss",
> port=3306,
> passwd="test1",
> db="links")
>
> cursor = conn.cursor()
> stmt = "DROP TABLE IF EXISTS links"
> cursor.execute(stmt)
> stmt = """CREATE TABLE links (
> ID INT NOT NULL,
> Name TEXT,
> URL LONGTEXT,
> Category LONGTEXT,
> primary key (ID)
> )"""
> cursor.execute(stmt)
>
>
> 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 (%s, %s, %s)""" % tuple(links[0:3])
> )
> cursor.close()
> conn.close()
>
>
>
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> O'reilly Python Archive,http://python.oreilly.com/archive.html,python
> Python Tutorials,http://www.awaretek.com/tutorials.html,python
> MySQL Python,http://sourceforge.net/projects/mysql-python,python
> Python Vaults of Parnassus,http://www.vex.net/parnassus/,python
> PyCrypto,http://www.amk.ca/python/code/crypto,Python
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
|