From jekabs.andrusaitis@tietoenator.com Sat Aug 10 19:32:48 2002 From: jekabs.andrusaitis@tietoenator.com (Jekabs Andrushaitis) Date: Sat, 10 Aug 2002 20:32:48 +0200 Subject: [DB-SIG] Which db mapping tool? In-Reply-To: <5.1.0.14.0.20020724105226.02941cf0@pop.viawest.net> Message-ID: <000601c2409c$547980c0$262a949f@konts.lv> Basically there are alot of events that could trigger the change of rowid for the record, since rowid is a reference to the physical data block in the tablespace of the said table row. It can even change if the row is updated - Oracle might decide to move the row physically around without you even knowing it. Although accessing records by using rowid is the fastest possible way, using unique indexes is not much slower. Jekabs Andrushaitis Senior system analyst TietoEnator Financial Solutions 41 Lacplesa Str. Riga, LV-1011, Latvia Tel: +371 7286660 Fax: +371 7243000 E-mail: jekabs.andrusaitis@tietoenator.com From rtheiss@yahoo.com Tue Aug 13 21:25:28 2002 From: rtheiss@yahoo.com (Robert Theiss) Date: Tue, 13 Aug 2002 13:25:28 -0700 (PDT) Subject: [DB-SIG] Help With Cursors Message-ID: <20020813202528.6635.qmail@web10411.mail.yahoo.com> I am trying to fetch a small number of rows into a cursor, using informixdb.py. I get the following error on the fetchall statement when executing the code: Exception type: InformixdbError Exception value: Error 0 performing FETCH: Null value eliminated in set function The relevant code looks like this: SqlSelectStatement = """ select loc_nbr, inv_loc_nbr, txn_type, txn_code, txn_reason, NVL(txn_from_disp, 'NONE'), NVL(txn_to_disp, 'NONE'), sum(qty_txn), sum((qty_txn*avg_cost)) from inv_audit where inv_loc_nbr = %i and txn_datet >= '2002-07-01 00:00' and txn_datet < '2002-08-01 00:00' group by loc_nbr, inv_loc_nbr, txn_type, txn_code, txn_reason, txn_from_disp, txn_to_disp; """ % EomInvLocNbr try: db.execute('set isolation dirty read;') except db.error: exc_type, exc_value = sys.exc_info()[:2] ExceptionHandler(exc_type, exc_value, DataFile, LogFile, db) print "dirty read set " try: db.cursor() db.execute(SqlSelectStatement) except db.error: exc_type, exc_value = sys.exc_info()[:2] ExceptionHandler(exc_type, exc_value, DataFile, LogFile, db) print "select done " try: TransactionList = [] TransactionList = db.fetchall() except db.error: exc_type, exc_value = sys.exc_info()[:2] ExceptionHandler(exc_type, exc_value, DataFile, LogFile, db) for record in TransactionList: InvAudLocNbr = record[0] InvAudInvLocNbr = record[1] InvAudTxnType = record[2] InvAudTxnCode = record[3] InvAudTxnReason = record[4] InvAudTxnFrom = record[5] InvAudTxnTo = record[6] InvAudQty = record[7] InvAudAvgCost = record[8] In the above code, the problem seems to be in the fields txn_from_disp and txn_to_disp. Either of these fields could be null. When I take them out of the select statement, the program works like a charm. >From researching other message threads, it appears that fetchall() should handle NULL values, but my code obviously does not. Any help is appreciated. Regards, Bob Theiss __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com From msanchez@grupoburke.com Tue Aug 13 22:16:33 2002 From: msanchez@grupoburke.com (Marcos =?ISO-8859-1?Q?S=E1nchez?= Provencio) Date: 13 Aug 2002 23:16:33 +0200 Subject: [DB-SIG] Help With Cursors In-Reply-To: <20020813202528.6635.qmail@web10411.mail.yahoo.com> References: <20020813202528.6635.qmail@web10411.mail.yahoo.com> Message-ID: <1029273394.1165.5.camel@renata.macondo.pri> The problem lies in the SQL layer. Your query seems to be unorthodox when asking for operations on NULL values. You would get the same answer from a isql/sqlplus/psql/whatever the minimal interface for informix is. This might do as reference: http://www.devx.com/upload/free/features/vbpj/2002/04apr02/jf0402/jf0402-3.= asp El mar, 13-08-2002 a las 22:25, Robert Theiss escribi=F3: > I am trying to fetch a small number of rows into a > cursor, using informixdb.py. I get the following > error on the fetchall statement when executing the > code: >=20 > Exception type: InformixdbError > Exception value: Error 0 performing FETCH: Null value > eliminated in set function >=20 > The relevant code looks like this: >=20 > SqlSelectStatement =3D """ > select =20 > loc_nbr, > inv_loc_nbr, > txn_type,=20 > txn_code, > txn_reason, > NVL(txn_from_disp, 'NONE'), > NVL(txn_to_disp, 'NONE'), > sum(qty_txn), > sum((qty_txn*avg_cost)) > from > inv_audit > where > inv_loc_nbr =3D %i and > txn_datet >=3D '2002-07-01 00:00' and > txn_datet < '2002-08-01 00:00'=20 > group by=20 > loc_nbr, > inv_loc_nbr, > txn_type, > txn_code, > txn_reason, > txn_from_disp, > txn_to_disp; > """ % EomInvLocNbr=20 > try: > db.execute('set isolation dirty read;') > except db.error: > exc_type, exc_value =3D sys.exc_info()[:2] > ExceptionHandler(exc_type, exc_value, DataFile, > LogFile, db) > print "dirty read set "=20 >=20 > try: > db.cursor() =20 > db.execute(SqlSelectStatement) > except db.error: > exc_type, exc_value =3D sys.exc_info()[:2] > ExceptionHandler(exc_type, exc_value, DataFile, > LogFile, db) > print "select done " =20 >=20 > try: > TransactionList =3D [] =20 > TransactionList =3D db.fetchall() > except db.error: > exc_type, exc_value =3D sys.exc_info()[:2] > ExceptionHandler(exc_type, exc_value, DataFile, > LogFile, db) >=20 > for record in TransactionList: > InvAudLocNbr =3D record[0] > InvAudInvLocNbr =3D record[1] > InvAudTxnType =3D record[2] > InvAudTxnCode =3D record[3] > InvAudTxnReason =3D record[4] > InvAudTxnFrom =3D record[5]=20 > InvAudTxnTo =3D record[6] > InvAudQty =3D record[7]=20 > InvAudAvgCost =3D record[8]=20 >=20 > In the above code, the problem seems to be in the > fields txn_from_disp and txn_to_disp. Either of these > fields could be null. When I take them out of the > select statement, the program works like a charm. >=20 > >From researching other message threads, it appears > that fetchall() should handle NULL values, but my code > obviously does not. >=20 > Any help is appreciated. >=20 > Regards, >=20 > Bob Theiss =20 >=20 > __________________________________________________ > Do You Yahoo!? > HotJobs - Search Thousands of New Jobs > http://www.hotjobs.com >=20 > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig From rtheiss@yahoo.com Wed Aug 14 13:46:13 2002 From: rtheiss@yahoo.com (Robert Theiss) Date: Wed, 14 Aug 2002 05:46:13 -0700 (PDT) Subject: [DB-SIG] Help With Cursors In-Reply-To: <1029273394.1165.5.camel@renata.macondo.pri> Message-ID: <20020814124613.81005.qmail@web10407.mail.yahoo.com> I don't believe the problem is in the SQL layer. when I run the query (as written) via ISQL, it works. I can also run the same query through MS-Access using an ODBC connection to informix. Sorry I didn't make that clear in the original message. That's one of the reasons I think the error is in the fetchall statement. In addition, I know that the select statement runs successfully in my Python script form looking at the return code. The fetchall is where it is failing. I'll check the reference you sent as well. Thanks for the help. Begards, Bob --- Marcos Sánchez Provencio wrote: > The problem lies in the SQL layer. Your query seems > to be unorthodox > when asking for operations on NULL values. You would > get the same answer > from a isql/sqlplus/psql/whatever the minimal > interface for informix is. > > This might do as reference: > http://www.devx.com/upload/free/features/vbpj/2002/04apr02/jf0402/jf0402-3.asp > > El mar, 13-08-2002 a las 22:25, Robert Theiss > escribió: > > I am trying to fetch a small number of rows into a > > cursor, using informixdb.py. I get the following > > error on the fetchall statement when executing the > > code: > > > > Exception type: InformixdbError > > Exception value: Error 0 performing FETCH: Null > value > > eliminated in set function > > > > The relevant code looks like this: > > > > SqlSelectStatement = """ > > select > > loc_nbr, > > inv_loc_nbr, > > txn_type, > > txn_code, > > txn_reason, > > NVL(txn_from_disp, 'NONE'), > > NVL(txn_to_disp, 'NONE'), > > sum(qty_txn), > > sum((qty_txn*avg_cost)) > > from > > inv_audit > > where > > inv_loc_nbr = %i and > > txn_datet >= '2002-07-01 00:00' and > > txn_datet < '2002-08-01 00:00' > > group by > > loc_nbr, > > inv_loc_nbr, > > txn_type, > > txn_code, > > txn_reason, > > txn_from_disp, > > txn_to_disp; > > """ % EomInvLocNbr > > try: > > db.execute('set isolation dirty read;') > > except db.error: > > exc_type, exc_value = sys.exc_info()[:2] > > ExceptionHandler(exc_type, exc_value, > DataFile, > > LogFile, db) > > print "dirty read set " > > > > try: > > db.cursor() > > db.execute(SqlSelectStatement) > > except db.error: > > exc_type, exc_value = sys.exc_info()[:2] > > ExceptionHandler(exc_type, exc_value, > DataFile, > > LogFile, db) > > print "select done " > > > > try: > > TransactionList = [] > > TransactionList = db.fetchall() > > except db.error: > > exc_type, exc_value = sys.exc_info()[:2] > > ExceptionHandler(exc_type, exc_value, > DataFile, > > LogFile, db) > > > > for record in TransactionList: > > InvAudLocNbr = record[0] > > InvAudInvLocNbr = record[1] > > InvAudTxnType = record[2] > > InvAudTxnCode = record[3] > > InvAudTxnReason = record[4] > > InvAudTxnFrom = record[5] > > InvAudTxnTo = record[6] > > InvAudQty = record[7] > > InvAudAvgCost = record[8] > > > > In the above code, the problem seems to be in the > > fields txn_from_disp and txn_to_disp. Either of > these > > fields could be null. When I take them out of the > > select statement, the program works like a charm. > > > > >From researching other message threads, it > appears > > that fetchall() should handle NULL values, but my > code > > obviously does not. > > > > Any help is appreciated. > > > > Regards, > > > > Bob Theiss > > > > __________________________________________________ > > Do You Yahoo!? > > HotJobs - Search Thousands of New Jobs > > http://www.hotjobs.com > > > > _______________________________________________ > > DB-SIG maillist - DB-SIG@python.org > > http://mail.python.org/mailman/listinfo/db-sig > > __________________________________________________ Do You Yahoo!? HotJobs - Search Thousands of New Jobs http://www.hotjobs.com From fcoutant@freesurf.fr Wed Aug 14 15:12:01 2002 From: fcoutant@freesurf.fr (Fabien COUTANT) Date: Wed, 14 Aug 2002 16:12:01 +0200 Subject: [DB-SIG] Request: Standardized way to get database schema Message-ID: <1YQP71WTKMG87PN211U652ZTRMMKTO.3d5a6531@philippe> Hello, I'm currently thinking about writing a python based database schema editor, as well as thin helper classes for database <-> (Gtk) GUI interactions. I had a quick look outside, to see some approaching tools already exist, but those tools are always specific to some database (mostly MySQL/PostgreSQL). What I want is a tool that only relies on DB-API standard drivers. For my tool I need schema introspection features. Unfortunately, all databases have this feature available, but always in a specific way. I expected that DB-API would provide a standard way to access those informations, but it doesn't. Is there any reason for this ? Wouldn't it be interesting and valuable (I'm pretty sure I'm not the only one missing this feature) to work on a DB-API extension (or a new version) for this ? There is not that much information to get if you want to remain standard w.r.t SQL: - list of tables, - list of columns for each table, - list of primary/foreign keys for each table (with target table, and source and target columns) - standard characteristics of columns (type, nullable, default value) - indexes for each table -- Hope this helps, Fabien. From ramrom@earthling.net Wed Aug 14 15:26:44 2002 From: ramrom@earthling.net (Bob Gailer) Date: Wed, 14 Aug 2002 08:26:44 -0600 Subject: [DB-SIG] Spreadsheet interface? In-Reply-To: <1YQP71WTKMG87PN211U652ZTRMMKTO.3d5a6531@philippe> Message-ID: <5.1.0.14.0.20020814082406.0219cd58@pop.viawest.net> --=======AAE21C9======= Content-Type: text/plain; x-avg-checked=avg-ok-15C175ED; charset=us-ascii; format=flowed Content-Transfer-Encoding: 8bit Months ago I found a spreadsheet-like interface for browsing and editing database tables. It required Gadfly, which I downloaded and installed. Now I have forgotten the name of the interface. Do you know what it might be. (I'm interested in ANY such tool). Bob Gailer mailto:ramrom@earthling.net 303 442 2625 --=======AAE21C9=======-- From bzimmer@ziclix.com Wed Aug 14 15:38:16 2002 From: bzimmer@ziclix.com (brian zimmer) Date: Wed, 14 Aug 2002 09:38:16 -0500 Subject: [DB-SIG] Request: Standardized way to get database schema In-Reply-To: <1YQP71WTKMG87PN211U652ZTRMMKTO.3d5a6531@philippe> Message-ID: <000201c243a0$3ddf54f0$6b01a8c0@mountain> > > Wouldn't it be interesting and valuable (I'm pretty sure I'm > not the only one missing this feature) to work on a > DB-API extension (or a new version) for this ? > For what it's worth, both mxODBC and zxJDBC provide access to this information. When I wrote zxJDBC I used the same API of mxODBC to facilitate my migration. > There is not that much information to get if you want to > remain standard w.r.t SQL: > - list of tables, .tables - list all tables {getTables} > - list of columns for each table, > - standard characteristics of columns (type, nullable, default value) .columns - list the columns (with standard characteristics) {getColumns} > - list of primary/foreign keys for each table (with target > table, and source and target columns) .primarykeys {getPrimaryKeys} .foreignkeys {getCrossReference} > - indexes for each table .statistics {getIndexInfo} In addition, getting procedures is nice as well: .procedures {getProcedures} .procedurecolumns {getProcedureColumns} The method name in {} is what zxJDBC calls on the JDBC DatabaseMetaData instance to get the appropriate information. You can get more information about the parameters to each zxJDBC method from: http://jython.org/docs/zxjdbc.html (look for Standard extensions...) and for the JDBC methods from: http://java.sun.com/j2se/1.3/docs/api/java/sql/DatabaseMetaData.html hope this helps, brian From fcoutant@freesurf.fr Wed Aug 14 17:43:07 2002 From: fcoutant@freesurf.fr (Fabien COUTANT) Date: Wed, 14 Aug 2002 18:43:07 +0200 Subject: [DB-SIG] Request: Standardized way to get database schema In-Reply-To: <000201c243a0$3ddf54f0$6b01a8c0@mountain> Message-ID: <4XKHLK2UYZUXUB0SM1X06PFC622ZQP.3d5a889b@philippe> 14/08/2002 16:38:16, "brian zimmer" wrote: >For what it's worth, both mxODBC and zxJDBC provide access to this >information. When I wrote zxJDBC I used the same API of mxODBC to >facilitate my migration. [...] Thanks. What I'm looking for is a common, uniform access way, that is not specific to any database driver. -- Hope this helps, Fabien. From magnus@thinkware.se Wed Aug 14 18:11:57 2002 From: magnus@thinkware.se (Magnus Lycka) Date: Wed, 14 Aug 2002 19:11:57 +0200 Subject: [DB-SIG] Request: Standardized way to get database schema In-Reply-To: <4XKHLK2UYZUXUB0SM1X06PFC622ZQP.3d5a889b@philippe> References: <000201c243a0$3ddf54f0$6b01a8c0@mountain> Message-ID: <5.1.0.14.0.20020814190610.029e4010@www.thinkware.se> At 18:43 2002-08-14 +0200, Fabien COUTANT wrote: >14/08/2002 16:38:16, "brian zimmer" wrote: > >For what it's worth, both mxODBC and zxJDBC provide access to this > >information. >... >Thanks. What I'm looking for is a common, uniform access way, that is not >specific to any database driver. Please tell us if you find one! ;-) I suppose the somewhat too ambitious idea that the DB-API should be able to cover any row/column-oriented database makes it difficult to mandate such a standard. I think the best we can hope for would be that the approach used in mxODBC and zxJDBC was turned into an optional extension of the DB-API standard. --=20 Magnus Lyck=E5, Thinkware AB =C4lvans v=E4g 99, SE-907 50 UME=C5 tel: 070-582 80 65, fax: 070-612 80 65 http://www.thinkware.se/ mailto:magnus@thinkware.se From msanchez@grupoburke.com Thu Aug 15 08:02:39 2002 From: msanchez@grupoburke.com (Marcos =?ISO-8859-1?Q?S=E1nchez?= Provencio) Date: 15 Aug 2002 09:02:39 +0200 Subject: [DB-SIG] Request: Standardized way to get database schema In-Reply-To: <000201c243a0$3ddf54f0$6b01a8c0@mountain> References: <000201c243a0$3ddf54f0$6b01a8c0@mountain> Message-ID: <1029394959.2221.4.camel@renata.macondo.pri> Well, I think we have the draft for a standard, then. Does anybody have schema code that he/she may donate to the group to convert into this standard? El mi=E9, 14-08-2002 a las 16:38, brian zimmer escribi=F3: > >=20 > > Wouldn't it be interesting and valuable (I'm pretty sure I'm=20 > > not the only one missing this feature) to work on a=20 > > DB-API extension (or a new version) for this ? > >=20 >=20 > For what it's worth, both mxODBC and zxJDBC provide access to this > information. When I wrote zxJDBC I used the same API of mxODBC to > facilitate my migration. >=20 > > There is not that much information to get if you want to=20 > > remain standard w.r.t SQL: > > - list of tables, >=20 > .tables > - list all tables {getTables} >=20 > > - list of columns for each table, > > - standard characteristics of columns (type, nullable, default value) >=20 > .columns > - list the columns (with standard characteristics) {getColumns} >=20 > > - list of primary/foreign keys for each table (with target=20 > > table, and source and target columns) >=20 > .primarykeys {getPrimaryKeys} > .foreignkeys {getCrossReference} >=20 > > - indexes for each table >=20 > .statistics {getIndexInfo} >=20 > In addition, getting procedures is nice as well: >=20 > .procedures {getProcedures} > .procedurecolumns {getProcedureColumns} >=20 > The method name in {} is what zxJDBC calls on the JDBC DatabaseMetaData > instance to get the appropriate information. You can get more > information about the parameters to each zxJDBC method from: >=20 > http://jython.org/docs/zxjdbc.html (look for Standard extensions...) >=20 > and for the JDBC methods from: >=20 > http://java.sun.com/j2se/1.3/docs/api/java/sql/DatabaseMetaData.html >=20 > hope this helps, >=20 > brian >=20 >=20 >=20 > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig From msanchez@grupoburke.com Fri Aug 16 13:45:45 2002 From: msanchez@grupoburke.com (=?iso-8859-1?Q?Marcos_S=E1nchez_Provencio?=) Date: Fri, 16 Aug 2002 14:45:45 +0200 (CEST) Subject: [DB-SIG] Parameters in DCOracle2 Message-ID: <44691.195.53.212.39.1029501945.squirrel@www.grupoburke.com> Hello, I am having a problem trying to get some data from an Solaris Oracle 7.3.3 server. I use the 8.1.7 client in the same machine. The problem is as follows: I get results if I say where nombre='SAENS' but not if I say where nombre=:p1 and pass a parameter 'SAENS', fetchall returns an empty list It is funny that I get some results if I say where nombre between :p1 and :p1 || 'Z' or (almost) what I want by saying where nombre like :p1 || ' %' I have been puzzled by Oracle since I am using it (I had used Sybase before). Is this an Oracle issue or a Python one? Thank you very much From gwatt3@backbonesecurity.com Fri Aug 16 14:39:05 2002 From: gwatt3@backbonesecurity.com (Watt III, Glenn) Date: Fri, 16 Aug 2002 09:39:05 -0400 Subject: [DB-SIG] warning problem Message-ID: <94FD5825A793194CBF039E6673E9AFE0373F0E@bbserver1.backbonesecurity.com> Ok heres my problem i am running a cgi in which i am updating a database here it is #!/usr/local/bin/python import cgi import sys import MySQLdb # firstname (contians in order title firstname lastname) # lastname (indicates accepted paper) # title (indicates unreadpaper newpaper) # email (email) # web (web) # city (city, state or country) # state (nothing) # country (nothing) # papertitle (papertitle) # abstract (abstract) # cot (full paper) sys.stderr =3D sys.stdout connection =3D MySQLdb.Connect(host=3D"localhost",user=3D"site",passwd=3D"s1te411",db=3D= "backbo ne") cursor =3D connection.cursor() try: query =3D cgi.FieldStorage() except: print"Please run via CGI... Thank you" sys.exit(0) if query.has_key("accept"): header =3D "Content-type: text/html\n" print header print """ Hamburgerstand.com """ else: print "Well that was kind of useless you didn't even decide whether or not to accept" sys.exit(0) if query['accept'].value =3D=3D "Yes": update =3D 'update newpapers set firstname=3D"' + = query["name"].value + '"' update =3D update + ", title=3D'accepted'" if query.has_key("emial"): update =3D update + ', email=3D"'+query["email"].value+'"' if query.has_key("web"): update =3D update + ', web=3D"'+query["web"].value+'"' if query.has_key("location"): update =3D update + ', city=3D"'+query["location"].value+'"' if query.has_key("papertitle"): update =3D update + ', = papertitle=3D"'+query["papertitle"].value+'"' if query.has_key("cot"): update =3D update + ', cot=3D"'+query["cot"].value+'"' if query.has_key("subject"): x =3D int(query["subject"].value) if query.has_key("topic"): x =3D x + int(query["topic"].value) if query.has_key("ltvalue"): x =3D x + int(query["ltvalue"].value) if query.has_key("tech"): x =3D x + int(query["tech"].value) if query.has_key("prof"): x =3D x + int(query["prof"].value) if query.has_key("pres"): x =3D x + int(query["pres"].value) if query.has_key("length"): x =3D x + int(query["length"].value) x =3D x * 100 / 28 average =3D str(x) update =3D update + ', lastname=3D"'+ average +'"' update =3D update + ' where = firstname=3D"'+query["refname"].value+'";' print update cursor.execute(update) sys.exit(0) else: delete =3D 'delete from newpapers where firstname=3D"'+query["refname"].value+'";' cursor.execute(delete) sys.exit(0) It doesnt have a problem if query['accept'].value is equal to no. the im fairly new to using MySQLdb module so the problem is probobly really obvious but here is the error i get the the first three lines are just the values i used in this instance but any no matter the values i have the problems. I tried running it in IDLE to find what it would do and i got a similar error however changed =3D 1 instead of zero=20 update newpapers set firstname=3D"Mr. asdf asdf", title=3D'accepted', web=3D"mam,germdfskln", city=3D",dgl/kh h'xdkb, Bahamas", papertitle=3D"kfjtrjhmbu", cot=3D"erjgfjdlfg;sldfj asdfjasdkjfasdfemwrkj asdmfkffkfkfkfkfk awerj75kjfvvyhmhfsdauer You can contact the author at: mfkeigk", lastname=3D"100" where firstname=3D"Mr. asdf asdf"; Traceback (most recent call last): File "/var/www/backbone/admin/newdesign/papers/cgi/final.py", line 77, in ? cursor.execute(update) File "/usr/local/lib/python2.1/site-packages/MySQLdb/cursors.py", line 61, in execute r =3D self._query(query) File "/usr/local/lib/python2.1/site-packages/MySQLdb/cursors.py", line 168, in _query rowcount =3D self._BaseCursor__do_query(q) File "/usr/local/lib/python2.1/site-packages/MySQLdb/cursors.py", line 118, in __do_query self._check_for_warnings() File "/usr/local/lib/python2.1/site-packages/MySQLdb/cursors.py", line 150, in _check_for_warnings raise Warning, self._info _mysql_exceptions.Warning: Rows matched: 1 Changed: 0 Warnings: 1=20 any help would be greatly appeciate thanks! From matt@zope.com Fri Aug 16 15:12:33 2002 From: matt@zope.com (Matthew T. Kromer) Date: Fri, 16 Aug 2002 10:12:33 -0400 Subject: [DB-SIG] Parameters in DCOracle2 References: <44691.195.53.212.39.1029501945.squirrel@www.grupoburke.com> Message-ID: <3D5D0851.10805@zope.com> Marcos S=E1nchez Provencio wrote: >Hello, I am having a problem trying to get some data from an Solaris Ora= cle >7.3.3 server. I use the 8.1.7 client in the same machine. The problem is= as >follows: > >I get results if I say > > where nombre=3D'SAENS' > >but not if I say > > where nombre=3D:p1 > >and pass a parameter 'SAENS', fetchall returns an empty list > >It is funny that I get some results if I say > > where nombre between :p1 and :p1 || 'Z' > >or (almost) what I want by saying > > where nombre like :p1 || ' %' > >I have been puzzled by Oracle since I am using it (I had used Sybase bef= ore). >Is this an Oracle issue or a Python one? > >Thank you very much > > =20 > Hello Marcos, If you use named parameters (ala :p1 etc) you need to pass them in as=20 named parameters to the execute call: cursor.execute('select * from table where nombre=3D:p1', p1=3D'SAEN= S') Otherwise, you can use positional arguments cursor.execute('select * from table where nombre=3D:1', 'SAENS') --=20 Matt Kromer Zope Corporation http://www.zope.com/=20 From chris@cogdon.org Fri Aug 16 18:22:24 2002 From: chris@cogdon.org (Chris Cogdon) Date: Fri, 16 Aug 2002 10:22:24 -0700 Subject: [DB-SIG] warning problem In-Reply-To: <94FD5825A793194CBF039E6673E9AFE0373F0E@bbserver1.backbonesecurity.com> References: <94FD5825A793194CBF039E6673E9AFE0373F0E@bbserver1.backbonesecurity.com> Message-ID: <200208161022.24026.chris@cogdon.org> On Friday 16 August 2002 06:39, Watt III, Glenn wrote: > if query['accept'].value =3D=3D "Yes": > update =3D 'update newpapers set firstname=3D"' + query["name"].val= ue + > '"' > update =3D update + ", title=3D'accepted'" > if query.has_key("emial"): > update =3D update + ', email=3D"'+query["email"].value+'"' > if query.has_key("web"): > update =3D update + ', web=3D"'+query["web"].value+'"' > if query.has_key("location"): > update =3D update + ', city=3D"'+query["location"].value+'"' > if query.has_key("papertitle"): > update =3D update + ', papertitle=3D"'+query["papertitle"].valu= e+'"' [... and so on...] I know that this doesnt solve your immediate problem, but there is a 'sty= le'=20 issue here that might bite you if you're not careful. You're relying on all your input strings (eg, query["name"]) to not have = any=20 special characters in them. For example, if that value contained a quote=20 character, you'll get a mysql errror. The MySQLdb library contains an automatic quoting system, if you use it=20 properly, like this: cursor.execute ( "update newpapers set firstname=3D%s, title=3D'accepted'= ...and=20 so on", query["name"], andotherparams ) The library will automatically figure out the type of your parameters, an= d=20 quote them accordingly. The above is called the 'format' parameter method. MySQLdb also supports=20 'pyformat', which can work like this: cursor.execute ( "update newpapers set firstname=3D%(name)s, title=3D'acc= epted'=20 =2E..and so on", query ) notice how the %(name)s will automatically pull out the proper value from= a=20 dictionary, just like the % operator in python, but /dont/ actually use %= ,=20 because then you wont get the automatic quoting. Hope that's useful. --=20 ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL From andy@dustman.net Sun Aug 18 17:47:47 2002 From: andy@dustman.net (Andy Dustman) Date: 18 Aug 2002 12:47:47 -0400 Subject: [DB-SIG] warning problem In-Reply-To: <94FD5825A793194CBF039E6673E9AFE0373F0E@bbserver1.backbonesecurity.com> References: <94FD5825A793194CBF039E6673E9AFE0373F0E@bbserver1.backbonesecurity.com> Message-ID: <1029689267.4886.8.camel@4.0.0.10.in-addr.arpa> On Fri, 2002-08-16 at 09:39, Watt III, Glenn wrote: > _mysql_exceptions.Warning: Rows matched: 1 Changed: 0 Warnings: 1 > > any help would be greatly appeciate thanks! Warnings on UPDATE are almost always due to a bad type conversion or data truncation. Unfortunately MySQL itself is quite vague about what the actual problem was. Also, read PEP-249 or the MySQLdb docs for the proper use of cursor.execute(). http://www.python.org/peps/pep-0249.html -- Andy Dustman PGP: 0x930B8AB6 @ .net http://dustman.net/andy "Cogito, ergo sum." -- Rene Descartes "I yam what I yam and that's all what I yam." -- Popeye From andy@dustman.net Sun Aug 18 18:34:55 2002 From: andy@dustman.net (Andy Dustman) Date: 18 Aug 2002 13:34:55 -0400 Subject: [DB-SIG] warning problem In-Reply-To: <94FD5825A793194CBF039E6673E9AFE0373F0E@bbserver1.backbonesecurity.com> References: <94FD5825A793194CBF039E6673E9AFE0373F0E@bbserver1.backbonesecurity.com> Message-ID: <1029692095.4716.29.camel@4.0.0.10.in-addr.arpa> On Fri, 2002-08-16 at 09:39, Watt III, Glenn wrote: > Ok heres my problem i am running a cgi in which i am updating a database > here it is Here's a shorter (untested) version, which may be useful for other people on this list (or perhaps someone reading the archives before asking a question, like that'll happen). #!/usr/local/bin/python import cgi import sys import MySQLdb try: query = cgi.FieldStorage() except: print"Please run via CGI... Thank you" sys.exit(0) connection = MySQLdb.Connect(host="localhost",user="site",passwd="s1te411",db="backbone") cursor = connection.cursor() if query.has_key("accept"): header = "Content-type: text/html\n" print header print """ Hamburgerstand.com """ else: print "Well that was kind of useless you didn't even decide whether or not to accept" sys.exit(0) columns = 'firstname lastname title email web city state country ' \ 'papertitle abstract cot'.split() changes = {} if query['accept'].value == "Yes": for c in columns: if query.has_key(c): changes[c] = query[c].value placeholders = [ "%s=%%(%s)s" % (k,k) for k in changes.keys() ] stmt = "UPDATE newspapers SET %s" % placeholders else: stmt = 'delete from newpapers where firstname=%s' changes['refname'] = query["refname"].value print stmt % MySQLdb.literal(changes) cursor.execute(stmt, changes) sys.exit(0) -- Andy Dustman PGP: 0x930B8AB6 @ .net http://dustman.net/andy "Cogito, ergo sum." -- Rene Descartes "I yam what I yam and that's all what I yam." -- Popeye From msanchez@grupoburke.com Mon Aug 19 10:27:53 2002 From: msanchez@grupoburke.com (=?iso-8859-1?Q?Marcos_S=E1nchez_Provencio?=) Date: Mon, 19 Aug 2002 11:27:53 +0200 (CEST) Subject: [DB-SIG] Parameters in DCOracle2 In-Reply-To: <44691.195.53.212.39.1029501945.squirrel@www.grupoburke.com> References: <44691.195.53.212.39.1029501945.squirrel@www.grupoburke.com> Message-ID: <31046.195.53.212.39.1029749273.squirrel@www.grupoburke.com> First, thank you for your help, I have found out several new things. The value is stored in the table as 'SAENS ' with spaces, but _not_ to thefull length of the column, which is 50. So, the non-parameter query does find results, but the parametrised query only finds results when providing the exactnumber of spaces (5 in this case). I can't touch the data in the table. Is theresome way to get the same results as a SQL*Plus window? PS. I use now named parameters correctly. Thanks. > Hello, I am having a problem trying to get some data from an Solaris > Oracle 7.3.3 server. I use the 8.1.7 client in the same machine. The > problem is as follows: > > I get results if I say > > where nombre='SAENS' > > but not if I say > > where nombre=:p1 > > and pass a parameter 'SAENS', fetchall returns an empty list > > It is funny that I get some results if I say > > where nombre between :p1 and :p1 || 'Z' > > or (almost) what I want by saying > > where nombre like :p1 || ' %' > > I have been puzzled by Oracle since I am using it (I had used Sybase > before). Is this an Oracle issue or a Python one? > > Thank you very much > > > > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig From matt@zope.com Mon Aug 19 14:05:18 2002 From: matt@zope.com (Matthew T. Kromer) Date: Mon, 19 Aug 2002 09:05:18 -0400 Subject: [DB-SIG] Parameters in DCOracle2 In-Reply-To: <31046.195.53.212.39.1029749273.squirrel@www.grupoburke.com> Message-ID: <4F6EEFE4-B374-11D6-A7AB-003065488930@zope.com> I think you're really after something like cursor.execute("select * from table where RTRIM(nombre) =3D :1",=20= nombre) Although I'm away from my manual to look up RTRIM to see if you need to=20= pass it a 2nd parameter to tell it to trim trailing spaces. On Monday, August 19, 2002, at 05:27 AM, Marcos S=E1nchez Provencio = wrote: > First, thank you for your help, I have found out several new things. > > The value is stored in the table as 'SAENS ' with spaces, but = _not_=20 > to > thefull length of the column, which is 50. So, the non-parameter query=20= > does find > results, but the parametrised query only finds results when providing=20= > the > exactnumber of spaces (5 in this case). I can't touch the data in the=20= > table. Is > theresome way to get the same results as a SQL*Plus window? > > PS. I use now named parameters correctly. Thanks. > >> Hello, I am having a problem trying to get some data from an Solaris >> Oracle 7.3.3 server. I use the 8.1.7 client in the same machine. The >> problem is as follows: >> >> I get results if I say >> >> where nombre=3D'SAENS' >> >> but not if I say >> >> where nombre=3D:p1 >> >> and pass a parameter 'SAENS', fetchall returns an empty list >> >> It is funny that I get some results if I say >> >> where nombre between :p1 and :p1 || 'Z' >> >> or (almost) what I want by saying >> >> where nombre like :p1 || ' %' >> >> I have been puzzled by Oracle since I am using it (I had used Sybase >> before). Is this an Oracle issue or a Python one? >> >> Thank you very much >> >> >> >> _______________________________________________ >> DB-SIG maillist - DB-SIG@python.org >> http://mail.python.org/mailman/listinfo/db-sig > > > > > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig From anthony@computronix.com Mon Aug 19 17:22:02 2002 From: anthony@computronix.com (Anthony Tuininga) Date: 19 Aug 2002 10:22:02 -0600 Subject: [DB-SIG] cx_Oracle 2.5a Message-ID: <1029774127.28898.55.camel@chl0151.edmonton.computronix.com> What is cx_Oracle? cx_Oracle is a Python extension module that allows access to Oracle and conforms to the Python database API 2.0 specifications with a few exceptions. Where do I get it? http://computronix.com/utilities What's new? A problem was discovered with Oracle 9i when retrieving strings. It seems that Oracle 9i uses the correct method for dynamic callback but Oracle 8i will not work with the correct method so an #ifdef was added to check for the existence of an Oracle 9i specific feature. Thanks to Paul Denize for discovering this problem and working with me to get a solution. I have provided Oracle 9i specific binaries for Windows and Linux. DO NOT use the Oracle 8i specific binaries in Oracle 9i as they will not work. -- Anthony Tuininga anthony@computronix.com Computronix Distinctive Software. Real People. Suite 200, 10216 - 124 Street NW Edmonton, AB, Canada T5N 4A3 Phone: (780) 454-3700 Fax: (780) 454-3838 http://www.computronix.com From msanchez@grupoburke.com Mon Aug 19 17:51:18 2002 From: msanchez@grupoburke.com (Marcos =?ISO-8859-1?Q?S=E1nchez?= Provencio) Date: 19 Aug 2002 18:51:18 +0200 Subject: [DB-SIG] cx_Oracle 2.5a In-Reply-To: <1029774127.28898.55.camel@chl0151.edmonton.computronix.com> References: <1029774127.28898.55.camel@chl0151.edmonton.computronix.com> Message-ID: <1029775878.4850.13.camel@renata.macondo.pri> Thank you for working for all of us, I'll try that tomorrow. What are the main differences from DCoracle2 to cx_Oracle? El lun, 19-08-2002 a las 18:22, Anthony Tuininga escribi=F3: > What is cx_Oracle? >=20 > cx_Oracle is a Python extension module that allows access to Oracle and > conforms to the Python database API 2.0 specifications with a few > exceptions. >=20 >=20 > Where do I get it? >=20 > http://computronix.com/utilities >=20 >=20 > What's new? >=20 > A problem was discovered with Oracle 9i when retrieving strings. It > seems that Oracle 9i uses the correct method for dynamic callback but > Oracle 8i will not work with the correct method so an #ifdef was added > to check for the existence of an Oracle 9i specific feature. Thanks to > Paul Denize for discovering this problem and working with me to get a > solution. I have provided Oracle 9i specific binaries for Windows and > Linux. DO NOT use the Oracle 8i specific binaries in Oracle 9i as they > will not work. >=20 > --=20 > Anthony Tuininga > anthony@computronix.com > =20 > Computronix > Distinctive Software. Real People. > Suite 200, 10216 - 124 Street NW > Edmonton, AB, Canada T5N 4A3 > Phone: (780) 454-3700 > Fax: (780) 454-3838 > http://www.computronix.com >=20 >=20 > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig From anthony@computronix.com Mon Aug 19 18:19:38 2002 From: anthony@computronix.com (Anthony Tuininga) Date: 19 Aug 2002 11:19:38 -0600 Subject: [DB-SIG] cx_Oracle 2.5a In-Reply-To: <1029775878.4850.13.camel@renata.macondo.pri> References: <1029775878.4850.13.camel@renata.macondo.pri> Message-ID: <1029777582.29748.5.camel@chl0151.edmonton.computronix.com> A really good question.... :-) Perhaps someone who develops (or uses extensively) the DCOracle2 module can state something similar to what is below. cx_Oracle follows the DB API 2.0 standards rigorously. If there are any known exceptions (now, as of 2.5), I would consider that a bug. There are a number of extensions which make working with Oracle possible and a number of extensions which are used exclusively for performance reasons. None of the extensions are required to get work done with the module. cx_Oracle uses named format argument passing exclusively. I believe that DCOracle2 uses both named and positional arguments. On Mon, 2002-08-19 at 10:51, Marcos S=E1nchez Provencio wrote: > Thank you for working for all of us, I'll try that tomorrow. What are > the main differences from DCoracle2 to cx_Oracle? >=20 > El lun, 19-08-2002 a las 18:22, Anthony Tuininga escribi=F3: > > What is cx_Oracle? > >=20 > > cx_Oracle is a Python extension module that allows access to Oracle > and > > conforms to the Python database API 2.0 specifications with a few > > exceptions. > >=20 > >=20 > > Where do I get it? > >=20 > > http://computronix.com/utilities > >=20 > >=20 > > What's new? > >=20 > > A problem was discovered with Oracle 9i when retrieving strings. It > > seems that Oracle 9i uses the correct method for dynamic callback but > > Oracle 8i will not work with the correct method so an #ifdef was added > > to check for the existence of an Oracle 9i specific feature. Thanks to > > Paul Denize for discovering this problem and working with me to get a > > solution. I have provided Oracle 9i specific binaries for Windows and > > Linux. DO NOT use the Oracle 8i specific binaries in Oracle 9i as they > > will not work. > >=20 > > --=20 > > Anthony Tuininga > > anthony@computronix.com > > =20 > > Computronix > > Distinctive Software. Real People. > > Suite 200, 10216 - 124 Street NW > > Edmonton, AB, Canada T5N 4A3 > > Phone: (780) 454-3700 > > Fax: (780) 454-3838 > > http://www.computronix.com > >=20 > >=20 > > _______________________________________________ > > DB-SIG maillist - DB-SIG@python.org > > http://mail.python.org/mailman/listinfo/db-sig >=20 --=20 Anthony Tuininga anthony@computronix.com =20 Computronix Distinctive Software. Real People. Suite 200, 10216 - 124 Street NW Edmonton, AB, Canada T5N 4A3 Phone: (780) 454-3700 Fax: (780) 454-3838 http://www.computronix.com From msanchez@grupoburke.com Mon Aug 19 19:04:36 2002 From: msanchez@grupoburke.com (Marcos =?ISO-8859-1?Q?S=E1nchez?= Provencio) Date: 19 Aug 2002 20:04:36 +0200 Subject: [DB-SIG] Parameters in DCOracle2 In-Reply-To: <4F6EEFE4-B374-11D6-A7AB-003065488930@zope.com> References: <4F6EEFE4-B374-11D6-A7AB-003065488930@zope.com> Message-ID: <1029780276.9577.0.camel@renata.macondo.pri> I expect this to break index usage, I suppose... El lun, 19-08-2002 a las 15:05, Matthew T. Kromer escribi=F3: > I think you're really after something like >=20 > cursor.execute("select * from table where RTRIM(nombre) =3D :1",=20 > nombre) >=20 > Although I'm away from my manual to look up RTRIM to see if you need to=20 > pass it a 2nd parameter to tell it to trim trailing spaces. >=20 >=20 > On Monday, August 19, 2002, at 05:27 AM, Marcos S=E1nchez Provencio wrote= : >=20 > > First, thank you for your help, I have found out several new things. > > > > The value is stored in the table as 'SAENS ' with spaces, but _not_= =20 > > to > > thefull length of the column, which is 50. So, the non-parameter query=20 > > does find > > results, but the parametrised query only finds results when providing=20 > > the > > exactnumber of spaces (5 in this case). I can't touch the data in the=20 > > table. Is > > theresome way to get the same results as a SQL*Plus window? > > > > PS. I use now named parameters correctly. Thanks. > > > >> Hello, I am having a problem trying to get some data from an Solaris > >> Oracle 7.3.3 server. I use the 8.1.7 client in the same machine. The > >> problem is as follows: > >> > >> I get results if I say > >> > >> where nombre=3D'SAENS' > >> > >> but not if I say > >> > >> where nombre=3D:p1 > >> > >> and pass a parameter 'SAENS', fetchall returns an empty list > >> > >> It is funny that I get some results if I say > >> > >> where nombre between :p1 and :p1 || 'Z' > >> > >> or (almost) what I want by saying > >> > >> where nombre like :p1 || ' %' > >> > >> I have been puzzled by Oracle since I am using it (I had used Sybase > >> before). Is this an Oracle issue or a Python one? > >> > >> Thank you very much > >> > >> > >> > >> _______________________________________________ > >> DB-SIG maillist - DB-SIG@python.org > >> http://mail.python.org/mailman/listinfo/db-sig > > > > > > > > > > _______________________________________________ > > DB-SIG maillist - DB-SIG@python.org > > http://mail.python.org/mailman/listinfo/db-sig >=20 >=20 > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig From chris@cogdon.org Mon Aug 19 22:15:24 2002 From: chris@cogdon.org (Chris Cogdon) Date: Mon, 19 Aug 2002 14:15:24 -0700 Subject: [DB-SIG] format vs pyformat Message-ID: <200208191415.24603.chris@cogdon.org> In all my database coding to date, I've been using the 'format' parameter= =20 passing protocol to get my stuff into the database query. However, I keep= =20 reading and hearing that 'pyformat' is by far superior. However, whenever= =20 I've 'given it a go', it's always seemed far clunkier to me. For example, for pyformat to work, all your variables have to be in a=20 dictionary already. Yes, this can be reasonably easy to set up. Viz: cur.execute ( "select * from people where name ilike %(name)s and=20 age>%(age)s", =09{ 'name':criteria.name, 'age':criteria.age } ) But I still find it much easier to use the positional parameters. Viz: cur.execute ( "select * from people where name ilike %s and age > %s", =09criteria.name, criteria.age ) The above is a simple example... the disparity between the two protocols=20 becomes greater with greater complexity. I understand it's possible to pa= ss a=20 dictionary from a pre-existing namespace. Viz: cur.execute ( "select * from people where name ilike %(name)s and=20 age>%(age)s", =09criteria.__dict__ ) But this assumes that the values to be passed are already pre-calculated,= or=20 you'll need to find 'temporary' space for them so you can throw them into= the=20 dictionary. pyformat also allows reuse of parameters, but I've seen this = used=20 too seldom to make it a big plus. To me, 'format' parameter passing still seems a lot easier to use, but th= ere's=20 quite a few DB connectors that support 'pyformat' over 'format': For exam= ple,=20 PoPy only supports pyformat, while pyPgSQL supports both format and pyfor= mat. Am I completely missing some 'neat trick' here that would make pyformat=20 magically easy?=20 What are other people's views on the ease of using the two formats ? Thanks in advance. --=20 ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL From TKeating@origin.ea.com Mon Aug 19 22:23:55 2002 From: TKeating@origin.ea.com (Keating, Tim) Date: Mon, 19 Aug 2002 16:23:55 -0500 Subject: [DB-SIG] format vs pyformat Message-ID: <9B8090A2F0EBDB4ABD59B08E81C1A6842F62A7@osi-postal.osi.ad.ea.com> Am I missing something? Aren't you constructing a string and passing it in either way? Why would the database adapter care how it was formatted? In any case, dictionary-based formatting isn't nearly as ugly if you already have the data in a dictionary and don't have to construct an anonymous one to pass to the format operator. This might seem like a pain, but I suggest you look at the vars() built-in function and consider the possibilities . . . -----Original Message----- From: Chris Cogdon [mailto:chris@cogdon.org] Sent: Monday, August 19, 2002 4:15 PM To: db-sig@python.org Subject: [DB-SIG] format vs pyformat In all my database coding to date, I've been using the 'format' parameter passing protocol to get my stuff into the database query. However, I keep reading and hearing that 'pyformat' is by far superior. However, whenever I've 'given it a go', it's always seemed far clunkier to me. For example, for pyformat to work, all your variables have to be in a dictionary already. Yes, this can be reasonably easy to set up. Viz: cur.execute ( "select * from people where name ilike %(name)s and age>%(age)s", { 'name':criteria.name, 'age':criteria.age } ) But I still find it much easier to use the positional parameters. Viz: cur.execute ( "select * from people where name ilike %s and age > %s", criteria.name, criteria.age ) The above is a simple example... the disparity between the two protocols becomes greater with greater complexity. I understand it's possible to pass a dictionary from a pre-existing namespace. Viz: cur.execute ( "select * from people where name ilike %(name)s and age>%(age)s", criteria.__dict__ ) But this assumes that the values to be passed are already pre-calculated, or you'll need to find 'temporary' space for them so you can throw them into the dictionary. pyformat also allows reuse of parameters, but I've seen this used too seldom to make it a big plus. To me, 'format' parameter passing still seems a lot easier to use, but there's quite a few DB connectors that support 'pyformat' over 'format': For example, PoPy only supports pyformat, while pyPgSQL supports both format and pyformat. Am I completely missing some 'neat trick' here that would make pyformat magically easy? What are other people's views on the ease of using the two formats ? Thanks in advance. -- ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL _______________________________________________ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig From TKeating@origin.ea.com Mon Aug 19 22:33:39 2002 From: TKeating@origin.ea.com (Keating, Tim) Date: Mon, 19 Aug 2002 16:33:39 -0500 Subject: [DB-SIG] format vs pyformat Message-ID: <9B8090A2F0EBDB4ABD59B08E81C1A6842F62A8@osi-postal.osi.ad.ea.com> For that matter (is it vain to reply to yourself?), I'm pretty sure you could just implement __getattr__() for the criteria class type in the example below, then pass the critera class instance as the formatting argument. That solves your issue with "dictionary entries" being pre-calculated. -----Original Message----- From: Keating, Tim [mailto:TKeating@origin.ea.com] Sent: Monday, August 19, 2002 4:24 PM To: 'Chris Cogdon'; db-sig@python.org Subject: RE: [DB-SIG] format vs pyformat Am I missing something? Aren't you constructing a string and passing it in either way? Why would the database adapter care how it was formatted? In any case, dictionary-based formatting isn't nearly as ugly if you already have the data in a dictionary and don't have to construct an anonymous one to pass to the format operator. This might seem like a pain, but I suggest you look at the vars() built-in function and consider the possibilities . . . -----Original Message----- From: Chris Cogdon [mailto:chris@cogdon.org] Sent: Monday, August 19, 2002 4:15 PM To: db-sig@python.org Subject: [DB-SIG] format vs pyformat In all my database coding to date, I've been using the 'format' parameter passing protocol to get my stuff into the database query. However, I keep reading and hearing that 'pyformat' is by far superior. However, whenever I've 'given it a go', it's always seemed far clunkier to me. For example, for pyformat to work, all your variables have to be in a dictionary already. Yes, this can be reasonably easy to set up. Viz: cur.execute ( "select * from people where name ilike %(name)s and age>%(age)s", { 'name':criteria.name, 'age':criteria.age } ) But I still find it much easier to use the positional parameters. Viz: cur.execute ( "select * from people where name ilike %s and age > %s", criteria.name, criteria.age ) The above is a simple example... the disparity between the two protocols becomes greater with greater complexity. I understand it's possible to pass a dictionary from a pre-existing namespace. Viz: cur.execute ( "select * from people where name ilike %(name)s and age>%(age)s", criteria.__dict__ ) But this assumes that the values to be passed are already pre-calculated, or you'll need to find 'temporary' space for them so you can throw them into the dictionary. pyformat also allows reuse of parameters, but I've seen this used too seldom to make it a big plus. To me, 'format' parameter passing still seems a lot easier to use, but there's quite a few DB connectors that support 'pyformat' over 'format': For example, PoPy only supports pyformat, while pyPgSQL supports both format and pyformat. Am I completely missing some 'neat trick' here that would make pyformat magically easy? What are other people's views on the ease of using the two formats ? Thanks in advance. -- ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL _______________________________________________ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig _______________________________________________ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig From chris@cogdon.org Mon Aug 19 22:52:46 2002 From: chris@cogdon.org (Chris Cogdon) Date: Mon, 19 Aug 2002 14:52:46 -0700 Subject: [DB-SIG] format vs pyformat In-Reply-To: <9B8090A2F0EBDB4ABD59B08E81C1A6842F62A7@osi-postal.osi.ad.ea.com> References: <9B8090A2F0EBDB4ABD59B08E81C1A6842F62A7@osi-postal.osi.ad.ea.com> Message-ID: <200208191452.46721.chris@cogdon.org> On Monday 19 August 2002 14:23, Keating, Tim wrote: > Am I missing something? Aren't you constructing a string and passing it= in > either way? Why would the database adapter care how it was formatted? One isn't 'supposed to' construct the whole string yourself. If you pass=20 arguments to the execute method, the adaptor will do all the value quotin= g=20 for you. For example: cur.execute ( "select * from person where name ilike '%s'" % name ) wont always work, especially if 'name' contains characters special to the= SQL=20 syntax. And: cur.execute ( "select * from person where name ilike %r" % name ) won't work either, as the SQL quoting rules aren't the same as python's. = Sure,=20 I could do: cur.execute ( "select * from person where name ilike '%s'" % dblib.quote(= name)=20 ) to explicitly call the quoting routine, but this is hardly an elegant=20 solution. The current protocol, to specify the quotable values as argumen= ts=20 to the execute method, is much neater: cur.execute ( "select * from person where name ilike %s", name ) > In any case, dictionary-based formatting isn't nearly as ugly if you > already have the data in a dictionary and don't have to construct an > anonymous one to pass to the format operator. This might seem like a pa= in, > but I suggest you look at the vars() built-in function and consider the > possibilities . . . It's rare that the values you want to pass to the formatter are handily i= n a=20 dictionary already. vars() is neat, but it means that you need to put all your values into lo= cal=20 variables before calling execute. Viz: cur.execute ( "update person set thingy=3D%s", counter+1 ) becomes: newcounter =3D counter + 1 cur.execute ( "update person set thingy=3D%(newcounter)s", vars() ) In this example, 'format' parameter passing is by far shorter and neater. --=20 ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL From chris@cogdon.org Mon Aug 19 23:21:37 2002 From: chris@cogdon.org (Chris Cogdon) Date: Mon, 19 Aug 2002 15:21:37 -0700 Subject: [DB-SIG] format vs pyformat In-Reply-To: <9B8090A2F0EBDB4ABD59B08E81C1A6842F62A8@osi-postal.osi.ad.ea.com> References: <9B8090A2F0EBDB4ABD59B08E81C1A6842F62A8@osi-postal.osi.ad.ea.com> Message-ID: <200208191521.37788.chris@cogdon.org> On Monday 19 August 2002 14:33, Keating, Tim wrote: > For that matter (is it vain to reply to yourself?), I'm pretty sure you > could just implement __getattr__() for the criteria class type in the > example below, then pass the critera class instance as the formatting > argument. That solves your issue with "dictionary entries" being > pre-calculated. Unless the values I want to pass need to be calculated :) A private conversation with Anthony Tuininga has raised this important is= sue,=20 though: As the number of parameters increase, it becomes increasingly diffcult t= o=20 keep accurate track of which positional parameter is being inserted into=20 which part of the query string. Anthony's term was 'doing a mental zip()'= =2E I've had no problem with this to date (perhaps I have a large buffer in t= he=20 wetware ;) but I can certainly see how it would /become/ a problem at som= e=20 point. Hmm... perhaps there's no easy, neat solution to this problem, and what w= e=20 have IS what's optimal. --=20 ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL From James.Briggs@unisuper.com.au Tue Aug 20 01:12:02 2002 From: James.Briggs@unisuper.com.au (James Briggs) Date: Tue, 20 Aug 2002 10:12:02 +1000 Subject: [DB-SIG] Parameters in DCOracle2 Message-ID: To avoid breaking the index usage, you could try: cursor.execute("select * from table where nombre like :1||'%'", = nombre) Of course you still have to test the nombre you now have is "SAENS" with = optional trailing spaces and not "SAENSA", but at least your using the = database index to only fetch the rows that possible match. I guess the = ugliness of the extra code is the price for having trailing spaces in the = database... buena suerte James >>> Marcos S=E1nchez Provencio 20/08/2002 = 4:04:36 am >>> I expect this to break index usage, I suppose... El lun, 19-08-2002 a las 15:05, Matthew T. Kromer escribi=F3: > I think you're really after something like >=20 > cursor.execute("select * from table where RTRIM(nombre) =3D = :1",=20 > nombre) >=20 > Although I'm away from my manual to look up RTRIM to see if you need = to=20 > pass it a 2nd parameter to tell it to trim trailing spaces. >=20 >=20 > On Monday, August 19, 2002, at 05:27 AM, Marcos S=E1nchez Provencio = wrote: >=20 > > First, thank you for your help, I have found out several new things. > > > > The value is stored in the table as 'SAENS ' with spaces, but = _not_=20 > > to > > thefull length of the column, which is 50. So, the non-parameter = query=20 > > does find > > results, but the parametrised query only finds results when = providing=20 > > the > > exactnumber of spaces (5 in this case). I can't touch the data in = the=20 > > table. Is > > theresome way to get the same results as a SQL*Plus window? > > > > PS. I use now named parameters correctly. Thanks. > > > >> Hello, I am having a problem trying to get some data from an Solaris > >> Oracle 7.3.3 server. I use the 8.1.7 client in the same machine. The > >> problem is as follows: > >> > >> I get results if I say > >> > >> where nombre=3D'SAENS' > >> > >> but not if I say > >> > >> where nombre=3D:p1 > >> > >> and pass a parameter 'SAENS', fetchall returns an empty list > >> > >> It is funny that I get some results if I say > >> > >> where nombre between :p1 and :p1 || 'Z' > >> > >> or (almost) what I want by saying > >> > >> where nombre like :p1 || ' %' > >> > >> I have been puzzled by Oracle since I am using it (I had used Sybase > >> before). Is this an Oracle issue or a Python one? > >> > >> Thank you very much > >> > >> > >> > >> _______________________________________________ > >> DB-SIG maillist - DB-SIG@python.org=20 > >> http://mail.python.org/mailman/listinfo/db-sig=20 > > > > > > > > > > _______________________________________________ > > DB-SIG maillist - DB-SIG@python.org=20 > > http://mail.python.org/mailman/listinfo/db-sig=20 >=20 >=20 > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org=20 > http://mail.python.org/mailman/listinfo/db-sig=20 _______________________________________________ DB-SIG maillist - DB-SIG@python.org=20 http://mail.python.org/mailman/listinfo/db-sig From msanchez@grupoburke.com Tue Aug 20 20:41:35 2002 From: msanchez@grupoburke.com (Marcos =?ISO-8859-1?Q?S=E1nchez?= Provencio) Date: 20 Aug 2002 21:41:35 +0200 Subject: [DB-SIG] Parameters in DCOracle2 In-Reply-To: References: Message-ID: <1029872495.1745.20.camel@sake> Thank you, really, but it must be a political question of mine not to do that. I refuse to have a system that is so costly to do everything in the program then. Why does the system return different results using exactly the same string as a parameter and as a constant string? select * from tb where fd1=3D'SAENS' [returns rows] select * from tb where fd1=3D:1 //// 'SAENS' [returns nothing] What are the _real_ advantages of using Oracle versus Sybase? I find it full of little nasty things that make it impossible to work fluently. El mar, 20-08-2002 a las 02:12, James Briggs escribi=F3: >=20 > To avoid breaking the index usage, you could try: >=20 > cursor.execute("select * from table where nombre like :1||'%'", nomb= re) >=20 Or between :1 and :1 || ' ' but I still don't like it... > Of course you still have to test the nombre you now have is "SAENS" with = optional trailing spaces and not "SAENSA", but at least your using the data= base index to only fetch the rows that possible match. I guess the ugliness= of the extra code is the price for having trailing spaces in the database.= .. >=20 > buena suerte >=20 Hasta la vista > James >=20 > >>> Marcos S=E1nchez Provencio 20/08/2002 4:04:= 36 am >>> > I expect this to break index usage, I suppose... >=20 > El lun, 19-08-2002 a las 15:05, Matthew T. Kromer escribi=F3: > > I think you're really after something like > >=20 > > cursor.execute("select * from table where RTRIM(nombre) =3D :1",=20 > > nombre) > >=20 > > Although I'm away from my manual to look up RTRIM to see if you need to= =20 > > pass it a 2nd parameter to tell it to trim trailing spaces. > >=20 > >=20 > > On Monday, August 19, 2002, at 05:27 AM, Marcos S=E1nchez Provencio wro= te: > >=20 > > > First, thank you for your help, I have found out several new things. > > > > > > The value is stored in the table as 'SAENS ' with spaces, but _no= t_=20 > > > to > > > thefull length of the column, which is 50. So, the non-parameter quer= y=20 > > > does find > > > results, but the parametrised query only finds results when providing= =20 > > > the > > > exactnumber of spaces (5 in this case). I can't touch the data in the= =20 > > > table. Is > > > theresome way to get the same results as a SQL*Plus window? > > > > > > PS. I use now named parameters correctly. Thanks. > > > > > >> Hello, I am having a problem trying to get some data from an Solaris > > >> Oracle 7.3.3 server. I use the 8.1.7 client in the same machine. The > > >> problem is as follows: > > >> > > >> I get results if I say > > >> > > >> where nombre=3D'SAENS' > > >> > > >> but not if I say > > >> > > >> where nombre=3D:p1 > > >> > > >> and pass a parameter 'SAENS', fetchall returns an empty list > > >> > > >> It is funny that I get some results if I say > > >> > > >> where nombre between :p1 and :p1 || 'Z' > > >> > > >> or (almost) what I want by saying > > >> > > >> where nombre like :p1 || ' %' > > >> > > >> I have been puzzled by Oracle since I am using it (I had used Sybase > > >> before). Is this an Oracle issue or a Python one? > > >> > > >> Thank you very much > > >> > > >> > > >> > > >> _______________________________________________ > > >> DB-SIG maillist - DB-SIG@python.org=20 > > >> http://mail.python.org/mailman/listinfo/db-sig=20 > > > > > > > > > > > > > > > _______________________________________________ > > > DB-SIG maillist - DB-SIG@python.org=20 > > > http://mail.python.org/mailman/listinfo/db-sig=20 > >=20 > >=20 > > _______________________________________________ > > DB-SIG maillist - DB-SIG@python.org=20 > > http://mail.python.org/mailman/listinfo/db-sig=20 >=20 >=20 >=20 > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org=20 > http://mail.python.org/mailman/listinfo/db-sig From anthony@computronix.com Tue Aug 20 20:07:56 2002 From: anthony@computronix.com (Anthony Tuininga) Date: 20 Aug 2002 13:07:56 -0600 Subject: [DB-SIG] Parameters in DCOracle2 In-Reply-To: <1029872495.1745.20.camel@sake> References: <1029872495.1745.20.camel@sake> Message-ID: <1029870477.31445.44.camel@chl0151.edmonton.computronix.com> Would you mind posting your table definition? I am suspecting that you are using "char" as a data type rather than "varchar2" which is what Oracle recommends. If you use "char", strange things start to happen because Oracle will convert some arguments to "varchar2" automatically and others it won't. The internal representation of the "char" data type includes spaces, unfortunately, so you have to match perfectly or have Oracle do some implicit conversion for you or do your own explicit conversion. Why not just use "varchar2" and have done with it!!? On Tue, 2002-08-20 at 13:41, Marcos S=E1nchez Provencio wrote: > Thank you, really, but it must be a political question of mine not to do > that. I refuse to have a system that is so costly to do everything in > the program then. Why does the system return different results using > exactly the same string as a parameter and as a constant string? >=20 > select * from tb where fd1=3D'SAENS' > [returns rows] >=20 > select * from tb where fd1=3D:1 //// 'SAENS' > [returns nothing] >=20 > What are the _real_ advantages of using Oracle versus Sybase? I find it > full of little nasty things that make it impossible to work fluently. >=20 > El mar, 20-08-2002 a las 02:12, James Briggs escribi=F3: > >=20 > > To avoid breaking the index usage, you could try: > >=20 > > cursor.execute("select * from table where nombre like :1||'%'", > nombre) > >=20 >=20 > Or > between :1 and :1 || ' ' > but I still don't like it... > > Of course you still have to test the nombre you now have is "SAENS" > with optional trailing spaces and not "SAENSA", but at least your using > the database index to only fetch the rows that possible match. I guess > the ugliness of the extra code is the price for having trailing spaces > in the database... > >=20 > > buena suerte > >=20 > Hasta la vista >=20 > > James > >=20 > > >>> Marcos S=E1nchez Provencio 20/08/2002 > 4:04:36 am >>> > > I expect this to break index usage, I suppose... > >=20 > > El lun, 19-08-2002 a las 15:05, Matthew T. Kromer escribi=F3: > > > I think you're really after something like > > >=20 > > > cursor.execute("select * from table where RTRIM(nombre) =3D :1"= , >=20 > > > nombre) > > >=20 > > > Although I'm away from my manual to look up RTRIM to see if you need > to=20 > > > pass it a 2nd parameter to tell it to trim trailing spaces. > > >=20 > > >=20 > > > On Monday, August 19, 2002, at 05:27 AM, Marcos S=E1nchez Provencio > wrote: > > >=20 > > > > First, thank you for your help, I have found out several new > things. > > > > > > > > The value is stored in the table as 'SAENS ' with spaces, but > _not_=20 > > > > to > > > > thefull length of the column, which is 50. So, the non-parameter > query=20 > > > > does find > > > > results, but the parametrised query only finds results when > providing=20 > > > > the > > > > exactnumber of spaces (5 in this case). I can't touch the data in > the=20 > > > > table. Is > > > > theresome way to get the same results as a SQL*Plus window? > > > > > > > > PS. I use now named parameters correctly. Thanks. > > > > > > > >> Hello, I am having a problem trying to get some data from an > Solaris > > > >> Oracle 7.3.3 server. I use the 8.1.7 client in the same machine. > The > > > >> problem is as follows: > > > >> > > > >> I get results if I say > > > >> > > > >> where nombre=3D'SAENS' > > > >> > > > >> but not if I say > > > >> > > > >> where nombre=3D:p1 > > > >> > > > >> and pass a parameter 'SAENS', fetchall returns an empty list > > > >> > > > >> It is funny that I get some results if I say > > > >> > > > >> where nombre between :p1 and :p1 || 'Z' > > > >> > > > >> or (almost) what I want by saying > > > >> > > > >> where nombre like :p1 || ' %' > > > >> > > > >> I have been puzzled by Oracle since I am using it (I had used > Sybase > > > >> before). Is this an Oracle issue or a Python one? > > > >> > > > >> Thank you very much > > > >> > > > >> > > > >> > > > >> _______________________________________________ > > > >> DB-SIG maillist - DB-SIG@python.org=20 > > > >> http://mail.python.org/mailman/listinfo/db-sig=20 > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > DB-SIG maillist - DB-SIG@python.org=20 > > > > http://mail.python.org/mailman/listinfo/db-sig=20 > > >=20 > > >=20 > > > _______________________________________________ > > > DB-SIG maillist - DB-SIG@python.org=20 > > > http://mail.python.org/mailman/listinfo/db-sig=20 > >=20 > >=20 > >=20 > > _______________________________________________ > > DB-SIG maillist - DB-SIG@python.org=20 > > http://mail.python.org/mailman/listinfo/db-sig >=20 >=20 >=20 > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig --=20 Anthony Tuininga anthony@computronix.com =20 Computronix Distinctive Software. Real People. Suite 200, 10216 - 124 Street NW Edmonton, AB, Canada T5N 4A3 Phone: (780) 454-3700 Fax: (780) 454-3838 http://www.computronix.com From James.Briggs@unisuper.com.au Wed Aug 21 00:55:31 2002 From: James.Briggs@unisuper.com.au (James Briggs) Date: Wed, 21 Aug 2002 09:55:31 +1000 Subject: [DB-SIG] Parameters in DCOracle2 Message-ID: >From the first example I see fd1 in tb must be defined as a CHAR type. This is valid point, CHAR and VARCHAR behave differently in Oracle. You = should consider CHAR to be a fixed length string with trailing spaces = attached. All comparisons are done by attaching trailing spaces to = constant strings (which is why example 1 below returns rows). All selects = with DCOracle2 Bind variables in the DCOracle2 interface (and everyother = Oracle interface I have tried) convert strings to VARCHARs which when = compared with a CHAR produce these weird results. As an oracle DBA I always craete tables with VARCHARs because of these = issues and the fact that VARCHARs don't store all those extra spaces on = disk somewhere, important when there are millions of rows. CHARs are = really for backward compatability and situations where fix length strings = are necessary. Options: 1) Convert your CHAR columns to VARCHAR2 columns in the database (recommend= ed by Oracle, but politically unacceptable I think...) 2) Dynamically recreate all selects using string manipulation, inefficient = as it involves a lot of string manipulation and re-parsing in Oracle. But = the comparisons are now done with Oracle literals and will now work as = expected. 3) Tweak or Force DCOracle2, or the interface of your choic,e to convert = string bind variables to CHAR datatypes not VARCHAR datatypes, using = DCOracle2.TypeCoercion??? Not sure this is possible, I haven't had access = to a database to test this yet. I do know in the C layer it is possible to = define arrays to be mapped to the CHAR type... Onto your question regarding Sybase and Oracle, my background is Oracle, = but I am pretty sure both can work well and have their quirks. Oracle's = biggest advantages probably come with third-party tools available(?), huge = databases, table partitioning, and running on Unix clusters etc. There = heaps of quirks and options when it comes to setting up your database, = which is why it can run on a PC upto multi-terabyte machines. This is what = keeps me in work ;)=20 James >>> Anthony Tuininga 21/08/2002 5:07:56 am >>> Would you mind posting your table definition? I am suspecting that you are using "char" as a data type rather than "varchar2" which is what Oracle recommends. If you use "char", strange things start to happen because Oracle will convert some arguments to "varchar2" automatically and others it won't. The internal representation of the "char" data type includes spaces, unfortunately, so you have to match perfectly or have Oracle do some implicit conversion for you or do your own explicit conversion. Why not just use "varchar2" and have done with it!!? On Tue, 2002-08-20 at 13:41, Marcos S=E1nchez Provencio wrote: > Thank you, really, but it must be a political question of mine not to do > that. I refuse to have a system that is so costly to do everything in > the program then. Why does the system return different results using > exactly the same string as a parameter and as a constant string? >=20 > select * from tb where fd1=3D'SAENS' > [returns rows] >=20 > select * from tb where fd1=3D:1 //// 'SAENS' > [returns nothing] >=20 > What are the _real_ advantages of using Oracle versus Sybase? I find it > full of little nasty things that make it impossible to work fluently. >=20 > El mar, 20-08-2002 a las 02:12, James Briggs escribi=F3: > >=20 > > To avoid breaking the index usage, you could try: > >=20 > > cursor.execute("select * from table where nombre like :1||'%'", > nombre) > >=20 >=20 > Or > between :1 and :1 || ' ' > but I still don't like it... > > Of course you still have to test the nombre you now have is "SAENS" > with optional trailing spaces and not "SAENSA", but at least your using > the database index to only fetch the rows that possible match. I guess > the ugliness of the extra code is the price for having trailing spaces > in the database... > >=20 > > buena suerte > >=20 > Hasta la vista >=20 > > James > >=20 > > >>> Marcos S=E1nchez Provencio 20/08/2002 > 4:04:36 am >>> > > I expect this to break index usage, I suppose... > >=20 > > El lun, 19-08-2002 a las 15:05, Matthew T. Kromer escribi=F3: > > > I think you're really after something like > > >=20 > > > cursor.execute("select * from table where RTRIM(nombre) =3D = :1", >=20 > > > nombre) > > >=20 > > > Although I'm away from my manual to look up RTRIM to see if you need > to=20 > > > pass it a 2nd parameter to tell it to trim trailing spaces. > > >=20 > > >=20 > > > On Monday, August 19, 2002, at 05:27 AM, Marcos S=E1nchez Provencio > wrote: > > >=20 > > > > First, thank you for your help, I have found out several new > things. > > > > > > > > The value is stored in the table as 'SAENS ' with spaces, but > _not_=20 > > > > to > > > > thefull length of the column, which is 50. So, the non-parameter > query=20 > > > > does find > > > > results, but the parametrised query only finds results when > providing=20 > > > > the > > > > exactnumber of spaces (5 in this case). I can't touch the data in > the=20 > > > > table. Is > > > > theresome way to get the same results as a SQL*Plus window? > > > > > > > > PS. I use now named parameters correctly. Thanks. > > > > > > > >> Hello, I am having a problem trying to get some data from an > Solaris > > > >> Oracle 7.3.3 server. I use the 8.1.7 client in the same machine. > The > > > >> problem is as follows: > > > >> > > > >> I get results if I say > > > >> > > > >> where nombre=3D'SAENS' > > > >> > > > >> but not if I say > > > >> > > > >> where nombre=3D:p1 > > > >> > > > >> and pass a parameter 'SAENS', fetchall returns an empty list > > > >> > > > >> It is funny that I get some results if I say > > > >> > > > >> where nombre between :p1 and :p1 || 'Z' > > > >> > > > >> or (almost) what I want by saying > > > >> > > > >> where nombre like :p1 || ' %' > > > >> > > > >> I have been puzzled by Oracle since I am using it (I had used > Sybase > > > >> before). Is this an Oracle issue or a Python one? > > > >> > > > >> Thank you very much > > > >> > > > >> > > > >> > > > >> _______________________________________________ > > > >> DB-SIG maillist - DB-SIG@python.org=20 > > > >> http://mail.python.org/mailman/listinfo/db-sig=20 > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > DB-SIG maillist - DB-SIG@python.org=20 > > > > http://mail.python.org/mailman/listinfo/db-sig=20 > > >=20 > > >=20 > > > _______________________________________________ > > > DB-SIG maillist - DB-SIG@python.org=20 > > > http://mail.python.org/mailman/listinfo/db-sig=20 > >=20 > >=20 > >=20 > > _______________________________________________ > > DB-SIG maillist - DB-SIG@python.org=20 > > http://mail.python.org/mailman/listinfo/db-sig=20 >=20 >=20 >=20 > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org=20 > http://mail.python.org/mailman/listinfo/db-sig=20 --=20 Anthony Tuininga anthony@computronix.com=20 =20 Computronix Distinctive Software. Real People. Suite 200, 10216 - 124 Street NW Edmonton, AB, Canada T5N 4A3 Phone: (780) 454-3700 Fax: (780) 454-3838 http://www.computronix.com=20 From fcoutant@freesurf.fr Wed Aug 21 07:28:47 2002 From: fcoutant@freesurf.fr (Fabien COUTANT) Date: Wed, 21 Aug 2002 08:28:47 +0200 (CEST) Subject: [DB-SIG] Proposal: Standardized way to get database schema Message-ID: <34576.194.250.98.243.1029911327.squirrel@jose.freesurf.fr> ------=_20020821082847_52611 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Hello, I want to go on the idea of standardizing the way to introspect a database schema. Following the suggestion from Marcos Sanchez Provencio, I wrote a suggestion for an API extension that provides schema introspection. What I did: - tried to conform to the current spirit of the API. - took some ideas from Brian Zimmer - directly modified HTML since it's the only document I have. - am not sure whether multi-schema support should be kept, since there is otherwise no support for it in the rest of the API. - the parts about primary/foreign keys, procedures and indexes are incomplete. I just gave the idea. - not sure of the exact list of SQL kinds that should be included. I don't remember the standard perfectly... I hope this can be a starting point, as there is some work remaining. NB: Since I have wrapping problems with my webmail, I have to include the diff as a MIME attachment. Sorry for the inconvenience. -- Hope this helps, Fabien. ------=_20020821082847_52611 Content-Type: application/octet-stream; name="DatabaseAPI-2.0.html.patch" Content-Disposition: attachment; filename="DatabaseAPI-2.0.html.patch" Content-Transfer-Encoding: base64 LS0tIERhdGFiYXNlQVBJLTIuMC5odG1sCVdlZCBBdWcgMjEgMDg6MTU6MTMgMjAwMgorKysgRGF0 YWJhc2VBUEktMi4xLmh0bWwJV2VkIEF1ZyAyMSAwODoxNToxNCAyMDAyCkBAIC05MCw2ICs5MCw3 IEBACiAgICAgICA8TEk+IDxBIEhSRUY9IiNtb2R1bGUiPk1vZHVsZSBJbnRlcmZhY2U8L0E+CiAg ICAgICA8TEk+IDxBIEhSRUY9IiNjb25uZWN0aW9uIj5Db25uZWN0aW9uIE9iamVjdHM8L0E+CiAg ICAgICA8TEk+IDxBIEhSRUY9IiNjdXJzb3IiPkN1cnNvciBPYmplY3RzPC9BPgorICAgICAgPExJ PiA8QSBIUkVGPSIjc2NoZW1hIj5TY2hlbWEgT2JqZWN0czwvQT4KICAgICAgIDxMST4gPEEgSFJF Rj0iI3R5cGVzIj5UeXBlIE9iamVjdHMgYW5kIENvbnN0cnVjdG9yczwvQT4KICAgICAgIDxMST4g PEEgSFJFRj0iI2hpbnRzIj5JbXBsZW1lbnRhdGlvbiBIaW50czwvQT4KICAgICAgIDxMST4gPEEg SFJFRj0iI2NoYW5nZXMiPk1ham9yIENoYW5nZXMgZnJvbSAxLjAgdG8gMi4wPC9BPgpAQCAtNDAz LDYgKzQwNCw0OCBAQAogCSAgICBzcGVjaWZpY2F0aW9uLiAgPEEgSFJFRj0iI0Zvb3Rub3RlNCI+ WzRdPC9BPgogCSAgICA8UD4KIAorCSAgPERUPiA8Qj5zY2hlbWE8L0I+KFtuYW1lPSIiXSkKKwkg IDxERD4KKwkgICAgUmV0dXJuIGEgbmV3IDxBIEhSRUY9IiNzY2hlbWEiPjxJPlNjaGVtYSBPYmpl Y3Q8L0k+PC9BPgorCSAgICBmb3IgdGhlIGRhdGFiYXNlIGJlaW5nIGNvbm5lY3RlZCB0by4KKwkg ICAgVGhpcyBtZXRob2QgaXMgb3B0aW9uYWwgYW5kIHNob3VsZCBvbmx5IGJlIHByb3ZpZGVkIGlm IHRoZQorCSAgICBkYXRhYmFzZSBkcml2ZXIgc3VwcG9ydHMgc2NoZW1hIG9iamVjdHMuCisJICAg IDxQPgorCSAgICAgIElmIHRoZSB1bmRlcmx5aW5nIGRhdGFiYXNlIHN1cHBvcnRzIHNldmVyYWwg c2NoZW1hcyBwZXIKKwkgICAgICBkYXRhYmFzZSwgdGhlIHNjaGVtYSBhY2Nlc3MgcGFyYW1ldGVy cyBzaG91bGQgYmUgcHJvdmlkZWQKKwkgICAgICBhcyBhIHNpbmdsZSBzdHJpbmcgdGhyb3VnaCB0 aGUgIm5hbWUiIHBhcmFtZXRlci4KKwkgICAgICBJZiB0aGUgIm5hbWUiIHBhcmFtZXRlciBpcyBv bWl0dGVkIG9yIGVtcHR5LCBhIGRlZmF1bHQKKwkgICAgICBzY2hlbWEgaXMgYWNjZXNzZWQuCisJ ICAgIDxQPgorCSAgICAgIElmIHRoZSB1bmRlcmx5aW5nIGRhdGFiYXNlIHN1cHBvcnRzIGV4YWN0 bHkgb25lIHNjaGVtYSwKKwkgICAgICB0aGUgZHJpdmVyIG11c3QgYWNjZXB0IGF0IGxlYXN0IGFu IGVtcHR5IG9yIG9taXR0ZWQgIm5hbWUiCisJICAgICAgYXJndW1lbnQgYXMgY29ycmVjdCBwb3Nz aWJpbGl0aWVzIHRvIGFjY2VzcyB0aGUgdW5pcXVlCisJICAgICAgc2NoZW1hLiAgVXNpbmcgYSBu b24tZW1wdHkgIm5hbWUiIGFyZ3VtZW50IGluIHRoaXMgY2FzZQorCSAgICAgIGNhbiByYWlzZSBh ICJOb3RTdXBwb3J0ZWRFcnJvciIgZXhjZXB0aW9uLgorCSAgICA8UD4KKwkgICAgICBXYXJuaW5n OiAgdGhlIHdheSB0byBhY2Nlc3Mgc2NoZW1hcyBvdGhlciB0aGFuIGRlZmF1bHQKKwkgICAgICB0 aHJvdWdoIFNRTCBpcyB1bnNwZWNpZmllZCBhbmQgZGF0YWJhc2UgZGVwZW5kZW50OiAKKwkgICAg ICBBcHBsaWNhdGlvbnMgc2hvdWxkIG9ubHkgcmVseSBvbiBhIGRlZmF1bHQgc2NoZW1hLgorCSAg ICA8UD4KKworCSAgPERUPiA8Qj5zY2hlbWFsaXN0PC9CPigpCisJICA8REQ+CisJICAgIFJldHVy biBhIHNlcXVlbmNlIG9mIHN0cmluZ3MsIGVhY2ggb25lIGRlbm90aW5nIGFjY2VzcworCSAgICBw YXJhbWV0ZXJzIGZvciBhIHNlcGFyYXRlIHNjaGVtYS4KKwkgICAgU3RyaW5ncyBpbiB0aGlzIHNl cXVlbmNlIGNhbiBiZSB1c2VkIGFzIGlzIGluIHRoZSAibmFtZSIKKwkgICAgcGFyYW1ldGVyIG9m IHRoZSAic2NoZW1hIiBtZXRob2QuCisJICAgIFRoaXMgbWV0aG9kIHNob3VsZCBiZSBwcm92aWRl ZCBieSB0aGUgZHJpdmVyIGV4YWN0bHkgd2hlbgorCSAgICB0aGUgInNjaGVtYSIgbWV0aG9kIGlz IHByb3ZpZGVkLgorCSAgICA8UD4KKwkgICAgICBXaGVuIHRoZSB1bmRlcmx5aW5nIGRhdGFiYXNl IHN1cHBvcnRzIHNldmVyYWwgc2NoZW1hcyBwZXIKKwkgICAgICBkYXRhYmFzZSwgdGhpcyBtZXRo b2Qgc2hvdWxkIHJldHVybiBhIG5vbi1lbXB0eSBzZXF1ZW5jZQorCSAgICAgIG9mIG5vbi1lbXB0 eSBzdHJpbmdzLgorCSAgICA8UD4KKwkgICAgICBXaGVuIHRoZSB1bmRlcmx5aW5nIGRhdGFiYXNl IHN1cHBvcnRzIGV4YWN0bHkgb25lIHNjaGVtYSwKKwkgICAgICB0aGlzIG1ldGhvZCByZXR1cm5z IGV4YWN0bHkgYSBzZXF1ZW5jZSBvZiBvbmUgZW1wdHkKKwkgICAgICBzdHJpbmcuCisJICAgIDxQ PgorCiAJPC9ETD4KIAk8UD4KIApAQCAtNjQ1LDYgKzY4OCwxMDMgQEAKIAk8L0RMPgogCiAJPFA+ CisKKyAgICA8L1VMPgorCisgICAgPEEgTkFNRT0ic2NoZW1hIj48SDM+U2NoZW1hIE9iamVjdHM8 L0gzPjwvQT4KKworICAgIDxVTD4KKworCTxQPgorCSAgU2NoZW1hIE9iamVjdHMgc2hvdWxkIHJl c3BvbmQgdG8gdGhlIGZvbGxvd2luZyBtZXRob2RzIGFuZAorCSAgYXR0cmlidXRlczoKKwk8UD4K KworCTxETD4KKworCSAgPERUPiA8Qj50YWJsZXM8L0I+KCkKKwkgIDxERD4KKwkgICAgUmV0dXJu IGEgKHBvc3NpYmx5IGVtcHR5KSBzZXF1ZW5jZSBvZiBhdmFpbGFibGUgdGFibGUKKwkgICAgbm9u LWVtcHR5IG5hbWVzLgorCSAgICA8UD4KKworCSAgPERUPiA8Qj5jb2x1bW5zPC9CPih0YWJsZSkK KwkgIDxERD4KKwkgICAgUmV0dXJuIGEgbm9uLWVtcHR5IHNlcXVlbmNlIG9mIGFsbCB0aGUgY29s dW1uIG5vbi1lbXB0eQorCSAgICBuYW1lcyBkZWZpbmVkIGJ5IHRoZSBleGlzdGluZyB0YWJsZSB3 aGljaCBuYW1lIGlzIGdpdmVuIGJ5CisJICAgIHRoZSAidGFibGUiIGFyZ3VtZW50LgorCSAgICA8 UD4KKwkgICAgSWYgdGhlIHJlcXVlc3RlZCB0YWJsZSBkb2VzIG5vdCBleGlzdCwgYSBEYXRhRXJy b3IgZXhjZXB0aW9uCisJICAgIGlzIHJhaXNlZC4KKwkgICAgPFA+CisKKwkgIDxEVD4gPEI+Y29s dW1uZGVmPC9CPih0YWJsZSxjb2x1bW4pCisJICA8REQ+CisJICAgIFJldHVybiBhIHNlcXVlbmNl IG9mIHRoZSBmb2xsb3dpbmcgZWxlbWVudHMgaW4gdGhhdCBvcmRlcjogCisJICAgIGEgc3RyaW5n IGRlbm90aW5nIHRoZSBTUUwgc3RhbmRhcmQga2luZCBvZiB0aGUgY29sdW1uIChvbmUKKwkgICAg b2YgIkNIQVIiLCAiVkFSQ0hBUiIsICJJTlQiLCAiUkVBTCIsICJEQVRFIiwgIlRJTUUiKSwgYW4K KwkgICAgaW50ZWdlciBudW1iZXIgZ2l2aW5nIHRoZSBzaXplIG9mIHRoZSBjb2x1bSAob3IgTm9u ZSBpZgorCSAgICBpbmFwcHJvcHJpYXRlKSwgYSBib29sZWFuICgwIG9yIDEgYXMgaW50ZWdlciBu dW1iZXIpCisJICAgIGluZGljYXRpbmcgd2hldGhlciBOVUxMcyBhcmUgYWNjZXB0ZWQsIGFuZCBh IHN0cmluZworCSAgICBjb250YWluaW5nIHRoZSBTUUwgZXhwcmVzc2lvbiB1c2VkIGFzIGRlZmF1 bHQgdmFsdWUgd2hlbgorCSAgICBjcmVhdGluZyBuZXcgcm93cyAob3IgTm9uZSB3aGVuIG5vIGRl ZmF1bHQgdmFsdWUgaXMgZGVmaW5lZCwKKwkgICAgb3Igd2hlbiB0aGUgdW5kZXJseWluZyBkYXRh YmFzZSBkb2VzIG5vdCBzdXBwb3J0IGRlZmF1bHQKKwkgICAgdmFsdWVzKS4KKwkgICAgPFA+CisJ ICAgIElmIHRoZSByZXF1ZXN0ZWQgdGFibGUgb3IgY29sdW1uIGRvZXMgbm90IGV4aXN0LCBhIERh dGFFcnJvcgorCSAgICBleGNlcHRpb24gaXMgcmFpc2VkLgorCSAgICA8UD4KKworCSAgPERUPiA8 Qj5wcmltYXJ5a2V5PC9CPih0YWJsZSkKKwkgIDxERD4KKwkgICAgUmV0dXJuIGEgKHBvc3NpYmx5 IGVtcHR5KSBzZXF1ZW5jZSBvZiBjb2x1bW4gbm9uLWVtcHR5IG5hbWVzCisJICAgIGZvciB0aGUg cmVxdWVzdGVkIHRhYmxlLCB0aGF0IGZvcm0gdGhlIHByaW1hcnkga2V5LiAgVGhlCisJICAgIHNl cXVlbmNlIGlzIGVtcHR5IHdoZW4gdGhlcmUgaXMgbm8gcHJpbWFyeSBrZXkgZGVmaW5lZC4KKwkg ICAgPFA+CisJICAgIElmIHRoZSByZXF1ZXN0ZWQgdGFibGUgZG9lcyBub3QgZXhpc3QsIGEgRGF0 YUVycm9yIGV4Y2VwdGlvbgorCSAgICBpcyByYWlzZWQuCisJICAgIDxQPgorCisJICA8RFQ+IDxC PmZvcmVpZ25rZXlzPC9CPih0YWJsZSkKKwkgIDxERD4KKwkgICAgLi4uCisJICAgIDxQPgorCSAg ICBJZiB0aGUgcmVxdWVzdGVkIHRhYmxlIGRvZXMgbm90IGV4aXN0LCBhIERhdGFFcnJvciBleGNl cHRpb24KKwkgICAgaXMgcmFpc2VkLgorCSAgICA8UD4KKworCSAgPERUPiA8Qj5pbmRpY2VzPC9C Pih0YWJsZSkKKwkgIDxERD4KKwkgICAgUmV0dXJuIGEgKHBvc3NpYmx5IGVtcHR5KSBzZXF1ZW5j ZSBvZiBpbmRleCBub24tZW1wdHkgbmFtZXMKKwkgICAgZGVmaW5lZCBmb3IgdGhlIHJlcXVlc3Rl ZCB0YWJsZS4KKwkgICAgPFA+CisJICAgIElmIHRoZSByZXF1ZXN0ZWQgdGFibGUgZG9lcyBub3Qg ZXhpc3QsIGEgRGF0YUVycm9yIGV4Y2VwdGlvbgorCSAgICBpcyByYWlzZWQuCisJICAgIDxQPgor CisJICA8RFQ+IDxCPmluZGV4ZGVmPC9CPih0YWJsZSxpbmRleCkKKwkgIDxERD4KKwkgICAgLi4u CisJICAgIDxQPgorCSAgICBJZiB0aGUgcmVxdWVzdGVkIHRhYmxlIG9yIGluZGV4IGRvZXMgbm90 IGV4aXN0LCBhIERhdGFFcnJvcgorCSAgICBleGNlcHRpb24gaXMgcmFpc2VkLgorCSAgICA8UD4K KworCSAgPERUPiA8Qj5wcm9jZWR1cmVzPC9CPigpCisJICA8REQ+CisJICAgIFJldHVybiBhIChw b3NzaWJseSBlbXB0eSkgc2VxdWVuY2Ugb2YgYXZhaWxhYmxlIHByb2NlZHVyZQorCSAgICBub24t ZW1wdHkgbmFtZXMuCisJICAgIDxQPgorCisJICA8RFQ+IDxCPnByb2NlZHVyZWRlZjwvQj4ocHJv YykKKwkgIDxERD4KKwkgICAgLi4uCisJICAgIDxQPgorCSAgICBJZiB0aGUgcmVxdWVzdGVkIHBy b2NlZHVyZSBkb2VzIG5vdCBleGlzdCwgYSBEYXRhRXJyb3IKKwkgICAgZXhjZXB0aW9uIGlzIHJh aXNlZC4KKwkgICAgPFA+CisKKwk8L0RMPgogCiAgICAgPC9VTD4KIAo= ------=_20020821082847_52611-- From msanchez@grupoburke.com Wed Aug 21 13:17:20 2002 From: msanchez@grupoburke.com (=?iso-8859-1?Q?Marcos_S=E1nchez_Provencio?=) Date: Wed, 21 Aug 2002 14:17:20 +0200 (CEST) Subject: [DB-SIG] Parameters in DCOracle2 In-Reply-To: <1029870477.31445.44.camel@chl0151.edmonton.computronix.com> References: <1029870477.31445.44.camel@chl0151.edmonton.computronix.com> Message-ID: <16989.195.53.212.39.1029932240.squirrel@www.grupoburke.com> I am not going to defend this database, it is a port of a port of a port.= .. It started with vms/db2, in Cobol, now it's using ProC and whatever. If i= 'm lucky i get to do the new version (not patches) after 15 years. And yes, they are using char :-\ I hope to ask better questions from now on and promise not to write when = I'm angry :-) > Would you mind posting your table definition? I am suspecting that you > are using "char" as a data type rather than "varchar2" which is what > Oracle recommends. If you use "char", strange things start to happen > because Oracle will convert some arguments to "varchar2" automatically > and others it won't. The internal representation of the "char" data > type includes spaces, unfortunately, so you have to match perfectly or > have Oracle do some implicit conversion for you or do your own explicit > conversion. Why not just use "varchar2" and have done with it!!? > > On Tue, 2002-08-20 at 13:41, Marcos S=E1nchez Provencio wrote: >> Thank you, really, but it must be a political question of mine not to >> do that. I refuse to have a system that is so costly to do everything >> in the program then. Why does the system return different results >> using exactly the same string as a parameter and as a constant string? >> >> select * from tb where fd1=3D'SAENS' >> [returns rows] >> >> select * from tb where fd1=3D:1 //// 'SAENS' >> [returns nothing] >> >> What are the _real_ advantages of using Oracle versus Sybase? I find >> it full of little nasty things that make it impossible to work >> fluently. >> >> El mar, 20-08-2002 a las 02:12, James Briggs escribi=F3: >> > >> > To avoid breaking the index usage, you could try: >> > >> > cursor.execute("select * from table where nombre like :1||'%'", >> nombre) >> > >> >> Or >> between :1 and :1 || ' ' >> but I still don't like it... >> > Of course you still have to test the nombre you now have is "SAENS" >> with optional trailing spaces and not "SAENSA", but at least your >> using the database index to only fetch the rows that possible match. I >> guess the ugliness of the extra code is the price for having trailing >> spaces in the database... >> > >> > buena suerte >> > >> Hasta la vista >> >> > James >> > >> > >>> Marcos S=E1nchez Provencio 20/08/2002 >> 4:04:36 am >>> >> > I expect this to break index usage, I suppose... >> > >> > El lun, 19-08-2002 a las 15:05, Matthew T. Kromer escribi=F3: >> > > I think you're really after something like >> > > >> > > cursor.execute("select * from table where RTRIM(nombre) =3D >> > > :1", >> >> > > nombre) >> > > >> > > Although I'm away from my manual to look up RTRIM to see if you >> > > need >> to >> > > pass it a 2nd parameter to tell it to trim trailing spaces. >> > > >> > > >> > > On Monday, August 19, 2002, at 05:27 AM, Marcos S=E1nchez Provenci= o >> wrote: >> > > >> > > > First, thank you for your help, I have found out several new >> things. >> > > > >> > > > The value is stored in the table as 'SAENS ' with spaces, >> > > > but >> _not_ >> > > > to >> > > > thefull length of the column, which is 50. So, the non-parameter >> query >> > > > does find >> > > > results, but the parametrised query only finds results when >> providing >> > > > the >> > > > exactnumber of spaces (5 in this case). I can't touch the data >> > > > in >> the >> > > > table. Is >> > > > theresome way to get the same results as a SQL*Plus window? >> > > > >> > > > PS. I use now named parameters correctly. Thanks. >> > > > >> > > >> Hello, I am having a problem trying to get some data from an >> Solaris >> > > >> Oracle 7.3.3 server. I use the 8.1.7 client in the same >> > > >> machine. >> The >> > > >> problem is as follows: >> > > >> >> > > >> I get results if I say >> > > >> >> > > >> where nombre=3D'SAENS' >> > > >> >> > > >> but not if I say >> > > >> >> > > >> where nombre=3D:p1 >> > > >> >> > > >> and pass a parameter 'SAENS', fetchall returns an empty list >> > > >> >> > > >> It is funny that I get some results if I say >> > > >> >> > > >> where nombre between :p1 and :p1 || 'Z' >> > > >> >> > > >> or (almost) what I want by saying >> > > >> >> > > >> where nombre like :p1 || ' %' >> > > >> >> > > >> I have been puzzled by Oracle since I am using it (I had used >> Sybase >> > > >> before). Is this an Oracle issue or a Python one? >> > > >> >> > > >> Thank you very much >> > > >> >> > > >> >> > > >> >> > > >> _______________________________________________ >> > > >> DB-SIG maillist - DB-SIG@python.org >> > > >> http://mail.python.org/mailman/listinfo/db-sig >> > > > >> > > > >> > > > >> > > > >> > > > _______________________________________________ >> > > > DB-SIG maillist - DB-SIG@python.org >> > > > http://mail.python.org/mailman/listinfo/db-sig >> > > >> > > >> > > _______________________________________________ >> > > DB-SIG maillist - DB-SIG@python.org >> > > http://mail.python.org/mailman/listinfo/db-sig >> > >> > >> > >> > _______________________________________________ >> > DB-SIG maillist - DB-SIG@python.org >> > http://mail.python.org/mailman/listinfo/db-sig >> >> >> >> _______________________________________________ >> DB-SIG maillist - DB-SIG@python.org >> http://mail.python.org/mailman/listinfo/db-sig > -- > Anthony Tuininga > anthony@computronix.com > > Computronix > Distinctive Software. Real People. > Suite 200, 10216 - 124 Street NW > Edmonton, AB, Canada T5N 4A3 > Phone: (780) 454-3700 > Fax: (780) 454-3838 > http://www.computronix.com From matt@zope.com Wed Aug 21 14:45:11 2002 From: matt@zope.com (Matthew T. Kromer) Date: Wed, 21 Aug 2002 09:45:11 -0400 Subject: [DB-SIG] Parameters in DCOracle2 References: Message-ID: <3D639967.5080604@zope.com> James Briggs wrote: >[...] > >3) Tweak or Force DCOracle2, or the interface of your choic,e to convert string bind variables to CHAR datatypes not VARCHAR datatypes, using DCOracle2.TypeCoercion??? Not sure this is possible, I haven't had access to a database to test this yet. I do know in the C layer it is possible to define arrays to be mapped to the CHAR type... > > Yes, that will work. Here's an example: SQL> describe testchar Name Null? Type ----------------------------------------- -------- ---------------------------- ID NUMBER(38) CS CHAR(12) VC VARCHAR2(12) SQL> select * from testchar; ID CS VC ---------- ------------ ------------ 1 MATT MATT import DCOracle2 db = DCOracle2.connect('scott/tiger') c = db.cursor() c.execute('select * from testchar where cs=:1', DCOracle2.TypeCoercion('MATT', 'SQLT_AFC')) print c.fetchall() However, its fairly nonobvious that 'SQLT_AFC' (ANSI Fixed Character) is the type you get when you use datatype 'CHAR' -- you'd expect that to be 'SQLT_CHR' but that's VARCHAR. -- Matt Kromer Zope Corporation http://www.zope.com/ From TKeating@origin.ea.com Wed Aug 21 16:55:43 2002 From: TKeating@origin.ea.com (Keating, Tim) Date: Wed, 21 Aug 2002 10:55:43 -0500 Subject: [DB-SIG] Proposal: Standardized way to get database schema Message-ID: <9B8090A2F0EBDB4ABD59B08E81C1A6842F62CF@osi-postal.osi.ad.ea.com> I love this idea. The only issue I have with the proposed interface is that it pays homage to an aspect of the DB API that I don't particularly like -- specifically, the separation of items from their descriptions. I understand that this may have been done in the core API for performance reasons, but I still find myself having to write some really ugly, non-pythonic code to e.g. extract data from a row using the column name. I would very much prefer to see the DB Schema API rely on ADTs for Tables, Columns etc. that can be browsed in a more natural way, particularly in light of the fact that schema inspection is not likely to be a frequent activity. TK -----Original Message----- From: Fabien COUTANT [mailto:fcoutant@freesurf.fr] Sent: Wednesday, August 21, 2002 1:29 AM To: db-sig@python.org Subject: [DB-SIG] Proposal: Standardized way to get database schema Hello, I want to go on the idea of standardizing the way to introspect a database schema. Following the suggestion from Marcos Sanchez Provencio, I wrote a suggestion for an API extension that provides schema introspection. What I did: - tried to conform to the current spirit of the API. - took some ideas from Brian Zimmer - directly modified HTML since it's the only document I have. - am not sure whether multi-schema support should be kept, since there is otherwise no support for it in the rest of the API. - the parts about primary/foreign keys, procedures and indexes are incomplete. I just gave the idea. - not sure of the exact list of SQL kinds that should be included. I don't remember the standard perfectly... I hope this can be a starting point, as there is some work remaining. NB: Since I have wrapping problems with my webmail, I have to include the diff as a MIME attachment. Sorry for the inconvenience. -- Hope this helps, Fabien. From msanchez@grupoburke.com Wed Aug 21 17:02:48 2002 From: msanchez@grupoburke.com (Marcos =?ISO-8859-1?Q?S=E1nchez?= Provencio) Date: 21 Aug 2002 18:02:48 +0200 Subject: [DB-SIG] Parameters in DCOracle2 In-Reply-To: <3D639967.5080604@zope.com> References: <3D639967.5080604@zope.com> Message-ID: <1029945768.2833.3.camel@renata.macondo.pri> This is a message for all the people that helped me with my Oracle 'issue'. Some of these answers (a megamix of them, really) have allowed me to carry on my program. But all of them have given me a feeling that no matter the problems I have, there is someone in this list that is able to help fix them. This has allowed me to work without fear of getting stuck. So, thank all of you. El mi=E9, 21-08-2002 a las 15:45, Matthew T. Kromer escribi=F3: > James Briggs wrote: >=20 > >[...] > > > >3) Tweak or Force DCOracle2, or the interface of your choic,e to convert= string bind variables to CHAR datatypes not VARCHAR datatypes, using DCOra= cle2.TypeCoercion??? Not sure this is possible, I haven't had access to a d= atabase to test this yet. I do know in the C layer it is possible to define= arrays to be mapped to the CHAR type... > > =20 > > >=20 > Yes, that will work. Here's an example: >=20 > SQL> describe testchar > Name Null? Type > ----------------------------------------- --------=20 > ---------------------------- > ID NUMBER(38) > CS CHAR(12) > VC VARCHAR2(12) >=20 > SQL> select * from testchar; >=20 > ID CS VC > ---------- ------------ ------------ > 1 MATT MATT >=20 >=20 >=20 > import DCOracle2 > db =3D DCOracle2.connect('scott/tiger') > c =3D db.cursor() > c.execute('select * from testchar where cs=3D:1', > DCOracle2.TypeCoercion('MATT', 'SQLT_AFC')) >=20 > print c.fetchall() >=20 >=20 > However, its fairly nonobvious that 'SQLT_AFC' (ANSI Fixed Character) is=20 > the type you get when you use datatype 'CHAR' -- you'd expect that to be=20 > 'SQLT_CHR' but that's VARCHAR. >=20 > --=20 > Matt Kromer > Zope Corporation http://www.zope.com/=20 >=20 >=20 From chris@cogdon.org Thu Aug 22 03:11:43 2002 From: chris@cogdon.org (Chris Cogdon) Date: Wed, 21 Aug 2002 19:11:43 -0700 Subject: [DB-SIG] format and pyformat redux Message-ID: <200208211911.43299.chris@cogdon.org> I thought I'd just recap the previous discussion on format vs pyformat, s= ince=20 I got a few responses privately. At the end, I'll also add a 'neat=20 suggestion' we can all champion or lampoon as appropriate. I originally asked what where the advantages of pyformat over format. pyf= ormat=20 seems to be the 'preferred' paramater passing mechanism, even though my o= wn=20 experiences with 'pyformat' was that it was more cumbersome than 'format'= =2E However, when the number of parameters increases, it becomes more and mor= e=20 difficult to maintain sequencing with the 'format' method, given that a=20 change in parameters necessitates a change in the order the parameters ar= e=20 passed to the 'execute' method. For example, with the following compariso= n,=20 it appears that 'format' is much simpler: cur.execute ( "select * from people where name=3D%s and age>%s", name, ag= e ) cur.execute ( "select * from people where name=3D%(name)s and age>%(age)s= ", =09{'name':name,'age':age} The shorter 'format' becomes more complex with, say, 10 or more parameter= s.=20 (example omitted, I'm sure it's obvious to you all). Additionally, you can do some neat tricks with the 'pyformat' method. If = all=20 your variables are in your local namespace already, you can pass the outp= ut=20 of 'vars'. Viz: cur.execute ( "select * from people where name=3D%(name)s and age>%(age)s= ",=20 vars() ) In the cases where this is not the case, you can write a 'wrapper functio= n' to=20 help you create the anonymous dictionary. Viz: def execute2 ( cursor, format, **kwargs ): return cursor.execute ( format, kwargs ) execute2 ( cur, "select * from people where name=3D%(name)s and age>%(age= )s",=20 name=3Dgetname(), age=3Dgetage() ) So, thanks to you all fine folks out there, I dont find 'pyformat' as=20 unattractive anymore. I do have an interesting proposition, though. (Stop groaning, you ;) Currenty given the case where the information to be passed to the query i= s not=20 currently in any local variable. To get it in there, either a local varia= ble=20 needs to be created, and then the vars() function called to create the=20 dictionary, or a dictionary created to hold all the values. My suggestion= for=20 another parameter passing format, and the opportunity to create a new gen= eral=20 function for Python, is as follows: We create a function that treats the information inside the () of the %=20 operator (or the execute statement) as a full python expression, rather t= han=20 just a key into a dictionary. Since the current % expansion operator uses= =20 parenthesis, it's perfectly reasonable to assume these are the surroundin= g=20 parentesis of an expression, and evaluate the contents as a python=20 expression! Here's an example, assuming we have a new parameter passing=20 method called, say, pyexprformat (python expression format) cur.execute ( "select * from people where name=3D%(name)s and age>%(age)s= ",=20 locals(), globals() ) Okay, so that's nothing new, but in this case, the stuff inside the=20 parenthesis is a python expression, and it's been told to evaluage in the= =20 specified namespaces, just like 'eval'. Now, assume that the two paramete= rs=20 need to be calculated, we could have: cur.execute ( "select * from people where name=3D%(getname())s and=20 age>%(age())s", locals(), globals() ) I've shown an example of using a simple function call, but this could hav= e=20 been any python expression. To me, this seems to be very easy to set up. The syntax is clear, and I'm= sure=20 there's a hook into the interpretor that would stop parsing tokens when t= he=20 valid end of expression is reached (same syntax as function calls), we ge= t=20 the value of the expression, do type checking to find out what kind of=20 quoting is necessary for SQL, and then we can continue parsing the string= as=20 SQL :) Apart from needing to specify the namespace, (and I'm sure we can get=20 reasonable defaults by playing with the python call stack) one does ot ne= ed=20 to assign 'temporary' dictionary keys to get the information into the que= ry=20 at all. And finally, this can be expanded into a general python function for doin= g=20 'expression-based' formatting strings, like the following: formatexpr ( "Hello %(form['name'])s, if you are %(form['age'])s this yea= r,=20 you'll be %(form['age']+1)s next year." ) Is this not nifty? --=20 ("`-/")_.-'"``-._ Chris Cogdon . . `; -._ )-;-,_`) (v_,)' _ )`-.\ ``-' _.- _..-_/ / ((.' ((,.-' ((,/ fL From Denis.CM@Wanadoo.fr Thu Aug 22 14:10:06 2002 From: Denis.CM@Wanadoo.fr (Denis Cartier Millon) Date: Thu, 22 Aug 2002 15:10:06 +0200 Subject: [DB-SIG] PySQL/insert a list of tuples.... Message-ID: <3D64E2AE.8040207@Wanadoo.fr> I want insert a sequence of sequence (list og tuples) in a table , (x comme from the script select * from Mytable with an fethchall) and the script is : cur=conn.cursor() cur.executemany("insert into Mytable values (%s)",x) # is there a solution thanks..... From jekabs.andrusaitis@tietoenator.com Thu Aug 22 14:28:16 2002 From: jekabs.andrusaitis@tietoenator.com (Jekabs Andrushaitis) Date: Thu, 22 Aug 2002 15:28:16 +0200 Subject: [DB-SIG] Parameters in DCOracle2 In-Reply-To: <1029780276.9577.0.camel@renata.macondo.pri> Message-ID: <002501c249e0$c648d8c0$262a949f@konts.lv> > I expect this to break index usage, I suppose... Yes, under Oracle 7.x this does break index usage, however Oracle states that in 8.x and 9.x query execution has been improved and LTRIM and RTRIM in most cases does not break index usage any more. But still storing data in one style (with trailing spaces) and then trying to look it up by another style (without spaces) sounds a bad practice to me... Jekabs Andrushaitis Senior system analyst TietoEnator Financial Solutions 41 Lacplesa Str. Riga, LV-1011, Latvia Tel: +371 7286660 Fax: +371 7243000 E-mail: jekabs.andrusaitis@tietoenator.com From msanchez@grupoburke.com Thu Aug 22 17:32:05 2002 From: msanchez@grupoburke.com (Marcos =?ISO-8859-1?Q?S=E1nchez?= Provencio) Date: 22 Aug 2002 18:32:05 +0200 Subject: [DB-SIG] Parameters in DCOracle2 In-Reply-To: <002501c249e0$c648d8c0$262a949f@konts.lv> References: <002501c249e0$c648d8c0$262a949f@konts.lv> Message-ID: <1030033925.1157.1.camel@renata.macondo.pri> El jue, 22-08-2002 a las 15:28, Jekabs Andrushaitis escribi=F3: >=20 > > I expect this to break index usage, I suppose... > Yes, under Oracle 7.x this does break index usage, however > Oracle states that in 8.x and 9.x query execution has been improved > and LTRIM and RTRIM in most cases does not break index usage > any more. Now they are forced out of 7.x because of support reasons. Did I mention I love free software? > But still storing data in one style (with trailing spaces) and then > trying to look it up by another style (without spaces) sounds a bad > practice to me... Oh, I haven't given any gory details about this db yet ;-) From msanchez@grupoburke.com Thu Aug 22 17:35:37 2002 From: msanchez@grupoburke.com (Marcos =?ISO-8859-1?Q?S=E1nchez?= Provencio) Date: 22 Aug 2002 18:35:37 +0200 Subject: [DB-SIG] PySQL/insert a list of tuples.... In-Reply-To: <3D64E2AE.8040207@Wanadoo.fr> References: <3D64E2AE.8040207@Wanadoo.fr> Message-ID: <1030034137.1199.5.camel@renata.macondo.pri> El jue, 22-08-2002 a las 15:10, Denis Cartier Millon escribi=F3: > I want insert a sequence of sequence (list og tuples) in a table , > (x comme from the script select * from Mytable with an fethchall) >=20 > and the script is : > cur=3Dconn.cursor() > cur.executemany("insert into Mytable values (%s)",x) # is there a=20 > solution thanks..... >=20 Is there a problem? But seriously, you have to give as many %s as column values you want inserted in your sql=20 cur.executemany("insert into Mytable (col1,col2,col3) values (%s,%s,%s)",x) From LNSMTP02/EuroTel@eurotel.cz Thu Aug 22 19:48:00 2002 From: LNSMTP02/EuroTel@eurotel.cz (LNSMTP02/EuroTel@eurotel.cz) Date: Thu, 22 Aug 2002 20:48:00 +0200 Subject: [DB-SIG] NAV detected a virus in a document you authored. Message-ID: Please contact your system administrator. The scanned document was QUARANTINED. Virus Information: The attachment Vnp.pif contained the virus W32.Klez.H@mm and could NOT be repaired. From Denis.CM@Wanadoo.fr Fri Aug 23 09:24:43 2002 From: Denis.CM@Wanadoo.fr (Denis Cartier Millon) Date: Fri, 23 Aug 2002 10:24:43 +0200 Subject: [DB-SIG] PySQL/insert a list of tuples.... References: <3D64E2AE.8040207@Wanadoo.fr> <1030034137.1199.5.camel@renata.macondo.pri> Message-ID: <3D65F14B.7020202@Wanadoo.fr> --------------080608070500060807000702 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by cat686.snm.agriculture.gouv.fr id KAA32114 YES BUT two probl=E8mes : 1: the "%" : %s,%i,..... % (format like in C) ignore=20 the none (Python) null (SQL), 2: this solution needs to now the numbers and the types of parameters... before i use the module pg.py (module postgresql) and pg.inserttable=20 (,) : inserttable (Mytable,x) but this solution don't insert the none value. with cur.executemany ("insert into Mytable values (?,?,?)", list of params) =20 (example in LINUX JOURNAL the mappage is OK by the the dbapi but i must know the numbers of params. is the syntaxe : cur.executemany ("insert into Mytable values (?,?,?)", x) # where x is a list of tuples is OK ??? # if this is OK i win because i can build the string "insert into=20 Mytable values(?,?,?....) Marcos S=E1nchez Provencio a =E9crit: >El jue, 22-08-2002 a las 15:10, Denis Cartier Millon escribi=F3: > =20 > >>I want insert a sequence of sequence (list og tuples) in a table , >>(x comme from the script select * from Mytable with an fethchall) >> >>and the script is : >>cur=3Dconn.cursor() >>cur.executemany("insert into Mytable values (%s)",x) # is there a=20 >>solution thanks..... >> >> =20 >> >Is there a problem? > >But seriously, you have to give as many %s as column values you want >inserted in your sql=20 > >cur.executemany("insert into Mytable (col1,col2,col3) values >(%s,%s,%s)",x) > > >_______________________________________________ >DB-SIG maillist - DB-SIG@python.org >http://mail.python.org/mailman/listinfo/db-sig > > =20 > --------------080608070500060807000702 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit YES BUT two problèmes :

