SQLite and coercing to Unicode - please help.
Steve Holden
steve at holdenweb.com
Thu Sep 6 07:50:15 EDT 2007
special_dragonfly wrote:
> That helped immensely Steve thank you. You're right, this is my first really
> big project ever really, not just in Python.
> Just to clarify, my UPDATE statement instead of looking like this:
>
> longstring="UPDATE SecB SET
> currencyCode='"+Values[1]+"',issuerName='"+Values[2]
> "',instrName='"+Values[3]+\
> "',instrShortName='"+Values[4]+"',instrType='"+Values[5]+"',secCode='"+Values[6]+\
> "',SEDOL='"+Values[7]+"',Date='"+Values[8]+"',SuspendedState='"+Values[9]+\
> "',bidPrice='"+Values[10]+"',offerPrice='"+Values[11]+"',midPrice='"+Values[12]+\
> "',standardMarketSize='"+Values[13]+"',openOrClosed='"+Values[14]+\
> "' WHERE secBoardId='"+Values[0]+"'"
> cursor.execute(longstring)
>
> should instead look more like this:
> cursor.execute('UPDATE SecB SET
> (?,?,?,?,?,?,?,?,?,?,?,?,?,?)',tuple(Values[1:])) ?
>
Closer. It really needs to be more like
cursor.execute("""UPDATE SecB
SET currencyCode=?, issuerName=?, instrName=?,
...
openOrClosed=?
WHERE secBoardId=?""", data)
In this case, since the secBoardID is used as the last parameter, data
really needs to be se at
data = tuple(Values[1:] + Values[:1])
But of course it would probably be easier to assemble Values in the
right order in the first place. You will still need to turn it into a
tuple, however, for cursor.execute().
> The Elements list was from a time when it looked less pretty than it does
> now, where I iterated through it and didn't catch errors at all.
>
> Thank you again for your help and when it's finished and working I'll repost
> it online somewhere for ideas on how to optimise it slightly more!
> Dominic
>
Good one!
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
More information about the Python-list
mailing list