From: Erik T. <er...@th...> - 2004-07-22 08:05:02
|
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? and... why is there several styles in DB API 2.0? i mean the Sybase.paramstyle thing. i thought DB API was there for portability, and then i find out that different modules have different ways to create sql queries. so there is absolute zero portability. why? thx & byebye Erik -- Erik Thiele |
From: Dave C. <dj...@ob...> - 2004-07-23 21:19:32
|
Erik Thiele 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? FreeTDS has historically had problems with named parameters. Are you able to test the same query using the Perl bindings to FreeTDS? > and... why is there several styles in DB API 2.0? i mean the Sybase.paramstyle > thing. i thought DB API was there for portability, and then i find out > that different modules have different ways to create sql queries. so there > is absolute zero portability. why? You will have to ask the database vendors that one. - Dave -- http://www.object-craft.com.au |
From: Erik T. <er...@th...> - 2004-07-23 23:57:05
|
On Fri, 23 Jul 2004 14:19:32 +1000 Dave Cole <dj...@ob...> wrote: > Erik Thiele wrote: >=20 > > and... why is there several styles in DB API 2.0? i mean the > > Sybase.paramstyle thing. i thought DB API was there for portability, > > and then i find out that different modules have different ways to > > create sql queries. so there is absolute zero portability. why? >=20 > You will have to ask the database vendors that one. ah! so it's a problem with the database? i thought that this parameter substitution thing was an issue of the DB API and every python database driver programmer just decides which one to use. so that's not true! actually there should be a wrapper function on top of DB API that can transform one single paramstyle into all the others. or is there a technical reason why that's not possible? anyway once you maybe answer this question i will make a suggestion to python DB guys to add this to the FAQ. i tried to figure out why this is so for just too long time. also that FAQ entry must point out why there is no wrapper, or where it is :) thx! erik --=20 Erik Thiele Horst Thiele Maschinenbau-Hydraulische Ger=E4te GmbH Im Kampfrad 2 - 74196 Neuenstadt Tel.: 07139/4801-19 Fax.: 07139/4801-29 email: er...@th... Internet: http://www.thiele-hydraulik.de/ |
From: Skip M. <sk...@po...> - 2004-07-24 06:21:43
|
>> and... why is there several styles in DB API 2.0? i mean the >> Sybase.paramstyle thing. i thought DB API was there for portability, >> and then i find out that different modules have different ways to >> create sql queries. so there is absolute zero portability. why? Dave> You will have to ask the database vendors that one. Assuming all the possible substitution styles are equivalent (I've seen "%s" and "?" as placeholders as well as the dict style the python-sybase module supports), I think the DB API could have specified one style then required implementers to map from it to the native library's style. That might have been a PITA for some, but should be possible you'd think. DB API 3.0 anyone? Skip |
From: Erik T. <er...@th...> - 2004-07-24 06:49:47
|
On Fri, 23 Jul 2004 14:19:32 +1000 Dave Cole <dj...@ob...> wrote: > Erik Thiele wrote: > > hi. > > > > > > 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? > > FreeTDS has historically had problems with named parameters. Are you > able to test the same query using the Perl bindings to FreeTDS? i am using mxODBC, there it works. but not named parameters. it uses this ?-parameter thing, like all ODBC it sais. it seems like freetds has problems with timestamp columns. it returns them as hex data. datetime works. The term "timestamp" and "datetime" is what the SQL Enterprise Manager on SQL Server 7.0 on WinNT sais to be the datatype of the columns. i'm so confused :-) now i have a working mxODBC with broken mssql-timestamp and i have a working sybase python module with broken parameter passing and broken mssql-timestamp also. so maybe the timestamp thing really is a freetds issue. help! regards erik -- Erik Thiele |
From: Dave C. <dj...@ob...> - 2004-07-24 00:07:56
|
Erik Thiele wrote: > On Fri, 23 Jul 2004 14:19:32 +1000 > Dave Cole <dj...@ob...> wrote: > > >>Erik Thiele wrote: >> >> >>>and... why is there several styles in DB API 2.0? i mean the >>>Sybase.paramstyle thing. i thought DB API was there for portability, >>>and then i find out that different modules have different ways to >>>create sql queries. so there is absolute zero portability. why? >> >>You will have to ask the database vendors that one. > > > ah! so it's a problem with the database? i thought that this parameter > substitution thing was an issue of the DB API and every python database > driver programmer just decides which one to use. so that's not true! > actually there should be a wrapper function on top of DB API that can > transform one single paramstyle into all the others. or is there a > technical reason why that's not possible? anyway once you maybe answer > this question i will make a suggestion to python DB guys to add this to > the FAQ. i tried to figure out why this is so for just too long time. > also that FAQ entry must point out why there is no wrapper, or where it > is :) I am not sure that it is that simple for all databases. If at all possible it is a good idea to pass binary parameters to the server and let the binding of parameters to the SQL occur at the server. Unfortunately each database vendor has decided upon different parameter placeholders. Some databases do not support parameter passing so the client side must format the arguments into the SQL query sent to the server. It might be a good idea if some very clever person developed a bullet-proof SQL query formatter that worked for all SQL variants. Then the DB-API would just need to include formatters for native database types that could yield strings to be used by the formatter. Who knows - this might have already been done. - Dave -- http://www.object-craft.com.au |
From: Erik T. <er...@th...> - 2004-07-24 02:40:57
|
On Fri, 23 Jul 2004 17:07:55 +1000 Dave Cole <dj...@ob...> wrote: > Erik Thiele wrote: > > On Fri, 23 Jul 2004 14:19:32 +1000 > > Dave Cole <dj...@ob...> wrote: > > > > > >>Erik Thiele wrote: > >> > >> > >>>and... why is there several styles in DB API 2.0? i mean the > >>>Sybase.paramstyle thing. i thought DB API was there for > >portability,>>and then i find out that different modules have > >different ways to>>create sql queries. so there is absolute zero > >portability. why?> > >>You will have to ask the database vendors that one. > > > > > > ah! so it's a problem with the database? i thought that this > > parameter substitution thing was an issue of the DB API and every > > python database driver programmer just decides which one to use. so > > that's not true! actually there should be a wrapper function on top > > of DB API that can transform one single paramstyle into all the > > others. or is there a technical reason why that's not possible? > > anyway once you maybe answer this question i will make a suggestion > > to python DB guys to add this to the FAQ. i tried to figure out why > > this is so for just too long time. also that FAQ entry must point > > out why there is no wrapper, or where it is :) > > I am not sure that it is that simple for all databases. If at all > possible it is a good idea to pass binary parameters to the server and > > let the binding of parameters to the SQL occur at the server. > Unfortunately each database vendor has decided upon different > parameter placeholders. Some databases do not support parameter > passing so the client side must format the arguments into the SQL > query sent to the server. > > It might be a good idea if some very clever person developed a > bullet-proof SQL query formatter that worked for all SQL variants. > Then the DB-API would just need to include formatters for native > database types that could yield strings to be used by the formatter. > Who knows - this might have already been done. it would be the ultimate step in the direction of database independency if there was only one paramstyle left. then the DB-API wins over the other APIS finally. until now i have to do some assertion that the paramstyle is correct, otherwise the program does not run. i cannot quite understand why they didn't include it from the beginning. i don't see a big problem in writing a function that converts the query in one paramstyle into a query of another paramstyle. Am i missing something? -- Erik Thiele |
From: Erik T. <er...@th...> - 2004-07-24 06:49:47
|
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 |
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 |