1:  the "%"  : %s,%i,..... % <list og params>  (format like in C) ignore the none (Python) null (SQL),
2:  this solution needs to now the numbers and the types of parameters...

before i use the module pg.py (module postgresql) and pg.inserttable (<table>,<liste o tuples>) :  inserttable (Mytable,x) but this solution
don't insert the none value.


with  <?>

cur.executemany  ("insert into Mytable values (?,?,?)", list of params)  (example in LINUX JOURNAL
    the mappage is  OK by the the dbapi
    but i must know the numbers of params.

is the syntaxe :

cur.executemany ("insert into Mytable values (?,?,?)", x)
 # where x is a list of tuples is OK ???
# if this is OK i win because i can build  the string "insert into Mytable values(?,?,?....)


Marcos Sánchez Provencio a écrit:
El jue, 22-08-2002 a las 15:10, Denis Cartier Millon escribió:
  
I  want insert a sequence of sequence (list og tuples) in a table ,
(x comme from the script select * from Mytable with an fethchall)

and the script is :
cur=conn.cursor()
cur.executemany("insert into Mytable values (%s)",x) # is there a 
solution thanks.....

    
Is there a problem?

But seriously, you have to give as many %s as column values you want
inserted in your sql 

cur.executemany("insert into Mytable (col1,col2,col3) values
(%s,%s,%s)",x)


_______________________________________________
DB-SIG maillist  -  DB-SIG@python.org
http://mail.python.org/mailman/listinfo/db-sig

  

--------------080608070500060807000702-- From jekabs.andrusaitis@tietoenator.com Thu Aug 22 19:42:16 2002 From: jekabs.andrusaitis@tietoenator.com (Jekabs Andrushaitis) Date: Thu, 22 Aug 2002 20:42:16 +0200 Subject: [DB-SIG] Parameters in DCOracle2 In-Reply-To: <1030033925.1157.1.camel@renata.macondo.pri> Message-ID: <001001c24a82$b8ecdd50$262a949f@konts.lv> > Now they are forced out of 7.x because of support reasons. > Did I mention > I love free software? Yeah, Oracle is cancelling the support for 7.x series - another reason to upgrade to 8.x. 9.x seems to be stable too though, but I would not rush with that one :). I love free software too, btw ;) P.S. Ignore this mail, it is basically a SPAM :) Jekabs Andrushaitis Senior system analyst TietoEnator Financial Solutions 41 Lacplesa Str. Riga, LV-1011, Latvia Tel: +371 7286660 Fax: +371 7243000 E-mail: jekabs.andrusaitis@tietoenator.com From printers@sendme.cz Sat Aug 24 08:55:19 2002 From: printers@sendme.cz (A) Date: Sat, 24 Aug 2002 09:55:19 +0200 Subject: [DB-SIG] Paradox Message-ID: <3D675807.26841.11FE74@localhost> Hi, Is there a module for using Paradox (.DB) files with Python? Thanks for help Ladislav From msanchez@grupoburke.com Sat Aug 24 11:13:01 2002 From: msanchez@grupoburke.com (Marcos =?ISO-8859-1?Q?S=E1nchez?= Provencio) Date: 24 Aug 2002 12:13:01 +0200 Subject: [DB-SIG] PySQL/insert a list of tuples.... In-Reply-To: <3D65F14B.7020202@Wanadoo.fr> References: <3D64E2AE.8040207@Wanadoo.fr> <1030034137.1199.5.camel@renata.macondo.pri> <3D65F14B.7020202@Wanadoo.fr> Message-ID: <1030183982.1716.54.camel@renata.macondo.pri> El vie, 23-08-2002 a las 10:24, Denis Cartier Millon escribi=F3: > YES BUT two probl=E8mes : >=20 > 1: the "%" : %s,%i,..... % (format like in C) ignore=20 > the none (Python) null (SQL), > 2: this solution needs to now the numbers and the types of parameters... You must not merge the string with %, but pass the parameters to the function executemany('sql blablabla ' , (list of parameters in tuples) ) I believe you may use %s for every parameter, whatever its type. >=20 > before i use the module pg.py (module postgresql) and pg.inserttable=20 > (
,) : inserttable (Mytable,x) but this solution > don't insert the none value. >=20 >=20 > with >=20 > cur.executemany ("insert into Mytable values (?,?,?)", list of params) =20 > (example in LINUX JOURNAL > the mappage is OK by the the dbapi > but i must know the numbers of params. >=20 > is the syntaxe : >=20 > cur.executemany ("insert into Mytable values (?,?,?)", x) > # where x is a list of tuples is OK ??? > # if this is OK i win because i can build the string "insert into=20 > Mytable values(?,?,?....) >=20 >=20 I believe that is the solution. > Marcos S=E1nchez Provencio a =E9crit: >=20 > >El jue, 22-08-2002 a las 15:10, Denis Cartier Millon escribi=F3: > > =20 > > > >>I want insert a sequence of sequence (list og tuples) in a table , > >>(x comme from the script select * from Mytable with an fethchall) > >> > >>and the script is : > >>cur=3Dconn.cursor() > >>cur.executemany("insert into Mytable values (%s)",x) # is there a=20 > >>solution thanks..... > >> > >> =20 > >> > >Is there a problem? > > > >But seriously, you have to give as many %s as column values you want > >inserted in your sql=20 > > > >cur.executemany("insert into Mytable (col1,col2,col3) values > >(%s,%s,%s)",x) > > > > > >_______________________________________________ > >DB-SIG maillist - DB-SIG@python.org > >http://mail.python.org/mailman/listinfo/db-sig > > > > =20 > > >=20 From Denis.CM@Wanadoo.fr Mon Aug 26 09:17:01 2002 From: Denis.CM@Wanadoo.fr (Denis Cartier Millon) Date: Mon, 26 Aug 2002 10:17:01 +0200 Subject: [DB-SIG] PySQL/insert a list of tuples.... References: <3D64E2AE.8040207@Wanadoo.fr> <1030034137.1199.5.camel@renata.macondo.pri> <3D65F14B.7020202@Wanadoo.fr> <1030183982.1716.54.camel@renata.macondo.pri> Message-ID: <3D69E3FD.8030208@Wanadoo.fr> --------------010302060006040409020708 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by cat686.snm.agriculture.gouv.fr id KAA08458 i can't execute this synthaxe with the module pgdb.py cur.execut("insert into Mytable values (?,?,?)", list of params in tuples= ) why?=20 i try an other module "psycopg.so" Marcos S=E1nchez Provencio a =E9crit: >El vie, 23-08-2002 a las 10:24, Denis Cartier Millon escribi=F3: > =20 > >>YES BUT two probl=E8mes : >> >>1: the "%" : %s,%i,..... % (format like in C) ignor= e=20 >>the none (Python) null (SQL), >>2: this solution needs to now the numbers and the types of parameters.= .. >> =20 >> > >You must not merge the string with %, but pass the parameters to the >function > >executemany('sql blablabla ' , (list of parameters in tuples) ) >I believe you may use %s for every parameter, whatever its type. > > > =20 > >>before i use the module pg.py (module postgresql) and pg.inserttable=20 >>(
,) : inserttable (Mytable,x) but this solution >>don't insert the none value. >> >> >>with >> >>cur.executemany ("insert into Mytable values (?,?,?)", list of params)= =20 >>(example in LINUX JOURNAL >> the mappage is OK by the the dbapi >> but i must know the numbers of params. >> >>is the syntaxe : >> >>cur.executemany ("insert into Mytable values (?,?,?)", x) >> # where x is a list of tuples is OK ??? >># if this is OK i win because i can build the string "insert into=20 >>Mytable values(?,?,?....) >> >> >> =20 >> > >I believe that is the solution. > > =20 > >>Marcos S=E1nchez Provencio a =E9crit: >> >> =20 >> >>>El jue, 22-08-2002 a las 15:10, Denis Cartier Millon escribi=F3: >>>=20 >>> >>> =20 >>> >>>>I want insert a sequence of sequence (list og tuples) in a table , >>>>(x comme from the script select * from Mytable with an fethchall) >>>> >>>>and the script is : >>>>cur=3Dconn.cursor() >>>>cur.executemany("insert into Mytable values (%s)",x) # is there a=20 >>>>solution thanks..... >>>> >>>> =20 >>>> >>>> =20 >>>> >>>Is there a problem? >>> >>>But seriously, you have to give as many %s as column values you want >>>inserted in your sql=20 >>> >>>cur.executemany("insert into Mytable (col1,col2,col3) values >>>(%s,%s,%s)",x) >>> >>> >>>_______________________________________________ >>>DB-SIG maillist - DB-SIG@python.org >>>http://mail.python.org/mailman/listinfo/db-sig >>> >>>=20 >>> >>> =20 >>> > > > >_______________________________________________ >DB-SIG maillist - DB-SIG@python.org >http://mail.python.org/mailman/listinfo/db-sig > > =20 > --------------010302060006040409020708 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit

