From: stan l. <st...@ya...> - 2004-07-31 19:47:46
|
--- Erik Thiele <er...@th...> wrote: > On Wed, 21 Jul 2004 17:04:45 +0200 > Erik Thiele <er...@th...> wrote: > > > hi. > > > > i am using > > > > - gentoo linux. > > - sybase-0.36 > > - freetds-0.62.3 > > - python 2.3.3 > > > > from this linux machine i am accessing a mssql 7 > server on an nt4.0 > > windows server. > > > > i am doing > > > > > db=Sybase.connect('myserver','myuser','mypass','mydb') > > c=db.cursor() > > c.execute('select * from foo where something=@x', > {'@x' : "blabla"}) > > > > it sais: > > > > Sybase.DatabaseError: ------ > > Must declare the variable '@x' > > > > ??? i do not understand. why is this so? > > > > i am trying to use python DB API 2.0. but i find > the documentation for > > this not very sufficient. there seems to be no > good example at all on > > the net. > > > > questions never covered and done wrong in almost > all examples is the > > issue with escaping the datatypes. some really do > > c.execute("select from where x="%s"" % mystring) > > this is of course fatal since mystring may contain > closing " and then > > sql commands. > > > > anyway... how do i get the module to work? > > hmmmm. still i have no working example. > > there is this python-sybase module and i cannot get > it to work. there > must be something wrong here. Could you give me a > query that runs on the > above configuration? i want to create the query > dynamically. i.e. no > static query, but instead some query like the one > above. > > is the python-sybase module broken? > > > -- > Erik Thiele > _______________________________________________ > Python-sybase mailing list > Pyt...@ww... > https://www.object-craft.com.au/cgi-bin/mailman/listinfo/python-sybase > Hi, I haven't had reason to use python to call Sybase on linux, but have used it to call Sybase on Win XP (at work). The equivalent to what you write above would be: import odi import odbc # order is important, not sure this is it db=odbc.connect('myserver'/'myuser'/'mypass') c=db.cursor() c.execute('select * from foo where something=?', ("blabla",)) results = c.fetchall() In windows, the link to the odbc driver for myserver is defined in a dialog, and the odbc call automatically invokes the correct link. I would think there should be a configuration file for linux that does the same. Probably somewhere in /etc or the home directory. Note that the variable substitution occurs from a tuple to the variables. Here there is only one, but more would be filled from the tuple in the order they occur in the query. The tuple is usually populated using variables so that the query changes depending on the values assigned to them. I have had no troubles with this except when there was a small error in win32py, which Mark fixed quickly. Hope this helps. stan __________________________________ Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail |