tag:blogger.com,1999:blog-11802292.post116278798289076007..comments2023-10-16T03:31:20.095-07:00Comments on Catherine: pyOraGeek: TurboGears and OracleAnonymoushttp://www.blogger.com/profile/12229578427522022392noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-11802292.post-54367007463733863472007-06-22T14:42:00.000-07:002007-06-22T14:42:00.000-07:00Thanks Catherine : a great jumpstart for myself. I...Thanks Catherine : a great jumpstart for myself. I have 13 years Oracle experience as an Oracle DBA but I haven't done very much in the way of development. I'll post now and then to inform you of my progress as a Turbogears newbie if that's OK.Unknownhttps://www.blogger.com/profile/13480870714367501097noreply@blogger.comtag:blogger.com,1999:blog-11802292.post-89489649782862719642007-04-25T15:12:00.000-07:002007-04-25T15:12:00.000-07:00I got it!In your dev.cfg (or prod.cfg, or whatever...I got it!<BR/><BR/>In your dev.cfg (or prod.cfg, or whatever), try setting<BR/><BR/>sqlalchemy.convert_unicode=True<BR/><BR/>I suspect that I have the problem because I didn't set up my Oracle database to handle unicode. TG handles all strings as unicode, so it needs to be converted before it can be shipped up to Oracle.<BR/><BR/>See <A HREF="http://www.sqlalchemy.org/docs/dbengine.html" REL="nofollow">http://www.sqlalchemy.org/docs/dbengine.html</A><BR/><BR/>and<BR/><BR/>http://trac.turbogears.org/ticket/1215<BR/><BR/>which mentions the (otherwise undocumented, AFAIK) fact that you can pass "extra" parameters to SQLAlchemy's create_engine call by using sqlalchemy.<I>parameter</I> in your .cfg file.Anonymoushttps://www.blogger.com/profile/12229578427522022392noreply@blogger.comtag:blogger.com,1999:blog-11802292.post-11141081507568754242007-04-25T14:49:00.000-07:002007-04-25T14:49:00.000-07:00Ravi,Hmm... good question! It's not so simple aft...Ravi,<BR/><BR/>Hmm... good question! It's not so simple after all... it seems to trace down to cx_Oracle itself.<BR/><BR/>If you execute SQL through a cx_Oracle cursor that includes bind variables, and have a unicode value in the dictionary of bind variables, you get precisely this error, even with TurboGears nowhere in sight.<BR/><BR/>curs.execute('SELECT * FROM dual WHERE dummy = :dum', {'dum':u'X'})<BR/><BR/>cx_Oracle.NotSupportedError: Variable_TypeByValue(): unhandled data type unicode<BR/><BR/>I think the reason you can insert successfully separately from TG is that, when you do it by hand, you're using ordinary strings, not unicode ones. Replace your<BR/><BR/>>>> v_name='Ravi Kasibhatla'<BR/><BR/>with<BR/><BR/>>>> v_name=u'Ravi Kasibhatla'<BR/><BR/>and you'll see the error. <BR/><BR/>I'm still working on this. Stay tuned...Anonymoushttps://www.blogger.com/profile/12229578427522022392noreply@blogger.comtag:blogger.com,1999:blog-11802292.post-23041265737021821872007-04-25T10:12:00.000-07:002007-04-25T10:12:00.000-07:00Catherine,Thats just great the job with SA+TG+Orac...Catherine,<BR/><BR/>Thats just great the job with SA+TG+Oracle. A new alternative for the J2EE stuff.<BR/><BR/>But I have got stuck with a pretty simple problem. If you can help me out I would be thankful to you.<BR/><BR/>I have configured Turbogears and created a quick-start web site with<BR/>SQL Alchemy as the database modeler. The kid template pages where I<BR/>showed some data from the database are working perfectly. But the part<BR/>of the controller where I am trying to do an INSERT into a table of my<BR/>oracle database using the values of the bind variables of a remote<BR/>form that I have shown, is not working.<BR/><BR/>Apparently there is some problem with the UNICODE data that sqlAlchemy<BR/>sends to oracle from the turbo gears framework. But I have tried the<BR/>same from the python command line with named parameters and its works<BR/>without any issues.<BR/><BR/>I furnish below all the code parts related to the issue and any kind<BR/>help is appreciated.<BR/><BR/>Regards<BR/><BR/>Ravi<BR/><BR/>--- FROM TURBOGEARS ---<BR/>The method in the controller which is in-charge of doing the INSERT<BR/>into the database using the received parameters<BR/><BR/>def add(self, _name, _email, _text, _somedate, *args):<BR/> #ins_comment = model.comments_table.insert().execute(name="Ravi",<BR/>email="kap_r...@hotmail.com", text="Some Text") ---> This worked 100%<BR/>inserting the row into the table.<BR/><BR/> print _name, _email, _text, _somedate ---> This prints the values<BR/>correclty<BR/><BR/> ins_comment = model.comments_table.insert().execute(email=_email,<BR/>name=_name, text=_text) ---> This is not doing the insert into the<BR/>oracle table correctly but throwing the following error.<BR/><BR/>SQLError: (NotSupportedError) Variable_TypeByValue(): unhandled data<BR/>type unicode 'INSERT INTO comments (email, name, text) VALUES<BR/>(:email, :name, :text)' {'text': u'This is a comment', 'email':<BR/>u'kap_r...@hotmail.com', 'name': u'Ravi'}<BR/><BR/>--- FROM PYTHON CLI ---<BR/><BR/>Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]<BR/>on win32<BR/>Type "help", "copyright", "credits" or "license" for more information.<BR/>>>> from sqlalchemy import *<BR/>>>> db = create_engine('oracle://scott:tigress@xe')<BR/>>>> metadata = BoundMetaData(db)<BR/>>>> comments_table = Table("comments", metadata, autoload=True)<BR/>>>> v_email='kap_r...@hotmail.com'<BR/>>>> v_name='Ravi Kasibhatla'<BR/>>>> v_text='This is a comment from Python CLI'<BR/>>>> ins = comments_table.insert()<BR/>>>> ins.execute(email=v_email, name=v_name, text=v_text)<BR/><BR/>sqlalchemy.engine.base.ResultProxy object at 0x00D503D0<BR/>>>> sel = comments_table.select()<BR/>>>> rows = sel.execute()<BR/>>>> print rows.fetchall()<BR/><BR/>[('kap_r...@hotmail.com', 'Ravi Kasibhatla', 'This is a comment from<BR/>Python CLI', datetime.datetime(2007, 4, 25, 11, 24, 13))]<BR/><BR/> AS YOU CAN SEE, THE INSERT WAS SUCCESSFULRavi Kasibhatlahttps://www.blogger.com/profile/14265588223858219456noreply@blogger.comtag:blogger.com,1999:blog-11802292.post-1164098740728509302006-11-21T00:45:00.000-08:002006-11-21T00:45:00.000-08:00hey catherine -im glad to see you working with SA ...hey catherine -<BR/><BR/>im glad to see you working with SA (also thanks for the oracle patch, ill have a look at that soon)...and you are correct that SA is a little more "database centric" than the typical scripting language database tool. while im mainly a developer, i have about 5 years of oracle experience, and database-centric types and DBAs are definitely one of my "target audiences" I hope to attract to Python.<BR/><BR/>so thanks for the interest and keep the suggestions coming....<BR/><BR/>- mikemike bayerhttps://www.blogger.com/profile/01417862951114999907noreply@blogger.com