i can't execute this synthaxe with the module pgdb.py
cur.execut("insert into Mytable values (?,?,?)", list of params in tuples)
why? 

i try  an other module "psycopg.so"

Marcos Sánchez Provencio a écrit:
El vie, 23-08-2002 a las 10:24, Denis Cartier Millon escribió:
  
YES BUT two problèmes :

1:  the "%"  : %s,%i,..... % <list og params>  (format like in C) ignore 
the none (Python) null (SQL),
2:  this solution needs to now the numbers and the types of parameters...
    

You must not merge the string with %, but pass the parameters to the
function

executemany('sql blablabla '   ,    (list of parameters in tuples) )
I believe you may use %s for every parameter, whatever its type.


  
before i use the module pg.py (module postgresql) and pg.inserttable 
(<table>,<liste o tuples>) :  inserttable (Mytable,x) but this solution
don't insert the none value.


with  <?>

cur.executemany  ("insert into Mytable values (?,?,?)", list of params)  
(example in LINUX JOURNAL
    the mappage is  OK by the the dbapi
    but i must know the numbers of params.

is the syntaxe :

cur.executemany ("insert into Mytable values (?,?,?)", x)
 # where x is a list of tuples is OK ???
# if this is OK i win because i can build  the string "insert into 
Mytable values(?,?,?....)


    

I believe that is the solution.

  
Marcos Sánchez Provencio a écrit:

    
El jue, 22-08-2002 a las 15:10, Denis Cartier Millon escribió:
 

      
I  want insert a sequence of sequence (list og tuples) in a table ,
(x comme from the script select * from Mytable with an fethchall)

and the script is :
cur=conn.cursor()
cur.executemany("insert into Mytable values (%s)",x) # is there a 
solution thanks.....

   

        
Is there a problem?

But seriously, you have to give as many %s as column values you want
inserted in your sql 

cur.executemany("insert into Mytable (col1,col2,col3) values
(%s,%s,%s)",x)


_______________________________________________
DB-SIG maillist  -  DB-SIG@python.org
http://mail.python.org/mailman/listinfo/db-sig

 

      



_______________________________________________
DB-SIG maillist  -  DB-SIG@python.org
http://mail.python.org/mailman/listinfo/db-sig

  

--------------010302060006040409020708-- From laszlo.asboth@yageo.com Mon Aug 26 11:31:53 2002 From: laszlo.asboth@yageo.com (Laszlo Asboth) Date: Mon, 26 Aug 2002 11:31:53 +0100 Subject: [DB-SIG] Introduction of new project Message-ID: --=_mixed 00390300C1256C20_= Content-Type: multipart/alternative; boundary="=_alternative 00390300C1256C20_=" --=_alternative 00390300C1256C20_= Content-Type: text/plain; charset="us-ascii" Dear all, I would like to inform you that I started a new project. Please see attached file. Many thanks and best regards, Laszlo Asboth --=_alternative 00390300C1256C20_= Content-Type: text/html; charset="us-ascii"
Dear all,

I would like to inform you that I started a new project.
Please see attached file.



Many thanks and best regards,

Laszlo Asboth
--=_alternative 00390300C1256C20_=-- --=_mixed 00390300C1256C20_= Content-Type: text/plain; name="Takas Introduction.txt" Content-Disposition: attachment; filename="Takas Introduction.txt" Content-Transfer-Encoding: quoted-printable "TAKAS" Project Introduction History: The idea of this project was arisen already 10 years ago. At that time in H= ungary mostly was used computers with Intel 386 processor and Novell 3.1 op= eration system. Due to informatics development there was made a lot of new = programs. I found a problem with them. For each task we used other standalo= ne program, in most cases made by totally different supplier/programmer. Th= e bottleneck of such kind of way of working is that each program needs to b= e updated with the same data. This means waste of energy. Then came up an i= dea, why we do not use only one system for all tasks, which can be done by = computer within a company? At my next workplace found the same situation. While this company was multi= national company the decision about each important issue came from abroad. = Here we used more different operating systems than before (Windows 3.1, Nov= ell, AS/400). In my existing workplace (started at 2nd of February 1998) the so called "d= iffusion" had been grown, against that we use more ERP & CRM systems like B= aan, SAP, etc. Fortunately between these systems a lot of interfaces were b= uilt to share data (via automatic ftp jobs). After introducing the structur= e of the informatics's system I found that we use these systems only partly= . This shows for me that these systems can not fulfil fundamental (all) req= uirements of a normal company. After more than 4 yearly preparation and collection of experiences I decide= d to start to build an own ERP & CRM system which applies the existing know= ledge of mine and volunteer's who joins to this idea. Mine main philosophy is that the computer should serve people and not oppos= ite (as works nowadays). Meaning the name of the project: The name has no definite meaning. At my workplace I work together with a co= lleague. When I discussed with him about this idea, he thought there is som= ething in it too. We started to plan it. While we are already on way we nee= d to call the project somehow. After some thinking and intuition the name w= as found: TAKAS. This is coming from two slices: "TAK" and "AS". Both are c= oming from our names (TAKacs, ASboth). Purpose of the project: The project has the following purposes:=20 * Build only one new - homogeneous - computer system, which helps operate t= o maintain data of the company. * Create a framework where possible to find and realise a solution on an ea= sier, faster way. Advantages: * Robust, fast, easy to use * Clasps all tasks of informatics of an arbitrary big organisation * Decreases time of maladministration * Increases the level of services within and between companies * Much less bug possibilities (no any interfaces necessary) * Each data needs to enter once and at the point of origin only (efficiency= , more disengagedness) * The user works in unitary surface (less learning time) * Economical solution, while it can be modified easily The project would like to reach: all data, which can be handled via compute= rs, should be handled in this system only. That means integrate all tasks i= n computer into this program (beside normal direction of the company the sy= stem should handle the e-mails, fax, personal tasks, contacts, etc. too). Philosophy of the project: >From company's management point of view the purpose to use this system can = be to build an effective, economical organisation with it. A system is good= when the user can faster and easier use it. Other important issue is the cost of the programs. There are big difference= s between people about. Most of the managers think that programs bought fro= m software companies shares the responsibility of use. The consequence of t= his kind of thinking is higher cost. There are a lot of programs which costs very little or nothing (called shar= eware, freeware or open source programs). My experience shows that program = of both categories work fine. At the beginning of the project should be decided which category this syste= m will join. We already discussed about. It can be evident that experts can= be found with charge only. My opinion (was and) is now that it can be foun= d good people who join to the project in behalf of creation and psychologic= al appreciation only. On other hand I am sure that later on we will get bac= k our efforts in material form too. This means that this project will be on the open source category. Certainly= before the real implementation we have to find the concord how can the pro= ject continue to exist and fluent grow. This philosophy brought already big result according to many projects on th= e Internet where a lot of experts are participated. There is other point of view. The project has a purpose to help people to g= row and develop themselves too. New ideas, proposals change the world into = a better way as we go now. I think this issue will be much more concrete la= ter on. Backgrounds: To be successful with this project it has to have very good background. Sho= uld be defined which operating system, graphical interface, programming lan= guage and database is the best for this project. Operating system: Beside Windows there are a lot of other operating system. Although there ar= e a lot of good things in it, I think for us better to choose FreeBSD, beca= use it is organised by a "core-team", works robustly, grows dynamically and= well documented. Programming language: In this area we can find a lot of them starting from the low level to high = level languages. My opinion is that we need a high level programming langua= ge for this project. After a long search on Internet I found Python program= ming language. This language takes into account best the object-oriented ph= ilosophy. The advantage of Python is that can be used as low level and high= level operation too. There are a lot of packages to it, which are very use= ful to create arbitrary program. The possibility to use it on mostly used o= perating systems is a very good aspect too. Graphical interface: We need a graphical interface too, while to my opinion a reliable system in= our world should work with it. There are more interfaces to Python too, I = think for us the wxPython is the best choice. Database manager: This point is the most important for such a big system. There is 2 differen= t type of database managers: relational and object-oriented. In the past I = introduced relational databases only. After knowing Python I found Zope Obj= ect DataBase (ZODB). The main advantage of it that it was written in Python= . There is an "extension" for it Zope Enterprise Objects (ZEO) which provid= es to connect to ZODB via network. My existing experience about ZEO that it= is not ready for handling more than 1 database in same time (I hope maybe = this project gives the chance to go further in this way). The above mentioned backgrounds are the fundamentals of the project. Certai= nly each idea, which can help to make better solutions, is welcome. I know = that there are a lot of experts who knows much more about these and other c= omponents than I. This is the reason why I would like to ask anybody to joi= n to the project. Introdution of the actor: I would like to introduce myself too. My name is L=E1szl=F3 Asb=F3th. I am = 38 years old. I have 2 children (my daughter D=F3ra 13, my son =C1d=E1m 7).= I live in Hungary, at 5 Kiss J. str, in S=E1rv=E1r. My professions are lan= d surveyor, computer programmer and preventive parapsychologist. My existing workplace is in Szombathely, called Phycomp Hungary Kft. I work= as a program engineer. My first impression about computers started when the first IBM AT computers= came to Matav Rt (the biggest telecommunication's company of Hungary). I d= id not know the command "dir" yet. I started to play with it, because it wa= s very interesting. After some months I learned a lot about DOS, and starte= d to make a program in Basic language. This was a "TOTO" program. Although = we won some money on the second week we could not make a fortune. My boss s= howed my interest for computers he assigned me to a new post. Then I starte= d to learn programming, which I ended in 1993. I learned more computer lang= uages (Clipper, Pascal, C). On my existing workplace in 1998 met with the U= nix operating system and Baan ERP system. I learned to program in Baan as a= utodidact. Last year I started seriously search for components to the project.=20 In my spare time I am interested in self-development. I use and teach some = methods in this area. Invitation: When you think this project has something for you, or you have interest to = join, please contact me. When you can give some advises only they are welco= me too. Thank you very much for reading this introduction (excuse me for my english= ). In S=E1rv=E1r, on 19th of august, 2002. L=E1szl=F3 Asb=F3th --=_mixed 00390300C1256C20_=-- From babu@bessy.de Tue Aug 27 15:10:27 2002 From: babu@bessy.de (Babu Manjasetty) Date: Tue, 27 Aug 2002 16:10:27 +0200 (CEST) Subject: [DB-SIG] MySQLdb build error Message-ID: Hi there, I try to build and install the MySQLdb 0.9.2 on linux Suse 8.0 and end with the following error. ~/mysqldownload/MySQL-python-0.9.2> python setup.py build running build running build_py not copying CompatMysqldb.py (output up-to-date) not copying _mysql_exceptions.py (output up-to-date) not copying MySQLdb/__init__.py (output up-to-date) not copying MySQLdb/converters.py (output up-to-date) not copying MySQLdb/connections.py (output up-to-date) not copying MySQLdb/cursors.py (output up-to-date) not copying MySQLdb/sets.py (output up-to-date) not copying MySQLdb/times.py (output up-to-date) not copying MySQLdb/constants/__init__.py (output up-to-date) not copying MySQLdb/constants/CR.py (output up-to-date) not copying MySQLdb/constants/FIELD_TYPE.py (output up-to-date) not copying MySQLdb/constants/ER.py (output up-to-date) not copying MySQLdb/constants/FLAG.py (output up-to-date) not copying MySQLdb/constants/REFRESH.py (output up-to-date) not copying MySQLdb/constants/CLIENT.py (output up-to-date) running build_ext building '_mysql' extension skipping _mysql.c (build/temp.linux-i686-2.2/_mysql.o up-to-date) gcc -shared build/temp.linux-i686-2.2/_mysql.o -L/usr/lib/mysql -L/usr/local/lib/mysql -L/usr/local/mysql/lib/mysql -lmysqlclient_r -lz -o build/lib.linux-i686-2.2/_mysql.so /usr/i486-suse-linux/bin/ld: cannot find -lmysqlclient_r collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1 This is the first time, I am installing the stuff on the computers. Your help is appreciated. Looking forward to hearing from you. Babu ################################################################### Dr. Babu A. Manjasetty Protein Structure Factory C/o Bessy GmbH Albert-Einstein-Str.15 12489 Berlin Germany Phone : +49 (0)30 6392 4920 Fax : +49 (0)30 6392 4975 e-mail : babu@bessy.de ################################################################## From andy@dustman.net Wed Aug 28 04:00:20 2002 From: andy@dustman.net (Andy Dustman) Date: 27 Aug 2002 23:00:20 -0400 Subject: [DB-SIG] MySQLdb build error In-Reply-To: References: Message-ID: <1030503620.6262.4.camel@4.0.0.10.in-addr.arpa> On Tue, 2002-08-27 at 10:10, Babu Manjasetty wrote: > > building '_mysql' extension > skipping _mysql.c (build/temp.linux-i686-2.2/_mysql.o up-to-date) > gcc -shared build/temp.linux-i686-2.2/_mysql.o -L/usr/lib/mysql > -L/usr/local/lib/mysql -L/usr/local/mysql/lib/mysql -lmysqlclient_r -lz -o > build/lib.linux-i686-2.2/_mysql.so > /usr/i486-suse-linux/bin/ld: cannot find -lmysqlclient_r > collect2: ld returned 1 exit status You don't have the thread-safe library, or the normal mysqlclient library is thread-safe. Therefore set thread_safe_library to NO in setup.py. -- Andy Dustman PGP: 0x930B8AB6 @ .net http://dustman.net/andy "Cogito, ergo sum." -- Rene Descartes "I yam what I yam and that's all what I yam." -- Popeye From msanchez@grupoburke.com Wed Aug 28 10:51:18 2002 From: msanchez@grupoburke.com (=?iso-8859-1?Q?Marcos_S=E1nchez_Provencio?=) Date: Wed, 28 Aug 2002 11:51:18 +0200 (CEST) Subject: [DB-SIG] Accessing MSSQL from Python Message-ID: <28108.195.53.212.39.1030528278.squirrel@www.grupoburke.com> Hello there. Is there some portable way (I mean non-MS) to access MSSQL from Python? FreeTDS has a Python page which is absolutely blank. From jno@glasnet.ru Wed Aug 28 10:53:45 2002 From: jno@glasnet.ru (Eugene V. Dvurechenski) Date: Wed, 28 Aug 2002 13:53:45 +0400 Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: <28108.195.53.212.39.1030528278.squirrel@www.grupoburke.com> References: <28108.195.53.212.39.1030528278.squirrel@www.grupoburke.com> Message-ID: <20020828095345.GW12279@glas.net> On Wed, Aug 28, 2002 at 11:51:18AM +0200, Marcos Sánchez Provencio wrote: > Hello there. > > Is there some portable way (I mean non-MS) to access MSSQL from Python? > FreeTDS has a Python page which is absolutely blank. ODBC? (i mean mxODBC package, for instance) -- SY, jno (PRIVATE PERSON) [ http://www.glasnet.ru/~jno ] a TeleRoss techie [ http://www.aviation.ru/ ] If God meant man to fly, He'd have given him more money. From msanchez@grupoburke.com Wed Aug 28 11:47:48 2002 From: msanchez@grupoburke.com (=?iso-8859-1?Q?Marcos_S=E1nchez_Provencio?=) Date: Wed, 28 Aug 2002 12:47:48 +0200 (CEST) Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: <20020828095345.GW12279@glas.net> References: <20020828095345.GW12279@glas.net> Message-ID: <17743.195.53.212.39.1030531668.squirrel@www.grupoburke.com> That could be useful. Do you mean MSSQL - FreeTDS - [unix]ODBC - mxODBC - Python ? Has anybody tried that? Anyway, I'd rather skip ODBC. > On Wed, Aug 28, 2002 at 11:51:18AM +0200, Marcos S=E1nchez Provencio > wrote: >> Hello there. >> >> Is there some portable way (I mean non-MS) to access MSSQL from >> Python? FreeTDS has a Python page which is absolutely blank. > > ODBC? (i mean mxODBC package, for instance) > > -- > SY, > jno (PRIVATE PERSON) [ http://www.glasnet.ru/~jno ] > a TeleRoss techie [ http://www.aviation.ru/ ] > If God meant man to fly, He'd have given him more money. > > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig From jno@glasnet.ru Wed Aug 28 11:50:14 2002 From: jno@glasnet.ru (Eugene V. Dvurechenski) Date: Wed, 28 Aug 2002 14:50:14 +0400 Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: <17743.195.53.212.39.1030531668.squirrel@www.grupoburke.com> References: <20020828095345.GW12279@glas.net> <17743.195.53.212.39.1030531668.squirrel@www.grupoburke.com> Message-ID: <20020828105014.GB12279@glas.net> it's just my guess. i'm lucky enough to not bother with MS products ;-) but AFAIK, it's possible to use mxODBC directly to access MSSQL server. -jno On Wed, Aug 28, 2002 at 12:47:48PM +0200, Marcos Sánchez Provencio wrote: > That could be useful. Do you mean > > MSSQL - FreeTDS - [unix]ODBC - mxODBC - Python > > ? > > Has anybody tried that? Anyway, I'd rather skip ODBC. > > > > > On Wed, Aug 28, 2002 at 11:51:18AM +0200, Marcos Sánchez Provencio > > wrote: > >> Hello there. > >> > >> Is there some portable way (I mean non-MS) to access MSSQL from > >> Python? FreeTDS has a Python page which is absolutely blank. > > > > ODBC? (i mean mxODBC package, for instance) > > > > -- > > SY, > > jno (PRIVATE PERSON) [ http://www.glasnet.ru/~jno ] > > a TeleRoss techie [ http://www.aviation.ru/ ] > > If God meant man to fly, He'd have given him more money. > > > > _______________________________________________ > > DB-SIG maillist - DB-SIG@python.org > > http://mail.python.org/mailman/listinfo/db-sig > > -- SY, jno (PRIVATE PERSON) [ http://www.glasnet.ru/~jno ] a TeleRoss techie [ http://www.aviation.ru/ ] If God meant man to fly, He'd have given him more money. From msanchez@grupoburke.com Wed Aug 28 12:06:34 2002 From: msanchez@grupoburke.com (=?iso-8859-1?Q?Marcos_S=E1nchez_Provencio?=) Date: Wed, 28 Aug 2002 13:06:34 +0200 (CEST) Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: <20020828105014.GB12279@glas.net> References: <20020828105014.GB12279@glas.net> Message-ID: <32825.195.53.212.39.1030532794.squirrel@www.grupoburke.com> You still need the MSSQL ODBC driver for the operating system, though. That's the one I'm not sure about. > it's just my guess. > i'm lucky enough to not bother with MS products ;-) > but AFAIK, it's possible to use mxODBC directly to access MSSQL server. > > -jno > [... Accessing MSSQL from Python from other than win] From jacobs@penguin.theopalgroup.com Wed Aug 28 12:23:34 2002 From: jacobs@penguin.theopalgroup.com (Kevin Jacobs) Date: Wed, 28 Aug 2002 07:23:34 -0400 (EDT) Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: <28108.195.53.212.39.1030528278.squirrel@www.grupoburke.com> Message-ID: On Wed, 28 Aug 2002, Marcos S=E1nchez Provencio wrote: > Is there some portable way (I mean non-MS) to access MSSQL from Python? > FreeTDS has a Python page which is absolutely blank. I was able to compile David Cole's Sybase module (with very few changes) with FreeTDS using the TDS version 7 protocol. I was then able to connec= t to a MSSQL 2000 server and run queries very reliably. -Kevin -- Kevin Jacobs The OPAL Group - Enterprise Systems Architect Voice: (216) 986-0710 x 19 E-mail: jacobs@theopalgroup.com Fax: (216) 986-0714 WWW: http://www.theopalgroup.com From msanchez@grupoburke.com Wed Aug 28 12:41:47 2002 From: msanchez@grupoburke.com (=?iso-8859-1?Q?Marcos_S=E1nchez_Provencio?=) Date: Wed, 28 Aug 2002 13:41:47 +0200 (CEST) Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: References: Message-ID: <13981.195.53.212.39.1030534907.squirrel@www.grupoburke.com> Thank you very much, that would be perfect for me. So, all I need is: freeTDS Sybase module Do i need any proprietary sw? What were the changes that you had to make? Any gotchas? TIA > On Wed, 28 Aug 2002, Marcos S=E1nchez Provencio wrote: >> Is there some portable way (I mean non-MS) to access MSSQL from >> Python? FreeTDS has a Python page which is absolutely blank. > > I was able to compile David Cole's Sybase module (with very few > changes) with FreeTDS using the TDS version 7 protocol. I was then > able to connect to a MSSQL 2000 server and run queries very reliably. > > -Kevin > > -- > Kevin Jacobs > The OPAL Group - Enterprise Systems Architect > Voice: (216) 986-0710 x 19 E-mail: jacobs@theopalgroup.com Fax: > (216) 986-0714 WWW: http://www.theopalgroup.com > > > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig From jacobs@penguin.theopalgroup.com Wed Aug 28 12:39:22 2002 From: jacobs@penguin.theopalgroup.com (Kevin Jacobs) Date: Wed, 28 Aug 2002 07:39:22 -0400 (EDT) Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: <13981.195.53.212.39.1030534907.squirrel@www.grupoburke.com> Message-ID: On Wed, 28 Aug 2002, Marcos S=E1nchez Provencio wrote: > Thank you very much, that would be perfect for me. So, all I need is: >=20 > freeTDS > Sybase module Make sure you get the current CVS version of FreeTDS. The last release i= s useless. > Do i need any proprietary sw? What were the changes that you had to mak= e? > Any gotchas? That all. There is only one important change I needed to make: diff -ur sybase-0.35pre1/Sybase.py sybase-kbj/Sybase.py --- sybase-0.35pre1/Sybase.py Sun Apr 21 02:00:03 2002 +++ sybase-kbj/Sybase.py Tue Jul 9 17:49:41 2002 @@ -136,7 +136,7 @@ raise DatabaseError(_fmt_client(msg)) def _servermsg_cb(ctx, conn, msg): - if msg.msgnumber not in (5701,): + if msg.msgnumber not in (5701,5703): raise DatabaseError(_fmt_server(msg)) def _row_bind(cmd, count =3D 1): I have a few more patches that I am still testing that fix some locking issues with the Python driver. Let me know if you run into those and I c= an send them too. Good luck, -Kevin >=20 > TIA >=20 > > On Wed, 28 Aug 2002, Marcos S=E1nchez Provencio wrote: > >> Is there some portable way (I mean non-MS) to access MSSQL from > >> Python? FreeTDS has a Python page which is absolutely blank. > > > > I was able to compile David Cole's Sybase module (with very few > > changes) with FreeTDS using the TDS version 7 protocol. I was then > > able to connect to a MSSQL 2000 server and run queries very reliably. > > > > -Kevin > > > > -- > > Kevin Jacobs > > The OPAL Group - Enterprise Systems Architect > > Voice: (216) 986-0710 x 19 E-mail: jacobs@theopalgroup.com Fa= x: > > (216) 986-0714 WWW: http://www.theopalgroup.com > > > > > > _______________________________________________ > > DB-SIG maillist - DB-SIG@python.org > > http://mail.python.org/mailman/listinfo/db-sig >=20 >=20 >=20 --=20 -- Kevin Jacobs The OPAL Group - Enterprise Systems Architect Voice: (216) 986-0710 x 19 E-mail: jacobs@theopalgroup.com Fax: (216) 986-0714 WWW: http://www.theopalgroup.com From msanchez@grupoburke.com Wed Aug 28 14:03:14 2002 From: msanchez@grupoburke.com (=?iso-8859-1?Q?Marcos_S=E1nchez_Provencio?=) Date: Wed, 28 Aug 2002 15:03:14 +0200 (CEST) Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: References: Message-ID: <17922.195.53.212.39.1030539794.squirrel@www.grupoburke.com> Oops, I built freeTDS alright, but I get this when building Sybase. i hav= e to leave now, but I will look into it tomorrow. Any quick pointers? Hasta ma=F1ana... running install running build running build_py not copying Sybase.py (output up-to-date) running build_ext building 'sybasect' extension skipping blk.c (build/temp.linux-i686-2.1/blk.o up-to-date) gcc -g -O2 -Wall -Wstrict-prototypes -fPIC -DWANT_BULKCOPY - I/home/atheneos/local/freetds/include - I/home/atheneos/python21/include/python2.1 -c databuf.c -o build/temp.lin= ux- i686-2.1/databuf.o In file included from /home/atheneos/local/freetds/include/cspublic.h:24, from /home/atheneos/local/freetds/include/ctpublic.h:24, from sybasect.h:27, from databuf.c:26: /home/atheneos/local/freetds/include/tds.h:640: warning: function declara= tion isn't a prototype /home/atheneos/local/freetds/include/tds.h:644: warning: function declara= tion isn't a prototype /home/atheneos/local/freetds/include/tds.h:647: warning: function declara= tion isn't a prototype /home/atheneos/local/freetds/include/tds.h:651: warning: function declara= tion isn't a prototype databuf.c: In function `databuf_alloc': databuf.c:87: `CS_SRC_VALUE' undeclared (first use in this function) databuf.c:87: (Each undeclared identifier is reported only once databuf.c:87: for each function it appears in.) databuf.c: In function `DataBuf_item': databuf.c:181: `CS_BIT' undeclared (first use in this function) databuf.c:181: parse error before `)' databuf.c: In function `DataBuf_ass_item': databuf.c:292: `CS_BIT' undeclared (first use in this function) databuf.c:292: parse error before `)' error: command 'gcc' failed with exit status 1 > On Wed, 28 Aug 2002, Marcos S=E1nchez Provencio wrote: >> Thank you very much, that would be perfect for me. So, all I need is: >> >> freeTDS >> Sybase module > > Make sure you get the current CVS version of FreeTDS. The last release > is useless. > >> Do i need any proprietary sw? What were the changes that you had to >> make? Any gotchas? > > That all. There is only one important change I needed to make: > > diff -ur sybase-0.35pre1/Sybase.py sybase-kbj/Sybase.py > --- sybase-0.35pre1/Sybase.py Sun Apr 21 02:00:03 2002 > +++ sybase-kbj/Sybase.py Tue Jul 9 17:49:41 2002 > @@ -136,7 +136,7 @@ > raise DatabaseError(_fmt_client(msg)) > > def _servermsg_cb(ctx, conn, msg): > - if msg.msgnumber not in (5701,): > + if msg.msgnumber not in (5701,5703): > raise DatabaseError(_fmt_server(msg)) > > def _row_bind(cmd, count =3D 1): > > I have a few more patches that I am still testing that fix some locking > issues with the Python driver. Let me know if you run into those and I > can send them too. > > Good luck, > -Kevin > >> >> TIA >> >> > On Wed, 28 Aug 2002, Marcos S=E1nchez Provencio wrote: >> >> Is there some portable way (I mean non-MS) to access MSSQL from >> >> Python? FreeTDS has a Python page which is absolutely blank. >> > >> > I was able to compile David Cole's Sybase module (with very few >> > changes) with FreeTDS using the TDS version 7 protocol. I was then >> > able to connect to a MSSQL 2000 server and run queries very >> > reliably. >> > >> > -Kevin >> > >> > -- >> > Kevin Jacobs >> > The OPAL Group - Enterprise Systems Architect >> > Voice: (216) 986-0710 x 19 E-mail: jacobs@theopalgroup.com >> > Fax: >> > (216) 986-0714 WWW: http://www.theopalgroup.com >> > >> > >> > _______________________________________________ >> > DB-SIG maillist - DB-SIG@python.org >> > http://mail.python.org/mailman/listinfo/db-sig >> >> >> > > -- > -- > Kevin Jacobs > The OPAL Group - Enterprise Systems Architect > Voice: (216) 986-0710 x 19 E-mail: jacobs@theopalgroup.com Fax: > (216) 986-0714 WWW: http://www.theopalgroup.com From jacobs@penguin.theopalgroup.com Wed Aug 28 14:00:18 2002 From: jacobs@penguin.theopalgroup.com (Kevin Jacobs) Date: Wed, 28 Aug 2002 09:00:18 -0400 (EDT) Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: <17922.195.53.212.39.1030539794.squirrel@www.grupoburke.com> Message-ID: On Wed, 28 Aug 2002, Marcos S=E1nchez Provencio wrote: > Oops, I built freeTDS alright, but I get this when building Sybase. i h= ave to > leave now, but I will look into it tomorrow. Any quick pointers? Run setup.py like this: setup.py build_ext -D WANT_THREADS -D HAVE_FREETDS -U WANT_BULKCOPY -- Kevin Jacobs The OPAL Group - Enterprise Systems Architect Voice: (216) 986-0710 x 19 E-mail: jacobs@theopalgroup.com Fax: (216) 986-0714 WWW: http://www.theopalgroup.com From k.weinert@gmx.net Wed Aug 28 15:17:50 2002 From: k.weinert@gmx.net (Karsten Weinert) Date: Wed, 28 Aug 2002 16:17:50 +0200 Subject: [DB-SIG] mxODBC question Message-ID: <000001c24e9d$d6a51410$15552da0@cipzd11> This is a multi-part message in MIME format. ------=_NextPart_000_0005_01C24EAE.74A23A20 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, the following behavior of the Access ODBC driver=20 and/or Python with mxODBC is a problem for me: I open a ODBC connection, = do some SQL-statements, for example create a new table an put some data in it. Then I close the connection. When I open the connection again, the new table has disappeared! Here is some code which illustrates this: #---------------------- snip import mx.ODBC.Windows dsn=3D"DataSourceName" conn=3DNone curs=3DNone def test(): # open connection conn=3Dmx.ODBC.Windows.Connect(dsn) curs=3Dconn.cursor() # create a table sqlmsg=3D'CREATE TABLE test13 (nr Integer, val Integer)' print(sqlmsg) curs.execute(sqlmsg) # put some data in the table for i in range(10): sqlmsg=3D"INSERT INTO test13 VALUES (%d,%d)" % (i, i*i) print(sqlmsg) curs.execute(sqlmsg) # see that there is really data in the table curs.execute("SELECT count(nr) FROM test13") res=3Dcurs.fetchall() print("There are now %s rows in the table." % res[0][0]) # but what happens when the connection is closed and reopened? curs.close() conn.close() conn=3Dmx.ODBC.Windows.Connect(dsn) curs=3Dconn.cursor() curs.execute("SELECT count(nr) FROM test13") res=3Dcurs.fetchall() print("There are now %s rows in the table." % res[0][0]) The first select count() statement returns 10, the second statement = produces an error messages "table not found". =20 I am using python 2.2 on Win98 with the Access-ODBC-driver (Desktop Driver Pack 3.0). I don't have Access itself installed. Can you please give me some advice what I did wrong? Regards, Karsten ------=_NextPart_000_0005_01C24EAE.74A23A20 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi,
the following behavior of the Access ODBC driver=20
and/or Python with =
mxODBC is a problem for me: I open a ODBC connection, do some
SQL-statements, for example create a new table an put some data in it.
Then I close the connection. When I open the connection again, the new
table has disappeared!

Here is some code which illustrates this:
#---------------------- snip
import mx.ODBC.Windows

dsn=3D"DataSourceName"
conn=3DNone
curs=3DNone

def test():
  # open connection
  conn=3Dmx.ODBC.Windows.Connect(dsn)
  curs=3Dconn.cursor()

  # create a table
  sqlmsg=3D'CREATE TABLE test13 (nr Integer, val Integer)'
  print(sqlmsg)
  curs.execute(sqlmsg)

  # put some data in the table
  for i in range(10):
    sqlmsg=3D"INSERT INTO test13 VALUES (%d,%d)" % (i, i*i)
    print(sqlmsg)
    curs.execute(sqlmsg)

  # see that there is really data in the table
  curs.execute("SELECT count(nr) FROM test13")
  res=3Dcurs.fetchall()
  print("There are now %s rows in the table." % res[0][0])

  # but what happens when the connection is closed and reopened?
  curs.close()
  conn.close()
  conn=3Dmx.ODBC.Windows.Connect(dsn)
  curs=3Dconn.cursor()
  curs.execute("SELECT count(nr) FROM test13")
  res=3Dcurs.fetchall()
  print("There are now %s rows in the table." % res[0][0])
The first select count() statement returns 10, the second =
statement produces an error messages "table not found".
 =20
I am using python 2.2 on Win98 with the Access-ODBC-driver (Desktop
Driver Pack 3.0). I don't have Access itself installed.

Can you please give me some advice what I did wrong?
Regards,
Karsten
------=_NextPart_000_0005_01C24EAE.74A23A20-- From matt@zope.com Wed Aug 28 15:24:29 2002 From: matt@zope.com (Matthew T. Kromer) Date: Wed, 28 Aug 2002 10:24:29 -0400 Subject: [DB-SIG] mxODBC question References: <000001c24e9d$d6a51410$15552da0@cipzd11> Message-ID: <3D6CDD1D.5000006@zope.com> Karsten Weinert wrote: >Hi, >the following behavior of the Access ODBC driver >and/or *Python with mxODBC is a problem for me:* I open a ODBC connection, do some >SQL-statements, for example create a new table an put some data in it. >Then I close the connection. When I open the connection again, the new >table has disappeared! >... > > # put some data in the table > for i in range(10): > sqlmsg="INSERT INTO test13 VALUES (%d,%d)" % (i, i*i) > print(sqlmsg) > curs.execute(sqlmsg) > > You need a conn.commit() right here to commit your changes. Otherwise, they're being rolled back for you automatically. > >Can you please give me some advice what I did wrong? >Regards, >Karsten > From TKeating@origin.ea.com Wed Aug 28 15:34:45 2002 From: TKeating@origin.ea.com (Keating, Tim) Date: Wed, 28 Aug 2002 09:34:45 -0500 Subject: [DB-SIG] Accessing MSSQL from Python Message-ID: <9B8090A2F0EBDB4ABD59B08E81C1A6842F6335@osi-postal.osi.ad.ea.com> I see you have a separate thread going on using FreeTDS, but I thought = I would throw out another suggestion: use win32com to call ADO. I have = done this and it's pretty easy. -----Original Message----- From: Marcos S=E1nchez Provencio [mailto:msanchez@grupoburke.com]=20 Sent: Wednesday, August 28, 2002 4:51 AM To: db-sig@python.org Subject: [DB-SIG] Accessing MSSQL from Python Hello there. Is there some portable way (I mean non-MS) to access MSSQL from Python? FreeTDS has a Python page which is absolutely blank. _______________________________________________ DB-SIG maillist - DB-SIG@python.org http://mail.python.org/mailman/listinfo/db-sig From bkline@rksystems.com Wed Aug 28 16:03:12 2002 From: bkline@rksystems.com (Bob Kline) Date: Wed, 28 Aug 2002 11:03:12 -0400 (EDT) Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: <9B8090A2F0EBDB4ABD59B08E81C1A6842F6335@osi-postal.osi.ad.ea.com> Message-ID: On Wed, 28 Aug 2002, Keating, Tim wrote: > I see you have a separate thread going on using FreeTDS, but I > thought I would throw out another suggestion: use win32com to call > ADO. I have done this and it's pretty easy. Please read the original poster's message again. The operative word here is "portable." > > -----Original Message----- > From: Marcos S=E1nchez Provencio [mailto:msanchez@grupoburke.com] > Sent: Wednesday, August 28, 2002 4:51 AM > To: db-sig@python.org > Subject: [DB-SIG] Accessing MSSQL from Python > > > Hello there. > > Is there some portable way (I mean non-MS) to access MSSQL from > Python? FreeTDS has a Python page which is absolutely blank. --=20 Bob Kline mailto:bkline@rksystems.com http://www.rksystems.com From msanchez@grupoburke.com Thu Aug 29 09:18:50 2002 From: msanchez@grupoburke.com (=?iso-8859-1?Q?Marcos_S=E1nchez_Provencio?=) Date: Thu, 29 Aug 2002 10:18:50 +0200 (CEST) Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: References: Message-ID: <24789.195.53.212.39.1030609130.squirrel@www.grupoburke.com> All right! Now it is built and it connects fine. I get Violaci=F3n de segmento (core dumped) when exiting Python, though. PS No matter how hard you try, I am not giving you this week's salary ;-) > On Wed, 28 Aug 2002, Marcos S=E1nchez Provencio wrote: >> Oops, I built freeTDS alright, but I get this when building Sybase. i >> have to leave now, but I will look into it tomorrow. Any quick >> pointers? > > Run setup.py like this: > > setup.py build_ext -D WANT_THREADS -D HAVE_FREETDS -U WANT_BULKCOPY > > -- > Kevin Jacobs > The OPAL Group - Enterprise Systems Architect > Voice: (216) 986-0710 x 19 E-mail: jacobs@theopalgroup.com Fax: > (216) 986-0714 WWW: http://www.theopalgroup.com From jacobs@penguin.theopalgroup.com Thu Aug 29 11:38:51 2002 From: jacobs@penguin.theopalgroup.com (Kevin Jacobs) Date: Thu, 29 Aug 2002 06:38:51 -0400 (EDT) Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: <24789.195.53.212.39.1030609130.squirrel@www.grupoburke.com> Message-ID: On Thu, 29 Aug 2002, Marcos S=E1nchez Provencio wrote: > All right! Now it is built and it connects fine. I get > Violaci=F3n de segmento (core dumped) > when exiting Python, though. What versions of Python and the Sybase module are you using? Also, can y= ou generate a gdb stack trace for me? -Kevin -- Kevin Jacobs The OPAL Group - Enterprise Systems Architect Voice: (216) 986-0710 x 19 E-mail: jacobs@theopalgroup.com Fax: (216) 986-0714 WWW: http://www.theopalgroup.com From djc@object-craft.com.au Thu Aug 29 14:22:01 2002 From: djc@object-craft.com.au (Dave Cole) Date: 29 Aug 2002 23:22:01 +1000 Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: References: Message-ID: >>>>> "Kevin" =3D=3D Kevin Jacobs writes: Kevin> On Wed, 28 Aug 2002, Marcos S=E1nchez Provencio wrote: >> Is there some portable way (I mean non-MS) to access MSSQL from >> Python? FreeTDS has a Python page which is absolutely blank. Kevin> I was able to compile David Cole's Sybase module (with very few Kevin> changes) with FreeTDS using the TDS version 7 protocol. I was Kevin> then able to connect to a MSSQL 2000 server and run queries Kevin> very reliably. I still have to integrate all of Kevin's excellent work and make a new release. I have nothing but weak excuses to explain why it has not happened yet :-( - Dave --=20 http://www.object-craft.com.au From djc@object-craft.com.au Thu Aug 29 14:28:05 2002 From: djc@object-craft.com.au (Dave Cole) Date: 29 Aug 2002 23:28:05 +1000 Subject: [DB-SIG] Accessing MSSQL from Python In-Reply-To: <24789.195.53.212.39.1030609130.squirrel@www.grupoburke.com> References: <24789.195.53.212.39.1030609130.squirrel@www.grupoburke.com> Message-ID: >>>>> "Marcos" =3D=3D Marcos S=E1nchez Provencio = writes: Marcos> All right! Now it is built and it connects fine. I get Marcos> Violaci=F3n de segmento (core dumped) when exiting Python, Marcos> though. One thing worth trying when things go bad is to turn on the debugging output. It helps work out where the problem might be. Do this: import Sybase Sybase._ctx.debug =3D 1 Sybase.py directs the debug output to sys.stderr but you can specify a different destination by doing this: import Sybase Sybase._ctx.debug =3D 1 Sybase.set_debug(open('afile.log', 'w')) The output will mean something to people familiar with the Sybase CT library. - Dave --=20 http://www.object-craft.com.au From m.frasca@hyperborea.com Fri Aug 30 16:16:55 2002 From: m.frasca@hyperborea.com (m.frasca@hyperborea.com) Date: Fri, 30 Aug 2002 17:16:55 +0200 Subject: [DB-SIG] http://www.python.org/topics/database/DatabaseAPI-2.0.html Message-ID: <20020830171655.C780@edelweiss.hyperborea.it> Hallo everybody, I'm developing yet another web-based interface to an Oracle database using Python and DCOracle2. I would like to write as little implementation-dependent code as possible. In this attempt, I miss something in the API. my question is about automatically generated primary keys. when I let the database generate the primary keys (the technique involved is implementation-dependent), how on earth do I retrieve the keys of my newly inserted record? in practice: >>> import DCOracle2 >>> db = DCOracle2.connect('user/password@service') >>> crsr = db.cursor() >>> crsr.execute("insert into persone (nome, cognome, datanascita) values ('Ave', 'Ninchi', '14-Dic-1915')") here the method returns a value, but I assume that this is only to be used by the ones how developed the DCOracle2 package. how do I retrieve the primary key of the 'Ave Ninchi' record? the cursor.execute method can be used to prepare a SELECT and thus, it makes sense to ask the cursor to fetchxxx what was prepared by the executexxx. this is what I tried, with no luck: dco2.ProgrammingError: No results available from last execute operation maybe this possibility is offered somewhere else, but I don't find it in the documentation of the API. if it is not there, what about extending the API by requiring the execute('INSERT ...') to prepare the cursor as if the user had asked to execute('SELECT ...')? the other option, as far as I can understand, is not to use any automatically generated primary keys and do all the work from inside Python. Whenever I try to insert any object into a table, I should check if the primary keys are defined, if that is not the case, generate them in my Python program and only then put the object into the database. I don't like this solution (in practice, it forces me to accesses the database *only* from the Python program) I wonder if there was a discussion on this regard and if the API2 reflects the results of the discussion. thanks for your time, Mario Frasca From jekabs.andrusaitis@tietoenator.com Fri Aug 30 16:13:15 2002 From: jekabs.andrusaitis@tietoenator.com (Jekabs Andrushaitis) Date: Fri, 30 Aug 2002 17:13:15 +0200 Subject: [DB-SIG] http://www.python.org/topics/database/DatabaseAPI-2.0.html In-Reply-To: <20020830171655.C780@edelweiss.hyperborea.it> Message-ID: <000001c25037$c48614a0$262a949f@konts.lv> If I understood the question here correctly - I am looking for answer to it too. I am using PostgreSQL however, but I have tables with fields whose default values are taken from sequence. Since I need to know the primary key value for record directly after insertion, I am fetching next value from sequence seperately, and only then inserting the row into table with primary key field value supplied. Is there a way to easily fetch the field values for inserted row after insert statement execution? Jekabs Andrushaitis Senior system analyst TietoEnator Financial Solutions 41 Lacplesa Str. Riga, LV-1011, Latvia Tel: +371 7286660 Fax: +371 7243000 E-mail: jekabs.andrusaitis@tietoenator.com > -----Original Message----- > From: db-sig-admin@python.org > [mailto:db-sig-admin@python.org]On Behalf Of m.frasca@hyperborea.com > Sent: piektdiena, 2002. gada 30. august? 17:17 > To: db-sig@python.org > Subject: [DB-SIG] > http://www.python.org/topics/database/DatabaseAPI-2.0.html > > > Hallo everybody, > > I'm developing yet another web-based interface to an Oracle database > using Python and DCOracle2. I would like to write as little > implementation-dependent code as possible. In this attempt, I miss > something in the API. > > my question is about automatically generated primary keys. > > when I let the database generate the primary keys (the > technique involved > is implementation-dependent), how on earth do I retrieve the > keys of my > newly inserted record? > > in practice: > >>> import DCOracle2 > >>> db = DCOracle2.connect('user/password@service') > >>> crsr = db.cursor() > >>> crsr.execute("insert into persone (nome, cognome, > datanascita) values ('Ave', 'Ninchi', '14-Dic-1915')") > > here the method returns a value, but I assume that this is only to be > used by the ones how developed the DCOracle2 package. > > how do I retrieve the primary key of the 'Ave Ninchi' record? > > the cursor.execute method can be used to prepare a SELECT and thus, > it makes sense to ask the cursor to fetchxxx what was prepared by the > executexxx. this is what I tried, with no luck: > > dco2.ProgrammingError: No results available from last execute > operation > > maybe this possibility is offered somewhere else, but I don't > find it in > the documentation of the API. if it is not there, what about > extending > the API by requiring the execute('INSERT ...') to prepare the > cursor as > if the user had asked to execute('SELECT ...')? > > the other option, as far as I can understand, is not to use any > automatically generated primary keys and do all the work from inside > Python. Whenever I try to insert any object into a table, I should > check if the primary keys are defined, if that is not the > case, generate > them in my Python program and only then put the object into > the database. > > I don't like this solution (in practice, it forces me to accesses > the database *only* from the Python program) I wonder if there was a > discussion on this regard and if the API2 reflects the results of the > discussion. > > thanks for your time, > > Mario Frasca > > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig > From anthony@computronix.com Fri Aug 30 16:57:26 2002 From: anthony@computronix.com (Anthony Tuininga) Date: 30 Aug 2002 09:57:26 -0600 Subject: [DB-SIG] Re: [DB-SIG] http://www.python.org/topics/database/DatabaseAPI-2.0.ht ml In-Reply-To: <20020830171655.C780@edelweiss.hyperborea.it> References: <20020830171655.C780@edelweiss.hyperborea.it> Message-ID: <1030723046.22208.198.camel@chl0151.edmonton.computronix.com> There is no DB independent way of doing this that I am aware of. In Oracle you use the "returning" clause. I am not familiar with DCOracle2 but I suspect something similar can be done. import cx_Oracle v_Connection = cx_Oracle.connect("user/pw@tns") v_Cursor = v_Connection.cursor() v_Vars = v_Cursor.setinputsizes(p_PrimaryKeyValue = cx_Oracle.NUMBER) v_Cursor.execute(""" insert into SomeTable ( SomeValue ) values ( :p_SomeValue ) returning PrimaryKey into :p_PrimaryKeyValue""") print "PrimaryKeyValue:", v_Vars["p_PrimaryKeyValue"].getvalue() This method is also not compatible with the DB-API as the DB-API does not specify a method for handling output variables in anything other than stored procedures. If you want to conform to the DB-API, you will have to use a stored procedure and use the cursor method callproc() instead of the method above. On Fri, 2002-08-30 at 09:16, m.frasca@hyperborea.com wrote: > Hallo everybody, > > I'm developing yet another web-based interface to an Oracle database > using Python and DCOracle2. I would like to write as little > implementation-dependent code as possible. In this attempt, I miss > something in the API. > > my question is about automatically generated primary keys. > > when I let the database generate the primary keys (the technique > involved > is implementation-dependent), how on earth do I retrieve the keys of my > newly inserted record? > > in practice: > >>> import DCOracle2 > >>> db = DCOracle2.connect('user/password@service') > >>> crsr = db.cursor() > >>> crsr.execute("insert into persone (nome, cognome, datanascita) > values ('Ave', 'Ninchi', '14-Dic-1915')") > > here the method returns a value, but I assume that this is only to be > used by the ones how developed the DCOracle2 package. > > how do I retrieve the primary key of the 'Ave Ninchi' record? > > the cursor.execute method can be used to prepare a SELECT and thus, > it makes sense to ask the cursor to fetchxxx what was prepared by the > executexxx. this is what I tried, with no luck: > > dco2.ProgrammingError: No results available from last execute operation > > maybe this possibility is offered somewhere else, but I don't find it in > the documentation of the API. if it is not there, what about extending > the API by requiring the execute('INSERT ...') to prepare the cursor as > if the user had asked to execute('SELECT ...')? > > the other option, as far as I can understand, is not to use any > automatically generated primary keys and do all the work from inside > Python. Whenever I try to insert any object into a table, I should > check if the primary keys are defined, if that is not the case, generate > them in my Python program and only then put the object into the > database. > > I don't like this solution (in practice, it forces me to accesses > the database *only* from the Python program) I wonder if there was a > discussion on this regard and if the API2 reflects the results of the > discussion. > > thanks for your time, > > Mario Frasca > > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig -- Anthony Tuininga anthony@computronix.com Computronix Distinctive Software. Real People. Suite 200, 10216 - 124 Street NW Edmonton, AB, Canada T5N 4A3 Phone: (780) 454-3700 Fax: (780) 454-3838 http://www.computronix.com From matt@zope.com Fri Aug 30 18:16:18 2002 From: matt@zope.com (Matthew T. Kromer) Date: Fri, 30 Aug 2002 13:16:18 -0400 Subject: [DB-SIG] Re: [DB-SIG] http://www.python.org/topics/database/DatabaseAPI-2.0.ht ml References: <20020830171655.C780@edelweiss.hyperborea.it> <1030723046.22208.198.camel@chl0151.edmonton.computronix.com> Message-ID: <3D6FA862.1090101@zope.com> Anthony Tuininga wrote: >There is no DB independent way of doing this that I am aware of. In >Oracle you use the "returning" clause. I am not familiar with DCOracle2 >but I suspect something similar can be done. > >import cx_Oracle > >v_Connection = cx_Oracle.connect("user/pw@tns") >v_Cursor = v_Connection.cursor() >v_Vars = v_Cursor.setinputsizes(p_PrimaryKeyValue = cx_Oracle.NUMBER) >v_Cursor.execute(""" > insert into SomeTable ( > SomeValue > ) values ( > :p_SomeValue > ) returning PrimaryKey into :p_PrimaryKeyValue""") >print "PrimaryKeyValue:", v_Vars["p_PrimaryKeyValue"].getvalue() > >This method is also not compatible with the DB-API as the DB-API does >not specify a method for handling output variables in anything other >than stored procedures. If you want to conform to the DB-API, you will >have to use a stored procedure and use the cursor method callproc() >instead of the method above. > > DCOracle does this similarly, albeit in yet another incompatible way import DCOracle2 db = DCOracle2.connect('scott/tiger') c = db.cursor() rval = db.BindingArray(1, 45, 'SQLT_STR') c.execute('Insert into foo values(...) returning SomeVar into :rval', rval=rval) print rval[0] BindingArrays in DCOracle2 are incredibly primative; and not exactly pleasant to use. One quirk is they can't decode Oracle types for you to Python numbers -- so you use SQLT_STR as the format to have Oracle convert the value to a string instead (they really provide something like a raw buffer for input/output values). Normally the Python layer handles all of this for you, but it doesn't understand how to do that for RETURNING clauses. From msanchez@grupoburke.com Sat Aug 31 11:40:22 2002 From: msanchez@grupoburke.com (Marcos =?ISO-8859-1?Q?S=E1nchez?= Provencio) Date: 31 Aug 2002 12:40:22 +0200 Subject: [DB-SIG] How to return results from stored procedures in Oracle In-Reply-To: <1030723046.22208.198.camel@chl0151.edmonton.computronix.com> References: <20020830171655.C780@edelweiss.hyperborea.it> <1030723046.22208.198.camel@chl0151.edmonton.computronix.com> Message-ID: <1030790422.1025.19.camel@renata.macondo.pri> Hello there. In TSQL (the procedural language used in Sybase and MSSQL) it is very simple to return rows from a procedure and use it as a query issued by the user dinamically. I have managed to do get the same effect in ADO/VB using a rather contrived mechanism which involved putting the procedure in a package and returning some type (cursor, I think). How can I get it using DBAPI in Oracle? How about PostgreSQL? What I want is something like --TSQL code-- create procedure onlyone @id int as select * from mytable where id=@id --END TSQL code-- So, for example, I can give permissions to access the data one by one, knowing the id in advance. From haering_postgresql@gmx.de Sat Aug 31 12:54:41 2002 From: haering_postgresql@gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 31 Aug 2002 13:54:41 +0200 Subject: [DB-SIG] How to return results from stored procedures in Oracle In-Reply-To: <1030790422.1025.19.camel@renata.macondo.pri> References: <20020830171655.C780@edelweiss.hyperborea.it> <1030723046.22208.198.camel@chl0151.edmonton.computronix.com> <1030790422.1025.19.camel@renata.macondo.pri> Message-ID: <20020831115441.GA716@lilith.ghaering.test> * Marcos Sánchez Provencio [2002-08-31 12:40 +0200]: > Hello there. > > In TSQL (the procedural language used in Sybase and MSSQL) it is very > simple to return rows from a procedure and use it as a query issued by > the user dinamically. I have managed to do get the same effect in > ADO/VB using a rather contrived mechanism which involved putting the > procedure in a package and returning some type (cursor, I think). Cool - I have to keep in mind that this is possible for Oracle, too. I'm in a project where we just write in a table (not even temporary) that has the necessary fields, plus a SESSIONID field. I do the following, then: 1) call stored procedure 2) select from table where sessionid = userenv('sessionid') 3) delete from table where sessionid = userenv('sessionid') > How can I get it using DBAPI in Oracle? How about PostgreSQL? http://developer.postgresql.org/docs/postgres/plpgsql-cursors.html - 22.7.3.3. Returning Cursors. It's currently not so easy in pyPgSQL, but I plan to introduce a little magic for pyPgSQL 3.0: http://sourceforge.net/mailarchive/message.php?msg_id=1911314 Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b'))) From mal@lemburg.com Sat Aug 31 16:00:47 2002 From: mal@lemburg.com (M.-A. Lemburg) Date: Sat, 31 Aug 2002 17:00:47 +0200 Subject: [DB-SIG] Accessing MSSQL from Python References: <20020828095345.GW12279@glas.net> <17743.195.53.212.39.1030531668.squirrel@www.grupoburke.com> Message-ID: <3D70DA1F.1050008@lemburg.com> Marcos S=E1nchez Provencio wrote: > That could be useful. Do you mean >=20 > MSSQL - FreeTDS - [unix]ODBC - mxODBC - Python >=20 > ? >=20 > Has anybody tried that? Anyway, I'd rather skip ODBC. That procedure is described on the FreeTDS web-page, so I suppose it works. The advantage here is that you can easily port your program between Unix and Windows machines without changing a single line of code. >>On Wed, Aug 28, 2002 at 11:51:18AM +0200, Marcos S=E1nchez Provencio >>wrote: >> >>>Hello there. >>> >>>Is there some portable way (I mean non-MS) to access MSSQL from >>>Python? FreeTDS has a Python page which is absolutely blank. >> >>ODBC? (i mean mxODBC package, for instance) --=20 Marc-Andre Lemburg CEO eGenix.com Software GmbH _______________________________________________________________________ eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,... Python Consulting: http://www.egenix.com/ Python Software: http://www.egenix.com/files/python/ From andy47@halfcooked.com Sat Aug 31 17:10:00 2002 From: andy47@halfcooked.com (Andy Todd) Date: Sat, 31 Aug 2002 17:10:00 +0100 Subject: [DB-SIG] How to return results from stored procedures in Oracle References: <20020830171655.C780@edelweiss.hyperborea.it> <1030723046.22208.198.camel@chl0151.edmonton.computronix.com> <1030790422.1025.19.camel@renata.macondo.pri> Message-ID: <3D70EA58.1040700@halfcooked.com> Marcos Sánchez Provencio wrote: > Hello there. > > In TSQL (the procedural language used in Sybase and MSSQL) it is very > simple to return rows from a procedure and use it as a query issued by > the user dinamically. I have managed to do get the same effect in ADO/VB > using a rather contrived mechanism which involved putting the procedure > in a package and returning some type (cursor, I think). > > How can I get it using DBAPI in Oracle? How about PostgreSQL? > > What I want is something like > > --TSQL code-- > > create procedure onlyone @id int > as > select * from mytable where id=@id > > --END TSQL code-- > > So, for example, I can give permissions to access the data one by one, > knowing the id in advance. > > > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig > In Oracle, return a collection from your stored *function* http://download-uk.oracle.com/docs/cd/A87860_01/doc/index.htm In other words return a TABLE or a VARRAY from your stored function and see what happens. I haven't tried this using either of the DB-API modules for Oracle (DCOracle2 and cx_Oracle) so I can't confirm whether it works or not. The reason I haven't tried it is because if I use stored procedures or functions I tend to make them pretty self contained and only return a status field. If you want to get a set of data into your Python program then just write a select statement and get the set using a cursor. By returning a set of data as a result of a stored function it would seem you are trying to dome some work in one place and the rest in another. If you start doing half of a transaction in a stored procedure and half in Python then only bad things can happen <0.5 wink> Of course, YMMV. Regards, Andy -- ---------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com From anthony@computronix.com Sat Aug 31 19:33:25 2002 From: anthony@computronix.com (Anthony Tuininga) Date: Sat, 31 Aug 2002 12:33:25 -0600 Subject: [DB-SIG] How to return results from stored procedures in Orac le In-Reply-To: <3D70EA58.1040700@halfcooked.com> References: <3D70EA58.1040700@halfcooked.com> Message-ID: <1030818805.1772.3.camel@localhost> On Sat, 2002-08-31 at 10:10, Andy Todd wrote: > Marcos S=E1nchez Provencio wrote: > > Hello there. > >=20 > > In TSQL (the procedural language used in Sybase and MSSQL) it is very > > simple to return rows from a procedure and use it as a query issued by > > the user dinamically. I have managed to do get the same effect in > ADO/VB > > using a rather contrived mechanism which involved putting the > procedure > > in a package and returning some type (cursor, I think). > >=20 > > How can I get it using DBAPI in Oracle? How about PostgreSQL? > >=20 > > What I want is something like > >=20 > > --TSQL code-- > >=20 > > create procedure onlyone @id int > > as > > select * from mytable where id=3D@id > >=20 > > --END TSQL code-- > >=20 > > So, for example, I can give permissions to access the data one by one, > > knowing the id in advance. > >=20 > >=20 > > _______________________________________________ > > DB-SIG maillist - DB-SIG@python.org > > http://mail.python.org/mailman/listinfo/db-sig > >=20 >=20 > In Oracle, return a collection from your stored *function* >=20 > http://download-uk.oracle.com/docs/cd/A87860_01/doc/index.htm >=20 > In other words return a TABLE or a VARRAY from your stored function and=20 > see what happens. Right. Or you can return a ref cursor. > I haven't tried this using either of the DB-API modules for Oracle=20 > (DCOracle2 and cx_Oracle) so I can't confirm whether it works or not. Both of these work in cx_Oracle. You do have to use non DB-API constructs because the DB-API doesn't cover this very well. It seems to cover returning a result set (and thus using fetchxxx() methods) but does not handle arrays or complex data types at all. > The reason I haven't tried it is because if I use stored procedures or=20 > functions I tend to make them pretty self contained and only return a=20 > status field. If you want to get a set of data into your Python program=20 > then just write a select statement and get the set using a cursor. >=20 > By returning a set of data as a result of a stored function it would=20 > seem you are trying to dome some work in one place and the rest in=20 > another. If you start doing half of a transaction in a stored procedure=20 > and half in Python then only bad things can happen <0.5 wink> Yes. That can become problematic. In addition, PL/SQL (Oracle's programming language) has some serious limitations when compared with Python. I just translated a complex program that I wrote a year or so ago in PL/SQL to Python and the speedup involved ranges from 40% to 500%! If I had tried some complex combination of PL/SQL and Python I would have run into some serious problems. > Of course, YMMV. Definitely. :-) > Regards, > Andy > --=20 > ---------------------------------------------------------------------- > From the desk of Andrew J Todd esq - http://www.halfcooked.com >=20 >=20 > _______________________________________________ > DB-SIG maillist - DB-SIG@python.org > http://mail.python.org/mailman/listinfo/db-sig From haering_postgresql@gmx.de Sat Aug 31 20:06:25 2002 From: haering_postgresql@gmx.de (Gerhard =?iso-8859-1?Q?H=E4ring?=) Date: Sat, 31 Aug 2002 21:06:25 +0200 Subject: [DB-SIG] How to return results from stored procedures in Oracle In-Reply-To: <1030818805.1772.3.camel@localhost> References: <3D70EA58.1040700@halfcooked.com> <1030818805.1772.3.camel@localhost> Message-ID: <20020831190625.GA4323@lilith.ghaering.test> * Anthony Tuininga [2002-08-31 12:33 -0600]: > On Sat, 2002-08-31 at 10:10, Andy Todd wrote: > > In Oracle, return a collection from your stored *function* > > > > http://download-uk.oracle.com/docs/cd/A87860_01/doc/index.htm > > > > In other words return a TABLE or a VARRAY from your stored function and > > see what happens. > > Right. Or you can return a ref cursor. > > > I haven't tried this using either of the DB-API modules for Oracle > > (DCOracle2 and cx_Oracle) so I can't confirm whether it works or not. > > Both of these work in cx_Oracle. You do have to use non DB-API > constructs because the DB-API doesn't cover this very well. It seems to > cover returning a result set (and thus using fetchxxx() methods) but > does not handle arrays or complex data types at all. I plan to implement that for the next major release of pyPgSQL. As I know the type that a PostgreSQL function returned I can wrap it into an appropriate class, if it is a REFCURSOR. So that I can then do: cursor.callproc("myfunc", 2) sp_cursor = cursor.fetchone()[0] # ref. cursor that stored procedure # returns for row in sp_cursor.fetchall(): # do stuff instead of: cursor.callproc("myfunc", 2) cursorname = cursor.fetchone()[0] cursor.execute('fetch all in "%s"' % cursorname) for row in cursor.fetchall(): # do stuff IOW wrap the returned Cursor object with a special class, that has fetchone(), fetchmany(), fetchall(), scroll(), __iter__, next(), close() and perhaps something I forgot about :) Any comments? Would this be against the intention of the DB-API? Gerhard -- mail: gerhard bigfoot de registered Linux user #64239 web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930 public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930 reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))