[DB-SIG] DataError: ('22005', 0, '[Microsoft][ODBC SQL Server Driver]

Khawaja-Shahzad Butt kshahzadbutt at gmail.com
Mon Oct 18 14:37:35 CEST 2004


Hi,
      When i am connecting to SQL Server through mxODBC as system DSN.

db = mx.ODBC.Windows.DriverConnect('DSN=zoe;UID=test;PWD=temp')
c = db.cursor()
When i use this SQL query, it gives me this error

 q="""INSERT INTO rss_feed_items(
   item_date,
   item_title,
   item_author,
   item_permalink,             
   item_description)
    VALUES(
     ?, ?, ?, ?, ?)"""
c.execute(q,(item_dmodified,feed_item_title,item_author,feed_item_link,feed_item_feeddescription),)

    db.commit()

I get this weird error.

raceback (most recent call last):
  File "C:\Python23\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\feedparser-3.3\feedparser\test.py", line 561, in ?
    info_extract(data,url);
  File "C:\feedparser-3.3\feedparser\test.py", line 41, in info_extract
    rss_20extraction(result,url)
  File "C:\feedparser-3.3\feedparser\test.py", line 312, in rss_20extraction
    dbinsertfeeditem(feed_item_title,feed_item_link,item_author,feed_item_feeddescription,item_dmodified)
  File "C:\feedparser-3.3\feedparser\test.py", line 417, in dbinsertfeeditem
    c.execute(q,(item_dmodified,feed_item_title,item_author,feed_item_link,feed_item_feeddescription),)
DataError: ('22005', 0, '[Microsoft][ODBC SQL Server Driver]Invalid
character value for cast specification', 4579)


I know the query works if use it like a string but all the fields in
the table are not strings. e.g.

    q = "insert into
rss_feed_items(item_date,item_title,item_author,item_permalink,item_description)\
    values('%s','%s','%s','%s','%s')" %
(item_dmodified,feed_item_title,item_author,feed_item_link,feed_item_feeddescription)

Then i have encoded into utf-8 otherwise pythong gives error that the
query string should be string. something like that.

q=q.encode("utf-8");

 db.commit()

So what should i do. I have looked around and didn't see any solution
for this problem.Please help. I would be grateful.
Regards
Shahzad


More information about the DB-SIG mailing list