[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-db-sig
Subject:    [DB-SIG] DataError: ('22005', 0,	'[Microsoft][ODBC SQL Server
From:       marcos () burke ! ath ! cx (=?ISO-8859-1?Q?Marcos_S=E1nchez_Provencio?=)
Date:       2004-10-18 16:02:29
Message-ID: 4173CC53.9080505 () burke ! ath ! cx
[Download RAW message or body]

You may try to convert each of the strings you want to insert into UTF8
before using them in the query. For example, if the string that contains
non-ascii chars is feed_item_feeddescription:

feed_item_feeddescription_utf8=feed_item_feeddescription.encode('utf8')
c.execute(q,(item_dmodified,feed_item_title,item_author,feed_item_link,feed_item_feeddescription_utf8),)




Khawaja-Shahzad Butt escribi?:

> 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
> 
> 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic